From b0c8c0de7dcb1accca1b4218ba74f96aa4bcd2da Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 6 Jul 2000 02:53:12 +0000 Subject: [PATCH] - avoid non portable casts - cast arguments to avoid promotion warnings --- lib/libc/net/getifaddrs.c | 76 ++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c index 765e1a83377d..d37a282017d7 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -1,4 +1,4 @@ -/* $NetBSD: getifaddrs.c,v 1.4 2000/04/24 10:40:25 itojun Exp $ */ +/* $NetBSD: getifaddrs.c,v 1.5 2000/07/06 02:53:12 christos Exp $ */ /* * Copyright (c) 1995, 1999 @@ -27,7 +27,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getifaddrs.c,v 1.4 2000/04/24 10:40:25 itojun Exp $"); +__RCSID("$NetBSD: getifaddrs.c,v 1.5 2000/07/06 02:53:12 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -101,7 +101,7 @@ getifaddrs(struct ifaddrs **pif) struct sockaddr_dl *dl; struct sockaddr *sa; struct ifaddrs *ifa, *ift; - u_short index = 0; + u_short idx = 0; #else /* NET_RT_IFLIST */ char buf[1024]; int m, sock; @@ -131,35 +131,35 @@ getifaddrs(struct ifaddrs **pif) } for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; + rtm = (struct rt_msghdr *)(void *)next; if (rtm->rtm_version != RTM_VERSION) continue; switch (rtm->rtm_type) { case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; + ifm = (struct if_msghdr *)(void *)rtm; if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; + idx = ifm->ifm_index; ++icnt; - dl = (struct sockaddr_dl *)(ifm + 1); - dcnt += SA_RLEN((struct sockaddr *)dl) + - ALIGNBYTES; + dl = (struct sockaddr_dl *)(void *)(ifm + 1); + dcnt += SA_RLEN((struct sockaddr *)(void*)dl) + + ALIGNBYTES; #ifdef HAVE_IFM_DATA dcnt += sizeof(ifm->ifm_data); #endif /* HAVE_IFM_DATA */ ncnt += dl->sdl_nlen + 1; } else - index = 0; + idx = 0; break; case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) + ifam = (struct ifa_msghdr *)(void *)rtm; + if (idx && ifam->ifam_index != idx) abort(); /* this cannot happen */ #define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) + if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) break; - p = (char *)(ifam + 1); + p = (char *)(void *)(ifam + 1); ++icnt; #ifdef HAVE_IFAM_DATA dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES; @@ -170,7 +170,7 @@ getifaddrs(struct ifaddrs **pif) if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) == 0) continue; - sa = (struct sockaddr *)p; + sa = (struct sockaddr *)(void *)p; len = SA_RLEN(sa); if (i == RTAX_IFA) { alen = len; @@ -182,7 +182,7 @@ getifaddrs(struct ifaddrs **pif) if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) == 0) continue; - sa = (struct sockaddr *)p; + sa = (struct sockaddr *)(void *)p; len = SA_RLEN(sa); if (i == RTAX_NETMASK && SA_LEN(sa) == 0) dcnt += alen; @@ -230,7 +230,7 @@ getifaddrs(struct ifaddrs **pif) return(-1); } - ifa = (struct ifaddrs *)data; + ifa = (struct ifaddrs *)(void *)data; data += sizeof(struct ifaddrs) * icnt; names = data + dcnt; @@ -238,28 +238,31 @@ getifaddrs(struct ifaddrs **pif) ift = ifa; #ifdef NET_RT_IFLIST - index = 0; + idx = 0; for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; + rtm = (struct rt_msghdr *)(void *)next; if (rtm->rtm_version != RTM_VERSION) continue; switch (rtm->rtm_type) { case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; + ifm = (struct if_msghdr *)(void *)rtm; if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - dl = (struct sockaddr_dl *)(ifm + 1); + idx = ifm->ifm_index; + dl = (struct sockaddr_dl *)(void *)(ifm + 1); cif = ift; ift->ifa_name = names; ift->ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, dl->sdl_nlen); + memcpy(names, dl->sdl_data, + (size_t)dl->sdl_nlen); names[dl->sdl_nlen] = 0; names += dl->sdl_nlen + 1; - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, dl, SA_LEN((struct sockaddr *)dl)); - data += SA_RLEN((struct sockaddr *)dl); + ift->ifa_addr = (struct sockaddr *)(void *)data; + memcpy(data, dl, + (size_t)SA_LEN((struct sockaddr *) + (void *)dl)); + data += SA_RLEN((struct sockaddr *)(void *)dl); #ifdef HAVE_IFM_DATA /* ifm_data needs to be aligned */ @@ -272,27 +275,27 @@ getifaddrs(struct ifaddrs **pif) ift = (ift->ifa_next = ift + 1); } else - index = 0; + idx = 0; break; case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) + ifam = (struct ifa_msghdr *)(void *)rtm; + if (idx && ifam->ifam_index != idx) abort(); /* this cannot happen */ - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) + if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) break; ift->ifa_name = cif->ifa_name; ift->ifa_flags = cif->ifa_flags; ift->ifa_data = NULL; - p = (char *)(ifam + 1); + p = (char *)(void *)(ifam + 1); /* Scan to look for length of address */ alen = 0; for (p0 = p, i = 0; i < RTAX_MAX; i++) { if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) == 0) continue; - sa = (struct sockaddr *)p; + sa = (struct sockaddr *)(void *)p; len = SA_RLEN(sa); if (i == RTAX_IFA) { alen = len; @@ -304,18 +307,19 @@ getifaddrs(struct ifaddrs **pif) if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) == 0) continue; - sa = (struct sockaddr *)p; + sa = (struct sockaddr *)(void *)p; len = SA_RLEN(sa); switch (i) { case RTAX_IFA: - ift->ifa_addr = (struct sockaddr *)data; + ift->ifa_addr = + (struct sockaddr *)(void *)data; memcpy(data, p, len); data += len; break; case RTAX_NETMASK: ift->ifa_netmask = - (struct sockaddr *)data; + (struct sockaddr *)(void *)data; if (SA_LEN(sa) == 0) { memset(data, 0, alen); data += alen; @@ -327,7 +331,7 @@ getifaddrs(struct ifaddrs **pif) case RTAX_BRD: ift->ifa_broadaddr = - (struct sockaddr *)data; + (struct sockaddr *)(void *)data; memcpy(data, p, len); data += len; break;