summaryrefslogtreecommitdiff
path: root/devel/ptlib/patches/patch-ah
blob: b74d1e8cac4bf92e4c7185b9fba1b7a2e38e068c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
$NetBSD: patch-ah,v 1.1.1.1 2008/09/12 13:18:26 jmcneill Exp $

--- src/ptlib/unix/socket.cxx.orig	2008-09-12 08:46:26.000000000 -0400
+++ src/ptlib/unix/socket.cxx	2008-09-12 08:57:49.000000000 -0400
@@ -67,6 +67,10 @@
 #include <netinet/if_ether.h>
 #endif
 
+#if defined(P_NETBSD)
+#include <ifaddrs.h>
+#endif
+
 #define ROUNDUP(a) \
         ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
 
@@ -462,6 +466,12 @@
   PBYTEArray buffer;
   struct ifconf ifConf;
 
+#if defined(P_NETBSD)
+  struct ifaddrs *ifap, *ifa;
+
+  PAssert(getifaddrs(&ifap) == 0, "getifaddrs failed");
+  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+#else
 #ifdef SIOCGIFNUM
   int ifNum;
   PAssert(::ioctl(sock.GetHandle(), SIOCGIFNUM, &ifNum) >= 0, "could not do ioctl for ifNum");
@@ -477,8 +487,14 @@
     ifreq * ifName = ifConf.ifc_req;
 
     while (ifName < ifEndList) {
+#endif
       struct ifreq ifReq;
+#if !defined(P_NETBSD)
       memcpy(&ifReq, ifName, sizeof(ifreq));
+#else
+      memset(&ifReq, 0, sizeof(ifReq));
+      strncpy(ifReq.ifr_name, ifa->ifa_name, sizeof(ifReq.ifr_name) - 1);
+#endif
       
       if (ioctl(sock.GetHandle(), SIOCGIFFLAGS, &ifReq) >= 0) {
         int flags = ifReq.ifr_flags;
@@ -490,14 +506,16 @@
         }
       }
       
-#if defined(P_FREEBSD) || defined(P_OPENBSD) || defined(P_NETBSD) || defined(P_MACOSX) || defined(P_VXWORKS) || defined(P_RTEMS) || defined(P_QNX)
+#if defined(P_FREEBSD) || defined(P_OPENBSD) || defined(P_MACOSX) || defined(P_VXWORKS) || defined(P_RTEMS) || defined(P_QNX)
       // move the ifName pointer along to the next ifreq entry
       ifName = (struct ifreq *)((char *)ifName + _SIZEOF_ADDR_IFREQ(*ifName));
-#else
+#elif !defined(P_NETBSD)
       ifName++;
 #endif
     }
+#if !defined(P_NETBSD)
   }
+#endif
   
   return PFalse;
 }
@@ -1554,7 +1572,13 @@
   PBYTEArray buffer;
   struct ifconf ifConf;
   
+#if defined(P_NETBSD)
+  struct ifaddrs *ifap, *ifa;
+
+  PAssert(getifaddrs(&ifap) == 0, "getifaddrs failed");
 
+  for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+#else
   // HERE
 #if defined(SIOCGIFNUM)
   int ifNum;
@@ -1570,9 +1594,14 @@
     void * ifEndList = (char *)ifConf.ifc_req + ifConf.ifc_len;
     ifreq * ifName = ifConf.ifc_req;
     while (ifName < ifEndList) {
-
+#endif
       struct ifreq ifReq;
+#if !defined(P_NETBSD)
       memcpy(&ifReq, ifName, sizeof(ifreq));
+#else
+      memset(&ifReq, 0, sizeof(ifReq));
+      strncpy(ifReq.ifr_name, ifa->ifa_name, sizeof(ifReq.ifr_name) - 1);
+#endif
 
       if (ioctl(sock.GetHandle(), SIOCGIFFLAGS, &ifReq) >= 0) {
         int flags = ifReq.ifr_flags;
@@ -1588,13 +1617,23 @@
           }
 #endif
 
+#if defined(P_NETBSD)
+          memset(&ifReq, 0, sizeof(ifReq));
+          strncpy(ifReq.ifr_name, ifa->ifa_name, sizeof(ifReq.ifr_name) - 1);
+#else
           memcpy(&ifReq, ifName, sizeof(ifreq));
+#endif
           if (ioctl(sock.GetHandle(), SIOCGIFADDR, &ifReq) >= 0) {
 
             sockaddr_in * sin = (sockaddr_in *)&ifReq.ifr_addr;
             PIPSocket::Address addr = sin->sin_addr;
 
+#if defined(P_NETBSD)
+            memset(&ifReq, 0, sizeof(ifReq));
+            strncpy(ifReq.ifr_name, ifa->ifa_name, sizeof(ifReq.ifr_name) - 1);
+#else
             memcpy(&ifReq, ifName, sizeof(ifreq));
+#endif
             if (ioctl(sock.GetHandle(), SIOCGIFNETMASK, &ifReq) >= 0) {
               PIPSocket::Address mask = 
 #ifndef __BEOS__
@@ -1632,15 +1671,17 @@
         }
       }
 
-#if defined(P_FREEBSD) || defined(P_OPENBSD) || defined(P_NETBSD) || defined(P_MACOSX) || defined(P_VXWORKS) || defined(P_RTEMS) || defined(P_QNX)
+#if defined(P_FREEBSD) || defined(P_OPENBSD) || defined(P_MACOSX) || defined(P_VXWORKS) || defined(P_RTEMS) || defined(P_QNX)
       // move the ifName pointer along to the next ifreq entry
       ifName = (struct ifreq *)((char *)ifName + _SIZEOF_ADDR_IFREQ(*ifName));
-#else
+#elif !defined(P_NETBSD)
       ifName++;
 #endif
 
     }
+#if !defined(P_NETBSD)
   }
+#endif
   return PTrue;
 }