summaryrefslogtreecommitdiffstats
path: root/sys/net/route.h
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2004-04-13 11:22:22 +0000
committerluigi <luigi@FreeBSD.org>2004-04-13 11:22:22 +0000
commitf83ca5e62d50a0c97e6da783970932ec1865b591 (patch)
treef81cadb2baf9d439843a5c8123c911c7980bb872 /sys/net/route.h
parentc3b6d70103e7aa78831dc2504b16900173fbc234 (diff)
downloadFreeBSD-src-f83ca5e62d50a0c97e6da783970932ec1865b591.zip
FreeBSD-src-f83ca5e62d50a0c97e6da783970932ec1865b591.tar.gz
route.h: introduce a macro, SA_SIZE(struct sockaddr *) which returns
the space occupied by a struct sockaddr when passed through a routing socket. Use it to replace the macro ROUNDUP(int), that does the same but is redefined by every file which uses it, courtesy of the School of Cut'n'Paste Programming(TM). (partial) userland changes to follow.
Diffstat (limited to 'sys/net/route.h')
-rw-r--r--sys/net/route.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/net/route.h b/sys/net/route.h
index 3f3b111..fb5d3ca 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -260,6 +260,18 @@ struct rt_addrinfo {
struct ifnet *rti_ifp;
};
+/*
+ * This macro returns the size of a struct sockaddr when passed
+ * through a routing socket. Basically we round up sa_len to
+ * a multiple of sizeof(long), with a minimum of sizeof(long).
+ * The check for a NULL pointer is just a convenience, probably never used.
+ * The case sa_len == 0 should only apply to empty structures.
+ */
+#define SA_SIZE(sa) \
+ ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
+ sizeof(long) : \
+ 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
+
#ifdef _KERNEL
#define RT_LOCK_INIT(_rt) \
OpenPOWER on IntegriCloud