Debian Codegraph @

Xpjproject/pjlib/src/pj/ip_helper_generic.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #include <pj/ip_helper.h>
20 #include <pj/addr_resolv.h>
21 #include <pj/assert.h>
22 #include <pj/errno.h>
23 #include <pj/string.h>
24 #include <pj/compat/socket.h>
25 #include <pj/sock.h>
26
27
28 #if defined(PJ_LINUX) && PJ_LINUX!=0
29 /* The following headers are used to get DEPRECATED addresses */
30 #include <arpa/inet.h>
31 #include <asm/types.h>
32 #include <linux/netlink.h>
33 #include <linux/rtnetlink.h>
34 #include <sys/socket.h>
35 #include <unistd.h>
36 #endif
37
38 /* Set to 1 to enable tracing */
39 #if 0
40 # include <pj/log.h>
41 # define THIS_FILE "ip_helper_generic.c"
42 # define TRACE_(exp) PJ_LOG(5,exp)
43 static const char *get_os_errmsg(void)
44 {
45 static char errmsg[PJ_ERR_MSG_SIZE];
46 pj_strerror(pj_get_os_error(), errmsg, sizeof(errmsg));
47 return errmsg;
48 }
49 static const char *get_addr(void *addr)
50 {
51 static char txt[PJ_INET6_ADDRSTRLEN];
52 struct sockaddr *ad = (struct sockaddr*)addr;
53 if (ad->sa_family != PJ_AF_INET && ad->sa_family != PJ_AF_INET6)
54 return "?";
55 return pj_inet_ntop2(ad->sa_family, pj_sockaddr_get_addr(ad),
56 txt, sizeof(txt));
57 }
58 #else
59 # define TRACE_(exp)
60 #endif
61
62
63 #if 0
64 /* dummy */
65
66 #elif defined(PJ_HAS_IFADDRS_H) && PJ_HAS_IFADDRS_H != 0 && \
67 defined(PJ_HAS_NET_IF_H) && PJ_HAS_NET_IF_H != 0
68 /* Using getifaddrs() is preferred since it can work with both IPv4 and IPv6 */
69 static pj_status_t if_enum_by_af(int af,
70 unsigned *p_cnt,
71 pj_sockaddr ifs[])
72 {
73 struct ifaddrs *ifap = NULL, *it;
74 unsigned max;
75
76 PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL);
77
78 TRACE_((THIS_FILE, "Starting interface enum with getifaddrs() for af=%d",
79 af));
80
81 if (getifaddrs(&ifap) != 0) {
82 TRACE_((THIS_FILE, " getifarrds() failed: %s", get_os_errmsg()));
83 return PJ_RETURN_OS_ERROR(pj_get_netos_error());
84 }
85
86 it = ifap;
87 max = *p_cnt;
88 *p_cnt = 0;
89 for (; it!=NULL && *p_cnt < max; it = it->ifa_next) {
90 struct sockaddr *ad = it->ifa_addr;
91
92 TRACE_((THIS_FILE, " checking %s", it->ifa_name));
93
94 if ((it->ifa_flags & IFF_UP)==0) {
95 TRACE_((THIS_FILE, " interface is down"));
96 continue; /* Skip when interface is down */
97 }
98
99 if ((it->ifa_flags & IFF_RUNNING)==0) {
100 TRACE_((THIS_FILE, " interface is not running"));
101 continue; /* Skip when interface is not running */
102 }
103
104 #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
105 if (it->ifa_flags & IFF_LOOPBACK) {
106 TRACE_((THIS_FILE, " loopback interface"));
107 continue; /* Skip loopback interface */
108 }
109 #endif
110
111 if (ad==NULL) {
112 TRACE_((THIS_FILE, " NULL address ignored"));
113 continue; /* reported to happen on Linux 2.6.25.9
114 with ppp interface */
115 }
116
117 if (ad->sa_family != af) {
118 TRACE_((THIS_FILE, " address %s ignored (af=%d)",
119 get_addr(ad), ad->sa_family));
120 continue; /* Skip when interface is down */
121 }
122
123 /* Ignore 192.0.0.0/29 address.
124 * Ref: https://datatracker.ietf.org/doc/html/rfc7335#section-4
125 */
126 if (af==pj_AF_INET() &&
127 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 4) ==
128 201326592) /* 0b1100000000000000000000000000 which is
129 192.0.0.0 >> 4 */
130 {
131 TRACE_((THIS_FILE, " address %s ignored (192.0.0.0/29 class)",
132 get_addr(ad), ad->sa_family));
133 continue;
134 }
135
136 /* Ignore 0.0.0.0/8 address. This is a special address
137 * which doesn't seem to have practical use.
138 */
139 if (af==pj_AF_INET() &&
140 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0)
141 {
142 TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)",
143 get_addr(ad), ad->sa_family));
144 continue;
145 }
146
147 TRACE_((THIS_FILE, " address %s (af=%d) added at index %d",
148 get_addr(ad), ad->sa_family, *p_cnt));
149
150 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0]));
151 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad));
152 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]);
153 (*p_cnt)++;
154 }
155
156 freeifaddrs(ifap);
157 TRACE_((THIS_FILE, "done, found %d address(es)", *p_cnt));
158 return (*p_cnt != 0) ? PJ_SUCCESS : PJ_ENOTFOUND;
159 }
160
161 #elif defined(SIOCGIFCONF) && \
162 defined(PJ_HAS_NET_IF_H) && PJ_HAS_NET_IF_H != 0
163
164 /* Note: this does not work with IPv6 */
165 static pj_status_t if_enum_by_af(int af,
166 unsigned *p_cnt,
167 pj_sockaddr ifs[])
168 {
169 pj_sock_t sock;
170 char buf[512];
171 struct ifconf ifc;
172 struct ifreq *ifr;
173 int i, count;
174 pj_status_t status;
175
176 PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL);
177
178 TRACE_((THIS_FILE, "Starting interface enum with SIOCGIFCONF for af=%d",
179 af));
180
181 status = pj_sock_socket(af, PJ_SOCK_DGRAM, 0, &sock);
182 if (status != PJ_SUCCESS)
183 return status;
184
185 /* Query available interfaces */
186 ifc.ifc_len = sizeof(buf);
187 ifc.ifc_buf = buf;
188
189 if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
190 int oserr = pj_get_netos_error();
191 TRACE_((THIS_FILE, " ioctl(SIOCGIFCONF) failed: %s", get_os_errmsg()));
192 pj_sock_close(sock);
193 return PJ_RETURN_OS_ERROR(oserr);
194 }
195
196 /* Interface interfaces */
197 ifr = (struct ifreq*) ifc.ifc_req;
198 count = ifc.ifc_len / sizeof(struct ifreq);
199 if (count > *p_cnt)
200 count = *p_cnt;
201
202 *p_cnt = 0;
203 for (i=0; i<count; ++i) {
204 struct ifreq *itf = &ifr[i];
205 struct ifreq iff = *itf;
206 struct sockaddr *ad = &itf->ifr_addr;
207
208 TRACE_((THIS_FILE, " checking interface %s", itf->ifr_name));
209
210 /* Skip address with different family */
211 if (ad->sa_family != af) {
212 TRACE_((THIS_FILE, " address %s (af=%d) ignored",
213 get_addr(ad), (int)ad->sa_family));
214 continue;
215 }
216
217 if (ioctl(sock, SIOCGIFFLAGS, &iff) != 0) {
218 TRACE_((THIS_FILE, " ioctl(SIOCGIFFLAGS) failed: %s",
219 get_os_errmsg()));
220 continue; /* Failed to get flags, continue */
221 }
222
223 if ((iff.ifr_flags & IFF_UP)==0) {
224 TRACE_((THIS_FILE, " interface is down"));
225 continue; /* Skip when interface is down */
226 }
227
228 if ((iff.ifr_flags & IFF_RUNNING)==0) {
229 TRACE_((THIS_FILE, " interface is not running"));
230 continue; /* Skip when interface is not running */
231 }
232
233 #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
234 if (iff.ifr_flags & IFF_LOOPBACK) {
235 TRACE_((THIS_FILE, " loopback interface"));
236 continue; /* Skip loopback interface */
237 }
238 #endif
239
240 /* Ignore 192.0.0.0/29 address.
241 * Ref: https://datatracker.ietf.org/doc/html/rfc7335#section-4
242 */
243 if (af==pj_AF_INET() &&
244 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 4) ==
245 201326592) /* 0b1100000000000000000000000000 which is
246 192.0.0.0 >> 4 */
247 {
248 TRACE_((THIS_FILE, " address %s ignored (192.0.0.0/29 class)",
249 get_addr(ad), ad->sa_family));
250 continue;
251 }
252
253 /* Ignore 0.0.0.0/8 address. This is a special address
254 * which doesn't seem to have practical use.
255 */
256 if (af==pj_AF_INET() &&
257 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0)
258 {
259 TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)",
260 get_addr(ad), ad->sa_family));
261 continue;
262 }
263
264 TRACE_((THIS_FILE, " address %s (af=%d) added at index %d",
265 get_addr(ad), ad->sa_family, *p_cnt));
266
267 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0]));
268 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad));
269 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]);
270 (*p_cnt)++;
271 }
272
273 /* Done with socket */
274 pj_sock_close(sock);
275
276 TRACE_((THIS_FILE, "done, found %d address(es)", *p_cnt));
277 return (*p_cnt != 0) ? PJ_SUCCESS : PJ_ENOTFOUND;
278 }
279
280
281 #elif defined(PJ_HAS_NET_IF_H) && PJ_HAS_NET_IF_H != 0
282 /* Note: this does not work with IPv6 */
283 static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[])
284 {
285 struct if_nameindex *if_list;
286 struct ifreq ifreq;
287 pj_sock_t sock;
288 unsigned i, max_count;
289 pj_status_t status;
290
291 PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL);
292
293 TRACE_((THIS_FILE, "Starting if_nameindex() for af=%d", af));
294
295 status = pj_sock_socket(af, PJ_SOCK_DGRAM, 0, &sock);
296 if (status != PJ_SUCCESS)
297 return status;
298
299 if_list = if_nameindex();
300 if (if_list == NULL)
301 return PJ_ENOTFOUND;
302
303 max_count = *p_cnt;
304 *p_cnt = 0;
305 for (i=0; if_list[i].if_index && *p_cnt<max_count; ++i) {
306 struct sockaddr *ad;
307 int rc;
308
309 pj_ansi_strxcpy(ifreq.ifr_name, if_list[i].if_name, IFNAMSIZ);
310
311 TRACE_((THIS_FILE, " checking interface %s", ifreq.ifr_name));
312
313 if ((rc=ioctl(sock, SIOCGIFFLAGS, &ifreq)) != 0) {
314 TRACE_((THIS_FILE, " ioctl(SIOCGIFFLAGS) failed: %s",
315 get_os_errmsg()));
316 continue; /* Failed to get flags, continue */
317 }
318
319 if ((ifreq.ifr_flags & IFF_UP)==0) {
320 TRACE_((THIS_FILE, " interface is down"));
321 continue; /* Skip when interface is down */
322 }
323
324 if ((ifreq.ifr_flags & IFF_RUNNING)==0) {
325 TRACE_((THIS_FILE, " interface is not running"));
326 continue; /* Skip when interface is not running */
327 }
328
329 #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
330 if (ifreq.ifr_flags & IFF_LOOPBACK) {
331 TRACE_((THIS_FILE, " loopback interface"));
332 continue; /* Skip loopback interface */
333 }
334 #endif
335
336 /* Note: SIOCGIFADDR does not work for IPv6! */
337 if ((rc=ioctl(sock, SIOCGIFADDR, &ifreq)) != 0) {
338 TRACE_((THIS_FILE, " ioctl(SIOCGIFADDR) failed: %s",
339 get_os_errmsg()));
340 continue; /* Failed to get address, continue */
341 }
342
343 ad = (struct sockaddr*) &ifreq.ifr_addr;
344
345 if (ad->sa_family != af) {
346 TRACE_((THIS_FILE, " address %s family %d ignored",
347 get_addr(&ifreq.ifr_addr),
348 ifreq.ifr_addr.sa_family));
349 continue; /* Not address family that we want, continue */
350 }
351
352 /* Ignore 192.0.0.0/29 address.
353 * Ref: https://datatracker.ietf.org/doc/html/rfc7335#section-4
354 */
355 if (af==pj_AF_INET() &&
356 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 4) ==
357 201326592) /* 0b1100000000000000000000000000 which is
358 192.0.0.0 >> 4 */
359 {
360 TRACE_((THIS_FILE, " address %s ignored (192.0.0.0/29 class)",
361 get_addr(ad), ad->sa_family));
362 continue;
363 }
364
365 /* Ignore 0.0.0.0/8 address. This is a special address
366 * which doesn't seem to have practical use.
367 */
368 if (af==pj_AF_INET() &&
369 (pj_ntohl(((pj_sockaddr_in*)ad)->sin_addr.s_addr) >> 24) == 0)
370 {
371 TRACE_((THIS_FILE, " address %s ignored (0.0.0.0/8 class)",
372 get_addr(ad), ad->sa_family));
373 continue;
374 }
375
376 /* Got an address ! */
377 TRACE_((THIS_FILE, " address %s (af=%d) added at index %d",
378 get_addr(ad), ad->sa_family, *p_cnt));
379
380 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0]));
381 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad));
382 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]);
383 (*p_cnt)++;
384 }
385
386 if_freenameindex(if_list);
387 pj_sock_close(sock);
388
389 TRACE_((THIS_FILE, "done, found %d address(es)", *p_cnt));
390 return (*p_cnt != 0) ? PJ_SUCCESS : PJ_ENOTFOUND;
391 }
392
393 #else
394 static pj_status_t if_enum_by_af(int af,
395 unsigned *p_cnt,
396 pj_sockaddr ifs[])
397 {
398 pj_status_t status;
399
400 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && ifs, PJ_EINVAL);
401
402 pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt));
403
404 /* Just get one default route */
405 status = pj_getdefaultipinterface(af, &ifs[0]);
406 if (status != PJ_SUCCESS)
407 return status;
408
409 *p_cnt = 1;
410 return PJ_SUCCESS;
411 }
412 #endif /* SIOCGIFCONF */
413
414 /*
415 * Enumerate the local IP interface currently active in the host.
416 */
417 PJ_DEF(pj_status_t) pj_enum_ip_interface(int af,
418 unsigned *p_cnt,
419 pj_sockaddr ifs[])
420 {
421 unsigned start;
422 pj_status_t status;
423
424 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && ifs, PJ_EINVAL);
425 pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt));
426
427 start = 0;
428 if (af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) {
429 unsigned max = *p_cnt;
430 status = if_enum_by_af(PJ_AF_INET6, &max, &ifs[start]);
431 if (status == PJ_SUCCESS) {
432 start += max;
433 (*p_cnt) -= max;
434 }
435 }
436
437 if (af==PJ_AF_INET || af==PJ_AF_UNSPEC) {
438 unsigned max = *p_cnt;
439 status = if_enum_by_af(PJ_AF_INET, &max, &ifs[start]);
440 if (status == PJ_SUCCESS) {
441 start += max;
442 (*p_cnt) -= max;
443 }
444 }
445
446 *p_cnt = start;
447
448 return (*p_cnt != 0) ? PJ_SUCCESS : PJ_ENOTFOUND;
449 }
450
451 /*
452 * Enumerate the IP routing table for this host.
453 */
454 PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt,
455 pj_ip_route_entry routes[])
456 {
457 pj_sockaddr itf;
458 pj_status_t status;
459
460 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL);
461
462 pj_bzero(routes, sizeof(routes[0]) * (*p_cnt));
463
464 /* Just get one default route */
465 status = pj_getdefaultipinterface(PJ_AF_INET, &itf);
466 if (status != PJ_SUCCESS)
467 return status;
468
469 routes[0].ipv4.if_addr.s_addr = itf.ipv4.sin_addr.s_addr;
470 routes[0].ipv4.dst_addr.s_addr = 0;
471 routes[0].ipv4.mask.s_addr = 0;
472 *p_cnt = 1;
473
474 return PJ_SUCCESS;
475 }
476
477 #if defined(PJ_LINUX) && PJ_LINUX!=0
478 static pj_status_t get_ipv6_deprecated(unsigned *count, pj_sockaddr addr[])
479 {
480 struct {
481 struct nlmsghdr nlmsg_info;
482 struct ifaddrmsg ifaddrmsg_info;
483 } netlink_req;
484 long pagesize;
485 int fd;
486 int rtn;
487 char *read_buffer;
488 size_t idx = 0;
489
490 pagesize = sysconf(_SC_PAGESIZE);
491 if (pagesize <= 0)
492 pagesize = 4096; /* Assume pagesize is 4096 if sysconf() failed */
493
494 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
495 if (fd < 0)
496 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
497
498 bzero(&netlink_req, sizeof(netlink_req));
499
500 netlink_req.nlmsg_info.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
501 netlink_req.nlmsg_info.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
502 netlink_req.nlmsg_info.nlmsg_type = RTM_GETADDR;
503 netlink_req.nlmsg_info.nlmsg_pid = getpid();
504 netlink_req.ifaddrmsg_info.ifa_family = AF_INET6;
505
506 rtn = send(fd, &netlink_req, netlink_req.nlmsg_info.nlmsg_len, 0);
507 if (rtn < 0) {
508 close(fd);
509 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
510 }
511
512 read_buffer = (char*)alloca(pagesize);
513
514 while(1) {
515 struct nlmsghdr *nlmsg_ptr;
516 int nlmsg_len;
517 int read_size;
518
519 bzero(read_buffer, pagesize);
520 read_size = recv(fd, read_buffer, pagesize, 0);
521 if (read_size < 0) {
522 close(fd);
523 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
524 }
525
526 nlmsg_ptr = (struct nlmsghdr *) read_buffer;
527 nlmsg_len = read_size;
528
529 if (nlmsg_len < (int)sizeof (struct nlmsghdr)) {
530 close(fd);
531 return PJ_ETOOSMALL;
532 }
533
534 for(; NLMSG_OK(nlmsg_ptr, nlmsg_len);
535 nlmsg_ptr = NLMSG_NEXT(nlmsg_ptr, nlmsg_len))
536 {
537 struct ifaddrmsg *ifaddrmsg_ptr;
538 struct rtattr *rtattr_ptr;
539 int ifaddrmsg_len;
540
541 if (nlmsg_ptr->nlmsg_type == NLMSG_DONE)
542 goto on_return;
543
544 ifaddrmsg_ptr = (struct ifaddrmsg*)NLMSG_DATA(nlmsg_ptr);
545
546 if (ifaddrmsg_ptr->ifa_flags & IFA_F_DEPRECATED ||
547 ifaddrmsg_ptr->ifa_flags & IFA_F_TENTATIVE)
548 {
549 rtattr_ptr = (struct rtattr*)IFA_RTA(ifaddrmsg_ptr);
550 ifaddrmsg_len = IFA_PAYLOAD(nlmsg_ptr);
551
552 for(;RTA_OK(rtattr_ptr, ifaddrmsg_len);
553 rtattr_ptr = RTA_NEXT(rtattr_ptr, ifaddrmsg_len))
554 {
555 switch(rtattr_ptr->rta_type) {
556 case IFA_ADDRESS:
557 {
558 /* Check if addr can contain more data */
559 char deprecatedAddr[PJ_INET6_ADDRSTRLEN];
560 pj_str_t pj_addr_str;
561
562 if (idx >= *count)
563 break;
564 /* Store deprecated IP */
565 inet_ntop(ifaddrmsg_ptr->ifa_family,
566 RTA_DATA(rtattr_ptr),
567 deprecatedAddr,
568 sizeof(deprecatedAddr));
569 pj_cstr(&pj_addr_str, deprecatedAddr);
570 pj_sockaddr_init(pj_AF_INET6(), &addr[idx],
571 &pj_addr_str, 0);
572 ++idx;
573 break;
574 }
575 default:
576 break;
577 }
578 }
579 }
580 }
581 }
582
583 on_return:
584 close(fd);
585 *count = idx;
586
587 return PJ_SUCCESS;
588 }
589 #endif
590
591 /*
592 * Enumerate the local IP interface currently active in the host.
593 */
594 PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
595 unsigned *p_cnt,
596 pj_sockaddr ifs[])
597 {
598 pj_enum_ip_option opt_;
599
600 if (opt)
601 opt_ = *opt;
602 else
603 pj_enum_ip_option_default(&opt_);
604
605 if (opt_.af != pj_AF_INET() && opt_.omit_deprecated_ipv6) {
606
607 #if defined(PJ_LINUX) && PJ_LINUX!=0
608 pj_sockaddr addrs[*p_cnt];
609 pj_sockaddr deprecatedAddrs[*p_cnt];
610 unsigned deprecatedCount = *p_cnt;
611 unsigned cnt = 0;
612 unsigned i;
613 pj_status_t status;
614
615 status = get_ipv6_deprecated(&deprecatedCount, deprecatedAddrs);
616 if (status != PJ_SUCCESS)
617 return status;
618
619 status = pj_enum_ip_interface(opt_.af, p_cnt, addrs);
620 if (status != PJ_SUCCESS)
621 return status;
622
623 for (i = 0; i < *p_cnt; ++i) {
624 unsigned j;
625
626 ifs[cnt++] = addrs[i];
627
628 if (addrs[i].addr.sa_family != pj_AF_INET6())
629 continue;
630
631 for (j = 0; j < deprecatedCount; ++j) {
632 if (pj_sockaddr_cmp(&addrs[i], &deprecatedAddrs[j]) == 0) {
633 cnt--;
634 break;
635 }
636 }
637 }
638
639 *p_cnt = cnt;
640 return *p_cnt ? PJ_SUCCESS : PJ_ENOTFOUND;
641 #else
642 return PJ_ENOTSUP;
643 #endif
644 }
645
646 return pj_enum_ip_interface(opt_.af, p_cnt, ifs);
647 }