]> Pileus Git - ~andy/fetchmail/blobdiff - interface.c
Attempt merging from 6.3.24.
[~andy/fetchmail] / interface.c
index c9a5db01345d29a0b18b4afa7c91d6a18dee1b31..f9445cb8aba1a01948dc50beb25aed0445146ae3 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
-#if defined(STDC_HEADERS)
 #include <stdlib.h>
-#endif
-#if defined(HAVE_UNISTD_H)
 #include <unistd.h>
-#endif
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <net/if.h>
 #if defined(__FreeBSD__)
 #if defined __FreeBSD_USE_KVM
-#if __FreeBSD_version >= 300001
 #include <net/if_var.h>
-#endif
 #include <kvm.h>
 #include <nlist.h>
 #include <sys/fcntl.h>
-#else
+#else /* !defined __FreeBSD_USE_KVM */
 #include <sys/sysctl.h>
 #include <net/route.h>
 #include <net/if_dl.h>
-#endif
-#endif
+#endif /* defined __FreeBSD_USE_KVM */
+#endif /* defined __FreeBSD__ */
 #include "socket.h"
-#include "i18n.h"
+#include "gettext.h"
 #include "tunable.h"
 
 typedef struct {
@@ -74,7 +68,7 @@ struct interface_pair_s {
 #ifdef linux
 #define have_interface_init
 
-static char *netdevfmt;
+static const char *netdevfmt;
 
 void interface_init(void)
 /* figure out which /proc/net/dev format to use */
@@ -173,13 +167,13 @@ static int get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
                result = FALSE;
        else
        {
-           char        *sp = strchr(ifname, '/');
+           char *tmp = xstrdup(ifname);
+           char *sp = strchr(tmp, '/');
            /* hide slash and trailing info from ifname */
            if (sp)
                *sp = '\0';
-           result = _get_ifinfoGT_(socket_fd, stats_file, ifname, ifinfo);
-           if (sp)
-               *sp = '/';
+           result = _get_ifinfoGT_(socket_fd, stats_file, tmp, ifinfo);
+           free(tmp);
        }
        if (socket_fd >= 0)
            SockClose(socket_fd);
@@ -231,14 +225,11 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
        char                    iname[16];
        struct ifnet            ifnet;
        unsigned long           ifnet_addr = ifnet_savedaddr;
-#if __FreeBSD_version >= 300001
        struct ifnethead        ifnethead;
        struct ifaddrhead       ifaddrhead;
-#endif
        struct ifaddr           ifaddr;
        unsigned long           ifaddr_addr;
        struct sockaddr         sa;
-       unsigned long           sa_addr;
        uint                    i;
        
        if (if_egid)
@@ -260,18 +251,14 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
                }
        }
 
-#if __FreeBSD_version >= 300001
        kvm_read(kvmfd, ifnet_savedaddr, (char *) &ifnethead, sizeof ifnethead);
        ifnet_addr = (u_long) ifnethead.tqh_first;
-#else
-       ifnet_addr = ifnet_savedaddr;
-#endif
 
        while (ifnet_addr)
        {
                kvm_read(kvmfd, ifnet_addr, &ifnet, sizeof(ifnet));
                kvm_read(kvmfd, (unsigned long) ifnet.if_name, tname, sizeof tname);
-               snprintf(tname, sizeof tname, "%s%d", tname, ifnet.if_unit);
+               snprintf(tname + strlen(tname), sizeof(tname) - strlen(tname), "%d", ifnet.if_unit);
 
                if (!strcmp(tname, iname))
                {
@@ -285,11 +272,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
                        ifinfo->rx_packets = ifnet.if_ipackets;
                        ifinfo->tx_packets = ifnet.if_opackets;
 
-#if __FreeBSD_version >= 300001
                        ifaddr_addr = (u_long) ifnet.if_addrhead.tqh_first;
-#else
-                       ifaddr_addr = (u_long) ifnet.if_addrlist;
-#endif
                        
                        while(ifaddr_addr)
                        {
@@ -298,11 +281,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
                                
                                if (sa.sa_family != AF_INET)
                                {
-#if __FreeBSD_version >= 300001
                                        ifaddr_addr = (u_long) ifaddr.ifa_link.tqe_next;
-#else
-                                       ifaddr_addr = (u_long) ifaddr.ifa_next;
-#endif
                                        continue;
                                }
                        
@@ -324,11 +303,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
                        return 0;
                }
 
-#if __FreeBSD_version >= 300001
                ifnet_addr = (u_long) ifnet.if_link.tqe_next;
-#else
-               ifnet_addr = (unsigned long) ifnet.if_next;
-#endif
        }
 
        if (if_egid)
@@ -384,7 +359,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
     char               iname[16];
     int                        mib[6];
 
-    memset(ifinfo, 0, sizeof(ifinfo));
+    memset(ifinfo, 0, sizeof(*ifinfo));
 
     /* trim interface name */
 
@@ -418,7 +393,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
            GT_("get_ifinfo: sysctl (iflist estimate) failed"));
        exit(1);
     }
-    if ((buf = malloc(needed)) == NULL)
+    if ((buf = (char *)malloc(needed)) == NULL)
     {
        report(stderr, 
            GT_("get_ifinfo: malloc failed"));
@@ -514,7 +489,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
            }
 
            sin = (struct sockaddr_in *)info.rti_info[RTAX_NETMASK];
-           if (!sin)
+           if (sin)
            {
                ifinfo->netmask = sin->sin_addr;
            }
@@ -524,7 +499,7 @@ get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
             * of non point-to-point link
             */
            sin = (struct sockaddr_in *)info.rti_info[RTAX_BRD];
-           if (!sin)
+           if (sin)
            {
                ifinfo->dstaddr = sin->sin_addr;
            }
@@ -579,6 +554,7 @@ void interface_parse(char *buf, struct hostdata *hp)
 /* parse 'interface' specification */
 {
        char *cp1, *cp2;
+       char mask1[] = "255.255.255.255";
 
        hp->interface = xstrdup(buf);
 
@@ -593,7 +569,7 @@ void interface_parse(char *buf, struct hostdata *hp)
 
        /* find and isolate just the netmask */
        if (!(cp2 = strchr(cp1, '/')))
-               cp2 = "255.255.255.255";
+               cp2 = mask1;
        else
                *cp2++ = '\000';
 
@@ -736,5 +712,5 @@ int interface_approve(struct hostdata *hp, flag domonitor)
 #endif /* CAN_MONITOR */
 
 #ifndef have_interface_init
-void interface_init(void) {};
+void interface_init(void) {}
 #endif