From 6f82d0e8f9756938f04071892206a5af85e676f0 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Fri, 13 Jul 2012 17:49:56 +0000 Subject: This commit was manufactured by cvs2git to create tag 'eric_g2k12'. --- src/lib/libc/crypt/Makefile.inc | 15 - src/lib/libc/crypt/arc4random.3 | 138 --- src/lib/libc/crypt/arc4random.c | 254 ----- src/lib/libc/crypt/bcrypt.c | 338 ------ src/lib/libc/crypt/blowfish.3 | 106 -- src/lib/libc/crypt/blowfish.c | 685 ------------- src/lib/libc/crypt/crypt.3 | 325 ------ src/lib/libc/crypt/crypt.c | 696 ------------- src/lib/libc/crypt/crypt2.c | 104 -- src/lib/libc/crypt/md5crypt.c | 149 --- src/lib/libc/include/ctype_private.h | 7 - src/lib/libc/include/namespace.h | 18 - src/lib/libc/include/thread_private.h | 175 ---- src/lib/libc/net/Makefile.inc | 100 -- src/lib/libc/net/base64.c | 308 ------ src/lib/libc/net/byteorder.3 | 206 ---- src/lib/libc/net/ethers.3 | 124 --- src/lib/libc/net/ethers.c | 232 ----- src/lib/libc/net/freeaddrinfo.c | 50 - src/lib/libc/net/gai_strerror.3 | 95 -- src/lib/libc/net/gai_strerror.c | 78 -- src/lib/libc/net/getaddrinfo.3 | 469 --------- src/lib/libc/net/getaddrinfo.c | 1755 ------------------------------- src/lib/libc/net/gethostbyname.3 | 297 ------ src/lib/libc/net/gethostnamadr.c | 1131 -------------------- src/lib/libc/net/getifaddrs.3 | 158 --- src/lib/libc/net/getifaddrs.c | 284 ------ src/lib/libc/net/getnameinfo.3 | 264 ----- src/lib/libc/net/getnameinfo.c | 351 ------- src/lib/libc/net/getnetbyaddr.c | 47 - src/lib/libc/net/getnetbyname.c | 54 - src/lib/libc/net/getnetent.3 | 140 --- src/lib/libc/net/getnetent.c | 120 --- src/lib/libc/net/getnetnamadr.c | 384 ------- src/lib/libc/net/getpeereid.3 | 121 --- src/lib/libc/net/getpeereid.c | 36 - src/lib/libc/net/getproto.c | 59 -- src/lib/libc/net/getprotoent.3 | 213 ---- src/lib/libc/net/getprotoent.c | 166 --- src/lib/libc/net/getprotoname.c | 67 -- src/lib/libc/net/getrrsetbyname.3 | 166 --- src/lib/libc/net/getrrsetbyname.c | 517 ---------- src/lib/libc/net/getservbyname.c | 70 -- src/lib/libc/net/getservbyport.c | 64 -- src/lib/libc/net/getservent.3 | 220 ---- src/lib/libc/net/getservent.c | 168 --- src/lib/libc/net/herror.c | 106 -- src/lib/libc/net/htonl.c | 21 - src/lib/libc/net/htons.c | 21 - src/lib/libc/net/if_indextoname.3 | 144 --- src/lib/libc/net/if_indextoname.c | 86 -- src/lib/libc/net/if_nameindex.c | 146 --- src/lib/libc/net/if_nametoindex.c | 81 -- src/lib/libc/net/inet.3 | 346 ------- src/lib/libc/net/inet6_opt_init.3 | 338 ------ src/lib/libc/net/inet6_option_space.3 | 444 -------- src/lib/libc/net/inet6_rth_space.3 | 219 ---- src/lib/libc/net/inet6_rthdr_space.3 | 314 ------ src/lib/libc/net/inet_addr.c | 171 ---- src/lib/libc/net/inet_lnaof.c | 51 - src/lib/libc/net/inet_makeaddr.c | 54 - src/lib/libc/net/inet_net.3 | 197 ---- src/lib/libc/net/inet_net_ntop.c | 162 --- src/lib/libc/net/inet_net_pton.c | 230 ----- src/lib/libc/net/inet_neta.c | 80 -- src/lib/libc/net/inet_netof.c | 50 - src/lib/libc/net/inet_network.c | 84 -- src/lib/libc/net/inet_ntoa.c | 51 - src/lib/libc/net/inet_ntop.c | 195 ---- src/lib/libc/net/inet_pton.c | 213 ---- src/lib/libc/net/ip6opt.c | 596 ----------- src/lib/libc/net/link_addr.3 | 127 --- src/lib/libc/net/linkaddr.c | 148 --- src/lib/libc/net/nsap_addr.c | 94 -- src/lib/libc/net/ntohl.c | 21 - src/lib/libc/net/ntohs.c | 21 - src/lib/libc/net/rcmd.3 | 266 ----- src/lib/libc/net/rcmd.c | 303 ------ src/lib/libc/net/rcmdsh.3 | 96 -- src/lib/libc/net/rcmdsh.c | 186 ---- src/lib/libc/net/recv.c | 40 - src/lib/libc/net/res_comp.c | 475 --------- src/lib/libc/net/res_data.c | 105 -- src/lib/libc/net/res_debug.c | 1395 ------------------------- src/lib/libc/net/res_debug_syms.c | 189 ---- src/lib/libc/net/res_init.c | 707 ------------- src/lib/libc/net/res_mkquery.c | 232 ----- src/lib/libc/net/res_query.c | 403 -------- src/lib/libc/net/res_random.c | 264 ----- src/lib/libc/net/res_send.c | 853 ---------------- src/lib/libc/net/resolver.3 | 354 ------- src/lib/libc/net/rresvport.c | 107 -- src/lib/libc/net/rthdr.c | 378 ------- src/lib/libc/net/ruserok.c | 437 -------- src/lib/libc/net/send.c | 40 - src/lib/libc/net/sethostent.c | 57 -- src/lib/libc/net/vars6.c | 42 - src/lib/libc/stdlib/Makefile.inc | 73 -- src/lib/libc/stdlib/_Exit.c | 22 - src/lib/libc/stdlib/_rand48.c | 47 - src/lib/libc/stdlib/a64l.3 | 133 --- src/lib/libc/stdlib/a64l.c | 42 - src/lib/libc/stdlib/abort.3 | 63 -- src/lib/libc/stdlib/abort.c | 78 -- src/lib/libc/stdlib/abs.3 | 65 -- src/lib/libc/stdlib/abs.c | 37 - src/lib/libc/stdlib/alloca.3 | 76 -- src/lib/libc/stdlib/atexit.3 | 77 -- src/lib/libc/stdlib/atexit.c | 209 ---- src/lib/libc/stdlib/atexit.h | 51 - src/lib/libc/stdlib/atof.3 | 69 -- src/lib/libc/stdlib/atof.c | 37 - src/lib/libc/stdlib/atoi.3 | 86 -- src/lib/libc/stdlib/atoi.c | 37 - src/lib/libc/stdlib/atol.3 | 70 -- src/lib/libc/stdlib/atol.c | 37 - src/lib/libc/stdlib/atoll.3 | 70 -- src/lib/libc/stdlib/atoll.c | 38 - src/lib/libc/stdlib/bsearch.3 | 84 -- src/lib/libc/stdlib/bsearch.c | 67 -- src/lib/libc/stdlib/cfree.c | 40 - src/lib/libc/stdlib/div.3 | 64 -- src/lib/libc/stdlib/div.c | 71 -- src/lib/libc/stdlib/drand48.c | 23 - src/lib/libc/stdlib/ecvt.3 | 168 --- src/lib/libc/stdlib/ecvt.c | 107 -- src/lib/libc/stdlib/erand48.c | 24 - src/lib/libc/stdlib/exit.3 | 123 --- src/lib/libc/stdlib/exit.c | 59 -- src/lib/libc/stdlib/gcvt.c | 125 --- src/lib/libc/stdlib/getenv.3 | 187 ---- src/lib/libc/stdlib/getenv.c | 81 -- src/lib/libc/stdlib/getopt.3 | 364 ------- src/lib/libc/stdlib/getopt_long.3 | 445 -------- src/lib/libc/stdlib/getopt_long.c | 511 ---------- src/lib/libc/stdlib/getsubopt.3 | 145 --- src/lib/libc/stdlib/getsubopt.c | 92 -- src/lib/libc/stdlib/hcreate.3 | 239 ----- src/lib/libc/stdlib/hcreate.c | 191 ---- src/lib/libc/stdlib/heapsort.c | 173 ---- src/lib/libc/stdlib/imaxabs.3 | 65 -- src/lib/libc/stdlib/imaxabs.c | 38 - src/lib/libc/stdlib/imaxdiv.3 | 66 -- src/lib/libc/stdlib/imaxdiv.c | 50 - src/lib/libc/stdlib/insque.3 | 106 -- src/lib/libc/stdlib/insque.c | 48 - src/lib/libc/stdlib/jrand48.c | 22 - src/lib/libc/stdlib/l64a.c | 42 - src/lib/libc/stdlib/labs.3 | 68 -- src/lib/libc/stdlib/labs.c | 37 - src/lib/libc/stdlib/lcong48.c | 31 - src/lib/libc/stdlib/ldiv.3 | 66 -- src/lib/libc/stdlib/ldiv.c | 50 - src/lib/libc/stdlib/llabs.c | 38 - src/lib/libc/stdlib/lldiv.3 | 66 -- src/lib/libc/stdlib/lldiv.c | 50 - src/lib/libc/stdlib/lrand48.c | 24 - src/lib/libc/stdlib/lsearch.3 | 108 -- src/lib/libc/stdlib/lsearch.c | 84 -- src/lib/libc/stdlib/malloc.3 | 458 --------- src/lib/libc/stdlib/malloc.c | 1816 --------------------------------- src/lib/libc/stdlib/merge.c | 333 ------ src/lib/libc/stdlib/mrand48.c | 24 - src/lib/libc/stdlib/nrand48.c | 22 - src/lib/libc/stdlib/posix_memalign.3 | 92 -- src/lib/libc/stdlib/qabs.3 | 56 - src/lib/libc/stdlib/qabs.c | 37 - src/lib/libc/stdlib/qdiv.3 | 61 -- src/lib/libc/stdlib/qdiv.c | 50 - src/lib/libc/stdlib/qsort.3 | 233 ----- src/lib/libc/stdlib/qsort.c | 162 --- src/lib/libc/stdlib/radixsort.3 | 155 --- src/lib/libc/stdlib/radixsort.c | 294 ------ src/lib/libc/stdlib/rand.3 | 97 -- src/lib/libc/stdlib/rand.c | 52 - src/lib/libc/stdlib/rand48.3 | 179 ---- src/lib/libc/stdlib/rand48.h | 32 - src/lib/libc/stdlib/random.3 | 185 ---- src/lib/libc/stdlib/random.c | 396 ------- src/lib/libc/stdlib/realpath.3 | 130 --- src/lib/libc/stdlib/realpath.c | 212 ---- src/lib/libc/stdlib/remque.c | 44 - src/lib/libc/stdlib/seed48.c | 37 - src/lib/libc/stdlib/setenv.c | 178 ---- src/lib/libc/stdlib/srand48.c | 31 - src/lib/libc/stdlib/strtod.3 | 145 --- src/lib/libc/stdlib/strtoimax.c | 140 --- src/lib/libc/stdlib/strtol.3 | 264 ----- src/lib/libc/stdlib/strtol.c | 140 --- src/lib/libc/stdlib/strtoll.c | 153 --- src/lib/libc/stdlib/strtonum.3 | 152 --- src/lib/libc/stdlib/strtonum.c | 65 -- src/lib/libc/stdlib/strtoul.3 | 245 ----- src/lib/libc/stdlib/strtoul.c | 102 -- src/lib/libc/stdlib/strtoull.c | 115 --- src/lib/libc/stdlib/strtoumax.c | 102 -- src/lib/libc/stdlib/system.3 | 104 -- src/lib/libc/stdlib/system.c | 74 -- src/lib/libc/stdlib/tfind.c | 41 - src/lib/libc/stdlib/tsearch.3 | 130 --- src/lib/libc/stdlib/tsearch.c | 119 --- src/lib/libc/string/Makefile.inc | 172 ---- src/lib/libc/string/bcmp.3 | 88 -- src/lib/libc/string/bcmp.c | 55 - src/lib/libc/string/bcopy.3 | 67 -- src/lib/libc/string/bcopy.c | 128 --- src/lib/libc/string/bm.3 | 120 --- src/lib/libc/string/bm.c | 205 ---- src/lib/libc/string/bstring.3 | 108 -- src/lib/libc/string/bzero.3 | 61 -- src/lib/libc/string/bzero.c | 48 - src/lib/libc/string/ffs.3 | 61 -- src/lib/libc/string/ffs.c | 44 - src/lib/libc/string/index.c | 47 - src/lib/libc/string/memccpy.3 | 75 -- src/lib/libc/string/memccpy.c | 48 - src/lib/libc/string/memchr.3 | 101 -- src/lib/libc/string/memchr.c | 48 - src/lib/libc/string/memcmp.3 | 85 -- src/lib/libc/string/memcmp.c | 51 - src/lib/libc/string/memcpy.3 | 85 -- src/lib/libc/string/memmove.3 | 76 -- src/lib/libc/string/memrchr.c | 38 - src/lib/libc/string/memset.3 | 75 -- src/lib/libc/string/memset.c | 47 - src/lib/libc/string/rindex.c | 49 - src/lib/libc/string/stpcpy.3 | 117 --- src/lib/libc/string/stpcpy.c | 44 - src/lib/libc/string/stpncpy.c | 56 - src/lib/libc/string/strcasecmp.3 | 92 -- src/lib/libc/string/strcasecmp.c | 105 -- src/lib/libc/string/strcasestr.c | 60 -- src/lib/libc/string/strcat.3 | 141 --- src/lib/libc/string/strcat.c | 51 - src/lib/libc/string/strchr.3 | 114 --- src/lib/libc/string/strcmp.3 | 95 -- src/lib/libc/string/strcmp.c | 51 - src/lib/libc/string/strcoll.3 | 73 -- src/lib/libc/string/strcoll.c | 44 - src/lib/libc/string/strcpy.3 | 162 --- src/lib/libc/string/strcpy.c | 50 - src/lib/libc/string/strcspn.3 | 108 -- src/lib/libc/string/strcspn.c | 58 -- src/lib/libc/string/strdup.3 | 112 -- src/lib/libc/string/strdup.c | 49 - src/lib/libc/string/strerror.3 | 122 --- src/lib/libc/string/strerror.c | 41 - src/lib/libc/string/strerror_r.c | 137 --- src/lib/libc/string/string.3 | 136 --- src/lib/libc/string/strlcat.c | 55 - src/lib/libc/string/strlcpy.3 | 182 ---- src/lib/libc/string/strlcpy.c | 51 - src/lib/libc/string/strlen.3 | 104 -- src/lib/libc/string/strlen.c | 47 - src/lib/libc/string/strmode.3 | 157 --- src/lib/libc/string/strmode.c | 140 --- src/lib/libc/string/strncat.c | 57 -- src/lib/libc/string/strncmp.c | 51 - src/lib/libc/string/strncpy.c | 62 -- src/lib/libc/string/strndup.c | 39 - src/lib/libc/string/strnlen.c | 36 - src/lib/libc/string/strpbrk.3 | 80 -- src/lib/libc/string/strpbrk.c | 48 - src/lib/libc/string/strrchr.3 | 116 --- src/lib/libc/string/strsep.3 | 110 -- src/lib/libc/string/strsep.c | 71 -- src/lib/libc/string/strsignal.3 | 68 -- src/lib/libc/string/strsignal.c | 41 - src/lib/libc/string/strspn.3 | 92 -- src/lib/libc/string/strspn.c | 51 - src/lib/libc/string/strstr.3 | 100 -- src/lib/libc/string/strstr.c | 56 - src/lib/libc/string/strtok.3 | 166 --- src/lib/libc/string/strtok.c | 86 -- src/lib/libc/string/strxfrm.3 | 79 -- src/lib/libc/string/strxfrm.c | 51 - src/lib/libc/string/swab.3 | 61 -- src/lib/libc/string/swab.c | 61 -- src/lib/libc/string/timingsafe_bcmp.c | 33 - src/lib/libc/string/wcscasecmp.3 | 94 -- src/lib/libc/string/wcscasecmp.c | 61 -- src/lib/libc/string/wcscat.3 | 115 --- src/lib/libc/string/wcscat.c | 55 - src/lib/libc/string/wcschr.3 | 85 -- src/lib/libc/string/wcschr.c | 50 - src/lib/libc/string/wcscmp.3 | 92 -- src/lib/libc/string/wcscmp.c | 51 - src/lib/libc/string/wcscpy.3 | 123 --- src/lib/libc/string/wcscpy.c | 52 - src/lib/libc/string/wcscspn.3 | 83 -- src/lib/libc/string/wcscspn.c | 53 - src/lib/libc/string/wcsdup.3 | 97 -- src/lib/libc/string/wcsdup.c | 31 - src/lib/libc/string/wcslcat.c | 56 - src/lib/libc/string/wcslcpy.3 | 147 --- src/lib/libc/string/wcslcpy.c | 52 - src/lib/libc/string/wcslen.3 | 70 -- src/lib/libc/string/wcslen.c | 44 - src/lib/libc/string/wcsncat.c | 52 - src/lib/libc/string/wcsncmp.c | 52 - src/lib/libc/string/wcsncpy.c | 50 - src/lib/libc/string/wcspbrk.3 | 81 -- src/lib/libc/string/wcspbrk.c | 53 - src/lib/libc/string/wcsrchr.3 | 85 -- src/lib/libc/string/wcsrchr.c | 50 - src/lib/libc/string/wcsspn.3 | 79 -- src/lib/libc/string/wcsspn.c | 55 - src/lib/libc/string/wcsstr.3 | 88 -- src/lib/libc/string/wcsstr.c | 70 -- src/lib/libc/string/wcstok.3 | 151 --- src/lib/libc/string/wcstok.c | 93 -- src/lib/libc/string/wcswcs.c | 5 - src/lib/libc/string/wcswidth.3 | 69 -- src/lib/libc/string/wcswidth.c | 50 - src/lib/libc/string/wmemchr.3 | 81 -- src/lib/libc/string/wmemchr.c | 47 - src/lib/libc/string/wmemcmp.3 | 78 -- src/lib/libc/string/wmemcmp.c | 50 - src/lib/libc/string/wmemcpy.3 | 85 -- src/lib/libc/string/wmemcpy.c | 40 - src/lib/libc/string/wmemmove.3 | 78 -- src/lib/libc/string/wmemmove.c | 40 - src/lib/libc/string/wmemset.3 | 73 -- src/lib/libc/string/wmemset.c | 46 - 324 files changed, 46043 deletions(-) delete mode 100644 src/lib/libc/crypt/Makefile.inc delete mode 100644 src/lib/libc/crypt/arc4random.3 delete mode 100644 src/lib/libc/crypt/arc4random.c delete mode 100644 src/lib/libc/crypt/bcrypt.c delete mode 100644 src/lib/libc/crypt/blowfish.3 delete mode 100644 src/lib/libc/crypt/blowfish.c delete mode 100644 src/lib/libc/crypt/crypt.3 delete mode 100644 src/lib/libc/crypt/crypt.c delete mode 100644 src/lib/libc/crypt/crypt2.c delete mode 100644 src/lib/libc/crypt/md5crypt.c delete mode 100644 src/lib/libc/include/ctype_private.h delete mode 100644 src/lib/libc/include/namespace.h delete mode 100644 src/lib/libc/include/thread_private.h delete mode 100644 src/lib/libc/net/Makefile.inc delete mode 100644 src/lib/libc/net/base64.c delete mode 100644 src/lib/libc/net/byteorder.3 delete mode 100644 src/lib/libc/net/ethers.3 delete mode 100644 src/lib/libc/net/ethers.c delete mode 100644 src/lib/libc/net/freeaddrinfo.c delete mode 100644 src/lib/libc/net/gai_strerror.3 delete mode 100644 src/lib/libc/net/gai_strerror.c delete mode 100644 src/lib/libc/net/getaddrinfo.3 delete mode 100644 src/lib/libc/net/getaddrinfo.c delete mode 100644 src/lib/libc/net/gethostbyname.3 delete mode 100644 src/lib/libc/net/gethostnamadr.c delete mode 100644 src/lib/libc/net/getifaddrs.3 delete mode 100644 src/lib/libc/net/getifaddrs.c delete mode 100644 src/lib/libc/net/getnameinfo.3 delete mode 100644 src/lib/libc/net/getnameinfo.c delete mode 100644 src/lib/libc/net/getnetbyaddr.c delete mode 100644 src/lib/libc/net/getnetbyname.c delete mode 100644 src/lib/libc/net/getnetent.3 delete mode 100644 src/lib/libc/net/getnetent.c delete mode 100644 src/lib/libc/net/getnetnamadr.c delete mode 100644 src/lib/libc/net/getpeereid.3 delete mode 100644 src/lib/libc/net/getpeereid.c delete mode 100644 src/lib/libc/net/getproto.c delete mode 100644 src/lib/libc/net/getprotoent.3 delete mode 100644 src/lib/libc/net/getprotoent.c delete mode 100644 src/lib/libc/net/getprotoname.c delete mode 100644 src/lib/libc/net/getrrsetbyname.3 delete mode 100644 src/lib/libc/net/getrrsetbyname.c delete mode 100644 src/lib/libc/net/getservbyname.c delete mode 100644 src/lib/libc/net/getservbyport.c delete mode 100644 src/lib/libc/net/getservent.3 delete mode 100644 src/lib/libc/net/getservent.c delete mode 100644 src/lib/libc/net/herror.c delete mode 100644 src/lib/libc/net/htonl.c delete mode 100644 src/lib/libc/net/htons.c delete mode 100644 src/lib/libc/net/if_indextoname.3 delete mode 100644 src/lib/libc/net/if_indextoname.c delete mode 100644 src/lib/libc/net/if_nameindex.c delete mode 100644 src/lib/libc/net/if_nametoindex.c delete mode 100644 src/lib/libc/net/inet.3 delete mode 100644 src/lib/libc/net/inet6_opt_init.3 delete mode 100644 src/lib/libc/net/inet6_option_space.3 delete mode 100644 src/lib/libc/net/inet6_rth_space.3 delete mode 100644 src/lib/libc/net/inet6_rthdr_space.3 delete mode 100644 src/lib/libc/net/inet_addr.c delete mode 100644 src/lib/libc/net/inet_lnaof.c delete mode 100644 src/lib/libc/net/inet_makeaddr.c delete mode 100644 src/lib/libc/net/inet_net.3 delete mode 100644 src/lib/libc/net/inet_net_ntop.c delete mode 100644 src/lib/libc/net/inet_net_pton.c delete mode 100644 src/lib/libc/net/inet_neta.c delete mode 100644 src/lib/libc/net/inet_netof.c delete mode 100644 src/lib/libc/net/inet_network.c delete mode 100644 src/lib/libc/net/inet_ntoa.c delete mode 100644 src/lib/libc/net/inet_ntop.c delete mode 100644 src/lib/libc/net/inet_pton.c delete mode 100644 src/lib/libc/net/ip6opt.c delete mode 100644 src/lib/libc/net/link_addr.3 delete mode 100644 src/lib/libc/net/linkaddr.c delete mode 100644 src/lib/libc/net/nsap_addr.c delete mode 100644 src/lib/libc/net/ntohl.c delete mode 100644 src/lib/libc/net/ntohs.c delete mode 100644 src/lib/libc/net/rcmd.3 delete mode 100644 src/lib/libc/net/rcmd.c delete mode 100644 src/lib/libc/net/rcmdsh.3 delete mode 100644 src/lib/libc/net/rcmdsh.c delete mode 100644 src/lib/libc/net/recv.c delete mode 100644 src/lib/libc/net/res_comp.c delete mode 100644 src/lib/libc/net/res_data.c delete mode 100644 src/lib/libc/net/res_debug.c delete mode 100644 src/lib/libc/net/res_debug_syms.c delete mode 100644 src/lib/libc/net/res_init.c delete mode 100644 src/lib/libc/net/res_mkquery.c delete mode 100644 src/lib/libc/net/res_query.c delete mode 100644 src/lib/libc/net/res_random.c delete mode 100644 src/lib/libc/net/res_send.c delete mode 100644 src/lib/libc/net/resolver.3 delete mode 100644 src/lib/libc/net/rresvport.c delete mode 100644 src/lib/libc/net/rthdr.c delete mode 100644 src/lib/libc/net/ruserok.c delete mode 100644 src/lib/libc/net/send.c delete mode 100644 src/lib/libc/net/sethostent.c delete mode 100644 src/lib/libc/net/vars6.c delete mode 100644 src/lib/libc/stdlib/Makefile.inc delete mode 100644 src/lib/libc/stdlib/_Exit.c delete mode 100644 src/lib/libc/stdlib/_rand48.c delete mode 100644 src/lib/libc/stdlib/a64l.3 delete mode 100644 src/lib/libc/stdlib/a64l.c delete mode 100644 src/lib/libc/stdlib/abort.3 delete mode 100644 src/lib/libc/stdlib/abort.c delete mode 100644 src/lib/libc/stdlib/abs.3 delete mode 100644 src/lib/libc/stdlib/abs.c delete mode 100644 src/lib/libc/stdlib/alloca.3 delete mode 100644 src/lib/libc/stdlib/atexit.3 delete mode 100644 src/lib/libc/stdlib/atexit.c delete mode 100644 src/lib/libc/stdlib/atexit.h delete mode 100644 src/lib/libc/stdlib/atof.3 delete mode 100644 src/lib/libc/stdlib/atof.c delete mode 100644 src/lib/libc/stdlib/atoi.3 delete mode 100644 src/lib/libc/stdlib/atoi.c delete mode 100644 src/lib/libc/stdlib/atol.3 delete mode 100644 src/lib/libc/stdlib/atol.c delete mode 100644 src/lib/libc/stdlib/atoll.3 delete mode 100644 src/lib/libc/stdlib/atoll.c delete mode 100644 src/lib/libc/stdlib/bsearch.3 delete mode 100644 src/lib/libc/stdlib/bsearch.c delete mode 100644 src/lib/libc/stdlib/cfree.c delete mode 100644 src/lib/libc/stdlib/div.3 delete mode 100644 src/lib/libc/stdlib/div.c delete mode 100644 src/lib/libc/stdlib/drand48.c delete mode 100644 src/lib/libc/stdlib/ecvt.3 delete mode 100644 src/lib/libc/stdlib/ecvt.c delete mode 100644 src/lib/libc/stdlib/erand48.c delete mode 100644 src/lib/libc/stdlib/exit.3 delete mode 100644 src/lib/libc/stdlib/exit.c delete mode 100644 src/lib/libc/stdlib/gcvt.c delete mode 100644 src/lib/libc/stdlib/getenv.3 delete mode 100644 src/lib/libc/stdlib/getenv.c delete mode 100644 src/lib/libc/stdlib/getopt.3 delete mode 100644 src/lib/libc/stdlib/getopt_long.3 delete mode 100644 src/lib/libc/stdlib/getopt_long.c delete mode 100644 src/lib/libc/stdlib/getsubopt.3 delete mode 100644 src/lib/libc/stdlib/getsubopt.c delete mode 100644 src/lib/libc/stdlib/hcreate.3 delete mode 100644 src/lib/libc/stdlib/hcreate.c delete mode 100644 src/lib/libc/stdlib/heapsort.c delete mode 100644 src/lib/libc/stdlib/imaxabs.3 delete mode 100644 src/lib/libc/stdlib/imaxabs.c delete mode 100644 src/lib/libc/stdlib/imaxdiv.3 delete mode 100644 src/lib/libc/stdlib/imaxdiv.c delete mode 100644 src/lib/libc/stdlib/insque.3 delete mode 100644 src/lib/libc/stdlib/insque.c delete mode 100644 src/lib/libc/stdlib/jrand48.c delete mode 100644 src/lib/libc/stdlib/l64a.c delete mode 100644 src/lib/libc/stdlib/labs.3 delete mode 100644 src/lib/libc/stdlib/labs.c delete mode 100644 src/lib/libc/stdlib/lcong48.c delete mode 100644 src/lib/libc/stdlib/ldiv.3 delete mode 100644 src/lib/libc/stdlib/ldiv.c delete mode 100644 src/lib/libc/stdlib/llabs.c delete mode 100644 src/lib/libc/stdlib/lldiv.3 delete mode 100644 src/lib/libc/stdlib/lldiv.c delete mode 100644 src/lib/libc/stdlib/lrand48.c delete mode 100644 src/lib/libc/stdlib/lsearch.3 delete mode 100644 src/lib/libc/stdlib/lsearch.c delete mode 100644 src/lib/libc/stdlib/malloc.3 delete mode 100644 src/lib/libc/stdlib/malloc.c delete mode 100644 src/lib/libc/stdlib/merge.c delete mode 100644 src/lib/libc/stdlib/mrand48.c delete mode 100644 src/lib/libc/stdlib/nrand48.c delete mode 100644 src/lib/libc/stdlib/posix_memalign.3 delete mode 100644 src/lib/libc/stdlib/qabs.3 delete mode 100644 src/lib/libc/stdlib/qabs.c delete mode 100644 src/lib/libc/stdlib/qdiv.3 delete mode 100644 src/lib/libc/stdlib/qdiv.c delete mode 100644 src/lib/libc/stdlib/qsort.3 delete mode 100644 src/lib/libc/stdlib/qsort.c delete mode 100644 src/lib/libc/stdlib/radixsort.3 delete mode 100644 src/lib/libc/stdlib/radixsort.c delete mode 100644 src/lib/libc/stdlib/rand.3 delete mode 100644 src/lib/libc/stdlib/rand.c delete mode 100644 src/lib/libc/stdlib/rand48.3 delete mode 100644 src/lib/libc/stdlib/rand48.h delete mode 100644 src/lib/libc/stdlib/random.3 delete mode 100644 src/lib/libc/stdlib/random.c delete mode 100644 src/lib/libc/stdlib/realpath.3 delete mode 100644 src/lib/libc/stdlib/realpath.c delete mode 100644 src/lib/libc/stdlib/remque.c delete mode 100644 src/lib/libc/stdlib/seed48.c delete mode 100644 src/lib/libc/stdlib/setenv.c delete mode 100644 src/lib/libc/stdlib/srand48.c delete mode 100644 src/lib/libc/stdlib/strtod.3 delete mode 100644 src/lib/libc/stdlib/strtoimax.c delete mode 100644 src/lib/libc/stdlib/strtol.3 delete mode 100644 src/lib/libc/stdlib/strtol.c delete mode 100644 src/lib/libc/stdlib/strtoll.c delete mode 100644 src/lib/libc/stdlib/strtonum.3 delete mode 100644 src/lib/libc/stdlib/strtonum.c delete mode 100644 src/lib/libc/stdlib/strtoul.3 delete mode 100644 src/lib/libc/stdlib/strtoul.c delete mode 100644 src/lib/libc/stdlib/strtoull.c delete mode 100644 src/lib/libc/stdlib/strtoumax.c delete mode 100644 src/lib/libc/stdlib/system.3 delete mode 100644 src/lib/libc/stdlib/system.c delete mode 100644 src/lib/libc/stdlib/tfind.c delete mode 100644 src/lib/libc/stdlib/tsearch.3 delete mode 100644 src/lib/libc/stdlib/tsearch.c delete mode 100644 src/lib/libc/string/Makefile.inc delete mode 100644 src/lib/libc/string/bcmp.3 delete mode 100644 src/lib/libc/string/bcmp.c delete mode 100644 src/lib/libc/string/bcopy.3 delete mode 100644 src/lib/libc/string/bcopy.c delete mode 100644 src/lib/libc/string/bm.3 delete mode 100644 src/lib/libc/string/bm.c delete mode 100644 src/lib/libc/string/bstring.3 delete mode 100644 src/lib/libc/string/bzero.3 delete mode 100644 src/lib/libc/string/bzero.c delete mode 100644 src/lib/libc/string/ffs.3 delete mode 100644 src/lib/libc/string/ffs.c delete mode 100644 src/lib/libc/string/index.c delete mode 100644 src/lib/libc/string/memccpy.3 delete mode 100644 src/lib/libc/string/memccpy.c delete mode 100644 src/lib/libc/string/memchr.3 delete mode 100644 src/lib/libc/string/memchr.c delete mode 100644 src/lib/libc/string/memcmp.3 delete mode 100644 src/lib/libc/string/memcmp.c delete mode 100644 src/lib/libc/string/memcpy.3 delete mode 100644 src/lib/libc/string/memmove.3 delete mode 100644 src/lib/libc/string/memrchr.c delete mode 100644 src/lib/libc/string/memset.3 delete mode 100644 src/lib/libc/string/memset.c delete mode 100644 src/lib/libc/string/rindex.c delete mode 100644 src/lib/libc/string/stpcpy.3 delete mode 100644 src/lib/libc/string/stpcpy.c delete mode 100644 src/lib/libc/string/stpncpy.c delete mode 100644 src/lib/libc/string/strcasecmp.3 delete mode 100644 src/lib/libc/string/strcasecmp.c delete mode 100644 src/lib/libc/string/strcasestr.c delete mode 100644 src/lib/libc/string/strcat.3 delete mode 100644 src/lib/libc/string/strcat.c delete mode 100644 src/lib/libc/string/strchr.3 delete mode 100644 src/lib/libc/string/strcmp.3 delete mode 100644 src/lib/libc/string/strcmp.c delete mode 100644 src/lib/libc/string/strcoll.3 delete mode 100644 src/lib/libc/string/strcoll.c delete mode 100644 src/lib/libc/string/strcpy.3 delete mode 100644 src/lib/libc/string/strcpy.c delete mode 100644 src/lib/libc/string/strcspn.3 delete mode 100644 src/lib/libc/string/strcspn.c delete mode 100644 src/lib/libc/string/strdup.3 delete mode 100644 src/lib/libc/string/strdup.c delete mode 100644 src/lib/libc/string/strerror.3 delete mode 100644 src/lib/libc/string/strerror.c delete mode 100644 src/lib/libc/string/strerror_r.c delete mode 100644 src/lib/libc/string/string.3 delete mode 100644 src/lib/libc/string/strlcat.c delete mode 100644 src/lib/libc/string/strlcpy.3 delete mode 100644 src/lib/libc/string/strlcpy.c delete mode 100644 src/lib/libc/string/strlen.3 delete mode 100644 src/lib/libc/string/strlen.c delete mode 100644 src/lib/libc/string/strmode.3 delete mode 100644 src/lib/libc/string/strmode.c delete mode 100644 src/lib/libc/string/strncat.c delete mode 100644 src/lib/libc/string/strncmp.c delete mode 100644 src/lib/libc/string/strncpy.c delete mode 100644 src/lib/libc/string/strndup.c delete mode 100644 src/lib/libc/string/strnlen.c delete mode 100644 src/lib/libc/string/strpbrk.3 delete mode 100644 src/lib/libc/string/strpbrk.c delete mode 100644 src/lib/libc/string/strrchr.3 delete mode 100644 src/lib/libc/string/strsep.3 delete mode 100644 src/lib/libc/string/strsep.c delete mode 100644 src/lib/libc/string/strsignal.3 delete mode 100644 src/lib/libc/string/strsignal.c delete mode 100644 src/lib/libc/string/strspn.3 delete mode 100644 src/lib/libc/string/strspn.c delete mode 100644 src/lib/libc/string/strstr.3 delete mode 100644 src/lib/libc/string/strstr.c delete mode 100644 src/lib/libc/string/strtok.3 delete mode 100644 src/lib/libc/string/strtok.c delete mode 100644 src/lib/libc/string/strxfrm.3 delete mode 100644 src/lib/libc/string/strxfrm.c delete mode 100644 src/lib/libc/string/swab.3 delete mode 100644 src/lib/libc/string/swab.c delete mode 100644 src/lib/libc/string/timingsafe_bcmp.c delete mode 100644 src/lib/libc/string/wcscasecmp.3 delete mode 100644 src/lib/libc/string/wcscasecmp.c delete mode 100644 src/lib/libc/string/wcscat.3 delete mode 100644 src/lib/libc/string/wcscat.c delete mode 100644 src/lib/libc/string/wcschr.3 delete mode 100644 src/lib/libc/string/wcschr.c delete mode 100644 src/lib/libc/string/wcscmp.3 delete mode 100644 src/lib/libc/string/wcscmp.c delete mode 100644 src/lib/libc/string/wcscpy.3 delete mode 100644 src/lib/libc/string/wcscpy.c delete mode 100644 src/lib/libc/string/wcscspn.3 delete mode 100644 src/lib/libc/string/wcscspn.c delete mode 100644 src/lib/libc/string/wcsdup.3 delete mode 100644 src/lib/libc/string/wcsdup.c delete mode 100644 src/lib/libc/string/wcslcat.c delete mode 100644 src/lib/libc/string/wcslcpy.3 delete mode 100644 src/lib/libc/string/wcslcpy.c delete mode 100644 src/lib/libc/string/wcslen.3 delete mode 100644 src/lib/libc/string/wcslen.c delete mode 100644 src/lib/libc/string/wcsncat.c delete mode 100644 src/lib/libc/string/wcsncmp.c delete mode 100644 src/lib/libc/string/wcsncpy.c delete mode 100644 src/lib/libc/string/wcspbrk.3 delete mode 100644 src/lib/libc/string/wcspbrk.c delete mode 100644 src/lib/libc/string/wcsrchr.3 delete mode 100644 src/lib/libc/string/wcsrchr.c delete mode 100644 src/lib/libc/string/wcsspn.3 delete mode 100644 src/lib/libc/string/wcsspn.c delete mode 100644 src/lib/libc/string/wcsstr.3 delete mode 100644 src/lib/libc/string/wcsstr.c delete mode 100644 src/lib/libc/string/wcstok.3 delete mode 100644 src/lib/libc/string/wcstok.c delete mode 100644 src/lib/libc/string/wcswcs.c delete mode 100644 src/lib/libc/string/wcswidth.3 delete mode 100644 src/lib/libc/string/wcswidth.c delete mode 100644 src/lib/libc/string/wmemchr.3 delete mode 100644 src/lib/libc/string/wmemchr.c delete mode 100644 src/lib/libc/string/wmemcmp.3 delete mode 100644 src/lib/libc/string/wmemcmp.c delete mode 100644 src/lib/libc/string/wmemcpy.3 delete mode 100644 src/lib/libc/string/wmemcpy.c delete mode 100644 src/lib/libc/string/wmemmove.3 delete mode 100644 src/lib/libc/string/wmemmove.c delete mode 100644 src/lib/libc/string/wmemset.3 delete mode 100644 src/lib/libc/string/wmemset.c (limited to 'src/lib/libc') diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc deleted file mode 100644 index 5dbd240bf5..0000000000 --- a/src/lib/libc/crypt/Makefile.inc +++ /dev/null @@ -1,15 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.18 2010/10/28 08:34:37 mikeb Exp $ - -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/crypt ${LIBCSRCDIR}/crypt - -SRCS+= crypt.c crypt2.c md5crypt.c arc4random.c blowfish.c bcrypt.c - -MAN+= crypt.3 blowfish.3 arc4random.3 -MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 -MLINKS+=crypt.3 bcrypt_gensalt.3 crypt.3 bcrypt.3 crypt.3 md5crypt.3 -MLINKS+=crypt.3 des_setkey.3 blowfish.3 blf_key.3 blowfish.3 blf_enc.3 -MLINKS+=blowfish.3 blf_dec.3 blowfish.3 blf_ecb_encrypt.3 -MLINKS+=blowfish.3 blf_ecb_decrypt.3 blowfish.3 blf_cbc_encrypt.3 -MLINKS+=blowfish.3 blf_cbc_decrypt.3 -MLINKS+=arc4random.3 arc4random_stir.3 arc4random.3 arc4random_addrandom.3 -MLINKS+=arc4random.3 arc4random_buf.3 arc4random.3 arc4random_uniform.3 diff --git a/src/lib/libc/crypt/arc4random.3 b/src/lib/libc/crypt/arc4random.3 deleted file mode 100644 index d9f07ade6e..0000000000 --- a/src/lib/libc/crypt/arc4random.3 +++ /dev/null @@ -1,138 +0,0 @@ -.\" $OpenBSD: arc4random.3,v 1.27 2008/12/23 18:31:02 deraadt Exp $ -.\" -.\" Copyright 1997 Niels Provos -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Niels Provos. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: December 23 2008 $ -.Dt ARC4RANDOM 3 -.Os -.Sh NAME -.Nm arc4random , -.Nm arc4random_buf , -.Nm arc4random_uniform , -.Nm arc4random_stir , -.Nm arc4random_addrandom -.Nd arc4 random number generator -.Sh SYNOPSIS -.Fd #include -.Ft u_int32_t -.Fn arc4random "void" -.Ft void -.Fn arc4random_buf "void *buf" "size_t nbytes" -.Ft u_int32_t -.Fn arc4random_uniform "u_int32_t upper_bound" -.Ft void -.Fn arc4random_stir "void" -.Ft void -.Fn arc4random_addrandom "u_char *dat" "int datlen" -.Sh DESCRIPTION -The -.Fn arc4random -function provides a high quality 32-bit pseudo-random -number very quickly. -.Fn arc4random -seeds itself on a regular basis from the kernel strong random number -subsystem described in -.Xr random 4 . -On each call, an ARC4 generator is used to generate a new result. -The -.Fn arc4random -function uses the ARC4 cipher key stream generator, -which uses 8*8 8-bit S-Boxes. -The S-Boxes can be in about (2**1700) states. -.Pp -.Fn arc4random -fits into a middle ground not covered by other subsystems such as -the strong, slow, and resource expensive random -devices described in -.Xr random 4 -versus the fast but poor quality interfaces described in -.Xr rand 3 , -.Xr random 3 , -and -.Xr drand48 3 . -.Pp -.Fn arc4random_buf -fills the region -.Fa buf -of length -.Fa nbytes -with ARC4-derived random data. -.Pp -.Fn arc4random_uniform -will return a uniformly distributed random number less than -.Fa upper_bound . -.Fn arc4random_uniform -is recommended over constructions like -.Dq Li arc4random() % upper_bound -as it avoids "modulo bias" when the upper bound is not a power of two. -.Pp -The -.Fn arc4random_stir -function reads data using -.Xr sysctl 3 -from -.Va kern.arandom -and uses it to permute the S-Boxes via -.Fn arc4random_addrandom . -.Pp -There is no need to call -.Fn arc4random_stir -before using -.Fn arc4random , -since -.Fn arc4random -automatically initializes itself. -.Sh RETURN VALUES -These functions are always successful, and no return value is -reserved to indicate an error. -.Sh SEE ALSO -.Xr rand 3 , -.Xr rand48 3 , -.Xr random 3 -.Sh HISTORY -An algorithm called -.Pa RC4 -was designed by RSA Data Security, Inc. -It was considered a trade secret. -Because it was a trade secret, it obviously could not be patented. -A clone of this was posted anonymously to USENET and confirmed to -be equivalent by several sources who had access to the original cipher. -Because of the trade secret situation, RSA Data Security, Inc. could -do nothing about the release of the -.Ql Alleged RC4 -algorithm. -Since -.Pa RC4 -was trademarked, the cipher is now referred to as -.Pa ARC4 . -.Pp -These functions first appeared in -.Ox 2.1 . diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c deleted file mode 100644 index 1697752a1a..0000000000 --- a/src/lib/libc/crypt/arc4random.c +++ /dev/null @@ -1,254 +0,0 @@ -/* $OpenBSD: arc4random.c,v 1.23 2012/06/24 18:25:12 matthew Exp $ */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Arc4 random number generator for OpenBSD. - * - * This code is derived from section 17.1 of Applied Cryptography, - * second edition, which describes a stream cipher allegedly - * compatible with RSA Labs "RC4" cipher (the actual description of - * which is a trade secret). The same algorithm is used as a stream - * cipher called "arcfour" in Tatu Ylonen's ssh package. - * - * RC4 is a registered trademark of RSA Laboratories. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "thread_private.h" - -#ifdef __GNUC__ -#define inline __inline -#else /* !__GNUC__ */ -#define inline -#endif /* !__GNUC__ */ - -struct arc4_stream { - u_int8_t i; - u_int8_t j; - u_int8_t s[256]; -}; - -static int rs_initialized; -static struct arc4_stream rs; -static pid_t arc4_stir_pid; -static int arc4_count; - -static inline u_int8_t arc4_getbyte(void); - -static inline void -arc4_init(void) -{ - int n; - - for (n = 0; n < 256; n++) - rs.s[n] = n; - rs.i = 0; - rs.j = 0; -} - -static inline void -arc4_addrandom(u_char *dat, int datlen) -{ - int n; - u_int8_t si; - - rs.i--; - for (n = 0; n < 256; n++) { - rs.i = (rs.i + 1); - si = rs.s[rs.i]; - rs.j = (rs.j + si + dat[n % datlen]); - rs.s[rs.i] = rs.s[rs.j]; - rs.s[rs.j] = si; - } - rs.j = rs.i; -} - -static void -arc4_stir(void) -{ - int i, mib[2]; - size_t len; - u_char rnd[128]; - - if (!rs_initialized) { - arc4_init(); - rs_initialized = 1; - } - - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; - - len = sizeof(rnd); - sysctl(mib, 2, rnd, &len, NULL, 0); - - arc4_addrandom(rnd, sizeof(rnd)); - - /* - * Discard early keystream, as per recommendations in: - * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps - */ - for (i = 0; i < 256; i++) - (void)arc4_getbyte(); - arc4_count = 1600000; -} - -static void -arc4_stir_if_needed(void) -{ - pid_t pid = getpid(); - - if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) - { - arc4_stir_pid = pid; - arc4_stir(); - } -} - -static inline u_int8_t -arc4_getbyte(void) -{ - u_int8_t si, sj; - - rs.i = (rs.i + 1); - si = rs.s[rs.i]; - rs.j = (rs.j + si); - sj = rs.s[rs.j]; - rs.s[rs.i] = sj; - rs.s[rs.j] = si; - return (rs.s[(si + sj) & 0xff]); -} - -static inline u_int32_t -arc4_getword(void) -{ - u_int32_t val; - val = arc4_getbyte() << 24; - val |= arc4_getbyte() << 16; - val |= arc4_getbyte() << 8; - val |= arc4_getbyte(); - return val; -} - -void -arc4random_stir(void) -{ - _ARC4_LOCK(); - arc4_stir(); - _ARC4_UNLOCK(); -} - -void -arc4random_addrandom(u_char *dat, int datlen) -{ - _ARC4_LOCK(); - if (!rs_initialized) - arc4_stir(); - arc4_addrandom(dat, datlen); - _ARC4_UNLOCK(); -} - -u_int32_t -arc4random(void) -{ - u_int32_t val; - _ARC4_LOCK(); - arc4_count -= 4; - arc4_stir_if_needed(); - val = arc4_getword(); - _ARC4_UNLOCK(); - return val; -} - -void -arc4random_buf(void *_buf, size_t n) -{ - u_char *buf = (u_char *)_buf; - _ARC4_LOCK(); - arc4_stir_if_needed(); - while (n--) { - if (--arc4_count <= 0) - arc4_stir(); - buf[n] = arc4_getbyte(); - } - _ARC4_UNLOCK(); -} - -/* - * Calculate a uniformly distributed random number less than upper_bound - * avoiding "modulo bias". - * - * Uniformity is achieved by generating new random numbers until the one - * returned is outside the range [0, 2**32 % upper_bound). This - * guarantees the selected random number will be inside - * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) - * after reduction modulo upper_bound. - */ -u_int32_t -arc4random_uniform(u_int32_t upper_bound) -{ - u_int32_t r, min; - - if (upper_bound < 2) - return 0; - - /* 2**32 % x == (2**32 - x) % x */ - min = -upper_bound % upper_bound; - - /* - * This could theoretically loop forever but each retry has - * p > 0.5 (worst case, usually far better) of selecting a - * number inside the range we need, so it should rarely need - * to re-roll. - */ - for (;;) { - r = arc4random(); - if (r >= min) - break; - } - - return r % upper_bound; -} - -#if 0 -/*-------- Test code for i386 --------*/ -#include -#include -int -main(int argc, char **argv) -{ - const int iter = 1000000; - int i; - pctrval v; - - v = rdtsc(); - for (i = 0; i < iter; i++) - arc4random(); - v = rdtsc() - v; - v /= iter; - - printf("%qd cycles\n", v); -} -#endif diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c deleted file mode 100644 index 207e76ea46..0000000000 --- a/src/lib/libc/crypt/bcrypt.c +++ /dev/null @@ -1,338 +0,0 @@ -/* $OpenBSD: bcrypt.c,v 1.24 2008/04/02 19:54:05 millert Exp $ */ - -/* - * Copyright 1997 Niels Provos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* This password hashing algorithm was designed by David Mazieres - * and works as follows: - * - * 1. state := InitState () - * 2. state := ExpandKey (state, salt, password) 3. - * REPEAT rounds: - * state := ExpandKey (state, 0, salt) - * state := ExpandKey(state, 0, password) - * 4. ctext := "OrpheanBeholderScryDoubt" - * 5. REPEAT 64: - * ctext := Encrypt_ECB (state, ctext); - * 6. RETURN Concatenate (salt, ctext); - * - */ - -#include -#include -#include -#include -#include -#include - -/* This implementation is adaptable to current computing power. - * You can have up to 2^31 rounds which should be enough for some - * time to come. - */ - -#define BCRYPT_VERSION '2' -#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ -#define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ -#define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ - -char *bcrypt_gensalt(u_int8_t); - -static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); -static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); -static void decode_base64(u_int8_t *, u_int16_t, u_int8_t *); - -static char encrypted[_PASSWORD_LEN]; -static char gsalt[7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1]; -static char error[] = ":"; - -const static u_int8_t Base64Code[] = -"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - -const static u_int8_t index_64[128] = { - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, - 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 255, 255, 255, 255, 255, 255, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 255, 255, 255, 255, 255 -}; -#define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)]) - -static void -decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data) -{ - u_int8_t *bp = buffer; - u_int8_t *p = data; - u_int8_t c1, c2, c3, c4; - while (bp < buffer + len) { - c1 = CHAR64(*p); - c2 = CHAR64(*(p + 1)); - - /* Invalid data */ - if (c1 == 255 || c2 == 255) - break; - - *bp++ = (c1 << 2) | ((c2 & 0x30) >> 4); - if (bp >= buffer + len) - break; - - c3 = CHAR64(*(p + 2)); - if (c3 == 255) - break; - - *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); - if (bp >= buffer + len) - break; - - c4 = CHAR64(*(p + 3)); - if (c4 == 255) - break; - *bp++ = ((c3 & 0x03) << 6) | c4; - - p += 4; - } -} - -static void -encode_salt(char *salt, u_int8_t *csalt, u_int16_t clen, u_int8_t logr) -{ - salt[0] = '$'; - salt[1] = BCRYPT_VERSION; - salt[2] = 'a'; - salt[3] = '$'; - - snprintf(salt + 4, 4, "%2.2u$", logr); - - encode_base64((u_int8_t *) salt + 7, csalt, clen); -} -/* Generates a salt for this version of crypt. - Since versions may change. Keeping this here - seems sensible. - */ - -char * -bcrypt_gensalt(u_int8_t log_rounds) -{ - u_int8_t csalt[BCRYPT_MAXSALT]; - u_int16_t i; - u_int32_t seed = 0; - - for (i = 0; i < BCRYPT_MAXSALT; i++) { - if (i % 4 == 0) - seed = arc4random(); - csalt[i] = seed & 0xff; - seed = seed >> 8; - } - - if (log_rounds < 4) - log_rounds = 4; - else if (log_rounds > 31) - log_rounds = 31; - - encode_salt(gsalt, csalt, BCRYPT_MAXSALT, log_rounds); - return gsalt; -} -/* We handle $Vers$log2(NumRounds)$salt+passwd$ - i.e. $2$04$iwouldntknowwhattosayetKdJ6iFtacBqJdKe6aW7ou */ - -char * -bcrypt(const char *key, const char *salt) -{ - blf_ctx state; - u_int32_t rounds, i, k; - u_int16_t j; - u_int8_t key_len, salt_len, logr, minor; - u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; - u_int8_t csalt[BCRYPT_MAXSALT]; - u_int32_t cdata[BCRYPT_BLOCKS]; - int n; - - /* Discard "$" identifier */ - salt++; - - if (*salt > BCRYPT_VERSION) { - /* How do I handle errors ? Return ':' */ - return error; - } - - /* Check for minor versions */ - if (salt[1] != '$') { - switch (salt[1]) { - case 'a': - /* 'ab' should not yield the same as 'abab' */ - minor = salt[1]; - salt++; - break; - default: - return error; - } - } else - minor = 0; - - /* Discard version + "$" identifier */ - salt += 2; - - if (salt[2] != '$') - /* Out of sync with passwd entry */ - return error; - - /* Computer power doesn't increase linear, 2^x should be fine */ - n = atoi(salt); - if (n > 31 || n < 0) - return error; - logr = (u_int8_t)n; - if ((rounds = (u_int32_t) 1 << logr) < BCRYPT_MINROUNDS) - return error; - - /* Discard num rounds + "$" identifier */ - salt += 3; - - if (strlen(salt) * 3 / 4 < BCRYPT_MAXSALT) - return error; - - /* We dont want the base64 salt but the raw data */ - decode_base64(csalt, BCRYPT_MAXSALT, (u_int8_t *) salt); - salt_len = BCRYPT_MAXSALT; - key_len = strlen(key) + (minor >= 'a' ? 1 : 0); - - /* Setting up S-Boxes and Subkeys */ - Blowfish_initstate(&state); - Blowfish_expandstate(&state, csalt, salt_len, - (u_int8_t *) key, key_len); - for (k = 0; k < rounds; k++) { - Blowfish_expand0state(&state, (u_int8_t *) key, key_len); - Blowfish_expand0state(&state, csalt, salt_len); - } - - /* This can be precomputed later */ - j = 0; - for (i = 0; i < BCRYPT_BLOCKS; i++) - cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); - - /* Now do the encryption */ - for (k = 0; k < 64; k++) - blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); - - for (i = 0; i < BCRYPT_BLOCKS; i++) { - ciphertext[4 * i + 3] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 2] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 1] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 0] = cdata[i] & 0xff; - } - - - i = 0; - encrypted[i++] = '$'; - encrypted[i++] = BCRYPT_VERSION; - if (minor) - encrypted[i++] = minor; - encrypted[i++] = '$'; - - snprintf(encrypted + i, 4, "%2.2u$", logr); - - encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); - encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext, - 4 * BCRYPT_BLOCKS - 1); - memset(&state, 0, sizeof(state)); - memset(ciphertext, 0, sizeof(ciphertext)); - memset(csalt, 0, sizeof(csalt)); - memset(cdata, 0, sizeof(cdata)); - return encrypted; -} - -static void -encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len) -{ - u_int8_t *bp = buffer; - u_int8_t *p = data; - u_int8_t c1, c2; - while (p < data + len) { - c1 = *p++; - *bp++ = Base64Code[(c1 >> 2)]; - c1 = (c1 & 0x03) << 4; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 4) & 0x0f; - *bp++ = Base64Code[c1]; - c1 = (c2 & 0x0f) << 2; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 6) & 0x03; - *bp++ = Base64Code[c1]; - *bp++ = Base64Code[c2 & 0x3f]; - } - *bp = '\0'; -} -#if 0 -void -main() -{ - char blubber[73]; - char salt[100]; - char *p; - salt[0] = '$'; - salt[1] = BCRYPT_VERSION; - salt[2] = '$'; - - snprintf(salt + 3, 4, "%2.2u$", 5); - - printf("24 bytes of salt: "); - fgets(salt + 6, sizeof(salt) - 6, stdin); - salt[99] = 0; - printf("72 bytes of password: "); - fpurge(stdin); - fgets(blubber, sizeof(blubber), stdin); - blubber[72] = 0; - - p = crypt(blubber, salt); - printf("Passwd entry: %s\n\n", p); - - p = bcrypt_gensalt(5); - printf("Generated salt: %s\n", p); - p = crypt(blubber, p); - printf("Passwd entry: %s\n", p); -} -#endif diff --git a/src/lib/libc/crypt/blowfish.3 b/src/lib/libc/crypt/blowfish.3 deleted file mode 100644 index 4defaecc34..0000000000 --- a/src/lib/libc/crypt/blowfish.3 +++ /dev/null @@ -1,106 +0,0 @@ -.\" $OpenBSD: blowfish.3,v 1.20 2007/05/31 19:19:27 jmc Exp $ -.\" -.\" Copyright 1997 Niels Provos -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Niels Provos. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt BLOWFISH 3 -.Os -.Sh NAME -.Nm blf_key , -.Nm blf_enc , -.Nm blf_dec , -.Nm blf_ecb_encrypt , -.Nm blf_ecb_decrypt , -.Nm blf_cbc_encrypt , -.Nm blf_cbc_decrypt -.Nd Blowfish encryption -.Sh SYNOPSIS -.Fd #include -.Ft void -.Fn blf_key "blf_ctx *state" "const u_int8_t *key" "u_int16_t keylen" -.Ft void -.Fn blf_enc "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" -.Ft void -.Fn blf_dec "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" -.Ft void -.Fn blf_ecb_encrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_ecb_decrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_cbc_encrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_cbc_decrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" -.Sh DESCRIPTION -.Em Blowfish -is a fast unpatented block cipher designed by Bruce Schneier. -It basically consists of a 16-round Feistel network. -The block size is 64 bits and the maximum key size is 448 bits. -.Pp -The -.Fn blf_key -function initializes the 4 8-bit S-boxes and the 18 Subkeys with -the hexadecimal digits of Pi. -The key is used for further randomization. -The first argument to -.Fn blf_enc -is the initialized state derived from -.Fn blf_key . -The stream of 32-bit words is encrypted in Electronic Codebook -Mode (ECB) and -.Fa blocks -is the number of 64-bit blocks in the stream. -.Fn blf_dec -is used for decrypting Blowfish encrypted blocks. -.Pp -The functions -.Fn blf_ecb_encrypt -and -.Fn blf_ecb_decrypt -are used for encrypting and decrypting octet streams in ECB mode. -The functions -.Fn blf_cbc_encrypt -and -.Fn blf_cbc_decrypt -are used for encrypting and decrypting octet streams in -Cipherblock Chaining Mode (CBC). -For these functions -.Fa datalen -specifies the number of octets of data to encrypt or decrypt. -It must be a multiple of 8 (64-bit block). -The initialisation vector -.Fa iv -points to an 8-byte buffer. -.Sh SEE ALSO -.Xr passwd 1 , -.Xr crypt 3 , -.Xr passwd 5 -.Sh AUTHORS -.An Niels Provos Aq provos@physnet.uni-hamburg.de diff --git a/src/lib/libc/crypt/blowfish.c b/src/lib/libc/crypt/blowfish.c deleted file mode 100644 index c337df8a0a..0000000000 --- a/src/lib/libc/crypt/blowfish.c +++ /dev/null @@ -1,685 +0,0 @@ -/* $OpenBSD: blowfish.c,v 1.18 2004/11/02 17:23:26 hshoexer Exp $ */ -/* - * Blowfish block cipher for OpenBSD - * Copyright 1997 Niels Provos - * All rights reserved. - * - * Implementation advice by David Mazieres . - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This code is derived from section 14.3 and the given source - * in section V of Applied Cryptography, second edition. - * Blowfish is an unpatented fast block cipher designed by - * Bruce Schneier. - */ - -#if 0 -#include /* used for debugging */ -#include -#endif - -#include -#include - -#undef inline -#ifdef __GNUC__ -#define inline __inline -#else /* !__GNUC__ */ -#define inline -#endif /* !__GNUC__ */ - -/* Function for Feistel Networks */ - -#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ - + (s)[0x100 + (((x)>>16)&0xFF)]) \ - ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ - + (s)[0x300 + ( (x) &0xFF)]) - -#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) - -void -Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) -{ - u_int32_t Xl; - u_int32_t Xr; - u_int32_t *s = c->S[0]; - u_int32_t *p = c->P; - - Xl = *xl; - Xr = *xr; - - Xl ^= p[0]; - BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); - BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); - BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); - BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); - BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); - BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); - BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); - BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); - - *xl = Xr ^ p[17]; - *xr = Xl; -} - -void -Blowfish_decipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) -{ - u_int32_t Xl; - u_int32_t Xr; - u_int32_t *s = c->S[0]; - u_int32_t *p = c->P; - - Xl = *xl; - Xr = *xr; - - Xl ^= p[17]; - BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15); - BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13); - BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11); - BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9); - BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7); - BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5); - BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3); - BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1); - - *xl = Xr ^ p[0]; - *xr = Xl; -} - -void -Blowfish_initstate(blf_ctx *c) -{ - /* P-box and S-box tables initialized with digits of Pi */ - - static const blf_ctx initstate = - { { - { - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, - { - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, - { - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, - { - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} - }, - { - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, - 0x9216d5d9, 0x8979fb1b - } }; - - *c = initstate; -} - -u_int32_t -Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes, - u_int16_t *current) -{ - u_int8_t i; - u_int16_t j; - u_int32_t temp; - - temp = 0x00000000; - j = *current; - - for (i = 0; i < 4; i++, j++) { - if (j >= databytes) - j = 0; - temp = (temp << 8) | data[j]; - } - - *current = j; - return temp; -} - -void -Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes) -{ - u_int16_t i; - u_int16_t j; - u_int16_t k; - u_int32_t temp; - u_int32_t datal; - u_int32_t datar; - - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } - - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - Blowfish_encipher(c, &datal, &datar); - - c->P[i] = datal; - c->P[i + 1] = datar; - } - - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - Blowfish_encipher(c, &datal, &datar); - - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } -} - - -void -Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes, - const u_int8_t *key, u_int16_t keybytes) -{ - u_int16_t i; - u_int16_t j; - u_int16_t k; - u_int32_t temp; - u_int32_t datal; - u_int32_t datar; - - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } - - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); - - c->P[i] = datal; - c->P[i + 1] = datar; - } - - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); - - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } - -} - -void -blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len) -{ - /* Initialize S-boxes and subkeys with Pi */ - Blowfish_initstate(c); - - /* Transform S-boxes and subkeys with key */ - Blowfish_expand0state(c, k, len); -} - -void -blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks) -{ - u_int32_t *d; - u_int16_t i; - - d = data; - for (i = 0; i < blocks; i++) { - Blowfish_encipher(c, d, d + 1); - d += 2; - } -} - -void -blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks) -{ - u_int32_t *d; - u_int16_t i; - - d = data; - for (i = 0; i < blocks; i++) { - Blowfish_decipher(c, d, d + 1); - d += 2; - } -} - -void -blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i; - - for (i = 0; i < len; i += 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - data += 8; - } -} - -void -blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i; - - for (i = 0; i < len; i += 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - data += 8; - } -} - -void -blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i, j; - - for (i = 0; i < len; i += 8) { - for (j = 0; j < 8; j++) - data[j] ^= iv[j]; - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - iv = data; - data += 8; - } -} - -void -blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int8_t *iv; - u_int32_t i, j; - - iv = data + len - 16; - data = data + len - 8; - for (i = len - 8; i >= 8; i -= 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - for (j = 0; j < 8; j++) - data[j] ^= iv[j]; - iv -= 8; - data -= 8; - } - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - for (j = 0; j < 8; j++) - data[j] ^= iva[j]; -} - -#if 0 -void -report(u_int32_t data[], u_int16_t len) -{ - u_int16_t i; - for (i = 0; i < len; i += 2) - printf("Block %0hd: %08lx %08lx.\n", - i / 2, data[i], data[i + 1]); -} -void -main(void) -{ - - blf_ctx c; - char key[] = "AAAAA"; - char key2[] = "abcdefghijklmnopqrstuvwxyz"; - - u_int32_t data[10]; - u_int32_t data2[] = - {0x424c4f57l, 0x46495348l}; - - u_int16_t i; - - /* First test */ - for (i = 0; i < 10; i++) - data[i] = i; - - blf_key(&c, (u_int8_t *) key, 5); - blf_enc(&c, data, 5); - blf_dec(&c, data, 1); - blf_dec(&c, data + 2, 4); - printf("Should read as 0 - 9.\n"); - report(data, 10); - - /* Second test */ - blf_key(&c, (u_int8_t *) key2, strlen(key2)); - blf_enc(&c, data2, 1); - printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); - report(data2, 2); - blf_dec(&c, data2, 1); - report(data2, 2); -} -#endif diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3 deleted file mode 100644 index 8415f28b9b..0000000000 --- a/src/lib/libc/crypt/crypt.3 +++ /dev/null @@ -1,325 +0,0 @@ -.\" $OpenBSD: crypt.3,v 1.28 2012/06/02 00:14:16 guenther Exp $ -.\" -.\" FreeSec: libcrypt -.\" -.\" Copyright (c) 1994 David Burren -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the author nor the names of other contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: June 2 2012 $ -.Dt CRYPT 3 -.Os -.Sh NAME -.Nm crypt , -.Nm setkey , -.Nm encrypt , -.Nm des_setkey , -.Nm des_cipher , -.Nm bcrypt_gensalt , -.Nm bcrypt , -.Nm md5crypt -.Nd DES encryption -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn setkey "const char *key" -.Pp -.Fd #include -.Ft char * -.Fn crypt "const char *key" "const char *setting" -.Ft int -.Fn encrypt "char *block" "int flag" -.Ft int -.Fn des_setkey "const char *key" -.Ft int -.Fn des_cipher "const char *in" "char *out" "int32_t salt" "int count" -.Ft char * -.Fn bcrypt_gensalt "u_int8_t log_rounds" -.Ft char * -.Fn bcrypt "const char *key" "const char *salt" -.Ft char * -.Fn md5crypt "const char *key" "const char *salt" -.Sh DESCRIPTION -The -.Fn crypt -function performs password encryption based on the -.Tn NBS -Data Encryption Standard (DES). -Additional code has been added to deter key search attempts and to use -stronger hashing algorithms. -.Pp -The first argument to -.Fn crypt -is a -.Dv NUL Ns -terminated -string, typically a user's typed password. -The second is in one of three forms: -if it begins with an underscore -.Pq Ql _ -then an extended format is used -in interpreting both the key and the setting, as outlined below. -If it begins -with a string character -.Pq Ql $ -and a number then a different algorithm is used depending on the number. -At the moment a -.Ql $1 -chooses MD5 hashing and a -.Ql $2 -chooses Blowfish hashing; see below for more information. -.Ss Extended crypt -The -.Ar key -is divided into groups of 8 characters (the last group is null-padded) -and the low-order 7 bits of each character (56 bits per group) are -used to form the DES key as follows: -the first group of 56 bits becomes the initial DES key. -For each additional group, the XOR of the encryption of the current DES -key with itself and the group bits becomes the next DES key. -.Pp -The setting is a 9-character array consisting of an underscore followed -by 4 bytes of iteration count and 4 bytes of salt. -These are encoded as printable characters, 6 bits per character, -least significant character first. -The values 0 to 63 are encoded as -.Dq \&./0-9A-Za-z . -This allows 24 bits for both -.Fa count -and -.Fa salt . -.Ss "MD5" crypt -For -.Tn MD5 -crypt the version number, -.Fa salt -and the hashed password are separated by the -.Ql $ -character. -The maximum length of a password is limited by -the length counter of the MD5 context, which is about -2**64. -A valid MD5 password entry looks like this: -.Pp -.Dq $1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1 . -.Pp -The whole MD5 password string is passed as -.Fa setting -for interpretation. -.Ss "Blowfish" crypt -The -.Tn Blowfish -version of crypt has 128 bits of -.Fa salt -in order to make building dictionaries of common passwords space consuming. -The initial state of the -.Tn Blowfish -cipher is expanded using the -.Fa salt -and the -.Fa password -repeating the process a variable number of rounds, which is encoded in -the password string. -The maximum password length is 72. -The final Blowfish password entry is created by encrypting the string -.Pp -.Dq OrpheanBeholderScryDoubt -.Pp -with the -.Tn Blowfish -state 64 times. -.Pp -The version number, the logarithm of the number of rounds and -the concatenation of salt and hashed password are separated by the -.Ql $ -character. -An encoded -.Sq 8 -would specify 256 rounds. -A valid Blowfish password looks like this: -.Pp -.Dq $2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC . -.Pp -The whole Blowfish password string is passed as -.Fa setting -for interpretation. -.Ss "Traditional" crypt -The first 8 bytes of the key are null-padded, and the low-order 7 bits of -each character is used to form the 56-bit -.Tn DES -key. -.Pp -The setting is a 2-character array of the ASCII-encoded salt. -Thus only 12 bits of -.Fa salt -are used. -.Fa count -is set to 25. -.Ss DES Algorithm -The -.Fa salt -introduces disorder in the -.Tn DES -algorithm in one of 16777216 or 4096 possible ways -(i.e., with 24 or 12 bits: if bit -.Em i -of the -.Ar salt -is set, then bits -.Em i -and -.Em i+24 -are swapped in the -.Tn DES -E-box output). -.Pp -The DES key is used to encrypt a 64-bit constant using -.Ar count -iterations of -.Tn DES . -The value returned is a -.Dv NUL Ns -terminated -string, 20 or 13 bytes (plus NUL) in length, consisting of the -.Ar setting -followed by the encoded 64-bit encryption. -.Pp -The functions -.Fn encrypt , -.Fn setkey , -.Fn des_setkey , -and -.Fn des_cipher -provide access to the -.Tn DES -algorithm itself. -.Fn setkey -is passed a 64-byte array of binary values (numeric 0 or 1). -A 56-bit key is extracted from this array by dividing the -array into groups of 8, and ignoring the last bit in each group. -That bit is reserved for a byte parity check by DES, but is ignored -by these functions. -.Pp -The -.Fa block -argument to -.Fn encrypt -is also a 64-byte array of binary values. -If the value of -.Fa flag -is 0, -.Fa block -is encrypted otherwise it is decrypted. -The result is returned in the original array -.Fa block -after using the key specified by -.Fn setkey -to process it. -.Pp -The argument to -.Fn des_setkey -is a character array of length 8. -The least significant bit (the parity bit) in each character is ignored, -and the remaining bits are concatenated to form a 56-bit key. -The function -.Fn des_cipher -encrypts (or decrypts if -.Fa count -is negative) the 64-bits stored in the 8 characters at -.Fa in -using -.Xr abs 3 -of -.Fa count -iterations of -.Tn DES -and stores the 64-bit result in the 8 characters at -.Fa out -(which may be the same as -.Fa in ) . -The -.Fa salt -specifies perturbations to the -.Tn DES -E-box output as described above. -.Pp -The -.Fn crypt , -.Fn setkey , -and -.Fn des_setkey -functions all manipulate the same key space. -.Sh RETURN VALUES -The function -.Fn crypt -returns a pointer to the encrypted value on success, and -.Dv NULL -on failure. -The functions -.Fn setkey , -.Fn encrypt , -.Fn des_setkey , -and -.Fn des_cipher -return 0 on success and 1 on failure. -.Sh SEE ALSO -.Xr login 1 , -.Xr passwd 1 , -.Xr blowfish 3 , -.Xr getpass 3 , -.Xr md5 3 , -.Xr passwd 5 -.Sh HISTORY -A rotor-based -.Fn crypt -function appeared in -.At v3 . -The current style -.Fn crypt -first appeared in -.At v7 . -.Pp -This library (FreeSec 1.0) was developed outside the United States of America -as an unencumbered replacement for the U.S.-only libcrypt encryption -library. -Programs linked against the -.Fn crypt -interface may be exported from the U.S.A. only if they use -.Fn crypt -solely for authentication purposes and avoid use of -the other programmer interfaces listed above. -Special care has been taken -in the library so that programs which only use the -.Fn crypt -interface do not pull in the other components. -.Sh AUTHORS -.An David Burren Aq davidb@werj.com.au -.Sh BUGS -The -.Fn crypt -function returns a pointer to static data, and subsequent calls to -.Fn crypt -will modify the same object. diff --git a/src/lib/libc/crypt/crypt.c b/src/lib/libc/crypt/crypt.c deleted file mode 100644 index 15a784532d..0000000000 --- a/src/lib/libc/crypt/crypt.c +++ /dev/null @@ -1,696 +0,0 @@ -/* $OpenBSD: crypt.c,v 1.20 2005/08/08 08:05:33 espie Exp $ */ - -/* - * FreeSec: libcrypt - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren . - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - */ - -#include -#include -#include -#include -#include - -#ifdef DEBUG -# include -#endif - -static const u_char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 -}; - -static u_char inv_key_perm[64]; -static u_char u_key_perm[56]; -static u_char const key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -static const u_char key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -static u_char inv_comp_perm[56]; -static const u_char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -/* - * No E box is used, as it's replaced by some ANDs, shifts, and ORs. - */ - -static u_char u_sbox[8][64]; -static const u_char sbox[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 - }, - { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 - }, - { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 - }, - { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 - }, - { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 - }, - { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 - }, - { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 - }, - { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } -}; - -static u_char un_pbox[32]; -static const u_char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -const u_int32_t _des_bits32[32] = -{ - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 -}; - -const u_char _des_bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; - -static u_int32_t saltbits; -static int32_t old_salt; -static const u_int32_t *bits28, *bits24; -static u_char init_perm[64], final_perm[64]; -static u_int32_t en_keysl[16], en_keysr[16]; -static u_int32_t de_keysl[16], de_keysr[16]; -int _des_initialised = 0; -static u_char m_sbox[4][4096]; -static u_int32_t psbox[4][256]; -static u_int32_t ip_maskl[8][256], ip_maskr[8][256]; -static u_int32_t fp_maskl[8][256], fp_maskr[8][256]; -static u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; -static u_int32_t comp_maskl[8][128], comp_maskr[8][128]; -static u_int32_t old_rawkey0, old_rawkey1; - -static u_char ascii64[] = - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -/* 0000000000111111111122222222223333333333444444444455555555556666 */ -/* 0123456789012345678901234567890123456789012345678901234567890123 */ - -static __inline int -ascii_to_bin(char ch) -{ - if (ch > 'z') - return(0); - if (ch >= 'a') - return(ch - 'a' + 38); - if (ch > 'Z') - return(0); - if (ch >= 'A') - return(ch - 'A' + 12); - if (ch > '9') - return(0); - if (ch >= '.') - return(ch - '.'); - return(0); -} - -void -_des_init(void) -{ - int i, j, b, k, inbit, obit; - u_int32_t *p, *il, *ir, *fl, *fr; - - old_rawkey0 = old_rawkey1 = 0; - saltbits = 0; - old_salt = 0; - bits24 = (bits28 = _des_bits32 + 4) + 4; - - /* - * Invert the S-boxes, reordering the input bits. - */ - for (i = 0; i < 8; i++) - for (j = 0; j < 64; j++) { - b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); - u_sbox[i][j] = sbox[i][b]; - } - - /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. - */ - for (b = 0; b < 4; b++) - for (i = 0; i < 64; i++) - for (j = 0; j < 64; j++) - m_sbox[b][(i << 6) | j] = - (u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]; - - /* - * Set up the initial & final permutations into a useful form, and - * initialise the inverted key permutation. - */ - for (i = 0; i < 64; i++) { - init_perm[final_perm[i] = IP[i] - 1] = i; - inv_key_perm[i] = 255; - } - - /* - * Invert the key permutation and initialise the inverted key - * compression permutation. - */ - for (i = 0; i < 56; i++) { - u_key_perm[i] = key_perm[i] - 1; - inv_key_perm[key_perm[i] - 1] = i; - inv_comp_perm[i] = 255; - } - - /* - * Invert the key compression permutation. - */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = i; - } - - /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. - */ - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(il = &ip_maskl[k][i]) = 0; - *(ir = &ip_maskr[k][i]) = 0; - *(fl = &fp_maskl[k][i]) = 0; - *(fr = &fp_maskr[k][i]) = 0; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & _des_bits8[j]) { - if ((obit = init_perm[inbit]) < 32) - *il |= _des_bits32[obit]; - else - *ir |= _des_bits32[obit-32]; - if ((obit = final_perm[inbit]) < 32) - *fl |= _des_bits32[obit]; - else - *fr |= _des_bits32[obit - 32]; - } - } - } - for (i = 0; i < 128; i++) { - *(il = &key_perm_maskl[k][i]) = 0; - *(ir = &key_perm_maskr[k][i]) = 0; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & _des_bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit < 28) - *il |= bits28[obit]; - else - *ir |= bits28[obit - 28]; - } - } - *(il = &comp_maskl[k][i]) = 0; - *(ir = &comp_maskr[k][i]) = 0; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & _des_bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) - continue; - if (obit < 24) - *il |= bits24[obit]; - else - *ir |= bits24[obit - 24]; - } - } - } - } - - /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. - */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = i; - - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { - *(p = &psbox[b][i]) = 0; - for (j = 0; j < 8; j++) { - if (i & _des_bits8[j]) - *p |= _des_bits32[un_pbox[8 * b + j]]; - } - } - - _des_initialised = 1; -} - -void -_des_setup_salt(int32_t salt) -{ - u_int32_t obit, saltbit; - int i; - - if (salt == old_salt) - return; - old_salt = salt; - - saltbits = 0; - saltbit = 1; - obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } -} - -int -des_setkey(const char *key) -{ - u_int32_t k0, k1, rawkey0, rawkey1; - int shifts, round; - - if (!_des_initialised) - _des_init(); - - rawkey0 = ntohl(*(u_int32_t *) key); - rawkey1 = ntohl(*(u_int32_t *) (key + 4)); - - if ((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { - /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. - */ - return(0); - } - old_rawkey0 = rawkey0; - old_rawkey1 = rawkey1; - - /* - * Do key permutation and split into two 28-bit subkeys. - */ - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for (round = 0; round < 16; round++) { - u_int32_t t0, t1; - - shifts += key_shifts[round]; - - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - - de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; - - de_keysr[15 - round] = - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; - } - return(0); -} - -int -_des_do_des(u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, - int count) -{ - /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - u_int32_t l, r, *kl, *kr, *kl1, *kr1; - u_int32_t f, r48l, r48r; - int round; - - if (count == 0) { - return(1); - } else if (count > 0) { - /* - * Encrypting - */ - kl1 = en_keysl; - kr1 = en_keysr; - } else { - /* - * Decrypting - */ - count = -count; - kl1 = de_keysl; - kr1 = de_keysr; - } - - /* - * Do initial permutation (IP). - */ - l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] - | ip_maskl[7][r_in & 0xff]; - r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] - | ip_maskr[7][r_in & 0xff]; - - while (count--) { - /* - * Do each round. - */ - kl = kl1; - kr = kr1; - round = 16; - while (round--) { - /* - * Expand R to 48 bits (simulate the E-box). - */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); - - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. - */ - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* - * Now that we've permuted things, complete f(). - */ - f ^= l; - l = r; - r = f; - } - r = l; - l = f; - } - /* - * Do final permutation (inverse of IP). - */ - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; - return(0); -} - -int -des_cipher(const char *in, char *out, int32_t salt, int count) -{ - u_int32_t l_out, r_out, rawl, rawr; - u_int32_t x[2]; - int retval; - - if (!_des_initialised) - _des_init(); - - _des_setup_salt(salt); - - memcpy(x, in, sizeof x); - rawl = ntohl(x[0]); - rawr = ntohl(x[1]); - retval = _des_do_des(rawl, rawr, &l_out, &r_out, count); - - x[0] = htonl(l_out); - x[1] = htonl(r_out); - memcpy(out, x, sizeof x); - return(retval); -} - -char * -crypt(const char *key, const char *setting) -{ - int i; - u_int32_t count, salt, l, r0, r1, keybuf[2]; - u_char *p, *q; - static u_char output[21]; - extern char *md5crypt(const char *, const char *); - extern char *bcrypt(const char *, const char *); - - if (setting[0] == '$') { - switch (setting[1]) { - case '1': - return (md5crypt(key, setting)); - default: - return bcrypt(key, setting); - } - } - - if (!_des_initialised) - _des_init(); - - /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. - */ - q = (u_char *) keybuf; - while ((q - (u_char *) keybuf) < sizeof(keybuf)) { - if ((*q++ = *key << 1)) - key++; - } - if (des_setkey((char *) keybuf)) - return(NULL); - - if (*setting == _PASSWORD_EFMT1) { - /* - * "new"-style: - * setting - underscore, 4 bytes of count, 4 bytes of salt - * key - unlimited characters - */ - for (i = 1, count = 0; i < 5; i++) - count |= ascii_to_bin(setting[i]) << (i - 1) * 6; - - for (i = 5, salt = 0; i < 9; i++) - salt |= ascii_to_bin(setting[i]) << (i - 5) * 6; - - while (*key) { - /* - * Encrypt the key with itself. - */ - if (des_cipher((char *)keybuf, (char *)keybuf, 0, 1)) - return(NULL); - /* - * And XOR with the next 8 characters of the key. - */ - q = (u_char *) keybuf; - while (((q - (u_char *) keybuf) < sizeof(keybuf)) && - *key) - *q++ ^= *key++ << 1; - - if (des_setkey((char *) keybuf)) - return(NULL); - } - strlcpy((char *)output, setting, 10); - - /* - * Double check that we weren't given a short setting. - * If we were, the above code will probably have created - * weird values for count and salt, but we don't really care. - * Just make sure the output string doesn't have an extra - * NUL in it. - */ - p = output + strlen((const char *)output); - } else { - /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters - */ - count = 25; - - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); - - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; - - p = output + 2; - } - _des_setup_salt(salt); - - /* - * Do it. - */ - if (_des_do_des(0, 0, &r0, &r1, count)) - return(NULL); - /* - * Now encode the result... - */ - l = (r0 >> 8); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = (r0 << 16) | ((r1 >> 16) & 0xffff); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = r1 << 2; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - *p = 0; - - return((char *)output); -} diff --git a/src/lib/libc/crypt/crypt2.c b/src/lib/libc/crypt/crypt2.c deleted file mode 100644 index 63a297e510..0000000000 --- a/src/lib/libc/crypt/crypt2.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $OpenBSD: crypt2.c,v 1.3 2005/08/08 08:05:33 espie Exp $ */ - -/* - * FreeSec: libcrypt - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren . - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - */ - -#include -#include -#include -#include -#include - -#ifdef DEBUG -# include -#endif - -extern const u_char _des_bits8[8]; -extern const u_int32_t _des_bits32[32]; -extern int _des_initialised; - -int -setkey(const char *key) -{ - int i, j; - u_int32_t packed_keys[2]; - u_char *p; - - p = (u_char *) packed_keys; - - for (i = 0; i < 8; i++) { - p[i] = 0; - for (j = 0; j < 8; j++) - if (*key++ & 1) - p[i] |= _des_bits8[j]; - } - return(des_setkey((char *)p)); -} - -int -encrypt(char *block, int flag) -{ - u_int32_t io[2]; - u_char *p; - int i, j, retval; - - if (!_des_initialised) - _des_init(); - - _des_setup_salt(0); - p = (u_char *)block; - for (i = 0; i < 2; i++) { - io[i] = 0L; - for (j = 0; j < 32; j++) - if (*p++ & 1) - io[i] |= _des_bits32[j]; - } - retval = _des_do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); - for (i = 0; i < 2; i++) - for (j = 0; j < 32; j++) - block[(i << 5) | j] = (io[i] & _des_bits32[j]) ? 1 : 0; - return(retval); -} diff --git a/src/lib/libc/crypt/md5crypt.c b/src/lib/libc/crypt/md5crypt.c deleted file mode 100644 index b32cd2115f..0000000000 --- a/src/lib/libc/crypt/md5crypt.c +++ /dev/null @@ -1,149 +0,0 @@ -/* $OpenBSD: md5crypt.c,v 1.15 2009/10/31 13:29:07 sobrado Exp $ */ - -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $ - * - */ - -#include -#include -#include -#include -#include - -static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static void to64(char *, u_int32_t, int); - -static void -to64(char *s, u_int32_t v, int n) -{ - while (--n >= 0) { - *s++ = itoa64[v&0x3f]; - v >>= 6; - } -} - -/* - * UNIX password - * - * Use MD5 for what it is best at... - */ - -char *md5crypt(const char *pw, const char *salt); - -char * -md5crypt(const char *pw, const char *salt) -{ - /* - * This string is magic for this algorithm. Having - * it this way, we can get get better later on - */ - static unsigned char *magic = (unsigned char *)"$1$"; - - static char passwd[120], *p; - static const unsigned char *sp,*ep; - unsigned char final[16]; - int sl,pl,i; - MD5_CTX ctx,ctx1; - u_int32_t l; - - /* Refine the Salt first */ - sp = (const unsigned char *)salt; - - /* If it starts with the magic string, then skip that */ - if(!strncmp((const char *)sp,(const char *)magic,strlen((const char *)magic))) - sp += strlen((const char *)magic); - - /* It stops at the first '$', max 8 chars */ - for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++) - continue; - - /* get the length of the true salt */ - sl = ep - sp; - - MD5Init(&ctx); - - /* The password first, since that is what is most unknown */ - MD5Update(&ctx,(const unsigned char *)pw,strlen(pw)); - - /* Then our magic string */ - MD5Update(&ctx,magic,strlen((const char *)magic)); - - /* Then the raw salt */ - MD5Update(&ctx,sp,sl); - - /* Then just as many characters of the MD5(pw,salt,pw) */ - MD5Init(&ctx1); - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Update(&ctx1,sp,sl); - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Final(final,&ctx1); - for(pl = strlen(pw); pl > 0; pl -= 16) - MD5Update(&ctx,final,pl>16 ? 16 : pl); - - /* Don't leave anything around in vm they could use. */ - memset(final,0,sizeof final); - - /* Then something really weird... */ - for (i = strlen(pw); i ; i >>= 1) - if(i&1) - MD5Update(&ctx, final, 1); - else - MD5Update(&ctx, (const unsigned char *)pw, 1); - - /* Now make the output string */ - snprintf(passwd, sizeof(passwd), "%s%.*s$", (char *)magic, - sl, (const char *)sp); - - MD5Final(final,&ctx); - - /* - * and now, just to make sure things don't run too fast - * On a 60 MHz Pentium this takes 34 msec, so you would - * need 30 seconds to build a 1000 entry dictionary... - */ - for(i=0;i<1000;i++) { - MD5Init(&ctx1); - if(i & 1) - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - else - MD5Update(&ctx1,final,16); - - if(i % 3) - MD5Update(&ctx1,sp,sl); - - if(i % 7) - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - - if(i & 1) - MD5Update(&ctx1,final,16); - else - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Final(final,&ctx1); - } - - p = passwd + strlen(passwd); - - l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; to64(p,l,4); p += 4; - l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; to64(p,l,4); p += 4; - l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; to64(p,l,4); p += 4; - l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; to64(p,l,4); p += 4; - l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; to64(p,l,4); p += 4; - l = final[11] ; to64(p,l,2); p += 2; - *p = '\0'; - - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof final); - - return passwd; -} - diff --git a/src/lib/libc/include/ctype_private.h b/src/lib/libc/include/ctype_private.h deleted file mode 100644 index 39cc792ea4..0000000000 --- a/src/lib/libc/include/ctype_private.h +++ /dev/null @@ -1,7 +0,0 @@ -/* $OpenBSD: ctype_private.h,v 1.1 2005/08/08 05:53:00 espie Exp $ */ -/* Written by Marc Espie, public domain */ -#define CTYPE_NUM_CHARS 256 -extern const char _C_ctype_[]; -extern const short _C_toupper_[]; -extern const short _C_tolower_[]; - diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h deleted file mode 100644 index 4a51f15ddf..0000000000 --- a/src/lib/libc/include/namespace.h +++ /dev/null @@ -1,18 +0,0 @@ -/* $OpenBSD: namespace.h,v 1.2 1996/08/19 08:28:08 tholo Exp $ */ - -#define catclose _catclose -#define catgets _catgets -#define catopen _catopen -#define err _err -#define errx _errx -#define strtoq _strtoq -#define strtouq _strtouq -#define sys_errlist _sys_errlist -#define sys_nerr _sys_nerr -#define sys_siglist _sys_siglist -#define verr _verr -#define verrx _verrx -#define vwarn _vwarn -#define vwarnx _vwarnx -#define warn _warn -#define warnx _warnx diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h deleted file mode 100644 index 673fb9c6a6..0000000000 --- a/src/lib/libc/include/thread_private.h +++ /dev/null @@ -1,175 +0,0 @@ -/* $OpenBSD: thread_private.h,v 1.25 2011/10/16 06:29:56 guenther Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ - -#ifndef _THREAD_PRIVATE_H_ -#define _THREAD_PRIVATE_H_ - -/* - * This file defines the thread library interface to libc. Thread - * libraries must implement the functions described here for proper - * inter-operation with libc. libc contains weak versions of the - * described functions for operation in a non-threaded environment. - */ - -/* - * This variable is 0 until a second thread is created. - */ -extern int __isthreaded; - -/* - * Weak symbols are used in libc so that the thread library can - * efficiently wrap libc functions. - * - * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n), - * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, - * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). - */ -#define WEAK_NAME(name) __CONCAT(_weak_,name) -#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) -#ifdef __GNUC__ -#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) -#else -#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ -#endif - -/* - * Ditto for hand-written syscall stubs: - * - * Use STUB_NAME(n) to get the strong name of the stub: _thread_sys_n - * STUB_ALIAS(n) to generate the weak symbol n pointing to _thread_sys_n, - * STUB_PROTOTYPE(n) to generate a prototype for _thread_sys_n (based on n). - */ -#define STUB_NAME(name) __CONCAT(_thread_sys_,name) -#define STUB_ALIAS(name) __weak_alias(name, STUB_NAME(name)) -#ifdef __GNUC__ -#define STUB_PROTOTYPE(name) __typeof__(name) STUB_NAME(name) -#else -#define STUB_PROTOTYPE(name) /* typeof() only in gcc */ -#endif - -/* - * helper macro to make unique names in the thread namespace - */ -#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) - -/* - * helper functions that exist as (weak) null functions in libc and - * (strong) functions in the thread library. These functions: - * - * _thread_tag_lock: - * lock the mutex associated with the given tag. If the given - * tag is NULL a tag is first allocated. - * - * _thread_tag_unlock: - * unlock the mutex associated with the given tag. If the given - * tag is NULL a tag is first allocated. - * - * _thread_tag_storage: - * return a pointer to per thread instance of data associated - * with the given tag. If the given tag is NULL a tag is first - * allocated. - * - * _thread_mutex_lock: - * lock the given mutex. If the given mutex is NULL, - * rely on rthreads/pthreads implementation to initialize - * the mutex before locking. - * - * _thread_mutex_unlock: - * unlock the given mutex. - * - * _thread_mutex_destroy: - * destroy the given mutex. - */ -void _thread_tag_lock(void **); -void _thread_tag_unlock(void **); -void *_thread_tag_storage(void **, void *, size_t, void *); -void _thread_mutex_lock(void **); -void _thread_mutex_unlock(void **); -void _thread_mutex_destroy(void **); - -/* - * Macros used in libc to access thread mutex, keys, and per thread storage. - * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for - * historical reasons. They do the same thing, define a static variable - * keyed by 'name' that identifies a mutex and a key to identify per thread - * data. - */ -#define _THREAD_PRIVATE_KEY(name) \ - static void *__THREAD_NAME(name) -#define _THREAD_PRIVATE_MUTEX(name) \ - static void *__THREAD_NAME(name) -#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ - _thread_tag_lock(&(__THREAD_NAME(name))) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ - _thread_tag_unlock(&(__THREAD_NAME(name))) -#define _THREAD_PRIVATE(keyname, storage, error) \ - _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ - sizeof (storage), error) - -/* - * Macros used in libc to access mutexes. - */ -#define _MUTEX_LOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_lock(mutex); \ - } while (0) -#define _MUTEX_UNLOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_unlock(mutex); \ - } while (0) -#define _MUTEX_DESTROY(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_destroy(mutex); \ - } while (0) - -/* - * Resolver code is special cased in that it uses global keys. - */ -extern void *__THREAD_NAME(_res); -extern void *__THREAD_NAME(_res_ext); -extern void *__THREAD_NAME(serv_mutex); - -/* - * malloc lock/unlock prototypes and definitions - */ -void _thread_malloc_lock(void); -void _thread_malloc_unlock(void); - -#define _MALLOC_LOCK() do { \ - if (__isthreaded) \ - _thread_malloc_lock(); \ - } while (0) -#define _MALLOC_UNLOCK() do { \ - if (__isthreaded) \ - _thread_malloc_unlock();\ - } while (0) - -void _thread_atexit_lock(void); -void _thread_atexit_unlock(void); - -#define _ATEXIT_LOCK() do { \ - if (__isthreaded) \ - _thread_atexit_lock(); \ - } while (0) -#define _ATEXIT_UNLOCK() do { \ - if (__isthreaded) \ - _thread_atexit_unlock();\ - } while (0) - -void _thread_arc4_lock(void); -void _thread_arc4_unlock(void); - -#define _ARC4_LOCK() do { \ - if (__isthreaded) \ - _thread_arc4_lock(); \ - } while (0) -#define _ARC4_UNLOCK() do { \ - if (__isthreaded) \ - _thread_arc4_unlock();\ - } while (0) - -#endif /* _THREAD_PRIVATE_H_ */ diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc deleted file mode 100644 index 48279d2423..0000000000 --- a/src/lib/libc/net/Makefile.inc +++ /dev/null @@ -1,100 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.49 2012/01/17 02:33:20 deraadt Exp $ - -# net sources -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net - -CFLAGS+=-DRESOLVSORT - -SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \ - getifaddrs.c getnameinfo.c getnetbyaddr.c getnetbyname.c getnetent.c \ - getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ - getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ - herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ - inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ - inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ - linkaddr.c nsap_addr.c \ - rcmd.c ruserok.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \ - res_debug_syms.c \ - res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \ - sethostent.c ethers.c rcmdsh.c - -# IPv6 -SRCS+= ip6opt.c rthdr.c vars6.c - -# machine-dependent net sources -# m-d Makefile.inc must include sources for: -# htonl() htons() ntohl() ntohs() - -.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/net/Makefile.inc" - -MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ - getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ - getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ - inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ - inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ - rcmd.3 rcmdsh.3 resolver.3 - -MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ - byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ - byteorder.3 htobe64.3 byteorder.3 betoh16.3 byteorder.3 betoh32.3 \ - byteorder.3 betoh64.3 byteorder.3 htole16.3 byteorder.3 htole32.3 \ - byteorder.3 htole64.3 byteorder.3 letoh16.3 byteorder.3 letoh32.3 \ - byteorder.3 letoh64.3 byteorder.3 swap16.3 byteorder.3 swap32.3 \ - byteorder.3 swap64.3 -MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ - ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 -MLINKS+=getaddrinfo.3 freeaddrinfo.3 -MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ - gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ - gethostbyname.3 herror.3 gethostbyname.3 gethostbyname2.3 \ - gethostbyname.3 hstrerror.3 -MLINKS+=getifaddrs.3 freeifaddrs.3 -MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ - getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 -MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ - getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3 \ - getprotoent.3 getprotoent_r.3 getprotoent.3 getprotobyname_r.3 \ - getprotoent.3 getprotobynumber_r.3 getprotoent.3 setprotoent_r.3 \ - getprotoent.3 endprotoent_r.3 -MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ - getservent.3 getservbyport.3 getservent.3 setservent.3 \ - getservent.3 getservent_r.3 getservent.3 getservbyname_r.3 \ - getservent.3 getservbyport_r.3 getservent.3 setservent_r.3 \ - getservent.3 endservent_r.3 -MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ - if_indextoname.3 if_freenameindex.3 -MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ - inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ - inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 network.3 \ - inet.3 ntoa.3 inet.3 inet_ntop.3 inet.3 inet_pton.3 -MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 -MLINKS+=link_addr.3 link_ntoa.3 -MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ - rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 -MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ - resolver.3 res_mkquery.3 resolver.3 res_send.3 resolver.3 res_query.3 \ - resolver.3 res_search.3 -MLINKS+=getrrsetbyname.3 freerrset.3 -MLINKS+=inet6_option_space.3 inet6_option_init.3 \ - inet6_option_space.3 inet6_option_append.3 \ - inet6_option_space.3 inet6_option_alloc.3 \ - inet6_option_space.3 inet6_option_next.3 \ - inet6_option_space.3 inet6_option_find.3 -MLINKS+=inet6_rthdr_space.3 inet6_rthdr_init.3 \ - inet6_rthdr_space.3 inet6_rthdr_add.3 \ - inet6_rthdr_space.3 inet6_rthdr_lasthop.3 \ - inet6_rthdr_space.3 inet6_rthdr_reverse.3 \ - inet6_rthdr_space.3 inet6_rthdr_segments.3 \ - inet6_rthdr_space.3 inet6_rthdr_getaddr.3 \ - inet6_rthdr_space.3 inet6_rthdr_getflags.3 -MLINKS+=inet6_opt_init.3 inet6_opt_append.3 \ - inet6_opt_init.3 inet6_opt_finish.3 \ - inet6_opt_init.3 inet6_opt_set_val.3 \ - inet6_opt_init.3 inet6_opt_next.3 \ - inet6_opt_init.3 inet6_opt_find.3 \ - inet6_opt_init.3 inet6_opt_get_val.3 -MLINKS+=inet6_rth_space.3 inet6_rth_init.3 \ - inet6_rth_space.3 inet6_rth_add.3 \ - inet6_rth_space.3 inet6_rth_reverse.3 \ - inet6_rth_space.3 inet6_rth_segments.3 \ - inet6_rth_space.3 inet6_rth_getaddr.3 \ diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c deleted file mode 100644 index d432c48d5c..0000000000 --- a/src/lib/libc/net/base64.c +++ /dev/null @@ -1,308 +0,0 @@ -/* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char Pad64 = '='; - -/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein - and Freed. It is reproduced here in a slightly edited form for - convenience. - - A 65-character subset of US-ASCII is used, enabling 6 bits to be - represented per printable character. (The extra 65th character, "=", - is used to signify a special processing function.) - - The encoding process represents 24-bit groups of input bits as output - strings of 4 encoded characters. Proceeding from left to right, a - 24-bit input group is formed by concatenating 3 8-bit input groups. - These 24 bits are then treated as 4 concatenated 6-bit groups, each - of which is translated into a single digit in the base64 alphabet. - - Each 6-bit group is used as an index into an array of 64 printable - characters. The character referenced by the index is placed in the - output string. - - Table 1: The Base64 Alphabet - - Value Encoding Value Encoding Value Encoding Value Encoding - 0 A 17 R 34 i 51 z - 1 B 18 S 35 j 52 0 - 2 C 19 T 36 k 53 1 - 3 D 20 U 37 l 54 2 - 4 E 21 V 38 m 55 3 - 5 F 22 W 39 n 56 4 - 6 G 23 X 40 o 57 5 - 7 H 24 Y 41 p 58 6 - 8 I 25 Z 42 q 59 7 - 9 J 26 a 43 r 60 8 - 10 K 27 b 44 s 61 9 - 11 L 28 c 45 t 62 + - 12 M 29 d 46 u 63 / - 13 N 30 e 47 v - 14 O 31 f 48 w (pad) = - 15 P 32 g 49 x - 16 Q 33 h 50 y - - Special processing is performed if fewer than 24 bits are available - at the end of the data being encoded. A full encoding quantum is - always completed at the end of a quantity. When fewer than 24 input - bits are available in an input group, zero bits are added (on the - right) to form an integral number of 6-bit groups. Padding at the - end of the data is performed using the '=' character. - - Since all base64 input is an integral number of octets, only the - ------------------------------------------------- - following cases can arise: - - (1) the final quantum of encoding input is an integral - multiple of 24 bits; here, the final unit of encoded - output will be an integral multiple of 4 characters - with no "=" padding, - (2) the final quantum of encoding input is exactly 8 bits; - here, the final unit of encoded output will be two - characters followed by two "=" padding characters, or - (3) the final quantum of encoding input is exactly 16 bits; - here, the final unit of encoded output will be three - characters followed by one "=" padding character. - */ - -int -b64_ntop(src, srclength, target, targsize) - u_char const *src; - size_t srclength; - char *target; - size_t targsize; -{ - size_t datalength = 0; - u_char input[3]; - u_char output[4]; - int i; - - while (2 < srclength) { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; - } - - /* Now we worry about padding. */ - if (0 != srclength) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; i++) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; - else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; - } - if (datalength >= targsize) - return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return (datalength); -} - -/* skips all whitespace anywhere. - converts characters, four at a time, starting at (or after) - src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. - */ - -int -b64_pton(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; -{ - int tarindex, state, ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); -} diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 deleted file mode 100644 index ba9798a137..0000000000 --- a/src/lib/libc/net/byteorder.3 +++ /dev/null @@ -1,206 +0,0 @@ -.\" $OpenBSD: byteorder.3,v 1.17 2012/03/20 06:06:03 dlg Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: March 20 2012 $ -.Dt BYTEORDER 3 -.Os -.Sh NAME -.Nm htonl , -.Nm htons , -.Nm ntohl , -.Nm ntohs , -.Nm htobe64 , -.Nm htobe32 , -.Nm htobe16 , -.Nm betoh64 , -.Nm betoh32 , -.Nm betoh16 , -.Nm htole64 , -.Nm htole32 , -.Nm htole16 , -.Nm letoh64 , -.Nm letoh32 , -.Nm letoh16 , -.Nm swap64 , -.Nm swap32 , -.Nm swap16 -.Nd convert values between different byte orderings -.Sh SYNOPSIS -.Fd #include -.Ft u_int32_t -.Fn htonl "u_int32_t host32" -.Ft u_int16_t -.Fn htons "u_int16_t host16" -.Ft u_int32_t -.Fn ntohl "u_int32_t net32" -.Ft u_int16_t -.Fn ntohs "u_int16_t net16" -.Ft u_int64_t -.Fn htobe64 "u_int64_t host64" -.Ft u_int32_t -.Fn htobe32 "u_int32_t host32" -.Ft u_int16_t -.Fn htobe16 "u_int16_t host16" -.Ft u_int64_t -.Fn betoh64 "u_int64_t big64" -.Ft u_int32_t -.Fn betoh32 "u_int32_t big32" -.Ft u_int16_t -.Fn betoh16 "u_int16_t big16" -.Ft u_int64_t -.Fn htole64 "u_int64_t host64" -.Ft u_int32_t -.Fn htole32 "u_int32_t host32" -.Ft u_int16_t -.Fn htole16 "u_int16_t host16" -.Ft u_int64_t -.Fn letoh64 "u_int64_t little64" -.Ft u_int32_t -.Fn letoh32 "u_int32_t little32" -.Ft u_int16_t -.Fn letoh16 "u_int16_t little16" -.Ft u_int64_t -.Fn swap64 "u_int64_t val64" -.Ft u_int32_t -.Fn swap32 "u_int32_t val32" -.Ft u_int16_t -.Fn swap16 "u_int16_t val16" -.Sh DESCRIPTION -These routines convert 16, 32 and 64-bit quantities between different -byte orderings. -The -.Dq swap -functions reverse the byte ordering of -the given quantity; the others convert either from/to the native -byte order used by the host to/from either little- or big-endian (a.k.a -network) order. -.Pp -Apart from the swap functions, the names can be described by this form: -{src-order}to{dst-order}{size}. -Both {src-order} and {dst-order} can take the following forms: -.Pp -.Bl -tag -width "be " -offset indent -compact -.It h -Host order. -.It n -Network order (big-endian). -.It be -Big-endian (most significant byte first). -.It le -Little-endian (least significant byte first). -.El -.Pp -One of the specified orderings must be -.Sq h . -{size} will take these forms: -.Pp -.Bl -tag -width "32 " -offset indent -compact -.It l -Long (32-bit, used in conjunction with forms involving -.Sq n ) . -.It s -Short (16-bit, used in conjunction with forms involving -.Sq n ) . -.It 16 -16-bit. -.It 32 -32-bit. -.It 64 -64-bit. -.El -.Pp -The swap functions are of the form: swap{size}. -.Pp -Names involving -.Sq n -convert quantities between network -byte order and host byte order. -The last letter -.Pf ( Sq s -or -.Sq l ) -is a mnemonic -for the traditional names for such quantities, -.Li short -and -.Li long , -respectively. -Today, the C concept of -.Li short -and -.Li long -integers need not coincide with this traditional misunderstanding. -On machines which have a byte order which is the same as the network -order, routines are defined as null macros. -.Pp -The functions involving either -.Dq be , -.Dq le , -or -.Dq swap -use the numbers -16, 32, or 64 for specifying the bitwidth of the quantities they operate on. -Currently all supported architectures are either big- or little-endian -so either the -.Dq be -or -.Dq le -variants are implemented as null macros. -.Pp -The routines mentioned above which have either {src-order} or {dst-order} -set to -.Sq n -are most often used in -conjunction with Internet addresses and ports as returned by -.Xr gethostbyname 3 -and -.Xr getservent 3 . -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr getservent 3 -.Sh STANDARDS -The -.Fn htonl , -.Fn htons , -.Fn ntohl , -and -.Fn ntohs -functions conform to -.St -p1003.1 . -The other functions are extensions that should not be used when portability -is required. -.Sh HISTORY -The -.Nm byteorder -functions appeared in -.Bx 4.2 . -.Sh BUGS -On the vax, alpha, amd64, i386, and some mips and arm architectures, -bytes are handled backwards from most everyone else in the world. -This is not expected to be fixed in the near future. diff --git a/src/lib/libc/net/ethers.3 b/src/lib/libc/net/ethers.3 deleted file mode 100644 index 041ee981ec..0000000000 --- a/src/lib/libc/net/ethers.3 +++ /dev/null @@ -1,124 +0,0 @@ -.\" $OpenBSD: ethers.3,v 1.21 2011/04/19 22:38:26 matthew Exp $ -.\" -.\" Written by roland@frob.com. Public domain. -.\" -.Dd $Mdocdate: April 19 2011 $ -.Dt ETHERS 3 -.Os -.Sh NAME -.Nm ether_aton , -.Nm ether_ntoa , -.Nm ether_ntohost , -.Nm ether_hostton , -.Nm ether_line -.Nd get ethers entry -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft char * -.Fn ether_ntoa "struct ether_addr *e" -.Ft struct ether_addr * -.Fn ether_aton "const char *s" -.Ft int -.Fn ether_ntohost "char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_hostton "const char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" -.Sh DESCRIPTION -Ethernet addresses are represented by the -following structure: -.Bd -literal -offset indent -struct ether_addr { - u_int8_t ether_addr_octet[6]; -}; -.Ed -.Pp -The -.Fn ether_ntoa -function converts this structure into an -.Tn ASCII -string of the form -.Dq xx:xx:xx:xx:xx:xx , -consisting of 6 hexadecimal numbers separated -by colons. -It returns a pointer to a static buffer that is reused for each call. -The -.Fn ether_aton -converts an -.Tn ASCII -string of the same form and to a structure -containing the 6 octets of the address. -It returns a pointer to a static structure that is reused for each call. -.Fn ether_aton -will return NULL if the string does not represent a valid address. -.Pp -The -.Fn ether_ntohost -and -.Fn ether_hostton -functions interrogate the database mapping host names to Ethernet -addresses, -.Pa /etc/ethers . -The -.Fn ether_ntohost -function looks up the given Ethernet address and writes the associated -host name into the character buffer passed. -This buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -The -.Fn ether_hostton -function looks up the given host name and writes the associated -Ethernet address into the structure passed. -Both functions return -zero if they find the requested host name or address, and \-1 if not. -.Pp -Each call reads -.Pa /etc/ethers -from the beginning; if a -.Ql + -appears alone on a line in the file, then -.Fn ether_hostton -will consult the -.Pa ethers.byname -YP map, and -.Fn ether_ntohost -will consult the -.Pa ethers.byaddr -YP map. -.Pp -The -.Fn ether_line -function parses a line from the -.Pa /etc/ethers -file and fills in the passed -.Li struct ether_addr -and character buffer with the Ethernet address and host name on the line. -It returns zero if the line was successfully parsed and \-1 if not. -The character buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -.Sh FILES -.Bl -tag -width /etc/ethers -compact -.It Pa /etc/ethers -.El -.Sh SEE ALSO -.Xr ethers 5 -.Sh HISTORY -The -.Fn ether_ntoa , -.Fn ether_aton , -.Fn ether_ntohost , -.Fn ether_hostton , -and -.Fn ether_line -functions were adopted from SunOS and appeared in -.Nx 0.9b . -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls to -these functions overwrite it. diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c deleted file mode 100644 index d4243ff1da..0000000000 --- a/src/lib/libc/net/ethers.c +++ /dev/null @@ -1,232 +0,0 @@ -/* $OpenBSD: ethers.c,v 1.20 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * ethers(3) a la Sun. - * Originally Written by Roland McGrath 10/14/93. - * Substantially modified by Todd C. Miller - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef YP -#include -#endif - -#ifndef _PATH_ETHERS -#define _PATH_ETHERS "/etc/ethers" -#endif - -static char * _ether_aton(const char *, struct ether_addr *); - -char * -ether_ntoa(struct ether_addr *e) -{ - static char a[] = "xx:xx:xx:xx:xx:xx"; - - (void)snprintf(a, sizeof a, "%02x:%02x:%02x:%02x:%02x:%02x", - e->ether_addr_octet[0], e->ether_addr_octet[1], - e->ether_addr_octet[2], e->ether_addr_octet[3], - e->ether_addr_octet[4], e->ether_addr_octet[5]); - - return (a); -} - -static char * -_ether_aton(const char *s, struct ether_addr *e) -{ - int i; - long l; - char *pp; - - while (isspace(*s)) - s++; - - /* expect 6 hex octets separated by ':' or space/NUL if last octet */ - for (i = 0; i < 6; i++) { - l = strtol(s, &pp, 16); - if (pp == s || l > 0xFF || l < 0) - return (NULL); - if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0')))) - return (NULL); - e->ether_addr_octet[i] = (u_char)l; - s = pp + 1; - } - - /* return character after the octets ala strtol(3) */ - return (pp); -} - -struct ether_addr * -ether_aton(const char *s) -{ - static struct ether_addr n; - - return (_ether_aton(s, &n) ? &n : NULL); -} - -int -ether_ntohost(char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - size_t len; - struct ether_addr try; -#ifdef YP - char trybuf[sizeof("xx:xx:xx:xx:xx:xx")]; - int trylen; -#endif - -#ifdef YP - snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x", - e->ether_addr_octet[0], e->ether_addr_octet[1], - e->ether_addr_octet[2], e->ether_addr_octet[3], - e->ether_addr_octet[4], e->ether_addr_octet[5]); - trylen = strlen(trybuf); -#endif - - f = fopen(_PATH_ETHERS, "r"); - if (f == NULL) - return (-1); - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - (void)memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; -#ifdef YP - /* A + in the file means try YP now. */ - if (!strncmp(buf, "+\n", sizeof(buf))) { - char *ypbuf, *ypdom; - int ypbuflen; - - if (yp_get_default_domain(&ypdom)) - continue; - if (yp_match(ypdom, "ethers.byaddr", trybuf, - trylen, &ypbuf, &ypbuflen)) - continue; - if (ether_line(ypbuf, &try, hostname) == 0) { - free(ypbuf); - (void)fclose(f); - return (0); - } - free(ypbuf); - continue; - } -#endif - if (ether_line(buf, &try, hostname) == 0 && - memcmp((void *)&try, (void *)e, sizeof(try)) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_hostton(const char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - char try[MAXHOSTNAMELEN]; - size_t len; -#ifdef YP - int hostlen = strlen(hostname); -#endif - - f = fopen(_PATH_ETHERS, "r"); - if (f==NULL) - return (-1); - - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; -#ifdef YP - /* A + in the file means try YP now. */ - if (!strncmp(buf, "+\n", sizeof(buf))) { - char *ypbuf, *ypdom; - int ypbuflen; - - if (yp_get_default_domain(&ypdom)) - continue; - if (yp_match(ypdom, "ethers.byname", hostname, hostlen, - &ypbuf, &ypbuflen)) - continue; - if (ether_line(ypbuf, e, try) == 0) { - free(ypbuf); - (void)fclose(f); - return (0); - } - free(ypbuf); - continue; - } -#endif - if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_line(const char *line, struct ether_addr *e, char *hostname) -{ - char *p; - size_t n; - - /* Parse "xx:xx:xx:xx:xx:xx" */ - if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t')) - goto bad; - - /* Now get the hostname */ - while (isspace(*p)) - p++; - if (*p == '\0') - goto bad; - n = strcspn(p, " \t\n"); - if (n >= MAXHOSTNAMELEN) - goto bad; - strlcpy(hostname, p, n + 1); - return (0); - -bad: - errno = EINVAL; - return (-1); -} diff --git a/src/lib/libc/net/freeaddrinfo.c b/src/lib/libc/net/freeaddrinfo.c deleted file mode 100644 index 58702d0b18..0000000000 --- a/src/lib/libc/net/freeaddrinfo.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: freeaddrinfo.c,v 1.6 2005/03/25 13:24:11 otto Exp $ */ - -/* - * Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -void -freeaddrinfo(struct addrinfo *ai) -{ - struct addrinfo *p; - - do { - p = ai; - ai = ai->ai_next; - if (p->ai_canonname) - free(p->ai_canonname); - free((void *)p); - } while (ai); -} diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 deleted file mode 100644 index 6ce94e30a1..0000000000 --- a/src/lib/libc/net/gai_strerror.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" $OpenBSD: gai_strerror.3,v 1.7 2009/06/02 16:47:50 jasper Exp $ -.\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: June 2 2009 $ -.Dt GAI_STRERROR 3 -.Os -.Sh NAME -.Nm gai_strerror -.Nd get error message string from EAI_xxx error code -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft "const char *" -.Fn gai_strerror "int ecode" -.Sh DESCRIPTION -The -.Fn gai_strerror -function returns an error message string corresponding to the error code -returned by -.Xr getaddrinfo 3 -or -.Xr getnameinfo 3 . -.Pp -The following error codes and their meaning are defined in -.Aq Pa netdb.h : -.Pp -.Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact -.It Dv EAI_ADDRFAMILY -address family for -.Fa hostname -not supported -.It Dv EAI_AGAIN -temporary failure in name resolution -.It Dv EAI_BADFLAGS -invalid value for -.Fa ai_flags -.It Dv EAI_BADHINTS -invalid value for -.Fa hints -.It Dv EAI_FAIL -non-recoverable failure in name resolution -.It Dv EAI_FAMILY -.Fa ai_family -not supported. -.It Dv EAI_MEMORY -memory allocation failure -.It Dv EAI_NODATA -no address associated with -.Fa hostname -.It Dv EAI_NONAME -.Fa hostname -or -.Fa servname -not provided, or not known -.It Dv EAI_OVERFLOW -argument buffer overflow -.It Dv EAI_PROTOCOL -resolved protocol is unknown -.It Dv EAI_SERVICE -.Fa servname -not supported for -.Fa ai_socktype -.It Dv EAI_SOCKTYPE -.Fa ai_socktype -not supported -.It Dv EAI_SYSTEM -system error returned in -.Va errno -.El -.Sh RETURN VALUES -.Fn gai_strerror -returns a pointer to the error message string corresponding to -.Fa ecode . -If -.Fa ecode -is out of range, an implementation-specific error message string is returned. -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 diff --git a/src/lib/libc/net/gai_strerror.c b/src/lib/libc/net/gai_strerror.c deleted file mode 100644 index f4126413f8..0000000000 --- a/src/lib/libc/net/gai_strerror.c +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: gai_strerror.c,v 1.7 2009/06/02 16:47:50 jasper Exp $ */ - -/* - * Copyright (c) 1997-1999, Craig Metz, All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* gai_strerror() v1.38 */ - -#include -#include -#include - -const char * -gai_strerror(int errnum) -{ - switch (errnum) { - case 0: - return "no error"; - case EAI_BADFLAGS: - return "invalid value for ai_flags"; - case EAI_NONAME: - return "name or service is not known"; - case EAI_AGAIN: - return "temporary failure in name resolution"; - case EAI_FAIL: - return "non-recoverable failure in name resolution"; - case EAI_NODATA: - return "no address associated with name"; - case EAI_FAMILY: - return "ai_family not supported"; - case EAI_SOCKTYPE: - return "ai_socktype not supported"; - case EAI_SERVICE: - return "service not supported for ai_socktype"; - case EAI_ADDRFAMILY: - return "address family for name not supported"; - case EAI_MEMORY: - return "memory allocation failure"; - case EAI_SYSTEM: - return "system error"; - case EAI_BADHINTS: - return "invalid value for hints"; - case EAI_PROTOCOL: - return "resolved protocol is unknown"; - case EAI_OVERFLOW: - return "argument buffer overflow"; - default: - return "unknown/invalid error"; - } -} diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 deleted file mode 100644 index af3df3c2f6..0000000000 --- a/src/lib/libc/net/getaddrinfo.3 +++ /dev/null @@ -1,469 +0,0 @@ -.\" $OpenBSD: getaddrinfo.3,v 1.50 2012/04/20 16:37:07 sthen Exp $ -.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: April 20 2012 $ -.Dt GETADDRINFO 3 -.Os -.Sh NAME -.Nm getaddrinfo , -.Nm freeaddrinfo -.Nd host and service name to socket address structure -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getaddrinfo "const char *hostname" "const char *servname" \ - "const struct addrinfo *hints" "struct addrinfo **res" -.Ft void -.Fn freeaddrinfo "struct addrinfo *ai" -.Sh DESCRIPTION -The -.Fn getaddrinfo -function is used to get a list of -.Tn IP -addresses and port numbers for host -.Fa hostname -and service -.Fa servname . -It is a replacement for and provides more flexibility than the -.Xr gethostbyname 3 -and -.Xr getservbyname 3 -functions. -.Pp -The -.Fa hostname -and -.Fa servname -arguments are either pointers to NUL-terminated strings or the null pointer. -An acceptable value for -.Fa hostname -is either a valid host name or a numeric host address string consisting -of a dotted decimal IPv4 address or an IPv6 address. -The -.Fa servname -is either a decimal port number or a service name listed in -.Xr services 5 . -At least one of -.Fa hostname -and -.Fa servname -must be non-null. -.Pp -.Fa hints -is an optional pointer to a -.Li struct addrinfo , -as defined by -.Aq Pa netdb.h : -.Bd -literal -struct addrinfo { - int ai_flags; /* input flags */ - int ai_family; /* protocol family for socket */ - int ai_socktype; /* socket type */ - int ai_protocol; /* protocol for socket */ - socklen_t ai_addrlen; /* length of socket-address */ - struct sockaddr *ai_addr; /* socket-address for socket */ - char *ai_canonname; /* canonical name for service location */ - struct addrinfo *ai_next; /* pointer to next in list */ -}; -.Ed -.Pp -This structure can be used to provide hints concerning the type of socket -that the caller supports or wishes to use. -The caller can supply the following structure elements in -.Fa hints : -.Bl -tag -width "ai_socktypeXX" -.It Fa ai_family -The protocol family that should be used. -When -.Fa ai_family -is set to -.Dv PF_UNSPEC , -it means the caller will accept any protocol family supported by the -operating system. -.It Fa ai_socktype -Denotes the type of socket that is wanted: -.Dv SOCK_STREAM , -.Dv SOCK_DGRAM , -or -.Dv SOCK_RAW . -When -.Fa ai_socktype -is zero the caller will accept any socket type. -.It Fa ai_protocol -Indicates which transport protocol is desired, -.Dv IPPROTO_UDP -or -.Dv IPPROTO_TCP . -If -.Fa ai_protocol -is zero the caller will accept any protocol. -.It Fa ai_flags -.Fa ai_flags -is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "AI_CANONNAMEXX" -.It Dv AI_CANONNAME -If the -.Dv AI_CANONNAME -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the canonical name -of the specified host name in the -.Fa ai_canonname -element of the first -.Li addrinfo -structure returned. -.It Dv AI_FQDN -If the -.Dv AI_FQDN -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the fully qualified domain name -of the specified host name in the -.Fa ai_canonname -element of the first -.Li addrinfo -structure returned. -.Pp -This is different from the -.Dv AI_CANONNAME -bit flag that returns the canonical name registered in DNS, -which may be different from the fully qualified domain name -that the host name resolved to. -Only one of the -.Dv AI_FQDN -and -.Dv AI_CANONNAME -bits can be set. -.It Dv AI_NUMERICHOST -If the -.Dv AI_NUMERICHOST -bit is set, it indicates that -.Fa hostname -should be treated as a numeric string defining an IPv4 or IPv6 address -and no name resolution should be attempted. -.It Dv AI_NUMERICSERV -If the -.Dv AI_NUMERICSERV -bit is set, it indicates that -.Fa servname -should be treated as a numeric port string -and no service name resolution should be attempted. -.It Dv AI_PASSIVE -If the -.Dv AI_PASSIVE -bit is set it indicates that the returned socket address structure -is intended for use in a call to -.Xr bind 2 . -In this case, if the -.Fa hostname -argument is the null pointer, then the IP address portion of the -socket address structure will be set to -.Dv INADDR_ANY -for an IPv4 address or -.Dv IN6ADDR_ANY_INIT -for an IPv6 address. -.Pp -If the -.Dv AI_PASSIVE -bit is not set, the returned socket address structure will be ready -for use in a call to -.Xr connect 2 -for a connection-oriented protocol or -.Xr connect 2 , -.Xr sendto 2 , -or -.Xr sendmsg 2 -if a connectionless protocol was chosen. -The -.Tn IP -address portion of the socket address structure will be set to the -loopback address if -.Fa hostname -is the null pointer and -.Dv AI_PASSIVE -is not set. -.El -.El -.Pp -All other elements of the -.Li addrinfo -structure passed via -.Fa hints -must be zero or the null pointer. -.Pp -If -.Fa hints -is the null pointer, -.Fn getaddrinfo -behaves as if the caller provided a -.Li struct addrinfo -with -.Fa ai_family -set to -.Dv PF_UNSPEC -and all other elements set to zero or -.Dv NULL . -.Pp -After a successful call to -.Fn getaddrinfo , -.Fa *res -is a pointer to a linked list of one or more -.Li addrinfo -structures. -The list can be traversed by following the -.Fa ai_next -pointer in each -.Li addrinfo -structure until a null pointer is encountered. -The three members -.Fa ai_family , -.Fa ai_socktype , -and -.Fa ai_protocol -in each returned -.Li addrinfo -structure are suitable for a call to -.Xr socket 2 . -For each -.Li addrinfo -structure in the list, the -.Fa ai_addr -member points to a filled-in socket address structure of length -.Fa ai_addrlen . -.Pp -This implementation of -.Fn getaddrinfo -allows numeric IPv6 address notation with scope identifier, -as documented in RFC 4007. -By appending the percent character and scope identifier to addresses, -one can fill the -.Li sin6_scope_id -field for addresses. -This would make management of scoped addresses easier -and allows cut-and-paste input of scoped addresses. -.Pp -At this moment the code supports only link-local addresses with the format. -The scope identifier is hardcoded to the name of the hardware interface -associated -with the link -.Po -such as -.Li ne0 -.Pc . -An example is -.Dq Li fe80::1%ne0 , -which means -.Do -.Li fe80::1 -on the link associated with the -.Li ne0 -interface -.Dc . -.Pp -The current implementation assumes a one-to-one relationship between -the interface and link, which is not necessarily true from the specification. -.Pp -All of the information returned by -.Fn getaddrinfo -is dynamically allocated: the -.Li addrinfo -structures themselves as well as the socket address structures and -the canonical host name strings included in the -.Li addrinfo -structures. -.Pp -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getaddrinfo -is released by the -.Fn freeaddrinfo -function. -The -.Fa ai -pointer should be an -.Li addrinfo -structure created by a call to -.Fn getaddrinfo . -.Sh RETURN VALUES -.Fn getaddrinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -If an error occurs, no memory is allocated by -.Fn getaddrinfo , -therefore it is not necessary to release the -.Li addrinfo -structure(s). -.Sh EXAMPLES -The following code tries to connect to -.Dq Li www.kame.net -service -.Dq Li www -via a stream socket. -It loops through all the addresses available, regardless of address family. -If the destination resolves to an IPv4 address, it will use an -.Dv AF_INET -socket. -Similarly, if it resolves to IPv6, an -.Dv AF_INET6 -socket is used. -Observe that there is no hardcoded reference to a particular address family. -The code works even if -.Fn getaddrinfo -returns addresses that are not IPv4/v6. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = PF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -error = getaddrinfo("www.kame.net", "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -s = -1; -for (res = res0; res; res = res->ai_next) { - s = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s == -1) { - cause = "socket"; - continue; - } - - if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { - cause = "connect"; - save_errno = errno; - close(s); - errno = save_errno; - s = -1; - continue; - } - - break; /* okay we got one */ -} -if (s == -1) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Pp -The following example tries to open a wildcard listening socket onto service -.Dq Li www , -for all the address families available. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s[MAXSOCK]; -int nsock; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = PF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -hints.ai_flags = AI_PASSIVE; -error = getaddrinfo(NULL, "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -nsock = 0; -for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { - s[nsock] = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s[nsock] == -1) { - cause = "socket"; - continue; - } - - if (bind(s[nsock], res->ai_addr, res->ai_addrlen) == -1) { - cause = "bind"; - save_errno = errno; - close(s[nsock]); - errno = save_errno; - continue; - } - (void) listen(s[nsock], 5); - - nsock++; -} -if (nsock == 0) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Sh SEE ALSO -.Xr bind 2 , -.Xr connect 2 , -.Xr send 2 , -.Xr socket 2 , -.Xr gai_strerror 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr getservbyname 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 , -.Xr named 8 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 3493 -.%D February 2003 -.Re -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%T "IPv6 Scoped Address Architecture" -.%R RFC 4007 -.%D March 2005 -.Re -.Rs -.%A Craig Metz -.%T Protocol Independence Using the Sockets API -.%B "Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference" -.%D June 2000 -.Re -.Sh STANDARDS -The -.Fn getaddrinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in -.Dv "RFC 3493" , -.Dq Basic Socket Interface Extensions for IPv6 . -.Pp -The -.Dv AI_FQDN -flag bit first appeared in Windows 7. -.Sh BUGS -The implementation of -.Fn getaddrinfo -is not thread-safe. diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c deleted file mode 100644 index 29cc1f463e..0000000000 --- a/src/lib/libc/net/getaddrinfo.c +++ /dev/null @@ -1,1755 +0,0 @@ -/* $OpenBSD: getaddrinfo.c,v 1.72 2011/04/05 00:46:06 matthew Exp $ */ -/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Issues to be discussed: - * - Thread safe-ness must be checked. - * - Return values. There are nonstandard return values defined and used - * in the source code. This is because RFC2553 is silent about which error - * code must be returned for which situation. - * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2 - * says to use inet_aton() to convert IPv4 numeric to binary (allows - * classful form as a result). - * current code - disallow classful form for IPv4 (due to use of inet_pton). - * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is - * invalid. - * current code - SEGV on freeaddrinfo(NULL) - * Note: - * - We use getipnodebyname() just for thread-safeness. There's no intent - * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to - * getipnodebyname(). - * - The code filters out AFs that are not supported by the kernel, - * when globbing NULL hostname (to loopback, or wildcard). Is it the right - * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG - * in ai_flags? - * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. - * (1) what should we do against numeric hostname (2) what should we do - * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? - * non-loopback address configured? global address configured? - * - To avoid search order issue, we have a big amount of code duplicate - * from gethnamaddr.c and some other places. The issues that there's no - * lower layer function to lookup "IPv4 or IPv6" record. Calling - * gethostbyname2 from getaddrinfo will end up in wrong search order, as - * follows: - * - The code makes use of following calls when asked to resolver with - * ai_family = PF_UNSPEC: - * getipnodebyname(host, AF_INET6); - * getipnodebyname(host, AF_INET); - * This will result in the following queries if the node is configure to - * prefer /etc/hosts than DNS: - * lookup /etc/hosts for IPv6 address - * lookup DNS for IPv6 address - * lookup /etc/hosts for IPv4 address - * lookup DNS for IPv4 address - * which may not meet people's requirement. - * The right thing to happen is to have underlying layer which does - * PF_UNSPEC lookup (lookup both) and return chain of addrinfos. - * This would result in a bit of code duplicate with _dns_ghbyname() and - * friends. - */ - -#ifndef INET6 -#define INET6 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef YP -#include -#include -#include -#include "ypinternal.h" -#endif - -#include "thread_private.h" - -#define SUCCESS 0 -#define ANY 0 -#define YES 1 -#define NO 0 - -static const char in_addrany[] = { 0, 0, 0, 0 }; -static const char in6_addrany[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; -static const char in_loopback[] = { 127, 0, 0, 1 }; -static const char in6_loopback[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 -}; - -static const struct afd { - int a_af; - int a_addrlen; - int a_socklen; - int a_off; - const char *a_addrany; - const char *a_loopback; - int a_scoped; -} afdl [] = { -#ifdef INET6 - {PF_INET6, sizeof(struct in6_addr), - sizeof(struct sockaddr_in6), - offsetof(struct sockaddr_in6, sin6_addr), - in6_addrany, in6_loopback, 1}, -#endif - {PF_INET, sizeof(struct in_addr), - sizeof(struct sockaddr_in), - offsetof(struct sockaddr_in, sin_addr), - in_addrany, in_loopback, 0}, - {0, 0, 0, 0, NULL, NULL, 0}, -}; - -struct explore { - int e_af; - int e_socktype; - int e_protocol; - const char *e_protostr; - int e_wild; -#define WILD_AF(ex) ((ex)->e_wild & 0x01) -#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) -#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) -}; - -static const struct explore explore[] = { -#if 0 - { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, -#endif -#ifdef INET6 - { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, -#endif - { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, - { PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 }, - { -1, 0, 0, NULL, 0 }, -}; - -#ifdef INET6 -#define PTON_MAX 16 -#else -#define PTON_MAX 4 -#endif - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -struct res_target { - struct res_target *next; - const char *name; /* domain name */ - int qclass, qtype; /* class and type of query */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer buffer */ - int n; /* result length */ -}; - -static int explore_fqdn(const struct addrinfo *, const char *, - const char *, struct addrinfo **); -static int explore_null(const struct addrinfo *, - const char *, struct addrinfo **); -static int explore_numeric(const struct addrinfo *, const char *, - const char *, struct addrinfo **, const char *); -static int explore_numeric_scope(const struct addrinfo *, const char *, - const char *, struct addrinfo **); -static int get_canonname(const struct addrinfo *, - struct addrinfo *, const char *); -static struct addrinfo *get_ai(const struct addrinfo *, - const struct afd *, const char *); -static int get_portmatch(const struct addrinfo *, const char *); -static int get_port(struct addrinfo *, const char *, int); -static const struct afd *find_afd(int); -#ifdef INET6 -static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); -#endif - -static struct addrinfo * _gethtent(const char *, const struct addrinfo *, - FILE *); -static struct addrinfo *_files_getaddrinfo(const char *, - const struct addrinfo *); - -#ifdef YP -static struct addrinfo *_yphostent(char *, const struct addrinfo *); -static struct addrinfo *_yp_getaddrinfo(const char *, - const struct addrinfo *); -#endif - -static struct addrinfo *getanswer(const querybuf *, int, const char *, int, - const struct addrinfo *); -static int res_queryN(const char *, struct res_target *); -static int res_searchN(const char *, struct res_target *); -static int res_querydomainN(const char *, const char *, struct res_target *); -static struct addrinfo *_dns_getaddrinfo(const char *, const struct addrinfo *, - const struct __res_state *); - - -/* XXX macros that make external reference is BAD. */ - -#define GET_AI(ai, afd, addr) \ -do { \ - /* external reference: pai, error, and label free */ \ - (ai) = get_ai(pai, (afd), (addr)); \ - if ((ai) == NULL) { \ - error = EAI_MEMORY; \ - goto free; \ - } \ -} while (/*CONSTCOND*/0) - -#define GET_PORT(ai, serv) \ -do { \ - /* external reference: error and label free */ \ - error = get_port((ai), (serv), 0); \ - if (error != 0) \ - goto free; \ -} while (/*CONSTCOND*/0) - -#define GET_CANONNAME(ai, str) \ -do { \ - /* external reference: pai, error and label free */ \ - error = get_canonname(pai, (ai), (str)); \ - if (error != 0) \ - goto free; \ -} while (/*CONSTCOND*/0) - -#define ERR(err) \ -do { \ - /* external reference: error, and label bad */ \ - error = (err); \ - goto bad; \ - /*NOTREACHED*/ \ -} while (/*CONSTCOND*/0) - -#define MATCH_FAMILY(x, y, w) \ - ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) -#define MATCH(x, y, w) \ - ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) - -int -getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res) -{ - struct addrinfo sentinel; - struct addrinfo *cur; - int error = 0; - struct addrinfo ai; - struct addrinfo ai0; - struct addrinfo *pai; - const struct explore *ex; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - pai = &ai; - pai->ai_flags = 0; - pai->ai_family = PF_UNSPEC; - pai->ai_socktype = ANY; - pai->ai_protocol = ANY; - pai->ai_addrlen = 0; - pai->ai_canonname = NULL; - pai->ai_addr = NULL; - pai->ai_next = NULL; - - if (hostname == NULL && servname == NULL) - return EAI_NONAME; - if (hints) { - /* error check for hints */ - if (hints->ai_addrlen || hints->ai_canonname || - hints->ai_addr || hints->ai_next) - ERR(EAI_BADHINTS); /* xxx */ - if ((hints->ai_flags & ~AI_MASK) != 0 || - (hints->ai_flags & (AI_CANONNAME | AI_FQDN)) == - (AI_CANONNAME | AI_FQDN)) - ERR(EAI_BADFLAGS); - switch (hints->ai_family) { - case PF_UNSPEC: - case PF_INET: -#ifdef INET6 - case PF_INET6: -#endif - break; - default: - ERR(EAI_FAMILY); - } - memcpy(pai, hints, sizeof(*pai)); - - /* - * if both socktype/protocol are specified, check if they - * are meaningful combination. - */ - if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) { - for (ex = explore; ex->e_af >= 0; ex++) { - if (pai->ai_family != ex->e_af) - continue; - if (ex->e_socktype == ANY) - continue; - if (ex->e_protocol == ANY) - continue; - if (pai->ai_socktype == ex->e_socktype - && pai->ai_protocol != ex->e_protocol) { - ERR(EAI_BADHINTS); - } - } - } - } - - /* - * check for special cases. (1) numeric servname is disallowed if - * socktype/protocol are left unspecified. (2) servname is disallowed - * for raw and other inet{,6} sockets. - */ - if (MATCH_FAMILY(pai->ai_family, PF_INET, 1) -#ifdef PF_INET6 - || MATCH_FAMILY(pai->ai_family, PF_INET6, 1) -#endif - ) { - ai0 = *pai; /* backup *pai */ - - if (pai->ai_family == PF_UNSPEC) { -#ifdef PF_INET6 - pai->ai_family = PF_INET6; -#else - pai->ai_family = PF_INET; -#endif - } - error = get_portmatch(pai, servname); - if (error) - ERR(error); - - *pai = ai0; - } - - ai0 = *pai; - - /* NULL hostname, or numeric hostname */ - for (ex = explore; ex->e_af >= 0; ex++) { - *pai = ai0; - - /* PF_UNSPEC entries are prepared for DNS queries only */ - if (ex->e_af == PF_UNSPEC) - continue; - - if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) - continue; - if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex))) - continue; - if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) - continue; - - if (pai->ai_family == PF_UNSPEC) - pai->ai_family = ex->e_af; - if (pai->ai_socktype == ANY && ex->e_socktype != ANY) - pai->ai_socktype = ex->e_socktype; - if (pai->ai_protocol == ANY && ex->e_protocol != ANY) - pai->ai_protocol = ex->e_protocol; - - if (hostname == NULL) - error = explore_null(pai, servname, &cur->ai_next); - else - error = explore_numeric_scope(pai, hostname, servname, - &cur->ai_next); - - if (error) - goto free; - - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - /* - * XXX - * If numeric representation of AF1 can be interpreted as FQDN - * representation of AF2, we need to think again about the code below. - */ - if (sentinel.ai_next) - goto good; - - if (hostname == NULL) - ERR(EAI_NODATA); - if (pai->ai_flags & AI_NUMERICHOST) - ERR(EAI_NONAME); - - /* - * hostname as alphabetical name. - * we would like to prefer AF_INET6 than AF_INET, so we'll make an - * outer loop by AFs. - */ - for (ex = explore; ex->e_af >= 0; ex++) { - *pai = ai0; - - /* require exact match for family field */ - if (pai->ai_family != ex->e_af) - continue; - - if (!MATCH(pai->ai_socktype, ex->e_socktype, - WILD_SOCKTYPE(ex))) { - continue; - } - if (!MATCH(pai->ai_protocol, ex->e_protocol, - WILD_PROTOCOL(ex))) { - continue; - } - - if (pai->ai_socktype == ANY && ex->e_socktype != ANY) - pai->ai_socktype = ex->e_socktype; - if (pai->ai_protocol == ANY && ex->e_protocol != ANY) - pai->ai_protocol = ex->e_protocol; - - error = explore_fqdn(pai, hostname, servname, - &cur->ai_next); - - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - /* XXX */ - if (sentinel.ai_next) - error = 0; - - if (error == 0) { - if (sentinel.ai_next) { - good: - *res = sentinel.ai_next; - return SUCCESS; - } else - error = EAI_FAIL; - } - free: - bad: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - *res = NULL; - return error; -} - -/* - * FQDN hostname, DNS lookup - */ - -static int -explore_fqdn(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - struct addrinfo *result; - struct addrinfo *cur; - int error = 0; - char lookups[MAXDNSLUS]; - int i; - _THREAD_PRIVATE_MUTEX(_explore_mutex); - - result = NULL; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) { - return 0; - } - - if (_res_init(0) == -1) - strlcpy(lookups, "f", sizeof lookups); - else { - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - } - - /* - * The yp/dns/files getaddrinfo functions are not thread safe. - * Protect them with a mutex. - */ - _THREAD_PRIVATE_MUTEX_LOCK(_explore_mutex); - for (i = 0; i < MAXDNSLUS && result == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - result = _yp_getaddrinfo(hostname, pai); - break; -#endif - case 'b': - result = _dns_getaddrinfo(hostname, pai, _resp); - break; - case 'f': - result = _files_getaddrinfo(hostname, pai); - break; - } - } - _THREAD_PRIVATE_MUTEX_UNLOCK(_explore_mutex); - if (result) { - for (cur = result; cur; cur = cur->ai_next) { - GET_PORT(cur, servname); - /* canonname should be filled already */ - } - *res = result; - return 0; - } else { - /* translate error code */ - switch (h_errno) { - case NETDB_SUCCESS: - error = EAI_FAIL; /*XXX strange */ - break; - case HOST_NOT_FOUND: - error = EAI_NODATA; - break; - case TRY_AGAIN: - error = EAI_AGAIN; - break; - case NO_RECOVERY: - error = EAI_FAIL; - break; - case NO_DATA: -#if NO_ADDRESS != NO_DATA - case NO_ADDRESS: -#endif - error = EAI_NODATA; - break; - default: /* unknown ones */ - error = EAI_FAIL; - break; - } - } - -free: - if (result) - freeaddrinfo(result); - return error; -} - -/* - * hostname == NULL. - * passive socket -> anyaddr (0.0.0.0 or ::) - * non-passive socket -> localhost (127.0.0.1 or ::1) - */ -static int -explore_null(const struct addrinfo *pai, const char *servname, - struct addrinfo **res) -{ - int s; - const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; - int error; - - *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; - - /* - * filter out AFs that are not supported by the kernel - * XXX errno? - */ - s = socket(pai->ai_family, SOCK_DGRAM, 0); - if (s < 0) { - if (errno != EMFILE) - return 0; - } else - close(s); - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - if (pai->ai_flags & AI_PASSIVE) { - GET_AI(cur->ai_next, afd, afd->a_addrany); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "anyaddr"); - */ - } else { - GET_AI(cur->ai_next, afd, afd->a_loopback); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "localhost"); - */ - } - GET_PORT(cur->ai_next, servname); - cur = cur->ai_next; - - *res = sentinel.ai_next; - return 0; - -free: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - return error; -} - -/* - * numeric hostname - */ -static int -explore_numeric(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res, const char *canonname) -{ - const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; - int error; - char pton[PTON_MAX]; - - *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - switch (afd->a_af) { -#if 0 /*X/Open spec*/ - case AF_INET: - error = inet_aton(hostname, (struct in_addr *)pton); - break; -#endif - default: - error = inet_pton(afd->a_af, hostname, pton); - break; - } - if (error == 1) { - if (pai->ai_family == afd->a_af || - pai->ai_family == PF_UNSPEC /*?*/) { - GET_AI(cur->ai_next, afd, pton); - GET_PORT(cur->ai_next, servname); - /* - * Set the numeric address itself as - * the canonical name, based on a - * clarification in rfc2553bis-03. - */ - GET_CANONNAME(cur->ai_next, canonname); - - while (cur && cur->ai_next) - cur = cur->ai_next; - } else - ERR(EAI_FAMILY); /*xxx*/ - } - - *res = sentinel.ai_next; - return 0; - -free: -bad: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - return error; -} - -/* - * numeric hostname with scope - */ -static int -explore_numeric_scope(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res) -{ -#if !defined(SCOPE_DELIMITER) || !defined(INET6) - return explore_numeric(pai, hostname, servname, res, hostname); -#else - const struct afd *afd; - struct addrinfo *cur; - int error; - char *cp, *hostname2 = NULL, *scope, *addr; - struct sockaddr_in6 *sin6; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - if (!afd->a_scoped) - return explore_numeric(pai, hostname, servname, res, hostname); - - cp = strchr(hostname, SCOPE_DELIMITER); - if (cp == NULL) - return explore_numeric(pai, hostname, servname, res, hostname); - - /* - * Handle special case of - */ - hostname2 = strdup(hostname); - if (hostname2 == NULL) - return EAI_MEMORY; - /* terminate at the delimiter */ - hostname2[cp - hostname] = '\0'; - addr = hostname2; - scope = cp + 1; - - error = explore_numeric(pai, addr, servname, res, hostname); - if (error == 0) { - u_int32_t scopeid; - - for (cur = *res; cur; cur = cur->ai_next) { - if (cur->ai_family != AF_INET6) - continue; - sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr; - if (ip6_str2scopeid(scope, sin6, &scopeid) == -1) { - free(hostname2); - return(EAI_NODATA); /* XXX: is return OK? */ - } - sin6->sin6_scope_id = scopeid; - } - } - - free(hostname2); - - return error; -#endif -} - -static int -get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str) -{ - if ((pai->ai_flags & (AI_CANONNAME | AI_FQDN)) != 0) { - ai->ai_canonname = strdup(str); - if (ai->ai_canonname == NULL) - return EAI_MEMORY; - } - return 0; -} - -static struct addrinfo * -get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr) -{ - char *p; - struct addrinfo *ai; - - ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) - + (afd->a_socklen)); - if (ai == NULL) - return NULL; - - memcpy(ai, pai, sizeof(struct addrinfo)); - ai->ai_addr = (struct sockaddr *)(void *)(ai + 1); - memset(ai->ai_addr, 0, (size_t)afd->a_socklen); - ai->ai_addr->sa_len = afd->a_socklen; - ai->ai_addrlen = afd->a_socklen; - ai->ai_addr->sa_family = ai->ai_family = afd->a_af; - p = (char *)(void *)(ai->ai_addr); - memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen); - return ai; -} - -static int -get_portmatch(const struct addrinfo *ai, const char *servname) -{ - - /* get_port does not touch first argument. when matchonly == 1. */ - /* LINTED const cast */ - return get_port((struct addrinfo *)ai, servname, 1); -} - -static int -get_port(struct addrinfo *ai, const char *servname, int matchonly) -{ - const char *errstr, *proto; - int port; - int allownumeric; - - if (servname == NULL) - return 0; - switch (ai->ai_family) { - case AF_INET: -#ifdef AF_INET6 - case AF_INET6: -#endif - break; - default: - return 0; - } - - switch (ai->ai_socktype) { - case SOCK_RAW: - return EAI_SERVICE; - case SOCK_DGRAM: - case SOCK_STREAM: - case ANY: - allownumeric = 1; - break; - default: - return EAI_SOCKTYPE; - } - - port = (int)strtonum(servname, 0, USHRT_MAX, &errstr); - if (!errstr) { - if (!allownumeric) - return EAI_SERVICE; - port = htons(port); - } else { - struct servent sp; - struct servent_data sd; - - if (errno == ERANGE) - return EAI_SERVICE; - if (ai->ai_flags & AI_NUMERICSERV) - return EAI_NONAME; - - switch (ai->ai_socktype) { - case SOCK_DGRAM: - proto = "udp"; - break; - case SOCK_STREAM: - proto = "tcp"; - break; - default: - proto = NULL; - break; - } - - (void)memset(&sd, 0, sizeof(sd)); - if (getservbyname_r(servname, proto, &sp, &sd) == -1) - return EAI_SERVICE; - port = sp.s_port; - endservent_r(&sd); - } - - if (!matchonly) { - switch (ai->ai_family) { - case AF_INET: - ((struct sockaddr_in *)(void *) - ai->ai_addr)->sin_port = port; - break; -#ifdef INET6 - case AF_INET6: - ((struct sockaddr_in6 *)(void *) - ai->ai_addr)->sin6_port = port; - break; -#endif - } - } - - return 0; -} - -static const struct afd * -find_afd(int af) -{ - const struct afd *afd; - - if (af == PF_UNSPEC) - return NULL; - for (afd = afdl; afd->a_af; afd++) { - if (afd->a_af == af) - return afd; - } - return NULL; -} - -#ifdef INET6 -/* convert a string to a scope identifier. XXX: IPv6 specific */ -static int -ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid) -{ - struct in6_addr *a6 = &sin6->sin6_addr; - const char *errstr; - - /* empty scopeid portion is invalid */ - if (*scope == '\0') - return -1; - - if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || - IN6_IS_ADDR_MC_INTFACELOCAL(a6)) { - /* - * We currently assume a one-to-one mapping between links - * and interfaces, so we simply use interface indices for - * like-local scopes. - */ - *scopeid = if_nametoindex(scope); - if (*scopeid == 0) - goto trynumeric; - return 0; - } - - /* still unclear about literal, allow numeric only - placeholder */ - if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6)) - goto trynumeric; - if (IN6_IS_ADDR_MC_ORGLOCAL(a6)) - goto trynumeric; - else - goto trynumeric; /* global */ - - /* try to convert to a numeric id as a last resort */ - trynumeric: - *scopeid = (u_int32_t)strtonum(scope, 0, UINT32_MAX, &errstr); - if (errstr) - return (-1); - return (0); -} -#endif - -/* code duplicate with gethnamaddr.c */ - -static const char AskedForGot[] = - "gethostby*.getanswer: asked for \"%s\", got \"%s\""; - -static struct addrinfo * -getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, - const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo ai; - const struct afd *afd; - char *canonname; - const HEADER *hp; - const u_char *cp; - int n; - const u_char *eom; - char *bp, *ep; - int type, class, ancount, qdcount; - int haveanswer, had_error; - char tbuf[MAXDNAME]; - int (*name_ok)(const char *); - char hostbuf[8*1024]; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - canonname = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: - case T_ANY: /*use T_ANY only for T_A/T_AAAA lookup*/ - name_ok = res_hnok; - break; - default: - return (NULL); /* XXX should be abort() -- but that is illegal */ - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - ep = hostbuf + sizeof hostbuf; - cp = answer->buf + HFIXEDSZ; - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return (NULL); - } - cp += n + QFIXEDSZ; - if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) { - size_t len; - - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - len = strlen(bp) + 1; /* for the \0 */ - if (len >= MAXHOSTNAMELEN) { - h_errno = NO_RECOVERY; - return (NULL); - } - canonname = bp; - bp += len; - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = canonname; - } - haveanswer = 0; - had_error = 0; - while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - type = _getshort(cp); - cp += INT16SZ; /* type */ - class = _getshort(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ - n = _getshort(cp); - cp += INT16SZ; /* len */ - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) && - type == T_CNAME) { - size_t len; - - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp || len >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - canonname = bp; - bp += len; - continue; - } - if (qtype == T_ANY) { - if (!(type == T_A || type == T_AAAA)) { - cp += n; - continue; - } - } else if (type != qtype) { -#ifndef NO_LOG_BAD_DNS_RESPONSES - if (type != T_KEY && type != T_SIG) { - struct syslog_data sdata = SYSLOG_DATA_INIT; - - syslog_r(LOG_NOTICE|LOG_AUTH, &sdata, - "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - } -#endif /* NO_LOG_BAD_DNS_RESPONSES */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_A: - case T_AAAA: - if (strcasecmp(canonname, bp) != 0) { - struct syslog_data sdata = SYSLOG_DATA_INIT; - - syslog_r(LOG_NOTICE|LOG_AUTH, &sdata, - AskedForGot, canonname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (type == T_A && n != INADDRSZ) { - cp += n; - continue; - } - if (type == T_AAAA && n != IN6ADDRSZ) { - cp += n; - continue; - } - if (type == T_AAAA) { - struct in6_addr in6; - memcpy(&in6, cp, IN6ADDRSZ); - if (IN6_IS_ADDR_V4MAPPED(&in6)) { - cp += n; - continue; - } - } - if (!haveanswer) { - canonname = bp; - bp += strlen(bp) + 1; /* for the \0 */ - } - - /* don't overwrite pai */ - ai = *pai; - ai.ai_family = (type == T_A) ? AF_INET : AF_INET6; - afd = find_afd(ai.ai_family); - if (afd == NULL) { - cp += n; - continue; - } - cur->ai_next = get_ai(&ai, afd, (const char *)cp); - if (cur->ai_next == NULL) - had_error++; - while (cur && cur->ai_next) - cur = cur->ai_next; - cp += n; - break; - default: - abort(); /* XXX abort illegal in library */ - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - if (!canonname || (pai->ai_flags & AI_FQDN) != 0) - (void)get_canonname(pai, sentinel.ai_next, qname); - else - (void)get_canonname(pai, sentinel.ai_next, canonname); - h_errno = NETDB_SUCCESS; - return sentinel.ai_next; - } - - h_errno = NO_RECOVERY; - return NULL; -} - -/*ARGSUSED*/ -static struct addrinfo * -_dns_getaddrinfo(const char *name, const struct addrinfo *pai, - const struct __res_state *_resp) -{ - struct addrinfo *ai; - querybuf *buf, *buf2; - struct addrinfo sentinel, *cur; - struct res_target q, q2; - - memset(&q, 0, sizeof(q)); - memset(&q2, 0, sizeof(q2)); - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NULL; - } - buf2 = malloc(sizeof(*buf2)); - if (buf2 == NULL) { - free(buf); - h_errno = NETDB_INTERNAL; - return NULL; - } - - switch (pai->ai_family) { - case AF_UNSPEC: - /* respect user supplied order */ - q.qclass = C_IN; - q.qtype = (_resp->family[0] == AF_INET6) ? T_AAAA : T_A; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - q.next = &q2; - - if (_resp->family[1] == -1) { - /* stop here if only one family was given */ - q.next = NULL; - break; - } - - q2.qclass = C_IN; - q2.qtype = (_resp->family[1] == AF_INET6) ? T_AAAA : T_A; - q2.answer = buf2->buf; - q2.anslen = sizeof(buf2->buf); - break; - case AF_INET: - q.qclass = C_IN; - q.qtype = T_A; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - break; - case AF_INET6: - q.qclass = C_IN; - q.qtype = T_AAAA; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - break; - default: - free(buf); - free(buf2); - return NULL; - } - if (res_searchN(name, &q) < 0) { - free(buf); - free(buf2); - return NULL; - } - ai = getanswer(buf, q.n, q.name, q.qtype, pai); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - if (q.next) { - ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai); - if (ai) - cur->ai_next = ai; - } - free(buf); - free(buf2); - return sentinel.ai_next; -} - -static struct addrinfo * -_gethtent(const char *name, const struct addrinfo *pai, FILE *hostf) -{ - char *p; - char *cp, *tname, *cname; - struct addrinfo hints, *res0, *res; - int error; - const char *addr; - char hostbuf[8*1024]; - - again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) - return (NULL); - if (*p == '#') - goto again; - if (!(cp = strpbrk(p, "#\n"))) - goto again; - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - addr = p; - /* if this is not something we're looking for, skip it. */ - cname = NULL; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (!cname) - cname = cp; - tname = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - if (strcasecmp(name, tname) == 0) - goto found; - } - goto again; - -found: - hints = *pai; - hints.ai_flags = AI_NUMERICHOST; - error = getaddrinfo(addr, NULL, &hints, &res0); - if (error) - goto again; - for (res = res0; res; res = res->ai_next) { - /* cover it up */ - res->ai_flags = pai->ai_flags; - - if (get_canonname(pai, res, cname) != 0) { - freeaddrinfo(res0); - goto again; - } - } - return res0; -} - -/*ARGSUSED*/ -static struct addrinfo * -_files_getaddrinfo(const char *name, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo *p; - FILE *hostf; - - hostf = fopen(_PATH_HOSTS, "r"); - if (hostf == NULL) - return NULL; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - while ((p = _gethtent(name, pai, hostf)) != NULL) { - cur->ai_next = p; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - fclose(hostf); - - return sentinel.ai_next; -} - -#ifdef YP -static char *__ypdomain; - -/*ARGSUSED*/ -static struct addrinfo * -_yphostent(char *line, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo hints, *res, *res0; - int error; - char *p = line; - const char *addr, *canonname; - char *nextline; - char *cp; - - addr = canonname = NULL; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - -nextline: - /* terminate line */ - cp = strchr(p, '\n'); - if (cp) { - *cp++ = '\0'; - nextline = cp; - } else - nextline = NULL; - - cp = strpbrk(p, " \t"); - if (cp == NULL) { - if (canonname == NULL) - return (NULL); - else - goto done; - } - *cp++ = '\0'; - - addr = p; - - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (!canonname) - canonname = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - } - - hints = *pai; - hints.ai_flags = AI_NUMERICHOST; - error = getaddrinfo(addr, NULL, &hints, &res0); - if (error == 0) { - for (res = res0; res; res = res->ai_next) { - /* cover it up */ - res->ai_flags = pai->ai_flags; - - (void)get_canonname(pai, res, canonname); - } - } else - res0 = NULL; - if (res0) { - cur->ai_next = res0; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - if (nextline) { - p = nextline; - goto nextline; - } - -done: - return sentinel.ai_next; -} - -/*ARGSUSED*/ -static struct addrinfo * -_yp_getaddrinfo(const char *name, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo *ai = NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NULL; - } - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - - /* hosts.byname is only for IPv4 (Solaris8) */ - if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) { - r = yp_match(__ypdomain, "hosts.byname", name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) { - struct addrinfo ai4; - - ai4 = *pai; - ai4.ai_family = AF_INET; - ai = _yphostent(__ypcurrent, &ai4); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - } - } - - /* ipnodes.byname can hold both IPv4/v6 */ - r = yp_match(__ypdomain, "ipnodes.byname", name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) { - ai = _yphostent(__ypcurrent, pai); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - } - - return sentinel.ai_next; -} -#endif - - -/* resolver logic */ - -extern const char *__hostalias(const char *); -extern int h_errno; -extern int res_opt(int, u_char *, int, int); - -/* - * Formulate a normal query, send, and await answer. - * Returned answer is placed in supplied buffer "answer". - * Perform preliminary check of answer, returning success only - * if no error is indicated and the answer count is nonzero. - * Return the size of the response on success, -1 on error. - * Error number is left in h_errno. - * - * Caller must parse answer and determine whether it answers the question. - */ -static int -res_queryN(const char *name, struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - u_char *buf; - HEADER *hp; - int n; - struct res_target *t; - int rcode; - int ancount; - - buf = malloc(MAXPACKET); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return (-1); - } - - rcode = NOERROR; - ancount = 0; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - free(buf); - return (-1); - } - - for (t = target; t; t = t->next) { - int class, type; - u_char *answer; - int anslen; - - hp = (HEADER *)(void *)t->answer; - hp->rcode = NOERROR; /* default */ - - /* make it easier... */ - class = t->qclass; - type = t->qtype; - answer = t->answer; - anslen = t->anslen; -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query(%s, %d, %d)\n", name, class, type); -#endif - - n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, - buf, MAXPACKET); - if (n > 0 && (_resp->options & RES_USE_EDNS0) != 0) - n = res_opt(n, buf, MAXPACKET, anslen); - if (n <= 0) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query: mkquery failed\n"); -#endif - h_errno = NO_RECOVERY; - free(buf); - return (n); - } - n = res_send(buf, n, answer, anslen); -#if 0 - if (n < 0) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query: send error\n"); -#endif - h_errno = TRY_AGAIN; - free(buf); - return (n); - } -#endif - - if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { - rcode = hp->rcode; /* record most recent error */ -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; rcode = %u, ancount=%u\n", hp->rcode, - ntohs(hp->ancount)); -#endif - continue; - } - - ancount += ntohs(hp->ancount); - - t->n = n; - } - - if (ancount == 0) { - switch (rcode) { - case NXDOMAIN: - h_errno = HOST_NOT_FOUND; - break; - case SERVFAIL: - h_errno = TRY_AGAIN; - break; - case NOERROR: - h_errno = NO_DATA; - break; - case FORMERR: - case NOTIMP: - case REFUSED: - default: - h_errno = NO_RECOVERY; - break; - } - free(buf); - return (-1); - } - free(buf); - return (ancount); -} - -/* - * Formulate a normal query, send, and retrieve answer in supplied buffer. - * Return the size of the response on success, -1 on error. - * If enabled, implement search rules until answer or unrecoverable failure - * is detected. Error code, if any, is left in h_errno. - */ -static int -res_searchN(const char *name, struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const char *cp, * const *domain; - HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ - u_int dots; - int trailing_dot, ret, saved_herrno; - int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } - - errno = 0; - h_errno = HOST_NOT_FOUND; /* default, if we never query */ - dots = 0; - for (cp = name; *cp; cp++) - dots += (*cp == '.'); - trailing_dot = 0; - if (cp > name && *--cp == '.') - trailing_dot++; - - /* - * if there aren't any dots, it could be a user-level alias - */ - if (!dots && (cp = __hostalias(name)) != NULL) - return (res_queryN(cp, target)); - - /* - * If there are dots in the name already, let's just give it a try - * 'as is'. The threshold can be set with the "ndots" option. - */ - saved_herrno = -1; - if (dots >= _resp->ndots) { - ret = res_querydomainN(name, NULL, target); - if (ret > 0) - return (ret); - saved_herrno = h_errno; - tried_as_is++; - } - - /* - * We do at least one level of search if - * - there is no dot and RES_DEFNAME is set, or - * - there is at least one dot, there is no trailing dot, - * and RES_DNSRCH is set. - */ - if ((!dots && (_resp->options & RES_DEFNAMES)) || - (dots && !trailing_dot && (_resp->options & RES_DNSRCH))) { - int done = 0; - - for (domain = (const char * const *)_resp->dnsrch; - *domain && !done; - domain++) { - - ret = res_querydomainN(name, *domain, target); - if (ret > 0) - return (ret); - - /* - * If no server present, give up. - * If name isn't found in this domain, - * keep trying higher domains in the search list - * (if that's enabled). - * On a NO_DATA error, keep trying, otherwise - * a wildcard entry of another type could keep us - * from finding this entry higher in the domain. - * If we get some other error (negative answer or - * server failure), then stop searching up, - * but try the input name below in case it's - * fully-qualified. - */ - if (errno == ECONNREFUSED) { - h_errno = TRY_AGAIN; - return (-1); - } - - switch (h_errno) { - case NO_DATA: - got_nodata++; - /* FALLTHROUGH */ - case HOST_NOT_FOUND: - /* keep trying */ - break; - case TRY_AGAIN: - if (hp->rcode == SERVFAIL) { - /* try next search element, if any */ - got_servfail++; - break; - } - /* FALLTHROUGH */ - default: - /* anything else implies that we're done */ - done++; - } - /* - * if we got here for some reason other than DNSRCH, - * we only wanted one iteration of the loop, so stop. - */ - if (!(_resp->options & RES_DNSRCH)) - done++; - } - } - - /* - * if we have not already tried the name "as is", do that now. - * note that we do this regardless of how many dots were in the - * name or whether it ends with a dot. - */ - if (!tried_as_is) { - ret = res_querydomainN(name, NULL, target); - if (ret > 0) - return (ret); - } - - /* - * if we got here, we didn't satisfy the search. - * if we did an initial full query, return that query's h_errno - * (note that we wouldn't be here if that query had succeeded). - * else if we ever got a nodata, send that back as the reason. - * else send back meaningless h_errno, that being the one from - * the last DNSRCH we did. - */ - if (saved_herrno != -1) - h_errno = saved_herrno; - else if (got_nodata) - h_errno = NO_DATA; - else if (got_servfail) - h_errno = TRY_AGAIN; - return (-1); -} - -/* - * Perform a call on res_query on the concatenation of name and domain, - * removing a trailing dot from name if domain is NULL. - */ -static int -res_querydomainN(const char *name, const char *domain, - struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - char nbuf[MAXDNAME]; - const char *longname = nbuf; - size_t len; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_querydomain(%s, %s)\n", - name, domain?domain:""); -#endif - if (domain == NULL) { - /* - * Check for trailing '.'; - * copy without '.' if present. - */ - len = strlcpy(nbuf, name, sizeof(nbuf)); - if (len >= sizeof(nbuf)) { - h_errno = NO_RECOVERY; - return (-1); - } - if (len > 0 && nbuf[len - 1] == '.') - nbuf[len - 1] = '\0'; - } else { - int i; - - i = snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain); - if (i < 0 || i >= sizeof(nbuf)) { - h_errno = NO_RECOVERY; - return (-1); - } - } - return (res_queryN(longname, target)); -} diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 deleted file mode 100644 index 1a05460da4..0000000000 --- a/src/lib/libc/net/gethostbyname.3 +++ /dev/null @@ -1,297 +0,0 @@ -.\" $OpenBSD: gethostbyname.3,v 1.25 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1987, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETHOSTBYNAME 3 -.Os -.Sh NAME -.Nm gethostbyname , -.Nm gethostbyname2 , -.Nm gethostbyaddr , -.Nm gethostent , -.Nm sethostent , -.Nm endhostent , -.Nm hstrerror , -.Nm herror -.Nd get network host entry -.Sh SYNOPSIS -.Fd #include -.Vt extern int h_errno ; -.Ft struct hostent * -.Fn gethostbyname "const char *name" -.Ft struct hostent * -.Fn gethostbyname2 "const char *name" "int af" -.Ft struct hostent * -.Fn gethostbyaddr "const void *addr" "socklen_t len" "int af" -.Ft struct hostent * -.Fn gethostent void -.Ft void -.Fn sethostent "int stayopen" -.Ft void -.Fn endhostent void -.Ft void -.Fn herror "const char *string" -.Ft const char * -.Fn hstrerror "int err" -.Sh DESCRIPTION -The -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -functions each return a pointer to an object with the following structure -describing an Internet host referenced by name or by address, respectively. -This structure contains either information obtained from the name server (i.e., -.Xr resolver 3 -and -.Xr named 8 ) , -broken-out fields from a line in -.Pa /etc/hosts , -or database entries supplied by the -.Xr yp 8 -system. -.Xr resolv.conf 5 -describes how the particular database is chosen. -.Bd -literal -offset indent -struct hostent { - char *h_name; /* official name of host */ - char **h_aliases; /* alias list */ - int h_addrtype; /* host address type */ - int h_length; /* length of address */ - char **h_addr_list; /* list of returned addresses */ -}; -#define h_addr h_addr_list[0] /* address, for backward compat */ -.Ed -.Pp -The members of this structure are: -.Bl -tag -width h_addr_list -.It Fa h_name -Official name of the host. -.It Fa h_aliases -A null-terminated array of alternate names for the host. -.It Fa h_addrtype -The type of address being returned. -.It Fa h_length -The length, in bytes, of the address. -.It Fa h_addr_list -A null-terminated array of network addresses for the host. -Host addresses are returned in network byte order. -.It Fa h_addr -The first address in -.Fa h_addr_list ; -this is for backward compatibility. -.El -.Pp -The function -.Fn gethostbyname -will search for the named host in the current domain and its parents -using the search lookup semantics detailed in -.Xr resolv.conf 5 -and -.Xr hostname 7 . -.Pp -.Fn gethostbyname2 -is an advanced form of -.Fn gethostbyname -which allows lookups in address families other than -.Dv AF_INET . -Currently, the only supported address family besides -.Dv AF_INET -is -.Dv AF_INET6 . -.Pp -The -.Fn gethostbyaddr -function will search for the specified address of length -.Fa len -in the address family -.Fa af . -The only address family currently supported is -.Dv AF_INET . -.Pp -The -.Fn sethostent -function may be used to request the use of a connected -.Tn TCP -socket for queries. -If the -.Fa stayopen -flag is non-zero, -this sets the option to send all queries to the name server using -.Tn TCP -and to retain the connection after each call to -.Fn gethostbyname -or -.Fn gethostbyaddr . -Otherwise, queries are performed using -.Tn UDP -datagrams. -.Pp -The -.Fn endhostent -function closes the -.Tn TCP -connection. -.Pp -The -.Fn herror -function prints an error message describing the failure. -If its argument -.Fa string -is non-null, -it is prepended to the message string and separated from it by a colon -.Pq Ql \&: -and a space. -The error message is printed with a trailing newline. -The contents of the error message is the same as that returned by -.Fn hstrerror -with argument -.Fa h_errno . -.Sh ENVIRONMENT -.Bl -tag -width HOSTALIASES -.It HOSTALIASES -A file containing local host aliases. -See -.Xr hostname 7 -for more information. -.It RES_OPTIONS -A list of options to override the resolver's internal defaults. -See -.Xr resolver 3 -for more information. -.El -.Sh FILES -.Bl -tag -width /etc/resolv.conf -compact -.It Pa /etc/hosts -.It Pa /etc/resolv.conf -.El -.Sh DIAGNOSTICS -Error return status from -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -is indicated by return of a null pointer. -The external integer -.Va h_errno -may then be checked to see whether this is a temporary failure -or an invalid or unknown host. -.Pp -The variable -.Va h_errno -can have the following values: -.Bl -tag -width HOST_NOT_FOUND -.It Dv HOST_NOT_FOUND -No such host is known. -.It Dv TRY_AGAIN -This is usually a temporary error -and means that the local server did not receive -a response from an authoritative server. -A retry at some later time may succeed. -.It Dv NO_RECOVERY -Some unexpected server failure was encountered. -This is a non-recoverable error. -.It Dv NO_DATA -The requested name is valid but does not have an IP address; -this is not a temporary error. -This means that the name is known to the name server but there is no address -associated with this name. -Another type of request to the name server using this domain name -will result in an answer; -for example, a mail-forwarder may be registered for this domain. -.It Dv NETDB_INTERNAL -An internal error occurred. -This may occur when an address family other than -.Dv AF_INET -or -.Dv AF_INET6 -is specified or when a resource is unable to be allocated. -.It Dv NETDB_SUCCESS -The function completed successfully. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr hostname 7 , -.Xr named 8 -.Sh HISTORY -The -.Fn herror -function appeared in -.Bx 4.3 . -The -.Fn endhostent , -.Fn gethostbyaddr , -.Fn gethostbyname , -.Fn gethostent , -and -.Fn sethostent -functions appeared in -.Bx 4.2 . -.Sh CAVEATS -If the search routines in -.Xr resolv.conf 5 -decide to read the -.Pa /etc/hosts -file, -.Fn gethostent -and other functions will -read the next line of the file, -re-opening the file if necessary. -.Pp -The -.Fn sethostent -function opens and/or rewinds the file -.Pa /etc/hosts . -If the -.Fa stayopen -argument is non-zero, the file will not be closed after each call to -.Fn gethostbyname , -.Fn gethostbyname2 , -or -.Fn gethostbyaddr . -.Pp -The -.Fn endhostent -function closes the file. -.Sh BUGS -These functions use static data storage; -if the data is needed for future use, it should be -copied before any subsequent calls overwrite it. -.Pp -Only the Internet -address formats are currently understood. -.Pp -YP does not support any address families other than -.Dv AF_INET -and uses -the traditional database format. diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c deleted file mode 100644 index f4e655eeaf..0000000000 --- a/src/lib/libc/net/gethostnamadr.c +++ /dev/null @@ -1,1131 +0,0 @@ -/* $OpenBSD: gethostnamadr.c,v 1.73 2009/11/18 07:43:22 guenther Exp $ */ -/*- - * Copyright (c) 1985, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef YP -#include -#include -#include -#include "ypinternal.h" -#endif -#include "thread_private.h" - -#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ - -#define MAXALIASES 35 -#define MAXADDRS 35 - -static char *h_addr_ptrs[MAXADDRS + 1]; - -#ifdef YP -static char *__ypdomain; -#endif - -static struct hostent host; -static char *host_aliases[MAXALIASES]; -static char hostbuf[BUFSIZ+1]; -static union { - struct in_addr _host_in_addr; - u_char _host_addr[16]; /* IPv4 or IPv6 */ -} _host_addr_u; -#define host_addr _host_addr_u._host_addr -static FILE *hostf = NULL; -static int stayopen = 0; - -static void map_v4v6_address(const char *src, char *dst); -static void map_v4v6_hostent(struct hostent *hp, char **bp, char *); - -#ifdef RESOLVSORT -static void addrsort(char **, int); -#endif - -int _hokchar(const char *); - -static const char AskedForGot[] = - "gethostby*.getanswer: asked for \"%s\", got \"%s\""; - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - int32_t al; - char ac; -} align; - -static struct hostent *getanswer(const querybuf *, int, const char *, int); - -extern int h_errno; - -int -_hokchar(const char *p) -{ - char c; - - /* - * Many people do not obey RFC 822 and 1035. The valid - * characters are a-z, A-Z, 0-9, '-' and . But the others - * tested for below can happen, and we must be more permissive - * than the resolver until those idiots clean up their act. - * We let '/' through, but not '..' - */ - while ((c = *p++)) { - if (('a' <= c && c <= 'z') || - ('A' <= c && c <= 'Z') || - ('0' <= c && c <= '9')) - continue; - if (strchr("-_/", c)) - continue; - if (c == '.' && *p != '.') - continue; - return 0; - } - return 1; -} - -static struct hostent * -getanswer(const querybuf *answer, int anslen, const char *qname, int qtype) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const HEADER *hp; - const u_char *cp, *eom; - char tbuf[MAXDNAME]; - char *bp, **ap, **hap, *ep; - int type, class, ancount, qdcount, n; - int haveanswer, had_error, toobig = 0; - const char *tname; - int (*name_ok)(const char *); - - tname = qname; - host.h_name = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: -#ifdef USE_RESOLV_NAME_OK - name_ok = res_hnok; - break; -#endif - case T_PTR: -#ifdef USE_RESOLV_NAME_OK - name_ok = res_dnok; -#else - name_ok = _hokchar; -#endif - break; - default: - return (NULL); - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - ep = hostbuf + sizeof hostbuf; - cp = answer->buf + HFIXEDSZ; - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return (NULL); - } - cp += n + QFIXEDSZ; - if (qtype == T_A || qtype == T_AAAA) { - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - host.h_name = bp; - bp += strlen(bp) + 1; /* for the \0 */ - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = host.h_name; - } - ap = host_aliases; - *ap = NULL; - host.h_aliases = host_aliases; - hap = h_addr_ptrs; - *hap = NULL; - host.h_addr_list = h_addr_ptrs; - haveanswer = 0; - had_error = 0; - while (ancount-- > 0 && cp < eom && !had_error) { - size_t len; - - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - if (cp >= eom) - break; - type = _getshort(cp); - cp += INT16SZ; /* type */ - if (cp >= eom) - break; - class = _getshort(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ - if (cp >= eom) - break; - n = _getshort(cp); - cp += INT16SZ; /* len */ - if (cp >= eom) - break; - if (type == T_SIG || type == T_RRSIG) { - /* XXX - ignore signatures as we don't use them yet */ - cp += n; - continue; - } - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { - if (ap >= &host_aliases[MAXALIASES-1]) - continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Store alias. */ - *ap++ = bp; - bp += strlen(bp) + 1; /* for the \0 */ - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - host.h_name = bp; - bp += len; - continue; - } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(tbuf)) { -#else - if ((n < 0) || !_hokchar(tbuf)) { -#endif - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - tname = bp; - bp += len; - continue; - } - if (type != qtype) { -#ifndef NO_LOG_BAD_DNS_RESPONSES - syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); -#endif /* NO_LOG_BAD_DNS_RESPONSES */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_PTR: - if (strcasecmp(tname, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, qname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(bp)) { -#else - if ((n < 0) || !_hokchar(bp)) { -#endif - had_error++; - break; - } -#if MULTI_PTRS_ARE_ALIASES - cp += n; - if (!haveanswer) - host.h_name = bp; - else if (ap < &host_aliases[MAXALIASES-1]) - *ap++ = bp; - else - n = -1; - if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ - bp += n; - } - break; -#else - host.h_name = bp; - if (_resp->options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - bp += n; - map_v4v6_hostent(&host, &bp, ep); - } - h_errno = NETDB_SUCCESS; - return (&host); -#endif - case T_A: - case T_AAAA: - if (strcasecmp(host.h_name, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, host.h_name, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (n != host.h_length) { - cp += n; - continue; - } - if (type == T_AAAA) { - struct in6_addr in6; - memcpy(&in6, cp, IN6ADDRSZ); - if (IN6_IS_ADDR_V4MAPPED(&in6)) { - cp += n; - continue; - } - } - if (!haveanswer) { - host.h_name = bp; - bp += strlen(bp) + 1; /* for the \0 */ - } - - bp += sizeof(align) - ((u_long)bp % sizeof(align)); - - if (bp + n >= &hostbuf[sizeof hostbuf]) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("size (%d) too big\n", n); -#endif - had_error++; - continue; - } - if (hap >= &h_addr_ptrs[MAXADDRS-1]) { - if (!toobig++) -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("Too many addresses (%d)\n", MAXADDRS); -#endif - cp += n; - continue; - } - bcopy(cp, *hap++ = bp, n); - bp += n; - cp += n; - break; - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - *ap = NULL; - *hap = NULL; -# if defined(RESOLVSORT) - /* - * Note: we sort even if host can take only one address - * in its return structures - should give it the "best" - * address in that case, not some random one - */ - if (_resp->nsort && haveanswer > 1 && qtype == T_A) - addrsort(h_addr_ptrs, haveanswer); -# endif /*RESOLVSORT*/ - if (!host.h_name) { - size_t len; - - len = strlen(qname) + 1; - if (len > ep - bp) /* for the \0 */ - goto try_again; - strlcpy(bp, qname, ep - bp); - host.h_name = bp; - bp += len; - } - if (_resp->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return (&host); - } - try_again: - h_errno = TRY_AGAIN; - return (NULL); -} - -#ifdef notyet -/* - * XXX This is an extremely bogus implementation. - * - * FreeBSD has this interface: - * int gethostbyaddr_r(const char *addr, int len, int type, - * struct hostent *result, struct hostent_data *buffer) - */ - -struct hostent * -gethostbyname_r(const char *name, struct hostent *hp, char *buf, int buflen, - int *errorp) -{ - struct hostent *res; - - res = gethostbyname(name); - *errorp = h_errno; - if (res == NULL) - return NULL; - memcpy(hp, res, sizeof *hp); /* XXX not sufficient */ - return hp; -} - -/* - * XXX This is an extremely bogus implementation. - */ -struct hostent * -gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, - char *buf, int buflen, int *errorp) -{ - struct hostent * res; - - res = gethostbyaddr(addr, len, af); - *errorp = h_errno; - if (res == NULL) - return NULL; - memcpy(he, res, sizeof *he); /* XXX not sufficient */ - return he; -} - -/* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */ -#endif - -struct hostent * -gethostbyname(const char *name) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - struct hostent *hp; - extern struct hostent *_gethtbyname2(const char *, int); - - if (_res_init(0) == -1) - hp = _gethtbyname2(name, AF_INET); - - else if (_resp->options & RES_USE_INET6) { - hp = gethostbyname2(name, AF_INET6); - if (hp == NULL) - hp = gethostbyname2(name, AF_INET); - } - else - hp = gethostbyname2(name, AF_INET); - return hp; -} - -struct hostent * -gethostbyname2(const char *name, int af) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - querybuf *buf; - const char *cp; - char *bp, *ep; - int n, size, type, i; - struct hostent *hp; - char lookups[MAXDNSLUS]; - extern struct hostent *_gethtbyname2(const char *, int); -#ifdef YP - extern struct hostent *_yp_gethtbyname(const char *); -#endif - - if (_res_init(0) == -1) - return (_gethtbyname2(name, af)); - - switch (af) { - case AF_INET: - size = INADDRSZ; - type = T_A; - break; - case AF_INET6: - size = IN6ADDRSZ; - type = T_AAAA; - break; - default: - h_errno = NETDB_INTERNAL; - errno = EAFNOSUPPORT; - return (NULL); - } - - host.h_addrtype = af; - host.h_length = size; - - /* - * if there aren't any dots, it could be a user-level alias. - * this is also done in res_query() since we are not the only - * function that looks up host names. - */ - if (!strchr(name, '.') && (cp = __hostalias(name))) - name = cp; - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit(name[0])) - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-numeric, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strlcpy(hostbuf, name, MAXHOSTNAMELEN); - bp = hostbuf + MAXHOSTNAMELEN; - ep = hostbuf + sizeof(hostbuf); - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - if (_resp->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isdigit(*cp) && *cp != '.') - break; - } - if ((isxdigit(name[0]) && strchr(name, ':') != NULL) || - name[0] == ':') - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-IPv6-legal, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strlcpy(hostbuf, name, MAXHOSTNAMELEN); - bp = hostbuf + MAXHOSTNAMELEN; - ep = hostbuf + sizeof(hostbuf); - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isxdigit(*cp) && *cp != ':' && *cp != '.') - break; - } - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - hp = (struct hostent *)NULL; - for (i = 0; i < MAXDNSLUS && hp == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* YP only supports AF_INET. */ - if (af == AF_INET) - hp = _yp_gethtbyname(name); - break; -#endif - case 'b': - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - if ((n = res_search(name, C_IN, type, buf->buf, - sizeof(buf->buf))) < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_search failed\n"); -#endif - break; - } - hp = getanswer(buf, n, name, type); - free(buf); - break; - case 'f': - hp = _gethtbyname2(name, af); - break; - } - } - /* XXX h_errno not correct in all cases... */ - return (hp); -} - -struct hostent * -gethostbyaddr(const void *addr, socklen_t len, int af) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const u_char *uaddr = (const u_char *)addr; - int n, size, i; - querybuf *buf; - struct hostent *hp; - char qbuf[MAXDNAME+1], *qp, *ep; - char lookups[MAXDNSLUS]; - struct hostent *res; - extern struct hostent *_gethtbyaddr(const void *, socklen_t, int); -#ifdef YP - extern struct hostent *_yp_gethtbyaddr(const void *); -#endif - - if (_res_init(0) == -1) { - res = _gethtbyaddr(addr, len, af); - return (res); - } - - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)uaddr) || - IN6_IS_ADDR_SITELOCAL((struct in6_addr *)uaddr))) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)uaddr) || - IN6_IS_ADDR_V4COMPAT((struct in6_addr *)uaddr))) { - /* Unmap. */ - uaddr += IN6ADDRSZ - INADDRSZ; - af = AF_INET; - len = INADDRSZ; - } - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; - return (NULL); - } - if (size != len) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return (NULL); - } - ep = qbuf + sizeof(qbuf); - switch (af) { - case AF_INET: - (void) snprintf(qbuf, sizeof qbuf, "%u.%u.%u.%u.in-addr.arpa", - (uaddr[3] & 0xff), (uaddr[2] & 0xff), - (uaddr[1] & 0xff), (uaddr[0] & 0xff)); - break; - case AF_INET6: - qp = qbuf; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - i = snprintf(qp, ep - qp, "%x.%x.", - uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf); - if (i <= 0 || i >= ep - qp) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return (NULL); - } - qp += i; - } - strlcpy(qp, "ip6.arpa", ep - qp); - break; - } - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - hp = (struct hostent *)NULL; - for (i = 0; i < MAXDNSLUS && hp == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* YP only supports AF_INET. */ - if (af == AF_INET) - hp = _yp_gethtbyaddr(uaddr); - break; -#endif - case 'b': - buf = malloc(sizeof(*buf)); - if (!buf) - break; - n = res_query(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (n < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - if (!(hp = getanswer(buf, n, qbuf, T_PTR))) { - free(buf); - break; - } - free(buf); - hp->h_addrtype = af; - hp->h_length = len; - bcopy(uaddr, host_addr, len); - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - if (af == AF_INET && (_resp->options & RES_USE_INET6)) { - map_v4v6_address((char*)host_addr, - (char*)host_addr); - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - } - h_errno = NETDB_SUCCESS; - break; - case 'f': - hp = _gethtbyaddr(uaddr, len, af); - break; - } - } - /* XXX h_errno not correct in all cases... */ - return (hp); -} - -void -_sethtent(int f) -{ - if (hostf == NULL) - hostf = fopen(_PATH_HOSTS, "r" ); - else - rewind(hostf); - stayopen = f; -} - -void -_endhtent(void) -{ - if (hostf && !stayopen) { - (void) fclose(hostf); - hostf = NULL; - } -} - -static struct hostent * -_gethtent(void) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - char *p, *cp, **q; - int af; - size_t len; - - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - again: - if ((p = fgetln(hostf, &len)) == NULL) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - if (p[len-1] == '\n') - len--; - if (len >= sizeof(hostbuf) || len == 0) - goto again; - p = memcpy(hostbuf, p, len); - hostbuf[len] = '\0'; - if (*p == '#') - goto again; - if ((cp = strchr(p, '#'))) - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - if (inet_pton(AF_INET6, p, host_addr) > 0) { - af = AF_INET6; - len = IN6ADDRSZ; - } else if (inet_pton(AF_INET, p, host_addr) > 0) { - if (_resp->options & RES_USE_INET6) { - map_v4v6_address((char*)host_addr, (char*)host_addr); - af = AF_INET6; - len = IN6ADDRSZ; - } else { - af = AF_INET; - len = INADDRSZ; - } - } else { - goto again; - } - /* if this is not something we're looking for, skip it. */ - if (host.h_addrtype != AF_UNSPEC && host.h_addrtype != af) - goto again; - if (host.h_length != 0 && host.h_length != len) - goto again; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = len; - host.h_addrtype = af; - while (*cp == ' ' || *cp == '\t') - cp++; - host.h_name = cp; - q = host.h_aliases = host_aliases; - if ((cp = strpbrk(cp, " \t"))) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - if ((cp = strpbrk(cp, " \t"))) - *cp++ = '\0'; - } - *q = NULL; - if (_resp->options & RES_USE_INET6) { - char *bp = hostbuf; - char *ep = hostbuf + sizeof hostbuf; - - map_v4v6_hostent(&host, &bp, ep); - } - h_errno = NETDB_SUCCESS; - return (&host); -} - -struct hostent * -_gethtbyname2(const char *name, int af) -{ - struct hostent *p; - char **cp; - - _sethtent(0); - while ((p = _gethtent())) { - if (p->h_addrtype != af) - continue; - if (strcasecmp(p->h_name, name) == 0) - break; - for (cp = p->h_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } - found: - _endhtent(); - return (p); -} - -struct hostent * -_gethtbyaddr(const void *addr, socklen_t len, int af) -{ - struct hostent *p; - - host.h_length = len; - host.h_addrtype = af; - - _sethtent(0); - while ((p = _gethtent())) - if (p->h_addrtype == af && p->h_length == len && - !bcmp(p->h_addr, addr, len)) - break; - _endhtent(); - return (p); -} - -#ifdef YP -struct hostent * -_yphostent(char *line) -{ - static struct in_addr host_addrs[MAXADDRS]; - char *p = line; - char *cp, **q; - char **hap; - struct in_addr *buf; - int more; - - host.h_name = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = INADDRSZ; - host.h_addrtype = AF_INET; - hap = h_addr_ptrs; - buf = host_addrs; - q = host.h_aliases = host_aliases; - -nextline: - /* check for host_addrs overflow */ - if (buf >= &host_addrs[sizeof(host_addrs) / sizeof(host_addrs[0])]) - goto done; - - more = 0; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto done; - *cp++ = '\0'; - - *hap++ = (char *)buf; - (void) inet_aton(p, buf++); - - while (*cp == ' ' || *cp == '\t') - cp++; - p = cp; - cp = strpbrk(p, " \t\n"); - if (cp != NULL) { - if (*cp == '\n') - more = 1; - *cp++ = '\0'; - } - if (!host.h_name) - host.h_name = p; - else if (strcmp(host.h_name, p)==0) - ; - else if (q < &host_aliases[MAXALIASES - 1]) - *q++ = p; - p = cp; - if (more) - goto nextline; - - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (*cp == '\n') { - cp++; - goto nextline; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } -done: - if (host.h_name == NULL) - return (NULL); - *q = NULL; - *hap = NULL; - return (&host); -} - -struct hostent * -_yp_gethtbyaddr(const void *addr) -{ - struct hostent *hp = NULL; - const u_char *uaddr = (const u_char *)addr; - static char *__ypcurrent; - int __ypcurrentlen, r; - char name[sizeof("xxx.xxx.xxx.xxx")]; - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return (hp); - } - snprintf(name, sizeof name, "%u.%u.%u.%u", (uaddr[0] & 0xff), - (uaddr[1] & 0xff), (uaddr[2] & 0xff), (uaddr[3] & 0xff)); - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - r = yp_match(__ypdomain, "hosts.byaddr", name, - strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r==0) - hp = _yphostent(__ypcurrent); - if (hp==NULL) - h_errno = HOST_NOT_FOUND; - return (hp); -} - -struct hostent * -_yp_gethtbyname(const char *name) -{ - struct hostent *hp = (struct hostent *)NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - - if (strlen(name) >= MAXHOSTNAMELEN) - return (NULL); - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return (hp); - } - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - r = yp_match(__ypdomain, "hosts.byname", name, - strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) - hp = _yphostent(__ypcurrent); - if (hp == NULL) - h_errno = HOST_NOT_FOUND; - return (hp); -} -#endif - -static void -map_v4v6_address(const char *src, char *dst) -{ - u_char *p = (u_char *)dst; - char tmp[INADDRSZ]; - int i; - - /* Stash a temporary copy so our caller can update in place. */ - bcopy(src, tmp, INADDRSZ); - /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Retrieve the saved copy and we're done. */ - bcopy(tmp, (void*)p, INADDRSZ); -} - -static void -map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) -{ - char **ap; - - if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) - return; - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); - - if (ep - *bpp < (i + IN6ADDRSZ)) { - /* Out of memory. Truncate address list here. XXX */ - *ap = NULL; - return; - } - *bpp += i; - map_v4v6_address(*ap, *bpp); - *ap = *bpp; - *bpp += IN6ADDRSZ; - } -} - -struct hostent * -gethostent(void) -{ - host.h_addrtype = AF_UNSPEC; - host.h_length = 0; - return (_gethtent()); -} - -#ifdef RESOLVSORT -static void -addrsort(char **ap, int num) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _resp->nsort; j++) - if (_resp->sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & - _resp->sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - } else - break; - } - needsort++; - } -} -#endif diff --git a/src/lib/libc/net/getifaddrs.3 b/src/lib/libc/net/getifaddrs.3 deleted file mode 100644 index 6fc5a8d404..0000000000 --- a/src/lib/libc/net/getifaddrs.3 +++ /dev/null @@ -1,158 +0,0 @@ -.\" $OpenBSD: getifaddrs.3,v 1.15 2012/07/13 09:32:23 krw Exp $ -.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp -.\" -.\" Copyright (c) 1995, 1999 -.\" Berkeley Software Design, Inc. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.Dd $Mdocdate: July 13 2012 $ -.Dt GETIFADDRS 3 -.Os -.Sh NAME -.Nm getifaddrs -.Nd get interface addresses -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getifaddrs "struct ifaddrs **ifap" -.Ft void -.Fn freeifaddrs "struct ifaddrs *ifap" -.Sh DESCRIPTION -The -.Fn getifaddrs -function stores a reference to a linked list of the network interfaces -on the local machine in the memory referenced by -.Fa ifap . -The list consists of -.Nm ifaddrs -structures, as defined in the include file -.Aq Pa ifaddrs.h . -The -.Nm ifaddrs -structure contains at least the following entries: -.Bd -literal - struct ifaddrs *ifa_next; /* Pointer to next struct */ - char *ifa_name; /* Interface name */ - u_int ifa_flags; /* Interface flags */ - struct sockaddr *ifa_addr; /* Interface address */ - struct sockaddr *ifa_netmask; /* Interface netmask */ - struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ - struct sockaddr *ifa_dstaddr; /* P2P interface destination */ - void *ifa_data; /* Address specific data */ -.Ed -.Bl -tag -width ifa_broadaddr -.It Fa ifa_next -Contains a pointer to the next structure on the list. -This field is set to -.Dv NULL -in the last structure on the list. -.It Fa ifa_name -Contains the interface name. -.It Fa ifa_flags -Contains the interface flags, as set by -.Xr ifconfig 8 . -.It Fa ifa_addr -References either the address of the interface or the link level -address of the interface, if one exists, otherwise it is -.Dv NULL . -(The -.Fa sa_family -field of the -.Fa ifa_addr -field should be consulted to determine the format of the -.Fa ifa_addr -address.) -.It Fa ifa_netmask -References the netmask associated with -.Fa ifa_addr , -if one is set, otherwise it is -.Dv NULL . -.It Fa ifa_broadaddr -This field, which should only be referenced for non-P2P interfaces, -references the broadcast address associated with -.Fa ifa_addr , -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_dstaddr -This field, which should only be referenced for P2P interfaces, -references the destination address on a P2P interface, -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_data -References address family specific data. -For -.Dv AF_LINK -addresses it contains a pointer to the -.Li struct if_data -(as defined in include file -.Aq Pa net/if.h ) -which contains various interface attributes and statistics. -For all other address families, -.Fa ifa_data -is -.Dv NULL . -.El -.Pp -The data returned by -.Fn getifaddrs -is dynamically allocated and should be freed using -.Fn freeifaddrs -when no longer needed. -.Sh RETURN VALUES -Upon successful completion, a value of 0 is returned. -Otherwise, a value of \-1 is returned and -.Va errno -is set to indicate the error. -.Sh ERRORS -The -.Fn getifaddrs -may fail and set -.Va errno -for any of the errors specified for the library routines -.Xr ioctl 2 , -.Xr socket 2 , -.Xr malloc 3 , -or -.Xr sysctl 3 . -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr socket 2 , -.Xr sysctl 3 , -.Xr networking 4 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn getifaddrs -function first appeared in BSDI BSD/OS. -The function has been available on -.Ox -since -.Ox 2.7 . -.Sh BUGS -If both -.Aq Pa net/if.h -and -.Aq Pa ifaddrs.h -are being included, -.Aq Pa net/if.h -.Em must -be included before -.Aq Pa ifaddrs.h . diff --git a/src/lib/libc/net/getifaddrs.c b/src/lib/libc/net/getifaddrs.c deleted file mode 100644 index 6f7ea15721..0000000000 --- a/src/lib/libc/net/getifaddrs.c +++ /dev/null @@ -1,284 +0,0 @@ -/* $OpenBSD: getifaddrs.c,v 1.10 2008/11/24 20:08:49 claudio Exp $ */ - -/* - * Copyright (c) 1995, 1999 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define SALIGN (sizeof(long) - 1) -#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1)) - -int -getifaddrs(struct ifaddrs **pif) -{ - int icnt = 1; - int dcnt = 0; - int ncnt = 0; - int mib[6]; - size_t needed; - char *buf; - char *next; - struct ifaddrs *cif = 0; - char *p, *p0; - struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct sockaddr_dl *dl; - struct sockaddr *sa; - u_short index = 0; - size_t len, alen, dlen; - struct ifaddrs *ifa, *ift; - int i; - char *data; - char *names; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; - mib[5] = 0; /* no flags */ - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - return (-1); - if ((buf = malloc(needed)) == NULL) - return (-1); - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - free(buf); - return (-1); - } - - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - ++icnt; - dl = (struct sockaddr_dl *)(next + - rtm->rtm_hdrlen); - dcnt += SA_RLEN((struct sockaddr *)dl) + - ALIGNBYTES; - dcnt += sizeof(ifm->ifm_data); - ncnt += dl->sdl_nlen + 1; - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - -#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - p = next + rtm->rtm_hdrlen; - ++icnt; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_NETMASK && sa->sa_len == 0) - dcnt += alen; - else - dcnt += len; - p += len; - } - break; - } - } - - if (icnt + dcnt + ncnt == 1) { - *pif = NULL; - free(buf); - return (0); - } - data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); - if (data == NULL) { - free(buf); - return(-1); - } - - ifa = (struct ifaddrs *)data; - data += sizeof(struct ifaddrs) * icnt; - names = data + dcnt; - - memset(ifa, 0, sizeof(struct ifaddrs) * icnt); - ift = ifa; - - index = 0; - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - dl = (struct sockaddr_dl *)(next + - rtm->rtm_hdrlen); - - cif = ift; - ift->ifa_name = names; - ift->ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, dl->sdl_nlen); - names[dl->sdl_nlen] = 0; - names += dl->sdl_nlen + 1; - - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, dl, - ((struct sockaddr *)dl)->sa_len); - data += SA_RLEN((struct sockaddr *)dl); - - /* ifm_data needs to be aligned */ - ift->ifa_data = data = (void *)ALIGN(data); - dlen = rtm->rtm_hdrlen - - offsetof(struct if_msghdr, ifm_data); - if (dlen > sizeof(ifm->ifm_data)) - dlen = sizeof(ifm->ifm_data); - memcpy(data, &ifm->ifm_data, dlen); - data += sizeof(ifm->ifm_data); - - ift = (ift->ifa_next = ift + 1); - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - ift->ifa_name = cif->ifa_name; - ift->ifa_flags = cif->ifa_flags; - ift->ifa_data = NULL; - p = next + rtm->rtm_hdrlen; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - switch (i) { - case RTAX_IFA: - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - - case RTAX_NETMASK: - ift->ifa_netmask = - (struct sockaddr *)data; - if (sa->sa_len == 0) { - memset(data, 0, alen); - data += alen; - break; - } - memcpy(data, p, len); - data += len; - break; - - case RTAX_BRD: - ift->ifa_broadaddr = - (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - } - p += len; - } - - - ift = (ift->ifa_next = ift + 1); - break; - } - } - - free(buf); - if (--ift >= ifa) { - ift->ifa_next = NULL; - *pif = ifa; - } else { - *pif = NULL; - free(ifa); - } - return (0); -} - -void -freeifaddrs(struct ifaddrs *ifp) -{ - free(ifp); -} diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 deleted file mode 100644 index 0d51ae211f..0000000000 --- a/src/lib/libc/net/getnameinfo.3 +++ /dev/null @@ -1,264 +0,0 @@ -.\" $OpenBSD: getnameinfo.3,v 1.42 2012/01/03 12:06:04 jmc Exp $ -.\" $KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: January 3 2012 $ -.Dt GETNAMEINFO 3 -.Os -.Sh NAME -.Nm getnameinfo -.Nd socket address structure to hostname and service name -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" \ - "size_t hostlen" "char *serv" "size_t servlen" "int flags" -.Sh DESCRIPTION -The -.Fn getnameinfo -function is used to convert a -.Li sockaddr -structure to a pair of host name and service strings. -It is a replacement for and provides more flexibility than the -.Xr gethostbyaddr 3 -and -.Xr getservbyport 3 -functions and is the converse of the -.Xr getaddrinfo 3 -function. -.Pp -The -.Li sockaddr -structure -.Fa sa -should point to either a -.Li sockaddr_in -or -.Li sockaddr_in6 -structure (for IPv4 or IPv6 respectively) that is -.Fa salen -bytes long. -.Pp -The host and service names associated with -.Fa sa -are stored in -.Fa host -and -.Fa serv -which have length parameters -.Fa hostlen -and -.Fa servlen . -The maximum value for -.Fa hostlen -is -.Dv NI_MAXHOST -and -the maximum value for -.Fa servlen -is -.Dv NI_MAXSERV , -as defined by -.Aq Pa netdb.h . -If a length parameter is zero, no string will be stored. -Otherwise, enough space must be provided to store the -host name or service string plus a byte for the NUL terminator. -.Pp -The -.Fa flags -argument is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "NI_NUMERICHOSTXX" -.It Dv NI_NOFQDN -A fully qualified domain name is not required for local hosts. -The local part of the fully qualified domain name is returned instead. -.It Dv NI_NUMERICHOST -Return the address in numeric form, as if calling -.Xr inet_ntop 3 , -instead of a host name. -.It Dv NI_NAMEREQD -A name is required. -If the host name cannot be found in DNS and this flag is set, -a non-zero error code is returned. -If the host name is not found and the flag is not set, the -address is returned in numeric form. -.It NI_NUMERICSERV -The service name is returned as a digit string representing the port number. -.It NI_DGRAM -Specifies that the service being looked up is a datagram -service, and causes -.Xr getservbyport 3 -to be called with a second argument of -.Dq udp -instead of its default of -.Dq tcp . -This is required for the few ports (512\-514) that have different services -for -.Tn UDP -and -.Tn TCP . -.El -.Pp -This implementation allows numeric IPv6 address notation with scope identifier, -as documented in RFC 4007. -IPv6 link-local address will appear as a string like -.Dq Li fe80::1%ne0 . -Refer to -.Xr getaddrinfo 3 -for more information. -.Sh RETURN VALUES -.Fn getnameinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -.Sh EXAMPLES -The following code tries to get a numeric host name, and service name, -for a given socket address. -Observe that there is no hardcoded reference to a particular address family. -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, - sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) - errx(1, "could not get numeric hostname"); -printf("host=%s, serv=%s\en", hbuf, sbuf); -.Ed -.Pp -The following version checks if the socket address has a reverse address mapping: -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, - NI_NAMEREQD)) - errx(1, "could not resolve hostname"); -printf("host=%s\en", hbuf); -.Ed -.Sh SEE ALSO -.Xr gai_strerror 3 , -.Xr getaddrinfo 3 , -.Xr gethostbyaddr 3 , -.Xr getservbyport 3 , -.Xr inet_ntop 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 , -.Xr named 8 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 2553 -.%D March 1999 -.Re -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%T "IPv6 Scoped Address Architecture" -.%R RFC 4007 -.%D March 2005 -.Re -.Rs -.%A Craig Metz -.%T Protocol Independence Using the Sockets API -.%B "Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference" -.%D June 2000 -.Re -.Sh STANDARDS -The -.Fn getnameinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in -.Tn "RFC 2553" , -.Dq Basic Socket Interface Extensions for IPv6 . -.Sh CAVEATS -.Fn getnameinfo -can return both numeric and FQDN forms of the address specified in -.Fa sa . -There is no return value that indicates whether the string returned in -.Fa host -is a result of binary to numeric-text translation (like -.Xr inet_ntop 3 ) , -or is the result of a DNS reverse lookup. -Because of this, malicious parties could set up a PTR record as follows: -.Bd -literal -offset indent -1.0.0.127.in-addr.arpa. IN PTR 10.1.1.1 -.Ed -.Pp -and trick the caller of -.Fn getnameinfo -into believing that -.Fa sa -is -.Li 10.1.1.1 -when it is actually -.Li 127.0.0.1 . -.Pp -To prevent such attacks, the use of -.Dv NI_NAMEREQD -is recommended when the result of -.Fn getnameinfo -is used -for access control purposes: -.Bd -literal -offset indent -struct sockaddr *sa; -char addr[NI_MAXHOST]; -struct addrinfo hints, *res; -int error; - -error = getnameinfo(sa, sa->sa_len, addr, sizeof(addr), - NULL, 0, NI_NAMEREQD); -if (error == 0) { - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(addr, "0", &hints, &res) == 0) { - /* malicious PTR record */ - freeaddrinfo(res); - printf("bogus PTR record\en"); - return -1; - } - /* addr is FQDN as a result of PTR lookup */ -} else { - /* addr is numeric string */ - error = getnameinfo(sa, sa->sa_len, addr, sizeof(addr), - NULL, 0, NI_NUMERICHOST); -} -.Ed -.Sh BUGS -The implementation of -.Fn getnameinfo -is not thread-safe. -.Pp -.Ox -intentionally uses a different -.Dv NI_MAXHOST -value from what -.Tn "RFC 2553" -suggests, to avoid buffer length handling mistakes. diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c deleted file mode 100644 index 7041a4ee48..0000000000 --- a/src/lib/libc/net/getnameinfo.c +++ /dev/null @@ -1,351 +0,0 @@ -/* $OpenBSD: getnameinfo.c,v 1.33 2007/02/15 04:25:35 ray Exp $ */ -/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Issues to be discussed: - * - Thread safe-ness must be checked - * - RFC2553 says that we should raise error on short buffer. X/Open says - * we need to truncate the result. We obey RFC2553 (and X/Open should be - * modified). ipngwg rough consensus seems to follow RFC2553. - * - What is "local" in NI_FQDN? - * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. - * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if - * sin6_scope_id is filled - standardization status? - * XXX breaks backward compat for code that expects no scopeid. - * beware on merge. - */ - -#ifndef INET6 -#define INET6 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -static const struct afd { - int a_af; - int a_addrlen; - int a_socklen; - int a_off; -} afdl [] = { -#ifdef INET6 - {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6), - offsetof(struct sockaddr_in6, sin6_addr)}, -#endif - {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), - offsetof(struct sockaddr_in, sin_addr)}, - {0, 0, 0}, -}; - -struct sockinet { - u_char si_len; - u_char si_family; - u_short si_port; -}; - -#ifdef INET6 -static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, - size_t, int); -static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); -#endif - -void *__THREAD_NAME(serv_mutex); - -int -getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags) -{ - const struct afd *afd; - struct hostent *hp; - u_short port; - int family, i; - const char *addr; - u_int32_t v4a; - char numserv[512]; - char numaddr[512]; - - if (sa == NULL) - return EAI_FAIL; - - family = sa->sa_family; - for (i = 0; afdl[i].a_af; i++) - if (afdl[i].a_af == family) { - afd = &afdl[i]; - goto found; - } - return EAI_FAMILY; - - found: - if (salen != afd->a_socklen) - return EAI_FAIL; - - /* network byte order */ - port = ((const struct sockinet *)sa)->si_port; - addr = (const char *)sa + afd->a_off; - - if (serv == NULL || servlen == 0) { - /* - * do nothing in this case. - * in case you are wondering if "&&" is more correct than - * "||" here: rfc2553bis-03 says that serv == NULL OR - * servlen == 0 means that the caller does not want the result. - */ - } else if (!(flags & NI_NUMERICSERV)) { - struct servent sp; - struct servent_data sd; - - (void)memset(&sd, 0, sizeof(sd)); - if (getservbyport_r(port, - (flags & NI_DGRAM) ? "udp" : "tcp", &sp, &sd) == -1) - goto numeric; - - if (strlen(sp.s_name) + 1 > servlen) { - endservent_r(&sd); - return EAI_MEMORY; - } - strlcpy(serv, sp.s_name, servlen); - endservent_r(&sd); - } else { - numeric: - i = snprintf(numserv, sizeof(numserv), "%u", ntohs(port)); - if (i < 0 || i >= servlen || i >= sizeof(numserv)) - return EAI_MEMORY; - strlcpy(serv, numserv, servlen); - } - - switch (sa->sa_family) { - case AF_INET: - v4a = (u_int32_t) - ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr); - if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) - flags |= NI_NUMERICHOST; - v4a >>= IN_CLASSA_NSHIFT; - if (v4a == 0) - flags |= NI_NUMERICHOST; - break; -#ifdef INET6 - case AF_INET6: - { - const struct sockaddr_in6 *sin6; - sin6 = (const struct sockaddr_in6 *)sa; - switch (sin6->sin6_addr.s6_addr[0]) { - case 0x00: - if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) - ; - else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) - ; - else - flags |= NI_NUMERICHOST; - break; - default: - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { - flags |= NI_NUMERICHOST; - } - else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) - flags |= NI_NUMERICHOST; - break; - } - } - break; -#endif - } - if (host == NULL || hostlen == 0) { - /* - * do nothing in this case. - * in case you are wondering if "&&" is more correct than - * "||" here: rfc2553bis-03 says that host == NULL or - * hostlen == 0 means that the caller does not want the result. - */ - } else if (flags & NI_NUMERICHOST) { - int numaddrlen; - - /* NUMERICHOST and NAMEREQD conflicts with each other */ - if (flags & NI_NAMEREQD) - return EAI_NONAME; - - switch(afd->a_af) { -#ifdef INET6 - case AF_INET6: - { - int error; - - if ((error = ip6_parsenumeric(sa, addr, host, - hostlen, flags)) != 0) - return(error); - break; - } -#endif - default: - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) - return EAI_SYSTEM; - numaddrlen = strlen(numaddr); - if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return EAI_MEMORY; - strlcpy(host, numaddr, hostlen); - break; - } - } else { - _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); - hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); - _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); - - if (hp) { -#if 0 - /* - * commented out, since "for local host" is not - * implemented here - see RFC2553 p30 - */ - if (flags & NI_NOFQDN) { - char *p; - p = strchr(hp->h_name, '.'); - if (p) - *p = '\0'; - } -#endif - if (strlen(hp->h_name) + 1 > hostlen) { - return EAI_MEMORY; - } - strlcpy(host, hp->h_name, hostlen); - } else { - if (flags & NI_NAMEREQD) - return EAI_NONAME; - switch(afd->a_af) { -#ifdef INET6 - case AF_INET6: - { - int error; - - if ((error = ip6_parsenumeric(sa, addr, host, - hostlen, - flags)) != 0) - return(error); - break; - } -#endif - default: - if (inet_ntop(afd->a_af, addr, host, - hostlen) == NULL) - return EAI_SYSTEM; - break; - } - } - } - return(0); -} - -#ifdef INET6 -static int -ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host, - size_t hostlen, int flags) -{ - int numaddrlen; - char numaddr[512]; - - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) - return EAI_SYSTEM; - - numaddrlen = strlen(numaddr); - if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return EAI_MEMORY; - strlcpy(host, numaddr, hostlen); - - if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { - char zonebuf[MAXHOSTNAMELEN]; - int zonelen; - - zonelen = ip6_sa2str( - (const struct sockaddr_in6 *)(const void *)sa, - zonebuf, sizeof(zonebuf), flags); - if (zonelen < 0) - return EAI_MEMORY; - if (zonelen + 1 + numaddrlen + 1 > hostlen) - return EAI_MEMORY; - - /* construct */ - memcpy(host + numaddrlen + 1, zonebuf, - (size_t)zonelen); - host[numaddrlen] = SCOPE_DELIMITER; - host[numaddrlen + 1 + zonelen] = '\0'; - } - - return 0; -} - -/* ARGSUSED */ -static int -ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) -{ - unsigned int ifindex; - const struct in6_addr *a6; - int n; - - ifindex = (unsigned int)sa6->sin6_scope_id; - a6 = &sa6->sin6_addr; - -#ifdef notdef - if ((flags & NI_NUMERICSCOPE) != 0) { - n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id); - if (n < 0 || n >= bufsiz) - return -1; - else - return n; - } -#endif - - /* if_indextoname() does not take buffer size. not a good api... */ - if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || - IN6_IS_ADDR_MC_INTFACELOCAL(a6)) && bufsiz >= IF_NAMESIZE) { - char *p = if_indextoname(ifindex, buf); - if (p) { - return(strlen(p)); - } - } - - /* last resort */ - n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id); - if (n < 0 || n >= bufsiz) - return -1; - else - return n; -} -#endif /* INET6 */ diff --git a/src/lib/libc/net/getnetbyaddr.c b/src/lib/libc/net/getnetbyaddr.c deleted file mode 100644 index a85106630c..0000000000 --- a/src/lib/libc/net/getnetbyaddr.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: getnetbyaddr.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -extern int _net_stayopen; - -struct netent * -_getnetbyaddr(in_addr_t net, int type) -{ - struct netent *p; - - setnetent(_net_stayopen); - while ((p = getnetent())) - if (p->n_addrtype == type && p->n_net == net) - break; - if (!_net_stayopen) - endnetent(); - return (p); -} diff --git a/src/lib/libc/net/getnetbyname.c b/src/lib/libc/net/getnetbyname.c deleted file mode 100644 index e6540cf12c..0000000000 --- a/src/lib/libc/net/getnetbyname.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: getnetbyname.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -extern int _net_stayopen; - -struct netent * -_getnetbyname(const char *name) -{ - struct netent *p; - char **cp; - - setnetent(_net_stayopen); - while ((p = getnetent())) { - if (strcasecmp(p->n_name, name) == 0) - break; - for (cp = p->n_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } -found: - if (!_net_stayopen) - endnetent(); - return (p); -} diff --git a/src/lib/libc/net/getnetent.3 b/src/lib/libc/net/getnetent.3 deleted file mode 100644 index 00fd543ec4..0000000000 --- a/src/lib/libc/net/getnetent.3 +++ /dev/null @@ -1,140 +0,0 @@ -.\" $OpenBSD: getnetent.3,v 1.15 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETNETENT 3 -.Os -.Sh NAME -.Nm getnetent , -.Nm getnetbyaddr , -.Nm getnetbyname , -.Nm setnetent , -.Nm endnetent -.Nd get network entry -.Sh SYNOPSIS -.Fd #include -.Ft struct netent * -.Fn getnetent "void" -.Ft struct netent * -.Fn getnetbyname "const char *name" -.Ft struct netent * -.Fn getnetbyaddr "in_addr_t net" "int type" -.Ft void -.Fn setnetent "int stayopen" -.Ft void -.Fn endnetent "void" -.Sh DESCRIPTION -The -.Fn getnetent , -.Fn getnetbyname , -and -.Fn getnetbyaddr -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network database, -.Pa /etc/networks . -.Bd -literal -offset indent -struct netent { - char *n_name; /* official name of net */ - char **n_aliases; /* alias list */ - int n_addrtype; /* net number type */ - in_addr_t n_net; /* net number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width n_addrtype -.It Fa n_name -The official name of the network. -.It Fa n_aliases -A null-terminated list of alternate names for the network. -.It Fa n_addrtype -The type of the network number returned; currently only -.Dv AF_INET . -.It Fa n_net -The network number. -Network numbers are returned in machine byte order. -.El -.Pp -The -.Fn getnetent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setnetent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the net database will not be closed after each call to -.Fn getnetbyname -or -.Fn getnetbyaddr . -.Pp -The -.Fn endnetent -function closes the file. -.Pp -The -.Fn getnetbyname -and -.Fn getnetbyaddr -functions search the domain name server if the system is configured to use one. -If the search fails, or no name server is configured, they sequentially -search from the beginning of the file until a matching net name or -net address and type is found, or until -.Dv EOF -is encountered. -Network numbers are supplied in host order. -.Sh FILES -.Bl -tag -width /etc/networks -compact -.It Pa /etc/networks -.El -.Sh DIAGNOSTICS -Null pointer (0) returned on -.Dv EOF -or error. -.Sh SEE ALSO -.Xr resolver 3 , -.Xr networks 5 -.Sh HISTORY -The -.Fn getnetent , -.Fn getnetbyaddr , -.Fn getnetbyname , -.Fn setnetent , -and -.Fn endnetent -functions appeared in -.Bx 4.2 . -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls -to these functions overwrite it. -Only Internet network numbers are currently understood. -Expecting network numbers to fit in no more than 32 bits is naive. diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c deleted file mode 100644 index 57fe459e2b..0000000000 --- a/src/lib/libc/net/getnetent.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $OpenBSD: getnetent.c,v 1.13 2012/04/10 16:41:10 eric Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define MAXALIASES 35 - -static FILE *netf; -static char line[BUFSIZ+1]; -static struct netent net; -static char *net_aliases[MAXALIASES]; -int _net_stayopen; - -void -setnetent(int f) -{ - if (netf == NULL) - netf = fopen(_PATH_NETWORKS, "r" ); - else - rewind(netf); - _net_stayopen |= f; -} - -void -endnetent(void) -{ - if (netf) { - fclose(netf); - netf = NULL; - } - _net_stayopen = 0; -} - -struct netent * -getnetent(void) -{ - char *p, *cp, **q; - size_t len; - - if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) - return (NULL); -again: - if ((p = fgetln(netf, &len)) == NULL) - return (NULL); - if (p[len-1] == '\n') - len--; - if (len >= sizeof(line) || len == 0) - goto again; - p = memcpy(line, p, len); - line[len] = '\0'; - if (*p == '#') - goto again; - if ((cp = strchr(p, '#')) != NULL) - *cp = '\0'; - net.n_name = p; - if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) - net.n_name[MAXHOSTNAMELEN-1] = '\0'; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - net.n_net = inet_network(cp); - net.n_addrtype = AF_INET; - q = net.n_aliases = net_aliases; - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &net_aliases[MAXALIASES - 1]) { - *q++ = cp; - if (strlen(cp) >= MAXHOSTNAMELEN-1) - cp[MAXHOSTNAMELEN-1] = '\0'; - } - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&net); -} diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c deleted file mode 100644 index 7b770f1ce7..0000000000 --- a/src/lib/libc/net/getnetnamadr.c +++ /dev/null @@ -1,384 +0,0 @@ -/* $OpenBSD: getnetnamadr.c,v 1.26 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1997, Jason Downs. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -extern int h_errno; - -struct netent *_getnetbyaddr(in_addr_t net, int type); -struct netent *_getnetbyname(const char *name); - -int _hokchar(const char *); - -#define BYADDR 0 -#define BYNAME 1 -#define MAXALIASES 35 - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - long al; - char ac; -} align; - -static struct netent * -getnetanswer(querybuf *answer, int anslen, int net_i) -{ - - HEADER *hp; - u_char *cp; - int n; - u_char *eom; - int type, class, ancount, qdcount, haveanswer, i, nchar; - char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN]; - char *in, *st, *pauxt, *bp, **ap, *ep; - char *paux1 = &aux1[0], *paux2 = &aux2[0]; - static struct netent net_entry; - static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; - - /* - * find first satisfactory answer - * - * answer --> +------------+ ( MESSAGE ) - * | Header | - * +------------+ - * | Question | the question for the name server - * +------------+ - * | Answer | RRs answering the question - * +------------+ - * | Authority | RRs pointing toward an authority - * | Additional | RRs holding additional information - * +------------+ - */ - eom = answer->buf + anslen; - hp = &answer->hdr; - ancount = ntohs(hp->ancount); /* #/records in the answer section */ - qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ - bp = netbuf; - ep = netbuf + sizeof(netbuf); - cp = answer->buf + HFIXEDSZ; - if (!qdcount) { - if (hp->aa) - h_errno = HOST_NOT_FOUND; - else - h_errno = TRY_AGAIN; - return (NULL); - } - while (qdcount-- > 0) { - n = __dn_skipname(cp, eom); - if (n < 0 || (cp + n + QFIXEDSZ) > eom) { - h_errno = NO_RECOVERY; - return(NULL); - } - cp += n + QFIXEDSZ; - } - ap = net_aliases; - *ap = NULL; - net_entry.n_aliases = net_aliases; - haveanswer = 0; - while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_dnok(bp)) -#else - if ((n < 0) || !_hokchar(bp)) -#endif - break; - cp += n; - ans[0] = '\0'; - strlcpy(&ans[0], bp, sizeof ans); - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); - if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(bp)) -#else - if ((n < 0) || !_hokchar(bp)) -#endif - { - cp += n; - return (NULL); - } - cp += n; - if ((ap + 2) < &net_aliases[MAXALIASES]) { - *ap++ = bp; - bp += strlen(bp) + 1; - net_entry.n_addrtype = - (class == C_IN) ? AF_INET : AF_UNSPEC; - haveanswer++; - } - } - } - if (haveanswer) { - *ap = NULL; - switch (net_i) { - case BYADDR: - net_entry.n_name = *net_entry.n_aliases; - net_entry.n_net = 0L; - break; - case BYNAME: - ap = net_entry.n_aliases; - next_alias: - in = *ap++; - if (in == NULL) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - net_entry.n_name = ans; - aux2[0] = '\0'; - for (i = 0; i < 4; i++) { - for (st = in, nchar = 0; - isdigit((unsigned char)*st); - st++, nchar++) - ; - if (*st != '.' || nchar == 0 || nchar > 3) - goto next_alias; - if (i != 0) - nchar++; - strlcpy(paux1, in, nchar+1); - strlcat(paux1, paux2, MAXHOSTNAMELEN); - pauxt = paux2; - paux2 = paux1; - paux1 = pauxt; - in = ++st; - } - if (strcasecmp(in, "IN-ADDR.ARPA") != 0) - goto next_alias; - net_entry.n_net = inet_network(paux2); - break; - } - net_entry.n_aliases++; - return (&net_entry); - } - h_errno = TRY_AGAIN; - return (NULL); -} - -struct netent * -getnetbyaddr(in_addr_t net, int net_type) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - unsigned int netbr[4]; - int nn, anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - in_addr_t net2; - struct netent *net_entry = NULL; - char lookups[MAXDNSLUS]; - int i; - - if (_res_init(0) == -1) - return(_getnetbyaddr(net, net_type)); - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* There is no YP support. */ - break; -#endif /* YP */ - case 'b': - if (net_type != AF_INET) - break; /* DNS only supports AF_INET? */ - - for (nn = 4, net2 = net; net2; net2 >>= 8) - netbr[--nn] = net2 & 0xff; - switch (nn) { - case 3: /* Class A */ - snprintf(qbuf, sizeof(qbuf), - "0.0.0.%u.in-addr.arpa", netbr[3]); - break; - case 2: /* Class B */ - snprintf(qbuf, sizeof(qbuf), - "0.0.%u.%u.in-addr.arpa", - netbr[3], netbr[2]); - break; - case 1: /* Class C */ - snprintf(qbuf, sizeof(qbuf), - "0.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1]); - break; - case 0: /* Class D - E */ - snprintf(qbuf, sizeof(qbuf), - "%u.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1], netbr[0]); - break; - } - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - anslen = res_query(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - net_entry = getnetanswer(buf, anslen, BYADDR); - free(buf); - if (net_entry != NULL) { - unsigned u_net = net; /* maybe net should be unsigned ? */ - - /* Strip trailing zeros */ - while ((u_net & 0xff) == 0 && u_net != 0) - u_net >>= 8; - net_entry->n_net = u_net; - return (net_entry); - } - break; - case 'f': - net_entry = _getnetbyaddr(net, net_type); - if (net_entry != NULL) - return (net_entry); - } - } - - /* Nothing matched. */ - return (NULL); -} - -struct netent * -getnetbyname(const char *net) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - struct netent *net_entry = NULL; - char lookups[MAXDNSLUS]; - int i; - - if (_res_init(0) == -1) - return (_getnetbyname(net)); - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* There is no YP support. */ - break; -#endif /* YP */ - case 'b': - strlcpy(qbuf, net, sizeof qbuf); - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - anslen = res_search(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - net_entry = getnetanswer(buf, anslen, BYNAME); - free(buf); - if (net_entry != NULL) - return (net_entry); - break; - case 'f': - net_entry = _getnetbyname(net); - if (net_entry != NULL) - return (net_entry); - break; - } - } - - /* Nothing matched. */ - return (NULL); -} diff --git a/src/lib/libc/net/getpeereid.3 b/src/lib/libc/net/getpeereid.3 deleted file mode 100644 index 8e777d3ca6..0000000000 --- a/src/lib/libc/net/getpeereid.3 +++ /dev/null @@ -1,121 +0,0 @@ -.\" $OpenBSD: getpeereid.3,v 1.2 2012/04/22 02:21:49 matthew Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.Dd $Mdocdate: April 22 2012 $ -.Dt GETPEEREID 3 -.Os -.Sh NAME -.Nm getpeereid -.Nd get effective user and group identification of locally-connected peer -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Ft int -.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid" -.Sh DESCRIPTION -.Fn getpeereid -returns the effective user ID and group ID of the peer connected to -a -.Ux Ns -domain -socket (see -.Xr unix 4 ) . -The argument -.Fa s -must be of type -.Dv SOCK_STREAM -or -.Dv SOCK_SEQPACKET . -.Pp -One common use is for -.Ux Ns -domain -servers to determine the credentials of clients that have connected to it. -.Pp -.Fn getpeereid -takes three parameters: -.Bl -bullet -.It -.Fa s -contains the file descriptor of the socket whose peer credentials -should be looked up. -.It -.Fa euid -points to a -.Li uid_t -variable into which the effective user ID for the connected peer will -be stored. -.It -.Fa egid -points to a -.Li gid_t -variable into which the effective group ID for the connected peer will -be stored. -.El -.Sh RETURN VALUES -If the call succeeds, a 0 is returned and -.Fa euid -and -.Fa egid -are set to the effective user ID and group ID of the connected peer. -Otherwise, -.Va errno -is set and a value of \-1 is returned. -.Sh ERRORS -On failure, -.Va errno -is set to one of the following: -.Bl -tag -width Er -.It Bq Er EBADF -The argument -.Fa s -is not a valid descriptor. -.It Bq Er ENOTSOCK -The argument -.Fa s -is a file, not a socket. -.It Bq Er EOPNOTSUPP -The socket is not in the -.Ux Ns -domain . -.It Bq Er ENOTCONN -The socket is not connected. -.It Bq Er ENOBUFS -Insufficient resources were available in the system -to perform the operation. -.El -.Sh SEE ALSO -.Xr accept 2 , -.Xr bind 2 , -.Xr getpeername 2 , -.Xr getsockname 2 , -.Xr getsockopt 2 , -.Xr socket 2 , -.Xr unix 4 -.Sh HISTORY -The -.Fn getpeereid -function call appeared in -.Ox 3.0 . diff --git a/src/lib/libc/net/getpeereid.c b/src/lib/libc/net/getpeereid.c deleted file mode 100644 index 208e541f17..0000000000 --- a/src/lib/libc/net/getpeereid.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $OpenBSD: getpeereid.c,v 1.1 2010/07/01 19:15:30 deraadt Exp $ */ - -/* - * Copyright (c) 2010 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -int -getpeereid(int s, uid_t *euid, gid_t *egid) -{ - struct sockpeercred creds; - socklen_t credslen = sizeof(creds); - int error; - - error = getsockopt(s, SOL_SOCKET, SO_PEERCRED, - &creds, &credslen); - if (error) - return (error); - *euid = creds.uid; - *egid = creds.gid; - return (0); -} diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c deleted file mode 100644 index 07fa33288d..0000000000 --- a/src/lib/libc/net/getproto.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: getproto.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -int -getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) -{ - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) - if (pe->p_proto == num) - break; - if (!pd->stayopen && pd->fp != NULL) { - (void)fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} - -struct protoent * -getprotobynumber(int num) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobynumber_r(num, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoent.3 b/src/lib/libc/net/getprotoent.3 deleted file mode 100644 index df4cd0c323..0000000000 --- a/src/lib/libc/net/getprotoent.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: getprotoent.3,v 1.17 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETPROTOENT 3 -.Os -.Sh NAME -.Nm getprotoent , -.Nm getprotoent_r , -.Nm getprotobynumber , -.Nm getprotobynumber_r , -.Nm getprotobyname , -.Nm getprotobyname_r , -.Nm setprotoent , -.Nm setprotoent_r , -.Nm endprotoent , -.Nm endprotoent_r -.Nd get protocol entry -.Sh SYNOPSIS -.Fd #include -.Ft struct protoent * -.Fn getprotoent "void" -.Ft int -.Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobyname "const char *name" -.Ft int -.Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobynumber "int proto" -.Ft int -.Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft void -.Fn setprotoent "int stayopen" -.Ft void -.Fn setprotoent_r "int stayopen" "struct protoent_data *protoent_data" -.Ft void -.Fn endprotoent "void" -.Ft void -.Fn endprotoent_r "struct protoent_data *protoent_data" -.Sh DESCRIPTION -The -.Fn getprotoent , -.Fn getprotobyname , -and -.Fn getprotobynumber -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network protocol database, -.Pa /etc/protocols . -.Bd -literal -offset indent -.Pp -struct protoent { - char *p_name; /* official name of protocol */ - char **p_aliases; /* alias list */ - int p_proto; /* protocol number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width p_aliases -.It Fa p_name -The official name of the protocol. -.It Fa p_aliases -A null-terminated list of alternate names for the protocol. -.It Fa p_proto -The protocol number. -.El -.Pp -The -.Fn getprotoent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setprotoent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the protocol database will not be closed after each call to -.Fn getprotobyname -or -.Fn getprotobynumber . -.Pp -The -.Fn endprotoent -function closes the file. -.Pp -The -.Fn getprotobyname -and -.Fn getprotobynumber -functions sequentially search from the beginning of the file until a -matching protocol name or protocol number is found, or until -.Dv EOF -is encountered. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Vt protoent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions -also take a pointer to a -.Vt protoent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getprotoent , -.Fn getprotobyport , -and -.Fn getprotobyname -functions return a pointer to a -.Vt protoent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/protocols -compact -.It Pa /etc/protocols -.El -.Sh SEE ALSO -.Xr protocols 5 -.Sh STANDARDS -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use a static data space; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Only the Internet protocols are currently understood. diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c deleted file mode 100644 index f0705e0765..0000000000 --- a/src/lib/libc/net/getprotoent.c +++ /dev/null @@ -1,166 +0,0 @@ -/* $OpenBSD: getprotoent.c,v 1.10 2007/09/02 15:19:17 deraadt Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setprotoent_r(int f, struct protoent_data *pd) -{ - if (pd->fp == NULL) - pd->fp = fopen(_PATH_PROTOCOLS, "r" ); - else - rewind(pd->fp); - pd->stayopen |= f; -} - -void -endprotoent_r(struct protoent_data *pd) -{ - if (pd->fp) { - fclose(pd->fp); - pd->fp = NULL; - } - free(pd->aliases); - pd->aliases = NULL; - pd->maxaliases = 0; - free(pd->line); - pd->line = NULL; - pd->stayopen = 0; -} - -int -getprotoent_r(struct protoent *pe, struct protoent_data *pd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r" )) == NULL) - return (-1); -again: - if ((p = fgetln(pd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(pd->line, len + 1); - if (cp == NULL) - return (-1); - pd->line = pe->p_name = memcpy(cp, p, len); - cp[len] = '\0'; - cp = strpbrk(cp, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - l = strtol(cp, &endp, 10); - if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) - goto again; - pe->p_proto = l; - if (pd->aliases == NULL) { - pd->maxaliases = 5; - pd->aliases = calloc(pd->maxaliases, sizeof(char *)); - if (pd->aliases == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - } - q = pe->p_aliases = pd->aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &pe->p_aliases[pd->maxaliases - 1]) { - p = realloc(pe->p_aliases, - 2 * pd->maxaliases * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - pd->maxaliases *= 2; - q = (char **)p + (q - pe->p_aliases); - pe->p_aliases = pd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - return (0); -} - -struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ - -void -setprotoent(int f) -{ - setprotoent_r(f, &_protoent_data); -} - -void -endprotoent(void) -{ - endprotoent_r(&_protoent_data); -} - -struct protoent * -getprotoent(void) -{ - static struct protoent proto; - - if (getprotoent_r(&proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c deleted file mode 100644 index 749b6b3f13..0000000000 --- a/src/lib/libc/net/getprotoname.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $OpenBSD: getprotoname.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getprotobyname_r(const char *name, struct protoent *pe, - struct protoent_data *pd) -{ - char **cp; - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) { - if (strcmp(pe->p_name, name) == 0) - break; - for (cp = pe->p_aliases; *cp != 0; cp++) - if (strcmp(*cp, name) == 0) - goto found; - } -found: - if (!pd->stayopen && pd->fp != NULL) { - fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} - -struct protoent * -getprotobyname(const char *name) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobyname_r(name, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getrrsetbyname.3 b/src/lib/libc/net/getrrsetbyname.3 deleted file mode 100644 index 121cb67fcc..0000000000 --- a/src/lib/libc/net/getrrsetbyname.3 +++ /dev/null @@ -1,166 +0,0 @@ -.\" $OpenBSD: getrrsetbyname.3,v 1.15 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM -.\" DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL -.\" INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING -.\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -.\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -.\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETRRSETBYNAME 3 -.Os -.Sh NAME -.Nm freerrset , -.Nm getrrsetbyname -.Nd retrieve DNS records -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn getrrsetbyname "const char *hostname" "unsigned int rdclass" \ -"unsigned int rdtype" "unsigned int flags" "struct rrsetinfo **res" -.Ft void -.Fn freerrset "struct rrsetinfo *rrset" -.Sh DESCRIPTION -.Fn getrrsetbyname -gets a set of resource records associated with a -.Fa hostname , -.Fa rdclass , -and -.Fa rdtype . -.Fa hostname -is a pointer to a NUL-terminated string. -The -.Fa flags -field is currently unused and must be zero. -.Pp -After a successful call to -.Fn getrrsetbyname , -.Fa *res -is a pointer to an -.Li rrsetinfo -structure, containing a list of one or more -.Li rdatainfo -structures containing resource records and potentially another list of -.Li rdatainfo -structures containing SIG resource records associated with those records. -The members -.Li rri_rdclass -and -.Li rri_rdtype -are copied from the parameters. -.Li rri_ttl -and -.Li rri_name -are properties of the obtained rrset. -The resource records contained in -.Li rri_rdatas -and -.Li rri_sigs -are in uncompressed DNS wire format. -Properties of the rdataset are represented in the -.Li rri_flags -bitfield. -If the -.Dv RRSET_VALIDATED -bit is set, the data has been DNSSEC -validated and the signatures verified. -.Pp -The following structures are used: -.Bd -literal -offset indent -struct rdatainfo { - unsigned int rdi_length; /* length of data */ - unsigned char *rdi_data; /* record data */ -}; - -struct rrsetinfo { - unsigned int rri_flags; /* RRSET_VALIDATED ... */ - unsigned int rri_rdclass; /* class number */ - unsigned int rri_rdtype; /* RR type number */ - unsigned int rri_ttl; /* time to live */ - unsigned int rri_nrdatas; /* size of rdatas array */ - unsigned int rri_nsigs; /* size of sigs array */ - char *rri_name; /* canonical name */ - struct rdatainfo *rri_rdatas; /* individual records */ - struct rdatainfo *rri_sigs; /* individual signatures */ -}; -.Ed -.Pp -All of the information returned by -.Fn getrrsetbyname -is dynamically allocated: the -.Li rrsetinfo -and -.Li rdatainfo -structures, -and the canonical host name strings pointed to by the -.Li rrsetinfo -structure. -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getrrsetbyname -is released by -.Fn freerrset . -.Li rrset -is a pointer to a -.Li struct rrsetinfo -created by a call to -.Fn getrrsetbyname . -.Pp -If the EDNS0 option is activated in -.Xr resolv.conf 5 , -.Fn getrrsetbyname -will request DNSSEC authentication using the EDNS0 DNSSEC OK (DO) bit. -.Sh RETURN VALUES -.Fn getrrsetbyname -returns zero on success, and one of the following error -codes if an error occurred: -.Pp -.Bl -tag -width ERRSET_NOMEMORY -.It Bq Er ERRSET_NONAME -The name does not exist. -.It Bq Er ERRSET_NODATA -The name exists, but does not have data of the desired type. -.It Bq Er ERRSET_NOMEMORY -Memory could not be allocated. -.It Bq Er ERRSET_INVAL -A parameter is invalid. -.It Bq Er ERRSET_FAIL -Other failure. -.El -.Sh SEE ALSO -.Xr resolver 3 , -.Xr resolv.conf 5 , -.Xr named 8 -.Sh HISTORY -.Fn getrrsetbyname -first appeared in -.Ox 3.0 . -The API first appeared in ISC BIND version 9. -.Sh AUTHORS -.An Jakob Schlyter Aq jakob@openbsd.org -.Sh CAVEATS -The -.Dv RRSET_VALIDATED -flag in -.Li rri_flags -is set if the AD (authenticated data) bit in the DNS answer is -set. -This flag -.Em should not -be trusted unless the transport between the nameserver and the resolver -is secure (e.g. IPsec, trusted network, loopback communication). -.Sh BUGS -The data in -.Li *rdi_data -should be returned in uncompressed wire format. -Currently, the data is in compressed format and the caller can't -uncompress since it doesn't have the full message. diff --git a/src/lib/libc/net/getrrsetbyname.c b/src/lib/libc/net/getrrsetbyname.c deleted file mode 100644 index 2bbb6ccf83..0000000000 --- a/src/lib/libc/net/getrrsetbyname.c +++ /dev/null @@ -1,517 +0,0 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.12 2010/06/29 09:22:06 deraadt Exp $ */ - -/* - * Copyright (c) 2001 Jakob Schlyter. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Portions Copyright (c) 1999-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -#define MAXPACKET 1024*64 - -struct dns_query { - char *name; - u_int16_t type; - u_int16_t class; - struct dns_query *next; -}; - -struct dns_rr { - char *name; - u_int16_t type; - u_int16_t class; - u_int16_t ttl; - u_int16_t size; - void *rdata; - struct dns_rr *next; -}; - -struct dns_response { - HEADER header; - struct dns_query *query; - struct dns_rr *answer; - struct dns_rr *authority; - struct dns_rr *additional; -}; - -static struct dns_response *parse_dns_response(const u_char *, int); -static struct dns_query *parse_dns_qsection(const u_char *, int, - const u_char **, int); -static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **, - int); - -static void free_dns_query(struct dns_query *); -static void free_dns_rr(struct dns_rr *); -static void free_dns_response(struct dns_response *); - -static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t); - -int -getrrsetbyname(const char *hostname, unsigned int rdclass, - unsigned int rdtype, unsigned int flags, - struct rrsetinfo **res) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int result; - struct rrsetinfo *rrset = NULL; - struct dns_response *response = NULL; - struct dns_rr *rr; - struct rdatainfo *rdata; - int length; - unsigned int index_ans, index_sig; - union { - HEADER hdr; - u_char buf[MAXPACKET]; - } answer; - - /* check for invalid class and type */ - if (rdclass > 0xffff || rdtype > 0xffff) { - result = ERRSET_INVAL; - goto fail; - } - - /* don't allow queries of class or type ANY */ - if (rdclass == 0xff || rdtype == 0xff) { - result = ERRSET_INVAL; - goto fail; - } - - /* don't allow flags yet, unimplemented */ - if (flags) { - result = ERRSET_INVAL; - goto fail; - } - - /* initialize resolver */ - if (_res_init(0) == -1) { - result = ERRSET_FAIL; - goto fail; - } - -#ifdef DEBUG - _resp->options |= RES_DEBUG; -#endif /* DEBUG */ - -#ifdef RES_USE_DNSSEC - /* turn on DNSSEC if EDNS0 is configured */ - if (_resp->options & RES_USE_EDNS0) - _resp->options |= RES_USE_DNSSEC; -#endif /* RES_USE_DNSEC */ - - /* make query */ - length = res_query(hostname, (signed int) rdclass, (signed int) rdtype, - answer.buf, sizeof(answer.buf)); - if (length < 0) { - switch(h_errno) { - case HOST_NOT_FOUND: - result = ERRSET_NONAME; - goto fail; - case NO_DATA: - result = ERRSET_NODATA; - goto fail; - default: - result = ERRSET_FAIL; - goto fail; - } - } - - /* parse result */ - response = parse_dns_response(answer.buf, length); - if (response == NULL) { - result = ERRSET_FAIL; - goto fail; - } - - if (response->header.qdcount != 1) { - result = ERRSET_FAIL; - goto fail; - } - - /* initialize rrset */ - rrset = calloc(1, sizeof(struct rrsetinfo)); - if (rrset == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - rrset->rri_rdclass = response->query->class; - rrset->rri_rdtype = response->query->type; - rrset->rri_ttl = response->answer->ttl; - rrset->rri_nrdatas = response->header.ancount; - - /* check for authenticated data */ - if (response->header.ad == 1) - rrset->rri_flags |= RRSET_VALIDATED; - - /* copy name from answer section */ - rrset->rri_name = strdup(response->answer->name); - if (rrset->rri_name == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* count answers */ - rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, - rrset->rri_rdtype); - rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, - T_RRSIG); - - /* allocate memory for answers */ - rrset->rri_rdatas = calloc(rrset->rri_nrdatas, - sizeof(struct rdatainfo)); - if (rrset->rri_rdatas == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* allocate memory for signatures */ - rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); - if (rrset->rri_sigs == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* copy answers & signatures */ - for (rr = response->answer, index_ans = 0, index_sig = 0; - rr; rr = rr->next) { - - rdata = NULL; - - if (rr->class == rrset->rri_rdclass && - rr->type == rrset->rri_rdtype) - rdata = &rrset->rri_rdatas[index_ans++]; - - if (rr->class == rrset->rri_rdclass && - rr->type == T_RRSIG) - rdata = &rrset->rri_sigs[index_sig++]; - - if (rdata) { - rdata->rdi_length = rr->size; - rdata->rdi_data = malloc(rr->size); - - if (rdata->rdi_data == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - memcpy(rdata->rdi_data, rr->rdata, rr->size); - } - } - free_dns_response(response); - - *res = rrset; - return (ERRSET_SUCCESS); - -fail: - if (rrset != NULL) - freerrset(rrset); - if (response != NULL) - free_dns_response(response); - return (result); -} - -void -freerrset(struct rrsetinfo *rrset) -{ - u_int16_t i; - - if (rrset == NULL) - return; - - if (rrset->rri_rdatas) { - for (i = 0; i < rrset->rri_nrdatas; i++) { - if (rrset->rri_rdatas[i].rdi_data == NULL) - break; - free(rrset->rri_rdatas[i].rdi_data); - } - free(rrset->rri_rdatas); - } - - if (rrset->rri_sigs) { - for (i = 0; i < rrset->rri_nsigs; i++) { - if (rrset->rri_sigs[i].rdi_data == NULL) - break; - free(rrset->rri_sigs[i].rdi_data); - } - free(rrset->rri_sigs); - } - - if (rrset->rri_name) - free(rrset->rri_name); - free(rrset); -} - -/* - * DNS response parsing routines - */ -static struct dns_response * -parse_dns_response(const u_char *answer, int size) -{ - struct dns_response *resp; - const u_char *cp; - - /* allocate memory for the response */ - resp = calloc(1, sizeof(*resp)); - if (resp == NULL) - return (NULL); - - /* initialize current pointer */ - cp = answer; - - /* copy header */ - memcpy(&resp->header, cp, HFIXEDSZ); - cp += HFIXEDSZ; - - /* fix header byte order */ - resp->header.qdcount = ntohs(resp->header.qdcount); - resp->header.ancount = ntohs(resp->header.ancount); - resp->header.nscount = ntohs(resp->header.nscount); - resp->header.arcount = ntohs(resp->header.arcount); - - /* there must be at least one query */ - if (resp->header.qdcount < 1) { - free_dns_response(resp); - return (NULL); - } - - /* parse query section */ - resp->query = parse_dns_qsection(answer, size, &cp, - resp->header.qdcount); - if (resp->header.qdcount && resp->query == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse answer section */ - resp->answer = parse_dns_rrsection(answer, size, &cp, - resp->header.ancount); - if (resp->header.ancount && resp->answer == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse authority section */ - resp->authority = parse_dns_rrsection(answer, size, &cp, - resp->header.nscount); - if (resp->header.nscount && resp->authority == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse additional section */ - resp->additional = parse_dns_rrsection(answer, size, &cp, - resp->header.arcount); - if (resp->header.arcount && resp->additional == NULL) { - free_dns_response(resp); - return (NULL); - } - - return (resp); -} - -static struct dns_query * -parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count) -{ - struct dns_query *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_query)); - if (curr == NULL) { - free_dns_query(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_query(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_query(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - } - - return (head); -} - -static struct dns_rr * -parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, - int count) -{ - struct dns_rr *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_rr)); - if (curr == NULL) { - free_dns_rr(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_rr(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_rr(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - - /* ttl */ - curr->ttl = _getlong(*cp); - *cp += INT32SZ; - - /* rdata size */ - curr->size = _getshort(*cp); - *cp += INT16SZ; - - /* rdata itself */ - curr->rdata = malloc(curr->size); - if (curr->rdata == NULL) { - free_dns_rr(head); - return (NULL); - } - memcpy(curr->rdata, *cp, curr->size); - *cp += curr->size; - } - - return (head); -} - -static void -free_dns_query(struct dns_query *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - free_dns_query(p->next); - free(p); -} - -static void -free_dns_rr(struct dns_rr *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - if (p->rdata) - free(p->rdata); - free_dns_rr(p->next); - free(p); -} - -static void -free_dns_response(struct dns_response *p) -{ - if (p == NULL) - return; - - free_dns_query(p->query); - free_dns_rr(p->answer); - free_dns_rr(p->authority); - free_dns_rr(p->additional); - free(p); -} - -static int -count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type) -{ - int n = 0; - - while(p) { - if (p->class == class && p->type == type) - n++; - p = p->next; - } - - return (n); -} diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c deleted file mode 100644 index beb8943af6..0000000000 --- a/src/lib/libc/net/getservbyname.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: getservbyname.c,v 1.10 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getservbyname_r(const char *name, const char *proto, struct servent *se, - struct servent_data *sd) -{ - char **cp; - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (strcmp(name, se->s_name) == 0) - goto gotname; - for (cp = se->s_aliases; *cp; cp++) - if (strcmp(name, *cp) == 0) - goto gotname; - continue; -gotname: - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} - -struct servent * -getservbyname(const char *name, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyname_r(name, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c deleted file mode 100644 index 46679ba366..0000000000 --- a/src/lib/libc/net/getservbyport.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: getservbyport.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getservbyport_r(int port, const char *proto, struct servent *se, - struct servent_data *sd) -{ - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (se->s_port != port) - continue; - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} - -struct servent * -getservbyport(int port, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyport_r(port, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3 deleted file mode 100644 index 7888b5f1b8..0000000000 --- a/src/lib/libc/net/getservent.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: getservent.3,v 1.20 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETSERVENT 3 -.Os -.Sh NAME -.Nm getservent , -.Nm getservent_r , -.Nm getservbyport , -.Nm getservbyport_r , -.Nm getservbyname , -.Nm getservbyname_r , -.Nm setservent , -.Nm setservent_r , -.Nm endservent , -.Nm endservent_r -.Nd get service entry -.Sh SYNOPSIS -.Fd #include -.Ft struct servent * -.Fn getservent "void" -.Ft int -.Fn getservent_r "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyname "const char *name" "const char *proto" -.Ft int -.Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyport "int port" "const char *proto" -.Ft int -.Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft void -.Fn setservent "int stayopen" -.Ft void -.Fn setservent_r "int stayopen" "struct servent_data *servent_data" -.Ft void -.Fn endservent "void" -.Ft void -.Fn endservent_r "struct servent_data *servent_data" -.Sh DESCRIPTION -The -.Fn getservent , -.Fn getservbyname , -and -.Fn getservbyport -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network services database, -.Pa /etc/services . -.Bd -literal -offset indent -struct servent { - char *s_name; /* official name of service */ - char **s_aliases; /* alias list */ - int s_port; /* port service resides at */ - char *s_proto; /* protocol to use */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width s_aliases -.It Fa s_name -The official name of the service. -.It Fa s_aliases -A null-terminated list of alternate names for the service. -.It Fa s_port -The port number at which the service resides. -Port numbers are returned in network byte order. -.It Fa s_proto -The name of the protocol to use when contacting the service. -.El -.Pp -The -.Fn getservent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setservent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the services database will not be closed after each call to -.Fn getservbyname -or -.Fn getservbyport . -.Pp -The -.Fn endservent -function closes the file. -.Pp -The -.Fn getservbyname -and -.Fn getservbyport -functions sequentially search from the beginning of the file until a -matching protocol name or port number (specified in network byte order) -is found, or until -.Dv EOF -is encountered. -If a protocol name is also supplied (non-null), -searches must also match the protocol. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Fa servent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions -also take a pointer to a -.Fa servent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getservent , -.Fn getservbyport , -and -.Fn getservbyname -functions return a pointer to a -.Fa servent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/services -compact -.It Pa /etc/services -.El -.Sh SEE ALSO -.Xr getprotoent 3 , -.Xr services 5 -.Sh STANDARDS -The -.Fn getservent , -.Fn getservbynumber , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getservent , -.Fn getservbyport , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use static data storage; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Expecting port numbers to fit in a 32-bit quantity is probably naive. diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c deleted file mode 100644 index c81a4cf3e2..0000000000 --- a/src/lib/libc/net/getservent.c +++ /dev/null @@ -1,168 +0,0 @@ -/* $OpenBSD: getservent.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setservent_r(int f, struct servent_data *sd) -{ - if (sd->fp == NULL) - sd->fp = fopen(_PATH_SERVICES, "r" ); - else - rewind(sd->fp); - sd->stayopen |= f; -} - -void -endservent_r(struct servent_data *sd) -{ - if (sd->fp) { - fclose(sd->fp); - sd->fp = NULL; - } - free(sd->aliases); - sd->aliases = NULL; - sd->maxaliases = 0; - free(sd->line); - sd->line = NULL; - sd->stayopen = 0; -} - -int -getservent_r(struct servent *se, struct servent_data *sd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "r" )) == NULL) - return (-1); -again: - if ((p = fgetln(sd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(sd->line, len + 1); - if (cp == NULL) - return (-1); - sd->line = se->s_name = memcpy(cp, p, len); - cp[len] = '\0'; - p = strpbrk(cp, " \t"); - if (p == NULL) - goto again; - *p++ = '\0'; - while (*p == ' ' || *p == '\t') - p++; - cp = strpbrk(p, ",/"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - l = strtol(p, &endp, 10); - if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) - goto again; - se->s_port = htons((in_port_t)l); - se->s_proto = cp; - if (sd->aliases == NULL) { - sd->maxaliases = 10; - sd->aliases = calloc(sd->maxaliases, sizeof(char *)); - if (sd->aliases == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - } - q = se->s_aliases = sd->aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &se->s_aliases[sd->maxaliases - 1]) { - p = realloc(se->s_aliases, - 2 * sd->maxaliases * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - sd->maxaliases *= 2; - q = (char **)p + (q - se->s_aliases); - se->s_aliases = sd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (0); -} - -struct servent_data _servent_data; /* shared with getservby{name,port}.c */ - -void -setservent(int f) -{ - setservent_r(f, &_servent_data); -} - -void -endservent(void) -{ - endservent_r(&_servent_data); -} - -struct servent * -getservent(void) -{ - static struct servent serv; - - if (getservent_r(&serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c deleted file mode 100644 index 7787115a9d..0000000000 --- a/src/lib/libc/net/herror.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: herror.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ - -/* - * ++Copyright++ 1987, 1993 - * - - * Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include -#include - -const char * const h_errlist[] = { - "Resolver Error 0 (no error)", - "Unknown host", /* 1 HOST_NOT_FOUND */ - "Host name lookup failure", /* 2 TRY_AGAIN */ - "Unknown server error", /* 3 NO_RECOVERY */ - "No address associated with name", /* 4 NO_ADDRESS */ -}; -const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; - -extern int h_errno; - -/* - * herror -- - * print the error indicated by the h_errno value. - */ -void -herror(const char *s) -{ - struct iovec iov[4]; - struct iovec *v = iov; - - if (s && *s) { - v->iov_base = (char *)s; - v->iov_len = strlen(s); - v++; - v->iov_base = ": "; - v->iov_len = 2; - v++; - } - v->iov_base = (char *)hstrerror(h_errno); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = "\n"; - v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); -} - -const char * -hstrerror(int err) -{ - if (err < 0) - return ("Resolver internal error"); - else if (err < h_nerr) - return (h_errlist[err]); - return ("Unknown resolver error"); -} diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c deleted file mode 100644 index 5ab4189597..0000000000 --- a/src/lib/libc/net/htonl.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: htonl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef htonl - -u_int32_t -htonl(u_int32_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c deleted file mode 100644 index c8b73fdbb7..0000000000 --- a/src/lib/libc/net/htons.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: htons.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef htons - -u_int16_t -htons(u_int16_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3 deleted file mode 100644 index 8ffc35a5fa..0000000000 --- a/src/lib/libc/net/if_indextoname.3 +++ /dev/null @@ -1,144 +0,0 @@ -.\" $OpenBSD: if_indextoname.3,v 1.11 2007/05/31 19:19:30 jmc Exp $ -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt IF_NAMETOINDEX 3 -.Os -.Sh NAME -.Nm if_nametoindex , -.Nm if_indextoname , -.Nm if_nameindex , -.Nm if_freenameindex -.Nd convert interface index to name, and vice versa -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft "unsigned int" -.Fn if_nametoindex "const char *ifname" -.Ft "char *" -.Fn if_indextoname "unsigned int ifindex" "char *ifname" -.Ft "struct if_nameindex *" -.Fn if_nameindex "void" -.Ft "void" -.Fn if_freenameindex "struct if_nameindex *ptr" -.Sh DESCRIPTION -These functions map interface indexes to interface names (such as -.Dq lo0 ) , -and vice versa. -.Pp -The -.Fn if_nametoindex -function converts an interface name specified by the -.Fa ifname -argument to an interface index (positive integer value). -If the specified interface does not exist, 0 will be returned. -.Pp -.Fn if_indextoname -converts an interface index specified by the -.Fa ifindex -argument to an interface name. -The -.Fa ifname -argument must point to a buffer of at least -.Dv IF_NAMESIZE -bytes into which the interface name corresponding to the specified index is -returned. -.Pf ( Dv IF_NAMESIZE -is also defined in -.Aq Pa net/if.h -and its value includes a terminating NUL byte at the end of the -interface name.) -This pointer is also the return value of the function. -If there is no interface corresponding to the specified index, -.Dv NULL -is returned. -.Pp -.Fn if_nameindex -returns an array of -.Vt if_nameindex -structures. -.Vt if_nameindex -is also defined in -.Aq Pa net/if.h , -and is as follows: -.Bd -literal -offset indent -struct if_nameindex { - unsigned int if_index; /* 1, 2, ... */ - char *if_name; /* NUL-terminated name */ -}; -.Ed -.Pp -The end of the array of structures is indicated by a structure with -an -.Fa if_index -of 0 and an -.Fa if_name -of -.Dv NULL . -The function returns a null pointer on error. -The memory used for this array of structures along with the interface -names pointed to by the -.Fa if_name -members is obtained dynamically. -This memory is freed by the -.Fn if_freenameindex -function. -.Pp -.Fn if_freenameindex -takes a pointer that was returned by -.Fn if_nameindex -as argument -.Pq Fa ptr , -and it reclaims the region allocated. -.Sh DIAGNOSTICS -.Fn if_nametoindex -returns 0 on error, positive integer on success. -.Fn if_indextoname -and -.Fn if_nameindex -return -.Dv NULL -on errors. -.Sh SEE ALSO -.Xr getifaddrs 3 , -.Xr networking 4 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 2553 -.%D March 1999 -.Re -.Sh STANDARDS -These functions are defined in ``Basic Socket Interface Extensions for IPv6'' -.Pq RFC 2533 . diff --git a/src/lib/libc/net/if_indextoname.c b/src/lib/libc/net/if_indextoname.c deleted file mode 100644 index f99e52e387..0000000000 --- a/src/lib/libc/net/if_indextoname.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $OpenBSD: if_indextoname.c,v 1.9 2002/03/07 22:40:23 millert Exp $ */ -/* $KAME: if_indextoname.c,v 1.6 2000/11/07 22:33:25 jinmei Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_indextoname.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2533: - * - * The second function maps an interface index into its corresponding - * name. - * - * #include - * - * char *if_indextoname(unsigned int ifindex, char *ifname); - * - * The ifname argument must point to a buffer of at least IF_NAMESIZE - * bytes into which the interface name corresponding to the specified - * index is returned. (IF_NAMESIZE is also defined in and - * its value includes a terminating null byte at the end of the - * interface name.) This pointer is also the return value of the - * function. If there is no interface corresponding to the specified - * index, NULL is returned, and errno is set to ENXIO, if there was a - * system error (such as running out of memory), if_indextoname returns - * NULL and errno would be set to the proper value (e.g., ENOMEM). - */ - -char * -if_indextoname(unsigned int ifindex, char *ifname) -{ - struct ifaddrs *ifaddrs, *ifa; - int error = 0; - - if (getifaddrs(&ifaddrs) < 0) - return(NULL); /* getifaddrs properly set errno */ - - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK && - ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index) - break; - } - - if (ifa == NULL) { - error = ENXIO; - ifname = NULL; - } - else - strlcpy(ifname, ifa->ifa_name, IFNAMSIZ); - - freeifaddrs(ifaddrs); - - errno = error; - return(ifname); -} diff --git a/src/lib/libc/net/if_nameindex.c b/src/lib/libc/net/if_nameindex.c deleted file mode 100644 index c5a771869b..0000000000 --- a/src/lib/libc/net/if_nameindex.c +++ /dev/null @@ -1,146 +0,0 @@ -/* $OpenBSD: if_nameindex.c,v 1.10 2010/09/24 13:29:29 claudio Exp $ */ -/* $KAME: if_nameindex.c,v 1.7 2000/11/24 08:17:20 itojun Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_nameindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.3 Return All Interface Names and Indexes - * - * The if_nameindex structure holds the information about a single - * interface and is defined as a result of including the - * header. - * - * struct if_nameindex { - * unsigned int if_index; - * char *if_name; - * }; - * - * The final function returns an array of if_nameindex structures, one - * structure per interface. - * - * struct if_nameindex *if_nameindex(void); - * - * The end of the array of structures is indicated by a structure with - * an if_index of 0 and an if_name of NULL. The function returns a NULL - * pointer upon an error, and would set errno to the appropriate value. - * - * The memory used for this array of structures along with the interface - * names pointed to by the if_name members is obtained dynamically. - * This memory is freed by the next function. - * - * 4.4. Free Memory - * - * The following function frees the dynamic memory that was allocated by - * if_nameindex(). - * - * #include - * - * void if_freenameindex(struct if_nameindex *ptr); - * - * The argument to this function must be a pointer that was returned by - * if_nameindex(). - */ - -struct if_nameindex * -if_nameindex(void) -{ - struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - size_t nbytes; - struct if_nameindex *ifni, *ifni2; - char *cp; - - if (getifaddrs(&ifaddrs) < 0) - return(NULL); - - /* - * First, find out how many interfaces there are, and how - * much space we need for the string names. - */ - ni = 0; - nbytes = 0; - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK) { - nbytes += strlen(ifa->ifa_name) + 1; - ni++; - } - } - - /* - * Next, allocate a chunk of memory, use the first part - * for the array of structures, and the last part for - * the strings. - */ - cp = malloc((ni + 1) * sizeof(struct if_nameindex) + nbytes); - ifni = (struct if_nameindex *)cp; - if (ifni == NULL) - goto out; - cp += (ni + 1) * sizeof(struct if_nameindex); - - /* - * Now just loop through the list of interfaces again, - * filling in the if_nameindex array and making copies - * of all the strings. - */ - ifni2 = ifni; - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK) { - ifni2->if_index = - ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; - ifni2->if_name = cp; - nbytes = strlen(ifa->ifa_name) + 1; - memcpy(cp, ifa->ifa_name, nbytes); - ifni2++; - cp += nbytes; - } - } - /* - * Finally, don't forget to terminate the array. - */ - ifni2->if_index = 0; - ifni2->if_name = NULL; -out: - freeifaddrs(ifaddrs); - return(ifni); -} - -void -if_freenameindex(struct if_nameindex *ptr) -{ - free(ptr); -} diff --git a/src/lib/libc/net/if_nametoindex.c b/src/lib/libc/net/if_nametoindex.c deleted file mode 100644 index 8bd792b949..0000000000 --- a/src/lib/libc/net/if_nametoindex.c +++ /dev/null @@ -1,81 +0,0 @@ -/* $OpenBSD: if_nametoindex.c,v 1.8 2002/03/07 22:40:23 millert Exp $ */ -/* $KAME: if_nametoindex.c,v 1.5 2000/11/24 08:04:40 itojun Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.1 Name-to-Index - * - * - * The first function maps an interface name into its corresponding - * index. - * - * #include - * - * unsigned int if_nametoindex(const char *ifname); - * - * If the specified interface name does not exist, the return value is - * 0, and errno is set to ENXIO. If there was a system error (such as - * running out of memory), the return value is 0 and errno is set to the - * proper value (e.g., ENOMEM). - */ - -unsigned int -if_nametoindex(const char *ifname) -{ - struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - - if (getifaddrs(&ifaddrs) < 0) - return(0); - - ni = 0; - - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK && - strcmp(ifa->ifa_name, ifname) == 0) { - ni = ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; - break; - } - } - - freeifaddrs(ifaddrs); - if (!ni) - errno = ENXIO; - return(ni); -} diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3 deleted file mode 100644 index ba7a3c8375..0000000000 --- a/src/lib/libc/net/inet.3 +++ /dev/null @@ -1,346 +0,0 @@ -.\" $OpenBSD: inet.3,v 1.23 2012/04/20 07:00:21 jmc Exp $ -.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: April 20 2012 $ -.Dt INET 3 -.Os -.Sh NAME -.Nm inet_aton , -.Nm inet_addr , -.Nm inet_network , -.Nm inet_pton , -.Nm inet_ntop , -.Nm inet_ntoa , -.Nm inet_makeaddr , -.Nm inet_netof , -.Nm inet_lnaof -.Nd Internet address manipulation routines -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn inet_aton "const char *cp" "struct in_addr *addr" -.Ft in_addr_t -.Fn inet_addr "const char *cp" -.Ft in_addr_t -.Fn inet_network "const char *cp" -.Ft int -.Fn inet_pton "int af" "const char *src" "void *dst" -.Ft const char * -.Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size" -.Ft char * -.Fn inet_ntoa "struct in_addr in" -.Ft struct in_addr -.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" -.Ft in_addr_t -.Fn inet_netof "struct in_addr in" -.Ft in_addr_t -.Fn inet_lnaof "struct in_addr in" -.Sh DESCRIPTION -The routines -.Fn inet_aton , -.Fn inet_addr , -and -.Fn inet_network -interpret character strings representing -numbers expressed in the Internet standard -.Dq dot -notation. -.Pp -The -.Fn inet_aton -routine interprets the specified character string as an Internet address, -placing the address into the structure provided. -It returns 1 if the string was successfully interpreted, -or 0 if the string was invalid. -.Pp -The -.Fn inet_addr -and -.Fn inet_network -functions return numbers suitable for use -as Internet addresses and Internet network -numbers, respectively. -Both functions return the constant -.Dv INADDR_NONE -if the specified character string is malformed. -.Pp -The -.Fn inet_pton -function converts a presentation format address (that is, printable form -as held in a character string) to network format (usually a -.Li struct in_addr -or some other internal binary representation, in network byte order). -It returns 1 if the address was valid for the specified address family; -0 if the address wasn't parseable in the specified address family; or \-1 -if some system error occurred (in which case -.Va errno -will have been set). -This function is presently valid for -.Dv AF_INET -and -.Dv AF_INET6 . -.Pp -The function -.Fn inet_ntop -converts an address from network format (usually a -.Li struct in_addr -or some other binary form, in network byte order) to presentation format -(suitable for external display purposes). -It returns -.Dv NULL -if a system -error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -.Pp -The routine -.Fn inet_ntoa -takes an Internet address and returns an -ASCII string representing the address in dot notation. -.Pp -The routine -.Fn inet_makeaddr -takes an Internet network number and a local -network address and constructs an Internet address -from it. -.Pp -The routines -.Fn inet_netof -and -.Fn inet_lnaof -break apart Internet host addresses, returning -the network number and local network address part, -respectively. -.Pp -All Internet addresses are returned in network -order (bytes ordered from left to right). -All network numbers and local address parts are -returned as machine format integer values. -.Sh INTERNET ADDRESSES (IP VERSION 4) -Values specified using dot notation take one of the following forms: -.Bd -literal -offset indent -a.b.c.d -a.b.c -a.b -a -.Ed -.Pp -When four parts are specified, each is interpreted -as a byte of data and assigned, from left to right, -to the four bytes of an Internet address. -Note that when an Internet address is viewed as a 32-bit -integer quantity on a system that uses little-endian -byte order -(such as the Intel 386, 486 and Pentium processors) -the bytes referred to above appear as -.Dq Li d.c.b.a . -That is, little-endian bytes are ordered from right to left. -.Pp -When a three part address is specified, the last -part is interpreted as a 16-bit quantity and placed -in the rightmost two bytes of the network address. -This makes the three part address format convenient -for specifying Class B network addresses as -.Dq Li 128.net.host . -.Pp -When a two part address is supplied, the last part -is interpreted as a 24-bit quantity and placed in -the rightmost three bytes of the network address. -This makes the two part address format convenient -for specifying Class A network addresses as -.Dq Li net.host . -.Pp -When only one part is given, the value is stored -directly in the network address without any byte -rearrangement. -.Pp -All numbers supplied as -.Dq parts -in a dot notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh INTERNET ADDRESSES (IP VERSION 6) -In order to support scoped IPv6 addresses, -.Xr getaddrinfo 3 -and -.Xr getnameinfo 3 -are recommended rather than the functions presented here. -.Pp -The presentation format of an IPv6 address is given in RFC 2373: -.Pp -There are three conventional forms for representing IPv6 addresses as -text strings: -.Bl -enum -.It -The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the -hexadecimal values of the eight 16-bit pieces of the address. -Examples: -.Bd -literal -offset indent -FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 -1080:0:0:0:8:800:200C:417A -.Ed -.Pp -Note that it is not necessary to write the leading zeros in an -individual field, but there must be at least one numeral in -every field (except for the case described in 2.). -.It -Due to the method of allocating certain styles of IPv6 -addresses, it will be common for addresses to contain long -strings of zero bits. -In order to make writing addresses -containing zero bits easier, a special syntax is available to -compress the zeros. -The use of -.Dq \&:\&: -indicates multiple groups -of 16 bits of zeros. -The -.Dq \&:\&: -can only appear once in an -address. -The -.Dq \&:\&: -can also be used to compress the leading and/or trailing zeros in an address. -.Pp -For example the following addresses: -.Bd -literal -offset indent -1080:0:0:0:8:800:200C:417A a unicast address -FF01:0:0:0:0:0:0:43 a multicast address -0:0:0:0:0:0:0:1 the loopback address -0:0:0:0:0:0:0:0 the unspecified addresses -.Ed -.Pp -may be represented as: -.Bd -literal -offset indent -1080::8:800:200C:417A a unicast address -FF01::43 a multicast address -::1 the loopback address -:: the unspecified addresses -.Ed -.It -An alternative form that is sometimes more convenient when -dealing with a mixed environment of IPv4 and IPv6 nodes is -x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values -of the six high-order 16-bit pieces of the address, and the 'd's -are the decimal values of the four low-order 8-bit pieces of the -address (standard IPv4 representation). -Examples: -.Bd -literal -offset indent -0:0:0:0:0:0:13.1.68.3 -0:0:0:0:0:FFFF:129.144.52.38 -.Ed -.Pp -or in compressed form: -.Bd -literal -offset indent -::13.1.68.3 -::FFFF:129.144.52.38 -.Ed -.El -.Sh SEE ALSO -.Xr byteorder 3 , -.Xr gethostbyname 3 , -.Xr getnetent 3 , -.Xr inet_net 3 , -.Xr hosts 5 , -.Xr networks 5 -.Rs -.%R RFC 2373 -.%D July 1998 -.%T "IP Version 6 Addressing Architecture" -.Re -.Rs -.%R RFC 3493 -.%D February 2003 -.%T "Basic Socket Interface Extensions for IPv6" -.Re -.Sh STANDARDS -The -.Nm inet_ntop -and -.Nm inet_pton -functions conform to the IETF IPv6 BSD API and address formatting -specifications. -Note that -.Nm inet_pton -does not accept 1-, 2-, or 3-part dotted addresses; all four parts -must be specified. -This is a narrower input set than that accepted by -.Nm inet_aton . -.Sh HISTORY -The -.Nm inet_addr , -.Nm inet_network , -.Nm inet_makeaddr , -.Nm inet_lnaof , -and -.Nm inet_netof -functions appeared in -.Bx 4.2 . -The -.Nm inet_aton -and -.Nm inet_ntoa -functions appeared in -.Bx 4.3 . -The -.Nm inet_pton -and -.Nm inet_ntop -functions appeared in BIND 4.9.4. -.Sh BUGS -The value -.Dv INADDR_NONE -(0xffffffff) is a valid broadcast address, but -.Fn inet_addr -cannot return that value without indicating failure. -Also, -.Fn inet_addr -should have been designed to return a -.Li struct in_addr . -The newer -.Fn inet_aton -function does not share these problems, and almost all existing code -should be modified to use -.Fn inet_aton -instead. -.Pp -The problem of host byte ordering versus network byte ordering is -confusing. -.Pp -The string returned by -.Fn inet_ntoa -resides in a static memory area. diff --git a/src/lib/libc/net/inet6_opt_init.3 b/src/lib/libc/net/inet6_opt_init.3 deleted file mode 100644 index 21880a6382..0000000000 --- a/src/lib/libc/net/inet6_opt_init.3 +++ /dev/null @@ -1,338 +0,0 @@ -.\" $OpenBSD: inet6_opt_init.3,v 1.3 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_OPT_INIT 3 -.Os -.\" -.Sh NAME -.Nm inet6_opt_init , -.Nm inet6_opt_append , -.Nm inet6_opt_finish , -.Nm inet6_opt_set_val , -.Nm inet6_opt_next , -.Nm inet6_opt_find , -.Nm inet6_opt_get_val -.Nd IPv6 Hop-by-Hop and Destination Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft "int" -.Fn inet6_opt_init "void *extbuf" "socklen_t extlen" -.Ft "int" -.Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" -.Ft "int" -.Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" -.Ft "int" -.Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" -.Ft "int" -.Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" -.\" -.Sh DESCRIPTION -Building and parsing the Hop-by-Hop and Destination options is -complicated. -The advanced sockets API defines a set of functions to -help applications create and manipulate Hop-by-Hop and Destination -options. -.\"This man page describes the functions specified in -.\"IETF Draft RFC 3542 while the -.\".Xr inet6_options_space 3 -.\"man page documents the functions defined in RFC 2292. -.\"It is expected -.\"that this set of functions will supersede those in RFC 2292 but for -.\"the time being both APIs are retained. -These functions use the -formatting rules specified in Appendix B in RFC 2460, i.e. that the -largest field is placed last in the option. -The function prototypes -for these functions are all contained in the header file -.Aq Pa netinet/in.h . -.\" -.Ss inet6_opt_init -The -.Fn inet6_opt_init -function -returns the number of bytes needed for an empty -extension header, one without any options. -If the -.Va extbuf -argument points to a valid section of memory -then the -.Fn inet6_opt_init -function also initializes the extension header's length field. -When attempting to initialize an extension buffer passed in the -.Va extbuf -argument, -.Fa extlen -must be a positive multiple of 8 or else the function fails and -returns \-1 to the caller. -.\" -.Ss inet6_opt_append -The -.Fn inet6_opt_append -function can perform different jobs. -When a valid -.Fa extbuf -argument is supplied it appends an option to the extension buffer and -returns the updated total length as well as a pointer to the newly -created option in -.Fa databufp . -If the value -of -.Fa extbuf -is -.Dv NULL -then the -.Fn inet6_opt_append -function only reports what the total length would -be if the option were actually appended. -The -.Fa len -and -.Fa align -arguments specify the length of the option and the required data -alignment which must be used when appending the option. -The -.Fa offset -argument should be the length returned by the -.Fn inet6_opt_init -function or a previous call to -.Fn inet6_opt_append . -.Pp -The -.Fa type -argument is the 8-bit option type. -.Pp -After -.Fn inet6_opt_append -has been called, the application can use the buffer pointed to by -.Fa databufp -directly, or use -.Fn inet6_opt_set_val -to specify the data to be contained in the option. -.Pp -Option types of -.Li 0 -and -.Li 1 -are reserved for the -.Li Pad1 -and -.Li PadN -options. -All other values from 2 through 255 may be used by applications. -.Pp -The length of the option data is contained in an 8-bit value and so -may contain any value from 0 through 255. -.Pp -The -.Fa align -parameter must have a value of 1, 2, 4, or 8 and cannot exceed the -value of -.Fa len . -The alignment values represent no alignment, 16-bit, 32-bit and 64-bit -alignments respectively. -.\" -.Ss inet6_opt_finish -The -.Fn inet6_opt_finish -calculates the final padding necessary to make the extension header a -multiple of 8 bytes, as required by the IPv6 extension header -specification, and returns the extension header's updated total -length. -The -.Fa offset -argument should be the length returned by -.Fn inet6_opt_init -or -.Fn inet6_opt_append . -When -.Fa extbuf -is not -.Dv NULL -the function also sets up the appropriate padding bytes by inserting a -Pad1 or PadN option of the proper length. -.Pp -If the extension header is too small to contain the proper padding -then an error of \-1 is returned to the caller. -.\" -.Ss inet6_opt_set_val -The -.Fn inet6_opt_set_val -function inserts data items of various sizes into the data portion of -the option. -The -.Fa databuf -argument is a pointer to memory that was returned by the -.Fn inet6_opt_append -call and the -.Fa offset -argument specifies where the option should be placed in the -data buffer. -The -.Fa val -argument points to an area of memory containing the data to be -inserted into the extension header, and the -.Fa vallen -argument indicates how much data to copy. -.Pp -The caller should ensure that each field is aligned on its natural -boundaries as described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field which is calculated as -.Fa offset -+ -.Fa vallen -and is used when composing options with multiple fields. -.\" -.Ss inet6_opt_next -The -.Fn inet6_opt_next -function parses received extension headers. -The -.Fa extbuf -and -.Fa extlen -arguments specify the location and length of the extension header -being parsed. -The -.Fa offset -argument should either be zero, for the first option, or the length value -returned by a previous call to -.Fn inet6_opt_next -or -.Fn inet6_opt_find . -The return value specifies the position where to continue scanning the -extension buffer. -The option is returned in the arguments -.Fa typep , lenp , -and -.Fa databufp . -.Fa typep , lenp , -and -.Fa databufp -point to the 8-bit option type, the 8-bit option length and the option -data respectively. -This function does not return any PAD1 or PADN options. -When an error occurs or there are no more options the return -value is \-1. -.\" -.Ss inet6_opt_find -The -.Fn inet6_opt_find -function searches the extension buffer for a particular option type, -passed in through the -.Fa type -argument. -If the option is found then the -.Fa lenp -and -.Fa databufp -arguments are updated to point to the option's length and data -respectively. -.Fa extbuf -and -.Fa extlen -must point to a valid extension buffer and give its length. -The -.Fa offset -argument can be used to search from a location anywhere in the -extension header. -.Ss inet6_opt_get_val -The -.Fn inet6_opt_get_val -function extracts data items of various sizes in the data portion of -the option. -The -.Fa databuf -is a pointer returned by the -.Fn inet6_opt_next -or -.Fn inet6_opt_find -functions. -The -.Fa val -argument points to where the data will be extracted. -The -.Fa offset -argument specifies from where in the data portion of the option the -value should be extracted; the first byte of option data is specified -by an offset of zero. -.Pp -It is expected that each field is aligned on its natural boundaries as -described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field -by calculating -.Fa offset -+ -.Fa vallen -which can be used when extracting option content with multiple fields. -Robust receivers must verify alignment before calling this function. -.\" -.Sh EXAMPLES -RFC 3542 gives comprehensive examples in Section 23. -KAME also provides examples in the -.Pa advapitest -directory of its kit. -.\" -.Sh DIAGNOSTICS -All the functions return -\-1 -on an error. -.\" -.Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%T "Advanced Sockets API for IPv6" -.%N RFC 3542 -.%D October 2002 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.Sh STANDARDS -The functions are documented in -.Dq Advanced Sockets API for IPv6 -.Pq RFC 3542 . -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. -.\" diff --git a/src/lib/libc/net/inet6_option_space.3 b/src/lib/libc/net/inet6_option_space.3 deleted file mode 100644 index 8aa79a6d0b..0000000000 --- a/src/lib/libc/net/inet6_option_space.3 +++ /dev/null @@ -1,444 +0,0 @@ -.\" $OpenBSD: inet6_option_space.3,v 1.21 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_option_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_OPTION_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_option_space , -.Nm inet6_option_init , -.Nm inet6_option_append , -.Nm inet6_option_alloc , -.Nm inet6_option_next , -.Nm inet6_option_find -.Nd IPv6 Hop-by-Hop and Destination Option Manipulation -.\" -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft "int" -.Fn inet6_option_space "int nbytes" -.Ft "int" -.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" -.Ft "int" -.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" -.Ft "u_int8_t *" -.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" -.Ft "int" -.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" -.Ft "int" -.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" -.\" -.Sh DESCRIPTION -.\" -Note: -RFC 2292 has been superseded by RFC 3542. -The use of functions described in this page is deprecated. -See -.Xr inet6_opt_init 3 . -.Pp -Manipulating and parsing IPv6's Hop-by-Hop and Destination options is -complicated by the need to properly align and pad data as well as the -need to manipulate ancillary information that is not part of the data -stream. -RFC 2292 defines a set of functions, which are implemented as -part of the Kame libraries, to help developers create, change, -and parse Hop-by-Hop and Destination options. -All of the prototypes -for the option functions are defined in the -.Aq Pa netinet/in.h -header file. -.\" -.Ss inet6_option_space -In order to determine the amount of space necessary to hold any option -the -.Fn inet6_option_space -function is called. -It returns the number of bytes required to hold -an option when it is stored as ancillary data, including the -.Li cmsghdr -structure at the beginning, and any necessary padding at the end. -The -.Fa nbytes -argument indicates the size of the structure defining the option, -and must include any pad bytes at the beginning (the value -.Li y -in the alignment term -.Dq Li "xn + y" ) , -the type byte, the length byte, and the option data. -.Pp -Note: If multiple options are stored in a single ancillary data -object, which is the recommended technique, the -.Fn inet6_option_space -function overestimates the amount of space required by the size of -.Li N-1 -.Li cmsghdr -structures, where -.Li N -is the number of options to be stored in the object. -Usually this has -no impact because it is assumed that most Hop-by-Hop and Destination -option headers carry only one option as indicated in appendix B of RFC 2460. -.\" -.Ss inet6_option_init -The -.Fn inet6_option_init -function is called to initialize any ancillary data object that will contain -a Hop-by-Hop or Destination option. -It returns -.Li 0 -on success and -.Li \-1 -when an error occurs. -.Pp -The -.Fa bp -argument points to a previously allocated area of memory which must be -large enough to contain all the arguments that the application intends -to add later via the -.Fn inet6_option_append -and -.Fn inet6_option_alloc -routines. -.Pp -The -.Fa cmsgp -argument is a pointer to a pointer to a -.Li cmsghdr -structure. -The -.Fa *cmsgp -argument -points to a -.Li cmsghdr -structure which is constructed by this function and stored in the -area of memory pointed to by -.Fa bp . -.Pp -The -.Fa type -is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS -and is stored in the -.Li cmsg_type -member of the -.Li cmsghdr -structure mentioned above. -.\" -.Ss inet6_option_append -This function appends a Hop-by-Hop option or a Destination option into -an ancillary data object previously initialized by a call to -.Fn inet6_option_init . -The -.Fn inet6_option_append -function returns -.Li 0 -if it succeeds or -.Li \-1 -when an error occurs. -.Pp -The -.Fa cmsg -argument is a pointer to the -.Li cmsghdr -structure that was initialized by a call to -.Fn inet6_option_init . -.Pp -The -.Fa typep -argument is a pointer to the 8-bit option type. -All options are -encoded as type-length-value tuples and it is assumed that -the -.Fa typep -field is immediately followed by the 8-bit option data length field, -which is then followed by the option data. -.Pp -The option types of -.Li 0 -and -.Li 1 -are reserved for the -.Li Pad1 -and -.Li PadN -options respectively. -All other values from -.Li 2 -through -.Li 255 -are available for applications to use. -.Pp -The option data length, since it is stored in 8 bites, must have a -value between -.Li 0 -and -.Li 255 , -inclusive. -.Pp -The -.Fa multx -argument -is the value -.Li x -in the alignment term -.Dq Li xn + y -and indicates the byte alignment necessary for the data. -Alignments may be specified as -.Li 1 , -.Li 2 , -.Li 4 , -or -.Li 8 -bytes, which is no alignment, 16-bit, 32-bit and 64-bit alignments -respectively. -.Pp -The -.Fa plusy -argument -is the value -.Li y -in the alignment term -.Dq Li xn + y -and must have a value between -.Li 0 -and -.Li 7 , -inclusive, indicating the amount of padding that is necessary for an -option. -.\" -.Ss inet6_option_alloc -The -.Fn inet6_option_alloc -function appends a Hop-by-Hop option or a Destination option into an -ancillary data object that has previously been initialized by a call to -.Fn inet6_option_init . -A successful call to the -.Fn inet6_option_alloc -function returns a pointer to the 8-bit option type field, -which is at the beginning of the allocated region. -.Fn inet6_option_alloc -returns -.Dv NULL -when an error has occurred. -.Pp -The difference between the -.Fn inet6_option_alloc -and -.Fn inet6_option_append -functions is that the latter copies the contents of a previously built -option into the ancillary data object while the former returns a -pointer to the place in the data object where the option's TLV must -then be built by the application. -.Pp -The -.Fa cmsg -argument is a pointer to a -.Li cmsghdr -structure that was initialized by -.Fn inet6_option_init . -.Pp -The -.Fa datalen -argument is the value of the option data length byte for this option. -This value is required as an argument to allow the function to -determine if padding must be appended at the end of the option. -(The -.Fn inet6_option_append -function does not need a data length argument -since the option data length must already be stored by the caller.) -.Pp -The -.Fa multx -and -.Fa plusy -arguments -are identical to the arguments of the same name described in the -.Fn inet6_option_init -function above. -.\" -.Ss inet6_option_next -The -.Fn inet6_option_next -function is used to process Hop-by-Hop and Destination options that -are present in an ancillary data object. -When an option remains to -be processed, the return value of the -.Fn inet6_option_next -function is -.Li 0 -and the -.Fa *tptrp -argument points to the 8-bit option type field, which is followed by -the 8-bit option data length, and then the option data. -When no more -options remain to be processed, the return value is -.Li \-1 -and -.Fa *tptrp -is -.Dv NULL . -When an error occurs, the return value is -.Li \-1 , -but the -.Fa *tptrp -argument is not -.Dv NULL . -This set of return values allows a program to easily loop through all -the options in an ancillary data object, checking for the error and -end of stream conditions along the way. -.Pp -When a valid option is returned, the -.Fa cmsg -argument points to a -.Li cmsghdr -where the -.Li cmsg_level -element equals -.Dv IPPROTO_IPV6 -and the -.Li cmsg_type -element is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is a pointer to a pointer to an 8-bit byte and -.Fa *tptrp -is used by the function to remember its place in the ancillary data -object each time the function is called. -When the -.Fn inet6_option_next -function is called for the first time on a given ancillary data object, -.Fa *tptrp -must be set to -.Dv NULL . -.Pp -Each time the function returns success, -the -.Fa *tptrp -argument points to the 8-bit option type field for the next option to -be processed. -.\" -.Ss inet6_option_find -The -.Fn inet6_option_find -function allows an application to search for a particular option type -in an ancillary data object. -The -.Fa cmsg -argument is a pointer to a -.Li cmsghdr -structure in which the -.Li cmsg_level -element equals -.Dv IPPROTO_IPV6 -and the -.Li cmsg_type -element is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is handled exactly as in the -.Fn inet6_option_next -function described above. -.Pp -The -.Fn inet6_option_find -function starts searching for an option of the specified type -beginning after the value of -.Fa *tptrp . -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 6. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_option_init -and -.Fn inet6_option_append -functions return -.Li 0 -on success or -.Li \-1 -on an error. -.Pp -The -.Fn inet6_option_alloc -function returns -.Dv NULL -on an error. -.Pp -When -.Fn inet6_option_next -or -.Fn inet6_option_find -detect an error they return -.Li \-1 , -setting -.Fa *tptrp -to a non -.Dv NULL -value. -.\" -.Sh SEE ALSO -.Xr inet6 4 , -.Xr ip6 4 -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh STANDARDS -The functions are documented in -.Dq Advanced Sockets API for IPv6 -(RFC 2292). -.\" -.Sh HISTORY -This implementation first appeared in the KAME advanced networking kit. -.\" diff --git a/src/lib/libc/net/inet6_rth_space.3 b/src/lib/libc/net/inet6_rth_space.3 deleted file mode 100644 index 326521def7..0000000000 --- a/src/lib/libc/net/inet6_rth_space.3 +++ /dev/null @@ -1,219 +0,0 @@ -.\" $OpenBSD: inet6_rth_space.3,v 1.3 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_RTH_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_rth_space , -.Nm inet6_rth_init , -.Nm inet6_rth_add , -.Nm inet6_rth_reverse , -.Nm inet6_rth_segments , -.Nm inet6_rth_getaddr -.Nd IPv6 Routing Header Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft socklen_t -.Fn inet6_rth_space "int" "int" -.Ft "void *" -.Fn inet6_rth_init "void *" "socklen_t" "int" "int" -.Ft int -.Fn inet6_rth_add "void *" "const struct in6_addr *" -.Ft int -.Fn inet6_rth_reverse "const void *" "void *" -.Ft int -.Fn inet6_rth_segments "const void *" -.Ft "struct in6_addr *" -.Fn inet6_rth_getaddr "const void *" "int" -.\" -.Sh DESCRIPTION -The IPv6 Advanced API, RFC 3542, defines the functions that an -application calls to build and examine IPv6 Routing headers. -Routing headers are used to perform source routing in IPv6 networks. -The RFC uses the word -.Dq segments -to describe addresses and that is the term used here as well. -All of the functions are defined in the header file -.Aq Pa netinet/in.h . -The functions described in this manual page all operate -on routing header structures which are defined in -.Aq Pa netinet/ip6.h -but which should not need to be modified outside the use of this API. -The size and shape of the route header structures may change, so using -the APIs is a more portable, long term, solution. -.Pp -The functions in the API are split into two groups, those that build a -routing header and those that parse a received routing header. -The builder functions are described first, followed by the parser functions. -.Ss inet6_rth_space -The -.Fn inet6_rth_space -function returns the number of bytes required to hold a Routing Header -of the type, specified in the -.Fa type -argument and containing the number of addresses specified in the -.Fa segments -argument. -When the type is -.Dv IPV6_RTHDR_TYPE_0 -the number of segments must be from 0 through 127. -The return value from this function is the number of bytes required to -store the routing header. -If the value 0 is returned then either the -route header type was not recognized or another error occurred. -.Ss inet6_rth_init -The -.Fn inet6_rth_init -function initializes the pre-allocated buffer pointed to by -.Fa bp -to contain a routing header of the specified type. -The -.Fa bp_len -argument is used to verify that the buffer is large enough. -The caller must allocate the buffer pointed to by bp. -The necessary buffer size should be determined by calling -.Fn inet6_rth_space -described in the previous sections. -.Pp -The -.Fn inet6_rth_init -function returns a pointer to -.Fa bp -on success and -.Dv NULL -when there is an error. -.Ss inet6_rth_add -The -.Fn inet6_rth_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the routing header being constructed. -.Pp -A successful addition results in the function returning 0, otherwise -\-1 is returned. -.Ss inet6_rth_reverse -The -.Fn inet6_rth_reverse -function takes a routing header, pointed to by the -argument -.Fa in , -and writes a new routing header into the argument pointed to by -.Fa out . -The routing header at that sends datagrams along the reverse of that -route. -Both arguments are allowed to point to the same buffer meaning -that the reversal can occur in place. -.Pp -The return value of the function is 0 on success, or \-1 when -there is an error. -.\" -.Pp -The next set of functions operate on a routing header that the -application wants to parse. -In the usual case such a routing header -is received from the network, although these functions can also be -used with routing headers that the application itself created. -.Ss inet6_rth_segments -The -.Fn inet6_rth_segments -function returns the number of segments contained in the -routing header pointed to by -.Fa bp . -The return value is the number of segments contained in the routing -header, or \-1 if an error occurred. -It is not an error for 0 to be -returned as a routing header may contain 0 segments. -.\" -.Ss inet6_rth_getaddr -The -.Fn inet6_rth_getaddr -function is used to retrieve a single address from a routing header. -The -.Fa index -is the location in the routing header from which the application wants -to retrieve an address. -The -.Fa index -parameter must have a value between 0 and one less than the number of -segments present in the routing header. -The -.Fn inet6_rth_segments -function, described in the last section, should be used to determine -the total number of segments in the routing header. -The -.Fn inet6_rth_getaddr -function returns a pointer to an IPv6 address on success or -.Dv NULL -when an error has occurred. -.\" -.Sh EXAMPLES -RFC 3542 gives extensive examples in Section 21, Appendix B. -KAME also provides examples in the advapitest directory of its kit. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rth_space -and -.Fn inet6_rth_getaddr -functions return 0 on errors. -.Pp -The -.Fn inet6_rthdr_init -function returns -.Dv NULL -on error. -The -.Fn inet6_rth_add -and -.Fn inet6_rth_reverse -functions return 0 on success, or \-1 upon an error. -.\" -.Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%T "Advanced Sockets API for IPv6" -.%N RFC 3542 -.%D May 2003 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. diff --git a/src/lib/libc/net/inet6_rthdr_space.3 b/src/lib/libc/net/inet6_rthdr_space.3 deleted file mode 100644 index 3287bfe009..0000000000 --- a/src/lib/libc/net/inet6_rthdr_space.3 +++ /dev/null @@ -1,314 +0,0 @@ -.\" $OpenBSD: inet6_rthdr_space.3,v 1.20 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_rthdr_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_RTHDR_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_rthdr_space , -.Nm inet6_rthdr_init , -.Nm inet6_rthdr_add , -.Nm inet6_rthdr_lasthop , -.Nm inet6_rthdr_reverse , -.Nm inet6_rthdr_segments , -.Nm inet6_rthdr_getaddr , -.Nm inet6_rthdr_getflags -.Nd IPv6 Routing Header Options Manipulation -.\" -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft size_t -.Fn inet6_rthdr_space "int type" "int segments" -.Ft "struct cmsghdr *" -.Fn inet6_rthdr_init "void *bp" "int type" -.Ft int -.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out" -.Ft int -.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg" -.Ft "struct in6_addr *" -.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index" -.Ft int -.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index" -.\" -.Sh DESCRIPTION -.\"The RFC 2292 IPv6 Advanced API has been deprecated in favor of the -.\"newer, RFC 3542 APIs. -.\"On platforms that support it, currently only -.\"FreeBSD, please use the newer API to manipulate routing header -.\"options. -.\".Pp -Note: -RFC 2292 has been superseded by RFC 3542. -The use of functions described in this page is deprecated. -See -.Xr inet6_rth_space 3 . -.Pp -The RFC 2292 IPv6 Advanced API defined eight functions for -applications to use for building and parsing routing headers. -The -eight functions are split into two groups, the first of which builds -the header and the second of which can parse it. -The function prototypes for these functions are all in the -.Aq Pa netinet/in.h -header. -Although direct manipulation of a routing header is possible, -this set of APIs make it unnecessary and such direct manipulation -should be avoided so that changes to the underlying structures do not -break applications. -.Pp -Please note that RFC 2292 uses the term -.Dq segments -instead of the term -.Dq addresses -but they are considered equivalent for this manual page. -.\" -.Ss inet6_rthdr_space -The -.Fn inet6_rthdr_space -function returns the number of bytes required to hold a routing header -of the specified -.Fa type -and containing the specified number of -.Fa segments . -Only one -.Fa type -is supported, -.Dv IPV6_RTHDR_TYPE_0 , -and it can hold from 1 to 23 segments. -The return value includes the -size of the -.Vt cmsghdr -structure that precedes the routing header and -any required padding. -.Pp -A return value of 0 indicates an error. -Either the type was specified -incorrectly, or the number of segments was less than one or greater -than 23. -.Pp -Note: The -.Fn inet6_rthdr_space -function only returns the size required by the routing header and does -not allocate memory for the caller. -.\" -.Ss inet6_rthdr_init -The -.Fn inet6_rthdr_init -function initializes a buffer, pointed to by -.Fa bp -with an appropriate -.Li cmsghdr -structure followed by a routing header of the specified -.Fa type . -.Pp -The caller must use the -.Fn inet6_rthdr_space -function to determine the size of the buffer, and then allocate that -buffer before calling -.Fn inet6_rthdr_init . -.Pp -The return value is a pointer to a -.Li cmsghdr -structure, which is used as the first argument to the -.Fn inet6_rthdr_add -and -.Fn inet6_rthdr_lasthop -functions in order to construct the routing header. -When an error occurs the return value is -.Dv NULL . -.\" -.Ss inet6_rthdr_add -The -.Fn inet6_rthdr_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the -routing header being constructed and sets the type of this address to the -value of -.Fa flags . -The -.Fa flags -must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing is required. -.Pp -When the function succeeds it returns 0, otherwise \-1 is returned. -.\" -.Ss inet6_rthdr_lasthop -The -.Fn inet6_rthdr_lasthop -function specifies the strict or loose flag for the final hop of a -routing header. -The -.Fa flags -argument must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT . -.Pp -The return value of the function is 0 upon success, and \-1 when an -error has occurred. -.Pp -Please note that a routing header specifying -.Li N -intermediate nodes requires -.Li N+1 -strict or loose flags meaning that -.Fn inet6_rthdr_add -must be called -.Li N -times and then -.Fn inet6_rthdr_lasthop -must be called once. -.\" -.Ss inet6_rthdr_reverse -This function was never implemented. -.Pp -The following three functions provide an API for parsing a received -routing header: -.\" -.Ss inet6_rthdr_segments -The -.Fn inet6_rthdr_segments -function returns the number of segments contained in the routing -header pointed to by the -.Fa cmsg -argument. -On success the return value is from 1 to 23. -When an error occurs, \-1 is returned. -.\" -.Ss inet6_rthdr_getaddr -The -.Fn inet6_rthdr_getaddr -function returns a pointer to the IPv6 address specified by the -.Fa index -argument from the routing header pointed to by -.Fa cmsg . -The index must be between 1 and the number returned by -.Fn inet6_rthdr_segments , -described above. -An application must call -.Fn inet6_rthdr_segments -to obtain the number of segments in the routing header. -.Pp -If an error occurs, -.Dv NULL -is returned. -.\" -.Ss inet6_rthdr_getflags -The -.Fn inet6_rthdr_getflags -function returns the flags value of the segment specified by -.Fa index -of the routing header pointed to by -.Fa cmsg . -The -.Fa index -argument must be between 0 and the value returned by -.Fn inet6_rthdr_segments . -The return value will be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing was requested for -that segment. -.Pp -When an error occurs, \-1 is returned. -.Pp -Note: Flags begin at index 0 while segments begin at index 1, to -maintain consistency with the terminology and figures in RFC 2460. -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 8. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rthdr_space -function returns 0 when an error occurs. -.Pp -The -.Fn inet6_rthdr_add -and -.Fn inet6_rthdr_lasthop -functions return 0 on success, and \-1 on error. -.Pp -The -.Fn inet6_rthdr_init -and -.Fn inet6_rthdr_getaddr -functions -return -.Dv NULL -on error. -.Pp -The -.Fn inet6_rthdr_segments -and -.Fn inet6_rthdr_getflags -functions return \-1 on error. -.\" -.Sh SEE ALSO -.Xr inet6 4 , -.Xr ip6 4 -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh HISTORY -This implementation first appeared in the KAME advanced networking kit. -.\" -.Sh BUGS -The -.Fn inet6_rthdr_reverse -function was never implemented. -.\".Pp -.\"This API is deprecated in favor of -.\".Xr inet6_rth_space 3 -.\".Sh SEE ALSO -.\".Xr inet6_rth_space 3 diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c deleted file mode 100644 index c962a03382..0000000000 --- a/src/lib/libc/net/inet_addr.c +++ /dev/null @@ -1,171 +0,0 @@ -/* $OpenBSD: inet_addr.c,v 1.9 2005/08/06 20:30:03 espie Exp $ */ - -/* - * ++Copyright++ 1983, 1990, 1993 - * - - * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include - -/* - * Ascii internet address interpretation routine. - * The value returned is in network order. - */ -in_addr_t -inet_addr(const char *cp) -{ - struct in_addr val; - - if (inet_aton(cp, &val)) - return (val.s_addr); - return (INADDR_NONE); -} - -/* - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ -int -inet_aton(const char *cp, struct in_addr *addr) -{ - in_addr_t val; - int base, n; - char c; - u_int parts[4]; - u_int *pp = parts; - - c = *cp; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit(c)) - return (0); - val = 0; base = 10; - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; - else - base = 8; - } - for (;;) { - if (isascii(c) && isdigit(c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; - } else - break; - } - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3) - return (0); - *pp++ = val; - c = *++cp; - } else - break; - } - /* - * Check for trailing characters. - */ - if (c != '\0' && (!isascii(c) || !isspace(c))) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch (n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if ((val > 0xffffff) || (parts[0] > 0xff)) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if (addr) - addr->s_addr = htonl(val); - return (1); -} diff --git a/src/lib/libc/net/inet_lnaof.c b/src/lib/libc/net/inet_lnaof.c deleted file mode 100644 index b1a58cd2c1..0000000000 --- a/src/lib/libc/net/inet_lnaof.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: inet_lnaof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Return the local network address portion of an - * internet address; handles class a/b/c network - * number formats. - */ -in_addr_t -inet_lnaof(struct in_addr in) -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return ((i)&IN_CLASSA_HOST); - else if (IN_CLASSB(i)) - return ((i)&IN_CLASSB_HOST); - else - return ((i)&IN_CLASSC_HOST); -} diff --git a/src/lib/libc/net/inet_makeaddr.c b/src/lib/libc/net/inet_makeaddr.c deleted file mode 100644 index 87d9325231..0000000000 --- a/src/lib/libc/net/inet_makeaddr.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: inet_makeaddr.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(in_addr_t net, in_addr_t host) -{ - in_addr_t addr; - - if (net < 128) - addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); - else if (net < 16777216L) - addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); - else - addr = net | host; - addr = htonl(addr); - return (*(struct in_addr *)&addr); -} diff --git a/src/lib/libc/net/inet_net.3 b/src/lib/libc/net/inet_net.3 deleted file mode 100644 index 11cc1d67c6..0000000000 --- a/src/lib/libc/net/inet_net.3 +++ /dev/null @@ -1,197 +0,0 @@ -.\" $OpenBSD: inet_net.3,v 1.15 2012/06/24 18:06:42 gilles Exp $ -.\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ -.\" -.\" Copyright (c) 1997 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Luke Mewburn. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE -.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: June 24 2012 $ -.Dt INET_NET 3 -.Os -.Sh NAME -.Nm inet_net_ntop , -.Nm inet_net_pton -.Nd Internet network number manipulation routines -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft char * -.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" -.Ft int -.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" -.Sh DESCRIPTION -The -.Fn inet_net_ntop -function converts an Internet network number from network format (usually a -.Li struct in_addr -or some other binary form, in network byte order) to CIDR presentation format -(suitable for external display purposes). -.Fa bits -is the number of bits in -.Fa src -that are the network number. -It returns -.Dv NULL -if a system error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -.Pp -The -.Fn inet_net_pton -function converts a presentation format Internet network number (that is, -printable form as held in a character string) to network format (usually a -.Li struct in_addr -or some other internal binary representation, in network byte order). -It returns the number of bits (either computed based on the class, or -specified with /CIDR), or \-1 if a failure occurred -(in which case -.Va errno -will have been set. -It will be set to -.Er ENOENT -if the Internet network number was not valid). -.Pp -Caution: -The -.Fa dst -field should be zeroed before calling -.Fn inet_net_pton -as the function will only fill the number of bytes necessary to -encode the network number in network byte order. -.Pp -The only values for -.Fa af -currently supported are -.Dv AF_INET -and -.Dv AF_INET6 . -.Fa size -is the size of the result buffer -.Fa dst . -.Sh NETWORK NUMBERS (IP VERSION 4) -The external representation of Internet network numbers may be specified in -one of the following forms: -.Bd -literal -offset indent -a -a.b -a.b.c -a.b.c.d -.Ed -.Pp -Any of the above four forms may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-32 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified the number of bits in the network address is calculated -as the larger of the number of bits in the class to which the address -belongs and the number of bits provided rounded up modulo 8. -Examples: -.Pp -.Bl -tag -width 10.1.2.3/24 -offset indent -compact -.It Li 10 -an 8-bit network number (class A), value -.Li 10.0.0.0 . -.It Li 192 -a 24-bit network number (class C), value -.Li 192.0.0.0 . -.It Li 10.10 -a 16-bit network number, value -.Li 10.10.0.0 . -.It Li 10.1.2 -a 24-bit network number, value -.Li 10.1.2.0 . -.It Li 10.1.2.3 -a 32-bit network number, value -.Li 10.1.2.3 . -.It Li 10.1.2.3/24 -a 24-bit network number (explicit), value -.Li 10.1.2.3 . -.El -.Pp -Note that when the number of bits is specified using -.Dq Li /bits -notation, the value of the address still includes all bits supplied -in the external representation, even those bits which are the host -part of an Internet address. -Also, unlike -.Xr inet_pton 3 -where the external representation is assumed to be a host address, the -external representation for -.Fn inet_net_pton -is assumed to be a network address. -Thus -.Dq Li 10.1 -is assumed to be -.Dq Li 10.1.0.0 -not -.Dq Li 10.0.0.1 -.Pp -All numbers supplied as -.Dq parts -in a -.Ql \&. -notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; otherwise, a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh NETWORK NUMBERS (IP VERSION 6) -See -.Xr inet_pton 3 -for valid external representations of IP version 6 addresses. -A valid external representation may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-128 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified 128 is used. -Note that when the number of bits is specified using -.Dq Li /bits -notation, the value of the address still includes all bits supplied -in the external representation, even those bits which are the host -part of an Internet address. -.Sh SEE ALSO -.Xr byteorder 3 , -.Xr inet 3 , -.Xr inet_pton 3 , -.Xr networks 5 -.Sh HISTORY -The -.Nm inet_net_ntop -and -.Nm inet_net_pton -functions first appeared in BIND 4.9.4. diff --git a/src/lib/libc/net/inet_net_ntop.c b/src/lib/libc/net/inet_net_ntop.c deleted file mode 100644 index 35ae7909d3..0000000000 --- a/src/lib/libc/net/inet_net_ntop.c +++ /dev/null @@ -1,162 +0,0 @@ -/* $OpenBSD: inet_net_ntop.c,v 1.7 2012/06/22 19:13:37 gilles Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -static char *inet_net_ntop_ipv4(const u_char *, int, char *, size_t); -static char *inet_net_ntop_ipv6(const u_char *, int, char *, size_t); - -/* - * char * - * inet_net_ntop(af, src, bits, dst, size) - * convert network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_ntop_ipv4(src, bits, dst, size)); - case AF_INET6: - return (inet_net_ntop_ipv6(src, bits, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } -} - -/* - * static char * - * inet_net_ntop_ipv4(src, bits, dst, size) - * convert IPv4 network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), July 1996 - */ -static char * -inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) -{ - char *odst = dst; - u_int m; - int b; - char *ep; - int advance; - - ep = dst + size; - if (ep <= dst) - goto emsgsize; - - if (bits < 0 || bits > 32) { - errno = EINVAL; - return (NULL); - } - if (bits == 0) { - if (ep - dst < sizeof "0") - goto emsgsize; - *dst++ = '0'; - *dst = '\0'; - } - - /* Format whole octets. */ - for (b = bits / 8; b > 0; b--) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", *src++); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (b > 1) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - - /* Format partial octet. */ - b = bits % 8; - if (b > 0) { - if (ep - dst < sizeof ".255") - goto emsgsize; - if (dst != odst) - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - m = ((1 << b) - 1) << (8 - b); - advance = snprintf(dst, ep - dst, "%u", *src & m); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - } - - /* Format CIDR /width. */ - if (ep - dst < sizeof "/32") - goto emsgsize; - advance = snprintf(dst, ep - dst, "/%u", bits); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} - -static char * -inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) -{ - int ret; - char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")]; - - if (bits < 0 || bits > 128) { - errno = EINVAL; - return (NULL); - } - - if (inet_ntop(AF_INET6, src, buf, size) == NULL) - return (NULL); - - ret = snprintf(dst, size, "%s/%d", buf, bits); - if (ret == -1 || ret >= size) { - errno = EMSGSIZE; - return (NULL); - } - - return (dst); -} diff --git a/src/lib/libc/net/inet_net_pton.c b/src/lib/libc/net/inet_net_pton.c deleted file mode 100644 index 74261399f7..0000000000 --- a/src/lib/libc/net/inet_net_pton.c +++ /dev/null @@ -1,230 +0,0 @@ -/* $OpenBSD: inet_net_pton.c,v 1.7 2012/06/22 19:13:37 gilles Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static int inet_net_pton_ipv4(const char *, u_char *, size_t); -static int inet_net_pton_ipv6(const char *, u_char *, size_t); - -/* - * static int - * inet_net_pton(af, src, dst, size) - * convert network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not a valid network specification. - * author: - * Paul Vixie (ISC), June 1996 - */ -int -inet_net_pton(int af, const char *src, void *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(src, dst, size)); - case AF_INET6: - return (inet_net_pton_ipv6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (-1); - } -} - -/* - * static int - * inet_net_pton_ipv4(src, dst, size) - * convert IPv4 network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not an IPv4 network specification. - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), June 1996 - */ -static int -inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) -{ - static const char - xdigits[] = "0123456789abcdef", - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; - const u_char *odst = dst; - - ch = *src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size <= 0) - goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - *dst |= n; - if (!dirty++) - *dst <<= 4; - else if (size-- > 0) - *++dst = 0, dirty = 0; - else - goto emsgsize; - } - if (dirty) - size--; - } else if (isascii(ch) && isdigit(ch)) { - /* Decimal: eat dotted digit string. */ - for (;;) { - tmp = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - tmp *= 10; - tmp += n; - if (tmp > 255) - goto enoent; - } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (size-- <= 0) - goto emsgsize; - *dst++ = (u_char) tmp; - if (ch == '\0' || ch == '/') - break; - if (ch != '.') - goto enoent; - ch = *src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - if (bits > 32) - goto emsgsize; - } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - } - - /* Firey death and destruction unless we prefetched EOS. */ - if (ch != '\0') - goto enoent; - - /* If nothing was written to the destination, we found no address. */ - if (dst == odst) - goto enoent; - /* If no CIDR spec was given, infer width from net class. */ - if (bits == -1) { - if (*odst >= 240) /* Class E */ - bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ - bits = 24; - else if (*odst >= 128) /* Class B */ - bits = 16; - else /* Class A */ - bits = 8; - /* If imputed mask is narrower than specified octets, widen. */ - if (bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; - } - /* Extend network to cover the actual mask. */ - while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) - goto emsgsize; - *dst++ = '\0'; - } - return (bits); - - enoent: - errno = ENOENT; - return (-1); - - emsgsize: - errno = EMSGSIZE; - return (-1); -} - - -static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) -{ - int ret; - int bits; - char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")]; - char *sep; - const char *errstr; - - if (strlcpy(buf, src, sizeof buf) >= sizeof buf) { - errno = EMSGSIZE; - return (-1); - } - - sep = strchr(buf, '/'); - if (sep != NULL) - *sep++ = '\0'; - - ret = inet_pton(AF_INET6, buf, dst); - if (ret != 1) - return (-1); - - if (sep == NULL) - return 128; - - bits = strtonum(sep, 0, 128, &errstr); - if (errstr) { - errno = EINVAL; - return (-1); - } - - return bits; -} diff --git a/src/lib/libc/net/inet_neta.c b/src/lib/libc/net/inet_neta.c deleted file mode 100644 index e3e7d0eb71..0000000000 --- a/src/lib/libc/net/inet_neta.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $OpenBSD: inet_neta.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include - -/* - * char * - * inet_neta(src, dst, size) - * format an in_addr_t network number into presentation format. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * format of ``src'' is as for inet_network(). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_neta(in_addr_t src, char *dst, size_t size) -{ - char *odst = dst; - char *ep; - int advance; - - if (src == 0x00000000) { - if (size < sizeof "0.0.0.0") - goto emsgsize; - strlcpy(dst, "0.0.0.0", size); - return dst; - } - ep = dst + size; - if (ep <= dst) - goto emsgsize; - while (src & 0xffffffff) { - u_char b = (src & 0xff000000) >> 24; - - src <<= 8; - if (b || src) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", b); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (src != 0L) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - } - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/src/lib/libc/net/inet_netof.c b/src/lib/libc/net/inet_netof.c deleted file mode 100644 index 2f468c3aca..0000000000 --- a/src/lib/libc/net/inet_netof.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: inet_netof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -in_addr_t -inet_netof(struct in_addr in) -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); - else if (IN_CLASSB(i)) - return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); - else - return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); -} diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c deleted file mode 100644 index 8b26ba8ff9..0000000000 --- a/src/lib/libc/net/inet_network.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: inet_network.c,v 1.10 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* - * Internet network address interpretation routine. - * The library routines call this routine to interpret - * network numbers. - */ -in_addr_t -inet_network(const char *cp) -{ - in_addr_t val, base, n; - char c; - in_addr_t parts[4], *pp = parts; - int i; - -again: - val = 0; base = 10; - if (*cp == '0') - base = 8, cp++; - if (*cp == 'x' || *cp == 'X') - base = 16, cp++; - while ((c = *cp)) { - if (isdigit(c)) { - val = (val * base) + (c - '0'); - cp++; - continue; - } - if (base == 16 && isxdigit(c)) { - val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); - cp++; - continue; - } - break; - } - if (*cp == '.') { - if (pp >= parts + 3) - return (INADDR_NONE); - *pp++ = val, cp++; - goto again; - } - if (*cp && !isspace(*cp)) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - for (val = 0, i = 0; i < 4; i++) { - val <<= 8; - if (i < n) - val |= parts[i] & 0xff; - } - return (val); -} diff --git a/src/lib/libc/net/inet_ntoa.c b/src/lib/libc/net/inet_ntoa.c deleted file mode 100644 index ff5d93ded2..0000000000 --- a/src/lib/libc/net/inet_ntoa.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: inet_ntoa.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -#include -#include -#include -#include - -char * -inet_ntoa(struct in_addr in) -{ - static char b[18]; - char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - (void)snprintf(b, sizeof(b), - "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c deleted file mode 100644 index 9deb352e24..0000000000 --- a/src/lib/libc/net/inet_ntop.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $OpenBSD: inet_ntop.c,v 1.8 2008/12/09 19:38:38 otto Exp $ */ - -/* Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static const char *inet_ntop4(const u_char *src, char *dst, size_t size); -static const char *inet_ntop6(const u_char *src, char *dst, size_t size); - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -inet_ntop(int af, const void *src, char *dst, socklen_t size) -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, (size_t)size)); - case AF_INET6: - return (inet_ntop6(src, dst, (size_t)size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address, more or less like inet_ntoa() - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const u_char *src, char *dst, size_t size) -{ - static const char fmt[] = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; - int l; - - l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]); - if (l <= 0 || l >= size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop6(const u_char *src, char *dst, size_t size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; - char *tp, *ep; - struct { int base, len; } best, cur; - u_int words[IN6ADDRSZ / INT16SZ]; - int i; - int advance; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - cur.base = -1; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - ep = tmp + sizeof(tmp); - for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, (size_t)(ep - tp))) - return (NULL); - tp += strlen(tp); - break; - } - advance = snprintf(tp, ep - tp, "%x", words[i]); - if (advance <= 0 || advance >= ep - tp) - return (NULL); - tp += advance; - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - if (tp + 1 >= ep) - return (NULL); - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} diff --git a/src/lib/libc/net/inet_pton.c b/src/lib/libc/net/inet_pton.c deleted file mode 100644 index 7e521c3286..0000000000 --- a/src/lib/libc/net/inet_pton.c +++ /dev/null @@ -1,213 +0,0 @@ -/* $OpenBSD: inet_pton.c,v 1.8 2010/05/06 15:47:14 claudio Exp $ */ - -/* Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static int inet_pton4(const char *src, u_char *dst); -static int inet_pton6(const char *src, u_char *dst); - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -int -inet_pton(int af, const char *src, void *dst) -{ - switch (af) { - case AF_INET: - return (inet_pton4(src, dst)); - case AF_INET6: - return (inet_pton6(src, dst)); - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, u_char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - u_char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - u_int new = *tp * 10 + (pch - digits); - - if (new > 255) - return (0); - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - *tp = new; - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - memcpy(dst, tmp, INADDRSZ); - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, u_char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit, count_xdigit; - u_int val; - - memset((tp = tmp), '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = count_xdigit = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - if (count_xdigit >= 4) - return (0); - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - count_xdigit++; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } else if (*src == '\0') { - return (0); - } - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - count_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - count_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; - - if (tp == endp) - return (0); - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); -} diff --git a/src/lib/libc/net/ip6opt.c b/src/lib/libc/net/ip6opt.c deleted file mode 100644 index b215f9ac3e..0000000000 --- a/src/lib/libc/net/ip6opt.c +++ /dev/null @@ -1,596 +0,0 @@ -/* $OpenBSD: ip6opt.c,v 1.4 2006/12/09 01:12:28 itojun Exp $ */ -/* $KAME: ip6opt.c,v 1.18 2005/06/15 07:11:35 keiichi Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include -#include - -static int ip6optlen(u_int8_t *opt, u_int8_t *lim); -static void inet6_insert_padopt(u_char *p, int len); - -/* - * This function returns the number of bytes required to hold an option - * when it is stored as ancillary data, including the cmsghdr structure - * at the beginning, and any padding at the end (to make its size a - * multiple of 8 bytes). The argument is the size of the structure - * defining the option, which must include any pad bytes at the - * beginning (the value y in the alignment term "xn + y"), the type - * byte, the length byte, and the option data. - */ -int -inet6_option_space(int nbytes) -{ - nbytes += 2; /* we need space for nxt-hdr and length fields */ - return (CMSG_SPACE((nbytes + 7) & ~7)); -} - -/* - * This function is called once per ancillary data object that will - * contain either Hop-by-Hop or Destination options. It returns 0 on - * success or -1 on an error. - */ -int -inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) -{ - struct cmsghdr *ch = (struct cmsghdr *)bp; - - /* argument validation */ - if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) - return (-1); - - ch->cmsg_level = IPPROTO_IPV6; - ch->cmsg_type = type; - ch->cmsg_len = CMSG_LEN(0); - - *cmsgp = ch; - return (0); -} - -/* - * This function appends a Hop-by-Hop option or a Destination option - * into an ancillary data object that has been initialized by - * inet6_option_init(). This function returns 0 if it succeeds or -1 on - * an error. - * multx is the value x in the alignment term "xn + y" described - * earlier. It must have a value of 1, 2, 4, or 8. - * plusy is the value y in the alignment term "xn + y" described - * earlier. It must have a value between 0 and 7, inclusive. - */ -int -inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, - int plusy) -{ - int padlen, optlen, off; - u_char *bp = (u_char *)cmsg + cmsg->cmsg_len; - struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); - - /* argument validation */ - if (multx != 1 && multx != 2 && multx != 4 && multx != 8) - return (-1); - if (plusy < 0 || plusy > 7) - return (-1); -#if 0 - if (typep[0] > 255) - return (-1); -#endif - - /* - * If this is the first option, allocate space for the - * first 2 bytes(for next header and length fields) of - * the option header. - */ - if (bp == (u_char *)eh) { - bp += 2; - cmsg->cmsg_len += 2; - } - - /* calculate pad length before the option. */ - off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); - padlen += plusy; - padlen %= multx; /* keep the pad as short as possible */ - /* insert padding */ - inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; - bp += padlen; - - /* copy the option */ - if (typep[0] == IP6OPT_PAD1) - optlen = 1; - else - optlen = typep[1] + 2; - memcpy(bp, typep, optlen); - bp += optlen; - cmsg->cmsg_len += optlen; - - /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)eh; - padlen = ((off + 7) & ~7) - off; - inet6_insert_padopt(bp, padlen); - bp += padlen; - cmsg->cmsg_len += padlen; - - /* update the length field of the ip6 option header */ - eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; - - return (0); -} - -/* - * This function appends a Hop-by-Hop option or a Destination option - * into an ancillary data object that has been initialized by - * inet6_option_init(). This function returns a pointer to the 8-bit - * option type field that starts the option on success, or NULL on an - * error. - * The difference between this function and inet6_option_append() is - * that the latter copies the contents of a previously built option into - * the ancillary data object while the current function returns a - * pointer to the space in the data object where the option's TLV must - * then be built by the caller. - * - */ -u_int8_t * -inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) -{ - int padlen, off; - u_int8_t *bp = (u_char *)cmsg + cmsg->cmsg_len; - u_int8_t *retval; - struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); - - /* argument validation */ - if (multx != 1 && multx != 2 && multx != 4 && multx != 8) - return (NULL); - if (plusy < 0 || plusy > 7) - return (NULL); - - /* - * If this is the first option, allocate space for the - * first 2 bytes(for next header and length fields) of - * the option header. - */ - if (bp == (u_char *)eh) { - bp += 2; - cmsg->cmsg_len += 2; - } - - /* calculate pad length before the option. */ - off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); - padlen += plusy; - padlen %= multx; /* keep the pad as short as possible */ - /* insert padding */ - inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; - bp += padlen; - - /* keep space to store specified length of data */ - retval = bp; - bp += datalen; - cmsg->cmsg_len += datalen; - - /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)eh; - padlen = ((off + 7) & ~7) - off; - inet6_insert_padopt(bp, padlen); - bp += padlen; - cmsg->cmsg_len += padlen; - - /* update the length field of the ip6 option header */ - eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; - - return (retval); -} - -/* - * This function processes the next Hop-by-Hop option or Destination - * option in an ancillary data object. If another option remains to be - * processed, the return value of the function is 0 and *tptrp points to - * the 8-bit option type field (which is followed by the 8-bit option - * data length, followed by the option data). If no more options remain - * to be processed, the return value is -1 and *tptrp is NULL. If an - * error occurs, the return value is -1 and *tptrp is not NULL. - * (RFC 2292, 6.3.5) - */ -int -inet6_option_next(const struct cmsghdr *cmsg, u_int8_t **tptrp) -{ - struct ip6_ext *ip6e; - int hdrlen, optlen; - u_int8_t *lim; - - if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) - return (-1); - - /* message length validation */ - if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) - return (-1); - ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); - hdrlen = (ip6e->ip6e_len + 1) << 3; - if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) - return (-1); - - /* - * If the caller does not specify the starting point, - * simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - lim = (u_int8_t *)ip6e + hdrlen; - if (*tptrp == NULL) - *tptrp = (u_int8_t *)(ip6e + 1); - else { - if ((optlen = ip6optlen(*tptrp, lim)) == 0) - return (-1); - - *tptrp = *tptrp + optlen; - } - if (*tptrp >= lim) { /* there is no option */ - *tptrp = NULL; - return (-1); - } - /* - * Finally, checks if the next option is safely stored in the - * cmsg data. - */ - if (ip6optlen(*tptrp, lim) == 0) - return (-1); - else - return (0); -} - -/* - * This function is similar to the inet6_option_next() function, - * except this function lets the caller specify the option type to be - * searched for, instead of always returning the next option in the - * ancillary data object. - * Note: RFC 2292 says the type of tptrp is u_int8_t *, but we think - * it's a typo. The variable should be type of u_int8_t **. - */ -int -inet6_option_find(const struct cmsghdr *cmsg, u_int8_t **tptrp, int type) -{ - struct ip6_ext *ip6e; - int hdrlen, optlen; - u_int8_t *optp, *lim; - - if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) - return (-1); - - /* message length validation */ - if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) - return (-1); - ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); - hdrlen = (ip6e->ip6e_len + 1) << 3; - if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) - return (-1); - - /* - * If the caller does not specify the starting point, - * search from the beginning of the option list. - * Otherwise, search from *the next option* of the specified point. - */ - lim = (u_int8_t *)ip6e + hdrlen; - if (*tptrp == NULL) - *tptrp = (u_int8_t *)(ip6e + 1); - else { - if ((optlen = ip6optlen(*tptrp, lim)) == 0) - return (-1); - - *tptrp = *tptrp + optlen; - } - for (optp = *tptrp; optp < lim; optp += optlen) { - if (*optp == type) { - *tptrp = optp; - return (0); - } - if ((optlen = ip6optlen(optp, lim)) == 0) - return (-1); - } - - /* search failed */ - *tptrp = NULL; - return (-1); -} - -/* - * Calculate the length of a given IPv6 option. Also checks - * if the option is safely stored in user's buffer according to the - * calculated length and the limitation of the buffer. - */ -static int -ip6optlen(u_int8_t *opt, u_int8_t *lim) -{ - int optlen; - - if (*opt == IP6OPT_PAD1) - optlen = 1; - else { - /* is there enough space to store type and len? */ - if (opt + 2 > lim) - return (0); - optlen = *(opt + 1) + 2; - } - if (opt + optlen <= lim) - return (optlen); - - return (0); -} - -static void -inet6_insert_padopt(u_char *p, int len) -{ - switch(len) { - case 0: - return; - case 1: - p[0] = IP6OPT_PAD1; - return; - default: - p[0] = IP6OPT_PADN; - p[1] = len - 2; - memset(&p[2], 0, len - 2); - return; - } -} - -/* - * The following functions are defined in RFC3542, which is a successor - * of RFC2292. - */ - -int -inet6_opt_init(void *extbuf, socklen_t extlen) -{ - struct ip6_ext *ext = (struct ip6_ext *)extbuf; - - if (extlen < 0 || (extlen % 8)) - return (-1); - - if (ext) { - if (extlen == 0) - return (-1); - ext->ip6e_len = (extlen >> 3) - 1; - } - - return (2); /* sizeof the next and the length fields */ -} - -int -inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t len, u_int8_t align, void **databufp) -{ - int currentlen = offset, padlen = 0; - - /* - * The option type must have a value from 2 to 255, inclusive. - * (0 and 1 are reserved for the Pad1 and PadN options, respectively.) - */ -#if 0 /* always false */ - if (type < 2 || type > 255) -#else - if (type < 2) -#endif - return (-1); - - /* - * The option data length must have a value between 0 and 255, - * inclusive, and is the length of the option data that follows. - */ - if (len < 0 || len > 255) - return (-1); - - /* - * The align parameter must have a value of 1, 2, 4, or 8. - * The align value can not exceed the value of len. - */ - if (align != 1 && align != 2 && align != 4 && align != 8) - return (-1); - if (align > len) - return (-1); - - /* Calculate the padding length. */ - currentlen += 2 + len; /* 2 means "type + len" */ - if (currentlen % align) - padlen = align - (currentlen % align); - - /* The option must fit in the extension header buffer. */ - currentlen += padlen; - if (extlen && /* XXX: right? */ - currentlen > extlen) - return (-1); - - if (extbuf) { - u_int8_t *optp = (u_int8_t *)extbuf + offset; - - if (padlen == 1) { - /* insert a Pad1 option */ - *optp = IP6OPT_PAD1; - optp++; - } else if (padlen > 0) { - /* insert a PadN option for alignment */ - *optp++ = IP6OPT_PADN; - *optp++ = padlen - 2; - memset(optp, 0, padlen - 2); - optp += (padlen - 2); - } - - *optp++ = type; - *optp++ = len; - - *databufp = optp; - } - - return (currentlen); -} - -int -inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) -{ - int updatelen = offset > 0 ? (1 + ((offset - 1) | 7)) : 0;; - - if (extbuf) { - u_int8_t *padp; - int padlen = updatelen - offset; - - if (updatelen > extlen) - return (-1); - - padp = (u_int8_t *)extbuf + offset; - if (padlen == 1) - *padp = IP6OPT_PAD1; - else if (padlen > 0) { - *padp++ = IP6OPT_PADN; - *padp++ = (padlen - 2); - memset(padp, 0, padlen - 2); - } - } - - return (updatelen); -} - -int -inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - memcpy((u_int8_t *)databuf + offset, val, vallen); - return (offset + vallen); -} - -int -inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the next option skipping any padding options. */ - while (optp < lim) { - switch(*optp) { - case IP6OPT_PAD1: - optp++; - break; - case IP6OPT_PADN: - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - optp += optlen; - break; - default: /* found */ - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - *typep = *optp; - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the specified option */ - while (optp < lim) { - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - - if (*optp == type) { /* found */ - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - - optp += optlen; - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_get_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - /* we can't assume alignment here */ - memcpy(val, (u_int8_t *)databuf + offset, vallen); - - return (offset + vallen); -} diff --git a/src/lib/libc/net/link_addr.3 b/src/lib/libc/net/link_addr.3 deleted file mode 100644 index e6210ef2d0..0000000000 --- a/src/lib/libc/net/link_addr.3 +++ /dev/null @@ -1,127 +0,0 @@ -.\" $OpenBSD: link_addr.3,v 1.12 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Donn Seeley at BSDI. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt LINK_ADDR 3 -.Os -.Sh NAME -.Nm link_addr , -.Nm link_ntoa -.Nd elementary address specification routines for link level access -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft void -.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The -.Fn link_addr -function interprets character strings representing -link-level addresses, returning binary information suitable -for use in system calls. -.Fn link_ntoa -takes -a link-level -address and returns an -.Tn ASCII -string representing some of the information present, -including the link level address itself, and the interface name -or number, if present. -This facility is experimental and is -still subject to change. -.Pp -For -.Fn link_addr , -the string -.Fa addr -may contain -an optional network interface identifier of the form -.Dq name unit-number , -suitable for the first argument to -.Xr ifconfig 8 , -followed in all cases by a colon and -an interface address in the form of -groups of hexadecimal digits -separated by periods. -Each group represents a byte of address; -address bytes are filled left to right from -low order bytes through high order bytes. -.Pp -.\" A regular expression may make this format clearer: -.\" .Bd -literal -offset indent -.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* -.\" .Ed -.\" .Pp -Thus -.Li le0:8.0.9.13.d.30 -represents an Ethernet address -to be transmitted on the first Lance Ethernet interface. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a NUL-terminated string. -.Fn link_addr -has no return value. -(See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn link_addr -and -.Fn link_ntoa -functions appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for -.Fn link_ntoa -reside in a static memory area. -.Pp -The function -.Fn link_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. -.Pp -If the -.Fa sdl_len -field of the link socket address -.Fa sdl -is 0, -.Fn link_ntoa -will not insert a colon before the interface address bytes. -If this translated address is given to -.Fn link_addr -without inserting an initial colon, -the latter will not interpret it correctly. diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c deleted file mode 100644 index ac96f3acdf..0000000000 --- a/src/lib/libc/net/linkaddr.c +++ /dev/null @@ -1,148 +0,0 @@ -/* $OpenBSD: linkaddr.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(const char *addr, struct sockaddr_dl *sdl) -{ - char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - -static char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(const struct sockaddr_dl *sdl) -{ - static char obuf[64]; - char *out = obuf; - int i; - u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; - - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) - *out++ = ':'; - } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else - *out++ = '.'; - i = *in++; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return (obuf); -} diff --git a/src/lib/libc/net/nsap_addr.c b/src/lib/libc/net/nsap_addr.c deleted file mode 100644 index 8cfe86f475..0000000000 --- a/src/lib/libc/net/nsap_addr.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: nsap_addr.c,v 1.7 2006/03/31 05:35:44 deraadt Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include - -static u_char -xtob(int c) -{ - return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); -} - -u_int -inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) -{ - u_char c, nib; - u_int len = 0; - - while ((c = *ascii++) != '\0' && len < maxlen) { - if (c == '.' || c == '+' || c == '/') - continue; - if (!isascii(c)) - return (0); - if (islower(c)) - c = (u_char)toupper(c); - if (isxdigit(c)) { - nib = xtob(c); - if ((c = *ascii++)) { - c = (u_char)toupper(c); - if (isxdigit(c)) { - *binary++ = (nib << 4) | xtob(c); - len++; - } else - return (0); - } - else - return (0); - } - else - return (0); - } - return (len); -} - -char * -inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) -{ - int nib; - int i; - static char tmpbuf[255*3]; - char *start; - - if (ascii) - start = ascii; - else { - ascii = tmpbuf; - start = tmpbuf; - } - - if (binlen > 255) - binlen = 255; - - for (i = 0; i < binlen; i++) { - nib = *binary >> 4; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - nib = *binary++ & 0x0f; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - if (((i % 2) == 0 && (i + 1) < binlen)) - *ascii++ = '.'; - } - *ascii = '\0'; - return (start); -} diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c deleted file mode 100644 index 36414b7a13..0000000000 --- a/src/lib/libc/net/ntohl.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: ntohl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef ntohl - -u_int32_t -ntohl(u_int32_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c deleted file mode 100644 index 8f345e84ad..0000000000 --- a/src/lib/libc/net/ntohs.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: ntohs.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef ntohs - -u_int16_t -ntohs(u_int16_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 deleted file mode 100644 index 87e9a760a8..0000000000 --- a/src/lib/libc/net/rcmd.3 +++ /dev/null @@ -1,266 +0,0 @@ -.\" $OpenBSD: rcmd.3,v 1.27 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt RCMD 3 -.Os -.Sh NAME -.Nm rcmd , -.Nm rcmd_af , -.Nm rresvport , -.Nm rresvport_af , -.Nm iruserok , -.Nm ruserok , -.Nm iruserok_sa -.Nd routines for returning a stream to a remote command -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" -.Ft int -.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" -.Ft int -.Fn rresvport "int *port" -.Ft int -.Fn rresvport_af "int *port" "int af" -.Ft int -.Fn iruserok "u_int32_t raddr" "int superuser" "const char *ruser" "const char *luser" -.Ft int -.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" -.Ft int -.Fn iruserok_sa "const void *sa" "int salen" "int superuser" "const char *ruser" "const char *luser" -.Sh DESCRIPTION -The -.Fn rcmd -function is used by the superuser to execute a command on a remote -machine using an authentication scheme based on reserved -port numbers. -If the calling process is not setuid, the -.Ev RSH -environment variable is set, and -.Fa inport -is -.Dq shell/tcp , -.Xr rcmdsh 3 -is called instead with the value of -.Ev RSH . -Alternately, if the user is not the superuser, -.Fn rcmd -will invoke -.Xr rcmdsh 3 -to run the command via -.Xr rsh 1 . -While -.Fn rcmd -can handle IPv4 cases only, -the -.Fn rcmd_af -function can handle other cases as well. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a descriptor to a socket -with an address in the privileged port space. -The -.Fn iruserok -and -.Fn ruserok -functions are used by servers -to authenticate clients requesting service with -.Fn rcmd . -All four functions are present in the same file and are used -by the -.Xr rshd 8 -server (among others). -.Fn iruserok_sa -is an address family independent variant of -.Fn iruserok . -.Pp -The -.Fn rcmd -function looks up the host -.Fa *ahost -using -.Xr gethostbyname 3 , -returning \-1 if the host does not exist. -Otherwise -.Fa *ahost -is set to the standard name of the host -and a connection is established to a server -residing at the well-known Internet port -.Fa inport . -If the user is not the superuser, the only valid port is -.Dq shell/tcp -(usually port 514). -.Pp -If the connection succeeds, -a socket in the Internet domain of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout. -If -.Fa fd2p -is non-zero, then an auxiliary channel to a control -process will be set up, and a descriptor for it will be placed -in -.Fa *fd2p . -The control process will return diagnostic -output from the command (unit 2) on this channel, and will also -accept bytes on this channel as being -.Tn UNIX -signal numbers, to be -forwarded to the process group of the command. -If -.Fa fd2p -is -.Va NULL , -then the standard error (unit 2 of the remote command) will be made -the same as the standard output and no provision is made for sending -arbitrary signals to the remote process, although you may be able to -get its attention by using out-of-band data. -Note that if the user is not the superuser, -.Fa fd2p -must be -.Va NULL . -.Pp -.Fn rcmd_af -takes address family in the last argument. -If the last argument is -.Dv PF_UNSPEC , -interpretation of -.Fa *ahost -will obey the underlying address resolution like DNS. -.Pp -The protocol is described in detail in -.Xr rshd 8 . -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions are used to obtain a socket with a privileged -address bound to it. -This socket is suitable for use by -.Fn rcmd -and several other functions. -Privileged Internet ports are those in the range 0 to -.Va IPPORT_RESERVED - 1 , -which happens to be 1023. -Only the superuser is allowed to bind an address of this sort to a socket. -.Fn rresvport -and -.Fn rresvport_af -need to be seeded with a port number; if that port -is not available these functions will find another. -.Pp -The -.Fn iruserok -and -.Fn ruserok -functions take a remote host's IP address or name, respectively, -two user names and a flag indicating whether the local user's -name is that of the superuser. -Then, if the user is -.Em not -the superuser, it checks the -.Pa /etc/hosts.equiv -file. -If that lookup is not done, or is unsuccessful, the -.Pa .rhosts -in the local user's home directory is checked to see if the request for -service is allowed. -.Pp -If this file does not exist, is not a regular file, is owned by anyone -other than the user or the superuser, or is writeable by anyone other -than the owner, the check automatically fails. -Zero is returned if the machine name is listed in the -.Pa hosts.equiv -file, or the host and remote user name are found in the -.Pa .rhosts -file; otherwise -.Fn iruserok -and -.Fn ruserok -return \-1. -If the local domain (as obtained from -.Xr gethostname 3 ) -is the same as the remote domain, only the machine name need be specified. -.Pp -If the IP address of the remote host is known, -.Fn iruserok -should be used in preference to -.Fn ruserok , -as it does not require trusting the DNS server for the remote host's domain. -.Pp -While -.Fn iruserok -can handle IPv4 addresses only, -.Fn iruserok_sa -and -.Fn ruserok -can handle other address families as well, like IPv6. -The first argument of -.Fn iruserok_sa -is typed as -.Li "void *" -to avoid dependency between -.Aq Pa unistd.h -and -.Aq Pa sys/socket.h . -.Sh DIAGNOSTICS -The -.Fn rcmd -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a valid, bound socket descriptor on success. -It returns \-1 on error with the global value -.Va errno -set according to the reason for failure. -The error code -.Er EAGAIN -is overloaded to mean -.Dq all network ports in use . -.Sh SEE ALSO -.Xr rsh 1 , -.Xr intro 2 , -.Xr bindresvport 3 , -.Xr bindresvport_sa 3 , -.Xr rcmdsh 3 , -.Xr rshd 8 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c deleted file mode 100644 index d566e0ca4c..0000000000 --- a/src/lib/libc/net/rcmd.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. - * Copyright (c) 1983, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int -rcmd(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, int *fd2p) -{ - return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); -} - -int -rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, - const char *cmd, int *fd2p, int af) -{ - static char hbuf[MAXHOSTNAMELEN]; - char pbuf[NI_MAXSERV]; - struct addrinfo hints, *res, *r; - int error; - struct sockaddr_storage from; - fd_set *readsp = NULL; - sigset_t oldmask, mask; - pid_t pid; - int s, lport, timo; - char c, *p; - int refused; - in_port_t rport = porta; - - /* call rcmdsh() with specified remote shell if appropriate. */ - if (!issetugid() && (p = getenv("RSH")) && *p) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, p)); - } - - /* use rsh(1) if non-root and remote port is shell. */ - if (geteuid()) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, NULL)); - } - - pid = getpid(); - snprintf(pbuf, sizeof(pbuf), "%u", ntohs(rport)); - memset(&hints, 0, sizeof(hints)); - hints.ai_family = af; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - error = getaddrinfo(*ahost, pbuf, &hints, &res); - if (error) { -#if 0 - warnx("%s: %s", *ahost, gai_strerror(error)); -#endif - return (-1); - } - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } else - ; /*XXX*/ - - r = res; - refused = 0; - sigemptyset(&mask); - sigaddset(&mask, SIGURG); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - for (timo = 1, lport = IPPORT_RESERVED - 1;;) { - s = rresvport_af(&lport, r->ai_family); - if (s < 0) { - if (errno == EAGAIN) - (void)fprintf(stderr, - "rcmd: socket: All ports in use\n"); - else - (void)fprintf(stderr, "rcmd: socket: %s\n", - strerror(errno)); - if (r->ai_next) { - r = r->ai_next; - continue; - } else { - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - } - fcntl(s, F_SETOWN, pid); - if (connect(s, r->ai_addr, r->ai_addrlen) >= 0) - break; - (void)close(s); - if (errno == EADDRINUSE) { - lport--; - continue; - } - if (errno == ECONNREFUSED) - refused++; - if (r->ai_next) { - int oerrno = errno; - char hbuf[NI_MAXHOST]; - const int niflags = NI_NUMERICHOST; - - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "connect to address %s: ", hbuf); - errno = oerrno; - perror(0); - r = r->ai_next; - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "Trying %s...\n", hbuf); - continue; - } - if (refused && timo <= 16) { - (void)sleep(timo); - timo *= 2; - r = res; - refused = 0; - continue; - } - (void)fprintf(stderr, "%s: %s\n", res->ai_canonname, - strerror(errno)); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - /* given "af" can be PF_UNSPEC, we need the real af for "s" */ - af = r->ai_family; - freeaddrinfo(res); -#if 0 - /* - * try to rresvport() to the same port. This will make rresvport() - * fail it's first bind, resulting in it choosing a random port. - */ - lport--; -#endif - if (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - char num[8]; - int s2 = rresvport_af(&lport, af), s3; - socklen_t len = sizeof(from); - int fdssize = howmany(MAX(s, s2)+1, NFDBITS) * sizeof(fd_mask); - - if (s2 < 0) - goto bad; - readsp = (fd_set *)malloc(fdssize); - if (readsp == NULL) { - close(s2); - goto bad; - } - listen(s2, 1); - (void)snprintf(num, sizeof(num), "%d", lport); - if (write(s, num, strlen(num)+1) != strlen(num)+1) { - (void)fprintf(stderr, - "rcmd: write (setting up stderr): %s\n", - strerror(errno)); - (void)close(s2); - goto bad; - } -again: - bzero(readsp, fdssize); - FD_SET(s, readsp); - FD_SET(s2, readsp); - errno = 0; - if (select(MAX(s, s2) + 1, readsp, 0, 0, 0) < 1 || - !FD_ISSET(s2, readsp)) { - if (errno != 0) - (void)fprintf(stderr, - "rcmd: select (setting up stderr): %s\n", - strerror(errno)); - else - (void)fprintf(stderr, - "select: protocol failure in circuit setup\n"); - (void)close(s2); - goto bad; - } - s3 = accept(s2, (struct sockaddr *)&from, &len); - if (s3 < 0) { - (void)fprintf(stderr, - "rcmd: accept: %s\n", strerror(errno)); - lport = 0; - close(s2); - goto bad; - } - - /* - * XXX careful for ftp bounce attacks. If discovered, shut them - * down and check for the real auxiliary channel to connect. - */ - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) == 0 && - atoi(num) != 20) { - break; - } - close(s3); - goto again; - default: - break; - } - (void)close(s2); - - *fd2p = s3; - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 || - (atoi(num) >= IPPORT_RESERVED || - atoi(num) < IPPORT_RESERVED / 2)) { - (void)fprintf(stderr, - "socket: protocol failure in circuit setup.\n"); - goto bad2; - } - break; - default: - break; - } - } - (void)write(s, locuser, strlen(locuser)+1); - (void)write(s, remuser, strlen(remuser)+1); - (void)write(s, cmd, strlen(cmd)+1); - if (read(s, &c, 1) != 1) { - (void)fprintf(stderr, - "rcmd: %s: %s\n", *ahost, strerror(errno)); - goto bad2; - } - if (c != 0) { - while (read(s, &c, 1) == 1) { - (void)write(STDERR_FILENO, &c, 1); - if (c == '\n') - break; - } - goto bad2; - } - sigprocmask(SIG_SETMASK, &oldmask, NULL); - free(readsp); - return (s); -bad2: - if (lport) - (void)close(*fd2p); -bad: - if (readsp) - free(readsp); - (void)close(s); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - return (-1); -} - diff --git a/src/lib/libc/net/rcmdsh.3 b/src/lib/libc/net/rcmdsh.3 deleted file mode 100644 index f7de0808f5..0000000000 --- a/src/lib/libc/net/rcmdsh.3 +++ /dev/null @@ -1,96 +0,0 @@ -.\" $OpenBSD: rcmdsh.3,v 1.13 2009/12/29 10:25:43 sobrado Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: December 29 2009 $ -.Dt RCMDSH 3 -.Os -.Sh NAME -.Nm rcmdsh -.Nd return a stream to a remote command without superuser -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn rcmdsh "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "char *rshprog" -.Sh DESCRIPTION -The -.Fn rcmdsh -function is used by normal users to execute a command on a remote machine -using an authentication scheme based on reserved port numbers using -.Xr rsh 1 -or the value of -.Fa rshprog -(if non-null). -.Fa rshprog -may be a fully-qualified path, a non-qualified command, or a command containing -space-separated command line arguments. -.Pp -The -.Fn rcmdsh -function looks up the host -.Fa *ahost -using -.Xr gethostbyname 3 , -returning \-1 if the host does not exist. -Otherwise -.Fa *ahost -is set to the standard name of the host and a connection is established to -a server residing at the well-known Internet port -.Li shell/tcp -(or whatever port is used by -.Fa rshprog ) . -The parameter -.Fa inport -is ignored; it is only included to provide an interface similar to -.Xr rcmd 3 . -.Pp -If the connection succeeds, a socket in the -.Ux Ns -domain -of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout, and stderr. -.Sh DIAGNOSTICS -The -.Fn rcmdsh -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Sh SEE ALSO -.Xr rsh 1 , -.Xr socketpair 2 , -.Xr rcmd 3 , -.Xr rshd 8 -.Sh HISTORY -The -.Fn rcmdsh -function first appeared in -.Ox 2.0 . -.Sh BUGS -If -.Xr rsh 1 -encounters an error, a file descriptor is still returned instead of \-1. diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c deleted file mode 100644 index a472162711..0000000000 --- a/src/lib/libc/net/rcmdsh.c +++ /dev/null @@ -1,186 +0,0 @@ -/* $OpenBSD: rcmdsh.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ - -/* - * Copyright (c) 2001, MagniComp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the MagniComp nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is an rcmd() replacement originally by - * Chris Siebenmann . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * This is a replacement rcmd() function that uses the rsh(1) - * program in place of a direct rcmd(3) function call so as to - * avoid having to be root. Note that rport is ignored. - */ -/* ARGSUSED */ -int -rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, char *rshprog) -{ - struct hostent *hp; - int sp[2]; - pid_t cpid; - char *p; - struct passwd *pw; - - /* What rsh/shell to use. */ - if (rshprog == NULL) - rshprog = _PATH_RSH; - - /* locuser must exist on this host. */ - if ((pw = getpwnam(locuser)) == NULL) { - (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); - return(-1); - } - - /* Validate remote hostname. */ - if (strcmp(*ahost, "localhost") != 0) { - if (((hp = gethostbyname2(*ahost, AF_INET)) == NULL) && - ((hp = gethostbyname2(*ahost, AF_INET6)) == NULL)) { - herror(*ahost); - return(-1); - } - *ahost = hp->h_name; - } - - /* Get a socketpair we'll use for stdin and stdout. */ - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0) { - perror("rcmdsh: socketpair"); - return(-1); - } - - cpid = fork(); - if (cpid < 0) { - perror("rcmdsh: fork failed"); - return(-1); - } else if (cpid == 0) { - /* - * Child. We use sp[1] to be stdin/stdout, and close sp[0]. - */ - (void) close(sp[0]); - if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { - perror("rcmdsh: dup2 failed"); - _exit(255); - } - /* Fork again to lose parent. */ - cpid = fork(); - if (cpid < 0) { - perror("rcmdsh: fork to lose parent failed"); - _exit(255); - } - if (cpid > 0) - _exit(0); - - /* In grandchild here. Become local user for rshprog. */ - if (setuid(pw->pw_uid)) { - (void) fprintf(stderr, "rcmdsh: setuid(%u): %s\n", - pw->pw_uid, strerror(errno)); - _exit(255); - } - - /* - * If remote host is "localhost" and local and remote user - * are the same, avoid running remote shell for efficiency. - */ - if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) { - char *argv[4]; - if (pw->pw_shell[0] == '\0') - rshprog = _PATH_BSHELL; - else - rshprog = pw->pw_shell; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-c"; - argv[2] = (char *)cmd; - argv[3] = NULL; - execvp(rshprog, argv); - } else if ((p = strchr(rshprog, ' ')) == NULL) { - /* simple case */ - char *argv[6]; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-l"; - argv[2] = (char *)remuser; - argv[3] = *ahost; - argv[4] = (char *)cmd; - argv[5] = NULL; - execvp(rshprog, argv); - } else { - /* must pull args out of rshprog and dyn alloc argv */ - char **argv, **ap; - int n; - for (n = 7; (p = strchr(++p, ' ')) != NULL; n++) - continue; - rshprog = strdup(rshprog); - ap = argv = calloc(sizeof(char *), n); - if (rshprog == NULL || argv == NULL) { - perror("rcmdsh"); - _exit(255); - } - while ((p = strsep(&rshprog, " ")) != NULL) { - if (*p == '\0') - continue; - *ap++ = p; - } - if (ap != argv) /* all spaces?!? */ - rshprog = argv[0]; - if ((p = strrchr(argv[0], '/')) != NULL) - argv[0] = p + 1; - *ap++ = "-l"; - *ap++ = (char *)remuser; - *ap++ = *ahost; - *ap++ = (char *)cmd; - *ap++ = NULL; - execvp(rshprog, argv); - } - (void) fprintf(stderr, "rcmdsh: execvp %s failed: %s\n", - rshprog, strerror(errno)); - _exit(255); - } else { - /* Parent. close sp[1], return sp[0]. */ - (void) close(sp[1]); - /* Reap child. */ - (void) wait(NULL); - return(sp[0]); - } - /* NOTREACHED */ -} diff --git a/src/lib/libc/net/recv.c b/src/lib/libc/net/recv.c deleted file mode 100644 index 6241cc6b12..0000000000 --- a/src/lib/libc/net/recv.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: recv.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include - -ssize_t -recv(int s, void *buf, size_t len, int flags) -{ - return (recvfrom(s, buf, len, flags, NULL, 0)); -} diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c deleted file mode 100644 index 69a6ce0abb..0000000000 --- a/src/lib/libc/net/res_comp.c +++ /dev/null @@ -1,475 +0,0 @@ -/* $OpenBSD: res_comp.c,v 1.14 2008/04/16 22:35:23 deraadt Exp $ */ - -/* - * ++Copyright++ 1985, 1993 - * - - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -static int dn_find(u_char *, u_char *, u_char **, u_char **); - -/* - * Expand compressed domain name 'comp_dn' to full domain name. - * 'msg' is a pointer to the begining of the message, - * 'eomorig' points to the first location after the message, - * 'exp_dn' is a pointer to a buffer of size 'length' for the result. - * Return size of compressed name or -1 if there was an error. - */ -int -dn_expand(const u_char *msg, const u_char *eomorig, const u_char *comp_dn, - char *exp_dn, int length) -{ - const u_char *cp; - char *dn; - int n, c; - char *eom; - int len = -1, checked = 0; - - dn = exp_dn; - cp = comp_dn; - if (length > MAXHOSTNAMELEN-1) - length = MAXHOSTNAMELEN-1; - eom = exp_dn + length; - /* - * fetch next label in domain name - */ - while ((n = *cp++)) { - /* - * Check for indirection - */ - switch (n & INDIR_MASK) { - case 0: - if (dn != exp_dn) { - if (dn >= eom) - return (-1); - *dn++ = '.'; - } - if (dn+n >= eom) - return (-1); - checked += n + 1; - while (--n >= 0) { - if (((c = *cp++) == '.') || (c == '\\')) { - if (dn + n + 2 >= eom) - return (-1); - *dn++ = '\\'; - } - *dn++ = c; - if (cp >= eomorig) /* out of range */ - return (-1); - } - break; - - case INDIR_MASK: - if (len < 0) - len = cp - comp_dn + 1; - cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); - if (cp < msg || cp >= eomorig) /* out of range */ - return (-1); - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eomorig - msg) - return (-1); - break; - - default: - return (-1); /* flag error */ - } - } - *dn = '\0'; - if (len < 0) - len = cp - comp_dn; - return (len); -} - -/* - * Compress domain name 'exp_dn' into 'comp_dn'. - * Return the size of the compressed name or -1. - * 'length' is the size of the array pointed to by 'comp_dn'. - * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0] - * is a pointer to the beginning of the message. The list ends with NULL. - * 'lastdnptr' is a pointer to the end of the arrary pointed to - * by 'dnptrs'. Side effect is to update the list of pointers for - * labels inserted into the message as we compress the name. - * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' - * is NULL, we don't update the list. - */ -int -dn_comp(const char *exp_dn, u_char *comp_dn, int length, u_char **dnptrs, - u_char **lastdnptr) -{ - u_char *cp, *dn; - int c, l; - u_char **cpp, **lpp, *sp, *eob; - u_char *msg; - - dn = (u_char *)exp_dn; - cp = comp_dn; - eob = cp + length; - lpp = cpp = NULL; - if (dnptrs != NULL) { - if ((msg = *dnptrs++) != NULL) { - for (cpp = dnptrs; *cpp != NULL; cpp++) - ; - lpp = cpp; /* end of list to search */ - } - } else - msg = NULL; - for (c = *dn++; c != '\0'; ) { - /* look to see if we can use pointers */ - if (msg != NULL) { - if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) { - if (cp+1 >= eob) - return (-1); - *cp++ = (l >> 8) | INDIR_MASK; - *cp++ = l % 256; - return (cp - comp_dn); - } - /* not found, save it */ - if (lastdnptr != NULL && cpp < lastdnptr-1) { - *cpp++ = cp; - *cpp = NULL; - } - } - sp = cp++; /* save ptr to length byte */ - do { - if (c == '.') { - c = *dn++; - break; - } - if (c == '\\') { - if ((c = *dn++) == '\0') - break; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = c; - } while ((c = *dn++) != '\0'); - /* catch trailing '.'s but not '..' */ - if ((l = cp - sp - 1) == 0 && c == '\0') { - cp--; - break; - } - if (l <= 0 || l > MAXLABEL) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *sp = l; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = '\0'; - return (cp - comp_dn); -} - -/* - * Skip over a compressed domain name. Return the size or -1. - */ -int -__dn_skipname(const u_char *comp_dn, const u_char *eom) -{ - const u_char *cp; - int n; - - cp = comp_dn; - while (cp < eom && (n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - cp += n; - continue; - case INDIR_MASK: /* indirection */ - cp++; - break; - default: /* illegal type */ - return (-1); - } - break; - } - if (cp > eom) - return (-1); - return (cp - comp_dn); -} - -static int -mklower(int ch) -{ - if (isascii(ch) && isupper(ch)) - return (tolower(ch)); - return (ch); -} - -/* - * Search for expanded name from a list of previously compressed names. - * Return the offset from msg if found or -1. - * dnptrs is the pointer to the first name on the list, - * not the pointer to the start of the message. - */ -static int -dn_find(u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr) -{ - u_char *dn, *cp, **cpp; - int n; - u_char *sp; - - for (cpp = dnptrs; cpp < lastdnptr; cpp++) { - dn = exp_dn; - sp = cp = *cpp; - while ((n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - while (--n >= 0) { - if (*dn == '.') - goto next; - if (*dn == '\\') - dn++; - if (mklower(*dn++) != mklower(*cp++)) - goto next; - } - if ((n = *dn++) == '\0' && *cp == '\0') - return (sp - msg); - if (n == '.') - continue; - goto next; - - case INDIR_MASK: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - - default: /* illegal type */ - return (-1); - } - } - if (*dn == '\0') - return (sp - msg); - next: ; - } - return (-1); -} - -/* - * Verify that a domain name uses an acceptable character set. - */ - -/* - * Note the conspicuous absence of ctype macros in these definitions. On - * non-ASCII hosts, we can't depend on string literals or ctype macros to - * tell us anything about network-format data. The rest of the BIND system - * is not careful about this, but for some reason, we're doing it right here. - */ -#define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) -#define bslashchar(c) ((c) == 0x5c) -#define underscorechar(c) ((c) == 0x5f) -#define periodchar(c) ((c) == PERIOD) -#define asterchar(c) ((c) == 0x2a) -#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ - || ((c) >= 0x61 && (c) <= 0x7a)) -#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) - -#define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -int -res_hnok(const char *dn) -{ - int pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - ; - } else if (periodchar(pch)) { - if (!borderchar(ch)) - return (0); - } else if (periodchar(nch) || nch == '\0') { - if (!borderchar(ch)) - return (0); - } else { - if (!middlechar(ch)) - return (0); - } - pch = ch, ch = nch; - } - return (1); -} - -/* - * hostname-like (A, MX, WKS) owners can have "*" as their first label - * but must otherwise be as a host name. - */ -int -res_ownok(const char *dn) -{ - if (asterchar(dn[0])) { - if (periodchar(dn[1])) - return (res_hnok(dn+2)); - if (dn[1] == '\0') - return (1); - } - return (res_hnok(dn)); -} - -/* - * SOA RNAMEs and RP RNAMEs can have any printable character in their first - * label, but the rest of the name has to look like a host name. - */ -int -res_mailok(const char *dn) -{ - int ch, escaped = 0; - - /* "." is a valid missing representation */ - if (*dn == '\0') - return(1); - - /* otherwise