summaryrefslogtreecommitdiff
path: root/sys/netinet6/in6.h
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2013-03-28 15:05:33 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2013-03-28 15:05:33 +0000
commit074382f949295292cba8a708947bdfdd4cfb48c8 (patch)
tree88eee9238e6306eb5b6c6fc192db36d33cc6e66f /sys/netinet6/in6.h
parent9efd0f3534a333b6ec869aaadab31ddf7a7bbd21 (diff)
Convert the satosin, sintosa, ifatoia, satosin6, sin6tosa, ifatoia6
defines into static inline functions. This allows the compiler to check the source type before casting. liked by many; OK mpi@ haesbaert@
Diffstat (limited to 'sys/netinet6/in6.h')
-rw-r--r--sys/netinet6/in6.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index 52d8ca97042..cc377ebd62a 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.h,v 1.63 2013/03/14 14:28:38 mpi Exp $ */
+/* $OpenBSD: in6.h,v 1.64 2013/03/28 15:05:32 bluhm Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
@@ -764,9 +764,34 @@ extern void in6_if_up(struct ifnet *);
void in6_get_rand_ifid(struct ifnet *, struct in6_addr *);
int in6_mask2len(struct in6_addr *, u_char *);
-#define satosin6(sa) ((struct sockaddr_in6 *)(sa))
-#define sin6tosa(sin6) ((struct sockaddr *)(sin6))
-#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
+struct sockaddr;
+struct sockaddr_in6;
+struct ifaddr;
+struct in6_ifaddr;
+
+/*
+ * Convert between address family specific and general structs.
+ * Inline functions check the source type and are stricter than
+ * casts or defines.
+ */
+
+static __inline struct sockaddr_in6 *
+satosin6(struct sockaddr *sa)
+{
+ return ((struct sockaddr_in6 *)(sa));
+}
+
+static __inline struct sockaddr *
+sin6tosa(struct sockaddr_in6 *sin6)
+{
+ return ((struct sockaddr *)(sin6));
+}
+
+static __inline struct in6_ifaddr *
+ifatoia6(struct ifaddr *ifa)
+{
+ return ((struct in6_ifaddr *)(ifa));
+}
#endif /* _KERNEL */
#if __BSD_VISIBLE