summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getaddrinfo.c
diff options
context:
space:
mode:
authorotto <>2005-03-25 13:24:12 +0000
committerotto <>2005-03-25 13:24:12 +0000
commit2f490723a2e673b2457f65c4b06cacb7d700a3e8 (patch)
treec9dcd3a58da3f7404d9e626fe10abdd67c384fba /src/lib/libc/net/getaddrinfo.c
parent9a03506f8308b6023a12f108a2072feb958607a6 (diff)
downloadopenbsd-2f490723a2e673b2457f65c4b06cacb7d700a3e8.tar.gz
openbsd-2f490723a2e673b2457f65c4b06cacb7d700a3e8.tar.bz2
openbsd-2f490723a2e673b2457f65c4b06cacb7d700a3e8.zip
ansify. ok deraadt@ moritz@
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r--src/lib/libc/net/getaddrinfo.c111
1 files changed, 31 insertions, 80 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c
index 3db8cc82ee..c7cc0500c3 100644
--- a/src/lib/libc/net/getaddrinfo.c
+++ b/src/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getaddrinfo.c,v 1.50 2004/06/07 21:11:23 marc Exp $ */ 1/* $OpenBSD: getaddrinfo.c,v 1.51 2005/03/25 13:24:12 otto Exp $ */
2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ 2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
3 3
4/* 4/*
@@ -279,8 +279,7 @@ do { \
279 ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) 279 ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
280 280
281static int 281static int
282str2number(p) 282str2number(const char *p)
283 const char *p;
284{ 283{
285 char *ep; 284 char *ep;
286 unsigned long v; 285 unsigned long v;
@@ -297,10 +296,8 @@ str2number(p)
297} 296}
298 297
299int 298int
300getaddrinfo(hostname, servname, hints, res) 299getaddrinfo(const char *hostname, const char *servname,
301 const char *hostname, *servname; 300 const struct addrinfo *hints, struct addrinfo **res)
302 const struct addrinfo *hints;
303 struct addrinfo **res;
304{ 301{
305 struct addrinfo sentinel; 302 struct addrinfo sentinel;
306 struct addrinfo *cur; 303 struct addrinfo *cur;
@@ -499,11 +496,8 @@ getaddrinfo(hostname, servname, hints, res)
499 */ 496 */
500 497
501static int 498static int
502explore_fqdn(pai, hostname, servname, res) 499explore_fqdn(const struct addrinfo *pai, const char *hostname,
503 const struct addrinfo *pai; 500 const char *servname, struct addrinfo **res)
504 const char *hostname;
505 const char *servname;
506 struct addrinfo **res;
507{ 501{
508 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 502 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
509 struct addrinfo *result; 503 struct addrinfo *result;
@@ -597,10 +591,8 @@ free:
597 * non-passive socket -> localhost (127.0.0.1 or ::1) 591 * non-passive socket -> localhost (127.0.0.1 or ::1)
598 */ 592 */
599static int 593static int
600explore_null(pai, servname, res) 594explore_null(const struct addrinfo *pai, const char *servname,
601 const struct addrinfo *pai; 595 struct addrinfo **res)
602 const char *servname;
603 struct addrinfo **res;
604{ 596{
605 int s; 597 int s;
606 const struct afd *afd; 598 const struct afd *afd;
@@ -661,12 +653,8 @@ free:
661 * numeric hostname 653 * numeric hostname
662 */ 654 */
663static int 655static int
664explore_numeric(pai, hostname, servname, res, canonname) 656explore_numeric(const struct addrinfo *pai, const char *hostname,
665 const struct addrinfo *pai; 657 const char *servname, struct addrinfo **res, const char *canonname)
666 const char *hostname;
667 const char *servname;
668 struct addrinfo **res;
669 const char *canonname;
670{ 658{
671 const struct afd *afd; 659 const struct afd *afd;
672 struct addrinfo *cur; 660 struct addrinfo *cur;
@@ -747,11 +735,8 @@ bad:
747 * numeric hostname with scope 735 * numeric hostname with scope
748 */ 736 */
749static int 737static int
750explore_numeric_scope(pai, hostname, servname, res) 738explore_numeric_scope(const struct addrinfo *pai, const char *hostname,
751 const struct addrinfo *pai; 739 const char *servname, struct addrinfo **res)
752 const char *hostname;
753 const char *servname;
754 struct addrinfo **res;
755{ 740{
756#if !defined(SCOPE_DELIMITER) || !defined(INET6) 741#if !defined(SCOPE_DELIMITER) || !defined(INET6)
757 return explore_numeric(pai, hostname, servname, res, hostname); 742 return explore_numeric(pai, hostname, servname, res, hostname);
@@ -813,10 +798,7 @@ explore_numeric_scope(pai, hostname, servname, res)
813} 798}
814 799
815static int 800static int
816get_canonname(pai, ai, str) 801get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str)
817 const struct addrinfo *pai;
818 struct addrinfo *ai;
819 const char *str;
820{ 802{
821 if ((pai->ai_flags & AI_CANONNAME) != 0) { 803 if ((pai->ai_flags & AI_CANONNAME) != 0) {
822 ai->ai_canonname = strdup(str); 804 ai->ai_canonname = strdup(str);
@@ -827,10 +809,7 @@ get_canonname(pai, ai, str)
827} 809}
828 810
829static struct addrinfo * 811static struct addrinfo *
830get_ai(pai, afd, addr) 812get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
831 const struct addrinfo *pai;
832 const struct afd *afd;
833 const char *addr;
834{ 813{
835 char *p; 814 char *p;
836 struct addrinfo *ai; 815 struct addrinfo *ai;
@@ -852,9 +831,7 @@ get_ai(pai, afd, addr)
852} 831}
853 832
854static int 833static int
855get_portmatch(ai, servname) 834get_portmatch(const struct addrinfo *ai, const char *servname)
856 const struct addrinfo *ai;
857 const char *servname;
858{ 835{
859 836
860 /* get_port does not touch first argument. when matchonly == 1. */ 837 /* get_port does not touch first argument. when matchonly == 1. */
@@ -863,10 +840,7 @@ get_portmatch(ai, servname)
863} 840}
864 841
865static int 842static int
866get_port(ai, servname, matchonly) 843get_port(struct addrinfo *ai, const char *servname, int matchonly)
867 struct addrinfo *ai;
868 const char *servname;
869 int matchonly;
870{ 844{
871 const char *proto; 845 const char *proto;
872 struct servent *sp; 846 struct servent *sp;
@@ -951,8 +925,7 @@ get_port(ai, servname, matchonly)
951} 925}
952 926
953static const struct afd * 927static const struct afd *
954find_afd(af) 928find_afd(int af)
955 int af;
956{ 929{
957 const struct afd *afd; 930 const struct afd *afd;
958 931
@@ -968,10 +941,7 @@ find_afd(af)
968#ifdef INET6 941#ifdef INET6
969/* convert a string to a scope identifier. XXX: IPv6 specific */ 942/* convert a string to a scope identifier. XXX: IPv6 specific */
970static int 943static int
971ip6_str2scopeid(scope, sin6, scopeid) 944ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid)
972 char *scope;
973 struct sockaddr_in6 *sin6;
974 u_int32_t *scopeid;
975{ 945{
976 u_long lscopeid; 946 u_long lscopeid;
977 struct in6_addr *a6 = &sin6->sin6_addr; 947 struct in6_addr *a6 = &sin6->sin6_addr;
@@ -1020,12 +990,8 @@ static const char AskedForGot[] =
1020static FILE *hostf = NULL; 990static FILE *hostf = NULL;
1021 991
1022static struct addrinfo * 992static struct addrinfo *
1023getanswer(answer, anslen, qname, qtype, pai) 993getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
1024 const querybuf *answer; 994 const struct addrinfo *pai)
1025 int anslen;
1026 const char *qname;
1027 int qtype;
1028 const struct addrinfo *pai;
1029{ 995{
1030 struct addrinfo sentinel, *cur; 996 struct addrinfo sentinel, *cur;
1031 struct addrinfo ai; 997 struct addrinfo ai;
@@ -1212,9 +1178,7 @@ getanswer(answer, anslen, qname, qtype, pai)
1212 1178
1213/*ARGSUSED*/ 1179/*ARGSUSED*/
1214static struct addrinfo * 1180static struct addrinfo *
1215_dns_getaddrinfo(name, pai) 1181_dns_getaddrinfo(const char *name, const struct addrinfo *pai)
1216 const char *name;
1217 const struct addrinfo *pai;
1218{ 1182{
1219 struct addrinfo *ai; 1183 struct addrinfo *ai;
1220 querybuf *buf, *buf2; 1184 querybuf *buf, *buf2;
@@ -1292,7 +1256,7 @@ _dns_getaddrinfo(name, pai)
1292static FILE *hostf; 1256static FILE *hostf;
1293 1257
1294static void 1258static void
1295_sethtent() 1259_sethtent(void)
1296{ 1260{
1297 if (!hostf) 1261 if (!hostf)
1298 hostf = fopen(_PATH_HOSTS, "r" ); 1262 hostf = fopen(_PATH_HOSTS, "r" );
@@ -1301,7 +1265,7 @@ _sethtent()
1301} 1265}
1302 1266
1303static void 1267static void
1304_endhtent() 1268_endhtent(void)
1305{ 1269{
1306 if (hostf) { 1270 if (hostf) {
1307 (void) fclose(hostf); 1271 (void) fclose(hostf);
@@ -1310,9 +1274,7 @@ _endhtent()
1310} 1274}
1311 1275
1312static struct addrinfo * 1276static struct addrinfo *
1313_gethtent(name, pai) 1277_gethtent(const char *name, const struct addrinfo *pai)
1314 const char *name;
1315 const struct addrinfo *pai;
1316{ 1278{
1317 char *p; 1279 char *p;
1318 char *cp, *tname, *cname; 1280 char *cp, *tname, *cname;
@@ -1374,9 +1336,7 @@ found:
1374 1336
1375/*ARGSUSED*/ 1337/*ARGSUSED*/
1376static struct addrinfo * 1338static struct addrinfo *
1377_files_getaddrinfo(name, pai) 1339_files_getaddrinfo(const char *name, const struct addrinfo *pai)
1378 const char *name;
1379 const struct addrinfo *pai;
1380{ 1340{
1381 struct addrinfo sentinel, *cur; 1341 struct addrinfo sentinel, *cur;
1382 struct addrinfo *p; 1342 struct addrinfo *p;
@@ -1400,9 +1360,7 @@ static char *__ypdomain;
1400 1360
1401/*ARGSUSED*/ 1361/*ARGSUSED*/
1402static struct addrinfo * 1362static struct addrinfo *
1403_yphostent(line, pai) 1363_yphostent(char *line, const struct addrinfo *pai)
1404 char *line;
1405 const struct addrinfo *pai;
1406{ 1364{
1407 struct addrinfo sentinel, *cur; 1365 struct addrinfo sentinel, *cur;
1408 struct addrinfo hints, *res, *res0; 1366 struct addrinfo hints, *res, *res0;
@@ -1478,9 +1436,7 @@ done:
1478 1436
1479/*ARGSUSED*/ 1437/*ARGSUSED*/
1480static struct addrinfo * 1438static struct addrinfo *
1481_yp_getaddrinfo(name, pai) 1439_yp_getaddrinfo(const char *name, const struct addrinfo *pai)
1482 const char *name;
1483 const struct addrinfo *pai;
1484{ 1440{
1485 struct addrinfo sentinel, *cur; 1441 struct addrinfo sentinel, *cur;
1486 struct addrinfo *ai = NULL; 1442 struct addrinfo *ai = NULL;
@@ -1550,9 +1506,7 @@ extern int res_opt(int, u_char *, int, int);
1550 * Caller must parse answer and determine whether it answers the question. 1506 * Caller must parse answer and determine whether it answers the question.
1551 */ 1507 */
1552static int 1508static int
1553res_queryN(name, target) 1509res_queryN(const char *name, struct res_target *target)
1554 const char *name; /* domain name */
1555 struct res_target *target;
1556{ 1510{
1557 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 1511 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
1558 u_char *buf; 1512 u_char *buf;
@@ -1668,9 +1622,7 @@ res_queryN(name, target)
1668 * is detected. Error code, if any, is left in h_errno. 1622 * is detected. Error code, if any, is left in h_errno.
1669 */ 1623 */
1670static int 1624static int
1671res_searchN(name, target) 1625res_searchN(const char *name, struct res_target *target)
1672 const char *name; /* domain name */
1673 struct res_target *target;
1674{ 1626{
1675 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 1627 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
1676 const char *cp, * const *domain; 1628 const char *cp, * const *domain;
@@ -1808,9 +1760,8 @@ res_searchN(name, target)
1808 * removing a trailing dot from name if domain is NULL. 1760 * removing a trailing dot from name if domain is NULL.
1809 */ 1761 */
1810static int 1762static int
1811res_querydomainN(name, domain, target) 1763res_querydomainN(const char *name, const char *domain,
1812 const char *name, *domain; 1764 struct res_target *target)
1813 struct res_target *target;
1814{ 1765{
1815 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 1766 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
1816 char nbuf[MAXDNAME]; 1767 char nbuf[MAXDNAME];