diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/os_network.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/os_network.c')
-rw-r--r-- | src/util/os_network.c | 560 |
1 files changed, 279 insertions, 281 deletions
diff --git a/src/util/os_network.c b/src/util/os_network.c index 9008c5c5a..6bf9d1846 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c | |||
@@ -17,7 +17,7 @@ | |||
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | 19 | ||
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @file util/os_network.c | 22 | * @file util/os_network.c |
23 | * @brief function to determine available network interfaces | 23 | * @brief function to determine available network interfaces |
@@ -31,11 +31,11 @@ | |||
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | 32 | ||
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "util-os-network", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-os-network", __VA_ARGS__) |
35 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-network", syscall, filename) | 35 | #define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-os-network", syscall, filename) |
36 | 36 | ||
37 | 37 | ||
38 | #if ! (HAVE_GETIFADDRS && HAVE_FREEIFADDRS) && !MINGW | 38 | #if !(HAVE_GETIFADDRS && HAVE_FREEIFADDRS) && !MINGW |
39 | /** | 39 | /** |
40 | * Try to enumerate all network interfaces using 'ifconfig'. | 40 | * Try to enumerate all network interfaces using 'ifconfig'. |
41 | * | 41 | * |
@@ -44,8 +44,8 @@ | |||
44 | * @return #GNUNET_OK if it worked | 44 | * @return #GNUNET_OK if it worked |
45 | */ | 45 | */ |
46 | static int | 46 | static int |
47 | try_ifconfig (GNUNET_OS_NetworkInterfaceProcessor proc, | 47 | try_ifconfig(GNUNET_OS_NetworkInterfaceProcessor proc, |
48 | void *proc_cls) | 48 | void *proc_cls) |
49 | { | 49 | { |
50 | int i; | 50 | int i; |
51 | char line[1024]; | 51 | char line[1024]; |
@@ -70,159 +70,159 @@ try_ifconfig (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
70 | static char *pcall; | 70 | static char *pcall; |
71 | 71 | ||
72 | if (NULL == pcall) | 72 | if (NULL == pcall) |
73 | { | 73 | { |
74 | const char *sbin_ifconfig; | 74 | const char *sbin_ifconfig; |
75 | 75 | ||
76 | #ifdef IFCONFIG | 76 | #ifdef IFCONFIG |
77 | if (0 == access (IFCONFIG, X_OK)) | 77 | if (0 == access(IFCONFIG, X_OK)) |
78 | sbin_ifconfig = IFCONFIG; | 78 | sbin_ifconfig = IFCONFIG; |
79 | else | 79 | else |
80 | #endif | 80 | #endif |
81 | if (0 == access ("/sbin/ifconfig", X_OK)) | 81 | if (0 == access("/sbin/ifconfig", X_OK)) |
82 | sbin_ifconfig = "/sbin/ifconfig"; | 82 | sbin_ifconfig = "/sbin/ifconfig"; |
83 | else if (0 == access ("/usr/sbin/ifconfig", X_OK)) | 83 | else if (0 == access("/usr/sbin/ifconfig", X_OK)) |
84 | sbin_ifconfig = "/usr/sbin/ifconfig"; | 84 | sbin_ifconfig = "/usr/sbin/ifconfig"; |
85 | else | 85 | else |
86 | sbin_ifconfig = "ifconfig"; | 86 | sbin_ifconfig = "ifconfig"; |
87 | GNUNET_asprintf (&pcall, | 87 | GNUNET_asprintf(&pcall, |
88 | "%s -a 2> /dev/null", | 88 | "%s -a 2> /dev/null", |
89 | sbin_ifconfig); | 89 | sbin_ifconfig); |
90 | } | 90 | } |
91 | f = popen (pcall, "r"); | 91 | f = popen(pcall, "r"); |
92 | if (NULL == f) | 92 | if (NULL == f) |
93 | { | 93 | { |
94 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 94 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
95 | "popen", | 95 | "popen", |
96 | "ifconfig"); | 96 | "ifconfig"); |
97 | 97 | ||
98 | return GNUNET_SYSERR; | 98 | return GNUNET_SYSERR; |
99 | } | 99 | } |
100 | 100 | ||
101 | have_ifc = GNUNET_NO; | 101 | have_ifc = GNUNET_NO; |
102 | ifc[11] = '\0'; | 102 | ifc[11] = '\0'; |
103 | while (NULL != fgets (line, sizeof (line), f)) | 103 | while (NULL != fgets(line, sizeof(line), f)) |
104 | { | ||
105 | if (strlen (line) == 0) | ||
106 | { | 104 | { |
107 | have_ifc = GNUNET_NO; | 105 | if (strlen(line) == 0) |
108 | continue; | 106 | { |
109 | } | 107 | have_ifc = GNUNET_NO; |
110 | if (!isspace (line[0])) | 108 | continue; |
111 | { | 109 | } |
112 | have_ifc = (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; | 110 | if (!isspace(line[0])) |
113 | /* would end with ':' on OSX, fix it! */ | 111 | { |
114 | if (ifc[strlen (ifc) - 1] == ':') | 112 | have_ifc = (1 == SSCANF(line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; |
115 | ifc[strlen (ifc) - 1] = '\0'; | 113 | /* would end with ':' on OSX, fix it! */ |
116 | continue; | 114 | if (ifc[strlen(ifc) - 1] == ':') |
117 | } | 115 | ifc[strlen(ifc) - 1] = '\0'; |
118 | if (!have_ifc) | 116 | continue; |
119 | continue; /* strange input, hope for the best */ | 117 | } |
118 | if (!have_ifc) | ||
119 | continue; /* strange input, hope for the best */ | ||
120 | 120 | ||
121 | /* make parsing of ipv6 addresses easier */ | 121 | /* make parsing of ipv6 addresses easier */ |
122 | for (replace = line; *replace != '\0'; replace++) | 122 | for (replace = line; *replace != '\0'; replace++) |
123 | { | 123 | { |
124 | if (*replace == '/') | 124 | if (*replace == '/') |
125 | *replace = ' '; | 125 | *replace = ' '; |
126 | } | 126 | } |
127 | prefixlen = -1; | 127 | prefixlen = -1; |
128 | 128 | ||
129 | start = line; | 129 | start = line; |
130 | while (('\0' != *start) && (isspace (*start))) | 130 | while (('\0' != *start) && (isspace(*start))) |
131 | start++; | 131 | start++; |
132 | 132 | ||
133 | /* Zero-out stack allocated values */ | 133 | /* Zero-out stack allocated values */ |
134 | memset (addrstr, 0, 128); | 134 | memset(addrstr, 0, 128); |
135 | memset (netmaskstr, 0, 128); | 135 | memset(netmaskstr, 0, 128); |
136 | memset (bcstr, 0, 128); | 136 | memset(bcstr, 0, 128); |
137 | prefixlen = 0; | 137 | prefixlen = 0; |
138 | 138 | ||
139 | if ( /* Linux */ | 139 | if ( /* Linux */ |
140 | (3 == SSCANF (start, "inet addr:%127s Bcast:%127s Mask:%127s", addrstr, bcstr, netmaskstr)) || | 140 | (3 == SSCANF(start, "inet addr:%127s Bcast:%127s Mask:%127s", addrstr, bcstr, netmaskstr)) || |
141 | (2 == SSCANF (start, "inet addr:%127s Mask:%127s", addrstr, netmaskstr)) || | 141 | (2 == SSCANF(start, "inet addr:%127s Mask:%127s", addrstr, netmaskstr)) || |
142 | (2 == SSCANF (start, "inet6 addr:%127s %d", addrstr, &prefixlen)) || | 142 | (2 == SSCANF(start, "inet6 addr:%127s %d", addrstr, &prefixlen)) || |
143 | /* Solaris, OS X */ | 143 | /* Solaris, OS X */ |
144 | (1 == SSCANF (start, "inet %127s", addrstr)) || | 144 | (1 == SSCANF(start, "inet %127s", addrstr)) || |
145 | (1 == SSCANF (start, "inet6 %127s", addrstr))) | 145 | (1 == SSCANF(start, "inet6 %127s", addrstr))) |
146 | { | 146 | { |
147 | /* IPv4 */ | 147 | /* IPv4 */ |
148 | if (1 == inet_pton (AF_INET, addrstr, &v4)) | 148 | if (1 == inet_pton(AF_INET, addrstr, &v4)) |
149 | { | 149 | { |
150 | memset (&a4, 0, sizeof (a4)); | 150 | memset(&a4, 0, sizeof(a4)); |
151 | a4.sin_family = AF_INET; | 151 | a4.sin_family = AF_INET; |
152 | #if HAVE_SOCKADDR_IN_SIN_LEN | 152 | #if HAVE_SOCKADDR_IN_SIN_LEN |
153 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); | 153 | a4.sin_len = (u_char)sizeof(struct sockaddr_in); |
154 | #endif | 154 | #endif |
155 | a4.sin_addr = v4; | 155 | a4.sin_addr = v4; |
156 | 156 | ||
157 | pass_bcaddr = NULL; | 157 | pass_bcaddr = NULL; |
158 | pass_netmask = NULL; | 158 | pass_netmask = NULL; |
159 | if (1 == inet_pton (AF_INET, bcstr, &v4)) | 159 | if (1 == inet_pton(AF_INET, bcstr, &v4)) |
160 | { | 160 | { |
161 | memset (&bcaddr, 0, sizeof (bcaddr)); | 161 | memset(&bcaddr, 0, sizeof(bcaddr)); |
162 | bcaddr.sin_family = AF_INET; | 162 | bcaddr.sin_family = AF_INET; |
163 | #if HAVE_SOCKADDR_IN_SIN_LEN | 163 | #if HAVE_SOCKADDR_IN_SIN_LEN |
164 | bcaddr.sin_len = (u_char) sizeof (struct sockaddr_in); | 164 | bcaddr.sin_len = (u_char)sizeof(struct sockaddr_in); |
165 | #endif | 165 | #endif |
166 | bcaddr.sin_addr = v4; | 166 | bcaddr.sin_addr = v4; |
167 | pass_bcaddr = (struct sockaddr *) &bcaddr; | 167 | pass_bcaddr = (struct sockaddr *)&bcaddr; |
168 | } | 168 | } |
169 | if (1 == inet_pton (AF_INET, netmaskstr, &v4)) | 169 | if (1 == inet_pton(AF_INET, netmaskstr, &v4)) |
170 | { | 170 | { |
171 | memset (&netmask, 0, sizeof (netmask)); | 171 | memset(&netmask, 0, sizeof(netmask)); |
172 | netmask.sin_family = AF_INET; | 172 | netmask.sin_family = AF_INET; |
173 | #if HAVE_SOCKADDR_IN_SIN_LEN | 173 | #if HAVE_SOCKADDR_IN_SIN_LEN |
174 | netmask.sin_len = (u_char) sizeof (struct sockaddr_in); | 174 | netmask.sin_len = (u_char)sizeof(struct sockaddr_in); |
175 | #endif | 175 | #endif |
176 | netmask.sin_addr = v4; | 176 | netmask.sin_addr = v4; |
177 | pass_netmask = (struct sockaddr *) &netmask; | 177 | pass_netmask = (struct sockaddr *)&netmask; |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | if (GNUNET_OK != | 181 | if (GNUNET_OK != |
182 | proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | 182 | proc(proc_cls, ifc, 0 == strcmp(ifc, GNUNET_DEFAULT_INTERFACE), |
183 | (const struct sockaddr *) &a4, | 183 | (const struct sockaddr *)&a4, |
184 | pass_bcaddr, pass_netmask, sizeof (a4))) | 184 | pass_bcaddr, pass_netmask, sizeof(a4))) |
185 | break; | 185 | break; |
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | /* IPv6 */ | 188 | /* IPv6 */ |
189 | if (1 == inet_pton (AF_INET6, addrstr, &v6)) | 189 | if (1 == inet_pton(AF_INET6, addrstr, &v6)) |
190 | { | 190 | { |
191 | memset (&a6, 0, sizeof (a6)); | 191 | memset(&a6, 0, sizeof(a6)); |
192 | a6.sin6_family = AF_INET6; | 192 | a6.sin6_family = AF_INET6; |
193 | #if HAVE_SOCKADDR_IN_SIN_LEN | 193 | #if HAVE_SOCKADDR_IN_SIN_LEN |
194 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 194 | a6.sin6_len = (u_char)sizeof(struct sockaddr_in6); |
195 | #endif | 195 | #endif |
196 | a6.sin6_addr = v6; | 196 | a6.sin6_addr = v6; |
197 | 197 | ||
198 | pass_netmask = NULL; | 198 | pass_netmask = NULL; |
199 | if (prefixlen != -1) | 199 | if (prefixlen != -1) |
200 | { | 200 | { |
201 | memset (v6.s6_addr, 0, sizeof (v6.s6_addr)); | 201 | memset(v6.s6_addr, 0, sizeof(v6.s6_addr)); |
202 | for (i = 0; i < prefixlen; i++) | 202 | for (i = 0; i < prefixlen; i++) |
203 | { | 203 | { |
204 | v6.s6_addr[i >> 3] |= 1 << (i & 7); | 204 | v6.s6_addr[i >> 3] |= 1 << (i & 7); |
205 | } | 205 | } |
206 | memset (&netmask6, 0, sizeof (netmask6)); | 206 | memset(&netmask6, 0, sizeof(netmask6)); |
207 | netmask6.sin6_family = AF_INET6; | 207 | netmask6.sin6_family = AF_INET6; |
208 | #if HAVE_SOCKADDR_IN_SIN_LEN | 208 | #if HAVE_SOCKADDR_IN_SIN_LEN |
209 | netmask6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 209 | netmask6.sin6_len = (u_char)sizeof(struct sockaddr_in6); |
210 | #endif | 210 | #endif |
211 | netmask6.sin6_addr = v6; | 211 | netmask6.sin6_addr = v6; |
212 | 212 | ||
213 | pass_netmask = (struct sockaddr *) &netmask6; | 213 | pass_netmask = (struct sockaddr *)&netmask6; |
214 | } | ||
215 | |||
216 | if (GNUNET_OK != | ||
217 | proc(proc_cls, ifc, 0 == strcmp(ifc, GNUNET_DEFAULT_INTERFACE), | ||
218 | (const struct sockaddr *)&a6, | ||
219 | NULL, pass_netmask, sizeof(a6))) | ||
220 | break; | ||
221 | continue; | ||
222 | } | ||
214 | } | 223 | } |
215 | |||
216 | if (GNUNET_OK != | ||
217 | proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | ||
218 | (const struct sockaddr *) &a6, | ||
219 | NULL, pass_netmask, sizeof (a6))) | ||
220 | break; | ||
221 | continue; | ||
222 | } | ||
223 | } | 224 | } |
224 | } | 225 | pclose(f); |
225 | pclose (f); | ||
226 | return GNUNET_OK; | 226 | return GNUNET_OK; |
227 | } | 227 | } |
228 | 228 | ||
@@ -235,8 +235,8 @@ try_ifconfig (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
235 | * @return #GNUNET_OK if it worked | 235 | * @return #GNUNET_OK if it worked |
236 | */ | 236 | */ |
237 | static int | 237 | static int |
238 | try_ip (GNUNET_OS_NetworkInterfaceProcessor proc, | 238 | try_ip(GNUNET_OS_NetworkInterfaceProcessor proc, |
239 | void *proc_cls) | 239 | void *proc_cls) |
240 | { | 240 | { |
241 | char line[1024]; | 241 | char line[1024]; |
242 | char *replace; | 242 | char *replace; |
@@ -255,124 +255,124 @@ try_ip (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
255 | static char *pcall; | 255 | static char *pcall; |
256 | 256 | ||
257 | if (NULL == pcall) | 257 | if (NULL == pcall) |
258 | { | 258 | { |
259 | const char *sbin_ip; | 259 | const char *sbin_ip; |
260 | 260 | ||
261 | #ifdef IFCONFIG | 261 | #ifdef IFCONFIG |
262 | if (0 == access (PATH_TO_IP, X_OK)) | 262 | if (0 == access(PATH_TO_IP, X_OK)) |
263 | sbin_ip = PATH_TO_IP; | 263 | sbin_ip = PATH_TO_IP; |
264 | else | 264 | else |
265 | #endif | 265 | #endif |
266 | if (0 == access ("/sbin/ip", X_OK)) | 266 | if (0 == access("/sbin/ip", X_OK)) |
267 | sbin_ip = "/sbin/ip"; | 267 | sbin_ip = "/sbin/ip"; |
268 | else if (0 == access ("/usr/sbin/ip", X_OK)) | 268 | else if (0 == access("/usr/sbin/ip", X_OK)) |
269 | sbin_ip = "/usr/sbin/ip"; | 269 | sbin_ip = "/usr/sbin/ip"; |
270 | else | 270 | else |
271 | sbin_ip = "if"; | 271 | sbin_ip = "if"; |
272 | GNUNET_asprintf (&pcall, | 272 | GNUNET_asprintf(&pcall, |
273 | "%s -o add 2> /dev/null", | 273 | "%s -o add 2> /dev/null", |
274 | sbin_ip); | 274 | sbin_ip); |
275 | } | 275 | } |
276 | f = popen (pcall, "r"); | 276 | f = popen(pcall, "r"); |
277 | if (! f) | 277 | if (!f) |
278 | { | ||
279 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
280 | "popen", | ||
281 | "ip"); | ||
282 | return GNUNET_SYSERR; | ||
283 | } | ||
284 | |||
285 | while (NULL != fgets (line, sizeof (line), f)) | ||
286 | { | ||
287 | /* make parsing easier */ | ||
288 | for (replace = line; *replace != '\0'; replace++) | ||
289 | { | 278 | { |
290 | if (*replace == '/') | 279 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
291 | *replace = ' '; | 280 | "popen", |
281 | "ip"); | ||
282 | return GNUNET_SYSERR; | ||
292 | } | 283 | } |
293 | /* Zero-out stack allocated values */ | 284 | |
294 | memset (ifname, 0, 64); | 285 | while (NULL != fgets(line, sizeof(line), f)) |
295 | memset (afstr, 0, 6); | 286 | { |
296 | memset (addrstr, 0, 128); | 287 | /* make parsing easier */ |
297 | if (4 != SSCANF (line, | 288 | for (replace = line; *replace != '\0'; replace++) |
298 | "%*u: %63s %5s %127s %6u", | 289 | { |
299 | ifname, | 290 | if (*replace == '/') |
300 | afstr, | 291 | *replace = ' '; |
301 | addrstr, | 292 | } |
302 | &prefixlen)) | 293 | /* Zero-out stack allocated values */ |
303 | continue; | 294 | memset(ifname, 0, 64); |
304 | /* IPv4 */ | 295 | memset(afstr, 0, 6); |
305 | if ( (0 == strcasecmp ("inet", | 296 | memset(addrstr, 0, 128); |
297 | if (4 != SSCANF(line, | ||
298 | "%*u: %63s %5s %127s %6u", | ||
299 | ifname, | ||
300 | afstr, | ||
301 | addrstr, | ||
302 | &prefixlen)) | ||
303 | continue; | ||
304 | /* IPv4 */ | ||
305 | if ((0 == strcasecmp("inet", | ||
306 | afstr)) && | 306 | afstr)) && |
307 | (1 == inet_pton (AF_INET, | 307 | (1 == inet_pton(AF_INET, |
308 | addrstr, | 308 | addrstr, |
309 | &v4)) ) | 309 | &v4))) |
310 | { | 310 | { |
311 | memset (&a4, 0, sizeof (a4)); | 311 | memset(&a4, 0, sizeof(a4)); |
312 | a4.sin_family = AF_INET; | 312 | a4.sin_family = AF_INET; |
313 | #if HAVE_SOCKADDR_IN_SIN_LEN | 313 | #if HAVE_SOCKADDR_IN_SIN_LEN |
314 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); | 314 | a4.sin_len = (u_char)sizeof(struct sockaddr_in); |
315 | #endif | 315 | #endif |
316 | a4.sin_addr = v4; | 316 | a4.sin_addr = v4; |
317 | 317 | ||
318 | memset (&v4.s_addr, 0, sizeof (v4.s_addr)); | 318 | memset(&v4.s_addr, 0, sizeof(v4.s_addr)); |
319 | for (i = 0; i < prefixlen; i++) | 319 | for (i = 0; i < prefixlen; i++) |
320 | v4.s_addr |= 1 << (i & 7); | 320 | v4.s_addr |= 1 << (i & 7); |
321 | memset (&netmask, 0, sizeof (netmask)); | 321 | memset(&netmask, 0, sizeof(netmask)); |
322 | netmask.sin_family = AF_INET; | 322 | netmask.sin_family = AF_INET; |
323 | #if HAVE_SOCKADDR_IN_SIN_LEN | 323 | #if HAVE_SOCKADDR_IN_SIN_LEN |
324 | netmask.sin_len = (u_char) sizeof (struct sockaddr_in); | 324 | netmask.sin_len = (u_char)sizeof(struct sockaddr_in); |
325 | #endif | 325 | #endif |
326 | netmask.sin_addr = v4; | 326 | netmask.sin_addr = v4; |
327 | 327 | ||
328 | if (GNUNET_OK != | 328 | if (GNUNET_OK != |
329 | proc (proc_cls, | 329 | proc(proc_cls, |
330 | ifname, | 330 | ifname, |
331 | (0 == strcmp (ifname, | 331 | (0 == strcmp(ifname, |
332 | GNUNET_DEFAULT_INTERFACE)), | 332 | GNUNET_DEFAULT_INTERFACE)), |
333 | (const struct sockaddr *) &a4, | 333 | (const struct sockaddr *)&a4, |
334 | NULL, | 334 | NULL, |
335 | (const struct sockaddr *) &netmask, | 335 | (const struct sockaddr *)&netmask, |
336 | sizeof (a4))) | 336 | sizeof(a4))) |
337 | break; | 337 | break; |
338 | } | 338 | } |
339 | /* IPv6 */ | 339 | /* IPv6 */ |
340 | if ( (0 == strcasecmp ("inet6", | 340 | if ((0 == strcasecmp("inet6", |
341 | afstr)) && | 341 | afstr)) && |
342 | (1 == inet_pton (AF_INET6, | 342 | (1 == inet_pton(AF_INET6, |
343 | addrstr, | 343 | addrstr, |
344 | &v6)) ) | 344 | &v6))) |
345 | { | 345 | { |
346 | memset (&a6, 0, sizeof (a6)); | 346 | memset(&a6, 0, sizeof(a6)); |
347 | a6.sin6_family = AF_INET6; | 347 | a6.sin6_family = AF_INET6; |
348 | #if HAVE_SOCKADDR_IN_SIN_LEN | 348 | #if HAVE_SOCKADDR_IN_SIN_LEN |
349 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 349 | a6.sin6_len = (u_char)sizeof(struct sockaddr_in6); |
350 | #endif | 350 | #endif |
351 | a6.sin6_addr = v6; | 351 | a6.sin6_addr = v6; |
352 | 352 | ||
353 | memset (v6.s6_addr, 0, sizeof (v6.s6_addr)); | 353 | memset(v6.s6_addr, 0, sizeof(v6.s6_addr)); |
354 | for (i = 0; i < prefixlen; i++) | 354 | for (i = 0; i < prefixlen; i++) |
355 | v6.s6_addr[i >> 3] |= 1 << (i & 7); | 355 | v6.s6_addr[i >> 3] |= 1 << (i & 7); |
356 | memset (&netmask6, 0, sizeof (netmask6)); | 356 | memset(&netmask6, 0, sizeof(netmask6)); |
357 | netmask6.sin6_family = AF_INET6; | 357 | netmask6.sin6_family = AF_INET6; |
358 | #if HAVE_SOCKADDR_IN_SIN_LEN | 358 | #if HAVE_SOCKADDR_IN_SIN_LEN |
359 | netmask6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 359 | netmask6.sin6_len = (u_char)sizeof(struct sockaddr_in6); |
360 | #endif | 360 | #endif |
361 | netmask6.sin6_addr = v6; | 361 | netmask6.sin6_addr = v6; |
362 | 362 | ||
363 | if (GNUNET_OK != | 363 | if (GNUNET_OK != |
364 | proc (proc_cls, | 364 | proc(proc_cls, |
365 | ifname, | 365 | ifname, |
366 | (0 == strcmp (ifname, | 366 | (0 == strcmp(ifname, |
367 | GNUNET_DEFAULT_INTERFACE)), | 367 | GNUNET_DEFAULT_INTERFACE)), |
368 | (const struct sockaddr *) &a6, | 368 | (const struct sockaddr *)&a6, |
369 | NULL, | 369 | NULL, |
370 | (const struct sockaddr *) &netmask6, | 370 | (const struct sockaddr *)&netmask6, |
371 | sizeof (a6))) | 371 | sizeof(a6))) |
372 | break; | 372 | break; |
373 | } | ||
373 | } | 374 | } |
374 | } | 375 | pclose(f); |
375 | pclose (f); | ||
376 | return GNUNET_OK; | 376 | return GNUNET_OK; |
377 | } | 377 | } |
378 | #endif | 378 | #endif |
@@ -385,8 +385,8 @@ try_ip (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
385 | * @param proc_cls closure for @a proc | 385 | * @param proc_cls closure for @a proc |
386 | */ | 386 | */ |
387 | void | 387 | void |
388 | GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | 388 | GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, |
389 | void *proc_cls) | 389 | void *proc_cls) |
390 | { | 390 | { |
391 | #ifdef MINGW | 391 | #ifdef MINGW |
392 | int r; | 392 | int r; |
@@ -394,67 +394,65 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
394 | struct EnumNICs3_results *results = NULL; | 394 | struct EnumNICs3_results *results = NULL; |
395 | int results_count; | 395 | int results_count; |
396 | 396 | ||
397 | r = EnumNICs3 (&results, &results_count); | 397 | r = EnumNICs3(&results, &results_count); |
398 | if (r != GNUNET_OK) | 398 | if (r != GNUNET_OK) |
399 | return; | 399 | return; |
400 | 400 | ||
401 | for (i = 0; i < results_count; i++) | 401 | for (i = 0; i < results_count; i++) |
402 | { | 402 | { |
403 | if (GNUNET_OK != | 403 | if (GNUNET_OK != |
404 | proc (proc_cls, results[i].pretty_name, results[i].is_default, | 404 | proc(proc_cls, results[i].pretty_name, results[i].is_default, |
405 | (const struct sockaddr *) &results[i].address, | 405 | (const struct sockaddr *)&results[i].address, |
406 | results[i]. | 406 | results[i]. |
407 | flags & ENUMNICS3_BCAST_OK ? | 407 | flags & ENUMNICS3_BCAST_OK ? |
408 | (const struct sockaddr *) &results[i].broadcast : NULL, | 408 | (const struct sockaddr *)&results[i].broadcast : NULL, |
409 | results[i].flags & ENUMNICS3_MASK_OK ? | 409 | results[i].flags & ENUMNICS3_MASK_OK ? |
410 | (const struct sockaddr *) &results[i].mask : NULL, | 410 | (const struct sockaddr *)&results[i].mask : NULL, |
411 | results[i].addr_size)) | 411 | results[i].addr_size)) |
412 | break; | 412 | break; |
413 | } | 413 | } |
414 | EnumNICs3_free (results); | 414 | EnumNICs3_free(results); |
415 | return; | 415 | return; |
416 | |||
417 | #elif HAVE_GETIFADDRS && HAVE_FREEIFADDRS | 416 | #elif HAVE_GETIFADDRS && HAVE_FREEIFADDRS |
418 | |||
419 | struct ifaddrs *ifa_first; | 417 | struct ifaddrs *ifa_first; |
420 | struct ifaddrs *ifa_ptr; | 418 | struct ifaddrs *ifa_ptr; |
421 | socklen_t alen; | 419 | socklen_t alen; |
422 | 420 | ||
423 | if (getifaddrs (&ifa_first) == 0) | 421 | if (getifaddrs(&ifa_first) == 0) |
424 | { | ||
425 | for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) | ||
426 | { | 422 | { |
427 | if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL && | 423 | for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) |
428 | (ifa_ptr->ifa_flags & IFF_UP) != 0) | 424 | { |
429 | { | 425 | if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL && |
430 | if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && | 426 | (ifa_ptr->ifa_flags & IFF_UP) != 0) |
431 | (ifa_ptr->ifa_addr->sa_family != AF_INET6)) | 427 | { |
432 | continue; | 428 | if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && |
433 | if (ifa_ptr->ifa_addr->sa_family == AF_INET) | 429 | (ifa_ptr->ifa_addr->sa_family != AF_INET6)) |
434 | alen = sizeof (struct sockaddr_in); | 430 | continue; |
435 | else | 431 | if (ifa_ptr->ifa_addr->sa_family == AF_INET) |
436 | alen = sizeof (struct sockaddr_in6); | 432 | alen = sizeof(struct sockaddr_in); |
437 | if (GNUNET_OK != | 433 | else |
438 | proc (proc_cls, ifa_ptr->ifa_name, | 434 | alen = sizeof(struct sockaddr_in6); |
439 | 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE), | 435 | if (GNUNET_OK != |
440 | ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr, | 436 | proc(proc_cls, ifa_ptr->ifa_name, |
441 | ifa_ptr->ifa_netmask, alen)) | 437 | 0 == strcmp(ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE), |
442 | break; | 438 | ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr, |
443 | } | 439 | ifa_ptr->ifa_netmask, alen)) |
440 | break; | ||
441 | } | ||
442 | } | ||
443 | freeifaddrs(ifa_first); | ||
444 | } | 444 | } |
445 | freeifaddrs (ifa_first); | ||
446 | } | ||
447 | #else | 445 | #else |
448 | if (GNUNET_OK == | 446 | if (GNUNET_OK == |
449 | try_ip (proc, | 447 | try_ip(proc, |
450 | proc_cls)) | 448 | proc_cls)) |
451 | return; | 449 | return; |
452 | if (GNUNET_OK == | 450 | if (GNUNET_OK == |
453 | try_ifconfig (proc, | 451 | try_ifconfig(proc, |
454 | proc_cls)) | 452 | proc_cls)) |
455 | return; | 453 | return; |
456 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 454 | LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
457 | "Failed to enumerate network interfaces\n"); | 455 | "Failed to enumerate network interfaces\n"); |
458 | #endif | 456 | #endif |
459 | } | 457 | } |
460 | 458 | ||