diff options
| author | millert <> | 2003-10-06 19:18:09 +0000 |
|---|---|---|
| committer | millert <> | 2003-10-06 19:18:09 +0000 |
| commit | 277f2be8038aabd4fe7853d4c45ba79f7732b845 (patch) | |
| tree | 6c30f5e5eac4b0c436d8cfb56a76a3ab294b55a8 | |
| parent | cf7d98dd2f6946868dc8344ce30b64791005f29b (diff) | |
| download | openbsd-277f2be8038aabd4fe7853d4c45ba79f7732b845.tar.gz openbsd-277f2be8038aabd4fe7853d4c45ba79f7732b845.tar.bz2 openbsd-277f2be8038aabd4fe7853d4c45ba79f7732b845.zip | |
ANSIfication; most from Patrick Latifi
OK deraadt@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 111 |
1 files changed, 39 insertions, 72 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 89afb634f1..ee4af36191 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
| @@ -48,7 +48,7 @@ | |||
| 48 | */ | 48 | */ |
| 49 | 49 | ||
| 50 | #if defined(LIBC_SCCS) && !defined(lint) | 50 | #if defined(LIBC_SCCS) && !defined(lint) |
| 51 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.58 2003/10/03 19:48:10 millert Exp $"; | 51 | static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.59 2003/10/06 19:18:09 millert Exp $"; |
| 52 | #endif /* LIBC_SCCS and not lint */ | 52 | #endif /* LIBC_SCCS and not lint */ |
| 53 | 53 | ||
| 54 | #include <sys/param.h> | 54 | #include <sys/param.h> |
| @@ -123,8 +123,7 @@ static struct hostent *getanswer(const querybuf *, int, const char *, int); | |||
| 123 | extern int h_errno; | 123 | extern int h_errno; |
| 124 | 124 | ||
| 125 | int | 125 | int |
| 126 | _hokchar(p) | 126 | _hokchar(const char *p) |
| 127 | const char *p; | ||
| 128 | { | 127 | { |
| 129 | char c; | 128 | char c; |
| 130 | 129 | ||
| @@ -150,11 +149,7 @@ _hokchar(p) | |||
| 150 | } | 149 | } |
| 151 | 150 | ||
| 152 | static struct hostent * | 151 | static struct hostent * |
| 153 | getanswer(answer, anslen, qname, qtype) | 152 | getanswer(const querybuf *answer, int anslen, const char *qname, int qtype) |
| 154 | const querybuf *answer; | ||
| 155 | int anslen; | ||
| 156 | const char *qname; | ||
| 157 | int qtype; | ||
| 158 | { | 153 | { |
| 159 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 154 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 160 | const HEADER *hp; | 155 | const HEADER *hp; |
| @@ -370,7 +365,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 370 | } | 365 | } |
| 371 | } | 366 | } |
| 372 | if (!haveanswer) { | 367 | if (!haveanswer) { |
| 373 | register int nn; | 368 | int nn; |
| 374 | 369 | ||
| 375 | host.h_name = bp; | 370 | host.h_name = bp; |
| 376 | nn = strlen(bp) + 1; /* for the \0 */ | 371 | nn = strlen(bp) + 1; /* for the \0 */ |
| @@ -444,12 +439,8 @@ getanswer(answer, anslen, qname, qtype) | |||
| 444 | */ | 439 | */ |
| 445 | 440 | ||
| 446 | struct hostent * | 441 | struct hostent * |
| 447 | gethostbyname_r(name, hp, buf, buflen, errorp) | 442 | gethostbyname_r(const char *name, struct hostent *hp, char *buf, int buflen, |
| 448 | const char * name; | 443 | int *errorp) |
| 449 | struct hostent * hp; | ||
| 450 | char * buf; | ||
| 451 | int buflen; | ||
| 452 | int * errorp; | ||
| 453 | { | 444 | { |
| 454 | struct hostent *res; | 445 | struct hostent *res; |
| 455 | 446 | ||
| @@ -465,13 +456,8 @@ gethostbyname_r(name, hp, buf, buflen, errorp) | |||
| 465 | * XXX This is an extremely bogus implementation. | 456 | * XXX This is an extremely bogus implementation. |
| 466 | */ | 457 | */ |
| 467 | struct hostent * | 458 | struct hostent * |
| 468 | gethostbyaddr_r(addr, len, af, he, buf, buflen, errorp) | 459 | gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, |
| 469 | const char *addr; /* XXX should have been def'd as u_char! */ | 460 | char *buf, int buflen, int *errorp) |
| 470 | int len, af; | ||
| 471 | struct hostent * he; | ||
| 472 | char * buf; | ||
| 473 | int buflen; | ||
| 474 | int * errorp; | ||
| 475 | { | 461 | { |
| 476 | struct hostent * res; | 462 | struct hostent * res; |
| 477 | 463 | ||
| @@ -487,12 +473,11 @@ gethostbyaddr_r(addr, len, af, he, buf, buflen, errorp) | |||
| 487 | #endif | 473 | #endif |
| 488 | 474 | ||
| 489 | struct hostent * | 475 | struct hostent * |
| 490 | gethostbyname(name) | 476 | gethostbyname(const char *name) |
| 491 | const char *name; | ||
| 492 | { | 477 | { |
| 493 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 478 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 494 | struct hostent *hp; | 479 | struct hostent *hp; |
| 495 | extern struct hostent *_gethtbyname2(); | 480 | extern struct hostent *_gethtbyname2(const char *, int); |
| 496 | 481 | ||
| 497 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) | 482 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 498 | hp = _gethtbyname2(name, AF_INET); | 483 | hp = _gethtbyname2(name, AF_INET); |
| @@ -508,18 +493,17 @@ gethostbyname(name) | |||
| 508 | } | 493 | } |
| 509 | 494 | ||
| 510 | struct hostent * | 495 | struct hostent * |
| 511 | gethostbyname2(name, af) | 496 | gethostbyname2(const char *name, int af) |
| 512 | const char *name; | ||
| 513 | int af; | ||
| 514 | { | 497 | { |
| 515 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 498 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 516 | querybuf *buf; | 499 | querybuf *buf; |
| 517 | register const char *cp; | 500 | const char *cp; |
| 518 | char *bp, *ep; | 501 | char *bp, *ep; |
| 519 | int n, size, type, i; | 502 | int n, size, type, i; |
| 520 | extern struct hostent *_gethtbyname2(), *_yp_gethtbyname(); | 503 | struct hostent *hp; |
| 521 | register struct hostent *hp; | ||
| 522 | char lookups[MAXDNSLUS]; | 504 | char lookups[MAXDNSLUS]; |
| 505 | extern struct hostent *_gethtbyname2(const char *, int); | ||
| 506 | extern struct hostent *_yp_gethtbyname(const char *); | ||
| 523 | 507 | ||
| 524 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) | 508 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 525 | return (_gethtbyname2(name, af)); | 509 | return (_gethtbyname2(name, af)); |
| @@ -656,19 +640,18 @@ gethostbyname2(name, af) | |||
| 656 | } | 640 | } |
| 657 | 641 | ||
| 658 | struct hostent * | 642 | struct hostent * |
| 659 | gethostbyaddr(addr, len, af) | 643 | gethostbyaddr(const char *addr, int len, int af) |
| 660 | const char *addr; /* XXX should have been def'd as u_char! */ | ||
| 661 | int len, af; | ||
| 662 | { | 644 | { |
| 663 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 645 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 664 | const u_char *uaddr = (const u_char *)addr; | 646 | const u_char *uaddr = (const u_char *)addr; |
| 665 | int n, size, i; | 647 | int n, size, i; |
| 666 | querybuf *buf; | 648 | querybuf *buf; |
| 667 | register struct hostent *hp; | 649 | struct hostent *hp; |
| 668 | char qbuf[MAXDNAME+1], *qp, *ep; | 650 | char qbuf[MAXDNAME+1], *qp, *ep; |
| 669 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); | ||
| 670 | char lookups[MAXDNSLUS]; | 651 | char lookups[MAXDNSLUS]; |
| 671 | struct hostent *res; | 652 | struct hostent *res; |
| 653 | extern struct hostent *_gethtbyaddr(const char *, int, int); | ||
| 654 | extern struct hostent *_yp_gethtbyaddr(const char *); | ||
| 672 | 655 | ||
| 673 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { | 656 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 674 | res = _gethtbyaddr(addr, len, af); | 657 | res = _gethtbyaddr(addr, len, af); |
| @@ -792,8 +775,7 @@ gethostbyaddr(addr, len, af) | |||
| 792 | } | 775 | } |
| 793 | 776 | ||
| 794 | void | 777 | void |
| 795 | _sethtent(f) | 778 | _sethtent(int f) |
| 796 | int f; | ||
| 797 | { | 779 | { |
| 798 | if (hostf == NULL) | 780 | if (hostf == NULL) |
| 799 | hostf = fopen(_PATH_HOSTS, "r" ); | 781 | hostf = fopen(_PATH_HOSTS, "r" ); |
| @@ -803,7 +785,7 @@ _sethtent(f) | |||
| 803 | } | 785 | } |
| 804 | 786 | ||
| 805 | void | 787 | void |
| 806 | _endhtent() | 788 | _endhtent(void) |
| 807 | { | 789 | { |
| 808 | if (hostf && !stayopen) { | 790 | if (hostf && !stayopen) { |
| 809 | (void) fclose(hostf); | 791 | (void) fclose(hostf); |
| @@ -812,11 +794,10 @@ _endhtent() | |||
| 812 | } | 794 | } |
| 813 | 795 | ||
| 814 | struct hostent * | 796 | struct hostent * |
| 815 | _gethtent() | 797 | _gethtent(void) |
| 816 | { | 798 | { |
| 817 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 799 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 818 | char *p; | 800 | char *p, *cp, **q; |
| 819 | register char *cp, **q; | ||
| 820 | int af; | 801 | int af; |
| 821 | size_t len; | 802 | size_t len; |
| 822 | 803 | ||
| @@ -895,12 +876,11 @@ _gethtent() | |||
| 895 | } | 876 | } |
| 896 | 877 | ||
| 897 | struct hostent * | 878 | struct hostent * |
| 898 | _gethtbyname(name) | 879 | _gethtbyname(const char *name) |
| 899 | const char *name; | ||
| 900 | { | 880 | { |
| 901 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 881 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 902 | extern struct hostent *_gethtbyname2(); | ||
| 903 | struct hostent *hp; | 882 | struct hostent *hp; |
| 883 | extern struct hostent *_gethtbyname2(const char *, int); | ||
| 904 | 884 | ||
| 905 | if (_resp->options & RES_USE_INET6) { | 885 | if (_resp->options & RES_USE_INET6) { |
| 906 | hp = _gethtbyname2(name, AF_INET6); | 886 | hp = _gethtbyname2(name, AF_INET6); |
| @@ -911,12 +891,10 @@ _gethtbyname(name) | |||
| 911 | } | 891 | } |
| 912 | 892 | ||
| 913 | struct hostent * | 893 | struct hostent * |
| 914 | _gethtbyname2(name, af) | 894 | _gethtbyname2(const char *name, int af) |
| 915 | const char *name; | ||
| 916 | int af; | ||
| 917 | { | 895 | { |
| 918 | register struct hostent *p; | 896 | struct hostent *p; |
| 919 | register char **cp; | 897 | char **cp; |
| 920 | 898 | ||
| 921 | _sethtent(0); | 899 | _sethtent(0); |
| 922 | while ((p = _gethtent())) { | 900 | while ((p = _gethtent())) { |
| @@ -934,11 +912,9 @@ _gethtbyname2(name, af) | |||
| 934 | } | 912 | } |
| 935 | 913 | ||
| 936 | struct hostent * | 914 | struct hostent * |
| 937 | _gethtbyaddr(addr, len, af) | 915 | _gethtbyaddr(const char *addr, int len, int af) |
| 938 | const char *addr; | ||
| 939 | int len, af; | ||
| 940 | { | 916 | { |
| 941 | register struct hostent *p; | 917 | struct hostent *p; |
| 942 | 918 | ||
| 943 | host.h_length = len; | 919 | host.h_length = len; |
| 944 | host.h_addrtype = af; | 920 | host.h_addrtype = af; |
| @@ -953,8 +929,7 @@ _gethtbyaddr(addr, len, af) | |||
| 953 | 929 | ||
| 954 | #ifdef YP | 930 | #ifdef YP |
| 955 | struct hostent * | 931 | struct hostent * |
| 956 | _yphostent(line) | 932 | _yphostent(char *line) |
| 957 | char *line; | ||
| 958 | { | 933 | { |
| 959 | static struct in_addr host_addrs[MAXADDRS]; | 934 | static struct in_addr host_addrs[MAXADDRS]; |
| 960 | char *p = line; | 935 | char *p = line; |
| @@ -1028,8 +1003,7 @@ done: | |||
| 1028 | } | 1003 | } |
| 1029 | 1004 | ||
| 1030 | struct hostent * | 1005 | struct hostent * |
| 1031 | _yp_gethtbyaddr(addr) | 1006 | _yp_gethtbyaddr(const char *addr) |
| 1032 | const char *addr; | ||
| 1033 | { | 1007 | { |
| 1034 | struct hostent *hp = (struct hostent *)NULL; | 1008 | struct hostent *hp = (struct hostent *)NULL; |
| 1035 | static char *__ypcurrent; | 1009 | static char *__ypcurrent; |
| @@ -1056,8 +1030,7 @@ _yp_gethtbyaddr(addr) | |||
| 1056 | } | 1030 | } |
| 1057 | 1031 | ||
| 1058 | struct hostent * | 1032 | struct hostent * |
| 1059 | _yp_gethtbyname(name) | 1033 | _yp_gethtbyname(const char *name) |
| 1060 | const char *name; | ||
| 1061 | { | 1034 | { |
| 1062 | struct hostent *hp = (struct hostent *)NULL; | 1035 | struct hostent *hp = (struct hostent *)NULL; |
| 1063 | static char *__ypcurrent; | 1036 | static char *__ypcurrent; |
| @@ -1083,9 +1056,7 @@ _yp_gethtbyname(name) | |||
| 1083 | #endif | 1056 | #endif |
| 1084 | 1057 | ||
| 1085 | static void | 1058 | static void |
| 1086 | map_v4v6_address(src, dst) | 1059 | map_v4v6_address(const char *src, char *dst) |
| 1087 | const char *src; | ||
| 1088 | char *dst; | ||
| 1089 | { | 1060 | { |
| 1090 | u_char *p = (u_char *)dst; | 1061 | u_char *p = (u_char *)dst; |
| 1091 | char tmp[INADDRSZ]; | 1062 | char tmp[INADDRSZ]; |
| @@ -1103,10 +1074,7 @@ map_v4v6_address(src, dst) | |||
| 1103 | } | 1074 | } |
| 1104 | 1075 | ||
| 1105 | static void | 1076 | static void |
| 1106 | map_v4v6_hostent(hp, bpp, ep) | 1077 | map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) |
| 1107 | struct hostent *hp; | ||
| 1108 | char **bpp; | ||
| 1109 | char *ep; | ||
| 1110 | { | 1078 | { |
| 1111 | char **ap; | 1079 | char **ap; |
| 1112 | 1080 | ||
| @@ -1130,16 +1098,14 @@ map_v4v6_hostent(hp, bpp, ep) | |||
| 1130 | } | 1098 | } |
| 1131 | 1099 | ||
| 1132 | struct hostent * | 1100 | struct hostent * |
| 1133 | gethostent() | 1101 | gethostent(void) |
| 1134 | { | 1102 | { |
| 1135 | return (_gethtent()); | 1103 | return (_gethtent()); |
| 1136 | } | 1104 | } |
| 1137 | 1105 | ||
| 1138 | #ifdef RESOLVSORT | 1106 | #ifdef RESOLVSORT |
| 1139 | static void | 1107 | static void |
| 1140 | addrsort(ap, num) | 1108 | addrsort(char **ap, int num) |
| 1141 | char **ap; | ||
| 1142 | int num; | ||
| 1143 | { | 1109 | { |
| 1144 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | 1110 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 1145 | int i, j; | 1111 | int i, j; |
| @@ -1151,7 +1117,8 @@ addrsort(ap, num) | |||
| 1151 | for (i = 0; i < num; i++, p++) { | 1117 | for (i = 0; i < num; i++, p++) { |
| 1152 | for (j = 0 ; (unsigned)j < _resp->nsort; j++) | 1118 | for (j = 0 ; (unsigned)j < _resp->nsort; j++) |
| 1153 | if (_resp->sort_list[j].addr.s_addr == | 1119 | if (_resp->sort_list[j].addr.s_addr == |
| 1154 | (((struct in_addr *)(*p))->s_addr & _resp->sort_list[j].mask)) | 1120 | (((struct in_addr *)(*p))->s_addr & |
| 1121 | _resp->sort_list[j].mask)) | ||
| 1155 | break; | 1122 | break; |
| 1156 | aval[i] = j; | 1123 | aval[i] = j; |
| 1157 | if (needsort == 0 && i > 0 && j < aval[i-1]) | 1124 | if (needsort == 0 && i > 0 && j < aval[i-1]) |
