Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2008-05-23 01:30:28 +0400
committerJeff Johnston <jjohnstn@redhat.com>2008-05-23 01:30:28 +0400
commit3c77dcff9ebf51910b01ca770f7a8ffef52b617c (patch)
tree8424a3ed0b00dfcb1d31428f57817fadf658ba80 /newlib
parent8a179967e670032fb2decf0ebcdd0059f9d139d8 (diff)
2008-05-22 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/reent.h: Add _h_errno field. * libc/sys/linux/libc-symbols.h: Add default stubs for new libc macros now used in net directory. * libc/sys/linux/bits/libc-lock.h: Always define _IO_MTSAFE_IO. * libc/sys/linux/include/hesiod.h: Add needed macros for new code in net directory. * libc/sys/linux/include/netdb.h: Ditto. * libc/sys/linux/include/resolv.h: Ditto. * libc/sys/linux/include/stdint.h: Ditto. * libc/sys/linux/include/arpa/nameser.h: Ditto. * libc/sys/linux/include/net/ethernet.h: Ditto. * libc/sys/linux/include/net/if_ppp.h: Ditto. * libc/sys/linux/include/netinet/if_ether.h: Ditto. * libc/sys/linux/machine/i386/get_clockfreq.c: Remove static memmem. * libc/sys/linux/machine/i386/include/endian.h: Protect macros with flags to avoid duplicate definition. * libc/sys/linux/machine/i386/include/param.h: Ditto. * libc/sys/linux/net/Makefile.am: Modified to account for removed and added files. * libc/sys/linux/net/Makefile.in: Regenerated. * libc/sys/linux/net/base64.c: Replaced with glibc version of code. * libc/sys/linux/net/getaddrinfo.c: Ditto. * libc/sys/linux/net/getnameinfo.c: Ditto. * libc/sys/linux/net/getproto.c: Ditto. * libc/sys/linux/net/getservent.c: Ditto. * libc/sys/linux/net/inet_netof.c: Ditto. * libc/sys/linux/net/inet_lnaof.c: Ditto. * libc/sys/linux/net/ns_name.c: Ditto. * libc/sys/linux/net/ns_netint.c: Ditto. * libc/sys/linux/net/inet_ntoa.c: Ditto. * libc/sys/linux/net/ns_parse.c: Ditto. * libc/sys/linux/net/ns_print.c: Ditto. * libc/sys/linux/net/ns_ttl.c: Ditto. * libc/sys/linux/net/nsap_addr.c: Ditto. * libc/sys/linux/net/rcmd.c: Ditto. * libc/sys/linux/net/res_comp.c: Ditto. * libc/sys/linux/net/res_data.c: Ditto. * libc/sys/linux/net/res_debug.c: Ditto. * libc/sys/linux/net/res_init.c: Ditto. * libc/sys/linux/net/res_mkquery.c: Ditto. * libc/sys/linux/net/res_query.c: Ditto. * libc/sys/linux/net/res_send.c: Ditto. * libc/sys/linux/net/send.c: Ditto. * libc/sys/linux/stdlib/collate.c: Ditto. * libc/sys/linux/sys/ioctl.h: Ditto. * libc/sys/linux/sys/socket.h: Ditto. * libc/sys/linux/sys/unistd.h: Ditto. * libc/sys/linux/iconv/iconvconfig.c: Removed either because no longer used or because licensing includes advertising clause that cannot be ignored. * libc/sys/linux/iconv/strtab.c: Ditto. * libc/sys/linux/include/libc_private.h: Ditto. * libc/sys/linux/include/nsswitch.h: Ditto. * libc/sys/linux/include/net/if_atm.h: Ditto. * libc/sys/linux/include/net/if_media.h: Ditto. * libc/sys/linux/include/net/if_pppvar.h: Ditto. * libc/sys/linux/include/netinet/if_atm.h: Ditto. * libc/sys/linux/include/netinet/ip_flow.h: Ditto. * libc/sys/linux/intl/locale.alias: Ditto. * libc/sys/linux/net/addr2ascii.3: Ditto. * libc/sys/linux/net/bindresvport.c: Ditto. * libc/sys/linux/net/byteorder.3: Ditto. * libc/sys/linux/net/res_config.h: Ditto. * libc/sys/linux/net/ether_addr.c: Ditto. * libc/sys/linux/net/ethers.3: Ditto. * libc/sys/linux/net/getaddrinfo.3: Ditto. * libc/sys/linux/net/gethostbydns.c: Ditto. * libc/sys/linux/net/gethostbyht.c: Ditto. * libc/sys/linux/net/gethostbyname.3: Ditto. * libc/sys/linux/net/gethostbynis.c: Ditto. * libc/sys/linux/net/gethostnamadr.c: Ditto. * libc/sys/linux/net/getifaddrs.3: Ditto. * libc/sys/linux/net/getifaddrs.c: Ditto. * libc/sys/linux/net/getipnodebyname.3: Ditto. * libc/sys/linux/net/getnameinfo.3: Ditto. * libc/sys/linux/net/getnetbydns.c: Ditto. * libc/sys/linux/net/getnetbyht.c: Ditto. * libc/sys/linux/net/getnetbynis.c: Ditto. * libc/sys/linux/net/getnetent.3: Ditto. * libc/sys/linux/net/getnetnamadr.c: Ditto. * libc/sys/linux/net/getprotoent.3: Ditto. * libc/sys/linux/net/getprotoent.c: Ditto. * libc/sys/linux/net/getprotoname.c: Ditto. * libc/sys/linux/net/getservbyname.c: Ditto. * libc/sys/linux/net/getservbyport.c: Ditto. * libc/sys/linux/net/getservent.3: Ditto. * libc/sys/linux/net/herror.c: Ditto. * libc/sys/linux/net/hesiod.3: Ditto. * libc/sys/linux/net/hesiod.c: Ditto. * libc/sys/linux/net/if_indextoname.3: Ditto. * libc/sys/linux/net/inet.3: Ditto. * libc/sys/linux/net/inet6_option_space.3: Ditto. * libc/sys/linux/net/inet6_rthdr_space.3: Ditto. * libc/sys/linux/net/inet_makeaddr.c: Ditto. * libc/sys/linux/net/inet_net.3: Ditto. * libc/sys/linux/net/inet_network.c: Ditto. * libc/sys/linux/net/innetgr-stub.c: Ditto. * libc/sys/linux/net/ip6opt.c: Ditto. * libc/sys/linux/net/iso_addr.3: Ditto. * libc/sys/linux/net/iso_addr.c: Ditto. * libc/sys/linux/net/linkaddr.3: Ditto. * libc/sys/linux/net/linkaddr.c: Ditto. * libc/sys/linux/net/map_v4v6.c: Ditto. * libc/sys/linux/net/name6.c: Ditto. * libc/sys/linux/net/namespace.h: Ditto. * libc/sys/linux/net/ns.3: Ditto. * libc/sys/linux/net/ns_addr.c: Ditto. * libc/sys/linux/net/ns_ntoa.c: Ditto. * libc/sys/linux/net/nsdispatch.3: Ditto. * libc/sys/linux/net/nsdispatch.c: Ditto. * libc/sys/linux/net/nslexer.c: Ditto. * libc/sys/linux/net/nslexer.l: Ditto. * libc/sys/linux/net/nsparser.c: Ditto. * libc/sys/linux/net/nsparser.h: Ditto. * libc/sys/linux/net/nsparser.y: Ditto. * libc/sys/linux/net/rcmd.3: Ditto. * libc/sys/linux/net/rcmdsh.3: Ditto. * libc/sys/linux/net/res_mkupdate.c: Ditto. * libc/sys/linux/net/res_update.c: Ditto. * libc/sys/linux/net/resolver.3: Ditto. * libc/sys/linux/net/rthdr.c: Ditto. * libc/sys/linux/net/vars.c: Ditto. * libc/sys/linux/shlib-compat.h: New file. * libc/sys/linux/machine/i386/atomic.h: Ditto. * libc/sys/linux/net/XXX-lookup.c: Ditto. * libc/sys/linux/net/alias-lookup.c: Ditto. * libc/sys/linux/net/res_libc.c: Ditto. * libc/sys/linux/net/aliases.h: Ditto. * libc/sys/linux/net/check_pf.c: Ditto. * libc/sys/linux/net/databases.def: Ditto. * libc/sys/linux/net/digits_dots.c: Ditto. * libc/sys/linux/net/ether_aton.c: Ditto. * libc/sys/linux/net/ether_aton_r.c: Ditto. * libc/sys/linux/net/ether_hton.c: Ditto. * libc/sys/linux/net/ether_line.c: Ditto. * libc/sys/linux/net/ether_ntoa.c: Ditto. * libc/sys/linux/net/ether_ntoa_r.c: Ditto. * libc/sys/linux/net/ether_ntoh.c: Ditto. * libc/sys/linux/net/etherent.h: Ditto. * libc/sys/linux/net/ethers-lookup.c: Ditto. * libc/sys/linux/net/function.def: Ditto. * libc/sys/linux/net/getXXbyYY.c: Ditto. * libc/sys/linux/net/getXXbyYY_r.c: Ditto. * libc/sys/linux/net/getXXent.c: Ditto. * libc/sys/linux/net/getXXent_r.c: Ditto. * libc/sys/linux/net/getaliasent.c: Ditto. * libc/sys/linux/net/getaliasent_r.c: Ditto. * libc/sys/linux/net/getaliasname.c: Ditto. * libc/sys/linux/net/getaliasname_r.c: Ditto. * libc/sys/linux/net/gethstbyad.c: Ditto. * libc/sys/linux/net/gethstbyad_r.c: Ditto. * libc/sys/linux/net/gethstbynm.c: Ditto. * libc/sys/linux/net/gethstbynm2.c: Ditto. * libc/sys/linux/net/gethstbynm2_r.c: Ditto. * libc/sys/linux/net/gethstbynm_r.c: Ditto. * libc/sys/linux/net/gethstent.c: Ditto. * libc/sys/linux/net/gethstent_r.c: Ditto. * libc/sys/linux/net/getnetbyad.c: Ditto. * libc/sys/linux/net/getnetbyad_r.c: Ditto. * libc/sys/linux/net/getnetbynm.c: Ditto. * libc/sys/linux/net/getnetbynm_r.c: Ditto. * libc/sys/linux/net/getnetent.c: Ditto. * libc/sys/linux/net/getnetent_r.c: Ditto. * libc/sys/linux/net/getnetgrent.c: Ditto. * libc/sys/linux/net/getnetgrent_r.c: Ditto. * libc/sys/linux/net/getnssent.c: Ditto. * libc/sys/linux/net/getnssent_r.c: Ditto. * libc/sys/linux/net/getproto_r.c: Ditto. * libc/sys/linux/net/getprtent.c: Ditto. * libc/sys/linux/net/getprtent_r.c: Ditto. * libc/sys/linux/net/getprtname.c: Ditto. * libc/sys/linux/net/getprtname_r.c: Ditto. * libc/sys/linux/net/getrpcbyname.c: Ditto. * libc/sys/linux/net/getrpcbyname_r.c: Ditto. * libc/sys/linux/net/getrpcbynumber.c: Ditto. * libc/sys/linux/net/getrpcbynumber_r.c: Ditto. * libc/sys/linux/net/getrpcent.c: Ditto. * libc/sys/linux/net/getrpcent_r.c: Ditto. * libc/sys/linux/net/getservent_r.c: Ditto. * libc/sys/linux/net/getsrvbynm.c: Ditto. * libc/sys/linux/net/getsrvbynm_r.c: Ditto. * libc/sys/linux/net/getsrvbypt.c: Ditto. * libc/sys/linux/net/getsrvbypt_r.c: Ditto. * libc/sys/linux/net/grp-lookup.c: Ditto. * libc/sys/linux/net/herrno.c: Ditto. * libc/sys/linux/net/hosts-lookup.c: Ditto. * libc/sys/linux/net/ifaddrs.h: Ditto. * libc/sys/linux/net/ifreq.c: Ditto. * libc/sys/linux/net/ifreq.h: Ditto. * libc/sys/linux/net/in6_addr.c: Ditto. * libc/sys/linux/net/inet6_option.c: Ditto. * libc/sys/linux/net/inet_mkadr.c: Ditto. * libc/sys/linux/net/inet_net.c: Ditto. * libc/sys/linux/net/key-lookup.c: Ditto. * libc/sys/linux/net/local.h: Ditto. * libc/sys/linux/net/netgroup.h: Ditto. * libc/sys/linux/net/netgrp-lookup.c: Ditto. * libc/sys/linux/net/network-lookup.c: Ditto. * libc/sys/linux/net/not-cancel.h: Ditto. * libc/sys/linux/net/ns_samedomain.c: Ditto. * libc/sys/linux/net/nscd-types.h: Ditto. * libc/sys/linux/net/nss.h: Ditto. * libc/sys/linux/net/nsswitch.c: Ditto. * libc/sys/linux/net/nsswitch.h: Ditto. * libc/sys/linux/net/opensock.c: Ditto. * libc/sys/linux/net/proto-lookup.c: Ditto. * libc/sys/linux/net/pwd-lookup.c: Ditto. * libc/sys/linux/net/res_debug.h: Ditto. * libc/sys/linux/net/res_hconf.c: Ditto. * libc/sys/linux/net/res_hconf.h: Ditto. * libc/sys/linux/net/rexec.c: Ditto. * libc/sys/linux/net/rpc-lookup.c: Ditto. * libc/sys/linux/net/ruserpass.c: Ditto. * libc/sys/linux/net/service-lookup.c: Ditto. * libc/sys/linux/net/spwd-lookup.c: Ditto. * libc/sys/linux/net/nscd/nscd-client.h: Ditto. * libc/sys/linux/net/nscd/nscd_proto.h: Ditto.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog220
-rw-r--r--newlib/libc/include/sys/reent.h1
-rw-r--r--newlib/libc/sys/linux/bits/libc-lock.h2
-rw-r--r--newlib/libc/sys/linux/iconv/iconvconfig.c1176
-rw-r--r--newlib/libc/sys/linux/iconv/strtab.c341
-rw-r--r--newlib/libc/sys/linux/include/arpa/nameser.h174
-rw-r--r--newlib/libc/sys/linux/include/hesiod.h102
-rw-r--r--newlib/libc/sys/linux/include/libc_private.h72
-rw-r--r--newlib/libc/sys/linux/include/net/ethernet.h166
-rw-r--r--newlib/libc/sys/linux/include/net/if_atm.h107
-rw-r--r--newlib/libc/sys/linux/include/net/if_media.h409
-rw-r--r--newlib/libc/sys/linux/include/net/if_ppp.h148
-rw-r--r--newlib/libc/sys/linux/include/net/if_pppvar.h109
-rw-r--r--newlib/libc/sys/linux/include/netdb.h50
-rw-r--r--newlib/libc/sys/linux/include/netinet/if_atm.h47
-rw-r--r--newlib/libc/sys/linux/include/netinet/if_ether.h3
-rw-r--r--newlib/libc/sys/linux/include/netinet/ip_flow.h57
-rw-r--r--newlib/libc/sys/linux/include/nsswitch.h184
-rw-r--r--newlib/libc/sys/linux/include/resolv.h115
-rw-r--r--newlib/libc/sys/linux/include/stdint.h29
-rw-r--r--newlib/libc/sys/linux/intl/locale.alias75
-rw-r--r--newlib/libc/sys/linux/libc-symbols.h27
-rw-r--r--newlib/libc/sys/linux/machine/i386/atomic.h366
-rw-r--r--newlib/libc/sys/linux/machine/i386/get_clockfreq.c27
-rw-r--r--newlib/libc/sys/linux/machine/i386/include/endian.h11
-rw-r--r--newlib/libc/sys/linux/machine/i386/include/param.h2
-rw-r--r--newlib/libc/sys/linux/net/Makefile.am48
-rw-r--r--newlib/libc/sys/linux/net/Makefile.in1061
-rw-r--r--newlib/libc/sys/linux/net/XXX-lookup.c75
-rw-r--r--newlib/libc/sys/linux/net/addr2ascii.3222
-rw-r--r--newlib/libc/sys/linux/net/alias-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/aliases.h64
-rw-r--r--newlib/libc/sys/linux/net/base64.c24
-rw-r--r--newlib/libc/sys/linux/net/bindresvport.c160
-rw-r--r--newlib/libc/sys/linux/net/byteorder.384
-rw-r--r--newlib/libc/sys/linux/net/check_pf.c199
-rw-r--r--newlib/libc/sys/linux/net/databases.def40
-rw-r--r--newlib/libc/sys/linux/net/digits_dots.c317
-rw-r--r--newlib/libc/sys/linux/net/ether_addr.c231
-rw-r--r--newlib/libc/sys/linux/net/ether_aton.c29
-rw-r--r--newlib/libc/sys/linux/net/ether_aton_r.c64
-rw-r--r--newlib/libc/sys/linux/net/ether_hton.c83
-rw-r--r--newlib/libc/sys/linux/net/ether_line.c81
-rw-r--r--newlib/libc/sys/linux/net/ether_ntoa.c30
-rw-r--r--newlib/libc/sys/linux/net/ether_ntoa_r.c34
-rw-r--r--newlib/libc/sys/linux/net/ether_ntoh.c86
-rw-r--r--newlib/libc/sys/linux/net/etherent.h9
-rw-r--r--newlib/libc/sys/linux/net/ethers-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/ethers.3197
-rw-r--r--newlib/libc/sys/linux/net/function.def78
-rw-r--r--newlib/libc/sys/linux/net/getXXbyYY.c156
-rw-r--r--newlib/libc/sys/linux/net/getXXbyYY_r.c292
-rw-r--r--newlib/libc/sys/linux/net/getXXent.c96
-rw-r--r--newlib/libc/sys/linux/net/getXXent_r.c209
-rw-r--r--newlib/libc/sys/linux/net/getaddrinfo.3620
-rw-r--r--newlib/libc/sys/linux/net/getaddrinfo.c3416
-rw-r--r--newlib/libc/sys/linux/net/getaliasent.c26
-rw-r--r--newlib/libc/sys/linux/net/getaliasent_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getaliasname.c30
-rw-r--r--newlib/libc/sys/linux/net/getaliasname_r.c29
-rw-r--r--newlib/libc/sys/linux/net/gethostbydns.c815
-rw-r--r--newlib/libc/sys/linux/net/gethostbyht.c285
-rw-r--r--newlib/libc/sys/linux/net/gethostbyname.3380
-rw-r--r--newlib/libc/sys/linux/net/gethostbynis.c281
-rw-r--r--newlib/libc/sys/linux/net/gethostnamadr.c221
-rw-r--r--newlib/libc/sys/linux/net/gethstbyad.c31
-rw-r--r--newlib/libc/sys/linux/net/gethstbyad_r.c53
-rw-r--r--newlib/libc/sys/linux/net/gethstbynm.c38
-rw-r--r--newlib/libc/sys/linux/net/gethstbynm2.c39
-rw-r--r--newlib/libc/sys/linux/net/gethstbynm2_r.c46
-rw-r--r--newlib/libc/sys/linux/net/gethstbynm_r.c45
-rw-r--r--newlib/libc/sys/linux/net/gethstent.c27
-rw-r--r--newlib/libc/sys/linux/net/gethstent_r.c35
-rw-r--r--newlib/libc/sys/linux/net/getifaddrs.3164
-rw-r--r--newlib/libc/sys/linux/net/getifaddrs.c401
-rw-r--r--newlib/libc/sys/linux/net/getipnodebyname.3461
-rw-r--r--newlib/libc/sys/linux/net/getnameinfo.3311
-rw-r--r--newlib/libc/sys/linux/net/getnameinfo.c768
-rw-r--r--newlib/libc/sys/linux/net/getnetbyad.c32
-rw-r--r--newlib/libc/sys/linux/net/getnetbyad_r.c32
-rw-r--r--newlib/libc/sys/linux/net/getnetbydns.c327
-rw-r--r--newlib/libc/sys/linux/net/getnetbyht.c183
-rw-r--r--newlib/libc/sys/linux/net/getnetbynis.c190
-rw-r--r--newlib/libc/sys/linux/net/getnetbynm.c31
-rw-r--r--newlib/libc/sys/linux/net/getnetbynm_r.c31
-rw-r--r--newlib/libc/sys/linux/net/getnetent.3172
-rw-r--r--newlib/libc/sys/linux/net/getnetent.c27
-rw-r--r--newlib/libc/sys/linux/net/getnetent_r.c32
-rw-r--r--newlib/libc/sys/linux/net/getnetgrent.c52
-rw-r--r--newlib/libc/sys/linux/net/getnetgrent_r.c446
-rw-r--r--newlib/libc/sys/linux/net/getnetnamadr.c113
-rw-r--r--newlib/libc/sys/linux/net/getnssent.c58
-rw-r--r--newlib/libc/sys/linux/net/getnssent_r.c218
-rw-r--r--newlib/libc/sys/linux/net/getproto.c75
-rw-r--r--newlib/libc/sys/linux/net/getproto_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getprotoent.3149
-rw-r--r--newlib/libc/sys/linux/net/getprotoent.c121
-rw-r--r--newlib/libc/sys/linux/net/getprotoname.c64
-rw-r--r--newlib/libc/sys/linux/net/getprtent.c26
-rw-r--r--newlib/libc/sys/linux/net/getprtent_r.c30
-rw-r--r--newlib/libc/sys/linux/net/getprtname.c30
-rw-r--r--newlib/libc/sys/linux/net/getprtname_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getrpcbyname.c30
-rw-r--r--newlib/libc/sys/linux/net/getrpcbyname_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getrpcbynumber.c30
-rw-r--r--newlib/libc/sys/linux/net/getrpcbynumber_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getrpcent.c26
-rw-r--r--newlib/libc/sys/linux/net/getrpcent_r.c30
-rw-r--r--newlib/libc/sys/linux/net/getservbyname.c81
-rw-r--r--newlib/libc/sys/linux/net/getservbyport.c76
-rw-r--r--newlib/libc/sys/linux/net/getservent.3158
-rw-r--r--newlib/libc/sys/linux/net/getservent.c294
-rw-r--r--newlib/libc/sys/linux/net/getservent_r.c30
-rw-r--r--newlib/libc/sys/linux/net/getsrvbynm.c30
-rw-r--r--newlib/libc/sys/linux/net/getsrvbynm_r.c29
-rw-r--r--newlib/libc/sys/linux/net/getsrvbypt.c30
-rw-r--r--newlib/libc/sys/linux/net/getsrvbypt_r.c29
-rw-r--r--newlib/libc/sys/linux/net/grp-lookup.c23
-rw-r--r--newlib/libc/sys/linux/net/herrno.c6
-rw-r--r--newlib/libc/sys/linux/net/herror.c103
-rw-r--r--newlib/libc/sys/linux/net/hesiod.3159
-rw-r--r--newlib/libc/sys/linux/net/hesiod.c600
-rw-r--r--newlib/libc/sys/linux/net/hosts-lookup.c23
-rw-r--r--newlib/libc/sys/linux/net/if_indextoname.3142
-rw-r--r--newlib/libc/sys/linux/net/ifaddrs.h74
-rw-r--r--newlib/libc/sys/linux/net/ifreq.c100
-rw-r--r--newlib/libc/sys/linux/net/ifreq.h40
-rw-r--r--newlib/libc/sys/linux/net/in6_addr.c28
-rw-r--r--newlib/libc/sys/linux/net/inet.3271
-rw-r--r--newlib/libc/sys/linux/net/inet6_option.c346
-rw-r--r--newlib/libc/sys/linux/net/inet6_option_space.3445
-rw-r--r--newlib/libc/sys/linux/net/inet6_rthdr_space.3323
-rw-r--r--newlib/libc/sys/linux/net/inet_lnaof.c16
-rw-r--r--newlib/libc/sys/linux/net/inet_mkadr.c (renamed from newlib/libc/sys/linux/net/inet_makeaddr.c)30
-rw-r--r--newlib/libc/sys/linux/net/inet_net.3157
-rw-r--r--newlib/libc/sys/linux/net/inet_net.c (renamed from newlib/libc/sys/linux/net/inet_network.c)49
-rw-r--r--newlib/libc/sys/linux/net/inet_netof.c18
-rw-r--r--newlib/libc/sys/linux/net/inet_ntoa.c151
-rw-r--r--newlib/libc/sys/linux/net/innetgr-stub.c7
-rw-r--r--newlib/libc/sys/linux/net/ip6opt.c387
-rw-r--r--newlib/libc/sys/linux/net/iso_addr.3113
-rw-r--r--newlib/libc/sys/linux/net/iso_addr.c119
-rw-r--r--newlib/libc/sys/linux/net/key-lookup.c23
-rw-r--r--newlib/libc/sys/linux/net/linkaddr.3140
-rw-r--r--newlib/libc/sys/linux/net/linkaddr.c160
-rw-r--r--newlib/libc/sys/linux/net/local.h24
-rw-r--r--newlib/libc/sys/linux/net/map_v4v6.c128
-rw-r--r--newlib/libc/sys/linux/net/name6.c1812
-rw-r--r--newlib/libc/sys/linux/net/namespace.h152
-rw-r--r--newlib/libc/sys/linux/net/netgroup.h80
-rw-r--r--newlib/libc/sys/linux/net/netgrp-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/network-lookup.c23
-rw-r--r--newlib/libc/sys/linux/net/not-cancel.h53
-rw-r--r--newlib/libc/sys/linux/net/ns.3133
-rw-r--r--newlib/libc/sys/linux/net/ns_addr.c239
-rw-r--r--newlib/libc/sys/linux/net/ns_name.c320
-rw-r--r--newlib/libc/sys/linux/net/ns_netint.c17
-rw-r--r--newlib/libc/sys/linux/net/ns_ntoa.c105
-rw-r--r--newlib/libc/sys/linux/net/ns_parse.c125
-rw-r--r--newlib/libc/sys/linux/net/ns_print.c143
-rw-r--r--newlib/libc/sys/linux/net/ns_samedomain.c204
-rw-r--r--newlib/libc/sys/linux/net/ns_ttl.c21
-rw-r--r--newlib/libc/sys/linux/net/nsap_addr.c41
-rw-r--r--newlib/libc/sys/linux/net/nscd-types.h22
-rw-r--r--newlib/libc/sys/linux/net/nscd/nscd-client.h312
-rw-r--r--newlib/libc/sys/linux/net/nscd/nscd_proto.h67
-rw-r--r--newlib/libc/sys/linux/net/nsdispatch.3231
-rw-r--r--newlib/libc/sys/linux/net/nsdispatch.c266
-rw-r--r--newlib/libc/sys/linux/net/nslexer.c1712
-rw-r--r--newlib/libc/sys/linux/net/nslexer.l114
-rw-r--r--newlib/libc/sys/linux/net/nsparser.c541
-rw-r--r--newlib/libc/sys/linux/net/nsparser.h13
-rw-r--r--newlib/libc/sys/linux/net/nsparser.y178
-rw-r--r--newlib/libc/sys/linux/net/nss.h52
-rw-r--r--newlib/libc/sys/linux/net/nsswitch.c772
-rw-r--r--newlib/libc/sys/linux/net/nsswitch.h180
-rw-r--r--newlib/libc/sys/linux/net/opensock.c120
-rw-r--r--newlib/libc/sys/linux/net/proto-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/pwd-lookup.c23
-rw-r--r--newlib/libc/sys/linux/net/rcmd.3298
-rw-r--r--newlib/libc/sys/linux/net/rcmd.c1190
-rw-r--r--newlib/libc/sys/linux/net/rcmdsh.3116
-rw-r--r--newlib/libc/sys/linux/net/res_comp.c74
-rw-r--r--newlib/libc/sys/linux/net/res_config.h10
-rw-r--r--newlib/libc/sys/linux/net/res_data.c303
-rw-r--r--newlib/libc/sys/linux/net/res_debug.c407
-rw-r--r--newlib/libc/sys/linux/net/res_debug.h34
-rw-r--r--newlib/libc/sys/linux/net/res_hconf.c676
-rw-r--r--newlib/libc/sys/linux/net/res_hconf.h55
-rw-r--r--newlib/libc/sys/linux/net/res_init.c495
-rw-r--r--newlib/libc/sys/linux/net/res_libc.c166
-rw-r--r--newlib/libc/sys/linux/net/res_mkquery.c137
-rw-r--r--newlib/libc/sys/linux/net/res_mkupdate.c412
-rw-r--r--newlib/libc/sys/linux/net/res_query.c315
-rw-r--r--newlib/libc/sys/linux/net/res_send.c1480
-rw-r--r--newlib/libc/sys/linux/net/res_update.c515
-rw-r--r--newlib/libc/sys/linux/net/resolver.3422
-rw-r--r--newlib/libc/sys/linux/net/rexec.c202
-rw-r--r--newlib/libc/sys/linux/net/rpc-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/rthdr.c319
-rw-r--r--newlib/libc/sys/linux/net/ruserpass.c336
-rw-r--r--newlib/libc/sys/linux/net/send.c1
-rw-r--r--newlib/libc/sys/linux/net/service-lookup.c22
-rw-r--r--newlib/libc/sys/linux/net/spwd-lookup.c24
-rw-r--r--newlib/libc/sys/linux/net/vars.c45
-rw-r--r--newlib/libc/sys/linux/shlib-compat.h1
-rw-r--r--newlib/libc/sys/linux/stdlib/collate.c2
-rw-r--r--newlib/libc/sys/linux/sys/ioctl.h2
-rw-r--r--newlib/libc/sys/linux/sys/socket.h149
-rw-r--r--newlib/libc/sys/linux/sys/unistd.h1
210 files changed, 15079 insertions, 25484 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 5876f2632..11867b60e 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,223 @@
+2008-05-22 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/include/sys/reent.h: Add _h_errno field.
+ * libc/sys/linux/libc-symbols.h: Add default stubs for new libc macros
+ now used in net directory.
+ * libc/sys/linux/bits/libc-lock.h: Always define _IO_MTSAFE_IO.
+ * libc/sys/linux/include/hesiod.h: Add needed macros for new code
+ in net directory.
+ * libc/sys/linux/include/netdb.h: Ditto.
+ * libc/sys/linux/include/resolv.h: Ditto.
+ * libc/sys/linux/include/stdint.h: Ditto.
+ * libc/sys/linux/include/arpa/nameser.h: Ditto.
+ * libc/sys/linux/include/net/ethernet.h: Ditto.
+ * libc/sys/linux/include/net/if_ppp.h: Ditto.
+ * libc/sys/linux/include/netinet/if_ether.h: Ditto.
+ * libc/sys/linux/machine/i386/get_clockfreq.c: Remove static memmem.
+ * libc/sys/linux/machine/i386/include/endian.h: Protect macros with
+ flags to avoid duplicate definition.
+ * libc/sys/linux/machine/i386/include/param.h: Ditto.
+ * libc/sys/linux/net/Makefile.am: Modified to account for removed and
+ added files.
+ * libc/sys/linux/net/Makefile.in: Regenerated.
+ * libc/sys/linux/net/base64.c: Replaced with glibc version of code.
+ * libc/sys/linux/net/getaddrinfo.c: Ditto.
+ * libc/sys/linux/net/getnameinfo.c: Ditto.
+ * libc/sys/linux/net/getproto.c: Ditto.
+ * libc/sys/linux/net/getservent.c: Ditto.
+ * libc/sys/linux/net/inet_netof.c: Ditto.
+ * libc/sys/linux/net/inet_lnaof.c: Ditto.
+ * libc/sys/linux/net/ns_name.c: Ditto.
+ * libc/sys/linux/net/ns_netint.c: Ditto.
+ * libc/sys/linux/net/inet_ntoa.c: Ditto.
+ * libc/sys/linux/net/ns_parse.c: Ditto.
+ * libc/sys/linux/net/ns_print.c: Ditto.
+ * libc/sys/linux/net/ns_ttl.c: Ditto.
+ * libc/sys/linux/net/nsap_addr.c: Ditto.
+ * libc/sys/linux/net/rcmd.c: Ditto.
+ * libc/sys/linux/net/res_comp.c: Ditto.
+ * libc/sys/linux/net/res_data.c: Ditto.
+ * libc/sys/linux/net/res_debug.c: Ditto.
+ * libc/sys/linux/net/res_init.c: Ditto.
+ * libc/sys/linux/net/res_mkquery.c: Ditto.
+ * libc/sys/linux/net/res_query.c: Ditto.
+ * libc/sys/linux/net/res_send.c: Ditto.
+ * libc/sys/linux/net/send.c: Ditto.
+ * libc/sys/linux/stdlib/collate.c: Ditto.
+ * libc/sys/linux/sys/ioctl.h: Ditto.
+ * libc/sys/linux/sys/socket.h: Ditto.
+ * libc/sys/linux/sys/unistd.h: Ditto.
+ * libc/sys/linux/iconv/iconvconfig.c: Removed either because no longer
+ used or because licensing includes advertising clause that cannot be
+ ignored.
+ * libc/sys/linux/iconv/strtab.c: Ditto.
+ * libc/sys/linux/include/libc_private.h: Ditto.
+ * libc/sys/linux/include/nsswitch.h: Ditto.
+ * libc/sys/linux/include/net/if_atm.h: Ditto.
+ * libc/sys/linux/include/net/if_media.h: Ditto.
+ * libc/sys/linux/include/net/if_pppvar.h: Ditto.
+ * libc/sys/linux/include/netinet/if_atm.h: Ditto.
+ * libc/sys/linux/include/netinet/ip_flow.h: Ditto.
+ * libc/sys/linux/intl/locale.alias: Ditto.
+ * libc/sys/linux/net/addr2ascii.3: Ditto.
+ * libc/sys/linux/net/bindresvport.c: Ditto.
+ * libc/sys/linux/net/byteorder.3: Ditto.
+ * libc/sys/linux/net/res_config.h: Ditto.
+ * libc/sys/linux/net/ether_addr.c: Ditto.
+ * libc/sys/linux/net/ethers.3: Ditto.
+ * libc/sys/linux/net/getaddrinfo.3: Ditto.
+ * libc/sys/linux/net/gethostbydns.c: Ditto.
+ * libc/sys/linux/net/gethostbyht.c: Ditto.
+ * libc/sys/linux/net/gethostbyname.3: Ditto.
+ * libc/sys/linux/net/gethostbynis.c: Ditto.
+ * libc/sys/linux/net/gethostnamadr.c: Ditto.
+ * libc/sys/linux/net/getifaddrs.3: Ditto.
+ * libc/sys/linux/net/getifaddrs.c: Ditto.
+ * libc/sys/linux/net/getipnodebyname.3: Ditto.
+ * libc/sys/linux/net/getnameinfo.3: Ditto.
+ * libc/sys/linux/net/getnetbydns.c: Ditto.
+ * libc/sys/linux/net/getnetbyht.c: Ditto.
+ * libc/sys/linux/net/getnetbynis.c: Ditto.
+ * libc/sys/linux/net/getnetent.3: Ditto.
+ * libc/sys/linux/net/getnetnamadr.c: Ditto.
+ * libc/sys/linux/net/getprotoent.3: Ditto.
+ * libc/sys/linux/net/getprotoent.c: Ditto.
+ * libc/sys/linux/net/getprotoname.c: Ditto.
+ * libc/sys/linux/net/getservbyname.c: Ditto.
+ * libc/sys/linux/net/getservbyport.c: Ditto.
+ * libc/sys/linux/net/getservent.3: Ditto.
+ * libc/sys/linux/net/herror.c: Ditto.
+ * libc/sys/linux/net/hesiod.3: Ditto.
+ * libc/sys/linux/net/hesiod.c: Ditto.
+ * libc/sys/linux/net/if_indextoname.3: Ditto.
+ * libc/sys/linux/net/inet.3: Ditto.
+ * libc/sys/linux/net/inet6_option_space.3: Ditto.
+ * libc/sys/linux/net/inet6_rthdr_space.3: Ditto.
+ * libc/sys/linux/net/inet_makeaddr.c: Ditto.
+ * libc/sys/linux/net/inet_net.3: Ditto.
+ * libc/sys/linux/net/inet_network.c: Ditto.
+ * libc/sys/linux/net/innetgr-stub.c: Ditto.
+ * libc/sys/linux/net/ip6opt.c: Ditto.
+ * libc/sys/linux/net/iso_addr.3: Ditto.
+ * libc/sys/linux/net/iso_addr.c: Ditto.
+ * libc/sys/linux/net/linkaddr.3: Ditto.
+ * libc/sys/linux/net/linkaddr.c: Ditto.
+ * libc/sys/linux/net/map_v4v6.c: Ditto.
+ * libc/sys/linux/net/name6.c: Ditto.
+ * libc/sys/linux/net/namespace.h: Ditto.
+ * libc/sys/linux/net/ns.3: Ditto.
+ * libc/sys/linux/net/ns_addr.c: Ditto.
+ * libc/sys/linux/net/ns_ntoa.c: Ditto.
+ * libc/sys/linux/net/nsdispatch.3: Ditto.
+ * libc/sys/linux/net/nsdispatch.c: Ditto.
+ * libc/sys/linux/net/nslexer.c: Ditto.
+ * libc/sys/linux/net/nslexer.l: Ditto.
+ * libc/sys/linux/net/nsparser.c: Ditto.
+ * libc/sys/linux/net/nsparser.h: Ditto.
+ * libc/sys/linux/net/nsparser.y: Ditto.
+ * libc/sys/linux/net/rcmd.3: Ditto.
+ * libc/sys/linux/net/rcmdsh.3: Ditto.
+ * libc/sys/linux/net/res_mkupdate.c: Ditto.
+ * libc/sys/linux/net/res_update.c: Ditto.
+ * libc/sys/linux/net/resolver.3: Ditto.
+ * libc/sys/linux/net/rthdr.c: Ditto.
+ * libc/sys/linux/net/vars.c: Ditto.
+ * libc/sys/linux/shlib-compat.h: New file.
+ * libc/sys/linux/machine/i386/atomic.h: Ditto.
+ * libc/sys/linux/net/XXX-lookup.c: Ditto.
+ * libc/sys/linux/net/alias-lookup.c: Ditto.
+ * libc/sys/linux/net/res_libc.c: Ditto.
+ * libc/sys/linux/net/aliases.h: Ditto.
+ * libc/sys/linux/net/check_pf.c: Ditto.
+ * libc/sys/linux/net/databases.def: Ditto.
+ * libc/sys/linux/net/digits_dots.c: Ditto.
+ * libc/sys/linux/net/ether_aton.c: Ditto.
+ * libc/sys/linux/net/ether_aton_r.c: Ditto.
+ * libc/sys/linux/net/ether_hton.c: Ditto.
+ * libc/sys/linux/net/ether_line.c: Ditto.
+ * libc/sys/linux/net/ether_ntoa.c: Ditto.
+ * libc/sys/linux/net/ether_ntoa_r.c: Ditto.
+ * libc/sys/linux/net/ether_ntoh.c: Ditto.
+ * libc/sys/linux/net/etherent.h: Ditto.
+ * libc/sys/linux/net/ethers-lookup.c: Ditto.
+ * libc/sys/linux/net/function.def: Ditto.
+ * libc/sys/linux/net/getXXbyYY.c: Ditto.
+ * libc/sys/linux/net/getXXbyYY_r.c: Ditto.
+ * libc/sys/linux/net/getXXent.c: Ditto.
+ * libc/sys/linux/net/getXXent_r.c: Ditto.
+ * libc/sys/linux/net/getaliasent.c: Ditto.
+ * libc/sys/linux/net/getaliasent_r.c: Ditto.
+ * libc/sys/linux/net/getaliasname.c: Ditto.
+ * libc/sys/linux/net/getaliasname_r.c: Ditto.
+ * libc/sys/linux/net/gethstbyad.c: Ditto.
+ * libc/sys/linux/net/gethstbyad_r.c: Ditto.
+ * libc/sys/linux/net/gethstbynm.c: Ditto.
+ * libc/sys/linux/net/gethstbynm2.c: Ditto.
+ * libc/sys/linux/net/gethstbynm2_r.c: Ditto.
+ * libc/sys/linux/net/gethstbynm_r.c: Ditto.
+ * libc/sys/linux/net/gethstent.c: Ditto.
+ * libc/sys/linux/net/gethstent_r.c: Ditto.
+ * libc/sys/linux/net/getnetbyad.c: Ditto.
+ * libc/sys/linux/net/getnetbyad_r.c: Ditto.
+ * libc/sys/linux/net/getnetbynm.c: Ditto.
+ * libc/sys/linux/net/getnetbynm_r.c: Ditto.
+ * libc/sys/linux/net/getnetent.c: Ditto.
+ * libc/sys/linux/net/getnetent_r.c: Ditto.
+ * libc/sys/linux/net/getnetgrent.c: Ditto.
+ * libc/sys/linux/net/getnetgrent_r.c: Ditto.
+ * libc/sys/linux/net/getnssent.c: Ditto.
+ * libc/sys/linux/net/getnssent_r.c: Ditto.
+ * libc/sys/linux/net/getproto_r.c: Ditto.
+ * libc/sys/linux/net/getprtent.c: Ditto.
+ * libc/sys/linux/net/getprtent_r.c: Ditto.
+ * libc/sys/linux/net/getprtname.c: Ditto.
+ * libc/sys/linux/net/getprtname_r.c: Ditto.
+ * libc/sys/linux/net/getrpcbyname.c: Ditto.
+ * libc/sys/linux/net/getrpcbyname_r.c: Ditto.
+ * libc/sys/linux/net/getrpcbynumber.c: Ditto.
+ * libc/sys/linux/net/getrpcbynumber_r.c: Ditto.
+ * libc/sys/linux/net/getrpcent.c: Ditto.
+ * libc/sys/linux/net/getrpcent_r.c: Ditto.
+ * libc/sys/linux/net/getservent_r.c: Ditto.
+ * libc/sys/linux/net/getsrvbynm.c: Ditto.
+ * libc/sys/linux/net/getsrvbynm_r.c: Ditto.
+ * libc/sys/linux/net/getsrvbypt.c: Ditto.
+ * libc/sys/linux/net/getsrvbypt_r.c: Ditto.
+ * libc/sys/linux/net/grp-lookup.c: Ditto.
+ * libc/sys/linux/net/herrno.c: Ditto.
+ * libc/sys/linux/net/hosts-lookup.c: Ditto.
+ * libc/sys/linux/net/ifaddrs.h: Ditto.
+ * libc/sys/linux/net/ifreq.c: Ditto.
+ * libc/sys/linux/net/ifreq.h: Ditto.
+ * libc/sys/linux/net/in6_addr.c: Ditto.
+ * libc/sys/linux/net/inet6_option.c: Ditto.
+ * libc/sys/linux/net/inet_mkadr.c: Ditto.
+ * libc/sys/linux/net/inet_net.c: Ditto.
+ * libc/sys/linux/net/key-lookup.c: Ditto.
+ * libc/sys/linux/net/local.h: Ditto.
+ * libc/sys/linux/net/netgroup.h: Ditto.
+ * libc/sys/linux/net/netgrp-lookup.c: Ditto.
+ * libc/sys/linux/net/network-lookup.c: Ditto.
+ * libc/sys/linux/net/not-cancel.h: Ditto.
+ * libc/sys/linux/net/ns_samedomain.c: Ditto.
+ * libc/sys/linux/net/nscd-types.h: Ditto.
+ * libc/sys/linux/net/nss.h: Ditto.
+ * libc/sys/linux/net/nsswitch.c: Ditto.
+ * libc/sys/linux/net/nsswitch.h: Ditto.
+ * libc/sys/linux/net/opensock.c: Ditto.
+ * libc/sys/linux/net/proto-lookup.c: Ditto.
+ * libc/sys/linux/net/pwd-lookup.c: Ditto.
+ * libc/sys/linux/net/res_debug.h: Ditto.
+ * libc/sys/linux/net/res_hconf.c: Ditto.
+ * libc/sys/linux/net/res_hconf.h: Ditto.
+ * libc/sys/linux/net/rexec.c: Ditto.
+ * libc/sys/linux/net/rpc-lookup.c: Ditto.
+ * libc/sys/linux/net/ruserpass.c: Ditto.
+ * libc/sys/linux/net/service-lookup.c: Ditto.
+ * libc/sys/linux/net/spwd-lookup.c: Ditto.
+ * libc/sys/linux/net/nscd/nscd-client.h: Ditto.
+ * libc/sys/linux/net/nscd/nscd_proto.h: Ditto.
+
2008-05-21 Eric Blake <ebb9@byu.net>
Optimize the generic strchr.
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 0daa6cbee..fffb05de0 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -623,6 +623,7 @@ struct _reent
_mbstate_t _mbsrtowcs_state;
_mbstate_t _wcrtomb_state;
_mbstate_t _wcsrtombs_state;
+ int _h_errno;
} _reent;
/* Two next two fields were once used by malloc. They are no longer
used. They are used to preserve the space used before so as to
diff --git a/newlib/libc/sys/linux/bits/libc-lock.h b/newlib/libc/sys/linux/bits/libc-lock.h
index 2b170444b..5779a6c93 100644
--- a/newlib/libc/sys/linux/bits/libc-lock.h
+++ b/newlib/libc/sys/linux/bits/libc-lock.h
@@ -27,6 +27,8 @@
#include <linuxthreads/internals.h>
#endif
+#define _IO_MTSAFE_IO /* add this as we always want this in newlib */
+
/* Mutex type. */
#if defined(_LIBC) || defined(_IO_MTSAFE_IO)
typedef pthread_mutex_t __libc_lock_t;
diff --git a/newlib/libc/sys/linux/iconv/iconvconfig.c b/newlib/libc/sys/linux/iconv/iconvconfig.c
deleted file mode 100644
index 8ad6c93e2..000000000
--- a/newlib/libc/sys/linux/iconv/iconvconfig.c
+++ /dev/null
@@ -1,1176 +0,0 @@
-/* Generate fastloading iconv module configuration files.
- Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <argp.h>
-#include <assert.h>
-#include <error.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <libintl.h>
-#include <locale.h>
-#include <mcheck.h>
-#include <search.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdio_ext.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/cdefs.h>
-#include <sys/uio.h>
-
-#include "iconvconfig.h"
-
-/* Get libc version number. */
-#include "../version.h"
-
-#define PACKAGE _libc_intl_domainname
-
-
-/* The hashing function we use. */
-#include "../intl/hash-string.h"
-
-
-/* Types used. */
-struct module
-{
- char *fromname;
- struct Strent *fromname_strent;
- char *filename;
- struct Strent *filename_strent;
- const char *directory;
- struct Strent *directory_strent;
- struct module *next;
- int cost;
- struct Strent *toname_strent;
- char toname[0];
-};
-
-struct alias
-{
- char *fromname;
- struct Strent *froment;
- struct module *module;
- struct Strent *toent;
- char toname[0];
-};
-
-struct name
-{
- const char *name;
- struct Strent *strent;
- int module_idx;
- uint32_t hashval;
-};
-
-struct name_info
-{
- const char *canonical_name;
- struct Strent *canonical_strent;
-
- struct module *from_internal;
- struct module *to_internal;
-
- struct other_conv_list
- {
- int dest_idx;
- struct other_conv
- {
- gidx_t module_idx;
- struct module *module;
- struct other_conv *next;
- } other_conv;
- struct other_conv_list *next;
- } *other_conv_list;
-};
-
-
-/* Name and version of program. */
-static void print_version (FILE *stream, struct argp_state *state);
-void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
-
-/* Short description of program. */
-static const char doc[] = N_("\
-Create fastloading iconv module configuration file.");
-
-/* Strings for arguments in help texts. */
-static const char args_doc[] = N_("[DIR...]");
-
-/* Function to print some extra text in the help message. */
-static char *more_help (int key, const char *text, void *input);
-
-/* Data structure to communicate with argp functions. */
-static struct argp argp =
-{
- NULL, NULL, args_doc, doc, NULL, more_help
-};
-
-
-/* The function doing the actual work. */
-static int handle_dir (const char *dir);
-
-/* Add all known builtin conversions and aliases. */
-static void add_builtins (void);
-
-/* Create list of all aliases without circular aliases. */
-static void get_aliases (void);
-
-/* Create list of all modules. */
-static void get_modules (void);
-
-/* Get list of all the names and thereby indexing them. */
-static void generate_name_list (void);
-
-/* Collect information about all the names. */
-static void generate_name_info (void);
-
-/* Write the output file. */
-static int write_output (void);
-
-
-/* Search tree of the modules we know. */
-static void *modules;
-
-/* Search tree of the aliases we know. */
-static void *aliases;
-
-/* Search tree for name to index mapping. */
-static void *names;
-
-/* Number of names we know about. */
-static int nnames;
-
-/* List of all aliases. */
-static struct alias **alias_list;
-static size_t nalias_list;
-static size_t nalias_list_max;
-
-/* List of all modules. */
-static struct module **module_list;
-static size_t nmodule_list;
-static size_t nmodule_list_max;
-
-/* Names and information about them. */
-static struct name_info *name_info;
-static size_t nname_info;
-
-/* Number of translations not from or to INTERNAL. */
-static size_t nextra_modules;
-
-
-/* Names and aliases for the builtin transformations. */
-static struct
-{
- const char *from;
- const char *to;
-} builtin_alias[] =
- {
-#define BUILTIN_ALIAS(alias, real) \
- { .from = alias, .to = real },
-#define BUILTIN_TRANSFORMATION(From, To, Cost, Name, Fct, MinF, MaxF, \
- MinT, MaxT)
-#include <gconv_builtin.h>
- };
-#undef BUILTIN_ALIAS
-#undef BUILTIN_TRANSFORMATION
-#define nbuiltin_alias (sizeof (builtin_alias) / sizeof (builtin_alias[0]))
-
-static struct
-{
- const char *from;
- const char *to;
- const char *module;
- int cost;
-} builtin_trans[] =
- {
-#define BUILTIN_ALIAS(alias, real)
-#define BUILTIN_TRANSFORMATION(From, To, Cost, Name, Fct, MinF, MaxF, \
- MinT, MaxT) \
- { .from = From, .to = To, .module = Name, .cost = Cost },
-#include <gconv_builtin.h>
- };
-#define nbuiltin_trans (sizeof (builtin_trans) / sizeof (builtin_trans[0]))
-
-
-/* Filename extension for the modules. */
-#ifndef MODULE_EXT
-# define MODULE_EXT ".so"
-#endif
-static const char gconv_module_ext[] = MODULE_EXT;
-
-
-extern void *xmalloc (size_t n) __attribute_malloc__;
-extern void *xcalloc (size_t n, size_t m) __attribute_malloc__;
-extern void *xrealloc (void *p, size_t n);
-
-
-/* C string table handling. */
-struct Strtab;
-struct Strent;
-
-/* Create new C string table object in memory. */
-extern struct Strtab *strtabinit (void);
-
-/* Free resources allocated for C string table ST. */
-extern void strtabfree (struct Strtab *st);
-
-/* Add string STR (length LEN is != 0) to C string table ST. */
-extern struct Strent *strtabadd (struct Strtab *st, const char *str,
- size_t len);
-
-/* Finalize string table ST and store size in *SIZE and return a pointer. */
-extern void *strtabfinalize (struct Strtab *st, size_t *size);
-
-/* Get offset in string table for string associated with SE. */
-extern size_t strtaboffset (struct Strent *se);
-
-/* String table we construct. */
-static struct Strtab *strtab;
-
-
-
-int
-main (int argc, char *argv[])
-{
- int remaining;
- int status = 0;
- char *path;
- char *tp;
- const char *old = GCONV_PATH;
- size_t len = strlen (old) + 1;
- char *new = alloca(len);
-
- /* Enable memory use testing. */
- /* mcheck_pedantic (NULL); */
- mtrace ();
-
- /* Set locale via LC_ALL. */
- setlocale (LC_ALL, "");
-
- /* Set the text message domain. */
- textdomain (_libc_intl_domainname);
-
- /* Parse and process arguments. */
- argp_parse (&argp, argc, argv, 0, &remaining, NULL);
-
- /* Initialize the string table. */
- strtab = strtabinit ();
-
- /* Handle all directories mentioned. */
- while (remaining < argc)
- status |= handle_dir (argv[remaining++]);
-
- /* In any case also handle the standard directory. */
- path = memcpy (new, old, len);
- tp = strtok (path, ":");
- while (tp != NULL)
- {
- status |= handle_dir (tp);
-
- tp = strtok (NULL, ":");
- }
-
- /* Add the builtin transformations and aliases without overwriting
- anything. */
- add_builtins ();
-
- /* Store aliases in an array. */
- get_aliases ();
-
- /* Get list of all modules. */
- get_modules ();
-
- /* Generate list of all the names we know to handle in some way. */
- generate_name_list ();
-
- /* Now we know all the names we will handle, collect information
- about them. */
- generate_name_info ();
-
- /* Write the output file, but only if we haven't seen any error. */
- if (status == 0)
- status = write_output ();
- else
- error (1, 0, _("no output file produced because warning were issued"));
-
- return status;
-}
-
-
-static char *
-more_help (int key, const char *text, void *input)
-{
- switch (key)
- {
- case ARGP_KEY_HELP_EXTRA:
- /* We print some extra information. */
- return strdup (gettext ("\
-Report bugs using the `glibcbug' script to <bugs@gnu.org>.\n"));
- default:
- break;
- }
- return (char *) text;
-}
-
-
-/* Print the version information. */
-static void
-print_version (FILE *stream, struct argp_state *state)
-{
- fprintf (stream, "iconvconfig (GNU %s) %s\n", PACKAGE, VERSION);
- fprintf (stream, gettext ("\
-Copyright (C) %s Free Software Foundation, Inc.\n\
-This is free software; see the source for copying conditions. There is NO\n\
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2002");
- fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
-}
-
-
-static int
-alias_compare (const void *p1, const void *p2)
-{
- const struct alias *a1 = (const struct alias *) p1;
- const struct alias *a2 = (const struct alias *) p2;
-
- return strcmp (a1->fromname, a2->fromname);
-}
-
-
-static void
-new_alias (const char *fromname, size_t fromlen, const char *toname,
- size_t tolen)
-{
- struct alias *newp;
- void **inserted;
-
- newp = (struct alias *) xmalloc (sizeof (struct alias) + fromlen + tolen);
-
- newp->fromname = memcpy (newp->toname, toname, tolen);
- newp->fromname += tolen;
- memcpy (newp->fromname, fromname, fromlen);
- newp->module = NULL;
-
- inserted = (void **) tsearch (newp, &aliases, alias_compare);
- if (inserted == NULL)
- error (EXIT_FAILURE, errno, gettext ("while inserting in search tree"));
- if (*inserted != newp)
- /* Something went wrong, free this entry. */
- free (newp);
- else
- {
- newp->froment = strtabadd (strtab, newp->fromname, fromlen);
- newp->toent = strtabadd (strtab, newp->toname, tolen);
- }
-}
-
-
-/* Add new alias. */
-static void
-add_alias (char *rp)
-{
- /* We now expect two more string. The strings are normalized
- (converted to UPPER case) and strored in the alias database. */
- char *from;
- char *to;
- char *wp;
-
- while (isspace (*rp))
- ++rp;
- from = wp = rp;
- while (*rp != '\0' && !isspace (*rp))
- *wp++ = toupper (*rp++);
- if (*rp == '\0')
- /* There is no `to' string on the line. Ignore it. */
- return;
- *wp++ = '\0';
- to = ++rp;
- while (isspace (*rp))
- ++rp;
- while (*rp != '\0' && !isspace (*rp))
- *wp++ = toupper (*rp++);
- if (to == wp)
- /* No `to' string, ignore the line. */
- return;
- *wp++ = '\0';
-
- assert (strlen (from) + 1 == to - from);
- assert (strlen (to) + 1 == wp - to);
-
- new_alias (from, to - from, to, wp - to);
-}
-
-
-static void
-append_alias (const void *nodep, VISIT value, int level)
-{
- if (value != leaf && value != postorder)
- return;
-
- if (nalias_list_max == nalias_list)
- {
- nalias_list_max += 50;
- alias_list = (struct alias **) xrealloc (alias_list,
- (nalias_list_max
- * sizeof (struct alias *)));
- }
-
- alias_list[nalias_list++] = *(struct alias **) nodep;
-}
-
-
-static void
-get_aliases (void)
-{
- twalk (aliases, append_alias);
-}
-
-
-static int
-module_compare (const void *p1, const void *p2)
-{
- const struct module *m1 = (const struct module *) p1;
- const struct module *m2 = (const struct module *) p2;
- int result;
-
- result = strcmp (m1->fromname, m2->fromname);
- if (result == 0)
- result = strcmp (m1->toname, m2->toname);
-
- return result;
-}
-
-
-/* Create new module record. */
-static void
-new_module (const char *fromname, size_t fromlen, const char *toname,
- size_t tolen, const char *directory,
- const char *filename, size_t filelen, int cost, size_t need_ext)
-{
- struct module *new_module;
- size_t dirlen = strlen (directory) + 1;
- char *tmp;
- void **inserted;
-
- new_module = (struct module *) xmalloc (sizeof (struct module)
- + fromlen + tolen + filelen
- + need_ext);
-
- new_module->fromname = memcpy (new_module->toname, toname, tolen);
- new_module->fromname += tolen;
-
- new_module->filename = memcpy (new_module->fromname, fromname, fromlen);
- new_module->filename += fromlen;
-
- new_module->cost = cost;
- new_module->next = NULL;
-
- tmp = memcpy (new_module->filename, filename, filelen);
- tmp += filelen;
-
- if (need_ext)
- {
- memcpy (tmp - 1, gconv_module_ext, need_ext + 1);
- filelen += need_ext;
- }
- new_module->directory = directory;
-
- /* Now insert the new module data structure in our search tree. */
- inserted = (void **) tsearch (new_module, &modules, module_compare);
- if (inserted == NULL)
- error (EXIT_FAILURE, errno, "while inserting in search tree");
- if (*inserted != new_module)
- free (new_module);
- else
- {
- new_module->fromname_strent = strtabadd (strtab, new_module->fromname,
- fromlen);
- new_module->toname_strent = strtabadd (strtab, new_module->toname,
- tolen);
- new_module->filename_strent = strtabadd (strtab, new_module->filename,
- filelen);
- new_module->directory_strent = strtabadd (strtab, directory, dirlen);
- }
-}
-
-
-/* Add new module. */
-static void
-internal_function
-add_module (char *rp, const char *directory)
-{
- /* We expect now
- 1. `from' name
- 2. `to' name
- 3. filename of the module
- 4. an optional cost value
- */
- char *from;
- char *to;
- char *module;
- char *wp;
- int need_ext;
- int cost;
-
- while (isspace (*rp))
- ++rp;
- from = rp;
- while (*rp != '\0' && !isspace (*rp))
- {
- *rp = toupper (*rp);
- ++rp;
- }
- if (*rp == '\0')
- return;
- *rp++ = '\0';
- to = wp = rp;
- while (isspace (*rp))
- ++rp;
- while (*rp != '\0' && !isspace (*rp))
- *wp++ = toupper (*rp++);
- if (*rp == '\0')
- return;
- *wp++ = '\0';
- do
- ++rp;
- while (isspace (*rp));
- module = wp;
- while (*rp != '\0' && !isspace (*rp))
- *wp++ = *rp++;
- if (*rp == '\0')
- {
- /* There is no cost, use one by default. */
- *wp++ = '\0';
- cost = 1;
- }
- else
- {
- /* There might be a cost value. */
- char *endp;
-
- *wp++ = '\0';
- cost = strtol (rp, &endp, 10);
- if (rp == endp || cost < 1)
- /* No useful information. */
- cost = 1;
- }
-
- if (module[0] == '\0')
- /* No module name given. */
- return;
-
- /* See whether we must add the ending. */
- need_ext = 0;
- if (wp - module < sizeof (gconv_module_ext)
- || memcmp (wp - sizeof (gconv_module_ext), gconv_module_ext,
- sizeof (gconv_module_ext)) != 0)
- /* We must add the module extension. */
- need_ext = sizeof (gconv_module_ext) - 1;
-
- assert (strlen (from) + 1 == to - from);
- assert (strlen (to) + 1 == module - to);
- assert (strlen (module) + 1 == wp - module);
-
- new_module (from, to - from, to, module - to, directory, module, wp - module,
- cost, need_ext);
-}
-
-
-/* Read the config file and add the data for this directory to that. */
-static int
-handle_dir (const char *dir)
-{
- char *infile;
- FILE *fp;
- char *line = NULL;
- size_t linelen = 0;
- size_t dirlen = strlen (dir);
- char *tmp;
-
- if (dir[dirlen - 1] != '/')
- {
- char *newp = (char *) xmalloc (dirlen + 2);
- dir = memcpy (newp, dir, dirlen);
- newp[dirlen++] = '/';
- newp[dirlen] = '\0';
- }
-
- infile = (char *) alloca (dirlen + sizeof "gconv-modules");
- tmp = mempcpy (infile, dir, dirlen);
- tmp += dirlen;
- strcpy (tmp, "gconv-modules");
-
- fp = fopen (infile, "r");
- if (fp == NULL)
- {
- error (0, errno, "cannot open `%s'", infile);
- return 1;
- }
-
- /* No threads present. */
- __fsetlocking (fp, FSETLOCKING_BYCALLER);
-
- while (!feof_unlocked (fp))
- {
- char *rp, *endp, *word;
- ssize_t n = __getdelim (&line, &linelen, '\n', fp);
-
- if (n < 0)
- /* An error occurred. */
- break;
-
- rp = line;
- /* Terminate the line (excluding comments or newline) with a NUL
- byte to simplify the following code. */
- endp = strchr (rp, '#');
- if (endp != NULL)
- *endp = '\0';
- else
- if (rp[n - 1] == '\n')
- rp[n - 1] = '\0';
-
- while (isspace (*rp))
- ++rp;
-
- /* If this is an empty line go on with the next one. */
- if (rp == endp)
- continue;
-
- word = rp;
- while (*rp != '\0' && !isspace (*rp))
- ++rp;
-
- if (rp - word == sizeof ("alias") - 1
- && memcmp (word, "alias", sizeof ("alias") - 1) == 0)
- add_alias (rp);
- else if (rp - word == sizeof ("module") - 1
- && memcmp (word, "module", sizeof ("module") - 1) == 0)
- add_module (rp, dir);
- /* else */
- /* Otherwise ignore the line. */
- }
-
- free (line);
-
- fclose (fp);
-
- return 0;
-}
-
-
-static void
-append_module (const void *nodep, VISIT value, int level)
-{
- struct module *mo;
-
- if (value != leaf && value != postorder)
- return;
-
- mo = *(struct module **) nodep;
-
- if (nmodule_list > 0
- && strcmp (module_list[nmodule_list - 1]->fromname, mo->fromname) == 0)
- {
- /* Same name. */
- mo->next = module_list[nmodule_list - 1];
- module_list[nmodule_list - 1] = mo;
-
- return;
- }
-
- if (nmodule_list_max == nmodule_list)
- {
- nmodule_list_max += 50;
- module_list = (struct module **) xrealloc (module_list,
- (nmodule_list_max
- * sizeof (struct module *)));
- }
-
- module_list[nmodule_list++] = mo;
-}
-
-
-static void
-get_modules (void)
-{
- twalk (modules, append_module);
-}
-
-
-static void
-add_builtins (void)
-{
- size_t cnt;
-
- /* Add all aliases. */
- for (cnt = 0; cnt < nbuiltin_alias; ++cnt)
- new_alias (builtin_alias[cnt].from,
- strlen (builtin_alias[cnt].from) + 1,
- builtin_alias[cnt].to,
- strlen (builtin_alias[cnt].to) + 1);
-
- /* add the builtin transformations. */
- for (cnt = 0; cnt < nbuiltin_trans; ++cnt)
- new_module (builtin_trans[cnt].from,
- strlen (builtin_trans[cnt].from) + 1,
- builtin_trans[cnt].to,
- strlen (builtin_trans[cnt].to) + 1,
- "", builtin_trans[cnt].module,
- strlen (builtin_trans[cnt].module) + 1,
- builtin_trans[cnt].cost, 0);
-}
-
-
-static int
-name_compare (const void *p1, const void *p2)
-{
- const struct name *n1 = (const struct name *) p1;
- const struct name *n2 = (const struct name *) p2;
-
- return strcmp (n1->name, n2->name);
-}
-
-
-static struct name *
-new_name (const char *str, struct Strent *strent)
-{
- struct name *newp = (struct name *) xmalloc (sizeof (struct name));
-
- newp->name = str;
- newp->strent = strent;
- newp->module_idx = -1;
- newp->hashval = hash_string (str);
-
- ++nnames;
-
- return newp;
-}
-
-
-static void
-generate_name_list (void)
-{
- size_t i;
-
- /* A name we always need. */
- tsearch (new_name ("INTERNAL", strtabadd (strtab, "INTERNAL",
- sizeof ("INTERNAL"))),
- &names, name_compare);
-
- for (i = 0; i < nmodule_list; ++i)
- {
- struct module *runp;
-
- if (strcmp (module_list[i]->fromname, "INTERNAL") != 0)
- tsearch (new_name (module_list[i]->fromname,
- module_list[i]->fromname_strent),
- &names, name_compare);
-
- for (runp = module_list[i]; runp != NULL; runp = runp->next)
- if (strcmp (runp->toname, "INTERNAL") != 0)
- tsearch (new_name (runp->toname, runp->toname_strent),
- &names, name_compare);
- }
-}
-
-
-static int
-name_to_module_idx (const char *name, int add)
-{
- struct name **res;
- struct name fake_name = { .name = name };
- int idx;
-
- res = (struct name **) tfind (&fake_name, &names, name_compare);
- if (res == NULL)
- abort ();
-
- idx = (*res)->module_idx;
- if (idx == -1 && add)
- /* No module index assigned yet. */
- idx = (*res)->module_idx = nname_info++;
-
- return idx;
-}
-
-
-static void
-generate_name_info (void)
-{
- size_t i;
- int idx;
-
- name_info = (struct name_info *) xcalloc (nmodule_list + 1,
- sizeof (struct name_info));
-
- /* First add a special entry for the INTERNAL name. This must have
- index zero. */
- idx = name_to_module_idx ("INTERNAL", 1);
- name_info[0].canonical_name = "INTERNAL";
- name_info[0].canonical_strent = strtabadd (strtab, "INTERNAL",
- sizeof ("INTERNAL"));
- assert (nname_info == 1);
-
- for (i = 0; i < nmodule_list; ++i)
- {
- struct module *runp;
-
- for (runp = module_list[i]; runp != NULL; runp = runp->next)
- if (strcmp (runp->fromname, "INTERNAL") == 0)
- {
- idx = name_to_module_idx (runp->toname, 1);
- name_info[idx].from_internal = runp;
- assert (name_info[idx].canonical_name == NULL
- || strcmp (name_info[idx].canonical_name,
- runp->toname) == 0);
- name_info[idx].canonical_name = runp->toname;
- name_info[idx].canonical_strent = runp->toname_strent;
- }
- else if (strcmp (runp->toname, "INTERNAL") == 0)
- {
- idx = name_to_module_idx (runp->fromname, 1);
- name_info[idx].to_internal = runp;
- assert (name_info[idx].canonical_name == NULL
- || strcmp (name_info[idx].canonical_name,
- runp->fromname) == 0);
- name_info[idx].canonical_name = runp->fromname;
- name_info[idx].canonical_strent = runp->fromname_strent;
- }
- else
- {
- /* This is a transformation not to or from the INTERNAL
- encoding. */
- int from_idx = name_to_module_idx (runp->fromname, 1);
- int to_idx = name_to_module_idx (runp->toname, 1);
- struct other_conv_list *newp;
-
- newp = (struct other_conv_list *)
- xmalloc (sizeof (struct other_conv_list));
- newp->other_conv.module_idx = to_idx;
- newp->other_conv.module = runp;
- newp->other_conv.next = NULL; /* XXX Allow multiple module sequence */
- newp->dest_idx = to_idx;
- newp->next = name_info[from_idx].other_conv_list;
- name_info[from_idx].other_conv_list = newp;
- assert (name_info[from_idx].canonical_name == NULL
- || strcmp (name_info[from_idx].canonical_name,
- runp->fromname) == 0);
- name_info[from_idx].canonical_name = runp->fromname;
- name_info[from_idx].canonical_strent = runp->fromname_strent;
-
- ++nextra_modules;
- }
- }
-
- /* Now add the module index information for all the aliases. */
- for (i = 0; i < nalias_list; ++i)
- {
- struct name fake_name = { .name = alias_list[i]->toname };
- struct name **tonamep;
-
- tonamep = (struct name **) tfind (&fake_name, &names, name_compare);
- if (tonamep != NULL)
- {
- struct name *newp = new_name (alias_list[i]->fromname,
- alias_list[i]->froment);
- newp->module_idx = (*tonamep)->module_idx;
- tsearch (newp, &names, name_compare);
- }
- }
-}
-
-
-static int
-is_prime (unsigned long int candidate)
-{
- /* No even number and none less than 10 will be passed here. */
- unsigned long int divn = 3;
- unsigned long int sq = divn * divn;
-
- while (sq < candidate && candidate % divn != 0)
- {
- ++divn;
- sq += 4 * divn;
- ++divn;
- }
-
- return candidate % divn != 0;
-}
-
-
-static uint32_t
-next_prime (uint32_t seed)
-{
- /* Make it definitely odd. */
- seed |= 1;
-
- while (!is_prime (seed))
- seed += 2;
-
- return seed;
-}
-
-
-/* Format of the output file.
-
- Offset Length Description
- 0000 4 Magic header bytes
- 0004 4 Offset of string table (stoff)
- 0008 4 Offset of name hashing table (hoff)
- 000C 4 Hashing table size (hsize)
- 0010 4 Offset of module table (moff)
- 0014 4 Offset of other conversion module table (ooff)
-
- stoff ??? String table
-
- hoff 8*hsize Array of tuples
- string table offset
- module index
-
- moff ??? Array of tuples
- canonical name offset
- from-internal module dir name offset
- from-internal module name off
- to-internal module dir name offset
- to-internal module name offset
- offset into other conversion table
-
- ooff ??? One or more of
- number of steps/modules
- one or more of tuple
- canonical name offset for output
- module dir name offset
- module name offset
- (following last entry with step count 0)
-*/
-static int
-write_output (void)
-{
- int fd;
- char *string_table;
- size_t string_table_size;
- struct gconvcache_header header;
- struct hash_entry *hash_table;
- size_t hash_size;
- struct module_entry *module_table;
- char *extra_table;
- char *cur_extra_table;
- size_t n;
- int idx;
- struct iovec iov[6];
- static const gidx_t null_word;
- size_t total;
- char tmpfname[sizeof (GCONV_MODULES_CACHE) + strlen (".XXXXXX")];
-
- /* Function to insert the names. */
- static void name_insert (const void *nodep, VISIT value, int level)
- {
- struct name *name;
- unsigned int idx;
- unsigned int hval2;
-
- if (value != leaf && value != postorder)
- return;
-
- name = *(struct name **) nodep;
- idx = name->hashval % hash_size;
- hval2 = 1 + name->hashval % (hash_size - 2);
-
- while (hash_table[idx].string_offset != 0)
- if ((idx += hval2) >= hash_size)
- idx -= hash_size;
-
- hash_table[idx].string_offset = strtaboffset (name->strent);
-
- assert (name->module_idx != -1);
- hash_table[idx].module_idx = name->module_idx;
- }
-
- /* Open the output file. */
- strcpy (stpcpy (tmpfname, GCONV_MODULES_CACHE), ".XXXXXX");
- fd = mkstemp (tmpfname);
- if (fd == -1)
- return 1;
-
- /* Create the string table. */
- string_table = strtabfinalize (strtab, &string_table_size);
-
- /* Create the hashing table. We know how many strings we have.
- Creating a perfect hash table is not reasonable here. Therefore
- we use open hashing and a table size which is the next prime 40%
- larger than the number of strings. */
- hash_size = next_prime (nnames * 1.4);
- hash_table = (struct hash_entry *) xcalloc (hash_size,
- sizeof (struct hash_entry));
- /* Fill the hash table. */
- twalk (names, name_insert);
-
- /* Create the section for the module list. */
- module_table = (struct module_entry *) xcalloc (sizeof (struct module_entry),
- nname_info);
-
- /* Allocate memory for the non-INTERNAL conversions. The allocated
- memory can be more than is actually needed. */
- extra_table = (char *) xcalloc (sizeof (struct extra_entry)
- + sizeof (gidx_t)
- + sizeof (struct extra_entry_module),
- nextra_modules);
- cur_extra_table = extra_table;
-
- /* Fill in the module information. */
- for (n = 0; n < nname_info; ++n)
- {
- module_table[n].canonname_offset =
- strtaboffset (name_info[n].canonical_strent);
-
- if (name_info[n].from_internal == NULL)
- {
- module_table[n].fromdir_offset = 0;
- module_table[n].fromname_offset = 0;
- }
- else
- {
- module_table[n].fromdir_offset =
- strtaboffset (name_info[n].from_internal->directory_strent);
- module_table[n].fromname_offset =
- strtaboffset (name_info[n].from_internal->filename_strent);
- }
-
- if (name_info[n].to_internal == NULL)
- {
- module_table[n].todir_offset = 0;
- module_table[n].toname_offset = 0;
- }
- else
- {
- module_table[n].todir_offset =
- strtaboffset (name_info[n].to_internal->directory_strent);
- module_table[n].toname_offset =
- strtaboffset (name_info[n].to_internal->filename_strent);
- }
-
- if (name_info[n].other_conv_list != NULL)
- {
- struct other_conv_list *other = name_info[n].other_conv_list;
-
- /* Store the reference. We add 1 to distinguish the entry
- at offset zero from the case where no extra modules are
- available. The file reader has to account for the
- offset. */
- module_table[n].extra_offset = 1 + cur_extra_table - extra_table;
-
- do
- {
- struct other_conv *runp;
- struct extra_entry *extra;
-
- /* Allocate new entry. */
- extra = (struct extra_entry *) cur_extra_table;
- cur_extra_table += sizeof (struct extra_entry);
- extra->module_cnt = 0;
-
- runp = &other->other_conv;
- do
- {
- cur_extra_table += sizeof (struct extra_entry_module);
- extra->module[extra->module_cnt].outname_offset =
- runp->next == NULL
- ? other->dest_idx : runp->next->module_idx;
- extra->module[extra->module_cnt].dir_offset =
- strtaboffset (runp->module->directory_strent);
- extra->module[extra->module_cnt].name_offset =
- strtaboffset (runp->module->filename_strent);
- ++extra->module_cnt;
-
- runp = runp->next;
- }
- while (runp != NULL);
-
- other = other->next;
- }
- while (other != NULL);
-
- /* Final module_cnt is zero. */
- *((gidx_t *) cur_extra_table) = 0;
- cur_extra_table += sizeof (gidx_t);
- }
- }
-
- header.magic = GCONVCACHE_MAGIC;
-
- iov[0].iov_base = &header;
- iov[0].iov_len = sizeof (struct gconvcache_header);
- total = iov[0].iov_len;
-
- header.string_offset = total;
- iov[1].iov_base = string_table;
- iov[1].iov_len = string_table_size;
- total += iov[1].iov_len;
-
- idx = 2;
- if ((string_table_size & (sizeof (gidx_t) - 1)) != 0)
- {
- iov[2].iov_base = (void *) &null_word;
- iov[2].iov_len = (sizeof (gidx_t)
- - (string_table_size & (sizeof (gidx_t) - 1)));
- total += iov[2].iov_len;
- ++idx;
- }
-
- header.hash_offset = total;
- header.hash_size = hash_size;
- iov[idx].iov_base = hash_table;
- iov[idx].iov_len = hash_size * sizeof (struct hash_entry);
- total += iov[idx].iov_len;
- ++idx;
-
- header.module_offset = total;
- iov[idx].iov_base = module_table;
- iov[idx].iov_len = nname_info * sizeof (struct module_entry);
- total += iov[idx].iov_len;
- ++idx;
-
- assert (cur_extra_table - extra_table
- <= ((sizeof (struct extra_entry) + sizeof (gidx_t)
- + sizeof (struct extra_entry_module))
- * nextra_modules));
- header.otherconv_offset = total;
- iov[idx].iov_base = extra_table;
- iov[idx].iov_len = cur_extra_table - extra_table;
- total += iov[idx].iov_len;
- ++idx;
-
- if (TEMP_FAILURE_RETRY (writev (fd, iov, idx)) != total
- /* The file was created with mode 0600. Make it world-readable. */
- || fchmod (fd, 0644) != 0
- /* Rename the file, possibly replacing an old one. */
- || rename (tmpfname, GCONV_MODULES_CACHE) != 0)
- {
- int save_errno = errno;
- close (fd);
- unlink (tmpfname);
- error (EXIT_FAILURE, save_errno,
- gettext ("cannot generate output file"));
- }
-
- close (fd);
-
- return 0;
-}
diff --git a/newlib/libc/sys/linux/iconv/strtab.c b/newlib/libc/sys/linux/iconv/strtab.c
deleted file mode 100644
index 0f5e2b632..000000000
--- a/newlib/libc/sys/linux/iconv/strtab.c
+++ /dev/null
@@ -1,341 +0,0 @@
-/* C string table handling.
- Copyright (C) 2000, 2001 Free Software Foundation, Inc.
- Written by Ulrich Drepper <drepper@redhat.com>, 2000.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <assert.h>
-#include <inttypes.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/cdefs.h>
-#include <sys/param.h>
-
-
-struct Strent
-{
- const char *string;
- size_t len;
- struct Strent *next;
- struct Strent *left;
- struct Strent *right;
- size_t offset;
- char reverse[0];
-};
-
-
-struct memoryblock
-{
- struct memoryblock *next;
- char memory[0];
-};
-
-
-struct Strtab
-{
- struct Strent *root;
- struct memoryblock *memory;
- char *backp;
- size_t left;
- size_t total;
-
- struct Strent null;
-};
-
-
-/* Cache for the pagesize. We correct this value a bit so that `malloc'
- is not allocating more than a page. */
-static size_t ps;
-
-
-extern void *xmalloc (size_t n) __attribute_malloc__;
-
-/* Prototypes for our functions that are used from iconvconfig.c. If
- you change these, change also iconvconfig.c. */
-/* Create new C string table object in memory. */
-extern struct Strtab *strtabinit (void);
-
-/* Free resources allocated for C string table ST. */
-extern void strtabfree (struct Strtab *st);
-
-/* Add string STR (length LEN is != 0) to C string table ST. */
-extern struct Strent *strtabadd (struct Strtab *st, const char *str,
- size_t len);
-
-/* Finalize string table ST and store size in *SIZE and return a pointer. */
-extern void *strtabfinalize (struct Strtab *st, size_t *size);
-
-/* Get offset in string table for string associated with SE. */
-extern size_t strtaboffset (struct Strent *se);
-
-
-struct Strtab *
-strtabinit (void)
-{
- struct Strtab *ret;
-
- if (ps == 0)
- {
- ps = sysconf (_SC_PAGESIZE) - 2 * sizeof (void *);
- assert (sizeof (struct memoryblock) < ps);
- }
-
- ret = (struct Strtab *) calloc (1, sizeof (struct Strtab));
- if (ret != NULL)
- {
- ret->null.len = 1;
- ret->null.string = "";
- }
- return ret;
-}
-
-
-static void
-morememory (struct Strtab *st, size_t len)
-{
- struct memoryblock *newmem;
-
- if (len < ps)
- len = ps;
- newmem = (struct memoryblock *) malloc (len);
- if (newmem == NULL)
- abort ();
-
- newmem->next = st->memory;
- st->memory = newmem;
- st->backp = newmem->memory;
- st->left = len - offsetof (struct memoryblock, memory);
-}
-
-
-void
-strtabfree (struct Strtab *st)
-{
- struct memoryblock *mb = st->memory;
-
- while (mb != NULL)
- {
- void *old = mb;
- mb = mb->next;
- free (old);
- }
-
- free (st);
-}
-
-
-static struct Strent *
-newstring (struct Strtab *st, const char *str, size_t len)
-{
- struct Strent *newstr;
- size_t align;
- int i;
-
- /* Compute the amount of padding needed to make the structure aligned. */
- align = ((__alignof__ (struct Strent)
- - (((uintptr_t) st->backp)
- & (__alignof__ (struct Strent) - 1)))
- & (__alignof__ (struct Strent) - 1));
-
- /* Make sure there is enough room in the memory block. */
- if (st->left < align + sizeof (struct Strent) + len)
- {
- morememory (st, sizeof (struct Strent) + len);
- align = 0;
- }
-
- /* Create the reserved string. */
- newstr = (struct Strent *) (st->backp + align);
- newstr->string = str;
- newstr->len = len;
- newstr->next = NULL;
- newstr->left = NULL;
- newstr->right = NULL;
- newstr->offset = 0;
- for (i = len - 2; i >= 0; --i)
- newstr->reverse[i] = str[len - 2 - i];
- newstr->reverse[len - 1] = '\0';
- st->backp += align + sizeof (struct Strent) + len;
- st->left -= align + sizeof (struct Strent) + len;
-
- return newstr;
-}
-
-
-/* XXX This function should definitely be rewritten to use a balancing
- tree algorith (AVL, red-black trees). For now a simple, correct
- implementation is enough. */
-static struct Strent **
-searchstring (struct Strent **sep, struct Strent *newstr)
-{
- int cmpres;
-
- /* More strings? */
- if (*sep == NULL)
- {
- *sep = newstr;
- return sep;
- }
-
- /* Compare the strings. */
- cmpres = memcmp ((*sep)->reverse, newstr->reverse,
- MIN ((*sep)->len, newstr->len) - 1);
- if (cmpres == 0)
- /* We found a matching string. */
- return sep;
- else if (cmpres > 0)
- return searchstring (&(*sep)->left, newstr);
- else
- return searchstring (&(*sep)->right, newstr);
-}
-
-
-/* Add new string. The actual string is assumed to be permanent. */
-struct Strent *
-strtabadd (struct Strtab *st, const char *str, size_t len)
-{
- struct Strent *newstr;
- struct Strent **sep;
-
- /* Compute the string length if the caller doesn't know it. */
- if (len == 0)
- len = strlen (str) + 1;
-
- /* Make sure all "" strings get offset 0. */
- if (len == 1)
- return &st->null;
-
- /* Allocate memory for the new string and its associated information. */
- newstr = newstring (st, str, len);
-
- /* Search in the array for the place to insert the string. If there
- is no string with matching prefix and no string with matching
- leading substring, create a new entry. */
- sep = searchstring (&st->root, newstr);
- if (*sep != newstr)
- {
- /* This is not the same entry. This means we have a prefix match. */
- if ((*sep)->len > newstr->len)
- {
- struct Strent *subs;
-
- for (subs = (*sep)->next; subs; subs = subs->next)
- if (subs->len == newstr->len)
- {
- /* We have an exact match with a substring. Free the memory
- we allocated. */
- st->left += st->backp - (char *) newstr;
- st->backp = (char *) newstr;
-
- return subs;
- }
-
- /* We have a new substring. This means we don't need the reverse
- string of this entry anymore. */
- st->backp -= newstr->len;
- st->left += newstr->len;
-
- newstr->next = (*sep)->next;
- (*sep)->next = newstr;
- }
- else if ((*sep)->len != newstr->len)
- {
- /* When we get here it means that the string we are about to
- add has a common prefix with a string we already have but
- it is longer. In this case we have to put it first. */
- st->total += newstr->len - (*sep)->len;
- newstr->next = *sep;
- newstr->left = (*sep)->left;
- newstr->right = (*sep)->right;
- *sep = newstr;
- }
- else
- {
- /* We have an exact match. Free the memory we allocated. */
- st->left += st->backp - (char *) newstr;
- st->backp = (char *) newstr;
-
- newstr = *sep;
- }
- }
- else
- st->total += newstr->len;
-
- return newstr;
-}
-
-
-static void
-copystrings (struct Strent *nodep, char **freep, size_t *offsetp)
-{
- struct Strent *subs;
-
- if (nodep->left != NULL)
- copystrings (nodep->left, freep, offsetp);
-
- /* Process the current node. */
- nodep->offset = *offsetp;
- *freep = (char *) memcpy (*freep, nodep->string, nodep->len);
- *freep += nodep->len;
- *offsetp += nodep->len;
-
- for (subs = nodep->next; subs != NULL; subs = subs->next)
- {
- assert (subs->len < nodep->len);
- subs->offset = nodep->offset + nodep->len - subs->len;
- }
-
- if (nodep->right != NULL)
- copystrings (nodep->right, freep, offsetp);
-}
-
-
-void *
-strtabfinalize (struct Strtab *st, size_t *size)
-{
- size_t copylen;
- char *endp;
- char *retval;
-
- /* Fill in the information. */
- endp = retval = (char *) xmalloc (st->total + 1);
-
- /* Always put an empty string at the beginning so that a zero offset
- can mean error. */
- *endp++ = '\0';
-
- /* Now run through the tree and add all the string while also updating
- the offset members of the elfstrent records. */
- copylen = 1;
- copystrings (st->root, &endp, &copylen);
- assert (copylen == st->total + 1);
- assert (endp = retval + st->total + 1);
- *size = copylen;
-
- return retval;
-}
-
-
-size_t
-strtaboffset (struct Strent *se)
-{
- return se->offset;
-}
diff --git a/newlib/libc/sys/linux/include/arpa/nameser.h b/newlib/libc/sys/linux/include/arpa/nameser.h
index 8735b8bd3..6209afdf7 100644
--- a/newlib/libc/sys/linux/include/arpa/nameser.h
+++ b/newlib/libc/sys/linux/include/arpa/nameser.h
@@ -202,7 +202,11 @@ typedef enum __ns_rcode {
ns_r_nxrrset = 8, /* RRset does not exist */
ns_r_notauth = 9, /* Not authoritative for zone */
ns_r_notzone = 10, /* Zone of record different from zone section */
- ns_r_max = 11
+ ns_r_max = 11,
+ /* The following are TSIG extended errors */
+ ns_r_badsig = 16,
+ ns_r_badkey = 17,
+ ns_r_badtime = 18
} ns_rcode;
/* BIND_UPDATE */
@@ -213,6 +217,104 @@ typedef enum __ns_update_operation {
} ns_update_operation;
/*
+ * * This structure is used for TSIG authenticated messages
+ * */
+struct ns_tsig_key {
+ char name[NS_MAXDNAME], alg[NS_MAXDNAME];
+ unsigned char *data;
+ int len;
+};
+typedef struct ns_tsig_key ns_tsig_key;
+
+/*
+ * * This structure is used for TSIG authenticated TCP messages
+ * */
+struct ns_tcp_tsig_state {
+ int counter;
+ struct dst_key *key;
+ void *ctx;
+ unsigned char sig[NS_PACKETSZ];
+ int siglen;
+};
+typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
+
+#define NS_TSIG_FUDGE 300
+#define NS_TSIG_TCP_COUNT 100
+#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
+
+#define NS_TSIG_ERROR_NO_TSIG -10
+#define NS_TSIG_ERROR_NO_SPACE -11
+#define NS_TSIG_ERROR_FORMERR -12
+
+/*
+ * Currently defined type values for resources and queries.
+ */
+typedef enum __ns_type {
+ ns_t_invalid = 0, /* Cookie. */
+ ns_t_a = 1, /* Host address. */
+ ns_t_ns = 2, /* Authoritative server. */
+ ns_t_md = 3, /* Mail destination. */
+ ns_t_mf = 4, /* Mail forwarder. */
+ ns_t_cname = 5, /* Canonical name. */
+ ns_t_soa = 6, /* Start of authority zone. */
+ ns_t_mb = 7, /* Mailbox domain name. */
+ ns_t_mg = 8, /* Mail group member. */
+ ns_t_mr = 9, /* Mail rename name. */
+ ns_t_null = 10, /* Null resource record. */
+ ns_t_wks = 11, /* Well known service. */
+ ns_t_ptr = 12, /* Domain name pointer. */
+ ns_t_hinfo = 13, /* Host information. */
+ ns_t_minfo = 14, /* Mailbox information. */
+ ns_t_mx = 15, /* Mail routing information. */
+ ns_t_txt = 16, /* Text strings. */
+ ns_t_rp = 17, /* Responsible person. */
+ ns_t_afsdb = 18, /* AFS cell database. */
+ ns_t_x25 = 19, /* X_25 calling address. */
+ ns_t_isdn = 20, /* ISDN calling address. */
+ ns_t_rt = 21, /* Router. */
+ ns_t_nsap = 22, /* NSAP address. */
+ ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
+ ns_t_sig = 24, /* Security signature. */
+ ns_t_key = 25, /* Security key. */
+ ns_t_px = 26, /* X.400 mail mapping. */
+ ns_t_gpos = 27, /* Geographical position (withdrawn). */
+ ns_t_aaaa = 28, /* Ip6 Address. */
+ ns_t_loc = 29, /* Location Information. */
+ ns_t_nxt = 30, /* Next domain (security). */
+ ns_t_eid = 31, /* Endpoint identifier. */
+ ns_t_nimloc = 32, /* Nimrod Locator. */
+ ns_t_srv = 33, /* Server Selection. */
+ ns_t_atma = 34, /* ATM Address */
+ ns_t_naptr = 35, /* Naming Authority PoinTeR */
+ ns_t_kx = 36, /* Key Exchange */
+ ns_t_cert = 37, /* Certification record */
+ ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */
+ ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */
+ ns_t_sink = 40, /* Kitchen sink (experimentatl) */
+ ns_t_opt = 41, /* EDNS0 option (meta-RR) */
+ ns_t_tsig = 250, /* Transaction signature. */
+ ns_t_ixfr = 251, /* Incremental zone transfer. */
+ ns_t_axfr = 252, /* Transfer zone of authority. */
+ ns_t_mailb = 253, /* Transfer mailbox records. */
+ ns_t_maila = 254, /* Transfer mail agent records. */
+ ns_t_any = 255, /* Wildcard match. */
+ ns_t_zxfr = 256, /* BIND-specific, nonstandard. */
+ ns_t_max = 65536
+} ns_type;
+
+/* Exclusively a QTYPE? (not also an RTYPE) */
+#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
+ (t) == ns_t_mailb || (t) == ns_t_maila)
+/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
+#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
+/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
+#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
+#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
+#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
+ (t) == ns_t_zxfr)
+
+
+/*
* This RR-like structure is particular to UPDATE.
*/
struct ns_updrec {
@@ -234,54 +336,6 @@ struct ns_updrec {
};
typedef struct ns_updrec ns_updrec;
-/*
- * Currently defined type values for resources and queries.
- */
-typedef enum __ns_type {
- ns_t_a = 1, /* Host address. */
- ns_t_ns = 2, /* Authoritative server. */
- ns_t_md = 3, /* Mail destination. */
- ns_t_mf = 4, /* Mail forwarder. */
- ns_t_cname = 5, /* Canonical name. */
- ns_t_soa = 6, /* Start of authority zone. */
- ns_t_mb = 7, /* Mailbox domain name. */
- ns_t_mg = 8, /* Mail group member. */
- ns_t_mr = 9, /* Mail rename name. */
- ns_t_null = 10, /* Null resource record. */
- ns_t_wks = 11, /* Well known service. */
- ns_t_ptr = 12, /* Domain name pointer. */
- ns_t_hinfo = 13, /* Host information. */
- ns_t_minfo = 14, /* Mailbox information. */
- ns_t_mx = 15, /* Mail routing information. */
- ns_t_txt = 16, /* Text strings. */
- ns_t_rp = 17, /* Responsible person. */
- ns_t_afsdb = 18, /* AFS cell database. */
- ns_t_x25 = 19, /* X_25 calling address. */
- ns_t_isdn = 20, /* ISDN calling address. */
- ns_t_rt = 21, /* Router. */
- ns_t_nsap = 22, /* NSAP address. */
- ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
- ns_t_sig = 24, /* Security signature. */
- ns_t_key = 25, /* Security key. */
- ns_t_px = 26, /* X.400 mail mapping. */
- ns_t_gpos = 27, /* Geographical position (withdrawn). */
- ns_t_aaaa = 28, /* Ip6 Address. */
- ns_t_loc = 29, /* Location Information. */
- ns_t_nxt = 30, /* Next domain (security). */
- ns_t_eid = 31, /* Endpoint identifier. */
- ns_t_nimloc = 32, /* Nimrod Locator. */
- ns_t_srv = 33, /* Server Selection. */
- ns_t_atma = 34, /* ATM Address */
- ns_t_naptr = 35, /* Naming Authority PoinTeR */
- ns_t_opt = 41, /* OPT pseudo-RR, RFC2761 */
- /* Query type values which do not appear in resource records. */
- ns_t_ixfr = 251, /* Incremental zone transfer. */
- ns_t_axfr = 252, /* Transfer zone of authority. */
- ns_t_mailb = 253, /* Transfer mailbox records. */
- ns_t_maila = 254, /* Transfer mail agent records. */
- ns_t_any = 255, /* Wildcard match. */
- ns_t_max = 65536
-} ns_type;
/*
* Values for class field
@@ -297,6 +351,24 @@ typedef enum __ns_class {
ns_c_max = 65536
} ns_class;
+/* DNSSEC constants. */
+
+typedef enum __ns_key_types {
+ ns_kt_rsa = 1, /* key type RSA/MD5 */
+ ns_kt_dh = 2, /* Diffie Hellman */
+ ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */
+ ns_kt_private = 254 /* Private key type starts with OID */
+} ns_key_types;
+
+typedef enum __ns_cert_types {
+ cert_t_pkix = 1, /* PKIX (X.509v3) */
+ cert_t_spki = 2, /* SPKI */
+ cert_t_pgp = 3, /* PGP */
+ cert_t_url = 253, /* URL private type */
+ cert_t_oid = 254 /* OID private type */
+} ns_cert_types;
+
+
/*
* Flags field of the KEY RR rdata
*/
@@ -327,6 +399,10 @@ typedef enum __ns_class {
/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
#define NS_ALG_MD5RSA 1 /* MD5 with RSA */
+#define NS_ALG_DH 2 /* Diffie Hellman KEY */
+#define NS_ALG_DSA 3 /* DSA KEY */
+#define NS_ALG_DSS NS_ALG_DSA
+
#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */
#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */
diff --git a/newlib/libc/sys/linux/include/hesiod.h b/newlib/libc/sys/linux/include/hesiod.h
index c7dbeee33..82fce3076 100644
--- a/newlib/libc/sys/linux/include/hesiod.h
+++ b/newlib/libc/sys/linux/include/hesiod.h
@@ -1,42 +1,5 @@
-/* $NetBSD: hesiod.h,v 1.3 1999/01/24 23:53:18 lukem Exp $ */
-/* $FreeBSD: src/include/hesiod.h,v 1.2 2002/03/23 17:24:53 imp Exp $ */
-
-
-/*-
- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, 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.
- * 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 the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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.
- */
-
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 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
@@ -52,47 +15,26 @@
* SOFTWARE.
*/
-#ifndef _HESIOD_H_
-#define _HESIOD_H_
-
- /* Application-visible indication that we have the new interfaces */
-
-#define HESIOD_INTERFACES
-
- /* Configuration information. */
-
-#ifndef _PATH_HESIOD_CONF /* Configuration file. */
-#define _PATH_HESIOD_CONF "/etc/hesiod.conf"
-#endif
-
-#define DEF_RHS "" /* Defaults if HESIOD_CONF */
-#define DEF_LHS "" /* file is not present. */
-
- /* Error codes (for backwards compatibility) */
-
-#define HES_ER_UNINIT -1 /* uninitialized */
-#define HES_ER_OK 0 /* no error */
-#define HES_ER_NOTFOUND 1 /* Hesiod name not found by server */
-#define HES_ER_CONFIG 2 /* local problem (no config file?) */
-#define HES_ER_NET 3 /* network problem */
-
- /* Declaration of routines */
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int hesiod_init(void **);
-char **hesiod_resolve(void *, const char *, const char *);
-void hesiod_free_list(void *, char **);
-char *hesiod_to_bind(void *, const char *, const char *);
-void hesiod_end(void *);
+/*
+ * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>.
+ */
- /* backwards compatibility */
-int hes_init(void);
-char *hes_to_bind(const char *, const char *);
-char **hes_resolve(const char *, const char *);
-int hes_error(void);
-void hes_free(char **);
-__END_DECLS
+/*
+ * $BINDId: hesiod.h,v 1.7 1999/01/08 19:22:45 vixie Exp $
+ */
-#endif /* ! _HESIOD_H_ */
+#ifndef _HESIOD_H_INCLUDED
+#define _HESIOD_H_INCLUDED
+
+int hesiod_init (void **context);
+void hesiod_end (void *context);
+char * hesiod_to_bind (void *context, const char *name,
+ const char *type);
+char ** hesiod_resolve (void *context, const char *name,
+ const char *type);
+void hesiod_free_list (void *context, char **list);
+struct __res_state * __hesiod_res_get (void *context);
+void __hesiod_res_set (void *context, struct __res_state *,
+ void (*)(void *));
+
+#endif /*_HESIOD_H_INCLUDED*/
diff --git a/newlib/libc/sys/linux/include/libc_private.h b/newlib/libc/sys/linux/include/libc_private.h
deleted file mode 100644
index af7df8c8b..000000000
--- a/newlib/libc/sys/linux/include/libc_private.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
- * 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 John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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.
- *
- * $FreeBSD: src/lib/libc/include/libc_private.h,v 1.5 2002/03/29 22:43:42 markm Exp $
- *
- * Private definitions for libc, libc_r and libpthread.
- *
- */
-
-#ifndef _LIBC_PRIVATE_H_
-#define _LIBC_PRIVATE_H_
-
-/*
- * This global flag is non-zero when a process has created one
- * or more threads. It is used to avoid calling locking functions
- * when they are not required.
- */
-extern int __isthreaded;
-
-/*
- * File lock contention is difficult to diagnose without knowing
- * where locks were set. Allow a debug library to be built which
- * records the source file and line number of each lock call.
- */
-#ifdef _FLOCK_DEBUG
-#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__)
-#else
-#define _FLOCKFILE(x) _flockfile(x)
-#endif
-
-/*
- * Macros for locking and unlocking FILEs. These test if the
- * process is threaded to avoid locking when not required.
- */
-#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp)
-#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp)
-
-/*
- * This is a pointer in the C run-time startup code. It is used
- * by getprogname() and setprogname().
- */
-extern const char *__progname;
-
-#endif /* _LIBC_PRIVATE_H_ */
diff --git a/newlib/libc/sys/linux/include/net/ethernet.h b/newlib/libc/sys/linux/include/net/ethernet.h
index 6b1d1c9be..7ca8e8348 100644
--- a/newlib/libc/sys/linux/include/net/ethernet.h
+++ b/newlib/libc/sys/linux/include/net/ethernet.h
@@ -1,75 +1,66 @@
-/*
- * Fundamental constants relating to ethernet.
- *
- * $FreeBSD: src/sys/net/ethernet.h,v 1.20 2002/04/04 05:42:09 luigi Exp $
- *
- */
+/* Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-#ifndef _NET_ETHERNET_H_
-#define _NET_ETHERNET_H_
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
-/*
- * The number of bytes in an ethernet (MAC) address.
- */
-#define ETHER_ADDR_LEN 6
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
-/*
- * The number of bytes in the type field.
- */
-#define ETHER_TYPE_LEN 2
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
-/*
- * The number of bytes in the trailing CRC field.
- */
-#define ETHER_CRC_LEN 4
+/* Based on the FreeBSD version of this file. Curiously, that file
+ lacks a copyright in the header. */
-/*
- * The length of the combined header.
- */
-#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
+#ifndef __NET_ETHERNET_H
+#define __NET_ETHERNET_H 1
-/*
- * The minimum packet length.
- */
-#define ETHER_MIN_LEN 64
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <linux/if_ether.h> /* IEEE 802.3 Ethernet constants */
-/*
- * The maximum packet length.
- */
-#define ETHER_MAX_LEN 1518
+__BEGIN_DECLS
-/*
- * A macro to validate a length with
- */
+/* This is a name for the 48 bit ethernet address available on many
+ systems. */
+struct ether_addr
+{
+ u_int8_t ether_addr_octet[ETH_ALEN];
+} __attribute__ ((__packed__));
+
+/* 10Mb/s ethernet header */
+struct ether_header
+{
+ u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
+ u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
+ u_int16_t ether_type; /* packet type ID field */
+} __attribute__ ((__packed__));
+
+/* Ethernet protocol ID's */
+#define ETHERTYPE_PUP 0x0200 /* Xerox PUP */
+#define ETHERTYPE_IP 0x0800 /* IP */
+#define ETHERTYPE_ARP 0x0806 /* Address resolution */
+#define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */
+
+#define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */
+#define ETHER_TYPE_LEN 2 /* bytes in type field */
+#define ETHER_CRC_LEN 4 /* bytes in CRC field */
+#define ETHER_HDR_LEN ETH_HLEN /* total octets in header */
+#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
+#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
+
+/* make sure ethenet length is valid */
#define ETHER_IS_VALID_LEN(foo) \
((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
/*
- * Structure of a 10Mb/s Ethernet header.
- */
-struct ether_header {
- u_char ether_dhost[ETHER_ADDR_LEN];
- u_char ether_shost[ETHER_ADDR_LEN];
- u_short ether_type;
-};
-
-/*
- * Structure of a 48-bit Ethernet address.
- */
-struct ether_addr {
- u_char octet[ETHER_ADDR_LEN];
-};
-
-#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
-#define ETHERTYPE_IP 0x0800 /* IP protocol */
-#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
-#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
-#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
-#define ETHERTYPE_IPV6 0x86dd /* IPv6 */
-#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
-/* XXX - add more useful types here */
-
-/*
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
* by an ETHER type (as given above) and then the (variable-length) header.
@@ -77,58 +68,9 @@ struct ether_addr {
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
#define ETHERTYPE_NTRAILER 16
-#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
-#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
+#define ETHERMTU ETH_DATA_LEN
+#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
-#ifdef _KERNEL
-
-/*
- * For device drivers to specify whether they support BPF or not
- */
-#define ETHER_BPF_UNSUPPORTED 0
-#define ETHER_BPF_SUPPORTED 1
-
-struct ifnet;
-struct mbuf;
-
-extern void (*ng_ether_input_p)(struct ifnet *ifp,
- struct mbuf **mp, struct ether_header *eh);
-extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp,
- struct mbuf *m, struct ether_header *eh);
-extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp);
-extern void (*ng_ether_attach_p)(struct ifnet *ifp);
-extern void (*ng_ether_detach_p)(struct ifnet *ifp);
-
-extern int (*vlan_input_p)(struct ether_header *eh, struct mbuf *m);
-extern int (*vlan_input_tag_p)(struct ether_header *eh, struct mbuf *m,
- u_int16_t t);
-
-#define VLAN_INPUT_TAG(eh, m, t) do { \
- /* XXX: lock */ \
- if (vlan_input_tag_p != NULL) \
- (*vlan_input_tag_p)(eh, m, t); \
- else { \
- (m)->m_pkthdr.rcvif->if_noproto++; \
- m_freem(m); \
- } \
- /* XXX: unlock */ \
-} while (0)
-
-#else /* _KERNEL */
-
-#include <sys/cdefs.h>
-
-/*
- * Ethernet address conversion/parsing routines.
- */
-__BEGIN_DECLS
-struct ether_addr *ether_aton(const char *);
-int ether_hostton(const char *, struct ether_addr *);
-int ether_line(const char *, struct ether_addr *, char *);
-char *ether_ntoa(const struct ether_addr *);
-int ether_ntohost(char *, const struct ether_addr *);
__END_DECLS
-#endif /* !_KERNEL */
-
-#endif /* !_NET_ETHERNET_H_ */
+#endif /* net/ethernet.h */
diff --git a/newlib/libc/sys/linux/include/net/if_atm.h b/newlib/libc/sys/linux/include/net/if_atm.h
deleted file mode 100644
index c9ff107c0..000000000
--- a/newlib/libc/sys/linux/include/net/if_atm.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* $NetBSD: if_atm.h,v 1.7 1996/11/09 23:02:27 chuck Exp $ */
-/* $FreeBSD: src/sys/net/if_atm.h,v 1.5 2002/03/19 21:54:16 alfred Exp $ */
-
-/*
- *
- * Copyright (c) 1996 Charles D. Cranor and Washington University.
- * 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 Charles D. Cranor and
- * Washington University.
- * 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.
- */
-
-/*
- * net/if_atm.h
- */
-
-#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
-#define RTALLOC1(A,B) rtalloc1((A),(B))
-#elif defined(__FreeBSD__)
-#define RTALLOC1(A,B) rtalloc1((A),(B),0UL)
-#endif
-
-/*
- * pseudo header for packet transmission
- */
-struct atm_pseudohdr {
- u_int8_t atm_ph[4]; /* flags+VPI+VCI1(msb)+VCI2(lsb) */
-};
-
-#define ATM_PH_FLAGS(X) ((X)->atm_ph[0])
-#define ATM_PH_VPI(X) ((X)->atm_ph[1])
-#define ATM_PH_VCI(X) ((((X)->atm_ph[2]) << 8) | ((X)->atm_ph[3]))
-#define ATM_PH_SETVCI(X,V) { \
- (X)->atm_ph[2] = ((V) >> 8) & 0xff; \
- (X)->atm_ph[3] = ((V) & 0xff); \
-}
-
-#define ATM_PH_AAL5 0x01 /* use AAL5? (0 == aal0) */
-#define ATM_PH_LLCSNAP 0x02 /* use the LLC SNAP encoding (iff aal5) */
-
-#define ATM_PH_DRIVER7 0x40 /* reserve for driver's use */
-#define ATM_PH_DRIVER8 0x80 /* reserve for driver's use */
-
-#define ATMMTU 9180 /* ATM MTU size for IP */
- /* XXX: could be 9188 with LLC/SNAP according
- to comer */
-
-/* user's ioctl hook for raw atm mode */
-#define SIOCRAWATM _IOWR('a', 122, int) /* set driver's raw mode */
-
-/* atm_pseudoioctl: turns on and off RX VCIs [for internal use only!] */
-struct atm_pseudoioctl {
- struct atm_pseudohdr aph;
- void *rxhand;
-};
-#define SIOCATMENA _IOWR('a', 123, struct atm_pseudoioctl) /* enable */
-#define SIOCATMDIS _IOWR('a', 124, struct atm_pseudoioctl) /* disable */
-
-
-/*
- * XXX forget all the garbage in if_llc.h and do it the easy way
- */
-
-#define ATMLLC_HDR "\252\252\3\0\0\0"
-struct atmllc {
- u_int8_t llchdr[6]; /* aa.aa.03.00.00.00 */
- u_int8_t type[2]; /* "ethernet" type */
-};
-
-/* ATM_LLC macros: note type code in host byte order */
-#define ATM_LLC_TYPE(X) (((X)->type[0] << 8) | ((X)->type[1]))
-#define ATM_LLC_SETTYPE(X,V) { \
- (X)->type[1] = ((V) >> 8) & 0xff; \
- (X)->type[0] = ((V) & 0xff); \
-}
-
-#ifdef _KERNEL
-void atm_ifattach(struct ifnet *);
-void atm_input(struct ifnet *, struct atm_pseudohdr *,
- struct mbuf *, void *);
-int atm_output(struct ifnet *, struct mbuf *, struct sockaddr *,
- struct rtentry *);
-#endif
-
diff --git a/newlib/libc/sys/linux/include/net/if_media.h b/newlib/libc/sys/linux/include/net/if_media.h
deleted file mode 100644
index 80599bdc0..000000000
--- a/newlib/libc/sys/linux/include/net/if_media.h
+++ /dev/null
@@ -1,409 +0,0 @@
-/* $NetBSD: if_media.h,v 1.3 1997/03/26 01:19:27 thorpej Exp $ */
-/* $FreeBSD: src/sys/net/if_media.h,v 1.17 2002/05/07 18:16:39 imp Exp $ */
-
-/*
- * Copyright (c) 1997
- * Jonathan Stone and Jason R. Thorpe. All rights reserved.
- *
- * This software is derived from information provided by Matt Thomas.
- *
- * 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 Jonathan Stone
- * and Jason R. Thorpe for the NetBSD Project.
- * 4. The names of the authors may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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.
- */
-
-#ifndef _NET_IF_MEDIA_H_
-#define _NET_IF_MEDIA_H_
-
-/*
- * Prototypes and definitions for BSD/OS-compatible network interface
- * media selection.
- *
- * Where it is safe to do so, this code strays slightly from the BSD/OS
- * design. Software which uses the API (device drivers, basically)
- * shouldn't notice any difference.
- *
- * Many thanks to Matt Thomas for providing the information necessary
- * to implement this interface.
- */
-
-#ifdef _KERNEL
-
-#include <sys/queue.h>
-
-/*
- * Driver callbacks for media status and change requests.
- */
-typedef int (*ifm_change_cb_t)(struct ifnet *ifp);
-typedef void (*ifm_stat_cb_t)(struct ifnet *ifp, struct ifmediareq *req);
-
-/*
- * In-kernel representation of a single supported media type.
- */
-struct ifmedia_entry {
- LIST_ENTRY(ifmedia_entry) ifm_list;
- int ifm_media; /* description of this media attachment */
- int ifm_data; /* for driver-specific use */
- void *ifm_aux; /* for driver-specific use */
-};
-
-/*
- * One of these goes into a network interface's softc structure.
- * It is used to keep general media state.
- */
-struct ifmedia {
- int ifm_mask; /* mask of changes we don't care about */
- int ifm_media; /* current user-set media word */
- struct ifmedia_entry *ifm_cur; /* currently selected media */
- LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
- ifm_change_cb_t ifm_change; /* media change driver callback */
- ifm_stat_cb_t ifm_status; /* media status driver callback */
-};
-
-/* Initialize an interface's struct if_media field. */
-void ifmedia_init(struct ifmedia *ifm, int dontcare_mask,
- ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback);
-
-/* Remove all mediums from a struct ifmedia. */
-void ifmedia_removeall( struct ifmedia *ifm);
-
-/* Add one supported medium to a struct ifmedia. */
-void ifmedia_add(struct ifmedia *ifm, int mword, int data, void *aux);
-
-/* Add an array (of ifmedia_entry) media to a struct ifmedia. */
-void ifmedia_list_add(struct ifmedia *mp, struct ifmedia_entry *lp,
- int count);
-
-/* Set default media type on initialization. */
-void ifmedia_set(struct ifmedia *ifm, int mword);
-
-/* Common ioctl function for getting/setting media, called by driver. */
-int ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr,
- struct ifmedia *ifm, u_long cmd);
-
-#endif /*_KERNEL */
-
-/*
- * if_media Options word:
- * Bits Use
- * ---- -------
- * 0-4 Media variant
- * 5-7 Media type
- * 8-15 Type specific options
- * 16-19 RFU
- * 20-27 Shared (global) options
- * 28-31 Instance
- */
-
-/*
- * Ethernet
- */
-#define IFM_ETHER 0x00000020
-#define IFM_10_T 3 /* 10BaseT - RJ45 */
-#define IFM_10_2 4 /* 10Base2 - Thinnet */
-#define IFM_10_5 5 /* 10Base5 - AUI */
-#define IFM_100_TX 6 /* 100BaseTX - RJ45 */
-#define IFM_100_FX 7 /* 100BaseFX - Fiber */
-#define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */
-#define IFM_100_VG 9 /* 100VG-AnyLAN */
-#define IFM_100_T2 10 /* 100BaseT2 */
-#define IFM_1000_SX 11 /* 1000BaseSX - multi-mode fiber */
-#define IFM_10_STP 12 /* 10BaseT over shielded TP */
-#define IFM_10_FL 13 /* 10BaseFL - Fiber */
-#define IFM_1000_LX 14 /* 1000baseLX - single-mode fiber */
-#define IFM_1000_CX 15 /* 1000baseCX - 150ohm STP */
-#define IFM_1000_T 16 /* 1000baseT - 4 pair cat 5 */
-#define IFM_HPNA_1 17 /* HomePNA 1.0 (1Mb/s) */
-/* note 31 is the max! */
-
-#define IFM_ETH_MASTER 0x00000100 /* master mode (1000baseT) */
-
-/*
- * Token ring
- */
-#define IFM_TOKEN 0x00000040
-#define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */
-#define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */
-#define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */
-#define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */
-#define IFM_TOK_STP100 7 /* Shielded twisted pair 100m - DB9 */
-#define IFM_TOK_UTP100 8 /* Unshielded twisted pair 100m - RJ45 */
-#define IFM_TOK_ETR 0x00000200 /* Early token release */
-#define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */
-#define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */
-#define IFM_TOK_DTR 0x00002000 /* Dedicated token ring */
-#define IFM_TOK_CLASSIC 0x00004000 /* Classic token ring */
-#define IFM_TOK_AUTO 0x00008000 /* Automatic Dedicate/Classic token ring */
-
-/*
- * FDDI
- */
-#define IFM_FDDI 0x00000060
-#define IFM_FDDI_SMF 3 /* Single-mode fiber */
-#define IFM_FDDI_MMF 4 /* Multi-mode fiber */
-#define IFM_FDDI_UTP 5 /* CDDI / UTP */
-#define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */
-
-/*
- * IEEE 802.11 Wireless
- */
-#define IFM_IEEE80211 0x00000080
-#define IFM_IEEE80211_FH1 3 /* Frequency Hopping 1Mbps */
-#define IFM_IEEE80211_FH2 4 /* Frequency Hopping 2Mbps */
-#define IFM_IEEE80211_DS1 5 /* Direct Sequence 1Mbps */
-#define IFM_IEEE80211_DS2 6 /* Direct Sequence 2Mbps */
-#define IFM_IEEE80211_DS5 7 /* Direct Sequence 5.5Mbps */
-#define IFM_IEEE80211_DS11 8 /* Direct Sequence 11Mbps */
-#define IFM_IEEE80211_DS22 9 /* Direct Sequence 22Mbps */
-#define IFM_IEEE80211_ADHOC 0x00000100 /* Operate in Adhoc mode */
-#define IFM_IEEE80211_HOSTAP 0x00000200 /* Operate in Host AP mode */
-#define IFM_IEEE80211_IBSS 0x00000400 /* Operate in IBSS mode */
-#define IFM_IEEE80211_IBSSMASTER 0x00000800 /* Operate as an IBSS master */
-
-/*
- * Shared media sub-types
- */
-#define IFM_AUTO 0 /* Autoselect best media */
-#define IFM_MANUAL 1 /* Jumper/dipswitch selects media */
-#define IFM_NONE 2 /* Deselect all media */
-
-/*
- * Shared options
- */
-#define IFM_FDX 0x00100000 /* Force full duplex */
-#define IFM_HDX 0x00200000 /* Force half duplex */
-#define IFM_FLAG0 0x01000000 /* Driver defined flag */
-#define IFM_FLAG1 0x02000000 /* Driver defined flag */
-#define IFM_FLAG2 0x04000000 /* Driver defined flag */
-#define IFM_LOOP 0x08000000 /* Put hardware in loopback */
-
-/*
- * Masks
- */
-#define IFM_NMASK 0x000000e0 /* Network type */
-#define IFM_TMASK 0x0000001f /* Media sub-type */
-#define IFM_IMASK 0xf0000000 /* Instance */
-#define IFM_ISHIFT 28 /* Instance shift */
-#define IFM_OMASK 0x0000ff00 /* Type specific options */
-#define IFM_GMASK 0x0ff00000 /* Global options */
-
-/*
- * Status bits
- */
-#define IFM_AVALID 0x00000001 /* Active bit valid */
-#define IFM_ACTIVE 0x00000002 /* Interface attached to working net */
-
-/*
- * Macros to extract various bits of information from the media word.
- */
-#define IFM_TYPE(x) ((x) & IFM_NMASK)
-#define IFM_SUBTYPE(x) ((x) & IFM_TMASK)
-#define IFM_TYPE_OPTIONS(x) ((x) & IFM_OMASK)
-#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT)
-#define IFM_OPTIONS(x) ((x) & (IFM_OMASK|IFM_GMASK))
-
-#define IFM_INST_MAX IFM_INST(IFM_IMASK)
-
-/*
- * Macro to create a media word.
- */
-#define IFM_MAKEWORD(type, subtype, options, instance) \
- ((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
-
-/*
- * NetBSD extension not defined in the BSDI API. This is used in various
- * places to get the canonical description for a given type/subtype.
- *
- * NOTE: all but the top-level type descriptions must contain NO whitespace!
- * Otherwise, parsing these in ifconfig(8) would be a nightmare.
- */
-struct ifmedia_description {
- int ifmt_word; /* word value; may be masked */
- const char *ifmt_string; /* description */
-};
-
-#define IFM_TYPE_DESCRIPTIONS { \
- { IFM_ETHER, "Ethernet" }, \
- { IFM_TOKEN, "Token ring" }, \
- { IFM_FDDI, "FDDI" }, \
- { IFM_IEEE80211, "IEEE 802.11 Wireless Ethernet" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_ETHERNET_DESCRIPTIONS { \
- { IFM_10_T, "10baseT/UTP" }, \
- { IFM_10_2, "10base2/BNC" }, \
- { IFM_10_5, "10base5/AUI" }, \
- { IFM_100_TX, "100baseTX" }, \
- { IFM_100_FX, "100baseFX" }, \
- { IFM_100_T4, "100baseT4" }, \
- { IFM_100_VG, "100baseVG" }, \
- { IFM_100_T2, "100baseT2" }, \
- { IFM_10_STP, "10baseSTP" }, \
- { IFM_10_FL, "10baseFL" }, \
- { IFM_1000_SX, "1000baseSX" }, \
- { IFM_1000_LX, "1000baseLX" }, \
- { IFM_1000_CX, "1000baseCX" }, \
- { IFM_1000_T, "1000baseTX" }, \
- { IFM_1000_T, "1000baseT" }, \
- { IFM_HPNA_1, "homePNA" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_ETHERNET_ALIASES { \
- { IFM_10_T, "UTP" }, \
- { IFM_10_T, "10UTP" }, \
- { IFM_10_2, "BNC" }, \
- { IFM_10_2, "10BNC" }, \
- { IFM_10_5, "AUI" }, \
- { IFM_10_5, "10AUI" }, \
- { IFM_100_TX, "100TX" }, \
- { IFM_100_T4, "100T4" }, \
- { IFM_100_VG, "100VG" }, \
- { IFM_100_T2, "100T2" }, \
- { IFM_10_STP, "10STP" }, \
- { IFM_10_FL, "10FL" }, \
- { IFM_1000_SX, "1000SX" }, \
- { IFM_1000_LX, "1000LX" }, \
- { IFM_1000_CX, "1000CX" }, \
- { IFM_1000_T, "1000TX" }, \
- { IFM_1000_T, "1000T" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS { \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_TOKENRING_DESCRIPTIONS { \
- { IFM_TOK_STP4, "DB9/4Mbit" }, \
- { IFM_TOK_STP16, "DB9/16Mbit" }, \
- { IFM_TOK_UTP4, "UTP/4Mbit" }, \
- { IFM_TOK_UTP16, "UTP/16Mbit" }, \
- { IFM_TOK_STP100, "STP/100Mbit" }, \
- { IFM_TOK_UTP100, "UTP/100Mbit" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_TOKENRING_ALIASES { \
- { IFM_TOK_STP4, "4STP" }, \
- { IFM_TOK_STP16, "16STP" }, \
- { IFM_TOK_UTP4, "4UTP" }, \
- { IFM_TOK_UTP16, "16UTP" }, \
- { IFM_TOK_STP100, "100STP" }, \
- { IFM_TOK_UTP100, "100UTP" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS { \
- { IFM_TOK_ETR, "EarlyTokenRelease" }, \
- { IFM_TOK_SRCRT, "SourceRouting" }, \
- { IFM_TOK_ALLR, "AllRoutes" }, \
- { IFM_TOK_DTR, "Dedicated" }, \
- { IFM_TOK_CLASSIC,"Classic" }, \
- { IFM_TOK_AUTO, " " }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_FDDI_DESCRIPTIONS { \
- { IFM_FDDI_SMF, "Single-mode" }, \
- { IFM_FDDI_MMF, "Multi-mode" }, \
- { IFM_FDDI_UTP, "UTP" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_FDDI_ALIASES { \
- { IFM_FDDI_SMF, "SMF" }, \
- { IFM_FDDI_MMF, "MMF" }, \
- { IFM_FDDI_UTP, "CDDI" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS { \
- { IFM_FDDI_DA, "Dual-attach" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_IEEE80211_DESCRIPTIONS { \
- { IFM_IEEE80211_FH1, "FH/1Mbps" }, \
- { IFM_IEEE80211_FH2, "FH/2Mbps" }, \
- { IFM_IEEE80211_DS1, "DS/1Mbps" }, \
- { IFM_IEEE80211_DS2, "DS/2Mbps" }, \
- { IFM_IEEE80211_DS5, "DS/5.5Mbps" }, \
- { IFM_IEEE80211_DS11, "DS/11Mbps" }, \
- { IFM_IEEE80211_DS22, "DS/22Mbps" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_IEEE80211_ALIASES { \
- { IFM_IEEE80211_FH1, "FH1" }, \
- { IFM_IEEE80211_FH2, "FH2" }, \
- { IFM_IEEE80211_FH1, "FrequencyHopping/1Mbps" }, \
- { IFM_IEEE80211_FH2, "FrequencyHopping/2Mbps" }, \
- { IFM_IEEE80211_DS1, "DS1" }, \
- { IFM_IEEE80211_DS2, "DS2" }, \
- { IFM_IEEE80211_DS5, "DS5.5" }, \
- { IFM_IEEE80211_DS11, "DS11" }, \
- { IFM_IEEE80211_DS22, "DS22" }, \
- { IFM_IEEE80211_DS1, "DirectSequence/1Mbps" }, \
- { IFM_IEEE80211_DS2, "DirectSequence/2Mbps" }, \
- { IFM_IEEE80211_DS5, "DirectSequence/5.5Mbps" }, \
- { IFM_IEEE80211_DS11, "DirectSequence/11Mbps" }, \
- { IFM_IEEE80211_DS22, "DirectSequence/22Mbps" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS { \
- { IFM_IEEE80211_ADHOC, "adhoc" }, \
- { IFM_IEEE80211_HOSTAP, "hostap" }, \
- { IFM_IEEE80211_IBSS, "ibss" }, \
- { IFM_IEEE80211_IBSSMASTER, "ibss-master" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_SHARED_DESCRIPTIONS { \
- { IFM_AUTO, "autoselect" }, \
- { IFM_MANUAL, "manual" }, \
- { IFM_NONE, "none" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SUBTYPE_SHARED_ALIASES { \
- { IFM_AUTO, "auto" }, \
- { 0, NULL }, \
-}
-
-#define IFM_SHARED_OPTION_DESCRIPTIONS { \
- { IFM_FDX, "full-duplex" }, \
- { IFM_HDX, "half-duplex" }, \
- { IFM_FLAG0, "flag0" }, \
- { IFM_FLAG1, "flag1" }, \
- { IFM_FLAG2, "flag2" }, \
- { IFM_LOOP, "hw-loopback" }, \
- { 0, NULL }, \
-}
-
-#endif /* _NET_IF_MEDIA_H_ */
diff --git a/newlib/libc/sys/linux/include/net/if_ppp.h b/newlib/libc/sys/linux/include/net/if_ppp.h
index 0d4b6078f..bf5ec8387 100644
--- a/newlib/libc/sys/linux/include/net/if_ppp.h
+++ b/newlib/libc/sys/linux/include/net/if_ppp.h
@@ -1,41 +1,78 @@
+/* From: if_ppp.h,v 1.3 1995/06/12 11:36:50 paulus Exp */
+
/*
* if_ppp.h - Point-to-Point Protocol definitions.
*
- * Copyright (c) 1989 Carnegie Mellon University.
- * All rights reserved.
+ * Copyright (c) 1989 Carnegie Mellon University.
+ *
+ * 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.
*
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by Carnegie Mellon University. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY 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 UNIVERSITY 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.
+ *
+ */
+
+/*
+ * ==FILEVERSION 960926==
*
- * $FreeBSD: src/sys/net/if_ppp.h,v 1.14 1999/08/28 00:48:20 peter Exp $
+ * NOTE TO MAINTAINERS:
+ * If you modify this file at all, please set the above date.
+ * if_ppp.h is shipped with a PPP distribution as well as with the kernel;
+ * if everyone increases the FILEVERSION number above, then scripts
+ * can do the right thing when deciding whether to install a new if_ppp.h
+ * file. Don't change the format of that line otherwise, so the
+ * installation script can recognize it.
*/
-#ifndef _IF_PPP_H_
-#define _IF_PPP_H_
-/* XXX this used to be self-contained. */
-#include <net/ppp_defs.h>
+#ifndef __NET_IF_PPP_H
+#define __NET_IF_PPP_H 1
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
#include <net/if.h>
+#include <sys/ioctl.h>
+#include <net/ppp_defs.h>
+
+__BEGIN_DECLS
/*
* Packet sizes
*/
+
#define PPP_MTU 1500 /* Default MTU (size of Info field) */
#define PPP_MAXMRU 65000 /* Largest MRU we allow */
-#define PPP_MAXMTU 16384 /* Largest MTU we allow */
+#define PPP_VERSION "2.2.0"
+#define PPP_MAGIC 0x5002 /* Magic value for the ppp structure */
+#define PROTO_IPX 0x002b /* protocol numbers */
+#define PROTO_DNA_RT 0x0027 /* DNA Routing */
+
/*
* Bit definitions for flags.
*/
+
#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
#define SC_COMP_AC 0x00000002 /* header compression (output) */
#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
@@ -44,57 +81,57 @@
#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
+#define SC_ENABLE_IP 0x00000100 /* IP packets may be exchanged */
+#define SC_COMP_RUN 0x00001000 /* compressor has been inited */
+#define SC_DECOMP_RUN 0x00002000 /* decompressor has been inited */
#define SC_DEBUG 0x00010000 /* enable debug messages */
#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
-#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
-#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
-#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
-#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
-#define SC_MASK 0x0fff00ff /* bits that user can change */
+#define SC_MASK 0x0fE0ffff /* bits that user can change */
-/*
- * State bits in sc_flags, not changeable by user.
- */
-#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
-#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
-#define SC_COMP_RUN 0x00001000 /* compressor has been initiated */
-#define SC_DECOMP_RUN 0x00002000 /* decompressor has been initiated */
-#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */
-#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */
-#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */
-#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */
-#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
+/* state bits */
#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
+#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
+#define SC_VJ_RESET 0x20000000 /* Need to reset the VJ decompressor */
+#define SC_XMIT_BUSY 0x10000000 /* ppp_write_wakeup is active */
+#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
+#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
+#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
+#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
+#define SC_DC_FERROR 0x00800000 /* fatal decomp error detected */
+#define SC_DC_ERROR 0x00400000 /* non-fatal decomp error detected */
/*
* Ioctl definitions.
*/
struct npioctl {
- int protocol; /* PPP procotol, e.g. PPP_IP */
+ int protocol; /* PPP protocol, e.g. PPP_IP */
enum NPmode mode;
};
/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
struct ppp_option_data {
- u_char *ptr;
- u_int length;
- int transmit;
+ u_int8_t *ptr;
+ u_int32_t length;
+ int transmit;
};
struct ifpppstatsreq {
- char ifr_name[IFNAMSIZ];
- struct ppp_stats stats;
+ struct ifreq b;
+ struct ppp_stats stats; /* statistic information */
};
struct ifpppcstatsreq {
- char ifr_name[IFNAMSIZ];
- struct ppp_comp_stats stats;
+ struct ifreq b;
+ struct ppp_comp_stats stats;
};
+#define ifr__name b.ifr_ifrn.ifrn_name
+#define stats_ptr b.ifr_ifru.ifru_data
+
/*
* Ioctl definitions.
*/
@@ -115,23 +152,18 @@ struct ifpppcstatsreq {
#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
-#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */
-#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */
-#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */
+#define PPPIOCGDEBUG _IOR('t', 65, int) /* Read debug level */
+#define PPPIOCSDEBUG _IOW('t', 64, int) /* Set debug level */
+#define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle) /* get idle time */
-/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
-#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */
-#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */
-
-/*
- * These two are interface ioctls so that pppstats can do them on
- * a socket without having to open the serial device.
- */
-#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
-#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
+#define SIOCGPPPSTATS (SIOCDEVPRIVATE + 0)
+#define SIOCGPPPVER (SIOCDEVPRIVATE + 1) /* NEVER change this!! */
+#define SIOCGPPPCSTATS (SIOCDEVPRIVATE + 2)
#if !defined(ifr_mtu)
#define ifr_mtu ifr_ifru.ifru_metric
#endif
-#endif /* _IF_PPP_H_ */
+__END_DECLS
+
+#endif /* net/if_ppp.h */
diff --git a/newlib/libc/sys/linux/include/net/if_pppvar.h b/newlib/libc/sys/linux/include/net/if_pppvar.h
deleted file mode 100644
index b4380f4ec..000000000
--- a/newlib/libc/sys/linux/include/net/if_pppvar.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * if_pppvar.h - private structures and declarations for PPP.
- *
- * Copyright (c) 1994 The Australian National University.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation is hereby granted, provided that the above copyright
- * notice appears in all copies. This software is provided without any
- * warranty, express or implied. The Australian National University
- * makes no representations about the suitability of this software for
- * any purpose.
- *
- * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
- * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
- * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
- *
- * Copyright (c) 1989 Carnegie Mellon University.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by Carnegie Mellon University. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * $FreeBSD: src/sys/net/if_pppvar.h,v 1.19 2002/03/24 09:34:04 bde Exp $
- */
-
-/*
- * Supported network protocols. These values are used for
- * indexing sc_npmode.
- */
-#define NP_IP 0 /* Internet Protocol */
-#define NUM_NP 1 /* Number of NPs. */
-
-/*
- * Structure describing each ppp unit.
- */
-struct ppp_softc {
- struct ifnet sc_if; /* network-visible interface */
-/*hi*/ u_int sc_flags; /* control/status bits; see if_ppp.h */
- struct callout_handle sc_ch; /* Used for scheduling timeouts */
- void *sc_devp; /* pointer to device-dep structure */
- void (*sc_start)(struct ppp_softc *); /* start output proc */
- void (*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */
- void (*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */
- void (*sc_setmtu)(struct ppp_softc *); /* set mtu */
- short sc_mru; /* max receive unit */
- pid_t sc_xfer; /* used in transferring unit */
-/*hi*/ struct ifqueue sc_rawq; /* received packets */
-/*net*/ struct ifqueue sc_inq; /* queue of input packets for daemon */
-/*net*/ struct ifqueue sc_fastq; /* interactive output packet q */
- struct mbuf *sc_npqueue; /* output packets not to be sent yet */
- struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */
- struct pppstat sc_stats; /* count of bytes/pkts sent/rcvd */
- enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */
- struct compressor *sc_xcomp; /* transmit compressor */
- void *sc_xc_state; /* transmit compressor state */
- struct compressor *sc_rcomp; /* receive decompressor */
- void *sc_rc_state; /* receive decompressor state */
- time_t sc_last_sent; /* time (secs) last NP pkt sent */
- time_t sc_last_recv; /* time (secs) last NP pkt rcvd */
-#ifdef PPP_FILTER
- struct bpf_program sc_pass_filt; /* filter for packets to pass */
- struct bpf_program sc_active_filt; /* filter for "non-idle" packets */
-#endif /* PPP_FILTER */
-#ifdef VJC
- struct slcompress *sc_comp; /* vjc control buffer */
-#endif
-
- /* Device-dependent part for async lines. */
- ext_accm sc_asyncmap; /* async control character map */
- u_long sc_rasyncmap; /* receive async control char map */
- struct mbuf *sc_outm; /* mbuf chain currently being output */
- struct mbuf *sc_m; /* pointer to input mbuf chain */
- struct mbuf *sc_mc; /* pointer to current input mbuf */
- char *sc_mp; /* ptr to next char in input mbuf */
- short sc_ilen; /* length of input packet so far */
- u_short sc_fcs; /* FCS so far (input) */
- u_short sc_outfcs; /* FCS so far for output packet */
- u_char sc_rawin[16]; /* chars as received */
- int sc_rawin_count; /* # in sc_rawin */
-};
-
-struct ppp_softc *pppalloc(pid_t pid);
-void pppdealloc(struct ppp_softc *sc);
-int pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, int flag,
- struct thread *td);
-int pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
- struct rtentry *rtp);
-void ppp_restart(struct ppp_softc *sc);
-void ppppktin(struct ppp_softc *sc, struct mbuf *m, int lost);
-struct mbuf *ppp_dequeue(struct ppp_softc *sc);
diff --git a/newlib/libc/sys/linux/include/netdb.h b/newlib/libc/sys/linux/include/netdb.h
index e92b269e2..9e57ffe9c 100644
--- a/newlib/libc/sys/linux/include/netdb.h
+++ b/newlib/libc/sys/linux/include/netdb.h
@@ -83,8 +83,12 @@ typedef _BSD_SOCKLEN_T_ socklen_t;
#define _PATH_NETWORKS "/etc/networks"
#define _PATH_PROTOCOLS "/etc/protocols"
#define _PATH_SERVICES "/etc/services"
+#define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
-extern int h_errno;
+
+extern int *__h_errno_location(void);
+
+#define h_errno (*(__h_errno_location()))
#define MAXALIASES 35
/* For now, only support one return address. */
@@ -158,20 +162,27 @@ struct addrinfo {
/*
* Error return codes from getaddrinfo()
*/
-#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
-#define EAI_AGAIN 2 /* temporary failure in name resolution */
-#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
-#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
-#define EAI_FAMILY 5 /* ai_family not supported */
-#define EAI_MEMORY 6 /* memory allocation failure */
-#define EAI_NODATA 7 /* no address associated with hostname */
-#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
-#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
-#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
-#define EAI_SYSTEM 11 /* system error returned in errno */
-#define EAI_BADHINTS 12
-#define EAI_PROTOCOL 13
-#define EAI_MAX 14
+/* Error values for `getaddrinfo' function. */
+# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
+# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
+# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
+# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
+# define EAI_NODATA -5 /* No address associated with NAME. */
+# define EAI_FAMILY -6 /* `ai_family' not supported. */
+# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
+# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
+# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
+# define EAI_MEMORY -10 /* Memory allocation failure. */
+# define EAI_SYSTEM -11 /* System error returned in `errno'. */
+# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
+# ifdef __USE_GNU
+# define EAI_INPROGRESS -100 /* Processing request in progress. */
+# define EAI_CANCELED -101 /* Request canceled. */
+# define EAI_NOTCANCELED -102 /* Request not canceled. */
+# define EAI_ALLDONE -103 /* All requests done. */
+# define EAI_INTR -104 /* Interrupted by a signal. */
+# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
+# endif
/*
* Flag values for getaddrinfo()
@@ -179,6 +190,7 @@ struct addrinfo {
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
+#define AI_NUMERICSERV 0x00000008 /* don't use name resolution. */
/* valid flags for addrinfo */
#define AI_MASK \
(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
@@ -219,14 +231,14 @@ void endnetgrent(void);
void endprotoent(void);
void endservent(void);
void freehostent(struct hostent *);
-struct hostent *gethostbyaddr(const char *, int, int);
+struct hostent *gethostbyaddr(const void *, socklen_t, int);
struct hostent *gethostbyname(const char *);
struct hostent *gethostbyname2(const char *, int);
struct hostent *gethostent(void);
int gethostent_r(struct hostent *, char *, int, int *, FILE **);
struct hostent *getipnodebyaddr(const void *, size_t, int, int *);
struct hostent *getipnodebyname(const char *, int, int, int *);
-struct netent *getnetbyaddr(unsigned long, int);
+struct netent *getnetbyaddr(uint32_t, int);
struct netent *getnetbyname(const char *);
struct netent *getnetent(void);
int getnetgrent(char **, char **, char **);
@@ -247,10 +259,10 @@ void setprotoent(int);
int getaddrinfo(const char *, const char *,
const struct addrinfo *, struct addrinfo **);
int getnameinfo(const struct sockaddr *, socklen_t, char *,
- size_t, char *, size_t, int);
+ socklen_t, char *, socklen_t, unsigned int);
void freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
-void setnetgrent(const char *);
+int setnetgrent(const char *);
void setservent(int);
/*
diff --git a/newlib/libc/sys/linux/include/netinet/if_atm.h b/newlib/libc/sys/linux/include/netinet/if_atm.h
deleted file mode 100644
index 04ce13ea2..000000000
--- a/newlib/libc/sys/linux/include/netinet/if_atm.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* $FreeBSD: src/sys/netinet/if_atm.h,v 1.5 2002/03/19 21:25:46 alfred Exp $ */
-/* $NetBSD: if_atm.h,v 1.2 1996/07/03 17:17:17 chuck Exp $ */
-
-/*
- *
- * Copyright (c) 1996 Charles D. Cranor and Washington University.
- * 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 Charles D. Cranor and
- * Washington University.
- * 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.
- */
-
-/*
- * if_atm.h
- */
-
-struct atm_pseudohdr;
-struct mbuf;
-struct rtentry;
-struct sockaddr;
-
-void atm_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
-int atmresolve(struct rtentry *, struct mbuf *, struct sockaddr *,
- struct atm_pseudohdr *);
diff --git a/newlib/libc/sys/linux/include/netinet/if_ether.h b/newlib/libc/sys/linux/include/netinet/if_ether.h
index ec65a3e58..4bba84912 100644
--- a/newlib/libc/sys/linux/include/netinet/if_ether.h
+++ b/newlib/libc/sys/linux/include/netinet/if_ether.h
@@ -37,6 +37,9 @@
#ifndef _NETINET_IF_ETHER_H_
#define _NETINET_IF_ETHER_H_
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <libc-symbols.h>
#include <net/ethernet.h>
#include <net/if_arp.h>
diff --git a/newlib/libc/sys/linux/include/netinet/ip_flow.h b/newlib/libc/sys/linux/include/netinet/ip_flow.h
deleted file mode 100644
index 90561f07b..000000000
--- a/newlib/libc/sys/linux/include/netinet/ip_flow.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by the 3am Software Foundry ("3am"). It was developed by Matt Thomas.
- *
- * 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 the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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.
- *
- * $FreeBSD: src/sys/netinet/ip_flow.h,v 1.4 2000/05/26 02:05:46 jake Exp $
- */
-
-#ifndef _NETINET_IP_FLOW_H
-#define _NETINET_IP_FLOW_H
-
-struct ipflow {
- LIST_ENTRY(ipflow) ipf_next; /* next ipflow in bucket */
- struct in_addr ipf_dst; /* destination address */
- struct in_addr ipf_src; /* source address */
-
- u_int8_t ipf_tos; /* type-of-service */
- struct route ipf_ro; /* associated route entry */
- u_long ipf_uses; /* number of uses in this period */
-
- int ipf_timer; /* remaining lifetime of this entry */
- u_long ipf_dropped; /* ENOBUFS returned by if_output */
- u_long ipf_errors; /* other errors returned by if_output */
- u_long ipf_last_uses; /* number of uses in last period */
-};
-
-#endif
diff --git a/newlib/libc/sys/linux/include/nsswitch.h b/newlib/libc/sys/linux/include/nsswitch.h
deleted file mode 100644
index 3a578e4ff..000000000
--- a/newlib/libc/sys/linux/include/nsswitch.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */
-/* $FreeBSD: src/include/nsswitch.h,v 1.2 2002/03/23 17:24:53 imp Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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.
- */
-
-#ifndef _NSSWITCH_H
-#define _NSSWITCH_H 1
-
-#include <sys/types.h>
-
-#include <stdarg.h>
-
-#ifndef _PATH_NS_CONF
-#define _PATH_NS_CONF "/etc/nsswitch.conf"
-#endif
-
-#define NS_CONTINUE 0
-#define NS_RETURN 1
-
-#define NS_SUCCESS (1<<0) /* entry was found */
-#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */
-#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */
-#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retrys */
-#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */
-
-/*
- * currently implemented sources
- */
-#define NSSRC_FILES "files" /* local files */
-#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */
-#define NSSRC_NIS "nis" /* YP/NIS */
-#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */
-
-/*
- * currently implemented databases
- */
-#define NSDB_HOSTS "hosts"
-#define NSDB_GROUP "group"
-#define NSDB_GROUP_COMPAT "group_compat"
-#define NSDB_NETGROUP "netgroup"
-#define NSDB_NETWORKS "networks"
-#define NSDB_PASSWD "passwd"
-#define NSDB_PASSWD_COMPAT "passwd_compat"
-#define NSDB_SHELLS "shells"
-
-/*
- * suggested databases to implement
- */
-#define NSDB_ALIASES "aliases"
-#define NSDB_AUTH "auth"
-#define NSDB_AUTOMOUNT "automount"
-#define NSDB_BOOTPARAMS "bootparams"
-#define NSDB_ETHERS "ethers"
-#define NSDB_EXPORTS "exports"
-#define NSDB_NETMASKS "netmasks"
-#define NSDB_PHONES "phones"
-#define NSDB_PRINTCAP "printcap"
-#define NSDB_PROTOCOLS "protocols"
-#define NSDB_REMOTE "remote"
-#define NSDB_RPC "rpc"
-#define NSDB_SENDMAILVARS "sendmailvars"
-#define NSDB_SERVICES "services"
-#define NSDB_TERMCAP "termcap"
-#define NSDB_TTYS "ttys"
-
-/*
- * ns_dtab - `nsswitch dispatch table'
- * contains an entry for each source and the appropriate function to call
- */
-typedef struct {
- const char *src;
- int (*callback)(void *retval, void *cb_data, va_list ap);
- void *cb_data;
-} ns_dtab;
-
-/*
- * macros to help build an ns_dtab[]
- */
-#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C },
-#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C },
-
-#ifdef HESIOD
-# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C },
-#else
-# define NS_DNS_CB(F,C)
-#endif
-
-#ifdef YP
-# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C },
-#else
-# define NS_NIS_CB(F,C)
-#endif
-
-/*
- * ns_src - `nsswitch source'
- * used by the nsparser routines to store a mapping between a source
- * and its dispatch control flags for a given database.
- */
-typedef struct {
- const char *name;
- u_int32_t flags;
-} ns_src;
-
-
-/*
- * default sourcelist (if nsswitch.conf is missing, corrupt,
- * or the requested database doesn't have an entry.
- */
-extern const ns_src __nsdefaultsrc[];
-
-
-#ifdef _NS_PRIVATE
-
-/*
- * private data structures for back-end nsswitch implementation
- */
-
-/*
- * ns_dbt - `nsswitch database thang'
- * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
- * name and a list of ns_src's containing the source information.
- */
-typedef struct {
- const char *name; /* name of database */
- ns_src *srclist; /* list of sources */
- int srclistsize; /* size of srclist */
-} ns_dbt;
-
-#endif /* _NS_PRIVATE */
-
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-extern int nsdispatch(void *, const ns_dtab [], const char *,
- const char *, const ns_src [], ...);
-
-#ifdef _NS_PRIVATE
-extern void _nsdbtaddsrc(ns_dbt *, const ns_src *);
-extern void _nsdbtdump(const ns_dbt *);
-extern const ns_dbt *_nsdbtget(const char *);
-extern void _nsdbtput(const ns_dbt *);
-extern void _nsyyerror(const char *);
-extern int _nsyylex(void);
-extern int _nsyylineno;
-#endif /* _NS_PRIVATE */
-
-__END_DECLS
-
-#endif /* !_NSSWITCH_H */
diff --git a/newlib/libc/sys/linux/include/resolv.h b/newlib/libc/sys/linux/include/resolv.h
index 1114f2d92..35db205d9 100644
--- a/newlib/libc/sys/linux/include/resolv.h
+++ b/newlib/libc/sys/linux/include/resolv.h
@@ -94,6 +94,27 @@
#define RES_TIMEOUT 5 /* min. seconds between retries */
#define MAXRESOLVSORT 10 /* number of net to sort on */
#define RES_MAXNDOTS 15 /* should reflect bit field size */
+#define RES_MAXRETRANS 30 /* only for resolv.conf/RES_OPTIONS */
+#define RES_MAXRETRY 5 /* only for resolv.conf/RES_OPTIONS */
+#define RES_DFLRETRY 2 /* Default #/tries. */
+#define RES_MAXTIME 65535 /* Infinity, in milliseconds. */
+
+
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+ res_sendhookact;
+typedef res_sendhookact (*res_send_qhook) (struct sockaddr_in * const *ns, const u_char **query,
+ int *querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen);
+
+typedef res_sendhookact (*res_send_rhook) (const struct sockaddr_in *ns,
+ const u_char *query,
+ int querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen);
+
struct __res_state {
int retrans; /* retransmition time interval */
@@ -114,9 +135,31 @@ struct __res_state {
struct in_addr addr;
u_int32_t mask;
} sort_list[MAXRESOLVSORT];
- char pad[72]; /* on an i386 this means 512b total */
+ res_send_qhook qhook; /* query hook */
+ res_send_rhook rhook; /* response hook */
+ int res_h_errno; /* last one set for this context */
+ int _vcsock; /* PRIVATE: for res_send VC i/o */
+ u_int _flags; /* PRIVATE: see below */
+ union {
+ char pad[52]; /* On an i386 this means 512b total. */
+ struct {
+ u_int16_t nscount;
+ u_int16_t nsmap[MAXNS];
+ int nssocks[MAXNS];
+ u_int16_t nscount6;
+ u_int16_t nsinit;
+ struct sockaddr_in6 *nsaddrs[MAXNS];
+ unsigned long long int initstamp
+ __attribute__((packed));
+#if 0
+ unsigned int _initstamp[2];
+#endif
+ } _ext;
+ } _u;
};
+typedef struct __res_state *res_state;
+
/* for INET6 */
/*
* replacement of __res_state, separated to keep binary compatibility.
@@ -133,6 +176,15 @@ struct __res_state_ext {
};
/*
+ * * Resolver flags (used to be discrete per-module statics ints).
+ * */
+#define RES_F_VC 0x00000001 /* socket is TCP */
+#define RES_F_CONN 0x00000002 /* socket is connected */
+
+/* res_findzonecut() options */
+#define RES_EXHAUSTIVE 0x00000001 /* always do all queries */
+
+/*
* Resolver options (keep these in synch with res_debug.c, please)
*/
#define RES_INIT 0x00000001 /* address initialized */
@@ -149,11 +201,16 @@ struct __res_state_ext {
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
-#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */
-/* KAME extensions: use higher bit to avoid conflict with ISC use */
-#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */
+#define RES_ROTATE 0x00004000 /* rotate ns list after each query */
+#define RES_NOCHECKNAME 0x00008000 /* do not check names for sanity. */
+#define RES_KEEPTSIG 0x00010000 /* do not strip TSIG records */
+#define RES_BLAST 0x00020000 /* blast all recursive servers */
+#define RES_USEBSTRING 0x00040000 /* IPv6 reverse lookup with byte
+ strings */
+#define RES_NOIP6DOTINT 0x00080000 /* Do not use .ip6.int in IPv6
+ reverse lookup */
-#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
+#define RES_DEFAULT (RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)
/*
* Resolver "pfcode" values. Used by dig.
@@ -175,22 +232,13 @@ struct __res_state_ext {
#define RES_PRF_INIT 0x00004000
/* 0x00008000 */
-typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
- res_sendhookact;
-
-typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
- const u_char **query,
- int *querylen,
- u_char *ans,
- int anssiz,
- int *resplen);
-
-typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
- const u_char *query,
- int querylen,
- u_char *ans,
- int anssiz,
- int *resplen);
+#define RES_SET_H_ERRNO(r,x) \
+ do \
+ { \
+ (r)->res_h_errno = x; \
+ h_errno = (x); \
+ } \
+ while (0)
struct res_sym {
int number; /* Identifying number, like T_MX */
@@ -207,6 +255,7 @@ extern const struct res_sym __p_type_syms[];
/* Private routines shared between libc/net, named, nslookup and others. */
#define res_hnok __res_hnok
+#define res_hostalias __res_hostalias
#define res_ownok __res_ownok
#define res_mailok __res_mailok
#define res_dnok __res_dnok
@@ -227,6 +276,7 @@ extern const struct res_sym __p_type_syms[];
#define putlong __putlong
#define putshort __putshort
#define p_class __p_class
+#define p_rcode __p_rcode
#define p_time __p_time
#define p_type __p_type
#define p_query __p_query
@@ -249,6 +299,15 @@ extern const struct res_sym __p_type_syms[];
#define res_send __res_send
#define res_isourserver __res_isourserver
#define res_nameinquery __res_nameinquery
+#define res_nclose __res_nclose
+#define res_ninit __res_ninit
+#define res_nmkquery __res_nmkquery
+#define res_npquery __res_npquery
+#define res_nquery __res_nquery
+#define res_nquerydomain __res_nquerydomain
+#define res_nsearch __res_nsearch
+#define res_nsend __res_nsend
+#define res_nisourserver __res_nisourserver
#define res_queriesmatch __res_queriesmatch
#define res_close __res_close
#define res_opt __res_opt
@@ -276,6 +335,7 @@ const char * hostalias(const char *);
void putlong(u_int32_t, u_char *);
void putshort(u_int16_t, u_char *);
const char * p_class(int);
+const char * p_rcode (int);
const char * p_time(u_int32_t);
const char * p_type(int);
void p_query(const u_char *);
@@ -302,6 +362,18 @@ int res_send(const u_char *, int, u_char *, int);
int res_isourserver(const struct sockaddr_in *);
int res_nameinquery(const char *, int, int,
const u_char *, const u_char *);
+void res_npquery (const res_state, const u_char *, int, FILE *);
+const char * res_hostalias (const res_state, const char *, char *, size_t);
+int res_nquery (res_state, const char *, int, int, u_char *, int);
+int res_nsearch (res_state, const char *, int, int, u_char *, int);
+int res_nquerydomain (res_state, const char *, const char *, int,
+ int, u_char *, int);
+int res_nmkquery (res_state, int, const char *, int, int,
+ const u_char *, int, const u_char *, u_char *,
+ int);
+int res_nsend (res_state, const u_char *, int, u_char *, int);
+void res_nclose (res_state);
+
int res_queriesmatch(const u_char *, const u_char *,
const u_char *, const u_char *);
void res_close(void);
@@ -314,6 +386,7 @@ int res_mkupdate(ns_updrec *, u_char *, int);
ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long);
void res_freeupdrec(ns_updrec *);
#endif
+
__END_DECLS
#endif /* !_RESOLV_H_ */
diff --git a/newlib/libc/sys/linux/include/stdint.h b/newlib/libc/sys/linux/include/stdint.h
index d1197f66c..682af1f7a 100644
--- a/newlib/libc/sys/linux/include/stdint.h
+++ b/newlib/libc/sys/linux/include/stdint.h
@@ -15,6 +15,7 @@
#define _STDINT_H
#include <sys/types.h>
+#include <bits/wordsize.h>
#ifdef __cplusplus
extern "C" {
@@ -87,6 +88,34 @@ typedef uint32_t uint_least16_t;
#endif
#endif
+/* Fast types. */
+
+/* Signed. */
+typedef signed char int_fast8_t;
+#if __WORDSIZE == 64
+typedef long int int_fast16_t;
+typedef long int int_fast32_t;
+typedef long int int_fast64_t;
+#else
+typedef int int_fast16_t;
+typedef int int_fast32_t;
+__extension__
+typedef long long int int_fast64_t;
+#endif
+
+/* Unsigned. */
+typedef unsigned char uint_fast8_t;
+#if __WORDSIZE == 64
+typedef unsigned long int uint_fast16_t;
+typedef unsigned long int uint_fast32_t;
+typedef unsigned long int uint_fast64_t;
+#else
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+__extension__
+typedef unsigned long long int uint_fast64_t;
+#endif
+
#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
#define __int64_t_defined 1
#define __have_long64 1
diff --git a/newlib/libc/sys/linux/intl/locale.alias b/newlib/libc/sys/linux/intl/locale.alias
deleted file mode 100644
index 08c250d35..000000000
--- a/newlib/libc/sys/linux/intl/locale.alias
+++ /dev/null
@@ -1,75 +0,0 @@
-# Locale name alias data base.
-# Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-# The format of this file is the same as for the corresponding file of
-# the X Window System, which normally can be found in
-# /usr/lib/X11/locale/locale.alias
-# A single line contains two fields: an alias and a substitution value.
-# All entries are case independent.
-
-# Note: This file is far from being complete. If you have a value for
-# your own site which you think might be useful for others too, share
-# it with the rest of us. Send it using the `glibcbug' script to
-# bugs@gnu.org.
-
-bokmal no_NO.ISO-8859-1
-bokmål no_NO.ISO-8859-1
-catalan ca_ES.ISO-8859-1
-croatian hr_HR.ISO-8859-2
-czech cs_CZ.ISO-8859-2
-danish da_DK.ISO-8859-1
-dansk da_DK.ISO-8859-1
-deutsch de_DE.ISO-8859-1
-dutch nl_NL.ISO-8859-1
-eesti et_EE.ISO-8859-1
-estonian et_EE.ISO-8859-1
-finnish fi_FI.ISO-8859-1
-français fr_FR.ISO-8859-1
-french fr_FR.ISO-8859-1
-galego gl_ES.ISO-8859-1
-galician gl_ES.ISO-8859-1
-german de_DE.ISO-8859-1
-greek el_GR.ISO-8859-7
-hebrew he_IL.ISO-8859-8
-hrvatski hr_HR.ISO-8859-2
-hungarian hu_HU.ISO-8859-2
-icelandic is_IS.ISO-8859-1
-italian it_IT.ISO-8859-1
-japanese ja_JP.eucJP
-japanese.euc ja_JP.eucJP
-ja_JP ja_JP.eucJP
-ja_JP.ujis ja_JP.eucJP
-japanese.sjis ja_JP.SJIS
-korean ko_KR.eucKR
-korean.euc ko_KR.eucKR
-ko_KR ko_KR.eucKR
-lithuanian lt_LT.ISO-8859-13
-nb_NO no_NO.ISO-8859-1
-nb_NO.ISO-8859-1 no_NO.ISO-8859-1
-norwegian no_NO.ISO-8859-1
-nynorsk nn_NO.ISO-8859-1
-polish pl_PL.ISO-8859-2
-portuguese pt_PT.ISO-8859-1
-romanian ro_RO.ISO-8859-2
-russian ru_RU.ISO-8859-5
-slovak sk_SK.ISO-8859-2
-slovene sl_SI.ISO-8859-2
-slovenian sl_SI.ISO-8859-2
-spanish es_ES.ISO-8859-1
-swedish sv_SE.ISO-8859-1
-thai th_TH.TIS-620
-turkish tr_TR.ISO-8859-9
diff --git a/newlib/libc/sys/linux/libc-symbols.h b/newlib/libc/sys/linux/libc-symbols.h
index 97b672643..f32260c95 100644
--- a/newlib/libc/sys/linux/libc-symbols.h
+++ b/newlib/libc/sys/linux/libc-symbols.h
@@ -349,4 +349,31 @@
strong_alias(real, name)
#endif
+#define libc_hidden_def(x)
+#define libc_hidden_weak(x)
+#define libc_hidden_proto(x)
+#define libc_hidden_data_def(x)
+#define libresolv_hidden_def(x)
+#define libresolv_hidden_weak(x)
+#define libresolv_hidden_data_def(x)
+#define libresolv_hidden_proto(x)
+#define static_link_warning(x)
+#define libc_freeres_ptr(x) x
+#define DL_CALL_FCT(x,y) x y
+#define attribute_hidden
+#define internal_function
+
+/* Move compatibility symbols out of the way by placing them all in a
+ special section. */
+#ifndef __ASSEMBLER__
+# define attribute_compat_text_section \
+ __attribute__ ((section (".text.compat")))
+# define attribute_compat_data_section \
+ __attribute__ ((section (".data.compat")))
+#else
+# define compat_text_section .section ".text.compat", "ax";
+# define compat_data_section .section ".data.compat", "aw";
+#endif
+
+
#endif /* libc-symbols.h */
diff --git a/newlib/libc/sys/linux/machine/i386/atomic.h b/newlib/libc/sys/linux/machine/i386/atomic.h
new file mode 100644
index 000000000..c74876175
--- /dev/null
+++ b/newlib/libc/sys/linux/machine/i386/atomic.h
@@ -0,0 +1,366 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdint.h>
+
+
+typedef int8_t atomic8_t;
+typedef uint8_t uatomic8_t;
+typedef int_fast8_t atomic_fast8_t;
+typedef uint_fast8_t uatomic_fast8_t;
+
+typedef int16_t atomic16_t;
+typedef uint16_t uatomic16_t;
+typedef int_fast16_t atomic_fast16_t;
+typedef uint_fast16_t uatomic_fast16_t;
+
+typedef int32_t atomic32_t;
+typedef uint32_t uatomic32_t;
+typedef int_fast32_t atomic_fast32_t;
+typedef uint_fast32_t uatomic_fast32_t;
+
+typedef int64_t atomic64_t;
+typedef uint64_t uatomic64_t;
+typedef int_fast64_t atomic_fast64_t;
+typedef uint_fast64_t uatomic_fast64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+
+#ifndef LOCK_PREFIX
+# ifdef UP
+# define LOCK_PREFIX /* nothing */
+# else
+# define LOCK_PREFIX "lock;"
+# endif
+#endif
+
+
+#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret; \
+ __asm __volatile (LOCK_PREFIX "cmpxchgb %b2, %1" \
+ : "=a" (ret), "=m" (*mem) \
+ : "q" (newval), "m" (*mem), "0" (oldval)); \
+ ret; })
+
+#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret; \
+ __asm __volatile (LOCK_PREFIX "cmpxchgw %w2, %1" \
+ : "=a" (ret), "=m" (*mem) \
+ : "r" (newval), "m" (*mem), "0" (oldval)); \
+ ret; })
+
+#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret; \
+ __asm __volatile (LOCK_PREFIX "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (*mem) \
+ : "r" (newval), "m" (*mem), "0" (oldval)); \
+ ret; })
+
+/* XXX We do not really need 64-bit compare-and-exchange. At least
+ not in the moment. Using it would mean causing portability
+ problems since not many other 32-bit architectures have support for
+ such an operation. So don't define any code for now. If it is
+ really going to be used the code below can be used on Intel Pentium
+ and later, but NOT on i486. */
+#if 1
+# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret = *(mem); abort (); ret = (newval); ret = (oldval); })
+#else
+# ifdef __PIC__
+# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret; \
+ __asm __volatile ("xchgl %2, %%ebx\n\t" \
+ LOCK_PREFIX "cmpxchg8b %1\n\t" \
+ "xchgl %2, %%ebx" \
+ : "=A" (ret), "=m" (*mem) \
+ : "DS" (((unsigned long long int) (newval)) \
+ & 0xffffffff), \
+ "c" (((unsigned long long int) (newval)) >> 32), \
+ "m" (*mem), "a" (((unsigned long long int) (oldval)) \
+ & 0xffffffff), \
+ "d" (((unsigned long long int) (oldval)) >> 32)); \
+ ret; })
+# else
+# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
+ ({ __typeof (*mem) ret; \
+ __asm __volatile (LOCK_PREFIX "cmpxchg8b %1" \
+ : "=A" (ret), "=m" (*mem) \
+ : "b" (((unsigned long long int) (newval)) \
+ & 0xffffffff), \
+ "c" (((unsigned long long int) (newval)) >> 32), \
+ "m" (*mem), "a" (((unsigned long long int) (oldval)) \
+ & 0xffffffff), \
+ "d" (((unsigned long long int) (oldval)) >> 32)); \
+ ret; })
+# endif
+#endif
+
+
+/* Note that we need no lock prefix. */
+#define atomic_exchange_acq(mem, newvalue) \
+ ({ __typeof (*mem) result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile ("xchgb %b0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile ("xchgw %w0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile ("xchgl %0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "m" (*mem)); \
+ else \
+ { \
+ result = 0; \
+ abort (); \
+ } \
+ result; })
+
+
+#define atomic_exchange_and_add(mem, value) \
+ ({ __typeof (*mem) __result; \
+ __typeof (value) __addval = (value); \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "xaddb %b0, %1" \
+ : "=r" (__result), "=m" (*mem) \
+ : "0" (__addval), "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "xaddw %w0, %1" \
+ : "=r" (__result), "=m" (*mem) \
+ : "0" (__addval), "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "xaddl %0, %1" \
+ : "=r" (__result), "=m" (*mem) \
+ : "0" (__addval), "m" (*mem)); \
+ else \
+ { \
+ __typeof (mem) __memp = (mem); \
+ __typeof (*mem) __tmpval; \
+ __result = *__memp; \
+ do \
+ __tmpval = __result; \
+ while ((__result = __arch_compare_and_exchange_val_64_acq \
+ (__memp, __result + __addval, __result)) == __tmpval); \
+ } \
+ __result; })
+
+
+#define atomic_add(mem, value) \
+ (void) ({ if (__builtin_constant_p (value) && (value) == 1) \
+ atomic_increment (mem); \
+ else if (__builtin_constant_p (value) && (value) == -1) \
+ atomic_decrement (mem); \
+ else if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "addb %b1, %0" \
+ : "=m" (*mem) \
+ : "ir" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "addw %w1, %0" \
+ : "=m" (*mem) \
+ : "ir" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "addl %1, %0" \
+ : "=m" (*mem) \
+ : "ir" (value), "m" (*mem)); \
+ else \
+ { \
+ __typeof (value) __addval = (value); \
+ __typeof (mem) __memp = (mem); \
+ __typeof (*mem) __oldval = *__memp; \
+ __typeof (*mem) __tmpval; \
+ do \
+ __tmpval = __oldval; \
+ while ((__oldval = __arch_compare_and_exchange_val_64_acq \
+ (__memp, __oldval + __addval, __oldval)) == __tmpval); \
+ } \
+ })
+
+
+#define atomic_add_negative(mem, value) \
+ ({ unsigned char __result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "addb %b2, %0; sets %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "iq" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "addw %w2, %0; sets %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "ir" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "addl %2, %0; sets %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "ir" (value), "m" (*mem)); \
+ else \
+ abort (); \
+ __result; })
+
+
+#define atomic_add_zero(mem, value) \
+ ({ unsigned char __result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "addb %b2, %0; setz %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "ir" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "addw %w2, %0; setz %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "ir" (value), "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "addl %2, %0; setz %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "ir" (value), "m" (*mem)); \
+ else \
+ abort (); \
+ __result; })
+
+
+#define atomic_increment(mem) \
+ (void) ({ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "incb %b0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "incw %w0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "incl %0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else \
+ { \
+ __typeof (mem) __memp = (mem); \
+ __typeof (*mem) __oldval = *__memp; \
+ __typeof (*mem) __tmpval; \
+ do \
+ __tmpval = __oldval; \
+ while ((__oldval = __arch_compare_and_exchange_val_64_acq \
+ (__memp, __oldval + 1, __oldval)) == __tmpval); \
+ } \
+ })
+
+
+#define atomic_increment_and_test(mem) \
+ ({ unsigned char __result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "incb %0; sete %b1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "incw %0; sete %w1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "incl %0; sete %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else \
+ abort (); \
+ __result; })
+
+
+#define atomic_decrement(mem) \
+ (void) ({ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "decb %b0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "decw %w0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "decl %0" \
+ : "=m" (*mem) \
+ : "m" (*mem)); \
+ else \
+ { \
+ __typeof (mem) __memp = (mem); \
+ __typeof (*mem) __oldval = *__memp; \
+ __typeof (*mem) __tmpval; \
+ do \
+ __tmpval = __oldval; \
+ while ((__oldval = __arch_compare_and_exchange_val_64_acq \
+ (__memp, __oldval - 1, __oldval)) == __tmpval); \
+ } \
+ })
+
+
+#define atomic_decrement_and_test(mem) \
+ ({ unsigned char __result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "decb %b0; sete %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "decw %w0; sete %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "decl %0; sete %1" \
+ : "=m" (*mem), "=qm" (__result) \
+ : "m" (*mem)); \
+ else \
+ abort (); \
+ __result; })
+
+
+#define atomic_bit_set(mem, bit) \
+ (void) ({ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "orb %b2, %0" \
+ : "=m" (*mem) \
+ : "m" (*mem), "ir" (1 << (bit))); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "orw %w2, %0" \
+ : "=m" (*mem) \
+ : "m" (*mem), "ir" (1 << (bit))); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "orl %2, %0" \
+ : "=m" (*mem) \
+ : "m" (*mem), "ir" (1 << (bit))); \
+ else \
+ abort (); \
+ })
+
+
+#define atomic_bit_test_set(mem, bit) \
+ ({ unsigned char __result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile (LOCK_PREFIX "btsb %3, %1; setc %0" \
+ : "=q" (__result), "=m" (*mem) \
+ : "m" (*mem), "ir" (bit)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile (LOCK_PREFIX "btsw %3, %1; setc %0" \
+ : "=q" (__result), "=m" (*mem) \
+ : "m" (*mem), "ir" (bit)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile (LOCK_PREFIX "btsl %3, %1; setc %0" \
+ : "=q" (__result), "=m" (*mem) \
+ : "m" (*mem), "ir" (bit)); \
+ else \
+ abort (); \
+ __result; })
+
+
+#define atomic_delay() asm ("rep; nop")
diff --git a/newlib/libc/sys/linux/machine/i386/get_clockfreq.c b/newlib/libc/sys/linux/machine/i386/get_clockfreq.c
index ea46ed427..0f49fb07c 100644
--- a/newlib/libc/sys/linux/machine/i386/get_clockfreq.c
+++ b/newlib/libc/sys/linux/machine/i386/get_clockfreq.c
@@ -23,33 +23,6 @@
#include <unistd.h>
#include <libc-internal.h>
-static
-void *memmem (const void *a, size_t len1, const void *b, size_t len2)
-{
- char *end, *start;
- char *ptr1, *ptr2;
-
- if (len2 > len1)
- return NULL;
-
- start = (char *)a;
- end = start + len1;
-
- while (start < end)
- {
- size_t len = len2;
- ptr1 = start;
- ptr2 = (char *)b;
- while (len > 0 && *ptr1++ == *ptr2++)
- --len;
- if (len == 0)
- return start;
- ++start;
- }
-
- return NULL;
-}
-
hp_timing_t
__get_clockfreq (void)
{
diff --git a/newlib/libc/sys/linux/machine/i386/include/endian.h b/newlib/libc/sys/linux/machine/i386/include/endian.h
index aa9cd90a3..f5a8aafc7 100644
--- a/newlib/libc/sys/linux/machine/i386/include/endian.h
+++ b/newlib/libc/sys/linux/machine/i386/include/endian.h
@@ -47,11 +47,22 @@
* Definitions for byte order, according to byte significance from low
* address to high.
*/
+
+#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
+#endif
+
+#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
+#endif
+
+#ifndef PDP_ENDIAN
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
+#endif
+#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
+#endif
#ifndef KERNEL
#include <sys/cdefs.h>
diff --git a/newlib/libc/sys/linux/machine/i386/include/param.h b/newlib/libc/sys/linux/machine/i386/include/param.h
index fbe1be2ac..977a65711 100644
--- a/newlib/libc/sys/linux/machine/i386/include/param.h
+++ b/newlib/libc/sys/linux/machine/i386/include/param.h
@@ -60,7 +60,9 @@
#define LITTLE_ENDIAN 1234
#endif
+#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
+#endif
/*
* OBJFORMAT_NAMES is a comma-separated list of the object formats
diff --git a/newlib/libc/sys/linux/net/Makefile.am b/newlib/libc/sys/linux/net/Makefile.am
index 080709f4d..0b1a0d978 100644
--- a/newlib/libc/sys/linux/net/Makefile.am
+++ b/newlib/libc/sys/linux/net/Makefile.am
@@ -2,28 +2,38 @@
AUTOMAKE_OPTIONS = cygnus
-INCLUDES = -I$(srcdir)/../include $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+INCLUDES = -I$(srcdir)/../include -I$(srcdir)/.. $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-GENERAL_SOURCES = addr2ascii.c ascii2addr.c base64.c bindresvport.c ether_addr.c getaddrinfo.c \
- gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \
- getifaddrs.c getnameinfo.c \
- getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \
- getproto.c getprotoent.c getprotoname.c getservbyname.c \
- getservbyport.c getservent.c herror.c hesiod.c inet_addr.c \
- ifname.c inet_lnaof.c \
- inet_makeaddr.c inet_net_ntop.c inet_net_pton.c inet_neta.c \
- inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \
- inet_pton.c innetgr-stub.c ip6opt.c issetugid-stub.c \
- linkaddr.c map_v4v6.c namespace.h un-namespace.h \
- name6.c ns_addr.c \
- ns_name.c ns_netint.c \
- ns_ntoa.c ns_parse.c ns_print.c ns_ttl.c \
- nsdispatch.c nslexer.c nsparser.c nsparser.h \
- nsap_addr.c res_comp.c res_data.c res_debug.c \
- res_init.c res_mkquery.c res_mkupdate.c res_query.c \
- res_send.c res_update.c rthdr.c vars.c
+GENERAL_SOURCES = addr2ascii.c ascii2addr.c alias-lookup.c \
+ base64.c check_pf.c digits_dots.c \
+ ether_aton.c ether_aton_r.c ether_hton.c \
+ ether_line.c ether_ntoa.c ether_ntoa_r.c ether_ntoh.c \
+ ethers-lookup.c getaddrinfo.c getaliasent.c \
+ getaliasent_r.c getaliasname.c getaliasname_r.c gethstbyad.c \
+ gethstbyad_r.c gethstbynm2.c gethstbynm2_r.c gethstbynm.c \
+ gethstbynm_r.c gethstent.c gethstent_r.c getnameinfo.c getnetbyad.c \
+ getnetbyad_r.c getnetbynm.c getnetbynm_r.c getnetent.c getnetent_r.c \
+ getnetgrent.c getnetgrent_r.c getnssent.c getnssent_r.c getproto.c \
+ getproto_r.c getprtent.c \
+ getprtent_r.c getprtname.c getprtname_r.c getrpcbyname.c \
+ getrpcbyname_r.c getrpcbynumber.c getrpcbynumber_r.c getrpcent.c \
+ getrpcent_r.c getservent.c getservent_r.c getsrvbynm.c getsrvbynm_r.c \
+ getsrvbypt.c getsrvbypt_r.c grp-lookup.c \
+ herrno.c hosts-lookup.c ifreq.c \
+ in6_addr.c inet6_option.c inet_addr.c \
+ inet_lnaof.c inet_mkadr.c inet_net.c inet_neta.c inet_netof.c \
+ inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c \
+ inet_pton.c issetugid-stub.c key-lookup.c netgrp-lookup.c \
+ network-lookup.c nsswitch.c \
+ ns_name.c ns_netint.c ns_parse.c ns_print.c ns_samedomain.c \
+ ns_ttl.c nsap_addr.c proto-lookup.c opensock.c pwd-lookup.c recv.c \
+ res_comp.c res_data.c res_debug.c res_hconf.c res_init.c \
+ res_libc.c res_mkquery.c \
+ res_query.c res_send.c \
+ rexec.c rpc-lookup.c ruserpass.c send.c service-lookup.c spwd-lookup.c
ELIX_4_SOURCES = \
+ ifname.c \
rcmd.$(oext) \
rcmdsh.$(oext)
diff --git a/newlib/libc/sys/linux/net/Makefile.in b/newlib/libc/sys/linux/net/Makefile.in
index 84aeff804..f373a9094 100644
--- a/newlib/libc/sys/linux/net/Makefile.in
+++ b/newlib/libc/sys/linux/net/Makefile.in
@@ -56,38 +56,59 @@ ARFLAGS = cru
lib_a_AR = $(AR) $(ARFLAGS)
lib_a_LIBADD =
am__objects_1 = lib_a-addr2ascii.$(OBJEXT) lib_a-ascii2addr.$(OBJEXT) \
- lib_a-base64.$(OBJEXT) lib_a-bindresvport.$(OBJEXT) \
- lib_a-ether_addr.$(OBJEXT) lib_a-getaddrinfo.$(OBJEXT) \
- lib_a-gethostbydns.$(OBJEXT) lib_a-gethostbyht.$(OBJEXT) \
- lib_a-gethostbynis.$(OBJEXT) lib_a-gethostnamadr.$(OBJEXT) \
- lib_a-getifaddrs.$(OBJEXT) lib_a-getnameinfo.$(OBJEXT) \
- lib_a-getnetbydns.$(OBJEXT) lib_a-getnetbyht.$(OBJEXT) \
- lib_a-getnetbynis.$(OBJEXT) lib_a-getnetnamadr.$(OBJEXT) \
- lib_a-getproto.$(OBJEXT) lib_a-getprotoent.$(OBJEXT) \
- lib_a-getprotoname.$(OBJEXT) lib_a-getservbyname.$(OBJEXT) \
- lib_a-getservbyport.$(OBJEXT) lib_a-getservent.$(OBJEXT) \
- lib_a-herror.$(OBJEXT) lib_a-hesiod.$(OBJEXT) \
- lib_a-inet_addr.$(OBJEXT) lib_a-ifname.$(OBJEXT) \
- lib_a-inet_lnaof.$(OBJEXT) lib_a-inet_makeaddr.$(OBJEXT) \
- lib_a-inet_net_ntop.$(OBJEXT) lib_a-inet_net_pton.$(OBJEXT) \
- lib_a-inet_neta.$(OBJEXT) lib_a-inet_netof.$(OBJEXT) \
- lib_a-inet_network.$(OBJEXT) lib_a-inet_ntoa.$(OBJEXT) \
+ lib_a-alias-lookup.$(OBJEXT) lib_a-base64.$(OBJEXT) \
+ lib_a-check_pf.$(OBJEXT) lib_a-digits_dots.$(OBJEXT) \
+ lib_a-ether_aton.$(OBJEXT) lib_a-ether_aton_r.$(OBJEXT) \
+ lib_a-ether_hton.$(OBJEXT) lib_a-ether_line.$(OBJEXT) \
+ lib_a-ether_ntoa.$(OBJEXT) lib_a-ether_ntoa_r.$(OBJEXT) \
+ lib_a-ether_ntoh.$(OBJEXT) lib_a-ethers-lookup.$(OBJEXT) \
+ lib_a-getaddrinfo.$(OBJEXT) lib_a-getaliasent.$(OBJEXT) \
+ lib_a-getaliasent_r.$(OBJEXT) lib_a-getaliasname.$(OBJEXT) \
+ lib_a-getaliasname_r.$(OBJEXT) lib_a-gethstbyad.$(OBJEXT) \
+ lib_a-gethstbyad_r.$(OBJEXT) lib_a-gethstbynm2.$(OBJEXT) \
+ lib_a-gethstbynm2_r.$(OBJEXT) lib_a-gethstbynm.$(OBJEXT) \
+ lib_a-gethstbynm_r.$(OBJEXT) lib_a-gethstent.$(OBJEXT) \
+ lib_a-gethstent_r.$(OBJEXT) lib_a-getnameinfo.$(OBJEXT) \
+ lib_a-getnetbyad.$(OBJEXT) lib_a-getnetbyad_r.$(OBJEXT) \
+ lib_a-getnetbynm.$(OBJEXT) lib_a-getnetbynm_r.$(OBJEXT) \
+ lib_a-getnetent.$(OBJEXT) lib_a-getnetent_r.$(OBJEXT) \
+ lib_a-getnetgrent.$(OBJEXT) lib_a-getnetgrent_r.$(OBJEXT) \
+ lib_a-getnssent.$(OBJEXT) lib_a-getnssent_r.$(OBJEXT) \
+ lib_a-getproto.$(OBJEXT) lib_a-getproto_r.$(OBJEXT) \
+ lib_a-getprtent.$(OBJEXT) lib_a-getprtent_r.$(OBJEXT) \
+ lib_a-getprtname.$(OBJEXT) lib_a-getprtname_r.$(OBJEXT) \
+ lib_a-getrpcbyname.$(OBJEXT) lib_a-getrpcbyname_r.$(OBJEXT) \
+ lib_a-getrpcbynumber.$(OBJEXT) \
+ lib_a-getrpcbynumber_r.$(OBJEXT) lib_a-getrpcent.$(OBJEXT) \
+ lib_a-getrpcent_r.$(OBJEXT) lib_a-getservent.$(OBJEXT) \
+ lib_a-getservent_r.$(OBJEXT) lib_a-getsrvbynm.$(OBJEXT) \
+ lib_a-getsrvbynm_r.$(OBJEXT) lib_a-getsrvbypt.$(OBJEXT) \
+ lib_a-getsrvbypt_r.$(OBJEXT) lib_a-grp-lookup.$(OBJEXT) \
+ lib_a-herrno.$(OBJEXT) lib_a-hosts-lookup.$(OBJEXT) \
+ lib_a-ifreq.$(OBJEXT) lib_a-in6_addr.$(OBJEXT) \
+ lib_a-inet6_option.$(OBJEXT) lib_a-inet_addr.$(OBJEXT) \
+ lib_a-inet_lnaof.$(OBJEXT) lib_a-inet_mkadr.$(OBJEXT) \
+ lib_a-inet_net.$(OBJEXT) lib_a-inet_neta.$(OBJEXT) \
+ lib_a-inet_netof.$(OBJEXT) lib_a-inet_net_ntop.$(OBJEXT) \
+ lib_a-inet_net_pton.$(OBJEXT) lib_a-inet_ntoa.$(OBJEXT) \
lib_a-inet_ntop.$(OBJEXT) lib_a-inet_pton.$(OBJEXT) \
- lib_a-innetgr-stub.$(OBJEXT) lib_a-ip6opt.$(OBJEXT) \
- lib_a-issetugid-stub.$(OBJEXT) lib_a-linkaddr.$(OBJEXT) \
- lib_a-map_v4v6.$(OBJEXT) lib_a-name6.$(OBJEXT) \
- lib_a-ns_addr.$(OBJEXT) lib_a-ns_name.$(OBJEXT) \
- lib_a-ns_netint.$(OBJEXT) lib_a-ns_ntoa.$(OBJEXT) \
- lib_a-ns_parse.$(OBJEXT) lib_a-ns_print.$(OBJEXT) \
- lib_a-ns_ttl.$(OBJEXT) lib_a-nsdispatch.$(OBJEXT) \
- lib_a-nslexer.$(OBJEXT) lib_a-nsparser.$(OBJEXT) \
- lib_a-nsap_addr.$(OBJEXT) lib_a-res_comp.$(OBJEXT) \
- lib_a-res_data.$(OBJEXT) lib_a-res_debug.$(OBJEXT) \
- lib_a-res_init.$(OBJEXT) lib_a-res_mkquery.$(OBJEXT) \
- lib_a-res_mkupdate.$(OBJEXT) lib_a-res_query.$(OBJEXT) \
- lib_a-res_send.$(OBJEXT) lib_a-res_update.$(OBJEXT) \
- lib_a-rthdr.$(OBJEXT) lib_a-vars.$(OBJEXT)
-am__objects_2 =
+ lib_a-issetugid-stub.$(OBJEXT) lib_a-key-lookup.$(OBJEXT) \
+ lib_a-netgrp-lookup.$(OBJEXT) lib_a-network-lookup.$(OBJEXT) \
+ lib_a-nsswitch.$(OBJEXT) lib_a-ns_name.$(OBJEXT) \
+ lib_a-ns_netint.$(OBJEXT) lib_a-ns_parse.$(OBJEXT) \
+ lib_a-ns_print.$(OBJEXT) lib_a-ns_samedomain.$(OBJEXT) \
+ lib_a-ns_ttl.$(OBJEXT) lib_a-nsap_addr.$(OBJEXT) \
+ lib_a-proto-lookup.$(OBJEXT) lib_a-opensock.$(OBJEXT) \
+ lib_a-pwd-lookup.$(OBJEXT) lib_a-recv.$(OBJEXT) \
+ lib_a-res_comp.$(OBJEXT) lib_a-res_data.$(OBJEXT) \
+ lib_a-res_debug.$(OBJEXT) lib_a-res_hconf.$(OBJEXT) \
+ lib_a-res_init.$(OBJEXT) lib_a-res_libc.$(OBJEXT) \
+ lib_a-res_mkquery.$(OBJEXT) lib_a-res_query.$(OBJEXT) \
+ lib_a-res_send.$(OBJEXT) lib_a-rexec.$(OBJEXT) \
+ lib_a-rpc-lookup.$(OBJEXT) lib_a-ruserpass.$(OBJEXT) \
+ lib_a-send.$(OBJEXT) lib_a-service-lookup.$(OBJEXT) \
+ lib_a-spwd-lookup.$(OBJEXT)
+am__objects_2 = lib_a-ifname.$(OBJEXT)
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_3 = $(am__objects_2)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
@USE_LIBTOOL_FALSE@ $(am__objects_3)
@@ -95,38 +116,61 @@ lib_a_OBJECTS = $(am_lib_a_OBJECTS)
LTLIBRARIES = $(noinst_LTLIBRARIES)
libnet_la_LIBADD =
am__objects_4 = libnet_la-addr2ascii.lo libnet_la-ascii2addr.lo \
- libnet_la-base64.lo libnet_la-bindresvport.lo \
- libnet_la-ether_addr.lo libnet_la-getaddrinfo.lo \
- libnet_la-gethostbydns.lo libnet_la-gethostbyht.lo \
- libnet_la-gethostbynis.lo libnet_la-gethostnamadr.lo \
- libnet_la-getifaddrs.lo libnet_la-getnameinfo.lo \
- libnet_la-getnetbydns.lo libnet_la-getnetbyht.lo \
- libnet_la-getnetbynis.lo libnet_la-getnetnamadr.lo \
- libnet_la-getproto.lo libnet_la-getprotoent.lo \
- libnet_la-getprotoname.lo libnet_la-getservbyname.lo \
- libnet_la-getservbyport.lo libnet_la-getservent.lo \
- libnet_la-herror.lo libnet_la-hesiod.lo libnet_la-inet_addr.lo \
- libnet_la-ifname.lo libnet_la-inet_lnaof.lo \
- libnet_la-inet_makeaddr.lo libnet_la-inet_net_ntop.lo \
- libnet_la-inet_net_pton.lo libnet_la-inet_neta.lo \
- libnet_la-inet_netof.lo libnet_la-inet_network.lo \
+ libnet_la-alias-lookup.lo libnet_la-base64.lo \
+ libnet_la-check_pf.lo libnet_la-digits_dots.lo \
+ libnet_la-ether_aton.lo libnet_la-ether_aton_r.lo \
+ libnet_la-ether_hton.lo libnet_la-ether_line.lo \
+ libnet_la-ether_ntoa.lo libnet_la-ether_ntoa_r.lo \
+ libnet_la-ether_ntoh.lo libnet_la-ethers-lookup.lo \
+ libnet_la-getaddrinfo.lo libnet_la-getaliasent.lo \
+ libnet_la-getaliasent_r.lo libnet_la-getaliasname.lo \
+ libnet_la-getaliasname_r.lo libnet_la-gethstbyad.lo \
+ libnet_la-gethstbyad_r.lo libnet_la-gethstbynm2.lo \
+ libnet_la-gethstbynm2_r.lo libnet_la-gethstbynm.lo \
+ libnet_la-gethstbynm_r.lo libnet_la-gethstent.lo \
+ libnet_la-gethstent_r.lo libnet_la-getnameinfo.lo \
+ libnet_la-getnetbyad.lo libnet_la-getnetbyad_r.lo \
+ libnet_la-getnetbynm.lo libnet_la-getnetbynm_r.lo \
+ libnet_la-getnetent.lo libnet_la-getnetent_r.lo \
+ libnet_la-getnetgrent.lo libnet_la-getnetgrent_r.lo \
+ libnet_la-getnssent.lo libnet_la-getnssent_r.lo \
+ libnet_la-getproto.lo libnet_la-getproto_r.lo \
+ libnet_la-getprtent.lo libnet_la-getprtent_r.lo \
+ libnet_la-getprtname.lo libnet_la-getprtname_r.lo \
+ libnet_la-getrpcbyname.lo libnet_la-getrpcbyname_r.lo \
+ libnet_la-getrpcbynumber.lo libnet_la-getrpcbynumber_r.lo \
+ libnet_la-getrpcent.lo libnet_la-getrpcent_r.lo \
+ libnet_la-getservent.lo libnet_la-getservent_r.lo \
+ libnet_la-getsrvbynm.lo libnet_la-getsrvbynm_r.lo \
+ libnet_la-getsrvbypt.lo libnet_la-getsrvbypt_r.lo \
+ libnet_la-grp-lookup.lo libnet_la-herrno.lo \
+ libnet_la-hosts-lookup.lo libnet_la-ifreq.lo \
+ libnet_la-in6_addr.lo libnet_la-inet6_option.lo \
+ libnet_la-inet_addr.lo libnet_la-inet_lnaof.lo \
+ libnet_la-inet_mkadr.lo libnet_la-inet_net.lo \
+ libnet_la-inet_neta.lo libnet_la-inet_netof.lo \
+ libnet_la-inet_net_ntop.lo libnet_la-inet_net_pton.lo \
libnet_la-inet_ntoa.lo libnet_la-inet_ntop.lo \
- libnet_la-inet_pton.lo libnet_la-innetgr-stub.lo \
- libnet_la-ip6opt.lo libnet_la-issetugid-stub.lo \
- libnet_la-linkaddr.lo libnet_la-map_v4v6.lo libnet_la-name6.lo \
- libnet_la-ns_addr.lo libnet_la-ns_name.lo \
- libnet_la-ns_netint.lo libnet_la-ns_ntoa.lo \
+ libnet_la-inet_pton.lo libnet_la-issetugid-stub.lo \
+ libnet_la-key-lookup.lo libnet_la-netgrp-lookup.lo \
+ libnet_la-network-lookup.lo libnet_la-nsswitch.lo \
+ libnet_la-ns_name.lo libnet_la-ns_netint.lo \
libnet_la-ns_parse.lo libnet_la-ns_print.lo \
- libnet_la-ns_ttl.lo libnet_la-nsdispatch.lo \
- libnet_la-nslexer.lo libnet_la-nsparser.lo \
- libnet_la-nsap_addr.lo libnet_la-res_comp.lo \
- libnet_la-res_data.lo libnet_la-res_debug.lo \
- libnet_la-res_init.lo libnet_la-res_mkquery.lo \
- libnet_la-res_mkupdate.lo libnet_la-res_query.lo \
- libnet_la-res_send.lo libnet_la-res_update.lo \
- libnet_la-rthdr.lo libnet_la-vars.lo
+ libnet_la-ns_samedomain.lo libnet_la-ns_ttl.lo \
+ libnet_la-nsap_addr.lo libnet_la-proto-lookup.lo \
+ libnet_la-opensock.lo libnet_la-pwd-lookup.lo \
+ libnet_la-recv.lo libnet_la-res_comp.lo libnet_la-res_data.lo \
+ libnet_la-res_debug.lo libnet_la-res_hconf.lo \
+ libnet_la-res_init.lo libnet_la-res_libc.lo \
+ libnet_la-res_mkquery.lo libnet_la-res_query.lo \
+ libnet_la-res_send.lo libnet_la-rexec.lo \
+ libnet_la-rpc-lookup.lo libnet_la-ruserpass.lo \
+ libnet_la-send.lo libnet_la-service-lookup.lo \
+ libnet_la-spwd-lookup.lo
+am__objects_5 = libnet_la-ifname.lo
+@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = $(am__objects_5)
@USE_LIBTOOL_TRUE@am_libnet_la_OBJECTS = $(am__objects_4) \
-@USE_LIBTOOL_TRUE@ $(am__objects_3)
+@USE_LIBTOOL_TRUE@ $(am__objects_6)
libnet_la_OBJECTS = $(am_libnet_la_OBJECTS)
@USE_LIBTOOL_TRUE@am_libnet_la_rpath =
DEFAULT_INCLUDES = -I. -I$(srcdir)
@@ -277,27 +321,37 @@ sys_dir = @sys_dir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
AUTOMAKE_OPTIONS = cygnus
-INCLUDES = -I$(srcdir)/../include $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-GENERAL_SOURCES = addr2ascii.c ascii2addr.c base64.c bindresvport.c ether_addr.c getaddrinfo.c \
- gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \
- getifaddrs.c getnameinfo.c \
- getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \
- getproto.c getprotoent.c getprotoname.c getservbyname.c \
- getservbyport.c getservent.c herror.c hesiod.c inet_addr.c \
- ifname.c inet_lnaof.c \
- inet_makeaddr.c inet_net_ntop.c inet_net_pton.c inet_neta.c \
- inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \
- inet_pton.c innetgr-stub.c ip6opt.c issetugid-stub.c \
- linkaddr.c map_v4v6.c namespace.h un-namespace.h \
- name6.c ns_addr.c \
- ns_name.c ns_netint.c \
- ns_ntoa.c ns_parse.c ns_print.c ns_ttl.c \
- nsdispatch.c nslexer.c nsparser.c nsparser.h \
- nsap_addr.c res_comp.c res_data.c res_debug.c \
- res_init.c res_mkquery.c res_mkupdate.c res_query.c \
- res_send.c res_update.c rthdr.c vars.c
+INCLUDES = -I$(srcdir)/../include -I$(srcdir)/.. $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+GENERAL_SOURCES = addr2ascii.c ascii2addr.c alias-lookup.c \
+ base64.c check_pf.c digits_dots.c \
+ ether_aton.c ether_aton_r.c ether_hton.c \
+ ether_line.c ether_ntoa.c ether_ntoa_r.c ether_ntoh.c \
+ ethers-lookup.c getaddrinfo.c getaliasent.c \
+ getaliasent_r.c getaliasname.c getaliasname_r.c gethstbyad.c \
+ gethstbyad_r.c gethstbynm2.c gethstbynm2_r.c gethstbynm.c \
+ gethstbynm_r.c gethstent.c gethstent_r.c getnameinfo.c getnetbyad.c \
+ getnetbyad_r.c getnetbynm.c getnetbynm_r.c getnetent.c getnetent_r.c \
+ getnetgrent.c getnetgrent_r.c getnssent.c getnssent_r.c getproto.c \
+ getproto_r.c getprtent.c \
+ getprtent_r.c getprtname.c getprtname_r.c getrpcbyname.c \
+ getrpcbyname_r.c getrpcbynumber.c getrpcbynumber_r.c getrpcent.c \
+ getrpcent_r.c getservent.c getservent_r.c getsrvbynm.c getsrvbynm_r.c \
+ getsrvbypt.c getsrvbypt_r.c grp-lookup.c \
+ herrno.c hosts-lookup.c ifreq.c \
+ in6_addr.c inet6_option.c inet_addr.c \
+ inet_lnaof.c inet_mkadr.c inet_net.c inet_neta.c inet_netof.c \
+ inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c \
+ inet_pton.c issetugid-stub.c key-lookup.c netgrp-lookup.c \
+ network-lookup.c nsswitch.c \
+ ns_name.c ns_netint.c ns_parse.c ns_print.c ns_samedomain.c \
+ ns_ttl.c nsap_addr.c proto-lookup.c opensock.c pwd-lookup.c recv.c \
+ res_comp.c res_data.c res_debug.c res_hconf.c res_init.c \
+ res_libc.c res_mkquery.c \
+ res_query.c res_send.c \
+ rexec.c rpc-lookup.c ruserpass.c send.c service-lookup.c spwd-lookup.c
ELIX_4_SOURCES = \
+ ifname.c \
rcmd.$(oext) \
rcmdsh.$(oext)
@@ -393,23 +447,77 @@ lib_a-ascii2addr.o: ascii2addr.c
lib_a-ascii2addr.obj: ascii2addr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ascii2addr.obj `if test -f 'ascii2addr.c'; then $(CYGPATH_W) 'ascii2addr.c'; else $(CYGPATH_W) '$(srcdir)/ascii2addr.c'; fi`
+lib_a-alias-lookup.o: alias-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-alias-lookup.o `test -f 'alias-lookup.c' || echo '$(srcdir)/'`alias-lookup.c
+
+lib_a-alias-lookup.obj: alias-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-alias-lookup.obj `if test -f 'alias-lookup.c'; then $(CYGPATH_W) 'alias-lookup.c'; else $(CYGPATH_W) '$(srcdir)/alias-lookup.c'; fi`
+
lib_a-base64.o: base64.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-base64.o `test -f 'base64.c' || echo '$(srcdir)/'`base64.c
lib_a-base64.obj: base64.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-base64.obj `if test -f 'base64.c'; then $(CYGPATH_W) 'base64.c'; else $(CYGPATH_W) '$(srcdir)/base64.c'; fi`
-lib_a-bindresvport.o: bindresvport.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bindresvport.o `test -f 'bindresvport.c' || echo '$(srcdir)/'`bindresvport.c
+lib_a-check_pf.o: check_pf.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-check_pf.o `test -f 'check_pf.c' || echo '$(srcdir)/'`check_pf.c
+
+lib_a-check_pf.obj: check_pf.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-check_pf.obj `if test -f 'check_pf.c'; then $(CYGPATH_W) 'check_pf.c'; else $(CYGPATH_W) '$(srcdir)/check_pf.c'; fi`
+
+lib_a-digits_dots.o: digits_dots.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-digits_dots.o `test -f 'digits_dots.c' || echo '$(srcdir)/'`digits_dots.c
+
+lib_a-digits_dots.obj: digits_dots.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-digits_dots.obj `if test -f 'digits_dots.c'; then $(CYGPATH_W) 'digits_dots.c'; else $(CYGPATH_W) '$(srcdir)/digits_dots.c'; fi`
+
+lib_a-ether_aton.o: ether_aton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton.o `test -f 'ether_aton.c' || echo '$(srcdir)/'`ether_aton.c
+
+lib_a-ether_aton.obj: ether_aton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton.obj `if test -f 'ether_aton.c'; then $(CYGPATH_W) 'ether_aton.c'; else $(CYGPATH_W) '$(srcdir)/ether_aton.c'; fi`
+
+lib_a-ether_aton_r.o: ether_aton_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton_r.o `test -f 'ether_aton_r.c' || echo '$(srcdir)/'`ether_aton_r.c
+
+lib_a-ether_aton_r.obj: ether_aton_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton_r.obj `if test -f 'ether_aton_r.c'; then $(CYGPATH_W) 'ether_aton_r.c'; else $(CYGPATH_W) '$(srcdir)/ether_aton_r.c'; fi`
+
+lib_a-ether_hton.o: ether_hton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_hton.o `test -f 'ether_hton.c' || echo '$(srcdir)/'`ether_hton.c
+
+lib_a-ether_hton.obj: ether_hton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_hton.obj `if test -f 'ether_hton.c'; then $(CYGPATH_W) 'ether_hton.c'; else $(CYGPATH_W) '$(srcdir)/ether_hton.c'; fi`
+
+lib_a-ether_line.o: ether_line.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_line.o `test -f 'ether_line.c' || echo '$(srcdir)/'`ether_line.c
+
+lib_a-ether_line.obj: ether_line.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_line.obj `if test -f 'ether_line.c'; then $(CYGPATH_W) 'ether_line.c'; else $(CYGPATH_W) '$(srcdir)/ether_line.c'; fi`
-lib_a-bindresvport.obj: bindresvport.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bindresvport.obj `if test -f 'bindresvport.c'; then $(CYGPATH_W) 'bindresvport.c'; else $(CYGPATH_W) '$(srcdir)/bindresvport.c'; fi`
+lib_a-ether_ntoa.o: ether_ntoa.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa.o `test -f 'ether_ntoa.c' || echo '$(srcdir)/'`ether_ntoa.c
-lib_a-ether_addr.o: ether_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_addr.o `test -f 'ether_addr.c' || echo '$(srcdir)/'`ether_addr.c
+lib_a-ether_ntoa.obj: ether_ntoa.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa.obj `if test -f 'ether_ntoa.c'; then $(CYGPATH_W) 'ether_ntoa.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoa.c'; fi`
-lib_a-ether_addr.obj: ether_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_addr.obj `if test -f 'ether_addr.c'; then $(CYGPATH_W) 'ether_addr.c'; else $(CYGPATH_W) '$(srcdir)/ether_addr.c'; fi`
+lib_a-ether_ntoa_r.o: ether_ntoa_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa_r.o `test -f 'ether_ntoa_r.c' || echo '$(srcdir)/'`ether_ntoa_r.c
+
+lib_a-ether_ntoa_r.obj: ether_ntoa_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa_r.obj `if test -f 'ether_ntoa_r.c'; then $(CYGPATH_W) 'ether_ntoa_r.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoa_r.c'; fi`
+
+lib_a-ether_ntoh.o: ether_ntoh.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoh.o `test -f 'ether_ntoh.c' || echo '$(srcdir)/'`ether_ntoh.c
+
+lib_a-ether_ntoh.obj: ether_ntoh.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoh.obj `if test -f 'ether_ntoh.c'; then $(CYGPATH_W) 'ether_ntoh.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoh.c'; fi`
+
+lib_a-ethers-lookup.o: ethers-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ethers-lookup.o `test -f 'ethers-lookup.c' || echo '$(srcdir)/'`ethers-lookup.c
+
+lib_a-ethers-lookup.obj: ethers-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ethers-lookup.obj `if test -f 'ethers-lookup.c'; then $(CYGPATH_W) 'ethers-lookup.c'; else $(CYGPATH_W) '$(srcdir)/ethers-lookup.c'; fi`
lib_a-getaddrinfo.o: getaddrinfo.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaddrinfo.o `test -f 'getaddrinfo.c' || echo '$(srcdir)/'`getaddrinfo.c
@@ -417,35 +525,77 @@ lib_a-getaddrinfo.o: getaddrinfo.c
lib_a-getaddrinfo.obj: getaddrinfo.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaddrinfo.obj `if test -f 'getaddrinfo.c'; then $(CYGPATH_W) 'getaddrinfo.c'; else $(CYGPATH_W) '$(srcdir)/getaddrinfo.c'; fi`
-lib_a-gethostbydns.o: gethostbydns.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbydns.o `test -f 'gethostbydns.c' || echo '$(srcdir)/'`gethostbydns.c
+lib_a-getaliasent.o: getaliasent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent.o `test -f 'getaliasent.c' || echo '$(srcdir)/'`getaliasent.c
+
+lib_a-getaliasent.obj: getaliasent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent.obj `if test -f 'getaliasent.c'; then $(CYGPATH_W) 'getaliasent.c'; else $(CYGPATH_W) '$(srcdir)/getaliasent.c'; fi`
+
+lib_a-getaliasent_r.o: getaliasent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent_r.o `test -f 'getaliasent_r.c' || echo '$(srcdir)/'`getaliasent_r.c
+
+lib_a-getaliasent_r.obj: getaliasent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent_r.obj `if test -f 'getaliasent_r.c'; then $(CYGPATH_W) 'getaliasent_r.c'; else $(CYGPATH_W) '$(srcdir)/getaliasent_r.c'; fi`
+
+lib_a-getaliasname.o: getaliasname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname.o `test -f 'getaliasname.c' || echo '$(srcdir)/'`getaliasname.c
+
+lib_a-getaliasname.obj: getaliasname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname.obj `if test -f 'getaliasname.c'; then $(CYGPATH_W) 'getaliasname.c'; else $(CYGPATH_W) '$(srcdir)/getaliasname.c'; fi`
+
+lib_a-getaliasname_r.o: getaliasname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname_r.o `test -f 'getaliasname_r.c' || echo '$(srcdir)/'`getaliasname_r.c
+
+lib_a-getaliasname_r.obj: getaliasname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname_r.obj `if test -f 'getaliasname_r.c'; then $(CYGPATH_W) 'getaliasname_r.c'; else $(CYGPATH_W) '$(srcdir)/getaliasname_r.c'; fi`
+
+lib_a-gethstbyad.o: gethstbyad.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad.o `test -f 'gethstbyad.c' || echo '$(srcdir)/'`gethstbyad.c
-lib_a-gethostbydns.obj: gethostbydns.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbydns.obj `if test -f 'gethostbydns.c'; then $(CYGPATH_W) 'gethostbydns.c'; else $(CYGPATH_W) '$(srcdir)/gethostbydns.c'; fi`
+lib_a-gethstbyad.obj: gethstbyad.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad.obj `if test -f 'gethstbyad.c'; then $(CYGPATH_W) 'gethstbyad.c'; else $(CYGPATH_W) '$(srcdir)/gethstbyad.c'; fi`
-lib_a-gethostbyht.o: gethostbyht.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbyht.o `test -f 'gethostbyht.c' || echo '$(srcdir)/'`gethostbyht.c
+lib_a-gethstbyad_r.o: gethstbyad_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad_r.o `test -f 'gethstbyad_r.c' || echo '$(srcdir)/'`gethstbyad_r.c
-lib_a-gethostbyht.obj: gethostbyht.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbyht.obj `if test -f 'gethostbyht.c'; then $(CYGPATH_W) 'gethostbyht.c'; else $(CYGPATH_W) '$(srcdir)/gethostbyht.c'; fi`
+lib_a-gethstbyad_r.obj: gethstbyad_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad_r.obj `if test -f 'gethstbyad_r.c'; then $(CYGPATH_W) 'gethstbyad_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbyad_r.c'; fi`
-lib_a-gethostbynis.o: gethostbynis.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbynis.o `test -f 'gethostbynis.c' || echo '$(srcdir)/'`gethostbynis.c
+lib_a-gethstbynm2.o: gethstbynm2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2.o `test -f 'gethstbynm2.c' || echo '$(srcdir)/'`gethstbynm2.c
-lib_a-gethostbynis.obj: gethostbynis.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbynis.obj `if test -f 'gethostbynis.c'; then $(CYGPATH_W) 'gethostbynis.c'; else $(CYGPATH_W) '$(srcdir)/gethostbynis.c'; fi`
+lib_a-gethstbynm2.obj: gethstbynm2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2.obj `if test -f 'gethstbynm2.c'; then $(CYGPATH_W) 'gethstbynm2.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm2.c'; fi`
-lib_a-gethostnamadr.o: gethostnamadr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostnamadr.o `test -f 'gethostnamadr.c' || echo '$(srcdir)/'`gethostnamadr.c
+lib_a-gethstbynm2_r.o: gethstbynm2_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2_r.o `test -f 'gethstbynm2_r.c' || echo '$(srcdir)/'`gethstbynm2_r.c
-lib_a-gethostnamadr.obj: gethostnamadr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostnamadr.obj `if test -f 'gethostnamadr.c'; then $(CYGPATH_W) 'gethostnamadr.c'; else $(CYGPATH_W) '$(srcdir)/gethostnamadr.c'; fi`
+lib_a-gethstbynm2_r.obj: gethstbynm2_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2_r.obj `if test -f 'gethstbynm2_r.c'; then $(CYGPATH_W) 'gethstbynm2_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm2_r.c'; fi`
-lib_a-getifaddrs.o: getifaddrs.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getifaddrs.o `test -f 'getifaddrs.c' || echo '$(srcdir)/'`getifaddrs.c
+lib_a-gethstbynm.o: gethstbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm.o `test -f 'gethstbynm.c' || echo '$(srcdir)/'`gethstbynm.c
-lib_a-getifaddrs.obj: getifaddrs.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getifaddrs.obj `if test -f 'getifaddrs.c'; then $(CYGPATH_W) 'getifaddrs.c'; else $(CYGPATH_W) '$(srcdir)/getifaddrs.c'; fi`
+lib_a-gethstbynm.obj: gethstbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm.obj `if test -f 'gethstbynm.c'; then $(CYGPATH_W) 'gethstbynm.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm.c'; fi`
+
+lib_a-gethstbynm_r.o: gethstbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm_r.o `test -f 'gethstbynm_r.c' || echo '$(srcdir)/'`gethstbynm_r.c
+
+lib_a-gethstbynm_r.obj: gethstbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm_r.obj `if test -f 'gethstbynm_r.c'; then $(CYGPATH_W) 'gethstbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm_r.c'; fi`
+
+lib_a-gethstent.o: gethstent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent.o `test -f 'gethstent.c' || echo '$(srcdir)/'`gethstent.c
+
+lib_a-gethstent.obj: gethstent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent.obj `if test -f 'gethstent.c'; then $(CYGPATH_W) 'gethstent.c'; else $(CYGPATH_W) '$(srcdir)/gethstent.c'; fi`
+
+lib_a-gethstent_r.o: gethstent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent_r.o `test -f 'gethstent_r.c' || echo '$(srcdir)/'`gethstent_r.c
+
+lib_a-gethstent_r.obj: gethstent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent_r.obj `if test -f 'gethstent_r.c'; then $(CYGPATH_W) 'gethstent_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstent_r.c'; fi`
lib_a-getnameinfo.o: getnameinfo.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnameinfo.o `test -f 'getnameinfo.c' || echo '$(srcdir)/'`getnameinfo.c
@@ -453,29 +603,65 @@ lib_a-getnameinfo.o: getnameinfo.c
lib_a-getnameinfo.obj: getnameinfo.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnameinfo.obj `if test -f 'getnameinfo.c'; then $(CYGPATH_W) 'getnameinfo.c'; else $(CYGPATH_W) '$(srcdir)/getnameinfo.c'; fi`
-lib_a-getnetbydns.o: getnetbydns.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbydns.o `test -f 'getnetbydns.c' || echo '$(srcdir)/'`getnetbydns.c
+lib_a-getnetbyad.o: getnetbyad.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad.o `test -f 'getnetbyad.c' || echo '$(srcdir)/'`getnetbyad.c
+
+lib_a-getnetbyad.obj: getnetbyad.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad.obj `if test -f 'getnetbyad.c'; then $(CYGPATH_W) 'getnetbyad.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyad.c'; fi`
+
+lib_a-getnetbyad_r.o: getnetbyad_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad_r.o `test -f 'getnetbyad_r.c' || echo '$(srcdir)/'`getnetbyad_r.c
+
+lib_a-getnetbyad_r.obj: getnetbyad_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad_r.obj `if test -f 'getnetbyad_r.c'; then $(CYGPATH_W) 'getnetbyad_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyad_r.c'; fi`
+
+lib_a-getnetbynm.o: getnetbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm.o `test -f 'getnetbynm.c' || echo '$(srcdir)/'`getnetbynm.c
+
+lib_a-getnetbynm.obj: getnetbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm.obj `if test -f 'getnetbynm.c'; then $(CYGPATH_W) 'getnetbynm.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynm.c'; fi`
+
+lib_a-getnetbynm_r.o: getnetbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm_r.o `test -f 'getnetbynm_r.c' || echo '$(srcdir)/'`getnetbynm_r.c
+
+lib_a-getnetbynm_r.obj: getnetbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm_r.obj `if test -f 'getnetbynm_r.c'; then $(CYGPATH_W) 'getnetbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynm_r.c'; fi`
-lib_a-getnetbydns.obj: getnetbydns.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbydns.obj `if test -f 'getnetbydns.c'; then $(CYGPATH_W) 'getnetbydns.c'; else $(CYGPATH_W) '$(srcdir)/getnetbydns.c'; fi`
+lib_a-getnetent.o: getnetent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent.o `test -f 'getnetent.c' || echo '$(srcdir)/'`getnetent.c
-lib_a-getnetbyht.o: getnetbyht.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyht.o `test -f 'getnetbyht.c' || echo '$(srcdir)/'`getnetbyht.c
+lib_a-getnetent.obj: getnetent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent.obj `if test -f 'getnetent.c'; then $(CYGPATH_W) 'getnetent.c'; else $(CYGPATH_W) '$(srcdir)/getnetent.c'; fi`
-lib_a-getnetbyht.obj: getnetbyht.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyht.obj `if test -f 'getnetbyht.c'; then $(CYGPATH_W) 'getnetbyht.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyht.c'; fi`
+lib_a-getnetent_r.o: getnetent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent_r.o `test -f 'getnetent_r.c' || echo '$(srcdir)/'`getnetent_r.c
-lib_a-getnetbynis.o: getnetbynis.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynis.o `test -f 'getnetbynis.c' || echo '$(srcdir)/'`getnetbynis.c
+lib_a-getnetent_r.obj: getnetent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent_r.obj `if test -f 'getnetent_r.c'; then $(CYGPATH_W) 'getnetent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetent_r.c'; fi`
-lib_a-getnetbynis.obj: getnetbynis.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynis.obj `if test -f 'getnetbynis.c'; then $(CYGPATH_W) 'getnetbynis.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynis.c'; fi`
+lib_a-getnetgrent.o: getnetgrent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent.o `test -f 'getnetgrent.c' || echo '$(srcdir)/'`getnetgrent.c
-lib_a-getnetnamadr.o: getnetnamadr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetnamadr.o `test -f 'getnetnamadr.c' || echo '$(srcdir)/'`getnetnamadr.c
+lib_a-getnetgrent.obj: getnetgrent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent.obj `if test -f 'getnetgrent.c'; then $(CYGPATH_W) 'getnetgrent.c'; else $(CYGPATH_W) '$(srcdir)/getnetgrent.c'; fi`
-lib_a-getnetnamadr.obj: getnetnamadr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetnamadr.obj `if test -f 'getnetnamadr.c'; then $(CYGPATH_W) 'getnetnamadr.c'; else $(CYGPATH_W) '$(srcdir)/getnetnamadr.c'; fi`
+lib_a-getnetgrent_r.o: getnetgrent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent_r.o `test -f 'getnetgrent_r.c' || echo '$(srcdir)/'`getnetgrent_r.c
+
+lib_a-getnetgrent_r.obj: getnetgrent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent_r.obj `if test -f 'getnetgrent_r.c'; then $(CYGPATH_W) 'getnetgrent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetgrent_r.c'; fi`
+
+lib_a-getnssent.o: getnssent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent.o `test -f 'getnssent.c' || echo '$(srcdir)/'`getnssent.c
+
+lib_a-getnssent.obj: getnssent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent.obj `if test -f 'getnssent.c'; then $(CYGPATH_W) 'getnssent.c'; else $(CYGPATH_W) '$(srcdir)/getnssent.c'; fi`
+
+lib_a-getnssent_r.o: getnssent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent_r.o `test -f 'getnssent_r.c' || echo '$(srcdir)/'`getnssent_r.c
+
+lib_a-getnssent_r.obj: getnssent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent_r.obj `if test -f 'getnssent_r.c'; then $(CYGPATH_W) 'getnssent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnssent_r.c'; fi`
lib_a-getproto.o: getproto.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto.o `test -f 'getproto.c' || echo '$(srcdir)/'`getproto.c
@@ -483,29 +669,71 @@ lib_a-getproto.o: getproto.c
lib_a-getproto.obj: getproto.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto.obj `if test -f 'getproto.c'; then $(CYGPATH_W) 'getproto.c'; else $(CYGPATH_W) '$(srcdir)/getproto.c'; fi`
-lib_a-getprotoent.o: getprotoent.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoent.o `test -f 'getprotoent.c' || echo '$(srcdir)/'`getprotoent.c
+lib_a-getproto_r.o: getproto_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto_r.o `test -f 'getproto_r.c' || echo '$(srcdir)/'`getproto_r.c
+
+lib_a-getproto_r.obj: getproto_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto_r.obj `if test -f 'getproto_r.c'; then $(CYGPATH_W) 'getproto_r.c'; else $(CYGPATH_W) '$(srcdir)/getproto_r.c'; fi`
+
+lib_a-getprtent.o: getprtent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent.o `test -f 'getprtent.c' || echo '$(srcdir)/'`getprtent.c
+
+lib_a-getprtent.obj: getprtent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent.obj `if test -f 'getprtent.c'; then $(CYGPATH_W) 'getprtent.c'; else $(CYGPATH_W) '$(srcdir)/getprtent.c'; fi`
+
+lib_a-getprtent_r.o: getprtent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent_r.o `test -f 'getprtent_r.c' || echo '$(srcdir)/'`getprtent_r.c
+
+lib_a-getprtent_r.obj: getprtent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent_r.obj `if test -f 'getprtent_r.c'; then $(CYGPATH_W) 'getprtent_r.c'; else $(CYGPATH_W) '$(srcdir)/getprtent_r.c'; fi`
+
+lib_a-getprtname.o: getprtname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname.o `test -f 'getprtname.c' || echo '$(srcdir)/'`getprtname.c
+
+lib_a-getprtname.obj: getprtname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname.obj `if test -f 'getprtname.c'; then $(CYGPATH_W) 'getprtname.c'; else $(CYGPATH_W) '$(srcdir)/getprtname.c'; fi`
+
+lib_a-getprtname_r.o: getprtname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname_r.o `test -f 'getprtname_r.c' || echo '$(srcdir)/'`getprtname_r.c
-lib_a-getprotoent.obj: getprotoent.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoent.obj `if test -f 'getprotoent.c'; then $(CYGPATH_W) 'getprotoent.c'; else $(CYGPATH_W) '$(srcdir)/getprotoent.c'; fi`
+lib_a-getprtname_r.obj: getprtname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname_r.obj `if test -f 'getprtname_r.c'; then $(CYGPATH_W) 'getprtname_r.c'; else $(CYGPATH_W) '$(srcdir)/getprtname_r.c'; fi`
-lib_a-getprotoname.o: getprotoname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoname.o `test -f 'getprotoname.c' || echo '$(srcdir)/'`getprotoname.c
+lib_a-getrpcbyname.o: getrpcbyname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname.o `test -f 'getrpcbyname.c' || echo '$(srcdir)/'`getrpcbyname.c
-lib_a-getprotoname.obj: getprotoname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoname.obj `if test -f 'getprotoname.c'; then $(CYGPATH_W) 'getprotoname.c'; else $(CYGPATH_W) '$(srcdir)/getprotoname.c'; fi`
+lib_a-getrpcbyname.obj: getrpcbyname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname.obj `if test -f 'getrpcbyname.c'; then $(CYGPATH_W) 'getrpcbyname.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbyname.c'; fi`
-lib_a-getservbyname.o: getservbyname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyname.o `test -f 'getservbyname.c' || echo '$(srcdir)/'`getservbyname.c
+lib_a-getrpcbyname_r.o: getrpcbyname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname_r.o `test -f 'getrpcbyname_r.c' || echo '$(srcdir)/'`getrpcbyname_r.c
-lib_a-getservbyname.obj: getservbyname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyname.obj `if test -f 'getservbyname.c'; then $(CYGPATH_W) 'getservbyname.c'; else $(CYGPATH_W) '$(srcdir)/getservbyname.c'; fi`
+lib_a-getrpcbyname_r.obj: getrpcbyname_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname_r.obj `if test -f 'getrpcbyname_r.c'; then $(CYGPATH_W) 'getrpcbyname_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbyname_r.c'; fi`
-lib_a-getservbyport.o: getservbyport.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyport.o `test -f 'getservbyport.c' || echo '$(srcdir)/'`getservbyport.c
+lib_a-getrpcbynumber.o: getrpcbynumber.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber.o `test -f 'getrpcbynumber.c' || echo '$(srcdir)/'`getrpcbynumber.c
-lib_a-getservbyport.obj: getservbyport.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyport.obj `if test -f 'getservbyport.c'; then $(CYGPATH_W) 'getservbyport.c'; else $(CYGPATH_W) '$(srcdir)/getservbyport.c'; fi`
+lib_a-getrpcbynumber.obj: getrpcbynumber.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber.obj `if test -f 'getrpcbynumber.c'; then $(CYGPATH_W) 'getrpcbynumber.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbynumber.c'; fi`
+
+lib_a-getrpcbynumber_r.o: getrpcbynumber_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber_r.o `test -f 'getrpcbynumber_r.c' || echo '$(srcdir)/'`getrpcbynumber_r.c
+
+lib_a-getrpcbynumber_r.obj: getrpcbynumber_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber_r.obj `if test -f 'getrpcbynumber_r.c'; then $(CYGPATH_W) 'getrpcbynumber_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbynumber_r.c'; fi`
+
+lib_a-getrpcent.o: getrpcent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent.o `test -f 'getrpcent.c' || echo '$(srcdir)/'`getrpcent.c
+
+lib_a-getrpcent.obj: getrpcent.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent.obj `if test -f 'getrpcent.c'; then $(CYGPATH_W) 'getrpcent.c'; else $(CYGPATH_W) '$(srcdir)/getrpcent.c'; fi`
+
+lib_a-getrpcent_r.o: getrpcent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent_r.o `test -f 'getrpcent_r.c' || echo '$(srcdir)/'`getrpcent_r.c
+
+lib_a-getrpcent_r.obj: getrpcent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent_r.obj `if test -f 'getrpcent_r.c'; then $(CYGPATH_W) 'getrpcent_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcent_r.c'; fi`
lib_a-getservent.o: getservent.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent.o `test -f 'getservent.c' || echo '$(srcdir)/'`getservent.c
@@ -513,17 +741,71 @@ lib_a-getservent.o: getservent.c
lib_a-getservent.obj: getservent.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent.obj `if test -f 'getservent.c'; then $(CYGPATH_W) 'getservent.c'; else $(CYGPATH_W) '$(srcdir)/getservent.c'; fi`
-lib_a-herror.o: herror.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herror.o `test -f 'herror.c' || echo '$(srcdir)/'`herror.c
+lib_a-getservent_r.o: getservent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent_r.o `test -f 'getservent_r.c' || echo '$(srcdir)/'`getservent_r.c
+
+lib_a-getservent_r.obj: getservent_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent_r.obj `if test -f 'getservent_r.c'; then $(CYGPATH_W) 'getservent_r.c'; else $(CYGPATH_W) '$(srcdir)/getservent_r.c'; fi`
+
+lib_a-getsrvbynm.o: getsrvbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm.o `test -f 'getsrvbynm.c' || echo '$(srcdir)/'`getsrvbynm.c
+
+lib_a-getsrvbynm.obj: getsrvbynm.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm.obj `if test -f 'getsrvbynm.c'; then $(CYGPATH_W) 'getsrvbynm.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbynm.c'; fi`
+
+lib_a-getsrvbynm_r.o: getsrvbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm_r.o `test -f 'getsrvbynm_r.c' || echo '$(srcdir)/'`getsrvbynm_r.c
+
+lib_a-getsrvbynm_r.obj: getsrvbynm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm_r.obj `if test -f 'getsrvbynm_r.c'; then $(CYGPATH_W) 'getsrvbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbynm_r.c'; fi`
+
+lib_a-getsrvbypt.o: getsrvbypt.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt.o `test -f 'getsrvbypt.c' || echo '$(srcdir)/'`getsrvbypt.c
+
+lib_a-getsrvbypt.obj: getsrvbypt.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt.obj `if test -f 'getsrvbypt.c'; then $(CYGPATH_W) 'getsrvbypt.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbypt.c'; fi`
-lib_a-herror.obj: herror.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herror.obj `if test -f 'herror.c'; then $(CYGPATH_W) 'herror.c'; else $(CYGPATH_W) '$(srcdir)/herror.c'; fi`
+lib_a-getsrvbypt_r.o: getsrvbypt_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt_r.o `test -f 'getsrvbypt_r.c' || echo '$(srcdir)/'`getsrvbypt_r.c
-lib_a-hesiod.o: hesiod.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hesiod.o `test -f 'hesiod.c' || echo '$(srcdir)/'`hesiod.c
+lib_a-getsrvbypt_r.obj: getsrvbypt_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt_r.obj `if test -f 'getsrvbypt_r.c'; then $(CYGPATH_W) 'getsrvbypt_r.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbypt_r.c'; fi`
-lib_a-hesiod.obj: hesiod.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hesiod.obj `if test -f 'hesiod.c'; then $(CYGPATH_W) 'hesiod.c'; else $(CYGPATH_W) '$(srcdir)/hesiod.c'; fi`
+lib_a-grp-lookup.o: grp-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-grp-lookup.o `test -f 'grp-lookup.c' || echo '$(srcdir)/'`grp-lookup.c
+
+lib_a-grp-lookup.obj: grp-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-grp-lookup.obj `if test -f 'grp-lookup.c'; then $(CYGPATH_W) 'grp-lookup.c'; else $(CYGPATH_W) '$(srcdir)/grp-lookup.c'; fi`
+
+lib_a-herrno.o: herrno.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herrno.o `test -f 'herrno.c' || echo '$(srcdir)/'`herrno.c
+
+lib_a-herrno.obj: herrno.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herrno.obj `if test -f 'herrno.c'; then $(CYGPATH_W) 'herrno.c'; else $(CYGPATH_W) '$(srcdir)/herrno.c'; fi`
+
+lib_a-hosts-lookup.o: hosts-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hosts-lookup.o `test -f 'hosts-lookup.c' || echo '$(srcdir)/'`hosts-lookup.c
+
+lib_a-hosts-lookup.obj: hosts-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hosts-lookup.obj `if test -f 'hosts-lookup.c'; then $(CYGPATH_W) 'hosts-lookup.c'; else $(CYGPATH_W) '$(srcdir)/hosts-lookup.c'; fi`
+
+lib_a-ifreq.o: ifreq.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifreq.o `test -f 'ifreq.c' || echo '$(srcdir)/'`ifreq.c
+
+lib_a-ifreq.obj: ifreq.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifreq.obj `if test -f 'ifreq.c'; then $(CYGPATH_W) 'ifreq.c'; else $(CYGPATH_W) '$(srcdir)/ifreq.c'; fi`
+
+lib_a-in6_addr.o: in6_addr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-in6_addr.o `test -f 'in6_addr.c' || echo '$(srcdir)/'`in6_addr.c
+
+lib_a-in6_addr.obj: in6_addr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-in6_addr.obj `if test -f 'in6_addr.c'; then $(CYGPATH_W) 'in6_addr.c'; else $(CYGPATH_W) '$(srcdir)/in6_addr.c'; fi`
+
+lib_a-inet6_option.o: inet6_option.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet6_option.o `test -f 'inet6_option.c' || echo '$(srcdir)/'`inet6_option.c
+
+lib_a-inet6_option.obj: inet6_option.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet6_option.obj `if test -f 'inet6_option.c'; then $(CYGPATH_W) 'inet6_option.c'; else $(CYGPATH_W) '$(srcdir)/inet6_option.c'; fi`
lib_a-inet_addr.o: inet_addr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_addr.o `test -f 'inet_addr.c' || echo '$(srcdir)/'`inet_addr.c
@@ -531,35 +813,23 @@ lib_a-inet_addr.o: inet_addr.c
lib_a-inet_addr.obj: inet_addr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_addr.obj `if test -f 'inet_addr.c'; then $(CYGPATH_W) 'inet_addr.c'; else $(CYGPATH_W) '$(srcdir)/inet_addr.c'; fi`
-lib_a-ifname.o: ifname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.o `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c
-
-lib_a-ifname.obj: ifname.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.obj `if test -f 'ifname.c'; then $(CYGPATH_W) 'ifname.c'; else $(CYGPATH_W) '$(srcdir)/ifname.c'; fi`
-
lib_a-inet_lnaof.o: inet_lnaof.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_lnaof.o `test -f 'inet_lnaof.c' || echo '$(srcdir)/'`inet_lnaof.c
lib_a-inet_lnaof.obj: inet_lnaof.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_lnaof.obj `if test -f 'inet_lnaof.c'; then $(CYGPATH_W) 'inet_lnaof.c'; else $(CYGPATH_W) '$(srcdir)/inet_lnaof.c'; fi`
-lib_a-inet_makeaddr.o: inet_makeaddr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_makeaddr.o `test -f 'inet_makeaddr.c' || echo '$(srcdir)/'`inet_makeaddr.c
+lib_a-inet_mkadr.o: inet_mkadr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_mkadr.o `test -f 'inet_mkadr.c' || echo '$(srcdir)/'`inet_mkadr.c
-lib_a-inet_makeaddr.obj: inet_makeaddr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_makeaddr.obj `if test -f 'inet_makeaddr.c'; then $(CYGPATH_W) 'inet_makeaddr.c'; else $(CYGPATH_W) '$(srcdir)/inet_makeaddr.c'; fi`
+lib_a-inet_mkadr.obj: inet_mkadr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_mkadr.obj `if test -f 'inet_mkadr.c'; then $(CYGPATH_W) 'inet_mkadr.c'; else $(CYGPATH_W) '$(srcdir)/inet_mkadr.c'; fi`
-lib_a-inet_net_ntop.o: inet_net_ntop.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.o `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c
+lib_a-inet_net.o: inet_net.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net.o `test -f 'inet_net.c' || echo '$(srcdir)/'`inet_net.c
-lib_a-inet_net_ntop.obj: inet_net_ntop.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.obj `if test -f 'inet_net_ntop.c'; then $(CYGPATH_W) 'inet_net_ntop.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_ntop.c'; fi`
-
-lib_a-inet_net_pton.o: inet_net_pton.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.o `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c
-
-lib_a-inet_net_pton.obj: inet_net_pton.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.obj `if test -f 'inet_net_pton.c'; then $(CYGPATH_W) 'inet_net_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_pton.c'; fi`
+lib_a-inet_net.obj: inet_net.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net.obj `if test -f 'inet_net.c'; then $(CYGPATH_W) 'inet_net.c'; else $(CYGPATH_W) '$(srcdir)/inet_net.c'; fi`
lib_a-inet_neta.o: inet_neta.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_neta.o `test -f 'inet_neta.c' || echo '$(srcdir)/'`inet_neta.c
@@ -573,11 +843,17 @@ lib_a-inet_netof.o: inet_netof.c
lib_a-inet_netof.obj: inet_netof.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_netof.obj `if test -f 'inet_netof.c'; then $(CYGPATH_W) 'inet_netof.c'; else $(CYGPATH_W) '$(srcdir)/inet_netof.c'; fi`
-lib_a-inet_network.o: inet_network.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_network.o `test -f 'inet_network.c' || echo '$(srcdir)/'`inet_network.c
+lib_a-inet_net_ntop.o: inet_net_ntop.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.o `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c
-lib_a-inet_network.obj: inet_network.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_network.obj `if test -f 'inet_network.c'; then $(CYGPATH_W) 'inet_network.c'; else $(CYGPATH_W) '$(srcdir)/inet_network.c'; fi`
+lib_a-inet_net_ntop.obj: inet_net_ntop.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.obj `if test -f 'inet_net_ntop.c'; then $(CYGPATH_W) 'inet_net_ntop.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_ntop.c'; fi`
+
+lib_a-inet_net_pton.o: inet_net_pton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.o `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c
+
+lib_a-inet_net_pton.obj: inet_net_pton.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.obj `if test -f 'inet_net_pton.c'; then $(CYGPATH_W) 'inet_net_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_pton.c'; fi`
lib_a-inet_ntoa.o: inet_ntoa.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_ntoa.o `test -f 'inet_ntoa.c' || echo '$(srcdir)/'`inet_ntoa.c
@@ -597,47 +873,35 @@ lib_a-inet_pton.o: inet_pton.c
lib_a-inet_pton.obj: inet_pton.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_pton.obj `if test -f 'inet_pton.c'; then $(CYGPATH_W) 'inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_pton.c'; fi`
-lib_a-innetgr-stub.o: innetgr-stub.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-innetgr-stub.o `test -f 'innetgr-stub.c' || echo '$(srcdir)/'`innetgr-stub.c
-
-lib_a-innetgr-stub.obj: innetgr-stub.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-innetgr-stub.obj `if test -f 'innetgr-stub.c'; then $(CYGPATH_W) 'innetgr-stub.c'; else $(CYGPATH_W) '$(srcdir)/innetgr-stub.c'; fi`
-
-lib_a-ip6opt.o: ip6opt.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ip6opt.o `test -f 'ip6opt.c' || echo '$(srcdir)/'`ip6opt.c
-
-lib_a-ip6opt.obj: ip6opt.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ip6opt.obj `if test -f 'ip6opt.c'; then $(CYGPATH_W) 'ip6opt.c'; else $(CYGPATH_W) '$(srcdir)/ip6opt.c'; fi`
-
lib_a-issetugid-stub.o: issetugid-stub.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-issetugid-stub.o `test -f 'issetugid-stub.c' || echo '$(srcdir)/'`issetugid-stub.c
lib_a-issetugid-stub.obj: issetugid-stub.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-issetugid-stub.obj `if test -f 'issetugid-stub.c'; then $(CYGPATH_W) 'issetugid-stub.c'; else $(CYGPATH_W) '$(srcdir)/issetugid-stub.c'; fi`
-lib_a-linkaddr.o: linkaddr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-linkaddr.o `test -f 'linkaddr.c' || echo '$(srcdir)/'`linkaddr.c
+lib_a-key-lookup.o: key-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-key-lookup.o `test -f 'key-lookup.c' || echo '$(srcdir)/'`key-lookup.c
-lib_a-linkaddr.obj: linkaddr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-linkaddr.obj `if test -f 'linkaddr.c'; then $(CYGPATH_W) 'linkaddr.c'; else $(CYGPATH_W) '$(srcdir)/linkaddr.c'; fi`
+lib_a-key-lookup.obj: key-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-key-lookup.obj `if test -f 'key-lookup.c'; then $(CYGPATH_W) 'key-lookup.c'; else $(CYGPATH_W) '$(srcdir)/key-lookup.c'; fi`
-lib_a-map_v4v6.o: map_v4v6.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-map_v4v6.o `test -f 'map_v4v6.c' || echo '$(srcdir)/'`map_v4v6.c
+lib_a-netgrp-lookup.o: netgrp-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-netgrp-lookup.o `test -f 'netgrp-lookup.c' || echo '$(srcdir)/'`netgrp-lookup.c
-lib_a-map_v4v6.obj: map_v4v6.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-map_v4v6.obj `if test -f 'map_v4v6.c'; then $(CYGPATH_W) 'map_v4v6.c'; else $(CYGPATH_W) '$(srcdir)/map_v4v6.c'; fi`
+lib_a-netgrp-lookup.obj: netgrp-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-netgrp-lookup.obj `if test -f 'netgrp-lookup.c'; then $(CYGPATH_W) 'netgrp-lookup.c'; else $(CYGPATH_W) '$(srcdir)/netgrp-lookup.c'; fi`
-lib_a-name6.o: name6.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-name6.o `test -f 'name6.c' || echo '$(srcdir)/'`name6.c
+lib_a-network-lookup.o: network-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-network-lookup.o `test -f 'network-lookup.c' || echo '$(srcdir)/'`network-lookup.c
-lib_a-name6.obj: name6.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-name6.obj `if test -f 'name6.c'; then $(CYGPATH_W) 'name6.c'; else $(CYGPATH_W) '$(srcdir)/name6.c'; fi`
+lib_a-network-lookup.obj: network-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-network-lookup.obj `if test -f 'network-lookup.c'; then $(CYGPATH_W) 'network-lookup.c'; else $(CYGPATH_W) '$(srcdir)/network-lookup.c'; fi`
-lib_a-ns_addr.o: ns_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_addr.o `test -f 'ns_addr.c' || echo '$(srcdir)/'`ns_addr.c
+lib_a-nsswitch.o: nsswitch.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsswitch.o `test -f 'nsswitch.c' || echo '$(srcdir)/'`nsswitch.c
-lib_a-ns_addr.obj: ns_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_addr.obj `if test -f 'ns_addr.c'; then $(CYGPATH_W) 'ns_addr.c'; else $(CYGPATH_W) '$(srcdir)/ns_addr.c'; fi`
+lib_a-nsswitch.obj: nsswitch.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsswitch.obj `if test -f 'nsswitch.c'; then $(CYGPATH_W) 'nsswitch.c'; else $(CYGPATH_W) '$(srcdir)/nsswitch.c'; fi`
lib_a-ns_name.o: ns_name.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_name.o `test -f 'ns_name.c' || echo '$(srcdir)/'`ns_name.c
@@ -651,12 +915,6 @@ lib_a-ns_netint.o: ns_netint.c
lib_a-ns_netint.obj: ns_netint.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_netint.obj `if test -f 'ns_netint.c'; then $(CYGPATH_W) 'ns_netint.c'; else $(CYGPATH_W) '$(srcdir)/ns_netint.c'; fi`
-lib_a-ns_ntoa.o: ns_ntoa.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ntoa.o `test -f 'ns_ntoa.c' || echo '$(srcdir)/'`ns_ntoa.c
-
-lib_a-ns_ntoa.obj: ns_ntoa.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ntoa.obj `if test -f 'ns_ntoa.c'; then $(CYGPATH_W) 'ns_ntoa.c'; else $(CYGPATH_W) '$(srcdir)/ns_ntoa.c'; fi`
-
lib_a-ns_parse.o: ns_parse.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_parse.o `test -f 'ns_parse.c' || echo '$(srcdir)/'`ns_parse.c
@@ -669,35 +927,47 @@ lib_a-ns_print.o: ns_print.c
lib_a-ns_print.obj: ns_print.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_print.obj `if test -f 'ns_print.c'; then $(CYGPATH_W) 'ns_print.c'; else $(CYGPATH_W) '$(srcdir)/ns_print.c'; fi`
+lib_a-ns_samedomain.o: ns_samedomain.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_samedomain.o `test -f 'ns_samedomain.c' || echo '$(srcdir)/'`ns_samedomain.c
+
+lib_a-ns_samedomain.obj: ns_samedomain.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_samedomain.obj `if test -f 'ns_samedomain.c'; then $(CYGPATH_W) 'ns_samedomain.c'; else $(CYGPATH_W) '$(srcdir)/ns_samedomain.c'; fi`
+
lib_a-ns_ttl.o: ns_ttl.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ttl.o `test -f 'ns_ttl.c' || echo '$(srcdir)/'`ns_ttl.c
lib_a-ns_ttl.obj: ns_ttl.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ttl.obj `if test -f 'ns_ttl.c'; then $(CYGPATH_W) 'ns_ttl.c'; else $(CYGPATH_W) '$(srcdir)/ns_ttl.c'; fi`
-lib_a-nsdispatch.o: nsdispatch.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsdispatch.o `test -f 'nsdispatch.c' || echo '$(srcdir)/'`nsdispatch.c
+lib_a-nsap_addr.o: nsap_addr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.o `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c
-lib_a-nsdispatch.obj: nsdispatch.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsdispatch.obj `if test -f 'nsdispatch.c'; then $(CYGPATH_W) 'nsdispatch.c'; else $(CYGPATH_W) '$(srcdir)/nsdispatch.c'; fi`
+lib_a-nsap_addr.obj: nsap_addr.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.obj `if test -f 'nsap_addr.c'; then $(CYGPATH_W) 'nsap_addr.c'; else $(CYGPATH_W) '$(srcdir)/nsap_addr.c'; fi`
-lib_a-nslexer.o: nslexer.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nslexer.o `test -f 'nslexer.c' || echo '$(srcdir)/'`nslexer.c
+lib_a-proto-lookup.o: proto-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-proto-lookup.o `test -f 'proto-lookup.c' || echo '$(srcdir)/'`proto-lookup.c
-lib_a-nslexer.obj: nslexer.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nslexer.obj `if test -f 'nslexer.c'; then $(CYGPATH_W) 'nslexer.c'; else $(CYGPATH_W) '$(srcdir)/nslexer.c'; fi`
+lib_a-proto-lookup.obj: proto-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-proto-lookup.obj `if test -f 'proto-lookup.c'; then $(CYGPATH_W) 'proto-lookup.c'; else $(CYGPATH_W) '$(srcdir)/proto-lookup.c'; fi`
-lib_a-nsparser.o: nsparser.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsparser.o `test -f 'nsparser.c' || echo '$(srcdir)/'`nsparser.c
+lib_a-opensock.o: opensock.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-opensock.o `test -f 'opensock.c' || echo '$(srcdir)/'`opensock.c
-lib_a-nsparser.obj: nsparser.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsparser.obj `if test -f 'nsparser.c'; then $(CYGPATH_W) 'nsparser.c'; else $(CYGPATH_W) '$(srcdir)/nsparser.c'; fi`
+lib_a-opensock.obj: opensock.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-opensock.obj `if test -f 'opensock.c'; then $(CYGPATH_W) 'opensock.c'; else $(CYGPATH_W) '$(srcdir)/opensock.c'; fi`
-lib_a-nsap_addr.o: nsap_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.o `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c
+lib_a-pwd-lookup.o: pwd-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-pwd-lookup.o `test -f 'pwd-lookup.c' || echo '$(srcdir)/'`pwd-lookup.c
-lib_a-nsap_addr.obj: nsap_addr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.obj `if test -f 'nsap_addr.c'; then $(CYGPATH_W) 'nsap_addr.c'; else $(CYGPATH_W) '$(srcdir)/nsap_addr.c'; fi`
+lib_a-pwd-lookup.obj: pwd-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-pwd-lookup.obj `if test -f 'pwd-lookup.c'; then $(CYGPATH_W) 'pwd-lookup.c'; else $(CYGPATH_W) '$(srcdir)/pwd-lookup.c'; fi`
+
+lib_a-recv.o: recv.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-recv.o `test -f 'recv.c' || echo '$(srcdir)/'`recv.c
+
+lib_a-recv.obj: recv.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-recv.obj `if test -f 'recv.c'; then $(CYGPATH_W) 'recv.c'; else $(CYGPATH_W) '$(srcdir)/recv.c'; fi`
lib_a-res_comp.o: res_comp.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_comp.o `test -f 'res_comp.c' || echo '$(srcdir)/'`res_comp.c
@@ -717,24 +987,30 @@ lib_a-res_debug.o: res_debug.c
lib_a-res_debug.obj: res_debug.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_debug.obj `if test -f 'res_debug.c'; then $(CYGPATH_W) 'res_debug.c'; else $(CYGPATH_W) '$(srcdir)/res_debug.c'; fi`
+lib_a-res_hconf.o: res_hconf.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_hconf.o `test -f 'res_hconf.c' || echo '$(srcdir)/'`res_hconf.c
+
+lib_a-res_hconf.obj: res_hconf.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_hconf.obj `if test -f 'res_hconf.c'; then $(CYGPATH_W) 'res_hconf.c'; else $(CYGPATH_W) '$(srcdir)/res_hconf.c'; fi`
+
lib_a-res_init.o: res_init.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_init.o `test -f 'res_init.c' || echo '$(srcdir)/'`res_init.c
lib_a-res_init.obj: res_init.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_init.obj `if test -f 'res_init.c'; then $(CYGPATH_W) 'res_init.c'; else $(CYGPATH_W) '$(srcdir)/res_init.c'; fi`
+lib_a-res_libc.o: res_libc.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_libc.o `test -f 'res_libc.c' || echo '$(srcdir)/'`res_libc.c
+
+lib_a-res_libc.obj: res_libc.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_libc.obj `if test -f 'res_libc.c'; then $(CYGPATH_W) 'res_libc.c'; else $(CYGPATH_W) '$(srcdir)/res_libc.c'; fi`
+
lib_a-res_mkquery.o: res_mkquery.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkquery.o `test -f 'res_mkquery.c' || echo '$(srcdir)/'`res_mkquery.c
lib_a-res_mkquery.obj: res_mkquery.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkquery.obj `if test -f 'res_mkquery.c'; then $(CYGPATH_W) 'res_mkquery.c'; else $(CYGPATH_W) '$(srcdir)/res_mkquery.c'; fi`
-lib_a-res_mkupdate.o: res_mkupdate.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkupdate.o `test -f 'res_mkupdate.c' || echo '$(srcdir)/'`res_mkupdate.c
-
-lib_a-res_mkupdate.obj: res_mkupdate.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkupdate.obj `if test -f 'res_mkupdate.c'; then $(CYGPATH_W) 'res_mkupdate.c'; else $(CYGPATH_W) '$(srcdir)/res_mkupdate.c'; fi`
-
lib_a-res_query.o: res_query.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_query.o `test -f 'res_query.c' || echo '$(srcdir)/'`res_query.c
@@ -747,23 +1023,47 @@ lib_a-res_send.o: res_send.c
lib_a-res_send.obj: res_send.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_send.obj `if test -f 'res_send.c'; then $(CYGPATH_W) 'res_send.c'; else $(CYGPATH_W) '$(srcdir)/res_send.c'; fi`
-lib_a-res_update.o: res_update.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_update.o `test -f 'res_update.c' || echo '$(srcdir)/'`res_update.c
+lib_a-rexec.o: rexec.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rexec.o `test -f 'rexec.c' || echo '$(srcdir)/'`rexec.c
+
+lib_a-rexec.obj: rexec.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rexec.obj `if test -f 'rexec.c'; then $(CYGPATH_W) 'rexec.c'; else $(CYGPATH_W) '$(srcdir)/rexec.c'; fi`
+
+lib_a-rpc-lookup.o: rpc-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rpc-lookup.o `test -f 'rpc-lookup.c' || echo '$(srcdir)/'`rpc-lookup.c
+
+lib_a-rpc-lookup.obj: rpc-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rpc-lookup.obj `if test -f 'rpc-lookup.c'; then $(CYGPATH_W) 'rpc-lookup.c'; else $(CYGPATH_W) '$(srcdir)/rpc-lookup.c'; fi`
+
+lib_a-ruserpass.o: ruserpass.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ruserpass.o `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c
-lib_a-res_update.obj: res_update.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_update.obj `if test -f 'res_update.c'; then $(CYGPATH_W) 'res_update.c'; else $(CYGPATH_W) '$(srcdir)/res_update.c'; fi`
+lib_a-ruserpass.obj: ruserpass.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ruserpass.obj `if test -f 'ruserpass.c'; then $(CYGPATH_W) 'ruserpass.c'; else $(CYGPATH_W) '$(srcdir)/ruserpass.c'; fi`
-lib_a-rthdr.o: rthdr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rthdr.o `test -f 'rthdr.c' || echo '$(srcdir)/'`rthdr.c
+lib_a-send.o: send.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-send.o `test -f 'send.c' || echo '$(srcdir)/'`send.c
-lib_a-rthdr.obj: rthdr.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rthdr.obj `if test -f 'rthdr.c'; then $(CYGPATH_W) 'rthdr.c'; else $(CYGPATH_W) '$(srcdir)/rthdr.c'; fi`
+lib_a-send.obj: send.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-send.obj `if test -f 'send.c'; then $(CYGPATH_W) 'send.c'; else $(CYGPATH_W) '$(srcdir)/send.c'; fi`
-lib_a-vars.o: vars.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vars.o `test -f 'vars.c' || echo '$(srcdir)/'`vars.c
+lib_a-service-lookup.o: service-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-service-lookup.o `test -f 'service-lookup.c' || echo '$(srcdir)/'`service-lookup.c
-lib_a-vars.obj: vars.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vars.obj `if test -f 'vars.c'; then $(CYGPATH_W) 'vars.c'; else $(CYGPATH_W) '$(srcdir)/vars.c'; fi`
+lib_a-service-lookup.obj: service-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-service-lookup.obj `if test -f 'service-lookup.c'; then $(CYGPATH_W) 'service-lookup.c'; else $(CYGPATH_W) '$(srcdir)/service-lookup.c'; fi`
+
+lib_a-spwd-lookup.o: spwd-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-spwd-lookup.o `test -f 'spwd-lookup.c' || echo '$(srcdir)/'`spwd-lookup.c
+
+lib_a-spwd-lookup.obj: spwd-lookup.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-spwd-lookup.obj `if test -f 'spwd-lookup.c'; then $(CYGPATH_W) 'spwd-lookup.c'; else $(CYGPATH_W) '$(srcdir)/spwd-lookup.c'; fi`
+
+lib_a-ifname.o: ifname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.o `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c
+
+lib_a-ifname.obj: ifname.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.obj `if test -f 'ifname.c'; then $(CYGPATH_W) 'ifname.c'; else $(CYGPATH_W) '$(srcdir)/ifname.c'; fi`
libnet_la-addr2ascii.lo: addr2ascii.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-addr2ascii.lo `test -f 'addr2ascii.c' || echo '$(srcdir)/'`addr2ascii.c
@@ -771,89 +1071,197 @@ libnet_la-addr2ascii.lo: addr2ascii.c
libnet_la-ascii2addr.lo: ascii2addr.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ascii2addr.lo `test -f 'ascii2addr.c' || echo '$(srcdir)/'`ascii2addr.c
+libnet_la-alias-lookup.lo: alias-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-alias-lookup.lo `test -f 'alias-lookup.c' || echo '$(srcdir)/'`alias-lookup.c
+
libnet_la-base64.lo: base64.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-base64.lo `test -f 'base64.c' || echo '$(srcdir)/'`base64.c
-libnet_la-bindresvport.lo: bindresvport.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-bindresvport.lo `test -f 'bindresvport.c' || echo '$(srcdir)/'`bindresvport.c
+libnet_la-check_pf.lo: check_pf.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-check_pf.lo `test -f 'check_pf.c' || echo '$(srcdir)/'`check_pf.c
+
+libnet_la-digits_dots.lo: digits_dots.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-digits_dots.lo `test -f 'digits_dots.c' || echo '$(srcdir)/'`digits_dots.c
+
+libnet_la-ether_aton.lo: ether_aton.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_aton.lo `test -f 'ether_aton.c' || echo '$(srcdir)/'`ether_aton.c
+
+libnet_la-ether_aton_r.lo: ether_aton_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_aton_r.lo `test -f 'ether_aton_r.c' || echo '$(srcdir)/'`ether_aton_r.c
+
+libnet_la-ether_hton.lo: ether_hton.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_hton.lo `test -f 'ether_hton.c' || echo '$(srcdir)/'`ether_hton.c
-libnet_la-ether_addr.lo: ether_addr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_addr.lo `test -f 'ether_addr.c' || echo '$(srcdir)/'`ether_addr.c
+libnet_la-ether_line.lo: ether_line.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_line.lo `test -f 'ether_line.c' || echo '$(srcdir)/'`ether_line.c
+
+libnet_la-ether_ntoa.lo: ether_ntoa.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoa.lo `test -f 'ether_ntoa.c' || echo '$(srcdir)/'`ether_ntoa.c
+
+libnet_la-ether_ntoa_r.lo: ether_ntoa_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoa_r.lo `test -f 'ether_ntoa_r.c' || echo '$(srcdir)/'`ether_ntoa_r.c
+
+libnet_la-ether_ntoh.lo: ether_ntoh.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoh.lo `test -f 'ether_ntoh.c' || echo '$(srcdir)/'`ether_ntoh.c
+
+libnet_la-ethers-lookup.lo: ethers-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ethers-lookup.lo `test -f 'ethers-lookup.c' || echo '$(srcdir)/'`ethers-lookup.c
libnet_la-getaddrinfo.lo: getaddrinfo.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaddrinfo.lo `test -f 'getaddrinfo.c' || echo '$(srcdir)/'`getaddrinfo.c
-libnet_la-gethostbydns.lo: gethostbydns.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbydns.lo `test -f 'gethostbydns.c' || echo '$(srcdir)/'`gethostbydns.c
+libnet_la-getaliasent.lo: getaliasent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasent.lo `test -f 'getaliasent.c' || echo '$(srcdir)/'`getaliasent.c
+
+libnet_la-getaliasent_r.lo: getaliasent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasent_r.lo `test -f 'getaliasent_r.c' || echo '$(srcdir)/'`getaliasent_r.c
+
+libnet_la-getaliasname.lo: getaliasname.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasname.lo `test -f 'getaliasname.c' || echo '$(srcdir)/'`getaliasname.c
+
+libnet_la-getaliasname_r.lo: getaliasname_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasname_r.lo `test -f 'getaliasname_r.c' || echo '$(srcdir)/'`getaliasname_r.c
-libnet_la-gethostbyht.lo: gethostbyht.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbyht.lo `test -f 'gethostbyht.c' || echo '$(srcdir)/'`gethostbyht.c
+libnet_la-gethstbyad.lo: gethstbyad.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbyad.lo `test -f 'gethstbyad.c' || echo '$(srcdir)/'`gethstbyad.c
-libnet_la-gethostbynis.lo: gethostbynis.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbynis.lo `test -f 'gethostbynis.c' || echo '$(srcdir)/'`gethostbynis.c
+libnet_la-gethstbyad_r.lo: gethstbyad_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbyad_r.lo `test -f 'gethstbyad_r.c' || echo '$(srcdir)/'`gethstbyad_r.c
-libnet_la-gethostnamadr.lo: gethostnamadr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostnamadr.lo `test -f 'gethostnamadr.c' || echo '$(srcdir)/'`gethostnamadr.c
+libnet_la-gethstbynm2.lo: gethstbynm2.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm2.lo `test -f 'gethstbynm2.c' || echo '$(srcdir)/'`gethstbynm2.c
-libnet_la-getifaddrs.lo: getifaddrs.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getifaddrs.lo `test -f 'getifaddrs.c' || echo '$(srcdir)/'`getifaddrs.c
+libnet_la-gethstbynm2_r.lo: gethstbynm2_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm2_r.lo `test -f 'gethstbynm2_r.c' || echo '$(srcdir)/'`gethstbynm2_r.c
+
+libnet_la-gethstbynm.lo: gethstbynm.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm.lo `test -f 'gethstbynm.c' || echo '$(srcdir)/'`gethstbynm.c
+
+libnet_la-gethstbynm_r.lo: gethstbynm_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm_r.lo `test -f 'gethstbynm_r.c' || echo '$(srcdir)/'`gethstbynm_r.c
+
+libnet_la-gethstent.lo: gethstent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstent.lo `test -f 'gethstent.c' || echo '$(srcdir)/'`gethstent.c
+
+libnet_la-gethstent_r.lo: gethstent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstent_r.lo `test -f 'gethstent_r.c' || echo '$(srcdir)/'`gethstent_r.c
libnet_la-getnameinfo.lo: getnameinfo.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnameinfo.lo `test -f 'getnameinfo.c' || echo '$(srcdir)/'`getnameinfo.c
-libnet_la-getnetbydns.lo: getnetbydns.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbydns.lo `test -f 'getnetbydns.c' || echo '$(srcdir)/'`getnetbydns.c
+libnet_la-getnetbyad.lo: getnetbyad.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyad.lo `test -f 'getnetbyad.c' || echo '$(srcdir)/'`getnetbyad.c
+
+libnet_la-getnetbyad_r.lo: getnetbyad_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyad_r.lo `test -f 'getnetbyad_r.c' || echo '$(srcdir)/'`getnetbyad_r.c
+
+libnet_la-getnetbynm.lo: getnetbynm.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynm.lo `test -f 'getnetbynm.c' || echo '$(srcdir)/'`getnetbynm.c
-libnet_la-getnetbyht.lo: getnetbyht.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyht.lo `test -f 'getnetbyht.c' || echo '$(srcdir)/'`getnetbyht.c
+libnet_la-getnetbynm_r.lo: getnetbynm_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynm_r.lo `test -f 'getnetbynm_r.c' || echo '$(srcdir)/'`getnetbynm_r.c
-libnet_la-getnetbynis.lo: getnetbynis.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynis.lo `test -f 'getnetbynis.c' || echo '$(srcdir)/'`getnetbynis.c
+libnet_la-getnetent.lo: getnetent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetent.lo `test -f 'getnetent.c' || echo '$(srcdir)/'`getnetent.c
-libnet_la-getnetnamadr.lo: getnetnamadr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetnamadr.lo `test -f 'getnetnamadr.c' || echo '$(srcdir)/'`getnetnamadr.c
+libnet_la-getnetent_r.lo: getnetent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetent_r.lo `test -f 'getnetent_r.c' || echo '$(srcdir)/'`getnetent_r.c
+
+libnet_la-getnetgrent.lo: getnetgrent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetgrent.lo `test -f 'getnetgrent.c' || echo '$(srcdir)/'`getnetgrent.c
+
+libnet_la-getnetgrent_r.lo: getnetgrent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetgrent_r.lo `test -f 'getnetgrent_r.c' || echo '$(srcdir)/'`getnetgrent_r.c
+
+libnet_la-getnssent.lo: getnssent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnssent.lo `test -f 'getnssent.c' || echo '$(srcdir)/'`getnssent.c
+
+libnet_la-getnssent_r.lo: getnssent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnssent_r.lo `test -f 'getnssent_r.c' || echo '$(srcdir)/'`getnssent_r.c
libnet_la-getproto.lo: getproto.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getproto.lo `test -f 'getproto.c' || echo '$(srcdir)/'`getproto.c
-libnet_la-getprotoent.lo: getprotoent.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprotoent.lo `test -f 'getprotoent.c' || echo '$(srcdir)/'`getprotoent.c
+libnet_la-getproto_r.lo: getproto_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getproto_r.lo `test -f 'getproto_r.c' || echo '$(srcdir)/'`getproto_r.c
+
+libnet_la-getprtent.lo: getprtent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtent.lo `test -f 'getprtent.c' || echo '$(srcdir)/'`getprtent.c
+
+libnet_la-getprtent_r.lo: getprtent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtent_r.lo `test -f 'getprtent_r.c' || echo '$(srcdir)/'`getprtent_r.c
+
+libnet_la-getprtname.lo: getprtname.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtname.lo `test -f 'getprtname.c' || echo '$(srcdir)/'`getprtname.c
-libnet_la-getprotoname.lo: getprotoname.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprotoname.lo `test -f 'getprotoname.c' || echo '$(srcdir)/'`getprotoname.c
+libnet_la-getprtname_r.lo: getprtname_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtname_r.lo `test -f 'getprtname_r.c' || echo '$(srcdir)/'`getprtname_r.c
-libnet_la-getservbyname.lo: getservbyname.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservbyname.lo `test -f 'getservbyname.c' || echo '$(srcdir)/'`getservbyname.c
+libnet_la-getrpcbyname.lo: getrpcbyname.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbyname.lo `test -f 'getrpcbyname.c' || echo '$(srcdir)/'`getrpcbyname.c
-libnet_la-getservbyport.lo: getservbyport.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservbyport.lo `test -f 'getservbyport.c' || echo '$(srcdir)/'`getservbyport.c
+libnet_la-getrpcbyname_r.lo: getrpcbyname_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbyname_r.lo `test -f 'getrpcbyname_r.c' || echo '$(srcdir)/'`getrpcbyname_r.c
+
+libnet_la-getrpcbynumber.lo: getrpcbynumber.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbynumber.lo `test -f 'getrpcbynumber.c' || echo '$(srcdir)/'`getrpcbynumber.c
+
+libnet_la-getrpcbynumber_r.lo: getrpcbynumber_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbynumber_r.lo `test -f 'getrpcbynumber_r.c' || echo '$(srcdir)/'`getrpcbynumber_r.c
+
+libnet_la-getrpcent.lo: getrpcent.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcent.lo `test -f 'getrpcent.c' || echo '$(srcdir)/'`getrpcent.c
+
+libnet_la-getrpcent_r.lo: getrpcent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcent_r.lo `test -f 'getrpcent_r.c' || echo '$(srcdir)/'`getrpcent_r.c
libnet_la-getservent.lo: getservent.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservent.lo `test -f 'getservent.c' || echo '$(srcdir)/'`getservent.c
-libnet_la-herror.lo: herror.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-herror.lo `test -f 'herror.c' || echo '$(srcdir)/'`herror.c
+libnet_la-getservent_r.lo: getservent_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservent_r.lo `test -f 'getservent_r.c' || echo '$(srcdir)/'`getservent_r.c
+
+libnet_la-getsrvbynm.lo: getsrvbynm.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbynm.lo `test -f 'getsrvbynm.c' || echo '$(srcdir)/'`getsrvbynm.c
+
+libnet_la-getsrvbynm_r.lo: getsrvbynm_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbynm_r.lo `test -f 'getsrvbynm_r.c' || echo '$(srcdir)/'`getsrvbynm_r.c
-libnet_la-hesiod.lo: hesiod.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-hesiod.lo `test -f 'hesiod.c' || echo '$(srcdir)/'`hesiod.c
+libnet_la-getsrvbypt.lo: getsrvbypt.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbypt.lo `test -f 'getsrvbypt.c' || echo '$(srcdir)/'`getsrvbypt.c
+
+libnet_la-getsrvbypt_r.lo: getsrvbypt_r.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbypt_r.lo `test -f 'getsrvbypt_r.c' || echo '$(srcdir)/'`getsrvbypt_r.c
+
+libnet_la-grp-lookup.lo: grp-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-grp-lookup.lo `test -f 'grp-lookup.c' || echo '$(srcdir)/'`grp-lookup.c
+
+libnet_la-herrno.lo: herrno.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-herrno.lo `test -f 'herrno.c' || echo '$(srcdir)/'`herrno.c
+
+libnet_la-hosts-lookup.lo: hosts-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-hosts-lookup.lo `test -f 'hosts-lookup.c' || echo '$(srcdir)/'`hosts-lookup.c
+
+libnet_la-ifreq.lo: ifreq.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifreq.lo `test -f 'ifreq.c' || echo '$(srcdir)/'`ifreq.c
+
+libnet_la-in6_addr.lo: in6_addr.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-in6_addr.lo `test -f 'in6_addr.c' || echo '$(srcdir)/'`in6_addr.c
+
+libnet_la-inet6_option.lo: inet6_option.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet6_option.lo `test -f 'inet6_option.c' || echo '$(srcdir)/'`inet6_option.c
libnet_la-inet_addr.lo: inet_addr.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_addr.lo `test -f 'inet_addr.c' || echo '$(srcdir)/'`inet_addr.c
-libnet_la-ifname.lo: ifname.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifname.lo `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c
-
libnet_la-inet_lnaof.lo: inet_lnaof.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_lnaof.lo `test -f 'inet_lnaof.c' || echo '$(srcdir)/'`inet_lnaof.c
-libnet_la-inet_makeaddr.lo: inet_makeaddr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_makeaddr.lo `test -f 'inet_makeaddr.c' || echo '$(srcdir)/'`inet_makeaddr.c
+libnet_la-inet_mkadr.lo: inet_mkadr.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_mkadr.lo `test -f 'inet_mkadr.c' || echo '$(srcdir)/'`inet_mkadr.c
-libnet_la-inet_net_ntop.lo: inet_net_ntop.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_ntop.lo `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c
-
-libnet_la-inet_net_pton.lo: inet_net_pton.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_pton.lo `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c
+libnet_la-inet_net.lo: inet_net.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net.lo `test -f 'inet_net.c' || echo '$(srcdir)/'`inet_net.c
libnet_la-inet_neta.lo: inet_neta.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_neta.lo `test -f 'inet_neta.c' || echo '$(srcdir)/'`inet_neta.c
@@ -861,8 +1269,11 @@ libnet_la-inet_neta.lo: inet_neta.c
libnet_la-inet_netof.lo: inet_netof.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_netof.lo `test -f 'inet_netof.c' || echo '$(srcdir)/'`inet_netof.c
-libnet_la-inet_network.lo: inet_network.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_network.lo `test -f 'inet_network.c' || echo '$(srcdir)/'`inet_network.c
+libnet_la-inet_net_ntop.lo: inet_net_ntop.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_ntop.lo `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c
+
+libnet_la-inet_net_pton.lo: inet_net_pton.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_pton.lo `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c
libnet_la-inet_ntoa.lo: inet_ntoa.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_ntoa.lo `test -f 'inet_ntoa.c' || echo '$(srcdir)/'`inet_ntoa.c
@@ -873,26 +1284,20 @@ libnet_la-inet_ntop.lo: inet_ntop.c
libnet_la-inet_pton.lo: inet_pton.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_pton.lo `test -f 'inet_pton.c' || echo '$(srcdir)/'`inet_pton.c
-libnet_la-innetgr-stub.lo: innetgr-stub.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-innetgr-stub.lo `test -f 'innetgr-stub.c' || echo '$(srcdir)/'`innetgr-stub.c
-
-libnet_la-ip6opt.lo: ip6opt.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ip6opt.lo `test -f 'ip6opt.c' || echo '$(srcdir)/'`ip6opt.c
-
libnet_la-issetugid-stub.lo: issetugid-stub.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-issetugid-stub.lo `test -f 'issetugid-stub.c' || echo '$(srcdir)/'`issetugid-stub.c
-libnet_la-linkaddr.lo: linkaddr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-linkaddr.lo `test -f 'linkaddr.c' || echo '$(srcdir)/'`linkaddr.c
+libnet_la-key-lookup.lo: key-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-key-lookup.lo `test -f 'key-lookup.c' || echo '$(srcdir)/'`key-lookup.c
-libnet_la-map_v4v6.lo: map_v4v6.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-map_v4v6.lo `test -f 'map_v4v6.c' || echo '$(srcdir)/'`map_v4v6.c
+libnet_la-netgrp-lookup.lo: netgrp-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-netgrp-lookup.lo `test -f 'netgrp-lookup.c' || echo '$(srcdir)/'`netgrp-lookup.c
-libnet_la-name6.lo: name6.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-name6.lo `test -f 'name6.c' || echo '$(srcdir)/'`name6.c
+libnet_la-network-lookup.lo: network-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-network-lookup.lo `test -f 'network-lookup.c' || echo '$(srcdir)/'`network-lookup.c
-libnet_la-ns_addr.lo: ns_addr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_addr.lo `test -f 'ns_addr.c' || echo '$(srcdir)/'`ns_addr.c
+libnet_la-nsswitch.lo: nsswitch.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsswitch.lo `test -f 'nsswitch.c' || echo '$(srcdir)/'`nsswitch.c
libnet_la-ns_name.lo: ns_name.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_name.lo `test -f 'ns_name.c' || echo '$(srcdir)/'`ns_name.c
@@ -900,29 +1305,32 @@ libnet_la-ns_name.lo: ns_name.c
libnet_la-ns_netint.lo: ns_netint.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_netint.lo `test -f 'ns_netint.c' || echo '$(srcdir)/'`ns_netint.c
-libnet_la-ns_ntoa.lo: ns_ntoa.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_ntoa.lo `test -f 'ns_ntoa.c' || echo '$(srcdir)/'`ns_ntoa.c
-
libnet_la-ns_parse.lo: ns_parse.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_parse.lo `test -f 'ns_parse.c' || echo '$(srcdir)/'`ns_parse.c
libnet_la-ns_print.lo: ns_print.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_print.lo `test -f 'ns_print.c' || echo '$(srcdir)/'`ns_print.c
+libnet_la-ns_samedomain.lo: ns_samedomain.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_samedomain.lo `test -f 'ns_samedomain.c' || echo '$(srcdir)/'`ns_samedomain.c
+
libnet_la-ns_ttl.lo: ns_ttl.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_ttl.lo `test -f 'ns_ttl.c' || echo '$(srcdir)/'`ns_ttl.c
-libnet_la-nsdispatch.lo: nsdispatch.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsdispatch.lo `test -f 'nsdispatch.c' || echo '$(srcdir)/'`nsdispatch.c
+libnet_la-nsap_addr.lo: nsap_addr.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsap_addr.lo `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c
-libnet_la-nslexer.lo: nslexer.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nslexer.lo `test -f 'nslexer.c' || echo '$(srcdir)/'`nslexer.c
+libnet_la-proto-lookup.lo: proto-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-proto-lookup.lo `test -f 'proto-lookup.c' || echo '$(srcdir)/'`proto-lookup.c
-libnet_la-nsparser.lo: nsparser.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsparser.lo `test -f 'nsparser.c' || echo '$(srcdir)/'`nsparser.c
+libnet_la-opensock.lo: opensock.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-opensock.lo `test -f 'opensock.c' || echo '$(srcdir)/'`opensock.c
-libnet_la-nsap_addr.lo: nsap_addr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsap_addr.lo `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c
+libnet_la-pwd-lookup.lo: pwd-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-pwd-lookup.lo `test -f 'pwd-lookup.c' || echo '$(srcdir)/'`pwd-lookup.c
+
+libnet_la-recv.lo: recv.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-recv.lo `test -f 'recv.c' || echo '$(srcdir)/'`recv.c
libnet_la-res_comp.lo: res_comp.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_comp.lo `test -f 'res_comp.c' || echo '$(srcdir)/'`res_comp.c
@@ -933,29 +1341,44 @@ libnet_la-res_data.lo: res_data.c
libnet_la-res_debug.lo: res_debug.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_debug.lo `test -f 'res_debug.c' || echo '$(srcdir)/'`res_debug.c
+libnet_la-res_hconf.lo: res_hconf.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_hconf.lo `test -f 'res_hconf.c' || echo '$(srcdir)/'`res_hconf.c
+
libnet_la-res_init.lo: res_init.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_init.lo `test -f 'res_init.c' || echo '$(srcdir)/'`res_init.c
+libnet_la-res_libc.lo: res_libc.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_libc.lo `test -f 'res_libc.c' || echo '$(srcdir)/'`res_libc.c
+
libnet_la-res_mkquery.lo: res_mkquery.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_mkquery.lo `test -f 'res_mkquery.c' || echo '$(srcdir)/'`res_mkquery.c
-libnet_la-res_mkupdate.lo: res_mkupdate.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_mkupdate.lo `test -f 'res_mkupdate.c' || echo '$(srcdir)/'`res_mkupdate.c
-
libnet_la-res_query.lo: res_query.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_query.lo `test -f 'res_query.c' || echo '$(srcdir)/'`res_query.c
libnet_la-res_send.lo: res_send.c
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_send.lo `test -f 'res_send.c' || echo '$(srcdir)/'`res_send.c
-libnet_la-res_update.lo: res_update.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_update.lo `test -f 'res_update.c' || echo '$(srcdir)/'`res_update.c
+libnet_la-rexec.lo: rexec.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rexec.lo `test -f 'rexec.c' || echo '$(srcdir)/'`rexec.c
-libnet_la-rthdr.lo: rthdr.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rthdr.lo `test -f 'rthdr.c' || echo '$(srcdir)/'`rthdr.c
+libnet_la-rpc-lookup.lo: rpc-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rpc-lookup.lo `test -f 'rpc-lookup.c' || echo '$(srcdir)/'`rpc-lookup.c
-libnet_la-vars.lo: vars.c
- $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-vars.lo `test -f 'vars.c' || echo '$(srcdir)/'`vars.c
+libnet_la-ruserpass.lo: ruserpass.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ruserpass.lo `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c
+
+libnet_la-send.lo: send.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-send.lo `test -f 'send.c' || echo '$(srcdir)/'`send.c
+
+libnet_la-service-lookup.lo: service-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-service-lookup.lo `test -f 'service-lookup.c' || echo '$(srcdir)/'`service-lookup.c
+
+libnet_la-spwd-lookup.lo: spwd-lookup.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-spwd-lookup.lo `test -f 'spwd-lookup.c' || echo '$(srcdir)/'`spwd-lookup.c
+
+libnet_la-ifname.lo: ifname.c
+ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifname.lo `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c
mostlyclean-libtool:
-rm -f *.lo
diff --git a/newlib/libc/sys/linux/net/XXX-lookup.c b/newlib/libc/sys/linux/net/XXX-lookup.c
new file mode 100644
index 000000000..da0e6f451
--- /dev/null
+++ b/newlib/libc/sys/linux/net/XXX-lookup.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume one symbol to be defined: *|
+|* *|
+|* DATABASE_NAME - name of the database the function accesses *|
+|* (e.g., hosts, services, ...) *|
+|* *|
+|* One additional symbol may optionally be defined: *|
+|* *|
+|* ALTERNATE_NAME - name of another service which is examined in *|
+|* case DATABASE_NAME is not found *|
+|* *|
+|* DEFAULT_CONFIG - string for default conf (e.g. "dns files") *|
+|* *|
+\*******************************************************************/
+
+#define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+#define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+#define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+
+#define DATABASE_NAME_SYMBOL CONCAT3_1 (__nss_, DATABASE_NAME, _database)
+#define DATABASE_NAME_STRING STRINGIFY1 (DATABASE_NAME)
+#define STRINGIFY1(Name) STRINGIFY2 (Name)
+#define STRINGIFY2(Name) #Name
+
+#ifdef ALTERNATE_NAME
+#define ALTERNATE_NAME_STRING STRINGIFY1 (ALTERNATE_NAME)
+#else
+#define ALTERNATE_NAME_STRING NULL
+#endif
+
+#ifndef DEFAULT_CONFIG
+#define DEFAULT_CONFIG NULL
+#endif
+
+service_user *DATABASE_NAME_SYMBOL attribute_hidden;
+
+extern int DB_LOOKUP_FCT (service_user **ni, const char *fct_name,
+ void **fctp) internal_function;
+libc_hidden_proto (DB_LOOKUP_FCT)
+
+int
+internal_function
+DB_LOOKUP_FCT (service_user **ni, const char *fct_name, void **fctp)
+{
+ if (DATABASE_NAME_SYMBOL == NULL
+ && __nss_database_lookup (DATABASE_NAME_STRING, ALTERNATE_NAME_STRING,
+ DEFAULT_CONFIG, &DATABASE_NAME_SYMBOL) < 0)
+ return -1;
+
+ *ni = DATABASE_NAME_SYMBOL;
+
+ return __nss_lookup (ni, fct_name, fctp);
+}
+libc_hidden_def (DB_LOOKUP_FCT)
diff --git a/newlib/libc/sys/linux/net/addr2ascii.3 b/newlib/libc/sys/linux/net/addr2ascii.3
deleted file mode 100644
index 10b1ac7f9..000000000
--- a/newlib/libc/sys/linux/net/addr2ascii.3
+++ /dev/null
@@ -1,222 +0,0 @@
-.\"
-.\" Copyright 1996 Massachusetts Institute of Technology
-.\"
-.\" Permission to use, copy, modify, and distribute this software and
-.\" its documentation for any purpose and without fee is hereby
-.\" granted, provided that both the above copyright notice and this
-.\" permission notice appear in all copies, that both the above
-.\" copyright notice and this permission notice appear in all
-.\" supporting documentation, and that the name of M.I.T. not be used
-.\" in advertising or publicity pertaining to distribution of the
-.\" software without specific, written prior permission. M.I.T. makes
-.\" no representations about the suitability of this software for any
-.\" purpose. It is provided "as is" without express or implied
-.\" warranty.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
-.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
-.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
-.\" SHALL M.I.T. 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.
-.\"
-.\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $
-.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.12 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd June 13, 1996
-.Dt ADDR2ASCII 3
-.Os
-.Sh NAME
-.Nm addr2ascii ,
-.Nm ascii2addr
-.Nd Generic address formatting routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In netinet/in.h
-.In arpa/inet.h
-.Ft "char *"
-.Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf"
-.Ft int
-.Fn ascii2addr "int af" "const char *ascii" "void *result"
-.Sh DESCRIPTION
-The routines
-.Fn addr2ascii
-and
-.Fn ascii2addr
-are used to convert network addresses between binary form and a
-printable form appropriate to the address family. Both functions take
-an
-.Fa af
-argument, specifying the address family to be used in the conversion
-process.
-(Currently, only the
-.Dv AF_INET
-and
-.Dv AF_LINK
-address families are supported.)
-.Pp
-The
-.Fn addr2ascii
-function
-is used to convert binary, network-format addresses into printable
-form. In addition to
-.Fa af ,
-there are three other arguments. The
-.Fa addrp
-argument is a pointer to the network address to be converted.
-The
-.Fa len
-argument is the length of the address. The
-.Fa buf
-argument is an optional pointer to a caller-allocated buffer to hold
-the result; if a null pointer is passed,
-.Fn addr2ascii
-uses a statically-allocated buffer.
-.Pp
-The
-.Fn ascii2addr
-function performs the inverse operation to
-.Fn addr2ascii .
-In addition to
-.Fa af ,
-it takes two parameters,
-.Fa ascii
-and
-.Fa result .
-The
-.Fa ascii
-parameter is a pointer to the string which is to be converted into
-binary. The
-.Fa result
-parameter is a pointer to an appropriate network address structure for
-the specified family.
-.Pp
-The following gives the appropriate structure to use for binary
-addresses in the specified family:
-.Pp
-.Bl -tag -width AF_INETxxxx -compact
-.It Dv AF_INET
-.Li struct in_addr
-(in
-.Aq Pa netinet/in.h )
-.It Dv AF_LINK
-.Li struct sockaddr_dl
-(in
-.Aq Pa net/if_dl.h )
-.\" .It Dv AF_INET6
-.\" .Li struct in6_addr
-.\" (in
-.\" .Aq Pa netinet6/in6.h )
-.El
-.Sh RETURN VALUES
-The
-.Fn addr2ascii
-function returns the address of the buffer it was passed, or a static
-buffer if the a null pointer was passed; on failure, it returns a null
-pointer.
-The
-.Fn ascii2addr
-function returns the length of the binary address in bytes, or -1 on
-failure.
-.Sh EXAMPLES
-The
-.Xr inet 3
-functions
-.Fn inet_ntoa
-and
-.Fn inet_aton
-could be implemented thusly:
-.Bd -literal -offset indent
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-char *
-inet_ntoa(struct in_addr addr)
-{
- return addr2ascii(AF_INET, &addr, sizeof addr, 0);
-}
-
-int
-inet_aton(const char *ascii, struct in_addr *addr)
-{
- return (ascii2addr(AF_INET, ascii, addr)
- == sizeof(*addr));
-}
-.Ed
-.Pp
-In actuality, this cannot be done because
-.Fn addr2ascii
-and
-.Fn ascii2addr
-are implemented in terms of the
-.Xr inet 3
-functions, rather than the other way around.
-.Sh ERRORS
-When a failure is returned,
-.Li errno
-is set to one of the following values:
-.Bl -tag -width Er
-.It Bq Er ENAMETOOLONG
-The
-.Fn addr2ascii
-routine was passed a
-.Fa len
-parameter which was inappropriate for the address family given by
-.Fa af .
-.It Bq Er EPROTONOSUPPORT
-Either routine was passed an
-.Fa af
-parameter other than
-.Dv AF_INET
-or
-.Dv AF_LINK .
-.It Bq Er EINVAL
-The string passed to
-.Fn ascii2addr
-was improperly formatted for address family
-.Fa af .
-.El
-.Sh SEE ALSO
-.Xr inet 3 ,
-.Xr linkaddr 3 ,
-.Xr inet 4
-.Sh HISTORY
-An interface close to this one was originally suggested by Craig
-Partridge. This particular interface originally appeared in the
-.Tn INRIA
-.Tn IPv6
-implementation.
-.Sh AUTHORS
-Code and documentation by
-.An Garrett A. Wollman ,
-MIT Laboratory for Computer Science.
-.Sh BUGS
-The original implementations supported IPv6. This support should
-eventually be resurrected. The
-.Tn NRL
-implementation also included support for the
-.Dv AF_ISO
-and
-.Dv AF_NS
-address families.
-.Pp
-The genericity of this interface is somewhat questionable. A truly
-generic interface would provide a means for determining the length of
-the buffer to be used so that it could be dynamically allocated, and
-would always require a
-.Dq Li "struct sockaddr"
-to hold the binary address. Unfortunately, this is incompatible with existing
-practice. This limitation means that a routine for printing network
-addresses from arbitrary address families must still have internal
-knowledge of the maximum buffer length needed and the appropriate part
-of the address to use as the binary address.
diff --git a/newlib/libc/sys/linux/net/alias-lookup.c b/newlib/libc/sys/linux/net/alias-lookup.c
new file mode 100644
index 000000000..6aba466b3
--- /dev/null
+++ b/newlib/libc/sys/linux/net/alias-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME aliases
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/aliases.h b/newlib/libc/sys/linux/net/aliases.h
new file mode 100644
index 000000000..58dd8f0fc
--- /dev/null
+++ b/newlib/libc/sys/linux/net/aliases.h
@@ -0,0 +1,64 @@
+/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _ALIASES_H
+#define _ALIASES_H 1
+
+#include <features.h>
+
+#include <sys/types.h>
+
+
+__BEGIN_DECLS
+
+/* Structure to represent one entry of the alias data base. */
+struct aliasent
+ {
+ char *alias_name;
+ size_t alias_members_len;
+ char **alias_members;
+ int alias_local;
+ };
+
+
+/* Open alias data base files. */
+extern void setaliasent (void) __THROW;
+
+/* Close alias data base files. */
+extern void endaliasent (void) __THROW;
+
+/* Get the next entry from the alias data base. */
+extern struct aliasent *getaliasent (void) __THROW;
+
+/* Get the next entry from the alias data base and put it in RESULT_BUF. */
+extern int getaliasent_r (struct aliasent *__restrict __result_buf,
+ char *__restrict __buffer, size_t __buflen,
+ struct aliasent **__restrict __result) __THROW;
+
+/* Get alias entry corresponding to NAME. */
+extern struct aliasent *getaliasbyname (__const char *__name) __THROW;
+
+/* Get alias entry corresponding to NAME and put it in RESULT_BUF. */
+extern int getaliasbyname_r (__const char *__restrict __name,
+ struct aliasent *__restrict __result_buf,
+ char *__restrict __buffer, size_t __buflen,
+ struct aliasent **__restrict __result) __THROW;
+
+__END_DECLS
+
+#endif /* aliases.h */
diff --git a/newlib/libc/sys/linux/net/base64.c b/newlib/libc/sys/linux/net/base64.c
index 35f7d867b..76c966fc3 100644
--- a/newlib/libc/sys/linux/net/base64.c
+++ b/newlib/libc/sys/linux/net/base64.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ * Copyright (c) 1996-1999 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
@@ -40,10 +40,11 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-#include <sys/cdefs.h>
+#if !defined(LINT) && !defined(CODECENTER)
+static const char rcsid[] = "$BINDId: base64.c,v 8.7 1999/10/13 16:39:33 vixie Exp $";
+#endif /* not lint */
#include <sys/types.h>
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
@@ -57,6 +58,8 @@
#include <stdlib.h>
#include <string.h>
+#include "libc-symbols.h"
+
#define Assert(Cond) if (!(Cond)) abort()
static const char Base64[] =
@@ -111,9 +114,9 @@ static const char Pad64 = '=';
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
@@ -155,14 +158,14 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
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);
@@ -185,6 +188,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return (datalength);
}
+libresolv_hidden_def (b64_ntop)
/* skips all whitespace anywhere.
converts characters, four at a time, starting at (or after)
@@ -205,7 +209,7 @@ b64_pton(src, target, targsize)
tarindex = 0;
while ((ch = *src++) != '\0') {
- if (isspace((unsigned char)ch)) /* Skip whitespace anywhere. */
+ if (isspace(ch)) /* Skip whitespace anywhere. */
continue;
if (ch == Pad64)
@@ -275,7 +279,7 @@ b64_pton(src, target, targsize)
case 2: /* Valid, means one byte of info */
/* Skip any number of spaces. */
for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace((unsigned char)ch))
+ if (!isspace(ch))
break;
/* Make sure there is another trailing = sign. */
if (ch != Pad64)
@@ -290,7 +294,7 @@ b64_pton(src, target, targsize)
* whitespace after it?
*/
for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace((unsigned char)ch))
+ if (!isspace(ch))
return (-1);
/*
diff --git a/newlib/libc/sys/linux/net/bindresvport.c b/newlib/libc/sys/linux/net/bindresvport.c
deleted file mode 100644
index 7b595b4dc..000000000
--- a/newlib/libc/sys/linux/net/bindresvport.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* $NetBSD: bindresvport.c,v 1.19 2000/07/06 03:03:59 christos Exp $ */
-
-/*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part. Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user.
- *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California 94043
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-/*static char *sccsid = "from: @(#)bindresvport.c 1.8 88/02/08 SMI";*/
-/*static char *sccsid = "from: @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC";*/
-/*from: OpenBSD: bindresvport.c,v 1.7 1996/07/30 16:25:47 downsj Exp */
-#endif
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-/*
- * Copyright (c) 1987 by Sun Microsystems, Inc.
- *
- * Portions Copyright(C) 1996, Jason Downs. All rights reserved.
- */
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <rpc/rpc.h>
-
-#include <string.h>
-#include "un-namespace.h"
-
-/*
- * Bind a socket to a privileged IP port
- */
-int
-bindresvport(sd, sin)
- int sd;
- struct sockaddr_in *sin;
-{
- return bindresvport_sa(sd, (struct sockaddr *)sin);
-}
-
-/*
- * Bind a socket to a privileged IP port
- */
-int
-bindresvport_sa(sd, sa)
- int sd;
- struct sockaddr *sa;
-{
- int old, error, af;
- struct sockaddr_storage myaddr;
- struct sockaddr_in *sin;
-#ifdef INET6
- struct sockaddr_in6 *sin6;
-#endif
- int proto, portrange, portlow;
- u_int16_t *portp;
- socklen_t salen;
-
- if (sa == NULL) {
- salen = sizeof(myaddr);
- sa = (struct sockaddr *)&myaddr;
-
- if (getsockname(sd, sa, &salen) == -1)
- return -1; /* errno is correctly set */
-
- af = sa->sa_family;
- memset(sa, 0, salen);
- } else
- af = sa->sa_family;
-
- switch (af) {
- case AF_INET:
- proto = IPPROTO_IP;
- portrange = IP_PORTRANGE;
- portlow = IP_PORTRANGE_LOW;
- sin = (struct sockaddr_in *)sa;
- salen = sizeof(struct sockaddr_in);
- portp = &sin->sin_port;
- break;
-#ifdef INET6
- case AF_INET6:
- proto = IPPROTO_IPV6;
- portrange = IPV6_PORTRANGE;
- portlow = IPV6_PORTRANGE_LOW;
- sin6 = (struct sockaddr_in6 *)sa;
- salen = sizeof(struct sockaddr_in6);
- portp = &sin6->sin6_port;
- break;
-#endif
- default:
- errno = EPFNOSUPPORT;
- return (-1);
- }
- sa->sa_family = af;
-
- if (*portp == 0) {
- socklen_t oldlen = sizeof(old);
-
- error = getsockopt(sd, proto, portrange, &old, &oldlen);
- if (error < 0)
- return (error);
-
- error = setsockopt(sd, proto, portrange, &portlow,
- sizeof(portlow));
- if (error < 0)
- return (error);
- }
-
- error = bind(sd, sa, salen);
-
- if (*portp == 0) {
- int saved_errno = errno;
-
- if (error < 0) {
- if (setsockopt(sd, proto, portrange, &old,
- sizeof(old)) < 0)
- errno = saved_errno;
- return (error);
- }
-
- if (sa != (struct sockaddr *)&myaddr) {
- /* Hmm, what did the kernel assign? */
- if (getsockname(sd, sa, &salen) < 0)
- errno = saved_errno;
- return (error);
- }
- }
- return (error);
-}
diff --git a/newlib/libc/sys/linux/net/byteorder.3 b/newlib/libc/sys/linux/net/byteorder.3
deleted file mode 100644
index 062ac9d70..000000000
--- a/newlib/libc/sys/linux/net/byteorder.3
+++ /dev/null
@@ -1,84 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/byteorder.3,v 1.9 2001/12/08 19:06:23 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt BYTEORDER 3
-.Os
-.Sh NAME
-.Nm htonl ,
-.Nm htons ,
-.Nm ntohl ,
-.Nm ntohs
-.Nd convert values between host and network byte order
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In arpa/inet.h
-.Ft uint32_t
-.Fn htonl "uint32_t hostlong"
-.Ft uint16_t
-.Fn htons "uint16_t hostshort"
-.Ft uint32_t
-.Fn ntohl "uint32_t netlong"
-.Ft uint16_t
-.Fn ntohs "uint16_t netshort"
-.Sh DESCRIPTION
-These routines convert 16 and 32 bit quantities between network
-byte order and host byte order.
-On machines which have a byte order which is the same as the network
-order, routines are defined as null macros.
-.Pp
-These routines 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
-.Nm byteorder
-functions are expected to conform with
-.St -p1003.1-2001 .
-.Sh HISTORY
-The
-.Nm byteorder
-functions appeared in
-.Bx 4.2 .
-.Sh BUGS
-On the
-.Tn VAX
-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/newlib/libc/sys/linux/net/check_pf.c b/newlib/libc/sys/linux/net/check_pf.c
new file mode 100644
index 000000000..086879e4e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/check_pf.c
@@ -0,0 +1,199 @@
+/* Determine protocol families for which interfaces exist. Linux version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdint.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/socket.h>
+
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include <stdbool.h>
+#include <sys/uio.h>
+
+#include "config.h"
+#include "local.h"
+
+#define __ASSUME_NETLINK_SUPPORT 1
+
+static int
+make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6)
+{
+ struct
+ {
+ struct nlmsghdr nlh;
+ struct rtgenmsg g;
+ } req;
+ struct sockaddr_nl nladdr;
+
+ req.nlh.nlmsg_len = sizeof (req);
+ req.nlh.nlmsg_type = RTM_GETADDR;
+ req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
+ req.nlh.nlmsg_pid = 0;
+ req.nlh.nlmsg_seq = time (NULL);
+ req.g.rtgen_family = AF_UNSPEC;
+
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+
+ if (TEMP_FAILURE_RETRY (sendto (fd, (void *) &req, sizeof (req), 0,
+ (struct sockaddr *) &nladdr,
+ sizeof (nladdr))) < 0)
+ return -1;
+
+ *seen_ipv4 = false;
+ *seen_ipv6 = false;
+
+ bool done = false;
+ char buf[4096];
+ struct iovec iov = { buf, sizeof (buf) };
+
+ do
+ {
+ struct msghdr msg =
+ {
+ (void *) &nladdr, sizeof (nladdr),
+ &iov, 1,
+ NULL, 0,
+ 0
+ };
+
+ ssize_t read_len = TEMP_FAILURE_RETRY (recvmsg (fd, &msg, 0));
+ if (read_len < 0)
+ return -1;
+
+ if (msg.msg_flags & MSG_TRUNC)
+ return -1;
+
+ struct nlmsghdr *nlmh;
+ for (nlmh = (struct nlmsghdr *) buf;
+ NLMSG_OK (nlmh, (size_t) read_len);
+ nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, read_len))
+ {
+ if (nladdr.nl_pid != 0 || (pid_t) nlmh->nlmsg_pid != pid
+ || nlmh->nlmsg_seq != req.nlh.nlmsg_seq)
+ continue;
+
+ if (nlmh->nlmsg_type == RTM_NEWADDR)
+ {
+ struct ifaddrmsg *ifam = (struct ifaddrmsg *) NLMSG_DATA (nlmh);
+
+ switch (ifam->ifa_family)
+ {
+ case AF_INET:
+ *seen_ipv4 = true;
+ break;
+ case AF_INET6:
+ *seen_ipv6 = true;
+ break;
+ default:
+ /* Ignore. */
+ break;
+ }
+ }
+ else if (nlmh->nlmsg_type == NLMSG_DONE)
+ /* We found the end, leave the loop. */
+ done = true;
+ else ;
+ }
+ }
+ while (! done);
+
+ close (fd);
+
+ return 0;
+}
+
+
+/* We don't know if we have NETLINK support compiled in in our
+ Kernel. */
+#if __ASSUME_NETLINK_SUPPORT == 0
+/* Define in ifaddrs.h. */
+extern int __no_netlink_support attribute_hidden;
+#else
+# define __no_netlink_support 0
+#endif
+
+
+void
+attribute_hidden
+__check_pf (bool *seen_ipv4, bool *seen_ipv6)
+{
+ if (! __no_netlink_support)
+ {
+ int fd = socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+
+ struct sockaddr_nl nladdr;
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+
+ socklen_t addr_len = sizeof (nladdr);
+
+ if (fd >= 0
+ && bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0
+ && getsockname (fd, (struct sockaddr *) &nladdr, &addr_len) == 0
+ && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6) == 0)
+ /* It worked. */
+ return;
+
+ if (fd >= 0)
+ close (fd);
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+ /* Remember that there is no netlink support. */
+ __no_netlink_support = 1;
+#else
+ /* We cannot determine what interfaces are available. Be
+ pessimistic. */
+ *seen_ipv4 = true;
+ *seen_ipv6 = true;
+#endif
+ }
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+ /* No netlink. Get the interface list via getifaddrs. */
+ struct ifaddrs *ifa = NULL;
+ if (getifaddrs (&ifa) != 0)
+ {
+ /* We cannot determine what interfaces are available. Be
+ pessimistic. */
+ *seen_ipv4 = true;
+ *seen_ipv6 = true;
+ return;
+ }
+
+ *seen_ipv4 = false;
+ *seen_ipv6 = false;
+
+ struct ifaddrs *runp;
+ for (runp = ifa; runp != NULL; runp = runp->ifa_next)
+ if (runp->ifa_addr->sa_family == PF_INET)
+ *seen_ipv4 = true;
+ else if (runp->ifa_addr->sa_family == PF_INET6)
+ *seen_ipv6 = true;
+
+ (void) freeifaddrs (ifa);
+#endif
+}
diff --git a/newlib/libc/sys/linux/net/databases.def b/newlib/libc/sys/linux/net/databases.def
new file mode 100644
index 000000000..27c15fc04
--- /dev/null
+++ b/newlib/libc/sys/linux/net/databases.def
@@ -0,0 +1,40 @@
+/* List of all databases defined for the NSS in GNU C Library.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This list must be kept sorted!!! */
+
+DEFINE_DATABASE (aliases)
+DEFINE_DATABASE (ethers)
+DEFINE_DATABASE (group)
+DEFINE_DATABASE (hosts)
+DEFINE_DATABASE (netgroup)
+DEFINE_DATABASE (networks)
+DEFINE_DATABASE (passwd)
+DEFINE_DATABASE (protocols)
+DEFINE_DATABASE (publickey)
+DEFINE_DATABASE (rpc)
+DEFINE_DATABASE (services)
+DEFINE_DATABASE (shadow)
+
+/*
+ Local Variables:
+ mode:C
+ End:
+ */
diff --git a/newlib/libc/sys/linux/net/digits_dots.c b/newlib/libc/sys/linux/net/digits_dots.c
new file mode 100644
index 000000000..9576dd53b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/digits_dots.c
@@ -0,0 +1,317 @@
+/* Copyright (C) 1997, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by H.J. Lu <hjl@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <wctype.h>
+#include <resolv.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include "nsswitch.h"
+
+#ifdef USE_NSCD
+# define inet_aton __inet_aton
+# include <nscd/nscd_proto.h>
+#endif
+
+int
+__nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
+ char **buffer, size_t *buffer_size,
+ size_t buflen, struct hostent **result,
+ enum nss_status *status, int af, int *h_errnop)
+{
+ int save;
+
+ /* We have to test for the use of IPv6 which can only be done by
+ examining `_res'. */
+ if (__res_maybe_init (&_res, 0) == -1)
+ {
+ if (h_errnop)
+ *h_errnop = NETDB_INTERNAL;
+ *result = NULL;
+ return -1;
+ }
+
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit (name[0]) || isxdigit (name[0]) || name[0] == ':')
+ {
+ const char *cp;
+ char *hostname;
+ typedef unsigned char host_addr_t[16];
+ host_addr_t *host_addr;
+ typedef char *host_addr_list_t[2];
+ host_addr_list_t *h_addr_ptrs;
+ char **h_alias_ptr;
+ size_t size_needed;
+ int addr_size;
+
+ switch (af)
+ {
+ case AF_INET:
+ addr_size = INADDRSZ;
+ break;
+
+ case AF_INET6:
+ addr_size = IN6ADDRSZ;
+ break;
+
+ default:
+ af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
+ addr_size = af == AF_INET6 ? IN6ADDRSZ : INADDRSZ;
+ break;
+ }
+
+ size_needed = (sizeof (*host_addr)
+ + sizeof (*h_addr_ptrs) + strlen (name) + 1);
+
+ if (buffer_size == NULL)
+ {
+ if (buflen < size_needed)
+ {
+ if (h_errnop != NULL)
+ *h_errnop = TRY_AGAIN;
+ __set_errno (ERANGE);
+ goto done;
+ }
+ }
+ else if (buffer_size != NULL && *buffer_size < size_needed)
+ {
+ char *new_buf;
+ *buffer_size = size_needed;
+ new_buf = (char *) realloc (*buffer, *buffer_size);
+
+ if (new_buf == NULL)
+ {
+ save = errno;
+ free (*buffer);
+ *buffer = NULL;
+ *buffer_size = 0;
+ __set_errno (save);
+ if (h_errnop != NULL)
+ *h_errnop = TRY_AGAIN;
+ *result = NULL;
+ goto done;
+ }
+ *buffer = new_buf;
+ }
+
+ memset (*buffer, '\0', size_needed);
+
+ host_addr = (host_addr_t *) *buffer;
+ h_addr_ptrs = (host_addr_list_t *)
+ ((char *) host_addr + sizeof (*host_addr));
+ h_alias_ptr = (char **) ((char *) h_addr_ptrs + sizeof (*h_addr_ptrs));
+ hostname = (char *) h_alias_ptr + sizeof (*h_alias_ptr);
+
+ if (isdigit (name[0]))
+ {
+ for (cp = name;; ++cp)
+ {
+ if (*cp == '\0')
+ {
+ int ok;
+
+ if (*--cp == '.')
+ break;
+
+ /* All-numeric, no dot at the end. Fake up a hostent as if
+ we'd actually done a lookup. What if someone types
+ 255.255.255.255? The test below will succeed
+ spuriously... ??? */
+ if (af == AF_INET)
+ ok = __inet_aton (name, (struct in_addr *) host_addr);
+ else
+ {
+ assert (af == AF_INET6);
+ ok = inet_pton (af, name, host_addr) > 0;
+ }
+ if (! ok)
+ {
+ *h_errnop = HOST_NOT_FOUND;
+ if (buffer_size)
+ *result = NULL;
+ goto done;
+ }
+
+ resbuf->h_name = strcpy (hostname, name);
+ h_alias_ptr[0] = NULL;
+ resbuf->h_aliases = h_alias_ptr;
+ (*h_addr_ptrs)[0] = (char *) host_addr;
+ (*h_addr_ptrs)[1] = NULL;
+ resbuf->h_addr_list = *h_addr_ptrs;
+ if (af == AF_INET && (_res.options & RES_USE_INET6))
+ {
+ /* We need to change the IP v4 address into the
+ IP v6 address. */
+ char tmp[INADDRSZ];
+ char *p = (char *) host_addr;
+ int i;
+
+ /* Save a copy of the IP v4 address. */
+ memcpy (tmp, host_addr, INADDRSZ);
+ /* Mark this ipv6 addr as a mapped ipv4. */
+ for (i = 0; i < 10; i++)
+ *p++ = 0x00;
+ *p++ = 0xff;
+ *p++ = 0xff;
+ /* Copy the IP v4 address. */
+ memcpy (p, tmp, INADDRSZ);
+ resbuf->h_addrtype = AF_INET6;
+ resbuf->h_length = IN6ADDRSZ;
+ }
+ else
+ {
+ resbuf->h_addrtype = af;
+ resbuf->h_length = addr_size;
+ }
+ if (h_errnop != NULL)
+ *h_errnop = NETDB_SUCCESS;
+ if (buffer_size == NULL)
+ *status = NSS_STATUS_SUCCESS;
+ else
+ *result = resbuf;
+ goto done;
+ }
+
+ if (!isdigit (*cp) && *cp != '.')
+ break;
+ }
+ }
+
+ if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
+ {
+ const char *cp;
+ char *hostname;
+ typedef unsigned char host_addr_t[16];
+ host_addr_t *host_addr;
+ typedef char *host_addr_list_t[2];
+ host_addr_list_t *h_addr_ptrs;
+ size_t size_needed;
+ int addr_size;
+
+ switch (af)
+ {
+ default:
+ af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
+ if (af == AF_INET6)
+ {
+ addr_size = IN6ADDRSZ;
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case AF_INET:
+ /* This is not possible. We cannot represent an IPv6 address
+ in an `struct in_addr' variable. */
+ *h_errnop = HOST_NOT_FOUND;
+ *result = NULL;
+ goto done;
+
+ case AF_INET6:
+ addr_size = IN6ADDRSZ;
+ break;
+ }
+
+ size_needed = (sizeof (*host_addr)
+ + sizeof (*h_addr_ptrs) + strlen (name) + 1);
+
+ if (buffer_size == NULL && buflen < size_needed)
+ {
+ if (h_errnop != NULL)
+ *h_errnop = TRY_AGAIN;
+ __set_errno (ERANGE);
+ goto done;
+ }
+ else if (buffer_size != NULL && *buffer_size < size_needed)
+ {
+ char *new_buf;
+ *buffer_size = size_needed;
+ new_buf = realloc (*buffer, *buffer_size);
+
+ if (new_buf == NULL)
+ {
+ save = errno;
+ free (*buffer);
+ __set_errno (save);
+ *buffer = NULL;
+ *buffer_size = 0;
+ *result = NULL;
+ goto done;
+ }
+ *buffer = new_buf;
+ }
+
+ memset (*buffer, '\0', size_needed);
+
+ host_addr = (host_addr_t *) *buffer;
+ h_addr_ptrs = (host_addr_list_t *)
+ ((char *) host_addr + sizeof (*host_addr));
+ hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
+
+ 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_INET6, name, host_addr) <= 0)
+ {
+ *h_errnop = HOST_NOT_FOUND;
+ if (buffer_size)
+ *result = NULL;
+ goto done;
+ }
+
+ resbuf->h_name = strcpy (hostname, name);
+ h_alias_ptr[0] = NULL;
+ resbuf->h_aliases = h_alias_ptr;
+ (*h_addr_ptrs)[0] = (char *) host_addr;
+ (*h_addr_ptrs)[1] = (char *) 0;
+ resbuf->h_addr_list = *h_addr_ptrs;
+ resbuf->h_addrtype = AF_INET6;
+ resbuf->h_length = addr_size;
+ *h_errnop = NETDB_SUCCESS;
+ if (buffer_size == NULL)
+ *status = NSS_STATUS_SUCCESS;
+ else
+ *result = resbuf;
+ goto done;
+ }
+
+ if (!isxdigit (*cp) && *cp != ':' && *cp != '.')
+ break;
+ }
+ }
+ }
+
+ return 0;
+
+done:
+ return 1;
+}
+libc_hidden_def (__nss_hostname_digits_dots)
diff --git a/newlib/libc/sys/linux/net/ether_addr.c b/newlib/libc/sys/linux/net/ether_addr.c
deleted file mode 100644
index 7d2b19f69..000000000
--- a/newlib/libc/sys/linux/net/ether_addr.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 1995
- * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY Bill Paul 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.
- *
- * ethernet address conversion and lookup routines
- *
- * Written by Bill Paul <wpaul@ctr.columbia.edu>
- * Center for Telecommunications Research
- * Columbia University, New York City
- */
-
-#include <sys/cdefs.h>
-
-#include <stdio.h>
-#include <paths.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <net/ethernet.h>
-#ifdef YP
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-#endif
-
-#ifndef _PATH_ETHERS
-#define _PATH_ETHERS "/etc/ethers"
-#endif
-
-/*
- * Parse a string of text containing an ethernet address and hostname
- * and separate it into its component parts.
- */
-int
-ether_line(l, e, hostname)
- const char *l;
- struct ether_addr *e;
- char *hostname;
-{
- int i, o[6];
-
- i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2],
- &o[3], &o[4], &o[5],
- hostname);
- if (i != 7)
- return (i);
-
- for (i=0; i<6; i++)
- e->octet[i] = o[i];
- return (0);
-}
-
-/*
- * Convert an ASCII representation of an ethernet address to
- * binary form.
- */
-struct
-ether_addr *ether_aton(a)
- const char *a;
-{
- int i;
- static struct ether_addr o;
- unsigned int o0, o1, o2, o3, o4, o5;
-
- i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5);
-
- if (i != 6)
- return (NULL);
-
- o.octet[0]=o0;
- o.octet[1]=o1;
- o.octet[2]=o2;
- o.octet[3]=o3;
- o.octet[4]=o4;
- o.octet[5]=o5;
-
- return ((struct ether_addr *)&o);
-}
-
-/*
- * Convert a binary representation of an ethernet address to
- * an ASCII string.
- */
-char
-*ether_ntoa(n)
- const struct ether_addr *n;
-{
- int i;
- static char a[18];
-
- i = sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x",
- n->octet[0], n->octet[1], n->octet[2],
- n->octet[3], n->octet[4], n->octet[5]);
- if (i < 17)
- return (NULL);
- return ((char *)&a);
-}
-
-/*
- * Map an ethernet address to a hostname. Use either /etc/ethers or
- * NIS/YP.
- */
-int
-ether_ntohost(hostname, e)
- char *hostname;
- const struct ether_addr *e;
-{
- FILE *fp;
- char buf[BUFSIZ + 2];
- struct ether_addr local_ether;
- char local_host[MAXHOSTNAMELEN];
-#ifdef YP
- char *result;
- int resultlen;
- char *ether_a;
- char *yp_domain;
-#endif
- if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
- return (1);
-
- while (fgets(buf,BUFSIZ,fp)) {
- if (buf[0] == '#')
- continue;
-#ifdef YP
- if (buf[0] == '+') {
- if (yp_get_default_domain(&yp_domain))
- continue;
- ether_a = ether_ntoa(e);
- if (yp_match(yp_domain, "ethers.byaddr", ether_a,
- strlen(ether_a), &result, &resultlen)) {
- continue;
- }
- strncpy(buf, result, resultlen);
- buf[resultlen] = '\0';
- free(result);
- }
-#endif
- if (!ether_line(buf, &local_ether, local_host)) {
- if (!memcmp((char *)&local_ether.octet[0],
- (char *)&e->octet[0], 6)) {
- /* We have a match */
- strcpy(hostname, local_host);
- fclose(fp);
- return(0);
- }
- }
- }
- fclose(fp);
- return (1);
-}
-
-/*
- * Map a hostname to an ethernet address using /etc/ethers or
- * NIS/YP.
- */
-int
-ether_hostton(hostname, e)
- const char *hostname;
- struct ether_addr *e;
-{
- FILE *fp;
- char buf[BUFSIZ + 2];
- struct ether_addr local_ether;
- char local_host[MAXHOSTNAMELEN];
-#ifdef YP
- char *result;
- int resultlen;
- char *yp_domain;
-#endif
- if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
- return (1);
-
- while (fgets(buf,BUFSIZ,fp)) {
- if (buf[0] == '#')
- continue;
-#ifdef YP
- if (buf[0] == '+') {
- if (yp_get_default_domain(&yp_domain))
- continue;
- if (yp_match(yp_domain, "ethers.byname", hostname,
- strlen(hostname), &result, &resultlen)) {
- continue;
- }
- strncpy(buf, result, resultlen);
- buf[resultlen] = '\0';
- free(result);
- }
-#endif
- if (!ether_line(buf, &local_ether, local_host)) {
- if (!strcmp(hostname, local_host)) {
- /* We have a match */
- bcopy((char *)&local_ether.octet[0],
- (char *)&e->octet[0], 6);
- fclose(fp);
- return(0);
- }
- }
- }
- fclose(fp);
- return (1);
-}
diff --git a/newlib/libc/sys/linux/net/ether_aton.c b/newlib/libc/sys/linux/net/ether_aton.c
new file mode 100644
index 000000000..071f329a6
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_aton.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netinet/ether.h>
+
+
+struct ether_addr *
+ether_aton (const char *asc)
+{
+ static struct ether_addr result;
+
+ return ether_aton_r (asc, &result);
+}
diff --git a/newlib/libc/sys/linux/net/ether_aton_r.c b/newlib/libc/sys/linux/net/ether_aton_r.c
new file mode 100644
index 000000000..1e9f15a12
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_aton_r.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+struct ether_addr *
+ether_aton_r (const char *asc, struct ether_addr *addr)
+{
+ size_t cnt;
+
+ for (cnt = 0; cnt < 6; ++cnt)
+ {
+ unsigned int number;
+ char ch;
+
+ ch = _tolower (*asc++);
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+ return NULL;
+ number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+ ch = _tolower (*asc);
+ if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch)))
+ {
+ ++asc;
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+ return NULL;
+ number <<= 4;
+ number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+ ch = *asc;
+ if (cnt < 5 && ch != ':')
+ return NULL;
+ }
+
+ /* Store result. */
+ addr->ether_addr_octet[cnt] = (unsigned char) number;
+
+ /* Skip ':'. */
+ ++asc;
+ }
+
+ return addr;
+}
+libc_hidden_def (ether_aton_r)
diff --git a/newlib/libc/sys/linux/net/ether_hton.c b/newlib/libc/sys/linux/net/ether_hton.c
new file mode 100644
index 000000000..a226d9f5f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_hton.c
@@ -0,0 +1,83 @@
+/* Copyright (C) 1996, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+#include <string.h>
+#include "etherent.h"
+
+#include "nsswitch.h"
+
+/* Type of the lookup function we need here. */
+typedef int (*lookup_function) (const char *, struct etherent *, char *, int,
+ int *);
+
+/* The lookup function for the first entry of this service. */
+extern int __nss_ethers_lookup (service_user **nip, const char *name,
+ void **fctp) internal_function;
+
+
+int
+ether_hostton (const char *hostname, struct ether_addr *addr)
+{
+ static service_user *startp;
+ static lookup_function start_fct;
+ service_user *nip;
+ union
+ {
+ lookup_function f;
+ void *ptr;
+ } fct;
+ int no_more;
+ enum nss_status status = NSS_STATUS_UNAVAIL;
+ struct etherent etherent;
+
+ if (startp == NULL)
+ {
+ no_more = __nss_ethers_lookup (&nip, "gethostton_r", &fct.ptr);
+ if (no_more)
+ startp = (service_user *) -1;
+ else
+ {
+ startp = nip;
+ start_fct = fct.f;
+ }
+ }
+ else
+ {
+ fct.f = start_fct;
+ no_more = (nip = startp) == (service_user *) -1;
+ }
+
+ while (no_more == 0)
+ {
+ char buffer[1024];
+
+ status = (*fct.f) (hostname, &etherent, buffer, sizeof buffer, &errno);
+
+ no_more = __nss_next (&nip, "gethostton_r", &fct.ptr, status, 0);
+ }
+
+ if (status == NSS_STATUS_SUCCESS)
+ memcpy (addr, etherent.e_addr.ether_addr_octet,
+ sizeof (struct ether_addr));
+
+ return status == NSS_STATUS_SUCCESS ? 0 : -1;
+}
diff --git a/newlib/libc/sys/linux/net/ether_line.c b/newlib/libc/sys/linux/net/ether_line.c
new file mode 100644
index 000000000..8be593ea9
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_line.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 1996, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+int
+ether_line (const char *line, struct ether_addr *addr, char *hostname)
+{
+ size_t cnt;
+ char *cp;
+
+ for (cnt = 0; cnt < 6; ++cnt)
+ {
+ unsigned int number;
+ char ch;
+
+ ch = _tolower (*line++);
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+ return -1;
+ number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+ ch = _tolower (*line);
+ if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch)))
+ {
+ ++line;
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+ return -1;
+ number <<= 4;
+ number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+ ch = *line;
+ if (cnt < 5 && ch != ':')
+ return -1;
+ }
+
+ /* Store result. */
+ addr->ether_addr_octet[cnt] = (unsigned char) number;
+
+ /* Skip ':'. */
+ if (ch != '\0')
+ ++line;
+ }
+
+ /* Remove trailing white space. */
+ cp = strchr (line, '#');
+ if (cp == NULL)
+ cp = line + strlen (line);
+ while (cp > line && isspace (cp[-1]))
+ --cp;
+
+ if (cp == line)
+ /* No hostname. */
+ return -1;
+
+ /* XXX This can cause trouble because the hostname might be too long
+ but we have no possibility to check it here. */
+ memcpy (hostname, line, cp - line);
+ hostname [cp - line] = '\0';
+
+ return 0;
+}
diff --git a/newlib/libc/sys/linux/net/ether_ntoa.c b/newlib/libc/sys/linux/net/ether_ntoa.c
new file mode 100644
index 000000000..815aebe0f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_ntoa.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+char *
+ether_ntoa (const struct ether_addr *addr)
+{
+ static char asc[18];
+
+ return ether_ntoa_r (addr, asc);
+}
diff --git a/newlib/libc/sys/linux/net/ether_ntoa_r.c b/newlib/libc/sys/linux/net/ether_ntoa_r.c
new file mode 100644
index 000000000..c5f347c63
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_ntoa_r.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+char *
+ether_ntoa_r (const struct ether_addr *addr, char *buf)
+{
+ sprintf (buf, "%x:%x:%x:%x:%x:%x",
+ addr->ether_addr_octet[0], addr->ether_addr_octet[1],
+ addr->ether_addr_octet[2], addr->ether_addr_octet[3],
+ addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
+ return buf;
+}
+libc_hidden_def (ether_ntoa_r)
diff --git a/newlib/libc/sys/linux/net/ether_ntoh.c b/newlib/libc/sys/linux/net/ether_ntoh.c
new file mode 100644
index 000000000..de8c41ef7
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ether_ntoh.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 1996, 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+#include <string.h>
+#include "etherent.h"
+
+#include "nsswitch.h"
+
+
+/* Type of the lookup function we need here. */
+typedef int (*lookup_function) (const struct ether_addr *, struct etherent *,
+ char *, size_t, int *);
+
+/* The lookup function for the first entry of this service. */
+extern int __nss_ethers_lookup (service_user **nip, const char *name,
+ void **fctp) internal_function;
+
+
+int
+ether_ntohost (char *hostname, const struct ether_addr *addr)
+{
+ static service_user *startp;
+ static lookup_function start_fct;
+ service_user *nip;
+ union
+ {
+ lookup_function f;
+ void *ptr;
+ } fct;
+ int no_more;
+ enum nss_status status = NSS_STATUS_UNAVAIL;
+ struct etherent etherent;
+
+ if (startp == NULL)
+ {
+ no_more = __nss_ethers_lookup (&nip, "getntohost_r", &fct.ptr);
+ if (no_more)
+ startp = (service_user *) -1;
+ else
+ {
+ startp = nip;
+ start_fct = fct.f;
+ }
+ }
+ else
+ {
+ fct.f = start_fct;
+ no_more = (nip = startp) == (service_user *) -1;
+ }
+
+ while (no_more == 0)
+ {
+ char buffer[1024];
+
+ status = (*fct.f) (addr, &etherent, buffer, sizeof buffer, &errno);
+
+ no_more = __nss_next (&nip, "getntohost_r", &fct.ptr, status, 0);
+ }
+
+ if (status == NSS_STATUS_SUCCESS)
+ /* XXX This is a potential cause of trouble because the size of
+ the HOSTNAME buffer is not known but the interface does not
+ provide this information. */
+ strcpy (hostname, etherent.e_name);
+
+ return status == NSS_STATUS_SUCCESS ? 0 : -1;
+}
diff --git a/newlib/libc/sys/linux/net/etherent.h b/newlib/libc/sys/linux/net/etherent.h
new file mode 100644
index 000000000..95a58b48c
--- /dev/null
+++ b/newlib/libc/sys/linux/net/etherent.h
@@ -0,0 +1,9 @@
+/* Because the `ethers' lookup does not fit so well in the scheme we
+ define a dummy struct here which helps us to use the available
+ functions. */
+struct etherent
+{
+ const char *e_name;
+ struct ether_addr e_addr;
+};
+
diff --git a/newlib/libc/sys/linux/net/ethers-lookup.c b/newlib/libc/sys/linux/net/ethers-lookup.c
new file mode 100644
index 000000000..d31ea841a
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ethers-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME ethers
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/ethers.3 b/newlib/libc/sys/linux/net/ethers.3
deleted file mode 100644
index 7b7866fd9..000000000
--- a/newlib/libc/sys/linux/net/ethers.3
+++ /dev/null
@@ -1,197 +0,0 @@
-.\" Copyright (c) 1995
-.\" Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul.
-.\" 4. Neither the name of the author nor the names of any co-contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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.
-.\"
-.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.19 2002/01/14 16:59:00 ru Exp $
-.\"
-.Dd April 12, 1995
-.Dt ETHERS 3
-.Os
-.Sh NAME
-.Nm ethers ,
-.Nm ether_line ,
-.Nm ether_aton ,
-.Nm ether_ntoa ,
-.Nm ether_ntohost ,
-.Nm ether_hostton
-.Nd Ethernet address conversion and lookup routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In net/ethernet.h
-.Ft int
-.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname"
-.Ft struct ether_addr *
-.Fn ether_aton "const char *a"
-.Ft char *
-.Fn ether_ntoa "const struct ether_addr *n"
-.Ft int
-.Fn ether_ntohost "char *hostname" "const struct ether_addr *e"
-.Ft int
-.Fn ether_hostton "const char *hostname" "struct ether_addr *e"
-.Sh DESCRIPTION
-These functions operate on ethernet addresses using an
-.Ar ether_addr
-structure, which is defined in the header file
-.Aq Pa netinet/if_ether.h :
-.Bd -literal -offset indent
-/*
- * The number of bytes in an ethernet (MAC) address.
- */
-#define ETHER_ADDR_LEN 6
-
-/*
- * Structure of a 48-bit Ethernet address.
- */
-struct ether_addr {
- u_char octet[ETHER_ADDR_LEN];
-};
-.Ed
-.Pp
-The function
-.Fn ether_line
-scans
-.Ar l ,
-an
-.Tn ASCII
-string in
-.Xr ethers 5
-format and sets
-.Ar e
-to the ethernet address specified in the string and
-.Ar h
-to the hostname.
-This function is used to parse lines from
-.Pa /etc/ethers
-into their component parts.
-.Pp
-The
-.Fn ether_aton
-function converts an
-.Tn ASCII
-representation of an ethernet address into an
-.Ar ether_addr
-structure.
-Likewise,
-.Fn ether_ntoa
-converts an ethernet address specified as an
-.Ar ether_addr
-structure into an
-.Tn ASCII
-string.
-.Pp
-The
-.Fn ether_ntohost
-and
-.Fn ether_hostton
-functions map ethernet addresses to their corresponding hostnames
-as specified in the
-.Pa /etc/ethers
-database.
-.Fn ether_ntohost
-converts from ethernet address to hostname, and
-.Fn ether_hostton
-converts from hostname to ethernet address.
-.Sh RETURN VALUES
-.Fn ether_line
-returns zero on success and non-zero if it was unable to parse
-any part of the supplied line
-.Ar l .
-It returns the extracted ethernet address in the supplied
-.Ar ether_addr
-structure
-.Ar e
-and the hostname in the supplied string
-.Ar h .
-.Pp
-On success,
-.Fn ether_ntoa
-returns a pointer to a string containing an
-.Tn ASCII
-representation of an ethernet address.
-If it is unable to convert
-the supplied
-.Ar ether_addr
-structure, it returns a
-.Dv NULL
-pointer.
-Likewise,
-.Fn ether_aton
-returns a pointer to an
-.Ar ether_addr
-structure on success and a
-.Dv NULL
-pointer on failure.
-.Pp
-The
-.Fn ether_ntohost
-and
-.Fn ether_hostton
-functions both return zero on success or non-zero if they were
-unable to find a match in the
-.Pa /etc/ethers
-database.
-.Sh NOTES
-The user must insure that the hostname strings passed to the
-.Fn ether_line ,
-.Fn ether_ntohost
-and
-.Fn ether_hostton
-functions are large enough to contain the returned hostnames.
-.Sh NIS INTERACTION
-If the
-.Pa /etc/ethers
-contains a line with a single + in it, the
-.Fn ether_ntohost
-and
-.Fn ether_hostton
-functions will attempt to consult the NIS
-.Pa ethers.byname
-and
-.Pa ethers.byaddr
-maps in addition to the data in the
-.Pa /etc/ethers
-file.
-.Sh SEE ALSO
-.Xr ethers 5 ,
-.Xr yp 8
-.Sh BUGS
-The
-.Fn ether_aton
-and
-.Fn ether_ntoa
-functions returns values that are stored in static memory areas
-which may be overwritten the next time they are called.
-.Sh HISTORY
-This particular implementation of the
-.Nm
-library functions were written for and first appeared in
-.Fx 2.1 .
diff --git a/newlib/libc/sys/linux/net/function.def b/newlib/libc/sys/linux/net/function.def
new file mode 100644
index 000000000..59a06a2d3
--- /dev/null
+++ b/newlib/libc/sys/linux/net/function.def
@@ -0,0 +1,78 @@
+/* List of functions defined for static NSS in GNU C Library.
+ Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ This is a minimal config. Only services `files' and `dns' are supported.
+*/
+
+/* aliases */
+DEFINE_ENT (files, alias)
+DEFINE_GETBY (files, alias, name)
+
+/* ethers */
+DEFINE_ENT (files, ether)
+
+/* group */
+DEFINE_ENT (files, gr)
+DEFINE_GET (files, grgid)
+DEFINE_GET (files, grnam)
+
+/* hosts */
+DEFINE_ENT (files, host)
+DEFINE_GETBY (files, host, addr)
+DEFINE_GETBY (files, host, name)
+DEFINE_GET (files, hostton)
+DEFINE_GET (files, ntohost)
+DEFINE_GETBY (dns, host, addr)
+DEFINE_GETBY (dns, host, name)
+DEFINE_GETBY (dns, host, name2)
+
+/* netgroup */
+DEFINE_ENT (files, netgr)
+
+/* networks */
+DEFINE_ENT (files, net)
+DEFINE_GETBY (files, net, name)
+DEFINE_GETBY (files, net, addr)
+DEFINE_GETBY (dns, net, name)
+DEFINE_GETBY (dns, net, addr)
+
+/* protocols */
+DEFINE_ENT (files, proto)
+DEFINE_GETBY (files, proto, name)
+DEFINE_GETBY (files, proto, number)
+
+/* passwd */
+DEFINE_ENT (files, pw)
+DEFINE_GET (files, pwnam)
+DEFINE_GET (files, pwuid)
+
+/* rpc */
+DEFINE_ENT (files, rpc)
+DEFINE_GETBY (files, rpc, name)
+DEFINE_GETBY (files, rpc, number)
+
+/* services */
+DEFINE_ENT (files, serv)
+DEFINE_GETBY (files, serv, name)
+DEFINE_GETBY (files, serv, port)
+
+/* shadow */
+DEFINE_ENT (files, sp)
+DEFINE_GET (files, spnam)
diff --git a/newlib/libc/sys/linux/net/getXXbyYY.c b/newlib/libc/sys/linux/net/getXXbyYY.c
new file mode 100644
index 000000000..4fa25fa14
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getXXbyYY.c
@@ -0,0 +1,156 @@
+/* Copyright (C) 1996-2001,2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include <stdlib.h>
+#include <resolv.h>
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined: *|
+|* *|
+|* LOOKUP_TYPE - the return type of the function *|
+|* *|
+|* FUNCTION_NAME - name of the non-reentrant function *|
+|* *|
+|* DATABASE_NAME - name of the database the function accesses *|
+|* (e.g., host, services, ...) *|
+|* *|
+|* ADD_PARAMS - additional parameter, can vary in number *|
+|* *|
+|* ADD_VARIABLES - names of additional parameter *|
+|* *|
+|* BUFLEN - length of buffer allocated for the non *|
+|* reentrant version *|
+|* *|
+|* Optionally the following vars can be defined: *|
+|* *|
+|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
+|* the global `h_errno' variable. *|
+|* *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier. */
+#define REENTRANT_NAME APPEND_R (FUNCTION_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+#define INTERNAL(name) INTERNAL1 (name)
+#define INTERNAL1(name) __##name
+
+/* Sometimes we need to store error codes in the `h_errno' variable. */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , &h_errno_tmp
+# define H_ERRNO_VAR_P &h_errno_tmp
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+# define H_ERRNO_VAR_P NULL
+#endif
+
+#ifdef HAVE_AF
+# define AF_VAL af
+#else
+# define AF_VAL AF_INET
+#endif
+
+/* Prototype for reentrant version we use here. */
+extern int INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf,
+ char *buffer, size_t buflen,
+ LOOKUP_TYPE **result H_ERRNO_PARM);
+
+/* We need to protect the dynamic buffer handling. */
+__libc_lock_define_initialized (static, lock);
+
+/* This points to the static buffer used. */
+libc_freeres_ptr (static char *buffer);
+
+
+LOOKUP_TYPE *
+FUNCTION_NAME (ADD_PARAMS)
+{
+ static size_t buffer_size;
+ static LOOKUP_TYPE resbuf;
+ LOOKUP_TYPE *result;
+#ifdef NEED_H_ERRNO
+ int h_errno_tmp = 0;
+#endif
+
+ /* Get lock. */
+ __libc_lock_lock (lock);
+
+ if (buffer == NULL)
+ {
+ buffer_size = BUFLEN;
+ buffer = (char *) malloc (buffer_size);
+ }
+
+#ifdef HANDLE_DIGITS_DOTS
+ if (buffer != NULL)
+ {
+ if (__nss_hostname_digits_dots (name, &resbuf, &buffer,
+ &buffer_size, 0, &result, NULL, AF_VAL,
+ H_ERRNO_VAR_P))
+ goto done;
+ }
+#endif
+
+ while (buffer != NULL
+ && (INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, &resbuf, buffer,
+ buffer_size, &result H_ERRNO_VAR)
+ == ERANGE)
+#ifdef NEED_H_ERRNO
+ && h_errno_tmp == NETDB_INTERNAL
+#endif
+ )
+ {
+ char *new_buf;
+ buffer_size *= 2;
+ new_buf = (char *) realloc (buffer, buffer_size);
+ if (new_buf == NULL)
+ {
+ /* We are out of memory. Free the current buffer so that the
+ process gets a chance for a normal termination. */
+ free (buffer);
+ errno = (ENOMEM);
+ }
+ buffer = new_buf;
+ }
+
+ if (buffer == NULL)
+ result = NULL;
+
+#ifdef HANDLE_DIGITS_DOTS
+done:
+#endif
+ /* Release lock. */
+ __libc_lock_unlock (lock);
+
+#ifdef NEED_H_ERRNO
+ if (h_errno_tmp != 0)
+ h_errno = (h_errno_tmp);
+#endif
+
+ return result;
+}
+
+static_link_warning (FUNCTION_NAME)
diff --git a/newlib/libc/sys/linux/net/getXXbyYY_r.c b/newlib/libc/sys/linux/net/getXXbyYY_r.c
new file mode 100644
index 000000000..326df94b7
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getXXbyYY_r.c
@@ -0,0 +1,292 @@
+/* Copyright (C) 1996-2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include "nsswitch.h"
+#ifdef USE_NSCD
+# include <nscd/nscd_proto.h>
+#endif
+#ifdef NEED__RES_HCONF
+# include "res_hconf.h"
+#endif
+#ifdef NEED__RES
+# include <resolv.h>
+#endif
+/*******************************************************************\
+|* Here we assume several symbols to be defined: *|
+|* *|
+|* LOOKUP_TYPE - the return type of the function *|
+|* *|
+|* FUNCTION_NAME - name of the non-reentrant function *|
+|* *|
+|* DATABASE_NAME - name of the database the function accesses *|
+|* (e.g., host, services, ...) *|
+|* *|
+|* ADD_PARAMS - additional parameter, can vary in number *|
+|* *|
+|* ADD_VARIABLES - names of additional parameter *|
+|* *|
+|* Optionally the following vars can be defined: *|
+|* *|
+|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
+|* the global `h_errno' variable. *|
+|* *|
+|* NEED__RES - the global _res variable might be used so we *|
+|* will have to initialize it if necessary *|
+|* *|
+|* PREPROCESS - code run before anything else *|
+|* *|
+|* POSTPROCESS - code run after the lookup *|
+|* *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier. */
+#define REENTRANT_NAME APPEND_R (FUNCTION_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+#define INTERNAL(name) INTERNAL1 (name)
+#define INTERNAL1(name) __##name
+#define NEW(name) NEW1 (name)
+#define NEW1(name) __new_##name
+
+#ifdef USE_NSCD
+# define NSCD_NAME ADD_NSCD (REENTRANT_NAME)
+# define ADD_NSCD(name) ADD_NSCD1 (name)
+# define ADD_NSCD1(name) __nscd_##name
+# define NOT_USENSCD_NAME ADD_NOT_NSCDUSE (DATABASE_NAME)
+# define ADD_NOT_NSCDUSE(name) ADD_NOT_NSCDUSE1 (name)
+# define ADD_NOT_NSCDUSE1(name) __nss_not_use_nscd_##name
+#endif
+
+#define FUNCTION_NAME_STRING STRINGIZE (FUNCTION_NAME)
+#define REENTRANT_NAME_STRING STRINGIZE (REENTRANT_NAME)
+#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
+#define STRINGIZE(name) STRINGIZE1 (name)
+#define STRINGIZE1(name) #name
+
+#ifndef DB_LOOKUP_FCT
+# define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+# define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+# define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+#endif
+
+/* Sometimes we need to store error codes in the `h_errno' variable. */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , h_errnop
+# define H_ERRNO_VAR_P h_errnop
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+# define H_ERRNO_VAR_P NULL
+#endif
+
+#ifdef HAVE_AF
+# define AF_VAL af
+#else
+# define AF_VAL AF_INET
+#endif
+
+/* Type of the lookup function we need here. */
+typedef enum nss_status (*lookup_function) (ADD_PARAMS, LOOKUP_TYPE *, char *,
+ size_t, int * H_ERRNO_PARM);
+
+/* The lookup function for the first entry of this service. */
+extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp)
+ internal_function;
+libc_hidden_proto (DB_LOOKUP_FCT)
+
+
+int
+INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
+ size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM)
+{
+ static service_user *startp;
+ static lookup_function start_fct;
+ service_user *nip;
+ union
+ {
+ lookup_function l;
+ void *ptr;
+ } fct;
+
+ int no_more;
+ enum nss_status status = NSS_STATUS_UNAVAIL;
+#ifdef USE_NSCD
+ int nscd_status;
+#endif
+#ifdef NEED_H_ERRNO
+ bool any_service = false;
+#endif
+
+#ifdef PREPROCESS
+ PREPROCESS;
+#endif
+
+#ifdef HANDLE_DIGITS_DOTS
+ switch (__nss_hostname_digits_dots (name, resbuf, &buffer, NULL,
+ buflen, result, &status, AF_VAL,
+ H_ERRNO_VAR_P))
+ {
+ case -1:
+ return errno;
+ case 1:
+ goto done;
+ }
+#endif
+
+#ifdef USE_NSCD
+ if (NOT_USENSCD_NAME > 0 && ++NOT_USENSCD_NAME > NSS_NSCD_RETRY)
+ NOT_USENSCD_NAME = 0;
+
+ if (!NOT_USENSCD_NAME)
+ {
+ nscd_status = NSCD_NAME (ADD_VARIABLES, resbuf, buffer, buflen, result
+ H_ERRNO_VAR);
+ if (nscd_status >= 0)
+ return nscd_status;
+ }
+#endif
+
+ if (startp == NULL)
+ {
+ no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, &fct.ptr);
+ if (no_more)
+ startp = (service_user *) -1l;
+ else
+ {
+ startp = nip;
+ start_fct = fct.l;
+
+#ifdef NEED__RES
+ /* The resolver code will really be used so we have to
+ initialize it. */
+ if (__res_maybe_init (&_res, 0) == -1)
+ {
+ *h_errnop = NETDB_INTERNAL;
+ *result = NULL;
+ return errno;
+ }
+#endif /* need _res */
+#ifdef NEED__RES_HCONF
+ if (!_res_hconf.initialized)
+ _res_hconf_init ();
+#endif /* need _res_hconf */
+ }
+ }
+ else
+ {
+ fct.l = start_fct;
+ no_more = (nip = startp) == (service_user *) -1l;
+ }
+
+ while (no_more == 0)
+ {
+#ifdef NEED_H_ERRNO
+ any_service = true;
+#endif
+
+ status = DL_CALL_FCT (fct.l, (ADD_VARIABLES, resbuf, buffer, buflen,
+ &errno H_ERRNO_VAR));
+
+ /* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
+ provided buffer is too small. In this case we should give
+ the user the possibility to enlarge the buffer and we should
+ not simply go on with the next service (even if the TRYAGAIN
+ action tells us so). */
+ if (status == NSS_STATUS_TRYAGAIN
+#ifdef NEED_H_ERRNO
+ && *h_errnop == NETDB_INTERNAL
+#endif
+ && errno == ERANGE)
+ break;
+
+ no_more = __nss_next (&nip, REENTRANT_NAME_STRING,
+ &fct.ptr, status, 0);
+ }
+
+#ifdef HANDLE_DIGITS_DOTS
+done:
+#endif
+ *result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
+#ifdef NEED_H_ERRNO
+ if (status != NSS_STATUS_SUCCESS && ! any_service)
+ /* We were not able to use any service. */
+ *h_errnop = NO_RECOVERY;
+#endif
+#ifdef POSTPROCESS
+ POSTPROCESS;
+#endif
+
+ int res;
+ if (status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND)
+ res = 0;
+ /* Don't pass back ERANGE if this is not for a too-small buffer. */
+ else if (errno == ERANGE && status != NSS_STATUS_TRYAGAIN)
+ res = EINVAL;
+#ifdef NEED_H_ERRNO
+ /* These functions only set errno if h_errno is NETDB_INTERNAL. */
+ else if (status == NSS_STATUS_TRYAGAIN && *h_errnop != NETDB_INTERNAL)
+ res = EAGAIN;
+#endif
+ else
+ return errno;
+
+ __set_errno (res);
+ return res;
+}
+
+
+#include <shlib-compat.h>
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2)
+#define OLD(name) OLD1 (name)
+#define OLD1(name) __old_##name
+
+int
+attribute_compat_text_section
+OLD (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
+ size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM)
+{
+ int ret = INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, resbuf, buffer,
+ buflen, result H_ERRNO_VAR);
+
+ if (ret != 0 || result == NULL)
+ ret = -1;
+
+ return ret;
+}
+
+#define do_symbol_version(real, name, version) \
+ compat_symbol (libc, real, name, version)
+do_symbol_version (OLD (REENTRANT_NAME), REENTRANT_NAME, GLIBC_2_0);
+#endif
+
+/* As INTERNAL (REENTRANT_NAME) may be hidden, we need an alias
+ in between so that the REENTRANT_NAME@@GLIBC_2.1.2 is not
+ hidden too. */
+strong_alias (INTERNAL (REENTRANT_NAME), NEW (REENTRANT_NAME));
+
+#define do_default_symbol_version(real, name, version) \
+ versioned_symbol (libc, real, name, version)
+do_default_symbol_version (NEW (REENTRANT_NAME),
+ REENTRANT_NAME, GLIBC_2_1_2);
+
+static_link_warning (REENTRANT_NAME)
diff --git a/newlib/libc/sys/linux/net/getXXent.c b/newlib/libc/sys/linux/net/getXXent.c
new file mode 100644
index 000000000..a2d5f401b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getXXent.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include <stdlib.h>
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined: *|
+|* *|
+|* LOOKUP_TYPE - the return type of the function *|
+|* *|
+|* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
+|* *|
+|* BUFLEN - size of static buffer *|
+|* *|
+|* Optionally the following vars can be defined: *|
+|* *|
+|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
+|* the global `h_errno' variable. *|
+|* *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier. */
+#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+#define INTERNAL(name) INTERNAL1 (name)
+#define INTERNAL1(name) __##name
+
+/* Sometimes we need to store error codes in the `h_errno' variable. */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR &h_errno
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR NULL
+#endif
+
+/* Prototype of the reentrant version. */
+extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
+ size_t buflen, LOOKUP_TYPE **result
+ H_ERRNO_PARM);
+
+/* We need to protect the dynamic buffer handling. */
+__libc_lock_define_initialized (static, lock);
+
+/* This points to the static buffer used. */
+libc_freeres_ptr (static char *buffer);
+
+
+LOOKUP_TYPE *
+GETFUNC_NAME (void)
+{
+ static size_t buffer_size;
+ static union
+ {
+ LOOKUP_TYPE l;
+ void *ptr;
+ } resbuf;
+ LOOKUP_TYPE *result;
+ int save;
+
+ /* Get lock. */
+ __libc_lock_lock (lock);
+
+ result = (LOOKUP_TYPE *)
+ __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
+ &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
+ H_ERRNO_VAR);
+
+ save = errno;
+ __libc_lock_unlock (lock);
+ __set_errno (save);
+ return result;
+}
+
+static_link_warning (GETFUNC_NAME)
diff --git a/newlib/libc/sys/linux/net/getXXent_r.c b/newlib/libc/sys/linux/net/getXXent_r.c
new file mode 100644
index 000000000..e0228e40e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getXXent_r.c
@@ -0,0 +1,209 @@
+/* Copyright (C) 1996,97,98,99,2000,2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined: *|
+|* *|
+|* LOOKUP_TYPE - the return type of the function *|
+|* *|
+|* SETFUNC_NAME - name of the non-reentrant setXXXent function *|
+|* *|
+|* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
+|* *|
+|* ENDFUNC_NAME - name of the non-reentrant endXXXent function *|
+|* *|
+|* DATABASE_NAME - name of the database the function accesses *|
+|* (e.g., host, services, ...) *|
+|* *|
+|* Optionally the following vars can be defined: *|
+|* *|
+|* STAYOPEN - variable declaration for setXXXent function *|
+|* *|
+|* STAYOPEN_VAR - variable name for setXXXent function *|
+|* *|
+|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
+|* the global `h_errno' variable. *|
+|* *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier. */
+#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
+#define APPEND_R(Name) CONCAT2_2 (Name, _r)
+#define INTERNAL(Name) CONCAT2_2 (__, Name)
+#define CONCAT2_1(Pre, Post) CONCAT2_2 (Pre, Post)
+#define CONCAT2_2(Pre, Post) Pre##Post
+#define NEW(name) NEW1 (name)
+#define NEW1(name) __new_##name
+
+#define SETFUNC_NAME_STRING STRINGIZE (SETFUNC_NAME)
+#define GETFUNC_NAME_STRING STRINGIZE (REENTRANT_GETNAME)
+#define ENDFUNC_NAME_STRING STRINGIZE (ENDFUNC_NAME)
+#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
+#define STRINGIZE(Name) STRINGIZE1 (Name)
+#define STRINGIZE1(Name) #Name
+
+#ifndef DB_LOOKUP_FCT
+# define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+# define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+# define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+#endif
+
+/* Sometimes we need to store error codes in the `h_errno' variable. */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , &h_errno
+# define H_ERRNO_VAR_P &h_errno
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+# define H_ERRNO_VAR_P NULL
+#endif
+
+/* Some databases take the `stayopen' flag. */
+#ifdef STAYOPEN
+# define STAYOPEN_TMP CONCAT2_1 (STAYOPEN, _tmp)
+# define STAYOPEN_TMPVAR &CONCAT2_1 (STAYOPEN_VAR, _tmp)
+#else
+# define STAYOPEN void
+# define STAYOPEN_VAR 0
+# define STAYOPEN_TMPVAR NULL
+#endif
+
+#ifndef NEED__RES
+# define NEED__RES 0
+#endif
+
+/* This handle for the NSS data base is shared between all
+ set/get/endXXXent functions. */
+static service_user *nip;
+/* Remember the last service used since the last call to `endXXent'. */
+static service_user *last_nip;
+/* Remember the first service_entry, it's always the same. */
+static service_user *startp;
+
+#ifdef STAYOPEN_TMP
+/* We need to remember the last `stayopen' flag given by the user
+ since the `setent' function is only called for the first available
+ service. */
+static STAYOPEN_TMP;
+#endif
+
+/* Protect above variable against multiple uses at the same time. */
+__libc_lock_define_initialized (static, lock)
+
+/* The lookup function for the first entry of this service. */
+extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp)
+ internal_function;
+libc_hidden_proto (DB_LOOKUP_FCT)
+
+void
+SETFUNC_NAME (STAYOPEN)
+{
+ int save;
+
+ __libc_lock_lock (lock);
+ __nss_setent (SETFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
+ &last_nip, STAYOPEN_VAR, STAYOPEN_TMPVAR, NEED__RES);
+
+ save = errno;
+ __libc_lock_unlock (lock);
+ __set_errno (save);
+}
+
+
+void
+ENDFUNC_NAME (void)
+{
+ int save;
+
+ /* If the service has not been used before do not do anything. */
+ if (startp != NULL)
+ {
+ __libc_lock_lock (lock);
+ __nss_endent (ENDFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
+ &last_nip, NEED__RES);
+ save = errno;
+ __libc_lock_unlock (lock);
+ __set_errno (save);
+ }
+}
+
+
+int
+INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
+ LOOKUP_TYPE **result H_ERRNO_PARM)
+{
+ int status;
+ int save;
+
+ __libc_lock_lock (lock);
+ status = __nss_getent_r (GETFUNC_NAME_STRING, SETFUNC_NAME_STRING,
+ DB_LOOKUP_FCT, &nip, &startp, &last_nip,
+ STAYOPEN_TMPVAR, NEED__RES, resbuf, buffer,
+ buflen, (void **) result, H_ERRNO_VAR_P);
+ save = errno;
+ __libc_lock_unlock (lock);
+ __set_errno (save);
+ return status;
+}
+
+
+#include <shlib-compat.h>
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2)
+#define OLD(name) OLD1 (name)
+#define OLD1(name) __old_##name
+
+int
+attribute_compat_text_section
+OLD (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
+ LOOKUP_TYPE **result H_ERRNO_PARM)
+{
+ int ret = INTERNAL (REENTRANT_GETNAME) (resbuf, buffer, buflen,
+ result H_ERRNO_VAR);
+
+ if (ret != 0)
+ ret = -1;
+
+ return ret;
+}
+
+#define do_symbol_version(real, name, version) \
+ compat_symbol (libc, real, name, version)
+do_symbol_version (OLD (REENTRANT_GETNAME), REENTRANT_GETNAME, GLIBC_2_0);
+#endif
+
+/* As INTERNAL (REENTRANT_GETNAME) may be hidden, we need an alias
+ in between so that the REENTRANT_GETNAME@@GLIBC_2.1.2 is not
+ hidden too. */
+strong_alias (INTERNAL (REENTRANT_GETNAME), NEW (REENTRANT_GETNAME));
+
+#define do_default_symbol_version(real, name, version) \
+ versioned_symbol (libc, real, name, version)
+do_default_symbol_version (NEW (REENTRANT_GETNAME),
+ REENTRANT_GETNAME, GLIBC_2_1_2);
+
+static_link_warning (SETFUNC_NAME)
+static_link_warning (ENDFUNC_NAME)
+static_link_warning (REENTRANT_GETNAME)
diff --git a/newlib/libc/sys/linux/net/getaddrinfo.3 b/newlib/libc/sys/linux/net/getaddrinfo.3
deleted file mode 100644
index eca8b03b2..000000000
--- a/newlib/libc/sys/linux/net/getaddrinfo.3
+++ /dev/null
@@ -1,620 +0,0 @@
-.\" $FreeBSD: src/lib/libc/net/getaddrinfo.3,v 1.18 2002/04/19 04:46:20 suz Exp $
-.\" $KAME: getaddrinfo.3,v 1.31 2001/08/05 18:19:38 itojun 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
-.\"
-.Dd May 25, 1995
-.Dt GETADDRINFO 3
-.Os
-.\"
-.Sh NAME
-.Nm getaddrinfo ,
-.Nm freeaddrinfo ,
-.Nm gai_strerror
-.Nd nodename-to-address translation in protocol-independent manner
-.\"
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In netdb.h
-.Ft int
-.Fn getaddrinfo "const char *nodename" "const char *servname" \
-"const struct addrinfo *hints" "struct addrinfo **res"
-.Ft void
-.Fn freeaddrinfo "struct addrinfo *ai"
-.Ft "char *"
-.Fn gai_strerror "int ecode"
-.\"
-.Sh DESCRIPTION
-The
-.Fn getaddrinfo
-function is defined for protocol-independent nodename-to-address translation.
-It performs the functionality of
-.Xr gethostbyname 3
-and
-.Xr getservbyname 3 ,
-but in a more sophisticated manner.
-.Pp
-The
-.Li addrinfo
-structure is defined as a result of including the
-.Aq Pa netdb.h
-header:
-.Bd -literal -offset
-struct addrinfo {
- int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
- int ai_family; /* PF_xxx */
- int ai_socktype; /* SOCK_xxx */
- int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
- size_t ai_addrlen; /* length of ai_addr */
- char *ai_canonname; /* canonical name for nodename */
- struct sockaddr *ai_addr; /* binary address */
- struct addrinfo *ai_next; /* next structure in linked list */
-};
-.Ed
-.Pp
-The
-.Fa nodename
-and
-.Fa servname
-arguments are pointers to null-terminated strings or
-.Dv NULL .
-One or both of these two arguments must be a
-.Pf non Dv -NULL
-pointer.
-In the normal client scenario, both the
-.Fa nodename
-and
-.Fa servname
-are specified.
-In the normal server scenario, only the
-.Fa servname
-is specified.
-A
-.Pf non Dv -NULL
-.Fa nodename
-string can be either a node name or a numeric host address string
-(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
-A
-.Pf non Dv -NULL
-.Fa servname
-string can be either a service name or a decimal port number.
-.Pp
-The caller can optionally pass an
-.Li addrinfo
-structure, pointed to by the third argument,
-to provide hints concerning the type of socket that the caller supports.
-In this
-.Fa hints
-structure all members other than
-.Fa ai_flags ,
-.Fa ai_family ,
-.Fa ai_socktype ,
-and
-.Fa ai_protocol
-must be zero or a
-.Dv NULL
-pointer.
-A value of
-.Dv PF_UNSPEC
-for
-.Fa ai_family
-means the caller will accept any protocol family.
-A value of 0 for
-.Fa ai_socktype
-means the caller will accept any socket type.
-A value of 0 for
-.Fa ai_protocol
-means the caller will accept any protocol.
-For example, if the caller handles only TCP and not UDP, then the
-.Fa ai_socktype
-member of the hints structure should be set to
-.Dv SOCK_STREAM
-when
-.Fn getaddrinfo
-is called.
-If the caller handles only IPv4 and not IPv6, then the
-.Fa ai_family
-member of the
-.Fa hints
-structure should be set to
-.Dv PF_INET
-when
-.Fn getaddrinfo
-is called.
-If the third argument to
-.Fn getaddrinfo
-is a
-.Dv NULL
-pointer, this is the same as if the caller had filled in an
-.Li addrinfo
-structure initialized to zero with
-.Fa ai_family
-set to
-.Dv PF_UNSPEC .
-.Pp
-Upon successful return a pointer to a linked list of one or more
-.Li addrinfo
-structures is returned through the final argument.
-The caller can process each
-.Li addrinfo
-structure in this list by following the
-.Fa ai_next
-pointer, until a
-.Dv NULL
-pointer is encountered.
-In each returned
-.Li addrinfo
-structure the three members
-.Fa ai_family ,
-.Fa ai_socktype ,
-and
-.Fa ai_protocol
-are the corresponding arguments for a call to the
-.Fn socket
-function.
-In each
-.Li addrinfo
-structure the
-.Fa ai_addr
-member points to a filled-in socket address structure whose length is
-specified by the
-.Fa ai_addrlen
-member.
-.Pp
-If the
-.Dv AI_PASSIVE
-bit is set in the
-.Fa ai_flags
-member of the
-.Fa hints
-structure, then the caller plans to use the returned socket address
-structure in a call to
-.Fn bind .
-In this case, if the
-.Fa nodename
-argument is a
-.Dv 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 in the
-.Fa ai_flags
-member of the
-.Fa hints
-structure, then the returned socket address structure will be ready for a
-call to
-.Fn connect
-(for a connection-oriented protocol)
-or either
-.Fn connect ,
-.Fn sendto ,
-or
-.Fn sendmsg
-(for a connectionless protocol).
-In this case, if the
-.Fa nodename
-argument is a
-.Dv NULL
-pointer, then the IP address portion of the
-socket address structure will be set to the loopback address.
-.Pp
-If the
-.Dv AI_CANONNAME
-bit is set in the
-.Fa ai_flags
-member of the
-.Fa hints
-structure, then upon successful return the
-.Fa ai_canonname
-member of the first
-.Li addrinfo
-structure in the linked list will point to a null-terminated string
-containing the canonical name of the specified
-.Fa nodename .
-.Pp
-If the
-.Dv AI_NUMERICHOST
-bit is set in the
-.Fa ai_flags
-member of the
-.Fa hints
-structure, then a
-.Pf non Dv -NULL
-.Fa nodename
-string must be a numeric host address string.
-Otherwise an error of
-.Dv EAI_NONAME
-is returned.
-This flag prevents any type of name resolution service (e.g., the DNS)
-from being called.
-.Pp
-The arguments to
-.Fn getaddrinfo
-must be sufficiently consistent and unambiguous.
-Here are some problem cases you may encounter:
-.Bl -bullet
-.It
-.Fn getaddrinfo
-will fail if the members in the
-.Fa hints
-structure are not consistent.
-For example, for internet address families,
-.Fn getaddrinfo
-will fail if you specify
-.Dv SOCK_STREAM
-to
-.Fa ai_socktype
-while you specify
-.Dv IPPROTO_UDP
-to
-.Fa ai_protocol .
-.It
-If you specify a
-.Fa servname
-which is defined only for certain
-.Fa ai_socktype ,
-.Fn getaddrinfo
-will fail because the arguments are not consistent.
-For example,
-.Fn getaddrinfo
-will return an error if you ask for
-.Dq Li tftp
-service on
-.Dv SOCK_STREAM .
-.It
-For internet address families, if you specify
-.Fa servname
-while you set
-.Fa ai_socktype
-to
-.Dv SOCK_RAW ,
-.Fn getaddrinfo
-will fail, because service names are not defined for the internet
-.Dv SOCK_RAW
-space.
-.It
-If you specify numeric
-.Fa servname ,
-while leaving
-.Fa ai_socktype
-and
-.Fa ai_protocol
-unspecified,
-.Fn getaddrinfo
-will fail.
-This is because the numeric
-.Fa servname
-does not identify any socket type, and
-.Fn getaddrinfo
-is not allowed to glob the argument in such case.
-.El
-.Pp
-All of the information returned by
-.Fn getaddrinfo
-is dynamically allocated:
-the
-.Li addrinfo
-structures, the socket address structures, and canonical node name
-strings pointed to by the addrinfo structures.
-To return this information to the system the function
-.Fn freeaddrinfo
-is called.
-The
-.Fa addrinfo
-structure pointed to by the
-.Fa ai argument
-is freed, along with any dynamic storage pointed to by the structure.
-This operation is repeated until a
-.Dv NULL
-.Fa ai_next
-pointer is encountered.
-.Pp
-To aid applications in printing error messages based on the
-.Dv EAI_xxx
-codes returned by
-.Fn getaddrinfo ,
-.Fn gai_strerror
-is defined.
-The argument is one of the
-.Dv EAI_xxx
-values defined earlier and the return value points to a string describing
-the error.
-If the argument is not one of the
-.Dv EAI_xxx
-values, the function still returns a pointer to a string whose contents
-indicate an unknown error.
-.\"
-.Sh EXTENSIONS
-This implementation supports numeric IPv6 address notation with the
-experimental scope identifier.
-By appending a percent sign and scope identifier to the address, you
-can specify the value of the
-.Li sin6_scope_id
-field of the socket address.
-This makes management of scoped address easier,
-and allows cut-and-paste input of scoped addresses.
-.Pp
-At the moment the code supports only link-local addresses in this format.
-The scope identifier is hardcoded to name of hardware interface associated
-with the link,
-(such as
-.Li ne0 ) .
-For example,
-.Dq Li fe80::1%ne0 ,
-which means
-.Do
-.Li fe80::1
-on the link associated with the
-.Li ne0
-interface
-.Dc .
-.Pp
-This implementation is still very experimental and non-standard.
-The current implementation assumes a one-to-one relationship between
-interfaces and links, which is not necessarily true according to the
-specification.
-.\"
-.Sh EXAMPLES
-The following code tries to connect to
-.Dq Li www.kame.net
-service
-.Dq Li http .
-via stream socket.
-It loops through all the addresses available, regardless of the 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 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 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", "http", &hints, &res0);
-if (error) {
- errx(1, "%s", gai_strerror(error));
- /*NOTREACHED*/
-}
-s = -1;
-cause = "no addresses";
-errno = EADDRNOTAVAIL;
-for (res = res0; res; res = res->ai_next) {
- s = socket(res->ai_family, res->ai_socktype,
- res->ai_protocol);
- if (s < 0) {
- cause = "socket";
- continue;
- }
-
- if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
- cause = "connect";
- close(s);
- s = -1;
- continue;
- }
-
- break; /* okay we got one */
-}
-if (s < 0) {
- err(1, cause);
- /*NOTREACHED*/
-}
-freeaddrinfo(res0);
-.Ed
-.Pp
-The following example tries to open a wildcard listening socket onto service
-.Dq Li http ,
-for all the address families available.
-.Bd -literal -offset indent
-struct addrinfo hints, *res, *res0;
-int error;
-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, "http", &hints, &res0);
-if (error) {
- errx(1, "%s", gai_strerror(error));
- /*NOTREACHED*/
-}
-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] < 0) {
- cause = "socket";
- continue;
- }
-
- if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) {
- cause = "bind";
- close(s[nsock]);
- continue;
- }
-
- if (listen(s[nsock], SOMAXCONN) < 0) {
- cause = "listen";
- close(s[nsock]);
- continue;
- }
-
- nsock++;
-}
-if (nsock == 0) {
- err(1, cause);
- /*NOTREACHED*/
-}
-freeaddrinfo(res0);
-.Ed
-.\"
-.Sh FILES
-.Bl -tag -width /etc/nsswitch.conf -compact
-.It Pa /etc/hosts
-.It Pa /etc/nsswitch.conf
-.It Pa /etc/resolv.conf
-.El
-.\"
-.Sh DIAGNOSTICS
-Error return status from
-.Fn getaddrinfo
-is zero on success and non-zero on errors.
-Non-zero error codes are defined in
-.Aq Pa netdb.h ,
-and as follows:
-.Pp
-.Bl -tag -width EAI_ADDRFAMILY -compact
-.It Dv EAI_ADDRFAMILY
-Address family for
-.Fa nodename
-not supported.
-.It Dv EAI_AGAIN
-Temporary failure in name resolution.
-.It Dv EAI_BADFLAGS
-Invalid value for
-.Fa ai_flags .
-.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 nodename .
-.It Dv EAI_NONAME
-.Fa nodename
-nor
-.Fa servname
-provided, or not known.
-.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 .
-.It Dv EAI_BADHINTS
-Invalid value for
-.Fa hints .
-.It Dv EAI_PROTOCOL
-Resolved protocol is unknown.
-.It Dv EAI_MAX
-Unknown error.
-.El
-.Pp
-If called with an appropriate argument,
-.Fn gai_strerror
-returns a pointer to a string describing the given error code.
-If the argument is not one of the
-.Dv EAI_xxx
-values, the function still returns a pointer to a string whose contents
-indicate an unknown error.
-.\"
-.Sh SEE ALSO
-.Xr gethostbyname 3 ,
-.Xr getnameinfo 3 ,
-.Xr getservbyname 3 ,
-.Xr hosts 5 ,
-.Xr resolv.conf 5 ,
-.Xr services 5 ,
-.Xr hostname 7 ,
-.Xr named 8
-.Pp
-.Rs
-.%A R. Gilligan
-.%A S. Thomson
-.%A J. Bound
-.%A W. Stevens
-.%T Basic Socket Interface Extensions for IPv6
-.%R RFC2553
-.%D March 1999
-.Re
-.Rs
-.%A Tatsuya Jinmei
-.%A Atsushi Onoe
-.%T "An Extension of Format for IPv6 Scoped Addresses"
-.%R internet draft
-.%N draft-ietf-ipngwg-scopedaddr-format-02.txt
-.%O work in progress material
-.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 HISTORY
-The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-.\"
-.Sh STANDARDS
-The
-.Fn getaddrinfo
-function is defined in
-.St -p1003.1g-2000 ,
-and documented in
-.Dq Basic Socket Interface Extensions for IPv6
-(RFC2553).
-.\"
-.Sh BUGS
-The current implementation is not thread-safe.
-.Pp
-The text was shamelessly copied from RFC2553.
diff --git a/newlib/libc/sys/linux/net/getaddrinfo.c b/newlib/libc/sys/linux/net/getaddrinfo.c
index 97ba36209..742d46c8f 100644
--- a/newlib/libc/sys/linux/net/getaddrinfo.c
+++ b/newlib/libc/sys/linux/net/getaddrinfo.c
@@ -1,1979 +1,1699 @@
-/* $KAME: getaddrinfo.c,v 1.15 2000/07/09 04:37:24 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.
- */
-
-/*
- * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator.
- *
- * 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.
- * - 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.
- */
-/*
- * diffs with other KAME platforms:
- * - other KAME platforms already nuked FAITH ($GAI), but as FreeBSD
- * 4.0-RELEASE supplies it, we still have the code here.
- * - AI_ADDRCONFIG support is supplied
- * - some of FreeBSD style (#define tabify and others)
- * - classful IPv4 numeric (127.1) is allowed.
- */
-
-#include <sys/cdefs.h>
-#include <machine/endian.h>
-
-#include "namespace.h"
+/* The Inner Net License, Version 2.00
+
+ The author(s) grant permission for redistribution and use in source and
+binary forms, with or without modification, of the software and documentation
+provided that the following conditions are met:
+
+0. If you receive a version of the software that is specifically labelled
+ as not being for redistribution (check the version message and/or README),
+ you are not permitted to redistribute that version of the software in any
+ way or form.
+1. All terms of the all other applicable copyrights and licenses must be
+ followed.
+2. Redistributions of source code must retain the authors' copyright
+ notice(s), this list of conditions, and the following disclaimer.
+3. Redistributions in binary form must reproduce the authors' copyright
+ notice(s), this list of conditions, and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+4. [The copyright holder has authorized the removal of this clause.]
+5. Neither the name(s) of the author(s) 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 ITS AUTHORS 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 AUTHORS 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.
+
+ If these license terms cause you a real problem, contact the author. */
+
+/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
+
+#include <alloca.h>
#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
+#include <assert.h>
+#include <errno.h>
+#include <ifaddrs.h>
#include <netdb.h>
#include <resolv.h>
-#include <string.h>
+#include <stdbool.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <stddef.h>
-#include <ctype.h>
+#include <string.h>
#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#ifdef DEBUG
-#include <syslog.h>
-#endif
-
-#include <syslog.h>
-#include <stdarg.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#include <sys/utsname.h>
+#include <net/if.h>
#include <nsswitch.h>
-#include "un-namespace.h"
-
-#if defined(__KAME__) && defined(INET6)
-# define FAITH
+#include <not-cancel.h>
+#include <nscd/nscd-client.h>
+#include <nscd/nscd_proto.h>
+#include "local.h"
+
+#ifdef HAVE_LIBIDN
+extern int __idna_to_ascii_lz (const char *input, char **output, int flags);
+extern int __idna_to_unicode_lzlz (const char *input, char **output,
+ int flags);
+# include <libidn/idna.h>
#endif
-#define SUCCESS 0
-#define ANY 0
-#define YES 1
-#define NO 0
+#define GAIH_OKIFUNSPEC 0x0100
+#define GAIH_EAI ~(GAIH_OKIFUNSPEC)
-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
-#define N_INET6 0
- {PF_INET6, sizeof(struct in6_addr),
- sizeof(struct sockaddr_in6),
- offsetof(struct sockaddr_in6, sin6_addr),
- in6_addrany, in6_loopback, 1},
-#define N_INET 1
-#else
-#define N_INET 0
-#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
+#ifndef UNIX_PATH_MAX
+#define UNIX_PATH_MAX 108
#endif
-static const ns_src default_dns_files[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { NSSRC_DNS, NS_SUCCESS },
- { 0 }
+struct gaih_service
+ {
+ const char *name;
+ int num;
+ };
+
+struct gaih_servtuple
+ {
+ struct gaih_servtuple *next;
+ int socktype;
+ int protocol;
+ int port;
+ };
+
+static const struct gaih_servtuple nullserv;
+
+struct gaih_addrtuple
+ {
+ struct gaih_addrtuple *next;
+ char *name;
+ int family;
+ uint32_t addr[4];
+ uint32_t scopeid;
+ };
+
+struct gaih_typeproto
+ {
+ int socktype;
+ int protocol;
+ char name[4];
+ int protoflag;
+ };
+
+/* Values for `protoflag'. */
+#define GAI_PROTO_NOSERVICE 1
+#define GAI_PROTO_PROTOANY 2
+
+static const struct gaih_typeproto gaih_inet_typeproto[] =
+{
+ { 0, 0, "", 0 },
+ { SOCK_STREAM, IPPROTO_TCP, "tcp", 0 },
+ { SOCK_DGRAM, IPPROTO_UDP, "udp", 0 },
+ { SOCK_RAW, 0, "raw", GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE },
+ { 0, 0, "", 0 }
};
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
+struct gaih
+ {
+ int family;
+ int (*gaih)(const char *name, const struct gaih_service *service,
+ const struct addrinfo *req, struct addrinfo **pai);
+ };
+
+static const struct addrinfo default_hints =
+ {
+ .ai_flags = AI_DEFAULT,
+ .ai_family = PF_UNSPEC,
+ .ai_socktype = 0,
+ .ai_protocol = 0,
+ .ai_addrlen = 0,
+ .ai_addr = NULL,
+ .ai_canonname = NULL,
+ .ai_next = NULL
+ };
+
+#define s6_addr32 __u6_addr.__u6_addr32
-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 */
-};
+#if 0
+/* Using Unix sockets this way is a security risk. */
+static int
+gaih_local (const char *name, const struct gaih_service *service,
+ const struct addrinfo *req, struct addrinfo **pai)
+{
+ struct utsname utsname;
+
+ if ((name != NULL) && (req->ai_flags & AI_NUMERICHOST))
+ return GAIH_OKIFUNSPEC | -EAI_NONAME;
+
+ if ((name != NULL) || (req->ai_flags & AI_CANONNAME))
+ if (uname (&utsname) < 0)
+ return -EAI_SYSTEM;
+
+ if (name != NULL)
+ {
+ if (strcmp(name, "localhost") &&
+ strcmp(name, "local") &&
+ strcmp(name, "unix") &&
+ strcmp(name, utsname.nodename))
+ return GAIH_OKIFUNSPEC | -EAI_NONAME;
+ }
+
+ if (req->ai_protocol || req->ai_socktype)
+ {
+ const struct gaih_typeproto *tp = gaih_inet_typeproto + 1;
+
+ while (tp->name[0]
+ && ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0
+ || (req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
+ || (req->ai_protocol != 0
+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
+ && req->ai_protocol != tp->protocol)))
+ ++tp;
+
+ if (! tp->name[0])
+ {
+ if (req->ai_socktype)
+ return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
+ else
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+ }
+ }
+
+ *pai = malloc (sizeof (struct addrinfo) + sizeof (struct sockaddr_un)
+ + ((req->ai_flags & AI_CANONNAME)
+ ? (strlen(utsname.nodename) + 1): 0));
+ if (*pai == NULL)
+ return -EAI_MEMORY;
+
+ (*pai)->ai_next = NULL;
+ (*pai)->ai_flags = req->ai_flags;
+ (*pai)->ai_family = AF_LOCAL;
+ (*pai)->ai_socktype = req->ai_socktype ? req->ai_socktype : SOCK_STREAM;
+ (*pai)->ai_protocol = req->ai_protocol;
+ (*pai)->ai_addrlen = sizeof (struct sockaddr_un);
+ (*pai)->ai_addr = (void *) (*pai) + sizeof (struct addrinfo);
+
+#if SALEN
+ ((struct sockaddr_un *) (*pai)->ai_addr)->sun_len =
+ sizeof (struct sockaddr_un);
+#endif /* SALEN */
+
+ ((struct sockaddr_un *)(*pai)->ai_addr)->sun_family = AF_LOCAL;
+ memset(((struct sockaddr_un *)(*pai)->ai_addr)->sun_path, 0, UNIX_PATH_MAX);
+
+ if (service)
+ {
+ struct sockaddr_un *sunp = (struct sockaddr_un *) (*pai)->ai_addr;
+
+ if (strchr (service->name, '/') != NULL)
+ {
+ if (strlen (service->name) >= sizeof (sunp->sun_path))
+ return GAIH_OKIFUNSPEC | -EAI_SERVICE;
+
+ strcpy (sunp->sun_path, service->name);
+ }
+ else
+ {
+ if (strlen (P_tmpdir "/") + 1 + strlen (service->name) >=
+ sizeof (sunp->sun_path))
+ return GAIH_OKIFUNSPEC | -EAI_SERVICE;
-static int str_isnumber(const char *);
-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 **);
-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);
-static int addrconfig(struct addrinfo *);
-#ifdef INET6
-static int ip6_str2scopeid(char *, struct sockaddr_in6 *);
-#endif
+ __stpcpy (__stpcpy (sunp->sun_path, P_tmpdir "/"), service->name);
+ }
+ }
+ else
+ {
+ /* This is a dangerous use of the interface since there is a time
+ window between the test for the file and the actual creation
+ (done by the caller) in which a file with the same name could
+ be created. */
+ char *buf = ((struct sockaddr_un *) (*pai)->ai_addr)->sun_path;
+
+ if (__builtin_expect (__path_search (buf, L_tmpnam, NULL, NULL, 0),
+ 0) != 0
+ || __builtin_expect (__gen_tempname (buf, __GT_NOCREATE), 0) != 0)
+ return -EAI_SYSTEM;
+ }
+
+ if (req->ai_flags & AI_CANONNAME)
+ (*pai)->ai_canonname = strcpy ((char *) *pai + sizeof (struct addrinfo)
+ + sizeof (struct sockaddr_un),
+ utsname.nodename);
+ else
+ (*pai)->ai_canonname = NULL;
+ return 0;
+}
+#endif /* 0 */
-static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
- const struct addrinfo *);
-static int _dns_getaddrinfo(void *, void *, va_list);
-static void _sethtent(void);
-static void _endhtent(void);
-static struct addrinfo *_gethtent(const char *, const struct addrinfo *);
-static int _files_getaddrinfo(void *, void *, va_list);
-#ifdef YP
-static struct addrinfo *_yphostent(char *, const struct addrinfo *);
-static int _yp_getaddrinfo(void *, void *, va_list);
-extern int _yp_check(char **);
-#endif
+static int
+gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp,
+ const struct addrinfo *req, struct gaih_servtuple *st)
+{
+ struct servent *s;
+ size_t tmpbuflen = 1024;
+ struct servent ts;
+ char *tmpbuf;
+ int r;
+
+ do
+ {
+ tmpbuf = alloca (tmpbuflen);
+
+ r = __getservbyname_r (servicename, tp->name, &ts, tmpbuf, tmpbuflen,
+ &s);
+ if (r != 0 || s == NULL)
+ {
+ if (r == ERANGE)
+ tmpbuflen *= 2;
+ else
+ return GAIH_OKIFUNSPEC | -EAI_SERVICE;
+ }
+ }
+ while (r);
-u_int16_t _getshort(const u_char *src);
-
-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 char *ai_errlist[] = {
- "Success",
- "Address family for hostname not supported", /* EAI_ADDRFAMILY */
- "Temporary failure in name resolution", /* EAI_AGAIN */
- "Invalid value for ai_flags", /* EAI_BADFLAGS */
- "Non-recoverable failure in name resolution", /* EAI_FAIL */
- "ai_family not supported", /* EAI_FAMILY */
- "Memory allocation failure", /* EAI_MEMORY */
- "No address associated with hostname", /* EAI_NODATA */
- "hostname nor servname provided, or not known", /* EAI_NONAME */
- "servname not supported for ai_socktype", /* EAI_SERVICE */
- "ai_socktype not supported", /* EAI_SOCKTYPE */
- "System error returned in errno", /* EAI_SYSTEM */
- "Invalid value for hints", /* EAI_BADHINTS */
- "Resolved protocol is unknown", /* EAI_PROTOCOL */
- "Unknown error", /* EAI_MAX */
-};
+ st->next = NULL;
+ st->socktype = tp->socktype;
+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
+ ? req->ai_protocol : tp->protocol);
+ st->port = s->s_port;
-/* 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)))
-
-char *
-gai_strerror(ecode)
- int ecode;
-{
- if (ecode < 0 || ecode > EAI_MAX)
- ecode = EAI_MAX;
- return ai_errlist[ecode];
+ return 0;
}
-void
-freeaddrinfo(ai)
- struct addrinfo *ai;
-{
- struct addrinfo *next;
-
- do {
- next = ai->ai_next;
- if (ai->ai_canonname)
- free(ai->ai_canonname);
- /* no need to free(ai->ai_addr) */
- free(ai);
- ai = next;
- } while (ai);
-}
+#define gethosts(_family, _type) \
+ { \
+ int i; \
+ int herrno; \
+ struct hostent th; \
+ struct hostent *h; \
+ char *localcanon = NULL; \
+ no_data = 0; \
+ while (1) { \
+ rc = 0; \
+ status = DL_CALL_FCT (fct, (name, _family, &th, tmpbuf, tmpbuflen, \
+ &rc, &herrno, NULL, &localcanon)); \
+ if (rc != ERANGE || herrno != NETDB_INTERNAL) \
+ break; \
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); \
+ } \
+ if (status == NSS_STATUS_SUCCESS && rc == 0) \
+ h = &th; \
+ else \
+ h = NULL; \
+ if (rc != 0) \
+ { \
+ if (herrno == NETDB_INTERNAL) \
+ { \
+ h_errno = (herrno); \
+ return -EAI_SYSTEM; \
+ } \
+ if (herrno == TRY_AGAIN) \
+ no_data = EAI_AGAIN; \
+ else \
+ no_data = herrno == NO_DATA; \
+ } \
+ else if (h != NULL) \
+ { \
+ for (i = 0; h->h_addr_list[i]; i++) \
+ { \
+ if (*pat == NULL) \
+ { \
+ *pat = alloca (sizeof (struct gaih_addrtuple)); \
+ (*pat)->scopeid = 0; \
+ } \
+ uint32_t *addr = (*pat)->addr; \
+ (*pat)->next = NULL; \
+ if (i == 0) \
+ { \
+ (*pat)->name = alloca (strlen (h->h_name) + 1); \
+ strcpy ((*pat)->name, h->h_name); \
+ } \
+ else \
+ (*pat)->name = NULL; \
+ if (_family == AF_INET && req->ai_family == AF_INET6) \
+ { \
+ (*pat)->family = AF_INET6; \
+ addr[3] = *(uint32_t *) h->h_addr_list[i]; \
+ addr[2] = htonl (0xffff); \
+ addr[1] = 0; \
+ addr[0] = 0; \
+ } \
+ else \
+ { \
+ (*pat)->family = _family; \
+ memcpy (addr, h->h_addr_list[i], sizeof(_type)); \
+ } \
+ pat = &((*pat)->next); \
+ } \
+ \
+ if (localcanon != NULL && canon == NULL) \
+ { \
+ canon = alloca (strlen (localcanon) + 1); \
+ strcpy (canon, localcanon); \
+ } \
+ \
+ if (_family == AF_INET6 && i > 0) \
+ got_ipv6 = true; \
+ } \
+ }
+
+
+typedef enum nss_status (*nss_gethostbyname3_r)
+ (const char *name, int af, struct hostent *host,
+ char *buffer, size_t buflen, int *errnop,
+ int *h_errnop, int32_t *ttlp, char **canonp);
+typedef enum nss_status (*nss_getcanonname_r)
+ (const char *name, char *buffer, size_t buflen, char **result,
+ int *errnop, int *h_errnop);
+extern service_user *__nss_hosts_database attribute_hidden;
static int
-str_isnumber(p)
- const char *p;
+gaih_inet (const char *name, const struct gaih_service *service,
+ const struct addrinfo *req, struct addrinfo **pai)
{
- char *ep;
-
- if (*p == '\0')
- return NO;
- ep = NULL;
- (void)strtoul(p, &ep, 10);
- if (ep && *ep == '\0')
- return YES;
- else
- return NO;
-}
+ const struct gaih_typeproto *tp = gaih_inet_typeproto;
+ struct gaih_servtuple *st = (struct gaih_servtuple *) &nullserv;
+ struct gaih_addrtuple *at = NULL;
+ int rc;
+ bool got_ipv6 = false;
+ const char *canon = NULL;
+ const char *orig_name = name;
+
+ if (req->ai_protocol || req->ai_socktype)
+ {
+ ++tp;
+
+ while (tp->name[0]
+ && ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
+ || (req->ai_protocol != 0
+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
+ && req->ai_protocol != tp->protocol)))
+ ++tp;
+
+ if (! tp->name[0])
+ {
+ if (req->ai_socktype)
+ return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
+ else
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+ }
+ }
+
+ if (service != NULL)
+ {
+ if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+
+ if (service->num < 0)
+ {
+ if (tp->name[0])
+ {
+ st = (struct gaih_servtuple *)
+ alloca (sizeof (struct gaih_servtuple));
+
+ if ((rc = gaih_inet_serv (service->name, tp, req, st)))
+ return rc;
+ }
+ else
+ {
+ struct gaih_servtuple **pst = &st;
+ for (tp++; tp->name[0]; tp++)
+ {
+ struct gaih_servtuple *newp;
+
+ if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
+ continue;
+
+ if (req->ai_socktype != 0
+ && req->ai_socktype != tp->socktype)
+ continue;
+ if (req->ai_protocol != 0
+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
+ && req->ai_protocol != tp->protocol)
+ continue;
+
+ newp = (struct gaih_servtuple *)
+ alloca (sizeof (struct gaih_servtuple));
+
+ if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
+ {
+ if (rc & GAIH_OKIFUNSPEC)
+ continue;
+ return rc;
+ }
-int
-getaddrinfo(hostname, servname, hints, res)
- const char *hostname, *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)
- 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);
- }
- }
+ *pst = newp;
+ pst = &(newp->next);
}
+ if (st == (struct gaih_servtuple *) &nullserv)
+ return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
+ }
}
-
- /*
- * post-2553: AI_ALL and AI_V4MAPPED are effective only against
- * AF_INET6 query. They needs to be ignored if specified in other
- * occassions.
- */
- switch (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) {
- case AI_V4MAPPED:
- case AI_ALL | AI_V4MAPPED:
- if (pai->ai_family != AF_INET6)
- pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED);
- break;
- case AI_ALL:
-#if 1
- /* illegal */
- ERR(EAI_BADFLAGS);
-#else
- pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED);
-#endif
- break;
+ else
+ {
+ if (req->ai_socktype || req->ai_protocol)
+ {
+ st = alloca (sizeof (struct gaih_servtuple));
+ st->next = NULL;
+ st->socktype = tp->socktype;
+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
+ ? req->ai_protocol : tp->protocol);
+ st->port = htons (service->num);
+ }
+ else
+ {
+ /* Neither socket type nor protocol is set. Return all
+ socket types we know about. */
+ struct gaih_servtuple **lastp = &st;
+ for (tp = gaih_inet_typeproto + 1; tp->name[0]; ++tp)
+ if ((tp->protoflag & GAI_PROTO_NOSERVICE) == 0)
+ {
+ struct gaih_servtuple *newp;
+
+ newp = alloca (sizeof (struct gaih_servtuple));
+ newp->next = NULL;
+ newp->socktype = tp->socktype;
+ newp->protocol = tp->protocol;
+ newp->port = htons (service->num);
+
+ *lastp = newp;
+ lastp = &newp->next;
+ }
+ }
+ }
+ }
+ else if (req->ai_socktype || req->ai_protocol)
+ {
+ st = alloca (sizeof (struct gaih_servtuple));
+ st->next = NULL;
+ st->socktype = tp->socktype;
+ st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
+ ? req->ai_protocol : tp->protocol);
+ st->port = 0;
+ }
+ else
+ {
+ /* Neither socket type nor protocol is set. Return all socket types
+ we know about. */
+ struct gaih_servtuple **lastp = &st;
+ for (++tp; tp->name[0]; ++tp)
+ {
+ struct gaih_servtuple *newp;
+
+ newp = alloca (sizeof (struct gaih_servtuple));
+ newp->next = NULL;
+ newp->socktype = tp->socktype;
+ newp->protocol = tp->protocol;
+ newp->port = 0;
+
+ *lastp = newp;
+ lastp = &newp->next;
+ }
+ }
+
+ if (name != NULL)
+ {
+ at = alloca (sizeof (struct gaih_addrtuple));
+
+ at->family = AF_UNSPEC;
+ at->scopeid = 0;
+ at->next = NULL;
+
+#ifdef HAVE_LIBIDN
+ if (req->ai_flags & AI_IDN)
+ {
+ int idn_flags = 0;
+ if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED)
+ idn_flags |= IDNA_ALLOW_UNASSIGNED;
+ if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES)
+ idn_flags |= IDNA_USE_STD3_ASCII_RULES;
+
+ char *p = NULL;
+ rc = __idna_to_ascii_lz (name, &p, idn_flags);
+ if (rc != IDNA_SUCCESS)
+ {
+ if (rc == IDNA_MALLOC_ERROR)
+ return -EAI_MEMORY;
+ if (rc == IDNA_DLOPEN_ERROR)
+ return -EAI_SYSTEM;
+ return -EAI_IDN_ENCODE;
+ }
+ /* In case the output string is the same as the input string
+ no new string has been allocated. */
+ if (p != name)
+ {
+ name = alloca (strlen (p) + 1);
+ strcpy (name, p);
+ free (p);
+ }
}
-
- /*
- * 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;
+ if (inet_aton (name, (struct in_addr *) at->addr) != 0)
+ {
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
+ at->family = AF_INET;
+ else if (req->ai_family == AF_INET6 && req->ai_flags & AI_V4MAPPED)
+ {
+ at->addr[3] = at->addr[0];
+ at->addr[2] = htonl (0xffff);
+ at->addr[1] = 0;
+ at->addr[0] = 0;
+ at->family = AF_INET6;
+ }
+ else
+ return -EAI_ADDRFAMILY;
+
+ dupname:
+ if (req->ai_flags & AI_CANONNAME)
+ {
+ canon = strdup (name);
+ if (canon == NULL)
+ return -EAI_MEMORY;
+ }
}
- 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 (at->family == AF_UNSPEC)
+ {
+ char *scope_delim;
+ char *namebuf = alloca (strlen (name) + 1);
+ strcpy (namebuf, name);
+
+ scope_delim = strchr (namebuf, SCOPE_DELIMITER);
+ if (scope_delim != NULL)
+ *scope_delim = '\0';
+
+ if (inet_pton (AF_INET6, namebuf, at->addr) > 0)
+ {
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
+ at->family = AF_INET6;
+ else if (req->ai_family == AF_INET
+ && IN6_IS_ADDR_V4MAPPED ((struct in6_addr *)at->addr))
+ {
+ at->addr[0] = at->addr[3];
+ at->family = AF_INET;
+ }
+ else
+ return -EAI_ADDRFAMILY;
+
+ if (scope_delim != NULL)
+ {
+ int try_numericscope = 0;
+ if (IN6_IS_ADDR_LINKLOCAL ((struct in6_addr *)at->addr)
+ || IN6_IS_ADDR_MC_LINKLOCAL ((struct in6_addr *)at->addr))
+ {
+ at->scopeid = if_nametoindex (scope_delim + 1);
+ if (at->scopeid == 0)
+ try_numericscope = 1;
+ }
+ else
+ try_numericscope = 1;
+
+ if (try_numericscope != 0)
+ {
+ char *end;
+ assert (sizeof (uint32_t) <= sizeof (unsigned long));
+ at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end,
+ 10);
+ if (*end != '\0')
+ return GAIH_OKIFUNSPEC | -EAI_NONAME;
+ }
+ }
- 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;
+ goto dupname;
+ }
+ }
- 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 (at->family == AF_UNSPEC && (req->ai_flags & AI_NUMERICHOST) == 0)
+ {
+ struct gaih_addrtuple **pat = &at;
+ int no_data = 0;
+ int no_inet6_data = 0;
+ service_user *nip = NULL;
+ enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
+ enum nss_status status = NSS_STATUS_UNAVAIL;
+ int no_more;
+ int old_res_options;
+
+ /* If we do not have to look for IPv4 and IPv6 together, use
+ the simple, old functions. */
+ if (req->ai_family == AF_INET || req->ai_family == AF_INET6)
+ {
+ int family = req->ai_family;
+ size_t tmpbuflen = 512;
+ char *tmpbuf = alloca (tmpbuflen);
+ int rc;
+ struct hostent th;
+ struct hostent *h;
+ int herrno;
+
+ simple_again:
+ while (1)
+ {
+ rc = __gethostbyname2_r (name, family, &th, tmpbuf,
+ tmpbuflen, &h, &herrno);
+ if (rc != ERANGE || herrno != NETDB_INTERNAL)
+ break;
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+ }
- if (hostname == NULL)
- error = explore_null(pai, servname, &cur->ai_next);
- else
- error = explore_numeric_scope(pai, hostname, servname, &cur->ai_next);
+ if (rc == 0)
+ {
+ if (h == NULL)
+ {
+ if (req->ai_family == AF_INET6
+ && (req->ai_flags & AI_V4MAPPED)
+ && family == AF_INET6)
+ {
+ /* Try again, this time looking for IPv4
+ addresses. */
+ family = AF_INET;
+ goto simple_again;
+ }
+ }
+ else
+ {
+ /* We found data, now convert it into the list. */
+ int i = 0;
+ for (i = 0; h->h_addr_list[i]; ++i)
+ {
+ if (*pat == NULL)
+ {
+ *pat = alloca (sizeof (struct gaih_addrtuple));
+ (*pat)->scopeid = 0;
+ }
+ (*pat)->next = NULL;
+ (*pat)->family = req->ai_family;
+ if (family == req->ai_family)
+ memcpy ((*pat)->addr, h->h_addr_list[i],
+ h->h_length);
+ else
+ {
+ int32_t *addr = (uint32_t *) (*pat)->addr;
+ addr[3] = *(uint32_t *) h->h_addr_list[i];
+ addr[2] = htonl (0xffff);
+ addr[1] = 0;
+ addr[0] = 0;
+ }
+ pat = &((*pat)->next);
+ }
+ }
+ }
+ else
+ {
+ if (herrno == NETDB_INTERNAL)
+ {
+ h_errno = (herrno);
+ return -EAI_SYSTEM;
+ }
+ if (herrno == TRY_AGAIN)
+ {
+ return -EAI_AGAIN;
+ }
+ /* We made requests but they turned out no data.
+ The name is known, though. */
+ return (GAIH_OKIFUNSPEC | -EAI_NODATA);
+ }
- if (error)
- goto free;
+ goto process_list;
+ }
+
+#ifdef USE_NSCD
+ if (__nss_not_use_nscd_hosts > 0
+ && ++__nss_not_use_nscd_hosts > NSS_NSCD_RETRY)
+ __nss_not_use_nscd_hosts = 0;
+
+ if (!__nss_not_use_nscd_hosts)
+ {
+ /* Try to use nscd. */
+ struct nscd_ai_result *air = NULL;
+ int herrno;
+ int err = __nscd_getai (name, &air, &herrno);
+ if (air != NULL)
+ {
+ /* Transform into gaih_addrtuple list. */
+ bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
+ char *addrs = air->addrs;
+
+ for (int i = 0; i < air->naddrs; ++i)
+ {
+ socklen_t size = (air->family[i] == AF_INET
+ ? INADDRSZ : IN6ADDRSZ);
+ if (*pat == NULL)
+ {
+ *pat = alloca (sizeof (struct gaih_addrtuple));
+ (*pat)->scopeid = 0;
+ }
+ uint32_t *pataddr = (*pat)->addr;
+ (*pat)->next = NULL;
+ if (added_canon || air->canon == NULL)
+ (*pat)->name = NULL;
+ else {
+ canon = (*pat)->name = alloca (strlen (air->canon) + 1);
+ strcpy (canon, air->canon);
+ }
+
+ if (air->family[i] == AF_INET
+ && req->ai_family == AF_INET6
+ && (req->ai_flags & AI_V4MAPPED))
+ {
+ (*pat)->family = AF_INET6;
+ pataddr[3] = *(uint32_t *) addrs;
+ pataddr[2] = htonl (0xffff);
+ pataddr[1] = 0;
+ pataddr[0] = 0;
+ pat = &((*pat)->next);
+ added_canon = true;
+ }
+ else if (req->ai_family == AF_UNSPEC
+ || air->family[i] == req->ai_family)
+ {
+ (*pat)->family = air->family[i];
+ memcpy (pataddr, addrs, size);
+ pat = &((*pat)->next);
+ added_canon = true;
+ if (air->family[i] == AF_INET6)
+ got_ipv6 = true;
+ }
+ addrs += size;
+ }
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
+ free (air);
- /*
- * XXX
- * If numreic 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 (pai->ai_flags & AI_NUMERICHOST)
- ERR(EAI_NONAME);
- if (hostname == NULL)
- ERR(EAI_NODATA);
-
- if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(&ai0))
- ERR(EAI_FAIL);
-
- /*
- * hostname as alphabetical name.
- * we would like to prefer AF_INET6 than AF_INET, so we'll make a
- * 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 (at->family == AF_UNSPEC)
+ return (GAIH_OKIFUNSPEC | -EAI_NONAME);
- if (!MATCH(pai->ai_socktype, ex->e_socktype,
- WILD_SOCKTYPE(ex))) {
- continue;
+ goto process_list;
}
- if (!MATCH(pai->ai_protocol, ex->e_protocol,
- WILD_PROTOCOL(ex))) {
- continue;
+ else if (err != 0 && __nss_not_use_nscd_hosts == 0)
+ {
+ if (herrno == NETDB_INTERNAL && errno == ENOMEM)
+ return -EAI_MEMORY;
+ if (herrno == TRY_AGAIN)
+ return -EAI_AGAIN;
+ return -EAI_SYSTEM;
}
+ }
+#endif
- 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;
- }
+ if (__nss_hosts_database != NULL)
+ {
+ no_more = 0;
+ nip = __nss_hosts_database;
+ }
+ else
+ no_more = __nss_database_lookup ("hosts", NULL,
+ "dns [!UNAVAIL=return] files",
+ &nip);
+
+ if (__res_maybe_init (&_res, 0) == -1)
+ no_more = 1;
+
+ /* If we are looking for both IPv4 and IPv6 address we don't
+ want the lookup functions to automatically promote IPv4
+ addresses to IPv6 addresses. Currently this is decided
+ by setting the RES_USE_INET6 bit in _res.options. */
+ old_res_options = _res.options;
+ _res.options &= ~RES_USE_INET6;
+
+ size_t tmpbuflen = 512;
+ char *tmpbuf = alloca (tmpbuflen);
+
+ while (!no_more)
+ {
+ nss_gethostbyname3_r fct = NULL;
+ if (req->ai_flags & AI_CANONNAME)
+ /* No need to use this function if we do not look for
+ the canonical name. The function does not exist in
+ all NSS modules and therefore the lookup would
+ often fail. */
+ fct = __nss_lookup_function (nip, "gethostbyname3_r");
+ if (fct == NULL)
+ /* We are cheating here. The gethostbyname2_r function does
+ not have the same interface as gethostbyname3_r but the
+ extra arguments the latter takes are added at the end.
+ So the gethostbyname2_r code will just ignore them. */
+ fct = __nss_lookup_function (nip, "gethostbyname2_r");
+
+ if (fct != NULL)
+ {
+ if (req->ai_family == AF_INET6
+ || req->ai_family == AF_UNSPEC)
+ {
+ gethosts (AF_INET6, struct in6_addr);
+ no_inet6_data = no_data;
+ inet6_status = status;
+ }
+ if (req->ai_family == AF_INET
+ || req->ai_family == AF_UNSPEC
+ || (req->ai_family == AF_INET6
+ && (req->ai_flags & AI_V4MAPPED)
+ /* Avoid generating the mapped addresses if we
+ know we are not going to need them. */
+ && ((req->ai_flags & AI_ALL) || !got_ipv6)))
+ {
+ gethosts (AF_INET, struct in_addr);
+
+ if (req->ai_family == AF_INET)
+ {
+ no_inet6_data = no_data;
+ inet6_status = status;
+ }
+ }
+
+ /* If we found one address for AF_INET or AF_INET6,
+ don't continue the search. */
+ if (inet6_status == NSS_STATUS_SUCCESS
+ || status == NSS_STATUS_SUCCESS)
+ {
+ if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL)
+ {
+ /* If we need the canonical name, get it
+ from the same service as the result. */
+ nss_getcanonname_r cfct;
+ int herrno;
+
+ cfct = __nss_lookup_function (nip, "getcanonname_r");
+ if (cfct != NULL)
+ {
+ const size_t max_fqdn_len = 256;
+ char *buf = alloca (max_fqdn_len);
+ char *s;
+
+ if (DL_CALL_FCT (cfct, (at->name ?: name, buf,
+ max_fqdn_len, &s, &rc,
+ &herrno))
+ == NSS_STATUS_SUCCESS)
+ canon = s;
+ else
+ /* Set to name now to avoid using
+ gethostbyaddr. */
+ canon = name;
+ }
+ }
- /* XXX */
- if (sentinel.ai_next)
- error = 0;
-
- if (error)
- goto free;
- 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;
-}
+ break;
+ }
-/*
- * FQDN hostname, DNS lookup
- */
-static int
-explore_fqdn(pai, hostname, servname, res)
- const struct addrinfo *pai;
- const char *hostname;
- const char *servname;
- struct addrinfo **res;
-{
- struct addrinfo *result;
- struct addrinfo *cur;
- int error = 0;
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_files_getaddrinfo, NULL)
- { NSSRC_DNS, _dns_getaddrinfo, NULL }, /* force -DHESIOD */
- NS_NIS_CB(_yp_getaddrinfo, NULL)
- { 0 }
- };
-
- result = NULL;
-
- /*
- * if the servname does not match socktype/protocol, ignore it.
- */
- if (get_portmatch(pai, servname) != 0)
- return 0;
-
- switch (nsdispatch(&result, dtab, NSDB_HOSTS, "getaddrinfo",
- default_dns_files, hostname, pai)) {
- case NS_TRYAGAIN:
- error = EAI_AGAIN;
- goto free;
- case NS_UNAVAIL:
- error = EAI_FAIL;
- goto free;
- case NS_NOTFOUND:
- error = EAI_NODATA;
- goto free;
- case NS_SUCCESS:
- error = 0;
- for (cur = result; cur; cur = cur->ai_next) {
- GET_PORT(cur, servname);
- /* canonname should be filled already */
+ /* We can have different states for AF_INET and
+ AF_INET6. Try to find a useful one for both. */
+ if (inet6_status == NSS_STATUS_TRYAGAIN)
+ status = NSS_STATUS_TRYAGAIN;
+ else if (status == NSS_STATUS_UNAVAIL &&
+ inet6_status != NSS_STATUS_UNAVAIL)
+ status = inet6_status;
}
+
+ if (nss_next_action (nip, status) == NSS_ACTION_RETURN)
break;
- }
- *res = result;
+ if (nip->next == NULL)
+ no_more = -1;
+ else
+ nip = nip->next;
+ }
- return 0;
+ _res.options = old_res_options;
-free:
- if (result)
- freeaddrinfo(result);
- return error;
-}
+ if (no_data != 0 && no_inet6_data != 0)
+ {
+ /* If both requests timed out report this. */
+ if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
+ return -EAI_AGAIN;
-/*
- * hostname == NULL.
- * passive socket -> anyaddr (0.0.0.0 or ::)
- * non-passive socket -> localhost (127.0.0.1 or ::1)
- */
-static int
-explore_null(pai, servname, res)
- 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");
- */
- GET_PORT(cur->ai_next, servname);
- } else {
- GET_AI(cur->ai_next, afd, afd->a_loopback);
- /* xxx meaningless?
- * GET_CANONNAME(cur->ai_next, "localhost");
- */
- GET_PORT(cur->ai_next, servname);
+ /* We made requests but they turned out no data. The name
+ is known, though. */
+ return (GAIH_OKIFUNSPEC | -EAI_NODATA);
+ }
}
- 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(pai, hostname, servname, res)
- const struct addrinfo *pai;
- const char *hostname;
- const char *servname;
- struct addrinfo **res;
-{
- 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 1 /*X/Open spec*/
- case AF_INET:
- if (inet_aton(hostname, (struct in_addr *)pton) == 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);
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- } else
- ERR(EAI_FAMILY); /*xxx*/
- }
- break;
-#endif
- default:
- if (inet_pton(afd->a_af, hostname, pton) == 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);
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- } else
- ERR(EAI_FAMILY); /*xxx*/
- }
- break;
+ process_list:
+ if (at->family == AF_UNSPEC)
+ return (GAIH_OKIFUNSPEC | -EAI_NONAME);
+ }
+ else
+ {
+ struct gaih_addrtuple *atr;
+ atr = at = alloca (sizeof (struct gaih_addrtuple));
+ memset (at, '\0', sizeof (struct gaih_addrtuple));
+
+ if (req->ai_family == AF_UNSPEC)
+ {
+ at->next = alloca (sizeof (struct gaih_addrtuple));
+ memset (at->next, '\0', sizeof (struct gaih_addrtuple));
}
- *res = sentinel.ai_next;
- return 0;
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
+ {
+ at->family = AF_INET6;
+ if ((req->ai_flags & AI_PASSIVE) == 0)
+ memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr));
+ atr = at->next;
+ }
-free:
-bad:
- if (sentinel.ai_next)
- freeaddrinfo(sentinel.ai_next);
- return error;
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
+ {
+ atr->family = AF_INET;
+ if ((req->ai_flags & AI_PASSIVE) == 0)
+ atr->addr[0] = htonl (INADDR_LOOPBACK);
+ }
+ }
+
+ if (pai == NULL)
+ return 0;
+
+ {
+ struct gaih_servtuple *st2;
+ struct gaih_addrtuple *at2 = at;
+ size_t socklen;
+ sa_family_t family;
+
+ /*
+ buffer is the size of an unformatted IPv6 address in printable format.
+ */
+ while (at2 != NULL)
+ {
+ /* Only the first entry gets the canonical name. */
+ if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0)
+ {
+ if (canon == NULL)
+ {
+ struct hostent *h = NULL;
+ int herrno;
+ struct hostent th;
+ size_t tmpbuflen = 512;
+ char *tmpbuf = NULL;
+
+ do
+ {
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen, tmpbuflen * 2);
+ rc = __gethostbyaddr_r (at2->addr,
+ ((at2->family == AF_INET6)
+ ? sizeof (struct in6_addr)
+ : sizeof (struct in_addr)),
+ at2->family, &th, tmpbuf,
+ tmpbuflen, &h, &herrno);
+ }
+ while (rc == ERANGE && herrno == NETDB_INTERNAL);
+
+ if (rc != 0 && herrno == NETDB_INTERNAL)
+ {
+ h_errno = (herrno);
+ return -EAI_SYSTEM;
+ }
+
+ if (h != NULL)
+ canon = h->h_name;
+ else
+ {
+ assert (orig_name != NULL);
+ /* If the canonical name cannot be determined, use
+ the passed in string. */
+ canon = orig_name;
+ }
+ }
+
+#ifdef HAVE_LIBIDN
+ if (req->ai_flags & AI_CANONIDN)
+ {
+ int idn_flags = 0;
+ if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED)
+ idn_flags |= IDNA_ALLOW_UNASSIGNED;
+ if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES)
+ idn_flags |= IDNA_USE_STD3_ASCII_RULES;
+
+ char *out;
+ int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags);
+ if (rc != IDNA_SUCCESS)
+ {
+ if (rc == IDNA_MALLOC_ERROR)
+ return -EAI_MEMORY;
+ if (rc == IDNA_DLOPEN_ERROR)
+ return -EAI_SYSTEM;
+ return -EAI_IDN_ENCODE;
+ }
+ /* In case the output string is the same as the input
+ string no new string has been allocated. Otherwise
+ make a copy. */
+ if (out == canon)
+ goto make_copy;
+ }
+ else
+#endif
+ {
+#ifdef HAVE_LIBIDN
+ make_copy:
+#endif
+ canon = strdup (canon);
+ if (canon == NULL)
+ return -EAI_MEMORY;
+ }
+ }
+
+ if (at2->family == AF_INET6)
+ {
+ family = AF_INET6;
+ socklen = sizeof (struct sockaddr_in6);
+
+ /* If we looked up IPv4 mapped address discard them here if
+ the caller isn't interested in all address and we have
+ found at least one IPv6 address. */
+ if (got_ipv6
+ && (req->ai_flags & (AI_V4MAPPED|AI_ALL)) == AI_V4MAPPED
+ && IN6_IS_ADDR_V4MAPPED ((struct in6_addr *)at2->addr))
+ goto ignore;
+ }
+ else
+ {
+ family = AF_INET;
+ socklen = sizeof (struct sockaddr_in);
+ }
+
+ for (st2 = st; st2 != NULL; st2 = st2->next)
+ {
+ struct addrinfo *ai;
+ ai = *pai = malloc (sizeof (struct addrinfo) + socklen);
+ if (ai == NULL)
+ return -EAI_MEMORY;
+
+ ai->ai_flags = req->ai_flags;
+ ai->ai_family = family;
+ ai->ai_socktype = st2->socktype;
+ ai->ai_protocol = st2->protocol;
+ ai->ai_addrlen = socklen;
+ ai->ai_addr = (void *) (ai + 1);
+
+ /* We only add the canonical name once. */
+ ai->ai_canonname = (char *) canon;
+ canon = NULL;
+
+#if SALEN
+ ai->ai_addr->sa_len = socklen;
+#endif /* SALEN */
+ ai->ai_addr->sa_family = family;
+
+ if (family == AF_INET6)
+ {
+ struct sockaddr_in6 *sin6p =
+ (struct sockaddr_in6 *) ai->ai_addr;
+
+ sin6p->sin6_port = st2->port;
+ sin6p->sin6_flowinfo = 0;
+ memcpy (&sin6p->sin6_addr,
+ at2->addr, sizeof (struct in6_addr));
+ sin6p->sin6_scope_id = at2->scopeid;
+ }
+ else
+ {
+ struct sockaddr_in *sinp =
+ (struct sockaddr_in *) ai->ai_addr;
+ sinp->sin_port = st2->port;
+ memcpy (&sinp->sin_addr,
+ at2->addr, sizeof (struct in_addr));
+ memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero));
+ }
+
+ pai = &(ai->ai_next);
+ }
+ *pai = NULL;
+
+ ignore:
+ at2 = at2->next;
+ }
+ }
+ return 0;
}
-/*
- * numeric hostname with scope
- */
-static int
-explore_numeric_scope(pai, hostname, servname, res)
- 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);
-#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);
-
- cp = strchr(hostname, SCOPE_DELIMITER);
- if (cp == NULL)
- return explore_numeric(pai, hostname, servname, res);
-
- /*
- * Handle special case of <scoped_address><delimiter><scope id>
- */
- 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);
- if (error == 0) {
- int 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 ((scopeid = ip6_str2scopeid(scope, sin6)) == -1) {
- free(hostname2);
- return(EAI_NODATA); /* XXX: is return OK? */
- }
- sin6->sin6_scope_id = scopeid;
- }
- }
+static struct gaih gaih[] =
+ {
+ { PF_INET6, gaih_inet },
+ { PF_INET, gaih_inet },
+#if 0
+ { PF_LOCAL, gaih_local },
+#endif
+ { PF_UNSPEC, NULL }
+ };
- free(hostname2);
+struct sort_result
+{
+ struct addrinfo *dest_addr;
+ struct sockaddr_storage source_addr;
+ uint8_t source_addr_len;
+ bool got_source_addr;
+};
- return error;
-#endif
-}
static int
-get_canonname(pai, ai, str)
- const struct addrinfo *pai;
- struct addrinfo *ai;
- const char *str;
+get_scope (const struct sockaddr_storage *ss)
{
- if ((pai->ai_flags & AI_CANONNAME) != 0) {
- ai->ai_canonname = (char *)malloc(strlen(str) + 1);
- if (ai->ai_canonname == NULL)
- return EAI_MEMORY;
- strcpy(ai->ai_canonname, str);
+ int scope;
+ if (ss->ss_family == PF_INET6)
+ {
+ const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) ss;
+
+ if (! IN6_IS_ADDR_MULTICAST (&in6->sin6_addr))
+ {
+ if (IN6_IS_ADDR_LINKLOCAL (&in6->sin6_addr))
+ scope = 2;
+ else if (IN6_IS_ADDR_SITELOCAL (&in6->sin6_addr))
+ scope = 5;
+ else
+ /* XXX Is this the correct default behavior? */
+ scope = 14;
}
- return 0;
+ else
+ scope = in6->sin6_addr.s6_addr[1] & 0xf;
+ }
+ else if (ss->ss_family == PF_INET)
+ {
+ const struct sockaddr_in *in = (const struct sockaddr_in *) ss;
+ const uint8_t *addr = (const uint8_t *) &in->sin_addr;
+
+ /* RFC 3484 specifies how to map IPv6 addresses to scopes.
+ 169.254/16 and 127/8 are link-local. */
+ if ((addr[0] == 169 && addr[1] == 254) || addr[0] == 127)
+ scope = 2;
+ else if (addr[0] == 10 || (addr[0] == 172 && addr[1] == 16)
+ || (addr[0] == 192 && addr[1] == 168))
+ scope = 5;
+ else
+ scope = 14;
+ }
+ else
+ /* XXX What is a good default? */
+ scope = 15;
+
+ return scope;
}
-static struct addrinfo *
-get_ai(pai, afd, addr)
- const struct addrinfo *pai;
- const struct afd *afd;
- const char *addr;
-{
- char *p;
- struct addrinfo *ai;
-#ifdef FAITH
- struct in6_addr faith_prefix;
- char *fp_str;
- int translate = 0;
-#endif
-
-#ifdef FAITH
- /*
- * Transfrom an IPv4 addr into a special IPv6 addr format for
- * IPv6->IPv4 translation gateway. (only TCP is supported now)
- *
- * +-----------------------------------+------------+
- * | faith prefix part (12 bytes) | embedded |
- * | | IPv4 addr part (4 bytes)
- * +-----------------------------------+------------+
- *
- * faith prefix part is specified as ascii IPv6 addr format
- * in environmental variable GAI.
- * For FAITH to work correctly, routing to faith prefix must be
- * setup toward a machine where a FAITH daemon operates.
- * Also, the machine must enable some mechanizm
- * (e.g. faith interface hack) to divert those packet with
- * faith prefixed destination addr to user-land FAITH daemon.
- */
- fp_str = getenv("GAI");
- if (fp_str && inet_pton(AF_INET6, fp_str, &faith_prefix) == 1 &&
- afd->a_af == AF_INET && pai->ai_socktype == SOCK_STREAM) {
- u_int32_t v4a;
- u_int8_t v4a_top;
-
- memcpy(&v4a, addr, sizeof v4a);
- v4a_top = v4a >> IN_CLASSA_NSHIFT;
- if (!IN_MULTICAST(v4a) && !IN_EXPERIMENTAL(v4a) &&
- v4a_top != 0 && v4a != IN_LOOPBACKNET) {
- afd = &afdl[N_INET6];
- memcpy(&faith_prefix.s6_addr[12], addr,
- sizeof(struct in_addr));
- translate = 1;
- }
- }
-#endif
-
- 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_addrlen = afd->a_socklen;
- ai->ai_addr->sa_family = ai->ai_family = afd->a_af;
- p = (char *)(void *)(ai->ai_addr);
-#ifdef FAITH
- if (translate == 1)
- memcpy(p + afd->a_off, &faith_prefix, (size_t)afd->a_addrlen);
- else
-#endif
- memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
- return ai;
-}
-static int
-get_portmatch(ai, servname)
- const struct addrinfo *ai;
- const char *servname;
+/* XXX The system administrator should be able to install other
+ tables. We need to make this configurable. The problem is that
+ the kernel is also involved since it needs the same table. */
+static const struct prefixlist
{
+ struct in6_addr prefix;
+ unsigned int bits;
+ int val;
+} default_labels[] =
+ {
+ /* See RFC 3484 for the details. */
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0001 } } },
+ 128, 0 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 16, 2 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 96, 3 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0xffff, 0x0000, 0x0000 } } },
+ 96, 4 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 0, 1 }
+ };
+
+
+static const struct prefixlist default_precedence[] =
+ {
+ /* See RFC 3484 for the details. */
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0001 } } },
+ 128, 50 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 16, 30 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 96, 20 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0xffff, 0x0000, 0x0000 } } },
+ 96, 10 },
+ { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000 } } },
+ 0, 40 }
+ };
- /* 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(ai, servname, matchonly)
- struct addrinfo *ai;
- const char *servname;
- int matchonly;
+match_prefix (const struct sockaddr_storage *ss, const struct prefixlist *list,
+ int default_val)
{
- const char *proto;
- struct servent *sp;
- 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;
+ int idx;
+ struct sockaddr_in6 in6_mem;
+ const struct sockaddr_in6 *in6;
+
+ if (ss->ss_family == PF_INET6)
+ in6 = (const struct sockaddr_in6 *) ss;
+ else if (ss->ss_family == PF_INET)
+ {
+ const struct sockaddr_in *in = (const struct sockaddr_in *) ss;
+
+ /* Convert to IPv6 address. */
+ in6_mem.sin6_family = PF_INET6;
+ in6_mem.sin6_port = in->sin_port;
+ in6_mem.sin6_flowinfo = 0;
+ if (in->sin_addr.s_addr == htonl (0x7f000001))
+ in6_mem.sin6_addr = (struct in6_addr) IN6ADDR_LOOPBACK_INIT;
+ else
+ {
+ /* Construct a V4-to-6 mapped address. */
+ memset (&in6_mem.sin6_addr, '\0', sizeof (in6_mem.sin6_addr));
+ in6_mem.sin6_addr.__u6_addr.__u6_addr16[5] = 0xffff;
+ in6_mem.sin6_addr.__u6_addr.__u6_addr32[3] = in->sin_addr.s_addr;
+ in6_mem.sin6_scope_id = 0;
}
- switch (ai->ai_socktype) {
- case SOCK_RAW:
- return EAI_SERVICE;
- case SOCK_DGRAM:
- case SOCK_STREAM:
- allownumeric = 1;
- break;
- case ANY:
- allownumeric = 0;
- break;
- default:
- return EAI_SOCKTYPE;
- }
-
- if (str_isnumber(servname)) {
- if (!allownumeric)
- return EAI_SERVICE;
- port = htons(atoi(servname));
- if (port < 0 || port > 65535)
- return EAI_SERVICE;
- } else {
- switch (ai->ai_socktype) {
- case SOCK_DGRAM:
- proto = "udp";
- break;
- case SOCK_STREAM:
- proto = "tcp";
- break;
- default:
- proto = NULL;
- break;
- }
-
- if ((sp = getservbyname(servname, proto)) == NULL)
- return EAI_SERVICE;
- port = sp->s_port;
+ in6 = &in6_mem;
+ }
+ else
+ return default_val;
+
+ for (idx = 0; ; ++idx)
+ {
+ unsigned int bits = list[idx].bits;
+ uint8_t *mask = list[idx].prefix.s6_addr;
+ uint8_t *val = in6->sin6_addr.s6_addr;
+
+ while (bits > 8)
+ {
+ if (*mask != *val)
+ break;
+
+ ++mask;
+ ++val;
+ bits -= 8;
}
- 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
- }
+ if (bits < 8)
+ {
+ if ((*mask & (0xff00 >> bits)) == (*val & (0xff00 >> bits)))
+ /* Match! */
+ break;
}
+ }
- return 0;
+ return list[idx].val;
}
-static const struct afd *
-find_afd(af)
- 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;
+static int
+get_label (const struct sockaddr_storage *ss)
+{
+ /* XXX What is a good default value? */
+ return match_prefix (ss, default_labels, INT_MAX);
}
-/*
- * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend
- * will take care of it.
- * the semantics of AI_ADDRCONFIG is not defined well. we are not sure
- * if the code is right or not.
- *
- * XXX PF_UNSPEC -> PF_INET6 + PF_INET mapping needs to be in sync with
- * _dns_getaddrinfo.
- */
+
static int
-addrconfig(pai)
- struct addrinfo *pai;
+get_precedence (const struct sockaddr_storage *ss)
{
- int s, af;
-
- /*
- * TODO:
- * Note that implementation dependent test for address
- * configuration should be done everytime called
- * (or apropriate interval),
- * because addresses will be dynamically assigned or deleted.
- */
- af = pai->ai_family;
- if (af == AF_UNSPEC) {
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- af = AF_INET;
- else {
- close(s);
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- af = AF_INET6;
- else
- close(s);
- }
- }
- if (af != AF_UNSPEC) {
- if ((s = socket(af, SOCK_DGRAM, 0)) < 0)
- return 0;
- close(s);
- }
- pai->ai_family = af;
- return 1;
+ /* XXX What is a good default value? */
+ return match_prefix (ss, default_precedence, 0);
}
-#ifdef INET6
-/* convert a string to a scope identifier. XXX: IPv6 specific */
+
static int
-ip6_str2scopeid(scope, sin6)
- char *scope;
- struct sockaddr_in6 *sin6;
+rfc3484_sort (const void *p1, const void *p2)
{
- int scopeid;
- struct in6_addr *a6 = &sin6->sin6_addr;
- char *ep;
-
- /* empty scopeid portion is invalid */
- if (*scope == '\0')
- return -1;
-
- if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(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(scopeid);
- }
+ const struct sort_result *a1 = (const struct sort_result *) p1;
+ const struct sort_result *a2 = (const struct sort_result *) p2;
- /* 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 */
+ /* Rule 1: Avoid unusable destinations.
+ We have the got_source_addr flag set if the destination is reachable. */
+ if (a1->got_source_addr && ! a2->got_source_addr)
+ return -1;
+ if (! a1->got_source_addr && a2->got_source_addr)
+ return 1;
- /* try to convert to a numeric id as a last resort */
- trynumeric:
- scopeid = (int)strtoul(scope, &ep, 10);
- if (*ep == '\0')
- return scopeid;
- else
- return -1;
-}
-#endif
-#ifdef DEBUG
-static const char AskedForGot[] =
- "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
-#endif
-static FILE *hostf = NULL;
-
-static struct addrinfo *
-getanswer(answer, anslen, qname, qtype, pai)
- 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;
- int type, class, buflen, 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(); */
- }
- /*
- * find first satisfactory answer
- */
- hp = &answer->hdr;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- bp = hostbuf;
- buflen = sizeof hostbuf;
- cp = answer->buf + HFIXEDSZ;
- if (qdcount != 1) {
- h_errno = NO_RECOVERY;
- return (NULL);
- }
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- 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) {
- /* 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).
- */
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- h_errno = NO_RECOVERY;
- return (NULL);
- }
- canonname = bp;
- bp += n;
- buflen -= n;
- /* 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, buflen);
- 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) {
- n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
- if ((n < 0) || !(*name_ok)(tbuf)) {
- had_error++;
- continue;
- }
- cp += n;
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
- strcpy(bp, tbuf);
- canonname = bp;
- bp += n;
- buflen -= n;
- continue;
- }
- if (qtype == T_ANY) {
- if (!(type == T_A || type == T_AAAA)) {
- cp += n;
- continue;
- }
- } else if (type != qtype) {
-#ifdef DEBUG
- if (type != T_KEY && type != T_SIG)
- 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
- cp += n;
- continue; /* XXX - had_error++ ? */
- }
- switch (type) {
- case T_A:
- case T_AAAA:
- if (strcasecmp(canonname, bp) != 0) {
-#ifdef DEBUG
- syslog(LOG_NOTICE|LOG_AUTH,
- AskedForGot, canonname, bp);
-#endif
- cp += n;
- continue; /* XXX - had_error++ ? */
- }
- if (type == T_A && n != INADDRSZ) {
- cp += n;
- continue;
- }
- if (type == T_AAAA && n != IN6ADDRSZ) {
- cp += n;
- continue;
- }
-#ifdef FILTER_V4MAPPED
- if (type == T_AAAA) {
- struct in6_addr in6;
- memcpy(&in6, cp, sizeof(in6));
- if (IN6_IS_ADDR_V4MAPPED(&in6)) {
- cp += n;
- continue;
- }
- }
-#endif
- if (!haveanswer) {
- int nn;
+ /* Rule 2: Prefer matching scope. Only interesting if both
+ destination addresses are IPv6. */
+ int a1_dst_scope
+ = get_scope ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
- canonname = bp;
- nn = strlen(bp) + 1; /* for the \0 */
- bp += nn;
- buflen -= nn;
- }
+ int a2_dst_scope
+ = get_scope ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
- /* 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();
- }
- if (!had_error)
- haveanswer++;
- }
- if (haveanswer) {
- if (!canonname)
- (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;
- }
+ if (a1->got_source_addr)
+ {
+ int a1_src_scope = get_scope (&a1->source_addr);
+ int a2_src_scope = get_scope (&a2->source_addr);
- h_errno = NO_RECOVERY;
- return NULL;
-}
+ if (a1_dst_scope == a1_src_scope && a2_dst_scope != a2_src_scope)
+ return -1;
+ if (a1_dst_scope != a1_src_scope && a2_dst_scope == a2_src_scope)
+ return 1;
+ }
-/*ARGSUSED*/
-static int
-_dns_getaddrinfo(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
-{
- struct addrinfo *ai;
- querybuf buf, buf2;
- const char *name;
- const struct addrinfo *pai;
- struct addrinfo sentinel, *cur;
- struct res_target q, q2;
-
- name = va_arg(ap, char *);
- pai = va_arg(ap, const struct addrinfo *);
-
- memset(&q, 0, sizeof(q2));
- memset(&q2, 0, sizeof(q2));
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- switch (pai->ai_family) {
- case AF_UNSPEC:
- /* prefer IPv6 */
- q.qclass = C_IN;
- q.qtype = T_AAAA;
- q.answer = buf.buf;
- q.anslen = sizeof(buf);
- q.next = &q2;
- q2.qclass = C_IN;
- q2.qtype = T_A;
- q2.answer = buf2.buf;
- q2.anslen = sizeof(buf2);
- break;
- case AF_INET:
- q.qclass = C_IN;
- q.qtype = T_A;
- q.answer = buf.buf;
- q.anslen = sizeof(buf);
- break;
- case AF_INET6:
- q.qclass = C_IN;
- q.qtype = T_AAAA;
- q.answer = buf.buf;
- q.anslen = sizeof(buf);
- break;
- default:
- return NS_UNAVAIL;
- }
- if (res_searchN(name, &q) < 0)
- return NS_NOTFOUND;
- 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;
- }
- if (sentinel.ai_next == NULL)
- switch (h_errno) {
- case HOST_NOT_FOUND:
- return NS_NOTFOUND;
- case TRY_AGAIN:
- return NS_TRYAGAIN;
- default:
- return NS_UNAVAIL;
- }
- *((struct addrinfo **)rv) = sentinel.ai_next;
- return NS_SUCCESS;
-}
-static void
-_sethtent()
-{
- if (!hostf)
- hostf = fopen(_PATH_HOSTS, "r" );
- else
- rewind(hostf);
-}
+ /* Rule 3: Avoid deprecated addresses.
+ That's something only the kernel could decide. */
-static void
-_endhtent()
-{
- if (hostf) {
- (void) fclose(hostf);
- hostf = NULL;
- }
-}
+ /* Rule 4: Prefer home addresses.
+ Another thing only the kernel can decide. */
-static struct addrinfo *
-_gethtent(name, pai)
- const char *name;
- const struct addrinfo *pai;
-{
- char *p;
- char *cp, *tname, *cname;
- struct addrinfo hints, *res0, *res;
- int error;
- const char *addr;
- char hostbuf[8*1024];
-
- if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" )))
- return (NULL);
- 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;
- cname = NULL;
- /* if this is not something we're looking for, skip it. */
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- tname = cp;
- if (cname == NULL)
- cname = 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;
-#ifdef FILTER_V4MAPPED
- /* XXX should check all items in the chain */
- if (res0->ai_family == AF_INET6 &&
- IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)res0->ai_addr)->sin6_addr)) {
- freeaddrinfo(res0);
- goto again;
- }
-#endif
- for (res = res0; res; res = res->ai_next) {
- /* cover it up */
- res->ai_flags = pai->ai_flags;
-
- if (pai->ai_flags & AI_CANONNAME) {
- if (get_canonname(pai, res, cname) != 0) {
- freeaddrinfo(res0);
- goto again;
- }
- }
- }
- return res0;
-}
+ /* Rule 5: Prefer matching label. */
+ if (a1->got_source_addr)
+ {
+ int a1_dst_label
+ = get_label ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
+ int a1_src_label = get_label (&a1->source_addr);
-/*ARGSUSED*/
-static int
-_files_getaddrinfo(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
-{
- const char *name;
- const struct addrinfo *pai;
- struct addrinfo sentinel, *cur;
- struct addrinfo *p;
-
- name = va_arg(ap, char *);
- pai = va_arg(ap, struct addrinfo *);
-
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- _sethtent();
- while ((p = _gethtent(name, pai)) != NULL) {
- cur->ai_next = p;
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
- _endhtent();
+ int a2_dst_label
+ = get_label ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
+ int a2_src_label = get_label (&a2->source_addr);
- *((struct addrinfo **)rv) = sentinel.ai_next;
- if (sentinel.ai_next == NULL)
- return NS_NOTFOUND;
- return NS_SUCCESS;
-}
+ if (a1_dst_label == a1_src_label && a2_dst_label != a2_src_label)
+ return -1;
+ if (a1_dst_label != a1_src_label && a2_dst_label == a2_src_label)
+ return 1;
+ }
-#ifdef YP
-static char *__ypdomain;
-/*ARGSUSED*/
-static struct addrinfo *
-_yphostent(line, pai)
- 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';
+ /* Rule 6: Prefer higher precedence. */
+ int a1_prec
+ = get_precedence ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
+ int a2_prec
+ = get_precedence ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
- addr = p;
+ if (a1_prec > a2_prec)
+ return -1;
+ if (a1_prec < a2_prec)
+ return 1;
- 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;
+ /* Rule 7: Prefer native transport.
+ XXX How to recognize tunnels? */
- if (pai->ai_flags & AI_CANONNAME)
- (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;
- }
+ /* Rule 8: Prefer smaller scope. */
+ if (a1_dst_scope < a2_dst_scope)
+ return -1;
+ if (a1_dst_scope > a2_dst_scope)
+ return 1;
-done:
- return sentinel.ai_next;
-}
-/*ARGSUSED*/
-static int
-_yp_getaddrinfo(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
-{
- struct addrinfo sentinel, *cur;
- struct addrinfo *ai = NULL;
- static char *__ypcurrent;
- int __ypcurrentlen, r;
- const char *name;
- const struct addrinfo *pai;
-
- name = va_arg(ap, char *);
- pai = va_arg(ap, const struct addrinfo *);
-
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- if (!__ypdomain) {
- if (_yp_check(&__ypdomain) == 0)
- return NS_UNAVAIL;
- }
- 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;
- }
- }
- }
+ /* Rule 9: Use longest matching prefix. */
+ if (a1->got_source_addr
+ && a1->dest_addr->ai_family == a2->dest_addr->ai_family)
+ {
+ int bit1 = 0;
+ int bit2 = 0;
- /* 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;
- }
- }
+ if (a1->dest_addr->ai_family == PF_INET)
+ {
+ assert (a1->source_addr.ss_family == PF_INET);
+ assert (a2->source_addr.ss_family == PF_INET);
- if (sentinel.ai_next == NULL) {
- h_errno = HOST_NOT_FOUND;
- return NS_NOTFOUND;
- }
- *((struct addrinfo **)rv) = sentinel.ai_next;
- return NS_SUCCESS;
-}
-#endif
+ struct sockaddr_in *in1_dst;
+ struct sockaddr_in *in1_src;
+ struct sockaddr_in *in2_dst;
+ struct sockaddr_in *in2_src;
-/* resolver logic */
-
-extern const char *__hostalias(const char *);
-extern int h_errno;
-
-/*
- * 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(name, target)
- const char *name; /* domain name */
- struct res_target *target;
-{
- u_char buf[MAXPACKET];
- HEADER *hp;
- int n;
- struct res_target *t;
- int rcode;
- int ancount;
-
- rcode = NOERROR;
- ancount = 0;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
+ in1_dst = (struct sockaddr_in *) a1->dest_addr->ai_addr;
+ in1_src = (struct sockaddr_in *) &a1->source_addr;
+ in2_dst = (struct sockaddr_in *) a2->dest_addr->ai_addr;
+ in2_src = (struct sockaddr_in *) &a2->source_addr;
+
+ bit1 = ffs (in1_dst->sin_addr.s_addr ^ in1_src->sin_addr.s_addr);
+ bit2 = ffs (in2_dst->sin_addr.s_addr ^ in2_src->sin_addr.s_addr);
+ }
+ else if (a1->dest_addr->ai_family == PF_INET6)
+ {
+ assert (a1->source_addr.ss_family == PF_INET6);
+ assert (a2->source_addr.ss_family == PF_INET6);
+
+ struct sockaddr_in6 *in1_dst;
+ struct sockaddr_in6 *in1_src;
+ struct sockaddr_in6 *in2_dst;
+ struct sockaddr_in6 *in2_src;
+
+ in1_dst = (struct sockaddr_in6 *) a1->dest_addr->ai_addr;
+ in1_src = (struct sockaddr_in6 *) &a1->source_addr;
+ in2_dst = (struct sockaddr_in6 *) a2->dest_addr->ai_addr;
+ in2_src = (struct sockaddr_in6 *) &a2->source_addr;
+
+ int i;
+ for (i = 0; i < 4; ++i)
+ if (in1_dst->sin6_addr.s6_addr32[i]
+ != in1_src->sin6_addr.s6_addr32[i]
+ || (in2_dst->sin6_addr.s6_addr32[i]
+ != in2_src->sin6_addr.s6_addr32[i]))
+ break;
+
+ if (i < 4)
+ {
+ bit1 = ffs (in1_dst->sin6_addr.s6_addr32[i]
+ ^ in1_src->sin6_addr.s6_addr32[i]);
+ bit2 = ffs (in2_dst->sin6_addr.s6_addr32[i]
+ ^ in2_src->sin6_addr.s6_addr32[i]);
+ }
}
- 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 (_res.options & RES_DEBUG)
- printf(";; res_query(%s, %d, %d)\n", name, class, type);
-#endif
+ if (bit1 > bit2)
+ return -1;
+ if (bit1 < bit2)
+ return 1;
+ }
- n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
- buf, sizeof(buf));
- if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
- n = res_opt(n, buf, sizeof(buf), anslen);
- if (n <= 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; res_query: mkquery failed\n");
-#endif
- h_errno = NO_RECOVERY;
- return (n);
- }
- n = res_send(buf, n, answer, anslen);
-#if 0
- if (n < 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; res_query: send error\n");
-#endif
- h_errno = TRY_AGAIN;
- return (n);
- }
-#endif
- if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
- rcode = hp->rcode; /* record most recent error */
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; rcode = %d, ancount=%d\n", hp->rcode,
- ntohs(hp->ancount));
-#endif
- continue;
- }
+ /* Rule 10: Otherwise, leave the order unchanged. */
+ return 0;
+}
- ancount += ntohs(hp->ancount);
- t->n = n;
+int
+getaddrinfo (const char *name, const char *service,
+ const struct addrinfo *hints, struct addrinfo **pai)
+{
+ int i = 0, j = 0, last_i = 0;
+ int nresults = 0;
+ struct addrinfo *p = NULL, **end;
+ struct gaih *g = gaih, *pg = NULL;
+ struct gaih_service gaih_service, *pservice;
+ struct addrinfo local_hints;
+
+ if (name != NULL && name[0] == '*' && name[1] == 0)
+ name = NULL;
+
+ if (service != NULL && service[0] == '*' && service[1] == 0)
+ service = NULL;
+
+ if (name == NULL && service == NULL)
+ return EAI_NONAME;
+
+ if (hints == NULL)
+ hints = &default_hints;
+
+ if (hints->ai_flags
+ & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|AI_ADDRCONFIG|AI_V4MAPPED
+#ifdef HAVE_LIBIDN
+ |AI_IDN|AI_CANONIDN|AI_IDN_ALLOW_UNASSIGNED
+ |AI_IDN_USE_STD3_ASCII_RULES
+#endif
+ |AI_NUMERICSERV|AI_ALL))
+ return EAI_BADFLAGS;
+
+ if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
+ return EAI_BADFLAGS;
+
+ if (hints->ai_flags & AI_ADDRCONFIG)
+ {
+ /* Determine whether we have IPv4 or IPv6 interfaces or both.
+ We cannot cache the results since new interfaces could be
+ added at any time. */
+ bool seen_ipv4;
+ bool seen_ipv6;
+ __check_pf (&seen_ipv4, &seen_ipv6);
+
+ /* Now make a decision on what we return, if anything. */
+ if (hints->ai_family == PF_UNSPEC && (seen_ipv4 || seen_ipv6))
+ {
+ /* If we haven't seen both IPv4 and IPv6 interfaces we can
+ narrow down the search. */
+ if (! seen_ipv4 || ! seen_ipv6)
+ {
+ local_hints = *hints;
+ local_hints.ai_family = seen_ipv4 ? PF_INET : PF_INET6;
+ hints = &local_hints;
+ }
+ }
+ else if ((hints->ai_family == PF_INET && ! seen_ipv4)
+ || (hints->ai_family == PF_INET6 && ! seen_ipv6))
+ /* We cannot possibly return a valid answer. */
+ return EAI_NONAME;
+ }
+
+ if (service && service[0])
+ {
+ char *c;
+ gaih_service.name = service;
+ gaih_service.num = strtoul (gaih_service.name, &c, 10);
+ if (*c != '\0')
+ {
+ if (hints->ai_flags & AI_NUMERICSERV)
+ return EAI_NONAME;
+
+ gaih_service.num = -1;
}
- 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;
+ pservice = &gaih_service;
+ }
+ else
+ pservice = NULL;
+
+ if (pai)
+ end = &p;
+ else
+ end = NULL;
+
+ while (g->gaih)
+ {
+ if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC)
+ {
+ j++;
+ if (pg == NULL || pg->gaih != g->gaih)
+ {
+ pg = g;
+ i = g->gaih (name, pservice, hints, end);
+ if (i != 0)
+ {
+ /* EAI_NODATA is a more specific result as it says that
+ we found a result but it is not usable. */
+ if (last_i != (GAIH_OKIFUNSPEC | -EAI_NODATA))
+ last_i = i;
+
+ if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
+ {
+ ++g;
+ continue;
+ }
+
+ freeaddrinfo (p);
+
+ return -(i & GAIH_EAI);
}
- return (-1);
+ if (end)
+ while (*end)
+ {
+ end = &((*end)->ai_next);
+ ++nresults;
+ }
+ }
}
- 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(name, target)
- const char *name; /* domain name */
- struct res_target *target;
-{
- 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.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
+ ++g;
+ }
+
+ if (j == 0)
+ return EAI_FAMILY;
+
+ if (nresults > 1)
+ {
+ /* Sort results according to RFC 3484. */
+ struct sort_result results[nresults];
+ struct addrinfo *q;
+ struct addrinfo *last = NULL;
+ char *canonname = NULL;
+
+ for (i = 0, q = p; q != NULL; ++i, last = q, q = q->ai_next)
+ {
+ results[i].dest_addr = q;
+ results[i].got_source_addr = false;
+
+ /* If we just looked up the address for a different
+ protocol, reuse the result. */
+ if (last != NULL && last->ai_addrlen == q->ai_addrlen
+ && memcmp (last->ai_addr, q->ai_addr, q->ai_addrlen) == 0)
+ {
+ memcpy (&results[i].source_addr, &results[i - 1].source_addr,
+ results[i - 1].source_addr_len);
+ results[i].source_addr_len = results[i - 1].source_addr_len;
+ results[i].got_source_addr = results[i - 1].got_source_addr;
+ }
+ else
+ {
+ /* We overwrite the type with SOCK_DGRAM since we do not
+ want connect() to connect to the other side. If we
+ cannot determine the source address remember this
+ fact. */
+ int fd = socket (q->ai_family, SOCK_DGRAM, IPPROTO_IP);
+ socklen_t sl = sizeof (results[i].source_addr);
+ if (fd != -1
+ && connect (fd, q->ai_addr, q->ai_addrlen) == 0
+ && getsockname (fd,
+ (struct sockaddr *) &results[i].source_addr,
+ &sl) == 0)
+ {
+ results[i].source_addr_len = sl;
+ results[i].got_source_addr = true;
+ }
+ else
+ /* Just make sure that if we have to process the same
+ address again we do not copy any memory. */
+ results[i].source_addr_len = 0;
+
+ if (fd != -1)
+ close_not_cancel_no_status (fd);
+ }
+
+ /* Remember the canonical name. */
+ if (q->ai_canonname != NULL)
+ {
+ assert (canonname == NULL);
+ canonname = q->ai_canonname;
+ q->ai_canonname = NULL;
+ }
}
- 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 >= _res.ndots) {
- ret = res_querydomainN(name, NULL, target);
- if (ret > 0)
- return (ret);
- saved_herrno = h_errno;
- tried_as_is++;
- }
+ /* We got all the source addresses we can get, now sort using
+ the information. */
+ qsort (results, nresults, sizeof (results[0]), rfc3484_sort);
- /*
- * 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 && (_res.options & RES_DEFNAMES)) ||
- (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
- int done = 0;
-
- for (domain = (const char * const *)_res.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);
- }
+ /* Queue the results up as they come out of sorting. */
+ q = p = results[0].dest_addr;
+ for (i = 1; i < nresults; ++i)
+ q = q->ai_next = results[i].dest_addr;
+ q->ai_next = NULL;
- 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 (!(_res.options & RES_DNSRCH))
- done++;
- }
- }
+ /* Fill in the canonical name into the new first entry. */
+ p->ai_canonname = canonname;
+ }
- /*
- * 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 && (dots || !(_res.options & RES_NOTLDQUERY))) {
- ret = res_querydomainN(name, NULL, target);
- if (ret > 0)
- return (ret);
- }
+ if (p)
+ {
+ *pai = p;
+ return 0;
+ }
+
+ if (pai == NULL && last_i == 0)
+ return 0;
- /*
- * 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);
+ return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
}
+libc_hidden_def (getaddrinfo)
-/*
- * 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(name, domain, target)
- const char *name, *domain;
- struct res_target *target;
-{
- char nbuf[MAXDNAME];
- const char *longname = nbuf;
- size_t n, d;
+static_link_warning (getaddrinfo)
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; res_querydomain(%s, %s)\n",
- name, domain?domain:"<Nil>");
-#endif
- if (domain == NULL) {
- /*
- * Check for trailing '.';
- * copy without '.' if present.
- */
- n = strlen(name);
- if (n >= MAXDNAME) {
- h_errno = NO_RECOVERY;
- return (-1);
- }
- if (n > 0 && name[--n] == '.') {
- strncpy(nbuf, name, n);
- nbuf[n] = '\0';
- } else
- longname = name;
- } else {
- n = strlen(name);
- d = strlen(domain);
- if (n + d + 1 >= MAXDNAME) {
- h_errno = NO_RECOVERY;
- return (-1);
- }
- sprintf(nbuf, "%s.%s", name, domain);
- }
- return (res_queryN(longname, target));
+void
+freeaddrinfo (struct addrinfo *ai)
+{
+ struct addrinfo *p;
+
+ while (ai != NULL)
+ {
+ p = ai;
+ ai = ai->ai_next;
+ free (p->ai_canonname);
+ free (p);
+ }
}
+libc_hidden_def (freeaddrinfo)
diff --git a/newlib/libc/sys/linux/net/getaliasent.c b/newlib/libc/sys/linux/net/getaliasent.c
new file mode 100644
index 000000000..e3234752e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getaliasent.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <aliases.h>
+
+
+#define LOOKUP_TYPE struct aliasent
+#define GETFUNC_NAME getaliasent
+#define BUFLEN 1024
+
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/getaliasent_r.c b/newlib/libc/sys/linux/net/getaliasent_r.c
new file mode 100644
index 000000000..70dbc26b1
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getaliasent_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <aliases.h>
+
+
+#define LOOKUP_TYPE struct aliasent
+#define SETFUNC_NAME setaliasent
+#define GETFUNC_NAME getaliasent
+#define ENDFUNC_NAME endaliasent
+#define DATABASE_NAME aliases
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getaliasname.c b/newlib/libc/sys/linux/net/getaliasname.c
new file mode 100644
index 000000000..2ad315f9f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getaliasname.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <aliases.h>
+
+
+#define LOOKUP_TYPE struct aliasent
+#define FUNCTION_NAME getaliasbyname
+#define DATABASE_NAME aliases
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getaliasname_r.c b/newlib/libc/sys/linux/net/getaliasname_r.c
new file mode 100644
index 000000000..ec3519d57
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getaliasname_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <aliases.h>
+
+
+#define LOOKUP_TYPE struct aliasent
+#define FUNCTION_NAME getaliasbyname
+#define DATABASE_NAME aliases
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/gethostbydns.c b/newlib/libc/sys/linux/net/gethostbydns.c
deleted file mode 100644
index 9c80539f2..000000000
--- a/newlib/libc/sys/linux/net/gethostbydns.c
+++ /dev/null
@@ -1,815 +0,0 @@
-/*
- * ++Copyright++ 1985, 1988, 1993
- * -
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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--
- */
-
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <ctype.h>
-#include <errno.h>
-#include <syslog.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-
-#include "res_config.h"
-
-#define SPRINTF(x) ((size_t)sprintf x)
-
-static const char AskedForGot[] =
- "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
-
-#ifdef RESOLVSORT
-static void addrsort(char **, int);
-#endif
-
-u_int32_t _getlong(const u_char *src);
-u_int16_t _getshort(const u_char *src);
-
-#ifdef DEBUG
-static void dbgprintf(char *, int);
-#endif
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-typedef union {
- int32_t al;
- char ac;
-} align;
-
-extern int h_errno;
-int _dns_ttl_;
-
-#ifdef DEBUG
-static void
-dbgprintf(msg, num)
- char *msg;
- int num;
-{
- if (_res.options & RES_DEBUG) {
- int save = errno;
-
- printf(msg, num);
- errno = save;
- }
-}
-#else
-# define dbgprintf(msg, num) /*nada*/
-#endif
-
-#define BOUNDED_INCR(x) \
- do { \
- cp += x; \
- if (cp > eom) { \
- *herr = NO_RECOVERY; \
- return (NULL); \
- } \
- } while (0)
-
-#define BOUNDS_CHECK(ptr, count) \
- do { \
- if ((ptr) + (count) > eom) { \
- *herr = NO_RECOVERY; \
- return (NULL); \
- } \
- } while (0)
-
-static struct hostent *
-gethostanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr)
- const querybuf *answer;
- int anslen;
- const char *qname;
- int qtype;
- struct hostent *host;
- char *hostbuf;
- int hostbuflen;
- int *herr;
-{
- const HEADER *hp;
- const u_char *cp;
- int n;
- const u_char *eom, *erdata;
- char *bp, **ap, **hap;
- int type, class, buflen, ancount, qdcount;
- int haveanswer, had_error;
- int toobig = 0;
- char tbuf[MAXDNAME];
- 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:
- name_ok = res_hnok;
- break;
- case T_PTR:
- name_ok = res_dnok;
- break;
- default:
- *herr = NO_RECOVERY;
- return (NULL); /* XXX should be abort(); */
- }
- /*
- * find first satisfactory answer
- */
- hp = &answer->hdr;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- bp = hostbuf;
- buflen = hostbuflen;
- cp = answer->buf;
- BOUNDED_INCR(HFIXEDSZ);
- if (qdcount != 1) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- if ((n < 0) || !(*name_ok)(bp)) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- BOUNDED_INCR(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).
- */
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- host->h_name = bp;
- bp += n;
- buflen -= n;
- /* The qname can be abbreviated, but h_name is now absolute. */
- qname = host->h_name;
- }
- ap = host->__host_aliases;
- *ap = NULL;
- host->h_aliases = host->__host_aliases;
- hap = host->__host_addrs;
- *hap = NULL;
- host->h_addr_list = host->__host_addrs;
- haveanswer = 0;
- had_error = 0;
- _dns_ttl_ = -1;
- while (ancount-- > 0 && cp < eom && !had_error) {
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- if ((n < 0) || !(*name_ok)(bp)) {
- had_error++;
- continue;
- }
- cp += n; /* name */
- BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
- type = _getshort(cp);
- cp += INT16SZ; /* type */
- class = _getshort(cp);
- cp += INT16SZ; /* class */
- if (qtype == T_A && type == T_A)
- _dns_ttl_ = _getlong(cp);
- cp += INT32SZ; /* TTL */
- n = _getshort(cp);
- cp += INT16SZ; /* len */
- BOUNDS_CHECK(cp, n);
- erdata = cp + n;
- 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->__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;
- if (cp != erdata) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- /* Store alias. */
- *ap++ = bp;
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
- bp += n;
- buflen -= n;
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
- strcpy(bp, tbuf);
- host->h_name = bp;
- bp += n;
- buflen -= n;
- continue;
- }
- if (qtype == T_PTR && type == T_CNAME) {
- n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
- if (n < 0 || !res_dnok(tbuf)) {
- had_error++;
- continue;
- }
- cp += n;
- if (cp != erdata) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
- strcpy(bp, tbuf);
- tname = bp;
- bp += n;
- buflen -= n;
- continue;
- }
- if (type != qtype) {
- if (type != T_SIG)
- syslog(LOG_NOTICE|LOG_AUTH,
- "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
- qname, p_class(C_IN), p_type(qtype),
- p_type(type));
- 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, buflen);
- if ((n < 0) || !res_hnok(bp)) {
- had_error++;
- break;
- }
-#if MULTI_PTRS_ARE_ALIASES
- cp += n;
- if (cp != erdata) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- if (!haveanswer)
- host->h_name = bp;
- else if (ap < &host->__host_aliases[MAXALIASES-1])
- *ap++ = bp;
- else
- n = -1;
- if (n != -1) {
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- had_error++;
- break;
- }
- bp += n;
- buflen -= n;
- }
- break;
-#else
- host->h_name = bp;
- if (_res.options & RES_USE_INET6) {
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- had_error++;
- break;
- }
- bp += n;
- buflen -= n;
- _map_v4v6_hostent(host, &bp, &buflen);
- }
- *herr = 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 (!haveanswer) {
- int nn;
-
- host->h_name = bp;
- nn = strlen(bp) + 1; /* for the \0 */
- bp += nn;
- buflen -= nn;
- }
-
- bp += sizeof(align) - ((u_long)bp % sizeof(align));
-
- if (bp + n >= &hostbuf[hostbuflen]) {
- dbgprintf("size (%d) too big\n", n);
- had_error++;
- continue;
- }
- if (hap >= &host->__host_addrs[MAXADDRS-1]) {
- if (!toobig++)
- dbgprintf("Too many addresses (%d)\n",
- MAXADDRS);
- cp += n;
- continue;
- }
- bcopy(cp, *hap++ = bp, n);
- bp += n;
- buflen -= n;
- cp += n;
- if (cp != erdata) {
- *herr = NO_RECOVERY;
- return (NULL);
- }
- break;
- default:
- dbgprintf("Impossible condition (type=%d)\n", type);
- *herr = NO_RECOVERY;
- return (NULL);
- /* BIND has abort() here, too risky on bad data */
- }
- 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 (_res.nsort && haveanswer > 1 && qtype == T_A)
- addrsort(host->__host_addrs, haveanswer);
-# endif /*RESOLVSORT*/
- if (!host->h_name) {
- n = strlen(qname) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN)
- goto no_recovery;
- strcpy(bp, qname);
- host->h_name = bp;
- bp += n;
- buflen -= n;
- }
- if (_res.options & RES_USE_INET6)
- _map_v4v6_hostent(host, &bp, &buflen);
- *herr = NETDB_SUCCESS;
- return host;
- }
- no_recovery:
- *herr = NO_RECOVERY;
- return (NULL);
-}
-
-struct hostent *
-__dns_getanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr)
- const char *answer;
- int anslen;
- const char *qname;
- int qtype;
- struct hostent *host;
- char *hostbuf;
- int hostbuflen;
- int *herr;
-{
- switch(qtype) {
- case T_AAAA:
- host->h_addrtype = AF_INET6;
- host->h_length = IN6ADDRSZ;
- break;
- case T_A:
- default:
- host->h_addrtype = AF_INET;
- host->h_length = INADDRSZ;
- break;
- }
-
- return(gethostanswer((const querybuf *)answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr));
-}
-
-int
-_dns_gethostbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- querybuf buf;
- const char *cp;
- char *bp;
- int n, size, type, len;
- struct hostent *resultbuf;
- char *hostbuf;
- int buflen;
- int *herr;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- hostbuf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- *herr = NETDB_INTERNAL;
- return NS_UNAVAIL;
- }
-
- switch (af) {
- case AF_INET:
- size = INADDRSZ;
- type = T_A;
- break;
- case AF_INET6:
- size = IN6ADDRSZ;
- type = T_AAAA;
- break;
- default:
- *herr = NETDB_INTERNAL;
- errno = EAFNOSUPPORT;
- return NS_UNAVAIL;
- }
-
- resultbuf->h_addrtype = af;
- resultbuf->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((unsigned char)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, resultbuf->__host_addr) <= 0) {
- *herr = HOST_NOT_FOUND;
- return NS_NOTFOUND;
- }
- strncpy(hostbuf, name, MAXDNAME);
- hostbuf[MAXDNAME] = '\0';
- bp = hostbuf + MAXDNAME;
- len = buflen - MAXDNAME;
- resultbuf->h_name = hostbuf;
- resultbuf->h_aliases = resultbuf->__host_aliases;
- resultbuf->__host_aliases[0] = NULL;
- resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr;
- resultbuf->__host_addrs[1] = NULL;
- resultbuf->h_addr_list = resultbuf->__host_addrs;
- if (_res.options & RES_USE_INET6)
- _map_v4v6_hostent(resultbuf, &bp, &len);
- *herr = NETDB_SUCCESS;
- *(struct hostent **)rval = resultbuf;
- return NS_SUCCESS;
- }
- if (!isdigit((unsigned char)*cp) && *cp != '.')
- break;
- }
- if ((isxdigit((unsigned char)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, resultbuf->__host_addr) <= 0) {
- *herr = HOST_NOT_FOUND;
- return NS_NOTFOUND;
- }
- strncpy(hostbuf, name, MAXDNAME);
- hostbuf[MAXDNAME] = '\0';
- bp = hostbuf + MAXDNAME;
- len = buflen - MAXDNAME;
- resultbuf->h_name = hostbuf;
- resultbuf->h_aliases = resultbuf->__host_aliases;
- resultbuf->__host_aliases[0] = NULL;
- resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr;
- resultbuf->__host_addrs[1] = NULL;
- resultbuf->h_addr_list = resultbuf->__host_addrs;
- *herr = NETDB_SUCCESS;
- *(struct hostent **)rval = resultbuf;
- return NS_SUCCESS;
- }
- if (!isxdigit((unsigned char)*cp) && *cp != ':' && *cp != '.')
- break;
- }
-
- if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
- dbgprintf("res_search failed (%d)\n", n);
- return NS_UNAVAIL;
- }
- *(struct hostent **)rval = gethostanswer(&buf, n, name, type, resultbuf, hostbuf, buflen, herr);
- return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-int
-_dns_gethostbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const char *addr; /* XXX should have been def'd as u_char! */
- int len, af;
- const u_char *uaddr;
- static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
- static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
- int n, size;
- querybuf buf;
- struct hostent *hp;
- char qbuf[MAXDNAME+1], *qp;
-#ifdef SUNSECURITY
- struct hostent *rhp;
- char **haddr;
- u_long old_options;
- char hname2[MAXDNAME+1];
-#endif /*SUNSECURITY*/
- struct hostent *resultbuf;
- char *hostbuf;
- int buflen;
- int *herr;
-
- addr = va_arg(ap, const char *);
- uaddr = (const u_char *)addr;
- len = va_arg(ap, int);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- hostbuf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- *herr = NETDB_INTERNAL;
- return NS_UNAVAIL;
- }
- if (af == AF_INET6 && len == IN6ADDRSZ &&
- (!memcmp(uaddr, mapped, sizeof mapped) ||
- !memcmp(uaddr, tunnelled, sizeof tunnelled))) {
- /* Unmap. */
- addr += sizeof mapped;
- uaddr += sizeof mapped;
- af = AF_INET;
- len = INADDRSZ;
- }
- switch (af) {
- case AF_INET:
- size = INADDRSZ;
- break;
- case AF_INET6:
- size = IN6ADDRSZ;
- break;
- default:
- errno = EAFNOSUPPORT;
- *herr = NETDB_INTERNAL;
- return NS_UNAVAIL;
- }
- if (size != len) {
- errno = EINVAL;
- *herr = NETDB_INTERNAL;
- return NS_UNAVAIL;
- }
- switch (af) {
- case AF_INET:
- (void) sprintf(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--) {
- qp += SPRINTF((qp, "%x.%x.",
- uaddr[n] & 0xf,
- (uaddr[n] >> 4) & 0xf));
- }
- strcpy(qp, "ip6.int");
- break;
- default:
- abort();
- }
- n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
- if (n < 0) {
- dbgprintf("res_query failed (%d)\n", n);
- return NS_UNAVAIL;
- }
- if (n > sizeof buf.buf) {
- dbgprintf("static buffer is too small (%d)\n", n);
- return NS_UNAVAIL;
- }
- if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR, resultbuf, hostbuf, buflen, herr)))
- return NS_NOTFOUND; /* *herr was set by gethostanswer() */
-#ifdef SUNSECURITY
- if (af == AF_INET) {
- /*
- * turn off search as the name should be absolute,
- * 'localhost' should be matched by defnames
- */
- strncpy(hname2, hp->h_name, MAXDNAME);
- hname2[MAXDNAME] = '\0';
- old_options = _res.options;
- _res.options &= ~RES_DNSRCH;
- _res.options |= RES_DEFNAMES;
- if (!(rhp = gethostbyname(hname2))) {
- syslog(LOG_NOTICE|LOG_AUTH,
- "gethostbyaddr: No A record for %s (verifying [%s])",
- hname2, inet_ntoa(*((struct in_addr *)addr)));
- _res.options = old_options;
- *herr = HOST_NOT_FOUND;
- return NS_NOTFOUND;
- }
- _res.options = old_options;
- for (haddr = rhp->h_addr_list; *haddr; haddr++)
- if (!memcmp(*haddr, addr, INADDRSZ))
- break;
- if (!*haddr) {
- syslog(LOG_NOTICE|LOG_AUTH,
- "gethostbyaddr: A record of %s != PTR record [%s]",
- hname2, inet_ntoa(*((struct in_addr *)addr)));
- *herr = HOST_NOT_FOUND;
- return NS_NOTFOUND;
- }
- }
-#endif /*SUNSECURITY*/
- hp->h_addrtype = af;
- hp->h_length = len;
- bcopy(addr, resultbuf->__host_addr, len);
- resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr;
- resultbuf->__host_addrs[1] = NULL;
- if (af == AF_INET && (_res.options & RES_USE_INET6)) {
- _map_v4v6_address((char*)resultbuf->__host_addr, (char*)resultbuf->__host_addr);
- hp->h_addrtype = AF_INET6;
- hp->h_length = IN6ADDRSZ;
- }
- *herr = NETDB_SUCCESS;
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-#ifdef RESOLVSORT
-static void
-addrsort(ap, num)
- char **ap;
- int num;
-{
- 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 < _res.nsort; j++)
- if (_res.sort_list[j].addr.s_addr ==
- (((struct in_addr *)(*p))->s_addr & _res.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
-void
-_sethostdnsent(stayopen)
- int stayopen;
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return;
- if (stayopen)
- _res.options |= RES_STAYOPEN | RES_USEVC;
-}
-
-void
-_endhostdnsent()
-{
- _res.options &= ~(RES_STAYOPEN | RES_USEVC);
- res_close();
-}
diff --git a/newlib/libc/sys/linux/net/gethostbyht.c b/newlib/libc/sys/linux/net/gethostbyht.c
deleted file mode 100644
index 4a15293dd..000000000
--- a/newlib/libc/sys/linux/net/gethostbyht.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*-
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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--
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-#include <arpa/nameser.h> /* XXX */
-#include <resolv.h> /* XXX */
-#include <dirent.h>
-#include <stdlib.h>
-#include <errno.h>
-
-static FILE *hostf = NULL;
-static int stayopen = 0;
-__LOCK_INIT(static, host_lock);
-
-void
-_sethosthtent_r(int f, FILE **hostfile, int *hstayopen)
-{
- if (!*hostfile)
- *hostfile = fopen(_PATH_HOSTS, "r" );
- else
- rewind(*hostfile);
- *hstayopen = f;
-}
-
-void
-_endhosthtent_r(FILE **hostfile, int *hstayopen)
-{
- if (*hostfile && !*hstayopen) {
- (void) fclose(*hostfile);
- *hostfile = NULL;
- }
-}
-
-void
-_sethosthtent(f)
- int f;
-{
- _sethosthtent_r(f, &hostf, &stayopen);
-}
-
-void
-_endhosthtent()
-{
- _endhosthtent_r(&hostf, &stayopen);
-}
-
-struct hostent *
-gethostent()
-{
- static struct hostent hp;
- static char buffer[BUFSIZ+1];
- static int len = BUFSIZ;
- static int herr;
-
-#ifdef HAVE_DD_LOCK
- __lock_acquire(host_lock);
-#endif
- gethostent_r(&hp, buffer, len, &herr, &hostf);
-#ifdef HAVE_DD_LOCK
- __lock_release(host_lock);
-#endif
- return &hp;
-}
-
-int
-gethostent_r(struct hostent *hp, char *buffer, int buflen, int *herr, FILE **hostfile)
-{
- char *p;
- char *cp, **q;
- int af, len;
-
- if (!*hostfile && !(*hostfile = fopen(_PATH_HOSTS, "r" ))) {
- *herr = NETDB_INTERNAL;
- return -1;
- }
- again:
- if (!(p = fgets(buffer, buflen, *hostfile))) {
- *herr = HOST_NOT_FOUND;
- return -1;
- }
- if (*p == '#')
- goto again;
- if (!(cp = strpbrk(p, "#\n")))
- goto again;
- *cp = '\0';
- if (!(cp = strpbrk(p, " \t")))
- goto again;
- *cp++ = '\0';
-
- hp->h_addr_list = hp->__host_addrs;
- hp->__host_addrs[0] = (char *)hp->__host_addr;
-
- if (inet_pton(AF_INET6, p, hp->h_addr_list[0]) > 0) {
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else if (inet_pton(AF_INET, p, hp->h_addr_list[0]) > 0) {
- if (_res.options & RES_USE_INET6) {
- _map_v4v6_address(hp->h_addr_list[0], hp->h_addr_list[0]);
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else {
- af = AF_INET;
- len = INADDRSZ;
- }
- } else {
- goto again;
- }
-
-
- hp->h_addr_list[1] = NULL;
- hp->h_addr = hp->__host_addrs[0];
- hp->h_length = len;
- hp->h_addrtype = af;
-
- while (*cp == ' ' || *cp == '\t')
- cp++;
- hp->h_name = cp;
- q = hp->h_aliases = hp->__host_aliases;
- if ((cp = strpbrk(cp, " \t")) != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &hp->h_aliases[MAXALIASES - 1])
- *q++ = cp;
- if ((cp = strpbrk(cp, " \t")) != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
-
- *herr = NETDB_SUCCESS;
- return 0;
-}
-
-int
-_ht_gethostbyname(void *rval, void *cb_data, va_list ap)
-{
- char **cp;
- const char *name;
- int af;
- struct hostent *resultbuf;
- char *buf;
- int buflen;
- int *herr;
- FILE *hostfile = NULL;
- int stayopen;
- int p;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- buf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- sethostent_r(0, &hostfile, &stayopen);
- while ((p = gethostent_r(resultbuf, buf, buflen, herr, &hostfile)) != -1) {
- if (resultbuf->h_addrtype != af)
- continue;
- if (strcasecmp(resultbuf->h_name, name) == 0)
- break;
- for (cp = resultbuf->h_aliases; *cp != 0; cp++)
- if (strcasecmp(*cp, name) == 0)
- goto found;
- }
-found:
- endhostent_r(&hostfile, &stayopen);
-
- if (p == -1)
- {
- *(struct hostent **)rval = NULL;
- return NS_NOTFOUND;
- }
- else
- {
- *(struct hostent **)rval = resultbuf;
- return NS_SUCCESS;
- }
-}
-
-int
-_ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const char *addr;
- int len, af;
- struct hostent *resultbuf;
- char *buf;
- int buflen;
- int *herr;
- FILE *hostfile = NULL;
- int stayopen;
- int p;
-
- addr = va_arg(ap, const char *);
- len = va_arg(ap, int);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- buf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- sethostent_r(0, &hostfile, &stayopen);
- while ((p = gethostent_r(resultbuf, buf, buflen, herr, &hostfile)) != -1)
- if (resultbuf->h_addrtype == af && !memcmp(resultbuf->h_addr, addr, len))
- break;
- endhostent_r(&hostfile, &stayopen);
-
- if (p == -1)
- {
- *(struct hostent **)rval = NULL;
- return NS_NOTFOUND;
- }
- else
- {
- *(struct hostent **)rval = resultbuf;
- return NS_SUCCESS;
- }
-}
diff --git a/newlib/libc/sys/linux/net/gethostbyname.3 b/newlib/libc/sys/linux/net/gethostbyname.3
deleted file mode 100644
index 51ed2f864..000000000
--- a/newlib/libc/sys/linux/net/gethostbyname.3
+++ /dev/null
@@ -1,380 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
-.\" $FreeBSD: src/lib/libc/net/gethostbyname.3,v 1.26 2002/01/14 16:59:00 ru Exp $
-.\"
-.Dd May 25, 1995
-.Dt GETHOSTBYNAME 3
-.Os
-.Sh NAME
-.Nm gethostbyname ,
-.Nm gethostbyname2 ,
-.Nm gethostbyaddr ,
-.Nm gethostent ,
-.Nm sethostent ,
-.Nm endhostent ,
-.Nm herror ,
-.Nm hstrerror
-.Nd get network host entry
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In netdb.h
-.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 char *addr" "int len" "int type"
-.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
-.Bf -symbolic
-The
-.Xr getaddrinfo 3
-and
-.Xr getnameinfo 3
-functions are preferred over the
-.Fn gethostbyname ,
-.Fn gethostbyname2 ,
-and
-.Fn gethostbyaddr
-functions.
-.Ef
-.Pp
-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.
-.Pp
-The
-.Fa name
-parameter passed to
-.Fn gethostbyname
-or
-.Fn gethostbyname2
-should point to a
-.Dv NUL Ns -terminated
-hostname.
-The
-.Fa addr
-parameter passed to
-.Fn gethostbyaddr
-should point to an address which is
-.Fa len
-bytes long,
-in binary form
-(i.e. not an IP address in human readable
-.Tn ASCII
-form).
-The
-.Fa type
-parameter specifies the address family
-(e.g.\&
-.Dv AF_INET , AF_INET6 ,
-etc.) of this address.
-.Pp
-The structure returned contains either the information obtained from the name
-server,
-.Xr named 8 ,
-broken-out fields from a line in
-.Pa /etc/hosts ,
-or database entries supplied by the
-.Xr yp 8
-system.
-The order of the lookups is controlled by the
-.Sq hosts
-entry in
-.Xr nsswitch.conf 5 .
-.Bd -literal
-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 addresses from name server */
-};
-#define h_addr h_addr_list[0] /* address, for backward compatibility */
-.Ed
-.Pp
-The members of this structure are:
-.Bl -tag -width h_addr_list
-.It Va h_name
-Official name of the host.
-.It Va h_aliases
-A
-.Dv NULL Ns -terminated
-array of alternate names for the host.
-.It Va h_addrtype
-The type of address being returned; usually
-.Dv AF_INET .
-.It Va h_length
-The length, in bytes, of the address.
-.It Va h_addr_list
-A
-.Dv NULL Ns -terminated
-array of network addresses for the host.
-Host addresses are returned in network byte order.
-.It Va h_addr
-The first address in
-.Va h_addr_list ;
-this is for backward compatibility.
-.El
-.Pp
-When using the nameserver,
-.Fn gethostbyname
-and
-.Fn gethostbyname2
-will search for the named host in the current domain and its parents
-unless the name ends in a dot.
-If the name contains no dot, and if the environment variable
-.Dq Ev HOSTALIASES
-contains the name of an alias file, the alias file will first be searched
-for an alias matching the input name.
-See
-.Xr hostname 7
-for the domain search procedure and the alias file format.
-.Pp
-The
-.Fn gethostbyname2
-function is an evolution of
-.Fn gethostbyname
-which is intended to allow lookups in address families other than
-.Dv AF_INET ,
-for example
-.Dv AF_INET6 .
-.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 ,
-.Fn gethostbyname2
-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 writes a message to the diagnostic output consisting of the
-string parameter
-.Fa s ,
-the constant string
-.Qq Li ":\ " ,
-and a message corresponding to the value of
-.Va h_errno .
-.Pp
-The
-.Fn hstrerror
-function returns a string which is the message text corresponding to the
-value of the
-.Fa err
-parameter.
-.Sh FILES
-.Bl -tag -width /etc/nsswitch.conf -compact
-.It Pa /etc/hosts
-.It Pa /etc/nsswitch.conf
-.It Pa /etc/resolv.conf
-.El
-.Sh EXAMPLES
-Print out the hostname associated with a specific IP address:
-.Bd -literal -offset indent
-const char *ipstr = "127.0.0.1";
-struct in_addr ip;
-struct hostent *hp;
-
-if (!inet_aton(ipstr, &ip))
- errx(1, "can't parse IP address %s", ipstr);
-
-if ((hp = gethostbyaddr((const char *)&ip,
- sizeof ip, AF_INET)) == NULL)
- errx(1, "no name associated with %s", ipstr);
-
-printf("name associated with %s is %s\en", ipstr, hp->h_name);
-.Ed
-.Sh DIAGNOSTICS
-Error return status from
-.Fn gethostbyname ,
-.Fn gethostbyname2
-and
-.Fn gethostbyaddr
-is indicated by return of a
-.Dv 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.
-The routine
-.Fn herror
-can be used to print an error message describing the failure.
-If its argument
-.Fa string
-is
-.Pf non- Dv NULL ,
-it is printed, followed by a colon and a space.
-The error message is printed with a trailing newline.
-.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.
-.El
-.Sh SEE ALSO
-.Xr getaddrinfo 3 ,
-.Xr getnameinfo 3 ,
-.Xr inet_aton 3 ,
-.Xr resolver 3 ,
-.Xr hosts 5 ,
-.Xr hostname 7 ,
-.Xr named 8
-.Sh CAVEAT
-The
-.Fn gethostent
-function
-is defined, and
-.Fn sethostent
-and
-.Fn endhostent
-are redefined,
-when
-.Xr libc 3
-is built to use only the routines to lookup in
-.Pa /etc/hosts
-and not the name server.
-.Pp
-The
-.Fn gethostent
-function
-reads the next line of
-.Pa /etc/hosts ,
-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 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 .
-The
-.Fn gethostbyname2
-function first appeared in
-.Tn BIND
-version 4.9.4.
-.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.
-Only the Internet
-address format is currently understood.
-.Pp
-.Fn gethostbyname2
-cannot perform
-.Dv AF_INET6
-lookups over NIS.
-.Xr getaddrinfo 3
-must be used instead.
diff --git a/newlib/libc/sys/linux/net/gethostbynis.c b/newlib/libc/sys/linux/net/gethostbynis.c
deleted file mode 100644
index 917e9409d..000000000
--- a/newlib/libc/sys/linux/net/gethostbynis.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*-
- * Copyright (c) 1994, Garrett Wollman
- *
- * 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 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 <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-#ifdef YP
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-#endif
-
-#ifdef YP
-static char *host_aliases[MAXALIASES];
-static char hostaddr[MAXADDRS];
-static char *host_addrs[2];
-
-static struct hostent *
-_gethostbynis(name, map, af)
- const char *name;
- char *map;
- int af;
-{
- char *cp, **q;
- char *result;
- int resultlen,size;
- static struct hostent h;
- static char *domain = (char *)NULL;
- static char ypbuf[YPMAXRECORD + 2];
-
- switch(af) {
- case AF_INET:
- size = NS_INADDRSZ;
- break;
- default:
- case AF_INET6:
- size = NS_IN6ADDRSZ;
- errno = EAFNOSUPPORT;
- h_errno = NETDB_INTERNAL;
- return NULL;
- }
-
- if (domain == (char *)NULL)
- if (yp_get_default_domain (&domain)) {
- h_errno = NETDB_INTERNAL;
- return ((struct hostent *)NULL);
- }
-
- if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) {
- h_errno = HOST_NOT_FOUND;
- return ((struct hostent *)NULL);
- }
-
- /* avoid potential memory leak */
- bcopy((char *)result, (char *)&ypbuf, resultlen);
- ypbuf[resultlen] = '\0';
- free(result);
- result = (char *)&ypbuf;
-
- if ((cp = index(result, '\n')))
- *cp = '\0';
-
- cp = strpbrk(result, " \t");
- *cp++ = '\0';
- h.h_addr_list = host_addrs;
- h.h_addr = hostaddr;
- *((u_long *)h.h_addr) = inet_addr(result);
- h.h_length = size;
- h.h_addrtype = AF_INET;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- h.h_name = cp;
- q = h.h_aliases = host_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &host_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- return (&h);
-}
-
-static struct hostent *
-_gethostbynis_r(name, map, af, hp, buffer, buflen, herr)
- const char *name;
- char *map;
- int af;
- struct hostent *hp;
- char *buffer;
- int buflen;
- int *herr;
-{
- char *cp, **q;
- char *result;
- int resultlen,size;
- char *domain = (char *)NULL;
-
- switch(af) {
- case AF_INET:
- size = NS_INADDRSZ;
- break;
- default:
- case AF_INET6:
- size = NS_IN6ADDRSZ;
- errno = EAFNOSUPPORT;
- *herr = NETDB_INTERNAL;
- return NULL;
- }
-
- if (domain == (char *)NULL)
- if (yp_get_default_domain (&domain)) {
- *herr = NETDB_INTERNAL;
- return ((struct hostent *)NULL);
- }
-
- if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) {
- *herr = HOST_NOT_FOUND;
- return ((struct hostent *)NULL);
- }
-
- /* avoid potential memory leak */
- bcopy((char *)result, buffer, resultlen);
- buffer[resultlen] = '\0';
- free(result);
- result = buffer;
-
- if ((cp = index(result, '\n')))
- *cp = '\0';
-
- cp = strpbrk(result, " \t");
- *cp++ = '\0';
- *((u_long *)hp->__host_addrs[0]) = inet_addr(result);
- hp->__host_addrs[1] = NULL;
- hp->h_addr_list = hp->__host_addrs;
- hp->h_addr = hp->__host_addrs[0];
- hp->h_length = size;
- hp->h_addrtype = AF_INET;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- hp->h_name = cp;
- q = hp->__host_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &hp->__host_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- hp->h_aliases = hp->__host_aliases;
- *q = NULL;
- return (&hp);
-}
-#endif /* YP */
-
-/* XXX _gethostbynisname/_gethostbynisaddr only used by getaddrinfo */
-struct hostent *
-_gethostbynisname(const char *name, int af)
-{
-#ifdef YP
- return _gethostbynis(name, "hosts.byname", af);
-#else
- return NULL;
-#endif
-}
-
-struct hostent *
-_gethostbynisaddr(const char *addr, int len, int af)
-{
-#ifdef YP
- return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),
- "hosts.byaddr", af);
-#else
- return NULL;
-#endif
-}
-
-
-int
-_nis_gethostbyname(void *rval, void *cb_data, va_list ap)
-{
-#ifdef YP
- const char *name;
- int af;
- struct hostent *resultbuf;
- char *buf;
- int buflen;
- int *herr;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- buf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- *(struct hostent **)rval = _gethostbynis_r(name, "hosts.byname", af, resultbuf, buf, buflen, herr);
-
- return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-#else
- return NS_UNAVAIL;
-#endif
-}
-
-int
-_nis_gethostbyaddr(void *rval, void *cb_data, va_list ap)
-{
-#ifdef YP
- const char *addr;
- int len;
- int af;
- struct hostent *resultbuf;
- char *buf;
- int buflen;
- int *herr;
-
- addr = va_arg(ap, const char *);
- len = va_arg(ap, int);
- af = va_arg(ap, int);
- resultbuf = va_arg(ap, struct hostent *);
- buf = va_arg(ap, char *);
- buflen = va_arg(ap, int);
- herr = va_arg(ap, int *);
-
- *(struct hostent **)rval = _gethostbynis_r(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
- return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-#else
- return NS_UNAVAIL;
-#endif
-}
diff --git a/newlib/libc/sys/linux/net/gethostnamadr.c b/newlib/libc/sys/linux/net/gethostnamadr.c
deleted file mode 100644
index de1efd8ed..000000000
--- a/newlib/libc/sys/linux/net/gethostnamadr.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*-
- * Copyright (c) 1994, Garrett Wollman
- *
- * 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 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 <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-#include <arpa/nameser.h> /* XXX hack for _res */
-#include <resolv.h> /* XXX hack for _res */
-#include <dirent.h>
-
-extern int _ht_gethostbyname(void *, void *, va_list);
-extern int _dns_gethostbyname(void *, void *, va_list);
-extern int _nis_gethostbyname(void *, void *, va_list);
-extern int _ht_gethostbyaddr(void *, void *, va_list);
-extern int _dns_gethostbyaddr(void *, void *, va_list);
-extern int _nis_gethostbyaddr(void *, void *, va_list);
-
-/* Host lookup order if nsswitch.conf is broken or nonexistant */
-static const ns_src default_src[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { NSSRC_DNS, NS_SUCCESS },
- { 0 }
-};
-
-__LOCK_INIT(static, name_lock);
-__LOCK_INIT(static, addr_lock);
-
-struct hostent *
-gethostbyname(const char *name)
-{
- struct hostent *hp = NULL;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (NULL);
- }
- if (_res.options & RES_USE_INET6) { /* XXX */
- hp = gethostbyname2(name, AF_INET6); /* XXX */
- if (hp) /* XXX */
- return (hp); /* XXX */
- } /* XXX */
- return (gethostbyname2(name, AF_INET));
-}
-
-struct hostent *
-gethostbyname2(const char *name, int type)
-{
- static struct hostent host, *hp;
- static char hostbuf[BUFSIZ];
- static int herr;
- int rval;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_gethostbyname, NULL)
- { NSSRC_DNS, _dns_gethostbyname, NULL },
- NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */
- { 0 }
- };
-
-#ifdef HAVE_DD_LOCK
- __lock_acquire(name_lock);
-#endif
- rval = nsdispatch((void *)&hp, dtab, NSDB_HOSTS, "gethostbyname",
- default_src, name, type, &host, hostbuf, BUFSIZ, &herr);
-
-#ifdef HAVE_DD_LOCK
- __lock_release(name_lock);
-#endif
- if (rval != NS_SUCCESS)
- return NULL;
- else
- return hp;
-}
-
-int
-__gethostbyname_r(const char *name, struct hostent *result,
- void *buffer, int buflen, struct hostent **hp, int *herr)
-{
- int rval;
- int type;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_gethostbyname, NULL)
- { NSSRC_DNS, _dns_gethostbyname, NULL },
- NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */
- { 0 }
- };
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return HOST_NOT_FOUND;
- }
-
- if (_res.options & RES_USE_INET6)
- type = AF_INET6;
- else
- type = AF_INET;
-
- rval = nsdispatch((void *)hp, dtab, NSDB_HOSTS, "gethostbyname",
- default_src, name, type, result, buffer, buflen, herr);
-
- if (rval != NS_SUCCESS)
- return rval;
- else
- return 0;
-}
-
-struct hostent *
-gethostbyaddr(const char *addr, int len, int type)
-{
- static struct hostent host, *hp;
- static char hostbuf[BUFSIZ];
- static int herr;
- int rval;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_gethostbyaddr, NULL)
- { NSSRC_DNS, _dns_gethostbyaddr, NULL },
- NS_NIS_CB(_nis_gethostbyaddr, NULL) /* force -DHESIOD */
- { 0 }
- };
-
-#ifdef HAVE_DD_LOCK
- __lock_acquire(addr_lock);
-#endif
- rval = nsdispatch((void *)&hp, dtab, NSDB_HOSTS, "gethostbyaddr",
- default_src, addr, len, type, &host, hostbuf, BUFSIZ, &herr);
-
-#ifdef HAVE_DD_LOCK
- __lock_release(addr_lock);
-#endif
- if (rval != NS_SUCCESS)
- return NULL;
- else
- return hp;
-}
-
-int
-__gethostbyaddr_r (const char *addr, int len, int type,
- struct hostent *result, void *buffer, int buflen,
- struct hostent **hp, int *herr)
-{
- int rval;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_gethostbyaddr, NULL)
- { NSSRC_DNS, _dns_gethostbyaddr, NULL },
- NS_NIS_CB(_nis_gethostbyaddr, NULL) /* force -DHESIOD */
- { 0 }
- };
-
- rval = nsdispatch((void *)hp, dtab, NSDB_HOSTS, "gethostbyaddr",
- default_src, addr, len, type, result, buffer, buflen, herr);
-
- if(rval != NS_SUCCESS)
- return rval;
- else
- return 0;
-}
-
-void
-sethostent(stayopen)
- int stayopen;
-{
- _sethosthtent(stayopen);
- _sethostdnsent(stayopen);
-}
-
-void
-endhostent()
-{
- _endhosthtent();
- _endhostdnsent();
-}
-
-void
-sethostent_r(int f, FILE **hostfile, int *stayopen)
-{
- _sethosthtent_r(f, hostfile, stayopen);
- _sethostdnsent(f);
-}
-
-void
-endhostent_r(FILE **hostfile, int *stayopen)
-{
- _endhosthtent_r(hostfile, stayopen);
- _endhostdnsent();
-}
diff --git a/newlib/libc/sys/linux/net/gethstbyad.c b/newlib/libc/sys/linux/net/gethstbyad.c
new file mode 100644
index 000000000..97992ad8d
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbyad.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyaddr
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const void *addr, socklen_t len, int type
+#define ADD_VARIABLES addr, len, type
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/gethstbyad_r.c b/newlib/libc/sys/linux/net/gethstbyad_r.c
new file mode 100644
index 000000000..244828e8d
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbyad_r.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+#include <string.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyaddr
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const void *addr, socklen_t len, int type
+#define ADD_VARIABLES addr, len, type
+#define NEED_H_ERRNO 1
+#define NEED__RES 1
+#define NEED__RES_HCONF 1
+/* If the addr parameter is the IPv6 unspecified address no query must
+ be performed. */
+#define PREPROCESS \
+ if (len == sizeof (struct in6_addr) \
+ && __builtin_expect (memcmp (&in6addr_any, addr, \
+ sizeof (struct in6_addr)), 1) == 0) \
+ { \
+ *h_errnop = HOST_NOT_FOUND; \
+ *result = NULL; \
+ return ENOENT; \
+ }
+#define POSTPROCESS \
+ if (status == NSS_STATUS_SUCCESS) \
+ { \
+ _res_hconf_reorder_addrs (resbuf); \
+ _res_hconf_trim_domains (resbuf); \
+ }
+
+/* Special name for the lookup function. */
+#define DB_LOOKUP_FCT __nss_hosts_lookup
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/gethstbynm.c b/newlib/libc/sys/linux/net/gethstbynm.c
new file mode 100644
index 000000000..e94eb0a0f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbynm.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyname
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#define HANDLE_DIGITS_DOTS 1
+
+#include <getXXbyYY.c>
diff --git a/newlib/libc/sys/linux/net/gethstbynm2.c b/newlib/libc/sys/linux/net/gethstbynm2.c
new file mode 100644
index 000000000..b365511a8
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbynm2.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyname2
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const char *name, int af
+#define ADD_VARIABLES name, af
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#define HANDLE_DIGITS_DOTS 1
+#define HAVE_AF 1
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/gethstbynm2_r.c b/newlib/libc/sys/linux/net/gethstbynm2_r.c
new file mode 100644
index 000000000..c7a2201c2
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbynm2_r.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyname2
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const char *name, int af
+#define ADD_VARIABLES name, af
+#define NEED_H_ERRNO 1
+#define NEED__RES_HCONF 1
+#define POSTPROCESS \
+ if (status == NSS_STATUS_SUCCESS) \
+ _res_hconf_reorder_addrs (resbuf);
+
+#define HANDLE_DIGITS_DOTS 1
+#define HAVE_LOOKUP_BUFFER 1
+#define HAVE_AF 1
+
+/* Special name for the lookup function. */
+#define DB_LOOKUP_FCT __nss_hosts_lookup
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/gethstbynm_r.c b/newlib/libc/sys/linux/net/gethstbynm_r.c
new file mode 100644
index 000000000..ccdd6c2a4
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstbynm_r.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define FUNCTION_NAME gethostbyname
+#define DATABASE_NAME hosts
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define NEED_H_ERRNO 1
+#define NEED__RES_HCONF 1
+#define POSTPROCESS \
+ if (status == NSS_STATUS_SUCCESS) \
+ _res_hconf_reorder_addrs (resbuf);
+
+#define HANDLE_DIGITS_DOTS 1
+#define HAVE_LOOKUP_BUFFER 1
+
+/* Special name for the lookup function. */
+#define DB_LOOKUP_FCT __nss_hosts_lookup
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/gethstent.c b/newlib/libc/sys/linux/net/gethstent.c
new file mode 100644
index 000000000..eab9f8f79
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstent.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define GETFUNC_NAME gethostent
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/gethstent_r.c b/newlib/libc/sys/linux/net/gethstent_r.c
new file mode 100644
index 000000000..c8afa8128
--- /dev/null
+++ b/newlib/libc/sys/linux/net/gethstent_r.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct hostent
+#define SETFUNC_NAME sethostent
+#define GETFUNC_NAME gethostent
+#define ENDFUNC_NAME endhostent
+#define DATABASE_NAME hosts
+#define STAYOPEN int stayopen
+#define STAYOPEN_VAR stayopen
+#define NEED_H_ERRNO 1
+#define NEED__RES 1
+
+/* Special name for the lookup function. */
+#define DB_LOOKUP_FCT __nss_hosts_lookup
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getifaddrs.3 b/newlib/libc/sys/linux/net/getifaddrs.3
deleted file mode 100644
index 47e50049d..000000000
--- a/newlib/libc/sys/linux/net/getifaddrs.3
+++ /dev/null
@@ -1,164 +0,0 @@
-.\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.6 2001/10/01 16:08:55 ru Exp $
-.\" $KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun 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 October 12, 1995
-.Dt GETIFADDRS 3
-.Os
-.Sh NAME
-.Nm getifaddrs
-.Nd get interface addresses
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In ifaddrs.h
-.Ft int
-.Fn getifaddrs "struct ifaddrs **ifap"
-.Ft void
-.Fn freeifaddrs "struct ifaddrs *ifp"
-.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
-.Pp
-The
-.Li ifa_next
-field contains a pointer to the next structure on the list.
-This field is
-.Dv NULL
-in last structure on the list.
-.Pp
-The
-.Li ifa_name
-field contains the interface name.
-.Pp
-The
-.Li ifa_flags
-field contains the interface flags, as set by
-.Xr ifconfig 8
-utility.
-.Pp
-The
-.Li ifa_addr
-field references either the address of the interface or the link level
-address of the interface, if one exists, otherwise it is NULL.
-(The
-.Li sa_family
-field of the
-.Li ifa_addr
-field should be consulted to determine the format of the
-.Li ifa_addr
-address.)
-.Pp
-The
-.Li ifa_netmask
-field references the netmask associated with
-.Li ifa_addr ,
-if one is set, otherwise it is NULL.
-.Pp
-The
-.Li ifa_broadaddr
-field,
-which should only be referenced for non-P2P interfaces,
-references the broadcast address associated with
-.Li ifa_addr ,
-if one exists, otherwise it is NULL.
-.Pp
-The
-.Li ifa_dstaddr
-field references the destination address on a P2P interface,
-if one exists, otherwise it is NULL.
-.Pp
-The
-.Li ifa_data
-field references address family specific data. For
-.Dv AF_LINK
-addresses it contains a pointer to the
-.Fa 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, it contains a pointer to the
-.Fa struct ifa_data
-(as defined in include file
-.Aq Pa net/if.h )
-which contains per-address interface statistics.
-.Pp
-The data returned by
-.Fn getifaddrs
-is dynamically allocated and should be freed using
-.Fn freeifaddrs
-when no longer needed.
-.Sh RETURN VALUES
-.Rv -std getifaddrs
-.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 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 .
-.Sh SEE ALSO
-.Xr ioctl 2 ,
-.Xr socket 2 ,
-.Xr sysctl 3 ,
-.Xr networking 4 ,
-.Xr ifconfig 8
-.Sh HISTORY
-The
-.Nm
-implementation first appeared in BSDi
-.Bsx .
diff --git a/newlib/libc/sys/linux/net/getifaddrs.c b/newlib/libc/sys/linux/net/getifaddrs.c
deleted file mode 100644
index fdb8c9b9d..000000000
--- a/newlib/libc/sys/linux/net/getifaddrs.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun 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
- */
-/*
- * NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform
- * try-and-error for region size.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/sockio.h>
-#include <unistd.h>
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#ifdef NET_RT_IFLIST
-#include <sys/param.h>
-#include <net/route.h>
-#include <sys/sysctl.h>
-#include <net/if_dl.h>
-#endif
-
-#include <ifaddrs.h>
-#include <stdlib.h>
-#include <string.h>
-#include "un-namespace.h"
-
-#if !defined(AF_LINK)
-#define SA_LEN(sa) sizeof(struct sockaddr)
-#endif
-
-#if !defined(SA_LEN)
-#define SA_LEN(sa) sizeof(struct sockaddr)
-#endif
-
-#define SALIGN (sizeof(long) - 1)
-#define SA_RLEN(sa) (sizeof(struct sockaddr) ? ((sizeof(struct sockaddr) + SALIGN) & ~SALIGN) : (SALIGN + 1))
-
-#ifndef ALIGNBYTES
-/*
- * On systems with a routing socket, ALIGNBYTES should match the value
- * that the kernel uses when building the messages.
- */
-#define ALIGNBYTES XXX
-#endif
-#ifndef ALIGN
-#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-#endif
-
-#if _BSDI_VERSION >= 199701
-#define HAVE_IFM_DATA
-#endif
-
-#if _BSDI_VERSION >= 199802
-/* ifam_data is very specific to recent versions of bsdi */
-#define HAVE_IFAM_DATA
-#endif
-
-#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
-#define HAVE_IFM_DATA
-#endif
-
-int
-getifaddrs(struct ifaddrs **pif)
-{
- int icnt = 1;
- int dcnt = 0;
- int ncnt = 0;
-#ifdef NET_RT_IFLIST
- 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;
- struct ifaddrs *ifa, *ift;
- u_short idx = 0;
-#else /* NET_RT_IFLIST */
- struct ifaddrs *ifa, *ift;
- char buf[1024];
- int m, sock;
- struct ifconf ifc;
- struct ifreq *ifr;
- struct ifreq *lifr;
-#endif /* NET_RT_IFLIST */
- int i;
- size_t len, alen;
- char *data;
- char *names;
-
-#ifdef NET_RT_IFLIST
- 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 *)(void *)next;
- if (rtm->rtm_version != RTM_VERSION)
- continue;
- switch (rtm->rtm_type) {
- case RTM_IFINFO:
- ifm = (struct if_msghdr *)(void *)rtm;
- if (ifm->ifm_addrs & RTA_IFP) {
- idx = ifm->ifm_index;
- ++icnt;
- dl = (struct sockaddr_dl *)(void *)(ifm + 1);
- dcnt += SA_RLEN((struct sockaddr *)(void*)dl) +
- ALIGNBYTES;
-#ifdef HAVE_IFM_DATA
- dcnt += sizeof(ifm->ifm_data);
-#endif /* HAVE_IFM_DATA */
- ncnt += dl->sdl_nlen + 1;
- } else
- idx = 0;
- break;
-
- case RTM_NEWADDR:
- ifam = (struct ifa_msghdr *)(void *)rtm;
- if (idx && ifam->ifam_index != idx)
- abort(); /* this cannot happen */
-
-#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD)
- if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
- break;
- p = (char *)(void *)(ifam + 1);
- ++icnt;
-#ifdef HAVE_IFAM_DATA
- dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES;
-#endif /* HAVE_IFAM_DATA */
- /* 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 *)(void *)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 *)(void *)p;
- len = SA_RLEN(sa);
- if (i == RTAX_NETMASK && SA_LEN(sa) == 0)
- dcnt += alen;
- else
- dcnt += len;
- p += len;
- }
- break;
- }
- }
-#else /* NET_RT_IFLIST */
- ifc.ifc_buf = buf;
- ifc.ifc_len = sizeof(buf);
-
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- return (-1);
- i = ioctl(sock, SIOCGIFCONF, (char *)&ifc);
- close(sock);
- if (i < 0)
- return (-1);
-
- ifr = ifc.ifc_req;
- lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
-
- while (ifr < lifr) {
- struct sockaddr *sa;
-
- sa = &ifr->ifr_addr;
- ++icnt;
- dcnt += SA_RLEN(sa);
- ncnt += sizeof(ifr->ifr_name) + 1;
-
- if (SA_LEN(sa) < sizeof(*sa))
- ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa));
- else
- ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
- }
-#endif /* NET_RT_IFLIST */
-
- 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 *)(void *)data;
- data += sizeof(struct ifaddrs) * icnt;
- names = data + dcnt;
-
- memset(ifa, 0, sizeof(struct ifaddrs) * icnt);
- ift = ifa;
-
-#ifdef NET_RT_IFLIST
- idx = 0;
- for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
- rtm = (struct rt_msghdr *)(void *)next;
- if (rtm->rtm_version != RTM_VERSION)
- continue;
- switch (rtm->rtm_type) {
- case RTM_IFINFO:
- ifm = (struct if_msghdr *)(void *)rtm;
- if (ifm->ifm_addrs & RTA_IFP) {
- idx = ifm->ifm_index;
- dl = (struct sockaddr_dl *)(void *)(ifm + 1);
-
- cif = ift;
- ift->ifa_name = names;
- ift->ifa_flags = (int)ifm->ifm_flags;
- memcpy(names, dl->sdl_data,
- (size_t)dl->sdl_nlen);
- names[dl->sdl_nlen] = 0;
- names += dl->sdl_nlen + 1;
-
- ift->ifa_addr = (struct sockaddr *)(void *)data;
- memcpy(data, dl,
- (size_t)SA_LEN((struct sockaddr *)
- (void *)dl));
- data += SA_RLEN((struct sockaddr *)(void *)dl);
-
-#ifdef HAVE_IFM_DATA
- /* ifm_data needs to be aligned */
- ift->ifa_data = data = (void *)ALIGN(data);
- memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data));
- data += sizeof(ifm->ifm_data);
-#else /* HAVE_IFM_DATA */
- ift->ifa_data = NULL;
-#endif /* HAVE_IFM_DATA */
-
- ift = (ift->ifa_next = ift + 1);
- } else
- idx = 0;
- break;
-
- case RTM_NEWADDR:
- ifam = (struct ifa_msghdr *)(void *)rtm;
- if (idx && ifam->ifam_index != idx)
- abort(); /* this cannot happen */
-
- if (idx == 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 = (char *)(void *)(ifam + 1);
- /* 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 *)(void *)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 *)(void *)p;
- len = SA_RLEN(sa);
- switch (i) {
- case RTAX_IFA:
- ift->ifa_addr =
- (struct sockaddr *)(void *)data;
- memcpy(data, p, len);
- data += len;
- break;
-
- case RTAX_NETMASK:
- ift->ifa_netmask =
- (struct sockaddr *)(void *)data;
- if (SA_LEN(sa) == 0) {
- memset(data, 0, alen);
- data += alen;
- break;
- }
- memcpy(data, p, len);
- data += len;
- break;
-
- case RTAX_BRD:
- ift->ifa_broadaddr =
- (struct sockaddr *)(void *)data;
- memcpy(data, p, len);
- data += len;
- break;
- }
- p += len;
- }
-
-#ifdef HAVE_IFAM_DATA
- /* ifam_data needs to be aligned */
- ift->ifa_data = data = (void *)ALIGN(data);
- memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data));
- data += sizeof(ifam->ifam_data);
-#endif /* HAVE_IFAM_DATA */
-
- ift = (ift->ifa_next = ift + 1);
- break;
- }
- }
-
- free(buf);
-#else /* NET_RT_IFLIST */
- ifr = ifc.ifc_req;
- lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
-
- while (ifr < lifr) {
- struct sockaddr *sa;
-
- ift->ifa_name = names;
- names[sizeof(ifr->ifr_name)] = 0;
- strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name));
- while (*names++)
- ;
-
- ift->ifa_addr = (struct sockaddr *)data;
- sa = &ifr->ifr_addr;
- memcpy(data, sa, SA_LEN(sa));
- data += SA_RLEN(sa);
-
- ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
- ift = (ift->ifa_next = ift + 1);
- }
-#endif /* NET_RT_IFLIST */
- 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/newlib/libc/sys/linux/net/getipnodebyname.3 b/newlib/libc/sys/linux/net/getipnodebyname.3
deleted file mode 100644
index 5b8ea1ecb..000000000
--- a/newlib/libc/sys/linux/net/getipnodebyname.3
+++ /dev/null
@@ -1,461 +0,0 @@
-.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.8 2001/10/01 16:08:55 ru Exp $
-.\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
-.\"
-.Dd May 25, 1995
-.Dt GETIPNODEBYNAME 3
-.Os
-.\"
-.Sh NAME
-.Nm getipnodebyname ,
-.Nm getipnodebyaddr ,
-.Nm freehostent
-.Nd nodename-to-address and address-to-nodename translation
-.\"
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In netdb.h
-.Ft "struct hostent *"
-.Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num"
-.Ft "struct hostent *"
-.Fn getipnodebyaddr "const void *src" "size_t len" "int af" "int *error_num"
-.Ft void
-.Fn freehostent "struct hostent *ptr"
-.\"
-.Sh DESCRIPTION
-.Fn getipnodebyname
-and
-.Fn getipnodebyaddr
-functions are very similar to
-.Xr gethostbyname 3 ,
-.Xr gethostbyname2 3
-and
-.Xr gethostbyaddr 3 .
-The functions cover all the functionalities provided by the older ones,
-and provide better interface to programmers.
-The functions require additional arguments,
-.Ar af ,
-and
-.Ar flags ,
-for specifying address family and operation mode.
-The additional arguments allow programmer to get address for a nodename,
-for specific address family
-(such as
-.Dv AF_INET
-or
-.Dv AF_INET6 ) .
-The functions also require an additional pointer argument,
-.Ar error_num
-to return the appropriate error code,
-to support thread safe error code returns.
-.Pp
-The type and usage of the return value,
-.Li "struct hostent"
-is described in
-.Xr gethostbyname 3 .
-.Pp
-For
-.Fn getipnodebyname ,
-the
-.Ar name
-argument can be either a node name or a numeric address
-string
-(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
-The
-.Ar af
-argument specifies the address family, either
-.Dv AF_INET
-or
-.Dv AF_INET6 .
-The
-.Ar flags
-argument specifies the types of addresses that are searched for,
-and the types of addresses that are returned.
-We note that a special flags value of
-.Dv AI_DEFAULT
-(defined below)
-should handle most applications.
-That is, porting simple applications to use IPv6 replaces the call
-.Bd -literal -offset
- hptr = gethostbyname(name);
-.Ed
-.Pp
-with
-.Bd -literal -offset
- hptr = getipnodebyname(name, AF_INET6, AI_DEFAULT, &error_num);
-.Ed
-.Pp
-Applications desiring finer control over the types of addresses
-searched for and returned, can specify other combinations of the
-.Ar flags
-argument.
-.Pp
-A
-.Ar flags
-of
-.Li 0
-implies a strict interpretation of the
-.Ar af
-argument:
-.Bl -bullet
-.It
-If
-.Ar flags
-is 0 and
-.Ar af
-is
-.Dv AF_INET ,
-then the caller wants only IPv4 addresses.
-A query is made for
-.Li A
-records.
-If successful, the IPv4 addresses are returned and the
-.Li h_length
-member of the
-.Li hostent
-structure will be 4, else the function returns a
-.Dv NULL
-pointer.
-.It
-If
-.Ar flags
-is 0 and if
-.Ar af
-is
-.Li AF_INET6 ,
-then the caller wants only IPv6 addresses.
-A query is made for
-.Li AAAA
-records.
-If successful, the IPv6 addresses are returned and the
-.Li h_length
-member of the
-.Li hostent
-structure will be 16, else the function returns a
-.Dv NULL
-pointer.
-.El
-.Pp
-Other constants can be logically-ORed into the
-.Ar flags
-argument, to modify the behavior of the function.
-.Bl -bullet
-.It
-If the
-.Dv AI_V4MAPPED
-flag is specified along with an
-.Ar af
-of
-.Dv AF_INET6 ,
-then the caller will accept IPv4-mapped IPv6 addresses.
-That is, if no
-.Li AAAA
-records are found then a query is made for
-.Li A
-records and any found are returned as IPv4-mapped IPv6 addresses
-.Li ( h_length
-will be 16).
-The
-.Dv AI_V4MAPPED
-flag is ignored unless
-.Ar af
-equals
-.Dv AF_INET6 .
-.It
-The
-.Dv AI_V4MAPPED_CFG
-flag is exact same as the
-.Dv AI_V4MAPPED
-flag only if the kernel supports IPv4-mapped IPv6 address.
-.It
-If the
-.Dv AI_ALL
-flag is used in conjunction with the
-.Dv AI_V4MAPPED
-flag, and only used with the IPv6 address family.
-When
-.Dv AI_ALL
-is logically or'd with
-.Dv AI_V4MAPPED
-flag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6.
-A query is first made for
-.Li AAAA
-records and if successful, the
-IPv6 addresses are returned. Another query is then made for
-.Li A
-records and any found are returned as IPv4-mapped IPv6 addresses.
-.Li h_length
-will be 16. Only if both queries fail does the function
-return a
-.Dv NULL
-pointer. This flag is ignored unless af equals
-AF_INET6. If both
-.Dv AI_ALL
-and
-.Dv AI_V4MAPPED
-are specified,
-.Dv AI_ALL
-takes precedence.
-.It
-The
-.Dv AI_ADDRCONFIG
-flag specifies that a query for
-.Li AAAA
-records
-should occur only if the node has at least one IPv6 source
-address configured and a query for
-.Li A
-records should occur only if the node has at least one IPv4 source address
-configured.
-.Pp
-For example, if the node has no IPv6 source addresses configured,
-and
-.Ar af
-equals AF_INET6, and the node name being looked up has both
-.Li AAAA
-and
-.Li A
-records, then:
-(a) if only
-.Dv AI_ADDRCONFIG
-is
-specified, the function returns a
-.Dv NULL
-pointer;
-(b) if
-.Dv AI_ADDRCONFIG
-|
-.Dv AI_V4MAPPED
-is specified, the
-.Li A
-records are returned as IPv4-mapped IPv6 addresses;
-.El
-.Pp
-The special flags value of
-.Dv AI_DEFAULT
-is defined as
-.Bd -literal -offset
- #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
-.Ed
-.Pp
-We noted that the
-.Fn getipnodebyname
-function must allow the
-.Ar name
-argument to be either a node name or a literal address string
-(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
-This saves applications from having to call
-.Xr inet_pton 3
-to handle literal address strings.
-When the
-.Ar name
-argument is a literal address string,
-the
-.Ar flags
-argument is always ignored.
-.Pp
-There are four scenarios based on the type of literal address string
-and the value of the
-.Ar af
-argument.
-The two simple cases are when
-.Ar name
-is a dotted-decimal IPv4 address and
-.Ar af
-equals
-.Dv AF_INET ,
-or when
-.Ar name
-is an IPv6 hex address and
-.Ar af
-equals
-.Dv AF_INET6 .
-The members of the
-returned hostent structure are:
-.Li h_name
-points to a copy of the
-.Ar name
-argument,
-.Li h_aliases
-is a
-.Dv NULL
-pointer,
-.Li h_addrtype
-is a copy of the
-.Ar af
-argument,
-.Li h_length
-is either 4
-(for
-.Dv AF_INET )
-or 16
-(for
-.Dv AF_INET6 ) ,
-.Li h_addr_list[0]
-is a pointer to the 4-byte or 16-byte binary address,
-and
-.Li h_addr_list[1]
-is a
-.Dv NULL
-pointer.
-.Pp
-When
-.Ar name
-is a dotted-decimal IPv4 address and
-.Ar af
-equals
-.Dv AF_INET6 ,
-and
-.Dv AI_V4MAPPED
-is specified,
-an IPv4-mapped IPv6 address is returned:
-.Li h_name
-points to an IPv6 hex address containing the IPv4-mapped IPv6 address,
-.Li h_aliases
-is a
-.Dv NULL
-pointer,
-.Li h_addrtype
-is
-.Dv AF_INET6 ,
-.Li h_length
-is 16,
-.Li h_addr_list[0]
-is a pointer to the 16-byte binary address, and
-.Li h_addr_list[1]
-is a
-.Dv NULL
-pointer.
-.Pp
-It is an error when
-.Ar name
-is an IPv6 hex address and
-.Ar af
-equals
-.Dv AF_INET .
-The function's return value is a
-.Dv NULL
-pointer and the value pointed to by
-.Ar error_num
-equals
-.Dv HOST_NOT_FOUND .
-.Pp
-.Fn getipnodebyaddr
-takes almost the same argument as
-.Xr gethostbyaddr 3 ,
-but adds a pointer to return an error number.
-Additionally it takes care of IPv4-mapped IPv6 addresses,
-and IPv4-compatible IPv6 addresses.
-.Pp
-.Fn getipnodebyname
-and
-.Fn getipnodebyaddr
-dynamically allocate the structure to be returned to the caller.
-.Fn freehostent
-reclaims memory region allocated and returned by
-.Fn getipnodebyname
-or
-.Fn getipnodebyaddr .
-.\"
-.Sh FILES
-.Bl -tag -width /etc/nsswitch.conf -compact
-.It Pa /etc/hosts
-.It Pa /etc/nsswitch.conf
-.It Pa /etc/resolv.conf
-.El
-.\"
-.Sh DIAGNOSTICS
-.Fn getipnodebyname
-and
-.Fn getipnodebyaddr
-returns
-.Dv NULL
-on errors.
-The integer values pointed to by
-.Ar error_num
-may then be checked to see whether this is a temporary failure
-or an invalid or unknown host.
-The meanings of each error code are described in
-.Xr gethostbyname 3 .
-.\"
-.Sh SEE ALSO
-.Xr gethostbyaddr 3 ,
-.Xr gethostbyname 3 ,
-.Xr hosts 5 ,
-.Xr nsswitch.conf 5 ,
-.Xr services 5 ,
-.Xr hostname 7 ,
-.Xr named 8
-.Pp
-.Rs
-.%A R. Gilligan
-.%A S. Thomson
-.%A J. Bound
-.%A W. Stevens
-.%T Basic Socket Interface Extensions for IPv6
-.%R RFC2553
-.%D March 1999
-.Re
-.\"
-.Sh HISTORY
-The implementation first appeared in KAME advanced networking kit.
-.\"
-.Sh STANDARDS
-.Fn getipnodebyname
-and
-.Fn getipnodebyaddr
-are documented in
-.Dq Basic Socket Interface Extensions for IPv6
-(RFC2553).
-.\"
-.Sh BUGS
-.Fn getipnodebyname
-and
-.Fn getipnodebyaddr
-do not handle scoped IPv6 address properly.
-If you use these functions,
-your program will not be able to handle scoped IPv6 addresses.
-For IPv6 address manipulation,
-.Fn getaddrinfo 3
-and
-.Fn getnameinfo 3
-are recommended.
-.Pp
-The current implementation is not thread-safe.
-.Pp
-The text was shamelessly copied from RFC2553.
diff --git a/newlib/libc/sys/linux/net/getnameinfo.3 b/newlib/libc/sys/linux/net/getnameinfo.3
deleted file mode 100644
index d7afa2f40..000000000
--- a/newlib/libc/sys/linux/net/getnameinfo.3
+++ /dev/null
@@ -1,311 +0,0 @@
-.\" $FreeBSD: src/lib/libc/net/getnameinfo.3,v 1.11 2001/10/01 16:08:55 ru Exp $
-.\" $KAME: getnameinfo.3,v 1.17 2000/08/09 21:16:17 itojun 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
-.\"
-.Dd May 25, 1995
-.Dt GETNAMEINFO 3
-.Os
-.\"
-.Sh NAME
-.Nm getnameinfo
-.Nd address-to-nodename translation in protocol-independent manner
-.\"
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In netdb.h
-.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 defined for protocol-independent address-to-nodename translation.
-Its functionality is a reverse conversion of
-.Xr getaddrinfo 3 ,
-and implements similar functionality with
-.Xr gethostbyaddr 3
-and
-.Xr getservbyport 3
-in more sophisticated manner.
-.Pp
-This function looks up an IP address and port number provided by the
-caller in the DNS and system-specific database, and returns text
-strings for both in buffers provided by the caller.
-The function indicates successful completion by a zero return value;
-a non-zero return value indicates failure.
-.Pp
-The first argument,
-.Fa sa ,
-points to either a
-.Li sockaddr_in
-structure (for IPv4) or a
-.Li sockaddr_in6
-structure (for IPv6) that holds the IP address and port number.
-The
-.Fa salen
-argument gives the length of the
-.Li sockaddr_in
-or
-.Li sockaddr_in6
-structure.
-.Pp
-The function returns the nodename associated with the IP address in
-the buffer pointed to by the
-.Fa host
-argument.
-The caller provides the size of this buffer via the
-.Fa hostlen
-argument.
-The service name associated with the port number is returned in the buffer
-pointed to by
-.Fa serv ,
-and the
-.Fa servlen
-argument gives the length of this buffer.
-The caller specifies not to return either string by providing a zero
-value for the
-.Fa hostlen
-or
-.Fa servlen
-arguments.
-Otherwise, the caller must provide buffers large enough to hold the
-nodename and the service name, including the terminating null characters.
-.Pp
-Unfortunately most systems do not provide constants that specify the
-maximum size of either a fully-qualified domain name or a service name.
-Therefore to aid the application in allocating buffers for these two
-returned strings the following constants are defined in
-.Aq Pa netdb.h :
-.Bd -literal -offset
-#define NI_MAXHOST 1025
-#define NI_MAXSERV 32
-.Ed
-.Pp
-The first value is actually defined as the constant
-.Dv MAXDNAME
-in recent versions of BIND's
-.Aq Pa arpa/nameser.h
-header
-(older versions of BIND define this constant to be 256)
-and the second is a guess based on the services listed in the current
-Assigned Numbers RFC.
-.Pp
-The final argument is a
-.Fa flag
-that changes the default actions of this function.
-By default the fully-qualified domain name (FQDN) for the host is
-looked up in the DNS and returned.
-If the flag bit
-.Dv NI_NOFQDN
-is set, only the nodename portion of the FQDN is returned for local hosts.
-.Pp
-If the
-.Fa flag
-bit
-.Dv NI_NUMERICHOST
-is set, or if the host's name cannot be located in the DNS,
-the numeric form of the host's address is returned instead of its name
-(e.g., by calling
-.Fn inet_ntop
-instead of
-.Fn getnodebyaddr ) .
-If the
-.Fa flag
-bit
-.Dv NI_NAMEREQD
-is set, an error is returned if the host's name cannot be located in the DNS.
-.Pp
-If the flag bit
-.Dv NI_NUMERICSERV
-is set, the numeric form of the service address is returned
-(e.g., its port number)
-instead of its name.
-The two
-.Dv NI_NUMERICxxx
-flags are required to support the
-.Fl n
-flag that many commands provide.
-.Pp
-A fifth flag bit,
-.Dv NI_DGRAM ,
-specifies that the service is a datagram service, and causes
-.Fn getservbyport
-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 UDP and TCP.
-.Pp
-These
-.Dv NI_xxx
-flags are defined in
-.Aq Pa netdb.h .
-.\"
-.Sh EXTENSION
-The implementation allows experimental numeric IPv6 address notation with
-scope identifier.
-IPv6 link-local address will appear as string like
-.Dq Li fe80::1%ne0 ,
-if
-.Dv NI_WITHSCOPEID
-bit is enabled in
-.Ar flags
-argument.
-Refer to
-.Xr getaddrinfo 3
-for the notation.
-.\"
-.Sh EXAMPLES
-The following code tries to get numeric hostname, and service name,
-for given socket address.
-Observe that there is no hardcoded reference to 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");
- /*NOTREACHED*/
-}
-printf("host=%s, serv=%s\\n", hbuf, sbuf);
-.Ed
-.Pp
-The following version checks if the socket address has 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");
- /*NOTREACHED*/
-}
-printf("host=%s\\n", hbuf);
-.Ed
-.\"
-.Sh FILES
-.Bl -tag -width /etc/nsswitch.conf -compact
-.It Pa /etc/hosts
-.It Pa /etc/nsswitch.conf
-.It Pa /etc/resolv.conf
-.El
-.\"
-.Sh DIAGNOSTICS
-The function indicates successful completion by a zero return value;
-a non-zero return value indicates failure.
-Error codes are as below:
-.Bl -tag -width Er
-.It Bq Er EAI_AGAIN
-The name could not be resolved at this time.
-Future attempts may succeed.
-.It Bq Er EAI_BADFLAGS
-The flags had an invalid value.
-.It Bq Er EAI_FAIL
-A non-recoverable error occurred.
-.It Bq Er EAI_FAMILY
-The address family was not recognized or the address length was invalid
-for the specified family.
-.It Bq Er EAI_MEMORY
-There was a memory allocation failure.
-.It Bq Er EAI_NONAME
-The name does not resolve for the supplied parameters.
-.Dv NI_NAMEREQD
-is set and the host's name cannot be located,
-or both nodename and servname were null.
-.It Bq Er EAI_SYSTEM
-A system error occurred.
-The error code can be found in errno.
-.El
-.\"
-.Sh SEE ALSO
-.Xr getaddrinfo 3 ,
-.Xr gethostbyaddr 3 ,
-.Xr getservbyport 3 ,
-.Xr hosts 5 ,
-.Xr services 5 ,
-.Xr hostname 7 ,
-.Xr named 8
-.Pp
-.Rs
-.%A R. Gilligan
-.%A S. Thomson
-.%A J. Bound
-.%A W. Stevens
-.%T Basic Socket Interface Extensions for IPv6
-.%R RFC2553
-.%D March 1999
-.Re
-.Rs
-.%A Tatsuya Jinmei
-.%A Atsushi Onoe
-.%T "An Extension of Format for IPv6 Scoped Addresses"
-.%R internet draft
-.%N draft-ietf-ipngwg-scopedaddr-format-02.txt
-.%O work in progress material
-.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 HISTORY
-The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-.\"
-.Sh STANDARDS
-The
-.Fn getaddrinfo
-function is defined in
-.St -p1003.1g-2000 ,
-and documented in
-.Dq Basic Socket Interface Extensions for IPv6
-(RFC2553).
-.\"
-.Sh BUGS
-The current implementation is not thread-safe.
-.Pp
-The text was shamelessly copied from RFC2553.
-.Pp
-The type of the 2nd argument should be
-.Li socklen_t
-for RFC2553 conformance.
-The current code is based on pre-RFC2553 specification.
diff --git a/newlib/libc/sys/linux/net/getnameinfo.c b/newlib/libc/sys/linux/net/getnameinfo.c
index e2f9631c1..f79bc317f 100644
--- a/newlib/libc/sys/linux/net/getnameinfo.c
+++ b/newlib/libc/sys/linux/net/getnameinfo.c
@@ -1,372 +1,456 @@
-/* $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) NI_WITHSCOPEID when called with global address,
- * and sin6_scope_id filled
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
+/* The Inner Net License, Version 2.00
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
+ The author(s) grant permission for redistribution and use in source and
+binary forms, with or without modification, of the software and documentation
+provided that the following conditions are met:
+
+0. If you receive a version of the software that is specifically labelled
+ as not being for redistribution (check the version message and/or README),
+ you are not permitted to redistribute that version of the software in any
+ way or form.
+1. All terms of the all other applicable copyrights and licenses must be
+ followed.
+2. Redistributions of source code must retain the authors' copyright
+ notice(s), this list of conditions, and the following disclaimer.
+3. Redistributions in binary form must reproduce the authors' copyright
+ notice(s), this list of conditions, and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+4. [The copyright holder has authorized the removal of this clause.]
+5. Neither the name(s) of the author(s) 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 ITS AUTHORS 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 AUTHORS 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.
+
+ If these license terms cause you a real problem, contact the author. */
+
+/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
+
+#include <alloca.h>
+#include <errno.h>
#include <netdb.h>
-#include <resolv.h>
+#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
-#include <stddef.h>
-#include <errno.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <sys/utsname.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include <libc-symbols.h>
+#include "local.h"
-#define SUCCESS 0
-#define ANY 0
-#define YES 1
-#define NO 0
-
-static 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)},
+#ifdef HAVE_LIBIDN
+# include <libidn/idna.h>
+extern int __idna_to_unicode_lzlz (const char *input, char **output,
+ int flags);
#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;
-};
+#ifndef min
+# define min(x,y) (((x) > (y)) ? (y) : (x))
+#endif /* min */
-#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
+libc_freeres_ptr (static char *domain);
-/* 2553bis: use EAI_xx for getnameinfo */
-#define ENI_NOSOCKET EAI_FAIL /*XXX*/
-#define ENI_NOSERVNAME EAI_NONAME
-#define ENI_NOHOSTNAME EAI_NONAME
-#define ENI_MEMORY EAI_MEMORY
-#define ENI_SYSTEM EAI_SYSTEM
-#define ENI_FAMILY EAI_FAMILY
-#define ENI_SALEN EAI_FAMILY
-int
-getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
- const struct sockaddr *sa;
- socklen_t salen;
- char *host;
- size_t hostlen;
- char *serv;
- size_t servlen;
- int flags;
+static char *
+internal_function
+nrl_domainname (void)
{
- struct afd *afd;
- struct servent *sp;
- struct hostent *hp;
- u_short port;
- int family, i;
- const char *addr;
- u_int32_t v4a;
- int h_error;
- char numserv[512];
- char numaddr[512];
-
- if (sa == NULL)
- return ENI_NOSOCKET;
-
- family = sa->sa_family;
- for (i = 0; afdl[i].a_af; i++)
- if (afdl[i].a_af == family) {
- afd = &afdl[i];
- goto found;
- }
- return ENI_FAMILY;
-
- found:
- if (salen != afd->a_socklen)
- return ENI_SALEN;
-
- /* 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: RFC2553 says that serv == NULL OR servlen == 0
- * means that the caller does not want the result.
- */
- } else {
- if (flags & NI_NUMERICSERV)
- sp = NULL;
- else {
- sp = getservbyport(port,
- (flags & NI_DGRAM) ? "udp" : "tcp");
- }
- if (sp) {
- if (strlen(sp->s_name) + 1 > servlen)
- return ENI_MEMORY;
- strcpy(serv, sp->s_name);
- } else {
- snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
- if (strlen(numserv) + 1 > servlen)
- return ENI_MEMORY;
- strcpy(serv, numserv);
- }
- }
+ static int not_first;
- 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:
+ if (! not_first)
+ {
+ __libc_lock_define_initialized (static, lock);
+ __libc_lock_lock (lock);
+
+ if (! not_first)
+ {
+ char *c;
+ struct hostent *h, th;
+ size_t tmpbuflen = 1024;
+ char *tmpbuf = alloca (tmpbuflen);
+ int herror;
+
+ not_first = 1;
+
+ while (__gethostbyname_r ("localhost", &th, tmpbuf, tmpbuflen, &h,
+ &herror))
{
- 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;
- }
- }
+ if (herror == NETDB_INTERNAL && errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+ else
break;
-#endif
- }
- if (host == NULL || hostlen == 0) {
- /*
- * do nothing in this case.
- * in case you are wondering if "&&" is more correct than
- * "||" here: RFC2553 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 ENI_NOHOSTNAME;
-
- switch(afd->a_af) {
-#ifdef INET6
- case AF_INET6:
+ }
+
+ if (h && (c = strchr (h->h_name, '.')))
+ domain = strdup (++c);
+ else
+ {
+ /* The name contains no domain information. Use the name
+ now to get more information. */
+ while (__gethostname (tmpbuf, tmpbuflen))
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+
+ if ((c = strchr (tmpbuf, '.')))
+ domain = strdup (++c);
+ else
{
- int error;
+ /* We need to preserve the hostname. */
+ const char *hstname = alloca (strlen (tmpbuf) + 1);
+ strcpy (hstname, tmpbuf);
- 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 ENI_SYSTEM;
- numaddrlen = strlen(numaddr);
- if (numaddrlen + 1 > hostlen) /* don't forget terminator */
- return ENI_MEMORY;
- strcpy(host, numaddr);
+ while (__gethostbyname_r (hstname, &th, tmpbuf, tmpbuflen,
+ &h, &herror))
+ {
+ if (herror == NETDB_INTERNAL && errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
+ 2 * tmpbuflen);
+ else
break;
- }
- } else {
- hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
-
- 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) {
- freehostent(hp);
- return ENI_MEMORY;
- }
- strcpy(host, hp->h_name);
- freehostent(hp);
- } else {
- if (flags & NI_NAMEREQD)
- return ENI_NOHOSTNAME;
- 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 ENI_SYSTEM;
- break;
+ if (h && (c = strchr(h->h_name, '.')))
+ domain = strdup (++c);
+ else
+ {
+ struct in_addr in_addr;
+
+ in_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+ while (__gethostbyaddr_r ((const char *) &in_addr,
+ sizeof (struct in_addr),
+ AF_INET, &th, tmpbuf,
+ tmpbuflen, &h, &herror))
+ {
+ if (herror == NETDB_INTERNAL && errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
+ 2 * tmpbuflen);
+ else
+ break;
}
+
+ if (h && (c = strchr (h->h_name, '.')))
+ domain = strdup (++c);
+ }
}
+ }
}
- return SUCCESS;
-}
-#ifdef INET6
-static int
-ip6_parsenumeric(sa, addr, host, hostlen, flags)
- const struct sockaddr *sa;
- const char *addr;
- char *host;
- size_t hostlen;
- int flags;
+ __libc_lock_unlock (lock);
+ }
+
+ return domain;
+};
+
+
+int
+getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
+ socklen_t hostlen, char *serv, socklen_t servlen,
+ unsigned int flags)
{
- int numaddrlen;
- char numaddr[512];
-
- if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr))
- == NULL)
- return ENI_SYSTEM;
-
- numaddrlen = strlen(numaddr);
- if (numaddrlen + 1 > hostlen) /* don't forget terminator */
- return ENI_MEMORY;
- strcpy(host, numaddr);
-
-#ifdef NI_WITHSCOPEID
- if (
-#ifdef DONT_OPAQUE_SCOPEID
- (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr) ||
- IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) &&
+ int serrno = errno;
+ int tmpbuflen = 1024;
+ int herrno;
+ char *tmpbuf = alloca (tmpbuflen);
+ struct hostent th;
+ int ok = 0;
+
+ if (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV|NI_NOFQDN|NI_NAMEREQD|NI_DGRAM
+#ifdef HAVE_LIBIDN
+ |NI_IDN|NI_IDN_ALLOW_UNASSIGNED|NI_IDN_USE_STD3_ASCII_RULES
#endif
- ((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
-#ifndef ALWAYS_WITHSCOPE
- if (flags & NI_WITHSCOPEID)
-#endif /* !ALWAYS_WITHSCOPE */
- {
- char scopebuf[MAXHOSTNAMELEN];
- int scopelen;
-
- /* ip6_sa2str never fails */
- scopelen = ip6_sa2str((const struct sockaddr_in6 *)sa,
- scopebuf, sizeof(scopebuf),
- flags);
- if (scopelen + 1 + numaddrlen + 1 > hostlen)
- return ENI_MEMORY;
- /*
- * construct <numeric-addr><delim><scopeid>
- */
- memcpy(host + numaddrlen + 1, scopebuf,
- scopelen);
- host[numaddrlen] = SCOPE_DELIMITER;
- host[numaddrlen + 1 + scopelen] = '\0';
- }
- }
-#endif /* NI_WITHSCOPEID */
+ ))
+ return EAI_BADFLAGS;
- return 0;
-}
+ if (sa == NULL || addrlen < sizeof (sa_family_t))
+ return EAI_FAMILY;
-/* ARGSUSED */
-static int
-ip6_sa2str(sa6, buf, bufsiz, flags)
- const struct sockaddr_in6 *sa6;
- char *buf;
- size_t bufsiz;
- int flags;
-{
- unsigned int ifindex = (unsigned int)sa6->sin6_scope_id;
- const struct in6_addr *a6 = &sa6->sin6_addr;
+ switch (sa->sa_family)
+ {
+ case AF_LOCAL:
+ if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
+ return EAI_FAMILY;
+ break;
+ case AF_INET:
+ if (addrlen < sizeof (struct sockaddr_in))
+ return EAI_FAMILY;
+ break;
+ case AF_INET6:
+ if (addrlen < sizeof (struct sockaddr_in6))
+ return EAI_FAMILY;
+ break;
+ default:
+ return EAI_FAMILY;
+ }
-#ifdef NI_NUMERICSCOPE
- if (flags & NI_NUMERICSCOPE) {
- return(snprintf(buf, bufsiz, "%d", sa6->sin6_scope_id));
- }
+ if (host != NULL && hostlen > 0)
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ case AF_INET6:
+ if (!(flags & NI_NUMERICHOST))
+ {
+ struct hostent *h = NULL;
+ if (h == NULL)
+ {
+ if (sa->sa_family == AF_INET6)
+ {
+ while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
+ sizeof(struct in6_addr),
+ AF_INET6, &th, tmpbuf, tmpbuflen,
+ &h, &herrno))
+ {
+ if (herrno == NETDB_INTERNAL)
+ {
+ if (errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
+ 2 * tmpbuflen);
+ else
+ {
+ h_errno = (herrno);
+ errno = (serrno);
+ return EAI_SYSTEM;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
+ sizeof(struct in_addr), AF_INET,
+ &th, tmpbuf, tmpbuflen,
+ &h, &herrno))
+ {
+ if (errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
+ 2 * tmpbuflen);
+ else
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if (h)
+ {
+ char *c;
+ if ((flags & NI_NOFQDN)
+ && (c = nrl_domainname ())
+ && (c = strstr (h->h_name, c))
+ && (c != h->h_name) && (*(--c) == '.'))
+ /* Terminate the string after the prefix. */
+ *c = '\0';
+
+#ifdef HAVE_LIBIDN
+ /* If requested, convert from the IDN format. */
+ if (flags & NI_IDN)
+ {
+ int idn_flags = 0;
+ if (flags & NI_IDN_ALLOW_UNASSIGNED)
+ idn_flags |= IDNA_ALLOW_UNASSIGNED;
+ if (flags & NI_IDN_USE_STD3_ASCII_RULES)
+ idn_flags |= IDNA_USE_STD3_ASCII_RULES;
+
+ char *out;
+ int rc = __idna_to_unicode_lzlz (h->h_name, &out,
+ idn_flags);
+ if (rc != IDNA_SUCCESS)
+ {
+ if (rc == IDNA_MALLOC_ERROR)
+ return EAI_MEMORY;
+ if (rc == IDNA_DLOPEN_ERROR)
+ return EAI_SYSTEM;
+ return EAI_IDN_ENCODE;
+ }
+
+ if (out != h->h_name)
+ {
+ h->h_name = strdupa (out);
+ free (out);
+ }
+ }
#endif
- /* if_indextoname() does not take buffer size. not a good api... */
- if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
- bufsiz >= IF_NAMESIZE) {
- char *p = if_indextoname(ifindex, buf);
- if (p) {
- return(strlen(p));
- }
- }
+ size_t len = strlen (h->h_name) + 1;
+ if (len > hostlen)
+ return EAI_OVERFLOW;
+
+ memcpy (host, h->h_name, len);
+
+ ok = 1;
+ }
+ }
+
+ if (!ok)
+ {
+ if (flags & NI_NAMEREQD)
+ {
+ __set_errno (serrno);
+ return EAI_NONAME;
+ }
+ else
+ {
+ const char *c;
+ if (sa->sa_family == AF_INET6)
+ {
+ const struct sockaddr_in6 *sin6p;
+ uint32_t scopeid;
+
+ sin6p = (const struct sockaddr_in6 *) sa;
+
+ c = inet_ntop (AF_INET6,
+ (const void *) &sin6p->sin6_addr, host, hostlen);
+ scopeid = sin6p->sin6_scope_id;
+ if (scopeid != 0)
+ {
+ /* Buffer is >= IFNAMSIZ+1. */
+ char scopebuf[IFNAMSIZ + 1];
+ char *scopeptr;
+ int ni_numericscope = 0;
+ size_t real_hostlen = strnlen (host, hostlen);
+ size_t scopelen = 0;
+
+ scopebuf[0] = SCOPE_DELIMITER;
+ scopebuf[1] = '\0';
+ scopeptr = &scopebuf[1];
+
+ if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
+ || IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr))
+ {
+ if (if_indextoname (scopeid, scopeptr) == NULL)
+ ++ni_numericscope;
+ else
+ scopelen = strlen (scopebuf);
+ }
+ else
+ ++ni_numericscope;
+
+ if (ni_numericscope)
+ scopelen = 1 + snprintf (scopeptr,
+ (scopebuf
+ + sizeof scopebuf
+ - scopeptr),
+ "%u", scopeid);
+
+ if (real_hostlen + scopelen + 1 > hostlen)
+ /* XXX We should not fail here. Simply enlarge
+ the buffer or return with out of memory. */
+ return EAI_SYSTEM;
+ memcpy (host + real_hostlen, scopebuf, scopelen + 1);
+ }
+ }
+ else
+ c = inet_ntop (AF_INET,
+ (const void *) &(((const struct sockaddr_in *) sa)->sin_addr),
+ host, hostlen);
+ if (c == NULL)
+ {
+ __set_errno (serrno);
+ return EAI_SYSTEM;
+ }
+ }
+ ok = 1;
+ }
+ break;
+
+ case AF_LOCAL:
+ if (!(flags & NI_NUMERICHOST))
+ {
+ struct utsname utsname;
+
+ if (!uname (&utsname))
+ {
+ strncpy (host, utsname.nodename, hostlen);
+ break;
+ };
+ };
+
+ if (flags & NI_NAMEREQD)
+ {
+ __set_errno (serrno);
+ return EAI_NONAME;
+ }
+
+ strncpy (host, "localhost", hostlen);
+ break;
+
+ default:
+ return EAI_FAMILY;
+ }
+
+ if (serv && (servlen > 0))
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ case AF_INET6:
+ if (!(flags & NI_NUMERICSERV))
+ {
+ struct servent *s, ts;
+ while (__getservbyport_r (((const struct sockaddr_in *) sa)->sin_port,
+ ((flags & NI_DGRAM) ? "udp" : "tcp"),
+ &ts, tmpbuf, tmpbuflen, &s))
+ {
+ if (herrno == NETDB_INTERNAL)
+ {
+ if (errno == ERANGE)
+ tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
+ 2 * tmpbuflen);
+ else
+ {
+ __set_errno (serrno);
+ return EAI_SYSTEM;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ if (s)
+ {
+ strncpy (serv, s->s_name, servlen);
+ break;
+ }
+ }
+
+ if (snprintf (serv, servlen, "%d",
+ ntohs (((const struct sockaddr_in *) sa)->sin_port))
+ + 1 > servlen)
+ return EAI_OVERFLOW;
+
+ break;
+
+ case AF_LOCAL:
+ strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
+ break;
+ }
- /* last resort */
- return(snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id));
+ if (host && (hostlen > 0))
+ host[hostlen-1] = 0;
+ if (serv && (servlen > 0))
+ serv[servlen-1] = 0;
+ errno = serrno;
+ return 0;
}
-#endif /* INET6 */
+libc_hidden_def (getnameinfo)
diff --git a/newlib/libc/sys/linux/net/getnetbyad.c b/newlib/libc/sys/linux/net/getnetbyad.c
new file mode 100644
index 000000000..73ae203e8
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetbyad.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+#include <stdint.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define FUNCTION_NAME getnetbyaddr
+#define DATABASE_NAME networks
+#define ADD_PARAMS uint32_t net, int type
+#define ADD_VARIABLES net, type
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getnetbyad_r.c b/newlib/libc/sys/linux/net/getnetbyad_r.c
new file mode 100644
index 000000000..7af3cb40b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetbyad_r.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+#include <stdint.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define FUNCTION_NAME getnetbyaddr
+#define DATABASE_NAME networks
+#define ADD_PARAMS uint32_t net, int type
+#define ADD_VARIABLES net, type
+#define NEED__RES 1
+#define NEED_H_ERRNO 1
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getnetbydns.c b/newlib/libc/sys/linux/net/getnetbydns.c
deleted file mode 100644
index 2cc4fce54..000000000
--- a/newlib/libc/sys/linux/net/getnetbydns.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*-
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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--
- */
-/* Portions 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <stdio.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-
-#include "res_config.h"
-
-extern int h_errno;
-
-#define BYADDR 0
-#define BYNAME 1
-#define MAXALIASES 35
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-typedef union {
- long al;
- char ac;
-} align;
-
-static struct netent *
-getnetanswer(answer, anslen, net_i)
- querybuf *answer;
- int anslen;
- int net_i;
-{
-
- HEADER *hp;
- u_char *cp;
- int n;
- u_char *eom;
- int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
- char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];
- char *in, *st, *pauxt, *bp, **ap;
- char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
-static struct netent net_entry;
-static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
-
- /*
- * 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;
- buflen = 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)
- cp += __dn_skipname(cp, eom) + 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, buflen);
- if ((n < 0) || !res_dnok(bp))
- break;
- cp += n;
- ans[0] = '\0';
- (void)strncpy(&ans[0], bp, sizeof(ans) - 1);
- ans[sizeof(ans) - 1] = '\0';
- 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, buflen);
- if ((n < 0) || !res_hnok(bp)) {
- cp += n;
- return (NULL);
- }
- cp += n;
- *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:
- in = *net_entry.n_aliases;
- net_entry.n_name = &ans[0];
- aux2[0] = '\0';
- for (i = 0; i < 4; i++) {
- for (st = in, nchar = 0;
- *st != '.';
- st++, nchar++)
- ;
- if (nchar != 1 || *in != '0' || flag) {
- flag = 1;
- (void)strncpy(paux1,
- (i==0) ? in : in-1,
- (i==0) ?nchar : nchar+1);
- paux1[(i==0) ? nchar : nchar+1] = '\0';
- pauxt = paux2;
- paux2 = strcat(paux1, paux2);
- paux1 = pauxt;
- }
- in = ++st;
- }
- net_entry.n_net = inet_network(paux2);
- break;
- }
- net_entry.n_aliases++;
- return (&net_entry);
- }
- h_errno = TRY_AGAIN;
- return (NULL);
-}
-
-int
-_dns_getnetbyaddr(void *rval, void *cb_data, va_list ap)
-{
- unsigned long net;
- int net_type;
- unsigned int netbr[4];
- int nn, anslen;
- querybuf buf;
- char qbuf[MAXDNAME];
- unsigned long net2;
- struct netent *net_entry;
-
- net = va_arg(ap, unsigned long);
- net_type = va_arg(ap, int);
-
- *(struct netent **)rval = NULL;
-
- if (net_type != AF_INET)
- return NS_UNAVAIL;
-
- for (nn = 4, net2 = net; net2; net2 >>= 8)
- netbr[--nn] = net2 & 0xff;
- switch (nn) {
- case 3: /* Class A */
- sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
- break;
- case 2: /* Class B */
- sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
- break;
- case 1: /* Class C */
- sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
- netbr[1]);
- break;
- case 0: /* Class D - E */
- sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
- netbr[1], netbr[0]);
- break;
- }
- anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
- if (anslen < 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("res_query failed\n");
-#endif
- return NS_UNAVAIL;
- }
- net_entry = getnetanswer(&buf, anslen, BYADDR);
- if (net_entry) {
- 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;
- *(struct netent **)rval = net_entry;
- return NS_SUCCESS;
- }
- return NS_NOTFOUND;
-}
-
-int
-_dns_getnetbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *net;
- int anslen;
- querybuf buf;
- char qbuf[MAXDNAME];
-
- net = va_arg(ap, const char *);
-
- *(struct netent**)rval = NULL;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return NS_UNAVAIL;
- }
- strncpy(qbuf, net, sizeof(qbuf) - 1);
- qbuf[sizeof(qbuf) - 1] = '\0';
- anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
- if (anslen < 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("res_query failed\n");
-#endif
- return NS_UNAVAIL;
- }
- *(struct netent**)rval = getnetanswer(&buf, anslen, BYNAME);
- return (*(struct netent**)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-void
-_setnetdnsent(stayopen)
- int stayopen;
-{
- if (stayopen)
- _res.options |= RES_STAYOPEN | RES_USEVC;
-}
-
-void
-_endnetdnsent()
-{
- _res.options &= ~(RES_STAYOPEN | RES_USEVC);
- res_close();
-}
diff --git a/newlib/libc/sys/linux/net/getnetbyht.c b/newlib/libc/sys/linux/net/getnetbyht.c
deleted file mode 100644
index 8e4a16f1c..000000000
--- a/newlib/libc/sys/linux/net/getnetbyht.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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 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.
- *
- * from getnetent.c 1.1 (Coimbra) 93/06/02
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-
-#define MAXALIASES 35
-
-static FILE *netf;
-static char line[BUFSIZ+1];
-static struct netent net;
-static char *net_aliases[MAXALIASES];
-static int _net_stayopen;
-
-void
-_setnethtent(f)
- int f;
-{
-
- if (netf == NULL)
- netf = fopen(_PATH_NETWORKS, "r" );
- else
- rewind(netf);
- _net_stayopen |= f;
-}
-
-void
-_endnethtent()
-{
-
- if (netf) {
- fclose(netf);
- netf = NULL;
- }
- _net_stayopen = 0;
-}
-
-struct netent *
-getnetent()
-{
- char *p;
- char *cp, **q;
-
- if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
- return (NULL);
-again:
- p = fgets(line, sizeof line, netf);
- if (p == NULL)
- return (NULL);
- if (*p == '#')
- goto again;
- cp = strpbrk(p, "#\n");
- if (cp == NULL)
- goto again;
- *cp = '\0';
- net.n_name = p;
- 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;
- if (p != NULL)
- cp = p;
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &net_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- return (&net);
-}
-
-int
-_ht_getnetbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- struct netent *p;
- char **cp;
-
- name = va_arg(ap, const char *);
-
- 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();
- *(struct netent **)rval = p;
- return (p != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-int
-_ht_getnetbyaddr(void *rval, void *cb_data, va_list ap)
-{
- unsigned long net;
- int type;
- struct netent *p;
-
- net = va_arg(ap, unsigned long);
- type = va_arg(ap, int);
-
- setnetent(_net_stayopen);
- while ( (p = getnetent()) )
- if (p->n_addrtype == type && p->n_net == net)
- break;
- if (!_net_stayopen)
- endnetent();
- *(struct netent **)rval = p;
- return (p != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
diff --git a/newlib/libc/sys/linux/net/getnetbynis.c b/newlib/libc/sys/linux/net/getnetbynis.c
deleted file mode 100644
index 6d222e60f..000000000
--- a/newlib/libc/sys/linux/net/getnetbynis.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/*-
- * Copyright (c) 1994, Garrett Wollman
- *
- * 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 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 <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-#include <arpa/nameser.h>
-#ifdef YP
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-#endif
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-
-#ifdef YP
-static char *host_aliases[MAXALIASES];
-
-static struct netent *
-_getnetbynis(const char *name, char *map, int af)
-{
- char *cp, **q;
- static char *result;
- int resultlen;
- static struct netent h;
- static char *domain = (char *)NULL;
- static char ypbuf[YPMAXRECORD + 2];
-
- switch(af) {
- case AF_INET:
- break;
- default:
- case AF_INET6:
- errno = EAFNOSUPPORT;
- return NULL;
- }
-
- if (domain == (char *)NULL)
- if (yp_get_default_domain (&domain))
- return (NULL);
-
- if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
- return (NULL);
-
- bcopy((char *)result, (char *)&ypbuf, resultlen);
- ypbuf[resultlen] = '\0';
- free(result);
- result = (char *)&ypbuf;
-
- if ((cp = index(result, '\n')))
- *cp = '\0';
-
- cp = strpbrk(result, " \t");
- *cp++ = '\0';
- h.n_name = result;
-
- while (*cp == ' ' || *cp == '\t')
- cp++;
-
- h.n_net = inet_network(cp);
- h.n_addrtype = AF_INET;
-
- q = h.n_aliases = host_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &host_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- return (&h);
-}
-#endif /* YP */
-
-int
-_nis_getnetbyname(void *rval, void *cb_data, va_list ap)
-{
-#ifdef YP
- const char *name;
-
- name = va_arg(ap, const char *);
-
- *(struct netent **)rval = _getnetbynis(name, "networks.byname", AF_INET);
- return (*(struct netent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-#else
- return NS_UNAVAIL;
-#endif
-
-}
-
-int
-_nis_getnetbyaddr(void *rval, void *cb_data, va_list ap)
-{
-#ifdef YP
- unsigned long addr;
- int af;
- char *str, *cp;
- unsigned long net2;
- int nn;
- unsigned int netbr[4];
- char buf[MAXDNAME];
-
- addr = va_arg(ap, unsigned long);
- af = va_arg(ap, int);
-
- *(struct netent **)rval = NULL;
-
- if (af != AF_INET) {
- errno = EAFNOSUPPORT;
- return NS_UNAVAIL;
- }
-
- for (nn = 4, net2 = addr; net2; net2 >>= 8) {
- netbr[--nn] = net2 & 0xff;
- }
-
- switch (nn) {
- case 3: /* Class A */
- sprintf(buf, "%u", netbr[3]);
- break;
- case 2: /* Class B */
- sprintf(buf, "%u.%u", netbr[2], netbr[3]);
- break;
- case 1: /* Class C */
- sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
- break;
- case 0: /* Class D - E */
- sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
- netbr[2], netbr[3]);
- break;
- }
-
- str = (char *)&buf;
- cp = str + (strlen(str) - 2);
-
- while(!strcmp(cp, ".0")) {
- *cp = '\0';
- cp = str + (strlen(str) - 2);
- }
-
- *(struct netent **)rval = _getnetbynis(str, "networks.byaddr", af);
- return (*(struct netent**)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-#else
- return NS_UNAVAIL;
-#endif /* YP */
-}
diff --git a/newlib/libc/sys/linux/net/getnetbynm.c b/newlib/libc/sys/linux/net/getnetbynm.c
new file mode 100644
index 000000000..cacf14899
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetbynm.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define FUNCTION_NAME getnetbyname
+#define DATABASE_NAME networks
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getnetbynm_r.c b/newlib/libc/sys/linux/net/getnetbynm_r.c
new file mode 100644
index 000000000..3acd2d3e6
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetbynm_r.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define FUNCTION_NAME getnetbyname
+#define DATABASE_NAME networks
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define NEED__RES 1
+#define NEED_H_ERRNO 1
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getnetent.3 b/newlib/libc/sys/linux/net/getnetent.3
deleted file mode 100644
index 6801e9707..000000000
--- a/newlib/libc/sys/linux/net/getnetent.3
+++ /dev/null
@@ -1,172 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.17 2002/01/14 16:59:01 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt GETNETENT 3
-.Os
-.Sh NAME
-.Nm getnetent ,
-.Nm getnetbyaddr ,
-.Nm getnetbyname ,
-.Nm setnetent ,
-.Nm endnetent
-.Nd get network entry
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In netdb.h
-.Ft struct netent *
-.Fn getnetent void
-.Ft struct netent *
-.Fn getnetbyname "const char *name"
-.Ft struct netent *
-.Fn getnetbyaddr "unsigned long 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 describing an internet network.
-This structure contains either the information obtained
-from the nameserver,
-.Xr named 8 ,
-broken-out fields of a line in the network data base
-.Pa /etc/networks ,
-or entries supplied by the
-.Xr yp 8
-system. The order of the lookups is controlled by the
-`networks' entry in
-.Xr nsswitch.conf 5 .
-.Pp
-.Bd -literal -offset indent
-struct netent {
- char *n_name; /* official name of net */
- char **n_aliases; /* alias list */
- int n_addrtype; /* net number type */
- unsigned long 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 zero terminated list of alternate names for the network.
-.It Fa n_addrtype
-The type of the network number returned; currently only 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 data base 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
-function
-and
-.Fn getnetbyaddr
-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.
-The
-.Fa type
-must be
-.Dv AF_INET .
-Network numbers are supplied in host order.
-.Sh FILES
-.Bl -tag -width /etc/nsswitch.conf -compact
-.It Pa /etc/networks
-.It Pa /etc/nsswitch.conf
-.It Pa /etc/resolv.conf
-.El
-.Sh DIAGNOSTICS
-Null pointer
-(0) returned on
-.Dv EOF
-or error.
-.Sh SEE ALSO
-.Xr networks 5
-.Pp
-.%T RFC 1101
-.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 probably
-naive.
diff --git a/newlib/libc/sys/linux/net/getnetent.c b/newlib/libc/sys/linux/net/getnetent.c
new file mode 100644
index 000000000..b42ef165e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetent.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define GETFUNC_NAME getnetent
+#define BUFLEN 1024
+#define NEED_H_ERRNO 1
+
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/getnetent_r.c b/newlib/libc/sys/linux/net/getnetent_r.c
new file mode 100644
index 000000000..bb698196c
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetent_r.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct netent
+#define SETFUNC_NAME setnetent
+#define GETFUNC_NAME getnetent
+#define ENDFUNC_NAME endnetent
+#define DATABASE_NAME networks
+#define STAYOPEN int stayopen
+#define STAYOPEN_VAR stayopen
+#define NEED__RES 1
+#define NEED_H_ERRNO 1
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getnetgrent.c b/newlib/libc/sys/linux/net/getnetgrent.c
new file mode 100644
index 000000000..050af800f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetgrent.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include "libc-symbols.h"
+
+/* Static buffer for return value. We allocate it when needed. */
+libc_freeres_ptr (static char *buffer);
+/* All three strings should fit in a block of 1kB size. */
+#define BUFSIZE 1024
+
+
+
+static void
+allocate (void)
+{
+ buffer = (char *) malloc (BUFSIZE);
+}
+
+int
+getnetgrent (char **hostp, char **userp, char **domainp)
+{
+ __libc_once_define (static, once);
+ __libc_once (once, allocate);
+
+ if (buffer == NULL)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return __getnetgrent_r (hostp, userp, domainp, buffer, BUFSIZE);
+}
diff --git a/newlib/libc/sys/linux/net/getnetgrent_r.c b/newlib/libc/sys/linux/net/getnetgrent_r.c
new file mode 100644
index 000000000..ebc2ac5ea
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnetgrent_r.c
@@ -0,0 +1,446 @@
+/* Copyright (C) 1996,1997,1998,1999,2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+#include "netgroup.h"
+#include "nsswitch.h"
+#include "libc-symbols.h"
+
+
+/* Protect above variable against multiple uses at the same time. */
+__libc_lock_define_initialized (static, lock)
+
+/* The whole information for the set/get/endnetgrent functions are
+ kept in this structure. */
+static struct __netgrent dataset;
+
+/* The lookup function for the first entry of this service. */
+extern int __nss_netgroup_lookup (service_user **nip, const char *name,
+ void **fctp) internal_function;
+
+
+/* Set up NIP to run through the services. If ALL is zero, use NIP's
+ current location if it's not nil. Return nonzero if there are no
+ services (left). */
+static enum nss_status
+setup (void **fctp, const char *func_name, int all, service_user **nipp)
+{
+ /* Remember the first service_entry, it's always the same. */
+ static service_user *startp;
+ int no_more;
+
+ if (startp == NULL)
+ {
+ /* Executing this more than once at the same time must yield the
+ same result every time. So we need no locking. */
+ no_more = __nss_netgroup_lookup (nipp, func_name, fctp);
+ startp = no_more ? (service_user *) -1 : *nipp;
+ }
+ else if (startp == (service_user *) -1)
+ /* No services at all. */
+ return 1;
+ else
+ {
+ if (all || *nipp == NULL)
+ /* Reset to the beginning of the service list. */
+ *nipp = startp;
+ /* Look up the first function. */
+ no_more = __nss_lookup (nipp, func_name, fctp);
+ }
+ return no_more;
+}
+
+/* Free used memory. */
+static void
+free_memory (struct __netgrent *data)
+{
+ while (data->known_groups != NULL)
+ {
+ struct name_list *tmp = data->known_groups;
+ data->known_groups = data->known_groups->next;
+ free (tmp);
+ }
+
+ while (data->needed_groups != NULL)
+ {
+ struct name_list *tmp = data->needed_groups;
+ data->needed_groups = data->needed_groups->next;
+ free (tmp);
+ }
+}
+
+static int
+internal_function
+__internal_setnetgrent_reuse (const char *group, struct __netgrent *datap,
+ int *errnop)
+{
+ union
+ {
+ enum nss_status (*f) (const char *, struct __netgrent *);
+ void *ptr;
+ } fct;
+ enum nss_status status = NSS_STATUS_UNAVAIL;
+ struct name_list *new_elem;
+
+ /* Cycle through all the services and run their setnetgrent functions. */
+ int no_more = setup (&fct.ptr, "setnetgrent", 1, &datap->nip);
+ while (! no_more)
+ {
+ /* Ignore status, we force check in `__nss_next'. */
+ status = (*fct.f) (group, datap);
+
+ no_more = __nss_next (&datap->nip, "setnetgrent", &fct.ptr, status, 0);
+ }
+
+ /* Add the current group to the list of known groups. */
+ size_t group_len = strlen (group) + 1;
+ new_elem = (struct name_list *) malloc (sizeof (struct name_list)
+ + group_len);
+ if (new_elem == NULL)
+ {
+ *errnop = errno;
+ status = NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ new_elem->next = datap->known_groups;
+ memcpy (new_elem->name, group, group_len);
+ datap->known_groups = new_elem;
+ }
+
+ return status == NSS_STATUS_SUCCESS;
+}
+
+int internal_setnetgrent (const char *group, struct __netgrent *datap);
+libc_hidden_proto (internal_setnetgrent)
+
+int
+internal_setnetgrent (const char *group, struct __netgrent *datap)
+{
+ /* Free list of all netgroup names from last run. */
+ free_memory (datap);
+
+ return __internal_setnetgrent_reuse (group, datap, &errno);
+}
+libc_hidden_def (internal_setnetgrent)
+strong_alias (internal_setnetgrent, __internal_setnetgrent)
+
+int
+setnetgrent (const char *group)
+{
+ int result;
+
+ __libc_lock_lock (lock);
+
+ result = internal_setnetgrent (group, &dataset);
+
+ __libc_lock_unlock (lock);
+
+ return result;
+}
+
+
+void internal_endnetgrent (struct __netgrent *datap);
+libc_hidden_proto (internal_endnetgrent)
+
+void
+internal_endnetgrent (struct __netgrent *datap)
+{
+ service_user *old_nip;
+ union
+ {
+ enum nss_status (*f) (struct __netgrent *);
+ void *ptr;
+ } fct;
+
+ /* Remember which was the last used service. */
+ old_nip = datap->nip;
+
+ /* Cycle through all the services and run their endnetgrent functions. */
+ int no_more = setup (&fct.ptr, "endnetgrent", 1, &datap->nip);
+ while (! no_more)
+ {
+ /* Ignore status, we force check in `__nss_next'. */
+ (void) (*fct.f) (datap);
+
+ no_more = (datap->nip == old_nip
+ || __nss_next (&datap->nip, "endnetgrent", &fct.ptr, 0, 1));
+ }
+
+ /* Now free list of all netgroup names from last run. */
+ free_memory (datap);
+}
+libc_hidden_def (internal_endnetgrent)
+strong_alias (internal_endnetgrent, __internal_endnetgrent)
+
+
+void
+endnetgrent (void)
+{
+ __libc_lock_lock (lock);
+
+ internal_endnetgrent (&dataset);
+
+ __libc_lock_unlock (lock);
+}
+
+
+int internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
+ struct __netgrent *datap,
+ char *buffer, size_t buflen, int *errnop);
+libc_hidden_proto (internal_getnetgrent_r)
+
+int
+internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
+ struct __netgrent *datap,
+ char *buffer, size_t buflen, int *errnop)
+{
+ union
+ {
+ enum nss_status (*f) (struct __netgrent *, char *, size_t, int *);
+ void *ptr;
+ } fct;
+
+ /* Initialize status to return if no more functions are found. */
+ enum nss_status status = NSS_STATUS_NOTFOUND;
+
+ /* Run through available functions, starting with the same function last
+ run. We will repeat each function as long as it succeeds, and then go
+ on to the next service action. */
+ int no_more = setup (&fct.ptr, "getnetgrent_r", 0, &datap->nip);
+ while (! no_more)
+ {
+ status = (*fct.f) (datap, buffer, buflen, &errno);
+
+ if (status == NSS_STATUS_RETURN)
+ {
+ /* This was the last one for this group. Look at next group
+ if available. */
+ int found = 0;
+ while (datap->needed_groups != NULL && ! found)
+ {
+ struct name_list *tmp = datap->needed_groups;
+ datap->needed_groups = datap->needed_groups->next;
+ tmp->next = datap->known_groups;
+ datap->known_groups = tmp;
+
+ found = __internal_setnetgrent_reuse (datap->known_groups->name,
+ datap, errnop);
+ }
+
+ if (found)
+ continue;
+ }
+ else if (status == NSS_STATUS_SUCCESS && datap->type == group_val)
+ {
+ /* The last entry was a name of another netgroup. */
+ struct name_list *namep;
+
+ /* Ignore if we've seen the name before. */
+ for (namep = datap->known_groups; namep != NULL;
+ namep = namep->next)
+ if (strcmp (datap->val.group, namep->name) == 0)
+ break;
+ if (namep != NULL)
+ /* Really ignore. */
+ continue;
+
+ size_t group_len = strlen (datap->val.group) + 1;
+ namep = (struct name_list *) malloc (sizeof (struct name_list)
+ + group_len);
+ if (namep == NULL)
+ /* We are out of memory. */
+ status = NSS_STATUS_RETURN;
+ else
+ {
+ namep->next = datap->needed_groups;
+ memcpy (namep->name, datap->val.group, group_len);
+ datap->needed_groups = namep;
+ /* And get the next entry. */
+ continue;
+ }
+ }
+
+ no_more = __nss_next (&datap->nip, "getnetgrent_r", &fct.ptr, status, 0);
+ }
+
+ if (status == NSS_STATUS_SUCCESS)
+ {
+ *hostp = (char *) datap->val.triple.host;
+ *userp = (char *) datap->val.triple.user;
+ *domainp = (char *) datap->val.triple.domain;
+ }
+
+ return status == NSS_STATUS_SUCCESS ? 1 : 0;
+}
+libc_hidden_def (internal_getnetgrent_r)
+strong_alias (internal_getnetgrent_r, __internal_getnetgrent_r)
+
+/* The real entry point. */
+int
+__getnetgrent_r (char **hostp, char **userp, char **domainp,
+ char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_getnetgrent_r (hostp, userp, domainp, &dataset,
+ buffer, buflen, &errno);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+weak_alias (__getnetgrent_r, getnetgrent_r)
+
+/* Test whether given (host,user,domain) triple is in NETGROUP. */
+int
+innetgr (const char *netgroup, const char *host, const char *user,
+ const char *domain)
+{
+ union
+ {
+ int (*f) (const char *, struct __netgrent *);
+ void *ptr;
+ } setfct;
+ union
+ {
+ void (*f) (struct __netgrent *);
+ void *ptr;
+ } endfct;
+ union
+ {
+ int (*f) (struct __netgrent *, char *, size_t, int *);
+ void *ptr;
+ } getfct;
+ struct __netgrent entry;
+ int result = 0;
+ const char *current_group = netgroup;
+ int real_entry = 0;
+
+ memset (&entry, '\0', sizeof (entry));
+
+ /* Walk through the services until we found an answer or we shall
+ not work further. We can do some optimization here. Since all
+ services must provide the `setnetgrent' function we can do all
+ the work during one walk through the service list. */
+ while (1)
+ {
+ int no_more = setup (&setfct.ptr, "setnetgrent", 1, &entry.nip);
+ while (! no_more)
+ {
+ /* Open netgroup. */
+ enum nss_status status = (*setfct.f) (current_group, &entry);
+
+ if (status == NSS_STATUS_SUCCESS
+ && __nss_lookup (&entry.nip, "getnetgrent_r", &getfct.ptr) == 0)
+ {
+ char buffer[1024];
+
+ while ((*getfct.f) (&entry, buffer, sizeof buffer, &errno)
+ == NSS_STATUS_SUCCESS)
+ {
+ if (entry.type == group_val)
+ {
+ /* Make sure we haven't seen the name before. */
+ struct name_list *namep;
+
+ for (namep = entry.known_groups; namep != NULL;
+ namep = namep->next)
+ if (strcmp (entry.val.group, namep->name) == 0)
+ break;
+ if (namep == NULL
+ && strcmp (netgroup, entry.val.group) != 0)
+ {
+ size_t group_len = strlen (entry.val.group) + 1;
+ namep =
+ (struct name_list *) malloc (sizeof (*namep)
+ + group_len);
+ if (namep == NULL)
+ {
+ /* Out of memory, simply return. */
+ result = -1;
+ break;
+ }
+
+ namep->next = entry.needed_groups;
+ memcpy (namep->name, entry.val.group, group_len);
+ entry.needed_groups = namep;
+ }
+ }
+ else
+ {
+ real_entry = 1;
+
+ if ((entry.val.triple.host == NULL || host == NULL
+ || strcasecmp (entry.val.triple.host, host) == 0)
+ && (entry.val.triple.user == NULL || user == NULL
+ || strcmp (entry.val.triple.user, user) == 0)
+ && (entry.val.triple.domain == NULL || domain == NULL
+ || strcasecmp (entry.val.triple.domain,
+ domain) == 0))
+ {
+ result = 1;
+ break;
+ }
+ }
+ }
+
+ if (result != 0)
+ break;
+
+ /* If we found one service which does know the given
+ netgroup we don't try further. */
+ status = NSS_STATUS_RETURN;
+ }
+
+ /* Free all resources of the service. */
+ if (__nss_lookup (&entry.nip, "endnetgrent", &endfct.ptr) == 0)
+ (*endfct.f) (&entry);
+
+ /* Look for the next service. */
+ no_more = __nss_next (&entry.nip, "setnetgrent",
+ &setfct.ptr, status, 0);
+ }
+
+ if (result == 0 && entry.needed_groups != NULL)
+ {
+ struct name_list *tmp = entry.needed_groups;
+ entry.needed_groups = tmp->next;
+ tmp->next = entry.known_groups;
+ entry.known_groups = tmp;
+ current_group = entry.known_groups->name;
+ continue;
+ }
+
+ /* No way out. */
+ break;
+ }
+
+ /* Free the memory. */
+ free_memory (&entry);
+
+ return result;
+}
+libc_hidden_def (innetgr)
diff --git a/newlib/libc/sys/linux/net/getnetnamadr.c b/newlib/libc/sys/linux/net/getnetnamadr.c
deleted file mode 100644
index 180ab14e2..000000000
--- a/newlib/libc/sys/linux/net/getnetnamadr.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- * Copyright (c) 1994, Garrett Wollman
- *
- * 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 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 <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-
-extern int _ht_getnetbyname(void *, void *, va_list);
-extern int _dns_getnetbyname(void *, void *, va_list);
-extern int _nis_getnetbyname(void *, void *, va_list);
-extern int _ht_getnetbyaddr(void *, void *, va_list);
-extern int _dns_getnetbyaddr(void *, void *, va_list);
-extern int _nis_getnetbyaddr(void *, void *, va_list);
-
-/* Network lookup order if nsswitch.conf is broken or nonexistant */
-static const ns_src default_src[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { NSSRC_DNS, NS_SUCCESS },
- { 0 }
-};
-
-struct netent *
-getnetbyname(const char *name)
-{
- struct netent *hp = 0;
- int rval;
-
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_getnetbyname, NULL)
- { NSSRC_DNS, _dns_getnetbyname, NULL },
- NS_NIS_CB(_nis_getnetbyname, NULL) /* force -DHESIOD */
- { 0 }
- };
-
- rval = nsdispatch((void *)&hp, dtab, NSDB_NETWORKS, "getnetbyname",
- default_src, name);
-
- if (rval != NS_SUCCESS)
- return NULL;
- else
- return hp;
-}
-
-struct netent *
-getnetbyaddr(u_long addr, int af)
-{
- struct netent *hp = 0;
- int rval;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_ht_getnetbyaddr, NULL)
- { NSSRC_DNS, _dns_getnetbyaddr, NULL },
- NS_NIS_CB(_nis_getnetbyaddr, NULL) /* force -DHESIOD */
- { 0 }
- };
-
- rval = nsdispatch((void *)&hp, dtab, NSDB_NETWORKS, "getnetbyaddr",
- default_src, addr, af);
-
- if (rval != NS_SUCCESS)
- return NULL;
- else
- return hp;
-}
-
-void
-setnetent(stayopen)
- int stayopen;
-{
- _setnethtent(stayopen);
- _setnetdnsent(stayopen);
-}
-
-void
-endnetent()
-{
- _endnethtent();
- _endnetdnsent();
-}
diff --git a/newlib/libc/sys/linux/net/getnssent.c b/newlib/libc/sys/linux/net/getnssent.c
new file mode 100644
index 000000000..1f7573da7
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnssent.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include "nsswitch.h"
+
+void *
+__nss_getent (getent_r_function func, void **resbuf, char **buffer,
+ size_t buflen, size_t *buffer_size, int *h_errnop)
+{
+ void *result;
+
+ if (*buffer == NULL)
+ {
+ *buffer_size = buflen;
+ *buffer = malloc (*buffer_size);
+ }
+
+ while (buffer != NULL
+ && func (resbuf, *buffer, *buffer_size, &result, h_errnop) == ERANGE
+ && (h_errnop == NULL || *h_errnop == NETDB_INTERNAL))
+ {
+ char *new_buf;
+ *buffer_size *= 2;
+ new_buf = realloc (*buffer, *buffer_size);
+ if (new_buf == NULL)
+ {
+ /* We are out of memory. Free the current buffer so that the
+ process gets a chance for a normal termination. */
+ int save = errno;
+ free (*buffer);
+ __set_errno (save);
+ }
+ *buffer = new_buf;
+ }
+
+ if (*buffer == NULL)
+ result = NULL;
+
+ return result;
+}
diff --git a/newlib/libc/sys/linux/net/getnssent_r.c b/newlib/libc/sys/linux/net/getnssent_r.c
new file mode 100644
index 000000000..517f19d02
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getnssent_r.c
@@ -0,0 +1,218 @@
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <netdb.h>
+#include "nsswitch.h"
+
+/* Set up NIP to run through the services. If ALL is zero, use NIP's
+ current location if it's not nil. Return nonzero if there are no
+ services (left). */
+static int
+setup (const char *func_name, db_lookup_function lookup_fct,
+ void **fctp, service_user **nip, service_user **startp, int all)
+{
+ int no_more;
+ if (*startp == NULL)
+ {
+ no_more = lookup_fct (nip, func_name, fctp);
+ *startp = no_more ? (service_user *) -1l : *nip;
+ }
+ else if (*startp == (service_user *) -1l)
+ /* No services at all. */
+ return 1;
+ else
+ {
+ if (all || !*nip)
+ /* Reset to the beginning of the service list. */
+ *nip = *startp;
+ /* Look up the first function. */
+ no_more = __nss_lookup (nip, func_name, fctp);
+ }
+ return no_more;
+}
+
+void
+__nss_setent (const char *func_name, db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int stayopen, int *stayopen_tmp,
+ int res)
+{
+ union
+ {
+ setent_function f;
+ void *ptr;
+ } fct;
+ int no_more;
+
+ if (res && __res_maybe_init (&_res, 0) == -1)
+ {
+ h_errno = (NETDB_INTERNAL);
+ return;
+ }
+
+ /* Cycle through the services and run their `setXXent' functions until
+ we find an available service. */
+ no_more = setup (func_name, lookup_fct, &fct.ptr, nip,
+ startp, 1);
+ while (! no_more)
+ {
+ int is_last_nip = *nip == *last_nip;
+ enum nss_status status;
+
+ if (stayopen_tmp)
+ status = DL_CALL_FCT (fct.f, (*stayopen_tmp));
+ else
+ status = DL_CALL_FCT (fct.f, (0));
+
+ no_more = __nss_next (nip, func_name, &fct.ptr,
+ status, 0);
+ if (is_last_nip)
+ *last_nip = *nip;
+ }
+
+ if (stayopen_tmp)
+ *stayopen_tmp = stayopen;
+}
+
+
+void
+__nss_endent (const char *func_name, db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int res)
+{
+ union
+ {
+ endent_function f;
+ void *ptr;
+ } fct;
+ int no_more;
+
+ if (res && __res_maybe_init (&_res, 0) == -1)
+ {
+ h_errno = (NETDB_INTERNAL);
+ return;
+ }
+
+ /* Cycle through all the services and run their endXXent functions. */
+ no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1);
+ while (! no_more)
+ {
+ /* Ignore status, we force check in __NSS_NEXT. */
+ DL_CALL_FCT (fct.f, ());
+
+ if (*nip == *last_nip)
+ /* We have processed all services which were used. */
+ break;
+
+ no_more = __nss_next (nip, func_name, &fct.ptr, 0, 1);
+ }
+ *last_nip = *nip = NULL;
+}
+
+
+int
+__nss_getent_r (const char *getent_func_name,
+ const char *setent_func_name,
+ db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int *stayopen_tmp, int res,
+ void *resbuf, char *buffer, size_t buflen,
+ void **result, int *h_errnop)
+{
+ union
+ {
+ getent_function f;
+ void *ptr;
+ } fct;
+ int no_more;
+ enum nss_status status;
+
+ if (res && __res_maybe_init (&_res, 0) == -1)
+ {
+ *h_errnop = NETDB_INTERNAL;
+ *result = NULL;
+ return errno;
+ }
+
+ /* Initialize status to return if no more functions are found. */
+ status = NSS_STATUS_NOTFOUND;
+
+ /* Run through available functions, starting with the same function last
+ run. We will repeat each function as long as it succeeds, and then go
+ on to the next service action. */
+ no_more = setup (getent_func_name, lookup_fct, &fct.ptr, nip,
+ startp, 0);
+ while (! no_more)
+ {
+ int is_last_nip = *nip == *last_nip;
+
+ status = DL_CALL_FCT (fct.f,
+ (resbuf, buffer, buflen, &errno, &h_errno));
+
+ /* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
+ provided buffer is too small. In this case we should give
+ the user the possibility to enlarge the buffer and we should
+ not simply go on with the next service (even if the TRYAGAIN
+ action tells us so). */
+ if (status == NSS_STATUS_TRYAGAIN
+ && (h_errnop == NULL || *h_errnop == NETDB_INTERNAL)
+ && errno == ERANGE)
+ break;
+
+ do
+ {
+ no_more = __nss_next (nip, getent_func_name, &fct.ptr,
+ status, 0);
+
+ if (is_last_nip)
+ *last_nip = *nip;
+
+ if (! no_more)
+ {
+ /* Call the `setXXent' function. This wasn't done before. */
+ union
+ {
+ setent_function f;
+ void *ptr;
+ } sfct;
+
+ no_more = __nss_lookup (nip, setent_func_name,
+ &sfct.ptr);
+
+ if (! no_more)
+ {
+ if (stayopen_tmp)
+ status = DL_CALL_FCT (sfct.f, (*stayopen_tmp));
+ else
+ status = DL_CALL_FCT (sfct.f, (0));
+ }
+ else
+ status = NSS_STATUS_NOTFOUND;
+ }
+ }
+ while (! no_more && status != NSS_STATUS_SUCCESS);
+ }
+
+ *result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
+ return (status == NSS_STATUS_SUCCESS ? 0
+ : status != NSS_STATUS_TRYAGAIN ? ENOENT
+ /* h_errno functions only set errno if h_errno is NETDB_INTERNAL. */
+ : (h_errnop == NULL || *h_errnop == NETDB_INTERNAL) ? errno
+ : EAGAIN);
+}
diff --git a/newlib/libc/sys/linux/net/getproto.c b/newlib/libc/sys/linux/net/getproto.c
index 937c30732..750c1097f 100644
--- a/newlib/libc/sys/linux/net/getproto.c
+++ b/newlib/libc/sys/linux/net/getproto.c
@@ -1,57 +1,30 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
#include <netdb.h>
-extern int _proto_stayopen;
-struct protoent *
-getprotobynumber(proto)
- int proto;
-{
- struct protoent *p;
+#define LOOKUP_TYPE struct protoent
+#define FUNCTION_NAME getprotobynumber
+#define DATABASE_NAME protocols
+#define ADD_PARAMS int proto
+#define ADD_VARIABLES proto
+#define BUFLEN 1024
- setprotoent(_proto_stayopen);
- while ( (p = getprotoent()) )
- if (p->p_proto == proto)
- break;
- if (!_proto_stayopen)
- endprotoent();
- return (p);
-}
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getproto_r.c b/newlib/libc/sys/linux/net/getproto_r.c
new file mode 100644
index 000000000..486df1d4e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getproto_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct protoent
+#define FUNCTION_NAME getprotobynumber
+#define DATABASE_NAME protocols
+#define ADD_PARAMS int proto
+#define ADD_VARIABLES proto
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getprotoent.3 b/newlib/libc/sys/linux/net/getprotoent.3
deleted file mode 100644
index 18b56541b..000000000
--- a/newlib/libc/sys/linux/net/getprotoent.3
+++ /dev/null
@@ -1,149 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/getprotoent.3,v 1.8 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt GETPROTOENT 3
-.Os
-.Sh NAME
-.Nm getprotoent ,
-.Nm getprotobynumber ,
-.Nm getprotobyname ,
-.Nm setprotoent ,
-.Nm endprotoent
-.Nd get protocol entry
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In netdb.h
-.Ft struct protoent *
-.Fn getprotoent void
-.Ft struct protoent *
-.Fn getprotobyname "const char *name"
-.Ft struct protoent *
-.Fn getprotobynumber "int proto"
-.Ft void
-.Fn setprotoent "int stayopen"
-.Ft void
-.Fn endprotoent void
-.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 data base,
-.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 zero 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 net data base 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
-function
-and
-.Fn getprotobynumber
-sequentially search from the beginning
-of the file until a matching
-protocol name or
-protocol number is found,
-or until
-.Dv EOF
-is encountered.
-.Sh RETURN VALUES
-Null pointer
-(0) returned on
-.Dv EOF
-or error.
-.Sh FILES
-.Bl -tag -width /etc/protocols -compact
-.It Pa /etc/protocols
-.El
-.Sh SEE ALSO
-.Xr protocols 5
-.Sh HISTORY
-The
-.Fn getprotoent ,
-.Fn getprotobynumber ,
-.Fn getprotobyname ,
-.Fn setprotoent ,
-and
-.Fn endprotoent
-functions appeared in
-.Bx 4.2 .
-.Sh BUGS
-These 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/newlib/libc/sys/linux/net/getprotoent.c b/newlib/libc/sys/linux/net/getprotoent.c
deleted file mode 100644
index 422eeacea..000000000
--- a/newlib/libc/sys/linux/net/getprotoent.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define MAXALIASES 35
-
-static FILE *protof = NULL;
-static char line[BUFSIZ+1];
-static struct protoent proto;
-static char *proto_aliases[MAXALIASES];
-int _proto_stayopen;
-
-void
-setprotoent(f)
- int f;
-{
- if (protof == NULL)
- protof = fopen(_PATH_PROTOCOLS, "r" );
- else
- rewind(protof);
- _proto_stayopen |= f;
-}
-
-void
-endprotoent()
-{
- if (protof) {
- fclose(protof);
- protof = NULL;
- }
- _proto_stayopen = 0;
-}
-
-struct protoent *
-getprotoent()
-{
- char *p;
- char *cp, **q;
-
- if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
- return (NULL);
-again:
- if ((p = fgets(line, BUFSIZ, protof)) == NULL)
- return (NULL);
- if (*p == '#')
- goto again;
- cp = strpbrk(p, "#\n");
- if (cp == NULL)
- goto again;
- *cp = '\0';
- proto.p_name = p;
- 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';
- proto.p_proto = atoi(cp);
- q = proto.p_aliases = proto_aliases;
- if (p != NULL) {
- cp = p;
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &proto_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- }
- *q = NULL;
- return (&proto);
-}
diff --git a/newlib/libc/sys/linux/net/getprotoname.c b/newlib/libc/sys/linux/net/getprotoname.c
deleted file mode 100644
index f25883fe8..000000000
--- a/newlib/libc/sys/linux/net/getprotoname.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <netdb.h>
-#include <string.h>
-
-extern int _proto_stayopen;
-
-struct protoent *
-getprotobyname(name)
- const char *name;
-{
- struct protoent *p;
- char **cp;
-
- setprotoent(_proto_stayopen);
- while ( (p = getprotoent()) ) {
- if (strcmp(p->p_name, name) == 0)
- break;
- for (cp = p->p_aliases; *cp != 0; cp++)
- if (strcmp(*cp, name) == 0)
- goto found;
- }
-found:
- if (!_proto_stayopen)
- endprotoent();
- return (p);
-}
diff --git a/newlib/libc/sys/linux/net/getprtent.c b/newlib/libc/sys/linux/net/getprtent.c
new file mode 100644
index 000000000..16a7e57bc
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getprtent.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct protoent
+#define GETFUNC_NAME getprotoent
+#define BUFLEN 1024
+
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/getprtent_r.c b/newlib/libc/sys/linux/net/getprtent_r.c
new file mode 100644
index 000000000..2f0ca473b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getprtent_r.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct protoent
+#define SETFUNC_NAME setprotoent
+#define GETFUNC_NAME getprotoent
+#define ENDFUNC_NAME endprotoent
+#define DATABASE_NAME protocols
+#define STAYOPEN int stayopen
+#define STAYOPEN_VAR stayopen
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getprtname.c b/newlib/libc/sys/linux/net/getprtname.c
new file mode 100644
index 000000000..1222daeea
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getprtname.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct protoent
+#define FUNCTION_NAME getprotobyname
+#define DATABASE_NAME protocols
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getprtname_r.c b/newlib/libc/sys/linux/net/getprtname_r.c
new file mode 100644
index 000000000..b0dee382e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getprtname_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct protoent
+#define FUNCTION_NAME getprotobyname
+#define DATABASE_NAME protocols
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getrpcbyname.c b/newlib/libc/sys/linux/net/getrpcbyname.c
new file mode 100644
index 000000000..266967aed
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcbyname.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define FUNCTION_NAME getrpcbyname
+#define DATABASE_NAME rpc
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getrpcbyname_r.c b/newlib/libc/sys/linux/net/getrpcbyname_r.c
new file mode 100644
index 000000000..3e7c2df74
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcbyname_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define FUNCTION_NAME getrpcbyname
+#define DATABASE_NAME rpc
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getrpcbynumber.c b/newlib/libc/sys/linux/net/getrpcbynumber.c
new file mode 100644
index 000000000..f9513eb62
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcbynumber.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define FUNCTION_NAME getrpcbynumber
+#define DATABASE_NAME rpc
+#define ADD_PARAMS int number
+#define ADD_VARIABLES number
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getrpcbynumber_r.c b/newlib/libc/sys/linux/net/getrpcbynumber_r.c
new file mode 100644
index 000000000..839442214
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcbynumber_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define FUNCTION_NAME getrpcbynumber
+#define DATABASE_NAME rpc
+#define ADD_PARAMS int number
+#define ADD_VARIABLES number
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getrpcent.c b/newlib/libc/sys/linux/net/getrpcent.c
new file mode 100644
index 000000000..1b4eb03a2
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcent.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define GETFUNC_NAME getrpcent
+#define BUFLEN 1024
+
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/getrpcent_r.c b/newlib/libc/sys/linux/net/getrpcent_r.c
new file mode 100644
index 000000000..e212b5f2e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getrpcent_r.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct rpcent
+#define SETFUNC_NAME setrpcent
+#define GETFUNC_NAME getrpcent
+#define ENDFUNC_NAME endrpcent
+#define DATABASE_NAME rpc
+#define STAYOPEN int stayopen
+#define STAYOPEN_VAR stayopen
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getservbyname.c b/newlib/libc/sys/linux/net/getservbyname.c
deleted file mode 100644
index ced03d617..000000000
--- a/newlib/libc/sys/linux/net/getservbyname.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <netdb.h>
-#include <string.h>
-
-extern int _serv_stayopen;
-
-struct servent *
-getservbyname(name, proto)
- const char *name, *proto;
-{
- struct servent *p;
- char **cp;
-
-#ifdef YP
- extern char *___getservbyname_yp;
- extern char *___getservbyproto_yp;
-
- ___getservbyname_yp = (char *)name;
- ___getservbyproto_yp = (char *)proto;
-#endif
-
- setservent(_serv_stayopen);
- while ( (p = getservent()) ) {
- if (strcmp(name, p->s_name) == 0)
- goto gotname;
- for (cp = p->s_aliases; *cp; cp++)
- if (strcmp(name, *cp) == 0)
- goto gotname;
- continue;
-gotname:
- if (proto == 0 || strcmp(p->s_proto, proto) == 0)
- break;
- }
- if (!_serv_stayopen)
- endservent();
-
-#ifdef YP
- ___getservbyname_yp = NULL;
- ___getservbyproto_yp = NULL;
-#endif
-
- return (p);
-}
diff --git a/newlib/libc/sys/linux/net/getservbyport.c b/newlib/libc/sys/linux/net/getservbyport.c
deleted file mode 100644
index 88b684da4..000000000
--- a/newlib/libc/sys/linux/net/getservbyport.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <netdb.h>
-#include <string.h>
-
-extern int _serv_stayopen;
-
-struct servent *
-getservbyport(port, proto)
- int port;
- const char *proto;
-{
- struct servent *p;
-
-#ifdef YP
- extern int ___getservbyport_yp;
- extern char *___getservbyproto_yp;
-
- ___getservbyport_yp = port;
- ___getservbyproto_yp = (char *)proto;
-#endif
-
- setservent(_serv_stayopen);
- while ( (p = getservent()) ) {
- if (p->s_port != port)
- continue;
- if (proto == 0 || strcmp(p->s_proto, proto) == 0)
- break;
- }
- if (!_serv_stayopen)
- endservent();
-
-#ifdef YP
- ___getservbyport_yp = 0;
- ___getservbyproto_yp = NULL;
-#endif
-
- return (p);
-}
diff --git a/newlib/libc/sys/linux/net/getservent.3 b/newlib/libc/sys/linux/net/getservent.3
deleted file mode 100644
index 3d398bdb1..000000000
--- a/newlib/libc/sys/linux/net/getservent.3
+++ /dev/null
@@ -1,158 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)getservent.3 8.3 (Berkeley) 1/12/94
-.\" $FreeBSD: src/lib/libc/net/getservent.3,v 1.12 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd July 9, 1995
-.Dt GETSERVENT 3
-.Os
-.Sh NAME
-.Nm getservent ,
-.Nm getservbyport ,
-.Nm getservbyname ,
-.Nm setservent ,
-.Nm endservent
-.Nd get service entry
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In netdb.h
-.Ft struct servent *
-.Fn getservent
-.Ft struct servent *
-.Fn getservbyname "const char *name" "const char *proto"
-.Ft struct servent *
-.Fn getservbyport "int port" "const char *proto"
-.Ft void
-.Fn setservent "int stayopen"
-.Ft void
-.Fn endservent void
-.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 data base,
-.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 zero 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 net data base 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 (which must be specified in
-network byte order) is found,
-or until
-.Dv EOF
-is encountered.
-If a protocol name is also supplied (non-
-.Dv NULL ) ,
-searches must also match the protocol.
-.Sh FILES
-.Bl -tag -width /etc/services -compact
-.It Pa /etc/services
-.El
-.Sh DIAGNOSTICS
-Null pointer
-(0) returned on
-.Dv EOF
-or error.
-.Sh SEE ALSO
-.Xr getprotoent 3 ,
-.Xr services 5
-.Sh HISTORY
-The
-.Fn getservent ,
-.Fn getservbyport ,
-.Fn getservbyname ,
-.Fn setservent ,
-and
-.Fn endservent
-functions appeared in
-.Bx 4.2 .
-.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.
-Expecting port numbers to fit in a 32 bit
-quantity is probably naive.
diff --git a/newlib/libc/sys/linux/net/getservent.c b/newlib/libc/sys/linux/net/getservent.c
index 1c26df75c..76a0ead8e 100644
--- a/newlib/libc/sys/linux/net/getservent.c
+++ b/newlib/libc/sys/linux/net/getservent.c
@@ -1,282 +1,26 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef YP
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-static int serv_stepping_yp = 0;
-extern int _yp_check( char ** );
-#endif
-
-
-#define MAXALIASES 35
-
-static FILE *servf = NULL;
-static char line[BUFSIZ+1];
-static struct servent serv;
-static char *serv_aliases[MAXALIASES];
-int _serv_stayopen;
-
-#ifdef YP
-char *___getservbyname_yp = NULL;
-char *___getservbyproto_yp = NULL;
-int ___getservbyport_yp = 0;
-static char *yp_domain = NULL;
-
-static int
-_getservbyport_yp(line)
- char *line;
-{
- char *result;
- int resultlen;
- char buf[YPMAXRECORD + 2];
- int rv;
-
- snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
- ___getservbyproto_yp);
-
- ___getservbyport_yp = 0;
- ___getservbyproto_yp = NULL;
-
- if(!yp_domain) {
- if(yp_get_default_domain(&yp_domain))
- return (0);
- }
-
- /*
- * We have to be a little flexible here. Ideally you're supposed
- * to have both a services.byname and a services.byport map, but
- * some systems have only services.byname. FreeBSD cheats a little
- * by putting the services.byport information in the same map as
- * services.byname so that either case will work. We allow for both
- * possibilities here: if there is no services.byport map, we try
- * services.byname instead.
- */
- if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
- &result, &resultlen))) {
- if (rv == YPERR_MAP) {
- if (yp_match(yp_domain, "services.byname", buf,
- strlen(buf), &result, &resultlen))
- return(0);
- } else
- return(0);
- }
-
- /* getservent() expects lines terminated with \n -- make it happy */
- snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
-
- free(result);
- return(1);
-}
-
-static int
-_getservbyname_yp(line)
- char *line;
-{
- char *result;
- int resultlen;
- char buf[YPMAXRECORD + 2];
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- if(!yp_domain) {
- if(yp_get_default_domain(&yp_domain))
- return (0);
- }
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
- snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
- ___getservbyproto_yp);
-
- ___getservbyname_yp = 0;
- ___getservbyproto_yp = NULL;
-
- if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
- &result, &resultlen)) {
- return(0);
- }
-
- /* getservent() expects lines terminated with \n -- make it happy */
- snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
-
- free(result);
- return(1);
-}
-
-static int
-_getservent_yp(line)
- char *line;
-{
- static char *key = NULL;
- static int keylen;
- char *lastkey, *result;
- int resultlen;
- int rv;
-
- if(!yp_domain) {
- if(yp_get_default_domain(&yp_domain))
- return (0);
- }
-
- if (!serv_stepping_yp) {
- if (key)
- free(key);
- if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
- &result, &resultlen))) {
- serv_stepping_yp = 0;
- return(0);
- }
- serv_stepping_yp = 1;
- } else {
- lastkey = key;
- rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
- &keylen, &result, &resultlen);
- free(lastkey);
- if (rv) {
- serv_stepping_yp = 0;
- return (0);
- }
- }
-
- /* getservent() expects lines terminated with \n -- make it happy */
- snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
-
- free(result);
-
- return(1);
-}
-#endif
-
-void
-setservent(f)
- int f;
-{
- if (servf == NULL)
- servf = fopen(_PATH_SERVICES, "r" );
- else
- rewind(servf);
- _serv_stayopen |= f;
-}
+#include <netdb.h>
-void
-endservent()
-{
- if (servf) {
- fclose(servf);
- servf = NULL;
- }
- _serv_stayopen = 0;
-}
-struct servent *
-getservent()
-{
- char *p;
- char *cp, **q;
+#define LOOKUP_TYPE struct servent
+#define GETFUNC_NAME getservent
+#define BUFLEN 1024
-#ifdef YP
- if (serv_stepping_yp && _getservent_yp(line)) {
- p = (char *)&line;
- goto unpack;
- }
-tryagain:
-#endif
- if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
- return (NULL);
-again:
- if ((p = fgets(line, BUFSIZ, servf)) == NULL)
- return (NULL);
-#ifdef YP
- if (*p == '+' && _yp_check(NULL)) {
- if (___getservbyname_yp != NULL) {
- if (!_getservbyname_yp(line))
- goto tryagain;
- }
- else if (___getservbyport_yp != 0) {
- if (!_getservbyport_yp(line))
- goto tryagain;
- }
- else if (!_getservent_yp(line))
- goto tryagain;
- }
-unpack:
-#endif
- if (*p == '#')
- goto again;
- cp = strpbrk(p, "#\n");
- if (cp == NULL)
- goto again;
- *cp = '\0';
- serv.s_name = p;
- p = strpbrk(p, " \t");
- if (p == NULL)
- goto again;
- *p++ = '\0';
- while (*p == ' ' || *p == '\t')
- p++;
- cp = strpbrk(p, ",/");
- if (cp == NULL)
- goto again;
- *cp++ = '\0';
- serv.s_port = htons((u_short)atoi(p));
- serv.s_proto = cp;
- q = serv.s_aliases = serv_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &serv_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- return (&serv);
-}
+#include "getXXent.c"
diff --git a/newlib/libc/sys/linux/net/getservent_r.c b/newlib/libc/sys/linux/net/getservent_r.c
new file mode 100644
index 000000000..93708bdc2
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getservent_r.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct servent
+#define SETFUNC_NAME setservent
+#define GETFUNC_NAME getservent
+#define ENDFUNC_NAME endservent
+#define DATABASE_NAME services
+#define STAYOPEN int stayopen
+#define STAYOPEN_VAR stayopen
+
+#include "getXXent_r.c"
diff --git a/newlib/libc/sys/linux/net/getsrvbynm.c b/newlib/libc/sys/linux/net/getsrvbynm.c
new file mode 100644
index 000000000..c3d2b2a21
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getsrvbynm.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct servent
+#define FUNCTION_NAME getservbyname
+#define DATABASE_NAME services
+#define ADD_PARAMS const char *name, const char *proto
+#define ADD_VARIABLES name, proto
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getsrvbynm_r.c b/newlib/libc/sys/linux/net/getsrvbynm_r.c
new file mode 100644
index 000000000..3abf99774
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getsrvbynm_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct servent
+#define FUNCTION_NAME getservbyname
+#define DATABASE_NAME services
+#define ADD_PARAMS const char *name, const char *proto
+#define ADD_VARIABLES name, proto
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/getsrvbypt.c b/newlib/libc/sys/linux/net/getsrvbypt.c
new file mode 100644
index 000000000..f6b383d6b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getsrvbypt.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct servent
+#define FUNCTION_NAME getservbyport
+#define DATABASE_NAME services
+#define ADD_PARAMS int port, const char *proto
+#define ADD_VARIABLES port, proto
+#define BUFLEN 1024
+
+#include "getXXbyYY.c"
diff --git a/newlib/libc/sys/linux/net/getsrvbypt_r.c b/newlib/libc/sys/linux/net/getsrvbypt_r.c
new file mode 100644
index 000000000..100a9b25e
--- /dev/null
+++ b/newlib/libc/sys/linux/net/getsrvbypt_r.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE struct servent
+#define FUNCTION_NAME getservbyport
+#define DATABASE_NAME services
+#define ADD_PARAMS int port, const char *proto
+#define ADD_VARIABLES port, proto
+
+#include "getXXbyYY_r.c"
diff --git a/newlib/libc/sys/linux/net/grp-lookup.c b/newlib/libc/sys/linux/net/grp-lookup.c
new file mode 100644
index 000000000..9373045b5
--- /dev/null
+++ b/newlib/libc/sys/linux/net/grp-lookup.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME group
+#define DEFAULT_CONFIG "compat [NOTFOUND=return] files"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/herrno.c b/newlib/libc/sys/linux/net/herrno.c
new file mode 100644
index 000000000..bb6d3f598
--- /dev/null
+++ b/newlib/libc/sys/linux/net/herrno.c
@@ -0,0 +1,6 @@
+#include <reent.h>
+
+int *__h_errno_location() {
+ return &(_REENT->_new._reent._h_errno);
+}
+
diff --git a/newlib/libc/sys/linux/net/herror.c b/newlib/libc/sys/linux/net/herror.c
deleted file mode 100644
index 0edec9890..000000000
--- a/newlib/libc/sys/linux/net/herror.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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) 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <netdb.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-const char *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 */
-};
-int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
-
-int h_errno;
-
-/*
- * herror --
- * print the error indicated by the h_errno value.
- */
-void
-herror(s)
- const char *s;
-{
- char *ptr;
- if (s && *s) {
- write(STDERR_FILENO, s, strlen(s));
- write(STDERR_FILENO, ": ", 2);
- }
- ptr = (char *)hstrerror(h_errno);
- write(STDERR_FILENO, ptr, strlen(ptr));
- write(STDERR_FILENO, "\n", 1);
-}
-
-const char *
-hstrerror(err)
- 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/newlib/libc/sys/linux/net/hesiod.3 b/newlib/libc/sys/linux/net/hesiod.3
deleted file mode 100644
index 8de1f9247..000000000
--- a/newlib/libc/sys/linux/net/hesiod.3
+++ /dev/null
@@ -1,159 +0,0 @@
-.\" $NetBSD: hesiod.3,v 1.1 1999/01/25 03:43:04 lukem Exp $
-.\" $FreeBSD: src/lib/libc/net/hesiod.3,v 1.3 2001/10/01 16:08:55 ru Exp $
-.\"
-.\" from: #Id: hesiod.3,v 1.9.2.1 1997/01/03 21:02:23 ghudson Exp #
-.\"
-.\" Copyright 1988, 1996 by the Massachusetts Institute of Technology.
-.\"
-.\" Permission to use, copy, modify, and distribute this
-.\" software and its documentation for any purpose and without
-.\" fee is hereby granted, provided that the above copyright
-.\" notice appear in all copies and that both that copyright
-.\" notice and this permission notice appear in supporting
-.\" documentation, and that the name of M.I.T. not be used in
-.\" advertising or publicity pertaining to distribution of the
-.\" software without specific, written prior permission.
-.\" M.I.T. makes no representations about the suitability of
-.\" this software for any purpose. It is provided "as is"
-.\" without express or implied warranty.
-.\"
-.Dd November 30, 1996
-.Dt HESIOD 3
-.Os
-.Sh NAME
-.Nm hesiod ,
-.Nm hesiod_init ,
-.Nm hesiod_resolve ,
-.Nm hesiod_free_list ,
-.Nm hesiod_to_bind ,
-.Nm hesiod_end
-.Nd Hesiod name server interface library
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In hesiod.h
-.Ft int
-.Fn hesiod_init "void **context"
-.Ft char **
-.Fn hesiod_resolve "void *context" "const char *name" "const char *type"
-.Ft void
-.Fn hesiod_free_list "void *context" "char **list"
-.Ft char *
-.Fn hesiod_to_bind "void *context" "const char *name" "const char *type"
-.Ft void
-.Fn hesiod_end "void *context"
-.Sh DESCRIPTION
-This family of functions allows you to perform lookups of Hesiod
-information, which is stored as text records in the Domain Name
-Service.
-To perform lookups, you must first initialize a
-.Fa context ,
-an opaque object which stores information used internally by the
-library between calls.
-.Fn hesiod_init
-initializes a context, storing a pointer to the context in the
-location pointed to by the
-.Fa context
-argument.
-.Fn hesiod_end
-frees the resources used by a context.
-.Pp
-.Fn hesiod_resolve
-is the primary interface to the library.
-If successful, it returns a
-list of one or more strings giving the records matching
-.Fa name
-and
-.Fa type .
-The last element of the list is followed by a
-.Dv NULL
-pointer.
-It is the
-caller's responsibility to call
-.Fn hesiod_free_list
-to free the resources used by the returned list.
-.Pp
-.Fn hesiod_to_bind
-converts
-.Fa name
-and
-.Fa type
-into the DNS name used by
-.Fn hesiod_resolve .
-It is the caller's responsibility to free the returned string using
-.Fn free .
-.Sh RETURN VALUES
-.Rv -std hesiod_init
-On failure,
-.Fn hesiod_resolve
-and
-.Fn hesiod_to_bind
-return
-.Dv NULL
-and set the global variable
-.Va errno
-to indicate the error.
-.Sh ENVIRONMENT
-.Bl -tag -width HESIOD_CONFIG
-.It Ev HES_DOMAIN
-If the environment variable
-.Ev HES_DOMAIN
-is set, it will override the domain in the Hesiod configuration file.
-.It Ev HESIOD_CONFIG
-If the environment variable
-.Ev HESIOD_CONFIG
-is set, it specifies the location of the Hesiod configuration file.
-.El
-.Sh SEE ALSO
-.Xr hesiod.conf 5 ,
-.Xr named 8
-.Rs
-.%T "Hesiod - Project Athena Technical Plan -- Name Service"
-.Re
-.Sh ERRORS
-Hesiod calls may fail because of:
-.Bl -tag -width Er
-.It Bq Er ENOMEM
-Insufficient memory was available to carry out the requested
-operation.
-.It Bq Er ENOEXEC
-.Fn hesiod_init
-failed because the Hesiod configuration file was invalid.
-.It Bq Er ECONNREFUSED
-.Fn hesiod_resolve
-failed because no name server could be contacted to answer the query.
-.It Bq Er EMSGSIZE
-.Fn hesiod_resolve
-or
-.Fn hesiod_to_bind
-failed because the query or response was too big to fit into the
-packet buffers.
-.It Bq Er ENOENT
-.Fn hesiod_resolve
-failed because the name server had no text records matching
-.Fa name
-and
-.Fa type ,
-or
-.Fn hesiod_to_bind
-failed because the
-.Fa name
-argument had a domain extension which could not be resolved with type
-.Dq rhs\-extension
-in the local Hesiod domain.
-.El
-.Sh AUTHORS
-.An Steve Dyer ,
-IBM/Project Athena
-.An Greg Hudson ,
-MIT Team Athena
-.Pp
-Copyright 1987, 1988, 1995, 1996 by the Massachusetts Institute of Technology.
-.Sh BUGS
-The strings corresponding to the
-.Va errno
-values set by the Hesiod functions are not particularly indicative of
-what went wrong, especially for
-.Er ENOEXEC
-and
-.Er ENOENT .
diff --git a/newlib/libc/sys/linux/net/hesiod.c b/newlib/libc/sys/linux/net/hesiod.c
deleted file mode 100644
index 909c09440..000000000
--- a/newlib/libc/sys/linux/net/hesiod.c
+++ /dev/null
@@ -1,600 +0,0 @@
-/* $NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb 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.
- */
-
-/* Copyright 1996 by the Massachusetts Institute of Technology.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
-/* This file is part of the hesiod library. It implements the core
- * portion of the hesiod resolver.
- *
- * This file is loosely based on an interim version of hesiod.c from
- * the BIND IRS library, which was in turn based on an earlier version
- * of this file. Extensive changes have been made on each step of the
- * path.
- *
- * This implementation is not truly thread-safe at the moment because
- * it uses res_send() and accesses _res.
- */
-
-#include <sys/cdefs.h>
-
-#if 0
-static char *orig_rcsid = "$NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb Exp $";
-#endif
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <hesiod.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-struct hesiod_p {
- char *lhs; /* normally ".ns" */
- char *rhs; /* AKA the default hesiod domain */
- int classes[2]; /* The class search order. */
-};
-
-#define MAX_HESRESP 1024
-
-static int read_config_file(struct hesiod_p *, const char *);
-static char **get_txt_records(int, const char *);
-static int init_context(void);
-static void translate_errors(void);
-
-
-/*
- * hesiod_init --
- * initialize a hesiod_p.
- */
-int
-hesiod_init(context)
- void **context;
-{
- struct hesiod_p *ctx;
- const char *p, *configname;
-
- ctx = malloc(sizeof(struct hesiod_p));
- if (ctx) {
- *context = ctx;
- if (!issetugid())
- configname = getenv("HESIOD_CONFIG");
- else
- configname = NULL;
- if (!configname)
- configname = _PATH_HESIOD_CONF;
- if (read_config_file(ctx, configname) >= 0) {
- /*
- * The default rhs can be overridden by an
- * environment variable.
- */
- if (!issetugid())
- p = getenv("HES_DOMAIN");
- else
- p = NULL;
- if (p) {
- if (ctx->rhs)
- free(ctx->rhs);
- ctx->rhs = malloc(strlen(p) + 2);
- if (ctx->rhs) {
- *ctx->rhs = '.';
- strcpy(ctx->rhs + 1,
- (*p == '.') ? p + 1 : p);
- return 0;
- } else
- errno = ENOMEM;
- } else
- return 0;
- }
- } else
- errno = ENOMEM;
-
- if (ctx->lhs)
- free(ctx->lhs);
- if (ctx->rhs)
- free(ctx->rhs);
- if (ctx)
- free(ctx);
- return -1;
-}
-
-/*
- * hesiod_end --
- * Deallocates the hesiod_p.
- */
-void
-hesiod_end(context)
- void *context;
-{
- struct hesiod_p *ctx = (struct hesiod_p *) context;
-
- free(ctx->rhs);
- if (ctx->lhs)
- free(ctx->lhs);
- free(ctx);
-}
-
-/*
- * hesiod_to_bind --
- * takes a hesiod (name, type) and returns a DNS
- * name which is to be resolved.
- */
-char *
-hesiod_to_bind(void *context, const char *name, const char *type)
-{
- struct hesiod_p *ctx = (struct hesiod_p *) context;
- char bindname[MAXDNAME], *p, *ret, **rhs_list = NULL;
- const char *rhs;
- int len;
- size_t bindnamelen;
-
- if (strlcpy(bindname, name, sizeof(bindname)) >= sizeof(bindname)) {
- errno = EMSGSIZE;
- return NULL;
- }
-
- /*
- * Find the right right hand side to use, possibly
- * truncating bindname.
- */
- p = strchr(bindname, '@');
- if (p) {
- *p++ = 0;
- if (strchr(p, '.'))
- rhs = name + (p - bindname);
- else {
- rhs_list = hesiod_resolve(context, p, "rhs-extension");
- if (rhs_list)
- rhs = *rhs_list;
- else {
- errno = ENOENT;
- return NULL;
- }
- }
- } else
- rhs = ctx->rhs;
-
- /* See if we have enough room. */
- len = strlen(bindname) + 1 + strlen(type);
- if (ctx->lhs)
- len += strlen(ctx->lhs) + ((ctx->lhs[0] != '.') ? 1 : 0);
- len += strlen(rhs) + ((rhs[0] != '.') ? 1 : 0);
- if (len > sizeof(bindname) - 1) {
- if (rhs_list)
- hesiod_free_list(context, rhs_list);
- errno = EMSGSIZE;
- return NULL;
- }
- /* Put together the rest of the domain. */
- strcat(bindname, ".");
- strcat(bindname, type);
- /* Only append lhs if it isn't empty. */
- if (ctx->lhs && ctx->lhs[0] != '\0' ) {
- if (ctx->lhs[0] != '.')
- strcat(bindname, ".");
- strcat(bindname, ctx->lhs);
- }
- if (rhs[0] != '.')
- strcat(bindname, ".");
- strcat(bindname, rhs);
-
- /* rhs_list is no longer needed, since we're done with rhs. */
- if (rhs_list)
- hesiod_free_list(context, rhs_list);
-
- /* Make a copy of the result and return it to the caller. */
- bindnamelen = strlen (bindname) + 1;
- ret = malloc (bindnamelen);
- if (!ret)
- errno = ENOMEM;
- else
- memcpy (ret, bindname, bindnamelen);
- return ret;
-}
-
-/*
- * hesiod_resolve --
- * Given a hesiod name and type, return an array of strings returned
- * by the resolver.
- */
-char **
-hesiod_resolve(context, name, type)
- void *context;
- const char *name;
- const char *type;
-{
- struct hesiod_p *ctx = (struct hesiod_p *) context;
- char *bindname, **retvec;
-
- bindname = hesiod_to_bind(context, name, type);
- if (!bindname)
- return NULL;
-
- retvec = get_txt_records(ctx->classes[0], bindname);
- if (retvec == NULL && errno == ENOENT && ctx->classes[1])
- retvec = get_txt_records(ctx->classes[1], bindname);
-
- free(bindname);
- return retvec;
-}
-
-/*ARGSUSED*/
-void
-hesiod_free_list(context, list)
- void *context;
- char **list;
-{
- char **p;
-
- if (list == NULL)
- return;
- for (p = list; *p; p++)
- free(*p);
- free(list);
-}
-
-
-/* read_config_file --
- * Parse the /etc/hesiod.conf file. Returns 0 on success,
- * -1 on failure. On failure, it might leave values in ctx->lhs
- * or ctx->rhs which need to be freed by the caller.
- */
-static int
-read_config_file(ctx, filename)
- struct hesiod_p *ctx;
- const char *filename;
-{
- char *key, *data, *p, **which;
- char buf[MAXDNAME + 7];
- int n;
- FILE *fp;
-
- /* Set default query classes. */
- ctx->classes[0] = C_IN;
- ctx->classes[1] = C_HS;
-
- /* Try to open the configuration file. */
- fp = fopen(filename, "r");
- if (!fp) {
- size_t len;
- /* Use compiled in default domain names. */
- len = strlen (DEF_LHS) + 1;
- ctx->lhs = malloc (len);
- if (ctx->lhs) {
- memcpy (ctx->lhs, DEF_LHS, len);
- len = strlen (DEF_RHS) + 1;
- ctx->rhs = malloc (len);
- if (ctx->rhs)
- memcpy (ctx->rhs, DEF_RHS, len);
- }
- if (ctx->lhs && ctx->rhs)
- return 0;
- else {
- errno = ENOMEM;
- return -1;
- }
- }
- ctx->lhs = NULL;
- ctx->rhs = NULL;
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- p = buf;
- if (*p == '#' || *p == '\n' || *p == '\r')
- continue;
- while (*p == ' ' || *p == '\t')
- p++;
- key = p;
- while (*p != ' ' && *p != '\t' && *p != '=')
- p++;
- *p++ = 0;
-
- while (isspace(*p) || *p == '=')
- p++;
- data = p;
- while (!isspace(*p))
- p++;
- *p = 0;
-
- if (strcasecmp(key, "lhs") == 0 ||
- strcasecmp(key, "rhs") == 0) {
- size_t len;
- which = (strcasecmp(key, "lhs") == 0)
- ? &ctx->lhs : &ctx->rhs;
- len = strlen (data) + 1;
- *which = malloc (len);
- if (!*which) {
- errno = ENOMEM;
- return -1;
- }
- else
- memcpy (*which, data, len);
- } else {
- if (strcasecmp(key, "classes") == 0) {
- n = 0;
- while (*data && n < 2) {
- p = data;
- while (*p && *p != ',')
- p++;
- if (*p)
- *p++ = 0;
- if (strcasecmp(data, "IN") == 0)
- ctx->classes[n++] = C_IN;
- else
- if (strcasecmp(data, "HS") == 0)
- ctx->classes[n++] =
- C_HS;
- data = p;
- }
- while (n < 2)
- ctx->classes[n++] = 0;
- }
- }
- }
- fclose(fp);
-
- if (!ctx->rhs || ctx->classes[0] == 0 ||
- ctx->classes[0] == ctx->classes[1]) {
- errno = ENOEXEC;
- return -1;
- }
- return 0;
-}
-
-/*
- * get_txt_records --
- * Given a DNS class and a DNS name, do a lookup for TXT records, and
- * return a list of them.
- */
-static char **
-get_txt_records(qclass, name)
- int qclass;
- const char *name;
-{
- HEADER *hp;
- unsigned char qbuf[PACKETSZ], abuf[MAX_HESRESP], *p, *eom, *eor;
- char *dst, **list;
- int ancount, qdcount, i, j, n, skip, type, class, len;
-
- /* Make sure the resolver is initialized. */
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return NULL;
-
- /* Construct the query. */
- n = res_mkquery(QUERY, name, qclass, T_TXT, NULL, 0,
- NULL, qbuf, PACKETSZ);
- if (n < 0)
- return NULL;
-
- /* Send the query. */
- n = res_send(qbuf, n, abuf, MAX_HESRESP);
- if (n < 0) {
- errno = ECONNREFUSED;
- return NULL;
- }
- /* Parse the header of the result. */
- hp = (HEADER *) (void *) abuf;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- p = abuf + sizeof(HEADER);
- eom = abuf + n;
-
- /*
- * Skip questions, trying to get to the answer section
- * which follows.
- */
- for (i = 0; i < qdcount; i++) {
- skip = dn_skipname(p, eom);
- if (skip < 0 || p + skip + QFIXEDSZ > eom) {
- errno = EMSGSIZE;
- return NULL;
- }
- p += skip + QFIXEDSZ;
- }
-
- /* Allocate space for the text record answers. */
- list = malloc((ancount + 1) * sizeof(char *));
- if (!list) {
- errno = ENOMEM;
- return NULL;
- }
- /* Parse the answers. */
- j = 0;
- for (i = 0; i < ancount; i++) {
- /* Parse the header of this answer. */
- skip = dn_skipname(p, eom);
- if (skip < 0 || p + skip + 10 > eom)
- break;
- type = p[skip + 0] << 8 | p[skip + 1];
- class = p[skip + 2] << 8 | p[skip + 3];
- len = p[skip + 8] << 8 | p[skip + 9];
- p += skip + 10;
- if (p + len > eom) {
- errno = EMSGSIZE;
- break;
- }
- /* Skip entries of the wrong class and type. */
- if (class != qclass || type != T_TXT) {
- p += len;
- continue;
- }
- /* Allocate space for this answer. */
- list[j] = malloc((size_t)len);
- if (!list[j]) {
- errno = ENOMEM;
- break;
- }
- dst = list[j++];
-
- /* Copy answer data into the allocated area. */
- eor = p + len;
- while (p < eor) {
- n = (unsigned char) *p++;
- if (p + n > eor) {
- errno = EMSGSIZE;
- break;
- }
- memcpy(dst, p, (size_t)n);
- p += n;
- dst += n;
- }
- if (p < eor) {
- errno = EMSGSIZE;
- break;
- }
- *dst = 0;
- }
-
- /*
- * If we didn't terminate the loop normally, something
- * went wrong.
- */
- if (i < ancount) {
- for (i = 0; i < j; i++)
- free(list[i]);
- free(list);
- return NULL;
- }
- if (j == 0) {
- errno = ENOENT;
- free(list);
- return NULL;
- }
- list[j] = NULL;
- return list;
-}
-
- /*
- * COMPATIBILITY FUNCTIONS
- */
-
-static int inited = 0;
-static void *context;
-static int errval = HES_ER_UNINIT;
-
-int
-hes_init()
-{
- init_context();
- return errval;
-}
-
-char *
-hes_to_bind(name, type)
- const char *name;
- const char *type;
-{
- static char *bindname;
- if (init_context() < 0)
- return NULL;
- if (bindname)
- free(bindname);
- bindname = hesiod_to_bind(context, name, type);
- if (!bindname)
- translate_errors();
- return bindname;
-}
-
-char **
-hes_resolve(name, type)
- const char *name;
- const char *type;
-{
- static char **list;
-
- if (init_context() < 0)
- return NULL;
-
- /*
- * In the old Hesiod interface, the caller was responsible for
- * freeing the returned strings but not the vector of strings itself.
- */
- if (list)
- free(list);
-
- list = hesiod_resolve(context, name, type);
- if (!list)
- translate_errors();
- return list;
-}
-
-int
-hes_error()
-{
- return errval;
-}
-
-void
-hes_free(hp)
- char **hp;
-{
- hesiod_free_list(context, hp);
-}
-
-static int
-init_context()
-{
- if (!inited) {
- inited = 1;
- if (hesiod_init(&context) < 0) {
- errval = HES_ER_CONFIG;
- return -1;
- }
- errval = HES_ER_OK;
- }
- return 0;
-}
-
-static void
-translate_errors()
-{
- switch (errno) {
- case ENOENT:
- errval = HES_ER_NOTFOUND;
- break;
- case ECONNREFUSED:
- case EMSGSIZE:
- errval = HES_ER_NET;
- break;
- case ENOMEM:
- default:
- /* Not a good match, but the best we can do. */
- errval = HES_ER_CONFIG;
- break;
- }
-}
diff --git a/newlib/libc/sys/linux/net/hosts-lookup.c b/newlib/libc/sys/linux/net/hosts-lookup.c
new file mode 100644
index 000000000..8dff71f7c
--- /dev/null
+++ b/newlib/libc/sys/linux/net/hosts-lookup.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME hosts
+#define DEFAULT_CONFIG "dns [!UNAVAIL=return] files"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/if_indextoname.3 b/newlib/libc/sys/linux/net/if_indextoname.3
deleted file mode 100644
index 4b5bff5aa..000000000
--- a/newlib/libc/sys/linux/net/if_indextoname.3
+++ /dev/null
@@ -1,142 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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
-.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.7 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd May 21, 1998
-.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 LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In net/if.h
-.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
-The functions map interface index to readable interface name
-(such as
-.Dq Li lo0 ) ,
-and vice versa.
-.Pp
-.Fn if_nametoindex
-converts readable interface name to interface index
-.Pp positive integer value .
-If the specified interface does not exist, 0 will be returned.
-.Pp
-.Fn if_indextoname
-converts interface index to readable 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.
-.Dv ( IF_NAMESIZE
-is also defined in
-.Aq Pa net/if.h
-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,
-.Dv NULL
-is returned.
-.Pp
-.Fn if_nameindex
-returns an array of
-.Fa if_nameindex
-structures.
-.Fa if_nametoindex
-is also defined in
-.Aq Pa net/if.h ,
-and is as follows:
-.Bd -literal -offset
-struct if_nameindex {
- unsigned int if_index; /* 1, 2, ... */
- char *if_name; /* null terminated name: "le0", ... */
-};
-.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
-.Dv NULL
-pointer upon an 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
-R. Gilligan, S. Thomson, J. Bound, and W. Stevens,
-``Basic Socket Interface Extensions for IPv6,'' RFC2553, March 1999.
-.Sh HISTORY
-The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-.Sh STANDARDS
-These functions are defined in ``Basic Socket Interface Extensions for IPv6''
-(RFC2533).
diff --git a/newlib/libc/sys/linux/net/ifaddrs.h b/newlib/libc/sys/linux/net/ifaddrs.h
new file mode 100644
index 000000000..ba6a1554b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ifaddrs.h
@@ -0,0 +1,74 @@
+/* ifaddrs.h -- declarations for getting network interface addresses
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _IFADDRS_H
+#define _IFADDRS_H 1
+
+#include <features.h>
+#include <sys/socket.h>
+
+__BEGIN_DECLS
+
+/* The `getifaddrs' function generates a linked list of these structures.
+ Each element of the list describes one network interface. */
+struct ifaddrs
+{
+ struct ifaddrs *ifa_next; /* Pointer to the next structure. */
+
+ char *ifa_name; /* Name of this network interface. */
+ unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */
+
+ struct sockaddr *ifa_addr; /* Network address of this interface. */
+ struct sockaddr *ifa_netmask; /* Netmask of this interface. */
+ union
+ {
+ /* At most one of the following two is valid. If the IFF_BROADCAST
+ bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the
+ IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid.
+ It is never the case that both these bits are set at once. */
+ struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
+ struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
+ } ifa_ifu;
+ /* These very same macros are defined by <net/if.h> for `struct ifaddr'.
+ So if they are defined already, the existing definitions will be fine. */
+# ifndef ifa_broadaddr
+# define ifa_broadaddr ifa_ifu.ifu_broadaddr
+# endif
+# ifndef ifa_dstaddr
+# define ifa_dstaddr ifa_ifu.ifu_dstaddr
+# endif
+
+ void *ifa_data; /* Address-specific data (may be unused). */
+};
+
+
+/* Create a linked list of `struct ifaddrs' structures, one for each
+ network interface on the host machine. If successful, store the
+ list in *IFAP and return 0. On errors, return -1 and set `errno'.
+
+ The storage returned in *IFAP is allocated dynamically and can
+ only be properly freed by passing it to `freeifaddrs'. */
+extern int getifaddrs (struct ifaddrs **__ifap) __THROW;
+
+/* Reclaim the storage allocated by a previous `getifaddrs' call. */
+extern void freeifaddrs (struct ifaddrs *__ifa) __THROW;
+
+__END_DECLS
+
+#endif /* ifaddrs.h */
diff --git a/newlib/libc/sys/linux/net/ifreq.c b/newlib/libc/sys/linux/net/ifreq.c
new file mode 100644
index 000000000..9d6a6121b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ifreq.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "ifreq.h"
+
+/* Variable to signal whether SIOCGIFCONF is not available. */
+#if __ASSUME_SIOCGIFNAME == 0 || 1
+static int old_siocgifconf;
+#else
+# define old_siocgifconf 0
+#endif
+
+
+void
+__ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
+{
+ int fd = sockfd;
+ struct ifconf ifc;
+ int rq_len;
+ int nifs;
+# define RQ_IFS 4
+
+ if (fd < 0)
+ fd = __opensock ();
+ if (fd < 0)
+ {
+ *num_ifs = 0;
+ *ifreqs = NULL;
+ return;
+ }
+
+ ifc.ifc_buf = NULL;
+
+ /* We may be able to get the needed buffer size directly, rather than
+ guessing. */
+ if (! old_siocgifconf)
+ {
+ ifc.ifc_buf = NULL;
+ ifc.ifc_len = 0;
+ if (ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ old_siocgifconf = 1;
+# endif
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+ }
+ else
+ rq_len = ifc.ifc_len;
+ }
+ else
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+
+ /* Read all the interfaces out of the kernel. */
+ while (1)
+ {
+ ifc.ifc_len = rq_len;
+ void *newp = realloc (ifc.ifc_buf, ifc.ifc_len);
+ if (newp == NULL
+ || (ifc.ifc_buf = newp, ioctl (fd, SIOCGIFCONF, &ifc)) < 0)
+ {
+ free (ifc.ifc_buf);
+
+ if (fd != sockfd)
+ close (fd);
+
+ *num_ifs = 0;
+ *ifreqs = NULL;
+ return;
+ }
+
+ if (!old_siocgifconf || ifc.ifc_len < rq_len)
+ break;
+
+ rq_len *= 2;
+ }
+
+ nifs = ifc.ifc_len / sizeof (struct ifreq);
+
+ if (fd != sockfd)
+ close (fd);
+
+ *num_ifs = nifs;
+ *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq));
+}
diff --git a/newlib/libc/sys/linux/net/ifreq.h b/newlib/libc/sys/linux/net/ifreq.h
new file mode 100644
index 000000000..ba55a39eb
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ifreq.h
@@ -0,0 +1,40 @@
+/* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+
+extern void __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd);
+
+static inline struct ifreq *
+__if_nextreq (struct ifreq *ifr)
+{
+ return ifr + 1;
+}
+
+static inline void
+__if_freereq (struct ifreq *ifreqs, int num_ifs)
+{
+ free (ifreqs);
+}
diff --git a/newlib/libc/sys/linux/net/in6_addr.c b/newlib/libc/sys/linux/net/in6_addr.c
new file mode 100644
index 000000000..a75b64ebc
--- /dev/null
+++ b/newlib/libc/sys/linux/net/in6_addr.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <netinet/in.h>
+#include "libc-symbols.h"
+
+const struct in6_addr in6addr_any =
+{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
+libc_hidden_data_def (in6addr_any)
+const struct in6_addr in6addr_loopback =
+{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } };
+libc_hidden_data_def (in6addr_loopback)
diff --git a/newlib/libc/sys/linux/net/inet.3 b/newlib/libc/sys/linux/net/inet.3
deleted file mode 100644
index 7a6fcf370..000000000
--- a/newlib/libc/sys/linux/net/inet.3
+++ /dev/null
@@ -1,271 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)inet.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.22 2001/12/01 03:43:01 mike Exp $
-.\"
-.Dd June 17, 1996
-.Dt INET 3
-.Os
-.Sh NAME
-.Nm inet_aton ,
-.Nm inet_addr ,
-.Nm inet_network ,
-.Nm inet_ntoa ,
-.Nm inet_ntop ,
-.Nm inet_pton ,
-.Nm inet_makeaddr ,
-.Nm inet_lnaof ,
-.Nm inet_netof
-.Nd Internet address manipulation routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In netinet/in.h
-.In arpa/inet.h
-.Ft int
-.Fn inet_aton "const char *cp" "struct in_addr *pin"
-.Ft in_addr_t
-.Fn inet_addr "const char *cp"
-.Ft in_addr_t
-.Fn inet_network "const char *cp"
-.Ft char *
-.Fn inet_ntoa "struct in_addr in"
-.Ft const char *
-.Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size"
-.Ft int
-.Fn inet_pton "int af" "const char *src" "void *dst"
-.Ft struct in_addr
-.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna"
-.Ft in_addr_t
-.Fn inet_lnaof "struct in_addr in"
-.Ft in_addr_t
-.Fn inet_netof "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
-.Ql .\&
-notation.
-.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
-.Ft 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, or
-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
-.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 is invalid.
-The
-.Fn inet_addr
-and
-.Fn inet_network
-functions return numbers suitable for use
-as Internet addresses and Internet network
-numbers, respectively.
-.Pp
-The function
-.Fn inet_ntop
-converts an address from network format (usually a
-.Ft struct in_addr
-or some other binary form, in network byte order) to presentation format
-(suitable for external display purposes).
-It returns NULL if a system error occurs (in which case,
-.Va errno
-will have been set), or it returns a pointer to the destination string.
-This function is presently valid for
-.Dv AF_INET
-and
-.Dv AF_INET6 .
-.Pp
-The routine
-.Fn inet_ntoa
-takes an Internet address and returns an
-.Tn ASCII
-string representing the address in
-.Ql .\&
-notation. The routine
-.Fn inet_makeaddr
-takes an Internet network number and a local
-network address and constructs an Internet address
-from it. 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 byte order integer values.
-.Sh INTERNET ADDRESSES
-Values specified using the
-.Ql .\&
-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 the
-.Tn VAX
-the bytes referred to
-above appear as
-.Dq Li d.c.b.a .
-That is,
-.Tn VAX
-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 right-most 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 right most 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
-.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).
-.Pp
-The
-.Fn inet_aton
-and
-.Fn inet_ntoa
-functions are semi-deprecated in favor of the
-.Xr addr2ascii 3
-family. However, since those functions are not yet widely implemented,
-portable programs cannot rely on their presence and will continue
-to use the
-.Xr inet 3
-functions for some time.
-.Sh DIAGNOSTICS
-The constant
-.Dv INADDR_NONE
-is returned by
-.Fn inet_addr
-and
-.Fn inet_network
-for malformed requests.
-.Sh SEE ALSO
-.Xr addr2ascii 3 ,
-.Xr byteorder 3 ,
-.Xr gethostbyname 3 ,
-.Xr getnetent 3 ,
-.Xr inet_net 3 ,
-.Xr hosts 5 ,
-.Xr networks 5
-.Rs
-.%R RFC
-.%N 2373
-.%D July 1998
-.%T "IP Version 6 Addressing Architecture"
-.Re
-.Sh STANDARDS
-The
-.Fn inet_ntop
-and
-.Fn inet_pton
-functions conform to
-.St -xns5.2 .
-Note that
-.Fn inet_pton
-does not accept 1-, 2-, or 3-part dotted addresses; all four parts
-must be specified and are interpreted only as decimal values.
-This is a narrower input set than that accepted by
-.Fn inet_aton .
-.Sh HISTORY
-These
-functions appeared in
-.Bx 4.2 .
-.Sh BUGS
-The value
-.Dv INADDR_NONE
-(0xffffffff) is a valid broadcast address, but
-.Fn inet_addr
-cannot return that value without indicating failure.
-The newer
-.Fn inet_aton
-function does not share this problem.
-The problem of host byte ordering versus network byte ordering is
-confusing.
-The string returned by
-.Fn inet_ntoa
-resides in a static memory area.
-.Pp
-Inet_addr should return a
-.Fa struct in_addr .
diff --git a/newlib/libc/sys/linux/net/inet6_option.c b/newlib/libc/sys/linux/net/inet6_option.c
new file mode 100644
index 000000000..182cfe942
--- /dev/null
+++ b/newlib/libc/sys/linux/net/inet6_option.c
@@ -0,0 +1,346 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include "libc-symbols.h"
+
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+
+static void
+internal_function
+add_pad (struct cmsghdr *cmsg, int len)
+{
+ unsigned char *p = CMSG_DATA (cmsg) + cmsg->cmsg_len - CMSG_LEN (0);
+
+ if (len == 1)
+ /* Special handling for 1, a one-byte solution. */
+ *p++ = IP6OPT_PAD1;
+ else if (len != 0)
+ {
+ /* Multibyte padding. */
+ *p++ = IP6OPT_PADN;
+ *p++ = len - 2; /* Discount the two header bytes. */
+ /* The rest is filled with zero. */
+ memset (p, '\0', len - 2);
+ p += len - 2;
+ }
+
+ /* Account for the bytes. */
+ cmsg->cmsg_len += len;
+}
+
+
+static int
+get_opt_end (const uint8_t **result, const uint8_t *startp,
+ const uint8_t *endp)
+{
+ if (startp >= endp)
+ /* Out of bounds. */
+ return -1;
+
+ if (*startp == IP6OPT_PAD1)
+ {
+ /* Just this one byte. */
+ *result = startp + 1;
+ return 0;
+ }
+
+ /* Now we know there must be at least two bytes. */
+ if (startp + 2 > endp
+ /* Now we can get the length byte. */
+ || startp + startp[1] + 2 > endp)
+ return -1;
+
+ *result = startp + startp[1] + 2;
+
+ return 0;
+}
+
+
+/* RFC 2292, 6.3.1
+
+ 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 (nbytes)
+ int nbytes;
+{
+ /* Add room for the extension header. */
+ nbytes += sizeof (struct ip6_ext);
+
+ return CMSG_SPACE (roundup (nbytes, 8));
+}
+
+
+/* RFC 2292, 6.3.2
+
+ 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 (bp, cmsgp, type)
+ void *bp;
+ struct cmsghdr **cmsgp;
+ int type;
+{
+ /* Only Hop-by-Hop or Destination options allowed. */
+ if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS)
+ return -1;
+
+ /* BP is a pointer to the previously allocated space. */
+ struct cmsghdr *newp = (struct cmsghdr *) bp;
+
+ /* Initialize the message header.
+
+ Length: No data yet, only the cmsghdr struct. */
+ newp->cmsg_len = CMSG_LEN (0);
+ /* Originating protocol: obviously IPv6. */
+ newp->cmsg_level = IPPROTO_IPV6;
+ /* Message type. */
+ newp->cmsg_type = type;
+
+ /* Pass up the result. */
+ *cmsgp = newp;
+
+ return 0;
+}
+
+
+/* RFC 2292, 6.3.3
+
+ 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. */
+int
+inet6_option_append (cmsg, typep, multx, plusy)
+ struct cmsghdr *cmsg;
+ const uint8_t *typep;
+ int multx;
+ int plusy;
+{
+ /* typep is a pointer to the 8-bit option type. It is assumed that this
+ field is immediately followed by the 8-bit option data length field,
+ which is then followed immediately by the option data.
+
+ The option types IP6OPT_PAD1 and IP6OPT_PADN also must be handled. */
+ int len = typep[0] == IP6OPT_PAD1 ? 1 : typep[1] + 2;
+
+ /* Get the pointer to the space in the message. */
+ uint8_t *ptr = inet6_option_alloc (cmsg, len, multx, plusy);
+ if (ptr == NULL)
+ /* Some problem with the parameters. */
+ return -1;
+
+ /* Copy the content. */
+ memcpy (ptr, typep, len);
+
+ return 0;
+}
+
+
+/* RFC 2292, 6.3.4
+
+ 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. */
+uint8_t *
+inet6_option_alloc (cmsg, datalen, multx, plusy)
+ struct cmsghdr *cmsg;
+ int datalen;
+ int multx;
+ int plusy;
+{
+ /* The RFC limits the value of the alignment values. */
+ if ((multx != 1 && multx != 2 && multx != 4 && multx != 8)
+ || ! (plusy >= 0 && plusy <= 7))
+ return NULL;
+
+ /* Current data size. */
+ int dsize = cmsg->cmsg_len - CMSG_LEN (0);
+
+ /* The first two bytes of the option are for the extended header. */
+ if (__builtin_expect (dsize == 0, 0))
+ {
+ cmsg->cmsg_len += sizeof (struct ip6_ext);
+ dsize = sizeof (struct ip6_ext);
+ }
+
+ /* First add padding. */
+ add_pad (cmsg, ((multx - (dsize & (multx - 1))) & (multx - 1)) + plusy);
+
+ /* Return the pointer to the start of the option space. */
+ uint8_t *result = CMSG_DATA (cmsg) + cmsg->cmsg_len - CMSG_LEN (0);
+ cmsg->cmsg_len += datalen;
+
+ /* The extended option header length is measured in 8-byte groups.
+ To represent the current length we might have to add padding. */
+ dsize = cmsg->cmsg_len - CMSG_LEN (0);
+ add_pad (cmsg, (8 - (dsize & (8 - 1))) & (8 - 1));
+
+ /* Record the new length of the option. */
+ assert (((cmsg->cmsg_len - CMSG_LEN (0)) % 8) == 0);
+ int len8b = (cmsg->cmsg_len - CMSG_LEN (0)) / 8 - 1;
+ if (len8b >= 256)
+ /* Too long. */
+ return NULL;
+
+ ((struct ip6_ext *) CMSG_DATA (cmsg))->ip6e_len = len8b;
+
+ return result;
+}
+libc_hidden_def (inet6_option_alloc)
+
+
+/* RFC 2292, 6.3.5
+
+ 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. */
+int
+inet6_option_next (cmsg, tptrp)
+ const struct cmsghdr *cmsg;
+ uint8_t **tptrp;
+{
+ /* Make sure it is an option of the right type. */
+ if (cmsg->cmsg_level != IPPROTO_IPV6
+ || (cmsg->cmsg_type != IPV6_HOPOPTS && cmsg->cmsg_type != IPV6_DSTOPTS))
+ return -1;
+
+ /* Pointer to the extension header. We only compute the address, we
+ don't access anything yet. */
+ const struct ip6_ext *ip6e = (const struct ip6_ext *) CMSG_DATA (cmsg);
+
+ /* Make sure the message is long enough. */
+ if (cmsg->cmsg_len < CMSG_LEN (sizeof (struct ip6_ext))
+ /* Now we can access the extension header. */
+ || cmsg->cmsg_len < CMSG_LEN ((ip6e->ip6e_len + 1) * 8))
+ /* Too small. */
+ return -1;
+
+ /* Determine the address of the byte past the message. */
+ const uint8_t *endp = CMSG_DATA (cmsg) + (ip6e->ip6e_len + 1) * 8;
+
+ const uint8_t *result;
+ if (tptrp == NULL)
+ /* This is the first call, return the first option if there is one. */
+ result = (const uint8_t *) (ip6e + 1);
+ else
+ {
+ /* Make sure *TPTRP points to a beginning of a new option in
+ the message. The upper limit is checked in get_opt_end. */
+ if (*tptrp < (const uint8_t *) (ip6e + 1))
+ return -1;
+
+ /* Get the beginning of the next option. */
+ if (get_opt_end (&result, *tptrp, endp) != 0)
+ return -1;
+ }
+
+ /* We know where the next option starts. */
+ *tptrp = (uint8_t *) result;
+
+ /* Check the option is fully represented in the message. */
+ return get_opt_end (&result, result, endp);
+}
+
+
+/* RFC 2292, 6.3.6
+
+ This function is similar to the previously described
+ 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. cmsg is a
+ pointer to cmsghdr structure of which cmsg_level equals IPPROTO_IPV6
+ and cmsg_type equals either IPV6_HOPOPTS or IPV6_DSTOPTS. */
+int
+inet6_option_find (cmsg, tptrp, type)
+ const struct cmsghdr *cmsg;
+ uint8_t **tptrp;
+ int type;
+{
+ /* Make sure it is an option of the right type. */
+ if (cmsg->cmsg_level != IPPROTO_IPV6
+ || (cmsg->cmsg_type != IPV6_HOPOPTS && cmsg->cmsg_type != IPV6_DSTOPTS))
+ return -1;
+
+ /* Pointer to the extension header. We only compute the address, we
+ don't access anything yet. */
+ const struct ip6_ext *ip6e = (const struct ip6_ext *) CMSG_DATA (cmsg);
+
+ /* Make sure the message is long enough. */
+ if (cmsg->cmsg_len < CMSG_LEN (sizeof (struct ip6_ext))
+ /* Now we can access the extension header. */
+ || cmsg->cmsg_len < CMSG_LEN ((ip6e->ip6e_len + 1) * 8))
+ /* Too small. */
+ return -1;
+
+ /* Determine the address of the byte past the message. */
+ const uint8_t *endp = CMSG_DATA (cmsg) + (ip6e->ip6e_len + 1) * 8;
+
+ const uint8_t *next;
+ if (tptrp == NULL)
+ /* This is the first call, return the first option if there is one. */
+ next = (const uint8_t *) (ip6e + 1);
+ else
+ {
+ /* Make sure *TPTRP points to a beginning of a new option in
+ the message. The upper limit is checked in get_opt_end. */
+ if (*tptrp < (const uint8_t *) (ip6e + 1))
+ return -1;
+
+ /* Get the beginning of the next option. */
+ if (get_opt_end (&next, *tptrp, endp) != 0)
+ return -1;
+ }
+
+ /* Now search for the appropriate typed entry. */
+ const uint8_t *result;
+ do
+ {
+ result = next;
+
+ /* Get the end of this entry. */
+ if (get_opt_end (&next, result, endp) != 0)
+ return -1;
+ }
+ while (*result != type);
+
+ /* We know where the next option starts. */
+ *tptrp = (uint8_t *) result;
+
+ /* Success. */
+ return 0;
+}
diff --git a/newlib/libc/sys/linux/net/inet6_option_space.3 b/newlib/libc/sys/linux/net/inet6_option_space.3
deleted file mode 100644
index 328c70f48..000000000
--- a/newlib/libc/sys/linux/net/inet6_option_space.3
+++ /dev/null
@@ -1,445 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" $Id$
-.\" $FreeBSD: src/lib/libc/net/inet6_option_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd December 10, 1999
-.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 Options manipulation
-.\"
-.Sh LIBRARY
-.Lb libc
-.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
-.\"
-Building and parsing the Hop-by-Hop and Destination options is
-complicated due to alignment constranints, padding and
-ancillary data manipulation.
-RFC2292 defines a set of functions to help the application.
-The function prototypes for
-these functions are all in the
-.Aq Li netinet/in.h
-header.
-.\"
-.Ss inet6_option_space
-.Fn inet6_option_space
-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 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
-.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, this 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.
-This is of little consequence, since it is assumed that most
-Hop-by-Hop option headers and Destination option headers carry only
-one option
-(appendix B of [RFC-2460]).
-.\"
-.Ss inet6_option_init
-.Fn inet6_option_init
-is called once per ancillary data object that will
-contain either Hop-by-Hop or Destination options.
-It returns
-.Li 0
-on success or
-.Li -1
-on an error.
-.Pp
-.Fa bp
-is a pointer to previously allocated space that will contain the
-ancillary data object.
-It must be large enough to contain all the
-individual options to be added by later calls to
-.Fn inet6_option_append
-and
-.Fn inet6_option_alloc .
-.Pp
-.Fa cmsgp
-is a pointer to a pointer to a
-.Li cmsghdr
-structure.
-.Fa *cmsgp
-is initialized by this function to point to the
-.Li cmsghdr
-structure constructed by this function in the buffer pointed to by
-.Fa bp .
-.Pp
-.Fa type
-is either
-.Dv IPV6_HOPOPTS
-or
-.Dv IPV6_DSTOPTS .
-This
-.Fa type
-is stored in the
-.Li cmsg_type
-member of the
-.Li cmsghdr
-structure pointed to by
-.Fa *cmsgp .
-.\"
-.Ss inet6_option_append
-This function appends a Hop-by-Hop option or a Destination option
-into an ancillary data object that has been initialized by
-.Fn inet6_option_init .
-This function returns
-.Li 0
-if it succeeds or
-.Li -1
-on an error.
-.Pp
-.Fa cmsg
-is a pointer to the
-.Li cmsghdr
-structure that must have been
-initialized by
-.Fn inet6_option_init .
-.Pp
-.Fa typep
-is a pointer to the 8-bit option type.
-It is assumed that this
-field is immediately followed by the 8-bit option data length field,
-which is then followed immediately by the option data.
-The caller
-initializes these three fields
-(the type-length-value, or TLV)
-before calling this function.
-.Pp
-The option type must have a value from
-.Li 2
-to
-.Li 255 ,
-inclusive.
-.Li ( 0
-and
-.Li 1
-are reserved for the
-.Li Pad1
-and
-.Li PadN
-options, respectively.)
-.Pp
-The option data length must have a value between
-.Li 0
-and
-.Li 255 ,
-inclusive, and is the length of the option data that follows.
-.Pp
-.Fa multx
-is the value
-.Li x
-in the alignment term
-.Dq Li xn + y .
-It must have a value of
-.Li 1 ,
-.Li 2 ,
-.Li 4 ,
-or
-.Li 8 .
-.Pp
-.Fa plusy
-is the value
-.Li y
-in the alignment term
-.Dq Li xn + y .
-It must have a value between
-.Li 0
-and
-.Li 7 ,
-inclusive.
-.\"
-.Ss inet6_option_alloc
-This function appends a Hop-by-Hop option or a Destination option
-into an ancillary data object that has been initialized by
-.Fn inet6_option_init .
-This function returns a pointer to the 8-bit
-option type field that starts the option on success, or
-.Dv NULL
-on an error.
-.Pp
-The difference between this function and
-.Fn 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.
-.Pp
-.Fa cmsg
-is a pointer to the
-.Li cmsghdr
-structure that must have been
-initialized by
-.Fn inet6_option_init .
-.Pp
-.Fa datalen
-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
-.Fa multx
-is the value
-.Li x
-in the alignment term
-.Dq Li xn + y .
-It must have a value of
-.Li 1 ,
-.Li 2 ,
-.Li 4 ,
-or
-.Li 8 .
-.Pp
-.Fa plusy
-is the value
-.Li y
-in the alignment term
-.Dq Li xn + y .
-It must have a value between
-.Li 0
-and
-.Li 7 ,
-inclusive.
-.\"
-.Ss inet6_option_next
-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
-.Li 0
-and
-.Fa *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
-.Li -1
-and
-.Fa *tptrp
-is
-.Dv NULL .
-If an error occurs, the return value is
-.Li -1
-and
-.Fa *tptrp
-is not
-.Dv NULL .
-.Pp
-.Fa cmsg
-is a pointer to
-.Li cmsghdr
-structure of which
-.Li cmsg_level
-equals
-.Dv IPPROTO_IPV6
-and
-.Li cmsg_type
-equals either
-.Dv IPV6_HOPOPTS
-or
-.Dv IPV6_DSTOPTS .
-.Pp
-.Fa tptrp
-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.
-The first time this function is
-called for a given ancillary data object,
-.Fa *tptrp
-must be set to
-.Dv NULL .
-.Pp
-Each time this function returns success,
-.Fa *tptrp
-points to the 8-bit
-option type field for the next option to be processed.
-.\"
-.Ss inet6_option_find
-This function is similar to the previously described
-.Fn 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.
-.Fa cmsg
-is a
-pointer to
-.Li cmsghdr
-structure of which
-.Li cmsg_level
-equals
-.Dv IPPROTO_IPV6
-and
-.Li cmsg_type
-equals either
-.Dv IPV6_HOPOPTS
-or
-.Dv IPV6_DSTOPTS .
-.Pp
-.Fa tptrp
-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.
-The first time this function is
-called for a given ancillary data object,
-.Fa *tptrp
-must be set to
-.Dv NULL .
-.Pa
-This function starts searching for an option of the specified type
-beginning after the value of
-.Fa *tptrp .
-If an option of the specified
-type is located, this function returns
-.Li 0
-and
-.Fa *tptrp
-points to the 8-
-bit option type field for the option of the specified type.
-If an
-option of the specified type is not located, the return value is
-.Li -1
-and
-.Fa *tptrp
-is
-.Dv NULL .
-If an error occurs, the return value is
-.Li -1
-and
-.Fa *tptrp
-is not
-.Dv NULL .
-.\"
-.Sh DIAGNOSTICS
-.Fn inet6_option_init
-and
-.Fn inet6_option_append
-return
-.Li 0
-on success or
-.Li -1
-on an error.
-.Pp
-.Fn inet6_option_alloc
-returns
-.Dv NULL
-on an error.
-.Pp
-On errors,
-.Fn inet6_option_next
-and
-.Fn inet6_option_find
-return
-.Li -1
-setting
-.Fa *tptrp
-to non
-.Dv NULL
-value.
-.\"
-.Sh EXAMPLES
-RFC2292 gives comprehensive examples in chapter 6.
-.\"
-.Sh SEE ALSO
-.Rs
-.%A W. Stevens
-.%A M. Thomas
-.%T "Advanced Sockets API for IPv6"
-.%N RFC2292
-.%D February 1998
-.Re
-.Rs
-.%A S. Deering
-.%A R. Hinden
-.%T "Internet Protocol, Version 6 (IPv6) Specification"
-.%N RFC2460
-.%D December 1998
-.Re
-.\"
-.Sh HISTORY
-The implementation first appeared in KAME advanced networking kit.
-.\"
-.Sh STANDARDS
-The functions
-are documented in
-.Dq Advanced Sockets API for IPv6
-(RFC2292).
-.\"
-.Sh BUGS
-The text was shamelessly copied from RFC2292.
diff --git a/newlib/libc/sys/linux/net/inet6_rthdr_space.3 b/newlib/libc/sys/linux/net/inet6_rthdr_space.3
deleted file mode 100644
index d2c575dca..000000000
--- a/newlib/libc/sys/linux/net/inet6_rthdr_space.3
+++ /dev/null
@@ -1,323 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" $Id$
-.\" $FreeBSD: src/lib/libc/net/inet6_rthdr_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $
-.\"
-.Dd December 10, 1999
-.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 LIBRARY
-.Lb libc
-.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
-RFC2292 IPv6 advanced API defines eight
-functions that the application calls to build and examine a Routing
-header. Four functions build a Routing header:
-.Bl -hang
-.It Fn inet6_rthdr_space
-return #bytes required for ancillary data
-.It Fn inet6_rthdr_init
-initialize ancillary data for Routing header
-.It Fn inet6_rthdr_add
-add IPv6 address & flags to Routing header
-.It Fn inet6_rthdr_lasthop
-specify the flags for the final hop
-.El
-.Pp
-Four functions deal with a returned Routing header:
-.Bl -hang
-.It Fn inet6_rthdr_reverse
-reverse a Routing header
-.It Fn inet6_rthdr_segments
-return #segments in a Routing header
-.It Fn inet6_rthdr_getaddr
-fetch one address from a Routing header
-.It Fn inet6_rthdr_getflags
-fetch one flag from a Routing header
-.El
-.Pp
-The function prototypes for these functions are all in the
-.Aq Li netinet/in.h
-header.
-.\"
-.Ss inet6_rthdr_space
-This function returns the number of bytes required to hold a Routing
-header of the specified
-.Fa type
-containing the specified number of
-.Fa segments
-(addresses).
-For an IPv6 Type 0 Routing header, the number
-of segments must be between 1 and 23, inclusive. The return value
-includes the size of the cmsghdr structure that precedes the Routing
-header, and any required padding.
-.Pp
-If the return value is 0, then either the type of the Routing header
-is not supported by this implementation or the number of segments is
-invalid for this type of Routing header.
-.Pp
-Note: This function returns the size but does not allocate the space
-required for the ancillary data.
-This allows an application to
-allocate a larger buffer, if other ancillary data objects are
-desired, since all the ancillary data objects must be specified to
-.Xr sendmsg 2
-as a single
-.Li msg_control
-buffer.
-.\"
-.Ss inet6_rthdr_init
-This function initializes the buffer pointed to by
-.Fa bp
-to contain a
-.Li cmsghdr
-structure followed by a Routing header of the specified
-.Fa type .
-The
-.Li cmsg_len
-member of the
-.Li cmsghdr
-structure is initialized to the
-size of the structure plus the amount of space required by the
-Routing header.
-The
-.Li cmsg_level
-and
-.Li cmsg_type
-members are also initialized as required.
-.Pp
-The caller must allocate the buffer and its size can be determined by
-calling
-.Fn inet6_rthdr_space .
-.Pp
-Upon success the return value is the pointer to the
-.Li cmsghdr
-structure, and this is then used as the first argument to the next
-two functions.
-Upon an error the return value is
-.Dv NULL .
-.\"
-.Ss inet6_rthdr_add
-This function adds the address pointed to by
-.Fa addr
-to the end of the
-Routing header being constructed and sets the type of this hop to the
-value of
-.Fa flags .
-For an IPv6 Type 0 Routing header,
-.Fa flags
-must be
-either
-.Dv IPV6_RTHDR_LOOSE
-or
-.Dv IPV6_RTHDR_STRICT .
-.Pp
-If successful, the
-.Li cmsg_len
-member of the
-.Li cmsghdr
-structure is
-updated to account for the new address in the Routing header and the
-return value of the function is 0.
-Upon an error the return value of
-the function is -1.
-.\"
-.Ss inet6_rthdr_lasthop
-This function specifies the Strict/Loose flag for the final hop of a
-Routing header.
-For an IPv6 Type 0 Routing header,
-.Fa flags
-must be either
-.Dv IPV6_RTHDR_LOOSE
-or
-.Dv IPV6_RTHDR_STRICT .
-.Pp
-The return value of the function is 0 upon success, or -1 upon an error.
-.Pp
-Notice that a Routing header specifying
-.Li N
-intermediate nodes requires
-.Li N+1
-Strict/Loose flags.
-This requires
-.Li N
-calls to
-.Fn inet6_rthdr_add
-followed by one call to
-.Fn inet6_rthdr_lasthop .
-.\"
-.Ss inet6_rthdr_reverse
-This function is not yet implemented.
-When implemented, this should behave as follows.
-.Pp
-This function takes a Routing header that was received as ancillary
-data
-(pointed to by the first argument,
-.Fa in )
-and writes a new Routing
-header that sends datagrams along the reverse of that route.
-Both
-arguments are allowed to point to the same buffer
-(that is, the reversal can occur in place).
-.Pp
-The return value of the function is 0 on success, or -1 upon an
-error.
-.\"
-.Ss inet6_rthdr_segments
-This function returns the number of segments
-(addresses)
-contained in
-the Routing header described by
-.Fa cmsg .
-On success the return value is
-between 1 and 23, inclusive.
-The return value of the function is -1 upon an error.
-.\"
-.Ss inet6_rthdr_getaddr
-This function returns a pointer to the IPv6 address specified by
-.Fa index
-(which must have a value between 1 and the value returned by
-.Fn inet6_rthdr_segments )
-in the Routing header described by
-.Fa cmsg .
-An
-application should first call
-.Fn inet6_rthdr_segments
-to obtain the number of segments in the Routing header.
-.Pp
-Upon an error the return value of the function is
-.Dv NULL .
-.\"
-.Ss inet6_rthdr_getflags
-This function returns the flags value specified by
-.Fa index
-(which must
-have a value between 0 and the value returned by
-.Fn inet6_rthdr_segments )
-in the Routing header described by
-.Fa cmsg .
-For an IPv6 Type 0 Routing header the return value will be either
-.Dv IPV6_RTHDR_LOOSE
-or
-.Dv IPV6_RTHDR_STRICT .
-.Pp
-Upon an error the return value of the function is -1.
-.Pp
-Note: Addresses are indexed starting at 1, and flags starting at 0,
-to maintain consistency with the terminology and figures in RFC2460.
-.\"
-.Sh DIAGNOSTICS
-.Fn inet6_rthdr_space
-returns 0 on errors.
-.Pp
-.Fn inet6_rthdr_add ,
-.Fn inet6_rthdr_lasthop
-and
-.Fn inet6_rthdr_reverse
-return 0 on success, and returns -1 on error.
-.Pp
-.Fn inet6_rthdr_init
-and
-.Fn inet6_rthdr_getaddr
-return
-.Dv NULL
-on error.
-.Pp
-.Fn inet6_rthdr_segments
-and
-.Fn inet6_rthdr_getflags
-return -1 on error.
-.\"
-.Sh EXAMPLES
-RFC2292 gives comprehensive examples in chapter 8.
-.\"
-.Sh SEE ALSO
-.Rs
-.%A W. Stevens
-.%A M. Thomas
-.%T "Advanced Sockets API for IPv6"
-.%N RFC2292
-.%D February 1998
-.Re
-.Rs
-.%A S. Deering
-.%A R. Hinden
-.%T "Internet Protocol, Version 6 (IPv6) Specification"
-.%N RFC2460
-.%D December 1998
-.Re
-.\"
-.Sh HISTORY
-The implementation first appeared in KAME advanced networking kit.
-.\"
-.Sh STANDARDS
-The functions
-are documented in
-.Dq Advanced Sockets API for IPv6
-(RFC2292).
-.\"
-.Sh BUGS
-The text was shamelessly copied from RFC2292.
-.Pp
-.Fn inet6_rthdr_reverse
-is not implemented yet.
diff --git a/newlib/libc/sys/linux/net/inet_lnaof.c b/newlib/libc/sys/linux/net/inet_lnaof.c
index c6c999dd1..0e115a442 100644
--- a/newlib/libc/sys/linux/net/inet_lnaof.c
+++ b/newlib/libc/sys/linux/net/inet_lnaof.c
@@ -10,10 +10,6 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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.
@@ -34,9 +30,6 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
#include <sys/param.h>
#include <netinet/in.h>
@@ -51,7 +44,7 @@ in_addr_t
inet_lnaof(in)
struct in_addr in;
{
- in_addr_t i = ntohl(in.s_addr);
+ register u_int32_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return ((i)&IN_CLASSA_HOST);
@@ -60,10 +53,3 @@ inet_lnaof(in)
else
return ((i)&IN_CLASSC_HOST);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_lnaof
-__weak_reference(__inet_lnaof, inet_lnaof);
diff --git a/newlib/libc/sys/linux/net/inet_makeaddr.c b/newlib/libc/sys/linux/net/inet_mkadr.c
index 339b2d5a7..26d54f244 100644
--- a/newlib/libc/sys/linux/net/inet_makeaddr.c
+++ b/newlib/libc/sys/linux/net/inet_mkadr.c
@@ -10,10 +10,6 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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.
@@ -34,13 +30,11 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "libc-symbols.h"
/*
* Formulate an Internet address from network + host. Used in
@@ -50,23 +44,17 @@ struct in_addr
inet_makeaddr(net, host)
in_addr_t net, host;
{
- in_addr_t addr;
+ struct in_addr in;
if (net < 128)
- addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+ in.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
else if (net < 65536)
- addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+ in.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
else if (net < 16777216L)
- addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+ in.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
else
- addr = net | host;
- addr = htonl(addr);
- return (*(struct in_addr *)&addr);
+ in.s_addr = net | host;
+ in.s_addr = htonl(in.s_addr);
+ return in;
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_makeaddr
-__weak_reference(__inet_makeaddr, inet_makeaddr);
+libc_hidden_def (inet_makeaddr)
diff --git a/newlib/libc/sys/linux/net/inet_net.3 b/newlib/libc/sys/linux/net/inet_net.3
deleted file mode 100644
index 1d43bcc1d..000000000
--- a/newlib/libc/sys/linux/net/inet_net.3
+++ /dev/null
@@ -1,157 +0,0 @@
-.\" $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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.
-.\"
-.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.1 2001/08/31 10:54:44 ru Exp $
-.\"
-.Dd June 18, 1997
-.Dt INET_NET 3
-.Os
-.Sh NAME
-.Nm inet_net_ntop ,
-.Nm inet_net_pton
-.Nd Internet network number manipulation routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In netinet/in.h
-.In arpa/inet.h
-.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
-.Vt "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
-.Vt "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
-The only value for
-.Fa af
-currently supported is
-.Dv AF_INET .
-.Fa size
-is the size of the result buffer
-.Fa dst .
-.Pp
-.Sh NETWORK NUMBERS (IP VERSION 4)
-Internet network numbers may be specified in one of the following forms:
-.Bd -literal -offset indent
-a.b.c.d/bits
-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 network number.
-Note
-that when an Internet network number is viewed as a 32-bit
-integer quantity on a system that uses little-endian
-byte order (such as the
-.Tn Intel 386 , 486 ,
-and
-.Tn 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 number is specified, the last
-part is interpreted as a 16-bit quantity and placed
-in the rightmost two bytes of the Internet network number.
-This makes the three part number format convenient
-for specifying Class B network numbers as
-.Dq Li 128.net.host .
-.Pp
-When a two part number is supplied, the last part
-is interpreted as a 24-bit quantity and placed in
-the rightmost three bytes of the Internet network number.
-This makes the two part number format convenient
-for specifying Class A network numbers as
-.Dq Li net.host .
-.Pp
-When only one part is given, the value is stored
-directly in the Internet network number without any byte
-rearrangement.
-.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 SEE ALSO
-.Xr byteorder 3 ,
-.Xr inet 3 ,
-.Xr networks 5
-.Sh HISTORY
-The
-.Fn inet_net_ntop
-and
-.Fn inet_net_pton
-functions appeared in BIND 4.9.4.
diff --git a/newlib/libc/sys/linux/net/inet_network.c b/newlib/libc/sys/linux/net/inet_net.c
index caf1d7869..e9331c592 100644
--- a/newlib/libc/sys/linux/net/inet_network.c
+++ b/newlib/libc/sys/linux/net/inet_net.c
@@ -10,10 +10,6 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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.
@@ -34,8 +30,6 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
#include <sys/types.h>
#include <netinet/in.h>
@@ -47,41 +41,49 @@ static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93";
* The library routines call this routine to interpret
* network numbers.
*/
-in_addr_t
+u_int32_t
inet_network(cp)
- const char *cp;
+ register const char *cp;
{
- in_addr_t val, base, n;
- char c;
- in_addr_t parts[4], *pp = parts;
- int i;
+ register u_int32_t val, base, n, i;
+ register char c;
+ u_int32_t parts[4], *pp = parts;
+ int digit;
again:
- val = 0; base = 10;
+ val = 0; base = 10; digit = 0;
if (*cp == '0')
- base = 8, cp++;
+ digit = 1, base = 8, cp++;
if (*cp == 'x' || *cp == 'X')
base = 16, cp++;
while ((c = *cp) != 0) {
- if (isdigit((unsigned char)c)) {
+ if (isdigit(c)) {
+ if (base == 8 && (c == '8' || c == '9'))
+ return (INADDR_NONE);
val = (val * base) + (c - '0');
cp++;
+ digit = 1;
continue;
}
- if (base == 16 && isxdigit((unsigned char)c)) {
- val = (val << 4) + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
+ if (base == 16 && isxdigit(c)) {
+ val = (val << 4) + (tolower (c) + 10 - 'a');
cp++;
+ digit = 1;
continue;
}
break;
}
+ if (!digit)
+ return (INADDR_NONE);
+ if (pp >= parts + 4 || val > 0xff)
+ return (INADDR_NONE);
if (*cp == '.') {
- if (pp >= parts + 3)
- return (INADDR_NONE);
*pp++ = val, cp++;
goto again;
}
- if (*cp && !isspace((unsigned char)*cp))
+ if (*cp && !isspace(*cp))
+ return (INADDR_NONE);
+ if (pp >= parts + 4 || val > 0xff)
return (INADDR_NONE);
*pp++ = val;
n = pp - parts;
@@ -91,10 +93,3 @@ again:
}
return (val);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_network
-__weak_reference(__inet_network, inet_network);
diff --git a/newlib/libc/sys/linux/net/inet_netof.c b/newlib/libc/sys/linux/net/inet_netof.c
index e2e84d340..3035f3402 100644
--- a/newlib/libc/sys/linux/net/inet_netof.c
+++ b/newlib/libc/sys/linux/net/inet_netof.c
@@ -10,10 +10,6 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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.
@@ -34,13 +30,11 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "libc-symbols.h"
/*
* Return the network number from an internet
@@ -50,7 +44,7 @@ in_addr_t
inet_netof(in)
struct in_addr in;
{
- in_addr_t i = ntohl(in.s_addr);
+ register u_int32_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
@@ -59,10 +53,4 @@ inet_netof(in)
else
return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_netof
-__weak_reference(__inet_netof, inet_netof);
+libc_hidden_def (inet_netof)
diff --git a/newlib/libc/sys/linux/net/inet_ntoa.c b/newlib/libc/sys/linux/net/inet_ntoa.c
index dedc4768d..b0b7a1535 100644
--- a/newlib/libc/sys/linux/net/inet_ntoa.c
+++ b/newlib/libc/sys/linux/net/inet_ntoa.c
@@ -1,67 +1,98 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+/* Convert Inet number to ASCII representation.
+ Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
#include <stdio.h>
-#include <string.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <bits/libc-lock.h>
+
+/* The interface of this function is completely stupid, it requires a
+ static buffer. We relax this a bit in that we allow at least one
+ buffer for each thread. */
+
+/* This is the key for the thread specific memory. */
+static __libc_key_t key;
+
+/* If nonzero the key allocation failed and we should better use a
+ static buffer than fail. */
+static char local_buf[18];
+static char *static_buf;
+
+/* Destructor for the thread-specific data. */
+static void init (void);
+static void free_key_mem (void *mem);
+
-/*
- * Convert network-format internet address
- * to base 256 d.d.d.d representation.
- */
char *
-inet_ntoa(in)
- struct in_addr in;
+inet_ntoa (struct in_addr in)
{
- static char ret[18];
+ __libc_once_define (static, once);
+ char *buffer;
+ unsigned char *bytes;
- strcpy(ret, "[inet_ntoa error]");
- (void) inet_ntop(AF_INET, &in, ret, sizeof ret);
- return (ret);
+ /* If we have not yet initialized the buffer do it now. */
+ __libc_once (once, init);
+
+ if (static_buf != NULL)
+ buffer = static_buf;
+ else
+ {
+ /* We don't use the static buffer and so we have a key. Use it
+ to get the thread-specific buffer. */
+ buffer = __libc_getspecific (key);
+ if (buffer == NULL)
+ {
+ /* No buffer allocated so far. */
+ buffer = malloc (18);
+ if (buffer == NULL)
+ /* No more memory available. We use the static buffer. */
+ buffer = local_buf;
+ else
+ __libc_setspecific (key, buffer);
+ }
+ }
+
+ bytes = (unsigned char *) &in;
+ snprintf (buffer, 18, "%d.%d.%d.%d",
+ bytes[0], bytes[1], bytes[2], bytes[3]);
+
+ return buffer;
+}
+
+
+/* Initialize buffer. */
+static void
+init (void)
+{
+ if (__libc_key_create (&key, free_key_mem))
+ /* Creating the key failed. This means something really went
+ wrong. In any case use a static buffer which is better than
+ nothing. */
+ static_buf = local_buf;
}
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_ntoa
-__weak_reference(__inet_ntoa, inet_ntoa);
+
+/* Free the thread specific data, this is done if a thread terminates. */
+static void
+free_key_mem (void *mem)
+{
+ free (mem);
+ __libc_setspecific (key, NULL);
+}
diff --git a/newlib/libc/sys/linux/net/innetgr-stub.c b/newlib/libc/sys/linux/net/innetgr-stub.c
deleted file mode 100644
index 690d82e14..000000000
--- a/newlib/libc/sys/linux/net/innetgr-stub.c
+++ /dev/null
@@ -1,7 +0,0 @@
-int
-innetgr(const char *netgroup, const char *host, const char *user,
- const char *domain)
-{
- return 0;
-}
-
diff --git a/newlib/libc/sys/linux/net/ip6opt.c b/newlib/libc/sys/linux/net/ip6opt.c
deleted file mode 100644
index f3f51d507..000000000
--- a/newlib/libc/sys/linux/net/ip6opt.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * 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 <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-
-#include <string.h>
-#include <stdio.h>
-
-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(nbytes)
- 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(bp, cmsgp, type)
- 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(cmsg, typep, multx, plusy)
- 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 (typep[0] > 255)
- return(-1);
-
- /*
- * 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;
- /* 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(cmsg, datalen, multx, plusy)
- 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;
- /* 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(cmsg, tptrp)
- 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(cmsg, tptrp, type)
- 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(opt, lim)
- u_int8_t *opt, *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;
- }
-}
diff --git a/newlib/libc/sys/linux/net/iso_addr.3 b/newlib/libc/sys/linux/net/iso_addr.3
deleted file mode 100644
index dc843c315..000000000
--- a/newlib/libc/sys/linux/net/iso_addr.3
+++ /dev/null
@@ -1,113 +0,0 @@
-.\" Copyright (c) 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)iso_addr.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/iso_addr.3,v 1.7 2001/10/01 16:08:56 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt ISO_ADDR 3
-.Os
-.Sh NAME
-.Nm iso_addr ,
-.Nm iso_ntoa
-.Nd "elementary network address conversion routines for Open System Interconnection
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In netiso/iso.h
-.Ft struct iso_addr *
-.Fn iso_addr "char *cp"
-.Ft char *
-.Fn iso_ntoa "struct iso_addr *isoa"
-.Sh DESCRIPTION
-The routine
-.Fn iso_addr
-interprets character strings representing
-.Tn OSI
-addresses, returning binary information suitable
-for use in system calls.
-The routine
-.Fn iso_ntoa
-takes
-.Tn OSI
-addresses and returns
-.Tn ASCII
-strings representing NSAPs (network service
-access points) in a
-notation inverse to that accepted by
-.Fn iso_addr .
-.Pp
-Unfortunately, no universal standard exists for representing
-.Tn OSI
-network addresses.
-.Pp
-The format employed by
-.Fn iso_addr
-is a sequence of hexadecimal
-.Dq digits
-(optionally separated by periods),
-of the form:
-.Bd -ragged -offset indent
-<hex digits>.<hex digits>.<hex digits>
-.Ed
-.Pp
-Each pair of hexadecimal digits represents a byte
-with the leading digit indicating the higher-ordered bits.
-A period following an even number of bytes has no
-effect (but may be used to increase legibility).
-A period following an odd number of bytes has the
-effect of causing the byte of address being translated
-to have its higher order bits filled with zeros.
-.Sh RETURN VALUES
-.Fn iso_ntoa
-always returns a null terminated string.
-.Fn iso_addr
-always returns a pointer to a struct iso_addr.
-(See
-.Sx BUGS . )
-.Sh SEE ALSO
-.Xr iso 4
-.Sh HISTORY
-The
-.Fn iso_addr
-and
-.Fn iso_ntoa
-functions appeared in
-.Bx 4.3 Reno .
-.Sh BUGS
-The returned values
-reside in a static memory area.
-.Pp
-The function
-.Fn iso_addr
-should diagnose improperly formed input, and there should be an unambiguous
-way to recognize this.
diff --git a/newlib/libc/sys/linux/net/iso_addr.c b/newlib/libc/sys/linux/net/iso_addr.c
deleted file mode 100644
index e943122f8..000000000
--- a/newlib/libc/sys/linux/net/iso_addr.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 1989, 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)iso_addr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <netiso/iso.h>
-#include <string.h>
-
-/* States*/
-#define VIRGIN 0
-#define GOTONE 1
-#define GOTTWO 2
-/* Inputs */
-#define DIGIT (4*0)
-#define END (4*1)
-#define DELIM (4*2)
-
-struct iso_addr *
-iso_addr(addr)
- const char *addr;
-{
- static struct iso_addr out_addr;
- char *cp = out_addr.isoa_genaddr;
- char *cplim = cp + sizeof(out_addr.isoa_genaddr);
- int byte = 0, state = VIRGIN, new;
-
- bzero((char *)&out_addr, sizeof(out_addr));
- do {
- 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
- state |= DELIM;
- addr++;
- switch (state /* | INPUT */) {
- case GOTTWO | DIGIT:
- *cp++ = byte; /*FALLTHROUGH*/
- case VIRGIN | DIGIT:
- state = GOTONE; byte = new; continue;
- case GOTONE | DIGIT:
- state = GOTTWO; byte = new + (byte << 4); continue;
- default: /* | DELIM */
- state = VIRGIN; *cp++ = byte; byte = 0; continue;
- case GOTONE | END:
- case GOTTWO | END:
- *cp++ = byte; /* FALLTHROUGH */
- case VIRGIN | END:
- break;
- }
- break;
- } while (cp < cplim);
- out_addr.isoa_len = cp - out_addr.isoa_genaddr;
- return (&out_addr);
-}
-
-static char hexlist[] = "0123456789abcdef";
-
-char *
-iso_ntoa(isoa)
- const struct iso_addr *isoa;
-{
- static char tmpbuf[sizeof(isoa->isoa_genaddr)*3];
- const u_char *binary;
- char *cp;
- int i;
-
- binary = isoa->isoa_genaddr;
- cp = tmpbuf;
-
- for (i = 0; i < isoa->isoa_len; i++) {
- *cp++ = hexlist[*binary >> 4];
- *cp++ = hexlist[*binary++ & 0xf];
-
- if ((((i % 2) == 0) && ((i + 1) < isoa->isoa_len)))
- *cp++ = '.';
- }
- *cp = '\0';
- return tmpbuf;
-}
diff --git a/newlib/libc/sys/linux/net/key-lookup.c b/newlib/libc/sys/linux/net/key-lookup.c
new file mode 100644
index 000000000..e2c4c14a6
--- /dev/null
+++ b/newlib/libc/sys/linux/net/key-lookup.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME publickey
+#define DEFAULT_CONFIG "nis nisplus"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/linkaddr.3 b/newlib/libc/sys/linux/net/linkaddr.3
deleted file mode 100644
index 1d664630b..000000000
--- a/newlib/libc/sys/linux/net/linkaddr.3
+++ /dev/null
@@ -1,140 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93
-.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.12 2001/10/01 16:08:56 ru Exp $
-.\"
-.Dd June 17, 1996
-.Dt LINK_ADDR 3
-.Os
-.Sh NAME
-.Nm link_addr ,
-.Nm link_ntoa
-.Nd elementary address specification routines for link level access
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In sys/socket.h
-.In net/if_dl.h
-.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 routine
-.Fn link_addr
-interprets character strings representing
-link-level addresses, returning binary information suitable
-for use in system calls.
-The routine
-.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.
-.Pp
-The direct use of these functions is deprecated in favor of the
-.Xr addr2ascii 3
-interface; however, portable programs cannot rely on the latter as it is
-not yet widely implemented.
-.Sh RETURN VALUES
-.Fn link_ntoa
-always returns a null terminated string.
-.Fn link_addr
-has no return value.
-(See
-.Sx BUGS . )
-.Sh SEE ALSO
-.Xr addr2ascii 3
-.\" .Xr iso 4
-.Sh HISTORY
-The
-.Fn link_addr
-and
-.Fn link_ntoa
-functions appeared in
-.Bx 4.3 Reno .
-.Sh BUGS
-The returned values for 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
-.Va 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/newlib/libc/sys/linux/net/linkaddr.c b/newlib/libc/sys/linux/net/linkaddr.c
deleted file mode 100644
index deeaa09ea..000000000
--- a/newlib/libc/sys/linux/net/linkaddr.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*-
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if_dl.h>
-#include <string.h>
-
-/* 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(addr, sdl)
- 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 = 0;
-
- bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
- sdl->sdl_family = AF_INET;
- 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(sdl)
- 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/newlib/libc/sys/linux/net/local.h b/newlib/libc/sys/linux/net/local.h
new file mode 100644
index 000000000..9380d7c55
--- /dev/null
+++ b/newlib/libc/sys/linux/net/local.h
@@ -0,0 +1,24 @@
+#include <alloca.h>
+#include "libc-symbols.h"
+
+# define extend_alloca(buf, len, newlen) \
+ (__typeof (buf)) ({ size_t __newlen = (newlen); \
+ char *__newbuf = alloca (__newlen); \
+ if (__newbuf > (char *)buf) \
+ if ((char *)buf + len == __newbuf) { \
+ len += __newlen; \
+ __newbuf = buf; \
+ } \
+ else { \
+ if (__newbuf + newlen == (char *)buf) \
+ len += __newlen; \
+ else \
+ len = __newlen; \
+ } \
+ __newbuf; })
+
+#define __fsetlocking(fp, x) fp
+
+extern const char *_res_opcodes[];
+libresolv_hidden_proto (_res_opcodes)
+
diff --git a/newlib/libc/sys/linux/net/map_v4v6.c b/newlib/libc/sys/linux/net/map_v4v6.c
deleted file mode 100644
index f746a8088..000000000
--- a/newlib/libc/sys/linux/net/map_v4v6.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ++Copyright++ 1985, 1988, 1993
- * -
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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--
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <ctype.h>
-#include <syslog.h>
-
-typedef union {
- int32_t al;
- char ac;
-} align;
-
-void
-_map_v4v6_address(src, dst)
- 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);
-}
-
-void
-_map_v4v6_hostent(hp, bpp, lenp)
- struct hostent *hp;
- char **bpp;
- int *lenp;
-{
- 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 (*lenp < (i + IN6ADDRSZ)) {
- /* Out of memory. Truncate address list here. XXX */
- *ap = NULL;
- return;
- }
- *bpp += i;
- *lenp -= i;
- _map_v4v6_address(*ap, *bpp);
- *ap = *bpp;
- *bpp += IN6ADDRSZ;
- *lenp -= IN6ADDRSZ;
- }
-}
diff --git a/newlib/libc/sys/linux/net/name6.c b/newlib/libc/sys/linux/net/name6.c
deleted file mode 100644
index f220e213c..000000000
--- a/newlib/libc/sys/linux/net/name6.c
+++ /dev/null
@@ -1,1812 +0,0 @@
-/* $KAME: name6.c,v 1.25 2000/06/26 16:44:40 itojun Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, 1998, and 1999 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.
- */
-/*
- * ++Copyright++ 1985, 1988, 1993
- * -
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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--
- */
-
-/*
- * Atsushi Onoe <onoe@sm.sony.co.jp>
- */
-
-/*
- * TODO for thread safe
- * use mutex for _hostconf, _hostconf_init.
- * rewrite resolvers to be thread safe
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/queue.h>
-#include <netinet/in.h>
-
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <nsswitch.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-#ifndef _PATH_HOSTS
-#define _PATH_HOSTS "/etc/hosts"
-#endif
-
-#ifndef MAXALIASES
-#define MAXALIASES 35
-#endif
-#ifndef MAXADDRS
-#define MAXADDRS 2
-#endif
-#ifndef MAXDNAME
-#define MAXDNAME 1025
-#endif
-
-#ifdef INET6
-#define ADDRLEN(af) ((af) == AF_INET6 ? sizeof(struct in6_addr) : \
- sizeof(struct in_addr))
-#else
-#define ADDRLEN(af) sizeof(struct in_addr)
-#endif
-
-#define MAPADDR(ab, ina) \
-do { \
- memcpy(&(ab)->map_inaddr, ina, sizeof(struct in_addr)); \
- memset((ab)->map_zero, 0, sizeof((ab)->map_zero)); \
- memset((ab)->map_one, 0xff, sizeof((ab)->map_one)); \
-} while (0)
-#define MAPADDRENABLED(flags) \
- (((flags) & AI_V4MAPPED) || \
- (((flags) & AI_V4MAPPED_CFG) && _mapped_addr_enabled()))
-
-union inx_addr {
- struct in_addr in_addr;
-#ifdef INET6
- struct in6_addr in6_addr;
-#endif
- struct {
- u_char mau_zero[10];
- u_char mau_one[2];
- struct in_addr mau_inaddr;
- } map_addr_un;
-#define map_zero map_addr_un.mau_zero
-#define map_one map_addr_un.mau_one
-#define map_inaddr map_addr_un.mau_inaddr
-};
-
-u_int16_t _getshort(const u_char *src);
-
-static struct hostent *_hpcopy(struct hostent *hp, int *errp);
-static struct hostent *_hpaddr(int af, const char *name, void *addr, int *errp);
-static struct hostent *_hpmerge(struct hostent *hp1, struct hostent *hp2, int *errp);
-#ifdef INET6
-static struct hostent *_hpmapv6(struct hostent *hp, int *errp);
-#endif
-static struct hostent *_hpsort(struct hostent *hp);
-static struct hostent *_ghbyname(const char *name, int af, int flags, int *errp);
-static char *_hgetword(char **pp);
-static int _mapped_addr_enabled(void);
-
-static FILE *_files_open(int *errp);
-static int _files_ghbyname(void *, void *, va_list);
-static int _files_ghbyaddr(void *, void *, va_list);
-#if 0 // keep gcc happy
-static void _files_shent(int stayopen);
-static void _files_ehent(void);
-#endif
-#ifdef YP
-static int _nis_ghbyname(void *, void *, va_list);
-static int _nis_ghbyaddr(void *, void *, va_list);
-#endif
-static int _dns_ghbyname(void *, void *, va_list);
-static int _dns_ghbyaddr(void *, void *, va_list);
-#if 0 // keep gcc happy
-static void _dns_shent(int stayopen);
-static void _dns_ehent(void);
-#endif
-
-#ifdef ICMPNL
-static int _icmp_ghbyaddr(void *, void *, va_list);
-#endif /* ICMPNL */
-
-/* Host lookup order if nsswitch.conf is broken or nonexistant */
-static const ns_src default_src[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { NSSRC_DNS, NS_SUCCESS },
-#ifdef ICMPNL
-#define NSSRC_ICMP "icmp"
- { NSSRC_ICMP, NS_SUCCESS },
-#endif
- { 0 }
-};
-
-/*
- * Check if kernel supports mapped address.
- * implementation dependent
- */
-#ifdef __KAME__
-#include <sys/sysctl.h>
-#endif /* __KAME__ */
-
-static int
-_mapped_addr_enabled(void)
-{
- /* implementation dependent check */
-#if defined(__KAME__) && defined(IPV6CTL_MAPPED_ADDR)
- int mib[4];
- size_t len;
- int val;
-
- mib[0] = CTL_NET;
- mib[1] = PF_INET6;
- mib[2] = IPPROTO_IPV6;
- mib[3] = IPV6CTL_MAPPED_ADDR;
- len = sizeof(val);
- if (__sysctl(mib, 4, &val, &len, 0, 0) == 0 && val != 0)
- return 1;
-#endif /* __KAME__ && IPV6CTL_MAPPED_ADDR */
- return 0;
-}
-
-/*
- * Functions defined in RFC2553
- * getipnodebyname, getipnodebyaddr, freehostent
- */
-
-static struct hostent *
-_ghbyname(const char *name, int af, int flags, int *errp)
-{
- struct hostent *hp;
- int rval;
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_files_ghbyname, NULL)
- { NSSRC_DNS, _dns_ghbyname, NULL },
- NS_NIS_CB(_nis_ghbyname, NULL)
- { 0 }
- };
-
- if (flags & AI_ADDRCONFIG) {
- int s;
-
- /*
- * TODO:
- * Note that implementation dependent test for address
- * configuration should be done everytime called
- * (or apropriate interval),
- * because addresses will be dynamically assigned or deleted.
- */
- if (af == AF_UNSPEC) {
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- af = AF_INET;
- else {
- close(s);
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- af = AF_INET6;
- else
- close(s);
- }
-
- }
- if (af != AF_UNSPEC) {
- if ((s = socket(af, SOCK_DGRAM, 0)) < 0)
- return NULL;
- close(s);
- }
- }
-
- rval = nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyname", default_src,
- name, af, errp);
- return (rval == NS_SUCCESS) ? hp : NULL;
-}
-
-/* getipnodebyname() internal routine for multiple query(PF_UNSPEC) support. */
-struct hostent *
-_getipnodebyname_multi(const char *name, int af, int flags, int *errp)
-{
- struct hostent *hp;
- union inx_addr addrbuf;
-
- /* XXX: PF_UNSPEC is only supposed to be passed from getaddrinfo() */
- if (af != AF_INET
-#ifdef INET6
- && af != AF_INET6
-#endif
- && af != PF_UNSPEC
- )
- {
- *errp = NO_RECOVERY;
- return NULL;
- }
-
-#ifdef INET6
- /* special case for literal address */
- if (inet_pton(AF_INET6, name, &addrbuf) == 1) {
- if (af != AF_INET6) {
- *errp = HOST_NOT_FOUND;
- return NULL;
- }
- return _hpaddr(af, name, &addrbuf, errp);
- }
-#endif
- if (inet_aton(name, (struct in_addr *)&addrbuf) == 1) {
- if (af != AF_INET) {
- if (MAPADDRENABLED(flags)) {
- MAPADDR(&addrbuf, &addrbuf.in_addr);
- } else {
- *errp = HOST_NOT_FOUND;
- return NULL;
- }
- }
- return _hpaddr(af, name, &addrbuf, errp);
- }
-
- *errp = HOST_NOT_FOUND;
- hp = _ghbyname(name, af, flags, errp);
-
-#ifdef INET6
- if (af == AF_INET6
- && ((flags & AI_ALL) || hp == NULL)
- && (MAPADDRENABLED(flags))) {
- struct hostent *hp2 = _ghbyname(name, AF_INET, flags, errp);
- if (hp == NULL)
- hp = _hpmapv6(hp2, errp);
- else {
- if (hp2 && strcmp(hp->h_name, hp2->h_name) != 0) {
- freehostent(hp2);
- hp2 = NULL;
- }
- hp = _hpmerge(hp, hp2, errp);
- }
- }
-#endif
- return _hpsort(hp);
-}
-
-struct hostent *
-getipnodebyname(const char *name, int af, int flags, int *errp)
-{
- if (af != AF_INET
-#ifdef INET6
- && af != AF_INET6
-#endif
- )
- {
- *errp = NO_RECOVERY;
- return NULL;
- }
- return(_getipnodebyname_multi(name, af ,flags, errp));
-}
-
-struct hostent *
-getipnodebyaddr(const void *src, size_t len, int af, int *errp)
-{
- struct hostent *hp;
- int rval;
-#ifdef INET6
- struct in6_addr addrbuf;
-#else
- struct in_addr addrbuf;
-#endif
-
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_files_ghbyaddr, NULL)
- { NSSRC_DNS, _dns_ghbyaddr, NULL },
- NS_NIS_CB(_nis_ghbyaddr, NULL)
-#ifdef ICMPNL
- { NSSRC_ICMP, _icmp_ghbyaddr, NULL },
-#endif
- { 0 }
- };
-
- *errp = HOST_NOT_FOUND;
-
- switch (af) {
- case AF_INET:
- if (len != sizeof(struct in_addr)) {
- *errp = NO_RECOVERY;
- return NULL;
- }
- if ((long)src & ~(sizeof(struct in_addr) - 1)) {
- memcpy(&addrbuf, src, len);
- src = &addrbuf;
- }
- if (((struct in_addr *)src)->s_addr == 0)
- return NULL;
- break;
-#ifdef INET6
- case AF_INET6:
- if (len != sizeof(struct in6_addr)) {
- *errp = NO_RECOVERY;
- return NULL;
- }
- if ((long)src & ~(sizeof(struct in6_addr) / 2 - 1)) { /*XXX*/
- memcpy(&addrbuf, src, len);
- src = &addrbuf;
- }
- if (IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *)src))
- return NULL;
- if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src)
- || IN6_IS_ADDR_V4COMPAT((struct in6_addr *)src)) {
- src = (char *)src +
- (sizeof(struct in6_addr) - sizeof(struct in_addr));
- af = AF_INET;
- len = sizeof(struct in_addr);
- }
- break;
-#endif
- default:
- *errp = NO_RECOVERY;
- return NULL;
- }
-
- rval = nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyaddr", default_src,
- src, len, af, errp);
- return (rval == NS_SUCCESS) ? hp : NULL;
-}
-
-void
-freehostent(struct hostent *ptr)
-{
- free(ptr);
-}
-
-#if 0
-
-/* XXX: should be deprecated */
-struct hostent *
-getnodebyname(const char *name, int af, int flags)
-{
- return getipnodebyname(name, af, flags, &h_errno);
-}
-
-#ifdef __warn_references
-__warn_references(getnodebyname,
- "warning: getnodebyname() deprecated, "
- "should use getaddrinfo() or getipnodebyname()");
-#endif
-
-struct hostent *
-getnodebyaddr(const void *src, size_t len, int af)
-{
- return getipnodebyaddr(src, len, af, &h_errno);
-}
-
-#ifdef __warn_references
-__warn_references(getnodebyaddr,
- "warning: getnodebyaddr() deprecated, "
- "should use getnameinfo() or getipnodebyaddr()");
-#endif
-
-#endif
-
-/*
- * Private utility functions
- */
-
-/*
- * _hpcopy: allocate and copy hostent structure
- */
-static struct hostent *
-_hpcopy(struct hostent *hp, int *errp)
-{
- struct hostent *nhp;
- char *cp, **pp;
- int size, addrsize;
- int nalias = 0, naddr = 0;
- int al_off;
- int i;
-
- if (hp == NULL)
- return hp;
-
- /* count size to be allocated */
- size = sizeof(struct hostent);
- if (hp->h_name != NULL)
- size += strlen(hp->h_name) + 1;
- if ((pp = hp->h_aliases) != NULL) {
- for (i = 0; *pp != NULL; i++, pp++) {
- if (**pp != '\0') {
- size += strlen(*pp) + 1;
- nalias++;
- }
- }
- }
- /* adjust alignment */
-#ifdef ALIGN
- size = ALIGN(size);
-#endif
- al_off = size;
- size += sizeof(char *) * (nalias + 1);
-#ifdef ALIGN
- addrsize = ALIGN(hp->h_length);
-#else
- addrsize = hp->h_length;
-#endif
-
- if ((pp = hp->h_addr_list) != NULL) {
- while (*pp++ != NULL)
- naddr++;
- }
- size += addrsize * naddr;
- size += sizeof(char *) * (naddr + 1);
-
- /* copy */
- if ((nhp = (struct hostent *)malloc(size)) == NULL) {
- *errp = TRY_AGAIN;
- return NULL;
- }
- cp = (char *)&nhp[1];
- if (hp->h_name != NULL) {
- nhp->h_name = cp;
- strcpy(cp, hp->h_name);
- cp += strlen(cp) + 1;
- } else
- nhp->h_name = NULL;
- nhp->h_aliases = (char **)((char *)nhp + al_off);
- if ((pp = hp->h_aliases) != NULL) {
- for (i = 0; *pp != NULL; pp++) {
- if (**pp != '\0') {
- nhp->h_aliases[i++] = cp;
- strcpy(cp, *pp);
- cp += strlen(cp) + 1;
- }
- }
- }
- nhp->h_aliases[nalias] = NULL;
- cp = (char *)&nhp->h_aliases[nalias + 1];
- nhp->h_addrtype = hp->h_addrtype;
- nhp->h_length = hp->h_length;
- nhp->h_addr_list = (char **)cp;
- if ((pp = hp->h_addr_list) != NULL) {
- cp = (char *)&nhp->h_addr_list[naddr + 1];
- for (i = 0; *pp != NULL; pp++) {
- nhp->h_addr_list[i++] = cp;
- memcpy(cp, *pp, hp->h_length);
- cp += addrsize;
- }
- }
- nhp->h_addr_list[naddr] = NULL;
- return nhp;
-}
-
-/*
- * _hpaddr: construct hostent structure with one address
- */
-static struct hostent *
-_hpaddr(int af, const char *name, void *addr, int *errp)
-{
- struct hostent *hp, hpbuf;
- char *addrs[2];
-
- hp = &hpbuf;
- hp->h_name = (char *)name;
- hp->h_aliases = NULL;
- hp->h_addrtype = af;
- hp->h_length = ADDRLEN(af);
- hp->h_addr_list = addrs;
- addrs[0] = (char *)addr;
- addrs[1] = NULL;
- return _hpcopy(hp, errp);
-}
-
-/*
- * _hpmerge: merge 2 hostent structure, arguments will be freed
- */
-static struct hostent *
-_hpmerge(struct hostent *hp1, struct hostent *hp2, int *errp)
-{
- int i, j;
- int naddr, nalias;
- char **pp;
- struct hostent *hp, hpbuf;
- char *aliases[MAXALIASES + 1], *addrs[MAXADDRS + 1];
- union inx_addr addrbuf[MAXADDRS];
-
- if (hp1 == NULL)
- return hp2;
- if (hp2 == NULL)
- return hp1;
-
-#define HP(i) (i == 1 ? hp1 : hp2)
- hp = &hpbuf;
- hp->h_name = (hp1->h_name != NULL ? hp1->h_name : hp2->h_name);
- hp->h_aliases = aliases;
- nalias = 0;
- for (i = 1; i <= 2; i++) {
- if ((pp = HP(i)->h_aliases) == NULL)
- continue;
- for (; nalias < MAXALIASES && *pp != NULL; pp++) {
- /* check duplicates */
- for (j = 0; j < nalias; j++)
- if (strcasecmp(*pp, aliases[j]) == 0)
- break;
- if (j == nalias)
- aliases[nalias++] = *pp;
- }
- }
- aliases[nalias] = NULL;
-#ifdef INET6
- if (hp1->h_length != hp2->h_length) {
- hp->h_addrtype = AF_INET6;
- hp->h_length = sizeof(struct in6_addr);
- } else {
-#endif
- hp->h_addrtype = hp1->h_addrtype;
- hp->h_length = hp1->h_length;
-#ifdef INET6
- }
-#endif
- hp->h_addr_list = addrs;
- naddr = 0;
- for (i = 1; i <= 2; i++) {
- if ((pp = HP(i)->h_addr_list) == NULL)
- continue;
- if (HP(i)->h_length == hp->h_length) {
- while (naddr < MAXADDRS && *pp != NULL)
- addrs[naddr++] = *pp++;
- } else {
- /* copy IPv4 addr as mapped IPv6 addr */
- while (naddr < MAXADDRS && *pp != NULL) {
- MAPADDR(&addrbuf[naddr], *pp++);
- addrs[naddr] = (char *)&addrbuf[naddr];
- naddr++;
- }
- }
- }
- addrs[naddr] = NULL;
- hp = _hpcopy(hp, errp);
- freehostent(hp1);
- freehostent(hp2);
- return hp;
-}
-
-/*
- * _hpmapv6: convert IPv4 hostent into IPv4-mapped IPv6 addresses
- */
-#ifdef INET6
-static struct hostent *
-_hpmapv6(struct hostent *hp, int *errp)
-{
- struct hostent *hp6;
-
- if (hp == NULL)
- return NULL;
- if (hp->h_addrtype == AF_INET6)
- return hp;
-
- /* make dummy hostent to convert IPv6 address */
- if ((hp6 = (struct hostent *)malloc(sizeof(struct hostent))) == NULL) {
- *errp = TRY_AGAIN;
- return NULL;
- }
- hp6->h_name = NULL;
- hp6->h_aliases = NULL;
- hp6->h_addrtype = AF_INET6;
- hp6->h_length = sizeof(struct in6_addr);
- hp6->h_addr_list = NULL;
- return _hpmerge(hp6, hp, errp);
-}
-#endif
-
-/*
- * _hpsort: sort address by sortlist
- */
-static struct hostent *
-_hpsort(struct hostent *hp)
-{
- int i, j, n;
- u_char *ap, *sp, *mp, **pp;
- char t;
- char order[MAXADDRS];
- int nsort = _res.nsort;
-
- if (hp == NULL || hp->h_addr_list[1] == NULL || nsort == 0)
- return hp;
- for (i = 0; (ap = (u_char *)hp->h_addr_list[i]); i++) {
- for (j = 0; j < nsort; j++) {
-#ifdef INET6
- if (_res_ext.sort_list[j].af != hp->h_addrtype)
- continue;
- sp = (u_char *)&_res_ext.sort_list[j].addr;
- mp = (u_char *)&_res_ext.sort_list[j].mask;
-#else
- sp = (u_char *)&_res.sort_list[j].addr;
- mp = (u_char *)&_res.sort_list[j].mask;
-#endif
- for (n = 0; n < hp->h_length; n++) {
- if ((ap[n] & mp[n]) != sp[n])
- break;
- }
- if (n == hp->h_length)
- break;
- }
- order[i] = j;
- }
- n = i;
- pp = (u_char **)hp->h_addr_list;
- for (i = 0; i < n - 1; i++) {
- for (j = i + 1; j < n; j++) {
- if (order[i] > order[j]) {
- ap = pp[i];
- pp[i] = pp[j];
- pp[j] = ap;
- t = order[i];
- order[i] = order[j];
- order[j] = t;
- }
- }
- }
- return hp;
-}
-
-static char *
-_hgetword(char **pp)
-{
- char c, *p, *ret;
- const char *sp;
- static const char sep[] = "# \t\n";
-
- ret = NULL;
- for (p = *pp; (c = *p) != '\0'; p++) {
- for (sp = sep; *sp != '\0'; sp++) {
- if (c == *sp)
- break;
- }
- if (c == '#')
- p[1] = '\0'; /* ignore rest of line */
- if (ret == NULL) {
- if (*sp == '\0')
- ret = p;
- } else {
- if (*sp != '\0') {
- *p++ = '\0';
- break;
- }
- }
- }
- *pp = p;
- if (ret == NULL || *ret == '\0')
- return NULL;
- return ret;
-}
-
-/*
- * FILES (/etc/hosts)
- */
-
-static FILE *
-_files_open(int *errp)
-{
- FILE *fp;
- fp = fopen(_PATH_HOSTS, "r");
- if (fp == NULL)
- *errp = NO_RECOVERY;
- return fp;
-}
-
-static int
-_files_ghbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- int *errp;
- int match, nalias;
- char *p, *line, *addrstr, *cname;
- FILE *fp;
- struct hostent *rethp, *hp, hpbuf;
- char *aliases[MAXALIASES + 1], *addrs[2];
- union inx_addr addrbuf;
- char buf[BUFSIZ];
- int af0;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- *(struct hostent **)rval = NULL;
-
- if ((fp = _files_open(errp)) == NULL)
- return NS_UNAVAIL;
- rethp = hp = NULL;
-
- af0 = af;
- while (fgets(buf, sizeof(buf), fp)) {
- line = buf;
- if ((addrstr = _hgetword(&line)) == NULL
- || (cname = _hgetword(&line)) == NULL)
- continue;
- match = (strcasecmp(cname, name) == 0);
- nalias = 0;
- while ((p = _hgetword(&line)) != NULL) {
- if (!match)
- match = (strcasecmp(p, name) == 0);
- if (nalias < MAXALIASES)
- aliases[nalias++] = p;
- }
- if (!match)
- continue;
- switch (af0) {
- case AF_INET:
- if (inet_aton(addrstr, (struct in_addr *)&addrbuf)
- != 1) {
- *errp = NO_DATA; /* name found */
- continue;
- }
- af = af0;
- break;
-#ifdef INET6
- case AF_INET6:
- if (inet_pton(af, addrstr, &addrbuf) != 1) {
- *errp = NO_DATA; /* name found */
- continue;
- }
- af = af0;
- break;
-#endif
- case AF_UNSPEC:
- if (inet_aton(addrstr, (struct in_addr *)&addrbuf)
- == 1) {
- af = AF_INET;
- break;
- }
-#ifdef INET6
- if (inet_pton(AF_INET6, addrstr, &addrbuf) == 1) {
- af = AF_INET6;
- break;
- }
-#endif
- *errp = NO_DATA; /* name found */
- continue;
- /* NOTREACHED */
- }
- hp = &hpbuf;
- hp->h_name = cname;
- hp->h_aliases = aliases;
- aliases[nalias] = NULL;
- hp->h_addrtype = af;
- hp->h_length = ADDRLEN(af);
- hp->h_addr_list = addrs;
- addrs[0] = (char *)&addrbuf;
- addrs[1] = NULL;
- hp = _hpcopy(hp, errp);
- rethp = _hpmerge(rethp, hp, errp);
- }
- fclose(fp);
- *(struct hostent **)rval = rethp;
- return (rethp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-static int
-_files_ghbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const void *addr;
- int addrlen;
- int af;
- int *errp;
- int nalias;
- char *p, *line;
- FILE *fp;
- struct hostent *hp, hpbuf;
- char *aliases[MAXALIASES + 1], *addrs[2];
- union inx_addr addrbuf;
- char buf[BUFSIZ];
-
- addr = va_arg(ap, const void *);
- addrlen = va_arg(ap, int);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- *(struct hostent**)rval = NULL;
-
- if ((fp = _files_open(errp)) == NULL)
- return NS_UNAVAIL;
- hp = NULL;
- while (fgets(buf, sizeof(buf), fp)) {
- line = buf;
- if ((p = _hgetword(&line)) == NULL
- || (af == AF_INET
- ? inet_aton(p, (struct in_addr *)&addrbuf)
- : inet_pton(af, p, &addrbuf)) != 1
- || memcmp(addr, &addrbuf, addrlen) != 0
- || (p = _hgetword(&line)) == NULL)
- continue;
- hp = &hpbuf;
- hp->h_name = p;
- hp->h_aliases = aliases;
- nalias = 0;
- while ((p = _hgetword(&line)) != NULL) {
- if (nalias < MAXALIASES)
- aliases[nalias++] = p;
- }
- aliases[nalias] = NULL;
- hp->h_addrtype = af;
- hp->h_length = addrlen;
- hp->h_addr_list = addrs;
- addrs[0] = (char *)&addrbuf;
- addrs[1] = NULL;
- hp = _hpcopy(hp, errp);
- break;
- }
- fclose(fp);
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-#ifdef YP
-/*
- * NIS
- *
- * XXX actually a hack, these are INET4 specific.
- */
-static int
-_nis_ghbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- int *errp;
- struct hostent *hp = NULL;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- if (af == AF_UNSPEC)
- af = AF_INET;
- if (af == AF_INET) {
- hp = _gethostbynisname(name, af);
- if (hp != NULL)
- hp = _hpcopy(hp, errp);
- }
-
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-
-}
-
-static int
-_nis_ghbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const void *addr;
- int addrlen;
- int af;
- int *errp;
- struct hostent *hp = NULL;
-
- addr = va_arg(ap, const void *);
- addrlen = va_arg(ap, int);
- af = va_arg(ap, int);
-
- if (af == AF_INET) {
- hp = _gethostbynisaddr(addr, addrlen, af);
- if (hp != NULL)
- hp = _hpcopy(hp, errp);
- }
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-#endif
-typedef struct __res_type_list res_type_list;
-
-struct __res_type_list {
- res_type_list * rtl_entry;
- int rtl_type;
-};
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-static struct hostent *getanswer(const querybuf *, int, const char *, int,
- struct hostent *, int *);
-
-/*
- * we don't need to take care about sorting, nor IPv4 mapped address here.
- */
-static struct hostent *
-getanswer(answer, anslen, qname, qtype, template, errp)
- const querybuf *answer;
- int anslen;
- const char *qname;
- int qtype;
- struct hostent *template;
- int *errp;
-{
- const HEADER *hp;
- const u_char *cp;
- int n;
- const u_char *eom, *erdata;
- char *bp, **ap, **hap;
- int type, class, buflen, ancount, qdcount;
- int haveanswer, had_error;
- char tbuf[MAXDNAME];
- const char *tname;
- int (*name_ok)(const char *);
- static char *h_addr_ptrs[MAXADDRS + 1];
- static char *host_aliases[MAXALIASES];
- static char hostbuf[8*1024];
-
-#define BOUNDED_INCR(x) \
- do { \
- cp += x; \
- if (cp > eom) { \
- *errp = NO_RECOVERY; \
- return (NULL); \
- } \
- } while (0)
-
-#define BOUNDS_CHECK(ptr, count) \
- do { \
- if ((ptr) + (count) > eom) { \
- *errp = NO_RECOVERY; \
- return (NULL); \
- } \
- } while (0)
-
-/* XXX do {} while (0) cannot be put here */
-#define DNS_ASSERT(x) \
- { \
- if (!(x)) { \
- cp += n; \
- continue; \
- } \
- }
-
-/* XXX do {} while (0) cannot be put here */
-#define DNS_FATAL(x) \
- { \
- if (!(x)) { \
- had_error++; \
- continue; \
- } \
- }
-
- tname = qname;
- template->h_name = NULL;
- eom = answer->buf + anslen;
- switch (qtype) {
- case T_A:
- case T_AAAA:
- name_ok = res_hnok;
- break;
- case T_PTR:
- name_ok = res_dnok;
- break;
- default:
- return (NULL); /* XXX should be abort(); */
- }
- /*
- * find first satisfactory answer
- */
- hp = &answer->hdr;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- bp = hostbuf;
- buflen = sizeof hostbuf;
- cp = answer->buf;
- BOUNDED_INCR(HFIXEDSZ);
- if (qdcount != 1) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- if ((n < 0) || !(*name_ok)(bp)) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- BOUNDED_INCR(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).
- */
- n = strlen(bp) + 1; /* for the \0 */
- if (n >= MAXHOSTNAMELEN) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- template->h_name = bp;
- bp += n;
- buflen -= n;
- /* The qname can be abbreviated, but h_name is now absolute. */
- qname = template->h_name;
- }
- ap = host_aliases;
- *ap = NULL;
- template->h_aliases = host_aliases;
- hap = h_addr_ptrs;
- *hap = NULL;
- template->h_addr_list = h_addr_ptrs;
- haveanswer = 0;
- had_error = 0;
- while (ancount-- > 0 && cp < eom && !had_error) {
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- DNS_FATAL(n >= 0);
- DNS_FATAL((*name_ok)(bp));
- cp += n; /* name */
- BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
- type = _getshort(cp);
- cp += INT16SZ; /* type */
- class = _getshort(cp);
- cp += INT16SZ + INT32SZ; /* class, TTL */
- n = _getshort(cp);
- cp += INT16SZ; /* len */
- BOUNDS_CHECK(cp, n);
- erdata = cp + n;
- DNS_ASSERT(class == C_IN);
- 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);
- DNS_FATAL(n >= 0);
- DNS_FATAL((*name_ok)(tbuf));
- cp += n;
- if (cp != erdata) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- /* Store alias. */
- *ap++ = bp;
- n = strlen(bp) + 1; /* for the \0 */
- DNS_FATAL(n < MAXHOSTNAMELEN);
- bp += n;
- buflen -= n;
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- DNS_FATAL(n <= buflen);
- DNS_FATAL(n < MAXHOSTNAMELEN);
- strcpy(bp, tbuf);
- template->h_name = bp;
- bp += n;
- buflen -= n;
- continue;
- }
- if (qtype == T_PTR && type == T_CNAME) {
- n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
- if (n < 0 || !res_dnok(tbuf)) {
- had_error++;
- continue;
- }
- cp += n;
- if (cp != erdata) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
- strcpy(bp, tbuf);
- tname = bp;
- bp += n;
- buflen -= n;
- continue;
- }
- DNS_ASSERT(type == qtype);
- switch (type) {
- case T_PTR:
- DNS_ASSERT(strcasecmp(tname, bp) == 0);
- n = dn_expand(answer->buf, eom, cp, bp, buflen);
- DNS_FATAL(n >= 0);
- DNS_FATAL(res_hnok(bp));
-#if MULTI_PTRS_ARE_ALIASES
- cp += n;
- if (cp != erdata) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- if (!haveanswer)
- template->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 */
- if (n >= MAXHOSTNAMELEN) {
- had_error++;
- break;
- }
- bp += n;
- buflen -= n;
- }
- break;
-#else
- template->h_name = bp;
- *errp = NETDB_SUCCESS;
- return (template);
-#endif
- case T_A:
- case T_AAAA:
- DNS_ASSERT(strcasecmp(template->h_name, bp) == 0);
- DNS_ASSERT(n == template->h_length);
- if (!haveanswer) {
- int nn;
-
- template->h_name = bp;
- nn = strlen(bp) + 1; /* for the \0 */
- bp += nn;
- buflen -= nn;
- }
-#ifdef ALIGN
- bp = (char *)ALIGN(bp);
-#else
- bp = (char *)(bp);
-#endif
-
- DNS_FATAL(bp + n < &hostbuf[sizeof hostbuf]);
- DNS_ASSERT(hap < &h_addr_ptrs[MAXADDRS-1]);
-#ifdef FILTER_V4MAPPED
- if (type == T_AAAA) {
- struct in6_addr in6;
- memcpy(&in6, cp, sizeof(in6));
- DNS_ASSERT(IN6_IS_ADDR_V4MAPPED(&in6) == 0);
- }
-#endif
- bcopy(cp, *hap++ = bp, n);
- bp += n;
- buflen -= n;
- cp += n;
- if (cp != erdata) {
- *errp = NO_RECOVERY;
- return (NULL);
- }
- break;
- default:
- abort();
- }
- if (!had_error)
- haveanswer++;
- }
- if (haveanswer) {
- *ap = NULL;
- *hap = NULL;
- if (!template->h_name) {
- n = strlen(qname) + 1; /* for the \0 */
- if (n > buflen || n >= MAXHOSTNAMELEN)
- goto no_recovery;
- strcpy(bp, qname);
- template->h_name = bp;
- bp += n;
- buflen -= n;
- }
- *errp = NETDB_SUCCESS;
- return (template);
- }
- no_recovery:
- *errp = NO_RECOVERY;
- return (NULL);
-
-#undef BOUNDED_INCR
-#undef BOUNDS_CHECK
-#undef DNS_ASSERT
-#undef DNS_FATAL
-}
-
-/* res_search() variant with multiple query support. */
-static struct hostent *
-_res_search_multi(name, rtl, errp)
- const char *name; /* domain name */
- struct __res_type_list *rtl; /* list of query types */
- int *errp;
-{
- const char *cp, * const *domain;
- struct hostent *hp0 = NULL, *hp;
- struct hostent hpbuf;
- u_int dots;
- int trailing_dot, ret, saved_herrno;
- int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
- struct __res_type_list *rtl0 = rtl;
- querybuf buf;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- *errp = NETDB_INTERNAL;
- return (NULL);
- }
- 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) {
- for(rtl = rtl0; rtl != NULL;
- rtl = rtl->rtl_entry) {
- ret = res_query(cp, C_IN, rtl->rtl_type, buf.buf,
- sizeof(buf.buf));
- if (ret > 0) {
- hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA)
- ? AF_INET6 : AF_INET;
- hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype);
- hp = getanswer(&buf, ret, name, rtl->rtl_type,
- &hpbuf, errp);
- if (!hp)
- continue;
- hp = _hpcopy(&hpbuf, errp);
- hp0 = _hpmerge(hp0, hp, errp);
- }
- }
- return (hp0);
- }
-
- /*
- * 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 >= _res.ndots) {
- for(rtl = rtl0; rtl != NULL;
- rtl = rtl->rtl_entry) {
- ret = res_querydomain(name, NULL, C_IN, rtl->rtl_type,
- buf.buf, sizeof(buf.buf));
- if (ret > 0) {
- hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA)
- ? AF_INET6 : AF_INET;
- hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype);
- hp = getanswer(&buf, ret, name, rtl->rtl_type,
- &hpbuf, errp);
- if (!hp)
- continue;
- hp = _hpcopy(&hpbuf, errp);
- hp0 = _hpmerge(hp0, hp, errp);
- }
- }
- if (hp0 != NULL)
- return (hp0);
- saved_herrno = *errp;
- 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 && (_res.options & RES_DEFNAMES)) ||
- (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
- int done = 0;
-
- for (domain = (const char * const *)_res.dnsrch;
- *domain && !done;
- domain++) {
-
- for(rtl = rtl0; rtl != NULL;
- rtl = rtl->rtl_entry) {
- ret = res_querydomain(name, *domain, C_IN,
- rtl->rtl_type,
- buf.buf, sizeof(buf.buf));
- if (ret > 0) {
- hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA)
- ? AF_INET6 : AF_INET;
- hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype);
- hp = getanswer(&buf, ret, name,
- rtl->rtl_type, &hpbuf, errp);
- if (!hp)
- continue;
- hp = _hpcopy(&hpbuf, errp);
- hp0 = _hpmerge(hp0, hp, errp);
- }
- }
- if (hp0 != NULL)
- return (hp0);
-
- /*
- * 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) {
- *errp = TRY_AGAIN;
- return (NULL);
- }
-
- switch (*errp) {
- case NO_DATA:
- got_nodata++;
- /* FALLTHROUGH */
- case HOST_NOT_FOUND:
- /* keep trying */
- break;
- case TRY_AGAIN:
- if (buf.hdr.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 (!(_res.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 unless NOTLDQUERY is set.
- */
- if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
- for(rtl = rtl0; rtl != NULL;
- rtl = rtl->rtl_entry) {
- ret = res_querydomain(name, NULL, C_IN, rtl->rtl_type,
- buf.buf, sizeof(buf.buf));
- if (ret > 0) {
- hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA)
- ? AF_INET6 : AF_INET;
- hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype);
- hp = getanswer(&buf, ret, name, rtl->rtl_type,
- &hpbuf, errp);
- if (!hp)
- continue;
- hp = _hpcopy(&hpbuf, errp);
- hp0 = _hpmerge(hp0, hp, errp);
- }
- }
- if (hp0 != NULL)
- return (hp0);
- }
-
- /* 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)
- *errp = saved_herrno;
- else if (got_nodata)
- *errp = NO_DATA;
- else if (got_servfail)
- *errp = TRY_AGAIN;
- return (NULL);
-}
-
-static int
-_dns_ghbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- int *errp;
- res_type_list *rtl, rtl4;
-#ifdef INET6
- res_type_list rtl6;
-#endif
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
-#ifdef INET6
- switch (af) {
- case AF_UNSPEC:
- rtl4.rtl_entry = NULL; rtl4.rtl_type = T_A;
- rtl6.rtl_entry = &rtl4; rtl6.rtl_type = T_AAAA;
- rtl = &rtl6;
- break;
- case AF_INET6:
- rtl6.rtl_entry = NULL; rtl6.rtl_type = T_AAAA;
- rtl = &rtl6;
- break;
- case AF_INET:
- rtl4.rtl_entry = NULL; rtl4.rtl_type = T_A;
- rtl = &rtl4;
- break;
- }
-#else
- (&rtl4)->rtl_entry = NULL;
- rtl4.rtl_type = T_A;
- rtl = &rtl4;
-#endif
- *(struct hostent **)rval = _res_search_multi(name, rtl, errp);
- return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-static int
-_dns_ghbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const void *addr;
- int addrlen;
- int af;
- int *errp;
- int n;
- struct hostent *hp;
- u_char c, *cp;
- char *bp;
- struct hostent hbuf;
- int na;
-#ifdef INET6
- static const char hex[] = "0123456789abcdef";
-#endif
- querybuf buf;
- char qbuf[MAXDNAME+1];
- char *hlist[2];
-
- addr = va_arg(ap, const void *);
- addrlen = va_arg(ap, int);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- *(struct hostent **)rval = NULL;
-
-#ifdef INET6
- /* XXX */
- if (af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr))
- return NS_NOTFOUND;
-#endif
-
- if ((_res.options & RES_INIT) == 0) {
- if (res_init() < 0) {
- *errp = h_errno;
- return NS_UNAVAIL;
- }
- }
- memset(&hbuf, 0, sizeof(hbuf));
- hbuf.h_name = NULL;
- hbuf.h_addrtype = af;
- hbuf.h_length = addrlen;
- na = 0;
-
- /* XXX assumes that MAXDNAME is big enough */
- n = 0;
- bp = qbuf;
- cp = (u_char *)addr+addrlen-1;
- switch (af) {
-#ifdef INET6
- case AF_INET6:
- for (; n < addrlen; n++, cp--) {
- c = *cp;
- *bp++ = hex[c & 0xf];
- *bp++ = '.';
- *bp++ = hex[c >> 4];
- *bp++ = '.';
- }
- strcpy(bp, "ip6.int");
- break;
-#endif
- default:
- for (; n < addrlen; n++, cp--) {
- c = *cp;
- if (c >= 100)
- *bp++ = '0' + c / 100;
- if (c >= 10)
- *bp++ = '0' + (c % 100) / 10;
- *bp++ = '0' + c % 10;
- *bp++ = '.';
- }
- strcpy(bp, "in-addr.arpa");
- break;
- }
-
- n = res_query(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf);
- if (n < 0) {
- *errp = h_errno;
- return NS_UNAVAIL;
- }
- hp = getanswer(&buf, n, qbuf, T_PTR, &hbuf, errp);
- if (!hp)
- return NS_NOTFOUND;
- hbuf.h_addrtype = af;
- hbuf.h_length = addrlen;
- hbuf.h_addr_list = hlist;
- hlist[0] = (char *)addr;
- hlist[1] = NULL;
- *(struct hostent **)rval = _hpcopy(&hbuf, errp);
- return NS_SUCCESS;
-}
-
-#if 0 // keep gcc happy
-static void
-_dns_shent(int stayopen)
-{
- if ((_res.options & RES_INIT) == 0) {
- if (res_init() < 0)
- return;
- }
- if (stayopen)
- _res.options |= RES_STAYOPEN | RES_USEVC;
-}
-
-static void
-_dns_ehent(void)
-{
- _res.options &= ~(RES_STAYOPEN | RES_USEVC);
- res_close();
-}
-#endif
-
-#ifdef ICMPNL
-
-/*
- * experimental:
- * draft-ietf-ipngwg-icmp-namelookups-02.txt
- * ifindex is assumed to be encoded in addr.
- */
-#include <sys/uio.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-
-struct _icmp_host_cache {
- struct _icmp_host_cache *hc_next;
- int hc_ifindex;
- struct in6_addr hc_addr;
- char *hc_name;
-};
-
-static char *
-_icmp_fqdn_query(const struct in6_addr *addr, int ifindex)
-{
- int s;
- struct icmp6_filter filter;
- struct msghdr msg;
- struct cmsghdr *cmsg;
- struct in6_pktinfo *pkt;
- char cbuf[256];
- char buf[1024];
- int cc;
- struct icmp6_fqdn_query *fq;
- struct icmp6_fqdn_reply *fr;
- struct _icmp_host_cache *hc;
- struct sockaddr_in6 sin6;
- struct iovec iov;
- fd_set s_fds, fds;
- struct timeval tout;
- int len;
- char *name;
- static int pid;
- static struct _icmp_host_cache *hc_head;
-
- for (hc = hc_head; hc; hc = hc->hc_next) {
- if (hc->hc_ifindex == ifindex
- && IN6_ARE_ADDR_EQUAL(&hc->hc_addr, addr))
- return hc->hc_name;
- }
-
- if (pid == 0)
- pid = getpid();
-
- ICMP6_FILTER_SETBLOCKALL(&filter);
- ICMP6_FILTER_SETPASS(ICMP6_FQDN_REPLY, &filter);
-
- FD_ZERO(&s_fds);
- tout.tv_sec = 0;
- tout.tv_usec = 200000; /*XXX: 200ms*/
-
- fq = (struct icmp6_fqdn_query *)buf;
- fq->icmp6_fqdn_type = ICMP6_FQDN_QUERY;
- fq->icmp6_fqdn_code = 0;
- fq->icmp6_fqdn_cksum = 0;
- fq->icmp6_fqdn_id = (u_short)pid;
- fq->icmp6_fqdn_unused = 0;
- fq->icmp6_fqdn_cookie[0] = 0;
- fq->icmp6_fqdn_cookie[1] = 0;
-
- memset(&sin6, 0, sizeof(sin6));
- sin6.sin6_family = AF_INET6;
- sin6.sin6_addr = *addr;
-
- memset(&msg, 0, sizeof(msg));
- msg.msg_name = (caddr_t)&sin6;
- msg.msg_namelen = sizeof(sin6);
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- iov.iov_base = (caddr_t)buf;
- iov.iov_len = sizeof(struct icmp6_fqdn_query);
-
- if (ifindex) {
- msg.msg_control = cbuf;
- msg.msg_controllen = sizeof(cbuf);
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
- cmsg->cmsg_level = IPPROTO_IPV6;
- cmsg->cmsg_type = IPV6_PKTINFO;
- pkt = (struct in6_pktinfo *)&cmsg[1];
- memset(&pkt->ipi6_addr, 0, sizeof(struct in6_addr));
- pkt->ipi6_ifindex = ifindex;
- cmsg = CMSG_NXTHDR(&msg, cmsg);
- msg.msg_controllen = (char *)cmsg - cbuf;
- }
-
- if ((s = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
- return NULL;
- (void)setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER,
- (char *)&filter, sizeof(filter));
- cc = _sendmsg(s, &msg, 0);
- if (cc < 0) {
- close(s);
- return NULL;
- }
- FD_SET(s, &s_fds);
- for (;;) {
- fds = s_fds;
- if (select(s + 1, &fds, NULL, NULL, &tout) <= 0) {
- close(s);
- return NULL;
- }
- len = sizeof(sin6);
- cc = _recvfrom(s, buf, sizeof(buf), 0,
- (struct sockaddr *)&sin6, &len);
- if (cc <= 0) {
- close(s);
- return NULL;
- }
- if (cc < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr))
- continue;
- if (!IN6_ARE_ADDR_EQUAL(addr, &sin6.sin6_addr))
- continue;
- fr = (struct icmp6_fqdn_reply *)(buf + sizeof(struct ip6_hdr));
- if (fr->icmp6_fqdn_type == ICMP6_FQDN_REPLY)
- break;
- }
- close(s);
- if (fr->icmp6_fqdn_cookie[1] != 0) {
- /* rfc1788 type */
- name = buf + sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr) + 4;
- len = (buf + cc) - name;
- } else {
- len = fr->icmp6_fqdn_namelen;
- name = fr->icmp6_fqdn_name;
- }
- if (len <= 0)
- return NULL;
- name[len] = 0;
-
- if ((hc = (struct _icmp_host_cache *)malloc(sizeof(*hc))) == NULL)
- return NULL;
- /* XXX: limit number of cached entries */
- hc->hc_ifindex = ifindex;
- hc->hc_addr = *addr;
- hc->hc_name = strdup(name);
- hc->hc_next = hc_head;
- hc_head = hc;
- return hc->hc_name;
-}
-
-static struct hostent *
-_icmp_ghbyaddr(const void *addr, int addrlen, int af, int *errp)
-{
- char *hname;
- int ifindex;
- struct in6_addr addr6;
-
- if (af != AF_INET6) {
- /*
- * Note: rfc1788 defines Who Are You for IPv4,
- * but no one implements it.
- */
- return NULL;
- }
-
- memcpy(&addr6, addr, addrlen);
- ifindex = (addr6.s6_addr[2] << 8) | addr6.s6_addr[3];
- addr6.s6_addr[2] = addr6.s6_addr[3] = 0;
-
- if (!IN6_IS_ADDR_LINKLOCAL(&addr6))
- return NULL; /*XXX*/
-
- if ((hname = _icmp_fqdn_query(&addr6, ifindex)) == NULL)
- return NULL;
- return _hpaddr(af, hname, &addr6, errp);
-}
-#endif /* ICMPNL */
diff --git a/newlib/libc/sys/linux/net/namespace.h b/newlib/libc/sys/linux/net/namespace.h
deleted file mode 100644
index 291aad580..000000000
--- a/newlib/libc/sys/linux/net/namespace.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>.
- * 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 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.
- *
- * $FreeBSD: src/lib/libc/include/namespace.h,v 1.9 2002/03/29 22:43:42 markm Exp $
- */
-
-#ifndef _NAMESPACE_H_
-#define _NAMESPACE_H_
-
-/*
- * Adjust names so that headers declare "hidden" names.
- */
-
-/*
- * ISO C (C90) section. Most names in libc aren't in ISO C, so they
- * should be here. Most aren't here...
- */
-#define err _err
-#define warn _warn
-
-/*
- * Prototypes for syscalls/functions that need to be overridden
- * in libc_r/libpthread.
- */
-#define accept _accept
-#define __acl_aclcheck_fd ___acl_aclcheck_fd
-#define __acl_delete_fd ___acl_delete_fd
-#define __acl_get_fd ___acl_get_fd
-#define __acl_set_fd ___acl_set_fd
-#define bind _bind
-#define __cap_get_fd ___cap_get_fd
-#define __cap_set_fd ___cap_set_fd
-#define close _close
-#define connect _connect
-#define dup _dup
-#define dup2 _dup2
-#define execve _execve
-#define fcntl _fcntl
-/*#define flock _flock */
-#define fstat _fstat
-#define fstatfs _fstatfs
-#define fsync _fsync
-#define getdirentries _getdirentries
-#define getlogin _getlogin
-#define getpeername _getpeername
-#define getprogname _getprogname
-#define getsockname _getsockname
-#define getsockopt _getsockopt
-#define ioctl _ioctl
-#define listen _listen
-#define nanosleep _nanosleep
-#define open _open
-#define poll _poll
-#define pthread_cond_signal _pthread_cond_signal
-#define pthread_cond_wait _pthread_cond_wait
-#define pthread_cond_init _pthread_cond_init
-#define pthread_exit _pthread_exit
-#define pthread_getspecific _pthread_getspecific
-#define pthread_key_create _pthread_key_create
-#define pthread_key_delete _pthread_key_delete
-#define pthread_main_np _pthread_main_np
-#define pthread_mutex_destroy _pthread_mutex_destroy
-#define pthread_mutex_init _pthread_mutex_init
-#define pthread_mutex_lock _pthread_mutex_lock
-#define pthread_mutex_trylock _pthread_mutex_trylock
-#define pthread_mutex_unlock _pthread_mutex_unlock
-#define pthread_mutexattr_init _pthread_mutexattr_init
-#define pthread_mutexattr_destroy _pthread_mutexattr_destroy
-#define pthread_mutexattr_settype _pthread_mutexattr_settype
-#define pthread_once _pthread_once
-#define pthread_rwlock_init _pthread_rwlock_init
-#define pthread_rwlock_rdlock _pthread_rwlock_rdlock
-#define pthread_rwlock_wrlock _pthread_rwlock_wrlock
-#define pthread_rwlock_unlock _pthread_rwlock_unlock
-#define pthread_self _pthread_self
-#define pthread_setspecific _pthread_setspecific
-#define pthread_sigmask _pthread_sigmask
-#define read _read
-#define readv _readv
-#define recvfrom _recvfrom
-#define recvmsg _recvmsg
-#define select _select
-#define sendmsg _sendmsg
-#define sendto _sendto
-#define setsockopt _setsockopt
-/*#define sigaction _sigaction*/
-#define sigprocmask _sigprocmask
-#define sigsuspend _sigsuspend
-#define socket _socket
-#define socketpair _socketpair
-#define wait4 _wait4
-#define write _write
-#define writev _writev
-
-
-/*
- * Other hidden syscalls/functions that libc_r needs to override
- * but are not used internally by libc.
- *
- * XXX - When modifying libc to use one of the following, remove
- * the prototype from below and place it in the list above.
- */
-#if 0
-#define creat _creat
-#define fchflags _fchflags
-#define fchmod _fchmod
-#define fpathconf _fpathconf
-#define msync _msync
-#define nfssvc _nfssvc
-#define pause _pause
-#define pthread_rwlock_destroy _pthread_rwlock_destroy
-#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock
-#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock
-#define pthread_rwlockattr_init _pthread_rwlockattr_init
-#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy
-#define sched_yield _sched_yield
-#define sendfile _sendfile
-#define shutdown _shutdown
-#define sigaltstack _sigaltstack
-#define sigpending _sigpending
-#define sigreturn _sigreturn
-#define sigsetmask _sigsetmask
-#define sleep _sleep
-#define system _system
-#define tcdrain _tcdrain
-#define wait _wait
-#define waitpid _waitpid
-#endif
-
-#endif /* _NAMESPACE_H_ */
diff --git a/newlib/libc/sys/linux/net/netgroup.h b/newlib/libc/sys/linux/net/netgroup.h
new file mode 100644
index 000000000..c6b77ba52
--- /dev/null
+++ b/newlib/libc/sys/linux/net/netgroup.h
@@ -0,0 +1,80 @@
+/* Internal header for netgroup related functions.
+ Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETGROUP_H
+#define _NETGROUP_H 1
+
+#include <nsswitch.h>
+
+/* A netgroup can consist of names of other netgroups. We have to
+ track which netgroups were read and which still have to be read. */
+struct name_list
+{
+ struct name_list *next;
+ char name[0];
+};
+
+
+/* Dataset for iterating netgroups. */
+struct __netgrent
+{
+ enum { triple_val, group_val } type;
+
+ union
+ {
+ struct
+ {
+ const char *host;
+ const char *user;
+ const char *domain;
+ }
+ triple;
+
+ const char *group;
+ } val;
+
+ /* Room for the data kept between the calls to the netgroup
+ functions. We must avoid global variables. */
+ char *data;
+ size_t data_size;
+ union
+ {
+ char *cursor;
+ unsigned long int position;
+ };
+ int first;
+
+ struct name_list *known_groups;
+ struct name_list *needed_groups;
+
+ /* This handle for the NSS data base is shared between all
+ set/get/endXXXent functions. */
+ service_user *nip;
+};
+
+
+/* The internal netgroup handling functions might be called from outside. */
+extern int __internal_setnetgrent (const char *group,
+ struct __netgrent *datap);
+extern void __internal_endnetgrent (struct __netgrent *datap);
+extern int __internal_getnetgrent_r (char **hostp, char **userp,
+ char **domainp, struct __netgrent *datap,
+ char *buffer, size_t buflen, int *errnop);
+
+#endif /* netgroup.h */
diff --git a/newlib/libc/sys/linux/net/netgrp-lookup.c b/newlib/libc/sys/linux/net/netgrp-lookup.c
new file mode 100644
index 000000000..526755a53
--- /dev/null
+++ b/newlib/libc/sys/linux/net/netgrp-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME netgroup
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/network-lookup.c b/newlib/libc/sys/linux/net/network-lookup.c
new file mode 100644
index 000000000..8bfaab8dd
--- /dev/null
+++ b/newlib/libc/sys/linux/net/network-lookup.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME networks
+#define DEFAULT_CONFIG "dns [!UNAVAIL=return] files"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/not-cancel.h b/newlib/libc/sys/linux/net/not-cancel.h
new file mode 100644
index 000000000..9dd7d30bb
--- /dev/null
+++ b/newlib/libc/sys/linux/net/not-cancel.h
@@ -0,0 +1,53 @@
+/* Uncancelable versions of cancelable interfaces. Linux version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <machine/syscall.h>
+
+/* Uncancelable open. */
+#define open_not_cancel(name, flags, mode) open((name), (flags), (mode))
+#define open_not_cancel_2(name, flags) open((name), (flags))
+
+/* Uncancelable close. */
+#define close_not_cancel(fd) close((fd))
+#define close_not_cancel_no_status(fd) (void)close((fd))
+
+/* Uncancelable read. */
+#define read_not_cancel(fd, buf, n) read((fd), (buf), (n))
+
+/* Uncancelable write. */
+#define write_not_cancel(fd, buf, n) write((fd), (buf), (n))
+
+/* Uncancelable writev. */
+#define writev_not_cancel_no_status(fd, iov, n) \
+ (void) writev((fd), (iov), (n))
+
+/* Uncancelable fcntl. */
+#define fcntl_not_cancel(fd, cmd, val) fcntl((fd), (cmd), (val))
+
+/* Uncancelable waitpid. */
+#ifdef __NR_waitpid
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ waitpid((pid), (stat_loc), (options))
+#else
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ wait4((pid), (stat_loc), (options), NULL)
+#endif
diff --git a/newlib/libc/sys/linux/net/ns.3 b/newlib/libc/sys/linux/net/ns.3
deleted file mode 100644
index be8d155c3..000000000
--- a/newlib/libc/sys/linux/net/ns.3
+++ /dev/null
@@ -1,133 +0,0 @@
-.\" Copyright (c) 1986, 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)ns.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/ns.3,v 1.10 2001/10/01 16:08:56 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt NS 3
-.Os
-.Sh NAME
-.Nm ns_addr ,
-.Nm ns_ntoa
-.Nd Xerox
-.Tn NS Ns (tm)
-address conversion routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In netns/ns.h
-.Ft struct ns_addr
-.Fn ns_addr "char *cp"
-.Ft char *
-.Fn ns_ntoa "struct ns_addr ns"
-.Sh DESCRIPTION
-The routine
-.Fn ns_addr
-interprets character strings representing
-.Tn XNS
-addresses, returning binary information suitable
-for use in system calls.
-The routine
-.Fn ns_ntoa
-takes
-.Tn XNS
-addresses and returns
-.Tn ASCII
-strings representing the address in a
-notation in common use in the Xerox Development Environment:
-.Bd -ragged -offset indent
-<network number>.<host number>.<port number>
-.Ed
-.Pp
-Trailing zero fields are suppressed, and each number is printed in hexadecimal,
-in a format suitable for input to
-.Fn ns_addr .
-Any fields lacking super-decimal digits will have a
-trailing
-.Ql H
-appended.
-.Pp
-Unfortunately, no universal standard exists for representing
-.Tn XNS
-addresses.
-An effort has been made to insure that
-.Fn ns_addr
-be compatible with most formats in common use.
-It will first separate an address into 1 to 3 fields using a single delimiter
-chosen from
-period
-.Ql \&. ,
-colon
-.Ql \&:
-or pound-sign
-.Ql \&# .
-Each field is then examined for byte separators (colon or period).
-If there are byte separators, each subfield separated is taken to be
-a small hexadecimal number, and the entirety is taken as a network-byte-ordered
-quantity to be zero extended in the high-network-order bytes.
-Next, the field is inspected for hyphens, in which case
-the field is assumed to be a number in decimal notation
-with hyphens separating the millenia.
-Next, the field is assumed to be a number:
-It is interpreted
-as hexadecimal if there is a leading
-.Ql 0x
-(as in C),
-a trailing
-.Ql H
-(as in Mesa), or there are any super-decimal digits present.
-It is interpreted as octal is there is a leading
-.Ql 0
-and there are no super-octal digits.
-Otherwise, it is converted as a decimal number.
-.Sh RETURN VALUES
-None. (See
-.Sx BUGS . )
-.Sh SEE ALSO
-.Xr hosts 5 ,
-.Xr networks 5
-.Sh HISTORY
-The
-.Fn ns_addr
-and
-.Fn ns_toa
-functions appeared in
-.Bx 4.3 .
-.Sh BUGS
-The string returned by
-.Fn ns_ntoa
-resides in a static memory area.
-The function
-.Fn ns_addr
-should diagnose improperly formed input, and there should be an unambiguous
-way to recognize this.
diff --git a/newlib/libc/sys/linux/net/ns_addr.c b/newlib/libc/sys/linux/net/ns_addr.c
deleted file mode 100644
index a86cf31b7..000000000
--- a/newlib/libc/sys/linux/net/ns_addr.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (c) 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * J.Q. Johnson.
- *
- * 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 the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <arpa/inet.h>
-#include <netns/ns.h>
-#include <stdio.h>
-#include <string.h>
-
-static struct ns_addr addr, zero_addr;
-
-static void Field(), cvtbase();
-
-struct ns_addr
-ns_addr(name)
- const char *name;
-{
- char separator;
- char *hostname, *socketname, *cp;
- char buf[50];
-
- (void)strncpy(buf, name, sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = '\0';
-
- /*
- * First, figure out what he intends as a field separtor.
- * Despite the way this routine is written, the preferred
- * form 2-272.AA001234H.01777, i.e. XDE standard.
- * Great efforts are made to insure backward compatibility.
- */
- if ((hostname = strchr(buf, '#')) != NULL)
- separator = '#';
- else {
- hostname = strchr(buf, '.');
- if ((cp = strchr(buf, ':')) &&
- ((hostname && cp < hostname) || (hostname == 0))) {
- hostname = cp;
- separator = ':';
- } else
- separator = '.';
- }
- if (hostname)
- *hostname++ = 0;
-
- addr = zero_addr;
- Field(buf, addr.x_net.c_net, 4);
- if (hostname == 0)
- return (addr); /* No separator means net only */
-
- socketname = strchr(hostname, separator);
- if (socketname) {
- *socketname++ = 0;
- Field(socketname, (u_char *)&addr.x_port, 2);
- }
-
- Field(hostname, addr.x_host.c_host, 6);
-
- return (addr);
-}
-
-static void
-Field(buf, out, len)
- char *buf;
- u_char *out;
- int len;
-{
- char *bp = buf;
- int i, ibase, base16 = 0, base10 = 0, clen = 0;
- int hb[6], *hp;
-
- /*
- * first try 2-273#2-852-151-014#socket
- */
- if ((*buf != '-') &&
- (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d",
- &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) {
- cvtbase(1000L, 256, hb, i, out, len);
- return;
- }
- /*
- * try form 8E1#0.0.AA.0.5E.E6#socket
- */
- if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x",
- &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
- cvtbase(256L, 256, hb, i, out, len);
- return;
- }
- /*
- * try form 8E1#0:0:AA:0:5E:E6#socket
- */
- if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x",
- &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
- cvtbase(256L, 256, hb, i, out, len);
- return;
- }
- /*
- * This is REALLY stretching it but there was a
- * comma notation separting shorts -- definitely non standard
- */
- if (1 < (i = sscanf(buf,"%x,%x,%x",
- &hb[0], &hb[1], &hb[2]))) {
- hb[0] = htons(hb[0]); hb[1] = htons(hb[1]);
- hb[2] = htons(hb[2]);
- cvtbase(65536L, 256, hb, i, out, len);
- return;
- }
-
- /* Need to decide if base 10, 16 or 8 */
- while (*bp) switch (*bp++) {
-
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '-':
- break;
-
- case '8': case '9':
- base10 = 1;
- break;
-
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- base16 = 1;
- break;
-
- case 'x': case 'X':
- *--bp = '0';
- base16 = 1;
- break;
-
- case 'h': case 'H':
- base16 = 1;
- /* fall into */
-
- default:
- *--bp = 0; /* Ends Loop */
- }
- if (base16) {
- ibase = 4096;
- } else if (base10 == 0 && *buf == '0') {
- ibase = 512;
- } else {
- base10 = 1;
- ibase = 1000;
- }
-
- for (bp = buf; *bp++; ) clen++;
- if (clen == 0) clen++;
- if (clen > 18) clen = 18;
- i = ((clen - 1) / 3) + 1;
- bp = clen + buf - 3;
- hp = hb + i - 1;
-
- while (hp > hb) {
- if (base16)
- (void)sscanf(bp, "%3x", hp);
- else if (base10)
- (void)sscanf(bp, "%3d", hp);
- else
- (void)sscanf(bp, "%3o", hp);
-
- bp[0] = 0;
- hp--;
- bp -= 3;
- }
- if (base16)
- (void)sscanf(buf, "%3x", hp);
- else if (base10)
- (void)sscanf(buf, "%3d", hp);
- else
- (void)sscanf(buf, "%3o", hp);
-
- cvtbase((long)ibase, 256, hb, i, out, len);
-}
-
-static void
-cvtbase(oldbase,newbase,input,inlen,result,reslen)
- long oldbase;
- int newbase;
- int input[];
- int inlen;
- unsigned char result[];
- int reslen;
-{
- int d, e;
- long sum;
-
- e = 1;
- while (e > 0 && reslen > 0) {
- d = 0; e = 0; sum = 0;
- /* long division: input=input/newbase */
- while (d < inlen) {
- sum = sum*oldbase + (long) input[d];
- e += (sum > 0);
- input[d++] = sum / newbase;
- sum %= newbase;
- }
- result[--reslen] = sum; /* accumulate remainder */
- }
- for (d=0; d < reslen; d++)
- result[d] = 0;
-}
diff --git a/newlib/libc/sys/linux/net/ns_name.c b/newlib/libc/sys/linux/net/ns_name.c
index 609df14f5..d6c4cc8b5 100644
--- a/newlib/libc/sys/linux/net/ns_name.c
+++ b/newlib/libc/sys/linux/net/ns_name.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 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
@@ -15,21 +15,25 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_name.c,v 8.15 2000/03/30 22:53:46 vixie Exp $";
+#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
+#include <ctype.h>
#include <errno.h>
#include <resolv.h>
#include <string.h>
+#include <ctype.h>
+#include "libc-symbols.h"
/* Data. */
-static char digits[] = "0123456789";
+static const char digits[] = "0123456789";
/* Forward. */
@@ -62,34 +66,57 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
eom = dst + dstsiz;
while ((n = *cp++) != 0) {
- if ((n & NS_CMPRSFLGS) != 0) {
+ if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) {
/* Some kind of compression pointer. */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
if (dn != dst) {
if (dn >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = '.';
}
+
+ if (n == 0x41) {
+ n = *cp++ / 8;
+ if (dn + n * 2 + 4 >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ *dn++ = '\\';
+ *dn++ = '[';
+ *dn++ = 'x';
+
+ while (n-- > 0) {
+ c = *cp++;
+ unsigned u = c >> 4;
+ *dn++ = u > 9 ? 'a' + u - 10 : '0' + u;
+ u = c & 0xf;
+ *dn++ = u > 9 ? 'a' + u - 10 : '0' + u;
+ }
+
+ *dn++ = ']';
+ continue;
+ }
+
if (dn + n >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
for ((void)NULL; n > 0; n--) {
c = *cp++;
if (special(c)) {
if (dn + 1 >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = '\\';
*dn++ = (char)c;
} else if (!printable(c)) {
if (dn + 3 >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = '\\';
@@ -98,7 +125,7 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
*dn++ = digits[c % 10];
} else {
if (dn >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = (char)c;
@@ -107,18 +134,19 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
}
if (dn == dst) {
if (dn >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = '.';
}
if (dn >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*dn++ = '\0';
return (dn - dst);
}
+libresolv_hidden_def (ns_name_ntop)
/*
* ns_name_pton(src, dst, dstsiz)
@@ -148,21 +176,56 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
n = (cp - digits) * 100;
if ((c = *src++) == 0 ||
(cp = strchr(digits, c)) == NULL) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
n += (cp - digits) * 10;
if ((c = *src++) == 0 ||
(cp = strchr(digits, c)) == NULL) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
n += (cp - digits);
if (n > 255) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
c = n;
+ } else if (c == '[' && label == bp - 1 && *src == 'x') {
+ /* Theoretically we would have to handle \[o
+ as well but we do not since we do not need
+ it internally. */
+ *label = 0x41;
+ label = bp++;
+ ++src;
+ while (isxdigit (*src)) {
+ n = *src > '9' ? *src - 'a' + 10 : *src - '0';
+ ++src;
+ if (! isxdigit(*src)) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ n <<= 4;
+ n += *src > '9' ? *src - 'a' + 10 : *src - '0';
+ if (bp + 1 >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ *bp++ = n;
+ ++src;
+ }
+ *label = (bp - label - 1) * 8;
+ if (*src++ != ']' || *src++ != '.') {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ escaped = 0;
+ label = bp++;
+ if (bp >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ continue;
}
escaped = 0;
} else if (c == '\\') {
@@ -171,11 +234,11 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
} else if (c == '.') {
c = (bp - label - 1);
if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
if (label >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*label = c;
@@ -183,55 +246,98 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
if (*src == '\0') {
if (c != 0) {
if (bp >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*bp++ = '\0';
}
if ((bp - dst) > MAXCDNAME) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
return (1);
}
- if (c == 0) {
- errno = EMSGSIZE;
+ if (c == 0 || *src == '.') {
+ __set_errno (EMSGSIZE);
return (-1);
}
label = bp++;
continue;
}
if (bp >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*bp++ = (u_char)c;
}
c = (bp - label - 1);
if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
if (label >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*label = c;
if (c != 0) {
if (bp >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*bp++ = 0;
}
if ((bp - dst) > MAXCDNAME) { /* src too big */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
return (0);
}
/*
+ * ns_name_ntol(src, dst, dstsiz)
+ * Convert a network strings labels into all lowercase.
+ * return:
+ * Number of bytes written to buffer, or -1 (with errno set)
+ * notes:
+ * Enforces label and domain length limits.
+ */
+
+int
+ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) {
+ const u_char *cp;
+ u_char *dn, *eom;
+ u_char c;
+ u_int n;
+
+ cp = src;
+ dn = dst;
+ eom = dst + dstsiz;
+
+ while ((n = *cp++) != 0) {
+ if ((n & NS_CMPRSFLGS) != 0) {
+ /* Some kind of compression pointer. */
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ *dn++ = n;
+ if (dn + n >= eom) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ for ((void)NULL; n > 0; n--) {
+ c = *cp++;
+ if (isupper(c))
+ *dn++ = tolower(c);
+ else
+ *dn++ = c;
+ }
+ }
+ *dn++ = '\0';
+ return (dn - dst);
+}
+
+/*
* ns_name_unpack(msg, eom, src, dst, dstsiz)
* Unpack a domain name from a message, source may be compressed.
* return:
@@ -251,36 +357,48 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
srcp = src;
dstlim = dst + dstsiz;
if (srcp < msg || srcp >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
/* Fetch next label in domain name. */
while ((n = *srcp++) != 0) {
/* Check for indirection. */
switch (n & NS_CMPRSFLGS) {
+ case 0x40:
+ if (n == 0x41) {
+ if (dstp + 1 >= dstlim) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ *dstp++ = 0x41;
+ n = *srcp++ / 8;
+ ++checked;
+ } else {
+ __set_errno (EMSGSIZE);
+ return (-1); /* flag error */
+ }
+ /* FALLTHROUGH */
case 0:
/* Limit checks. */
if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
checked += n + 1;
- *dstp++ = n;
- memcpy(dstp, srcp, n);
- dstp += n;
+ dstp = mempcpy(dstp, srcp - 1, n + 1);
srcp += n;
break;
case NS_CMPRSFLGS:
if (srcp >= eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
if (len < 0)
len = srcp - src + 1;
srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
if (srcp < msg || srcp >= eom) { /* Out of range. */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
checked += 2;
@@ -290,13 +408,13 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
* there must be a loop.
*/
if (checked >= eom - msg) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
break;
default:
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1); /* flag error */
}
}
@@ -305,6 +423,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
len = srcp - src;
return (len);
}
+libresolv_hidden_def (ns_name_unpack)
/*
* ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
@@ -330,7 +449,7 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
u_char *dstp;
const u_char **cpp, **lpp, *eob, *msg;
const u_char *srcp;
- int n, l;
+ int n, l, first = 1;
srcp = src;
dstp = dst;
@@ -349,29 +468,31 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
l = 0;
do {
n = *srcp;
- if ((n & NS_CMPRSFLGS) != 0) {
- errno = EMSGSIZE;
+ if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) {
+ __set_errno (EMSGSIZE);
return (-1);
}
+ if (n == 0x41)
+ n = *++srcp / 8;
l += n + 1;
if (l > MAXCDNAME) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
srcp += n + 1;
} while (n != 0);
+ /* from here on we need to reset compression pointer array on error */
srcp = src;
do {
/* Look to see if we can use pointers. */
n = *srcp;
- if (n != 0 && msg != NULL) {
+ if (n != 0 && n != 0x41 && msg != NULL) {
l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
(const u_char * const *)lpp);
if (l >= 0) {
if (dstp + 1 >= eob) {
- errno = EMSGSIZE;
- return (-1);
+ goto cleanup;
}
*dstp++ = (l >> 8) | NS_CMPRSFLGS;
*dstp++ = l % 256;
@@ -379,19 +500,24 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
}
/* Not found, save it. */
if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
- (dstp - msg) < 0x4000) {
+ (dstp - msg) < 0x4000 && first) {
*cpp++ = dstp;
*cpp = NULL;
+ first = 0;
}
}
/* copy label to buffer */
- if (n & NS_CMPRSFLGS) { /* Should not happen. */
- errno = EMSGSIZE;
- return (-1);
+ if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) { /* Should not happen. */
+ goto cleanup;
+ }
+ if (n == 0x41) {
+ n = *++srcp / 8;
+ if (dstp + 1 >= eob)
+ goto cleanup;
+ *dstp++ = 0x41;
}
if (dstp + 1 + n >= eob) {
- errno = EMSGSIZE;
- return (-1);
+ goto cleanup;
}
memcpy(dstp, srcp, n + 1);
srcp += n + 1;
@@ -399,11 +525,12 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
} while (n != 0);
if (dstp > eob) {
+cleanup:
if (msg != NULL)
*lpp = NULL;
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
- }
+ }
return (dstp - dst);
}
@@ -421,7 +548,7 @@ ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
{
u_char tmp[NS_MAXCDNAME];
int n;
-
+
if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
return (-1);
if (ns_name_ntop(tmp, dst, dstsiz) == -1)
@@ -455,6 +582,23 @@ ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
}
/*
+ * Reset dnptrs so that there are no active references to pointers at or
+ * after src.
+ */
+void
+ns_name_rollback(const u_char *src, const u_char **dnptrs,
+ const u_char **lastdnptr)
+{
+ while (dnptrs < lastdnptr && *dnptrs != NULL) {
+ if (*dnptrs >= src) {
+ *dnptrs = NULL;
+ break;
+ }
+ dnptrs++;
+ }
+}
+
+/*
* ns_name_skip(ptrptr, eom)
* Advance *ptrptr to skip over the compressed name it points at.
* return:
@@ -476,13 +620,13 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) {
cp++;
break;
default: /* illegal type */
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
break;
}
if (cp > eom) {
- errno = EMSGSIZE;
+ __set_errno (EMSGSIZE);
return (-1);
}
*ptrptr = cp;
@@ -556,37 +700,49 @@ dn_find(const u_char *domain, const u_char *msg,
u_int n;
for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
- dn = domain;
- sp = cp = *cpp;
- while ((n = *cp++) != 0) {
- /*
- * check for indirection
- */
- switch (n & NS_CMPRSFLGS) {
- case 0: /* normal case, n == len */
- if (n != *dn++)
- goto next;
- for ((void)NULL; n > 0; n--)
- if (mklower(*dn++) != mklower(*cp++))
+ sp = *cpp;
+ /*
+ * terminate search on:
+ * root label
+ * compression pointer
+ * unusable offset
+ */
+ while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
+ (sp - msg) < 0x4000) {
+ dn = domain;
+ cp = sp;
+ while ((n = *cp++) != 0) {
+ /*
+ * check for indirection
+ */
+ switch (n & NS_CMPRSFLGS) {
+ case 0: /* normal case, n == len */
+ if (n != *dn++)
goto next;
- /* Is next root for both ? */
- if (*dn == '\0' && *cp == '\0')
- return (sp - msg);
- if (*dn)
- continue;
- goto next;
-
- case NS_CMPRSFLGS: /* indirection */
- cp = msg + (((n & 0x3f) << 8) | *cp);
- break;
-
- default: /* illegal type */
- errno = EMSGSIZE;
- return (-1);
+ for ((void)NULL; n > 0; n--)
+ if (mklower(*dn++) !=
+ mklower(*cp++))
+ goto next;
+ /* Is next root for both ? */
+ if (*dn == '\0' && *cp == '\0')
+ return (sp - msg);
+ if (*dn)
+ continue;
+ goto next;
+
+ case NS_CMPRSFLGS: /* indirection */
+ cp = msg + (((n & 0x3f) << 8) | *cp);
+ break;
+
+ default: /* illegal type */
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
}
+ next:
+ sp += *sp + 1;
}
- next: ;
}
- errno = ENOENT;
+ __set_errno (ENOENT);
return (-1);
}
diff --git a/newlib/libc/sys/linux/net/ns_netint.c b/newlib/libc/sys/linux/net/ns_netint.c
index 18c9cccd6..16282e5a1 100644
--- a/newlib/libc/sys/linux/net/ns_netint.c
+++ b/newlib/libc/sys/linux/net/ns_netint.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 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
@@ -15,16 +15,17 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_netint.c,v 8.4 1999/10/13 16:39:35 vixie Exp $";
+#endif
/* Import. */
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
#include <arpa/nameser.h>
+#include <resolv.h>
+#include "libc-symbols.h"
+
+/* Public. */
u_int
ns_get16(const u_char *src) {
@@ -33,6 +34,7 @@ ns_get16(const u_char *src) {
NS_GET16(dst, src);
return (dst);
}
+libresolv_hidden_def (ns_get16)
u_long
ns_get32(const u_char *src) {
@@ -41,6 +43,7 @@ ns_get32(const u_char *src) {
NS_GET32(dst, src);
return (dst);
}
+libresolv_hidden_def (ns_get32)
void
ns_put16(u_int src, u_char *dst) {
diff --git a/newlib/libc/sys/linux/net/ns_ntoa.c b/newlib/libc/sys/linux/net/ns_ntoa.c
deleted file mode 100644
index b6a6c4c22..000000000
--- a/newlib/libc/sys/linux/net/ns_ntoa.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 1986, 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
-
-#include <sys/param.h>
-#include <arpa/inet.h>
-#include <netns/ns.h>
-#include <stdio.h>
-
-static char *spectHex(char *p0);
-
-char *
-ns_ntoa(addr)
- struct ns_addr addr;
-{
- static char obuf[40];
- union { union ns_net net_e; u_long long_e; } net;
- u_short port = htons(addr.x_port);
- char *cp;
- char *cp2;
- u_char *up = addr.x_host.c_host;
- u_char *uplim = up + 6;
-
- net.net_e = addr.x_net;
- sprintf(obuf, "%lx", (u_long)ntohl(net.long_e));
- cp = spectHex(obuf);
- cp2 = cp + 1;
- while (*up==0 && up < uplim) up++;
- if (up == uplim) {
- if (port) {
- sprintf(cp, ".0");
- cp += 2;
- }
- } else {
- sprintf(cp, ".%x", *up++);
- while (up < uplim) {
- while (*cp) cp++;
- sprintf(cp, "%02x", *up++);
- }
- cp = spectHex(cp2);
- }
- if (port) {
- sprintf(cp, ".%x", port);
- spectHex(cp + 1);
- }
- return (obuf);
-}
-
-static char *
-spectHex(p0)
- char *p0;
-{
- int ok = 0;
- int nonzero = 0;
- char *p = p0;
- for (; *p; p++) switch (*p) {
-
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- *p += ('A' - 'a');
- /* fall into . . . */
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- ok = 1;
- case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- nonzero = 1;
- }
- if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
- return (p);
-}
diff --git a/newlib/libc/sys/linux/net/ns_parse.c b/newlib/libc/sys/linux/net/ns_parse.c
index 38a684b87..5311e2496 100644
--- a/newlib/libc/sys/linux/net/ns_parse.c
+++ b/newlib/libc/sys/linux/net/ns_parse.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 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
@@ -15,8 +15,11 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_parse.c,v 8.13 1999/10/13 16:39:35 vixie Exp $";
+#endif
+
+/* Import. */
#include <sys/types.h>
@@ -27,6 +30,18 @@
#include <resolv.h>
#include <string.h>
+#include "libc-symbols.h"
+
+/* Forward. */
+
+static void setsection(ns_msg *msg, ns_sect sect);
+
+/* Macros. */
+
+#define RETERR(err) do { __set_errno (err); return (-1); } while (0)
+
+/* Public. */
+
/* These need to be in the same order as the nres.h:ns_flag enum. */
struct _ns_flagdata _ns_flagdata[16] = {
{ 0x8000, 15 }, /* qr. */
@@ -47,8 +62,8 @@ struct _ns_flagdata _ns_flagdata[16] = {
{ 0x0000, 0 }, /* expansion (6/6). */
};
-static int
-skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
+int
+ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
const u_char *optr = ptr;
for ((void)NULL; count > 0; count--) {
@@ -56,24 +71,19 @@ skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
b = dn_skipname(ptr, eom);
if (b < 0)
- goto emsgsize;
+ RETERR(EMSGSIZE);
ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
if (section != ns_s_qd) {
- if (ptr + NS_INT32SZ > eom)
- goto emsgsize;
+ if (ptr + NS_INT32SZ + NS_INT16SZ > eom)
+ RETERR(EMSGSIZE);
ptr += NS_INT32SZ/*TTL*/;
- if (ptr + NS_INT16SZ > eom)
- goto emsgsize;
NS_GET16(rdlength, ptr);
ptr += rdlength/*RData*/;
}
}
if (ptr > eom)
- goto emsgsize;
+ RETERR(EMSGSIZE);
return (ptr - optr);
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
}
int
@@ -85,22 +95,22 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
handle->_msg = msg;
handle->_eom = eom;
if (msg + NS_INT16SZ > eom)
- goto emsgsize;
+ RETERR(EMSGSIZE);
NS_GET16(handle->_id, msg);
if (msg + NS_INT16SZ > eom)
- goto emsgsize;
+ RETERR(EMSGSIZE);
NS_GET16(handle->_flags, msg);
for (i = 0; i < ns_s_max; i++) {
if (msg + NS_INT16SZ > eom)
- goto emsgsize;
+ RETERR(EMSGSIZE);
NS_GET16(handle->_counts[i], msg);
}
for (i = 0; i < ns_s_max; i++)
if (handle->_counts[i] == 0)
handle->_sections[i] = NULL;
else {
- int b = skiprr(msg, eom, (ns_sect)i,
- handle->_counts[i]);
+ int b = ns_skiprr(msg, eom, (ns_sect)i,
+ handle->_counts[i]);
if (b < 0)
return (-1);
@@ -108,14 +118,9 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
msg += b;
}
if (msg != eom)
- goto emsgsize;
- handle->_sect = ns_s_max;
- handle->_rrnum = -1;
- handle->_ptr = NULL;
+ RETERR(EMSGSIZE);
+ setsection(handle, ns_s_max);
return (0);
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
}
int
@@ -124,29 +129,26 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
/* Make section right. */
if (section < 0 || section >= ns_s_max)
- goto enodev;
- if ((int)section != (int)handle->_sect) {
- handle->_sect = section;
- handle->_rrnum = 0;
- handle->_ptr = handle->_sections[(int)section];
- }
+ RETERR(ENODEV);
+ if (section != handle->_sect)
+ setsection(handle, section);
/* Make rrnum right. */
if (rrnum == -1)
rrnum = handle->_rrnum;
if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
- goto enodev;
- if (rrnum < handle->_rrnum) {
- handle->_rrnum = 0;
- handle->_ptr = handle->_sections[(int)section];
+ RETERR(ENODEV);
+ if (rrnum < handle->_rrnum)
+ setsection(handle, section);
+ if (rrnum > handle->_rrnum) {
+ b = ns_skiprr(handle->_ptr, handle->_eom, section,
+ rrnum - handle->_rrnum);
+
+ if (b < 0)
+ return (-1);
+ handle->_ptr += b;
+ handle->_rrnum = rrnum;
}
-
- b = skiprr(handle->_msg, handle->_eom, section,
- rrnum - handle->_rrnum);
- if (b < 0)
- return (-1);
- handle->_ptr += b;
- handle->_rrnum = rrnum;
/* Do the parse. */
b = dn_expand(handle->_msg, handle->_eom,
@@ -154,36 +156,41 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
if (b < 0)
return (-1);
handle->_ptr += b;
- if (handle->_ptr + NS_INT16SZ > handle->_eom)
- goto emsgsize;
+ if (handle->_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
+ RETERR(EMSGSIZE);
NS_GET16(rr->type, handle->_ptr);
- if (handle->_ptr + NS_INT16SZ > handle->_eom)
- goto emsgsize;
NS_GET16(rr->rr_class, handle->_ptr);
if (section == ns_s_qd) {
rr->ttl = 0;
rr->rdlength = 0;
rr->rdata = NULL;
} else {
- if (handle->_ptr + NS_INT32SZ > handle->_eom)
- goto emsgsize;
+ if (handle->_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
+ RETERR(EMSGSIZE);
NS_GET32(rr->ttl, handle->_ptr);
- if (handle->_ptr + NS_INT16SZ > handle->_eom)
- goto emsgsize;
NS_GET16(rr->rdlength, handle->_ptr);
if (handle->_ptr + rr->rdlength > handle->_eom)
- goto emsgsize;
+ RETERR(EMSGSIZE);
rr->rdata = handle->_ptr;
handle->_ptr += rr->rdlength;
}
- handle->_rrnum++;
+ if (++handle->_rrnum > handle->_counts[(int)section])
+ setsection(handle, (ns_sect)((int)section + 1));
/* All done. */
return (0);
- enodev:
- errno = ENODEV;
- return (-1);
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
+}
+
+/* Private. */
+
+static void
+setsection(ns_msg *msg, ns_sect sect) {
+ msg->_sect = sect;
+ if (sect == ns_s_max) {
+ msg->_rrnum = -1;
+ msg->_ptr = NULL;
+ } else {
+ msg->_rrnum = 0;
+ msg->_ptr = msg->_sections[(int)sect];
+ }
}
diff --git a/newlib/libc/sys/linux/net/ns_print.c b/newlib/libc/sys/linux/net/ns_print.c
index 7cce6d7aa..bc11aa362 100644
--- a/newlib/libc/sys/linux/net/ns_print.c
+++ b/newlib/libc/sys/linux/net/ns_print.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ * Copyright (c) 1996-1999 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
@@ -15,10 +15,9 @@
* SOFTWARE.
*/
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_print.c,v 8.18 2000/02/29 05:48:12 vixie Exp $";
+#endif
/* Import. */
@@ -35,7 +34,13 @@
#include <string.h>
#include <ctype.h>
-#define SPRINTF(x) ((size_t)sprintf x)
+#include "libc-symbols.h"
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
/* Forward. */
@@ -51,6 +56,12 @@ static int addstr(const char *src, size_t len,
static int addtab(size_t len, size_t target, int spaced,
char **buf, size_t *buflen);
+/* Proto. */
+
+#ifndef _LIBC
+u_int16_t dst_s_dns_key_id(const u_char *, const int);
+#endif
+
/* Macros. */
#define T(x) \
@@ -108,7 +119,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
/*
* Owner.
*/
- if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) {
+ if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {
T(addstr("\t\t\t", 3, &buf, &buflen));
} else {
len = prune_origin(name, origin);
@@ -116,9 +127,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
T(addstr("@\t\t\t", 4, &buf, &buflen));
} else {
T(addstr(name, len, &buf, &buflen));
- /* Origin not used and no trailing dot? */
- if ((!origin || !origin[0] || name[len] == '\0') &&
- name[len - 1] != '.') {
+ /* Origin not used or not root, and no trailing dot? */
+ if (((origin == NULL || origin[0] == '\0') ||
+ (origin[0] != '.' && origin[1] != '\0' &&
+ name[len] == '\0')) && name[len - 1] != '.') {
T(addstr(".", 1, &buf, &buflen));
len++;
}
@@ -164,7 +176,11 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
rdata += len;
T(addstr(" ", 1, &buf, &buflen));
- /* Second word. */
+
+ /* Second word, optional in ISDN records. */
+ if (type == ns_t_isdn && rdata == edata)
+ break;
+
T(len = charstr(rdata, edata, &buf, &buflen));
if (len == 0)
goto formerr;
@@ -295,7 +311,9 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
break;
case ns_t_nsap: {
- char t[255*3];
+ /* 2*255 for hex digits, 128 for '.' and '\0', 2 for
+ 0x if inet_nsap_ntoa starts using it. */
+ char t[255*2 + 128 + 2];
(void) inet_nsap_ntoa(rdlen, rdata, t);
T(addstr(t, strlen(t), &buf, &buflen));
@@ -431,8 +449,9 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
}
case ns_t_key: {
+#ifndef _LIBC
char base64_key[NS_MD5RSA_MAX_BASE64];
- u_int keyflags, protocol, algorithm;
+ u_int keyflags, protocol, algorithm, key_id;
const char *leader;
int n;
@@ -440,6 +459,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
goto formerr;
/* Key flags, Protocol, Algorithm. */
+ key_id = dst_s_dns_key_id(rdata, edata-rdata);
keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
protocol = *rdata++;
algorithm = *rdata++;
@@ -465,11 +485,15 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
}
if (len > 15)
T(addstr(" )", 2, &buf, &buflen));
+ n = SPRINTF((tmp, " ; key_tag= %u", key_id));
+ T(addstr(tmp, n, &buf, &buflen));
+#endif /* !_LIBC */
break;
}
case ns_t_sig: {
+#ifndef _LIBC
char base64_key[NS_MD5RSA_MAX_BASE64];
u_int type, algorithm, labels, footprint;
const char *leader;
@@ -484,10 +508,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
algorithm = *rdata++;
labels = *rdata++;
t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, " %s %d %lu ",
- p_type(type), algorithm, t));
+ len = SPRINTF((tmp, "%s %d %d %lu ",
+ p_type(type), algorithm, labels, t));
T(addstr(tmp, len, &buf, &buflen));
- if (labels != (u_int)dn_count_labels(name))
+ if (labels > (u_int)dn_count_labels(name))
goto formerr;
/* Signature expiry. */
@@ -526,7 +550,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
}
if (len > 15)
T(addstr(" )", 2, &buf, &buflen));
-
+#endif /* !_LIBC */
break;
}
@@ -546,6 +570,63 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
break;
}
+ case ns_t_cert: {
+ u_int c_type, key_tag, alg;
+ int n, siz;
+ char base64_cert[8192], *leader, tmp[40];
+
+ c_type = ns_get16(rdata); rdata += NS_INT16SZ;
+ key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
+ alg = (u_int) *rdata++;
+
+ len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg));
+ T(addstr(tmp, len, &buf, &buflen));
+ siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
+ if (siz > sizeof(base64_cert) * 3/4) {
+ char *str = "record too long to print";
+ T(addstr(str, strlen(str), &buf, &buflen));
+ }
+ else {
+ len = b64_ntop(rdata, edata-rdata, base64_cert, siz);
+
+ if (len < 0)
+ goto formerr;
+ else if (len > 15) {
+ T(addstr(" (", 2, &buf, &buflen));
+ leader = "\n\t\t";
+ spaced = 0;
+ }
+ else
+ leader = " ";
+
+ for (n = 0; n < len; n += 48) {
+ T(addstr(leader, strlen(leader),
+ &buf, &buflen));
+ T(addstr(base64_cert + n, MIN(len - n, 48),
+ &buf, &buflen));
+ }
+ if (len > 15)
+ T(addstr(" )", 2, &buf, &buflen));
+ }
+ break;
+ }
+
+ case ns_t_tsig: {
+ /* BEW - need to complete this */
+ int n;
+
+ T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+ rdata += 8; /* time */
+ n = ns_get16(rdata); rdata += INT16SZ;
+ rdata += n; /* sig */
+ n = ns_get16(rdata); rdata += INT16SZ; /* original id */
+ sprintf(buf, "%d", ns_get16(rdata));
+ rdata += INT16SZ;
+ addlen(strlen(buf), &buf, &buflen);
+ break;
+ }
+
default:
comment = "unknown RR type";
goto hexify;
@@ -601,7 +682,7 @@ prune_origin(const char *name, const char *origin) {
const char *oname = name;
while (*name != '\0') {
- if (origin != NULL && strcasecmp(name, origin) == 0)
+ if (origin != NULL && ns_samename(name, origin) == 1)
return (name - oname - (name > oname));
while (*name != '\0') {
if (*name == '\\') {
@@ -658,7 +739,7 @@ charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
goto enospc;
return (rdata - odata);
enospc:
- errno = ENOSPC;
+ __set_errno (ENOSPC);
*buf = save_buf;
*buflen = save_buflen;
return (-1);
@@ -677,27 +758,29 @@ addname(const u_char *msg, size_t msglen,
if (n < 0)
goto enospc; /* Guess. */
newlen = prune_origin(*buf, origin);
- if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
- (newlen == 0 || (*buf)[newlen - 1] != '.')) {
- /* No trailing dot. */
- if (newlen + 2 > *buflen)
- goto enospc; /* No room for ".\0". */
- (*buf)[newlen++] = '.';
- (*buf)[newlen] = '\0';
- }
if (newlen == 0) {
/* Use "@" instead of name. */
if (newlen + 2 > *buflen)
goto enospc; /* No room for "@\0". */
(*buf)[newlen++] = '@';
(*buf)[newlen] = '\0';
+ } else {
+ if (((origin == NULL || origin[0] == '\0') ||
+ (origin[0] != '.' && origin[1] != '\0' &&
+ (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
+ /* No trailing dot. */
+ if (newlen + 2 > *buflen)
+ goto enospc; /* No room for ".\0". */
+ (*buf)[newlen++] = '.';
+ (*buf)[newlen] = '\0';
+ }
}
*pp += n;
addlen(newlen, buf, buflen);
**buf = '\0';
return (newlen);
enospc:
- errno = ENOSPC;
+ __set_errno (ENOSPC);
*buf = save_buf;
*buflen = save_buflen;
return (-1);
@@ -712,8 +795,8 @@ addlen(size_t len, char **buf, size_t *buflen) {
static int
addstr(const char *src, size_t len, char **buf, size_t *buflen) {
- if (len > *buflen) {
- errno = ENOSPC;
+ if (len >= *buflen) {
+ __set_errno (ENOSPC);
return (-1);
}
memcpy(*buf, src, len);
diff --git a/newlib/libc/sys/linux/net/ns_samedomain.c b/newlib/libc/sys/linux/net/ns_samedomain.c
new file mode 100644
index 000000000..964863719
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ns_samedomain.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 1995,1999 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.
+ */
+
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_samedomain.c,v 8.9 1999/10/15 21:06:51 vixie Exp $";
+#endif
+
+#include <sys/types.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <string.h>
+
+#include "libc-symbols.h"
+
+/*
+ * int
+ * ns_samedomain(a, b)
+ * Check whether a name belongs to a domain.
+ * Inputs:
+ * a - the domain whose ancestory is being verified
+ * b - the potential ancestor we're checking against
+ * Return:
+ * boolean - is a at or below b?
+ * Notes:
+ * Trailing dots are first removed from name and domain.
+ * Always compare complete subdomains, not only whether the
+ * domain name is the trailing string of the given name.
+ *
+ * "host.foobar.top" lies in "foobar.top" and in "top" and in ""
+ * but NOT in "bar.top"
+ */
+
+int
+ns_samedomain(const char *a, const char *b) {
+ size_t la, lb;
+ int diff, i, escaped;
+ const char *cp;
+
+ la = strlen(a);
+ lb = strlen(b);
+
+ /* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */
+ if (la != 0 && a[la - 1] == '.') {
+ escaped = 0;
+ /* Note this loop doesn't get executed if la==1. */
+ for (i = la - 2; i >= 0; i--)
+ if (a[i] == '\\') {
+ if (escaped)
+ escaped = 0;
+ else
+ escaped = 1;
+ } else
+ break;
+ if (!escaped)
+ la--;
+ }
+
+ /* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */
+ if (lb != 0 && b[lb - 1] == '.') {
+ escaped = 0;
+ /* note this loop doesn't get executed if lb==1 */
+ for (i = lb - 2; i >= 0; i--)
+ if (b[i] == '\\') {
+ if (escaped)
+ escaped = 0;
+ else
+ escaped = 1;
+ } else
+ break;
+ if (!escaped)
+ lb--;
+ }
+
+ /* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */
+ if (lb == 0)
+ return (1);
+
+ /* 'b' longer than 'a' means 'a' can't be in 'b'. */
+ if (lb > la)
+ return (0);
+
+ /* 'a' and 'b' being equal at this point indicates sameness. */
+ if (lb == la)
+ return (strncasecmp(a, b, lb) == 0);
+
+ /* Ok, we know la > lb. */
+
+ diff = la - lb;
+
+ /*
+ * If 'a' is only 1 character longer than 'b', then it can't be
+ * a subdomain of 'b' (because of the need for the '.' label
+ * separator).
+ */
+ if (diff < 2)
+ return (0);
+
+ /*
+ * If the character before the last 'lb' characters of 'b'
+ * isn't '.', then it can't be a match (this lets us avoid
+ * having "foobar.com" match "bar.com").
+ */
+ if (a[diff - 1] != '.')
+ return (0);
+
+ /*
+ * We're not sure about that '.', however. It could be escaped
+ * and thus not a really a label separator.
+ */
+ escaped = 0;
+ for (i = diff - 2; i >= 0; i--)
+ if (a[i] == '\\')
+ if (escaped)
+ escaped = 0;
+ else
+ escaped = 1;
+ else
+ break;
+ if (escaped)
+ return (0);
+
+ /* Now compare aligned trailing substring. */
+ cp = a + diff;
+ return (strncasecmp(cp, b, lb) == 0);
+}
+
+/*
+ * int
+ * ns_subdomain(a, b)
+ * is "a" a subdomain of "b"?
+ */
+int
+ns_subdomain(const char *a, const char *b) {
+ return (ns_samename(a, b) != 1 && ns_samedomain(a, b));
+}
+
+/*
+ * int
+ * ns_makecanon(src, dst, dstsize)
+ * make a canonical copy of domain name "src"
+ * notes:
+ * foo -> foo.
+ * foo. -> foo.
+ * foo.. -> foo.
+ * foo\. -> foo\..
+ * foo\\. -> foo\\.
+ */
+
+int
+ns_makecanon(const char *src, char *dst, size_t dstsize) {
+ size_t n = strlen(src);
+
+ if (n + sizeof "." > dstsize) {
+ __set_errno (EMSGSIZE);
+ return (-1);
+ }
+ strcpy(dst, src);
+ while (n > 0 && dst[n - 1] == '.') /* Ends in "." */
+ if (n > 1 && dst[n - 2] == '\\' && /* Ends in "\." */
+ (n < 2 || dst[n - 3] != '\\')) /* But not "\\." */
+ break;
+ else
+ dst[--n] = '\0';
+ dst[n++] = '.';
+ dst[n] = '\0';
+ return (0);
+}
+
+/*
+ * int
+ * ns_samename(a, b)
+ * determine whether domain name "a" is the same as domain name "b"
+ * return:
+ * -1 on error
+ * 0 if names differ
+ * 1 if names are the same
+ */
+
+int
+ns_samename(const char *a, const char *b) {
+ char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
+
+ if (ns_makecanon(a, ta, sizeof ta) < 0 ||
+ ns_makecanon(b, tb, sizeof tb) < 0)
+ return (-1);
+ if (strcasecmp(ta, tb) == 0)
+ return (1);
+ else
+ return (0);
+}
diff --git a/newlib/libc/sys/linux/net/ns_ttl.c b/newlib/libc/sys/linux/net/ns_ttl.c
index 63dbefb59..87cd7b1ed 100644
--- a/newlib/libc/sys/linux/net/ns_ttl.c
+++ b/newlib/libc/sys/linux/net/ns_ttl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 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
@@ -15,8 +15,9 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if !defined(_LIBC) && !defined(lint)
+static const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $";
+#endif
/* Import. */
@@ -27,7 +28,13 @@
#include <stdio.h>
#include <string.h>
-#define SPRINTF(x) ((size_t)sprintf x)
+#include "libc-symbols.h"
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
/* Forward. */
@@ -84,6 +91,9 @@ ns_format_ttl(u_long src, char *dst, size_t dstlen) {
return (dst - odst);
}
+#ifndef SHARED
+// Seems not to be needed. It's not exported from the DSO. Some libresolv.a
+// might depend on it so we let it in.
int
ns_parse_ttl(const char *src, u_long *dst) {
u_long ttl, tmp;
@@ -129,9 +139,10 @@ ns_parse_ttl(const char *src, u_long *dst) {
return (0);
einval:
- errno = EINVAL;
+ __set_errno (EINVAL);
return (-1);
}
+#endif
/* Private. */
diff --git a/newlib/libc/sys/linux/net/nsap_addr.c b/newlib/libc/sys/linux/net/nsap_addr.c
index b6651488b..5c0855f60 100644
--- a/newlib/libc/sys/linux/net/nsap_addr.c
+++ b/newlib/libc/sys/linux/net/nsap_addr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ * Copyright (c) 1996-1999 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
@@ -15,31 +15,30 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] = "$BINDId: nsap_addr.c,v 8.10 1999/10/13 16:39:28 vixie Exp $";
+#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
+
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+
#include <ctype.h>
#include <resolv.h>
+#include "libc-symbols.h"
+
static char
-xtob(c)
- int c;
-{
+xtob(int c) {
return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
}
u_int
-inet_nsap_addr(ascii, binary, maxlen)
- const char *ascii;
- u_char *binary;
- int maxlen;
-{
+inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) {
u_char c, nib;
u_int len = 0;
@@ -48,8 +47,7 @@ inet_nsap_addr(ascii, binary, maxlen)
continue;
if (!isascii(c))
return (0);
- if (islower(c))
- c = toupper(c);
+ c = toupper(c);
if (isxdigit(c)) {
nib = xtob(c);
c = *ascii++;
@@ -71,14 +69,10 @@ inet_nsap_addr(ascii, binary, maxlen)
}
char *
-inet_nsap_ntoa(binlen, binary, ascii)
- int binlen;
- const u_char *binary;
- char *ascii;
-{
+inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
int nib;
int i;
- static char tmpbuf[255*3];
+ static char tmpbuf[255*2 + 128];
char *start;
if (ascii)
@@ -102,12 +96,3 @@ inet_nsap_ntoa(binlen, binary, ascii)
*ascii = '\0';
return (start);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_nsap_addr
-__weak_reference(__inet_nsap_addr, inet_nsap_addr);
-#undef inet_nsap_ntoa
-__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa);
diff --git a/newlib/libc/sys/linux/net/nscd-types.h b/newlib/libc/sys/linux/net/nscd-types.h
new file mode 100644
index 000000000..dbe43b8bc
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nscd-types.h
@@ -0,0 +1,22 @@
+/* Types for the NSCD implementation. Generic version.
+ Copyright (c) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdint.h>
+
+typedef int32_t nscd_ssize_t;
diff --git a/newlib/libc/sys/linux/net/nscd/nscd-client.h b/newlib/libc/sys/linux/net/nscd/nscd-client.h
new file mode 100644
index 000000000..0ba8a2198
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nscd/nscd-client.h
@@ -0,0 +1,312 @@
+/* Copyright (c) 1998, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file defines everything that client code should need to
+ know to talk to the nscd daemon. */
+
+#ifndef _NSCD_CLIENT_H
+#define _NSCD_CLIENT_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <machine/atomic.h>
+#include <nscd-types.h>
+
+
+/* Version number of the daemon interface */
+#define NSCD_VERSION 2
+
+/* Path of the file where the PID of the running system is stored. */
+#define _PATH_NSCDPID "/var/run/nscd/nscd.pid"
+
+/* Path for the Unix domain socket. */
+#define _PATH_NSCDSOCKET "/var/run/nscd/socket"
+
+/* Path for the configuration file. */
+#define _PATH_NSCDCONF "/etc/nscd.conf"
+
+
+/* Available services. */
+typedef enum
+{
+ GETPWBYNAME,
+ GETPWBYUID,
+ GETGRBYNAME,
+ GETGRBYGID,
+ GETHOSTBYNAME,
+ GETHOSTBYNAMEv6,
+ GETHOSTBYADDR,
+ GETHOSTBYADDRv6,
+ LASTDBREQ = GETHOSTBYADDRv6,
+ SHUTDOWN, /* Shut the server down. */
+ GETSTAT, /* Get the server statistic. */
+ INVALIDATE, /* Invalidate one special cache. */
+ GETFDPW,
+ GETFDGR,
+ GETFDHST,
+ GETAI,
+ INITGROUPS,
+ LASTREQ
+} request_type;
+
+
+/* Header common to all requests */
+typedef struct
+{
+ int32_t version; /* Version number of the daemon interface. */
+ request_type type; /* Service requested. */
+ int32_t key_len; /* Key length. */
+} request_header;
+
+
+/* Structure sent in reply to password query. Note that this struct is
+ sent also if the service is disabled or there is no record found. */
+typedef struct
+{
+ int32_t version;
+ int32_t found;
+ nscd_ssize_t pw_name_len;
+ nscd_ssize_t pw_passwd_len;
+ uid_t pw_uid;
+ gid_t pw_gid;
+ nscd_ssize_t pw_gecos_len;
+ nscd_ssize_t pw_dir_len;
+ nscd_ssize_t pw_shell_len;
+} pw_response_header;
+
+
+/* Structure sent in reply to group query. Note that this struct is
+ sent also if the service is disabled or there is no record found. */
+typedef struct
+{
+ int32_t version;
+ int32_t found;
+ nscd_ssize_t gr_name_len;
+ nscd_ssize_t gr_passwd_len;
+ gid_t gr_gid;
+ nscd_ssize_t gr_mem_cnt;
+} gr_response_header;
+
+
+/* Structure sent in reply to host query. Note that this struct is
+ sent also if the service is disabled or there is no record found. */
+typedef struct
+{
+ int32_t version;
+ int32_t found;
+ nscd_ssize_t h_name_len;
+ nscd_ssize_t h_aliases_cnt;
+ int32_t h_addrtype;
+ int32_t h_length;
+ nscd_ssize_t h_addr_list_cnt;
+ int32_t error;
+} hst_response_header;
+
+
+/* Structure sent in reply to addrinfo query. Note that this struct is
+ sent also if the service is disabled or there is no record found. */
+typedef struct
+{
+ int32_t version;
+ int32_t found;
+ nscd_ssize_t naddrs;
+ nscd_ssize_t addrslen;
+ nscd_ssize_t canonlen;
+ int32_t error;
+} ai_response_header;
+
+/* Structure filled in by __nscd_getai. */
+struct nscd_ai_result
+{
+ int naddrs;
+ char *canon;
+ uint8_t *family;
+ char *addrs;
+};
+
+/* Structure sent in reply to initgroups query. Note that this struct is
+ sent also if the service is disabled or there is no record found. */
+typedef struct
+{
+ int32_t version;
+ int32_t found;
+ nscd_ssize_t ngrps;
+} initgr_response_header;
+
+
+/* Type for offsets in data part of database. */
+typedef uint32_t ref_t;
+/* Value for invalid/no reference. */
+#define ENDREF UINT32_MAX
+
+/* Timestamp type. */
+typedef uint64_t nscd_time_t;
+
+/* Alignment requirement of the beginning of the data region. */
+#define ALIGN 16
+
+
+/* Head of record in data part of database. */
+struct datahead
+{
+ nscd_ssize_t allocsize; /* Allocated Bytes. */
+ nscd_ssize_t recsize; /* Size of the record. */
+ nscd_time_t timeout; /* Time when this entry becomes invalid. */
+ uint8_t notfound; /* Nonzero if data has not been found. */
+ uint8_t nreloads; /* Reloads without use. */
+ uint8_t usable; /* False if the entry must be ignored. */
+ uint64_t :40; /* Alignment. */
+
+ /* We need to have the following element aligned for the response
+ header data types and their use in the 'struct dataset' types
+ defined in the XXXcache.c files. */
+ union
+ {
+ pw_response_header pwdata;
+ gr_response_header grdata;
+ hst_response_header hstdata;
+ ai_response_header aidata;
+ initgr_response_header initgrdata;
+ nscd_ssize_t align1;
+ nscd_time_t align2;
+ } data[0];
+};
+
+
+/* Structure for one hash table entry. */
+struct hashentry
+{
+ request_type type:8; /* Which type of dataset. */
+ bool first; /* True if this was the original key. */
+ nscd_ssize_t len; /* Length of key. */
+ ref_t key; /* Pointer to key. */
+ int32_t owner; /* If secure table, this is the owner. */
+ ref_t next; /* Next entry in this hash bucket list. */
+ ref_t packet; /* Records for the result. */
+ union
+ {
+ struct hashentry *dellist; /* Next record to be deleted. This can be a
+ pointer since only nscd uses this field. */
+ ref_t *prevp; /* Pointer to field containing forward
+ reference. */
+ };
+};
+
+
+/* Current persistent database version. */
+#define DB_VERSION 1
+
+/* Maximum time allowed between updates of the timestamp. */
+#define MAPPING_TIMEOUT (5 * 60)
+
+
+/* Header of persistent database file. */
+struct database_pers_head
+{
+ int32_t version;
+ int32_t header_size;
+ volatile int32_t gc_cycle;
+ volatile int32_t nscd_certainly_running;
+ volatile nscd_time_t timestamp;
+
+ nscd_ssize_t module;
+ nscd_ssize_t data_size;
+
+ nscd_ssize_t first_free; /* Offset of first free byte in data area. */
+
+ nscd_ssize_t nentries;
+ nscd_ssize_t maxnentries;
+ nscd_ssize_t maxnsearched;
+
+ uint64_t poshit;
+ uint64_t neghit;
+ uint64_t posmiss;
+ uint64_t negmiss;
+
+ uint64_t rdlockdelayed;
+ uint64_t wrlockdelayed;
+
+ uint64_t addfailed;
+
+ ref_t array[0];
+};
+
+
+/* Mapped database record. */
+struct mapped_database
+{
+ const struct database_pers_head *head;
+ const char *data;
+ size_t mapsize;
+ int counter; /* > 0 indicates it is usable. */
+};
+#define NO_MAPPING ((struct mapped_database *) -1l)
+
+struct locked_map_ptr
+{
+ int lock;
+ struct mapped_database *mapped;
+};
+#define libc_locked_map_ptr(class, name) class struct locked_map_ptr name
+
+
+/* Open socket connection to nscd server. */
+extern int __nscd_open_socket (const char *key, size_t keylen,
+ request_type type, void *response,
+ size_t responselen) attribute_hidden;
+
+/* Get reference of mapping. */
+extern struct mapped_database *__nscd_get_map_ref (request_type type,
+ const char *name,
+ struct locked_map_ptr *mapptr,
+ int *gc_cyclep);
+
+/* Unmap database. */
+extern void __nscd_unmap (struct mapped_database *mapped);
+
+/* Drop reference of mapping. */
+static inline int __nscd_drop_map_ref (struct mapped_database *map,
+ int *gc_cycle)
+{
+ if (map != NO_MAPPING)
+ {
+ int now_cycle = map->head->gc_cycle;
+ if (__builtin_expect (now_cycle != *gc_cycle, 0))
+ {
+ /* We might have read inconsistent data. */
+ *gc_cycle = now_cycle;
+ return -1;
+ }
+
+ if (atomic_decrement_and_test (&map->counter) == 0)
+ __nscd_unmap (map);
+ }
+
+ return 0;
+}
+
+
+/* Search the mapped database. */
+extern const struct datahead *__nscd_cache_search (request_type type,
+ const char *key,
+ size_t keylen,
+ const struct mapped_database *mapped);
+
+#endif /* nscd.h */
diff --git a/newlib/libc/sys/linux/net/nscd/nscd_proto.h b/newlib/libc/sys/linux/net/nscd/nscd_proto.h
new file mode 100644
index 000000000..64d9bd004
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nscd/nscd_proto.h
@@ -0,0 +1,67 @@
+/* Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NSCD_PROTO_H
+#define _NSCD_PROTO_H 1
+
+#include <grp.h>
+#include <netdb.h>
+#include <pwd.h>
+
+/* Interval in which we transfer retry to contact the NSCD. */
+#define NSS_NSCD_RETRY 100
+
+/* Type needed in the interfaces. */
+struct nscd_ai_result;
+
+
+/* Variables for communication between NSCD handler functions and NSS. */
+extern int __nss_not_use_nscd_passwd attribute_hidden;
+extern int __nss_not_use_nscd_group attribute_hidden;
+extern int __nss_not_use_nscd_hosts attribute_hidden;
+
+extern int __nscd_getpwnam_r (const char *name, struct passwd *resultbuf,
+ char *buffer, size_t buflen,
+ struct passwd **result);
+extern int __nscd_getpwuid_r (uid_t uid, struct passwd *resultbuf,
+ char *buffer, size_t buflen,
+ struct passwd **result);
+extern int __nscd_getgrnam_r (const char *name, struct group *resultbuf,
+ char *buffer, size_t buflen,
+ struct group **result);
+extern int __nscd_getgrgid_r (gid_t gid, struct group *resultbuf,
+ char *buffer, size_t buflen,
+ struct group **result);
+extern int __nscd_gethostbyname_r (const char *name,
+ struct hostent *resultbuf,
+ char *buffer, size_t buflen,
+ struct hostent **result, int *h_errnop);
+extern int __nscd_gethostbyname2_r (const char *name, int af,
+ struct hostent *resultbuf,
+ char *buffer, size_t buflen,
+ struct hostent **result, int *h_errnop);
+extern int __nscd_gethostbyaddr_r (const void *addr, socklen_t len, int type,
+ struct hostent *resultbuf,
+ char *buffer, size_t buflen,
+ struct hostent **result, int *h_errnop);
+extern int __nscd_getai (const char *key, struct nscd_ai_result **result,
+ int *h_errnop);
+extern int __nscd_getgrouplist (const char *user, gid_t group, long int *size,
+ gid_t **groupsp, long int limit);
+#endif /* _NSCD_PROTO_H */
diff --git a/newlib/libc/sys/linux/net/nsdispatch.3 b/newlib/libc/sys/linux/net/nsdispatch.3
deleted file mode 100644
index 708f97cba..000000000
--- a/newlib/libc/sys/linux/net/nsdispatch.3
+++ /dev/null
@@ -1,231 +0,0 @@
-.\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $
-.\" $FreeBSD: src/lib/libc/net/nsdispatch.3,v 1.5 2001/10/01 16:08:56 ru Exp $
-.\"
-.\" Copyright (c) 1997, 1998, 1999 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 January 19, 1999
-.Dt NSDISPATCH 3
-.Os
-.Sh NAME
-.Nm nsdispatch
-.Nd name-service switch dispatcher routine
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In nsswitch.h
-.Ft int
-.Fo nsdispatch
-.Fa "void *retval"
-.Fa "const ns_dtab dtab[]"
-.Fa "const char *database"
-.Fa "const char *method"
-.Fa "const ns_src defaults[]"
-.Fa "..."
-.Fc
-.Sh DESCRIPTION
-The
-.Fn nsdispatch
-function invokes the callback functions specified in
-.Va dtab
-in the order given in
-.Pa /etc/nsswitch.conf
-for the database
-.Va database
-until a successful entry is found.
-.Pp
-.Va retval
-is passed to each callback function to modify as necessary
-(to pass back to the caller of
-.Fn nsdispatch )
-.Pp
-.Va dtab
-is an array of
-.Va ns_dtab
-structures, which have the following format:
-.Bd -literal -offset indent
-typedef struct {
- const char *src;
- int (*cb)(void *retval, void *cb_data, va_list ap);
- void *cb_data;
-} ns_dtab;
-.Ed
-.Pp
-.Bd -ragged -offset indent
-For each source type that is implemented, an entry with
-.Va src
-set to the name of the source,
-.Va cb
-defined as a function which handles that source, and
-.Va cb_data
-is used to pass arbritrary data to the callback function.
-The last entry in
-.Va dtab
-should contain
-.Dv NULL
-values for
-.Va src ,
-.Va cb ,
-and
-.Va cb_data .
-.Ed
-.Pp
-.Va method
-is usually the name of the function calling
-.Fn nsdispatch .
-When dynamic loading is supported, a symbol constructed from
-.Va database ,
-the current source, and
-.Va method
-will be used as the name to invoke the dynamically loaded function.
-.Pp
-.Va defaults
-contains a list of default sources to try in the case of
-a missing or corrupt
-.Xr nsswitch.conf 5 ,
-or if there isn't a relevant entry for
-.Va database .
-It is an array of
-.Va ns_src
-structures, which have the following format:
-.Bd -literal -offset indent
-typedef struct {
- const char *src;
- u_int32_t flags;
-} ns_src;
-.Ed
-.Pp
-.Bd -ragged -offset indent
-For each default source type, an entry with
-.Va src
-set to the name of the source, and
-.Va flags
-set to the relevant flags
-(usually
-.Dv NS_SUCCESS ;
-refer to
-.Sx Callback return values
-for more information).
-The last entry in
-.Va defaults
-should have
-.Va src
-set to
-.Dv NULL
-and
-.Va flags
-set to 0.
-.Pp
-For convenience, a global variable defined as:
-.Dl extern const ns_src __nsdefaultsrc[];
-exists which contains a single default entry for
-.Sq files
-for use by callers which don't require complicated default rules.
-.Ed
-.Pp
-.Sq Va ...
-are optional extra arguments, which
-are passed to the appropriate callback function as a variable argument
-list of the type
-.Va va_list .
-.Ss Valid source types
-Whilst there is support for arbitrary sources, the following
-#defines for commonly implementated sources are available:
-.Bl -column NS_COMPAT COMPAT -offset indent
-.It Sy "#define value"
-.It "NSSRC_FILES ""files"""
-.It "NSSRC_DNS ""dns"""
-.It "NSSRC_NIS ""nis"""
-.It "NSSRC_COMPAT ""compat"""
-.El
-.Pp
-Refer to
-.Xr nsswitch.conf 5
-for a complete description of what each source type is.
-.Pp
-.Ss Callback return values
-The callback functions should return one of the following values
-depending upon status of the lookup:
-.Bl -column NS_NOTFOUND -offset indent
-.It Sy "Return value Status code"
-.It "NS_SUCCESS success"
-.It "NS_NOTFOUND notfound"
-.It "NS_UNAVAIL unavail"
-.It "NS_TRYAGAIN tryagain"
-.El
-.Pp
-Refer to
-.Xr nsswitch.conf 5
-for a complete description of what each status code is.
-.Pp
-.Nm
-returns the value of the callback that caused the dispatcher to finish,
-or NS_NOTFOUND otherwise.
-.Sh SEE ALSO
-.Xr hesiod 3 ,
-.Xr stdarg 3 ,
-.Xr ypclnt 3 ,
-.Xr nsswitch.conf 5
-.Sh HISTORY
-The
-.Nm
-routines first appeared in
-.Fx 4.1 .
-They were imported from the
-.Nx
-Project,
-where they appeared first in
-.Nx 1.4 .
-.Sh AUTHORS
-Luke Mewburn
-.Aq lukem@netbsd.org
-wrote this freely distributable name-service switch implementation,
-using ideas from the
-.Tn ULTRIX
-.Xr svc.conf 5
-and
-.Tn Solaris
-.Xr nsswitch.conf 4
-manual pages.
-.Sh BUGS
-The
-.Nm
-routines are not thread safe.
-This will be rectified in the future.
-.Pp
-Currently there is no support for dynamically loadable dispatcher callback
-functions.
-It is anticipated that this will be added in the future in the back-end
-without requiring changes to code that invokes
-.Fn nsdispatch .
diff --git a/newlib/libc/sys/linux/net/nsdispatch.c b/newlib/libc/sys/linux/net/nsdispatch.c
deleted file mode 100644
index ea5fc6d4b..000000000
--- a/newlib/libc/sys/linux/net/nsdispatch.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/* $NetBSD: nsdispatch.c,v 1.9 1999/01/25 00:16:17 lukem Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <fcntl.h>
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * default sourcelist: `files'
- */
-const ns_src __nsdefaultsrc[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { 0 },
-};
-
-
-static int _nsmapsize = 0;
-static ns_dbt *_nsmap = NULL;
-
-/*
- * size of dynamic array chunk for _nsmap and _nsmap[x].srclist
- */
-#define NSELEMSPERCHUNK 8
-
-
-int _nscmp(const void *, const void *);
-
-
-int
-_nscmp(a, b)
- const void *a;
- const void *b;
-{
- return (strcasecmp(((const ns_dbt *)a)->name,
- ((const ns_dbt *)b)->name));
-}
-
-
-void
-_nsdbtaddsrc(dbt, src)
- ns_dbt *dbt;
- const ns_src *src;
-{
- if ((dbt->srclistsize % NSELEMSPERCHUNK) == 0) {
- dbt->srclist = (ns_src *)realloc(dbt->srclist,
- (dbt->srclistsize + NSELEMSPERCHUNK) * sizeof(ns_src));
- if (dbt->srclist == NULL)
- printf("nsdispatch: memory allocation failure\n");
- }
- memmove(&dbt->srclist[dbt->srclistsize++], src, sizeof(ns_src));
-}
-
-
-void
-_nsdbtdump(dbt)
- const ns_dbt *dbt;
-{
- int i;
-
- printf("%s (%d source%s):", dbt->name, dbt->srclistsize,
- dbt->srclistsize == 1 ? "" : "s");
- for (i = 0; i < dbt->srclistsize; i++) {
- printf(" %s", dbt->srclist[i].name);
- if (!(dbt->srclist[i].flags &
- (NS_UNAVAIL|NS_NOTFOUND|NS_TRYAGAIN)) &&
- (dbt->srclist[i].flags & NS_SUCCESS))
- continue;
- printf(" [");
- if (!(dbt->srclist[i].flags & NS_SUCCESS))
- printf(" SUCCESS=continue");
- if (dbt->srclist[i].flags & NS_UNAVAIL)
- printf(" UNAVAIL=return");
- if (dbt->srclist[i].flags & NS_NOTFOUND)
- printf(" NOTFOUND=return");
- if (dbt->srclist[i].flags & NS_TRYAGAIN)
- printf(" TRYAGAIN=return");
- printf(" ]");
- }
- printf("\n");
-}
-
-
-const ns_dbt *
-_nsdbtget(name)
- const char *name;
-{
- static time_t confmod;
-
- struct stat statbuf;
- ns_dbt dbt;
-
- extern FILE *_nsyyin;
- extern int _nsyyparse(void);
-
- dbt.name = name;
-
- if (confmod) {
- if (stat(_PATH_NS_CONF, &statbuf) == -1)
- return (NULL);
- if (confmod < statbuf.st_mtime) {
- int i, j;
-
- for (i = 0; i < _nsmapsize; i++) {
- for (j = 0; j < _nsmap[i].srclistsize; j++) {
- if (_nsmap[i].srclist[j].name != NULL) {
- /*LINTED const cast*/
- free((void *)
- _nsmap[i].srclist[j].name);
- }
- }
- if (_nsmap[i].srclist)
- free(_nsmap[i].srclist);
- if (_nsmap[i].name) {
- /*LINTED const cast*/
- free((void *)_nsmap[i].name);
- }
- }
- if (_nsmap)
- free(_nsmap);
- _nsmap = NULL;
- _nsmapsize = 0;
- confmod = 0;
- }
- }
- if (!confmod) {
- if (stat(_PATH_NS_CONF, &statbuf) == -1)
- return (NULL);
- _nsyyin = fopen(_PATH_NS_CONF, "r");
- if (_nsyyin == NULL)
- return (NULL);
- _nsyyparse();
- (void)fclose(_nsyyin);
- qsort(_nsmap, (size_t)_nsmapsize, sizeof(ns_dbt), _nscmp);
- confmod = statbuf.st_mtime;
- }
- return (bsearch(&dbt, _nsmap, (size_t)_nsmapsize, sizeof(ns_dbt),
- _nscmp));
-}
-
-
-void
-_nsdbtput(dbt)
- const ns_dbt *dbt;
-{
- int i;
-
- for (i = 0; i < _nsmapsize; i++) {
- if (_nscmp(dbt, &_nsmap[i]) == 0) {
- /* overwrite existing entry */
- if (_nsmap[i].srclist != NULL)
- free(_nsmap[i].srclist);
- memmove(&_nsmap[i], dbt, sizeof(ns_dbt));
- return;
- }
- }
-
- if ((_nsmapsize % NSELEMSPERCHUNK) == 0) {
- _nsmap = (ns_dbt *)realloc(_nsmap,
- (_nsmapsize + NSELEMSPERCHUNK) * sizeof(ns_dbt));
- if (_nsmap == NULL)
- printf("nsdispatch: memory allocation failure\n");
- }
- memmove(&_nsmap[_nsmapsize++], dbt, sizeof(ns_dbt));
-}
-
-
-int
-#if __STDC__
-nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
- const char *method, const ns_src defaults[], ...)
-#else
-nsdispatch(retval, disp_tab, database, method, defaults, va_alist)
- void *retval;
- const ns_dtab disp_tab[];
- const char *database;
- const char *method;
- const ns_src defaults[];
- va_dcl
-#endif
-{
- va_list ap;
- int i, curdisp, result;
- const ns_dbt *dbt;
- const ns_src *srclist;
- int srclistsize;
-
- dbt = _nsdbtget(database);
- if (dbt != NULL) {
- srclist = dbt->srclist;
- srclistsize = dbt->srclistsize;
- } else {
- srclist = defaults;
- srclistsize = 0;
- while (srclist[srclistsize].name != NULL)
- srclistsize++;
- }
- result = 0;
-
- for (i = 0; i < srclistsize; i++) {
- for (curdisp = 0; disp_tab[curdisp].src != NULL; curdisp++)
- if (strcasecmp(disp_tab[curdisp].src,
- srclist[i].name) == 0)
- break;
- result = 0;
- if (disp_tab[curdisp].callback) {
-#if __STDC__
- va_start(ap, defaults);
-#else
- va_start(ap);
-#endif
- result = disp_tab[curdisp].callback(retval,
- disp_tab[curdisp].cb_data, ap);
- va_end(ap);
- if (result & srclist[i].flags) {
- break;
- }
- }
- }
- return (result ? result : NS_NOTFOUND);
-}
diff --git a/newlib/libc/sys/linux/net/nslexer.c b/newlib/libc/sys/linux/net/nslexer.c
deleted file mode 100644
index 3f6ba4dcd..000000000
--- a/newlib/libc/sys/linux/net/nslexer.c
+++ /dev/null
@@ -1,1712 +0,0 @@
-#define yy_create_buffer _nsyy_create_buffer
-#define yy_delete_buffer _nsyy_delete_buffer
-#define yy_scan_buffer _nsyy_scan_buffer
-#define yy_scan_string _nsyy_scan_string
-#define yy_scan_bytes _nsyy_scan_bytes
-#define yy_flex_debug _nsyy_flex_debug
-#define yy_init_buffer _nsyy_init_buffer
-#define yy_flush_buffer _nsyy_flush_buffer
-#define yy_load_buffer_state _nsyy_load_buffer_state
-#define yy_switch_to_buffer _nsyy_switch_to_buffer
-#define yyin _nsyyin
-#define yyleng _nsyyleng
-#define yylex _nsyylex
-#define yyout _nsyyout
-#define yyrestart _nsyyrestart
-#define yytext _nsyytext
-#define yylineno _nsyylineno
-#define yywrap _nsyywrap
-
-/* A lexical scanner generated by flex */
-
-/* Scanner skeleton version:
- * $Header$
- */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-
-#include <stdio.h>
-#include <unistd.h>
-
-
-/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-
-
-#ifdef __cplusplus
-
-#include <stdlib.h>
-
-/* Use prototypes in function declarations. */
-#define YY_USE_PROTOS
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-#if __STDC__
-
-#define YY_USE_PROTOS
-#define YY_USE_CONST
-
-#endif /* __STDC__ */
-#endif /* ! __cplusplus */
-
-#ifdef __TURBOC__
- #pragma warn -rch
- #pragma warn -use
-#include <io.h>
-#include <stdlib.h>
-#define YY_USE_CONST
-#define YY_USE_PROTOS
-#endif
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-
-#ifdef YY_USE_PROTOS
-#define YY_PROTO(proto) proto
-#else
-#define YY_PROTO(proto) ()
-#endif
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN yy_start = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START ((yy_start - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart( yyin )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#define YY_BUF_SIZE 1024
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-extern int yyleng;
-extern FILE *yyin, *yyout;
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
-/* The funky do-while in the following #define is used to turn the definition
- * int a single C statement (which needs a semi-colon terminator). This
- * avoids problems with code like:
- *
- * if ( condition_holds )
- * yyless( 5 );
- * else
- * do_something_else();
- *
- * Prior to using the do-while the compiler would get upset at the
- * "else" because it interpreted the "if" statement as being all
- * done when it reached the ';' after the yyless() call.
- */
-
-/* Return all but the first 'n' matched characters back to the input stream. */
-
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- *yy_cp = yy_hold_char; \
- YY_RESTORE_YY_MORE_OFFSET \
- yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up yytext again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, yytext_ptr )
-
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- */
-typedef unsigned int yy_size_t;
-
-
-struct yy_buffer_state
- {
- FILE *yy_input_file;
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- int yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via yyrestart()), so that the user can continue scanning by
- * just pointing yyin at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
- };
-
-static YY_BUFFER_STATE yy_current_buffer = 0;
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- */
-#define YY_CURRENT_BUFFER yy_current_buffer
-
-
-/* yy_hold_char holds the character lost when yytext is formed. */
-static char yy_hold_char;
-
-static int yy_n_chars; /* number of characters read into yy_ch_buf */
-
-
-int yyleng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 1; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow yywrap()'s to do buffer switches
- * instead of setting up a fresh yyin. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-
-void yyrestart YY_PROTO(( FILE *input_file ));
-
-void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
-void yy_load_buffer_state YY_PROTO(( void ));
-YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
-void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
-void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
-void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
-#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
-
-YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
-YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
-YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
-
-static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
-static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
-static void yy_flex_free YY_PROTO(( void * ));
-
-#define yy_new_buffer yy_create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! yy_current_buffer ) \
- yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
- yy_current_buffer->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! yy_current_buffer ) \
- yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
- yy_current_buffer->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
-
-
-#define YY_USES_REJECT
-typedef unsigned char YY_CHAR;
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
-typedef int yy_state_type;
-extern int yylineno;
-int yylineno = 1;
-extern char *yytext;
-#define yytext_ptr yytext
-
-static yy_state_type yy_get_previous_state YY_PROTO(( void ));
-static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
-static int yy_get_next_buffer YY_PROTO(( void ));
-static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up yytext.
- */
-#define YY_DO_BEFORE_ACTION \
- yytext_ptr = yy_bp; \
- yyleng = (int) (yy_cp - yy_bp); \
- yy_hold_char = *yy_cp; \
- *yy_cp = '\0'; \
- yy_c_buf_p = yy_cp;
-
-#define YY_NUM_RULES 13
-#define YY_END_OF_BUFFER 14
-static yyconst short int yy_acclist[83] =
- { 0,
- 14, 12, 13, 1, 12, 13, 4, 13, 2, 12,
- 13, 11, 12, 13, 11, 12, 13, 11, 12, 13,
- 11, 12, 13, 11, 12, 13, 11, 12, 13, 11,
- 12, 13, 12, 13, 1, 2, 11, 11, 11, 11,
- 11, 11, 11, 3, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 9, 11, 11, 11, 11, 11,
- 11, 5, 11, 11, 6, 11, 10, 11, 7, 11,
- 8, 11
- } ;
-
-static yyconst short int yy_accept[60] =
- { 0,
- 1, 1, 1, 2, 4, 7, 9, 12, 15, 18,
- 21, 24, 27, 30, 33, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
- 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 65, 67, 68, 69, 70,
- 71, 72, 74, 75, 77, 79, 81, 83, 83
- } ;
-
-static yyconst int yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 1, 4, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 1, 1, 1,
- 1, 1, 1, 1, 6, 7, 8, 9, 10, 11,
- 12, 7, 13, 7, 7, 14, 7, 15, 16, 7,
- 7, 17, 18, 19, 20, 21, 7, 7, 22, 7,
- 1, 23, 1, 1, 5, 1, 6, 7, 8, 9,
-
- 10, 11, 12, 7, 13, 7, 7, 14, 7, 15,
- 16, 7, 7, 17, 18, 19, 20, 21, 7, 7,
- 22, 7, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static yyconst int yy_meta[24] =
- { 0,
- 1, 1, 2, 1, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 1
- } ;
-
-static yyconst short int yy_base[61] =
- { 0,
- 0, 0, 68, 69, 65, 69, 0, 0, 50, 49,
- 54, 43, 45, 46, 57, 57, 0, 0, 43, 38,
- 37, 47, 32, 47, 69, 33, 40, 30, 41, 42,
- 26, 33, 29, 27, 33, 30, 35, 25, 19, 23,
- 19, 30, 22, 14, 18, 0, 14, 18, 16, 19,
- 19, 0, 12, 0, 0, 0, 0, 69, 23, 22
- } ;
-
-static yyconst short int yy_def[61] =
- { 0,
- 58, 1, 58, 58, 58, 58, 59, 60, 60, 60,
- 60, 60, 60, 60, 58, 58, 59, 60, 60, 60,
- 60, 60, 60, 60, 58, 60, 60, 60, 60, 60,
- 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
- 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
- 60, 60, 60, 60, 60, 60, 60, 0, 58, 58
- } ;
-
-static yyconst short int yy_nxt[93] =
- { 0,
- 4, 5, 6, 7, 4, 8, 8, 9, 8, 8,
- 8, 8, 8, 8, 10, 8, 11, 12, 13, 14,
- 8, 8, 15, 17, 18, 17, 57, 56, 55, 54,
- 53, 52, 51, 50, 49, 48, 47, 46, 45, 44,
- 43, 42, 41, 40, 39, 38, 37, 36, 35, 34,
- 33, 32, 31, 30, 29, 28, 27, 26, 16, 25,
- 24, 23, 22, 21, 20, 19, 16, 58, 3, 58,
- 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
- 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
- 58, 58
-
- } ;
-
-static yyconst short int yy_chk[93] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 59, 60, 59, 53, 51, 50, 49,
- 48, 47, 45, 44, 43, 42, 41, 40, 39, 38,
- 37, 36, 35, 34, 33, 32, 31, 30, 29, 28,
- 27, 26, 24, 23, 22, 21, 20, 19, 16, 15,
- 14, 13, 12, 11, 10, 9, 5, 3, 58, 58,
- 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
- 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
- 58, 58
-
- } ;
-
-static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;
-static char *yy_full_match;
-static int yy_lp;
-#define REJECT \
-{ \
-*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
-yy_cp = yy_full_match; /* restore poss. backed-over text */ \
-++yy_lp; \
-goto find_rule; \
-}
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *yytext;
-#line 1 "nslexer.l"
-#define INITIAL 0
-#line 2 "nslexer.l"
-/* $NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 <stdio.h>
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid =
- "$FreeBSD: src/lib/libc/net/nslexer.l,v 1.3 2001/11/11 02:48:09 bde Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <ctype.h>
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <string.h>
-
-#include "nsparser.h"
-
-#define YY_NO_UNPUT
-
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int yywrap YY_PROTO(( void ));
-#else
-extern int yywrap YY_PROTO(( void ));
-#endif
-#endif
-
-#ifndef YY_NO_UNPUT
-static void yyunput YY_PROTO(( int c, char *buf_ptr ));
-#endif
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen YY_PROTO(( yyconst char * ));
-#endif
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
-static int yyinput YY_PROTO(( void ));
-#else
-static int input YY_PROTO(( void ));
-#endif
-#endif
-
-#if YY_STACK_USED
-static int yy_start_stack_ptr = 0;
-static int yy_start_stack_depth = 0;
-static int *yy_start_stack = 0;
-#ifndef YY_NO_PUSH_STATE
-static void yy_push_state YY_PROTO(( int new_state ));
-#endif
-#ifndef YY_NO_POP_STATE
-static void yy_pop_state YY_PROTO(( void ));
-#endif
-#ifndef YY_NO_TOP_STATE
-static int yy_top_state YY_PROTO(( void ));
-#endif
-
-#else
-#define YY_NO_PUSH_STATE 1
-#define YY_NO_POP_STATE 1
-#define YY_NO_TOP_STATE 1
-#endif
-
-#ifdef YY_MALLOC_DECL
-YY_MALLOC_DECL
-#else
-#if __STDC__
-#ifndef __cplusplus
-#include <stdlib.h>
-#endif
-#else
-/* Just try to get by without declaring the routines. This will fail
- * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
- * or sizeof(void*) != sizeof(int).
- */
-#endif
-#endif
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-
-#ifndef ECHO
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
- if ( yy_current_buffer->yy_is_interactive ) \
- { \
- int c = '*', n; \
- for ( n = 0; n < max_size && \
- (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( yyin ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
- && ferror( yyin ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" );
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-#endif
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL int yylex YY_PROTO(( void ))
-#endif
-
-/* Code executed at the beginning of each rule, after yytext and yyleng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-YY_DECL
- {
- register yy_state_type yy_current_state;
- register char *yy_cp = NULL, *yy_bp = NULL;
- register int yy_act;
-
-#line 65 "nslexer.l"
-
-
-
- if ( yy_init )
- {
- yy_init = 0;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! yy_start )
- yy_start = 1; /* first start state */
-
- if ( ! yyin )
- yyin = stdin;
-
- if ( ! yyout )
- yyout = stdout;
-
- if ( ! yy_current_buffer )
- yy_current_buffer =
- yy_create_buffer( yyin, YY_BUF_SIZE );
-
- yy_load_buffer_state();
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
- yy_cp = yy_c_buf_p;
-
- /* Support of yytext. */
- *yy_cp = yy_hold_char;
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
- yy_current_state = yy_start;
- yy_state_ptr = yy_state_buf;
- *yy_state_ptr++ = yy_current_state;
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 59 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- *yy_state_ptr++ = yy_current_state;
- ++yy_cp;
- }
- while ( yy_base[yy_current_state] != 69 );
-
-yy_find_action:
- yy_current_state = *--yy_state_ptr;
- yy_lp = yy_accept[yy_current_state];
-find_rule: /* we branch to this label when backing up */
- for ( ; ; ) /* until we find what rule we matched */
- {
- if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )
- {
- yy_act = yy_acclist[yy_lp];
- {
- yy_full_match = yy_cp;
- break;
- }
- }
- --yy_cp;
- yy_current_state = *--yy_state_ptr;
- yy_lp = yy_accept[yy_current_state];
- }
-
- YY_DO_BEFORE_ACTION;
-
- if ( yy_act != YY_END_OF_BUFFER )
- {
- int yyl;
- for ( yyl = 0; yyl < yyleng; ++yyl )
- if ( yytext[yyl] == '\n' )
- ++yylineno;
- }
-
-do_action: /* This label is used only to access EOF actions. */
-
-
- switch ( yy_act )
- { /* beginning of action switch */
-case 1:
-YY_RULE_SETUP
-#line 67 "nslexer.l"
-; /* skip whitespace */
- YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 69 "nslexer.l"
-; /* skip comments */
- YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 71 "nslexer.l"
-; /* allow continuation */
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 73 "nslexer.l"
-return NL;
- YY_BREAK
-case 5:
-YY_RULE_SETUP
-#line 75 "nslexer.l"
-return SUCCESS;
- YY_BREAK
-case 6:
-YY_RULE_SETUP
-#line 76 "nslexer.l"
-return UNAVAIL;
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 77 "nslexer.l"
-return NOTFOUND;
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 78 "nslexer.l"
-return TRYAGAIN;
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 80 "nslexer.l"
-return RETURN;
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 81 "nslexer.l"
-return CONTINUE;
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 83 "nslexer.l"
-{
- char *p;
- int i;
- size_t len;
-
- len = strlen (yytext) + 1;
- if ((p = malloc (len)) == NULL)
- printf("nsdispatch: memory allocation failure\n");
- else
- memcpy (p, yytext, len);
-
- for (i = 0; i < strlen(p); i++) {
- if (isupper((unsigned char)p[i]))
- p[i] = tolower((unsigned char)p[i]);
- }
- _nsyylval.str = p;
- return STRING;
- }
- YY_BREAK
-case 12:
-YY_RULE_SETUP
-#line 99 "nslexer.l"
-return yytext[0];
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 101 "nslexer.l"
-ECHO;
- YY_BREAK
- case YY_STATE_EOF(INITIAL):
- yyterminate();
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = yy_hold_char;
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed yyin at a new source and called
- * yylex(). If so, then we have to assure
- * consistency between yy_current_buffer and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- yy_n_chars = yy_current_buffer->yy_n_chars;
- yy_current_buffer->yy_input_file = yyin;
- yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state();
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = yytext_ptr + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++yy_c_buf_p;
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
- yy_cp = yy_c_buf_p;
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer() )
- {
- case EOB_ACT_END_OF_FILE:
- {
- yy_did_buffer_switch_on_eof = 0;
-
- if ( yywrap() )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * yytext, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! yy_did_buffer_switch_on_eof )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- yy_c_buf_p =
- yytext_ptr + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state();
-
- yy_cp = yy_c_buf_p;
- yy_bp = yytext_ptr + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- yy_c_buf_p =
- &yy_current_buffer->yy_ch_buf[yy_n_chars];
-
- yy_current_state = yy_get_previous_state();
-
- yy_cp = yy_c_buf_p;
- yy_bp = yytext_ptr + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
- } /* end of yylex */
-
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-
-static int yy_get_next_buffer()
- {
- register char *dest = yy_current_buffer->yy_ch_buf;
- register char *source = yytext_ptr;
- register int number_to_move, i;
- int ret_val;
-
- if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( yy_current_buffer->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- yy_current_buffer->yy_n_chars = yy_n_chars = 0;
-
- else
- {
- int num_to_read =
- yy_current_buffer->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-#ifdef YY_USES_REJECT
- YY_FATAL_ERROR(
-"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
-#else
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = yy_current_buffer;
-
- int yy_c_buf_p_offset =
- (int) (yy_c_buf_p - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- int new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- yy_flex_realloc( (void *) b->yy_ch_buf,
- b->yy_buf_size + 2 );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = yy_current_buffer->yy_buf_size -
- number_to_move - 1;
-#endif
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
- yy_n_chars, num_to_read );
-
- yy_current_buffer->yy_n_chars = yy_n_chars;
- }
-
- if ( yy_n_chars == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- yyrestart( yyin );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- yy_current_buffer->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- yy_n_chars += number_to_move;
- yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
- yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
-
- yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
-
- return ret_val;
- }
-
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-static yy_state_type yy_get_previous_state()
- {
- register yy_state_type yy_current_state;
- register char *yy_cp;
-
- yy_current_state = yy_start;
- yy_state_ptr = yy_state_buf;
- *yy_state_ptr++ = yy_current_state;
-
- for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
- {
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 59 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- *yy_state_ptr++ = yy_current_state;
- }
-
- return yy_current_state;
- }
-
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-
-#ifdef YY_USE_PROTOS
-static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
-#else
-static yy_state_type yy_try_NUL_trans( yy_current_state )
-yy_state_type yy_current_state;
-#endif
- {
- register int yy_is_jam;
-
- register YY_CHAR yy_c = 1;
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 59 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 58);
- if ( ! yy_is_jam )
- *yy_state_ptr++ = yy_current_state;
-
- return yy_is_jam ? 0 : yy_current_state;
- }
-
-
-#ifndef YY_NO_UNPUT
-#ifdef YY_USE_PROTOS
-static void yyunput( int c, register char *yy_bp )
-#else
-static void yyunput( c, yy_bp )
-int c;
-register char *yy_bp;
-#endif
- {
- register char *yy_cp = yy_c_buf_p;
-
- /* undo effects of setting up yytext */
- *yy_cp = yy_hold_char;
-
- if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
- { /* need to shift things up to make room */
- /* +2 for EOB chars. */
- register int number_to_move = yy_n_chars + 2;
- register char *dest = &yy_current_buffer->yy_ch_buf[
- yy_current_buffer->yy_buf_size + 2];
- register char *source =
- &yy_current_buffer->yy_ch_buf[number_to_move];
-
- while ( source > yy_current_buffer->yy_ch_buf )
- *--dest = *--source;
-
- yy_cp += (int) (dest - source);
- yy_bp += (int) (dest - source);
- yy_current_buffer->yy_n_chars =
- yy_n_chars = yy_current_buffer->yy_buf_size;
-
- if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
- YY_FATAL_ERROR( "flex scanner push-back overflow" );
- }
-
- *--yy_cp = (char) c;
-
- if ( c == '\n' )
- --yylineno;
-
- yytext_ptr = yy_bp;
- yy_hold_char = *yy_cp;
- yy_c_buf_p = yy_cp;
- }
-#endif /* ifndef YY_NO_UNPUT */
-
-
-#ifdef __cplusplus
-static int yyinput()
-#else
-static int input()
-#endif
- {
- int c;
-
- *yy_c_buf_p = yy_hold_char;
-
- if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
- /* This was really a NUL. */
- *yy_c_buf_p = '\0';
-
- else
- { /* need more input */
- int offset = yy_c_buf_p - yytext_ptr;
- ++yy_c_buf_p;
-
- switch ( yy_get_next_buffer() )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- yyrestart( yyin );
-
- /* fall through */
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( yywrap() )
- return EOF;
-
- if ( ! yy_did_buffer_switch_on_eof )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- yy_c_buf_p = yytext_ptr + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
- *yy_c_buf_p = '\0'; /* preserve yytext */
- yy_hold_char = *++yy_c_buf_p;
-
- if ( c == '\n' )
- ++yylineno;
-
- return c;
- }
-
-
-#ifdef YY_USE_PROTOS
-void yyrestart( FILE *input_file )
-#else
-void yyrestart( input_file )
-FILE *input_file;
-#endif
- {
- if ( ! yy_current_buffer )
- yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
-
- yy_init_buffer( yy_current_buffer, input_file );
- yy_load_buffer_state();
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
-#else
-void yy_switch_to_buffer( new_buffer )
-YY_BUFFER_STATE new_buffer;
-#endif
- {
- if ( yy_current_buffer == new_buffer )
- return;
-
- if ( yy_current_buffer )
- {
- /* Flush out information for old buffer. */
- *yy_c_buf_p = yy_hold_char;
- yy_current_buffer->yy_buf_pos = yy_c_buf_p;
- yy_current_buffer->yy_n_chars = yy_n_chars;
- }
-
- yy_current_buffer = new_buffer;
- yy_load_buffer_state();
-
- /* We don't actually know whether we did this switch during
- * EOF (yywrap()) processing, but the only time this flag
- * is looked at is after yywrap() is called, so it's safe
- * to go ahead and always set it.
- */
- yy_did_buffer_switch_on_eof = 1;
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_load_buffer_state( void )
-#else
-void yy_load_buffer_state()
-#endif
- {
- yy_n_chars = yy_current_buffer->yy_n_chars;
- yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
- yyin = yy_current_buffer->yy_input_file;
- yy_hold_char = *yy_c_buf_p;
- }
-
-
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
-#else
-YY_BUFFER_STATE yy_create_buffer( file, size )
-FILE *file;
-int size;
-#endif
- {
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- yy_init_buffer( b, file );
-
- return b;
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_delete_buffer( YY_BUFFER_STATE b )
-#else
-void yy_delete_buffer( b )
-YY_BUFFER_STATE b;
-#endif
- {
- if ( ! b )
- return;
-
- if ( b == yy_current_buffer )
- yy_current_buffer = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- yy_flex_free( (void *) b->yy_ch_buf );
-
- yy_flex_free( (void *) b );
- }
-
-
-
-#ifdef YY_USE_PROTOS
-void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
-#else
-void yy_init_buffer( b, file )
-YY_BUFFER_STATE b;
-FILE *file;
-#endif
-
-
- {
- yy_flush_buffer( b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
-#if YY_ALWAYS_INTERACTIVE
- b->yy_is_interactive = 1;
-#else
-#if YY_NEVER_INTERACTIVE
- b->yy_is_interactive = 0;
-#else
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-#endif
-#endif
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_flush_buffer( YY_BUFFER_STATE b )
-#else
-void yy_flush_buffer( b )
-YY_BUFFER_STATE b;
-#endif
-
- {
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == yy_current_buffer )
- yy_load_buffer_state();
- }
-
-
-#ifndef YY_NO_SCAN_BUFFER
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
-#else
-YY_BUFFER_STATE yy_scan_buffer( base, size )
-char *base;
-yy_size_t size;
-#endif
- {
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- yy_switch_to_buffer( b );
-
- return b;
- }
-#endif
-
-
-#ifndef YY_NO_SCAN_STRING
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
-#else
-YY_BUFFER_STATE yy_scan_string( yy_str )
-yyconst char *yy_str;
-#endif
- {
- int len;
- for ( len = 0; yy_str[len]; ++len )
- ;
-
- return yy_scan_bytes( yy_str, len );
- }
-#endif
-
-
-#ifndef YY_NO_SCAN_BYTES
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
-#else
-YY_BUFFER_STATE yy_scan_bytes( bytes, len )
-yyconst char *bytes;
-int len;
-#endif
- {
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = len + 2;
- buf = (char *) yy_flex_alloc( n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
-
- for ( i = 0; i < len; ++i )
- buf[i] = bytes[i];
-
- buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = yy_scan_buffer( buf, n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
- }
-#endif
-
-
-#ifndef YY_NO_PUSH_STATE
-#ifdef YY_USE_PROTOS
-static void yy_push_state( int new_state )
-#else
-static void yy_push_state( new_state )
-int new_state;
-#endif
- {
- if ( yy_start_stack_ptr >= yy_start_stack_depth )
- {
- yy_size_t new_size;
-
- yy_start_stack_depth += YY_START_STACK_INCR;
- new_size = yy_start_stack_depth * sizeof( int );
-
- if ( ! yy_start_stack )
- yy_start_stack = (int *) yy_flex_alloc( new_size );
-
- else
- yy_start_stack = (int *) yy_flex_realloc(
- (void *) yy_start_stack, new_size );
-
- if ( ! yy_start_stack )
- YY_FATAL_ERROR(
- "out of memory expanding start-condition stack" );
- }
-
- yy_start_stack[yy_start_stack_ptr++] = YY_START;
-
- BEGIN(new_state);
- }
-#endif
-
-
-#ifndef YY_NO_POP_STATE
-static void yy_pop_state()
- {
- if ( --yy_start_stack_ptr < 0 )
- YY_FATAL_ERROR( "start-condition stack underflow" );
-
- BEGIN(yy_start_stack[yy_start_stack_ptr]);
- }
-#endif
-
-
-#ifndef YY_NO_TOP_STATE
-static int yy_top_state()
- {
- return yy_start_stack[yy_start_stack_ptr - 1];
- }
-#endif
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-#ifdef YY_USE_PROTOS
-static void yy_fatal_error( yyconst char msg[] )
-#else
-static void yy_fatal_error( msg )
-char msg[];
-#endif
- {
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
- }
-
-
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- yytext[yyleng] = yy_hold_char; \
- yy_c_buf_p = yytext + n; \
- yy_hold_char = *yy_c_buf_p; \
- *yy_c_buf_p = '\0'; \
- yyleng = n; \
- } \
- while ( 0 )
-
-
-/* Internal utility routines. */
-
-#ifndef yytext_ptr
-#ifdef YY_USE_PROTOS
-static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
-#else
-static void yy_flex_strncpy( s1, s2, n )
-char *s1;
-yyconst char *s2;
-int n;
-#endif
- {
- register int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
- }
-#endif
-
-#ifdef YY_NEED_STRLEN
-#ifdef YY_USE_PROTOS
-static int yy_flex_strlen( yyconst char *s )
-#else
-static int yy_flex_strlen( s )
-yyconst char *s;
-#endif
- {
- register int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
- }
-#endif
-
-
-#ifdef YY_USE_PROTOS
-static void *yy_flex_alloc( yy_size_t size )
-#else
-static void *yy_flex_alloc( size )
-yy_size_t size;
-#endif
- {
- return (void *) malloc( size );
- }
-
-#ifdef YY_USE_PROTOS
-static void *yy_flex_realloc( void *ptr, yy_size_t size )
-#else
-static void *yy_flex_realloc( ptr, size )
-void *ptr;
-yy_size_t size;
-#endif
- {
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
- }
-
-#ifdef YY_USE_PROTOS
-static void yy_flex_free( void *ptr )
-#else
-static void yy_flex_free( ptr )
-void *ptr;
-#endif
- {
- free( ptr );
- }
-
-#if YY_MAIN
-int main()
- {
- yylex();
- return 0;
- }
-#endif
-#line 101 "nslexer.l"
-
-
-#undef _nsyywrap
-int
-_nsyywrap()
-{
- return 1;
-} /* _nsyywrap */
-
-void
-_nsyyerror(msg)
- const char *msg;
-{
-
- printf("Error in nslexer\n");
-} /* _nsyyerror */
diff --git a/newlib/libc/sys/linux/net/nslexer.l b/newlib/libc/sys/linux/net/nslexer.l
deleted file mode 100644
index 0b66b6c66..000000000
--- a/newlib/libc/sys/linux/net/nslexer.l
+++ /dev/null
@@ -1,114 +0,0 @@
-%{
-/* $NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 <stdio.h>
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid =
- "$FreeBSD: src/lib/libc/net/nslexer.l,v 1.3 2001/11/11 02:48:09 bde Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <ctype.h>
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <string.h>
-
-#include "nsparser.h"
-
-#define YY_NO_UNPUT
-
-%}
-
-%option yylineno
-
-BLANK [ \t]
-CR \n
-STRING [a-zA-Z][a-zA-Z0-9_]*
-
-%%
-
-{BLANK}+ ; /* skip whitespace */
-
-#.* ; /* skip comments */
-
-\\{CR} ; /* allow continuation */
-
-{CR} return NL;
-
-[sS][uU][cC][cC][eE][sS][sS] return SUCCESS;
-[uU][nN][aA][vV][aA][iI][lL] return UNAVAIL;
-[nN][oO][tT][fF][oO][uU][nN][dD] return NOTFOUND;
-[tT][rR][yY][aA][gG][aA][iI][nN] return TRYAGAIN;
-
-[rR][eE][tT][uU][rR][nN] return RETURN;
-[cC][oO][nN][tT][iI][nN][uU][eE] return CONTINUE;
-
-{STRING} {
- char *p;
- int i;
-
- if ((p = strdup(yytext)) == NULL)
- printf("nsdispatch: memory allocation failure\n");
-
- for (i = 0; i < strlen(p); i++) {
- if (isupper((unsigned char)p[i]))
- p[i] = tolower((unsigned char)p[i]);
- }
- _nsyylval.str = p;
- return STRING;
- }
-
-. return yytext[0];
-
-%%
-
-#undef _nsyywrap
-int
-_nsyywrap()
-{
- return 1;
-} /* _nsyywrap */
-
-void
-_nsyyerror(msg)
- const char *msg;
-{
-
- printf("Error in nslexer\n");
-} /* _nsyyerror */
diff --git a/newlib/libc/sys/linux/net/nsparser.c b/newlib/libc/sys/linux/net/nsparser.c
deleted file mode 100644
index b4701aed1..000000000
--- a/newlib/libc/sys/linux/net/nsparser.c
+++ /dev/null
@@ -1,541 +0,0 @@
-#ifndef lint
-static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
-#endif
-#define YYBYACC 1
-#define YYMAJOR 1
-#define YYMINOR 9
-#define yyclearin (yychar=(-1))
-#define yyerrok (yyerrflag=0)
-#define YYRECOVERING (yyerrflag!=0)
-#define yyparse _nsyyparse
-#define yylex _nsyylex
-#define yyerror _nsyyerror
-#define yychar _nsyychar
-#define yyval _nsyyval
-#define yylval _nsyylval
-#define yydebug _nsyydebug
-#define yynerrs _nsyynerrs
-#define yyerrflag _nsyyerrflag
-#define yyss _nsyyss
-#define yyssp _nsyyssp
-#define yyvs _nsyyvs
-#define yyvsp _nsyyvsp
-#define yylhs _nsyylhs
-#define yylen _nsyylen
-#define yydefred _nsyydefred
-#define yydgoto _nsyydgoto
-#define yysindex _nsyysindex
-#define yyrindex _nsyyrindex
-#define yygindex _nsyygindex
-#define yytable _nsyytable
-#define yycheck _nsyycheck
-#define yyname _nsyyname
-#define yyrule _nsyyrule
-#define YYPREFIX "_nsyy"
-#line 2 "nsparser.y"
-/* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid =
- "$FreeBSD: src/lib/libc/net/nsparser.y,v 1.3 2002/03/21 22:47:17 obrien Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <stdio.h>
-#include <string.h>
-
-
-static void _nsaddsrctomap(const char *);
-
-static ns_dbt curdbt;
-static ns_src cursrc;
-#line 59 "nsparser.y"
-typedef union {
- char *str;
- int mapval;
-} YYSTYPE;
-#line 97 "y.tab.c"
-#define NL 257
-#define SUCCESS 258
-#define UNAVAIL 259
-#define NOTFOUND 260
-#define TRYAGAIN 261
-#define RETURN 262
-#define CONTINUE 263
-#define STRING 264
-#define YYERRCODE 256
-short _nsyylhs[] = { -1,
- 0, 0, 3, 3, 4, 4, 4, 4, 5, 6,
- 6, 7, 9, 7, 8, 8, 10, 1, 1, 1,
- 1, 2, 2,
-};
-short _nsyylen[] = { 2,
- 0, 1, 1, 2, 1, 3, 4, 2, 1, 1,
- 2, 1, 0, 5, 1, 2, 3, 1, 1, 1,
- 1, 1, 1,
-};
-short _nsyydefred[] = { 0,
- 0, 5, 9, 0, 0, 3, 0, 8, 4, 0,
- 6, 0, 0, 10, 13, 7, 11, 0, 18, 19,
- 20, 21, 0, 0, 15, 0, 14, 16, 22, 23,
- 17,
-};
-short _nsyydgoto[] = { 4,
- 23, 31, 5, 6, 7, 13, 14, 24, 18, 25,
-};
-short _nsyysindex[] = { -255,
- -249, 0, 0, 0, -255, 0, -41, 0, 0, -254,
- 0, -73, -253, 0, 0, 0, 0, -245, 0, 0,
- 0, 0, -42, -93, 0, -256, 0, 0, 0, 0,
- 0,
-};
-short _nsyyrindex[] = { 20,
- 0, 0, 0, 0, 21, 0, 0, 0, 0, 0,
- 0, -252, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0,
-};
-short _nsyygindex[] = { 0,
- 0, 0, 0, 17, 0, 0, 10, 0, 0, 1,
-};
-#define YYTABLESIZE 168
-short _nsyytable[] = { 27,
- 1, 2, 11, 16, 12, 29, 30, 8, 3, 12,
- 12, 12, 19, 20, 21, 22, 10, 15, 26, 1,
- 2, 9, 17, 0, 28, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 19, 20, 21, 22,
-};
-short _nsyycheck[] = { 93,
- 256, 257, 257, 257, 257, 262, 263, 257, 264, 264,
- 264, 264, 258, 259, 260, 261, 58, 91, 61, 0,
- 0, 5, 13, -1, 24, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 258, 259, 260, 261,
-};
-#define YYFINAL 4
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#endif
-#define YYMAXTOKEN 264
-#if YYDEBUG
-char *_nsyyname[] = {
-"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,"'='",0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'",0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NL","SUCCESS",
-"UNAVAIL","NOTFOUND","TRYAGAIN","RETURN","CONTINUE","STRING",
-};
-char *_nsyyrule[] = {
-"$accept : File",
-"File :",
-"File : Lines",
-"Lines : Entry",
-"Lines : Lines Entry",
-"Entry : NL",
-"Entry : Database ':' NL",
-"Entry : Database ':' Srclist NL",
-"Entry : error NL",
-"Database : STRING",
-"Srclist : Item",
-"Srclist : Srclist Item",
-"Item : STRING",
-"$$1 :",
-"Item : STRING '[' $$1 Criteria ']'",
-"Criteria : Criterion",
-"Criteria : Criteria Criterion",
-"Criterion : Status '=' Action",
-"Status : SUCCESS",
-"Status : UNAVAIL",
-"Status : NOTFOUND",
-"Status : TRYAGAIN",
-"Action : RETURN",
-"Action : CONTINUE",
-};
-#endif
-#ifdef YYSTACKSIZE
-#undef YYMAXDEPTH
-#define YYMAXDEPTH YYSTACKSIZE
-#else
-#ifdef YYMAXDEPTH
-#define YYSTACKSIZE YYMAXDEPTH
-#else
-#define YYSTACKSIZE 500
-#define YYMAXDEPTH 500
-#endif
-#endif
-int yydebug;
-int yynerrs;
-int yyerrflag;
-int yychar;
-short *yyssp;
-YYSTYPE *yyvsp;
-YYSTYPE yyval;
-YYSTYPE yylval;
-short yyss[YYSTACKSIZE];
-YYSTYPE yyvs[YYSTACKSIZE];
-#define yystacksize YYSTACKSIZE
-#line 150 "nsparser.y"
-
-static void
-_nsaddsrctomap(elem)
- const char *elem;
-{
- int i, lineno;
- extern int _nsyylineno;
- extern char * _nsyytext;
-
- lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0);
- if (curdbt.srclistsize > 0) {
- if ((strcasecmp(elem, NSSRC_COMPAT) == 0) ||
- (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) {
- /* XXX: syslog the following */
- printf("line %d 'compat' used with other sources",
- lineno);
- return;
- }
- }
- for (i = 0; i < curdbt.srclistsize; i++) {
- if (strcasecmp(curdbt.srclist[i].name, elem) == 0) {
- /* XXX: syslog the following */
- printf("%s line %d: duplicate source '%s'",
- lineno, elem);
- return;
- }
- }
- cursrc.name = elem;
- _nsdbtaddsrc(&curdbt, &cursrc);
-}
-#line 276 "y.tab.c"
-#define YYABORT goto yyabort
-#define YYREJECT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-int
-yyparse()
-{
- register int yym, yyn, yystate;
-#if YYDEBUG
- register char *yys;
- extern char *getenv();
-
- if (yys = getenv("YYDEBUG"))
- {
- yyn = *yys;
- if (yyn >= '0' && yyn <= '9')
- yydebug = yyn - '0';
- }
-#endif
-
- yynerrs = 0;
- yyerrflag = 0;
- yychar = (-1);
-
- yyssp = yyss;
- yyvsp = yyvs;
- *yyssp = yystate = 0;
-
-yyloop:
- if (yyn = yydefred[yystate]) goto yyreduce;
- if (yychar < 0)
- {
- if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("%sdebug: state %d, reading %d (%s)\n",
- YYPREFIX, yystate, yychar, yys);
- }
-#endif
- }
- if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
- {
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: state %d, shifting to state %d\n",
- YYPREFIX, yystate, yytable[yyn]);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate = yytable[yyn];
- *++yyvsp = yylval;
- yychar = (-1);
- if (yyerrflag > 0) --yyerrflag;
- goto yyloop;
- }
- if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
- {
- yyn = yytable[yyn];
- goto yyreduce;
- }
- if (yyerrflag) goto yyinrecovery;
-#ifdef lint
- goto yynewerror;
-#endif
-yynewerror:
- yyerror("syntax error");
-#ifdef lint
- goto yyerrlab;
-#endif
-yyerrlab:
- ++yynerrs;
-yyinrecovery:
- if (yyerrflag < 3)
- {
- yyerrflag = 3;
- for (;;)
- {
- if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
- {
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: state %d, error recovery shifting\
- to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate = yytable[yyn];
- *++yyvsp = yylval;
- goto yyloop;
- }
- else
- {
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: error recovery discarding state %d\n",
- YYPREFIX, *yyssp);
-#endif
- if (yyssp <= yyss) goto yyabort;
- --yyssp;
- --yyvsp;
- }
- }
- }
- else
- {
- if (yychar == 0) goto yyabort;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
- YYPREFIX, yystate, yychar, yys);
- }
-#endif
- yychar = (-1);
- goto yyloop;
- }
-yyreduce:
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: state %d, reducing by rule %d (%s)\n",
- YYPREFIX, yystate, yyn, yyrule[yyn]);
-#endif
- yym = yylen[yyn];
- yyval = yyvsp[1-yym];
- switch (yyn)
- {
-case 7:
-#line 87 "nsparser.y"
-{
- _nsdbtput(&curdbt);
- }
-break;
-case 8:
-#line 91 "nsparser.y"
-{
- yyerrok;
- }
-break;
-case 9:
-#line 98 "nsparser.y"
-{
- curdbt.name = yylval.str;
- curdbt.srclist = NULL;
- curdbt.srclistsize = 0;
- }
-break;
-case 12:
-#line 112 "nsparser.y"
-{
- cursrc.flags = NS_SUCCESS;
- _nsaddsrctomap(yyvsp[0].str);
- }
-break;
-case 13:
-#line 116 "nsparser.y"
-{ cursrc.flags = NS_SUCCESS; }
-break;
-case 14:
-#line 117 "nsparser.y"
-{
- _nsaddsrctomap(yyvsp[-4].str);
- }
-break;
-case 17:
-#line 129 "nsparser.y"
-{
- if (yyvsp[0].mapval) /* if action == RETURN set RETURN bit */
- cursrc.flags |= yyvsp[-2].mapval;
- else /* else unset it */
- cursrc.flags &= ~yyvsp[-2].mapval;
- }
-break;
-case 18:
-#line 138 "nsparser.y"
-{ yyval.mapval = NS_SUCCESS; }
-break;
-case 19:
-#line 139 "nsparser.y"
-{ yyval.mapval = NS_UNAVAIL; }
-break;
-case 20:
-#line 140 "nsparser.y"
-{ yyval.mapval = NS_NOTFOUND; }
-break;
-case 21:
-#line 141 "nsparser.y"
-{ yyval.mapval = NS_TRYAGAIN; }
-break;
-case 22:
-#line 145 "nsparser.y"
-{ yyval.mapval = 1L; }
-break;
-case 23:
-#line 146 "nsparser.y"
-{ yyval.mapval = 0L; }
-break;
-#line 487 "y.tab.c"
- }
- yyssp -= yym;
- yystate = *yyssp;
- yyvsp -= yym;
- yym = yylhs[yyn];
- if (yystate == 0 && yym == 0)
- {
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: after reduction, shifting from state 0 to\
- state %d\n", YYPREFIX, YYFINAL);
-#endif
- yystate = YYFINAL;
- *++yyssp = YYFINAL;
- *++yyvsp = yyval;
- if (yychar < 0)
- {
- if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("%sdebug: state %d, reading %d (%s)\n",
- YYPREFIX, YYFINAL, yychar, yys);
- }
-#endif
- }
- if (yychar == 0) goto yyaccept;
- goto yyloop;
- }
- if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
- yystate = yytable[yyn];
- else
- yystate = yydgoto[yym];
-#if YYDEBUG
- if (yydebug)
- printf("%sdebug: after reduction, shifting from state %d \
-to state %d\n", YYPREFIX, *yyssp, yystate);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate;
- *++yyvsp = yyval;
- goto yyloop;
-yyoverflow:
- yyerror("yacc stack overflow");
-yyabort:
- return (1);
-yyaccept:
- return (0);
-}
diff --git a/newlib/libc/sys/linux/net/nsparser.h b/newlib/libc/sys/linux/net/nsparser.h
deleted file mode 100644
index 6a6fae0be..000000000
--- a/newlib/libc/sys/linux/net/nsparser.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#define NL 257
-#define SUCCESS 258
-#define UNAVAIL 259
-#define NOTFOUND 260
-#define TRYAGAIN 261
-#define RETURN 262
-#define CONTINUE 263
-#define STRING 264
-typedef union {
- char *str;
- int mapval;
-} YYSTYPE;
-extern YYSTYPE _nsyylval;
diff --git a/newlib/libc/sys/linux/net/nsparser.y b/newlib/libc/sys/linux/net/nsparser.y
deleted file mode 100644
index 42f63a8a5..000000000
--- a/newlib/libc/sys/linux/net/nsparser.y
+++ /dev/null
@@ -1,178 +0,0 @@
-%{
-/* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */
-
-/*-
- * Copyright (c) 1997, 1998, 1999 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 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 FOUNDATION 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 <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid =
- "$FreeBSD: src/lib/libc/net/nsparser.y,v 1.3 2002/03/21 22:47:17 obrien Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <stdio.h>
-#include <string.h>
-
-
-static void _nsaddsrctomap(const char *);
-
-static ns_dbt curdbt;
-static ns_src cursrc;
-%}
-
-%union {
- char *str;
- int mapval;
-}
-
-%token NL
-%token SUCCESS UNAVAIL NOTFOUND TRYAGAIN
-%token RETURN CONTINUE
-%token <str> STRING
-
-%type <mapval> Status Action
-
-%%
-
-File
- : /* empty */
- | Lines
- ;
-
-Lines
- : Entry
- | Lines Entry
- ;
-
-Entry
- : NL
- | Database ':' NL
- | Database ':' Srclist NL
- {
- _nsdbtput(&curdbt);
- }
- | error NL
- {
- yyerrok;
- }
- ;
-
-Database
- : STRING
- {
- curdbt.name = yylval.str;
- curdbt.srclist = NULL;
- curdbt.srclistsize = 0;
- }
- ;
-
-Srclist
- : Item
- | Srclist Item
- ;
-
-Item
- : STRING
- {
- cursrc.flags = NS_SUCCESS;
- _nsaddsrctomap($1);
- }
- | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']'
- {
- _nsaddsrctomap($1);
- }
- ;
-
-Criteria
- : Criterion
- | Criteria Criterion
- ;
-
-Criterion
- : Status '=' Action
- {
- if ($3) /* if action == RETURN set RETURN bit */
- cursrc.flags |= $1;
- else /* else unset it */
- cursrc.flags &= ~$1;
- }
- ;
-
-Status
- : SUCCESS { $$ = NS_SUCCESS; }
- | UNAVAIL { $$ = NS_UNAVAIL; }
- | NOTFOUND { $$ = NS_NOTFOUND; }
- | TRYAGAIN { $$ = NS_TRYAGAIN; }
- ;
-
-Action
- : RETURN { $$ = 1L; }
- | CONTINUE { $$ = 0L; }
- ;
-
-%%
-
-static void
-_nsaddsrctomap(elem)
- const char *elem;
-{
- int i, lineno;
- extern int _nsyylineno;
- extern char * _nsyytext;
-
- lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0);
- if (curdbt.srclistsize > 0) {
- if ((strcasecmp(elem, NSSRC_COMPAT) == 0) ||
- (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) {
- /* XXX: syslog the following */
- printf("line %d 'compat' used with other sources",
- lineno);
- return;
- }
- }
- for (i = 0; i < curdbt.srclistsize; i++) {
- if (strcasecmp(curdbt.srclist[i].name, elem) == 0) {
- /* XXX: syslog the following */
- printf("%s line %d: duplicate source '%s'",
- lineno, elem);
- return;
- }
- }
- cursrc.name = elem;
- _nsdbtaddsrc(&curdbt, &cursrc);
-}
diff --git a/newlib/libc/sys/linux/net/nss.h b/newlib/libc/sys/linux/net/nss.h
new file mode 100644
index 000000000..f5c12afab
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nss.h
@@ -0,0 +1,52 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Define interface to NSS. This is meant for the interface functions
+ and for implementors of new services. */
+
+#ifndef _NSS_H
+#define _NSS_H 1
+
+#include <features.h>
+
+
+__BEGIN_DECLS
+
+/* Possible results of lookup using a nss_* function. */
+enum nss_status
+{
+ NSS_STATUS_TRYAGAIN = -2,
+ NSS_STATUS_UNAVAIL,
+ NSS_STATUS_NOTFOUND,
+ NSS_STATUS_SUCCESS,
+ NSS_STATUS_RETURN
+};
+
+
+/* Overwrite service selection for database DBNAME using specification
+ in STRING.
+ This function should only be used by system programs which have to
+ work around non-existing services (e.e., while booting).
+ Attention: Using this function repeatedly will slowly eat up the
+ whole memory since previous selection data cannot be freed. */
+extern int __nss_configure_lookup (__const char *__dbname,
+ __const char *__string) __THROW;
+
+__END_DECLS
+
+#endif /* nss.h */
diff --git a/newlib/libc/sys/linux/net/nsswitch.c b/newlib/libc/sys/linux/net/nsswitch.c
new file mode 100644
index 000000000..6c5d1f8e9
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nsswitch.c
@@ -0,0 +1,772 @@
+/* Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <netdb.h>
+#include <bits/libc-lock.h>
+#include <search.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <aliases.h>
+#include <grp.h>
+#include <netinet/ether.h>
+#include <pwd.h>
+#include <shadow.h>
+
+#include "local.h"
+
+#if !defined DO_STATIC_NSS || defined SHARED
+# include <gnu/lib-names.h>
+#endif
+
+#include "nsswitch.h"
+#include "nscd/nscd_proto.h"
+
+/* Prototypes for the local functions. */
+static name_database *nss_parse_file (const char *fname) internal_function;
+static name_database_entry *nss_getline (char *line) internal_function;
+static service_user *nss_parse_service_list (const char *line)
+ internal_function;
+static service_library *nss_new_service (name_database *database,
+ const char *name) internal_function;
+
+
+/* Declare external database variables. */
+#define DEFINE_DATABASE(name) \
+ extern service_user *__nss_##name##_database attribute_hidden; \
+ weak_extern (__nss_##name##_database)
+#include "databases.def"
+#undef DEFINE_DATABASE
+
+/* Structure to map database name to variable. */
+static struct
+{
+ const char *name;
+ service_user **dbp;
+} databases[] =
+{
+#define DEFINE_DATABASE(name) \
+ { #name, &__nss_##name##_database },
+#include "databases.def"
+#undef DEFINE_DATABASE
+};
+
+
+__libc_lock_define_initialized (static, lock)
+
+#if !defined DO_STATIC_NSS || defined SHARED
+/* String with revision number of the shared object files. */
+static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
+#endif
+
+/* The root of the whole data base. */
+static name_database *service_table;
+
+
+/* -1 == database not found
+ 0 == database entry pointer stored */
+int
+__nss_database_lookup (const char *database, const char *alternate_name,
+ const char *defconfig, service_user **ni)
+{
+ /* Prevent multiple threads to change the service table. */
+ __libc_lock_lock (lock);
+
+ /* Reconsider database variable in case some other thread called
+ `__nss_configure_lookup' while we waited for the lock. */
+ if (*ni != NULL)
+ {
+ __libc_lock_unlock (lock);
+ return 0;
+ }
+
+ /* Are we initialized yet? */
+ if (service_table == NULL)
+ /* Read config file. */
+ service_table = nss_parse_file (_PATH_NSSWITCH_CONF);
+
+ /* Test whether configuration data is available. */
+ if (service_table != NULL)
+ {
+ /* Return first `service_user' entry for DATABASE. */
+ name_database_entry *entry;
+
+ /* XXX Could use some faster mechanism here. But each database is
+ only requested once and so this might not be critical. */
+ for (entry = service_table->entry; entry != NULL; entry = entry->next)
+ if (strcmp (database, entry->name) == 0)
+ *ni = entry->service;
+
+ if (*ni == NULL && alternate_name != NULL)
+ /* We haven't found an entry so far. Try to find it with the
+ alternative name. */
+ for (entry = service_table->entry; entry != NULL; entry = entry->next)
+ if (strcmp (alternate_name, entry->name) == 0)
+ *ni = entry->service;
+ }
+
+ /* No configuration data is available, either because nsswitch.conf
+ doesn't exist or because it doesn't has a line for this database.
+
+ DEFCONFIG specifies the default service list for this database,
+ or null to use the most common default. */
+ if (*ni == NULL)
+ *ni = nss_parse_service_list (defconfig
+ ?: "nis [NOTFOUND=return] files");
+
+ __libc_lock_unlock (lock);
+
+ return 0;
+}
+libc_hidden_def (__nss_database_lookup)
+
+
+/* -1 == not found
+ 0 == function found
+ 1 == finished */
+int
+__nss_lookup (service_user **ni, const char *fct_name, void **fctp)
+{
+ *fctp = __nss_lookup_function (*ni, fct_name);
+
+ while (*fctp == NULL
+ && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
+ && (*ni)->next != NULL)
+ {
+ *ni = (*ni)->next;
+
+ *fctp = __nss_lookup_function (*ni, fct_name);
+ }
+
+ return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1;
+}
+
+
+/* -1 == not found
+ 0 == adjusted for next function
+ 1 == finished */
+int
+__nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
+ int all_values)
+{
+ if (all_values)
+ {
+ if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN
+ && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN
+ && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN
+ && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN)
+ return 1;
+ }
+ else
+ {
+ /* This is really only for debugging. */
+ if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN)
+ {
+ fprintf (stderr, "illegal status in __nss_next");
+ abort();
+ }
+
+ if (nss_next_action (*ni, status) == NSS_ACTION_RETURN)
+ return 1;
+ }
+
+ if ((*ni)->next == NULL)
+ return -1;
+
+ do
+ {
+ *ni = (*ni)->next;
+
+ *fctp = __nss_lookup_function (*ni, fct_name);
+ }
+ while (*fctp == NULL
+ && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
+ && (*ni)->next != NULL);
+
+ return *fctp != NULL ? 0 : -1;
+}
+libc_hidden_def (__nss_next)
+
+
+int
+__nss_configure_lookup (const char *dbname, const char *service_line)
+{
+ service_user *new_db;
+ size_t cnt;
+
+ for (cnt = 0; cnt < sizeof databases; ++cnt)
+ {
+ int cmp = strcmp (dbname, databases[cnt].name);
+ if (cmp == 0)
+ break;
+ if (cmp < 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+
+ if (cnt == sizeof databases)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Test whether it is really used. */
+ if (databases[cnt].dbp == NULL)
+ /* Nothing to do, but we could do. */
+ return 0;
+
+ /* Try to generate new data. */
+ new_db = nss_parse_service_list (service_line);
+ if (new_db == NULL)
+ {
+ /* Illegal service specification. */
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Prevent multiple threads to change the service table. */
+ __libc_lock_lock (lock);
+
+ /* Install new rules. */
+ *databases[cnt].dbp = new_db;
+
+ __libc_lock_unlock (lock);
+
+ return 0;
+}
+
+
+/* Comparison function for searching NI->known tree. */
+static int
+known_compare (const void *p1, const void *p2)
+{
+ return p1 == p2 ? 0 : strcmp (*(const char *const *) p1,
+ *(const char *const *) p2);
+}
+
+
+void *
+__nss_lookup_function (service_user *ni, const char *fct_name)
+{
+ void **found, *result;
+
+ /* We now modify global data. Protect it. */
+ __libc_lock_lock (lock);
+
+ /* Search the tree of functions previously requested. Data in the
+ tree are `known_function' structures, whose first member is a
+ `const char *', the lookup key. The search returns a pointer to
+ the tree node structure; the first member of the is a pointer to
+ our structure (i.e. what will be a `known_function'); since the
+ first member of that is the lookup key string, &FCT_NAME is close
+ enough to a pointer to our structure to use as a lookup key that
+ will be passed to `known_compare' (above). */
+
+ found = tsearch (&fct_name, (void **) &ni->known, &known_compare);
+ if (*found != &fct_name)
+ /* The search found an existing structure in the tree. */
+ result = ((known_function *) *found)->fct_ptr;
+ else
+ {
+ /* This name was not known before. Now we have a node in the tree
+ (in the proper sorted position for FCT_NAME) that points to
+ &FCT_NAME instead of any real `known_function' structure.
+ Allocate a new structure and fill it in. */
+
+ known_function *known = malloc (sizeof *known);
+ if (! known)
+ {
+ remove_from_tree:
+ /* Oops. We can't instantiate this node properly.
+ Remove it from the tree. */
+ tdelete (&fct_name, (void **) &ni->known, &known_compare);
+ result = NULL;
+ }
+ else
+ {
+ /* Point the tree node at this new structure. */
+ *found = known;
+ known->fct_name = fct_name;
+
+ if (ni->library == NULL)
+ {
+ /* This service has not yet been used. Fetch the service
+ library for it, creating a new one if need be. If there
+ is no service table from the file, this static variable
+ holds the head of the service_library list made from the
+ default configuration. */
+ static name_database default_table;
+ ni->library = nss_new_service (service_table ?: &default_table,
+ ni->name);
+ if (ni->library == NULL)
+ {
+ /* This only happens when out of memory. */
+ free (known);
+ goto remove_from_tree;
+ }
+ }
+
+#if !defined DO_STATIC_NSS || defined SHARED
+ if (ni->library->lib_handle == NULL)
+ {
+ /* Load the shared library. */
+ size_t shlen = (7 + strlen (ni->library->name) + 3
+ + strlen (__nss_shlib_revision) + 1);
+ int saved_errno = errno;
+ char shlib_name[shlen];
+
+ /* Construct shared object name. */
+ stpcpy (stpcpy (stpcpy (stpcpy (shlib_name,
+ "libnss_"),
+ ni->library->name),
+ ".so"),
+ __nss_shlib_revision);
+
+ ni->library->lib_handle = __libc_dlopen (shlib_name);
+ if (ni->library->lib_handle == NULL)
+ {
+ /* Failed to load the library. */
+ ni->library->lib_handle = (void *) -1l;
+ __set_errno (saved_errno);
+ }
+ }
+
+ if (ni->library->lib_handle == (void *) -1l)
+ /* Library not found => function not found. */
+ result = NULL;
+ else
+ {
+ /* Get the desired function. */
+ size_t namlen = (5 + strlen (ni->library->name) + 1
+ + strlen (fct_name) + 1);
+ char name[namlen];
+
+ /* Construct the function name. */
+ stpcpy (stpcpy (stpcpy (stpcpy (name, "_nss_"),
+ ni->library->name),
+ "_"),
+ fct_name);
+
+ /* Look up the symbol. */
+ result = __libc_dlsym (ni->library->lib_handle, name);
+ }
+#else
+ /* We can't get function address dynamically in static linking. */
+ {
+# define DEFINE_ENT(h,nm) \
+ { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
+ { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
+ { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
+# define DEFINE_GET(h,nm) \
+ { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
+# define DEFINE_GETBY(h,nm,ky) \
+ { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
+ static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
+ {
+# include "function.def"
+ { NULL, NULL }
+ };
+ size_t namlen = (5 + strlen (ni->library->name) + 1
+ + strlen (fct_name) + 1);
+ char name[namlen];
+
+ /* Construct the function name. */
+ stpcpy (stpcpy (stpcpy (name, ni->library->name),
+ "_"),
+ fct_name);
+
+ result = NULL;
+ for (tp = &tbl[0]; tp->fname; tp++)
+ if (strcmp (tp->fname, name) == 0)
+ {
+ result = tp->fp;
+ break;
+ }
+ }
+#endif
+
+ /* Remember function pointer for later calls. Even if null, we
+ record it so a second try needn't search the library again. */
+ known->fct_ptr = result;
+ }
+ }
+
+ /* Remove the lock. */
+ __libc_lock_unlock (lock);
+
+ return result;
+}
+libc_hidden_def (__nss_lookup_function)
+
+
+static name_database *
+internal_function
+nss_parse_file (const char *fname)
+{
+ FILE *fp;
+ name_database *result;
+ name_database_entry *last;
+ char *line;
+ size_t len;
+
+ /* Open the configuration file. */
+ fp = fopen (fname, "rc");
+ if (fp == NULL)
+ return NULL;
+
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ result = (name_database *) malloc (sizeof (name_database));
+ if (result == NULL)
+ return NULL;
+
+ result->entry = NULL;
+ result->library = NULL;
+ last = NULL;
+ line = NULL;
+ len = 0;
+ do
+ {
+ name_database_entry *this;
+ ssize_t n;
+ char *tmp;
+
+ n = __getline (&line, &len, fp);
+ if (n < 0)
+ break;
+ if (line[n - 1] == '\n')
+ line[n - 1] = '\0';
+
+ /* Because the file format does not know any form of quoting we
+ can search forward for the next '#' character and if found
+ make it terminating the line. */
+ tmp = strchr (line, '#');
+ if (tmp == NULL)
+ tmp = line + strlen (line);
+ *tmp = '\0';
+
+ /* If the line is blank it is ignored. */
+ if (line[0] == '\0')
+ continue;
+
+ /* Each line completely specifies the actions for a database. */
+ this = nss_getline (line);
+ if (this != NULL)
+ {
+ if (last != NULL)
+ last->next = this;
+ else
+ result->entry = this;
+
+ last = this;
+ }
+ }
+ while (!feof (fp));
+
+ /* Free the buffer. */
+ free (line);
+ /* Close configuration file. */
+ fclose (fp);
+
+ return result;
+}
+
+
+/* Read the source names:
+ `( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
+ */
+static service_user *
+internal_function
+nss_parse_service_list (const char *line)
+{
+ service_user *result = NULL, **nextp = &result;
+
+ while (1)
+ {
+ service_user *new_service;
+ const char *name;
+
+ while (isspace (line[0]))
+ ++line;
+ if (line[0] == '\0')
+ /* No source specified. */
+ return result;
+
+ /* Read <source> identifier. */
+ name = line;
+ while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
+ ++line;
+ if (name == line)
+ return result;
+
+
+ new_service = (service_user *) malloc (sizeof (service_user)
+ + (line - name + 1));
+ if (new_service == NULL)
+ return result;
+
+ *((char *) mempcpy (new_service->name, name, line - name)) = '\0';
+
+ /* Set default actions. */
+ new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
+ new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
+ new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
+ new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
+ new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN;
+ new_service->library = NULL;
+ new_service->known = NULL;
+ new_service->next = NULL;
+
+ while (isspace (line[0]))
+ ++line;
+
+ if (line[0] == '[')
+ {
+ /* Read criterions. */
+ do
+ ++line;
+ while (line[0] != '\0' && isspace (line[0]));
+
+ do
+ {
+ int not;
+ enum nss_status status;
+ lookup_actions action;
+
+ /* Grok ! before name to mean all statii but that one. */
+ not = line[0] == '!';
+ if (not)
+ ++line;
+
+ /* Read status name. */
+ name = line;
+ while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
+ && line[0] != ']')
+ ++line;
+
+ /* Compare with known statii. */
+ if (line - name == 7)
+ {
+ if (strncasecmp (name, "SUCCESS", 7) == 0)
+ status = NSS_STATUS_SUCCESS;
+ else if (strncasecmp (name, "UNAVAIL", 7) == 0)
+ status = NSS_STATUS_UNAVAIL;
+ else
+ return result;
+ }
+ else if (line - name == 8)
+ {
+ if (strncasecmp (name, "NOTFOUND", 8) == 0)
+ status = NSS_STATUS_NOTFOUND;
+ else if (strncasecmp (name, "TRYAGAIN", 8) == 0)
+ status = NSS_STATUS_TRYAGAIN;
+ else
+ return result;
+ }
+ else
+ return result;
+
+ while (isspace (line[0]))
+ ++line;
+ if (line[0] != '=')
+ return result;
+ do
+ ++line;
+ while (isspace (line[0]));
+
+ name = line;
+ while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
+ && line[0] != ']')
+ ++line;
+
+ if (line - name == 6 && strncasecmp (name, "RETURN", 6) == 0)
+ action = NSS_ACTION_RETURN;
+ else if (line - name == 8
+ && strncasecmp (name, "CONTINUE", 8) == 0)
+ action = NSS_ACTION_CONTINUE;
+ else
+ return result;
+
+ if (not)
+ {
+ /* Save the current action setting for this status,
+ set them all to the given action, and reset this one. */
+ const lookup_actions save = new_service->actions[2 + status];
+ new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action;
+ new_service->actions[2 + NSS_STATUS_UNAVAIL] = action;
+ new_service->actions[2 + NSS_STATUS_NOTFOUND] = action;
+ new_service->actions[2 + NSS_STATUS_SUCCESS] = action;
+ new_service->actions[2 + status] = save;
+ }
+ else
+ new_service->actions[2 + status] = action;
+
+ /* Skip white spaces. */
+ while (isspace (line[0]))
+ ++line;
+ }
+ while (line[0] != ']');
+
+ /* Skip the ']'. */
+ ++line;
+ }
+
+ *nextp = new_service;
+ nextp = &new_service->next;
+ }
+}
+
+static name_database_entry *
+internal_function
+nss_getline (char *line)
+{
+ const char *name;
+ name_database_entry *result;
+ size_t len;
+
+ /* Ignore leading white spaces. ATTENTION: this is different from
+ what is implemented in Solaris. The Solaris man page says a line
+ beginning with a white space character is ignored. We regard
+ this as just another misfeature in Solaris. */
+ while (isspace (line[0]))
+ ++line;
+
+ /* Recognize `<database> ":"'. */
+ name = line;
+ while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
+ ++line;
+ if (line[0] == '\0' || name == line)
+ /* Syntax error. */
+ return NULL;
+ *line++ = '\0';
+
+ len = strlen (name) + 1;
+
+ result = (name_database_entry *) malloc (sizeof (name_database_entry) + len);
+ if (result == NULL)
+ return NULL;
+
+ /* Save the database name. */
+ memcpy (result->name, name, len);
+
+ /* Parse the list of services. */
+ result->service = nss_parse_service_list (line);
+
+ result->next = NULL;
+ return result;
+}
+
+
+static service_library *
+internal_function
+nss_new_service (name_database *database, const char *name)
+{
+ service_library **currentp = &database->library;
+
+ while (*currentp != NULL)
+ {
+ if (strcmp ((*currentp)->name, name) == 0)
+ return *currentp;
+ currentp = &(*currentp)->next;
+ }
+
+ /* We have to add the new service. */
+ *currentp = (service_library *) malloc (sizeof (service_library));
+ if (*currentp == NULL)
+ return NULL;
+
+ (*currentp)->name = name;
+ (*currentp)->lib_handle = NULL;
+ (*currentp)->next = NULL;
+
+ return *currentp;
+}
+
+
+#ifdef USE_NSCD
+/* Called by nscd and nscd alone. */
+void
+__nss_disable_nscd (void)
+{
+ /* Disable all uses of NSCD. */
+ __nss_not_use_nscd_passwd = -1;
+ __nss_not_use_nscd_group = -1;
+ __nss_not_use_nscd_hosts = -1;
+}
+#endif
+
+
+/* Free all resources if necessary. */
+libc_freeres_fn (free_mem)
+{
+ name_database *top = service_table;
+ name_database_entry *entry;
+ service_library *library;
+
+ if (top == NULL)
+ /* Maybe we have not read the nsswitch.conf file. */
+ return;
+
+ /* Don't disturb ongoing other threads (if there are any). */
+ service_table = NULL;
+
+ entry = top->entry;
+ while (entry != NULL)
+ {
+ name_database_entry *olde = entry;
+ service_user *service = entry->service;
+
+ while (service != NULL)
+ {
+ service_user *olds = service;
+
+ if (service->known != NULL)
+ tdestroy (service->known, free);
+
+ service = service->next;
+ free (olds);
+ }
+
+ entry = entry->next;
+ free (olde);
+ }
+
+ library = top->library;
+ while (library != NULL)
+ {
+ service_library *oldl = library;
+
+ if (library->lib_handle && library->lib_handle != (void *) -1l)
+ __libc_dlclose (library->lib_handle);
+
+ library = library->next;
+ free (oldl);
+ }
+
+ free (top);
+}
diff --git a/newlib/libc/sys/linux/net/nsswitch.h b/newlib/libc/sys/linux/net/nsswitch.h
new file mode 100644
index 000000000..7ee6d5e4b
--- /dev/null
+++ b/newlib/libc/sys/linux/net/nsswitch.h
@@ -0,0 +1,180 @@
+/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NSSWITCH_H
+#define _NSSWITCH_H 1
+
+/* This is an *internal* header. */
+
+#include <arpa/nameser.h>
+#include <netinet/in.h>
+#include <nss.h>
+#include <resolv.h>
+#include <search.h>
+#include <dlfcn.h>
+#include <libc-symbols.h>
+
+/* Actions performed after lookup finished. */
+typedef enum
+{
+ NSS_ACTION_CONTINUE,
+ NSS_ACTION_RETURN
+} lookup_actions;
+
+
+typedef struct service_library
+{
+ /* Name of service (`files', `dns', `nis', ...). */
+ const char *name;
+ /* Pointer to the loaded shared library. */
+ void *lib_handle;
+ /* And the link to the next entry. */
+ struct service_library *next;
+} service_library;
+
+
+/* For mapping a function name to a function pointer. It is known in
+ nsswitch.c:nss_lookup_function that a string pointer for the lookup key
+ is the first member. */
+typedef struct
+{
+ const char *fct_name;
+ void *fct_ptr;
+} known_function;
+
+
+typedef struct service_user
+{
+ /* And the link to the next entry. */
+ struct service_user *next;
+ /* Action according to result. */
+ lookup_actions actions[5];
+ /* Link to the underlying library object. */
+ service_library *library;
+ /* Collection of known functions. */
+ struct entry *known;
+ /* Name of the service (`files', `dns', `nis', ...). */
+ char name[0];
+} service_user;
+
+/* To access the action based on the status value use this macro. */
+#define nss_next_action(ni, status) ((ni)->actions[2 + status])
+
+
+typedef struct name_database_entry
+{
+ /* And the link to the next entry. */
+ struct name_database_entry *next;
+ /* List of service to be used. */
+ service_user *service;
+ /* Name of the database. */
+ char name[0];
+} name_database_entry;
+
+
+typedef struct name_database
+{
+ /* List of all known databases. */
+ name_database_entry *entry;
+ /* List of libraries with service implementation. */
+ service_library *library;
+} name_database;
+
+
+/* Interface functions for NSS. */
+
+/* Get the data structure representing the specified database.
+ If there is no configuration for this database in the file,
+ parse a service list from DEFCONFIG and use that. More
+ than one function can use the database. */
+extern int __nss_database_lookup (const char *database,
+ const char *alternative_name,
+ const char *defconfig, service_user **ni);
+libc_hidden_proto (__nss_database_lookup)
+
+/* Put first function with name FCT_NAME for SERVICE in FCTP. The
+ position is remembered in NI. The function returns a value < 0 if
+ an error occurred or no such function exists. */
+extern int __nss_lookup (service_user **ni, const char *fct_name, void **fctp);
+
+/* Determine the next step in the lookup process according to the
+ result STATUS of the call to the last function returned by
+ `__nss_lookup' or `__nss_next'. NI specifies the last function
+ examined. The function return a value > 0 if the process should
+ stop with the last result of the last function call to be the
+ result of the entire lookup. The returned value is 0 if there is
+ another function to use and < 0 if an error occurred.
+
+ If ALL_VALUES is nonzero, the return value will not be > 0 as long as
+ there is a possibility the lookup process can ever use following
+ services. In other words, only if all four lookup results have
+ the action RETURN associated the lookup process stops before the
+ natural end. */
+extern int __nss_next (service_user **ni, const char *fct_name, void **fctp,
+ int status, int all_values);
+libc_hidden_proto (__nss_next)
+
+/* Search for the service described in NI for a function named FCT_NAME
+ and return a pointer to this function if successful. */
+extern void *__nss_lookup_function (service_user *ni, const char *fct_name);
+libc_hidden_proto (__nss_lookup_function)
+
+
+/* Called by NSCD to disable recursive calls. */
+extern void __nss_disable_nscd (void);
+
+
+typedef int (*db_lookup_function) (service_user **, const char *, void **)
+ internal_function;
+typedef enum nss_status (*setent_function) (int);
+typedef enum nss_status (*endent_function) (void);
+typedef enum nss_status (*getent_function) (void *, char *, size_t,
+ int *, int *);
+typedef int (*getent_r_function) (void *, char *, size_t,
+ void **result, int *);
+
+extern void __nss_setent (const char *func_name,
+ db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int stayon,
+ int *stayon_tmp, int res);
+extern void __nss_endent (const char *func_name,
+ db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int res);
+extern int __nss_getent_r (const char *getent_func_name,
+ const char *setent_func_name,
+ db_lookup_function lookup_fct,
+ service_user **nip, service_user **startp,
+ service_user **last_nip, int *stayon_tmp,
+ int res,
+ void *resbuf, char *buffer, size_t buflen,
+ void **result, int *h_errnop);
+extern void *__nss_getent (getent_r_function func,
+ void **resbuf, char **buffer, size_t buflen,
+ size_t *buffer_size, int *h_errnop);
+struct hostent;
+extern int __nss_hostname_digits_dots (const char *name,
+ struct hostent *resbuf, char **buffer,
+ size_t *buffer_size, size_t buflen,
+ struct hostent **result,
+ enum nss_status *status, int af,
+ int *h_errnop);
+libc_hidden_proto (__nss_hostname_digits_dots)
+
+#endif /* nsswitch.h */
diff --git a/newlib/libc/sys/linux/net/opensock.c b/newlib/libc/sys/linux/net/opensock.c
new file mode 100644
index 000000000..7ff3f69ed
--- /dev/null
+++ b/newlib/libc/sys/linux/net/opensock.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include "libc-symbols.h"
+
+/* Return a socket of any type. The socket can be used in subsequent
+ ioctl calls to talk to the kernel. */
+int internal_function
+__opensock (void)
+{
+ static int last_family; /* Available socket family we will use. */
+ static int last_type;
+ static const struct
+ {
+ int family;
+ const char procname[15];
+ } afs[] =
+ {
+ /* The 2.2 kernels cannot handle ioctl(SIOCGIFCONF) on AF_UNIX sockets.
+ Give the kernel a chance to user inet sockets on old kernels. */
+#if __LINUX_KERNEL_VERSION < 132096
+ { AF_INET, "" },
+ { AF_UNIX, "net/unix" },
+#else
+ { AF_UNIX, "net/unix" },
+ { AF_INET, "" },
+#endif
+ { AF_INET6, "net/if_inet6" },
+ { AF_AX25, "net/ax25" },
+ { AF_NETROM, "net/nr" },
+ { AF_ROSE, "net/rose" },
+ { AF_IPX, "net/ipx" },
+ { AF_APPLETALK, "net/appletalk" },
+ { AF_ECONET, "sys/net/econet" },
+ { AF_ASH, "sys/net/ash" },
+ { AF_X25, "net/x25" }
+ };
+#define nafs (sizeof (afs) / sizeof (afs[0]))
+ char fname[sizeof "/proc/" + 14];
+ int result;
+ int has_proc;
+ size_t cnt;
+
+ /* We already know which family to use from the last call. Use it
+ again. */
+ if (last_family != 0)
+ {
+ assert (last_type != 0);
+
+ result = socket (last_family, last_type, 0);
+ if (result != -1 || errno != EAFNOSUPPORT)
+ /* Maybe the socket type isn't supported anymore (module is
+ unloaded). In this case again try to find the type. */
+ return result;
+
+ /* Reset the values. They seem not valid anymore. */
+ last_family = 0;
+ last_type = 0;
+ }
+
+ /* Check whether the /proc filesystem is available. */
+ has_proc = access ("/proc/net", R_OK) != -1;
+ strcpy (fname, "/proc/");
+
+ /* Iterate over the interface families and find one which is
+ available. */
+ for (cnt = 0; cnt < nafs; ++cnt)
+ {
+ int type = SOCK_DGRAM;
+
+ if (has_proc && afs[cnt].procname[0] != '\0')
+ {
+ strcpy (fname + 6, afs[cnt].procname);
+ if (access (fname, R_OK) == -1)
+ /* The /proc entry is not available. I.e., we cannot
+ create a socket of this type (without loading the
+ module). Don't look for it since this might trigger
+ loading the module. */
+ continue;
+ }
+
+ if (afs[cnt].family == AF_NETROM || afs[cnt].family == AF_X25)
+ type = SOCK_SEQPACKET;
+
+ result = socket (afs[cnt].family, type, 0);
+ if (result != -1)
+ {
+ /* Found an available family. */
+ last_type = type;
+ last_family = afs[cnt].family;
+ return result;
+ }
+ }
+
+ /* None of the protocol families is available. It is unclear what kind
+ of error is returned. ENOENT seems like a reasonable choice. */
+ __set_errno (ENOENT);
+ return -1;
+}
diff --git a/newlib/libc/sys/linux/net/proto-lookup.c b/newlib/libc/sys/linux/net/proto-lookup.c
new file mode 100644
index 000000000..8f98158b3
--- /dev/null
+++ b/newlib/libc/sys/linux/net/proto-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME protocols
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/pwd-lookup.c b/newlib/libc/sys/linux/net/pwd-lookup.c
new file mode 100644
index 000000000..1def3a08c
--- /dev/null
+++ b/newlib/libc/sys/linux/net/pwd-lookup.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME passwd
+#define DEFAULT_CONFIG "compat [NOTFOUND=return] files"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/rcmd.3 b/newlib/libc/sys/linux/net/rcmd.3
deleted file mode 100644
index 9479a237d..000000000
--- a/newlib/libc/sys/linux/net/rcmd.3
+++ /dev/null
@@ -1,298 +0,0 @@
-.\" 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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
-.\" $FreeBSD: src/lib/libc/net/rcmd.3,v 1.20 2001/10/01 16:08:56 ru Exp $
-.\"
-.Dd March 3, 2000
-.Dt RCMD 3
-.Os
-.Sh NAME
-.Nm rcmd ,
-.Nm rresvport ,
-.Nm iruserok ,
-.Nm ruserok ,
-.Nm rcmd_af ,
-.Nm rresvport_af ,
-.Nm iruserok_sa
-.Nd routines for returning a stream to a remote command
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft int
-.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
-.Ft int
-.Fn rresvport "int *port"
-.Ft int
-.Fn iruserok "u_long 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 rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
-.Ft int
-.Fn rresvport_af "int *port" "int af"
-.Ft int
-.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser"
-.Sh DESCRIPTION
-The
-.Fn rcmd
-function
-is used by the super-user to execute a command on
-a remote machine using an authentication scheme based
-on reserved port numbers.
-The
-.Fn rresvport
-function
-returns a descriptor to a socket
-with an address in the privileged port space.
-The
-.Fn ruserok
-function
-is used by servers
-to authenticate clients requesting service with
-.Fn rcmd .
-All three functions are present in the same file and are used
-by the
-.Xr rshd 8
-server (among others).
-.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 .
-.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
-.Em stdin
-and
-.Em 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 0, then the
-.Em stderr
-(unit 2 of the remote
-command) will be made the same as the
-.Em stdout
-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.
-.Pp
-The protocol is described in detail in
-.Xr rshd 8 .
-.Pp
-The
-.Fn rresvport
-function is used to obtain a socket to which an address with a Privileged
-Internet port is bound.
-This socket is suitable for use by
-.Fn rcmd
-and several other functions.
-Privileged Internet ports are those in the range 0 to 1023.
-Only the super-user is allowed to bind an address of this sort
-to a socket.
-.Pp
-The
-.Fn iruserok
-and
-.Fn ruserok
-functions take a remote host's IP address or name, as returned by the
-.Xr gethostbyname 3
-routines, two user names and a flag indicating whether the local user's
-name is that of the super-user.
-Then, if the user is
-.Em NOT
-the super-user, 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 super-user, or is writable by anyone other
-than the owner, the check automatically fails.
-Zero is returned if the machine name is listed in the
-.Dq Pa hosts.equiv
-file, or the host and remote user name are found in the
-.Dq 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
-The
-.Fn iruserok
-function is strongly preferred for security reasons.
-It requires trusting the local DNS at most, while the
-.Fn ruserok
-function requires trusting the entire DNS, which can be spoofed.
-.Pp
-The functions with an
-.Dq Li _af
-or
-.Dq Li _sa
-suffix, i.e.,
-.Fn rcmd_af ,
-.Fn rresvport_af
-and
-.Fn iruserok_sa ,
-work the same as the corresponding functions without a
-suffix, except that they are capable of handling both IPv6 and IPv4 ports.
-.Pp
-The
-.Dq Li _af
-suffix means that the function has an additional
-.Fa af
-argument which is used to specify the address family,
-(see below).
-The
-.Fa af
-argument extension is implemented for functions
-that have no binary address argument.
-Instead, the
-.Fa af
-argument specifies which address family is desired.
-.Pp
-The
-.Dq Li _sa
-suffix means that the function has general socket address and
-length arguments.
-As the socket address is a protocol independent data structure,
-IPv4 and IPv6 socket address can be passed as desired.
-The
-.Fa sa
-argument extension is implemented for functions
-that pass a protocol dependent binary address argument.
-The argument needs to be replaced with a more general address structure
-to support multiple address families in a general way.
-.Pp
-The functions with neither an
-.Dq Li _af
-suffix nor an
-.Dq Li _sa
-suffix work for IPv4 only, except for
-.Fn ruserok
-which can handle both IPv6 and IPv4.
-To switch the address family, the
-.Fa af
-argument must be filled with
-.Dv AF_INET ,
-or
-.Dv AF_INET6 .
-For
-.Fn rcmd_af ,
-.Dv PF_UNSPEC
-is also allowed.
-.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
-function
-returns 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 ``All network ports in use.''
-.Sh SEE ALSO
-.Xr rlogin 1 ,
-.Xr rsh 1 ,
-.Xr intro 2 ,
-.Xr rexec 3 ,
-.Xr rexecd 8 ,
-.Xr rlogind 8 ,
-.Xr rshd 8
-.Pp
-.Rs
-.%A W. Stevens
-.%A M. Thomas
-.%T "Advanced Socket API for IPv6"
-.%O RFC2292
-.Re
-.Rs
-.%A W. Stevens
-.%A M. Thomas
-.%A E. Nordmark
-.%T "Advanced Socket API for IPv6"
-.%O draft-ietf-ipngwg-rfc2292bis-01.txt
-.Re
-.Sh HISTORY
-Most of these
-functions appeared in
-.Bx 4.2 .
-.Fn rresvport_af
-appeared in RFC2292, and was implemented by the WIDE project
-for the Hydrangea IPv6 protocol stack kit.
-.Fn rcmd_af
-appeared in draft-ietf-ipngwg-rfc2292bis-01.txt,
-and was implemented in the WIDE/KAME IPv6 protocol stack kit.
-.Fn iruserok_sa
-appeared in discussion on the IETF ipngwg mailing list,
-and was implemented in
-.Fx 4.0 .
diff --git a/newlib/libc/sys/linux/net/rcmd.c b/newlib/libc/sys/linux/net/rcmd.c
index 708b69d1b..ab3ade89b 100644
--- a/newlib/libc/sys/linux/net/rcmd.c
+++ b/newlib/libc/sys/linux/net/rcmd.c
@@ -1,4 +1,32 @@
/*
+ * Copyright (C) 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.
+ */
+/*
* Copyright (c) 1983, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
@@ -10,10 +38,6 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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.
@@ -34,55 +58,51 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <time.h>
-#include <sys/select.h>
-#include "namespace.h"
#include <sys/param.h>
+#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <alloca.h>
#include <signal.h>
#include <fcntl.h>
#include <netdb.h>
-#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <ctype.h>
#include <string.h>
-#ifdef YP
-#include <rpc/rpc.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-#endif
-#include <arpa/nameser.h>
-#include "un-namespace.h"
+#include <libintl.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <sys/uio.h>
-/* wrapper for KAME-special getnameinfo() */
-#ifndef NI_WITHSCOPEID
-#define NI_WITHSCOPEID 0
-#endif
+#include "local.h"
-extern int innetgr( const char *, const char *, const char *, const char * );
-extern int rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, const char *cmd, const char *rshprog);
-int rresvport_af(int *alport, int family);
-#define max(a, b) ((a > b) ? a : b)
+int __ivaliduser (FILE *, u_int32_t, const char *, const char *);
+static int __validuser2_sa (FILE *, struct sockaddr *, size_t,
+ const char *, const char *, const char *);
+static int ruserok2_sa (struct sockaddr *ra, size_t ralen,
+ int superuser, const char *ruser,
+ const char *luser, const char *rhost);
+static int ruserok_sa (struct sockaddr *ra, size_t ralen,
+ int superuser, const char *ruser,
+ const char *luser);
+int iruserok_af (const void *raddr, int superuser, const char *ruser,
+ const char *luser, sa_family_t af);
+int iruserok (u_int32_t raddr, int superuser, const char *ruser,
+ const char *luser);
-int __ivaliduser(FILE *, u_int32_t, const char *, const char *);
-int __ivaliduser_af(FILE *,const void *, const char *, const char *, int, int);
-int __ivaliduser_sa(FILE *, const struct sockaddr *, socklen_t, const char *,
- const char *);
-static int __icheckhost(const struct sockaddr *, socklen_t, const char *);
+libc_hidden_proto (iruserok_af)
-char paddr[NI_MAXHOST];
+libc_freeres_ptr(static char *ahostbuf);
int
rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
@@ -90,242 +110,300 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
u_short rport;
const char *locuser, *remuser, *cmd;
int *fd2p;
- int af;
+ sa_family_t af;
{
+ char paddr[INET6_ADDRSTRLEN];
struct addrinfo hints, *res, *ai;
struct sockaddr_storage from;
- fd_set reads;
- sigset_t oldmask, newmask;
+ struct pollfd pfd[2];
+ int32_t oldmask;
pid_t pid;
- int s, aport, lport, timo, error;
- char c, *p;
- int refused, nres;
+ int s, lport, timo, error;
+ char c;
+ int refused;
char num[8];
- static char canonnamebuf[MAXDNAME]; /* is it proper here? */
+ ssize_t n;
- /* call rcmdsh() with specified remote shell if appropriate. */
- if (!issetugid() && (p = getenv("RSH"))) {
- struct servent *sp = getservbyname("shell", "tcp");
+ if (af != AF_INET && af != AF_INET6 && af != AF_UNSPEC)
+ {
+ __set_errno (EAFNOSUPPORT);
+ return -1;
+ }
- 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();
- pid = getpid();
-
- memset(&hints, 0, sizeof(hints));
+ memset(&hints, '\0', sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = 0;
(void)snprintf(num, sizeof(num), "%d", ntohs(rport));
error = getaddrinfo(*ahost, num, &hints, &res);
if (error) {
- fprintf(stderr, "rcmd: getaddrinfo: %s\n",
- gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "rcmd: getaddrinfo: %s\n",
- strerror(errno));
- return (-1);
+ if (error == EAI_NONAME && *ahost != NULL) {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s: Unknown host\n",
+ *ahost);
+ else
+ fprintf(stderr, "%s: Unknown host\n", *ahost);
+ } else {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"rcmd: getaddrinfo: %s\n",
+ gai_strerror(error));
+ else
+ fprintf(stderr, "rcmd: getaddrinfo: %s\n",
+ gai_strerror(error));
+ }
+ return (-1);
}
- if (res->ai_canonname
- && strlen(res->ai_canonname) + 1 < sizeof(canonnamebuf)) {
- strncpy(canonnamebuf, res->ai_canonname, sizeof(canonnamebuf));
- *ahost = canonnamebuf;
- }
- nres = 0;
- for (ai = res; ai; ai = ai->ai_next)
- nres++;
+ pfd[0].events = POLLIN;
+ pfd[1].events = POLLIN;
+
+ if (res->ai_canonname){
+ free (ahostbuf);
+ ahostbuf = strdup (res->ai_canonname);
+ if (ahostbuf == NULL) {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s",
+ _("rcmd: Cannot allocate memory\n"));
+ else
+ fputs(_("rcmd: Cannot allocate memory\n"),
+ stderr);
+ return (-1);
+ }
+ *ahost = ahostbuf;
+ } else
+ *ahost = NULL;
ai = res;
refused = 0;
- sigemptyset(&newmask);
- sigaddset(&newmask, SIGURG);
- sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask);
+ oldmask = __sigblock(sigmask(SIGURG));
for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
+ char errbuf[200];
+
s = rresvport_af(&lport, ai->ai_family);
if (s < 0) {
- if (errno != EAGAIN && ai->ai_next) {
- ai = ai->ai_next;
- continue;
+ if (errno == EAGAIN) {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s",
+ _("rcmd: socket: All ports in use\n"));
+ else
+ fputs(_("rcmd: socket: All ports in use\n"),
+ stderr);
+ } else {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr,
+ L"rcmd: socket: %m\n");
+ else
+ fprintf(stderr, "rcmd: socket: %m\n");
}
- if (errno == EAGAIN)
- (void)fprintf(stderr,
- "rcmd: socket: All ports in use\n");
- else
- (void)fprintf(stderr, "rcmd: socket: %s\n",
- strerror(errno));
+ __sigsetmask(oldmask);
freeaddrinfo(res);
- sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask,
- NULL);
- return (-1);
+ return -1;
}
- fcntl(s, F_SETOWN, pid);
- if (connect(s, ai->ai_addr, ai->ai_addrlen) >= 0)
+ __fcntl(s, F_SETOWN, pid);
+ if (__connect(s, ai->ai_addr, ai->ai_addrlen) >= 0)
break;
- (void)close(s);
+ (void)__close(s);
if (errno == EADDRINUSE) {
lport--;
continue;
}
if (errno == ECONNREFUSED)
refused = 1;
- if (ai->ai_next == NULL && (!refused || timo > 16)) {
- (void)fprintf(stderr, "%s: %s\n",
- *ahost, strerror(errno));
- freeaddrinfo(res);
- sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask,
- NULL);
- return (-1);
- }
- if (nres > 1) {
+ if (ai->ai_next != NULL) {
int oerrno = errno;
+ char *buf = NULL;
getnameinfo(ai->ai_addr, ai->ai_addrlen,
paddr, sizeof(paddr),
NULL, 0,
- NI_NUMERICHOST|NI_WITHSCOPEID);
- (void)fprintf(stderr, "connect to address %s: ",
- paddr);
- errno = oerrno;
+ NI_NUMERICHOST);
+
+ if (__asprintf (&buf, _("connect to address %s: "),
+ paddr) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
+ __set_errno (oerrno);
perror(0);
+ ai = ai->ai_next;
+ getnameinfo(ai->ai_addr, ai->ai_addrlen,
+ paddr, sizeof(paddr),
+ NULL, 0,
+ NI_NUMERICHOST);
+ if (__asprintf (&buf, _("Trying %s...\n"), paddr) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
+ continue;
}
- if ((ai = ai->ai_next) == NULL) {
- /* refused && timo <= 16 */
- struct timespec time_to_sleep, time_remaining;
-
- time_to_sleep.tv_sec = timo;
- time_to_sleep.tv_nsec = 0;
- (void)nanosleep(&time_to_sleep, &time_remaining);
+ if (refused && timo <= 16) {
+ (void)sleep(timo);
timo *= 2;
ai = res;
refused = 0;
+ continue;
}
- if (nres > 1) {
- getnameinfo(ai->ai_addr, ai->ai_addrlen,
- paddr, sizeof(paddr),
- NULL, 0,
- NI_NUMERICHOST|NI_WITHSCOPEID);
- fprintf(stderr, "Trying %s...\n", paddr);
- }
+ freeaddrinfo(res);
+ if (_IO_fwide (stderr, 0) > 0)
+ (void)__fwprintf(stderr, L"%s: %s\n", *ahost,
+ strerror_r(errno,
+ errbuf, sizeof (errbuf)));
+ else
+ (void)fprintf(stderr, "%s: %s\n", *ahost,
+ strerror_r(errno,
+ errbuf, sizeof (errbuf)));
+ __sigsetmask(oldmask);
+ return -1;
}
lport--;
if (fd2p == 0) {
- write(s, "", 1);
+ __write(s, "", 1);
lport = 0;
} else {
char num[8];
int s2 = rresvport_af(&lport, ai->ai_family), s3;
- int len = ai->ai_addrlen;
- int nfds;
+ socklen_t len = ai->ai_addrlen;
if (s2 < 0)
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);
+ if (__write(s, num, strlen(num)+1) != (ssize_t)strlen(num)+1) {
+ char *buf = NULL;
+
+ if (__asprintf (&buf, _("\
+rcmd: write (setting up stderr): %m\n")) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
+ (void)__close(s2);
goto bad;
}
- nfds = max(s, s2)+1;
- if(nfds > FD_SETSIZE) {
- fprintf(stderr, "rcmd: too many files\n");
- (void)close(s2);
+ pfd[0].fd = s;
+ pfd[1].fd = s2;
+ __set_errno (0);
+ if (__poll (pfd, 2, -1) < 1 || (pfd[1].revents & POLLIN) == 0){
+ char *buf = NULL;
+
+ if ((errno != 0
+ && __asprintf(&buf, _("\
+rcmd: poll (setting up stderr): %m\n")) >= 0)
+ || (errno == 0
+ && __asprintf(&buf, _("\
+poll: protocol failure in circuit setup\n")) >= 0))
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
+ (void)__close(s2);
goto bad;
}
-again:
- FD_ZERO(&reads);
- FD_SET(s, &reads);
- FD_SET(s2, &reads);
- errno = 0;
- if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){
- 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);
+ s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from,
+ &len));
switch (from.ss_family) {
case AF_INET:
- aport = ntohs(((struct sockaddr_in *)&from)->sin_port);
+ rport = ntohs(((struct sockaddr_in *)&from)->sin_port);
break;
-#ifdef INET6
case AF_INET6:
- aport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port);
+ rport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port);
break;
-#endif
default:
- aport = 0; /* error */
+ rport = 0;
break;
}
- /*
- * XXX careful for ftp bounce attacks. If discovered, shut them
- * down and check for the real auxiliary channel to connect.
- */
- if (aport == 20) {
- close(s3);
- goto again;
- }
- (void)close(s2);
+ (void)__close(s2);
if (s3 < 0) {
- (void)fprintf(stderr,
- "rcmd: accept: %s\n", strerror(errno));
+ if (_IO_fwide (stderr, 0) > 0)
+ (void)__fwprintf(stderr,
+ L"rcmd: accept: %m\n");
+ else
+ (void)fprintf(stderr,
+ "rcmd: accept: %m\n");
lport = 0;
goto bad;
}
*fd2p = s3;
- if (aport >= IPPORT_RESERVED || aport < IPPORT_RESERVED / 2) {
- (void)fprintf(stderr,
- "socket: protocol failure in circuit setup.\n");
+
+ if (rport >= IPPORT_RESERVED || rport < IPPORT_RESERVED / 2){
+ char *buf = NULL;
+
+ if (__asprintf(&buf, _("\
+socket: protocol failure in circuit setup\n")) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
goto bad2;
}
}
- (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));
+ struct iovec iov[3] =
+ {
+ [0] = { .iov_base = (void *) locuser,
+ .iov_len = strlen (locuser) + 1 },
+ [1] = { .iov_base = (void *) remuser,
+ .iov_len = strlen (remuser) + 1 },
+ [2] = { .iov_base = (void *) cmd,
+ .iov_len = strlen (cmd) + 1 }
+ };
+ (void) TEMP_FAILURE_RETRY (writev (s, iov, 3));
+ n = TEMP_FAILURE_RETRY (read(s, &c, 1));
+ if (n != 1) {
+ char *buf = NULL;
+
+ if ((n == 0
+ && asprintf(&buf, _("rcmd: %s: short read"),
+ *ahost) >= 0)
+ || (n != 0
+ && asprintf(&buf, "rcmd: %s: %m\n", *ahost) >= 0))
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+ free (buf);
+ }
goto bad2;
}
if (c != 0) {
- while (read(s, &c, 1) == 1) {
- (void)write(STDERR_FILENO, &c, 1);
+ while (__read(s, &c, 1) == 1) {
+ (void)__write(STDERR_FILENO, &c, 1);
if (c == '\n')
break;
}
goto bad2;
}
- sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL);
+ __sigsetmask(oldmask);
freeaddrinfo(res);
- return (s);
+ return s;
bad2:
if (lport)
- (void)close(*fd2p);
+ (void)__close(*fd2p);
bad:
- (void)close(s);
- sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL);
+ (void)__close(s);
+ __sigsetmask(oldmask);
freeaddrinfo(res);
- return (-1);
+ return -1;
}
+libc_hidden_def (rcmd_af)
int
rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
@@ -334,90 +412,155 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
const char *locuser, *remuser, *cmd;
int *fd2p;
{
- return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET);
-}
-
-int
-rresvport(port)
- int *port;
-{
- return rresvport_af(port, AF_INET);
+ return rcmd_af (ahost, rport, locuser, remuser, cmd, fd2p, AF_INET);
}
int
rresvport_af(alport, family)
- int *alport, family;
+ int *alport;
+ sa_family_t family;
{
- int s;
struct sockaddr_storage ss;
- u_short *sport;
+ int s;
+ size_t len;
+ uint16_t *sport;
- memset(&ss, 0, sizeof(ss));
- ss.ss_family = family;
- switch (family) {
+ switch(family){
case AF_INET:
+ len = sizeof(struct sockaddr_in);
sport = &((struct sockaddr_in *)&ss)->sin_port;
- ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY;
break;
-#ifdef INET6
case AF_INET6:
+ len = sizeof(struct sockaddr_in6);
sport = &((struct sockaddr_in6 *)&ss)->sin6_port;
- ((struct sockaddr_in6 *)&ss)->sin6_addr = in6addr_any;
break;
-#endif
default:
- errno = EAFNOSUPPORT;
+ __set_errno (EAFNOSUPPORT);
return -1;
}
-
- s = socket(ss.ss_family, SOCK_STREAM, 0);
+ s = __socket(family, SOCK_STREAM, 0);
if (s < 0)
- return (-1);
-#if 0 /* compat_exact_traditional_rresvport_semantics */
- sin.sin_port = htons((u_short)*alport);
- if (_bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
- return (s);
- if (errno != EADDRINUSE) {
- (void)close(s);
- return (-1);
- }
+ return -1;
+
+ memset (&ss, '\0', sizeof(ss));
+#ifdef SALEN
+ ss.__ss_len = len;
#endif
- *sport = 0;
- if (bindresvport_sa(s, (struct sockaddr *)&ss) == -1) {
- (void)close(s);
- return (-1);
- }
- *alport = (int)ntohs(*sport);
- return (s);
+ ss.ss_family = family;
+
+ /* Ignore invalid values. */
+ if (*alport < IPPORT_RESERVED / 2)
+ *alport = IPPORT_RESERVED / 2;
+ else if (*alport >= IPPORT_RESERVED)
+ *alport = IPPORT_RESERVED - 1;
+
+ int start = *alport;
+ do {
+ *sport = htons((uint16_t) *alport);
+ if (__bind(s, (struct sockaddr *)&ss, len) >= 0)
+ return s;
+ if (errno != EADDRINUSE) {
+ (void)__close(s);
+ return -1;
+ }
+ if ((*alport)-- == IPPORT_RESERVED/2)
+ *alport = IPPORT_RESERVED - 1;
+ } while (*alport != start);
+ (void)__close(s);
+ __set_errno (EAGAIN);
+ return -1;
+}
+libc_hidden_def (rresvport_af)
+
+int
+rresvport(alport)
+ int *alport;
+{
+ return rresvport_af(alport, AF_INET);
}
int __check_rhosts_file = 1;
char *__rcmd_errstr;
int
-ruserok(rhost, superuser, ruser, luser)
+ruserok_af(rhost, superuser, ruser, luser, af)
const char *rhost, *ruser, *luser;
int superuser;
+ sa_family_t af;
{
- struct addrinfo hints, *res, *r;
- int error;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
- error = getaddrinfo(rhost, "0", &hints, &res);
- if (error)
- return (-1);
-
- for (r = res; r; r = r->ai_next) {
- if (iruserok_sa(r->ai_addr, r->ai_addrlen, superuser, ruser,
- luser) == 0) {
- freeaddrinfo(res);
- return (0);
+ struct addrinfo hints, *res, *res0;
+ int gai;
+ int ret;
+
+ memset (&hints, '\0', sizeof(hints));
+ hints.ai_family = af;
+ gai = getaddrinfo(rhost, NULL, &hints, &res0);
+ if (gai)
+ return -1;
+ ret = -1;
+ for (res=res0; res; res=res->ai_next)
+ if (ruserok2_sa(res->ai_addr, res->ai_addrlen,
+ superuser, ruser, luser, rhost) == 0){
+ ret = 0;
+ break;
}
- }
- freeaddrinfo(res);
- return (-1);
+ freeaddrinfo(res0);
+ return (ret);
+}
+libc_hidden_def (ruserok_af)
+
+int
+ruserok(rhost, superuser, ruser, luser)
+ const char *rhost, *ruser, *luser;
+ int superuser;
+{
+ return ruserok_af(rhost, superuser, ruser, luser, AF_INET);
+}
+
+/* Extremely paranoid file open function. */
+static FILE *
+iruserfopen (const char *file, uid_t okuser)
+{
+ struct stat64 st;
+ char *cp = NULL;
+ FILE *res = NULL;
+
+ /* If not a regular file, if owned by someone other than user or
+ root, if writeable by anyone but the owner, or if hardlinked
+ anywhere, quit. */
+ cp = NULL;
+ if (__lxstat64 (_STAT_VER, file, &st))
+ cp = _("lstat failed");
+ else if (!S_ISREG (st.st_mode))
+ cp = _("not regular file");
+ else
+ {
+ res = fopen (file, "rc");
+ if (!res)
+ cp = _("cannot open");
+ else if (__fxstat64 (_STAT_VER, fileno (res), &st) < 0)
+ cp = _("fstat failed");
+ else if (st.st_uid && st.st_uid != okuser)
+ cp = _("bad owner");
+ else if (st.st_mode & (S_IWGRP|S_IWOTH))
+ cp = _("writeable by other than owner");
+ else if (st.st_nlink > 1)
+ cp = _("hard linked somewhere");
+ }
+
+ /* If there were any problems, quit. */
+ if (cp != NULL)
+ {
+ __rcmd_errstr = cp;
+ if (res)
+ fclose (res);
+ return NULL;
+ }
+
+ /* No threads use this stream. */
+ __fsetlocking (res, FSETLOCKING_BYCALLER);
+
+ return res;
}
/*
@@ -429,110 +572,127 @@ ruserok(rhost, superuser, ruser, luser)
*
* Returns 0 if ok, -1 if not ok.
*/
-int
-iruserok(raddr, superuser, ruser, luser)
- unsigned long raddr;
- int superuser;
- const char *ruser, *luser;
+static int
+ruserok2_sa (ra, ralen, superuser, ruser, luser, rhost)
+ struct sockaddr *ra;
+ size_t ralen;
+ int superuser;
+ const char *ruser, *luser, *rhost;
{
- struct sockaddr_in sin;
- int sin_len;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin_len = sizeof(struct sockaddr_in);
- memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr));
- return iruserok_sa((struct sockaddr *)&sin, sin_len, superuser,
- ruser, luser);
+ FILE *hostf = NULL;
+ int isbad = -1;
+
+ if (!superuser)
+ hostf = iruserfopen (_PATH_HEQUIV, 0);
+
+ if (hostf)
+ {
+ isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
+ fclose (hostf);
+
+ if (!isbad)
+ return 0;
+ }
+
+ if (__check_rhosts_file || superuser)
+ {
+ char *pbuf;
+ struct passwd pwdbuf, *pwd;
+ size_t dirlen;
+ size_t buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
+ char *buffer = __alloca (buflen);
+ uid_t uid;
+
+ if (__getpwnam_r (luser, &pwdbuf, buffer, buflen, &pwd) != 0
+ || pwd == NULL)
+ return -1;
+
+ dirlen = strlen (pwd->pw_dir);
+ pbuf = alloca (dirlen + sizeof "/.rhosts");
+ __mempcpy (__mempcpy (pbuf, pwd->pw_dir, dirlen),
+ "/.rhosts", sizeof "/.rhosts");
+
+ /* Change effective uid while reading .rhosts. If root and
+ reading an NFS mounted file system, can't read files that
+ are protected read/write owner only. */
+ uid = __geteuid ();
+ seteuid (pwd->pw_uid);
+ hostf = iruserfopen (pbuf, pwd->pw_uid);
+
+ if (hostf != NULL)
+ {
+ isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
+ fclose (hostf);
+ }
+
+ seteuid (uid);
+ return isbad;
+ }
+ return -1;
}
-
/*
- * AF independent extension of iruserok.
- *
- * Returns 0 if ok, -1 if not ok.
+ * ruserok_sa() is now discussed on ipng, so
+ * currently disabled for external use
*/
+static int ruserok_sa(ra, ralen, superuser, ruser, luser)
+ struct sockaddr *ra;
+ size_t ralen;
+ int superuser;
+ const char *ruser, *luser;
+{
+ return ruserok2_sa(ra, ralen, superuser, ruser, luser, "-");
+}
+
+/* This is the exported version. */
int
-iruserok_sa(ra, rlen, superuser, ruser, luser)
- const void *ra;
- int rlen;
- int superuser;
- const char *ruser, *luser;
+iruserok_af (raddr, superuser, ruser, luser, af)
+ const void *raddr;
+ int superuser;
+ const char *ruser, *luser;
+ sa_family_t af;
{
- char *cp;
- struct stat sbuf;
- struct passwd *pwd;
- FILE *hostf;
- uid_t uid;
- int first;
- char pbuf[MAXPATHLEN];
- const struct sockaddr *raddr;
- struct sockaddr_storage ss;
+ struct sockaddr_storage ra;
+ size_t ralen;
+
+ memset (&ra, '\0', sizeof(ra));
+ switch (af){
+ case AF_INET:
+ ((struct sockaddr_in *)&ra)->sin_family = AF_INET;
+ memcpy (&(((struct sockaddr_in *)&ra)->sin_addr), raddr,
+ sizeof(struct in_addr));
+ ralen = sizeof(struct sockaddr_in);
+ break;
+ case AF_INET6:
+ ((struct sockaddr_in6 *)&ra)->sin6_family = AF_INET6;
+ memcpy (&(((struct sockaddr_in6 *)&ra)->sin6_addr), raddr,
+ sizeof(struct in6_addr));
+ ralen = sizeof(struct sockaddr_in6);
+ break;
+ default:
+ return 0;
+ }
+ return ruserok_sa ((struct sockaddr *)&ra, ralen, superuser, ruser, luser);
+}
+libc_hidden_def (iruserok_af)
- /* avoid alignment issue */
- if (rlen > sizeof(ss))
- return(-1);
- memcpy(&ss, ra, rlen);
- raddr = (struct sockaddr *)&ss;
-
- first = 1;
- hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
-again:
- if (hostf) {
- if (__ivaliduser_sa(hostf, raddr, rlen, luser, ruser) == 0) {
- (void)fclose(hostf);
- return (0);
- }
- (void)fclose(hostf);
- }
- if (first == 1 && (__check_rhosts_file || superuser)) {
- first = 0;
- if ((pwd = getpwnam(luser)) == NULL)
- return (-1);
- (void)strcpy(pbuf, pwd->pw_dir);
- (void)strcat(pbuf, "/.rhosts");
-
- /*
- * Change effective uid while opening .rhosts. If root and
- * reading an NFS mounted file system, can't read files that
- * are protected read/write owner only.
- */
- uid = geteuid();
- (void)seteuid(pwd->pw_uid);
- hostf = fopen(pbuf, "r");
- (void)seteuid(uid);
-
- if (hostf == NULL)
- return (-1);
- /*
- * If not a regular file, or is owned by someone other than
- * user or root or if writeable by anyone but the owner, quit.
- */
- cp = NULL;
- if (lstat(pbuf, &sbuf) < 0)
- cp = ".rhosts lstat failed";
- else if (!S_ISREG(sbuf.st_mode))
- cp = ".rhosts not regular file";
- else if (fstat(fileno(hostf), &sbuf) < 0)
- cp = ".rhosts fstat failed";
- else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
- cp = "bad .rhosts owner";
- else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
- cp = ".rhosts writeable by other than owner";
- /* If there were any problems, quit. */
- if (cp) {
- __rcmd_errstr = cp;
- (void)fclose(hostf);
- return (-1);
- }
- goto again;
- }
- return (-1);
+int
+iruserok (raddr, superuser, ruser, luser)
+ u_int32_t raddr;
+ int superuser;
+ const char *ruser, *luser;
+{
+ return iruserok_af (&raddr, superuser, ruser, luser, AF_INET);
}
/*
* XXX
* Don't make static, used by lpd(8).
*
+ * This function is not used anymore. It is only present because lpd(8)
+ * calls it (!?!). We simply call __invaliduser2() with an illegal rhost
+ * argument. This means that netgroups won't work in .rhost/hosts.equiv
+ * files. If you want lpd to work with netgroups, fix lpd to use ruserok()
+ * or PAM.
* Returns 0 if ok, -1 if not ok.
*/
int
@@ -541,239 +701,185 @@ __ivaliduser(hostf, raddr, luser, ruser)
u_int32_t raddr;
const char *luser, *ruser;
{
- struct sockaddr_in sin;
- int sin_len;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin_len = sizeof(struct sockaddr_in);
- memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr));
- return __ivaliduser_sa(hostf, (struct sockaddr *)&sin, sin_len,
- luser, ruser);
+ struct sockaddr_in ra;
+ memset(&ra, '\0', sizeof(ra));
+ ra.sin_family = AF_INET;
+ ra.sin_addr.s_addr = raddr;
+ return __validuser2_sa(hostf, (struct sockaddr *)&ra, sizeof(ra),
+ luser, ruser, "-");
}
-/*
- * Returns 0 if ok, -1 if not ok.
- *
- * XXX obsolete API.
- */
-int
-__ivaliduser_af(hostf, raddr, luser, ruser, af, len)
- FILE *hostf;
- const void *raddr;
- const char *luser, *ruser;
- int af, len;
+
+/* Returns 1 on positive match, 0 on no match, -1 on negative match. */
+static int
+internal_function
+__checkhost_sa (struct sockaddr *ra, size_t ralen, char *lhost,
+ const char *rhost)
{
- struct sockaddr *sa = NULL;
- struct sockaddr_in *sin = NULL;
-#ifdef INET6
- struct sockaddr_in6 *sin6 = NULL;
-#endif
- struct sockaddr_storage ss;
+ struct addrinfo hints, *res0, *res;
+ char raddr[INET6_ADDRSTRLEN];
+ int match;
+ int negate=1; /* Multiply return with this to get -1 instead of 1 */
+
+ /* Check nis netgroup. */
+ if (strncmp ("+@", lhost, 2) == 0)
+ return innetgr (&lhost[2], rhost, NULL, NULL);
+
+ if (strncmp ("-@", lhost, 2) == 0)
+ return -innetgr (&lhost[2], rhost, NULL, NULL);
+
+ /* -host */
+ if (strncmp ("-", lhost,1) == 0) {
+ negate = -1;
+ lhost++;
+ } else if (strcmp ("+",lhost) == 0) {
+ return 1; /* asking for trouble, but ok.. */
+ }
- memset(&ss, 0, sizeof(ss));
- switch (af) {
- case AF_INET:
- if (len != sizeof(sin->sin_addr))
- return -1;
- sin = (struct sockaddr_in *)&ss;
- sin->sin_family = AF_INET;
- memcpy(&sin->sin_addr, raddr, sizeof(sin->sin_addr));
- break;
-#ifdef INET6
- case AF_INET6:
- if (len != sizeof(sin6->sin6_addr))
- return -1;
- /* you will lose scope info */
- sin6 = (struct sockaddr_in6 *)&ss;
- sin6->sin6_family = AF_INET6;
- memcpy(&sin6->sin6_addr, raddr, sizeof(sin6->sin6_addr));
- break;
-#endif
- default:
- return -1;
+ /* Try for raw ip address first. */
+ /* XXX */
+ if (getnameinfo(ra, ralen,
+ raddr, sizeof(raddr), NULL, 0,
+ NI_NUMERICHOST) == 0
+ && strcmp(raddr, lhost) == 0)
+ return negate;
+
+ /* Better be a hostname. */
+ match = 0;
+ memset(&hints, '\0', sizeof(hints));
+ hints.ai_family = ra->sa_family;
+ if (getaddrinfo(lhost, NULL, &hints, &res0) == 0){
+ /* Spin through ip addresses. */
+ for (res = res0; res; res = res->ai_next)
+ {
+ if (res->ai_family == ra->sa_family
+ && !memcmp(res->ai_addr, ra, res->ai_addrlen))
+ {
+ match = 1;
+ break;
+ }
+ }
+ freeaddrinfo (res0);
}
+ return negate * match;
+}
+
+/* Returns 1 on positive match, 0 on no match, -1 on negative match. */
+static int
+internal_function
+__icheckuser (const char *luser, const char *ruser)
+{
+ /*
+ luser is user entry from .rhosts/hosts.equiv file
+ ruser is user id on remote host
+ */
+
+ /* [-+]@netgroup */
+ if (strncmp ("+@", luser, 2) == 0)
+ return innetgr (&luser[2], NULL, ruser, NULL);
+
+ if (strncmp ("-@", luser,2) == 0)
+ return -innetgr (&luser[2], NULL, ruser, NULL);
- sa = (struct sockaddr *)&ss;
- return __ivaliduser_sa(hostf, sa, 0, luser, ruser);
+ /* -user */
+ if (strncmp ("-", luser, 1) == 0)
+ return -(strcmp (&luser[1], ruser) == 0);
+
+ /* + */
+ if (strcmp ("+", luser) == 0)
+ return 1;
+
+ /* simple string match */
+ return strcmp (ruser, luser) == 0;
}
-int
-__ivaliduser_sa(hostf, raddr, salen, luser, ruser)
- FILE *hostf;
- const struct sockaddr *raddr;
- socklen_t salen;
- const char *luser, *ruser;
+/*
+ * Returns 1 for blank lines (or only comment lines) and 0 otherwise
+ */
+static int
+__isempty (char *p)
{
- char *user, *p;
- int ch;
- char buf[MAXHOSTNAMELEN + 128]; /* host + login */
- char hname[MAXHOSTNAMELEN];
- /* Presumed guilty until proven innocent. */
- int userok = 0, hostok = 0;
-#ifdef YP
- char *ypdomain;
-
- if (yp_get_default_domain(&ypdomain))
- ypdomain = NULL;
-#else
-#define ypdomain NULL
-#endif
- /* We need to get the damn hostname back for netgroup matching. */
- if (getnameinfo(raddr, salen, hname, sizeof(hname), NULL, 0,
- NI_NAMEREQD) != 0)
- return (-1);
-
- while (fgets(buf, sizeof(buf), hostf)) {
- p = buf;
- /* Skip lines that are too long. */
- if (strchr(p, '\n') == NULL) {
- while ((ch = getc(hostf)) != '\n' && ch != EOF);
- continue;
- }
- if (*p == '\n' || *p == '#') {
- /* comment... */
- continue;
- }
- while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
- *p = isupper((unsigned char)*p) ? tolower((unsigned char)*p) : *p;
- p++;
- }
- if (*p == ' ' || *p == '\t') {
- *p++ = '\0';
- while (*p == ' ' || *p == '\t')
- p++;
- user = p;
- while (*p != '\n' && *p != ' ' &&
- *p != '\t' && *p != '\0')
- p++;
- } else
- user = p;
- *p = '\0';
- /*
- * Do +/- and +@/-@ checking. This looks really nasty,
- * but it matches SunOS's behavior so far as I can tell.
- */
- switch(buf[0]) {
- case '+':
- if (!buf[1]) { /* '+' matches all hosts */
- hostok = 1;
- break;
- }
- if (buf[1] == '@') /* match a host by netgroup */
- hostok = innetgr((char *)&buf[2],
- (char *)&hname, NULL, ypdomain);
- else /* match a host by addr */
- hostok = __icheckhost(raddr, salen,
- (char *)&buf[1]);
- break;
- case '-': /* reject '-' hosts and all their users */
- if (buf[1] == '@') {
- if (innetgr((char *)&buf[2],
- (char *)&hname, NULL, ypdomain))
- return(-1);
- } else {
- if (__icheckhost(raddr, salen,
- (char *)&buf[1]))
- return(-1);
- }
- break;
- default: /* if no '+' or '-', do a simple match */
- hostok = __icheckhost(raddr, salen, buf);
- break;
- }
- switch(*user) {
- case '+':
- if (!*(user+1)) { /* '+' matches all users */
- userok = 1;
- break;
- }
- if (*(user+1) == '@') /* match a user by netgroup */
- userok = innetgr(user+2, NULL, ruser, ypdomain);
- else /* match a user by direct specification */
- userok = !(strcmp(ruser, user+1));
- break;
- case '-': /* if we matched a hostname, */
- if (hostok) { /* check for user field rejections */
- if (!*(user+1))
- return(-1);
- if (*(user+1) == '@') {
- if (innetgr(user+2, NULL,
- ruser, ypdomain))
- return(-1);
- } else {
- if (!strcmp(ruser, user+1))
- return(-1);
- }
- }
- break;
- default: /* no rejections: try to match the user */
- if (hostok)
- userok = !(strcmp(ruser,*user ? user : luser));
- break;
- }
- if (hostok && userok)
- return(0);
- }
- return (-1);
+ while (*p && isspace (*p)) {
+ ++p;
+ }
+
+ return (*p == '\0' || *p == '#') ? 1 : 0 ;
}
/*
- * Returns "true" if match, 0 if no match.
- *
- * NI_WITHSCOPEID is useful for comparing sin6_scope_id portion
- * if af == AF_INET6.
+ * Returns 0 if positive match, -1 if _not_ ok.
*/
static int
-__icheckhost(raddr, salen, lhost)
- const struct sockaddr *raddr;
- socklen_t salen;
- const char *lhost;
+__validuser2_sa(hostf, ra, ralen, luser, ruser, rhost)
+ FILE *hostf;
+ struct sockaddr *ra;
+ size_t ralen;
+ const char *luser, *ruser, *rhost;
{
- struct sockaddr_in sin;
- struct sockaddr_in6 *sin6;
- struct addrinfo hints, *res, *r;
- int error;
- char h1[NI_MAXHOST], h2[NI_MAXHOST];
-
- if (raddr->sa_family == AF_INET6) {
- sin6 = (struct sockaddr_in6 *)raddr;
- if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[12],
- sizeof(sin.sin_addr));
- raddr = (struct sockaddr *)&sin;
- salen = sizeof(struct sockaddr_in);
- }
+ register const char *user;
+ register char *p;
+ int hcheck, ucheck;
+ char *buf = NULL;
+ size_t bufsize = 0;
+ int retval = -1;
+
+ while (__getline (&buf, &bufsize, hostf) > 0) {
+ buf[bufsize - 1] = '\0'; /* Make sure it's terminated. */
+ p = buf;
+
+ /* Skip empty or comment lines */
+ if (__isempty (p)) {
+ continue;
}
- h1[0] = '\0';
- if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0,
- NI_NUMERICHOST | NI_WITHSCOPEID) != 0)
- return (0);
-
- /* Resolve laddr into sockaddr */
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = raddr->sa_family;
- hints.ai_socktype = SOCK_DGRAM; /*XXX dummy*/
- res = NULL;
- error = getaddrinfo(lhost, "0", &hints, &res);
- if (error)
- return (0);
-
- for (r = res; r ; r = r->ai_next) {
- h2[0] = '\0';
- if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2),
- NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) != 0)
- continue;
- if (strcmp(h1, h2) == 0) {
- freeaddrinfo(res);
- return (1);
- }
+ for (;*p && !isspace(*p); ++p) {
+ *p = _tolower (*p);
}
- /* No match. */
- freeaddrinfo(res);
- return (0);
+ /* Next we want to find the permitted name for the remote user. */
+ if (*p == ' ' || *p == '\t') {
+ /* <nul> terminate hostname and skip spaces */
+ for (*p++='\0'; *p && isspace (*p); ++p);
+
+ user = p; /* this is the user's name */
+ while (*p && !isspace (*p))
+ ++p; /* find end of user's name */
+ } else
+ user = p;
+
+ *p = '\0'; /* <nul> terminate username (+host?) */
+
+ /* buf -> host(?) ; user -> username(?) */
+
+ /* First check host part */
+ hcheck = __checkhost_sa (ra, ralen, buf, rhost);
+
+ if (hcheck < 0)
+ break;
+
+ if (hcheck) {
+ /* Then check user part */
+ if (! (*user))
+ user = luser;
+
+ ucheck = __icheckuser (user, ruser);
+
+ /* Positive 'host user' match? */
+ if (ucheck > 0) {
+ retval = 0;
+ break;
+ }
+
+ /* Negative 'host -user' match? */
+ if (ucheck < 0)
+ break;
+
+ /* Neither, go on looking for match */
+ }
+ }
+
+ if (buf != NULL)
+ free (buf);
+
+ return retval;
}
diff --git a/newlib/libc/sys/linux/net/rcmdsh.3 b/newlib/libc/sys/linux/net/rcmdsh.3
deleted file mode 100644
index 43e6a8daa..000000000
--- a/newlib/libc/sys/linux/net/rcmdsh.3
+++ /dev/null
@@ -1,116 +0,0 @@
-.\" $OpenBSD: rcmdsh.3,v 1.6 1999/07/05 04:41:00 aaron 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" $FreeBSD: src/lib/libc/net/rcmdsh.3,v 1.2 2001/11/09 15:19:25 ru Exp $
-.\"
-.Dd September 1, 1996
-.Dt RCMDSH 3
-.Os
-.Sh NAME
-.Nm rcmdsh
-.Nd return a stream to a remote command without superuser
-.Sh SYNOPSIS
-.In unistd.h
-.Ft int
-.Fo rcmdsh
-.Fa "char **ahost"
-.Fa "int inport"
-.Fa "const char *locuser"
-.Fa "const char *remuser"
-.Fa "const char *cmd"
-.Fa "const char *rshprog"
-.Fc
-.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 rshd 8
-or the value of
-.Fa rshprog
-(if
-.No non- Ns Dv NULL ) .
-.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
-.Dq 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
-domain of type
-.Dv SOCK_STREAM
-is returned to the caller, and given to the remote
-command as stdin, stdout, and stderr.
-.Sh RETURN VALUES
-The
-.Fn rcmdsh
-function
-returns a valid socket descriptor on success.
-Otherwise, \-1 is returned
-and a diagnostic message is printed on the standard error.
-.Sh SEE ALSO
-.Xr rsh 1 ,
-.Xr socketpair 2 ,
-.Xr rcmd 3 ,
-.Xr rshd 8
-.Sh BUGS
-If
-.Xr rsh 1
-encounters an error, a file descriptor is still returned instead of \-1.
-.Sh HISTORY
-The
-.Fn rcmdsh
-function first appeared in
-.Ox 2.0 ,
-and made its way into
-.Fx 5.0 .
diff --git a/newlib/libc/sys/linux/net/res_comp.c b/newlib/libc/sys/linux/net/res_comp.c
index 12ea02c6d..51211f743 100644
--- a/newlib/libc/sys/linux/net/res_comp.c
+++ b/newlib/libc/sys/linux/net/res_comp.c
@@ -1,7 +1,7 @@
/*
* 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -52,7 +48,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -69,11 +65,9 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
+static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "$BINDId: res_comp.c,v 8.15 1999/10/13 16:39:39 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -84,8 +78,7 @@ static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 hall
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-
-#define BIND_4_COMPAT
+#include "libc-symbols.h"
/*
* Expand compressed domain name 'comp_dn' to full domain name.
@@ -104,6 +97,7 @@ dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
dst[0] = '\0';
return (n);
}
+libresolv_hidden_def (dn_expand)
/*
* Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
@@ -118,6 +112,7 @@ dn_comp(const char *src, u_char *dst, int dstsiz,
(const u_char **)dnptrs,
(const u_char **)lastdnptr));
}
+libresolv_hidden_def (dn_comp)
/*
* Skip over a compressed domain name. Return the size or -1.
@@ -130,6 +125,7 @@ dn_skipname(const u_char *ptr, const u_char *eom) {
return (-1);
return (ptr - saveptr);
}
+libresolv_hidden_def (dn_skipname)
/*
* Verify that a domain name uses an acceptable character set.
@@ -143,6 +139,7 @@ dn_skipname(const u_char *ptr, const u_char *eom) {
*/
#define PERIOD 0x2e
#define hyphenchar(c) ((c) == 0x2d)
+#define underscorechar(c) ((c) == 0x5f)
#define bslashchar(c) ((c) == 0x5c)
#define periodchar(c) ((c) == PERIOD)
#define asterchar(c) ((c) == 0x2a)
@@ -151,13 +148,11 @@ dn_skipname(const u_char *ptr, const u_char *eom) {
#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
#define borderchar(c) (alphachar(c) || digitchar(c))
-#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
int
-res_hnok(dn)
- const char *dn;
-{
+res_hnok(const char *dn) {
int ppch = '\0', pch = PERIOD, ch = *dn++;
while (ch != '\0') {
@@ -179,15 +174,14 @@ res_hnok(dn)
}
return (1);
}
+libresolv_hidden_def (res_hnok)
/*
* hostname-like (A, MX, WKS) owners can have "*" as their first label
* but must otherwise be as a host name.
*/
int
-res_ownok(dn)
- const char *dn;
-{
+res_ownok(const char *dn) {
if (asterchar(dn[0])) {
if (periodchar(dn[1]))
return (res_hnok(dn+2));
@@ -202,9 +196,7 @@ res_ownok(dn)
* label, but the rest of the name has to look like a host name.
*/
int
-res_mailok(dn)
- const char *dn;
-{
+res_mailok(const char *dn) {
int ch, escaped = 0;
/* "." is a valid missing representation */
@@ -232,9 +224,7 @@ res_mailok(dn)
* recommendations.
*/
int
-res_dnok(dn)
- const char *dn;
-{
+res_dnok(const char *dn) {
int ch;
while ((ch = *dn++) != '\0')
@@ -242,27 +232,31 @@ res_dnok(dn)
return (0);
return (1);
}
+libresolv_hidden_def (res_dnok)
#ifdef BIND_4_COMPAT
/*
* This module must export the following externally-visible symbols:
- * ___putlong
- * ___putshort
- * __getlong
- * __getshort
+ * ___putlong
+ * ___putshort
+ * __getlong
+ * __getshort
* Note that one _ comes from C and the others come from us.
*/
void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
+libresolv_hidden_def (__putlong)
void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
+libresolv_hidden_def (__putshort)
+#ifndef __ultrix__
u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
+#endif /*__ultrix__*/
#endif /*BIND_4_COMPAT*/
+
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef dn_comp
-__weak_reference(__dn_comp, dn_comp);
-#undef dn_expand
-__weak_reference(__dn_expand, dn_expand);
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2)
+# undef dn_expand
+weak_alias (__dn_expand, dn_expand);
+#endif
diff --git a/newlib/libc/sys/linux/net/res_config.h b/newlib/libc/sys/linux/net/res_config.h
deleted file mode 100644
index b7deb38f9..000000000
--- a/newlib/libc/sys/linux/net/res_config.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* $FreeBSD: src/lib/libc/net/res_config.h,v 1.8 2002/03/22 23:41:54 obrien Exp $ */
-
-#define DEBUG 1 /* enable debugging code (needed for dig) */
-#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
-#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
-#undef USELOOPBACK /* res_init() bind to localhost */
-#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
-#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */
-#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */
-#define BIND_UPDATE 1 /* update support */
diff --git a/newlib/libc/sys/linux/net/res_data.c b/newlib/libc/sys/linux/net/res_data.c
index 7db548078..cb140eeb7 100644
--- a/newlib/libc/sys/linux/net/res_data.c
+++ b/newlib/libc/sys/linux/net/res_data.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995,1996 by Internet Software Consortium.
+ * Copyright (c) 1995-1999 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
@@ -15,24 +15,30 @@
* SOFTWARE.
*/
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] = "$BINDId: res_data.c,v 8.17 1999/10/13 17:11:31 vixie Exp $";
+#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
+
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+
#include <ctype.h>
+#include <netdb.h>
#include <resolv.h>
+#ifdef BIND_UPDATE
+#include <res_update.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include "res_config.h"
+#include "libc-symbols.h"
const char *_res_opcodes[] = {
"QUERY",
@@ -52,31 +58,278 @@ const char *_res_opcodes[] = {
"ZONEINIT",
"ZONEREF",
};
-
-const char *_res_resultcodes[] = {
- "NOERROR",
- "FORMERR",
- "SERVFAIL",
- "NXDOMAIN",
- "NOTIMP",
- "REFUSED",
- "YXDOMAIN",
- "YXRRSET",
- "NXRRSET",
- "NOTAUTH",
- "ZONEERR",
- "11",
- "12",
- "13",
- "14",
- "NOCHANGE",
-};
+libresolv_hidden_data_def (_res_opcodes)
#ifdef BIND_UPDATE
-const char *_res_sectioncodes[] = {
+const char *_res_sectioncodes[] attribute_hidden = {
"ZONE",
"PREREQUISITES",
"UPDATE",
"ADDITIONAL",
};
#endif
+
+#ifndef __BIND_NOSTATIC
+#ifdef _LIBC
+/* The definition has been moved to res_libc.c. */
+#else
+#undef _res
+struct __res_state _res
+# if defined(__BIND_RES_TEXT)
+ = { RES_TIMEOUT, } /* Motorola, et al. */
+# endif
+ ;
+#endif
+
+/* Proto. */
+#ifndef _LIBC
+int res_ourserver_p(const res_state, const struct sockaddr_in *);
+void res_pquery(const res_state, const u_char *, int, FILE *);
+#endif
+
+#ifndef _LIBC
+/* Moved to res_libc.c since res_init() should go into libc.so but the
+ rest of this file not. */
+int
+res_init(void) {
+ extern int __res_vinit(res_state, int);
+
+ /*
+ * These three fields used to be statically initialized. This made
+ * it hard to use this code in a shared library. It is necessary,
+ * now that we're doing dynamic initialization here, that we preserve
+ * the old semantics: if an application modifies one of these three
+ * fields of _res before res_init() is called, res_init() will not
+ * alter them. Of course, if an application is setting them to
+ * _zero_ before calling res_init(), hoping to override what used
+ * to be the static default, we can't detect it and unexpected results
+ * will follow. Zero for any of these fields would make no sense,
+ * so one can safely assume that the applications were already getting
+ * unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
+ */
+ if (!_res.retrans)
+ _res.retrans = RES_TIMEOUT;
+ if (!_res.retry)
+ _res.retry = 4;
+ if (!(_res.options & RES_INIT))
+ _res.options = RES_DEFAULT;
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = res_randomid();
+
+ return (__res_vinit(&_res, 1));
+}
+#endif
+
+void
+p_query(const u_char *msg) {
+ fp_query(msg, stdout);
+}
+
+void
+fp_query(const u_char *msg, FILE *file) {
+ fp_nquery(msg, PACKETSZ, file);
+}
+libresolv_hidden_def (fp_query)
+
+void
+fp_nquery(const u_char *msg, int len, FILE *file) {
+ if (__res_maybe_init (&_res, 0) == -1)
+ return;
+
+ res_pquery(&_res, msg, len, file);
+}
+libresolv_hidden_def (fp_nquery)
+
+int
+res_mkquery(int op, /* opcode of query */
+ const char *dname, /* domain name */
+ int class, int type, /* class and type of query */
+ const u_char *data, /* resource record data */
+ int datalen, /* length of data */
+ const u_char *newrr_in, /* new rr for modify or append */
+ u_char *buf, /* buffer to put query */
+ int buflen) /* size of buffer */
+{
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+ return (res_nmkquery(&_res, op, dname, class, type,
+ data, datalen,
+ newrr_in, buf, buflen));
+}
+
+#ifdef BIND_UPDATE
+int
+res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+
+ return (res_nmkupdate(&_res, rrecp_in, buf, buflen));
+}
+#endif
+
+int
+res_query(const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer buffer */
+{
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+ return (res_nquery(&_res, name, class, type, answer, anslen));
+}
+
+void
+res_send_setqhook(res_send_qhook hook) {
+ _res.qhook = hook;
+}
+
+void
+res_send_setrhook(res_send_rhook hook) {
+ _res.rhook = hook;
+}
+
+int
+res_isourserver(const struct sockaddr_in *inp) {
+ return (res_ourserver_p(&_res, (const struct sockaddr_in6 *) inp));
+}
+
+int
+res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
+ if (__res_maybe_init (&_res, 1) == -1) {
+ /* errno should have been set by res_init() in this case. */
+ return (-1);
+ }
+
+ return (res_nsend(&_res, buf, buflen, ans, anssiz));
+}
+
+#ifndef _LIBC
+int
+res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
+ u_char *ans, int anssiz)
+{
+ if (__res_maybe_init (&_res, 1) == -1) {
+ /* errno should have been set by res_init() in this case. */
+ return (-1);
+ }
+
+ return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz));
+}
+#endif
+
+void
+res_close(void) {
+#ifdef _LIBC
+ /*
+ * Some stupid programs out there call res_close() before res_init().
+ * Since _res._vcsock isn't explicitly initialized, these means that
+ * we could do a close(0), which might lead to some security problems.
+ * Therefore we check if res_init() was called before by looking at
+ * the RES_INIT bit in _res.options. If it hasn't been set we bail out
+ * early. */
+ if ((_res.options & RES_INIT) == 0)
+ return;
+#endif
+ res_nclose(&_res);
+}
+
+#ifdef BIND_UPDATE
+int
+res_update(ns_updrec *rrecp_in) {
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+
+ return (res_nupdate(&_res, rrecp_in, NULL));
+}
+#endif
+
+int
+res_search(const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
+{
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+
+ return (res_nsearch(&_res, name, class, type, answer, anslen));
+}
+
+int
+res_querydomain(const char *name,
+ const char *domain,
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
+{
+ if (__res_maybe_init (&_res, 1) == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+
+ return (res_nquerydomain(&_res, name, domain,
+ class, type,
+ answer, anslen));
+}
+
+const char *
+hostalias(const char *name) {
+ static char abuf[MAXDNAME];
+
+ return (res_hostalias(&_res, name, abuf, sizeof abuf));
+}
+libresolv_hidden_def (hostalias)
+
+#ifdef ultrix
+int
+local_hostname_length(const char *hostname) {
+ int len_host, len_domain;
+
+ if (!*_res.defdname)
+ res_init();
+ len_host = strlen(hostname);
+ len_domain = strlen(_res.defdname);
+ if (len_host > len_domain &&
+ !strcasecmp(hostname + len_host - len_domain, _res.defdname) &&
+ hostname[len_host - len_domain - 1] == '.')
+ return (len_host - len_domain - 1);
+ return (0);
+}
+#endif /*ultrix*/
+
+#endif
+
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2)
+# undef res_mkquery
+# undef res_query
+# undef res_querydomain
+# undef res_search
+weak_alias (__res_mkquery, res_mkquery);
+weak_alias (__res_query, res_query);
+weak_alias (__res_querydomain, res_querydomain);
+weak_alias (__res_search, res_search);
+#endif
diff --git a/newlib/libc/sys/linux/net/res_debug.c b/newlib/libc/sys/linux/net/res_debug.c
index 786f633f4..cd50fe546 100644
--- a/newlib/libc/sys/linux/net/res_debug.c
+++ b/newlib/libc/sys/linux/net/res_debug.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 1985
* 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -77,7 +73,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -94,10 +90,9 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
+static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "$BINDId: res_debug.c,v 8.34 2000/02/29 05:30:55 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -116,23 +111,24 @@ static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include "local.h"
-#define SPRINTF(x) sprintf x
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) sprintf x
+#endif
-extern const char *_res_opcodes[];
-extern const char *_res_resultcodes[];
-extern const char *_res_sectioncodes[];
+extern const char *_res_sectioncodes[] attribute_hidden;
/*
* Print the current options.
*/
void
-fp_resstat(struct __res_state *statp, FILE *file) {
+fp_resstat(const res_state statp, FILE *file) {
u_long mask;
fprintf(file, ";; res options:");
- if (!statp)
- statp = &_res;
for (mask = 1; mask != 0; mask <<= 1)
if (statp->options & mask)
fprintf(file, " %s", p_option(mask));
@@ -140,20 +136,30 @@ fp_resstat(struct __res_state *statp, FILE *file) {
}
static void
-do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
+do_section(const res_state statp,
+ ns_msg *handle, ns_sect section,
+ int pflag, FILE *file)
+{
int n, sflag, rrnum;
- char buf[2048]; /* XXX need to malloc */
+ static int buflen = 2048;
+ char *buf;
ns_opcode opcode;
ns_rr rr;
/*
* Print answer records.
*/
- sflag = (_res.pfcode & pflag);
- if (_res.pfcode && !sflag)
+ sflag = (statp->pfcode & pflag);
+ if (statp->pfcode && !sflag)
return;
- opcode = ns_msg_getflag(*handle, ns_f_opcode);
+ buf = malloc(buflen);
+ if (buf == NULL) {
+ fprintf(file, ";; memory allocation failure\n");
+ return;
+ }
+
+ opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode);
rrnum = 0;
for (;;) {
if (ns_parserr(handle, section, rrnum, &rr)) {
@@ -161,11 +167,11 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
fprintf(file, ";; ns_parserr: %s\n",
strerror(errno));
else if (rrnum > 0 && sflag != 0 &&
- (_res.pfcode & RES_PRF_HEAD1))
+ (statp->pfcode & RES_PRF_HEAD1))
putc('\n', file);
- return;
+ goto cleanup;
}
- if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
+ if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
fprintf(file, ";; %s SECTION:\n",
p_section(section, opcode));
if (section == ns_s_qd)
@@ -175,27 +181,32 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
p_class(ns_rr_class(rr)));
else {
n = ns_sprintrr(handle, &rr, NULL, NULL,
- buf, sizeof buf);
+ buf, buflen);
if (n < 0) {
+ if (errno == ENOSPC) {
+ free(buf);
+ buf = NULL;
+ if (buflen < 131072)
+ buf = malloc(buflen += 1024);
+ if (buf == NULL) {
+ fprintf(file,
+ ";; memory allocation failure\n");
+ return;
+ }
+ continue;
+ }
fprintf(file, ";; ns_sprintrr: %s\n",
strerror(errno));
- return;
+ goto cleanup;
}
fputs(buf, file);
fputc('\n', file);
}
rrnum++;
}
-}
-
-void
-p_query(const u_char *msg) {
- fp_query(msg, stdout);
-}
-
-void
-fp_query(const u_char *msg, FILE *file) {
- fp_nquery(msg, PACKETSZ, file);
+ cleanup:
+ if (buf != NULL)
+ free(buf);
}
/*
@@ -203,14 +214,11 @@ fp_query(const u_char *msg, FILE *file) {
* This is intended to be primarily a debugging routine.
*/
void
-fp_nquery(const u_char *msg, int len, FILE *file) {
+res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
ns_msg handle;
int qdcount, ancount, nscount, arcount;
u_int opcode, rcode, id;
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return;
-
if (ns_initparse(msg, len, &handle) < 0) {
fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
return;
@@ -226,13 +234,13 @@ fp_nquery(const u_char *msg, int len, FILE *file) {
/*
* Print header fields.
*/
- if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
+ if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
fprintf(file,
";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
- _res_opcodes[opcode], _res_resultcodes[rcode], id);
- if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
+ _res_opcodes[opcode], p_rcode(rcode), id);
+ if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
putc(';', file);
- if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
+ if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
fprintf(file, "; flags:");
if (ns_msg_getflag(handle, ns_f_qr))
fprintf(file, " qr");
@@ -251,7 +259,7 @@ fp_nquery(const u_char *msg, int len, FILE *file) {
if (ns_msg_getflag(handle, ns_f_cd))
fprintf(file, " cd");
}
- if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
+ if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
fprintf(file, "; %s: %d",
p_section(ns_s_qd, opcode), qdcount);
fprintf(file, ", %s: %d",
@@ -261,17 +269,17 @@ fp_nquery(const u_char *msg, int len, FILE *file) {
fprintf(file, ", %s: %d",
p_section(ns_s_ar, opcode), arcount);
}
- if ((!_res.pfcode) || (_res.pfcode &
+ if ((!statp->pfcode) || (statp->pfcode &
(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
putc('\n',file);
}
/*
* Print the various sections.
*/
- do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
- do_section(&handle, ns_s_an, RES_PRF_ANS, file);
- do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
- do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
+ do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
+ do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
+ do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
+ do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
if (qdcount == 0 && ancount == 0 &&
nscount == 0 && arcount == 0)
putc('\n', file);
@@ -290,6 +298,7 @@ p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
fputs(name, file);
return (cp + n);
}
+libresolv_hidden_def (p_cdnname)
const u_char *
p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
@@ -319,6 +328,7 @@ p_fqnname(cp, msg, msglen, name, namelen)
}
return (cp + n);
}
+libresolv_hidden_def (p_fqnname)
/* XXX: the rest of these functions need to become length-limited, too. */
@@ -339,6 +349,8 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
* that C_ANY is a qclass but not a class. (You can ask for records of class
* C_ANY, but you can't have any records of that class in the database.)
*/
+extern const struct res_sym __p_class_syms[];
+libresolv_hidden_proto (__p_class_syms)
const struct res_sym __p_class_syms[] = {
{C_IN, "IN"},
{C_CHAOS, "CHAOS"},
@@ -348,11 +360,12 @@ const struct res_sym __p_class_syms[] = {
{C_NONE, "NONE"},
{C_IN, (char *)0}
};
+libresolv_hidden_data_def (__p_class_syms)
/*
* Names of message sections.
*/
-const struct res_sym __p_default_section_syms[] = {
+const struct res_sym __p_default_section_syms[] attribute_hidden = {
{ns_s_qd, "QUERY"},
{ns_s_an, "ANSWER"},
{ns_s_ns, "AUTHORITY"},
@@ -360,7 +373,7 @@ const struct res_sym __p_default_section_syms[] = {
{0, (char *)0}
};
-const struct res_sym __p_update_section_syms[] = {
+const struct res_sym __p_update_section_syms[] attribute_hidden = {
{S_ZONE, "ZONE"},
{S_PREREQ, "PREREQUISITE"},
{S_UPDATE, "UPDATE"},
@@ -368,54 +381,101 @@ const struct res_sym __p_update_section_syms[] = {
{0, (char *)0}
};
+const struct res_sym __p_key_syms[] attribute_hidden = {
+ {NS_ALG_MD5RSA, "RSA", "RSA KEY with MD5 hash"},
+ {NS_ALG_DH, "DH", "Diffie Hellman"},
+ {NS_ALG_DSA, "DSA", "Digital Signature Algorithm"},
+ {NS_ALG_EXPIRE_ONLY, "EXPIREONLY", "No algorithm"},
+ {NS_ALG_PRIVATE_OID, "PRIVATE", "Algorithm obtained from OID"},
+ {0, NULL, NULL}
+};
+
+const struct res_sym __p_cert_syms[] attribute_hidden = {
+ {cert_t_pkix, "PKIX", "PKIX (X.509v3) Certificate"},
+ {cert_t_spki, "SPKI", "SPKI certificate"},
+ {cert_t_pgp, "PGP", "PGP certificate"},
+ {cert_t_url, "URL", "URL Private"},
+ {cert_t_oid, "OID", "OID Private"},
+ {0, NULL, NULL}
+};
+
/*
* Names of RR types and qtypes. Types and qtypes are the same, except
* that T_ANY is a qtype but not a type. (You can ask for records of type
* T_ANY, but you can't have any records of that type in the database.)
*/
+extern const struct res_sym __p_type_syms[];
+libresolv_hidden_proto (__p_type_syms)
const struct res_sym __p_type_syms[] = {
- {T_A, "A", "address"},
- {T_NS, "NS", "name server"},
- {T_MD, "MD", "mail destination (deprecated)"},
- {T_MF, "MF", "mail forwarder (deprecated)"},
- {T_CNAME, "CNAME", "canonical name"},
- {T_SOA, "SOA", "start of authority"},
- {T_MB, "MB", "mailbox"},
- {T_MG, "MG", "mail group member"},
- {T_MR, "MR", "mail rename"},
- {T_NULL, "NULL", "null"},
- {T_WKS, "WKS", "well-known service (deprecated)"},
- {T_PTR, "PTR", "domain name pointer"},
- {T_HINFO, "HINFO", "host information"},
- {T_MINFO, "MINFO", "mailbox information"},
- {T_MX, "MX", "mail exchanger"},
- {T_TXT, "TXT", "text"},
- {T_RP, "RP", "responsible person"},
- {T_AFSDB, "AFSDB", "DCE or AFS server"},
- {T_X25, "X25", "X25 address"},
- {T_ISDN, "ISDN", "ISDN address"},
- {T_RT, "RT", "router"},
- {T_NSAP, "NSAP", "nsap address"},
- {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
- {T_SIG, "SIG", "signature"},
- {T_KEY, "KEY", "key"},
- {T_PX, "PX", "mapping information"},
- {T_GPOS, "GPOS", "geographical position (withdrawn)"},
- {T_AAAA, "AAAA", "IPv6 address"},
- {T_LOC, "LOC", "location"},
- {T_NXT, "NXT", "next valid name (unimplemented)"},
- {T_EID, "EID", "endpoint identifier (unimplemented)"},
- {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
- {T_SRV, "SRV", "server selection"},
- {T_ATMA, "ATMA", "ATM address (unimplemented)"},
- {T_IXFR, "IXFR", "incremental zone transfer"},
- {T_AXFR, "AXFR", "zone transfer"},
- {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
- {T_MAILA, "MAILA", "mail agent (deprecated)"},
- {T_NAPTR, "NAPTR", "URN Naming Authority"},
- {T_ANY, "ANY", "\"any\""},
+ {ns_t_a, "A", "address"},
+ {ns_t_ns, "NS", "name server"},
+ {ns_t_md, "MD", "mail destination (deprecated)"},
+ {ns_t_mf, "MF", "mail forwarder (deprecated)"},
+ {ns_t_cname, "CNAME", "canonical name"},
+ {ns_t_soa, "SOA", "start of authority"},
+ {ns_t_mb, "MB", "mailbox"},
+ {ns_t_mg, "MG", "mail group member"},
+ {ns_t_mr, "MR", "mail rename"},
+ {ns_t_null, "NULL", "null"},
+ {ns_t_wks, "WKS", "well-known service (deprecated)"},
+ {ns_t_ptr, "PTR", "domain name pointer"},
+ {ns_t_hinfo, "HINFO", "host information"},
+ {ns_t_minfo, "MINFO", "mailbox information"},
+ {ns_t_mx, "MX", "mail exchanger"},
+ {ns_t_txt, "TXT", "text"},
+ {ns_t_rp, "RP", "responsible person"},
+ {ns_t_afsdb, "AFSDB", "DCE or AFS server"},
+ {ns_t_x25, "X25", "X25 address"},
+ {ns_t_isdn, "ISDN", "ISDN address"},
+ {ns_t_rt, "RT", "router"},
+ {ns_t_nsap, "NSAP", "nsap address"},
+ {ns_t_nsap_ptr, "NSAP_PTR", "domain name pointer"},
+ {ns_t_sig, "SIG", "signature"},
+ {ns_t_key, "KEY", "key"},
+ {ns_t_px, "PX", "mapping information"},
+ {ns_t_gpos, "GPOS", "geographical position (withdrawn)"},
+ {ns_t_aaaa, "AAAA", "IPv6 address"},
+ {ns_t_loc, "LOC", "location"},
+ {ns_t_nxt, "NXT", "next valid name (unimplemented)"},
+ {ns_t_eid, "EID", "endpoint identifier (unimplemented)"},
+ {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"},
+ {ns_t_srv, "SRV", "server selection"},
+ {ns_t_atma, "ATMA", "ATM address (unimplemented)"},
+ {ns_t_tsig, "TSIG", "transaction signature"},
+ {ns_t_ixfr, "IXFR", "incremental zone transfer"},
+ {ns_t_axfr, "AXFR", "zone transfer"},
+ {ns_t_zxfr, "ZXFR", "compressed zone transfer"},
+ {ns_t_mailb, "MAILB", "mailbox-related data (deprecated)"},
+ {ns_t_maila, "MAILA", "mail agent (deprecated)"},
+ {ns_t_naptr, "NAPTR", "URN Naming Authority"},
+ {ns_t_kx, "KX", "Key Exchange"},
+ {ns_t_cert, "CERT", "Certificate"},
+ {ns_t_any, "ANY", "\"any\""},
{0, NULL, NULL}
};
+libresolv_hidden_data_def (__p_type_syms)
+
+/*
+ * Names of DNS rcodes.
+ */
+const struct res_sym __p_rcode_syms[] attribute_hidden = {
+ {ns_r_noerror, "NOERROR", "no error"},
+ {ns_r_formerr, "FORMERR", "format error"},
+ {ns_r_servfail, "SERVFAIL", "server failed"},
+ {ns_r_nxdomain, "NXDOMAIN", "no such domain name"},
+ {ns_r_notimpl, "NOTIMP", "not implemented"},
+ {ns_r_refused, "REFUSED", "refused"},
+ {ns_r_yxdomain, "YXDOMAIN", "domain name exists"},
+ {ns_r_yxrrset, "YXRRSET", "rrset exists"},
+ {ns_r_nxrrset, "NXRRSET", "rrset doesn't exist"},
+ {ns_r_notauth, "NOTAUTH", "not authoritative"},
+ {ns_r_notzone, "NOTZONE", "Not in zone"},
+ {ns_r_max, "", ""},
+ {ns_r_badsig, "BADSIG", "bad signature"},
+ {ns_r_badkey, "BADKEY", "bad key"},
+ {ns_r_badtime, "BADTIME", "bad time"},
+ {0, NULL, NULL}
+};
int
sym_ston(const struct res_sym *syms, const char *name, int *success) {
@@ -443,11 +503,12 @@ sym_ntos(const struct res_sym *syms, int number, int *success) {
}
}
- sprintf(unname, "%d", number);
+ sprintf(unname, "%d", number); /* XXX nonreentrant */
if (success)
*success = 0;
return (unname);
}
+libresolv_hidden_def (sym_ntos)
const char *
sym_ntop(const struct res_sym *syms, int number, int *success) {
@@ -460,7 +521,7 @@ sym_ntop(const struct res_sym *syms, int number, int *success) {
return (syms->humanname);
}
}
- sprintf(unname, "%d", number);
+ sprintf(unname, "%d", number); /* XXX nonreentrant */
if (success)
*success = 0;
return (unname);
@@ -473,6 +534,7 @@ const char *
p_type(int type) {
return (sym_ntos(__p_type_syms, type, (int *)0));
}
+libresolv_hidden_def (p_type)
/*
* Return a string for the type.
@@ -499,6 +561,7 @@ const char *
p_class(int class) {
return (sym_ntos(__p_class_syms, class, (int *)0));
}
+libresolv_hidden_def (p_class)
/*
* Return a mnemonic for an option
@@ -520,27 +583,37 @@ p_option(u_long option) {
case RES_DNSRCH: return "dnsrch";
case RES_INSECURE1: return "insecure1";
case RES_INSECURE2: return "insecure2";
- case RES_NOALIASES: return "noaliases";
case RES_USE_INET6: return "inet6";
- case RES_NOTLDQUERY: return "no-tld-query";
- case RES_USE_EDNS0: return "edns0";
+ case RES_ROTATE: return "rotate";
+ case RES_NOCHECKNAME: return "no-check-names";
+ case RES_USEBSTRING: return "ip6-bytstring";
+ /* XXX nonreentrant */
default: sprintf(nbuf, "?0x%lx?", (u_long)option);
return (nbuf);
}
}
+libresolv_hidden_def (p_option)
/*
* Return a mnemonic for a time to live.
*/
const char *
p_time(u_int32_t value) {
- static char nbuf[40];
+ static char nbuf[40]; /* XXX nonreentrant */
if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
sprintf(nbuf, "%u", value);
return (nbuf);
}
+/*
+ * Return a string for the rcode.
+ */
+const char *
+p_rcode(int rcode) {
+ return (sym_ntos(__p_rcode_syms, rcode, (int *)0));
+}
+libresolv_hidden_def (p_rcode)
/*
* routines to convert between on-the-wire RR format and zone file format.
@@ -548,15 +621,16 @@ p_time(u_int32_t value) {
* by 60*60*1000 for that.
*/
-static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
- 1000000,10000000,100000000,1000000000};
+static const unsigned int poweroften[10]=
+ { 1, 10, 100, 1000, 10000, 100000,
+ 1000000,10000000,100000000,1000000000};
/* takes an XeY precision/size value, returns a string representation. */
static const char *
precsize_ntoa(prec)
u_int8_t prec;
{
- static char retbuf[sizeof "90000000.00"];
+ static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */
unsigned long val;
int mantissa, exponent;
@@ -572,24 +646,24 @@ precsize_ntoa(prec)
/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
static u_int8_t
precsize_aton(strptr)
- char **strptr;
+ const char **strptr;
{
unsigned int mval = 0, cmval = 0;
u_int8_t retval = 0;
- char *cp;
+ const char *cp;
int exponent;
int mantissa;
cp = *strptr;
- while (isdigit((unsigned char)*cp))
+ while (isdigit(*cp))
mval = mval * 10 + (*cp++ - '0');
if (*cp == '.') { /* centimeters */
cp++;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
cmval = (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
cmval += (*cp++ - '0');
}
}
@@ -614,53 +688,53 @@ precsize_aton(strptr)
/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
static u_int32_t
latlon2ul(latlonstrptr,which)
- char **latlonstrptr;
+ const char **latlonstrptr;
int *which;
{
- char *cp;
+ const char *cp;
u_int32_t retval;
int deg = 0, min = 0, secs = 0, secsfrac = 0;
cp = *latlonstrptr;
- while (isdigit((unsigned char)*cp))
+ while (isdigit(*cp))
deg = deg * 10 + (*cp++ - '0');
- while (isspace((unsigned char)*cp))
+ while (isspace(*cp))
cp++;
- if (!(isdigit((unsigned char)*cp)))
+ if (!(isdigit(*cp)))
goto fndhemi;
- while (isdigit((unsigned char)*cp))
+ while (isdigit(*cp))
min = min * 10 + (*cp++ - '0');
- while (isspace((unsigned char)*cp))
+ while (isspace(*cp))
cp++;
- if (!(isdigit((unsigned char)*cp)))
+ if (!(isdigit(*cp)))
goto fndhemi;
- while (isdigit((unsigned char)*cp))
+ while (isdigit(*cp))
secs = secs * 10 + (*cp++ - '0');
if (*cp == '.') { /* decimal seconds */
cp++;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
secsfrac = (*cp++ - '0') * 100;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
secsfrac += (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
secsfrac += (*cp++ - '0');
}
}
}
}
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ while (!isspace(*cp)) /* if any trailing garbage */
cp++;
- while (isspace((unsigned char)*cp))
+ while (isspace(*cp))
cp++;
fndhemi:
@@ -698,10 +772,10 @@ latlon2ul(latlonstrptr,which)
cp++; /* skip the hemisphere */
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ while (!isspace(*cp)) /* if any trailing garbage */
cp++;
- while (isspace((unsigned char)*cp)) /* move to next field */
+ while (isspace(*cp)) /* move to next field */
cp++;
*latlonstrptr = cp;
@@ -755,18 +829,18 @@ loc_aton(ascii, binary)
altsign = -1;
cp++;
}
-
+
if (*cp == '+')
cp++;
- while (isdigit((unsigned char)*cp))
+ while (isdigit(*cp))
altmeters = altmeters * 10 + (*cp++ - '0');
if (*cp == '.') { /* decimal meters */
cp++;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
altfrac = (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
+ if (isdigit(*cp)) {
altfrac += (*cp++ - '0');
}
}
@@ -774,21 +848,21 @@ loc_aton(ascii, binary)
alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
cp++;
- while (isspace((unsigned char)*cp) && (cp < maxcp))
+ while (isspace(*cp) && (cp < maxcp))
cp++;
if (cp >= maxcp)
goto defaults;
siz = precsize_aton(&cp);
-
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
cp++;
- while (isspace((unsigned char)*cp) && (cp < maxcp))
+ while (isspace(*cp) && (cp < maxcp))
cp++;
if (cp >= maxcp)
@@ -796,10 +870,10 @@ loc_aton(ascii, binary)
hp = precsize_aton(&cp);
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
cp++;
- while (isspace((unsigned char)*cp) && (cp < maxcp))
+ while (isspace(*cp) && (cp < maxcp))
cp++;
if (cp >= maxcp)
@@ -817,7 +891,7 @@ loc_aton(ascii, binary)
PUTLONG(latit,bcp);
PUTLONG(longit,bcp);
PUTLONG(alt,bcp);
-
+
return (16); /* size of RR in octets */
}
@@ -828,6 +902,8 @@ loc_ntoa(binary, ascii)
char *ascii;
{
static char *error = "?";
+ static char tmpbuf[sizeof
+"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
const u_char *cp = binary;
int latdeg, latmin, latsec, latsecfrac;
@@ -840,13 +916,14 @@ loc_ntoa(binary, ascii)
int32_t latval, longval, altval;
u_int32_t templ;
u_int8_t sizeval, hpval, vpval, versionval;
-
- char *sizestr, *hpstr, *vpstr;
- size_t len;
+ char *sizestr, *hpstr, *vpstr;
versionval = *cp++;
+ if (ascii == NULL)
+ ascii = tmpbuf;
+
if (versionval) {
(void) sprintf(ascii, "; error: unknown LOC RR version");
return (ascii);
@@ -903,21 +980,12 @@ loc_ntoa(binary, ascii)
altfrac = altval % 100;
altmeters = (altval / 100) * altsign;
- len = strlen (precsize_ntoa(sizeval)) + 1;
- if ((sizestr = malloc(len)) == NULL)
+ if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
sizestr = error;
- else
- memcpy (sizestr, precsize_ntoa(sizeval), len);
- len = strlen (precsize_ntoa(hpval)) + 1;
- if ((hpstr = malloc (len)) == NULL)
+ if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
hpstr = error;
- else
- memcpy (hpstr, precsize_ntoa(hpval), len);
- len = strlen (precsize_ntoa(vpval)) + 1;
- if ((vpstr = malloc (len)) == NULL)
+ if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
vpstr = error;
- else
- memcpy (vpstr, precsize_ntoa(vpval), len);
sprintf(ascii,
"%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
@@ -934,6 +1002,7 @@ loc_ntoa(binary, ascii)
return (ascii);
}
+libresolv_hidden_def (loc_ntoa)
/* Return the number of DNS hierarchy levels in the name. */
@@ -962,17 +1031,24 @@ dn_count_labels(const char *name) {
}
-/*
- * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+/*
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
* SIG records are required to be printed like this, by the Secure DNS RFC.
*/
char *
p_secstodate (u_long secs) {
+ /* XXX nonreentrant */
static char output[15]; /* YYYYMMDDHHMMSS and null */
time_t clock = secs;
struct tm *time;
-
+
+#ifdef HAVE_TIME_R
+ struct tm timebuf;
+
+ time = gmtime_r(&clock, &timebuf);
+#else
time = gmtime(&clock);
+#endif
time->tm_year += 1900;
time->tm_mon += 1;
sprintf(output, "%04d%02d%02d%02d%02d%02d",
@@ -980,24 +1056,3 @@ p_secstodate (u_long secs) {
time->tm_hour, time->tm_min, time->tm_sec);
return (output);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef fp_resstat
-__weak_reference(__fp_resstat, fp_resstat);
-#undef p_query
-__weak_reference(__p_query, p_query);
-#undef p_fqnname
-__weak_reference(__p_fqnname, p_fqnname);
-#undef sym_ston
-__weak_reference(__sym_ston, sym_ston);
-#undef sym_ntos
-__weak_reference(__sym_ntos, sym_ntos);
-#undef sym_ntop
-__weak_reference(__sym_ntop, sym_ntop);
-#undef dn_count_labels
-__weak_reference(__dn_count_labels, dn_count_labels);
-#undef p_secstodate
-__weak_reference(__p_secstodate, p_secstodate);
diff --git a/newlib/libc/sys/linux/net/res_debug.h b/newlib/libc/sys/linux/net/res_debug.h
new file mode 100644
index 000000000..4a0aa99ab
--- /dev/null
+++ b/newlib/libc/sys/linux/net/res_debug.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 1999 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.
+ */
+
+#ifndef _RES_DEBUG_H_
+#define _RES_DEBUG_H_
+
+#ifndef DEBUG
+# define Dprint(cond, args) /*empty*/
+# define DprintQ(cond, args, query, size) /*empty*/
+# define Aerror(statp, file, string, error, address) /*empty*/
+# define Perror(statp, file, string, error) /*empty*/
+#else
+# define Dprint(cond, args) if (cond) {fprintf args;} else {}
+# define DprintQ(cond, args, query, size) if (cond) {\
+ fprintf args;\
+ res_pquery(statp, query, size, stdout);\
+ } else {}
+#endif
+
+#endif /* _RES_DEBUG_H_ */
diff --git a/newlib/libc/sys/linux/net/res_hconf.c b/newlib/libc/sys/linux/net/res_hconf.c
new file mode 100644
index 000000000..ad1594040
--- /dev/null
+++ b/newlib/libc/sys/linux/net/res_hconf.c
@@ -0,0 +1,676 @@
+/* Copyright (C) 1993, 1995-2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger (davidm@azstarnet.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file provides a Linux /etc/host.conf compatible front end to
+ the various name resolvers (/etc/hosts, named, NIS server, etc.).
+ Though mostly compatibly, the following differences exist compared
+ to the original implementation:
+
+ - new command "spoof" takes an arguments like RESOLV_SPOOF_CHECK
+ environment variable (i.e., `off', `nowarn', or `warn').
+
+ - line comments can appear anywhere (not just at the beginning of
+ a line)
+*/
+
+#include <assert.h>
+#include <errno.h>
+#include <ctype.h>
+#include <libintl.h>
+#include <memory.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#define _IO_MTSAFE_IO
+#include <bits/libc-lock.h>
+#include "ifreq.h"
+#include "res_hconf.h"
+#include "local.h"
+#ifdef USE_IN_LIBIO
+# include <wchar.h>
+#endif
+
+#define _PATH_HOSTCONF "/etc/host.conf"
+
+/* Environment vars that all user to override default behavior: */
+#define ENV_HOSTCONF "RESOLV_HOST_CONF"
+#define ENV_SERVORDER "RESOLV_SERV_ORDER"
+#define ENV_SPOOF "RESOLV_SPOOF_CHECK"
+#define ENV_TRIM_OVERR "RESOLV_OVERRIDE_TRIM_DOMAINS"
+#define ENV_TRIM_ADD "RESOLV_ADD_TRIM_DOMAINS"
+#define ENV_MULTI "RESOLV_MULTI"
+#define ENV_REORDER "RESOLV_REORDER"
+
+static const char *arg_service_list (const char *, int, const char *,
+ unsigned int);
+static const char *arg_trimdomain_list (const char *, int, const char *,
+ unsigned int);
+static const char *arg_spoof (const char *, int, const char *, unsigned int);
+static const char *arg_bool (const char *, int, const char *, unsigned int);
+
+static struct cmd
+{
+ const char *name;
+ const char *(*parse_args) (const char * filename, int line_num,
+ const char * args, unsigned int arg);
+ unsigned int arg;
+} cmd[] =
+{
+ {"order", arg_service_list, 0},
+ {"trim", arg_trimdomain_list, 0},
+ {"spoof", arg_spoof, 0},
+ {"multi", arg_bool, HCONF_FLAG_MULTI},
+ {"nospoof", arg_bool, HCONF_FLAG_SPOOF},
+ {"spoofalert", arg_bool, HCONF_FLAG_SPOOFALERT},
+ {"reorder", arg_bool, HCONF_FLAG_REORDER}
+};
+
+/* Structure containing the state. */
+struct hconf _res_hconf;
+
+/* Skip white space. */
+static const char *
+skip_ws (const char *str)
+{
+ while (isspace (*str)) ++str;
+ return str;
+}
+
+
+/* Skip until whitespace, comma, end of line, or comment character. */
+static const char *
+skip_string (const char *str)
+{
+ while (*str && !isspace (*str) && *str != '#' && *str != ',')
+ ++str;
+ return str;
+}
+
+
+static const char *
+arg_service_list (const char *fname, int line_num, const char *args,
+ unsigned int arg)
+{
+ enum Name_Service service;
+ const char *start;
+ size_t len;
+ size_t i;
+ static struct
+ {
+ const char * name;
+ enum Name_Service service;
+ } svcs[] =
+ {
+ {"bind", SERVICE_BIND},
+ {"hosts", SERVICE_HOSTS},
+ {"nis", SERVICE_NIS},
+ };
+
+ do
+ {
+ start = args;
+ args = skip_string (args);
+ len = args - start;
+
+ service = SERVICE_NONE;
+ for (i = 0; i < sizeof (svcs) / sizeof (svcs[0]); ++i)
+ {
+ if (strncasecmp (start, svcs[i].name, len) == 0
+ && len == strlen (svcs[i].name))
+ {
+ service = svcs[i].service;
+ break;
+ }
+ }
+ if (service == SERVICE_NONE)
+ {
+ char *buf;
+
+ if (asprintf (&buf,
+ _("%s: line %d: expected service, found `%s'\n"),
+ fname, line_num, start) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ if (_res_hconf.num_services >= SERVICE_MAX)
+ {
+ char *buf;
+
+ if (asprintf (&buf, _("\
+%s: line %d: cannot specify more than %d services"),
+ fname, line_num, SERVICE_MAX) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ _res_hconf.service[_res_hconf.num_services++] = service;
+
+ args = skip_ws (args);
+ switch (*args)
+ {
+ case ',':
+ case ';':
+ case ':':
+ args = skip_ws (++args);
+ if (!*args || *args == '#')
+ {
+ char *buf;
+
+ if (asprintf (&buf, _("\
+%s: line %d: list delimiter not followed by keyword"),
+ fname, line_num) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ default:
+ break;
+ }
+ }
+ while (*args && *args != '#');
+ return args;
+}
+
+
+static const char *
+arg_trimdomain_list (const char *fname, int line_num, const char *args,
+ unsigned int flag)
+{
+ const char * start;
+ size_t len;
+
+ do
+ {
+ start = args;
+ args = skip_string (args);
+ len = args - start;
+
+ if (_res_hconf.num_trimdomains >= TRIMDOMAINS_MAX)
+ {
+ char *buf;
+
+ if (asprintf (&buf, _("\
+%s: line %d: cannot specify more than %d trim domains"),
+ fname, line_num, TRIMDOMAINS_MAX) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ _res_hconf.trimdomain[_res_hconf.num_trimdomains++] =
+ strndup (start, len);
+ args = skip_ws (args);
+ switch (*args)
+ {
+ case ',': case ';': case ':':
+ args = skip_ws (++args);
+ if (!*args || *args == '#')
+ {
+ char *buf;
+
+ if (asprintf (&buf, _("\
+%s: line %d: list delimiter not followed by domain"),
+ fname, line_num) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ default:
+ break;
+ }
+ }
+ while (*args && *args != '#');
+ return args;
+}
+
+
+static const char *
+arg_spoof (const char *fname, int line_num, const char *args, unsigned flag)
+{
+ const char *start = args;
+ size_t len;
+
+ args = skip_string (args);
+ len = args - start;
+
+ if (len == 3 && strncasecmp (start, "off", len) == 0)
+ _res_hconf.flags &= ~(HCONF_FLAG_SPOOF | HCONF_FLAG_SPOOFALERT);
+ else
+ {
+ _res_hconf.flags |= (HCONF_FLAG_SPOOF | HCONF_FLAG_SPOOFALERT);
+ if ((len == 6 && strncasecmp (start, "nowarn", len) == 0)
+ || !(len == 4 && strncasecmp (start, "warn", len) == 0))
+ _res_hconf.flags &= ~HCONF_FLAG_SPOOFALERT;
+ }
+ return args;
+}
+
+
+static const char *
+arg_bool (const char *fname, int line_num, const char *args, unsigned flag)
+{
+ if (strncasecmp (args, "on", 2) == 0)
+ {
+ args += 2;
+ _res_hconf.flags |= flag;
+ }
+ else if (strncasecmp (args, "off", 3) == 0)
+ {
+ args += 3;
+ _res_hconf.flags &= ~flag;
+ }
+ else
+ {
+ char *buf;
+
+ if (asprintf (&buf,
+ _("%s: line %d: expected `on' or `off', found `%s'\n"),
+ fname, line_num, args) < 0)
+ return 0;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return 0;
+ }
+ return args;
+}
+
+
+static void
+parse_line (const char *fname, int line_num, const char *str)
+{
+ const char *start;
+ struct cmd *c = 0;
+ size_t len;
+ size_t i;
+
+ str = skip_ws (str);
+
+ /* skip line comment and empty lines: */
+ if (*str == '\0' || *str == '#') return;
+
+ start = str;
+ str = skip_string (str);
+ len = str - start;
+
+ for (i = 0; i < sizeof (cmd) / sizeof (cmd[0]); ++i)
+ {
+ if (strncasecmp (start, cmd[i].name, len) == 0
+ && strlen (cmd[i].name) == len)
+ {
+ c = &cmd[i];
+ break;
+ }
+ }
+ if (c == NULL)
+ {
+ char *buf;
+
+ if (asprintf (&buf, _("%s: line %d: bad command `%s'\n"),
+ fname, line_num, start) < 0)
+ return;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ return;
+ }
+
+ /* process args: */
+ str = skip_ws (str);
+ str = (*c->parse_args) (fname, line_num, str, c->arg);
+ if (!str)
+ return;
+
+ /* rest of line must contain white space or comment only: */
+ while (*str)
+ {
+ if (!isspace (*str)) {
+ if (*str != '#')
+ {
+ char *buf;
+
+ if (asprintf (&buf,
+ _("%s: line %d: ignoring trailing garbage `%s'\n"),
+ fname, line_num, str) < 0)
+ break;
+
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+#endif
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+ break;
+ }
+ ++str;
+ }
+}
+
+
+static void
+do_init (void)
+{
+ const char *hconf_name;
+ int line_num = 0;
+ char buf[256], *envval;
+ FILE *fp;
+
+ memset (&_res_hconf, '\0', sizeof (_res_hconf));
+
+ hconf_name = getenv (ENV_HOSTCONF);
+ if (hconf_name == NULL)
+ hconf_name = _PATH_HOSTCONF;
+
+ fp = fopen (hconf_name, "rc");
+ if (!fp)
+ /* make up something reasonable: */
+ _res_hconf.service[_res_hconf.num_services++] = SERVICE_BIND;
+ else
+ {
+ /* No threads using this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ while (fgets (buf, sizeof (buf), fp))
+ {
+ char *tmp;
+ ++line_num;
+ tmp = strchr (buf, '\n');
+ if (tmp != NULL)
+ *tmp = '\0';
+ parse_line (hconf_name, line_num, buf);
+ }
+ fclose (fp);
+ }
+
+ envval = getenv (ENV_SERVORDER);
+ if (envval)
+ {
+ _res_hconf.num_services = 0;
+ arg_service_list (ENV_SERVORDER, 1, envval, 0);
+ }
+
+ envval = getenv (ENV_SPOOF);
+ if (envval)
+ arg_spoof (ENV_SPOOF, 1, envval, 0);
+
+ envval = getenv (ENV_MULTI);
+ if (envval)
+ arg_bool (ENV_MULTI, 1, envval, HCONF_FLAG_MULTI);
+
+ envval = getenv (ENV_REORDER);
+ if (envval)
+ arg_bool (ENV_REORDER, 1, envval, HCONF_FLAG_REORDER);
+
+ envval = getenv (ENV_TRIM_ADD);
+ if (envval)
+ arg_trimdomain_list (ENV_TRIM_ADD, 1, envval, 0);
+
+ envval = getenv (ENV_TRIM_OVERR);
+ if (envval)
+ {
+ _res_hconf.num_trimdomains = 0;
+ arg_trimdomain_list (ENV_TRIM_OVERR, 1, envval, 0);
+ }
+
+ _res_hconf.initialized = 1;
+}
+
+
+/* Initialize hconf datastructure by reading host.conf file and
+ environment variables. */
+void
+_res_hconf_init (void)
+{
+ __libc_once_define (static, once);
+
+ __libc_once (once, do_init);
+}
+
+
+/* List of known interfaces. */
+libc_freeres_ptr (
+static struct netaddr
+{
+ int addrtype;
+ union
+ {
+ struct
+ {
+ u_int32_t addr;
+ u_int32_t mask;
+ } ipv4;
+ } u;
+} *ifaddrs);
+
+/* We need to protect the dynamic buffer handling. */
+__libc_lock_define_initialized (static, lock);
+
+/* Reorder addresses returned in a hostent such that the first address
+ is an address on the local subnet, if there is such an address.
+ Otherwise, nothing is changed.
+
+ Note that this function currently only handles IPv4 addresses. */
+
+void
+_res_hconf_reorder_addrs (struct hostent *hp)
+{
+#if defined SIOCGIFCONF && defined SIOCGIFNETMASK
+ int i, j;
+ /* Number of interfaces. */
+ static int num_ifs = -1;
+
+ /* Only reorder if we're supposed to. */
+ if ((_res_hconf.flags & HCONF_FLAG_REORDER) == 0)
+ return;
+
+ /* Can't deal with anything but IPv4 for now... */
+ if (hp->h_addrtype != AF_INET)
+ return;
+
+ if (num_ifs <= 0)
+ {
+ struct ifreq *ifr, *cur_ifr;
+ int sd, num, i;
+ /* Save errno. */
+ int save = errno;
+
+ /* Initialize interface table. */
+
+ num_ifs = 0;
+
+ /* The SIOCGIFNETMASK ioctl will only work on an AF_INET socket. */
+ sd = socket (AF_INET, SOCK_DGRAM, 0);
+ if (sd < 0)
+ return;
+
+ /* Get lock. */
+ __libc_lock_lock (lock);
+
+ /* Get a list of interfaces. */
+ __ifreq (&ifr, &num, sd);
+ if (!ifr)
+ goto cleanup;
+
+ ifaddrs = malloc (num * sizeof (ifaddrs[0]));
+ if (!ifaddrs)
+ goto cleanup1;
+
+ /* Copy usable interfaces in ifaddrs structure. */
+ for (cur_ifr = ifr, i = 0; i < num; cur_ifr = __if_nextreq (cur_ifr), ++i)
+ {
+ if (cur_ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+
+ ifaddrs[num_ifs].addrtype = AF_INET;
+ ifaddrs[num_ifs].u.ipv4.addr =
+ ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;
+
+ if (ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
+ continue;
+
+ ifaddrs[num_ifs].u.ipv4.mask =
+ ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;
+
+ /* Now we're committed to this entry. */
+ ++num_ifs;
+ }
+ /* Just keep enough memory to hold all the interfaces we want. */
+ ifaddrs = realloc (ifaddrs, num_ifs * sizeof (ifaddrs[0]));
+ assert (ifaddrs != NULL);
+
+ cleanup1:
+ __if_freereq (ifr, num);
+
+ cleanup:
+ /* Release lock, preserve error value, and close socket. */
+ save = errno;
+ __libc_lock_unlock (lock);
+ close (sd);
+ }
+
+ if (num_ifs == 0)
+ return;
+
+ /* Find an address for which we have a direct connection. */
+ for (i = 0; hp->h_addr_list[i]; ++i)
+ {
+ struct in_addr *haddr = (struct in_addr *) hp->h_addr_list[i];
+
+ for (j = 0; j < num_ifs; ++j)
+ {
+ u_int32_t if_addr = ifaddrs[j].u.ipv4.addr;
+ u_int32_t if_netmask = ifaddrs[j].u.ipv4.mask;
+
+ if (((haddr->s_addr ^ if_addr) & if_netmask) == 0)
+ {
+ void *tmp;
+
+ tmp = hp->h_addr_list[i];
+ hp->h_addr_list[i] = hp->h_addr_list[0];
+ hp->h_addr_list[0] = tmp;
+ return;
+ }
+ }
+ }
+#endif /* defined(SIOCGIFCONF) && ... */
+}
+
+
+/* If HOSTNAME has a postfix matching any of the trimdomains, trim away
+ that postfix. Notice that HOSTNAME is modified inplace. Also, the
+ original code applied all trimdomains in order, meaning that the
+ same domainname could be trimmed multiple times. I believe this
+ was unintentional. */
+void
+_res_hconf_trim_domain (char *hostname)
+{
+ size_t hostname_len, trim_len;
+ int i;
+
+ hostname_len = strlen (hostname);
+
+ for (i = 0; i < _res_hconf.num_trimdomains; ++i)
+ {
+ const char *trim = _res_hconf.trimdomain[i];
+
+ trim_len = strlen (trim);
+ if (hostname_len > trim_len
+ && strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
+ {
+ hostname[hostname_len - trim_len] = '\0';
+ break;
+ }
+ }
+}
+
+
+/* Trim all hostnames/aliases in HP according to the trimdomain list.
+ Notice that HP is modified inplace! */
+void
+_res_hconf_trim_domains (struct hostent *hp)
+{
+ int i;
+
+ if (_res_hconf.num_trimdomains == 0)
+ return;
+
+ _res_hconf_trim_domain (hp->h_name);
+ for (i = 0; hp->h_aliases[i]; ++i)
+ _res_hconf_trim_domain (hp->h_aliases[i]);
+}
diff --git a/newlib/libc/sys/linux/net/res_hconf.h b/newlib/libc/sys/linux/net/res_hconf.h
new file mode 100644
index 000000000..77eeca4de
--- /dev/null
+++ b/newlib/libc/sys/linux/net/res_hconf.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger (davidm@azstarnet.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _RES_HCONF_H_
+#define _RES_HCONF_H_
+
+#include <netdb.h>
+
+#define TRIMDOMAINS_MAX 4
+
+enum Name_Service
+{
+ SERVICE_NONE = 0,
+ SERVICE_BIND, SERVICE_HOSTS, SERVICE_NIS,
+ SERVICE_MAX
+};
+
+struct hconf
+{
+ int initialized;
+ int num_services;
+ enum Name_Service service[SERVICE_MAX];
+ int num_trimdomains;
+ const char *trimdomain[TRIMDOMAINS_MAX];
+ unsigned int flags;
+# define HCONF_FLAG_INITED (1 << 0) /* initialized? */
+# define HCONF_FLAG_SPOOF (1 << 1) /* refuse spoofed addresses */
+# define HCONF_FLAG_SPOOFALERT (1 << 2) /* syslog warning of spoofed */
+# define HCONF_FLAG_REORDER (1 << 3) /* list best address first */
+# define HCONF_FLAG_MULTI (1 << 4) /* see comments for gethtbyname() */
+};
+extern struct hconf _res_hconf;
+
+extern void _res_hconf_init (void);
+extern void _res_hconf_trim_domain (char *domain);
+extern void _res_hconf_trim_domains (struct hostent *hp);
+extern void _res_hconf_reorder_addrs (struct hostent *hp);
+
+#endif /* _RES_HCONF_H_ */
diff --git a/newlib/libc/sys/linux/net/res_init.c b/newlib/libc/sys/linux/net/res_init.c
index 21f2696cd..81b06e710 100644
--- a/newlib/libc/sys/linux/net/res_init.c
+++ b/newlib/libc/sys/linux/net/res_init.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 1985, 1989, 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -52,7 +48,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -69,53 +65,56 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
-static char orig_rcsid[] = "From: Id: res_init.c,v 8.7 1996/11/18 09:10:04 vixie Exp $";
+static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
+static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
+#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
+
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+
#include <ctype.h>
-#include <resolv.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <netdb.h>
-#include "res_config.h"
+#include <not-cancel.h>
+#include "local.h"
+#include <resolv.h>
+
+/* Options. Should all be left alone. */
+#define RESOLVSORT
+#define RFC1535
+/* #undef DEBUG */
-static void res_setoptions(char *, char *);
+static void res_setoptions (res_state, const char *, const char *)
+ internal_function;
#ifdef RESOLVSORT
-static const char sort_mask[] = "/&";
-#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
-static u_int32_t net_mask(struct in_addr);
+static const char sort_mask_chars[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask_chars, ch) != NULL)
+static u_int32_t net_mask (struct in_addr) __THROW;
#endif
-#if !defined(isascii) /* XXX - could be a function */
+#if !defined(isascii) /* XXX - could be a function */
# define isascii(c) (!(c & 0200))
#endif
+#ifdef _LIBC
+unsigned long long int __res_initstamp attribute_hidden;
+#endif
+
/*
* Resolver state default settings.
*/
-struct __res_state _res
-# if defined(__BIND_RES_TEXT)
- = { RES_TIMEOUT, } /* Motorola, et al. */
-# endif
- ;
-
-struct __res_state_ext _res_ext;
-
/*
* Set up default settings. If the configuration file exist, the values
* there will have precedence. Otherwise, the server address is set to
@@ -126,7 +125,7 @@ struct __res_state_ext _res_ext;
* since it was noted that INADDR_ANY actually meant ``the first interface
* you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
* it had to be "up" in order for you to reach your own name server. It
- * was later decided that since the recommended practice is to always
+ * was later decided that since the recommended practice is to always
* install local static routes through 127.0.0.1 for all your network
* interfaces, that we could solve this problem without a code change.
*
@@ -138,13 +137,26 @@ struct __res_state_ext _res_ext;
* Return 0 if completes successfully, -1 on error
*/
int
-res_init()
-{
- FILE *fp;
- char *cp, **pp;
- int n;
- char buf[MAXDNAME];
+res_ninit(res_state statp) {
+ extern int __res_vinit(res_state, int);
+
+ return (__res_vinit(statp, 0));
+}
+#ifdef _LIBC
+libc_hidden_def (__res_ninit)
+#endif
+
+/* This function has to be reachable by res_data.c but not publically. */
+int
+__res_vinit(res_state statp, int preinit) {
+ register FILE *fp;
+ register char *cp, **pp;
+ register int n;
+ char buf[BUFSIZ];
int nserv = 0; /* number of nameserver records read from file */
+#ifdef _LIBC
+ int nservall = 0; /* number of NS records read, nserv IPv4 only */
+#endif
int haveenv = 0;
int havesearch = 0;
#ifdef RESOLVSORT
@@ -154,59 +166,45 @@ res_init()
#ifndef RFC1535
int dots;
#endif
- int sin_len;
-
- /*
- * These three fields used to be statically initialized. This made
- * it hard to use this code in a shared library. It is necessary,
- * now that we're doing dynamic initialization here, that we preserve
- * the old semantics: if an application modifies one of these three
- * fields of _res before res_init() is called, res_init() will not
- * alter them. Of course, if an application is setting them to
- * _zero_ before calling res_init(), hoping to override what used
- * to be the static default, we can't detect it and unexpected results
- * will follow. Zero for any of these fields would make no sense,
- * so one can safely assume that the applications were already getting
- * unexpected results.
- *
- * _res.options is tricky since some apps were known to diddle the bits
- * before res_init() was first called. We can't replicate that semantic
- * with dynamic initialization (they may have turned bits off that are
- * set in RES_DEFAULT). Our solution is to declare such applications
- * "broken". They could fool us by setting RES_INIT but none do (yet).
- */
- if (!_res.retrans)
- _res.retrans = RES_TIMEOUT;
- if (!_res.retry)
- _res.retry = 4;
- if (!(_res.options & RES_INIT))
- _res.options = RES_DEFAULT;
-
- /*
- * This one used to initialize implicitly to zero, so unless the app
- * has set it to something in particular, we can randomize it now.
- */
- if (!_res.id)
- _res.id = res_randomid();
+#ifdef _LIBC
+ statp->_u._ext.initstamp = __res_initstamp;
+#endif
+
+ if (!preinit) {
+ statp->retrans = RES_TIMEOUT;
+ statp->retry = RES_DFLRETRY;
+ statp->options = RES_DEFAULT;
+ statp->id = res_randomid();
+ }
#ifdef USELOOPBACK
- _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+ statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
#else
- _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+ statp->nsaddr.sin_addr.s_addr = INADDR_ANY;
+#endif
+ statp->nsaddr.sin_family = AF_INET;
+ statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
+ statp->nscount = 1;
+ statp->ndots = 1;
+ statp->pfcode = 0;
+ statp->_vcsock = -1;
+ statp->_flags = 0;
+ statp->qhook = NULL;
+ statp->rhook = NULL;
+ statp->_u._ext.nsinit = 0;
+ statp->_u._ext.nscount = 0;
+#ifdef _LIBC
+ statp->_u._ext.nscount6 = 0;
+ for (n = 0; n < MAXNS; n++) {
+ statp->_u._ext.nsaddrs[n] = NULL;
+ statp->_u._ext.nsmap[n] = MAXNS;
+ }
#endif
- _res.nsaddr.sin_family = AF_INET;
- _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
- sin_len = sizeof(struct sockaddr_in);
- if (sizeof(_res_ext.nsaddr) >= sin_len)
- memcpy(&_res_ext.nsaddr, &_res.nsaddr, sin_len);
- _res.nscount = 1;
- _res.ndots = 1;
- _res.pfcode = 0;
/* Allow user to override the local domain definition */
- if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) {
- (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
- _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+ if ((cp = getenv("LOCALDOMAIN")) != NULL) {
+ (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+ statp->defdname[sizeof(statp->defdname) - 1] = '\0';
haveenv++;
/*
@@ -216,10 +214,10 @@ res_init()
* one that they want to use as an individual (even more
* important now that the rfc1535 stuff restricts searches)
*/
- cp = _res.defdname;
- pp = _res.dnsrch;
+ cp = statp->defdname;
+ pp = statp->dnsrch;
*pp++ = cp;
- for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
if (*cp == '\n') /* silly backwards compat */
break;
else if (*cp == ' ' || *cp == '\t') {
@@ -243,7 +241,9 @@ res_init()
(line[sizeof(name) - 1] == ' ' || \
line[sizeof(name) - 1] == '\t'))
- if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+ if ((fp = fopen(_PATH_RESCONF, "rc")) != NULL) {
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
/* read the config file */
while (fgets(buf, sizeof(buf), fp) != NULL) {
/* skip comments */
@@ -258,9 +258,9 @@ res_init()
cp++;
if ((*cp == '\0') || (*cp == '\n'))
continue;
- strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
- _res.defdname[sizeof(_res.defdname) - 1] = '\0';
- if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
+ strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+ statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+ if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
*cp = '\0';
havesearch = 0;
continue;
@@ -274,18 +274,18 @@ res_init()
cp++;
if ((*cp == '\0') || (*cp == '\n'))
continue;
- strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
- _res.defdname[sizeof(_res.defdname) - 1] = '\0';
- if ((cp = strchr(_res.defdname, '\n')) != NULL)
+ strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+ statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+ if ((cp = strchr(statp->defdname, '\n')) != NULL)
*cp = '\0';
/*
* Set search list to be blank-separated strings
* on rest of line.
*/
- cp = _res.defdname;
- pp = _res.dnsrch;
+ cp = statp->defdname;
+ pp = statp->dnsrch;
*pp++ = cp;
- for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
if (*cp == ' ' || *cp == '\t') {
*cp = 0;
n = 1;
@@ -303,54 +303,53 @@ res_init()
continue;
}
/* read nameservers to query */
+#ifdef _LIBC
+ if (MATCH(buf, "nameserver") && nservall < MAXNS) {
+#else
if (MATCH(buf, "nameserver") && nserv < MAXNS) {
- char *q;
- struct addrinfo hints, *res;
- char pbuf[NI_MAXSERV];
+#endif
+ struct in_addr a;
cp = buf + sizeof("nameserver") - 1;
while (*cp == ' ' || *cp == '\t')
cp++;
- if ((*cp == '\0') || (*cp == '\n'))
- continue;
- for (q = cp; *q; q++) {
- if (isspace(*q)) {
- *q = '\0';
- break;
- }
- }
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_NUMERICHOST;
- hints.ai_socktype = SOCK_DGRAM;
- snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT);
- if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
- res->ai_next == NULL) {
- if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) {
- memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr,
- res->ai_addrlen);
- } else {
- memset(&_res_ext.nsaddr_list[nserv], 0,
- sizeof(_res_ext.nsaddr_list[nserv]));
- }
- if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) {
- memcpy(&_res.nsaddr_list[nserv], res->ai_addr,
- res->ai_addrlen);
- } else {
- memset(&_res.nsaddr_list[nserv], 0,
- sizeof(_res.nsaddr_list[nserv]));
- }
+ if ((*cp != '\0') && (*cp != '\n')
+ && inet_aton(cp, &a)) {
+ statp->nsaddr_list[nserv].sin_addr = a;
+ statp->nsaddr_list[nserv].sin_family = AF_INET;
+ statp->nsaddr_list[nserv].sin_port =
+ htons(NAMESERVER_PORT);
nserv++;
+#ifdef _LIBC
+ nservall++;
+ } else {
+ struct in6_addr a6;
+ char *el;
+
+ if ((el = strchr(cp, '\n')) != NULL)
+ *el = '\0';
+ if ((*cp != '\0') &&
+ (inet_pton(AF_INET6, cp, &a6) > 0)) {
+ struct sockaddr_in6 *sa6;
+
+ sa6 = malloc(sizeof(*sa6));
+ if (sa6 != NULL) {
+ sa6->sin6_addr = a6;
+ sa6->sin6_family = AF_INET6;
+ sa6->sin6_port = htons(NAMESERVER_PORT);
+ statp->_u._ext.nsaddrs[nservall] = sa6;
+ statp->_u._ext.nssocks[nservall] = -1;
+ statp->_u._ext.nsmap[nservall] = MAXNS + 1;
+ nservall++;
+ }
+ }
+#endif
}
- if (res)
- freeaddrinfo(res);
continue;
}
#ifdef RESOLVSORT
if (MATCH(buf, "sortlist")) {
struct in_addr a;
- struct in6_addr a6;
- int m, i;
- u_char *u;
cp = buf + sizeof("sortlist") - 1;
while (nsort < MAXRESOLVSORT) {
@@ -365,7 +364,7 @@ res_init()
n = *cp;
*cp = 0;
if (inet_aton(net, &a)) {
- _res.sort_list[nsort].addr = a;
+ statp->sort_list[nsort].addr = a;
if (ISSORTMASK(n)) {
*cp++ = n;
net = cp;
@@ -375,65 +374,15 @@ res_init()
n = *cp;
*cp = 0;
if (inet_aton(net, &a)) {
- _res.sort_list[nsort].mask = a.s_addr;
+ statp->sort_list[nsort].mask = a.s_addr;
} else {
- _res.sort_list[nsort].mask =
- net_mask(_res.sort_list[nsort].addr);
+ statp->sort_list[nsort].mask =
+ net_mask(statp->sort_list[nsort].addr);
}
} else {
- _res.sort_list[nsort].mask =
- net_mask(_res.sort_list[nsort].addr);
- }
- _res_ext.sort_list[nsort].af = AF_INET;
- _res_ext.sort_list[nsort].addr.ina =
- _res.sort_list[nsort].addr;
- _res_ext.sort_list[nsort].mask.ina.s_addr =
- _res.sort_list[nsort].mask;
- nsort++;
- }
- else if (inet_pton(AF_INET6, net, &a6) == 1) {
-
- _res_ext.sort_list[nsort].af = AF_INET6;
- _res_ext.sort_list[nsort].addr.in6a = a6;
- u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a;
- *cp++ = n;
- net = cp;
- while (*cp && *cp != ';' &&
- isascii(*cp) && !isspace(*cp))
- cp++;
- m = n;
- n = *cp;
- *cp = 0;
- switch (m) {
- case '/':
- m = atoi(net);
- break;
- case '&':
- if (inet_pton(AF_INET6, net, u) == 1) {
- m = -1;
- break;
- }
- /*FALLTHROUGH*/
- default:
- m = sizeof(struct in6_addr) * NBBY;
- break;
+ statp->sort_list[nsort].mask =
+ net_mask(statp->sort_list[nsort].addr);
}
- if (m >= 0) {
- for (i = 0; i < sizeof(struct in6_addr); i++) {
- if (m <= 0) {
- *u = 0;
- } else {
- m -= NBBY;
- *u = (u_char)~0;
- if (m < 0)
- *u <<= -m;
- }
- u++;
- }
- }
- _res.sort_list[nsort].addr.s_addr =
- (u_int32_t)0xffffffff;
- _res.sort_list[nsort].mask = (u_int32_t)0xffffffff;
nsort++;
}
*cp = n;
@@ -442,46 +391,50 @@ res_init()
}
#endif
if (MATCH(buf, "options")) {
- res_setoptions(buf + sizeof("options") - 1, "conf");
+ res_setoptions(statp, buf + sizeof("options") - 1, "conf");
continue;
}
}
- if (nserv > 1)
- _res.nscount = nserv;
+ if (nserv > 1)
+ statp->nscount = nserv;
+#ifdef _LIBC
+ if (nservall - nserv > 0)
+ statp->_u._ext.nscount6 = nservall - nserv;
+#endif
#ifdef RESOLVSORT
- _res.nsort = nsort;
+ statp->nsort = nsort;
#endif
(void) fclose(fp);
}
- if (_res.defdname[0] == 0 &&
- gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
+ if (statp->defdname[0] == 0 &&
+ __gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
(cp = strchr(buf, '.')) != NULL)
- strcpy(_res.defdname, cp + 1);
+ strcpy(statp->defdname, cp + 1);
/* find components of local domain that might be searched */
if (havesearch == 0) {
- pp = _res.dnsrch;
- *pp++ = _res.defdname;
+ pp = statp->dnsrch;
+ *pp++ = statp->defdname;
*pp = NULL;
#ifndef RFC1535
dots = 0;
- for (cp = _res.defdname; *cp; cp++)
+ for (cp = statp->defdname; *cp; cp++)
dots += (*cp == '.');
- cp = _res.defdname;
- while (pp < _res.dnsrch + MAXDFLSRCH) {
+ cp = statp->defdname;
+ while (pp < statp->dnsrch + MAXDFLSRCH) {
if (dots < LOCALDOMAINPARTS)
break;
- cp = strchr(cp, '.') + 1; /* we know there is one */
+ cp = memchr(cp, '.') + 1; /* we know there is one */
*pp++ = cp;
dots--;
}
*pp = NULL;
#ifdef DEBUG
- if (_res.options & RES_DEBUG) {
+ if (statp->options & RES_DEBUG) {
printf(";; res_init()... default dnsrch list:\n");
- for (pp = _res.dnsrch; *pp; pp++)
+ for (pp = statp->dnsrch; *pp; pp++)
printf(";;\t%s\n", *pp);
printf(";;\t..END..\n");
}
@@ -489,23 +442,20 @@ res_init()
#endif /* !RFC1535 */
}
- if (issetugid())
- _res.options |= RES_NOALIASES;
- else if ((cp = getenv("RES_OPTIONS")) != NULL)
- res_setoptions(cp, "env");
- _res.options |= RES_INIT;
+ if ((cp = getenv("RES_OPTIONS")) != NULL)
+ res_setoptions(statp, cp, "env");
+ statp->options |= RES_INIT;
return (0);
}
static void
-res_setoptions(options, source)
- char *options, *source;
-{
- char *cp = options;
+internal_function
+res_setoptions(res_state statp, const char *options, const char *source) {
+ const char *cp = options;
int i;
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ if (statp->options & RES_DEBUG)
printf(";; res_setoptions(\"%s\", \"%s\")...\n",
options, source);
#endif
@@ -517,32 +467,50 @@ res_setoptions(options, source)
if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
i = atoi(cp + sizeof("ndots:") - 1);
if (i <= RES_MAXNDOTS)
- _res.ndots = i;
+ statp->ndots = i;
else
- _res.ndots = RES_MAXNDOTS;
+ statp->ndots = RES_MAXNDOTS;
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";;\tndots=%d\n", _res.ndots);
+ if (statp->options & RES_DEBUG)
+ printf(";;\tndots=%d\n", statp->ndots);
#endif
+ } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
+ i = atoi(cp + sizeof("timeout:") - 1);
+ if (i <= RES_MAXRETRANS)
+ statp->retrans = i;
+ else
+ statp->retrans = RES_MAXRETRANS;
+ } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
+ i = atoi(cp + sizeof("attempts:") - 1);
+ if (i <= RES_MAXRETRY)
+ statp->retry = i;
+ else
+ statp->retry = RES_MAXRETRY;
} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
#ifdef DEBUG
- if (!(_res.options & RES_DEBUG)) {
+ if (!(statp->options & RES_DEBUG)) {
printf(";; res_setoptions(\"%s\", \"%s\")..\n",
options, source);
- _res.options |= RES_DEBUG;
+ statp->options |= RES_DEBUG;
}
printf(";;\tdebug\n");
#endif
} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
- _res.options |= RES_USE_INET6;
- } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) {
- _res.options |= RES_INSECURE1;
- } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) {
- _res.options |= RES_INSECURE2;
- } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) {
- _res.options |= RES_NOTLDQUERY;
- } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
- _res.options |= RES_USE_EDNS0;
+ statp->options |= RES_USE_INET6;
+ } else if (!strncmp(cp, "ip6-bytestring",
+ sizeof("ip6-bytestring") - 1)) {
+ statp->options |= RES_USEBSTRING;
+ } else if (!strncmp(cp, "no-ip6-dotint",
+ sizeof("no-ip6-dotint") - 1)) {
+ statp->options |= RES_NOIP6DOTINT;
+ } else if (!strncmp(cp, "ip6-dotint",
+ sizeof("ip6-dotint") - 1)) {
+ statp->options &= ~RES_NOIP6DOTINT;
+ } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
+ statp->options |= RES_ROTATE;
+ } else if (!strncmp(cp, "no-check-names",
+ sizeof("no-check-names") - 1)) {
+ statp->options |= RES_NOCHECKNAME;
} else {
/* XXX - print a warning here? */
}
@@ -558,7 +526,7 @@ static u_int32_t
net_mask(in) /* XXX - should really use system's version of this */
struct in_addr in;
{
- u_int32_t i = ntohl(in.s_addr);
+ register u_int32_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return (htonl(IN_CLASSA_NET));
@@ -569,17 +537,72 @@ net_mask(in) /* XXX - should really use system's version of this */
#endif
u_int
-res_randomid()
-{
+res_randomid(void) {
struct timeval now;
gettimeofday(&now, NULL);
return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
}
+#ifdef _LIBC
+libc_hidden_def (__res_randomid)
+#endif
+
/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it. This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
*/
-#undef res_init
-__weak_reference(__res_init, res_init);
+void
+res_nclose(res_state statp) {
+ int ns;
+
+ if (statp->_vcsock >= 0) {
+ close_not_cancel_no_status(statp->_vcsock);
+ statp->_vcsock = -1;
+ statp->_flags &= ~(RES_F_VC | RES_F_CONN);
+ }
+#ifdef _LIBC
+ for (ns = 0; ns < MAXNS; ns++)
+#else
+ for (ns = 0; ns < statp->_u._ext.nscount; ns++)
+#endif
+ if (statp->_u._ext.nsaddrs[ns]
+ && statp->_u._ext.nssocks[ns] != -1) {
+ close_not_cancel_no_status(statp->_u._ext.nssocks[ns]);
+ statp->_u._ext.nssocks[ns] = -1;
+ }
+ statp->_u._ext.nsinit = 0;
+}
+#ifdef _LIBC
+libc_hidden_def (__res_nclose)
+#endif
+
+#ifdef _LIBC
+# ifdef _LIBC_REENTRANT
+/* This is called when a thread is exiting to free resources held in _res. */
+static void __attribute__ ((section ("__libc_thread_freeres_fn")))
+res_thread_freeres (void)
+{
+ if (_res.nscount == 0)
+ /* Never called res_ninit. */
+ return;
+
+ __res_nclose (&_res); /* Close any VC sockets. */
+
+ for (int ns = 0; ns < MAXNS; ns++)
+ if (_res._u._ext.nsaddrs[ns] != NULL)
+ {
+ free (_res._u._ext.nsaddrs[ns]);
+ _res._u._ext.nsaddrs[ns] = NULL;
+ }
+
+ /* Make sure we do a full re-initialization the next time. */
+ _res.options = 0;
+}
+text_set_element (__libc_thread_subfreeres, res_thread_freeres);
+text_set_element (__libc_subfreeres, res_thread_freeres);
+# endif
+#endif
diff --git a/newlib/libc/sys/linux/net/res_libc.c b/newlib/libc/sys/linux/net/res_libc.c
new file mode 100644
index 000000000..739a51f58
--- /dev/null
+++ b/newlib/libc/sys/linux/net/res_libc.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 1995-1999 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 <machine/atomic.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#include <bits/libc-lock.h>
+
+#include "libc-symbols.h"
+
+
+/* The following bit is copied from res_data.c (where it is #ifdef'ed
+ out) since res_init() should go into libc.so but the rest of that
+ file should not. */
+
+extern unsigned long long int __res_initstamp attribute_hidden;
+/* We have atomic increment operations on 64-bit platforms. */
+#if __WORDSIZE == 64
+# define atomicinclock(lock) (void) 0
+# define atomicincunlock(lock) (void) 0
+# define atomicinc(var) atomic_increment (&(var))
+#else
+__libc_lock_define_initialized (static, lock);
+# define atomicinclock(lock) __libc_lock_lock (lock)
+# define atomicincunlock(lock) __libc_lock_unlock (lock)
+# define atomicinc(var) ++var
+#endif
+
+int
+res_init(void) {
+ extern int __res_vinit(res_state, int);
+
+ /*
+ * These three fields used to be statically initialized. This made
+ * it hard to use this code in a shared library. It is necessary,
+ * now that we're doing dynamic initialization here, that we preserve
+ * the old semantics: if an application modifies one of these three
+ * fields of _res before res_init() is called, res_init() will not
+ * alter them. Of course, if an application is setting them to
+ * _zero_ before calling res_init(), hoping to override what used
+ * to be the static default, we can't detect it and unexpected results
+ * will follow. Zero for any of these fields would make no sense,
+ * so one can safely assume that the applications were already getting
+ * unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
+ */
+ if (!_res.retrans)
+ _res.retrans = RES_TIMEOUT;
+ if (!_res.retry)
+ _res.retry = 4;
+ if (!(_res.options & RES_INIT))
+ _res.options = RES_DEFAULT;
+ else if (_res.nscount > 0) {
+ __res_nclose (&_res); /* Close any VC sockets. */
+ int ns;
+ for (ns = 0; ns < MAXNS; ns++) {
+ free (_res._u._ext.nsaddrs[ns]);
+ _res._u._ext.nsaddrs[ns] = NULL;
+ }
+ }
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = res_randomid();
+
+ atomicinclock (lock);
+ /* Request all threads to re-initialize their resolver states,
+ resolv.conf might have changed. */
+ atomicinc (__res_initstamp);
+ atomicincunlock (lock);
+
+ return (__res_vinit(&_res, 1));
+}
+
+/* Initialize resp if RES_INIT is not yet set or if res_init in some other
+ thread requested re-initializing. */
+int
+__res_maybe_init (res_state resp, int preinit)
+{
+ if (resp->options & RES_INIT) {
+ if (__res_initstamp != resp->_u._ext.initstamp) {
+ if (resp->nscount > 0) {
+ __res_nclose (resp);
+ int ns;
+ for (ns = 0; ns < MAXNS; ns++) {
+ free (resp->_u._ext.nsaddrs[ns]);
+ resp->_u._ext.nsaddrs[ns] = NULL;
+ }
+ return __res_vinit (resp, 1);
+ }
+ }
+ return 0;
+ } else if (preinit) {
+ if (!resp->retrans)
+ resp->retrans = RES_TIMEOUT;
+ if (!resp->retry)
+ resp->retry = 4;
+ resp->options = RES_DEFAULT;
+ if (!resp->id)
+ resp->id = res_randomid ();
+ return __res_vinit (resp, 1);
+ } else
+ return __res_ninit (resp);
+}
+libc_hidden_def (__res_maybe_init)
+
+/* This needs to be after the use of _res in res_init, above. */
+#undef _res
+
+/* The resolver state for use by single-threaded programs.
+ This differs from plain `struct __res_state _res;' in that it doesn't
+ create a common definition, but a plain symbol that resides in .bss,
+ which can have an alias. */
+struct __res_state _res __attribute__((section (".bss")));
+
+#define USE___THREAD 1
+
+#if USE___THREAD
+#undef __resp
+__thread struct __res_state *__resp = &_res;
+extern __thread struct __res_state *__libc_resp
+ __attribute__ ((alias ("__resp"))) attribute_hidden;
+#endif
+
+/* We declare this with compat_symbol so that it's not
+ visible at link time. Programs must use the accessor functions. */
+#if defined HAVE_ELF && defined SHARED && defined DO_VERSIONING
+# include <shlib-compat.h>
+compat_symbol (libc, _res, _res, GLIBC_2_0);
+#endif
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2)
+# undef res_init
+extern int __res_init_weak (void);
+weak_extern (__res_init_weak);
+strong_alias (__res_init, __res_init_weak);
+compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0);
+#endif
diff --git a/newlib/libc/sys/linux/net/res_mkquery.c b/newlib/libc/sys/linux/net/res_mkquery.c
index 0c6cca9c4..fa1ccd87f 100644
--- a/newlib/libc/sys/linux/net/res_mkquery.c
+++ b/newlib/libc/sys/linux/net/res_mkquery.c
@@ -1,7 +1,7 @@
/*
* 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -52,7 +48,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -69,12 +65,9 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $";
+static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "$BINDId: res_mkquery.c,v 8.12 1999/10/13 16:39:40 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -84,37 +77,43 @@ static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vi
#include <resolv.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
+#include "local.h"
+
+/* Options. Leave them on. */
+/* #define DEBUG */
-#include "res_config.h"
+#ifdef _LIBC
+# include <hp-timing.h>
+# if HP_TIMING_AVAIL
+# define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; }
+# endif
+#endif
/*
* Form all types of queries.
* Returns the size of the result or -1.
*/
int
-res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
- int op; /* opcode of query */
- const char *dname; /* domain name */
- int class, type; /* class and type of query */
- const u_char *data; /* resource record data */
- int datalen; /* length of data */
- const u_char *newrr_in; /* new rr for modify or append */
- u_char *buf; /* buffer to put query */
- int buflen; /* size of buffer */
+res_nmkquery(res_state statp,
+ int op, /* opcode of query */
+ const char *dname, /* domain name */
+ int class, int type, /* class and type of query */
+ const u_char *data, /* resource record data */
+ int datalen, /* length of data */
+ const u_char *newrr_in, /* new rr for modify or append */
+ u_char *buf, /* buffer to put query */
+ int buflen) /* size of buffer */
{
- HEADER *hp;
- u_char *cp;
- int n;
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
u_char *dnptrs[20], **dpp, **lastdnptr;
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; res_mkquery(%d, %s, %d, %d)\n",
- op, dname, class, type);
+ if (statp->options & RES_DEBUG)
+ printf(";; res_nmkquery(%s, %s, %s, %s)\n",
+ _res_opcodes[op], dname, p_class(class), p_type(type));
#endif
/*
* Initialize header fields.
@@ -123,9 +122,30 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
return (-1);
memset(buf, 0, HFIXEDSZ);
hp = (HEADER *) buf;
- hp->id = htons(++_res.id);
+ /* We randomize the IDs every time. The old code just
+ incremented by one after the initial randomization which
+ still predictable if the application does multiple
+ requests. */
+#if 0
+ hp->id = htons(++statp->id);
+#else
+ hp->id = htons(statp->id);
+ int randombits;
+ do
+ {
+#ifdef RANDOM_BITS
+ RANDOM_BITS (randombits);
+#else
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ randombits = (tv.tv_sec << 8) ^ tv.tv_usec;
+#endif
+ }
+ while ((randombits & 0xffff) == 0);
+ statp->id = (statp->id + randombits) & 0xffff;
+#endif
hp->opcode = op;
- hp->rd = (_res.options & RES_RECURSE) != 0;
+ hp->rd = (statp->options & RES_RECURSE) != 0;
hp->rcode = NOERROR;
cp = buf + HFIXEDSZ;
buflen -= HFIXEDSZ;
@@ -199,47 +219,4 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
}
return (cp - buf);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_mkquery
-__weak_reference(__res_mkquery, res_mkquery);
-
-/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
-int
-res_opt(n0, buf, buflen, anslen)
- int n0;
- u_char *buf; /* buffer to put query */
- int buflen; /* size of buffer */
- int anslen; /* answer buffer length */
-{
- HEADER *hp;
- u_char *cp;
-
- hp = (HEADER *) buf;
- cp = buf + n0;
- buflen -= n0;
-
- if (buflen < 1 + RRFIXEDSZ)
- return -1;
-
- *cp++ = 0; /* "." */
- buflen--;
-
- __putshort(T_OPT, cp); /* TYPE */
- cp += INT16SZ;
- __putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */
- cp += INT16SZ;
- *cp++ = NOERROR; /* extended RCODE */
- *cp++ = 0; /* EDNS version */
- __putshort(0, cp); /* MBZ */
- cp += INT16SZ;
- __putshort(0, cp); /* RDLEN */
- cp += INT16SZ;
- hp->arcount = htons(ntohs(hp->arcount) + 1);
- buflen -= RRFIXEDSZ;
-
- return cp - buf;
-}
+libresolv_hidden_def (res_nmkquery)
diff --git a/newlib/libc/sys/linux/net/res_mkupdate.c b/newlib/libc/sys/linux/net/res_mkupdate.c
deleted file mode 100644
index 4e21fe8cf..000000000
--- a/newlib/libc/sys/linux/net/res_mkupdate.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais@ccm.fm.intel.com>
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <limits.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "res_config.h"
-
-static int getnum_str(u_char **, u_char *);
-static int getword_str(char *, int, u_char **, u_char *);
-
-#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
-
-/*
- * Form update packets.
- * Returns the size of the resulting packet if no error
- * On error,
- * returns -1 if error in reading a word/number in rdata
- * portion for update packets
- * -2 if length of buffer passed is insufficient
- * -3 if zone section is not the first section in
- * the linked list, or section order has a problem
- * -4 on a number overflow
- * -5 unknown operation or no records
- */
-int
-res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
- ns_updrec *rrecp_start = rrecp_in;
- HEADER *hp;
- u_char *cp, *sp1, *sp2, *startp, *endp;
- int n, i, soanum, multiline;
- ns_updrec *rrecp;
- struct in_addr ina;
- char buf2[MAXDNAME];
- int section, numrrs = 0, counts[ns_s_max];
- u_int16_t rtype, rclass;
- u_int32_t n1, rttl;
- u_char *dnptrs[20], **dpp, **lastdnptr;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
-
- /*
- * Initialize header fields.
- */
- if ((buf == NULL) || (buflen < HFIXEDSZ))
- return (-1);
- memset(buf, 0, HFIXEDSZ);
- hp = (HEADER *) buf;
- hp->id = htons(++_res.id);
- hp->opcode = ns_o_update;
- hp->rcode = NOERROR;
- sp1 = buf + 2*INT16SZ; /* save pointer to zocount */
- cp = buf + HFIXEDSZ;
- buflen -= HFIXEDSZ;
- dpp = dnptrs;
- *dpp++ = buf;
- *dpp++ = NULL;
- lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
-
- if (rrecp_start == NULL)
- return (-5);
- else if (rrecp_start->r_section != S_ZONE)
- return (-3);
-
- memset(counts, 0, sizeof counts);
- for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
- numrrs++;
- section = rrecp->r_section;
- if (section < 0 || section >= ns_s_max)
- return (-1);
- counts[section]++;
- for (i = section + 1; i < ns_s_max; i++)
- if (counts[i])
- return (-3);
- rtype = rrecp->r_type;
- rclass = rrecp->r_class;
- rttl = rrecp->r_ttl;
- /* overload class and type */
- if (section == S_PREREQ) {
- rttl = 0;
- switch (rrecp->r_opcode) {
- case YXDOMAIN:
- rclass = C_ANY;
- rtype = T_ANY;
- rrecp->r_size = 0;
- break;
- case NXDOMAIN:
- rclass = C_NONE;
- rtype = T_ANY;
- rrecp->r_size = 0;
- break;
- case NXRRSET:
- rclass = C_NONE;
- rrecp->r_size = 0;
- break;
- case YXRRSET:
- if (rrecp->r_size == 0)
- rclass = C_ANY;
- break;
- default:
- fprintf(stderr,
- "res_mkupdate: incorrect opcode: %d\n",
- rrecp->r_opcode);
- fflush(stderr);
- return (-1);
- }
- } else if (section == S_UPDATE) {
- switch (rrecp->r_opcode) {
- case DELETE:
- rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
- break;
- case ADD:
- break;
- default:
- fprintf(stderr,
- "res_mkupdate: incorrect opcode: %d\n",
- rrecp->r_opcode);
- fflush(stderr);
- return (-1);
- }
- }
-
- /*
- * XXX appending default domain to owner name is omitted,
- * fqdn must be provided
- */
- if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
- lastdnptr)) < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n + 2*INT16SZ);
- PUTSHORT(rtype, cp);
- PUTSHORT(rclass, cp);
- if (section == S_ZONE) {
- if (numrrs != 1 || rrecp->r_type != T_SOA)
- return (-3);
- continue;
- }
- ShrinkBuffer(INT32SZ + INT16SZ);
- PUTLONG(rttl, cp);
- sp2 = cp; /* save pointer to length byte */
- cp += INT16SZ;
- if (rrecp->r_size == 0) {
- if (section == S_UPDATE && rclass != C_ANY)
- return (-1);
- else {
- PUTSHORT(0, sp2);
- continue;
- }
- }
- startp = rrecp->r_data;
- endp = startp + rrecp->r_size - 1;
- /* XXX this should be done centrally. */
- switch (rrecp->r_type) {
- case T_A:
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- if (!inet_aton(buf2, &ina))
- return (-1);
- n1 = ntohl(ina.s_addr);
- ShrinkBuffer(INT32SZ);
- PUTLONG(n1, cp);
- break;
- case T_CNAME:
- case T_MB:
- case T_MG:
- case T_MR:
- case T_NS:
- case T_PTR:
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- break;
- case T_MINFO:
- case T_SOA:
- case T_RP:
- for (i = 0; i < 2; i++) {
- if (!getword_str(buf2, sizeof buf2, &startp,
- endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen,
- dnptrs, lastdnptr);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- }
- if (rrecp->r_type == T_SOA) {
- ShrinkBuffer(5 * INT32SZ);
- while (isspace(*startp) || !*startp)
- startp++;
- if (*startp == '(') {
- multiline = 1;
- startp++;
- } else
- multiline = 0;
- /* serial, refresh, retry, expire, minimum */
- for (i = 0; i < 5; i++) {
- soanum = getnum_str(&startp, endp);
- if (soanum < 0)
- return (-1);
- PUTLONG(soanum, cp);
- }
- if (multiline) {
- while (isspace(*startp) || !*startp)
- startp++;
- if (*startp != ')')
- return (-1);
- }
- }
- break;
- case T_MX:
- case T_AFSDB:
- case T_RT:
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- PUTSHORT(n, cp);
- ShrinkBuffer(INT16SZ);
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- break;
- case T_PX:
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- PUTSHORT(n, cp);
- ShrinkBuffer(INT16SZ);
- for (i = 0; i < 2; i++) {
- if (!getword_str(buf2, sizeof buf2, &startp,
- endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, dnptrs,
- lastdnptr);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- }
- break;
- case T_WKS:
- case T_HINFO:
- case T_TXT:
- case T_X25:
- case T_ISDN:
- case T_NSAP:
- case T_LOC:
- /* XXX - more fine tuning needed here */
- ShrinkBuffer(rrecp->r_size);
- memcpy(cp, rrecp->r_data, rrecp->r_size);
- cp += rrecp->r_size;
- break;
- default:
- return (-1);
- } /*switch*/
- n = (u_int16_t)((cp - sp2) - INT16SZ);
- PUTSHORT(n, sp2);
- } /*for*/
-
- hp->qdcount = htons(counts[0]);
- hp->ancount = htons(counts[1]);
- hp->nscount = htons(counts[2]);
- hp->arcount = htons(counts[3]);
- return (cp - buf);
-}
-
-/*
- * Get a whitespace delimited word from a string (not file)
- * into buf. modify the start pointer to point after the
- * word in the string.
- */
-static int
-getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
- char *cp;
- int c;
-
- for (cp = buf; *startpp <= endp; ) {
- c = **startpp;
- if (isspace(c) || c == '\0') {
- if (cp != buf) /* trailing whitespace */
- break;
- else { /* leading whitespace */
- (*startpp)++;
- continue;
- }
- }
- (*startpp)++;
- if (cp >= buf+size-1)
- break;
- *cp++ = (u_char)c;
- }
- *cp = '\0';
- return (cp != buf);
-}
-
-/*
- * Get a whitespace delimited number from a string (not file) into buf
- * update the start pointer to point after the number in the string.
- */
-static int
-getnum_str(u_char **startpp, u_char *endp) {
- int c, n;
- int seendigit = 0;
- int m = 0;
-
- for (n = 0; *startpp <= endp; ) {
- c = **startpp;
- if (isspace(c) || c == '\0') {
- if (seendigit) /* trailing whitespace */
- break;
- else { /* leading whitespace */
- (*startpp)++;
- continue;
- }
- }
- if (c == ';') {
- while ((*startpp <= endp) &&
- ((c = **startpp) != '\n'))
- (*startpp)++;
- if (seendigit)
- break;
- continue;
- }
- if (!isdigit(c)) {
- if (c == ')' && seendigit) {
- (*startpp)--;
- break;
- }
- return (-1);
- }
- (*startpp)++;
- n = n * 10 + (c - '0');
- seendigit = 1;
- }
- return (n + m);
-}
-
-/*
- * Allocate a resource record buffer & save rr info.
- */
-ns_updrec *
-res_mkupdrec(int section, const char *dname,
- u_int class, u_int type, u_long ttl) {
- ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
-
- if (!rrecp || !(rrecp->r_dname = strdup(dname)))
- return (NULL);
- rrecp->r_class = class;
- rrecp->r_type = type;
- rrecp->r_ttl = ttl;
- rrecp->r_section = section;
- return (rrecp);
-}
-
-/*
- * Free a resource record buffer created by res_mkupdrec.
- */
-void
-res_freeupdrec(ns_updrec *rrecp) {
- /* Note: freeing r_dp is the caller's responsibility. */
- if (rrecp->r_dname != NULL)
- free(rrecp->r_dname);
- free(rrecp);
-}
diff --git a/newlib/libc/sys/linux/net/res_query.c b/newlib/libc/sys/linux/net/res_query.c
index ee6775d99..fcb624e8e 100644
--- a/newlib/libc/sys/linux/net/res_query.c
+++ b/newlib/libc/sys/linux/net/res_query.c
@@ -1,7 +1,7 @@
/*
* 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -52,7 +48,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -69,11 +65,9 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
-static char orig_rcsid = "From: Id: res_query.c,v 8.14 1997/06/09 17:47:05 halley Exp $";
+static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -87,144 +81,190 @@ static char orig_rcsid = "From: Id: res_query.c,v 8.14 1997/06/09 17:47:05 halle
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "libc-symbols.h"
-#include "res_config.h"
+/* Options. Leave them on. */
+/* #undef DEBUG */
-#if PACKETSZ > 1024
+#if PACKETSZ > 65536
#define MAXPACKET PACKETSZ
#else
-#define MAXPACKET 1024
+#define MAXPACKET 65536
#endif
+#define QUERYSIZE (HFIXEDSZ + QFIXEDSZ + MAXCDNAME + 1)
+
+static int
+__libc_res_nquerydomain(res_state statp, const char *name, const char *domain,
+ int class, int type, u_char *answer, int anslen,
+ u_char **answerp);
+
/*
* 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.
+ * Error number is left in H_ERRNO.
*
* Caller must parse answer and determine whether it answers the question.
*/
int
-res_query(name, class, type, answer, anslen)
- const char *name; /* domain name */
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer buffer */
+__libc_res_nquery(res_state statp,
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen, /* size of answer buffer */
+ u_char **answerp) /* if buffer needs to be enlarged */
{
- u_char buf[MAXPACKET];
+ u_char *buf;
HEADER *hp = (HEADER *) answer;
- int n;
+ int n, use_malloc = 0;
hp->rcode = NOERROR; /* default */
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
+ buf = alloca (QUERYSIZE);
+
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ if (statp->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, sizeof(buf));
- if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
- n = res_opt(n, buf, sizeof(buf), anslen);
- if (n <= 0) {
+ n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
+ buf, QUERYSIZE);
+ if (__builtin_expect (n <= 0, 0)) {
+ /* Retry just in case res_nmkquery failed because of too
+ short buffer. Shouldn't happen. */
+ buf = malloc (MAXPACKET);
+ if (buf != NULL) {
+ use_malloc = 1;
+ n = res_nmkquery(statp, QUERY, name, class, type, NULL,
+ 0, NULL, buf, MAXPACKET);
+ }
+ }
+ if (__builtin_expect (n <= 0, 0)) {
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ if (statp->options & RES_DEBUG)
printf(";; res_query: mkquery failed\n");
#endif
- h_errno = NO_RECOVERY;
+ RES_SET_H_ERRNO(statp, NO_RECOVERY);
+ if (use_malloc)
+ free (buf);
return (n);
}
- n = res_send(buf, n, answer, anslen);
+ n = __libc_res_nsend(statp, buf, n, answer, anslen, answerp);
+ if (use_malloc)
+ free (buf);
if (n < 0) {
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ if (statp->options & RES_DEBUG)
printf(";; res_query: send error\n");
#endif
- h_errno = TRY_AGAIN;
+ RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (n);
}
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ if (statp->options & RES_DEBUG)
printf(";; rcode = %d, ancount=%d\n", hp->rcode,
ntohs(hp->ancount));
#endif
switch (hp->rcode) {
case NXDOMAIN:
- h_errno = HOST_NOT_FOUND;
+ RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
break;
case SERVFAIL:
- h_errno = TRY_AGAIN;
+ RES_SET_H_ERRNO(statp, TRY_AGAIN);
break;
case NOERROR:
- h_errno = NO_DATA;
+ RES_SET_H_ERRNO(statp, NO_DATA);
break;
case FORMERR:
case NOTIMP:
case REFUSED:
default:
- h_errno = NO_RECOVERY;
+ RES_SET_H_ERRNO(statp, NO_RECOVERY);
break;
}
return (-1);
}
return (n);
}
+libresolv_hidden_def (__libc_res_nquery)
+
+int
+res_nquery(res_state statp,
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer buffer */
+{
+ return __libc_res_nquery(statp, name, class, type, answer, anslen,
+ NULL);
+}
+libresolv_hidden_def (res_nquery)
/*
* 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.
+ * is detected. Error code, if any, is left in H_ERRNO.
*/
int
-res_search(name, class, type, answer, anslen)
- const char *name; /* domain name */
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+__libc_res_nsearch(res_state statp,
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen, /* size of answer */
+ u_char **answerp)
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *) answer;
+ char tmp[NS_MAXDNAME];
u_int dots;
int trailing_dot, ret, saved_herrno;
- int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+ int got_nodata = 0, got_servfail = 0, root_on_list = 0;
+ int tried_as_is = 0;
+
+ __set_errno (0);
+ RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */
- if ((_res.options & RES_INIT) == 0 && res_init() == -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++)
+ for (cp = name; *cp != '\0'; 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_query(cp, class, type, answer, anslen));
+ /* If there aren't any dots, it could be a user-level alias. */
+ if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
+ return (__libc_res_nquery(statp, cp, class, type, answer,
+ anslen, answerp));
+
+#ifdef DEBUG
+ if (statp->options & RES_DEBUG)
+ printf("dots=%d, statp->ndots=%d, trailing_dot=%d, name=%s\n",
+ (int)dots,(int)statp->ndots,(int)trailing_dot,name);
+#endif
/*
- * 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.
+ * If there are enough dots in the name, let's just give it a
+ * try 'as is'. The threshold can be set with the "ndots" option.
+ * Also, query 'as is', if there is a trailing dot in the name.
*/
saved_herrno = -1;
- if (dots >= _res.ndots) {
- ret = res_querydomain(name, NULL, class, type, answer, anslen);
- if (ret > 0)
+ if (dots >= statp->ndots || trailing_dot) {
+ ret = __libc_res_nquerydomain(statp, name, NULL, class, type,
+ answer, anslen, answerp);
+ if (ret > 0 || trailing_dot)
return (ret);
saved_herrno = h_errno;
tried_as_is++;
+ if (answerp && *answerp != answer) {
+ answer = *answerp;
+ anslen = MAXPACKET;
+ }
}
/*
@@ -233,19 +273,29 @@ res_search(name, class, type, answer, anslen)
* - there is at least one dot, there is no trailing dot,
* and RES_DNSRCH is set.
*/
- if ((!dots && (_res.options & RES_DEFNAMES)) ||
- (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
+ if ((!dots && (statp->options & RES_DEFNAMES) != 0) ||
+ (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0)) {
int done = 0;
- for (domain = (const char * const *)_res.dnsrch;
+ for (domain = (const char * const *)statp->dnsrch;
*domain && !done;
domain++) {
- ret = res_querydomain(name, *domain, class, type,
- answer, anslen);
+ if (domain[0][0] == '\0' ||
+ (domain[0][0] == '.' && domain[0][1] == '\0'))
+ root_on_list++;
+
+ ret = __libc_res_nquerydomain(statp, name, *domain,
+ class, type,
+ answer, anslen, answerp);
if (ret > 0)
return (ret);
+ if (answerp && *answerp != answer) {
+ answer = *answerp;
+ anslen = MAXPACKET;
+ }
+
/*
* If no server present, give up.
* If name isn't found in this domain,
@@ -260,11 +310,11 @@ res_search(name, class, type, answer, anslen)
* fully-qualified.
*/
if (errno == ECONNREFUSED) {
- h_errno = TRY_AGAIN;
+ RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
}
- switch (h_errno) {
+ switch (statp->res_h_errno) {
case NO_DATA:
got_nodata++;
/* FALLTHROUGH */
@@ -286,60 +336,72 @@ res_search(name, class, type, answer, anslen)
/* if we got here for some reason other than DNSRCH,
* we only wanted one iteration of the loop, so stop.
*/
- if (!(_res.options & RES_DNSRCH))
+ if ((statp->options & RES_DNSRCH) == 0)
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 unless NOTLDQUERY is set.
+ * If the name has any dots at all, and no earlier 'as-is' query
+ * for the name, and "." is not on the search list, then try an as-is
+ * query now.
*/
- if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
- ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (dots && !(tried_as_is || root_on_list)) {
+ ret = __libc_res_nquerydomain(statp, name, NULL, class, type,
+ answer, anslen, answerp);
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
+ * 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
+ * else send back meaningless H_ERRNO, that being the one from
* the last DNSRCH we did.
*/
if (saved_herrno != -1)
- h_errno = saved_herrno;
+ RES_SET_H_ERRNO(statp, saved_herrno);
else if (got_nodata)
- h_errno = NO_DATA;
+ RES_SET_H_ERRNO(statp, NO_DATA);
else if (got_servfail)
- h_errno = TRY_AGAIN;
+ RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
}
+libresolv_hidden_def (__libc_res_nsearch)
+
+int
+res_nsearch(res_state statp,
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
+{
+ return __libc_res_nsearch(statp, name, class, type, answer,
+ anslen, NULL);
+}
+libresolv_hidden_def (res_nsearch)
/*
* Perform a call on res_query on the concatenation of name and domain,
* removing a trailing dot from name if domain is NULL.
*/
-int
-res_querydomain(name, domain, class, type, answer, anslen)
- const char *name, *domain;
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+static int
+__libc_res_nquerydomain(res_state statp,
+ const char *name,
+ const char *domain,
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen, /* size of answer */
+ u_char **answerp)
{
char nbuf[MAXDNAME];
const char *longname = nbuf;
int n, d;
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";; res_querydomain(%s, %s, %d, %d)\n",
+ if (statp->options & RES_DEBUG)
+ printf(";; res_nquerydomain(%s, %s, %d, %d)\n",
name, domain?domain:"<Nil>", class, type);
#endif
if (domain == NULL) {
@@ -349,7 +411,7 @@ res_querydomain(name, domain, class, type, answer, anslen)
*/
n = strlen(name);
if (n >= MAXDNAME) {
- h_errno = NO_RECOVERY;
+ RES_SET_H_ERRNO(statp, NO_RECOVERY);
return (-1);
}
n--;
@@ -362,27 +424,35 @@ res_querydomain(name, domain, class, type, answer, anslen)
n = strlen(name);
d = strlen(domain);
if (n + d + 1 >= MAXDNAME) {
- h_errno = NO_RECOVERY;
+ RES_SET_H_ERRNO(statp, NO_RECOVERY);
return (-1);
}
sprintf(nbuf, "%s.%s", name, domain);
}
- return (res_query(longname, class, type, answer, anslen));
+ return (__libc_res_nquery(statp, longname, class, type, answer,
+ anslen, answerp));
}
-const char *
-hostalias(name)
- const char *name;
+int
+res_nquerydomain(res_state statp,
+ const char *name,
+ const char *domain,
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
{
- char *cp1, *cp2;
- FILE *fp;
- char *file;
+ return __libc_res_nquerydomain(statp, name, domain, class, type,
+ answer, anslen, NULL);
+}
+libresolv_hidden_def (res_nquerydomain)
+
+const char *
+res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
+ char *file, *cp1, *cp2;
char buf[BUFSIZ];
- static char abuf[MAXDNAME];
+ FILE *fp;
- if (_res.options & RES_NOALIASES)
- return (NULL);
- if (issetugid())
+ if (statp->options & RES_NOALIASES)
return (NULL);
file = getenv("HOSTALIASES");
if (file == NULL || (fp = fopen(file, "r")) == NULL)
@@ -390,35 +460,26 @@ hostalias(name)
setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';
while (fgets(buf, sizeof(buf), fp)) {
- for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1)
+ for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
;
if (!*cp1)
break;
*cp1 = '\0';
- if (!strcasecmp(buf, name)) {
- while (isspace((unsigned char)*++cp1))
+ if (ns_samename(buf, name) == 1) {
+ while (isspace(*++cp1))
;
if (!*cp1)
break;
- for (cp2 = cp1 + 1; *cp2 && !isspace((unsigned char)*cp2); ++cp2)
+ for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
;
- abuf[sizeof(abuf) - 1] = *cp2 = '\0';
- strncpy(abuf, cp1, sizeof(abuf) - 1);
+ *cp2 = '\0';
+ strncpy(dst, cp1, siz - 1);
+ dst[siz - 1] = '\0';
fclose(fp);
- return (abuf);
+ return (dst);
}
}
fclose(fp);
return (NULL);
}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_query
-__weak_reference(__res_query, res_query);
-#undef res_search
-__weak_reference(__res_search, res_search);
-#undef res_querydomain
-__weak_reference(__res_querydomain, res_querydomain);
+libresolv_hidden_def (res_hostalias)
diff --git a/newlib/libc/sys/linux/net/res_send.c b/newlib/libc/sys/linux/net/res_send.c
index 153d2f5d9..5c2bcf746 100644
--- a/newlib/libc/sys/linux/net/res_send.c
+++ b/newlib/libc/sys/linux/net/res_send.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 1985, 1989, 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:
@@ -10,14 +10,10 @@
* 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 the University of
- * California, Berkeley and its contributors.
* 4. 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
@@ -33,14 +29,14 @@
/*
* 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
@@ -52,7 +48,7 @@
*/
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-1999 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
@@ -69,144 +65,136 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $";
+static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
+#define s6_addr32 __u6_addr.__u6_addr32
/*
* Send query to name server and wait for reply.
*/
+#include <assert.h>
#include <sys/types.h>
-#include <sys/event.h>
-#include <sys/poll.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/uio.h>
+#include <sys/poll.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>
+#include <sys/ioctl.h>
#include <errno.h>
+#include <fcntl.h>
#include <netdb.h>
#include <resolv.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "libc-symbols.h"
+
+#if PACKETSZ > 65536
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 65536
+#endif
-#include "res_config.h"
-static int s = -1; /* socket used for communications */
-static int connected = 0; /* is the socket connected */
-static int vc = 0; /* is the socket a virtual circuit? */
-static int af = 0; /* address family of socket */
-static res_send_qhook Qhook = NULL;
-static res_send_rhook Rhook = NULL;
+/* From ev_streams.c. */
+static inline void
+__attribute ((always_inline))
+evConsIovec(void *buf, size_t cnt, struct iovec *vec) {
+ memset(vec, 0xf5, sizeof (*vec));
+ vec->iov_base = buf;
+ vec->iov_len = cnt;
+}
-#define CAN_RECONNECT 1
+/* From ev_timers.c. */
-#ifndef DEBUG
-# define Dprint(cond, args) /*empty*/
-# define DprintQ(cond, args, query, size) /*empty*/
-# define Aerror(file, string, error, address) /*empty*/
-# define Perror(file, string, error) /*empty*/
-#else
-# define Dprint(cond, args) if (cond) {fprintf args;} else {}
-# define DprintQ(cond, args, query, size) if (cond) {\
- fprintf args;\
- __fp_nquery(query, size, stdout);\
- } else {}
-static char abuf[NI_MAXHOST];
-static char pbuf[NI_MAXSERV];
-static void Aerror(FILE *, char *, int, struct sockaddr *);
-static void Perror(FILE *, char *, int);
-
- static void
- Aerror(file, string, error, address)
- FILE *file;
- char *string;
- int error;
- struct sockaddr *address;
- {
- int save = errno;
+#define BILLION 1000000000
- if (_res.options & RES_DEBUG) {
- if (getnameinfo(address, 0, abuf, sizeof(abuf),
- pbuf, sizeof(pbuf),
- NI_NUMERICHOST|NI_NUMERICSERV|NI_WITHSCOPEID) != 0) {
- strncpy(abuf, "?", sizeof(abuf));
- strncpy(pbuf, "?", sizeof(pbuf));
- }
- fprintf(file, "res_send: %s ([%s].%s): %s\n",
- string, abuf, pbuf, strerror(error));
+static inline void
+evConsTime(struct timespec *res, time_t sec, long nsec) {
+ res->tv_sec = sec;
+ res->tv_nsec = nsec;
+}
+
+static inline void
+evAddTime(struct timespec *res, const struct timespec *addend1,
+ const struct timespec *addend2) {
+ res->tv_sec = addend1->tv_sec + addend2->tv_sec;
+ res->tv_nsec = addend1->tv_nsec + addend2->tv_nsec;
+ if (res->tv_nsec >= BILLION) {
+ res->tv_sec++;
+ res->tv_nsec -= BILLION;
}
- errno = save;
- }
- static void
- Perror(file, string, error)
- FILE *file;
- char *string;
- int error;
- {
- int save = errno;
+}
- if (_res.options & RES_DEBUG) {
- fprintf(file, "res_send: %s: %s\n",
- string, strerror(error));
+static inline void
+evSubTime(struct timespec *res, const struct timespec *minuend,
+ const struct timespec *subtrahend) {
+ res->tv_sec = minuend->tv_sec - subtrahend->tv_sec;
+ if (minuend->tv_nsec >= subtrahend->tv_nsec)
+ res->tv_nsec = minuend->tv_nsec - subtrahend->tv_nsec;
+ else {
+ res->tv_nsec = (BILLION
+ - subtrahend->tv_nsec + minuend->tv_nsec);
+ res->tv_sec--;
}
- errno = save;
- }
-#endif
+}
-void
-res_send_setqhook(hook)
- res_send_qhook hook;
-{
+static inline int
+evCmpTime(struct timespec a, struct timespec b) {
+ long x = a.tv_sec - b.tv_sec;
- Qhook = hook;
+ if (x == 0L)
+ x = a.tv_nsec - b.tv_nsec;
+ return (x < 0L ? (-1) : x > 0L ? (1) : (0));
}
-void
-res_send_setrhook(hook)
- res_send_rhook hook;
-{
+static inline void
+evNowTime(struct timespec *res) {
+ struct timeval now;
- Rhook = hook;
+ if (gettimeofday(&now, NULL) < 0)
+ evConsTime(res, 0, 0);
+ else
+ TIMEVAL_TO_TIMESPEC (&now, res);
}
-static struct sockaddr * get_nsaddr(size_t);
-/*
- * pick appropriate nsaddr_list for use. see res_init() for initialization.
- */
-static struct sockaddr *
-get_nsaddr(n)
- size_t n;
-{
+/* Options. Leave them on. */
+/* #undef DEBUG */
+#include "res_debug.h"
- if (!_res.nsaddr_list[n].sin_family) {
- /*
- * - _res_ext.nsaddr_list[n] holds an address that is larger
- * than struct sockaddr, and
- * - user code did not update _res.nsaddr_list[n].
- */
- return (struct sockaddr *)&_res_ext.nsaddr_list[n];
- } else {
- /*
- * - user code updated _res.nsaddr_list[n], or
- * - _res.nsaddr_list[n] has the same content as
- * _res_ext.nsaddr_list[n].
- */
- return (struct sockaddr *)&_res.nsaddr_list[n];
- }
-}
+#define EXT(res) ((res)->_u._ext)
+
+/* Forward. */
+
+static int send_vc(res_state, const u_char *, int,
+ u_char **, int *, int *, int, u_char **);
+static int send_dg(res_state, const u_char *, int,
+ u_char **, int *, int *, int,
+ int *, int *, u_char **);
+#ifdef DEBUG
+static void Aerror(const res_state, FILE *, const char *, int,
+ const struct sockaddr *);
+static void Perror(const res_state, FILE *, const char *, int);
+#endif
+static int sock_eq(struct sockaddr_in6 *, struct sockaddr_in6 *);
+
+/* Reachover. */
+
+static void convaddr4to6(struct sockaddr_in6 *sa);
+void res_pquery(const res_state, const u_char *, int, FILE *);
+
+/* Public. */
/* int
* res_isourserver(ina)
@@ -218,44 +206,38 @@ get_nsaddr(n)
* paul vixie, 29may94
*/
int
-res_isourserver(inp)
- const struct sockaddr_in *inp;
+res_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)
{
- const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp;
- const struct sockaddr_in6 *srv6;
- const struct sockaddr_in *srv;
- int ns, ret;
-
- ret = 0;
- switch (inp->sin_family) {
- case AF_INET6:
- for (ns = 0; ns < _res.nscount; ns++) {
- srv6 = (struct sockaddr_in6 *)get_nsaddr(ns);
- if (srv6->sin6_family == in6p->sin6_family &&
- srv6->sin6_port == in6p->sin6_port &&
- srv6->sin6_scope_id == in6p->sin6_scope_id &&
- (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
- IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr,
- &in6p->sin6_addr))) {
- ret++;
- break;
- }
- }
- break;
- case AF_INET:
- for (ns = 0; ns < _res.nscount; ns++) {
- srv = (struct sockaddr_in *)get_nsaddr(ns);
- if (srv->sin_family == inp->sin_family &&
- srv->sin_port == inp->sin_port &&
- (srv->sin_addr.s_addr == INADDR_ANY ||
- srv->sin_addr.s_addr == inp->sin_addr.s_addr)) {
- ret++;
- break;
- }
- }
- break;
- }
- return (ret);
+ int ns;
+
+ if (inp->sin6_family == AF_INET) {
+ struct sockaddr_in *in4p = (struct sockaddr_in *) inp;
+ in_port_t port = in4p->sin_port;
+ in_addr_t addr = in4p->sin_addr.s_addr;
+
+ for (ns = 0; ns < MAXNS; ns++) {
+ const struct sockaddr_in *srv =
+ (struct sockaddr_in *)EXT(statp).nsaddrs[ns];
+
+ if ((srv != NULL) && (srv->sin_family == AF_INET) &&
+ (srv->sin_port == port) &&
+ (srv->sin_addr.s_addr == INADDR_ANY ||
+ srv->sin_addr.s_addr == addr))
+ return (1);
+ }
+ } else if (inp->sin6_family == AF_INET6) {
+ for (ns = 0; ns < MAXNS; ns++) {
+ const struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];
+ if ((srv != NULL) && (srv->sin6_family == AF_INET6) &&
+ (srv->sin6_port == inp->sin6_port) &&
+ !(memcmp(&srv->sin6_addr, &in6addr_any,
+ sizeof (struct in6_addr)) &&
+ memcmp(&srv->sin6_addr, &inp->sin6_addr,
+ sizeof (struct in6_addr))))
+ return (1);
+ }
+ }
+ return (0);
}
/* int
@@ -271,10 +253,8 @@ res_isourserver(inp)
* paul vixie, 29may94
*/
int
-res_nameinquery(name, type, class, buf, eom)
- const char *name;
- int type, class;
- const u_char *buf, *eom;
+res_nameinquery(const char *name, int type, int class,
+ const u_char *buf, const u_char *eom)
{
const u_char *cp = buf + HFIXEDSZ;
int qdcount = ntohs(((HEADER*)buf)->qdcount);
@@ -291,13 +271,13 @@ res_nameinquery(name, type, class, buf, eom)
return (-1);
ttype = ns_get16(cp); cp += INT16SZ;
tclass = ns_get16(cp); cp += INT16SZ;
- if (ttype == type &&
- tclass == class &&
- strcasecmp(tname, name) == 0)
+ if (ttype == type && tclass == class &&
+ ns_samename(tname, name) == 1)
return (1);
}
return (0);
}
+libresolv_hidden_def (res_nameinquery)
/* int
* res_queriesmatch(buf1, eom1, buf2, eom2)
@@ -311,9 +291,8 @@ res_nameinquery(name, type, class, buf, eom)
* paul vixie, 29may94
*/
int
-res_queriesmatch(buf1, eom1, buf2, eom2)
- const u_char *buf1, *eom1;
- const u_char *buf2, *eom2;
+res_queriesmatch(const u_char *buf1, const u_char *eom1,
+ const u_char *buf2, const u_char *eom2)
{
const u_char *cp = buf1 + HFIXEDSZ;
int qdcount = ntohs(((HEADER*)buf1)->qdcount);
@@ -325,8 +304,8 @@ res_queriesmatch(buf1, eom1, buf2, eom2)
* Only header section present in replies to
* dynamic update packets.
*/
- if ( (((HEADER *)buf1)->opcode == ns_o_update) &&
- (((HEADER *)buf2)->opcode == ns_o_update) )
+ if ((((HEADER *)buf1)->opcode == ns_o_update) &&
+ (((HEADER *)buf2)->opcode == ns_o_update))
return (1);
if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
@@ -348,75 +327,172 @@ res_queriesmatch(buf1, eom1, buf2, eom2)
}
return (1);
}
+libresolv_hidden_def (res_queriesmatch)
int
-res_send(buf, buflen, ans, anssiz)
- const u_char *buf;
- int buflen;
- u_char *ans;
- int anssiz;
+__libc_res_nsend(res_state statp, const u_char *buf, int buflen,
+ u_char *ans, int anssiz, u_char **ansp)
{
- HEADER *hp = (HEADER *) buf;
- HEADER *anhp = (HEADER *) ans;
- int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns, n;
- int kq;
- u_int badns; /* XXX NSMAX can't exceed #/bits in this variable */
+ int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- /* errno should have been set by res_init() in this case. */
+ if (statp->nscount == 0) {
+ __set_errno (ESRCH);
return (-1);
}
+
if (anssiz < HFIXEDSZ) {
- errno = EINVAL;
+ __set_errno (EINVAL);
return (-1);
}
- DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+
+ if ((statp->qhook || statp->rhook) && anssiz < MAXPACKET && ansp) {
+ u_char *buf = malloc (MAXPACKET);
+ if (buf == NULL)
+ return (-1);
+ memcpy (buf, ans, HFIXEDSZ);
+ *ansp = buf;
+ ans = buf;
+ anssiz = MAXPACKET;
+ }
+
+ DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
(stdout, ";; res_send()\n"), buf, buflen);
- v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
+ v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
gotsomewhere = 0;
- connreset = 0;
terrno = ETIMEDOUT;
- badns = 0;
/*
- * Send request, RETRY times, or until successful
+ * If the ns_addr_list in the resolver context has changed, then
+ * invalidate our cached copy and the associated timing data.
*/
- for (try = 0; try < _res.retry; try++) {
- for (ns = 0; ns < _res.nscount; ns++) {
- struct sockaddr *nsap = get_nsaddr(ns);
- socklen_t salen;
-
- if (nsap->sa_family == AF_INET6)
- salen = sizeof(struct sockaddr_in6);
- else if (nsap->sa_family == AF_INET)
- salen = sizeof(struct sockaddr_in);
+ if (EXT(statp).nsinit) {
+ int needclose = 0;
+
+ if (EXT(statp).nscount != statp->nscount)
+ needclose++;
else
- salen = 0; /*unknown, die on connect*/
+ for (ns = 0; ns < MAXNS; ns++) {
+ unsigned int map = EXT(statp).nsmap[ns];
+ if (map < MAXNS
+ && !sock_eq((struct sockaddr_in6 *)
+ &statp->nsaddr_list[map],
+ EXT(statp).nsaddrs[ns]))
+ {
+ needclose++;
+ break;
+ }
+ }
+ if (needclose)
+ res_nclose(statp);
+ }
- same_ns:
- if (badns & (1 << ns)) {
- res_close();
- goto next_ns;
+ /*
+ * Maybe initialize our private copy of the ns_addr_list.
+ */
+ if (EXT(statp).nsinit == 0) {
+ unsigned char map[MAXNS];
+
+ memset (map, MAXNS, sizeof (map));
+ for (n = 0; n < MAXNS; n++) {
+ ns = EXT(statp).nsmap[n];
+ if (ns < statp->nscount)
+ map[ns] = n;
+ else if (ns < MAXNS) {
+ free(EXT(statp).nsaddrs[n]);
+ EXT(statp).nsaddrs[n] = NULL;
+ EXT(statp).nsmap[n] = MAXNS;
+ }
+ }
+ n = statp->nscount;
+ if (statp->nscount > EXT(statp).nscount)
+ for (n = EXT(statp).nscount, ns = 0;
+ n < statp->nscount; n++) {
+ while (ns < MAXNS
+ && EXT(statp).nsmap[ns] != MAXNS)
+ ns++;
+ if (ns == MAXNS)
+ break;
+ EXT(statp).nsmap[ns] = n;
+ map[n] = ns++;
+ }
+ EXT(statp).nscount = n;
+ for (ns = 0; ns < EXT(statp).nscount; ns++) {
+ n = map[ns];
+ if (EXT(statp).nsaddrs[n] == NULL)
+ EXT(statp).nsaddrs[n] =
+ malloc(sizeof (struct sockaddr_in6));
+ if (EXT(statp).nsaddrs[n] != NULL) {
+ memcpy(EXT(statp).nsaddrs[n],
+ &statp->nsaddr_list[ns],
+ sizeof (struct sockaddr_in));
+ EXT(statp).nssocks[n] = -1;
+ n++;
+ }
+ }
+ EXT(statp).nsinit = 1;
+ }
+
+ /*
+ * Some resolvers want to even out the load on their nameservers.
+ * Note that RES_BLAST overrides RES_ROTATE.
+ */
+ if ((statp->options & RES_ROTATE) != 0 &&
+ (statp->options & RES_BLAST) == 0) {
+ struct sockaddr_in6 *ina;
+ unsigned int map;
+
+ n = 0;
+ while (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)
+ n++;
+ if (n < MAXNS) {
+ ina = EXT(statp).nsaddrs[n];
+ map = EXT(statp).nsmap[n];
+ for (;;) {
+ ns = n + 1;
+ while (ns < MAXNS
+ && EXT(statp).nsmap[ns] == MAXNS)
+ ns++;
+ if (ns == MAXNS)
+ break;
+ EXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];
+ EXT(statp).nsmap[n] = EXT(statp).nsmap[ns];
+ n = ns;
+ }
+ EXT(statp).nsaddrs[n] = ina;
+ EXT(statp).nsmap[n] = map;
}
+ }
+
+ /*
+ * Send request, RETRY times, or until successful.
+ */
+ for (try = 0; try < statp->retry; try++) {
+ for (ns = 0; ns < MAXNS; ns++)
+ {
+ struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
- if (Qhook) {
+ if (nsap == NULL)
+ goto next_ns;
+ same_ns:
+ if (statp->qhook) {
int done = 0, loops = 0;
do {
res_sendhookact act;
- act = (*Qhook)((struct sockaddr_in **)&nsap,
- &buf, &buflen,
- ans, anssiz, &resplen);
+ struct sockaddr_in *nsap4;
+ nsap4 = (struct sockaddr_in *) nsap;
+ act = (*statp->qhook)(&nsap4, &buf, &buflen,
+ ans, anssiz, &resplen);
+ nsap = (struct sockaddr_in6 *) nsap4;
switch (act) {
case res_goahead:
done = 1;
break;
case res_nextns:
- res_close();
+ res_nclose(statp);
goto next_ns;
case res_done:
- close(kq);
return (resplen);
case res_modified:
/* give the hook another try */
@@ -426,473 +502,77 @@ res_send(buf, buflen, ans, anssiz)
case res_error:
/*FALLTHROUGH*/
default:
- close(kq);
return (-1);
}
} while (!done);
}
- Dprint((_res.options & RES_DEBUG) &&
- getnameinfo(nsap, salen, abuf, sizeof(abuf),
- NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0,
+#ifdef DEBUG
+ char tmpbuf[40];
+#endif
+ Dprint(statp->options & RES_DEBUG,
(stdout, ";; Querying server (# %d) address = %s\n",
- ns + 1, abuf));
+ ns + 1, inet_ntop(AF_INET6, &nsap->sin6_addr,
+ tmpbuf, sizeof (tmpbuf))));
if (v_circuit) {
- int truncated;
- u_short len;
- u_char *cp;
- ssize_t rc;
-
- /*
- * Use virtual circuit;
- * at most one attempt per server.
- */
- try = _res.retry;
- truncated = 0;
- if (s < 0 || !vc || hp->opcode == ns_o_update ||
- af != nsap->sa_family) {
- if (s >= 0)
- res_close();
-
- af = nsap->sa_family;
- s = socket(af, SOCK_STREAM, 0);
- if (s < 0) {
- terrno = errno;
- Perror(stderr, "socket(vc)", errno);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- errno = 0;
- if (connect(s, nsap, salen) < 0) {
- terrno = errno;
- Aerror(stderr, "connect/vc",
- errno, nsap);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- vc = 1;
- }
- /*
- * Send length & message
- */
- putshort((u_short)buflen, (u_char*)&len);
-#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
- {
- struct iovec iov[2];
- iov[0].iov_base = (caddr_t)&len;
- iov[0].iov_len = INT16SZ;
- iov[1].iov_base = (caddr_t)buf;
- iov[1].iov_len = buflen;
- rc = writev(s, iov, 2);
- }
-#else /* EL/IX level 1 */
- {
- char *tmpbuf;
- tmpbuf = malloc (INT16SZ + buflen);
- memcpy (tmpbuf, &len, INT16SZ);
- memcpy (tmpbuf + INT16SZ, buf, buflen);
- rc = write (s, tmpbuf, INT16SZ + buflen);
- }
-#endif /* EL/IX level 1 */
- if (rc != (INT16SZ + buflen)) {
- terrno = errno;
- Perror(stderr, "write failed", errno);
- badns |= (1 << ns);
- res_close();
+ /* Use VC; at most one attempt per server. */
+ try = statp->retry;
+ n = send_vc(statp, buf, buflen, &ans, &anssiz, &terrno,
+ ns, ansp);
+ if (n < 0)
+ return (-1);
+ if (n == 0)
goto next_ns;
- }
- /*
- * Receive length & response
- */
- read_len:
- cp = ans;
- len = INT16SZ;
- while ((n = read(s, (char *)cp, (int)len)) > 0) {
- cp += n;
- if ((len -= n) <= 0)
- break;
- }
- if (n <= 0) {
- terrno = errno;
- Perror(stderr, "read failed", errno);
- res_close();
- /*
- * A long running process might get its TCP
- * connection reset if the remote server was
- * restarted. Requery the server instead of
- * trying a new one. When there is only one
- * server, this means that a query might work
- * instead of failing. We only allow one reset
- * per query to prevent looping.
- */
- if (terrno == ECONNRESET && !connreset) {
- connreset = 1;
- res_close();
- goto same_ns;
- }
- res_close();
- goto next_ns;
- }
- resplen = ns_get16(ans);
- if (resplen > anssiz) {
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; response truncated\n")
- );
- truncated = 1;
- len = anssiz;
- } else
- len = resplen;
- if (len < HFIXEDSZ) {
- /*
- * Undersized message.
- */
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; undersized: %d\n", len));
- terrno = EMSGSIZE;
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- cp = ans;
- while (len != 0 &&
- (n = read(s, (char *)cp, (int)len)) > 0) {
- cp += n;
- len -= n;
- }
- if (n <= 0) {
- terrno = errno;
- Perror(stderr, "read(vc)", errno);
- res_close();
- goto next_ns;
- }
- if (truncated) {
- /*
- * Flush rest of answer
- * so connection stays in synch.
- */
- anhp->tc = 1;
- len = resplen - anssiz;
- while (len != 0) {
- char junk[PACKETSZ];
-
- n = (len > sizeof(junk)
- ? sizeof(junk)
- : len);
- if ((n = read(s, junk, n)) > 0)
- len -= n;
- else
- break;
- }
- }
- /*
- * The calling applicating has bailed out of
- * a previous call and failed to arrange to have
- * the circuit closed or the server has got
- * itself confused. Anyway drop the packet and
- * wait for the correct one.
- */
- if (hp->id != anhp->id) {
- DprintQ((_res.options & RES_DEBUG) ||
- (_res.pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer (unexpected):\n"),
- ans, (resplen>anssiz)?anssiz:resplen);
- goto read_len;
- }
+ resplen = n;
} else {
- /*
- * Use datagrams.
- */
- struct pollfd pfd[1];
- int ptimeout;
- struct timespec ts;
- struct timeval timeout, ctv;
- struct sockaddr_storage from;
- int fromlen;
-
- if (s < 0 || vc || af != nsap->sa_family) {
- if (vc)
- res_close();
- af = nsap->sa_family;
- s = socket(af, SOCK_DGRAM, 0);
- if (s < 0) {
-#ifndef CAN_RECONNECT
- bad_dg_sock:
-#endif
- terrno = errno;
- Perror(stderr, "socket(dg)", errno);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- connected = 0;
- }
-#ifndef CANNOT_CONNECT_DGRAM
- /*
- * On a 4.3BSD+ machine (client and server,
- * actually), sending to a nameserver datagram
- * port with no nameserver will cause an
- * ICMP port unreachable message to be returned.
- * If our datagram socket is "connected" to the
- * server, we get an ECONNREFUSED error on the next
- * socket operation, and select returns if the
- * error message is received. We can thus detect
- * the absence of a nameserver without timing out.
- * If we have sent queries to at least two servers,
- * however, we don't want to remain connected,
- * as we wish to receive answers from the first
- * server to respond.
- *
- * When the option "insecure1" is specified, we'd
- * rather expect to see responses from an "unknown"
- * address. In order to let the kernel accept such
- * responses, do not connect the socket here.
- * XXX: or do we need an explicit option to disable
- * connecting?
- */
- if (!(_res.options & RES_INSECURE1) &&
- (_res.nscount == 1 || (try == 0 && ns == 0))) {
- /*
- * Connect only if we are sure we won't
- * receive a response from another server.
- */
- if (!connected) {
- if (connect(s, nsap, salen) < 0) {
- Aerror(stderr,
- "connect(dg)",
- errno, nsap);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- connected = 1;
- }
-
- if (send(s, (char*)buf, buflen, 0) != buflen) {
- Perror(stderr, "send", errno);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- } else {
- /*
- * Disconnect if we want to listen
- * for responses from more than one server.
- */
- if (connected) {
-#ifdef CAN_RECONNECT
- /* XXX: any errornous address */
- struct sockaddr_in no_addr;
-
- no_addr.sin_family = AF_INET;
- no_addr.sin_addr.s_addr = INADDR_ANY;
- no_addr.sin_port = 0;
- (void) connect(s,
- (struct sockaddr *)
- &no_addr,
- sizeof no_addr);
-#else
- int s1 = socket(af, SOCK_DGRAM,0);
- if (s1 < 0)
- goto bad_dg_sock;
- (void)_dup2(s1, s);
- (void)close(s1);
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; new DG socket\n"))
-#endif /* CAN_RECONNECT */
- connected = 0;
- errno = 0;
- }
-#endif /* !CANNOT_CONNECT_DGRAM */
- if (sendto(s, (char*)buf, buflen, 0,
- nsap, salen) != buflen) {
- Aerror(stderr, "sendto", errno, nsap);
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
-#ifndef CANNOT_CONNECT_DGRAM
- }
-#endif /* !CANNOT_CONNECT_DGRAM */
-
- /*
- * Wait for reply
- */
-
- timeout.tv_sec = (_res.retrans << try);
- if (try > 0)
- timeout.tv_sec /= _res.nscount;
- if ((long) timeout.tv_sec <= 0)
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
- TIMEVAL_TO_TIMESPEC(&timeout, &ts);
- (void) gettimeofday(&ctv, NULL);
- timeradd(&timeout, &ctv, &timeout);
-
- /* Convert struct timespec in milliseconds. */
- ptimeout = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
- wait:
- pfd[0].fd = s;
- pfd[0].events = POLLIN;
- n = poll (pfd, 1, ptimeout);
-
- if (s < 0) {
- Perror(stderr, "s out-of-bounds", EMFILE);
- res_close();
- goto next_ns;
- }
-
- if (n < 0) {
- if (errno == EINTR) {
- (void) gettimeofday(&ctv, NULL);
- if (timercmp(&ctv, &timeout, <)) {
- timersub(&timeout, &ctv, &ctv);
- TIMEVAL_TO_TIMESPEC(&ctv, &ts);
- goto wait;
- }
- }
- Perror(stderr, "poll", errno);
- res_close();
+ /* Use datagrams. */
+ n = send_dg(statp, buf, buflen, &ans, &anssiz, &terrno,
+ ns, &v_circuit, &gotsomewhere, ansp);
+ if (n < 0)
+ return (-1);
+ if (n == 0)
goto next_ns;
- }
-
- if (n == 0) {
- /*
- * timeout
- */
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; timeout\n"));
- gotsomewhere = 1;
- res_close();
- goto next_ns;
- }
- errno = 0;
- fromlen = sizeof(from);
- resplen = recvfrom(s, (char*)ans, anssiz, 0,
- (struct sockaddr *)&from, &fromlen);
- if (resplen <= 0) {
- Perror(stderr, "recvfrom", errno);
- res_close();
- goto next_ns;
- }
- gotsomewhere = 1;
- if (resplen < HFIXEDSZ) {
- /*
- * Undersized message.
- */
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; undersized: %d\n",
- resplen));
- terrno = EMSGSIZE;
- badns |= (1 << ns);
- res_close();
- goto next_ns;
- }
- if (hp->id != anhp->id) {
- /*
- * response from old query, ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((_res.options & RES_DEBUG) ||
- (_res.pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer:\n"),
- ans, (resplen>anssiz)?anssiz:resplen);
- goto wait;
- }
-#ifdef CHECK_SRVR_ADDR
- if (!(_res.options & RES_INSECURE1) &&
- !res_isourserver((struct sockaddr_in *)&from)) {
- /*
- * response from wrong server? ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((_res.options & RES_DEBUG) ||
- (_res.pfcode & RES_PRF_REPLY),
- (stdout, ";; not our server:\n"),
- ans, (resplen>anssiz)?anssiz:resplen);
- goto wait;
- }
-#endif
- if (!(_res.options & RES_INSECURE2) &&
- !res_queriesmatch(buf, buf + buflen,
- ans, ans + anssiz)) {
- /*
- * response contains wrong query? ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((_res.options & RES_DEBUG) ||
- (_res.pfcode & RES_PRF_REPLY),
- (stdout, ";; wrong query name:\n"),
- ans, (resplen>anssiz)?anssiz:resplen);
- goto wait;
- }
- if (anhp->rcode == SERVFAIL ||
- anhp->rcode == NOTIMP ||
- anhp->rcode == REFUSED) {
- DprintQ(_res.options & RES_DEBUG,
- (stdout, "server rejected query:\n"),
- ans, (resplen>anssiz)?anssiz:resplen);
- badns |= (1 << ns);
- res_close();
- /* don't retry if called from dig */
- if (!_res.pfcode)
- goto next_ns;
- }
- if (!(_res.options & RES_IGNTC) && anhp->tc) {
- /*
- * get rest of answer;
- * use TCP with same server.
- */
- Dprint(_res.options & RES_DEBUG,
- (stdout, ";; truncated answer\n"));
- v_circuit = 1;
- res_close();
+ if (v_circuit)
goto same_ns;
- }
- } /*if vc/dg*/
- Dprint((_res.options & RES_DEBUG) ||
- ((_res.pfcode & RES_PRF_REPLY) &&
- (_res.pfcode & RES_PRF_HEAD1)),
+ resplen = n;
+ }
+
+ Dprint((statp->options & RES_DEBUG) ||
+ ((statp->pfcode & RES_PRF_REPLY) &&
+ (statp->pfcode & RES_PRF_HEAD1)),
(stdout, ";; got answer:\n"));
-#if 0
- DprintQ((_res.options & RES_DEBUG) ||
- (_res.pfcode & RES_PRF_REPLY),
- (stdout, ""),
- ans, (resplen>anssiz)?anssiz:resplen);
-#endif
+
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, "%s", ""),
+ ans, (resplen > anssiz) ? anssiz : resplen);
+
/*
- * If using virtual circuits, we assume that the first server
- * is preferred over the rest (i.e. it is on the local
- * machine) and only keep that one open.
* If we have temporarily opened a virtual circuit,
* or if we haven't been asked to keep a socket open,
* close the socket.
*/
- if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
- !(_res.options & RES_STAYOPEN)) {
- res_close();
+ if ((v_circuit && (statp->options & RES_USEVC) == 0) ||
+ (statp->options & RES_STAYOPEN) == 0) {
+ res_nclose(statp);
}
- if (Rhook) {
+ if (statp->rhook) {
int done = 0, loops = 0;
do {
res_sendhookact act;
- act = (*Rhook)((struct sockaddr_in *)nsap,
- buf, buflen,
- ans, anssiz, &resplen);
+ act = (*statp->rhook)((struct sockaddr_in *)
+ nsap, buf, buflen,
+ ans, anssiz, &resplen);
switch (act) {
case res_goahead:
case res_done:
done = 1;
break;
case res_nextns:
- res_close();
+ res_nclose(statp);
goto next_ns;
case res_modified:
/* give the hook another try */
@@ -902,53 +582,535 @@ res_send(buf, buflen, ans, anssiz)
case res_error:
/*FALLTHROUGH*/
default:
- close(kq);
return (-1);
}
} while (!done);
}
- close(kq);
return (resplen);
- next_ns: ;
+ next_ns: ;
} /*foreach ns*/
} /*foreach retry*/
- res_close();
- close(kq);
+ res_nclose(statp);
if (!v_circuit) {
if (!gotsomewhere)
- errno = ECONNREFUSED; /* no nameservers found */
+ __set_errno (ECONNREFUSED); /* no nameservers found */
else
- errno = ETIMEDOUT; /* no answer obtained */
+ __set_errno (ETIMEDOUT); /* no answer obtained */
} else
- errno = terrno;
+ __set_errno (terrno);
return (-1);
}
-/*
- * This routine is for closing the socket if a virtual circuit is used and
- * the program wants to close it. This provides support for endhostent()
- * which expects to close the socket.
- *
- * This routine is not expected to be user visible.
- */
-void
-res_close()
+int
+res_nsend(res_state statp,
+ const u_char *buf, int buflen, u_char *ans, int anssiz)
+{
+ return __libc_res_nsend(statp, buf, buflen, ans, anssiz, NULL);
+}
+libresolv_hidden_def (res_nsend)
+
+/* Private */
+
+static int
+send_vc(res_state statp,
+ const u_char *buf, int buflen, u_char **ansp, int *anssizp,
+ int *terrno, int ns, u_char **anscp)
{
- if (s >= 0) {
- (void)close(s);
- s = -1;
- connected = 0;
- vc = 0;
- af = 0;
+ const HEADER *hp = (HEADER *) buf;
+ u_char *ans = *ansp;
+ int anssiz = *anssizp;
+ HEADER *anhp = (HEADER *) ans;
+ struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
+ int truncating, connreset, resplen, n;
+ struct iovec iov[2];
+ u_short len;
+ u_char *cp;
+
+ connreset = 0;
+ same_ns:
+ truncating = 0;
+
+ /* Are we still talking to whom we want to talk to? */
+ if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
+ struct sockaddr_in6 peer;
+ int size = sizeof peer;
+
+ if (getpeername(statp->_vcsock,
+ (struct sockaddr *)&peer, &size) < 0 ||
+ !sock_eq(&peer, nsap)) {
+ res_nclose(statp);
+ statp->_flags &= ~RES_F_VC;
+ }
}
+
+ if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
+ if (statp->_vcsock >= 0)
+ res_nclose(statp);
+
+ statp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);
+ if (statp->_vcsock < 0) {
+ *terrno = errno;
+ Perror(statp, stderr, "socket(vc)", errno);
+ return (-1);
+ }
+ __set_errno (0);
+ if (connect(statp->_vcsock, (struct sockaddr *)nsap,
+ sizeof *nsap) < 0) {
+ *terrno = errno;
+ Aerror(statp, stderr, "connect/vc", errno,
+ (struct sockaddr *) nsap);
+ res_nclose(statp);
+ return (0);
+ }
+ statp->_flags |= RES_F_VC;
+ }
+
+ /*
+ * Send length & message
+ */
+ putshort((u_short)buflen, (u_char*)&len);
+ evConsIovec(&len, INT16SZ, &iov[0]);
+ evConsIovec((void*)buf, buflen, &iov[1]);
+ if (TEMP_FAILURE_RETRY (writev(statp->_vcsock, iov, 2))
+ != (INT16SZ + buflen)) {
+ *terrno = errno;
+ Perror(statp, stderr, "write failed", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ /*
+ * Receive length & response
+ */
+ read_len:
+ cp = ans;
+ len = INT16SZ;
+ while ((n = TEMP_FAILURE_RETRY (read(statp->_vcsock, (char *)cp,
+ (int)len))) > 0) {
+ cp += n;
+ if ((len -= n) <= 0)
+ break;
+ }
+ if (n <= 0) {
+ *terrno = errno;
+ Perror(statp, stderr, "read failed", errno);
+ res_nclose(statp);
+ /*
+ * A long running process might get its TCP
+ * connection reset if the remote server was
+ * restarted. Requery the server instead of
+ * trying a new one. When there is only one
+ * server, this means that a query might work
+ * instead of failing. We only allow one reset
+ * per query to prevent looping.
+ */
+ if (*terrno == ECONNRESET && !connreset) {
+ connreset = 1;
+ res_nclose(statp);
+ goto same_ns;
+ }
+ res_nclose(statp);
+ return (0);
+ }
+ resplen = ns_get16(ans);
+ if (resplen > anssiz) {
+ if (anscp) {
+ ans = malloc (MAXPACKET);
+ if (ans == NULL) {
+ *terrno = ENOMEM;
+ res_nclose(statp);
+ return (0);
+ }
+ anssiz = MAXPACKET;
+ *anssizp = MAXPACKET;
+ *ansp = ans;
+ *anscp = ans;
+ anhp = (HEADER *) ans;
+ len = resplen;
+ } else {
+ Dprint(statp->options & RES_DEBUG,
+ (stdout, ";; response truncated\n")
+ );
+ truncating = 1;
+ len = anssiz;
+ }
+ } else
+ len = resplen;
+ if (len < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(statp->options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n", len));
+ *terrno = EMSGSIZE;
+ res_nclose(statp);
+ return (0);
+ }
+ cp = ans;
+ while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0){
+ cp += n;
+ len -= n;
+ }
+ if (n <= 0) {
+ *terrno = errno;
+ Perror(statp, stderr, "read(vc)", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ if (truncating) {
+ /*
+ * Flush rest of answer so connection stays in synch.
+ */
+ anhp->tc = 1;
+ len = resplen - anssiz;
+ while (len != 0) {
+ char junk[PACKETSZ];
+
+ n = read(statp->_vcsock, junk,
+ (len > sizeof junk) ? sizeof junk : len);
+ if (n > 0)
+ len -= n;
+ else
+ break;
+ }
+ }
+ /*
+ * If the calling applicating has bailed out of
+ * a previous call and failed to arrange to have
+ * the circuit closed or the server has got
+ * itself confused, then drop the packet and
+ * wait for the correct one.
+ */
+ if (hp->id != anhp->id) {
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer (unexpected):\n"),
+ ans, (resplen > anssiz) ? anssiz: resplen);
+ goto read_len;
+ }
+
+ /*
+ * All is well, or the error is fatal. Signal that the
+ * next nameserver ought not be tried.
+ */
+ return (resplen);
+}
+
+static int
+send_dg(res_state statp,
+ const u_char *buf, int buflen, u_char **ansp, int *anssizp,
+ int *terrno, int ns, int *v_circuit, int *gotsomewhere, u_char **anscp)
+{
+ const HEADER *hp = (HEADER *) buf;
+ u_char *ans = *ansp;
+ int anssiz = *anssizp;
+ HEADER *anhp = (HEADER *) ans;
+ struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
+ struct timespec now, timeout, finish;
+ struct pollfd pfd[1];
+ int ptimeout;
+ struct sockaddr_in6 from;
+ static int socket_pf = 0;
+ int fromlen, resplen, seconds, n;
+
+ if (EXT(statp).nssocks[ns] == -1) {
+ /* only try IPv6 if IPv6 NS and if not failed before */
+ if ((EXT(statp).nscount6 > 0) && (socket_pf != PF_INET)) {
+ EXT(statp).nssocks[ns] =
+ socket(PF_INET6, SOCK_DGRAM, 0);
+ socket_pf = EXT(statp).nssocks[ns] < 0 ? PF_INET
+ : PF_INET6;
+ }
+ if (EXT(statp).nssocks[ns] < 0)
+ EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0);
+ if (EXT(statp).nssocks[ns] < 0) {
+ *terrno = errno;
+ Perror(statp, stderr, "socket(dg)", errno);
+ return (-1);
+ }
+ /* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */
+ if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET))
+ convaddr4to6(nsap);
+ /*
+ * On a 4.3BSD+ machine (client and server,
+ * actually), sending to a nameserver datagram
+ * port with no nameserver will cause an
+ * ICMP port unreachable message to be returned.
+ * If our datagram socket is "connected" to the
+ * server, we get an ECONNREFUSED error on the next
+ * socket operation, and select returns if the
+ * error message is received. We can thus detect
+ * the absence of a nameserver without timing out.
+ */
+ if (connect(EXT(statp).nssocks[ns], (struct sockaddr *)nsap,
+ sizeof *nsap) < 0) {
+ Aerror(statp, stderr, "connect(dg)", errno,
+ (struct sockaddr *) nsap);
+ res_nclose(statp);
+ return (0);
+ }
+ /* Make socket non-blocking. */
+ int fl = fcntl (EXT(statp).nssocks[ns], F_GETFL);
+ if (fl != -1)
+ fcntl (EXT(statp).nssocks[ns], F_SETFL,
+ fl | O_NONBLOCK);
+ Dprint(statp->options & RES_DEBUG,
+ (stdout, ";; new DG socket\n"))
+ }
+
+ /*
+ * Compute time for the total operation.
+ */
+ seconds = (statp->retrans << ns);
+ if (ns > 0)
+ seconds /= statp->nscount;
+ if (seconds <= 0)
+ seconds = 1;
+ evNowTime(&now);
+ evConsTime(&timeout, seconds, 0);
+ evAddTime(&finish, &now, &timeout);
+ int need_recompute = 0;
+ int nwritten = 0;
+ pfd[0].fd = EXT(statp).nssocks[ns];
+ pfd[0].events = POLLOUT;
+ wait:
+ if (need_recompute) {
+ evNowTime(&now);
+ if (evCmpTime(finish, now) <= 0) {
+ Perror(statp, stderr, "select", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ evSubTime(&timeout, &finish, &now);
+ }
+ /* Convert struct timespec in milliseconds. */
+ ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
+
+ n = 0;
+ if (nwritten == 0)
+ n = poll (pfd, 1, 0);
+ if (__builtin_expect (n == 0, 0)) {
+ n = poll (pfd, 1, ptimeout);
+ need_recompute = 1;
+ }
+ if (n == 0) {
+ Dprint(statp->options & RES_DEBUG, (stdout,
+ ";; timeout sending\n"));
+ *gotsomewhere = 1;
+ return (0);
+ }
+ if (n < 0) {
+ if (errno == EINTR) {
+ recompute_resend:
+ evNowTime(&now);
+ if (evCmpTime(finish, now) > 0) {
+ evSubTime(&timeout, &finish, &now);
+ goto wait;
+ }
+ }
+ Perror(statp, stderr, "poll", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ __set_errno (0);
+ if (pfd[0].revents & POLLOUT) {
+ if (send(pfd[0].fd, (char*)buf, buflen, 0) != buflen) {
+ if (errno == EINTR || errno == EAGAIN)
+ goto recompute_resend;
+ Perror(statp, stderr, "send", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ pfd[0].events = POLLIN;
+ ++nwritten;
+ goto wait;
+ } else if (pfd[0].revents & POLLIN) {
+ fromlen = sizeof(struct sockaddr_in6);
+ if (anssiz < MAXPACKET
+ && anscp
+ && (ioctl (pfd[0].fd, FIONREAD, &resplen) < 0
+ || anssiz < resplen)) {
+ ans = malloc (MAXPACKET);
+ if (ans == NULL)
+ ans = *ansp;
+ else {
+ anssiz = MAXPACKET;
+ *anssizp = MAXPACKET;
+ *ansp = ans;
+ *anscp = ans;
+ anhp = (HEADER *) ans;
+ }
+ }
+ resplen = recvfrom(pfd[0].fd, (char*)ans, anssiz,0,
+ (struct sockaddr *)&from, &fromlen);
+ if (resplen <= 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ need_recompute = 1;
+ goto wait;
+ }
+ Perror(statp, stderr, "recvfrom", errno);
+ res_nclose(statp);
+ return (0);
+ }
+ *gotsomewhere = 1;
+ if (resplen < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(statp->options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n",
+ resplen));
+ *terrno = EMSGSIZE;
+ res_nclose(statp);
+ return (0);
+ }
+ if (hp->id != anhp->id) {
+ /*
+ * response from old query, ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer:\n"),
+ ans, (resplen > anssiz) ? anssiz : resplen);
+ goto wait;
+ }
+ if (!(statp->options & RES_INSECURE1) &&
+ !res_ourserver_p(statp, &from)) {
+ /*
+ * response from wrong server? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, ";; not our server:\n"),
+ ans, (resplen > anssiz) ? anssiz : resplen);
+ goto wait;
+ }
+ if (!(statp->options & RES_INSECURE2) &&
+ !res_queriesmatch(buf, buf + buflen,
+ ans, ans + anssiz)) {
+ /*
+ * response contains wrong query? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, ";; wrong query name:\n"),
+ ans, (resplen > anssiz) ? anssiz : resplen);
+ goto wait;
+ }
+ if (anhp->rcode == SERVFAIL ||
+ anhp->rcode == NOTIMP ||
+ anhp->rcode == REFUSED) {
+ DprintQ(statp->options & RES_DEBUG,
+ (stdout, "server rejected query:\n"),
+ ans, (resplen > anssiz) ? anssiz : resplen);
+ res_nclose(statp);
+ /* don't retry if called from dig */
+ if (!statp->pfcode)
+ return (0);
+ }
+ if (!(statp->options & RES_IGNTC) && anhp->tc) {
+ /*
+ * To get the rest of answer,
+ * use TCP with same server.
+ */
+ Dprint(statp->options & RES_DEBUG,
+ (stdout, ";; truncated answer\n"));
+ *v_circuit = 1;
+ res_nclose(statp);
+ return (1);
+ }
+ /*
+ * All is well, or the error is fatal. Signal that the
+ * next nameserver ought not be tried.
+ */
+ return (resplen);
+ } else if (pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ /* Something went wrong. We can stop trying. */
+ res_nclose(statp);
+ return (0);
+ }
+}
+
+#ifdef DEBUG
+static void
+Aerror(const res_state statp, FILE *file, const char *string, int error,
+ const struct sockaddr *address)
+{
+ int save = errno;
+
+ if ((statp->options & RES_DEBUG) != 0) {
+ char tmp[sizeof "xxxx.xxxx.xxxx.255.255.255.255"];
+
+ fprintf(file, "res_send: %s ([%s].%u): %s\n",
+ string,
+ inet_ntop(address->sa_family, address->sa_data,
+ tmp, sizeof tmp),
+ (address->sa_family == AF_INET
+ ? ntohs(((struct sockaddr_in *) address)->sin_port)
+ : address->sa_family == AF_INET6
+ ? ntohs(((struct sockaddr_in6 *) address)->sin6_port)
+ : 0),
+ strerror(error));
+ }
+ __set_errno (save);
+}
+
+static void
+Perror(const res_state statp, FILE *file, const char *string, int error) {
+ int save = errno;
+
+ if ((statp->options & RES_DEBUG) != 0)
+ fprintf(file, "res_send: %s: %s\n",
+ string, strerror(error));
+ __set_errno (save);
+}
+#endif
+
+static int
+sock_eq(struct sockaddr_in6 *a1, struct sockaddr_in6 *a2) {
+ if (a1->sin6_family == a2->sin6_family) {
+ if (a1->sin6_family == AF_INET)
+ return ((((struct sockaddr_in *)a1)->sin_port ==
+ ((struct sockaddr_in *)a2)->sin_port) &&
+ (((struct sockaddr_in *)a1)->sin_addr.s_addr ==
+ ((struct sockaddr_in *)a2)->sin_addr.s_addr));
+ else
+ return ((a1->sin6_port == a2->sin6_port) &&
+ !memcmp(&a1->sin6_addr, &a2->sin6_addr,
+ sizeof (struct in6_addr)));
+ }
+ if (a1->sin6_family == AF_INET) {
+ struct sockaddr_in6 *sap = a1;
+ a1 = a2;
+ a2 = sap;
+ } /* assumes that AF_INET and AF_INET6 are the only possibilities */
+ return ((a1->sin6_port == ((struct sockaddr_in *)a2)->sin_port) &&
+ IN6_IS_ADDR_V4MAPPED(&a1->sin6_addr) &&
+ (a1->sin6_addr.s6_addr32[3] ==
+ ((struct sockaddr_in *)a2)->sin_addr.s_addr));
}
/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
+ * Converts IPv4 family, address and port to
+ * IPv6 family, IPv4-mapped IPv6 address and port.
*/
-#undef res_close
-__weak_reference(__res_close, _res_close);
-#undef res_send
-__weak_reference(__res_send, res_send);
+static void
+convaddr4to6(struct sockaddr_in6 *sa)
+{
+ struct sockaddr_in *sa4p = (struct sockaddr_in *) sa;
+ in_port_t port = sa4p->sin_port;
+ in_addr_t addr = sa4p->sin_addr.s_addr;
+
+ sa->sin6_family = AF_INET6;
+ sa->sin6_port = port;
+ sa->sin6_addr.s6_addr32[0] = 0;
+ sa->sin6_addr.s6_addr32[1] = 0;
+ sa->sin6_addr.s6_addr32[2] = htonl(0xFFFF);
+ sa->sin6_addr.s6_addr32[3] = addr;
+}
diff --git a/newlib/libc/sys/linux/net/res_update.c b/newlib/libc/sys/linux/net/res_update.c
deleted file mode 100644
index b427bf819..000000000
--- a/newlib/libc/sys/linux/net/res_update.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais@ccm.fm.intel.com>
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <machine/endian.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <limits.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/*
- * Separate a linked list of records into groups so that all records
- * in a group will belong to a single zone on the nameserver.
- * Create a dynamic update packet for each zone and send it to the
- * nameservers for that zone, and await answer.
- * Abort if error occurs in updating any zone.
- * Return the number of zones updated on success, < 0 on error.
- *
- * On error, caller must deal with the unsynchronized zones
- * eg. an A record might have been successfully added to the forward
- * zone but the corresponding PTR record would be missing if error
- * was encountered while updating the reverse zone.
- */
-
-#define NSMAX 16
-
-struct ns1 {
- char nsname[MAXDNAME];
- struct in_addr nsaddr1;
-};
-
-struct zonegrp {
- char z_origin[MAXDNAME];
- int16_t z_class;
- char z_soardata[MAXDNAME + 5 * INT32SZ];
- struct ns1 z_ns[NSMAX];
- int z_nscount;
- ns_updrec * z_rr;
- struct zonegrp *z_next;
-};
-
-
-int
-res_update(ns_updrec *rrecp_in) {
- ns_updrec *rrecp, *tmprrecp;
- u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
- char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
- mailaddr[MAXDNAME];
- u_char soardata[2*MAXCDNAME+5*INT32SZ];
- char *dname, *svdname, *cp1, *target;
- u_char *cp, *eom;
- HEADER *hp = (HEADER *) answer;
- struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
- int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
- newgroup, done, myzone, seen_before, numzones = 0;
- u_int16_t dlen, class, qclass, type, qtype;
- u_int32_t ttl;
-
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- h_errno = NETDB_INTERNAL;
- return (-1);
- }
-
- for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
- dname = rrecp->r_dname;
- n = strlen(dname);
- if (dname[n-1] == '.')
- dname[n-1] = '\0';
- qtype = T_SOA;
- qclass = rrecp->r_class;
- done = 0;
- seen_before = 0;
-
- while (!done && dname) {
- if (qtype == T_SOA) {
- for (tmpzptr = zgrp_start;
- tmpzptr && !seen_before;
- tmpzptr = tmpzptr->z_next) {
- if (strcasecmp(dname,
- tmpzptr->z_origin) == 0 &&
- tmpzptr->z_class == qclass)
- seen_before++;
- for (tmprrecp = tmpzptr->z_rr;
- tmprrecp && !seen_before;
- tmprrecp = tmprrecp->r_grpnext)
- if (strcasecmp(dname, tmprrecp->r_dname) == 0
- && tmprrecp->r_class == qclass) {
- seen_before++;
- break;
- }
- if (seen_before) {
- /*
- * Append to the end of
- * current group.
- */
- for (tmprrecp = tmpzptr->z_rr;
- tmprrecp->r_grpnext;
- tmprrecp = tmprrecp->r_grpnext)
- (void)NULL;
- tmprrecp->r_grpnext = rrecp;
- rrecp->r_grpnext = NULL;
- done = 1;
- break;
- }
- }
- } else if (qtype == T_A) {
- for (tmpzptr = zgrp_start;
- tmpzptr && !done;
- tmpzptr = tmpzptr->z_next)
- for (i = 0; i < tmpzptr->z_nscount; i++)
- if (tmpzptr->z_class == qclass &&
- strcasecmp(tmpzptr->z_ns[i].nsname,
- dname) == 0 &&
- tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
- zptr->z_ns[k].nsaddr1.s_addr =
- tmpzptr->z_ns[i].nsaddr1.s_addr;
- done = 1;
- break;
- }
- }
- if (done)
- break;
- n = res_mkquery(QUERY, dname, qclass, qtype, NULL,
- 0, NULL, buf, sizeof buf);
- if (n <= 0) {
- fprintf(stderr, "res_update: mkquery failed\n");
- return (n);
- }
- n = res_send(buf, n, answer, sizeof answer);
- if (n < 0) {
- fprintf(stderr, "res_update: send error for %s\n",
- rrecp->r_dname);
- return (n);
- }
- if (n < HFIXEDSZ)
- return (-1);
- ancount = ntohs(hp->ancount);
- nscount = ntohs(hp->nscount);
- arcount = ntohs(hp->arcount);
- rcode = hp->rcode;
- cp = answer + HFIXEDSZ;
- eom = answer + n;
- /* skip the question section */
- n = dn_skipname(cp, eom);
- if (n < 0 || cp + n + 2 * INT16SZ > eom)
- return (-1);
- cp += n + 2 * INT16SZ;
-
- if (qtype == T_SOA) {
- if (ancount == 0 && nscount == 0 && arcount == 0) {
- /*
- * if (rcode == NOERROR) then the dname exists but
- * has no soa record associated with it.
- * if (rcode == NXDOMAIN) then the dname does not
- * exist and the server is replying out of NCACHE.
- * in either case, proceed with the next try
- */
- dname = strchr(dname, '.');
- if (dname != NULL)
- dname++;
- continue;
- } else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
- ancount == 0 &&
- nscount == 1 && arcount == 0) {
- /*
- * name/data does not exist, soa record supplied in the
- * authority section
- */
- /* authority section must contain the soa record */
- if ((n = dn_expand(answer, eom, cp, zname,
- sizeof zname)) < 0)
- return (n);
- cp += n;
- if (cp + 2 * INT16SZ > eom)
- return (-1);
- GETSHORT(type, cp);
- GETSHORT(class, cp);
- if (type != T_SOA || class != qclass) {
- fprintf(stderr, "unknown answer\n");
- return (-1);
- }
- myzone = 0;
- svdname = dname;
- while (dname)
- if (strcasecmp(dname, zname) == 0) {
- myzone = 1;
- break;
- } else if ((dname = strchr(dname, '.')) != NULL)
- dname++;
- if (!myzone) {
- dname = strchr(svdname, '.');
- if (dname != NULL)
- dname++;
- continue;
- }
- nscount = 0;
- /* fallthrough */
- } else if (rcode == NOERROR && ancount == 1) {
- /*
- * found the zone name
- * new servers will supply NS records for the zone
- * in authority section and A records for those
- * nameservers in the additional section
- * older servers have to be explicitly queried for
- * NS records for the zone
- */
- /* answer section must contain the soa record */
- if ((n = dn_expand(answer, eom, cp, zname,
- sizeof zname)) < 0)
- return (n);
- else
- cp += n;
- if (cp + 2 * INT16SZ > eom)
- return (-1);
- GETSHORT(type, cp);
- GETSHORT(class, cp);
- if (type == T_CNAME) {
- dname = strchr(dname, '.');
- if (dname != NULL)
- dname++;
- continue;
- }
- if (strcasecmp(dname, zname) != 0 ||
- type != T_SOA ||
- class != rrecp->r_class) {
- fprintf(stderr, "unknown answer\n");
- return (-1);
- }
- /* FALLTHROUGH */
- } else {
- fprintf(stderr,
- "unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
- ancount, nscount, arcount, hp->rcode);
- return (-1);
- }
- if (cp + INT32SZ + INT16SZ > eom)
- return (-1);
- /* continue processing the soa record */
- GETLONG(ttl, cp);
- GETSHORT(dlen, cp);
- if (cp + dlen > eom)
- return (-1);
- newgroup = 1;
- zptr = zgrp_start;
- prevzptr = NULL;
- while (zptr) {
- if (strcasecmp(zname, zptr->z_origin) == 0 &&
- type == T_SOA && class == qclass) {
- newgroup = 0;
- break;
- }
- prevzptr = zptr;
- zptr = zptr->z_next;
- }
- if (!newgroup) {
- for (tmprrecp = zptr->z_rr;
- tmprrecp->r_grpnext;
- tmprrecp = tmprrecp->r_grpnext)
- ;
- tmprrecp->r_grpnext = rrecp;
- rrecp->r_grpnext = NULL;
- done = 1;
- cp += dlen;
- break;
- } else {
- if ((n = dn_expand(answer, eom, cp, primary,
- sizeof primary)) < 0)
- return (n);
- cp += n;
- /*
- * We don't have to bounds check here because the
- * next use of 'cp' is in dn_expand().
- */
- cp1 = (char *)soardata;
- strcpy(cp1, primary);
- cp1 += strlen(cp1) + 1;
- if ((n = dn_expand(answer, eom, cp, mailaddr,
- sizeof mailaddr)) < 0)
- return (n);
- cp += n;
- strcpy(cp1, mailaddr);
- cp1 += strlen(cp1) + 1;
- if (cp + 5*INT32SZ > eom)
- return (-1);
- memcpy(cp1, cp, 5*INT32SZ);
- cp += 5*INT32SZ;
- cp1 += 5*INT32SZ;
- rdatasize = (u_char *)cp1 - soardata;
- zptr = calloc(1, sizeof(struct zonegrp));
- if (zptr == NULL)
- return (-1);
- if (zgrp_start == NULL)
- zgrp_start = zptr;
- else
- prevzptr->z_next = zptr;
- zptr->z_rr = rrecp;
- rrecp->r_grpnext = NULL;
- strcpy(zptr->z_origin, zname);
- zptr->z_class = class;
- memcpy(zptr->z_soardata, soardata, rdatasize);
- /* fallthrough to process NS and A records */
- }
- } else if (qtype == T_NS) {
- if (rcode == NOERROR && ancount > 0) {
- strcpy(zname, dname);
- for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
- if (strcasecmp(zname, zptr->z_origin) == 0)
- break;
- }
- if (zptr == NULL)
- /* should not happen */
- return (-1);
- if (nscount > 0) {
- /*
- * answer and authority sections contain
- * the same information, skip answer section
- */
- for (j = 0; j < ancount; j++) {
- n = dn_skipname(cp, eom);
- if (n < 0)
- return (-1);
- n += 2*INT16SZ + INT32SZ;
- if (cp + n + INT16SZ > eom)
- return (-1);
- cp += n;
- GETSHORT(dlen, cp);
- cp += dlen;
- }
- } else
- nscount = ancount;
- /* fallthrough to process NS and A records */
- } else {
- fprintf(stderr, "cannot determine nameservers for %s:\
-ans=%d, auth=%d, add=%d, rcode=%d\n",
- dname, ancount, nscount, arcount, hp->rcode);
- return (-1);
- }
- } else if (qtype == T_A) {
- if (rcode == NOERROR && ancount > 0) {
- arcount = ancount;
- ancount = nscount = 0;
- /* fallthrough to process A records */
- } else {
- fprintf(stderr, "cannot determine address for %s:\
-ans=%d, auth=%d, add=%d, rcode=%d\n",
- dname, ancount, nscount, arcount, hp->rcode);
- return (-1);
- }
- }
- /* process NS records for the zone */
- j = 0;
- for (i = 0; i < nscount; i++) {
- if ((n = dn_expand(answer, eom, cp, name,
- sizeof name)) < 0)
- return (n);
- cp += n;
- if (cp + 3 * INT16SZ + INT32SZ > eom)
- return (-1);
- GETSHORT(type, cp);
- GETSHORT(class, cp);
- GETLONG(ttl, cp);
- GETSHORT(dlen, cp);
- if (cp + dlen > eom)
- return (-1);
- if (strcasecmp(name, zname) == 0 &&
- type == T_NS && class == qclass) {
- if ((n = dn_expand(answer, eom, cp,
- name, sizeof name)) < 0)
- return (n);
- target = zptr->z_ns[j++].nsname;
- strcpy(target, name);
- }
- cp += dlen;
- }
- if (zptr->z_nscount == 0)
- zptr->z_nscount = j;
- /* get addresses for the nameservers */
- for (i = 0; i < arcount; i++) {
- if ((n = dn_expand(answer, eom, cp, name,
- sizeof name)) < 0)
- return (n);
- cp += n;
- if (cp + 3 * INT16SZ + INT32SZ > eom)
- return (-1);
- GETSHORT(type, cp);
- GETSHORT(class, cp);
- GETLONG(ttl, cp);
- GETSHORT(dlen, cp);
- if (cp + dlen > eom)
- return (-1);
- if (type == T_A && dlen == INT32SZ && class == qclass) {
- for (j = 0; j < zptr->z_nscount; j++)
- if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
- memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
- INT32SZ);
- break;
- }
- }
- cp += dlen;
- }
- if (zptr->z_nscount == 0) {
- dname = zname;
- qtype = T_NS;
- continue;
- }
- done = 1;
- for (k = 0; k < zptr->z_nscount; k++)
- if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
- done = 0;
- dname = zptr->z_ns[k].nsname;
- qtype = T_A;
- }
-
- } /* while */
- }
-
- _res.options |= RES_DEBUG;
- for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
-
- /* append zone section */
- rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
- zptr->z_class, ns_t_soa, 0);
- if (rrecp == NULL) {
- fprintf(stderr, "saverrec error\n");
- fflush(stderr);
- return (-1);
- }
- rrecp->r_grpnext = zptr->z_rr;
- zptr->z_rr = rrecp;
-
- n = res_mkupdate(zptr->z_rr, packet, sizeof packet);
- if (n < 0) {
- fprintf(stderr, "res_mkupdate error\n");
- fflush(stderr);
- return (-1);
- } else
- fprintf(stdout, "res_mkupdate: packet size = %d\n", n);
-
- /*
- * Override the list of NS records from res_init() with
- * the authoritative nameservers for the zone being updated.
- * Sort primary to be the first in the list of nameservers.
- */
- for (i = 0; i < zptr->z_nscount; i++) {
- if (strcasecmp(zptr->z_ns[i].nsname,
- zptr->z_soardata) == 0) {
- struct in_addr tmpaddr;
-
- if (i != 0) {
- strcpy(zptr->z_ns[i].nsname,
- zptr->z_ns[0].nsname);
- strcpy(zptr->z_ns[0].nsname,
- zptr->z_soardata);
- tmpaddr = zptr->z_ns[i].nsaddr1;
- zptr->z_ns[i].nsaddr1 =
- zptr->z_ns[0].nsaddr1;
- zptr->z_ns[0].nsaddr1 = tmpaddr;
- }
- break;
- }
- }
- for (i = 0; i < MAXNS; i++) {
- _res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
- _res.nsaddr_list[i].sin_family = AF_INET;
- _res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
- }
- _res.nscount = (zptr->z_nscount < MAXNS) ?
- zptr->z_nscount : MAXNS;
- n = res_send(packet, n, answer, sizeof(answer));
- if (n < 0) {
- fprintf(stderr, "res_send: send error, n=%d\n", n);
- break;
- } else
- numzones++;
- }
-
- /* free malloc'ed memory */
- while(zgrp_start) {
- zptr = zgrp_start;
- zgrp_start = zgrp_start->z_next;
- res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */
- free((char *)zptr);
- }
-
- return (numzones);
-}
diff --git a/newlib/libc/sys/linux/net/resolver.3 b/newlib/libc/sys/linux/net/resolver.3
deleted file mode 100644
index 141759855..000000000
--- a/newlib/libc/sys/linux/net/resolver.3
+++ /dev/null
@@ -1,422 +0,0 @@
-.\" Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. 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.
-.\"
-.\" @(#)resolver.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/resolver.3,v 1.21 2001/10/01 16:08:56 ru Exp $
-.\"
-.Dd June 4, 1993
-.Dt RESOLVER 3
-.Os
-.Sh NAME
-.Nm res_query ,
-.Nm res_search ,
-.Nm res_mkquery ,
-.Nm res_send ,
-.Nm res_init ,
-.Nm dn_comp ,
-.Nm dn_expand ,
-.Nm dn_skipname ,
-.Nm ns_get16 ,
-.Nm ns_get32 ,
-.Nm ns_put16 ,
-.Nm ns_put32
-.Nd resolver routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In netinet/in.h
-.In arpa/nameser.h
-.In resolv.h
-.Ft int
-.Fo res_query
-.Fa "const char *dname"
-.Fa "int class"
-.Fa "int type"
-.Fa "u_char *answer"
-.Fa "int anslen"
-.Fc
-.Ft int
-.Fo res_search
-.Fa "const char *dname"
-.Fa "int class"
-.Fa "int type"
-.Fa "u_char *answer"
-.Fa "int anslen"
-.Fc
-.Ft int
-.Fo res_mkquery
-.Fa "int op"
-.Fa "const char *dname"
-.Fa "int class"
-.Fa "int type"
-.Fa "const u_char *data"
-.Fa "int datalen"
-.Fa "const u_char *newrr_in"
-.Fa "u_char *buf"
-.Fa "int buflen"
-.Fc
-.Ft int
-.Fo res_send
-.Fa "const u_char *msg"
-.Fa "int msglen"
-.Fa "u_char *answer"
-.Fa "int anslen"
-.Fc
-.Ft int
-.Fn res_init
-.Ft int
-.Fo dn_comp
-.Fa "const char *exp_dn"
-.Fa "u_char *comp_dn"
-.Fa "int length"
-.Fa "u_char **dnptrs"
-.Fa "u_char **lastdnptr"
-.Fc
-.Ft int
-.Fo dn_expand
-.Fa "const u_char *msg"
-.Fa "const u_char *eomorig"
-.Fa "const u_char *comp_dn"
-.Fa "char *exp_dn"
-.Fa "int length"
-.Fc
-.Ft int
-.Fn dn_skipname "const u_char *comp_dn" "const u_char *eom"
-.Ft u_int
-.Fn ns_get16 "const u_char *src"
-.Ft u_long
-.Fn ns_get32 "const u_char *src"
-.Ft void
-.Fn ns_put16 "u_int src" "u_char *dst"
-.Ft void
-.Fn ns_put32 "u_long src" "u_char *dst"
-.Sh DESCRIPTION
-These routines are used for making, sending and interpreting
-query and reply messages with Internet domain name servers.
-.Pp
-Global configuration and state information that is used by the
-resolver routines is kept in the structure
-.Em _res .
-Most of the values have reasonable defaults and can be ignored.
-Options
-stored in
-.Em _res.options
-are defined in
-.Pa resolv.h
-and are as follows.
-Options are stored as a simple bit mask containing the bitwise ``or''
-of the options enabled.
-.Bl -tag -width RES_USE_INET6
-.It Dv RES_INIT
-True if the initial name server address and default domain name are
-initialized (i.e.,
-.Fn res_init
-has been called).
-.It Dv RES_DEBUG
-Print debugging messages.
-.It Dv RES_AAONLY
-Accept authoritative answers only.
-With this option,
-.Fn res_send
-should continue until it finds an authoritative answer or finds an error.
-Currently this is not implemented.
-.It Dv RES_USEVC
-Use
-.Tn TCP
-connections for queries instead of
-.Tn UDP
-datagrams.
-.It Dv RES_STAYOPEN
-Used with
-.Dv RES_USEVC
-to keep the
-.Tn TCP
-connection open between
-queries.
-This is useful only in programs that regularly do many queries.
-.Tn UDP
-should be the normal mode used.
-.It Dv RES_IGNTC
-Unused currently (ignore truncation errors, i.e., don't retry with
-.Tn TCP ) .
-.It Dv RES_RECURSE
-Set the recursion-desired bit in queries.
-This is the default.
-.Pf ( Fn res_send
-does not do iterative queries and expects the name server
-to handle recursion.)
-.It Dv RES_DEFNAMES
-If set,
-.Fn res_search
-will append the default domain name to single-component names
-(those that do not contain a dot).
-This option is enabled by default.
-.It Dv RES_DNSRCH
-If this option is set,
-.Fn res_search
-will search for host names in the current domain and in parent domains; see
-.Xr hostname 7 .
-This is used by the standard host lookup routine
-.Xr gethostbyname 3 .
-This option is enabled by default.
-.It Dv RES_NOALIASES
-This option turns off the user level aliasing feature controlled by the
-.Dq Ev HOSTALIASES
-environment variable. Network daemons should set this option.
-.It Dv RES_USE_INET6
-Enables support for IPv6-only applications.
-This causes IPv4 addresses to be returned as an IPv4 mapped address.
-For example,
-.Li 10.1.1.1
-will be returned as
-.Li ::ffff:10.1.1.1 .
-The option is meaningful with certain kernel configuration only.
-.It Dv RES_USE_EDNS0
-Enables support for OPT pseudo-RR for EDNS0 extension.
-With the option, resolver code will attach OPT pseudo-RR into DNS queries,
-to inform of our receive buffer size.
-The option will allow DNS servers to take advantage of non-default receive
-buffer size, and to send larger replies.
-DNS query packets with EDNS0 extension is not compatible with
-non-EDNS0 DNS servers.
-.El
-.Pp
-The
-.Fn res_init
-routine
-reads the configuration file (if any; see
-.Xr resolver 5 )
-to get the default domain name,
-search list and
-the Internet address of the local name server(s).
-If no server is configured, the host running
-the resolver is tried.
-The current domain name is defined by the hostname
-if not specified in the configuration file;
-it can be overridden by the environment variable
-.Ev LOCALDOMAIN .
-This environment variable may contain several blank-separated
-tokens if you wish to override the
-.Em "search list"
-on a per-process basis. This is similar to the
-.Em search
-command in the configuration file.
-Another environment variable
-.Dq Ev RES_OPTIONS
-can be set to
-override certain internal resolver options which are otherwise
-set by changing fields in the
-.Em _res
-structure or are inherited from the configuration file's
-.Em options
-command. The syntax of the
-.Dq Ev RES_OPTIONS
-environment variable is explained in
-.Xr resolver 5 .
-Initialization normally occurs on the first call
-to one of the following routines.
-.Pp
-The
-.Fn res_query
-function provides an interface to the server query mechanism.
-It constructs a query, sends it to the local server,
-awaits a response, and makes preliminary checks on the reply.
-The query requests information of the specified
-.Fa type
-and
-.Fa class
-for the specified fully-qualified domain name
-.Fa dname .
-The reply message is left in the
-.Fa answer
-buffer with length
-.Fa anslen
-supplied by the caller.
-.Pp
-The
-.Fn res_search
-routine makes a query and awaits a response like
-.Fn res_query ,
-but in addition, it implements the default and search rules
-controlled by the
-.Dv RES_DEFNAMES
-and
-.Dv RES_DNSRCH
-options.
-It returns the first successful reply.
-.Pp
-The remaining routines are lower-level routines used by
-.Fn res_query .
-The
-.Fn res_mkquery
-function
-constructs a standard query message and places it in
-.Fa buf .
-It returns the size of the query, or \-1 if the query is
-larger than
-.Fa buflen .
-The query type
-.Fa op
-is usually
-.Dv QUERY ,
-but can be any of the query types defined in
-.Aq Pa arpa/nameser.h .
-The domain name for the query is given by
-.Fa dname .
-.Fa Newrr
-is currently unused but is intended for making update messages.
-.Pp
-The
-.Fn res_send
-routine
-sends a pre-formatted query and returns an answer.
-It will call
-.Fn res_init
-if
-.Dv RES_INIT
-is not set, send the query to the local name server, and
-handle timeouts and retries.
-The length of the reply message is returned, or
-\-1 if there were errors.
-.Pp
-The
-.Fn dn_comp
-function
-compresses the domain name
-.Fa exp_dn
-and stores it in
-.Fa comp_dn .
-The size of the compressed name is returned or \-1 if there were errors.
-The size of the array pointed to by
-.Fa comp_dn
-is given by
-.Fa length .
-The compression uses
-an array of pointers
-.Fa dnptrs
-to previously-compressed names in the current message.
-The first pointer points to
-the beginning of the message and the list ends with
-.Dv NULL .
-The limit to the array is specified by
-.Fa lastdnptr .
-A side effect of
-.Fn dn_comp
-is to update the list of pointers for
-labels inserted into the message
-as the name is compressed.
-If
-.Em dnptr
-is
-.Dv NULL ,
-names are not compressed.
-If
-.Fa lastdnptr
-is
-.Dv NULL ,
-the list of labels is not updated.
-.Pp
-The
-.Fn dn_expand
-entry
-expands the compressed domain name
-.Fa comp_dn
-to a full domain name
-The compressed name is contained in a query or reply message;
-.Fa msg
-is a pointer to the beginning of the message.
-The uncompressed name is placed in the buffer indicated by
-.Fa exp_dn
-which is of size
-.Fa length .
-The size of compressed name is returned or \-1 if there was an error.
-.Pp
-The
-.Fn dn_skipname
-function skips over a compressed domain name, which starts at a location
-pointed to by
-.Fa comp_dn .
-The compressed name is contained in a query or reply message;
-.Fa eom
-is a pointer to the end of the message.
-The size of compressed name is returned or \-1 if there was
-an error.
-.Pp
-The
-.Fn ns_get16
-function gets a 16-bit quantity from a buffer pointed to by
-.Fa src .
-.Pp
-The
-.Fn ns_get32
-function gets a 32-bit quantity from a buffer pointed to by
-.Fa src .
-.Pp
-The
-.Fn ns_put16
-function puts a 16-bit quantity
-.Fa src
-to a buffer pointed to by
-.Fa dst .
-.Pp
-The
-.Fn ns_put32
-function puts a 32-bit quantity
-.Fa src
-to a buffer pointed to by
-.Fa dst .
-.Sh FILES
-.Bl -tag -width /etc/resolv.conf
-.It Pa /etc/resolv.conf
-The configuration file,
-see
-.Xr resolver 5 .
-.El
-.Sh SEE ALSO
-.Xr gethostbyname 3 ,
-.Xr resolver 5 ,
-.Xr hostname 7 ,
-.Xr named 8
-.Pp
-.%T RFC1032 ,
-.%T RFC1033 ,
-.%T RFC1034 ,
-.%T RFC1035 ,
-.%T RFC974
-.Rs
-.%T "Name Server Operations Guide for BIND"
-.Re
-.Sh HISTORY
-The
-.Nm
-function appeared in
-.Bx 4.3 .
diff --git a/newlib/libc/sys/linux/net/rexec.c b/newlib/libc/sys/linux/net/rexec.c
new file mode 100644
index 000000000..f6ae42d6f
--- /dev/null
+++ b/newlib/libc/sys/linux/net/rexec.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 1980, 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.
+ * 4. 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)rexec.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <alloca.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/uio.h>
+#include "libc-symbols.h"
+
+int rexecoptions;
+libc_freeres_ptr (static char *ahostbuf);
+
+int
+rexec_af(ahost, rport, name, pass, cmd, fd2p, af)
+ char **ahost;
+ int rport;
+ const char *name, *pass, *cmd;
+ int *fd2p;
+ sa_family_t af;
+{
+ struct sockaddr_storage sa2, from;
+ struct addrinfo hints, *res0;
+ const char *orig_name = name;
+ const char *orig_pass = pass;
+ u_short port = 0;
+ int s, timo = 1, s3;
+ char c;
+ int gai;
+ char servbuff[NI_MAXSERV];
+
+ snprintf(servbuff, sizeof(servbuff), "%d", ntohs(rport));
+ servbuff[sizeof(servbuff) - 1] = '\0';
+
+ memset(&hints, '\0', sizeof(hints));
+ hints.ai_family = af;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_CANONNAME;
+ gai = getaddrinfo(*ahost, servbuff, &hints, &res0);
+ if (gai){
+ /* XXX: set errno? */
+ return -1;
+ }
+
+ if (res0->ai_canonname){
+ free (ahostbuf);
+ ahostbuf = strdup (res0->ai_canonname);
+ if (ahostbuf == NULL) {
+ perror ("rexec: strdup");
+ return (-1);
+ }
+ *ahost = ahostbuf;
+ } else
+ *ahost = NULL;
+ ruserpass(res0->ai_canonname, &name, &pass);
+retry:
+ s = socket(res0->ai_family, res0->ai_socktype, 0);
+ if (s < 0) {
+ perror("rexec: socket");
+ return (-1);
+ }
+ if (connect(s, res0->ai_addr, res0->ai_addrlen) < 0) {
+ if (errno == ECONNREFUSED && timo <= 16) {
+ (void) __close(s);
+ sleep(timo);
+ timo *= 2;
+ goto retry;
+ }
+ perror(res0->ai_canonname);
+ return (-1);
+ }
+ if (fd2p == 0) {
+ (void) write(s, "", 1);
+ port = 0;
+ } else {
+ char num[32];
+ int s2, sa2len;
+
+ s2 = socket(res0->ai_family, res0->ai_socktype, 0);
+ if (s2 < 0) {
+ (void) __close(s);
+ return (-1);
+ }
+ listen(s2, 1);
+ sa2len = sizeof (sa2);
+ if (getsockname(s2, (struct sockaddr *)&sa2, &sa2len) < 0) {
+ perror("getsockname");
+ (void) __close(s2);
+ goto bad;
+#ifdef SA_LEN
+ } else if (sa2len != SA_LEN((struct sockaddr *)&sa2)) {
+ __set_errno(EINVAL);
+ (void) __close(s2);
+ goto bad;
+#endif
+ }
+ port = 0;
+ if (!getnameinfo((struct sockaddr *)&sa2, sa2len,
+ NULL, 0, servbuff, sizeof(servbuff),
+ NI_NUMERICSERV))
+ port = atoi(servbuff);
+ (void) sprintf(num, "%u", port);
+ (void) __write(s, num, strlen(num)+1);
+ { int len = sizeof (from);
+ s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from,
+ &len));
+ __close(s2);
+ if (s3 < 0) {
+ perror("accept");
+ port = 0;
+ goto bad;
+ }
+ }
+ *fd2p = s3;
+ }
+
+ struct iovec iov[3] =
+ {
+ [0] = { .iov_base = (void *) name, .iov_len = strlen (name) + 1 },
+ /* should public key encypt the password here */
+ [1] = { .iov_base = (void *) pass, .iov_len = strlen (pass) + 1 },
+ [2] = { .iov_base = (void *) cmd, .iov_len = strlen (cmd) + 1 }
+ };
+ (void) TEMP_FAILURE_RETRY (writev (s, iov, 3));
+
+ /* We don't need the memory allocated for the name and the password
+ in ruserpass anymore. */
+ if (name != orig_name)
+ free ((char *) name);
+ if (pass != orig_pass)
+ free ((char *) pass);
+
+ if (__read(s, &c, 1) != 1) {
+ perror(*ahost);
+ goto bad;
+ }
+ if (c != 0) {
+ while (__read(s, &c, 1) == 1) {
+ (void) __write(2, &c, 1);
+ if (c == '\n')
+ break;
+ }
+ goto bad;
+ }
+ freeaddrinfo(res0);
+ return (s);
+bad:
+ if (port)
+ (void) __close(*fd2p);
+ (void) __close(s);
+ freeaddrinfo(res0);
+ return (-1);
+}
+libc_hidden_def (rexec_af)
+
+int
+rexec(ahost, rport, name, pass, cmd, fd2p)
+ char **ahost;
+ int rport;
+ const char *name, *pass, *cmd;
+ int *fd2p;
+{
+ return rexec_af(ahost, rport, name, pass, cmd, fd2p, AF_INET);
+}
diff --git a/newlib/libc/sys/linux/net/rpc-lookup.c b/newlib/libc/sys/linux/net/rpc-lookup.c
new file mode 100644
index 000000000..2de497c01
--- /dev/null
+++ b/newlib/libc/sys/linux/net/rpc-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME rpc
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/rthdr.c b/newlib/libc/sys/linux/net/rthdr.c
deleted file mode 100644
index e5f7814b1..000000000
--- a/newlib/libc/sys/linux/net/rthdr.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/* $KAME: rthdr.c,v 1.8 2001/08/20 02:32:40 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.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-
-#include <string.h>
-#include <stdio.h>
-
-/* to define items, should talk with KAME guys first, for *BSD compatibility */
-
-#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
-#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
-#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
-
-size_t
-inet6_rthdr_space(type, seg)
- int type, seg;
-{
- switch(type) {
- case IPV6_RTHDR_TYPE_0:
- if (seg < 1 || seg > 23)
- return(0);
- return(CMSG_SPACE(sizeof(struct in6_addr) * (seg - 1)
- + sizeof(struct ip6_rthdr0)));
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_space: unknown type(%d)\n", type);
-#endif
- return(0);
- }
-}
-
-struct cmsghdr *
-inet6_rthdr_init(bp, type)
- void *bp;
- int type;
-{
- struct cmsghdr *ch = (struct cmsghdr *)bp;
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(ch);
-
- ch->cmsg_level = IPPROTO_IPV6;
- ch->cmsg_type = IPV6_RTHDR;
-
- switch(type) {
- case IPV6_RTHDR_TYPE_0:
- ch->cmsg_len = CMSG_LEN(sizeof(struct ip6_rthdr0) - sizeof(struct in6_addr));
- bzero(rthdr, sizeof(struct ip6_rthdr0));
- rthdr->ip6r_type = IPV6_RTHDR_TYPE_0;
- return(ch);
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_init: unknown type(%d)\n", type);
-#endif
- return(NULL);
- }
-}
-
-int
-inet6_rthdr_add(cmsg, addr, flags)
- struct cmsghdr *cmsg;
- const struct in6_addr *addr;
- u_int flags;
-{
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
-
- switch(rthdr->ip6r_type) {
- case IPV6_RTHDR_TYPE_0:
- {
- struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
- if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_add: unsupported flag(%d)\n", flags);
-#endif
- return(-1);
- }
- if (rt0->ip6r0_segleft == 23) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_add: segment overflow\n");
-#endif
- return(-1);
- }
- if (flags == IPV6_RTHDR_STRICT) {
- int c, b;
- c = rt0->ip6r0_segleft / 8;
- b = rt0->ip6r0_segleft % 8;
- rt0->ip6r0_slmap[c] |= (1 << (7 - b));
- }
- rt0->ip6r0_segleft++;
- bcopy(addr, (caddr_t)rt0 + ((rt0->ip6r0_len + 1) << 3),
- sizeof(struct in6_addr));
- rt0->ip6r0_len += sizeof(struct in6_addr) >> 3;
- cmsg->cmsg_len = CMSG_LEN((rt0->ip6r0_len + 1) << 3);
- break;
- }
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_add: unknown type(%d)\n",
- rthdr->ip6r_type);
-#endif
- return(-1);
- }
-
- return(0);
-}
-
-int
-inet6_rthdr_lasthop(cmsg, flags)
- struct cmsghdr *cmsg;
- unsigned int flags;
-{
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
-
- switch(rthdr->ip6r_type) {
- case IPV6_RTHDR_TYPE_0:
- {
- struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
- if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_lasthop: unsupported flag(%d)\n", flags);
-#endif
- return(-1);
- }
- if (rt0->ip6r0_segleft > 23) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_add: segment overflow\n");
-#endif
- return(-1);
- }
- if (flags == IPV6_RTHDR_STRICT) {
- int c, b;
- c = rt0->ip6r0_segleft / 8;
- b = rt0->ip6r0_segleft % 8;
- rt0->ip6r0_slmap[c] |= (1 << (7 - b));
- }
- break;
- }
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_lasthop: unknown type(%d)\n",
- rthdr->ip6r_type);
-#endif
- return(-1);
- }
-
- return(0);
-}
-
-#if 0
-int
-inet6_rthdr_reverse(in, out)
- const struct cmsghdr *in;
- struct cmsghdr *out;
-{
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_reverse: not implemented yet\n");
-#endif
- return -1;
-}
-#endif
-
-int
-inet6_rthdr_segments(cmsg)
- const struct cmsghdr *cmsg;
-{
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
-
- switch(rthdr->ip6r_type) {
- case IPV6_RTHDR_TYPE_0:
- {
- struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
-
- if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_segments: invalid size(%d)\n",
- rt0->ip6r0_len);
-#endif
- return -1;
- }
-
- return (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
- }
-
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_segments: unknown type(%d)\n",
- rthdr->ip6r_type);
-#endif
- return -1;
- }
-}
-
-struct in6_addr *
-inet6_rthdr_getaddr(cmsg, idx)
- struct cmsghdr *cmsg;
- int idx;
-{
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
-
- switch(rthdr->ip6r_type) {
- case IPV6_RTHDR_TYPE_0:
- {
- struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
- int naddr;
-
- if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getaddr: invalid size(%d)\n",
- rt0->ip6r0_len);
-#endif
- return NULL;
- }
- naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
- if (idx <= 0 || naddr < idx) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getaddr: invalid idx(%d)\n", idx);
-#endif
- return NULL;
- }
- return &rt0->ip6r0_addr[idx - 1];
- }
-
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getaddr: unknown type(%d)\n",
- rthdr->ip6r_type);
-#endif
- return NULL;
- }
-}
-
-int
-inet6_rthdr_getflags(cmsg, idx)
- const struct cmsghdr *cmsg;
- int idx;
-{
- struct ip6_rthdr *rthdr;
-
- rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
-
- switch(rthdr->ip6r_type) {
- case IPV6_RTHDR_TYPE_0:
- {
- struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
- int naddr;
-
- if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getflags: invalid size(%d)\n",
- rt0->ip6r0_len);
-#endif
- return -1;
- }
- naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
- if (idx < 0 || naddr < idx) {
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getflags: invalid idx(%d)\n", idx);
-#endif
- return -1;
- }
- if (rt0->ip6r0_slmap[idx / 8] & (0x80 >> (idx % 8)))
- return IPV6_RTHDR_STRICT;
- else
- return IPV6_RTHDR_LOOSE;
- }
-
- default:
-#ifdef DEBUG
- fprintf(stderr, "inet6_rthdr_getflags: unknown type(%d)\n",
- rthdr->ip6r_type);
-#endif
- return -1;
- }
-}
diff --git a/newlib/libc/sys/linux/net/ruserpass.c b/newlib/libc/sys/linux/net/ruserpass.c
new file mode 100644
index 000000000..5c429b072
--- /dev/null
+++ b/newlib/libc/sys/linux/net/ruserpass.c
@@ -0,0 +1,336 @@
+/*
+ * Copyright (c) 1985, 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.
+ * 4. 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ruserpass.c 8.3 (Berkeley) 4/2/94";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <libintl.h>
+#include "local.h"
+
+/* #include "ftp_var.h" */
+
+static int token (void);
+static FILE *cfile;
+
+#define DEFAULT 1
+#define LOGIN 2
+#define PASSWD 3
+#define ACCOUNT 4
+#define MACDEF 5
+#define ID 10
+#define MACHINE 11
+
+static char tokval[100];
+
+static const char tokstr[] =
+{
+#define TOK_DEFAULT_IDX 0
+ "default\0"
+#define TOK_LOGIN_IDX (TOK_DEFAULT_IDX + sizeof "default")
+ "login\0"
+#define TOK_PASSWORD_IDX (TOK_LOGIN_IDX + sizeof "login")
+ "password\0"
+#define TOK_PASSWD_IDX (TOK_PASSWORD_IDX + sizeof "password")
+ "passwd\0"
+#define TOK_ACCOUNT_IDX (TOK_PASSWD_IDX + sizeof "passwd")
+ "account\0"
+#define TOK_MACHINE_IDX (TOK_ACCOUNT_IDX + sizeof "account")
+ "machine\0"
+#define TOK_MACDEF_IDX (TOK_MACHINE_IDX + sizeof "machine")
+ "macdef"
+};
+
+static const struct toktab {
+ int tokstr_off;
+ int tval;
+} toktab[]= {
+ { TOK_DEFAULT_IDX, DEFAULT },
+ { TOK_LOGIN_IDX, LOGIN },
+ { TOK_PASSWORD_IDX, PASSWD },
+ { TOK_PASSWD_IDX, PASSWD },
+ { TOK_ACCOUNT_IDX, ACCOUNT },
+ { TOK_MACHINE_IDX, MACHINE },
+ { TOK_MACDEF_IDX, MACDEF }
+};
+
+
+#define warnx(x) fprintf(stderr, x)
+#define warnx2(x, y) fprintf(stderr, x, y)
+
+int
+ruserpass(host, aname, apass)
+ const char *host, **aname, **apass;
+{
+ char *hdir, *buf, *tmp;
+ char myname[1024], *mydomain;
+ int t, usedefault = 0;
+ struct stat64 stb;
+
+ hdir = getenv("HOME");
+ if (hdir == NULL) {
+ /* If we can't get HOME, fail instead of trying ".",
+ which is no improvement. This really should call
+ getpwuid(getuid()). */
+ /*hdir = ".";*/
+ return -1;
+ }
+
+ buf = alloca (strlen (hdir) + 8);
+
+ stpcpy (stpcpy (buf, hdir), "/.netrc");
+ cfile = fopen(buf, "rc");
+ if (cfile == NULL) {
+ if (errno != ENOENT) {
+ char *t = asprintf("%s", buf);
+ perror(t);
+ }
+ return (0);
+ }
+ /* No threads use this stream. */
+ __fsetlocking (cfile, FSETLOCKING_BYCALLER);
+ if (__gethostname(myname, sizeof(myname)) < 0)
+ myname[0] = '\0';
+ tmp = strchr(myname, '.');
+ if (tmp == NULL)
+ tmp = myname + strlen(myname);
+ mydomain = tmp;
+next:
+ while ((t = token())) switch(t) {
+
+ case DEFAULT:
+ usedefault = 1;
+ /* FALL THROUGH */
+
+ case MACHINE:
+ if (!usedefault) {
+ if (token() != ID)
+ continue;
+ /*
+ * Allow match either for user's input host name
+ * or official hostname. Also allow match of
+ * incompletely-specified host in local domain.
+ */
+ if (strcasecmp(host, tokval) == 0)
+ goto match;
+/* if (strcasecmp(hostname, tokval) == 0)
+ goto match;
+ if ((tmp = strchr(hostname, '.')) != NULL &&
+ strcasecmp(tmp, mydomain) == 0 &&
+ strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
+ tokval[tmp - hostname] == '\0')
+ goto match; */
+ if ((tmp = strchr(host, '.')) != NULL &&
+ strcasecmp(tmp, mydomain) == 0 &&
+ strncasecmp(host, tokval, tmp - host) == 0 &&
+ tokval[tmp - host] == '\0')
+ goto match;
+ continue;
+ }
+ match:
+ while ((t = token()) && t != MACHINE && t != DEFAULT) switch(t) {
+
+ case LOGIN:
+ if (token()) {
+ if (*aname == 0) {
+ char *newp;
+ newp = malloc((unsigned) strlen(tokval) + 1);
+ if (newp == NULL)
+ {
+ warnx(_("out of memory"));
+ goto bad;
+ }
+ *aname = strcpy(newp, tokval);
+ } else {
+ if (strcmp(*aname, tokval))
+ goto next;
+ }
+ }
+ break;
+ case PASSWD:
+ if (strcmp(*aname, "anonymous") &&
+ fstat64(fileno(cfile), &stb) >= 0 &&
+ (stb.st_mode & 077) != 0) {
+ warnx(_("Error: .netrc file is readable by others."));
+ warnx(_("Remove password or make file unreadable by others."));
+ goto bad;
+ }
+ if (token() && *apass == 0) {
+ char *newp;
+ newp = malloc((unsigned) strlen(tokval) + 1);
+ if (newp == NULL)
+ {
+ warnx(_("out of memory"));
+ goto bad;
+ }
+ *apass = strcpy(newp, tokval);
+ }
+ break;
+ case ACCOUNT:
+#if 0
+ if (fstat64(fileno(cfile), &stb) >= 0
+ && (stb.st_mode & 077) != 0) {
+ warnx("Error: .netrc file is readable by others.");
+ warnx("Remove account or make file unreadable by others.");
+ goto bad;
+ }
+ if (token() && *aacct == 0) {
+ *aacct = malloc((unsigned) strlen(tokval) + 1);
+ (void) strcpy(*aacct, tokval);
+ }
+#endif
+ break;
+ case MACDEF:
+#if 0
+ if (proxy) {
+ (void) fclose(cfile);
+ return (0);
+ }
+ while ((c=getc_unlocked(cfile)) != EOF && c == ' '
+ || c == '\t');
+ if (c == EOF || c == '\n') {
+ printf("Missing macdef name argument.\n");
+ goto bad;
+ }
+ if (macnum == 16) {
+ printf("Limit of 16 macros have already been defined\n");
+ goto bad;
+ }
+ tmp = macros[macnum].mac_name;
+ *tmp++ = c;
+ for (i=0; i < 8 && (c=getc_unlocked(cfile)) != EOF &&
+ !isspace(c); ++i) {
+ *tmp++ = c;
+ }
+ if (c == EOF) {
+ printf("Macro definition missing null line terminator.\n");
+ goto bad;
+ }
+ *tmp = '\0';
+ if (c != '\n') {
+ while ((c=getc_unlocked(cfile)) != EOF
+ && c != '\n');
+ }
+ if (c == EOF) {
+ printf("Macro definition missing null line terminator.\n");
+ goto bad;
+ }
+ if (macnum == 0) {
+ macros[macnum].mac_start = macbuf;
+ }
+ else {
+ macros[macnum].mac_start = macros[macnum-1].mac_end + 1;
+ }
+ tmp = macros[macnum].mac_start;
+ while (tmp != macbuf + 4096) {
+ if ((c=getc_unlocked(cfile)) == EOF) {
+ printf("Macro definition missing null line terminator.\n");
+ goto bad;
+ }
+ *tmp = c;
+ if (*tmp == '\n') {
+ if (*(tmp-1) == '\0') {
+ macros[macnum++].mac_end = tmp - 1;
+ break;
+ }
+ *tmp = '\0';
+ }
+ tmp++;
+ }
+ if (tmp == macbuf + 4096) {
+ printf("4K macro buffer exceeded\n");
+ goto bad;
+ }
+#endif
+ break;
+ default:
+ warnx2(_("Unknown .netrc keyword %s"), tokval);
+ break;
+ }
+ goto done;
+ }
+done:
+ (void) fclose(cfile);
+ return (0);
+bad:
+ (void) fclose(cfile);
+ return (-1);
+}
+libc_hidden_def (ruserpass)
+
+static int
+token()
+{
+ char *cp;
+ int c;
+ int i;
+
+ if (feof(cfile) || ferror(cfile))
+ return (0);
+ while ((c = getc_unlocked(cfile)) != EOF &&
+ (c == '\n' || c == '\t' || c == ' ' || c == ','))
+ continue;
+ if (c == EOF)
+ return (0);
+ cp = tokval;
+ if (c == '"') {
+ while ((c = getc_unlocked(cfile)) != EOF && c != '"') {
+ if (c == '\\')
+ c = getc_unlocked(cfile);
+ *cp++ = c;
+ }
+ } else {
+ *cp++ = c;
+ while ((c = getc_unlocked(cfile)) != EOF
+ && c != '\n' && c != '\t' && c != ' ' && c != ',') {
+ if (c == '\\')
+ c = getc_unlocked(cfile);
+ *cp++ = c;
+ }
+ }
+ *cp = 0;
+ if (tokval[0] == 0)
+ return (0);
+ for (i = 0; i < (int) (sizeof (toktab) / sizeof (toktab[0])); ++i)
+ if (!strcmp(&tokstr[toktab[i].tokstr_off], tokval))
+ return toktab[i].tval;
+ return (ID);
+}
diff --git a/newlib/libc/sys/linux/net/send.c b/newlib/libc/sys/linux/net/send.c
index 8ff65d015..658c92b71 100644
--- a/newlib/libc/sys/linux/net/send.c
+++ b/newlib/libc/sys/linux/net/send.c
@@ -37,7 +37,6 @@ static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94";
#include <sys/cdefs.h>
#include <sys/types.h>
-#include "namespace.h"
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/newlib/libc/sys/linux/net/service-lookup.c b/newlib/libc/sys/linux/net/service-lookup.c
new file mode 100644
index 000000000..67d401e08
--- /dev/null
+++ b/newlib/libc/sys/linux/net/service-lookup.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME services
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/spwd-lookup.c b/newlib/libc/sys/linux/net/spwd-lookup.c
new file mode 100644
index 000000000..40c2f613c
--- /dev/null
+++ b/newlib/libc/sys/linux/net/spwd-lookup.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define DATABASE_NAME shadow
+#define ALTERNATE_NAME passwd
+#define DEFAULT_CONFIG "compat [NOTFOUND=return] files"
+
+#include "XXX-lookup.c"
diff --git a/newlib/libc/sys/linux/net/vars.c b/newlib/libc/sys/linux/net/vars.c
deleted file mode 100644
index c91a04bd1..000000000
--- a/newlib/libc/sys/linux/net/vars.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* $KAME: vars.c,v 1.2 2001/08/20 02:32:41 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.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-
-/*
- * Definitions of some costant IPv6 addresses.
- */
-const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
-const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
-const struct in6_addr in6addr_nodelocal_allnodes = IN6ADDR_NODELOCAL_ALLNODES_INIT;
-const struct in6_addr in6addr_linklocal_allnodes = IN6ADDR_LINKLOCAL_ALLNODES_INIT;
-
diff --git a/newlib/libc/sys/linux/shlib-compat.h b/newlib/libc/sys/linux/shlib-compat.h
new file mode 100644
index 000000000..eb7514c73
--- /dev/null
+++ b/newlib/libc/sys/linux/shlib-compat.h
@@ -0,0 +1 @@
+#define SHLIB_COMPAT(libc, introduced, obsoleted) 0
diff --git a/newlib/libc/sys/linux/stdlib/collate.c b/newlib/libc/sys/linux/stdlib/collate.c
index 37ef80bf5..caedd92d4 100644
--- a/newlib/libc/sys/linux/stdlib/collate.c
+++ b/newlib/libc/sys/linux/stdlib/collate.c
@@ -40,8 +40,6 @@
#include "collate.h"
#include "setlocale.h"
-#include "libc_private.h"
-
extern char *_PathLocale;
int __collate_load_error = 1;
int __collate_substitute_nontrivial;
diff --git a/newlib/libc/sys/linux/sys/ioctl.h b/newlib/libc/sys/linux/sys/ioctl.h
index 12e0cd22d..f0e2741e9 100644
--- a/newlib/libc/sys/linux/sys/ioctl.h
+++ b/newlib/libc/sys/linux/sys/ioctl.h
@@ -6,6 +6,8 @@
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
+#include <bits/ioctls.h>
+
int ioctl(int fd,int request,...);
#endif
diff --git a/newlib/libc/sys/linux/sys/socket.h b/newlib/libc/sys/linux/sys/socket.h
index b7a3dd1f1..33097a5e8 100644
--- a/newlib/libc/sys/linux/sys/socket.h
+++ b/newlib/libc/sys/linux/sys/socket.h
@@ -120,50 +120,69 @@ struct accept_filter_arg {
*/
#define SOL_SOCKET 0xffff /* options for socket level */
-/*
- * Address families.
- */
-#define AF_UNSPEC 0 /* unspecified */
-#define AF_LOCAL 1 /* local to host (pipes, portals) */
-#define AF_UNIX AF_LOCAL /* backward compatibility */
-#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
-#define AF_IMPLINK 3 /* arpanet imp addresses */
-#define AF_PUP 4 /* pup protocols: e.g. BSP */
-#define AF_CHAOS 5 /* mit CHAOS protocols */
-#define AF_NS 6 /* XEROX NS protocols */
-#define AF_ISO 7 /* ISO protocols */
-#define AF_OSI AF_ISO
-#define AF_ECMA 8 /* European computer manufacturers */
-#define AF_DATAKIT 9 /* datakit protocols */
-#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
-#define AF_SNA 11 /* IBM SNA */
-#define AF_DECnet 12 /* DECnet */
-#define AF_DLI 13 /* DEC Direct data link interface */
-#define AF_LAT 14 /* LAT */
-#define AF_HYLINK 15 /* NSC Hyperchannel */
-#define AF_APPLETALK 16 /* Apple Talk */
-#define AF_ROUTE 17 /* Internal Routing Protocol */
-#define AF_LINK 18 /* Link layer interface */
-#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
-#define AF_COIP 20 /* connection-oriented IP, aka ST II */
-#define AF_CNT 21 /* Computer Network Technology */
-#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
-#define AF_IPX 23 /* Novell Internet Protocol */
-#define AF_SIP 24 /* Simple Internet Protocol */
-#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
-#define AF_ISDN 26 /* Integrated Services Digital Network*/
-#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
-#define pseudo_AF_KEY 27 /* Internal key-management function */
-#define AF_INET6 28 /* IPv6 */
-#define AF_NATM 29 /* native ATM access */
-#define AF_ATM 30 /* ATM */
-#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
- * in interface output routine
- */
-#define AF_NETGRAPH 32 /* Netgraph sockets */
-#define AF_SLOW 33 /* 802.3ad slow protocol */
-#define AF_SCLUSTER 34 /* Sitara cluster protocol */
-#define AF_MAX 35
+/* Protocol families. */
+#define PF_UNSPEC 0 /* Unspecified. */
+#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
+#define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
+#define PF_FILE PF_LOCAL /* Another non-standard name for PF_LOCAL. */
+#define PF_INET 2 /* IP protocol family. */
+#define PF_AX25 3 /* Amateur Radio AX.25. */
+#define PF_IPX 4 /* Novell Internet Protocol. */
+#define PF_APPLETALK 5 /* Appletalk DDP. */
+#define PF_NETROM 6 /* Amateur radio NetROM. */
+#define PF_BRIDGE 7 /* Multiprotocol bridge. */
+#define PF_ATMPVC 8 /* ATM PVCs. */
+#define PF_X25 9 /* Reserved for X.25 project. */
+#define PF_INET6 10 /* IP version 6. */
+#define PF_ROSE 11 /* Amateur Radio X.25 PLP. */
+#define PF_DECnet 12 /* Reserved for DECnet project. */
+#define PF_NETBEUI 13 /* Reserved for 802.2LLC project. */
+#define PF_SECURITY 14 /* Security callback pseudo AF. */
+#define PF_KEY 15 /* PF_KEY key management API. */
+#define PF_NETLINK 16
+#define PF_ROUTE PF_NETLINK /* Alias to emulate 4.4BSD. */
+#define PF_PACKET 17 /* Packet family. */
+#define PF_ASH 18 /* Ash. */
+#define PF_ECONET 19 /* Acorn Econet. */
+#define PF_ATMSVC 20 /* ATM SVCs. */
+#define PF_SNA 22 /* Linux SNA Project */
+#define PF_IRDA 23 /* IRDA sockets. */
+#define PF_PPPOX 24 /* PPPoX sockets. */
+#define PF_WANPIPE 25 /* Wanpipe API sockets. */
+#define PF_BLUETOOTH 31 /* Bluetooth sockets. */
+#define PF_MAX 32 /* For now.. */
+
+/* Address families. */
+#define AF_UNSPEC PF_UNSPEC
+#define AF_LOCAL PF_LOCAL
+#define AF_UNIX PF_UNIX
+#define AF_FILE PF_FILE
+#define AF_INET PF_INET
+#define AF_AX25 PF_AX25
+#define AF_IPX PF_IPX
+#define AF_APPLETALK PF_APPLETALK
+#define AF_NETROM PF_NETROM
+#define AF_BRIDGE PF_BRIDGE
+#define AF_ATMPVC PF_ATMPVC
+#define AF_X25 PF_X25
+#define AF_INET6 PF_INET6
+#define AF_ROSE PF_ROSE
+#define AF_DECnet PF_DECnet
+#define AF_NETBEUI PF_NETBEUI
+#define AF_SECURITY PF_SECURITY
+#define AF_KEY PF_KEY
+#define AF_NETLINK PF_NETLINK
+#define AF_ROUTE PF_ROUTE
+#define AF_PACKET PF_PACKET
+#define AF_ASH PF_ASH
+#define AF_ECONET PF_ECONET
+#define AF_ATMSVC PF_ATMSVC
+#define AF_SNA PF_SNA
+#define AF_IRDA PF_IRDA
+#define AF_PPPOX PF_PPPOX
+#define AF_WANPIPE PF_WANPIPE
+#define AF_BLUETOOTH PF_BLUETOOTH
+#define AF_MAX PF_MAX
/*
* Structure used by kernel to store most
@@ -202,48 +221,6 @@ struct sockaddr_storage {
};
/*
- * Protocol families, same as address families for now.
- */
-#define PF_UNSPEC AF_UNSPEC
-#define PF_LOCAL AF_LOCAL
-#define PF_UNIX PF_LOCAL /* backward compatibility */
-#define PF_INET AF_INET
-#define PF_IMPLINK AF_IMPLINK
-#define PF_PUP AF_PUP
-#define PF_CHAOS AF_CHAOS
-#define PF_NS AF_NS
-#define PF_ISO AF_ISO
-#define PF_OSI AF_ISO
-#define PF_ECMA AF_ECMA
-#define PF_DATAKIT AF_DATAKIT
-#define PF_CCITT AF_CCITT
-#define PF_SNA AF_SNA
-#define PF_DECnet AF_DECnet
-#define PF_DLI AF_DLI
-#define PF_LAT AF_LAT
-#define PF_HYLINK AF_HYLINK
-#define PF_APPLETALK AF_APPLETALK
-#define PF_ROUTE AF_ROUTE
-#define PF_LINK AF_LINK
-#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
-#define PF_COIP AF_COIP
-#define PF_CNT AF_CNT
-#define PF_SIP AF_SIP
-#define PF_IPX AF_IPX /* same format as AF_NS */
-#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
-#define PF_PIP pseudo_AF_PIP
-#define PF_ISDN AF_ISDN
-#define PF_KEY pseudo_AF_KEY
-#define PF_INET6 AF_INET6
-#define PF_NATM AF_NATM
-#define PF_ATM AF_ATM
-#define PF_NETGRAPH AF_NETGRAPH
-#define PF_SLOW AF_SLOW
-#define PF_SCLUSTER AF_SCLUSTER
-
-#define PF_MAX AF_MAX
-
-/*
* Definitions for network related sysctl, CTL_NET.
*
* Second level is protocol family.
diff --git a/newlib/libc/sys/linux/sys/unistd.h b/newlib/libc/sys/linux/sys/unistd.h
index 502fb473a..18c70dd52 100644
--- a/newlib/libc/sys/linux/sys/unistd.h
+++ b/newlib/libc/sys/linux/sys/unistd.h
@@ -48,6 +48,7 @@ gid_t _EXFUN(getegid, (void ));
uid_t _EXFUN(geteuid, (void ));
gid_t _EXFUN(getgid, (void ));
int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] ));
+int _EXFUN(__gethostname, (char *__name, size_t __len));
char _EXFUN(*getlogin, (void ));
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
int _EXFUN(getlogin_r, (char *name, size_t namesize) );