totemip.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * Copyright (c) 2005 Red Hat Inc
  3. * Copyright (c) 2006 Sun Microsystems, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Patrick Caulfield (pcaulfie@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /* IPv4/6 abstraction */
  36. #include <sys/ioctl.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <arpa/inet.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #include <netdb.h>
  43. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) || defined(OPENAIS_SOLARIS)
  44. #include <sys/sockio.h>
  45. #include <net/if.h>
  46. #ifndef OPENAIS_SOLARIS
  47. #include <net/if_var.h>
  48. #endif
  49. #include <netinet/in_var.h>
  50. #endif
  51. #include <string.h>
  52. #include <stdio.h>
  53. #include <errno.h>
  54. #include <assert.h>
  55. #include <stdlib.h>
  56. #include <unistd.h>
  57. #if defined(OPENAIS_LINUX)
  58. #include <net/if.h>
  59. /* ARGH!! I hate netlink */
  60. #include <asm/types.h>
  61. #include <linux/rtnetlink.h>
  62. /* this should catch 2.6.19 headers */
  63. #ifndef IFA_MAX
  64. #include <linux/if_addr.h>
  65. #endif
  66. /* redefine macro that disappeared in 2.6.19 */
  67. #ifndef IFA_RTA
  68. #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
  69. #endif
  70. #endif
  71. #if ! defined(OPENAIS_SOLARIS) && ! defined(s6_addr16)
  72. #define s6_addr16 __u6_addr.__u6_addr16
  73. #endif
  74. #include "swab.h"
  75. #include "totemip.h"
  76. #define LOCALHOST_IPV4 "127.0.0.1"
  77. #define LOCALHOST_IPV6 "::1"
  78. #define NETLINK_BUFSIZE 16384
  79. #ifdef SO_NOSIGPIPE
  80. void totemip_nosigpipe(int s)
  81. {
  82. int on = 1;
  83. setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on));
  84. }
  85. #endif
  86. /* Compare two addresses */
  87. int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
  88. {
  89. int addrlen = 0;
  90. if (addr1->family != addr2->family)
  91. return 0;
  92. if (addr1->family == AF_INET) {
  93. addrlen = sizeof(struct in_addr);
  94. }
  95. if (addr1->family == AF_INET6) {
  96. addrlen = sizeof(struct in6_addr);
  97. }
  98. assert(addrlen);
  99. if (memcmp(addr1->addr, addr2->addr, addrlen) == 0)
  100. return 1;
  101. else
  102. return 0;
  103. }
  104. /* Copy a totem_ip_address */
  105. void totemip_copy(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
  106. {
  107. memcpy(addr1, addr2, sizeof(struct totem_ip_address));
  108. }
  109. void totemip_copy_endian_convert(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
  110. {
  111. addr1->nodeid = swab32(addr2->nodeid);
  112. addr1->family = swab16(addr2->family);
  113. if (addr1 != addr2) {
  114. memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
  115. }
  116. }
  117. /* For sorting etc. params are void * for qsort's benefit */
  118. int totemip_compare(const void *a, const void *b)
  119. {
  120. int i;
  121. struct totem_ip_address *totemip_a = (struct totem_ip_address *)a;
  122. struct totem_ip_address *totemip_b = (struct totem_ip_address *)b;
  123. struct in_addr ipv4_a1;
  124. struct in_addr ipv4_a2;
  125. struct in6_addr ipv6_a1;
  126. struct in6_addr ipv6_a2;
  127. unsigned short family;
  128. /*
  129. * Use memcpy to align since totem_ip_address is unaligned on various archs
  130. */
  131. memcpy (&family, &totemip_a->family, sizeof (unsigned short));
  132. if (family == AF_INET) {
  133. memcpy (&ipv4_a1, totemip_a->addr, sizeof (struct in_addr));
  134. memcpy (&ipv4_a2, totemip_b->addr, sizeof (struct in_addr));
  135. if (ipv4_a1.s_addr == ipv4_a2.s_addr) {
  136. return (0);
  137. }
  138. if (htonl(ipv4_a1.s_addr) < htonl(ipv4_a2.s_addr)) {
  139. return -1;
  140. } else {
  141. return +1;
  142. }
  143. } else
  144. if (family == AF_INET6) {
  145. /*
  146. * Compare 16 bits at a time the ipv6 address
  147. */
  148. memcpy (&ipv6_a1, totemip_a->addr, sizeof (struct in6_addr));
  149. memcpy (&ipv6_a2, totemip_b->addr, sizeof (struct in6_addr));
  150. for (i = 0; i < 8; i++) {
  151. #ifndef OPENAIS_SOLARIS
  152. int res = htons(ipv6_a1.s6_addr16[i]) -
  153. htons(ipv6_a2.s6_addr16[i]);
  154. #else
  155. int res = htons(((uint16_t *)ipv6_a1.s6_addr)[i]) -
  156. htons(((uint16_t *)ipv6_a2.s6_addr)[i]);
  157. #endif
  158. if (res) {
  159. return res;
  160. }
  161. }
  162. return 0;
  163. } else {
  164. /*
  165. * Family not set, should be!
  166. */
  167. assert (0);
  168. exit (1);
  169. }
  170. }
  171. /* Build a localhost totem_ip_address */
  172. int totemip_localhost(int family, struct totem_ip_address *localhost)
  173. {
  174. char *addr_text;
  175. uint32_t nodeid;
  176. memset (localhost, 0, sizeof (struct totem_ip_address));
  177. if (family == AF_INET) {
  178. addr_text = LOCALHOST_IPV4;
  179. if (inet_pton(family, addr_text, (char *)&nodeid) <= 0) {
  180. return -1;
  181. }
  182. localhost->nodeid = ntohl(nodeid);
  183. } else {
  184. addr_text = LOCALHOST_IPV6;
  185. }
  186. if (inet_pton(family, addr_text, (char *)localhost->addr) <= 0)
  187. return -1;
  188. localhost->family = family;
  189. return 0;
  190. }
  191. int totemip_localhost_check(struct totem_ip_address *addr)
  192. {
  193. struct totem_ip_address localhost;
  194. if (totemip_localhost(addr->family, &localhost))
  195. return 0;
  196. return totemip_equal(addr, &localhost);
  197. }
  198. const char *totemip_print(struct totem_ip_address *addr)
  199. {
  200. static char buf[INET6_ADDRSTRLEN];
  201. return inet_ntop(addr->family, addr->addr, buf, sizeof(buf));
  202. }
  203. /* Make a totem_ip_address into a usable sockaddr_storage */
  204. int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
  205. uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
  206. {
  207. int ret = -1;
  208. if (ip_addr->family == AF_INET) {
  209. struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
  210. memset(sin, 0, sizeof(struct sockaddr_in));
  211. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  212. sin->sin_len = sizeof(struct sockaddr_in);
  213. #endif
  214. sin->sin_family = ip_addr->family;
  215. sin->sin_port = htons (port);
  216. memcpy(&sin->sin_addr, ip_addr->addr, sizeof(struct in_addr));
  217. *addrlen = sizeof(struct sockaddr_in);
  218. ret = 0;
  219. }
  220. if (ip_addr->family == AF_INET6) {
  221. struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr;
  222. memset(sin, 0, sizeof(struct sockaddr_in6));
  223. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  224. sin->sin6_len = sizeof(struct sockaddr_in6);
  225. #endif
  226. sin->sin6_family = ip_addr->family;
  227. sin->sin6_port = htons (port);
  228. sin->sin6_scope_id = 2;
  229. memcpy(&sin->sin6_addr, ip_addr->addr, sizeof(struct in6_addr));
  230. *addrlen = sizeof(struct sockaddr_in6);
  231. ret = 0;
  232. }
  233. return ret;
  234. }
  235. /* Converts an address string string into a totem_ip_address.
  236. * family can be AF_INET, AF_INET6 or 0 (for "don't care")
  237. */
  238. int totemip_parse(struct totem_ip_address *totemip, char *addr, int family)
  239. {
  240. struct addrinfo *ainfo;
  241. struct addrinfo ahints;
  242. struct sockaddr_in *sa;
  243. struct sockaddr_in6 *sa6;
  244. int ret;
  245. memset(&ahints, 0, sizeof(ahints));
  246. ahints.ai_socktype = SOCK_DGRAM;
  247. ahints.ai_protocol = IPPROTO_UDP;
  248. ahints.ai_family = family;
  249. /* Lookup the nodename address */
  250. ret = getaddrinfo(addr, NULL, &ahints, &ainfo);
  251. if (ret)
  252. return -1;
  253. sa = (struct sockaddr_in *)ainfo->ai_addr;
  254. sa6 = (struct sockaddr_in6 *)ainfo->ai_addr;
  255. totemip->family = ainfo->ai_family;
  256. if (ainfo->ai_family == AF_INET)
  257. memcpy(totemip->addr, &sa->sin_addr, sizeof(struct in_addr));
  258. else
  259. memcpy(totemip->addr, &sa6->sin6_addr, sizeof(struct in6_addr));
  260. freeaddrinfo(ainfo);
  261. return 0;
  262. }
  263. /* Make a sockaddr_* into a totem_ip_address */
  264. int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr)
  265. {
  266. int ret = -1;
  267. ip_addr->family = saddr->ss_family;
  268. ip_addr->nodeid = 0;
  269. if (saddr->ss_family == AF_INET) {
  270. struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
  271. memcpy(ip_addr->addr, &sin->sin_addr, sizeof(struct in_addr));
  272. ret = 0;
  273. }
  274. if (saddr->ss_family == AF_INET6) {
  275. struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr;
  276. memcpy(ip_addr->addr, &sin->sin6_addr, sizeof(struct in6_addr));
  277. ret = 0;
  278. }
  279. return ret;
  280. }
  281. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) || defined(OPENAIS_SOLARIS)
  282. int totemip_iface_check(struct totem_ip_address *bindnet,
  283. struct totem_ip_address *boundto,
  284. int *interface_up,
  285. int *interface_num)
  286. {
  287. #ifndef OPENAIS_SOLARIS
  288. #define NEXT_IFR(a) ((struct ifreq *)((u_char *)&(a)->ifr_addr +\
  289. ((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr))))
  290. #else
  291. #define NEXT_IFR(a) ((struct ifreq *)((u_char *)&(a)->ifr_addr +\
  292. sizeof((a)->ifr_addr)))
  293. #endif
  294. struct sockaddr_in *intf_addr_mask;
  295. struct sockaddr_storage bindnet_ss, intf_addr_ss;
  296. struct sockaddr_in *intf_addr_sin = (struct sockaddr_in *)&intf_addr_ss;
  297. struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss;
  298. struct ifreq *ifr, *lifr;
  299. int id_fd;
  300. struct ifconf ifc;
  301. struct ifreq ifrb;
  302. int numreqs = 0;
  303. int res;
  304. int addrlen;
  305. *interface_up = 0;
  306. *interface_num = 0;
  307. totemip_totemip_to_sockaddr_convert(bindnet,
  308. 0, &bindnet_ss, &addrlen);
  309. /*
  310. * Generate list of local interfaces in ifc.ifc_req structure
  311. */
  312. id_fd = socket (AF_INET, SOCK_DGRAM, 0);
  313. ifc.ifc_buf = NULL;
  314. do {
  315. void *ifc_buf_tmp;
  316. numreqs += 32;
  317. ifc.ifc_len = sizeof (struct ifreq) * numreqs;
  318. ifc_buf_tmp = realloc (ifc.ifc_buf, ifc.ifc_len);
  319. if (ifc_buf_tmp == NULL) {
  320. close (id_fd);
  321. if (ifc.ifc_buf != NULL) {
  322. free (ifc.ifc_buf);
  323. }
  324. return -1;
  325. }
  326. ifc.ifc_buf = ifc_buf_tmp;
  327. res = ioctl (id_fd, SIOCGIFCONF, &ifc);
  328. if (res < 0) {
  329. close (id_fd);
  330. free (ifc.ifc_buf);
  331. return -1;
  332. }
  333. } while (ifc.ifc_len == sizeof (struct ifreq) * numreqs);
  334. res = -1;
  335. /*
  336. * Find interface address to bind to
  337. */
  338. lifr = (struct ifreq *)ifc.ifc_buf + (ifc.ifc_len / sizeof(*lifr));
  339. for (ifr = ifc.ifc_req; ifr < lifr; ifr = NEXT_IFR(ifr)) {
  340. strcpy(ifrb.ifr_name, ifr->ifr_name);
  341. /* Skip if no address set
  342. */
  343. if (ioctl(id_fd, SIOCGIFADDR, &ifrb) < 0)
  344. continue;
  345. memcpy(&intf_addr_ss, &ifrb.ifr_addr, sizeof(intf_addr_ss));
  346. if (intf_addr_sin->sin_family == AF_INET) {
  347. /* Retrieve mask
  348. */
  349. if (ioctl(id_fd, SIOCGIFNETMASK, &ifrb) < 0) {
  350. break;
  351. }
  352. intf_addr_mask = (struct sockaddr_in *)&ifrb.ifr_addr;
  353. if ( bindnet_sin->sin_family == AF_INET &&
  354. (intf_addr_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr) ==
  355. (bindnet_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr)) {
  356. totemip_copy(boundto, bindnet);
  357. memcpy(boundto->addr, &intf_addr_sin->sin_addr, sizeof(intf_addr_sin->sin_addr));
  358. /* Get inteface state
  359. */
  360. if (ioctl(id_fd, SIOCGIFFLAGS, &ifrb) < 0) {
  361. break;
  362. }
  363. *interface_up = ifrb.ifr_flags & IFF_UP;
  364. /* Get interface index
  365. */
  366. #ifdef SIOCGIFINDEX
  367. if (ioctl(id_fd, SIOCGIFINDEX, &ifrb) < 0) {
  368. break;
  369. }
  370. *interface_num = ifrb.ifr_index;
  371. #else
  372. *interface_num = if_nametoindex(ifrb.ifr_name);
  373. #endif
  374. res = 0;
  375. break; /* for */
  376. }
  377. }
  378. }
  379. if (ifc.ifc_buf != NULL) {
  380. free (ifc.ifc_buf);
  381. }
  382. close (id_fd);
  383. return (res);
  384. }
  385. #elif defined(OPENAIS_LINUX)
  386. static void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
  387. {
  388. while (RTA_OK(rta, len)) {
  389. if (rta->rta_type <= max)
  390. tb[rta->rta_type] = rta;
  391. rta = RTA_NEXT(rta,len);
  392. }
  393. }
  394. int totemip_iface_check(struct totem_ip_address *bindnet,
  395. struct totem_ip_address *boundto,
  396. int *interface_up,
  397. int *interface_num)
  398. {
  399. int fd;
  400. struct {
  401. struct nlmsghdr nlh;
  402. struct rtgenmsg g;
  403. } req;
  404. struct sockaddr_nl nladdr;
  405. struct totem_ip_address ipaddr;
  406. static char rcvbuf[NETLINK_BUFSIZE];
  407. *interface_up = 0;
  408. *interface_num = 0;
  409. memset(&ipaddr, 0, sizeof(ipaddr));
  410. /* Make sure we preserve these */
  411. ipaddr.family = bindnet->family;
  412. ipaddr.nodeid = bindnet->nodeid;
  413. /* Ask netlink for a list of interface addresses */
  414. fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  415. if (fd <0)
  416. return -1;
  417. setsockopt(fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf));
  418. memset(&nladdr, 0, sizeof(nladdr));
  419. nladdr.nl_family = AF_NETLINK;
  420. req.nlh.nlmsg_len = sizeof(req);
  421. req.nlh.nlmsg_type = RTM_GETADDR;
  422. req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
  423. req.nlh.nlmsg_pid = 0;
  424. req.nlh.nlmsg_seq = 1;
  425. req.g.rtgen_family = bindnet->family;
  426. if (sendto(fd, (void *)&req, sizeof(req), 0,
  427. (struct sockaddr*)&nladdr, sizeof(nladdr)) < 0) {
  428. close(fd);
  429. return -1;
  430. }
  431. /* Look through the return buffer for our address */
  432. while (1)
  433. {
  434. int status;
  435. struct nlmsghdr *h;
  436. struct iovec iov = { rcvbuf, sizeof(rcvbuf) };
  437. struct msghdr msg = {
  438. (void*)&nladdr, sizeof(nladdr),
  439. &iov, 1,
  440. NULL, 0,
  441. 0
  442. };
  443. status = recvmsg(fd, &msg, 0);
  444. if (!status) {
  445. close(fd);
  446. return -1;
  447. }
  448. h = (struct nlmsghdr *)rcvbuf;
  449. if (h->nlmsg_type == NLMSG_DONE)
  450. break;
  451. if (h->nlmsg_type == NLMSG_ERROR) {
  452. close(fd);
  453. return -1;
  454. }
  455. while (NLMSG_OK(h, status)) {
  456. if (h->nlmsg_type == RTM_NEWADDR) {
  457. struct ifaddrmsg *ifa = NLMSG_DATA(h);
  458. struct rtattr *tb[IFA_MAX+1];
  459. int len = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
  460. int found_if = 0;
  461. memset(tb, 0, sizeof(tb));
  462. parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
  463. memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN);
  464. if (totemip_equal(&ipaddr, bindnet))
  465. found_if = 1;
  466. /* If the address we have is an IPv4 network address, then
  467. substitute the actual IP address of this interface */
  468. if (!found_if && tb[IFA_BROADCAST] && ifa->ifa_family == AF_INET) {
  469. uint32_t network;
  470. uint32_t addr;
  471. uint32_t netmask = htonl(~((1<<(32-ifa->ifa_prefixlen))-1));
  472. memcpy(&network, RTA_DATA(tb[IFA_BROADCAST]), sizeof(uint32_t));
  473. memcpy(&addr, bindnet->addr, sizeof(uint32_t));
  474. if (addr == (network & netmask)) {
  475. memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN);
  476. found_if = 1;
  477. }
  478. }
  479. if (found_if) {
  480. /* Found it - check I/F is UP */
  481. struct ifreq ifr;
  482. int ioctl_fd; /* Can't do ioctls on netlink FDs */
  483. ioctl_fd = socket(AF_INET, SOCK_STREAM, 0);
  484. if (ioctl_fd < 0) {
  485. close(fd);
  486. return -1;
  487. }
  488. memset(&ifr, 0, sizeof(ifr));
  489. ifr.ifr_ifindex = ifa->ifa_index;
  490. /* SIOCGIFFLAGS needs an interface name */
  491. status = ioctl(ioctl_fd, SIOCGIFNAME, &ifr);
  492. status = ioctl(ioctl_fd, SIOCGIFFLAGS, &ifr);
  493. if (status) {
  494. close(ioctl_fd);
  495. close(fd);
  496. return -1;
  497. }
  498. if (ifr.ifr_flags & IFF_UP)
  499. *interface_up = 1;
  500. *interface_num = ifa->ifa_index;
  501. close(ioctl_fd);
  502. goto finished;
  503. }
  504. }
  505. h = NLMSG_NEXT(h, status);
  506. }
  507. }
  508. finished:
  509. totemip_copy (boundto, &ipaddr);
  510. close(fd);
  511. return 0;
  512. }
  513. #endif /* OPENAIS_LINUX */