cidr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /* $Id: cidr.c 2423 2010-03-13 07:09:49Z aturner $ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the names of the copyright owners nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  25. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  27. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include "config.h"
  32. #include "defines.h"
  33. #include "common.h"
  34. #include "lib/strlcpy.h"
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. /* required for inet_aton() */
  39. #include <sys/socket.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #ifdef DEBUG
  43. extern int debug;
  44. #endif
  45. static tcpr_cidr_t *cidr2cidr(char *);
  46. /**
  47. * prints to the given fd all the entries in mycidr
  48. */
  49. void
  50. print_cidr(tcpr_cidr_t * mycidr)
  51. {
  52. tcpr_cidr_t *cidr_ptr;
  53. fprintf(stderr, "Cidr List: ");
  54. cidr_ptr = mycidr;
  55. while (cidr_ptr != NULL) {
  56. /* print it */
  57. fprintf(stderr, "%s/%d, ", get_cidr2name(cidr_ptr, RESOLVE),
  58. cidr_ptr->masklen);
  59. /* go to the next */
  60. if (cidr_ptr->next != NULL) {
  61. cidr_ptr = cidr_ptr->next;
  62. }
  63. else {
  64. break;
  65. }
  66. }
  67. fprintf(stderr, "\n");
  68. }
  69. /**
  70. * deletes all entries in a cidr and destroys the datastructure
  71. */
  72. void
  73. destroy_cidr(tcpr_cidr_t * cidr)
  74. {
  75. if (cidr != NULL)
  76. if (cidr->next != NULL)
  77. destroy_cidr(cidr->next);
  78. safe_free(cidr);
  79. return;
  80. }
  81. /**
  82. * adds a new tcpr_cidr_t entry to cidrdata
  83. */
  84. void
  85. add_cidr(tcpr_cidr_t ** cidrdata, tcpr_cidr_t ** newcidr)
  86. {
  87. tcpr_cidr_t *cidr_ptr;
  88. dbg(1, "Running new_cidr()");
  89. if (*cidrdata == NULL) {
  90. *cidrdata = *newcidr;
  91. } else {
  92. cidr_ptr = *cidrdata;
  93. while (cidr_ptr->next != NULL)
  94. cidr_ptr = cidr_ptr->next;
  95. cidr_ptr->next = *newcidr;
  96. }
  97. }
  98. /**
  99. * takes in an IP and masklen, and returns a string in
  100. * cidr format: x.x.x.x/y. This malloc's memory.
  101. */
  102. u_char *
  103. ip2cidr(const unsigned long ip, const int masklen)
  104. {
  105. u_char *network;
  106. char mask[3];
  107. network = (u_char *)safe_malloc(20);
  108. strlcpy((char *)network, (char *)get_addr2name4(ip, RESOLVE),
  109. sizeof(network));
  110. strcat((char *)network, "/");
  111. if (masklen < 10) {
  112. snprintf(mask, 1, "%d", masklen);
  113. strncat((char *)network, mask, 1);
  114. } else {
  115. snprintf(mask, 2, "%d", masklen);
  116. strncat((char *)network, mask, 2);
  117. }
  118. return (network);
  119. }
  120. /**
  121. * Mallocs and sets to sane defaults a tcpr_cidr_t structure
  122. */
  123. tcpr_cidr_t *
  124. new_cidr(void)
  125. {
  126. tcpr_cidr_t *newcidr;
  127. newcidr = (tcpr_cidr_t *)safe_malloc(sizeof(tcpr_cidr_t));
  128. memset(newcidr, '\0', sizeof(tcpr_cidr_t));
  129. newcidr->masklen = 99;
  130. newcidr->next = NULL;
  131. return (newcidr);
  132. }
  133. /**
  134. * Creates a new tcpr_cidrmap_t structure. Malloc's memory
  135. */
  136. tcpr_cidrmap_t *
  137. new_cidr_map(void)
  138. {
  139. tcpr_cidrmap_t *new;
  140. new = (tcpr_cidrmap_t *)safe_malloc(sizeof(tcpr_cidrmap_t));
  141. memset(new, '\0', sizeof(tcpr_cidrmap_t));
  142. new->next = NULL;
  143. return (new);
  144. }
  145. /**
  146. * Converts a single cidr (string) in the form of x.x.x.x/y into a
  147. * tcpr_cidr_t structure. Will malloc the tcpr_cidr_t structure.
  148. */
  149. static tcpr_cidr_t *
  150. cidr2cidr(char *cidr)
  151. {
  152. int count = 0;
  153. unsigned int octets[4]; /* used in sscanf */
  154. tcpr_cidr_t *newcidr;
  155. char networkip[16], tempoctet[4], ebuf[EBUF_SIZE];
  156. int family;
  157. char* p;
  158. assert(cidr);
  159. assert(strlen(cidr) <= EBUF_SIZE);
  160. newcidr = new_cidr();
  161. for (p = cidr; *p; ++p) {
  162. if (*p == '#') {
  163. *p = ':';
  164. } else if (*p == ']') {
  165. *p = 0;
  166. break;
  167. }
  168. }
  169. /*
  170. * scan it, and make sure it scanned correctly, also copy over the
  171. * masklen
  172. */
  173. count = sscanf(cidr, "%u.%u.%u.%u/%d", &octets[0], &octets[1],
  174. &octets[2], &octets[3], &newcidr->masklen);
  175. if (count == 4) {
  176. newcidr->masklen = 32;
  177. family = AF_INET;
  178. } else if (count == 5) {
  179. family = AF_INET;
  180. } else {
  181. p = strstr(cidr, "/");
  182. if (p) {
  183. *p = 0;
  184. ++p;
  185. count = sscanf(p, "%d", &newcidr->masklen);
  186. } else {
  187. newcidr->masklen = 128;
  188. }
  189. if (newcidr->masklen < 0 || newcidr->masklen > 128)
  190. goto error;
  191. /* skip past the opening [ */
  192. if (*cidr == '[')
  193. cidr ++;
  194. if (get_name2addr6(cidr, RESOLVE, &newcidr->u.network6) > 0) {
  195. family = AF_INET6;
  196. } else {
  197. goto error;
  198. }
  199. }
  200. if (family == AF_INET) {
  201. /* masklen better be 0 =< masklen <= 32 */
  202. if (newcidr->masklen > 32)
  203. goto error;
  204. /* copy in the ip address */
  205. memset(networkip, '\0', 16);
  206. for (count = 0; count < 4; count++) {
  207. if (octets[count] > 255)
  208. goto error;
  209. snprintf(tempoctet, sizeof(octets[count]), "%d", octets[count]);
  210. strcat(networkip, tempoctet);
  211. /* we don't want a '.' at the end of the last octet */
  212. if (count < 3)
  213. strcat(networkip, ".");
  214. }
  215. /* copy over the network address and return */
  216. #ifdef HAVE_INET_ATON
  217. inet_aton(networkip, (struct in_addr *)&newcidr->u.network);
  218. #elif HAVE_INET_ADDR
  219. newcidr->network = inet_addr(networkip);
  220. #endif
  221. } else if (family == AF_INET6) {
  222. /* Everything's done */
  223. } else {
  224. goto error;
  225. }
  226. newcidr->family = family;
  227. return (newcidr);
  228. /* we only get here on error parsing input */
  229. error:
  230. memset(ebuf, '\0', EBUF_SIZE);
  231. strcpy(ebuf, "Unable to parse as a vaild CIDR: ");
  232. strlcat(ebuf, cidr, EBUF_SIZE);
  233. errx(-1, "%s", ebuf);
  234. return NULL;
  235. }
  236. static void
  237. mask_cidr6(char **cidrin, char* delim)
  238. {
  239. char *p;
  240. if (**cidrin == '[' && *delim == ':') {
  241. ++*cidrin;
  242. /* make strtok happy */
  243. for (p = *cidrin; *p && *p != ']'; ++p) {
  244. if (*p == ':') {
  245. *p = '#';
  246. }
  247. }
  248. }
  249. }
  250. /**
  251. * parses a list of tcpr_cidr_t's input from the user which should be in the form
  252. * of x.x.x.x/y,x.x.x.x/y...
  253. * returns 1 for success, or fails to return on failure (exit 1)
  254. * since we use strtok to process cidr, it gets zeroed out.
  255. */
  256. int
  257. parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)
  258. {
  259. tcpr_cidr_t *cidr_ptr; /* ptr to current cidr record */
  260. char *network = NULL;
  261. char *token = NULL;
  262. mask_cidr6(&cidrin, delim);
  263. /* first itteration of input using strtok */
  264. network = strtok_r(cidrin, delim, &token);
  265. *cidrdata = cidr2cidr(network);
  266. cidr_ptr = *cidrdata;
  267. /* do the same with the rest of the input */
  268. while (1) {
  269. if (token)
  270. mask_cidr6(&token, delim);
  271. network = strtok_r(NULL, delim, &token);
  272. /* if that was the last CIDR, then kickout */
  273. if (network == NULL)
  274. break;
  275. /* next record */
  276. cidr_ptr->next = cidr2cidr(network);
  277. cidr_ptr = cidr_ptr->next;
  278. }
  279. return 1;
  280. }
  281. /**
  282. * parses a pair of IP addresses: <IP1>:<IP2> and processes it like:
  283. * -N 0.0.0.0/0:<IP1> -N 0.0.0.0/0:<IP2>
  284. * returns 1 for success or returns 0 on failure
  285. * since we use strtok to process optarg, it gets zeroed out
  286. */
  287. int
  288. parse_endpoints(tcpr_cidrmap_t ** cidrmap1, tcpr_cidrmap_t ** cidrmap2, const char *optarg)
  289. {
  290. #define NEWMAP_LEN (INET6_ADDRSTRLEN * 2)
  291. char *map = NULL, newmap[NEWMAP_LEN];
  292. char *token = NULL;
  293. char *string;
  294. char *p;
  295. string = safe_strdup(optarg);
  296. if (*string == '[') {
  297. /* ipv6 mode */
  298. memset(newmap, '\0', NEWMAP_LEN);
  299. p = strstr(string, "]:[");
  300. if (!p)
  301. return 0;
  302. *p = 0;
  303. strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
  304. strlcat(newmap, string, NEWMAP_LEN);
  305. strlcat(newmap, "]", NEWMAP_LEN);
  306. if (! parse_cidr_map(cidrmap1, newmap))
  307. return 0;
  308. /* do again with the second IP */
  309. memset(newmap, '\0', NEWMAP_LEN);
  310. strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
  311. strlcat(newmap, p + 2, NEWMAP_LEN);
  312. if (! parse_cidr_map(cidrmap2, newmap))
  313. return 0;
  314. } else {
  315. /* ipv4 mode */
  316. memset(newmap, '\0', NEWMAP_LEN);
  317. map = strtok_r(string, ":", &token);
  318. strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
  319. strlcat(newmap, map, NEWMAP_LEN);
  320. if (! parse_cidr_map(cidrmap1, newmap))
  321. return 0;
  322. /* do again with the second IP */
  323. memset(newmap, '\0', NEWMAP_LEN);
  324. map = strtok_r(NULL, ":", &token);
  325. strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
  326. strlcat(newmap, map, NEWMAP_LEN);
  327. if (! parse_cidr_map(cidrmap2, newmap))
  328. return 0;
  329. }
  330. safe_free(string);
  331. return 1; /* success */
  332. }
  333. /**
  334. * parses a list of tcpr_cidrmap_t's input from the user which should be in the form
  335. * of x.x.x.x/y:x.x.x.x/y,...
  336. * IPv6 syntax: [addr/y]:[addr/y],...
  337. * returns 1 for success, or returns 0 on failure
  338. * since we use strtok to process optarg, it gets zeroed out.
  339. */
  340. int
  341. parse_cidr_map(tcpr_cidrmap_t **cidrmap, const char *optarg)
  342. {
  343. tcpr_cidr_t *cidr = NULL;
  344. char *map = NULL;
  345. char *token = NULL, *string = NULL;
  346. tcpr_cidrmap_t *ptr;
  347. string = safe_strdup(optarg);
  348. /* first iteration */
  349. map = strtok_r(string, ",", &token);
  350. if (! parse_cidr(&cidr, map, ":"))
  351. return 0;
  352. /* must return a linked list of two */
  353. if (cidr->next == NULL)
  354. return 0;
  355. /* copy over */
  356. *cidrmap = new_cidr_map();
  357. ptr = *cidrmap;
  358. ptr->from = cidr;
  359. ptr->to = cidr->next;
  360. ptr->from->next = NULL;
  361. /* do the same with the reset of the input */
  362. while(1) {
  363. map = strtok_r(NULL, ",", &token);
  364. if (map == NULL)
  365. break;
  366. if (! parse_cidr(&cidr, map, ":"))
  367. return 0;
  368. /* must return a linked list of two */
  369. if (cidr->next == NULL)
  370. return 0;
  371. /* copy over */
  372. ptr->next = new_cidr_map();
  373. ptr = ptr->next;
  374. ptr->from = cidr;
  375. ptr->to = cidr->next;
  376. ptr->from->next = NULL;
  377. }
  378. safe_free(string);
  379. return 1; /* success */
  380. }
  381. /**
  382. * checks to see if the ip address is in the cidr
  383. * returns 1 for true, 0 for false
  384. */
  385. int
  386. ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)
  387. {
  388. unsigned long ipaddr = 0, network = 0, mask = 0;
  389. int ret = 0;
  390. #ifdef DEBUG
  391. char netstr[20];
  392. #endif
  393. if (mycidr->family != AF_INET)
  394. return 0;
  395. /* always return 1 if 0.0.0.0/0 */
  396. if (mycidr->masklen == 0 && mycidr->u.network == 0)
  397. return 1;
  398. mask = ~0; /* turn on all the bits */
  399. /* shift over by the correct number of bits */
  400. mask = mask << (32 - mycidr->masklen);
  401. /* apply the mask to the network and ip */
  402. ipaddr = ntohl(ip) & mask;
  403. network = htonl(mycidr->u.network) & mask;
  404. #ifdef DEBUG
  405. /* copy this for debug purposes, since it's not re-entrant */
  406. strlcpy(netstr, get_addr2name4(htonl(mycidr->u.network), RESOLVE), 20);
  407. #endif
  408. /* if they're the same, then ip is in network */
  409. if (network == ipaddr) {
  410. #ifdef DEBUG
  411. dbgx(1, "The ip %s is inside of %s/%d",
  412. get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
  413. #endif
  414. ret = 1;
  415. } else {
  416. #ifdef DEBUG
  417. dbgx(1, "The ip %s is not inside of %s/%d",
  418. get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
  419. #endif
  420. ret = 0;
  421. }
  422. return ret;
  423. }
  424. static int
  425. ip6_addr_is_unspec(const struct tcpr_in6_addr *addr)
  426. {
  427. return addr->tcpr_s6_addr32[0] == 0 && addr->tcpr_s6_addr32[1] == 0 &&
  428. addr->tcpr_s6_addr32[2] == 0 && addr->tcpr_s6_addr32[3] == 0;
  429. }
  430. int
  431. ip6_in_cidr(const tcpr_cidr_t * mycidr, const struct tcpr_in6_addr *addr)
  432. {
  433. int ret = 0;
  434. #ifdef DEBUG
  435. char netstr[INET6_ADDRSTRLEN];
  436. #endif
  437. int i, j, k;
  438. if (mycidr->family != AF_INET6)
  439. return 0;
  440. /* always return 1 if ::/0 */
  441. if (mycidr->masklen == 0 && ip6_addr_is_unspec(addr))
  442. return 1;
  443. j = mycidr->masklen / 8;
  444. for (i = 0; i < j; i++) {
  445. if (addr->tcpr_s6_addr[i] != mycidr->u.network6.tcpr_s6_addr[i]) {
  446. ret = 0;
  447. goto out;
  448. }
  449. }
  450. if ((k = mycidr->masklen % 8) == 0) {
  451. ret = 1;
  452. goto out;
  453. }
  454. k = ~0 << (8 - k);
  455. i = addr->tcpr_s6_addr[j] & k;
  456. j = mycidr->u.network6.tcpr_s6_addr[j] & k;
  457. ret = i == j;
  458. out:
  459. #ifdef DEBUG
  460. /* copy this for debug purposes, since it's not re-entrant */
  461. strlcpy(netstr, get_addr2name6(&mycidr->u.network6, RESOLVE), INET6_ADDRSTRLEN);
  462. #endif
  463. /* if they're the same, then ip is in network */
  464. if (ret) {
  465. #ifdef DEBUG
  466. dbgx(1, "The ip %s is inside of %s/%d",
  467. get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
  468. #endif
  469. } else {
  470. #ifdef DEBUG
  471. dbgx(1, "The ip %s is not inside of %s/%d",
  472. get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
  473. #endif
  474. }
  475. return ret;
  476. }
  477. /**
  478. * iterates over cidrdata to find if a given ip matches
  479. * returns 1 for true, 0 for false
  480. */
  481. int
  482. check_ip_cidr(tcpr_cidr_t * cidrdata, const unsigned long ip)
  483. {
  484. tcpr_cidr_t *mycidr;
  485. /* if we have no cidrdata, of course it isn't in there
  486. * this actually should happen occasionally, so don't put an assert here
  487. */
  488. if (cidrdata == NULL)
  489. return 1;
  490. mycidr = cidrdata;
  491. /* loop through cidr */
  492. while (1) {
  493. /* if match, return 1 */
  494. if (ip_in_cidr(mycidr, ip)) {
  495. dbgx(3, "Found %s in cidr", get_addr2name4(ip, RESOLVE));
  496. return 1;
  497. }
  498. /* check for next record */
  499. if (mycidr->next != NULL) {
  500. mycidr = mycidr->next;
  501. } else {
  502. break;
  503. }
  504. }
  505. /* if we get here, no match */
  506. dbgx(3, "Didn't find %s in cidr", get_addr2name4(ip, RESOLVE));
  507. return 0;
  508. }
  509. int
  510. check_ip6_cidr(tcpr_cidr_t * cidrdata, const struct tcpr_in6_addr *addr)
  511. {
  512. tcpr_cidr_t *mycidr;
  513. /* if we have no cidrdata, of course it isn't in there
  514. * this actually should happen occasionally, so don't put an assert here
  515. */
  516. if (cidrdata == NULL) {
  517. return 1;
  518. }
  519. mycidr = cidrdata;
  520. /* loop through cidr */
  521. while (1) {
  522. /* if match, return 1 */
  523. if (ip6_in_cidr(mycidr, addr)) {
  524. dbgx(3, "Found %s in cidr", get_addr2name6(addr, RESOLVE));
  525. return 1;
  526. }
  527. /* check for next record */
  528. if (mycidr->next != NULL) {
  529. mycidr = mycidr->next;
  530. } else {
  531. break;
  532. }
  533. }
  534. /* if we get here, no match */
  535. dbgx(3, "Didn't find %s in cidr", get_addr2name6(addr, RESOLVE));
  536. return 0;
  537. }
  538. /**
  539. * cidr2ip takes a tcpr_cidr_t and a delimiter
  540. * and returns a string which lists all the IP addresses in the cidr
  541. * deliminated by the given char
  542. */
  543. char *
  544. cidr2iplist(tcpr_cidr_t * cidr, char delim)
  545. {
  546. char *list = NULL;
  547. char ipaddr[16];
  548. u_int32_t size, addr, first, last, numips;
  549. struct in_addr in;
  550. /*
  551. * 16 bytes per IP + delim
  552. * # of IP's = 2^(32-masklen)
  553. */
  554. numips = 2;
  555. for (int i = 2; i <= (32 - cidr->masklen); i++)
  556. numips *= 2;
  557. size = 16 * numips;
  558. list = (char *)safe_malloc(size);
  559. memset(list, 0, size);
  560. /* first and last should not include network or broadcast */
  561. first = ntohl(cidr->u.network) + 1;
  562. last = first + numips - 3;
  563. dbgx(1, "First: %u\t\tLast: %u", first, last);
  564. /* loop through all but the last one */
  565. for (addr = first; addr < last; addr++) {
  566. in.s_addr = htonl(addr);
  567. snprintf(ipaddr, 17, "%s%c", inet_ntoa(in), delim);
  568. dbgx(2, "%s", ipaddr);
  569. strlcat(list, ipaddr, size);
  570. }
  571. /* last is a special case, end in \0 */
  572. in.s_addr = htonl(addr);
  573. snprintf(ipaddr, 16, "%s", inet_ntoa(in));
  574. strlcat(list, ipaddr, size);
  575. return list;
  576. }