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.
This commit is contained in:
parent
8a179967e6
commit
3c77dcff9e
220
newlib/ChangeLog
220
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.
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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, ©len);
|
||||
assert (copylen == st->total + 1);
|
||||
assert (endp = retval + st->total + 1);
|
||||
*size = copylen;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
strtaboffset (struct Strent *se)
|
||||
{
|
||||
return se->offset;
|
||||
}
|
@ -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 */
|
||||
@ -212,6 +216,104 @@ typedef enum __ns_update_operation {
|
||||
ns_uop_max = 2
|
||||
} 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.
|
||||
*/
|
||||
@ -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 */
|
||||
|
||||
|
@ -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_
|
||||
/*
|
||||
* This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>.
|
||||
*/
|
||||
|
||||
/* Application-visible indication that we have the new interfaces */
|
||||
/*
|
||||
* $BINDId: hesiod.h,v 1.7 1999/01/08 19:22:45 vixie Exp $
|
||||
*/
|
||||
|
||||
#define HESIOD_INTERFACES
|
||||
#ifndef _HESIOD_H_INCLUDED
|
||||
#define _HESIOD_H_INCLUDED
|
||||
|
||||
/* Configuration information. */
|
||||
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 *));
|
||||
|
||||
#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 *);
|
||||
|
||||
/* 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
|
||||
|
||||
#endif /* ! _HESIOD_H_ */
|
||||
#endif /*_HESIOD_H_INCLUDED*/
|
||||
|
@ -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_ */
|
@ -1,74 +1,65 @@
|
||||
/*
|
||||
* 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
|
||||
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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_ */
|
@ -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 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.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY 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.
|
||||
*
|
||||
* $FreeBSD: src/sys/net/if_ppp.h,v 1.14 1999/08/28 00:48:20 peter Exp $
|
||||
*/
|
||||
|
||||
#ifndef _IF_PPP_H_
|
||||
#define _IF_PPP_H_
|
||||
/*
|
||||
* ==FILEVERSION 960926==
|
||||
*
|
||||
* 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 __NET_IF_PPP_H
|
||||
#define __NET_IF_PPP_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/* XXX this used to be self-contained. */
|
||||
#include <net/ppp_defs.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 */
|
||||
|
@ -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);
|
@ -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);
|
||||
|
||||
/*
|
||||
|
@ -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 *);
|
@ -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>
|
||||
|
||||
|
@ -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
|
@ -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 */
|
@ -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.
|
||||
@ -132,6 +175,15 @@ struct __res_state_ext {
|
||||
} sort_list[MAXRESOLVSORT];
|
||||
};
|
||||
|
||||
/*
|
||||
* * 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)
|
||||
*/
|
||||
@ -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_ */
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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 */
|
||||
|
366
newlib/libc/sys/linux/machine/i386/atomic.h
Normal file
366
newlib/libc/sys/linux/machine/i386/atomic.h
Normal file
@ -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")
|
@ -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)
|
||||
{
|
||||
|
@ -47,11 +47,22 @@
|
||||
* Definitions for byte order, according to byte significance from low
|
||||
* address to high.
|
||||
*/
|
||||
#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
|
||||
#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
|
||||
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
|
||||
|
||||
#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>
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
75
newlib/libc/sys/linux/net/XXX-lookup.c
Normal file
75
newlib/libc/sys/linux/net/XXX-lookup.c
Normal file
@ -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)
|
@ -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.
|
22
newlib/libc/sys/linux/net/alias-lookup.c
Normal file
22
newlib/libc/sys/linux/net/alias-lookup.c
Normal file
@ -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"
|
64
newlib/libc/sys/linux/net/aliases.h
Normal file
64
newlib/libc/sys/linux/net/aliases.h
Normal file
@ -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 */
|
@ -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,9 +40,10 @@
|
||||
* 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);
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
}
|
@ -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.
|
199
newlib/libc/sys/linux/net/check_pf.c
Normal file
199
newlib/libc/sys/linux/net/check_pf.c
Normal file
@ -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
|
||||
}
|
40
newlib/libc/sys/linux/net/databases.def
Normal file
40
newlib/libc/sys/linux/net/databases.def
Normal file
@ -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:
|
||||
*/
|
317
newlib/libc/sys/linux/net/digits_dots.c
Normal file
317
newlib/libc/sys/linux/net/digits_dots.c
Normal file
@ -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)
|
@ -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);
|
||||
}
|
29
newlib/libc/sys/linux/net/ether_aton.c
Normal file
29
newlib/libc/sys/linux/net/ether_aton.c
Normal file
@ -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);
|
||||
}
|
64
newlib/libc/sys/linux/net/ether_aton_r.c
Normal file
64
newlib/libc/sys/linux/net/ether_aton_r.c
Normal file
@ -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)
|
83
newlib/libc/sys/linux/net/ether_hton.c
Normal file
83
newlib/libc/sys/linux/net/ether_hton.c
Normal file
@ -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, ðerent, 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;
|
||||
}
|
81
newlib/libc/sys/linux/net/ether_line.c
Normal file
81
newlib/libc/sys/linux/net/ether_line.c
Normal file
@ -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;
|
||||
}
|
30
newlib/libc/sys/linux/net/ether_ntoa.c
Normal file
30
newlib/libc/sys/linux/net/ether_ntoa.c
Normal file
@ -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);
|
||||
}
|
34
newlib/libc/sys/linux/net/ether_ntoa_r.c
Normal file
34
newlib/libc/sys/linux/net/ether_ntoa_r.c
Normal file
@ -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)
|
86
newlib/libc/sys/linux/net/ether_ntoh.c
Normal file
86
newlib/libc/sys/linux/net/ether_ntoh.c
Normal file
@ -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, ðerent, 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;
|
||||
}
|
9
newlib/libc/sys/linux/net/etherent.h
Normal file
9
newlib/libc/sys/linux/net/etherent.h
Normal file
@ -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;
|
||||
};
|
||||
|
22
newlib/libc/sys/linux/net/ethers-lookup.c
Normal file
22
newlib/libc/sys/linux/net/ethers-lookup.c
Normal file
@ -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"
|
@ -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 .
|
78
newlib/libc/sys/linux/net/function.def
Normal file
78
newlib/libc/sys/linux/net/function.def
Normal file
@ -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)
|
156
newlib/libc/sys/linux/net/getXXbyYY.c
Normal file
156
newlib/libc/sys/linux/net/getXXbyYY.c
Normal file
@ -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)
|
292
newlib/libc/sys/linux/net/getXXbyYY_r.c
Normal file
292
newlib/libc/sys/linux/net/getXXbyYY_r.c
Normal file
@ -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)
|
96
newlib/libc/sys/linux/net/getXXent.c
Normal file
96
newlib/libc/sys/linux/net/getXXent.c
Normal file
@ -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)
|
209
newlib/libc/sys/linux/net/getXXent_r.c
Normal file
209
newlib/libc/sys/linux/net/getXXent_r.c
Normal file
@ -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)
|
@ -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.
|
File diff suppressed because it is too large
Load Diff
26
newlib/libc/sys/linux/net/getaliasent.c
Normal file
26
newlib/libc/sys/linux/net/getaliasent.c
Normal file
@ -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"
|
29
newlib/libc/sys/linux/net/getaliasent_r.c
Normal file
29
newlib/libc/sys/linux/net/getaliasent_r.c
Normal file
@ -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"
|
30
newlib/libc/sys/linux/net/getaliasname.c
Normal file
30
newlib/libc/sys/linux/net/getaliasname.c
Normal file
@ -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"
|
29
newlib/libc/sys/linux/net/getaliasname_r.c
Normal file
29
newlib/libc/sys/linux/net/getaliasname_r.c
Normal file
@ -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"
|
@ -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();
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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.
|
@ -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
|
||||
}
|
@ -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();
|
||||
}
|
31
newlib/libc/sys/linux/net/gethstbyad.c
Normal file
31
newlib/libc/sys/linux/net/gethstbyad.c
Normal file
@ -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"
|
53
newlib/libc/sys/linux/net/gethstbyad_r.c
Normal file
53
newlib/libc/sys/linux/net/gethstbyad_r.c
Normal file
@ -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"
|
38
newlib/libc/sys/linux/net/gethstbynm.c
Normal file
38
newlib/libc/sys/linux/net/gethstbynm.c
Normal file
@ -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>
|
39
newlib/libc/sys/linux/net/gethstbynm2.c
Normal file
39
newlib/libc/sys/linux/net/gethstbynm2.c
Normal file
@ -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"
|
46
newlib/libc/sys/linux/net/gethstbynm2_r.c
Normal file
46
newlib/libc/sys/linux/net/gethstbynm2_r.c
Normal file
@ -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"
|
45
newlib/libc/sys/linux/net/gethstbynm_r.c
Normal file
45
newlib/libc/sys/linux/net/gethstbynm_r.c
Normal file
@ -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"
|
27
newlib/libc/sys/linux/net/gethstent.c
Normal file
27
newlib/libc/sys/linux/net/gethstent.c
Normal file
@ -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"
|
35
newlib/libc/sys/linux/net/gethstent_r.c
Normal file
35
newlib/libc/sys/linux/net/gethstent_r.c
Normal file
@ -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"
|
@ -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 .
|
@ -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);
|
||||
}
|
@ -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.
|
@ -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.
|
@ -1,372 +1,456 @@
|
||||
/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
|
||||
/* The Inner Net License, Version 2.00
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
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:
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <machine/endian.h>
|
||||
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.
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.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)},
|
||||
#endif
|
||||
{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
|
||||
offsetof(struct sockaddr_in, sin_addr)},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
struct sockinet {
|
||||
u_char si_len;
|
||||
u_char si_family;
|
||||
u_short si_port;
|
||||
};
|
||||
|
||||
#ifdef INET6
|
||||
static int ip6_parsenumeric(const struct sockaddr *, const char *, char *,
|
||||
size_t, int);
|
||||
static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int);
|
||||
#ifdef HAVE_LIBIDN
|
||||
# include <libidn/idna.h>
|
||||
extern int __idna_to_unicode_lzlz (const char *input, char **output,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
#ifndef min
|
||||
# define min(x,y) (((x) > (y)) ? (y) : (x))
|
||||
#endif /* min */
|
||||
|
||||
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;
|
||||
libc_freeres_ptr (static char *domain);
|
||||
|
||||
|
||||
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];
|
||||
static int not_first;
|
||||
|
||||
if (sa == NULL)
|
||||
return ENI_NOSOCKET;
|
||||
if (! not_first)
|
||||
{
|
||||
__libc_lock_define_initialized (static, lock);
|
||||
__libc_lock_lock (lock);
|
||||
|
||||
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 (! not_first)
|
||||
{
|
||||
char *c;
|
||||
struct hostent *h, th;
|
||||
size_t tmpbuflen = 1024;
|
||||
char *tmpbuf = alloca (tmpbuflen);
|
||||
int herror;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
not_first = 1;
|
||||
|
||||
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:
|
||||
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;
|
||||
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);
|
||||
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
|
||||
{
|
||||
/* We need to preserve the hostname. */
|
||||
const char *hstname = alloca (strlen (tmpbuf) + 1);
|
||||
strcpy (hstname, tmpbuf);
|
||||
|
||||
while (__gethostbyname_r (hstname, &th, tmpbuf, tmpbuflen,
|
||||
&h, &herror))
|
||||
{
|
||||
if (herror == NETDB_INTERNAL && errno == ERANGE)
|
||||
tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
|
||||
2 * tmpbuflen);
|
||||
else
|
||||
break;
|
||||
default:
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
||||
flags |= NI_NUMERICHOST;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
|
||||
flags |= NI_NUMERICHOST;
|
||||
break;
|
||||
|
||||
if (h && (c = strchr (h->h_name, '.')))
|
||||
domain = strdup (++c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__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 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
|
||||
))
|
||||
return EAI_BADFLAGS;
|
||||
|
||||
if (sa == NULL || addrlen < sizeof (sa_family_t))
|
||||
return EAI_FAMILY;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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;
|
||||
#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;
|
||||
if (flags & NI_NAMEREQD)
|
||||
{
|
||||
__set_errno (serrno);
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
switch(afd->a_af) {
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
{
|
||||
int error;
|
||||
strncpy (host, "localhost", hostlen);
|
||||
break;
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
|
||||
default:
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
|
||||
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 (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 ((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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
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;
|
||||
}
|
||||
|
||||
if (host && (hostlen > 0))
|
||||
host[hostlen-1] = 0;
|
||||
if (serv && (servlen > 0))
|
||||
serv[servlen-1] = 0;
|
||||
errno = serrno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#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;
|
||||
{
|
||||
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)) &&
|
||||
#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 0;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
#ifdef NI_NUMERICSCOPE
|
||||
if (flags & NI_NUMERICSCOPE) {
|
||||
return(snprintf(buf, bufsiz, "%d", sa6->sin6_scope_id));
|
||||
}
|
||||
#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));
|
||||
}
|
||||
}
|
||||
|
||||
/* last resort */
|
||||
return(snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id));
|
||||
}
|
||||
#endif /* INET6 */
|
||||
libc_hidden_def (getnameinfo)
|
||||
|
32
newlib/libc/sys/linux/net/getnetbyad.c
Normal file
32
newlib/libc/sys/linux/net/getnetbyad.c
Normal file
@ -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"
|
32
newlib/libc/sys/linux/net/getnetbyad_r.c
Normal file
32
newlib/libc/sys/linux/net/getnetbyad_r.c
Normal file
@ -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"
|
@ -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();
|
||||
}
|
@ -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;
|
||||
}
|
@ -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 */
|
||||
}
|
31
newlib/libc/sys/linux/net/getnetbynm.c
Normal file
31
newlib/libc/sys/linux/net/getnetbynm.c
Normal file
@ -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"
|
31
newlib/libc/sys/linux/net/getnetbynm_r.c
Normal file
31
newlib/libc/sys/linux/net/getnetbynm_r.c
Normal file
@ -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"
|
@ -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.
|
27
newlib/libc/sys/linux/net/getnetent.c
Normal file
27
newlib/libc/sys/linux/net/getnetent.c
Normal file
@ -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"
|
32
newlib/libc/sys/linux/net/getnetent_r.c
Normal file
32
newlib/libc/sys/linux/net/getnetent_r.c
Normal file
@ -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"
|
52
newlib/libc/sys/linux/net/getnetgrent.c
Normal file
52
newlib/libc/sys/linux/net/getnetgrent.c
Normal file
@ -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);
|
||||
}
|
446
newlib/libc/sys/linux/net/getnetgrent_r.c
Normal file
446
newlib/libc/sys/linux/net/getnetgrent_r.c
Normal file
@ -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)
|
@ -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();
|
||||
}
|
58
newlib/libc/sys/linux/net/getnssent.c
Normal file
58
newlib/libc/sys/linux/net/getnssent.c
Normal file
@ -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;
|
||||
}
|
218
newlib/libc/sys/linux/net/getnssent_r.c
Normal file
218
newlib/libc/sys/linux/net/getnssent_r.c
Normal file
@ -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);
|
||||
}
|
@ -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"
|
||||
|
29
newlib/libc/sys/linux/net/getproto_r.c
Normal file
29
newlib/libc/sys/linux/net/getproto_r.c
Normal file
@ -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"
|
@ -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.
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
26
newlib/libc/sys/linux/net/getprtent.c
Normal file
26
newlib/libc/sys/linux/net/getprtent.c
Normal file
@ -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"
|
30
newlib/libc/sys/linux/net/getprtent_r.c
Normal file
30
newlib/libc/sys/linux/net/getprtent_r.c
Normal file
@ -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"
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user