Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net - avoid non portable casts



details:   https://anonhg.NetBSD.org/src/rev/1602342d5311
branches:  trunk
changeset: 494385:1602342d5311
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 06 02:53:12 2000 +0000

description:
- avoid non portable casts
- cast arguments to avoid promotion warnings

diffstat:

 lib/libc/net/getifaddrs.c |  76 ++++++++++++++++++++++++----------------------
 1 files changed, 40 insertions(+), 36 deletions(-)

diffs (208 lines):

diff -r 39cb05500c92 -r 1602342d5311 lib/libc/net/getifaddrs.c
--- a/lib/libc/net/getifaddrs.c Thu Jul 06 02:52:07 2000 +0000
+++ b/lib/libc/net/getifaddrs.c Thu Jul 06 02:53:12 2000 +0000
@@ -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 <sys/cdefs.h>
 #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 @@
        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 @@
        }
 
        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 @@
                                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 @@
                                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 @@
                return(-1);
        }
 
-       ifa = (struct ifaddrs *)data;
+       ifa = (struct ifaddrs *)(void *)data;
        data += sizeof(struct ifaddrs) * icnt;
        names = data + dcnt;
 
@@ -238,28 +238,31 @@
        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 @@
 
                                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 @@
                                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 @@
 
                                case RTAX_BRD:
                                        ift->ifa_broadaddr =
-                                           (struct sockaddr *)data;
+                                           (struct sockaddr *)(void *)data;
                                        memcpy(data, p, len);
                                        data += len;
                                        break;



Home | Main Index | Thread Index | Old Index