summaryrefslogtreecommitdiff
path: root/sys/netinet/in.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-05-04 15:00:25 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-05-04 15:00:25 +0000
commit7566c552e54be591cd5c3a70836b713a8da75698 (patch)
treea568cd9796fba6a3b2b906b3c9a85174e15890e0 /sys/netinet/in.c
parent0450d91d05ec91d21cddc13adeb254bf2a27044a (diff)
Introduce sstosa() for converting sockaddr_storage with a type safe
inline function instead of casting it to sockaddr. While there, use inline instead of __inline for all these conversions. Some struct sockaddr casts can be avoided completely. OK dhill@ mpi@
Diffstat (limited to 'sys/netinet/in.c')
-rw-r--r--sys/netinet/in.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index dfbc491ed26..7a20e768887 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.136 2017/03/27 09:38:03 rzalamena Exp $ */
+/* $OpenBSD: in.c,v 1.137 2017/05/04 15:00:24 bluhm Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -434,13 +434,13 @@ in_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
case SIOCALIFADDR:
case SIOCDLIFADDR:
/* address must be specified on ADD and DELETE */
- sa = (struct sockaddr *)&iflr->addr;
+ sa = sstosa(&iflr->addr);
if (sa->sa_family != AF_INET)
return EINVAL;
if (sa->sa_len != sizeof(struct sockaddr_in))
return EINVAL;
/* XXX need improvement */
- sa = (struct sockaddr *)&iflr->dstaddr;
+ sa = sstosa(&iflr->dstaddr);
if (sa->sa_family
&& sa->sa_family != AF_INET)
return EINVAL;
@@ -471,12 +471,11 @@ in_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
memcpy(ifra.ifra_name, iflr->iflr_name,
sizeof(ifra.ifra_name));
- memcpy(&ifra.ifra_addr, &iflr->addr,
- ((struct sockaddr *)&iflr->addr)->sa_len);
+ memcpy(&ifra.ifra_addr, &iflr->addr, iflr->addr.ss_len);
- if (((struct sockaddr *)&iflr->dstaddr)->sa_family) { /*XXX*/
+ if (iflr->dstaddr.ss_family) { /*XXX*/
memcpy(&ifra.ifra_dstaddr, &iflr->dstaddr,
- ((struct sockaddr *)&iflr->dstaddr)->sa_len);
+ iflr->dstaddr.ss_len);
}
ifra.ifra_mask.sin_family = AF_INET;