diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2013-03-28 15:05:33 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2013-03-28 15:05:33 +0000 |
commit | 074382f949295292cba8a708947bdfdd4cfb48c8 (patch) | |
tree | 88eee9238e6306eb5b6c6fc192db36d33cc6e66f /sys/netinet/in.h | |
parent | 9efd0f3534a333b6ec869aaadab31ddf7a7bbd21 (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/netinet/in.h')
-rw-r--r-- | sys/netinet/in.h | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 1a9053768a0..175129f9829 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.95 2012/10/21 13:06:03 benno Exp $ */ +/* $OpenBSD: in.h,v 1.96 2013/03/28 15:05:32 bluhm Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -844,8 +844,33 @@ void in_proto_cksum_out(struct mbuf *, struct ifnet *); #define in_hosteq(s,t) ((s).s_addr == (t).s_addr) #define in_nullhost(x) ((x).s_addr == INADDR_ANY) -#define satosin(sa) ((struct sockaddr_in *)(sa)) -#define sintosa(sin) ((struct sockaddr *)(sin)) -#define ifatoia(ifa) ((struct in_ifaddr *)(ifa)) +struct sockaddr; +struct sockaddr_in; +struct ifaddr; +struct in_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_in * +satosin(struct sockaddr *sa) +{ + return ((struct sockaddr_in *)(sa)); +} + +static __inline struct sockaddr * +sintosa(struct sockaddr_in *sin) +{ + return ((struct sockaddr *)(sin)); +} + +static __inline struct in_ifaddr * +ifatoia(struct ifaddr *ifa) +{ + return ((struct in_ifaddr *)(ifa)); +} #endif /* _KERNEL */ #endif /* _NETINET_IN_H_ */ |