Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net unifdef for auditability.



details:   https://anonhg.NetBSD.org/src/rev/b1d0178df1f4
branches:  trunk
changeset: 535051:b1d0178df1f4
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Aug 09 04:26:07 2002 +0000

description:
unifdef for auditability.

diffstat:

 lib/libc/net/getifaddrs.c |  120 +--------------------------------------------
 1 files changed, 5 insertions(+), 115 deletions(-)

diffs (245 lines):

diff -r f1c896c2ffc6 -r b1d0178df1f4 lib/libc/net/getifaddrs.c
--- a/lib/libc/net/getifaddrs.c Fri Aug 09 04:17:26 2002 +0000
+++ b/lib/libc/net/getifaddrs.c Fri Aug 09 04:26:07 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getifaddrs.c,v 1.8 2001/08/20 02:33:49 itojun Exp $    */
+/*     $NetBSD: getifaddrs.c,v 1.9 2002/08/09 04:26:07 itojun 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.8 2001/08/20 02:33:49 itojun Exp $");
+__RCSID("$NetBSD: getifaddrs.c,v 1.9 2002/08/09 04:26:07 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -35,12 +35,10 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#ifdef NET_RT_IFLIST
 #include <sys/param.h>
 #include <net/route.h>
 #include <sys/sysctl.h>
 #include <net/if_dl.h>
-#endif
 
 #include <assert.h>
 #include <errno.h>
@@ -53,48 +51,15 @@
 __weak_alias(freeifaddrs,_freeifaddrs)
 #endif
 
-#if !defined(AF_LINK)
-#define        SA_LEN(sa)      sizeof(struct sockaddr)
-#endif
-
-#if !defined(SA_LEN)
-#define        SA_LEN(sa)      (sa)->sa_len
-#endif
-
 #define        SALIGN  (sizeof(long) - 1)
 #define        SA_RLEN(sa)     ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1))
 
-#ifndef        ALIGNBYTES
-/*
- * On systems with a routing socket, ALIGNBYTES should match the value
- * that the kernel uses when building the messages.
- */
-#define        ALIGNBYTES      XXX
-#endif
-#ifndef        ALIGN
-#define        ALIGN(p)        (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-#endif
-
-#if    _BSDI_VERSION >= 199701
-#define        HAVE_IFM_DATA
-#endif
-
-#if    _BSDI_VERSION >= 199802
-/* ifam_data is very specific to recent versions of bsdi */
-#define        HAVE_IFAM_DATA
-#endif
-
-#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
-#define        HAVE_IFM_DATA
-#endif
-
 int
 getifaddrs(struct ifaddrs **pif)
 {
        int icnt = 1;
        int dcnt = 0;
        int ncnt = 0;
-#ifdef NET_RT_IFLIST
        int mib[6];
        size_t needed;
        char *buf;
@@ -108,13 +73,6 @@
        struct sockaddr *sa;
        struct ifaddrs *ifa, *ift;
        u_short idx = 0;
-#else  /* NET_RT_IFLIST */
-       char buf[1024];
-       int m, sock;
-       struct ifconf ifc;
-       struct ifreq *ifr;
-       struct ifreq *lifr;
-#endif /* NET_RT_IFLIST */
        int i;
        size_t len, alen;
        char *data;
@@ -122,7 +80,6 @@
 
        _DIAGASSERT(pif != NULL);
 
-#ifdef NET_RT_IFLIST
        mib[0] = CTL_NET;
        mib[1] = PF_ROUTE;
        mib[2] = 0;             /* protocol */
@@ -151,9 +108,7 @@
                                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
                                idx = 0;
@@ -169,9 +124,6 @@
                                break;
                        p = (char *)(void *)(ifam + 1);
                        ++icnt;
-#ifdef HAVE_IFAM_DATA
-                       dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES;
-#endif /* HAVE_IFAM_DATA */
                        /* Scan to look for length of address */
                        alen = 0;
                        for (p0 = p, i = 0; i < RTAX_MAX; i++) {
@@ -192,7 +144,7 @@
                                        continue;
                                sa = (struct sockaddr *)(void *)p;
                                len = SA_RLEN(sa);
-                               if (i == RTAX_NETMASK && SA_LEN(sa) == 0)
+                               if (i == RTAX_NETMASK && sa->sa_len == 0)
                                        dcnt += alen;
                                else
                                        dcnt += len;
@@ -201,34 +153,6 @@
                        break;
                }
        }
-#else  /* NET_RT_IFLIST */
-       ifc.ifc_buf = buf;
-       ifc.ifc_len = sizeof(buf);
-
-       if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
-               return (-1);
-       i =  ioctl(sock, SIOCGIFCONF, (char *)&ifc);
-       close(sock);
-       if (i < 0)
-               return (-1);
-
-       ifr = ifc.ifc_req;
-       lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
-
-       while (ifr < lifr) {
-               struct sockaddr *sa;
-
-               sa = &ifr->ifr_addr;
-               ++icnt;
-               dcnt += SA_RLEN(sa);
-               ncnt += sizeof(ifr->ifr_name) + 1;
-               
-               if (SA_LEN(sa) < sizeof(*sa))
-                       ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa));
-               else
-                       ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
-       }
-#endif /* NET_RT_IFLIST */
 
        if (icnt + dcnt + ncnt == 1) {
                *pif = NULL;
@@ -248,7 +172,6 @@
        memset(ifa, 0, sizeof(struct ifaddrs) * icnt);
        ift = ifa;
 
-#ifdef NET_RT_IFLIST
        idx = 0;
        for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
                rtm = (struct rt_msghdr *)(void *)next;
@@ -271,18 +194,13 @@
 
                                ift->ifa_addr = (struct sockaddr *)(void *)data;
                                memcpy(data, dl,
-                                   (size_t)SA_LEN((struct sockaddr *)
-                                   (void *)dl));
+                                   ((struct sockaddr *)(void *)dl)->sa_len);
                                data += SA_RLEN((struct sockaddr *)(void *)dl);
 
-#ifdef HAVE_IFM_DATA
                                /* ifm_data needs to be aligned */
                                ift->ifa_data = data = (void *)ALIGN(data);
                                memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data));
                                data += sizeof(ifm->ifm_data);
-#else  /* HAVE_IFM_DATA */
-                               ift->ifa_data = NULL;
-#endif /* HAVE_IFM_DATA */
 
                                ift = (ift->ifa_next = ift + 1);
                        } else
@@ -331,7 +249,7 @@
                                case RTAX_NETMASK:
                                        ift->ifa_netmask =
                                            (struct sockaddr *)(void *)data;
-                                       if (SA_LEN(sa) == 0) {
+                                       if (sa->sa_len == 0) {
                                                memset(data, 0, alen);
                                                data += alen;
                                                break;
@@ -350,12 +268,6 @@
                                p += len;
                        }
 
-#ifdef HAVE_IFAM_DATA
-                       /* ifam_data needs to be aligned */
-                       ift->ifa_data = data = (void *)ALIGN(data);
-                       memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data));
-                       data += sizeof(ifam->ifam_data);
-#endif /* HAVE_IFAM_DATA */
 
                        ift = (ift->ifa_next = ift + 1);
                        break;
@@ -363,28 +275,6 @@
        }
 
        free(buf);
-#else  /* NET_RT_IFLIST */
-       ifr = ifc.ifc_req;
-       lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
-
-       while (ifr < lifr) {
-               struct sockaddr *sa;
-
-               ift->ifa_name = names;
-               names[sizeof(ifr->ifr_name)] = 0;
-               strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name));
-               while (*names++)
-                       ;
-
-               ift->ifa_addr = (struct sockaddr *)data;
-               sa = &ifr->ifr_addr;
-               memcpy(data, sa, SA_LEN(sa));
-               data += SA_RLEN(sa);
-               
-               ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
-               ift = (ift->ifa_next = ift + 1);
-       }
-#endif /* NET_RT_IFLIST */
        if (--ift >= ifa) {
                ift->ifa_next = NULL;
                *pif = ifa;



Home | Main Index | Thread Index | Old Index