summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ipv4.h7
-rw-r--r--lib/ipv6.h11
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/ipv4.h b/lib/ipv4.h
index 5c8c390..52bed16 100644
--- a/lib/ipv4.h
+++ b/lib/ipv4.h
@@ -11,6 +11,7 @@
#include "lib/endian.h"
#include "lib/bitops.h"
+#include "lib/unaligned.h"
#ifdef DEBUGGING
@@ -63,6 +64,7 @@ typedef u32 ip_addr;
/* ipa_pxlen() requires that x != y */
#define ipa_pxlen(x, y) ipv4_pxlen(_I(x), _I(y))
#define ipa_getbit(x, y) (_I(x) & (0x80000000 >> (y)))
+#define ipa_put_addr(x, y) ipv4_put_addr(x, y)
#define ip_skip_header(x, y) ipv4_skip_header(x, y)
@@ -93,6 +95,11 @@ static inline u32 ipv4_pxlen(u32 a, u32 b)
return 31 - u32_log2(a ^ b);
}
+static inline byte * ipv4_put_addr(byte *buf, ip_addr a)
+{
+ put_u32(buf, _I(a));
+ return buf+4;
+}
#define IP_PREC_INTERNET_CONTROL 0xc0
diff --git a/lib/ipv6.h b/lib/ipv6.h
index 53888ff..e15c57a 100644
--- a/lib/ipv6.h
+++ b/lib/ipv6.h
@@ -14,6 +14,7 @@
#include <netinet/in.h>
#include "lib/string.h"
#include "lib/bitops.h"
+#include "lib/unaligned.h"
typedef struct ipv6_addr {
u32 addr[4];
@@ -68,6 +69,7 @@ typedef struct ipv6_addr {
/* ipa_pxlen() requires that x != y */
#define ipa_pxlen(x, y) ipv6_pxlen(x, y)
#define ipa_getbit(x, y) ipv6_getbit(x, y)
+#define ipa_put_addr(x, y) ipv6_put_addr(x, y)
#define ipa_absolutize(x,y) ipv6_absolutize(x,y)
/* In IPv6, SOCK_RAW does not return packet header */
@@ -115,6 +117,15 @@ static inline u32 ipv6_pxlen(ip_addr a, ip_addr b)
return 32 * i + 31 - u32_log2(a.addr[i] ^ b.addr[i]);
}
+static inline byte * ipv6_put_addr(byte *buf, ip_addr a)
+{
+ put_u32(buf+0, _I0(a));
+ put_u32(buf+4, _I1(a));
+ put_u32(buf+8, _I2(a));
+ put_u32(buf+12, _I3(a));
+ return buf+16;
+}
+
/*
* RFC 1883 defines packet precendece, but RFC 2460 replaces it
* by generic Traffic Class ID with no defined semantics. Better