From 07b4b67a88f386ce4716a14e0ff2c2bce992b985 Mon Sep 17 00:00:00 2001 From: cvs2svn <> Date: Thu, 4 Sep 2008 20:26:21 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'newlib-1_16_0'. Sprout from binutils-arc-20080908-branch 2008-09-04 20:26:19 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'binutils-' Cherrypick from master 2007-12-19 22:36:48 UTC Jeff Johnston '': ChangeLog MAINTAINERS Makefile.def Makefile.in Makefile.tpl config.guess config.rpath config.sub config/ChangeLog config/acinclude.m4 config/acx.m4 config/confsubdir.m4 config/mh-i370pic config/mh-ia64pic config/mh-mingw config/mh-ppc-darwin config/mh-s390pic config/mh-sparcpic config/mt-mips-elfoabi config/mt-spu config/tls.m4 configure configure.ac libgloss/ChangeLog libgloss/arm/configure libgloss/arm/crt0.S libgloss/arm/redboot-syscalls.c libgloss/bfin/Makefile.in libgloss/bfin/configure libgloss/bfin/syscalls.c libgloss/configure libgloss/cris/configure libgloss/cris/gensyscalls libgloss/crx/configure libgloss/d30v/configure libgloss/doc/configure libgloss/fr30/configure libgloss/fr30/syscalls.c libgloss/frv/configure libgloss/frv/crt0.S libgloss/frv/isatty.c libgloss/hp74x/configure libgloss/i386/configure libgloss/i960/configure libgloss/iq2000/configure libgloss/iq2000/crt0.S libgloss/iq2000/isatty.c libgloss/libnosys/configure libgloss/libnosys/configure.in libgloss/libnosys/isatty.c libgloss/m32c/configure libgloss/m32c/exit.S libgloss/m32r/configure libgloss/m32r/isatty.c libgloss/m68hc11/configure libgloss/m68k/cf-crt1.c libgloss/m68k/configure libgloss/mcore/configure libgloss/mep/configure libgloss/mips/configure libgloss/mn10200/configure libgloss/mn10200/isatty.c libgloss/mn10300/configure libgloss/mn10300/crt0.S libgloss/mn10300/isatty.c libgloss/mt/configure libgloss/pa/configure libgloss/rs6000/configure libgloss/sparc/configure libgloss/sparc/libsys/configure libgloss/spu/Makefile.in libgloss/spu/configure libgloss/spu/readlink.c libgloss/spu/sbrk.c libgloss/spu/syscalls.c libgloss/wince/configure libgloss/xstormy16/configure libtool.m4 ltsugar.m4 newlib/ChangeLog newlib/Makefile.am newlib/Makefile.in newlib/configure.host newlib/libc/argz/argz_count.c newlib/libc/argz/argz_extract.c newlib/libc/argz/argz_stringify.c newlib/libc/ctype/ctype_.c newlib/libc/ctype/isalnum.c newlib/libc/ctype/isalpha.c newlib/libc/ctype/iscntrl.c newlib/libc/ctype/isdigit.c newlib/libc/ctype/islower.c newlib/libc/ctype/isprint.c newlib/libc/ctype/ispunct.c newlib/libc/ctype/isspace.c newlib/libc/ctype/isupper.c newlib/libc/ctype/isxdigit.c newlib/libc/include/_ansi.h newlib/libc/include/_syslist.h newlib/libc/include/assert.h newlib/libc/include/ctype.h newlib/libc/include/getopt.h newlib/libc/include/machine/_default_types.h newlib/libc/include/machine/ieeefp.h newlib/libc/include/machine/setjmp.h newlib/libc/include/math.h newlib/libc/include/reent.h newlib/libc/include/stdint.h newlib/libc/include/stdio.h newlib/libc/include/string.h newlib/libc/include/sys/_default_fcntl.h newlib/libc/include/sys/reent.h newlib/libc/include/sys/stat.h newlib/libc/include/sys/unistd.h newlib/libc/libc.texinfo newlib/libc/machine/arm/setjmp.S newlib/libc/machine/configure newlib/libc/machine/i386/memchr.S newlib/libc/machine/i386/memset.S newlib/libc/machine/i386/strchr.S newlib/libc/machine/i386/strlen.S newlib/libc/machine/m68k/memcpy.S newlib/libc/machine/m68k/memset.S newlib/libc/machine/m68k/setjmp.S newlib/libc/machine/mips/strncpy.c newlib/libc/machine/mn10300/memset.S newlib/libc/machine/powerpc/vfprintf.c newlib/libc/machine/spu/Makefile.am newlib/libc/machine/spu/Makefile.in newlib/libc/machine/spu/fprintf.S newlib/libc/machine/spu/fscanf.S newlib/libc/machine/spu/mk_syscalls newlib/libc/machine/spu/printf.S newlib/libc/machine/spu/scanf.S newlib/libc/machine/spu/setjmp.S newlib/libc/machine/spu/snprintf.S newlib/libc/machine/spu/sprintf.S newlib/libc/machine/spu/sscanf.S newlib/libc/machine/spu/stack_reg_va.S newlib/libc/machine/spu/strcat.c newlib/libc/machine/spu/strcpy.c newlib/libc/machine/spu/strlen.c newlib/libc/machine/spu/strncat.c newlib/libc/machine/spu/strncmp.c newlib/libc/machine/spu/strncpy.c newlib/libc/machine/spu/sys/dirent.h newlib/libc/machine/spu/sys/errno.h newlib/libc/machine/spu/sys/sched.h newlib/libc/machine/spu/sys/syscall.h newlib/libc/posix/Makefile.am newlib/libc/posix/Makefile.in newlib/libc/posix/isatty.c newlib/libc/reent/Makefile.am newlib/libc/reent/Makefile.in newlib/libc/search/hash.h newlib/libc/stdio/Makefile.am newlib/libc/stdio/Makefile.in newlib/libc/stdio/asiprintf.c newlib/libc/stdio/asniprintf.c newlib/libc/stdio/asnprintf.c newlib/libc/stdio/asprintf.c newlib/libc/stdio/dprintf.c newlib/libc/stdio/fflush.c newlib/libc/stdio/freopen.c newlib/libc/stdio/ftell.c newlib/libc/stdio/local.h newlib/libc/stdio/makebuf.c newlib/libc/stdio/rget.c newlib/libc/stdio/siprintf.c newlib/libc/stdio/siscanf.c newlib/libc/stdio/sniprintf.c newlib/libc/stdio/snprintf.c newlib/libc/stdio/sprintf.c newlib/libc/stdio/sscanf.c newlib/libc/stdio/vasiprintf.c newlib/libc/stdio/vasniprintf.c newlib/libc/stdio/vasnprintf.c newlib/libc/stdio/vasprintf.c newlib/libc/stdio/vdiprintf.c newlib/libc/stdio/vdprintf.c newlib/libc/stdio/vfprintf.c newlib/libc/stdio/vfscanf.c newlib/libc/stdio/vsiprintf.c newlib/libc/stdio/vsiscanf.c newlib/libc/stdio/vsniprintf.c newlib/libc/stdio/vsnprintf.c newlib/libc/stdio/vsprintf.c newlib/libc/stdio/vsscanf.c newlib/libc/stdio64/ftello64.c newlib/libc/stdlib/envlock.h newlib/libc/stdlib/gdtoa-hexnan.c newlib/libc/stdlib/getopt.c newlib/libc/stdlib/mprec.h newlib/libc/stdlib/strtod.c newlib/libc/stdlib/wcsrtombs.c newlib/libc/string/Makefile.am newlib/libc/string/Makefile.in newlib/libc/string/memchr.c newlib/libc/string/memset.c newlib/libc/string/strcasestr.c newlib/libc/string/strchr.c newlib/libc/string/strings.tex newlib/libc/string/strlen.c newlib/libc/string/strstr.c newlib/libc/sys/a29khif/_isatty.S newlib/libc/sys/arc/isatty.c newlib/libc/sys/arm/syscalls.c newlib/libc/sys/configure newlib/libc/sys/d10v/syscalls.c newlib/libc/sys/h8300hms/syscalls.c newlib/libc/sys/h8500hms/syscalls.c newlib/libc/sys/linux/Makefile.am newlib/libc/sys/linux/Makefile.in newlib/libc/sys/linux/bits/libc-lock.h newlib/libc/sys/linux/iconv/iconvconfig.c newlib/libc/sys/linux/iconv/strtab.c newlib/libc/sys/linux/include/arpa/nameser.h newlib/libc/sys/linux/include/hesiod.h newlib/libc/sys/linux/include/libc_private.h newlib/libc/sys/linux/include/net/ethernet.h newlib/libc/sys/linux/include/net/if_atm.h newlib/libc/sys/linux/include/net/if_media.h newlib/libc/sys/linux/include/net/if_ppp.h newlib/libc/sys/linux/include/net/if_pppvar.h newlib/libc/sys/linux/include/netdb.h newlib/libc/sys/linux/include/netinet/if_atm.h newlib/libc/sys/linux/include/netinet/if_ether.h newlib/libc/sys/linux/include/netinet/ip_flow.h newlib/libc/sys/linux/include/nsswitch.h newlib/libc/sys/linux/include/resolv.h newlib/libc/sys/linux/include/sched.h newlib/libc/sys/linux/include/stdint.h newlib/libc/sys/linux/intl/locale.alias newlib/libc/sys/linux/libc-symbols.h newlib/libc/sys/linux/machine/i386/get_clockfreq.c newlib/libc/sys/linux/machine/i386/include/endian.h newlib/libc/sys/linux/machine/i386/include/param.h newlib/libc/sys/linux/net/Makefile.am newlib/libc/sys/linux/net/Makefile.in newlib/libc/sys/linux/net/addr2ascii.3 newlib/libc/sys/linux/net/base64.c newlib/libc/sys/linux/net/bindresvport.c newlib/libc/sys/linux/net/byteorder.3 newlib/libc/sys/linux/net/ether_addr.c newlib/libc/sys/linux/net/ethers.3 newlib/libc/sys/linux/net/getaddrinfo.3 newlib/libc/sys/linux/net/getaddrinfo.c newlib/libc/sys/linux/net/gethostbydns.c newlib/libc/sys/linux/net/gethostbyht.c newlib/libc/sys/linux/net/gethostbyname.3 newlib/libc/sys/linux/net/gethostbynis.c newlib/libc/sys/linux/net/gethostnamadr.c newlib/libc/sys/linux/net/getifaddrs.3 newlib/libc/sys/linux/net/getifaddrs.c newlib/libc/sys/linux/net/getipnodebyname.3 newlib/libc/sys/linux/net/getnameinfo.3 newlib/libc/sys/linux/net/getnameinfo.c newlib/libc/sys/linux/net/getnetbydns.c newlib/libc/sys/linux/net/getnetbyht.c newlib/libc/sys/linux/net/getnetbynis.c newlib/libc/sys/linux/net/getnetent.3 newlib/libc/sys/linux/net/getnetnamadr.c newlib/libc/sys/linux/net/getproto.c newlib/libc/sys/linux/net/getprotoent.3 newlib/libc/sys/linux/net/getprotoent.c newlib/libc/sys/linux/net/getprotoname.c newlib/libc/sys/linux/net/getservbyname.c newlib/libc/sys/linux/net/getservbyport.c newlib/libc/sys/linux/net/getservent.3 newlib/libc/sys/linux/net/getservent.c newlib/libc/sys/linux/net/herror.c newlib/libc/sys/linux/net/hesiod.3 newlib/libc/sys/linux/net/hesiod.c newlib/libc/sys/linux/net/if_indextoname.3 newlib/libc/sys/linux/net/inet.3 newlib/libc/sys/linux/net/inet6_option_space.3 newlib/libc/sys/linux/net/inet6_rthdr_space.3 newlib/libc/sys/linux/net/inet_lnaof.c newlib/libc/sys/linux/net/inet_makeaddr.c newlib/libc/sys/linux/net/inet_net.3 newlib/libc/sys/linux/net/inet_netof.c newlib/libc/sys/linux/net/inet_network.c newlib/libc/sys/linux/net/inet_ntoa.c newlib/libc/sys/linux/net/innetgr-stub.c newlib/libc/sys/linux/net/ip6opt.c newlib/libc/sys/linux/net/iso_addr.3 newlib/libc/sys/linux/net/iso_addr.c newlib/libc/sys/linux/net/linkaddr.3 newlib/libc/sys/linux/net/linkaddr.c newlib/libc/sys/linux/net/map_v4v6.c newlib/libc/sys/linux/net/name6.c newlib/libc/sys/linux/net/namespace.h newlib/libc/sys/linux/net/ns.3 newlib/libc/sys/linux/net/ns_addr.c newlib/libc/sys/linux/net/ns_name.c newlib/libc/sys/linux/net/ns_netint.c newlib/libc/sys/linux/net/ns_ntoa.c newlib/libc/sys/linux/net/ns_parse.c newlib/libc/sys/linux/net/ns_print.c newlib/libc/sys/linux/net/ns_ttl.c newlib/libc/sys/linux/net/nsap_addr.c newlib/libc/sys/linux/net/nsdispatch.3 newlib/libc/sys/linux/net/nsdispatch.c newlib/libc/sys/linux/net/nslexer.c newlib/libc/sys/linux/net/nslexer.l newlib/libc/sys/linux/net/nsparser.c newlib/libc/sys/linux/net/nsparser.h newlib/libc/sys/linux/net/nsparser.y newlib/libc/sys/linux/net/rcmd.3 newlib/libc/sys/linux/net/rcmd.c newlib/libc/sys/linux/net/rcmdsh.3 newlib/libc/sys/linux/net/res_comp.c newlib/libc/sys/linux/net/res_config.h newlib/libc/sys/linux/net/res_data.c newlib/libc/sys/linux/net/res_debug.c newlib/libc/sys/linux/net/res_init.c newlib/libc/sys/linux/net/res_mkquery.c newlib/libc/sys/linux/net/res_mkupdate.c newlib/libc/sys/linux/net/res_query.c newlib/libc/sys/linux/net/res_send.c newlib/libc/sys/linux/net/res_update.c newlib/libc/sys/linux/net/resolver.3 newlib/libc/sys/linux/net/rthdr.c newlib/libc/sys/linux/net/send.c newlib/libc/sys/linux/net/vars.c newlib/libc/sys/linux/stdlib/COPYRIGHT newlib/libc/sys/linux/stdlib/Makefile.am newlib/libc/sys/linux/stdlib/Makefile.in newlib/libc/sys/linux/stdlib/cclass.h newlib/libc/sys/linux/stdlib/cname.h newlib/libc/sys/linux/stdlib/collate.c newlib/libc/sys/linux/stdlib/collate.h newlib/libc/sys/linux/stdlib/collcmp.c newlib/libc/sys/linux/stdlib/engine.c newlib/libc/sys/linux/stdlib/fnmatch.3 newlib/libc/sys/linux/stdlib/fnmatch.c newlib/libc/sys/linux/stdlib/glob.3 newlib/libc/sys/linux/stdlib/glob.c newlib/libc/sys/linux/stdlib/reallocf.c newlib/libc/sys/linux/stdlib/regcomp.c newlib/libc/sys/linux/stdlib/regerror.c newlib/libc/sys/linux/stdlib/regex.3 newlib/libc/sys/linux/stdlib/regex2.h newlib/libc/sys/linux/stdlib/regexec.c newlib/libc/sys/linux/stdlib/regfree.c newlib/libc/sys/linux/stdlib/utils.h newlib/libc/sys/linux/stdlib/wordexp.c newlib/libc/sys/linux/stdlib/wordfree.c newlib/libc/sys/linux/sys/ioctl.h newlib/libc/sys/linux/sys/socket.h newlib/libc/sys/linux/sys/types.h newlib/libc/sys/linux/sys/unistd.h newlib/libc/sys/mmixware/isatty.c newlib/libc/sys/sh/syscalls.c newlib/libc/sys/sysnecv850/crt0.S newlib/libc/sys/sysnecv850/isatty.c newlib/libc/syscalls/Makefile.am newlib/libc/syscalls/Makefile.in newlib/libc/syscalls/sysclose.c newlib/libc/syscalls/sysexecve.c newlib/libc/syscalls/sysfcntl.c newlib/libc/syscalls/sysfork.c newlib/libc/syscalls/sysfstat.c newlib/libc/syscalls/sysgetpid.c newlib/libc/syscalls/sysgettod.c newlib/libc/syscalls/syskill.c newlib/libc/syscalls/syslink.c newlib/libc/syscalls/syslseek.c newlib/libc/syscalls/sysopen.c newlib/libc/syscalls/sysread.c newlib/libc/syscalls/syssbrk.c newlib/libc/syscalls/sysstat.c newlib/libc/syscalls/systimes.c newlib/libc/syscalls/sysunlink.c newlib/libc/syscalls/syswait.c newlib/libc/syscalls/syswrite.c newlib/libc/time/mktime.c newlib/libm/libm.texinfo newlib/libm/machine/spu/configure newlib/libm/machine/spu/headers/acosd2.h newlib/libm/machine/spu/headers/acosf4.h newlib/libm/machine/spu/headers/acoshd2.h newlib/libm/machine/spu/headers/acoshf4.h newlib/libm/machine/spu/headers/asind2.h newlib/libm/machine/spu/headers/asinf4.h newlib/libm/machine/spu/headers/asinhd2.h newlib/libm/machine/spu/headers/asinhf4.h newlib/libm/machine/spu/headers/atan2d2.h newlib/libm/machine/spu/headers/atan2f4.h newlib/libm/machine/spu/headers/atand2.h newlib/libm/machine/spu/headers/atanf4.h newlib/libm/machine/spu/headers/atanhd2.h newlib/libm/machine/spu/headers/atanhf4.h newlib/libm/machine/spu/headers/cbrt.h newlib/libm/machine/spu/headers/cbrtf.h newlib/libm/machine/spu/headers/cos_sin.h newlib/libm/machine/spu/headers/cosd2.h newlib/libm/machine/spu/headers/cosf4.h newlib/libm/machine/spu/headers/coshd2.h newlib/libm/machine/spu/headers/coshf4.h newlib/libm/machine/spu/headers/divd2.h newlib/libm/machine/spu/headers/divf4.h newlib/libm/machine/spu/headers/erf_utils.h newlib/libm/machine/spu/headers/erfcd2.h newlib/libm/machine/spu/headers/erfcf4.h newlib/libm/machine/spu/headers/erfd2.h newlib/libm/machine/spu/headers/erff4.h newlib/libm/machine/spu/headers/exp2d2.h newlib/libm/machine/spu/headers/exp2f4.h newlib/libm/machine/spu/headers/expd2.h newlib/libm/machine/spu/headers/expf4.h newlib/libm/machine/spu/headers/expm1d2.h newlib/libm/machine/spu/headers/expm1f4.h newlib/libm/machine/spu/headers/floord2.h newlib/libm/machine/spu/headers/floorf4.h newlib/libm/machine/spu/headers/hypotd2.h newlib/libm/machine/spu/headers/hypotf4.h newlib/libm/machine/spu/headers/isnand2.h newlib/libm/machine/spu/headers/isnanf4.h newlib/libm/machine/spu/headers/ldexpd2.h newlib/libm/machine/spu/headers/ldexpf4.h newlib/libm/machine/spu/headers/lgammad2.h newlib/libm/machine/spu/headers/lgammaf4.h newlib/libm/machine/spu/headers/log10d2.h newlib/libm/machine/spu/headers/log1pd2.h newlib/libm/machine/spu/headers/log1pf4.h newlib/libm/machine/spu/headers/log2d2.h newlib/libm/machine/spu/headers/log2f4.h newlib/libm/machine/spu/headers/logbf4.h newlib/libm/machine/spu/headers/logd2.h newlib/libm/machine/spu/headers/logf4.h newlib/libm/machine/spu/headers/nearbyintf4.h newlib/libm/machine/spu/headers/nextafterd2.h newlib/libm/machine/spu/headers/nextafterf4.h newlib/libm/machine/spu/headers/powd2.h newlib/libm/machine/spu/headers/powf4.h newlib/libm/machine/spu/headers/recipd2.h newlib/libm/machine/spu/headers/recipf4.h newlib/libm/machine/spu/headers/rintf4.h newlib/libm/machine/spu/headers/scalbnf4.h newlib/libm/machine/spu/headers/signbitd2.h newlib/libm/machine/spu/headers/simdmath.h newlib/libm/machine/spu/headers/sincosd2.h newlib/libm/machine/spu/headers/sincosf4.h newlib/libm/machine/spu/headers/sind2.h newlib/libm/machine/spu/headers/sinf4.h newlib/libm/machine/spu/headers/sinhd2.h newlib/libm/machine/spu/headers/sinhf4.h newlib/libm/machine/spu/headers/sqrtd2.h newlib/libm/machine/spu/headers/sqrtf4.h newlib/libm/machine/spu/headers/tand2.h newlib/libm/machine/spu/headers/tanf4.h newlib/libm/machine/spu/headers/tanhd2.h newlib/libm/machine/spu/headers/tanhf4.h newlib/libm/machine/spu/headers/tgammad2.h newlib/libm/machine/spu/headers/tgammaf4.h newlib/libm/machine/spu/headers/truncd2.h newlib/libm/machine/spu/headers/truncf4.h src-release Cherrypick from cygnus 1999-05-03 07:29:06 UTC Richard Henderson '19990502 sourceware import': config/mh-armpic config/mh-elfalphapic config/mh-m68kpic config/mh-papic config/mh-ppcpic config/mh-x86pic Delete: config/extensions.m4 config/futex.m4 config/mh-pa config/mh-pa-hpux10 config/mt-mips-gnu config/mt-mips16-compat config/override.m4 config/proginstall.m4 config/tcl.m4 libgloss/bfin/basiccrt.S libgloss/bfin/bf522.ld libgloss/bfin/bf523.ld libgloss/bfin/bf524.ld libgloss/bfin/bf525.ld libgloss/bfin/bf526.ld libgloss/bfin/bf527.ld libgloss/bfin/bf531.ld libgloss/bfin/bf532.ld libgloss/bfin/bf533.ld libgloss/bfin/bf534.ld libgloss/bfin/bf536.ld libgloss/bfin/bf537.ld libgloss/bfin/bf538.ld libgloss/bfin/bf539.ld libgloss/bfin/bf542.ld libgloss/bfin/bf544.ld libgloss/bfin/bf547.ld libgloss/bfin/bf548.ld libgloss/bfin/bf549.ld libgloss/bfin/bf561.ld libgloss/bfin/bf561a.ld libgloss/bfin/bf561b.ld libgloss/bfin/bf561m.ld libgloss/bfin/bfin-common-mc.ld libgloss/bfin/bfin-common-sc.ld libgloss/bfin/include/blackfin.h libgloss/bfin/include/cdefBF522.h libgloss/bfin/include/cdefBF525.h libgloss/bfin/include/cdefBF527.h libgloss/bfin/include/cdefBF52x_base.h libgloss/bfin/include/cdefBF531.h libgloss/bfin/include/cdefBF532.h libgloss/bfin/include/cdefBF533.h libgloss/bfin/include/cdefBF534.h libgloss/bfin/include/cdefBF535.h libgloss/bfin/include/cdefBF536.h libgloss/bfin/include/cdefBF537.h libgloss/bfin/include/cdefBF538.h libgloss/bfin/include/cdefBF539.h libgloss/bfin/include/cdefBF53x.h libgloss/bfin/include/cdefBF541.h libgloss/bfin/include/cdefBF542.h libgloss/bfin/include/cdefBF544.h libgloss/bfin/include/cdefBF547.h libgloss/bfin/include/cdefBF548.h libgloss/bfin/include/cdefBF549.h libgloss/bfin/include/cdefBF54x_base.h libgloss/bfin/include/cdefBF561.h libgloss/bfin/include/cdef_LPBlackfin.h libgloss/bfin/include/cdefblackfin.h libgloss/bfin/include/cplb.h libgloss/bfin/include/cplbtab.h libgloss/bfin/include/defBF522.h libgloss/bfin/include/defBF525.h libgloss/bfin/include/defBF527.h libgloss/bfin/include/defBF52x_base.h libgloss/bfin/include/defBF531.h libgloss/bfin/include/defBF532.h libgloss/bfin/include/defBF533.h libgloss/bfin/include/defBF534.h libgloss/bfin/include/defBF535.h libgloss/bfin/include/defBF536.h libgloss/bfin/include/defBF537.h libgloss/bfin/include/defBF538.h libgloss/bfin/include/defBF539.h libgloss/bfin/include/defBF541.h libgloss/bfin/include/defBF542.h libgloss/bfin/include/defBF544.h libgloss/bfin/include/defBF547.h libgloss/bfin/include/defBF548.h libgloss/bfin/include/defBF549.h libgloss/bfin/include/defBF54x_base.h libgloss/bfin/include/defBF561.h libgloss/bfin/include/def_LPBlackfin.h libgloss/bfin/include/defblackfin.h libgloss/bfin/include/sys/_adi_platform.h libgloss/bfin/include/sys/anomaly_macros_rtl.h libgloss/bfin/include/sys/excause.h libgloss/bfin/include/sys/exception.h libgloss/bfin/include/sys/mc_typedef.h libgloss/bfin/include/sys/platform.h libgloss/bfin/include/sys/pll.h libgloss/bfin/include/sysreg.h libgloss/spu/linux_syscalls.c libgloss/xstormy16/isatty.c newlib/libc/machine/m68k/m68kasm.h newlib/libc/machine/spu/assert.c newlib/libc/machine/spu/impure.c newlib/libc/machine/spu/include/spu_timer.h newlib/libc/machine/spu/memcmp.c newlib/libc/machine/spu/spu_clock_stop.c newlib/libc/machine/spu/spu_clock_svcs.c newlib/libc/machine/spu/spu_timebase.c newlib/libc/machine/spu/spu_timer_flih.S newlib/libc/machine/spu/spu_timer_free.c newlib/libc/machine/spu/spu_timer_internal.h newlib/libc/machine/spu/spu_timer_slih.c newlib/libc/machine/spu/spu_timer_slih_reg.c newlib/libc/machine/spu/spu_timer_stop.c newlib/libc/machine/spu/spu_timer_svcs.c newlib/libc/machine/spu/straddr.h newlib/libc/machine/spu/strcpy.h newlib/libc/machine/spu/strncmp.h newlib/libc/machine/spu/sys/linux_syscalls.h newlib/libc/posix/_isatty.c newlib/libc/reent/isattyr.c newlib/libc/string/memmem.c newlib/libc/string/str-two-way.h newlib/libc/sys/linux/isatty.c newlib/libc/sys/linux/machine/i386/atomic.h newlib/libc/sys/linux/net/XXX-lookup.c newlib/libc/sys/linux/net/alias-lookup.c newlib/libc/sys/linux/net/aliases.h newlib/libc/sys/linux/net/check_pf.c newlib/libc/sys/linux/net/databases.def newlib/libc/sys/linux/net/digits_dots.c newlib/libc/sys/linux/net/ether_aton.c newlib/libc/sys/linux/net/ether_aton_r.c newlib/libc/sys/linux/net/ether_hton.c newlib/libc/sys/linux/net/ether_line.c newlib/libc/sys/linux/net/ether_ntoa.c newlib/libc/sys/linux/net/ether_ntoa_r.c newlib/libc/sys/linux/net/ether_ntoh.c newlib/libc/sys/linux/net/etherent.h newlib/libc/sys/linux/net/ethers-lookup.c newlib/libc/sys/linux/net/function.def newlib/libc/sys/linux/net/getXXbyYY.c newlib/libc/sys/linux/net/getXXbyYY_r.c newlib/libc/sys/linux/net/getXXent.c newlib/libc/sys/linux/net/getXXent_r.c newlib/libc/sys/linux/net/getaliasent.c newlib/libc/sys/linux/net/getaliasent_r.c newlib/libc/sys/linux/net/getaliasname.c newlib/libc/sys/linux/net/getaliasname_r.c newlib/libc/sys/linux/net/gethstbyad.c newlib/libc/sys/linux/net/gethstbyad_r.c newlib/libc/sys/linux/net/gethstbynm.c newlib/libc/sys/linux/net/gethstbynm2.c newlib/libc/sys/linux/net/gethstbynm2_r.c newlib/libc/sys/linux/net/gethstbynm_r.c newlib/libc/sys/linux/net/gethstent.c newlib/libc/sys/linux/net/gethstent_r.c newlib/libc/sys/linux/net/getnetbyad.c newlib/libc/sys/linux/net/getnetbyad_r.c newlib/libc/sys/linux/net/getnetbynm.c newlib/libc/sys/linux/net/getnetbynm_r.c newlib/libc/sys/linux/net/getnetent.c newlib/libc/sys/linux/net/getnetent_r.c newlib/libc/sys/linux/net/getnetgrent.c newlib/libc/sys/linux/net/getnetgrent_r.c newlib/libc/sys/linux/net/getnssent.c newlib/libc/sys/linux/net/getnssent_r.c newlib/libc/sys/linux/net/getproto_r.c newlib/libc/sys/linux/net/getprtent.c newlib/libc/sys/linux/net/getprtent_r.c newlib/libc/sys/linux/net/getprtname.c newlib/libc/sys/linux/net/getprtname_r.c newlib/libc/sys/linux/net/getrpcbyname.c newlib/libc/sys/linux/net/getrpcbyname_r.c newlib/libc/sys/linux/net/getrpcbynumber.c newlib/libc/sys/linux/net/getrpcbynumber_r.c newlib/libc/sys/linux/net/getrpcent.c newlib/libc/sys/linux/net/getrpcent_r.c newlib/libc/sys/linux/net/getservent_r.c newlib/libc/sys/linux/net/getsrvbynm.c newlib/libc/sys/linux/net/getsrvbynm_r.c newlib/libc/sys/linux/net/getsrvbypt.c newlib/libc/sys/linux/net/getsrvbypt_r.c newlib/libc/sys/linux/net/grp-lookup.c newlib/libc/sys/linux/net/herrno.c newlib/libc/sys/linux/net/hosts-lookup.c newlib/libc/sys/linux/net/ifaddrs.h newlib/libc/sys/linux/net/ifreq.c newlib/libc/sys/linux/net/ifreq.h newlib/libc/sys/linux/net/in6_addr.c newlib/libc/sys/linux/net/inet6_option.c newlib/libc/sys/linux/net/inet_mkadr.c newlib/libc/sys/linux/net/inet_net.c newlib/libc/sys/linux/net/key-lookup.c newlib/libc/sys/linux/net/local.h newlib/libc/sys/linux/net/netgroup.h newlib/libc/sys/linux/net/netgrp-lookup.c newlib/libc/sys/linux/net/network-lookup.c newlib/libc/sys/linux/net/not-cancel.h newlib/libc/sys/linux/net/ns_samedomain.c newlib/libc/sys/linux/net/nscd-types.h newlib/libc/sys/linux/net/nscd/nscd-client.h newlib/libc/sys/linux/net/nscd/nscd_proto.h newlib/libc/sys/linux/net/nss.h newlib/libc/sys/linux/net/nsswitch.c newlib/libc/sys/linux/net/nsswitch.h newlib/libc/sys/linux/net/opensock.c newlib/libc/sys/linux/net/proto-lookup.c newlib/libc/sys/linux/net/pwd-lookup.c newlib/libc/sys/linux/net/res_debug.h newlib/libc/sys/linux/net/res_hconf.c newlib/libc/sys/linux/net/res_hconf.h newlib/libc/sys/linux/net/res_libc.c newlib/libc/sys/linux/net/rexec.c newlib/libc/sys/linux/net/rpc-lookup.c newlib/libc/sys/linux/net/ruserpass.c newlib/libc/sys/linux/net/service-lookup.c newlib/libc/sys/linux/net/spwd-lookup.c newlib/libc/sys/linux/shlib-compat.h newlib/libc/syscalls/sysisatty.c newlib/testsuite/newlib.stdlib/size_max.c newlib/testsuite/newlib.stdlib/stdlib.exp --- newlib/libc/sys/linux/net/Makefile.am | 48 +- newlib/libc/sys/linux/net/Makefile.in | 1061 +++----- newlib/libc/sys/linux/net/XXX-lookup.c | 75 - newlib/libc/sys/linux/net/addr2ascii.3 | 222 ++ newlib/libc/sys/linux/net/alias-lookup.c | 22 - newlib/libc/sys/linux/net/aliases.h | 64 - newlib/libc/sys/linux/net/base64.c | 24 +- newlib/libc/sys/linux/net/bindresvport.c | 160 ++ newlib/libc/sys/linux/net/byteorder.3 | 84 + newlib/libc/sys/linux/net/check_pf.c | 199 -- newlib/libc/sys/linux/net/databases.def | 40 - newlib/libc/sys/linux/net/digits_dots.c | 317 --- newlib/libc/sys/linux/net/ether_addr.c | 231 ++ newlib/libc/sys/linux/net/ether_aton.c | 29 - newlib/libc/sys/linux/net/ether_aton_r.c | 64 - newlib/libc/sys/linux/net/ether_hton.c | 83 - newlib/libc/sys/linux/net/ether_line.c | 81 - newlib/libc/sys/linux/net/ether_ntoa.c | 30 - newlib/libc/sys/linux/net/ether_ntoa_r.c | 34 - newlib/libc/sys/linux/net/ether_ntoh.c | 86 - newlib/libc/sys/linux/net/etherent.h | 9 - newlib/libc/sys/linux/net/ethers-lookup.c | 22 - newlib/libc/sys/linux/net/ethers.3 | 197 ++ newlib/libc/sys/linux/net/function.def | 78 - newlib/libc/sys/linux/net/getXXbyYY.c | 156 -- newlib/libc/sys/linux/net/getXXbyYY_r.c | 292 -- newlib/libc/sys/linux/net/getXXent.c | 96 - newlib/libc/sys/linux/net/getXXent_r.c | 209 -- newlib/libc/sys/linux/net/getaddrinfo.3 | 620 +++++ newlib/libc/sys/linux/net/getaddrinfo.c | 3416 +++++++++++++----------- newlib/libc/sys/linux/net/getaliasent.c | 26 - newlib/libc/sys/linux/net/getaliasent_r.c | 29 - newlib/libc/sys/linux/net/getaliasname.c | 30 - newlib/libc/sys/linux/net/getaliasname_r.c | 29 - newlib/libc/sys/linux/net/gethostbydns.c | 815 ++++++ newlib/libc/sys/linux/net/gethostbyht.c | 285 ++ newlib/libc/sys/linux/net/gethostbyname.3 | 380 +++ newlib/libc/sys/linux/net/gethostbynis.c | 281 ++ newlib/libc/sys/linux/net/gethostnamadr.c | 221 ++ newlib/libc/sys/linux/net/gethstbyad.c | 31 - newlib/libc/sys/linux/net/gethstbyad_r.c | 53 - newlib/libc/sys/linux/net/gethstbynm.c | 38 - newlib/libc/sys/linux/net/gethstbynm2.c | 39 - newlib/libc/sys/linux/net/gethstbynm2_r.c | 46 - newlib/libc/sys/linux/net/gethstbynm_r.c | 45 - newlib/libc/sys/linux/net/gethstent.c | 27 - newlib/libc/sys/linux/net/gethstent_r.c | 35 - newlib/libc/sys/linux/net/getifaddrs.3 | 164 ++ newlib/libc/sys/linux/net/getifaddrs.c | 401 +++ newlib/libc/sys/linux/net/getipnodebyname.3 | 461 ++++ newlib/libc/sys/linux/net/getnameinfo.3 | 311 +++ newlib/libc/sys/linux/net/getnameinfo.c | 768 +++--- newlib/libc/sys/linux/net/getnetbyad.c | 32 - newlib/libc/sys/linux/net/getnetbyad_r.c | 32 - newlib/libc/sys/linux/net/getnetbydns.c | 327 +++ newlib/libc/sys/linux/net/getnetbyht.c | 183 ++ newlib/libc/sys/linux/net/getnetbynis.c | 190 ++ newlib/libc/sys/linux/net/getnetbynm.c | 31 - newlib/libc/sys/linux/net/getnetbynm_r.c | 31 - newlib/libc/sys/linux/net/getnetent.3 | 172 ++ newlib/libc/sys/linux/net/getnetent.c | 27 - newlib/libc/sys/linux/net/getnetent_r.c | 32 - newlib/libc/sys/linux/net/getnetgrent.c | 52 - newlib/libc/sys/linux/net/getnetgrent_r.c | 446 ---- newlib/libc/sys/linux/net/getnetnamadr.c | 113 + newlib/libc/sys/linux/net/getnssent.c | 58 - newlib/libc/sys/linux/net/getnssent_r.c | 218 -- newlib/libc/sys/linux/net/getproto.c | 75 +- newlib/libc/sys/linux/net/getproto_r.c | 29 - newlib/libc/sys/linux/net/getprotoent.3 | 149 ++ newlib/libc/sys/linux/net/getprotoent.c | 121 + newlib/libc/sys/linux/net/getprotoname.c | 64 + newlib/libc/sys/linux/net/getprtent.c | 26 - newlib/libc/sys/linux/net/getprtent_r.c | 30 - newlib/libc/sys/linux/net/getprtname.c | 30 - newlib/libc/sys/linux/net/getprtname_r.c | 29 - newlib/libc/sys/linux/net/getrpcbyname.c | 30 - newlib/libc/sys/linux/net/getrpcbyname_r.c | 29 - newlib/libc/sys/linux/net/getrpcbynumber.c | 30 - newlib/libc/sys/linux/net/getrpcbynumber_r.c | 29 - newlib/libc/sys/linux/net/getrpcent.c | 26 - newlib/libc/sys/linux/net/getrpcent_r.c | 30 - newlib/libc/sys/linux/net/getservbyname.c | 81 + newlib/libc/sys/linux/net/getservbyport.c | 76 + newlib/libc/sys/linux/net/getservent.3 | 158 ++ newlib/libc/sys/linux/net/getservent.c | 294 +- newlib/libc/sys/linux/net/getservent_r.c | 30 - newlib/libc/sys/linux/net/getsrvbynm.c | 30 - newlib/libc/sys/linux/net/getsrvbynm_r.c | 29 - newlib/libc/sys/linux/net/getsrvbypt.c | 30 - newlib/libc/sys/linux/net/getsrvbypt_r.c | 29 - newlib/libc/sys/linux/net/grp-lookup.c | 23 - newlib/libc/sys/linux/net/herrno.c | 6 - newlib/libc/sys/linux/net/herror.c | 103 + newlib/libc/sys/linux/net/hesiod.3 | 159 ++ newlib/libc/sys/linux/net/hesiod.c | 600 +++++ newlib/libc/sys/linux/net/hosts-lookup.c | 23 - newlib/libc/sys/linux/net/if_indextoname.3 | 142 + newlib/libc/sys/linux/net/ifaddrs.h | 74 - newlib/libc/sys/linux/net/ifreq.c | 100 - newlib/libc/sys/linux/net/ifreq.h | 40 - newlib/libc/sys/linux/net/in6_addr.c | 28 - newlib/libc/sys/linux/net/inet.3 | 271 ++ newlib/libc/sys/linux/net/inet6_option.c | 346 --- newlib/libc/sys/linux/net/inet6_option_space.3 | 445 +++ newlib/libc/sys/linux/net/inet6_rthdr_space.3 | 323 +++ newlib/libc/sys/linux/net/inet_lnaof.c | 16 +- newlib/libc/sys/linux/net/inet_makeaddr.c | 72 + newlib/libc/sys/linux/net/inet_mkadr.c | 60 - newlib/libc/sys/linux/net/inet_net.3 | 157 ++ newlib/libc/sys/linux/net/inet_net.c | 95 - newlib/libc/sys/linux/net/inet_netof.c | 18 +- newlib/libc/sys/linux/net/inet_network.c | 100 + newlib/libc/sys/linux/net/inet_ntoa.c | 151 +- newlib/libc/sys/linux/net/innetgr-stub.c | 7 + newlib/libc/sys/linux/net/ip6opt.c | 387 +++ newlib/libc/sys/linux/net/iso_addr.3 | 113 + newlib/libc/sys/linux/net/iso_addr.c | 119 + newlib/libc/sys/linux/net/key-lookup.c | 23 - newlib/libc/sys/linux/net/linkaddr.3 | 140 + newlib/libc/sys/linux/net/linkaddr.c | 160 ++ newlib/libc/sys/linux/net/local.h | 24 - newlib/libc/sys/linux/net/map_v4v6.c | 128 + newlib/libc/sys/linux/net/name6.c | 1812 +++++++++++++ newlib/libc/sys/linux/net/namespace.h | 152 ++ newlib/libc/sys/linux/net/netgroup.h | 80 - newlib/libc/sys/linux/net/netgrp-lookup.c | 22 - newlib/libc/sys/linux/net/network-lookup.c | 23 - newlib/libc/sys/linux/net/not-cancel.h | 53 - newlib/libc/sys/linux/net/ns.3 | 133 + newlib/libc/sys/linux/net/ns_addr.c | 239 ++ newlib/libc/sys/linux/net/ns_name.c | 320 +-- newlib/libc/sys/linux/net/ns_netint.c | 17 +- newlib/libc/sys/linux/net/ns_ntoa.c | 105 + newlib/libc/sys/linux/net/ns_parse.c | 125 +- newlib/libc/sys/linux/net/ns_print.c | 143 +- newlib/libc/sys/linux/net/ns_samedomain.c | 204 -- newlib/libc/sys/linux/net/ns_ttl.c | 21 +- newlib/libc/sys/linux/net/nsap_addr.c | 41 +- newlib/libc/sys/linux/net/nscd-types.h | 22 - newlib/libc/sys/linux/net/nscd/nscd-client.h | 312 --- newlib/libc/sys/linux/net/nscd/nscd_proto.h | 67 - newlib/libc/sys/linux/net/nsdispatch.3 | 231 ++ newlib/libc/sys/linux/net/nsdispatch.c | 266 ++ newlib/libc/sys/linux/net/nslexer.c | 1712 ++++++++++++ newlib/libc/sys/linux/net/nslexer.l | 114 + newlib/libc/sys/linux/net/nsparser.c | 541 ++++ newlib/libc/sys/linux/net/nsparser.h | 13 + newlib/libc/sys/linux/net/nsparser.y | 178 ++ newlib/libc/sys/linux/net/nss.h | 52 - newlib/libc/sys/linux/net/nsswitch.c | 772 ------ newlib/libc/sys/linux/net/nsswitch.h | 180 -- newlib/libc/sys/linux/net/opensock.c | 120 - newlib/libc/sys/linux/net/proto-lookup.c | 22 - newlib/libc/sys/linux/net/pwd-lookup.c | 23 - newlib/libc/sys/linux/net/rcmd.3 | 298 +++ newlib/libc/sys/linux/net/rcmd.c | 1190 ++++----- newlib/libc/sys/linux/net/rcmdsh.3 | 116 + newlib/libc/sys/linux/net/res_comp.c | 74 +- newlib/libc/sys/linux/net/res_config.h | 10 + newlib/libc/sys/linux/net/res_data.c | 303 +-- newlib/libc/sys/linux/net/res_debug.c | 407 ++- newlib/libc/sys/linux/net/res_debug.h | 34 - newlib/libc/sys/linux/net/res_hconf.c | 676 ----- newlib/libc/sys/linux/net/res_hconf.h | 55 - newlib/libc/sys/linux/net/res_init.c | 495 ++-- newlib/libc/sys/linux/net/res_libc.c | 166 -- newlib/libc/sys/linux/net/res_mkquery.c | 137 +- newlib/libc/sys/linux/net/res_mkupdate.c | 412 +++ newlib/libc/sys/linux/net/res_query.c | 315 +-- newlib/libc/sys/linux/net/res_send.c | 1480 +++++----- newlib/libc/sys/linux/net/res_update.c | 515 ++++ newlib/libc/sys/linux/net/resolver.3 | 422 +++ newlib/libc/sys/linux/net/rexec.c | 202 -- newlib/libc/sys/linux/net/rpc-lookup.c | 22 - newlib/libc/sys/linux/net/rthdr.c | 319 +++ newlib/libc/sys/linux/net/ruserpass.c | 336 --- newlib/libc/sys/linux/net/send.c | 1 + newlib/libc/sys/linux/net/service-lookup.c | 22 - newlib/libc/sys/linux/net/spwd-lookup.c | 24 - newlib/libc/sys/linux/net/vars.c | 45 + 181 files changed, 22577 insertions(+), 14059 deletions(-) delete mode 100644 newlib/libc/sys/linux/net/XXX-lookup.c create mode 100644 newlib/libc/sys/linux/net/addr2ascii.3 delete mode 100644 newlib/libc/sys/linux/net/alias-lookup.c delete mode 100644 newlib/libc/sys/linux/net/aliases.h create mode 100644 newlib/libc/sys/linux/net/bindresvport.c create mode 100644 newlib/libc/sys/linux/net/byteorder.3 delete mode 100644 newlib/libc/sys/linux/net/check_pf.c delete mode 100644 newlib/libc/sys/linux/net/databases.def delete mode 100644 newlib/libc/sys/linux/net/digits_dots.c create mode 100644 newlib/libc/sys/linux/net/ether_addr.c delete mode 100644 newlib/libc/sys/linux/net/ether_aton.c delete mode 100644 newlib/libc/sys/linux/net/ether_aton_r.c delete mode 100644 newlib/libc/sys/linux/net/ether_hton.c delete mode 100644 newlib/libc/sys/linux/net/ether_line.c delete mode 100644 newlib/libc/sys/linux/net/ether_ntoa.c delete mode 100644 newlib/libc/sys/linux/net/ether_ntoa_r.c delete mode 100644 newlib/libc/sys/linux/net/ether_ntoh.c delete mode 100644 newlib/libc/sys/linux/net/etherent.h delete mode 100644 newlib/libc/sys/linux/net/ethers-lookup.c create mode 100644 newlib/libc/sys/linux/net/ethers.3 delete mode 100644 newlib/libc/sys/linux/net/function.def delete mode 100644 newlib/libc/sys/linux/net/getXXbyYY.c delete mode 100644 newlib/libc/sys/linux/net/getXXbyYY_r.c delete mode 100644 newlib/libc/sys/linux/net/getXXent.c delete mode 100644 newlib/libc/sys/linux/net/getXXent_r.c create mode 100644 newlib/libc/sys/linux/net/getaddrinfo.3 delete mode 100644 newlib/libc/sys/linux/net/getaliasent.c delete mode 100644 newlib/libc/sys/linux/net/getaliasent_r.c delete mode 100644 newlib/libc/sys/linux/net/getaliasname.c delete mode 100644 newlib/libc/sys/linux/net/getaliasname_r.c create mode 100644 newlib/libc/sys/linux/net/gethostbydns.c create mode 100644 newlib/libc/sys/linux/net/gethostbyht.c create mode 100644 newlib/libc/sys/linux/net/gethostbyname.3 create mode 100644 newlib/libc/sys/linux/net/gethostbynis.c create mode 100644 newlib/libc/sys/linux/net/gethostnamadr.c delete mode 100644 newlib/libc/sys/linux/net/gethstbyad.c delete mode 100644 newlib/libc/sys/linux/net/gethstbyad_r.c delete mode 100644 newlib/libc/sys/linux/net/gethstbynm.c delete mode 100644 newlib/libc/sys/linux/net/gethstbynm2.c delete mode 100644 newlib/libc/sys/linux/net/gethstbynm2_r.c delete mode 100644 newlib/libc/sys/linux/net/gethstbynm_r.c delete mode 100644 newlib/libc/sys/linux/net/gethstent.c delete mode 100644 newlib/libc/sys/linux/net/gethstent_r.c create mode 100644 newlib/libc/sys/linux/net/getifaddrs.3 create mode 100644 newlib/libc/sys/linux/net/getifaddrs.c create mode 100644 newlib/libc/sys/linux/net/getipnodebyname.3 create mode 100644 newlib/libc/sys/linux/net/getnameinfo.3 delete mode 100644 newlib/libc/sys/linux/net/getnetbyad.c delete mode 100644 newlib/libc/sys/linux/net/getnetbyad_r.c create mode 100644 newlib/libc/sys/linux/net/getnetbydns.c create mode 100644 newlib/libc/sys/linux/net/getnetbyht.c create mode 100644 newlib/libc/sys/linux/net/getnetbynis.c delete mode 100644 newlib/libc/sys/linux/net/getnetbynm.c delete mode 100644 newlib/libc/sys/linux/net/getnetbynm_r.c create mode 100644 newlib/libc/sys/linux/net/getnetent.3 delete mode 100644 newlib/libc/sys/linux/net/getnetent.c delete mode 100644 newlib/libc/sys/linux/net/getnetent_r.c delete mode 100644 newlib/libc/sys/linux/net/getnetgrent.c delete mode 100644 newlib/libc/sys/linux/net/getnetgrent_r.c create mode 100644 newlib/libc/sys/linux/net/getnetnamadr.c delete mode 100644 newlib/libc/sys/linux/net/getnssent.c delete mode 100644 newlib/libc/sys/linux/net/getnssent_r.c delete mode 100644 newlib/libc/sys/linux/net/getproto_r.c create mode 100644 newlib/libc/sys/linux/net/getprotoent.3 create mode 100644 newlib/libc/sys/linux/net/getprotoent.c create mode 100644 newlib/libc/sys/linux/net/getprotoname.c delete mode 100644 newlib/libc/sys/linux/net/getprtent.c delete mode 100644 newlib/libc/sys/linux/net/getprtent_r.c delete mode 100644 newlib/libc/sys/linux/net/getprtname.c delete mode 100644 newlib/libc/sys/linux/net/getprtname_r.c delete mode 100644 newlib/libc/sys/linux/net/getrpcbyname.c delete mode 100644 newlib/libc/sys/linux/net/getrpcbyname_r.c delete mode 100644 newlib/libc/sys/linux/net/getrpcbynumber.c delete mode 100644 newlib/libc/sys/linux/net/getrpcbynumber_r.c delete mode 100644 newlib/libc/sys/linux/net/getrpcent.c delete mode 100644 newlib/libc/sys/linux/net/getrpcent_r.c create mode 100644 newlib/libc/sys/linux/net/getservbyname.c create mode 100644 newlib/libc/sys/linux/net/getservbyport.c create mode 100644 newlib/libc/sys/linux/net/getservent.3 delete mode 100644 newlib/libc/sys/linux/net/getservent_r.c delete mode 100644 newlib/libc/sys/linux/net/getsrvbynm.c delete mode 100644 newlib/libc/sys/linux/net/getsrvbynm_r.c delete mode 100644 newlib/libc/sys/linux/net/getsrvbypt.c delete mode 100644 newlib/libc/sys/linux/net/getsrvbypt_r.c delete mode 100644 newlib/libc/sys/linux/net/grp-lookup.c delete mode 100644 newlib/libc/sys/linux/net/herrno.c create mode 100644 newlib/libc/sys/linux/net/herror.c create mode 100644 newlib/libc/sys/linux/net/hesiod.3 create mode 100644 newlib/libc/sys/linux/net/hesiod.c delete mode 100644 newlib/libc/sys/linux/net/hosts-lookup.c create mode 100644 newlib/libc/sys/linux/net/if_indextoname.3 delete mode 100644 newlib/libc/sys/linux/net/ifaddrs.h delete mode 100644 newlib/libc/sys/linux/net/ifreq.c delete mode 100644 newlib/libc/sys/linux/net/ifreq.h delete mode 100644 newlib/libc/sys/linux/net/in6_addr.c create mode 100644 newlib/libc/sys/linux/net/inet.3 delete mode 100644 newlib/libc/sys/linux/net/inet6_option.c create mode 100644 newlib/libc/sys/linux/net/inet6_option_space.3 create mode 100644 newlib/libc/sys/linux/net/inet6_rthdr_space.3 create mode 100644 newlib/libc/sys/linux/net/inet_makeaddr.c delete mode 100644 newlib/libc/sys/linux/net/inet_mkadr.c create mode 100644 newlib/libc/sys/linux/net/inet_net.3 delete mode 100644 newlib/libc/sys/linux/net/inet_net.c create mode 100644 newlib/libc/sys/linux/net/inet_network.c create mode 100644 newlib/libc/sys/linux/net/innetgr-stub.c create mode 100644 newlib/libc/sys/linux/net/ip6opt.c create mode 100644 newlib/libc/sys/linux/net/iso_addr.3 create mode 100644 newlib/libc/sys/linux/net/iso_addr.c delete mode 100644 newlib/libc/sys/linux/net/key-lookup.c create mode 100644 newlib/libc/sys/linux/net/linkaddr.3 create mode 100644 newlib/libc/sys/linux/net/linkaddr.c delete mode 100644 newlib/libc/sys/linux/net/local.h create mode 100644 newlib/libc/sys/linux/net/map_v4v6.c create mode 100644 newlib/libc/sys/linux/net/name6.c create mode 100644 newlib/libc/sys/linux/net/namespace.h delete mode 100644 newlib/libc/sys/linux/net/netgroup.h delete mode 100644 newlib/libc/sys/linux/net/netgrp-lookup.c delete mode 100644 newlib/libc/sys/linux/net/network-lookup.c delete mode 100644 newlib/libc/sys/linux/net/not-cancel.h create mode 100644 newlib/libc/sys/linux/net/ns.3 create mode 100644 newlib/libc/sys/linux/net/ns_addr.c create mode 100644 newlib/libc/sys/linux/net/ns_ntoa.c delete mode 100644 newlib/libc/sys/linux/net/ns_samedomain.c delete mode 100644 newlib/libc/sys/linux/net/nscd-types.h delete mode 100644 newlib/libc/sys/linux/net/nscd/nscd-client.h delete mode 100644 newlib/libc/sys/linux/net/nscd/nscd_proto.h create mode 100644 newlib/libc/sys/linux/net/nsdispatch.3 create mode 100644 newlib/libc/sys/linux/net/nsdispatch.c create mode 100644 newlib/libc/sys/linux/net/nslexer.c create mode 100644 newlib/libc/sys/linux/net/nslexer.l create mode 100644 newlib/libc/sys/linux/net/nsparser.c create mode 100644 newlib/libc/sys/linux/net/nsparser.h create mode 100644 newlib/libc/sys/linux/net/nsparser.y delete mode 100644 newlib/libc/sys/linux/net/nss.h delete mode 100644 newlib/libc/sys/linux/net/nsswitch.c delete mode 100644 newlib/libc/sys/linux/net/nsswitch.h delete mode 100644 newlib/libc/sys/linux/net/opensock.c delete mode 100644 newlib/libc/sys/linux/net/proto-lookup.c delete mode 100644 newlib/libc/sys/linux/net/pwd-lookup.c create mode 100644 newlib/libc/sys/linux/net/rcmd.3 create mode 100644 newlib/libc/sys/linux/net/rcmdsh.3 create mode 100644 newlib/libc/sys/linux/net/res_config.h delete mode 100644 newlib/libc/sys/linux/net/res_debug.h delete mode 100644 newlib/libc/sys/linux/net/res_hconf.c delete mode 100644 newlib/libc/sys/linux/net/res_hconf.h delete mode 100644 newlib/libc/sys/linux/net/res_libc.c create mode 100644 newlib/libc/sys/linux/net/res_mkupdate.c create mode 100644 newlib/libc/sys/linux/net/res_update.c create mode 100644 newlib/libc/sys/linux/net/resolver.3 delete mode 100644 newlib/libc/sys/linux/net/rexec.c delete mode 100644 newlib/libc/sys/linux/net/rpc-lookup.c create mode 100644 newlib/libc/sys/linux/net/rthdr.c delete mode 100644 newlib/libc/sys/linux/net/ruserpass.c delete mode 100644 newlib/libc/sys/linux/net/service-lookup.c delete mode 100644 newlib/libc/sys/linux/net/spwd-lookup.c create mode 100644 newlib/libc/sys/linux/net/vars.c (limited to 'newlib/libc/sys/linux/net') diff --git a/newlib/libc/sys/linux/net/Makefile.am b/newlib/libc/sys/linux/net/Makefile.am index 0b1a0d978..080709f4d 100644 --- a/newlib/libc/sys/linux/net/Makefile.am +++ b/newlib/libc/sys/linux/net/Makefile.am @@ -2,38 +2,28 @@ AUTOMAKE_OPTIONS = cygnus -INCLUDES = -I$(srcdir)/../include -I$(srcdir)/.. $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) +INCLUDES = -I$(srcdir)/../include $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -GENERAL_SOURCES = addr2ascii.c ascii2addr.c alias-lookup.c \ - base64.c check_pf.c digits_dots.c \ - ether_aton.c ether_aton_r.c ether_hton.c \ - ether_line.c ether_ntoa.c ether_ntoa_r.c ether_ntoh.c \ - ethers-lookup.c getaddrinfo.c getaliasent.c \ - getaliasent_r.c getaliasname.c getaliasname_r.c gethstbyad.c \ - gethstbyad_r.c gethstbynm2.c gethstbynm2_r.c gethstbynm.c \ - gethstbynm_r.c gethstent.c gethstent_r.c getnameinfo.c getnetbyad.c \ - getnetbyad_r.c getnetbynm.c getnetbynm_r.c getnetent.c getnetent_r.c \ - getnetgrent.c getnetgrent_r.c getnssent.c getnssent_r.c getproto.c \ - getproto_r.c getprtent.c \ - getprtent_r.c getprtname.c getprtname_r.c getrpcbyname.c \ - getrpcbyname_r.c getrpcbynumber.c getrpcbynumber_r.c getrpcent.c \ - getrpcent_r.c getservent.c getservent_r.c getsrvbynm.c getsrvbynm_r.c \ - getsrvbypt.c getsrvbypt_r.c grp-lookup.c \ - herrno.c hosts-lookup.c ifreq.c \ - in6_addr.c inet6_option.c inet_addr.c \ - inet_lnaof.c inet_mkadr.c inet_net.c inet_neta.c inet_netof.c \ - inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c \ - inet_pton.c issetugid-stub.c key-lookup.c netgrp-lookup.c \ - network-lookup.c nsswitch.c \ - ns_name.c ns_netint.c ns_parse.c ns_print.c ns_samedomain.c \ - ns_ttl.c nsap_addr.c proto-lookup.c opensock.c pwd-lookup.c recv.c \ - res_comp.c res_data.c res_debug.c res_hconf.c res_init.c \ - res_libc.c res_mkquery.c \ - res_query.c res_send.c \ - rexec.c rpc-lookup.c ruserpass.c send.c service-lookup.c spwd-lookup.c +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 ELIX_4_SOURCES = \ - ifname.c \ rcmd.$(oext) \ rcmdsh.$(oext) diff --git a/newlib/libc/sys/linux/net/Makefile.in b/newlib/libc/sys/linux/net/Makefile.in index f373a9094..84aeff804 100644 --- a/newlib/libc/sys/linux/net/Makefile.in +++ b/newlib/libc/sys/linux/net/Makefile.in @@ -56,59 +56,38 @@ ARFLAGS = cru lib_a_AR = $(AR) $(ARFLAGS) lib_a_LIBADD = am__objects_1 = lib_a-addr2ascii.$(OBJEXT) lib_a-ascii2addr.$(OBJEXT) \ - lib_a-alias-lookup.$(OBJEXT) lib_a-base64.$(OBJEXT) \ - lib_a-check_pf.$(OBJEXT) lib_a-digits_dots.$(OBJEXT) \ - lib_a-ether_aton.$(OBJEXT) lib_a-ether_aton_r.$(OBJEXT) \ - lib_a-ether_hton.$(OBJEXT) lib_a-ether_line.$(OBJEXT) \ - lib_a-ether_ntoa.$(OBJEXT) lib_a-ether_ntoa_r.$(OBJEXT) \ - lib_a-ether_ntoh.$(OBJEXT) lib_a-ethers-lookup.$(OBJEXT) \ - lib_a-getaddrinfo.$(OBJEXT) lib_a-getaliasent.$(OBJEXT) \ - lib_a-getaliasent_r.$(OBJEXT) lib_a-getaliasname.$(OBJEXT) \ - lib_a-getaliasname_r.$(OBJEXT) lib_a-gethstbyad.$(OBJEXT) \ - lib_a-gethstbyad_r.$(OBJEXT) lib_a-gethstbynm2.$(OBJEXT) \ - lib_a-gethstbynm2_r.$(OBJEXT) lib_a-gethstbynm.$(OBJEXT) \ - lib_a-gethstbynm_r.$(OBJEXT) lib_a-gethstent.$(OBJEXT) \ - lib_a-gethstent_r.$(OBJEXT) lib_a-getnameinfo.$(OBJEXT) \ - lib_a-getnetbyad.$(OBJEXT) lib_a-getnetbyad_r.$(OBJEXT) \ - lib_a-getnetbynm.$(OBJEXT) lib_a-getnetbynm_r.$(OBJEXT) \ - lib_a-getnetent.$(OBJEXT) lib_a-getnetent_r.$(OBJEXT) \ - lib_a-getnetgrent.$(OBJEXT) lib_a-getnetgrent_r.$(OBJEXT) \ - lib_a-getnssent.$(OBJEXT) lib_a-getnssent_r.$(OBJEXT) \ - lib_a-getproto.$(OBJEXT) lib_a-getproto_r.$(OBJEXT) \ - lib_a-getprtent.$(OBJEXT) lib_a-getprtent_r.$(OBJEXT) \ - lib_a-getprtname.$(OBJEXT) lib_a-getprtname_r.$(OBJEXT) \ - lib_a-getrpcbyname.$(OBJEXT) lib_a-getrpcbyname_r.$(OBJEXT) \ - lib_a-getrpcbynumber.$(OBJEXT) \ - lib_a-getrpcbynumber_r.$(OBJEXT) lib_a-getrpcent.$(OBJEXT) \ - lib_a-getrpcent_r.$(OBJEXT) lib_a-getservent.$(OBJEXT) \ - lib_a-getservent_r.$(OBJEXT) lib_a-getsrvbynm.$(OBJEXT) \ - lib_a-getsrvbynm_r.$(OBJEXT) lib_a-getsrvbypt.$(OBJEXT) \ - lib_a-getsrvbypt_r.$(OBJEXT) lib_a-grp-lookup.$(OBJEXT) \ - lib_a-herrno.$(OBJEXT) lib_a-hosts-lookup.$(OBJEXT) \ - lib_a-ifreq.$(OBJEXT) lib_a-in6_addr.$(OBJEXT) \ - lib_a-inet6_option.$(OBJEXT) lib_a-inet_addr.$(OBJEXT) \ - lib_a-inet_lnaof.$(OBJEXT) lib_a-inet_mkadr.$(OBJEXT) \ - lib_a-inet_net.$(OBJEXT) lib_a-inet_neta.$(OBJEXT) \ - lib_a-inet_netof.$(OBJEXT) lib_a-inet_net_ntop.$(OBJEXT) \ - lib_a-inet_net_pton.$(OBJEXT) lib_a-inet_ntoa.$(OBJEXT) \ + lib_a-base64.$(OBJEXT) lib_a-bindresvport.$(OBJEXT) \ + lib_a-ether_addr.$(OBJEXT) lib_a-getaddrinfo.$(OBJEXT) \ + lib_a-gethostbydns.$(OBJEXT) lib_a-gethostbyht.$(OBJEXT) \ + lib_a-gethostbynis.$(OBJEXT) lib_a-gethostnamadr.$(OBJEXT) \ + lib_a-getifaddrs.$(OBJEXT) lib_a-getnameinfo.$(OBJEXT) \ + lib_a-getnetbydns.$(OBJEXT) lib_a-getnetbyht.$(OBJEXT) \ + lib_a-getnetbynis.$(OBJEXT) lib_a-getnetnamadr.$(OBJEXT) \ + lib_a-getproto.$(OBJEXT) lib_a-getprotoent.$(OBJEXT) \ + lib_a-getprotoname.$(OBJEXT) lib_a-getservbyname.$(OBJEXT) \ + lib_a-getservbyport.$(OBJEXT) lib_a-getservent.$(OBJEXT) \ + lib_a-herror.$(OBJEXT) lib_a-hesiod.$(OBJEXT) \ + lib_a-inet_addr.$(OBJEXT) lib_a-ifname.$(OBJEXT) \ + lib_a-inet_lnaof.$(OBJEXT) lib_a-inet_makeaddr.$(OBJEXT) \ + lib_a-inet_net_ntop.$(OBJEXT) lib_a-inet_net_pton.$(OBJEXT) \ + lib_a-inet_neta.$(OBJEXT) lib_a-inet_netof.$(OBJEXT) \ + lib_a-inet_network.$(OBJEXT) lib_a-inet_ntoa.$(OBJEXT) \ lib_a-inet_ntop.$(OBJEXT) lib_a-inet_pton.$(OBJEXT) \ - lib_a-issetugid-stub.$(OBJEXT) lib_a-key-lookup.$(OBJEXT) \ - lib_a-netgrp-lookup.$(OBJEXT) lib_a-network-lookup.$(OBJEXT) \ - lib_a-nsswitch.$(OBJEXT) lib_a-ns_name.$(OBJEXT) \ - lib_a-ns_netint.$(OBJEXT) lib_a-ns_parse.$(OBJEXT) \ - lib_a-ns_print.$(OBJEXT) lib_a-ns_samedomain.$(OBJEXT) \ - lib_a-ns_ttl.$(OBJEXT) lib_a-nsap_addr.$(OBJEXT) \ - lib_a-proto-lookup.$(OBJEXT) lib_a-opensock.$(OBJEXT) \ - lib_a-pwd-lookup.$(OBJEXT) lib_a-recv.$(OBJEXT) \ - lib_a-res_comp.$(OBJEXT) lib_a-res_data.$(OBJEXT) \ - lib_a-res_debug.$(OBJEXT) lib_a-res_hconf.$(OBJEXT) \ - lib_a-res_init.$(OBJEXT) lib_a-res_libc.$(OBJEXT) \ - lib_a-res_mkquery.$(OBJEXT) lib_a-res_query.$(OBJEXT) \ - lib_a-res_send.$(OBJEXT) lib_a-rexec.$(OBJEXT) \ - lib_a-rpc-lookup.$(OBJEXT) lib_a-ruserpass.$(OBJEXT) \ - lib_a-send.$(OBJEXT) lib_a-service-lookup.$(OBJEXT) \ - lib_a-spwd-lookup.$(OBJEXT) -am__objects_2 = lib_a-ifname.$(OBJEXT) + lib_a-innetgr-stub.$(OBJEXT) lib_a-ip6opt.$(OBJEXT) \ + lib_a-issetugid-stub.$(OBJEXT) lib_a-linkaddr.$(OBJEXT) \ + lib_a-map_v4v6.$(OBJEXT) lib_a-name6.$(OBJEXT) \ + lib_a-ns_addr.$(OBJEXT) lib_a-ns_name.$(OBJEXT) \ + lib_a-ns_netint.$(OBJEXT) lib_a-ns_ntoa.$(OBJEXT) \ + lib_a-ns_parse.$(OBJEXT) lib_a-ns_print.$(OBJEXT) \ + lib_a-ns_ttl.$(OBJEXT) lib_a-nsdispatch.$(OBJEXT) \ + lib_a-nslexer.$(OBJEXT) lib_a-nsparser.$(OBJEXT) \ + lib_a-nsap_addr.$(OBJEXT) lib_a-res_comp.$(OBJEXT) \ + lib_a-res_data.$(OBJEXT) lib_a-res_debug.$(OBJEXT) \ + lib_a-res_init.$(OBJEXT) lib_a-res_mkquery.$(OBJEXT) \ + lib_a-res_mkupdate.$(OBJEXT) lib_a-res_query.$(OBJEXT) \ + lib_a-res_send.$(OBJEXT) lib_a-res_update.$(OBJEXT) \ + lib_a-rthdr.$(OBJEXT) lib_a-vars.$(OBJEXT) +am__objects_2 = @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_3 = $(am__objects_2) @USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \ @USE_LIBTOOL_FALSE@ $(am__objects_3) @@ -116,61 +95,38 @@ lib_a_OBJECTS = $(am_lib_a_OBJECTS) LTLIBRARIES = $(noinst_LTLIBRARIES) libnet_la_LIBADD = am__objects_4 = libnet_la-addr2ascii.lo libnet_la-ascii2addr.lo \ - libnet_la-alias-lookup.lo libnet_la-base64.lo \ - libnet_la-check_pf.lo libnet_la-digits_dots.lo \ - libnet_la-ether_aton.lo libnet_la-ether_aton_r.lo \ - libnet_la-ether_hton.lo libnet_la-ether_line.lo \ - libnet_la-ether_ntoa.lo libnet_la-ether_ntoa_r.lo \ - libnet_la-ether_ntoh.lo libnet_la-ethers-lookup.lo \ - libnet_la-getaddrinfo.lo libnet_la-getaliasent.lo \ - libnet_la-getaliasent_r.lo libnet_la-getaliasname.lo \ - libnet_la-getaliasname_r.lo libnet_la-gethstbyad.lo \ - libnet_la-gethstbyad_r.lo libnet_la-gethstbynm2.lo \ - libnet_la-gethstbynm2_r.lo libnet_la-gethstbynm.lo \ - libnet_la-gethstbynm_r.lo libnet_la-gethstent.lo \ - libnet_la-gethstent_r.lo libnet_la-getnameinfo.lo \ - libnet_la-getnetbyad.lo libnet_la-getnetbyad_r.lo \ - libnet_la-getnetbynm.lo libnet_la-getnetbynm_r.lo \ - libnet_la-getnetent.lo libnet_la-getnetent_r.lo \ - libnet_la-getnetgrent.lo libnet_la-getnetgrent_r.lo \ - libnet_la-getnssent.lo libnet_la-getnssent_r.lo \ - libnet_la-getproto.lo libnet_la-getproto_r.lo \ - libnet_la-getprtent.lo libnet_la-getprtent_r.lo \ - libnet_la-getprtname.lo libnet_la-getprtname_r.lo \ - libnet_la-getrpcbyname.lo libnet_la-getrpcbyname_r.lo \ - libnet_la-getrpcbynumber.lo libnet_la-getrpcbynumber_r.lo \ - libnet_la-getrpcent.lo libnet_la-getrpcent_r.lo \ - libnet_la-getservent.lo libnet_la-getservent_r.lo \ - libnet_la-getsrvbynm.lo libnet_la-getsrvbynm_r.lo \ - libnet_la-getsrvbypt.lo libnet_la-getsrvbypt_r.lo \ - libnet_la-grp-lookup.lo libnet_la-herrno.lo \ - libnet_la-hosts-lookup.lo libnet_la-ifreq.lo \ - libnet_la-in6_addr.lo libnet_la-inet6_option.lo \ - libnet_la-inet_addr.lo libnet_la-inet_lnaof.lo \ - libnet_la-inet_mkadr.lo libnet_la-inet_net.lo \ - libnet_la-inet_neta.lo libnet_la-inet_netof.lo \ - libnet_la-inet_net_ntop.lo libnet_la-inet_net_pton.lo \ + libnet_la-base64.lo libnet_la-bindresvport.lo \ + libnet_la-ether_addr.lo libnet_la-getaddrinfo.lo \ + libnet_la-gethostbydns.lo libnet_la-gethostbyht.lo \ + libnet_la-gethostbynis.lo libnet_la-gethostnamadr.lo \ + libnet_la-getifaddrs.lo libnet_la-getnameinfo.lo \ + libnet_la-getnetbydns.lo libnet_la-getnetbyht.lo \ + libnet_la-getnetbynis.lo libnet_la-getnetnamadr.lo \ + libnet_la-getproto.lo libnet_la-getprotoent.lo \ + libnet_la-getprotoname.lo libnet_la-getservbyname.lo \ + libnet_la-getservbyport.lo libnet_la-getservent.lo \ + libnet_la-herror.lo libnet_la-hesiod.lo libnet_la-inet_addr.lo \ + libnet_la-ifname.lo libnet_la-inet_lnaof.lo \ + libnet_la-inet_makeaddr.lo libnet_la-inet_net_ntop.lo \ + libnet_la-inet_net_pton.lo libnet_la-inet_neta.lo \ + libnet_la-inet_netof.lo libnet_la-inet_network.lo \ libnet_la-inet_ntoa.lo libnet_la-inet_ntop.lo \ - libnet_la-inet_pton.lo libnet_la-issetugid-stub.lo \ - libnet_la-key-lookup.lo libnet_la-netgrp-lookup.lo \ - libnet_la-network-lookup.lo libnet_la-nsswitch.lo \ - libnet_la-ns_name.lo libnet_la-ns_netint.lo \ + libnet_la-inet_pton.lo libnet_la-innetgr-stub.lo \ + libnet_la-ip6opt.lo libnet_la-issetugid-stub.lo \ + libnet_la-linkaddr.lo libnet_la-map_v4v6.lo libnet_la-name6.lo \ + libnet_la-ns_addr.lo libnet_la-ns_name.lo \ + libnet_la-ns_netint.lo libnet_la-ns_ntoa.lo \ libnet_la-ns_parse.lo libnet_la-ns_print.lo \ - libnet_la-ns_samedomain.lo libnet_la-ns_ttl.lo \ - libnet_la-nsap_addr.lo libnet_la-proto-lookup.lo \ - libnet_la-opensock.lo libnet_la-pwd-lookup.lo \ - libnet_la-recv.lo libnet_la-res_comp.lo libnet_la-res_data.lo \ - libnet_la-res_debug.lo libnet_la-res_hconf.lo \ - libnet_la-res_init.lo libnet_la-res_libc.lo \ - libnet_la-res_mkquery.lo libnet_la-res_query.lo \ - libnet_la-res_send.lo libnet_la-rexec.lo \ - libnet_la-rpc-lookup.lo libnet_la-ruserpass.lo \ - libnet_la-send.lo libnet_la-service-lookup.lo \ - libnet_la-spwd-lookup.lo -am__objects_5 = libnet_la-ifname.lo -@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = $(am__objects_5) + libnet_la-ns_ttl.lo libnet_la-nsdispatch.lo \ + libnet_la-nslexer.lo libnet_la-nsparser.lo \ + libnet_la-nsap_addr.lo libnet_la-res_comp.lo \ + libnet_la-res_data.lo libnet_la-res_debug.lo \ + libnet_la-res_init.lo libnet_la-res_mkquery.lo \ + libnet_la-res_mkupdate.lo libnet_la-res_query.lo \ + libnet_la-res_send.lo libnet_la-res_update.lo \ + libnet_la-rthdr.lo libnet_la-vars.lo @USE_LIBTOOL_TRUE@am_libnet_la_OBJECTS = $(am__objects_4) \ -@USE_LIBTOOL_TRUE@ $(am__objects_6) +@USE_LIBTOOL_TRUE@ $(am__objects_3) libnet_la_OBJECTS = $(am_libnet_la_OBJECTS) @USE_LIBTOOL_TRUE@am_libnet_la_rpath = DEFAULT_INCLUDES = -I. -I$(srcdir) @@ -321,37 +277,27 @@ sys_dir = @sys_dir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ AUTOMAKE_OPTIONS = cygnus -INCLUDES = -I$(srcdir)/../include -I$(srcdir)/.. $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -GENERAL_SOURCES = addr2ascii.c ascii2addr.c alias-lookup.c \ - base64.c check_pf.c digits_dots.c \ - ether_aton.c ether_aton_r.c ether_hton.c \ - ether_line.c ether_ntoa.c ether_ntoa_r.c ether_ntoh.c \ - ethers-lookup.c getaddrinfo.c getaliasent.c \ - getaliasent_r.c getaliasname.c getaliasname_r.c gethstbyad.c \ - gethstbyad_r.c gethstbynm2.c gethstbynm2_r.c gethstbynm.c \ - gethstbynm_r.c gethstent.c gethstent_r.c getnameinfo.c getnetbyad.c \ - getnetbyad_r.c getnetbynm.c getnetbynm_r.c getnetent.c getnetent_r.c \ - getnetgrent.c getnetgrent_r.c getnssent.c getnssent_r.c getproto.c \ - getproto_r.c getprtent.c \ - getprtent_r.c getprtname.c getprtname_r.c getrpcbyname.c \ - getrpcbyname_r.c getrpcbynumber.c getrpcbynumber_r.c getrpcent.c \ - getrpcent_r.c getservent.c getservent_r.c getsrvbynm.c getsrvbynm_r.c \ - getsrvbypt.c getsrvbypt_r.c grp-lookup.c \ - herrno.c hosts-lookup.c ifreq.c \ - in6_addr.c inet6_option.c inet_addr.c \ - inet_lnaof.c inet_mkadr.c inet_net.c inet_neta.c inet_netof.c \ - inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c \ - inet_pton.c issetugid-stub.c key-lookup.c netgrp-lookup.c \ - network-lookup.c nsswitch.c \ - ns_name.c ns_netint.c ns_parse.c ns_print.c ns_samedomain.c \ - ns_ttl.c nsap_addr.c proto-lookup.c opensock.c pwd-lookup.c recv.c \ - res_comp.c res_data.c res_debug.c res_hconf.c res_init.c \ - res_libc.c res_mkquery.c \ - res_query.c res_send.c \ - rexec.c rpc-lookup.c ruserpass.c send.c service-lookup.c spwd-lookup.c +INCLUDES = -I$(srcdir)/../include $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) +GENERAL_SOURCES = addr2ascii.c ascii2addr.c base64.c bindresvport.c ether_addr.c getaddrinfo.c \ + gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ + getifaddrs.c getnameinfo.c \ + getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ + getproto.c getprotoent.c getprotoname.c getservbyname.c \ + getservbyport.c getservent.c herror.c hesiod.c inet_addr.c \ + ifname.c inet_lnaof.c \ + inet_makeaddr.c inet_net_ntop.c inet_net_pton.c inet_neta.c \ + inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \ + inet_pton.c innetgr-stub.c ip6opt.c issetugid-stub.c \ + linkaddr.c map_v4v6.c namespace.h un-namespace.h \ + name6.c ns_addr.c \ + ns_name.c ns_netint.c \ + ns_ntoa.c ns_parse.c ns_print.c ns_ttl.c \ + nsdispatch.c nslexer.c nsparser.c nsparser.h \ + nsap_addr.c res_comp.c res_data.c res_debug.c \ + res_init.c res_mkquery.c res_mkupdate.c res_query.c \ + res_send.c res_update.c rthdr.c vars.c ELIX_4_SOURCES = \ - ifname.c \ rcmd.$(oext) \ rcmdsh.$(oext) @@ -447,77 +393,23 @@ lib_a-ascii2addr.o: ascii2addr.c lib_a-ascii2addr.obj: ascii2addr.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ascii2addr.obj `if test -f 'ascii2addr.c'; then $(CYGPATH_W) 'ascii2addr.c'; else $(CYGPATH_W) '$(srcdir)/ascii2addr.c'; fi` -lib_a-alias-lookup.o: alias-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-alias-lookup.o `test -f 'alias-lookup.c' || echo '$(srcdir)/'`alias-lookup.c - -lib_a-alias-lookup.obj: alias-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-alias-lookup.obj `if test -f 'alias-lookup.c'; then $(CYGPATH_W) 'alias-lookup.c'; else $(CYGPATH_W) '$(srcdir)/alias-lookup.c'; fi` - lib_a-base64.o: base64.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-base64.o `test -f 'base64.c' || echo '$(srcdir)/'`base64.c lib_a-base64.obj: base64.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-base64.obj `if test -f 'base64.c'; then $(CYGPATH_W) 'base64.c'; else $(CYGPATH_W) '$(srcdir)/base64.c'; fi` -lib_a-check_pf.o: check_pf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-check_pf.o `test -f 'check_pf.c' || echo '$(srcdir)/'`check_pf.c - -lib_a-check_pf.obj: check_pf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-check_pf.obj `if test -f 'check_pf.c'; then $(CYGPATH_W) 'check_pf.c'; else $(CYGPATH_W) '$(srcdir)/check_pf.c'; fi` - -lib_a-digits_dots.o: digits_dots.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-digits_dots.o `test -f 'digits_dots.c' || echo '$(srcdir)/'`digits_dots.c - -lib_a-digits_dots.obj: digits_dots.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-digits_dots.obj `if test -f 'digits_dots.c'; then $(CYGPATH_W) 'digits_dots.c'; else $(CYGPATH_W) '$(srcdir)/digits_dots.c'; fi` - -lib_a-ether_aton.o: ether_aton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton.o `test -f 'ether_aton.c' || echo '$(srcdir)/'`ether_aton.c - -lib_a-ether_aton.obj: ether_aton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton.obj `if test -f 'ether_aton.c'; then $(CYGPATH_W) 'ether_aton.c'; else $(CYGPATH_W) '$(srcdir)/ether_aton.c'; fi` - -lib_a-ether_aton_r.o: ether_aton_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton_r.o `test -f 'ether_aton_r.c' || echo '$(srcdir)/'`ether_aton_r.c - -lib_a-ether_aton_r.obj: ether_aton_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_aton_r.obj `if test -f 'ether_aton_r.c'; then $(CYGPATH_W) 'ether_aton_r.c'; else $(CYGPATH_W) '$(srcdir)/ether_aton_r.c'; fi` - -lib_a-ether_hton.o: ether_hton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_hton.o `test -f 'ether_hton.c' || echo '$(srcdir)/'`ether_hton.c - -lib_a-ether_hton.obj: ether_hton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_hton.obj `if test -f 'ether_hton.c'; then $(CYGPATH_W) 'ether_hton.c'; else $(CYGPATH_W) '$(srcdir)/ether_hton.c'; fi` - -lib_a-ether_line.o: ether_line.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_line.o `test -f 'ether_line.c' || echo '$(srcdir)/'`ether_line.c - -lib_a-ether_line.obj: ether_line.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_line.obj `if test -f 'ether_line.c'; then $(CYGPATH_W) 'ether_line.c'; else $(CYGPATH_W) '$(srcdir)/ether_line.c'; fi` +lib_a-bindresvport.o: bindresvport.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bindresvport.o `test -f 'bindresvport.c' || echo '$(srcdir)/'`bindresvport.c -lib_a-ether_ntoa.o: ether_ntoa.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa.o `test -f 'ether_ntoa.c' || echo '$(srcdir)/'`ether_ntoa.c +lib_a-bindresvport.obj: bindresvport.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bindresvport.obj `if test -f 'bindresvport.c'; then $(CYGPATH_W) 'bindresvport.c'; else $(CYGPATH_W) '$(srcdir)/bindresvport.c'; fi` -lib_a-ether_ntoa.obj: ether_ntoa.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa.obj `if test -f 'ether_ntoa.c'; then $(CYGPATH_W) 'ether_ntoa.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoa.c'; fi` +lib_a-ether_addr.o: ether_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_addr.o `test -f 'ether_addr.c' || echo '$(srcdir)/'`ether_addr.c -lib_a-ether_ntoa_r.o: ether_ntoa_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa_r.o `test -f 'ether_ntoa_r.c' || echo '$(srcdir)/'`ether_ntoa_r.c - -lib_a-ether_ntoa_r.obj: ether_ntoa_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoa_r.obj `if test -f 'ether_ntoa_r.c'; then $(CYGPATH_W) 'ether_ntoa_r.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoa_r.c'; fi` - -lib_a-ether_ntoh.o: ether_ntoh.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoh.o `test -f 'ether_ntoh.c' || echo '$(srcdir)/'`ether_ntoh.c - -lib_a-ether_ntoh.obj: ether_ntoh.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_ntoh.obj `if test -f 'ether_ntoh.c'; then $(CYGPATH_W) 'ether_ntoh.c'; else $(CYGPATH_W) '$(srcdir)/ether_ntoh.c'; fi` - -lib_a-ethers-lookup.o: ethers-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ethers-lookup.o `test -f 'ethers-lookup.c' || echo '$(srcdir)/'`ethers-lookup.c - -lib_a-ethers-lookup.obj: ethers-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ethers-lookup.obj `if test -f 'ethers-lookup.c'; then $(CYGPATH_W) 'ethers-lookup.c'; else $(CYGPATH_W) '$(srcdir)/ethers-lookup.c'; fi` +lib_a-ether_addr.obj: ether_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ether_addr.obj `if test -f 'ether_addr.c'; then $(CYGPATH_W) 'ether_addr.c'; else $(CYGPATH_W) '$(srcdir)/ether_addr.c'; fi` lib_a-getaddrinfo.o: getaddrinfo.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaddrinfo.o `test -f 'getaddrinfo.c' || echo '$(srcdir)/'`getaddrinfo.c @@ -525,77 +417,35 @@ lib_a-getaddrinfo.o: getaddrinfo.c lib_a-getaddrinfo.obj: getaddrinfo.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaddrinfo.obj `if test -f 'getaddrinfo.c'; then $(CYGPATH_W) 'getaddrinfo.c'; else $(CYGPATH_W) '$(srcdir)/getaddrinfo.c'; fi` -lib_a-getaliasent.o: getaliasent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent.o `test -f 'getaliasent.c' || echo '$(srcdir)/'`getaliasent.c - -lib_a-getaliasent.obj: getaliasent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent.obj `if test -f 'getaliasent.c'; then $(CYGPATH_W) 'getaliasent.c'; else $(CYGPATH_W) '$(srcdir)/getaliasent.c'; fi` - -lib_a-getaliasent_r.o: getaliasent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent_r.o `test -f 'getaliasent_r.c' || echo '$(srcdir)/'`getaliasent_r.c - -lib_a-getaliasent_r.obj: getaliasent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasent_r.obj `if test -f 'getaliasent_r.c'; then $(CYGPATH_W) 'getaliasent_r.c'; else $(CYGPATH_W) '$(srcdir)/getaliasent_r.c'; fi` - -lib_a-getaliasname.o: getaliasname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname.o `test -f 'getaliasname.c' || echo '$(srcdir)/'`getaliasname.c - -lib_a-getaliasname.obj: getaliasname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname.obj `if test -f 'getaliasname.c'; then $(CYGPATH_W) 'getaliasname.c'; else $(CYGPATH_W) '$(srcdir)/getaliasname.c'; fi` - -lib_a-getaliasname_r.o: getaliasname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname_r.o `test -f 'getaliasname_r.c' || echo '$(srcdir)/'`getaliasname_r.c - -lib_a-getaliasname_r.obj: getaliasname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getaliasname_r.obj `if test -f 'getaliasname_r.c'; then $(CYGPATH_W) 'getaliasname_r.c'; else $(CYGPATH_W) '$(srcdir)/getaliasname_r.c'; fi` - -lib_a-gethstbyad.o: gethstbyad.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad.o `test -f 'gethstbyad.c' || echo '$(srcdir)/'`gethstbyad.c +lib_a-gethostbydns.o: gethostbydns.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbydns.o `test -f 'gethostbydns.c' || echo '$(srcdir)/'`gethostbydns.c -lib_a-gethstbyad.obj: gethstbyad.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad.obj `if test -f 'gethstbyad.c'; then $(CYGPATH_W) 'gethstbyad.c'; else $(CYGPATH_W) '$(srcdir)/gethstbyad.c'; fi` +lib_a-gethostbydns.obj: gethostbydns.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbydns.obj `if test -f 'gethostbydns.c'; then $(CYGPATH_W) 'gethostbydns.c'; else $(CYGPATH_W) '$(srcdir)/gethostbydns.c'; fi` -lib_a-gethstbyad_r.o: gethstbyad_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad_r.o `test -f 'gethstbyad_r.c' || echo '$(srcdir)/'`gethstbyad_r.c +lib_a-gethostbyht.o: gethostbyht.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbyht.o `test -f 'gethostbyht.c' || echo '$(srcdir)/'`gethostbyht.c -lib_a-gethstbyad_r.obj: gethstbyad_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbyad_r.obj `if test -f 'gethstbyad_r.c'; then $(CYGPATH_W) 'gethstbyad_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbyad_r.c'; fi` +lib_a-gethostbyht.obj: gethostbyht.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbyht.obj `if test -f 'gethostbyht.c'; then $(CYGPATH_W) 'gethostbyht.c'; else $(CYGPATH_W) '$(srcdir)/gethostbyht.c'; fi` -lib_a-gethstbynm2.o: gethstbynm2.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2.o `test -f 'gethstbynm2.c' || echo '$(srcdir)/'`gethstbynm2.c +lib_a-gethostbynis.o: gethostbynis.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbynis.o `test -f 'gethostbynis.c' || echo '$(srcdir)/'`gethostbynis.c -lib_a-gethstbynm2.obj: gethstbynm2.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2.obj `if test -f 'gethstbynm2.c'; then $(CYGPATH_W) 'gethstbynm2.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm2.c'; fi` +lib_a-gethostbynis.obj: gethostbynis.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostbynis.obj `if test -f 'gethostbynis.c'; then $(CYGPATH_W) 'gethostbynis.c'; else $(CYGPATH_W) '$(srcdir)/gethostbynis.c'; fi` -lib_a-gethstbynm2_r.o: gethstbynm2_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2_r.o `test -f 'gethstbynm2_r.c' || echo '$(srcdir)/'`gethstbynm2_r.c +lib_a-gethostnamadr.o: gethostnamadr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostnamadr.o `test -f 'gethostnamadr.c' || echo '$(srcdir)/'`gethostnamadr.c -lib_a-gethstbynm2_r.obj: gethstbynm2_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm2_r.obj `if test -f 'gethstbynm2_r.c'; then $(CYGPATH_W) 'gethstbynm2_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm2_r.c'; fi` +lib_a-gethostnamadr.obj: gethostnamadr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethostnamadr.obj `if test -f 'gethostnamadr.c'; then $(CYGPATH_W) 'gethostnamadr.c'; else $(CYGPATH_W) '$(srcdir)/gethostnamadr.c'; fi` -lib_a-gethstbynm.o: gethstbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm.o `test -f 'gethstbynm.c' || echo '$(srcdir)/'`gethstbynm.c +lib_a-getifaddrs.o: getifaddrs.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getifaddrs.o `test -f 'getifaddrs.c' || echo '$(srcdir)/'`getifaddrs.c -lib_a-gethstbynm.obj: gethstbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm.obj `if test -f 'gethstbynm.c'; then $(CYGPATH_W) 'gethstbynm.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm.c'; fi` - -lib_a-gethstbynm_r.o: gethstbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm_r.o `test -f 'gethstbynm_r.c' || echo '$(srcdir)/'`gethstbynm_r.c - -lib_a-gethstbynm_r.obj: gethstbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstbynm_r.obj `if test -f 'gethstbynm_r.c'; then $(CYGPATH_W) 'gethstbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstbynm_r.c'; fi` - -lib_a-gethstent.o: gethstent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent.o `test -f 'gethstent.c' || echo '$(srcdir)/'`gethstent.c - -lib_a-gethstent.obj: gethstent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent.obj `if test -f 'gethstent.c'; then $(CYGPATH_W) 'gethstent.c'; else $(CYGPATH_W) '$(srcdir)/gethstent.c'; fi` - -lib_a-gethstent_r.o: gethstent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent_r.o `test -f 'gethstent_r.c' || echo '$(srcdir)/'`gethstent_r.c - -lib_a-gethstent_r.obj: gethstent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gethstent_r.obj `if test -f 'gethstent_r.c'; then $(CYGPATH_W) 'gethstent_r.c'; else $(CYGPATH_W) '$(srcdir)/gethstent_r.c'; fi` +lib_a-getifaddrs.obj: getifaddrs.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getifaddrs.obj `if test -f 'getifaddrs.c'; then $(CYGPATH_W) 'getifaddrs.c'; else $(CYGPATH_W) '$(srcdir)/getifaddrs.c'; fi` lib_a-getnameinfo.o: getnameinfo.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnameinfo.o `test -f 'getnameinfo.c' || echo '$(srcdir)/'`getnameinfo.c @@ -603,65 +453,29 @@ lib_a-getnameinfo.o: getnameinfo.c lib_a-getnameinfo.obj: getnameinfo.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnameinfo.obj `if test -f 'getnameinfo.c'; then $(CYGPATH_W) 'getnameinfo.c'; else $(CYGPATH_W) '$(srcdir)/getnameinfo.c'; fi` -lib_a-getnetbyad.o: getnetbyad.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad.o `test -f 'getnetbyad.c' || echo '$(srcdir)/'`getnetbyad.c - -lib_a-getnetbyad.obj: getnetbyad.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad.obj `if test -f 'getnetbyad.c'; then $(CYGPATH_W) 'getnetbyad.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyad.c'; fi` - -lib_a-getnetbyad_r.o: getnetbyad_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad_r.o `test -f 'getnetbyad_r.c' || echo '$(srcdir)/'`getnetbyad_r.c - -lib_a-getnetbyad_r.obj: getnetbyad_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyad_r.obj `if test -f 'getnetbyad_r.c'; then $(CYGPATH_W) 'getnetbyad_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyad_r.c'; fi` - -lib_a-getnetbynm.o: getnetbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm.o `test -f 'getnetbynm.c' || echo '$(srcdir)/'`getnetbynm.c - -lib_a-getnetbynm.obj: getnetbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm.obj `if test -f 'getnetbynm.c'; then $(CYGPATH_W) 'getnetbynm.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynm.c'; fi` - -lib_a-getnetbynm_r.o: getnetbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm_r.o `test -f 'getnetbynm_r.c' || echo '$(srcdir)/'`getnetbynm_r.c - -lib_a-getnetbynm_r.obj: getnetbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynm_r.obj `if test -f 'getnetbynm_r.c'; then $(CYGPATH_W) 'getnetbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynm_r.c'; fi` +lib_a-getnetbydns.o: getnetbydns.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbydns.o `test -f 'getnetbydns.c' || echo '$(srcdir)/'`getnetbydns.c -lib_a-getnetent.o: getnetent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent.o `test -f 'getnetent.c' || echo '$(srcdir)/'`getnetent.c +lib_a-getnetbydns.obj: getnetbydns.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbydns.obj `if test -f 'getnetbydns.c'; then $(CYGPATH_W) 'getnetbydns.c'; else $(CYGPATH_W) '$(srcdir)/getnetbydns.c'; fi` -lib_a-getnetent.obj: getnetent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent.obj `if test -f 'getnetent.c'; then $(CYGPATH_W) 'getnetent.c'; else $(CYGPATH_W) '$(srcdir)/getnetent.c'; fi` +lib_a-getnetbyht.o: getnetbyht.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyht.o `test -f 'getnetbyht.c' || echo '$(srcdir)/'`getnetbyht.c -lib_a-getnetent_r.o: getnetent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent_r.o `test -f 'getnetent_r.c' || echo '$(srcdir)/'`getnetent_r.c +lib_a-getnetbyht.obj: getnetbyht.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbyht.obj `if test -f 'getnetbyht.c'; then $(CYGPATH_W) 'getnetbyht.c'; else $(CYGPATH_W) '$(srcdir)/getnetbyht.c'; fi` -lib_a-getnetent_r.obj: getnetent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetent_r.obj `if test -f 'getnetent_r.c'; then $(CYGPATH_W) 'getnetent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetent_r.c'; fi` +lib_a-getnetbynis.o: getnetbynis.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynis.o `test -f 'getnetbynis.c' || echo '$(srcdir)/'`getnetbynis.c -lib_a-getnetgrent.o: getnetgrent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent.o `test -f 'getnetgrent.c' || echo '$(srcdir)/'`getnetgrent.c +lib_a-getnetbynis.obj: getnetbynis.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetbynis.obj `if test -f 'getnetbynis.c'; then $(CYGPATH_W) 'getnetbynis.c'; else $(CYGPATH_W) '$(srcdir)/getnetbynis.c'; fi` -lib_a-getnetgrent.obj: getnetgrent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent.obj `if test -f 'getnetgrent.c'; then $(CYGPATH_W) 'getnetgrent.c'; else $(CYGPATH_W) '$(srcdir)/getnetgrent.c'; fi` +lib_a-getnetnamadr.o: getnetnamadr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetnamadr.o `test -f 'getnetnamadr.c' || echo '$(srcdir)/'`getnetnamadr.c -lib_a-getnetgrent_r.o: getnetgrent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent_r.o `test -f 'getnetgrent_r.c' || echo '$(srcdir)/'`getnetgrent_r.c - -lib_a-getnetgrent_r.obj: getnetgrent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetgrent_r.obj `if test -f 'getnetgrent_r.c'; then $(CYGPATH_W) 'getnetgrent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnetgrent_r.c'; fi` - -lib_a-getnssent.o: getnssent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent.o `test -f 'getnssent.c' || echo '$(srcdir)/'`getnssent.c - -lib_a-getnssent.obj: getnssent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent.obj `if test -f 'getnssent.c'; then $(CYGPATH_W) 'getnssent.c'; else $(CYGPATH_W) '$(srcdir)/getnssent.c'; fi` - -lib_a-getnssent_r.o: getnssent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent_r.o `test -f 'getnssent_r.c' || echo '$(srcdir)/'`getnssent_r.c - -lib_a-getnssent_r.obj: getnssent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnssent_r.obj `if test -f 'getnssent_r.c'; then $(CYGPATH_W) 'getnssent_r.c'; else $(CYGPATH_W) '$(srcdir)/getnssent_r.c'; fi` +lib_a-getnetnamadr.obj: getnetnamadr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getnetnamadr.obj `if test -f 'getnetnamadr.c'; then $(CYGPATH_W) 'getnetnamadr.c'; else $(CYGPATH_W) '$(srcdir)/getnetnamadr.c'; fi` lib_a-getproto.o: getproto.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto.o `test -f 'getproto.c' || echo '$(srcdir)/'`getproto.c @@ -669,71 +483,29 @@ lib_a-getproto.o: getproto.c lib_a-getproto.obj: getproto.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto.obj `if test -f 'getproto.c'; then $(CYGPATH_W) 'getproto.c'; else $(CYGPATH_W) '$(srcdir)/getproto.c'; fi` -lib_a-getproto_r.o: getproto_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto_r.o `test -f 'getproto_r.c' || echo '$(srcdir)/'`getproto_r.c - -lib_a-getproto_r.obj: getproto_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getproto_r.obj `if test -f 'getproto_r.c'; then $(CYGPATH_W) 'getproto_r.c'; else $(CYGPATH_W) '$(srcdir)/getproto_r.c'; fi` - -lib_a-getprtent.o: getprtent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent.o `test -f 'getprtent.c' || echo '$(srcdir)/'`getprtent.c - -lib_a-getprtent.obj: getprtent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent.obj `if test -f 'getprtent.c'; then $(CYGPATH_W) 'getprtent.c'; else $(CYGPATH_W) '$(srcdir)/getprtent.c'; fi` - -lib_a-getprtent_r.o: getprtent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent_r.o `test -f 'getprtent_r.c' || echo '$(srcdir)/'`getprtent_r.c - -lib_a-getprtent_r.obj: getprtent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtent_r.obj `if test -f 'getprtent_r.c'; then $(CYGPATH_W) 'getprtent_r.c'; else $(CYGPATH_W) '$(srcdir)/getprtent_r.c'; fi` - -lib_a-getprtname.o: getprtname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname.o `test -f 'getprtname.c' || echo '$(srcdir)/'`getprtname.c - -lib_a-getprtname.obj: getprtname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname.obj `if test -f 'getprtname.c'; then $(CYGPATH_W) 'getprtname.c'; else $(CYGPATH_W) '$(srcdir)/getprtname.c'; fi` - -lib_a-getprtname_r.o: getprtname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname_r.o `test -f 'getprtname_r.c' || echo '$(srcdir)/'`getprtname_r.c +lib_a-getprotoent.o: getprotoent.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoent.o `test -f 'getprotoent.c' || echo '$(srcdir)/'`getprotoent.c -lib_a-getprtname_r.obj: getprtname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprtname_r.obj `if test -f 'getprtname_r.c'; then $(CYGPATH_W) 'getprtname_r.c'; else $(CYGPATH_W) '$(srcdir)/getprtname_r.c'; fi` +lib_a-getprotoent.obj: getprotoent.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoent.obj `if test -f 'getprotoent.c'; then $(CYGPATH_W) 'getprotoent.c'; else $(CYGPATH_W) '$(srcdir)/getprotoent.c'; fi` -lib_a-getrpcbyname.o: getrpcbyname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname.o `test -f 'getrpcbyname.c' || echo '$(srcdir)/'`getrpcbyname.c +lib_a-getprotoname.o: getprotoname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoname.o `test -f 'getprotoname.c' || echo '$(srcdir)/'`getprotoname.c -lib_a-getrpcbyname.obj: getrpcbyname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname.obj `if test -f 'getrpcbyname.c'; then $(CYGPATH_W) 'getrpcbyname.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbyname.c'; fi` +lib_a-getprotoname.obj: getprotoname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getprotoname.obj `if test -f 'getprotoname.c'; then $(CYGPATH_W) 'getprotoname.c'; else $(CYGPATH_W) '$(srcdir)/getprotoname.c'; fi` -lib_a-getrpcbyname_r.o: getrpcbyname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname_r.o `test -f 'getrpcbyname_r.c' || echo '$(srcdir)/'`getrpcbyname_r.c +lib_a-getservbyname.o: getservbyname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyname.o `test -f 'getservbyname.c' || echo '$(srcdir)/'`getservbyname.c -lib_a-getrpcbyname_r.obj: getrpcbyname_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbyname_r.obj `if test -f 'getrpcbyname_r.c'; then $(CYGPATH_W) 'getrpcbyname_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbyname_r.c'; fi` +lib_a-getservbyname.obj: getservbyname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyname.obj `if test -f 'getservbyname.c'; then $(CYGPATH_W) 'getservbyname.c'; else $(CYGPATH_W) '$(srcdir)/getservbyname.c'; fi` -lib_a-getrpcbynumber.o: getrpcbynumber.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber.o `test -f 'getrpcbynumber.c' || echo '$(srcdir)/'`getrpcbynumber.c +lib_a-getservbyport.o: getservbyport.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyport.o `test -f 'getservbyport.c' || echo '$(srcdir)/'`getservbyport.c -lib_a-getrpcbynumber.obj: getrpcbynumber.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber.obj `if test -f 'getrpcbynumber.c'; then $(CYGPATH_W) 'getrpcbynumber.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbynumber.c'; fi` - -lib_a-getrpcbynumber_r.o: getrpcbynumber_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber_r.o `test -f 'getrpcbynumber_r.c' || echo '$(srcdir)/'`getrpcbynumber_r.c - -lib_a-getrpcbynumber_r.obj: getrpcbynumber_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcbynumber_r.obj `if test -f 'getrpcbynumber_r.c'; then $(CYGPATH_W) 'getrpcbynumber_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcbynumber_r.c'; fi` - -lib_a-getrpcent.o: getrpcent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent.o `test -f 'getrpcent.c' || echo '$(srcdir)/'`getrpcent.c - -lib_a-getrpcent.obj: getrpcent.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent.obj `if test -f 'getrpcent.c'; then $(CYGPATH_W) 'getrpcent.c'; else $(CYGPATH_W) '$(srcdir)/getrpcent.c'; fi` - -lib_a-getrpcent_r.o: getrpcent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent_r.o `test -f 'getrpcent_r.c' || echo '$(srcdir)/'`getrpcent_r.c - -lib_a-getrpcent_r.obj: getrpcent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrpcent_r.obj `if test -f 'getrpcent_r.c'; then $(CYGPATH_W) 'getrpcent_r.c'; else $(CYGPATH_W) '$(srcdir)/getrpcent_r.c'; fi` +lib_a-getservbyport.obj: getservbyport.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservbyport.obj `if test -f 'getservbyport.c'; then $(CYGPATH_W) 'getservbyport.c'; else $(CYGPATH_W) '$(srcdir)/getservbyport.c'; fi` lib_a-getservent.o: getservent.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent.o `test -f 'getservent.c' || echo '$(srcdir)/'`getservent.c @@ -741,71 +513,17 @@ lib_a-getservent.o: getservent.c lib_a-getservent.obj: getservent.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent.obj `if test -f 'getservent.c'; then $(CYGPATH_W) 'getservent.c'; else $(CYGPATH_W) '$(srcdir)/getservent.c'; fi` -lib_a-getservent_r.o: getservent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent_r.o `test -f 'getservent_r.c' || echo '$(srcdir)/'`getservent_r.c - -lib_a-getservent_r.obj: getservent_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getservent_r.obj `if test -f 'getservent_r.c'; then $(CYGPATH_W) 'getservent_r.c'; else $(CYGPATH_W) '$(srcdir)/getservent_r.c'; fi` - -lib_a-getsrvbynm.o: getsrvbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm.o `test -f 'getsrvbynm.c' || echo '$(srcdir)/'`getsrvbynm.c - -lib_a-getsrvbynm.obj: getsrvbynm.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm.obj `if test -f 'getsrvbynm.c'; then $(CYGPATH_W) 'getsrvbynm.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbynm.c'; fi` - -lib_a-getsrvbynm_r.o: getsrvbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm_r.o `test -f 'getsrvbynm_r.c' || echo '$(srcdir)/'`getsrvbynm_r.c - -lib_a-getsrvbynm_r.obj: getsrvbynm_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbynm_r.obj `if test -f 'getsrvbynm_r.c'; then $(CYGPATH_W) 'getsrvbynm_r.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbynm_r.c'; fi` - -lib_a-getsrvbypt.o: getsrvbypt.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt.o `test -f 'getsrvbypt.c' || echo '$(srcdir)/'`getsrvbypt.c - -lib_a-getsrvbypt.obj: getsrvbypt.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt.obj `if test -f 'getsrvbypt.c'; then $(CYGPATH_W) 'getsrvbypt.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbypt.c'; fi` +lib_a-herror.o: herror.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herror.o `test -f 'herror.c' || echo '$(srcdir)/'`herror.c -lib_a-getsrvbypt_r.o: getsrvbypt_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt_r.o `test -f 'getsrvbypt_r.c' || echo '$(srcdir)/'`getsrvbypt_r.c +lib_a-herror.obj: herror.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herror.obj `if test -f 'herror.c'; then $(CYGPATH_W) 'herror.c'; else $(CYGPATH_W) '$(srcdir)/herror.c'; fi` -lib_a-getsrvbypt_r.obj: getsrvbypt_r.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getsrvbypt_r.obj `if test -f 'getsrvbypt_r.c'; then $(CYGPATH_W) 'getsrvbypt_r.c'; else $(CYGPATH_W) '$(srcdir)/getsrvbypt_r.c'; fi` +lib_a-hesiod.o: hesiod.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hesiod.o `test -f 'hesiod.c' || echo '$(srcdir)/'`hesiod.c -lib_a-grp-lookup.o: grp-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-grp-lookup.o `test -f 'grp-lookup.c' || echo '$(srcdir)/'`grp-lookup.c - -lib_a-grp-lookup.obj: grp-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-grp-lookup.obj `if test -f 'grp-lookup.c'; then $(CYGPATH_W) 'grp-lookup.c'; else $(CYGPATH_W) '$(srcdir)/grp-lookup.c'; fi` - -lib_a-herrno.o: herrno.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herrno.o `test -f 'herrno.c' || echo '$(srcdir)/'`herrno.c - -lib_a-herrno.obj: herrno.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-herrno.obj `if test -f 'herrno.c'; then $(CYGPATH_W) 'herrno.c'; else $(CYGPATH_W) '$(srcdir)/herrno.c'; fi` - -lib_a-hosts-lookup.o: hosts-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hosts-lookup.o `test -f 'hosts-lookup.c' || echo '$(srcdir)/'`hosts-lookup.c - -lib_a-hosts-lookup.obj: hosts-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hosts-lookup.obj `if test -f 'hosts-lookup.c'; then $(CYGPATH_W) 'hosts-lookup.c'; else $(CYGPATH_W) '$(srcdir)/hosts-lookup.c'; fi` - -lib_a-ifreq.o: ifreq.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifreq.o `test -f 'ifreq.c' || echo '$(srcdir)/'`ifreq.c - -lib_a-ifreq.obj: ifreq.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifreq.obj `if test -f 'ifreq.c'; then $(CYGPATH_W) 'ifreq.c'; else $(CYGPATH_W) '$(srcdir)/ifreq.c'; fi` - -lib_a-in6_addr.o: in6_addr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-in6_addr.o `test -f 'in6_addr.c' || echo '$(srcdir)/'`in6_addr.c - -lib_a-in6_addr.obj: in6_addr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-in6_addr.obj `if test -f 'in6_addr.c'; then $(CYGPATH_W) 'in6_addr.c'; else $(CYGPATH_W) '$(srcdir)/in6_addr.c'; fi` - -lib_a-inet6_option.o: inet6_option.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet6_option.o `test -f 'inet6_option.c' || echo '$(srcdir)/'`inet6_option.c - -lib_a-inet6_option.obj: inet6_option.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet6_option.obj `if test -f 'inet6_option.c'; then $(CYGPATH_W) 'inet6_option.c'; else $(CYGPATH_W) '$(srcdir)/inet6_option.c'; fi` +lib_a-hesiod.obj: hesiod.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-hesiod.obj `if test -f 'hesiod.c'; then $(CYGPATH_W) 'hesiod.c'; else $(CYGPATH_W) '$(srcdir)/hesiod.c'; fi` lib_a-inet_addr.o: inet_addr.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_addr.o `test -f 'inet_addr.c' || echo '$(srcdir)/'`inet_addr.c @@ -813,23 +531,35 @@ lib_a-inet_addr.o: inet_addr.c lib_a-inet_addr.obj: inet_addr.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_addr.obj `if test -f 'inet_addr.c'; then $(CYGPATH_W) 'inet_addr.c'; else $(CYGPATH_W) '$(srcdir)/inet_addr.c'; fi` +lib_a-ifname.o: ifname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.o `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c + +lib_a-ifname.obj: ifname.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.obj `if test -f 'ifname.c'; then $(CYGPATH_W) 'ifname.c'; else $(CYGPATH_W) '$(srcdir)/ifname.c'; fi` + lib_a-inet_lnaof.o: inet_lnaof.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_lnaof.o `test -f 'inet_lnaof.c' || echo '$(srcdir)/'`inet_lnaof.c lib_a-inet_lnaof.obj: inet_lnaof.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_lnaof.obj `if test -f 'inet_lnaof.c'; then $(CYGPATH_W) 'inet_lnaof.c'; else $(CYGPATH_W) '$(srcdir)/inet_lnaof.c'; fi` -lib_a-inet_mkadr.o: inet_mkadr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_mkadr.o `test -f 'inet_mkadr.c' || echo '$(srcdir)/'`inet_mkadr.c +lib_a-inet_makeaddr.o: inet_makeaddr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_makeaddr.o `test -f 'inet_makeaddr.c' || echo '$(srcdir)/'`inet_makeaddr.c -lib_a-inet_mkadr.obj: inet_mkadr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_mkadr.obj `if test -f 'inet_mkadr.c'; then $(CYGPATH_W) 'inet_mkadr.c'; else $(CYGPATH_W) '$(srcdir)/inet_mkadr.c'; fi` +lib_a-inet_makeaddr.obj: inet_makeaddr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_makeaddr.obj `if test -f 'inet_makeaddr.c'; then $(CYGPATH_W) 'inet_makeaddr.c'; else $(CYGPATH_W) '$(srcdir)/inet_makeaddr.c'; fi` -lib_a-inet_net.o: inet_net.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net.o `test -f 'inet_net.c' || echo '$(srcdir)/'`inet_net.c +lib_a-inet_net_ntop.o: inet_net_ntop.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.o `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c -lib_a-inet_net.obj: inet_net.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net.obj `if test -f 'inet_net.c'; then $(CYGPATH_W) 'inet_net.c'; else $(CYGPATH_W) '$(srcdir)/inet_net.c'; fi` +lib_a-inet_net_ntop.obj: inet_net_ntop.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.obj `if test -f 'inet_net_ntop.c'; then $(CYGPATH_W) 'inet_net_ntop.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_ntop.c'; fi` + +lib_a-inet_net_pton.o: inet_net_pton.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.o `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c + +lib_a-inet_net_pton.obj: inet_net_pton.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.obj `if test -f 'inet_net_pton.c'; then $(CYGPATH_W) 'inet_net_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_pton.c'; fi` lib_a-inet_neta.o: inet_neta.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_neta.o `test -f 'inet_neta.c' || echo '$(srcdir)/'`inet_neta.c @@ -843,17 +573,11 @@ lib_a-inet_netof.o: inet_netof.c lib_a-inet_netof.obj: inet_netof.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_netof.obj `if test -f 'inet_netof.c'; then $(CYGPATH_W) 'inet_netof.c'; else $(CYGPATH_W) '$(srcdir)/inet_netof.c'; fi` -lib_a-inet_net_ntop.o: inet_net_ntop.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.o `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c +lib_a-inet_network.o: inet_network.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_network.o `test -f 'inet_network.c' || echo '$(srcdir)/'`inet_network.c -lib_a-inet_net_ntop.obj: inet_net_ntop.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_ntop.obj `if test -f 'inet_net_ntop.c'; then $(CYGPATH_W) 'inet_net_ntop.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_ntop.c'; fi` - -lib_a-inet_net_pton.o: inet_net_pton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.o `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c - -lib_a-inet_net_pton.obj: inet_net_pton.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_net_pton.obj `if test -f 'inet_net_pton.c'; then $(CYGPATH_W) 'inet_net_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_net_pton.c'; fi` +lib_a-inet_network.obj: inet_network.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_network.obj `if test -f 'inet_network.c'; then $(CYGPATH_W) 'inet_network.c'; else $(CYGPATH_W) '$(srcdir)/inet_network.c'; fi` lib_a-inet_ntoa.o: inet_ntoa.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_ntoa.o `test -f 'inet_ntoa.c' || echo '$(srcdir)/'`inet_ntoa.c @@ -873,35 +597,47 @@ lib_a-inet_pton.o: inet_pton.c lib_a-inet_pton.obj: inet_pton.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_pton.obj `if test -f 'inet_pton.c'; then $(CYGPATH_W) 'inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/inet_pton.c'; fi` +lib_a-innetgr-stub.o: innetgr-stub.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-innetgr-stub.o `test -f 'innetgr-stub.c' || echo '$(srcdir)/'`innetgr-stub.c + +lib_a-innetgr-stub.obj: innetgr-stub.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-innetgr-stub.obj `if test -f 'innetgr-stub.c'; then $(CYGPATH_W) 'innetgr-stub.c'; else $(CYGPATH_W) '$(srcdir)/innetgr-stub.c'; fi` + +lib_a-ip6opt.o: ip6opt.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ip6opt.o `test -f 'ip6opt.c' || echo '$(srcdir)/'`ip6opt.c + +lib_a-ip6opt.obj: ip6opt.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ip6opt.obj `if test -f 'ip6opt.c'; then $(CYGPATH_W) 'ip6opt.c'; else $(CYGPATH_W) '$(srcdir)/ip6opt.c'; fi` + lib_a-issetugid-stub.o: issetugid-stub.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-issetugid-stub.o `test -f 'issetugid-stub.c' || echo '$(srcdir)/'`issetugid-stub.c lib_a-issetugid-stub.obj: issetugid-stub.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-issetugid-stub.obj `if test -f 'issetugid-stub.c'; then $(CYGPATH_W) 'issetugid-stub.c'; else $(CYGPATH_W) '$(srcdir)/issetugid-stub.c'; fi` -lib_a-key-lookup.o: key-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-key-lookup.o `test -f 'key-lookup.c' || echo '$(srcdir)/'`key-lookup.c +lib_a-linkaddr.o: linkaddr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-linkaddr.o `test -f 'linkaddr.c' || echo '$(srcdir)/'`linkaddr.c -lib_a-key-lookup.obj: key-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-key-lookup.obj `if test -f 'key-lookup.c'; then $(CYGPATH_W) 'key-lookup.c'; else $(CYGPATH_W) '$(srcdir)/key-lookup.c'; fi` +lib_a-linkaddr.obj: linkaddr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-linkaddr.obj `if test -f 'linkaddr.c'; then $(CYGPATH_W) 'linkaddr.c'; else $(CYGPATH_W) '$(srcdir)/linkaddr.c'; fi` -lib_a-netgrp-lookup.o: netgrp-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-netgrp-lookup.o `test -f 'netgrp-lookup.c' || echo '$(srcdir)/'`netgrp-lookup.c +lib_a-map_v4v6.o: map_v4v6.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-map_v4v6.o `test -f 'map_v4v6.c' || echo '$(srcdir)/'`map_v4v6.c -lib_a-netgrp-lookup.obj: netgrp-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-netgrp-lookup.obj `if test -f 'netgrp-lookup.c'; then $(CYGPATH_W) 'netgrp-lookup.c'; else $(CYGPATH_W) '$(srcdir)/netgrp-lookup.c'; fi` +lib_a-map_v4v6.obj: map_v4v6.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-map_v4v6.obj `if test -f 'map_v4v6.c'; then $(CYGPATH_W) 'map_v4v6.c'; else $(CYGPATH_W) '$(srcdir)/map_v4v6.c'; fi` -lib_a-network-lookup.o: network-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-network-lookup.o `test -f 'network-lookup.c' || echo '$(srcdir)/'`network-lookup.c +lib_a-name6.o: name6.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-name6.o `test -f 'name6.c' || echo '$(srcdir)/'`name6.c -lib_a-network-lookup.obj: network-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-network-lookup.obj `if test -f 'network-lookup.c'; then $(CYGPATH_W) 'network-lookup.c'; else $(CYGPATH_W) '$(srcdir)/network-lookup.c'; fi` +lib_a-name6.obj: name6.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-name6.obj `if test -f 'name6.c'; then $(CYGPATH_W) 'name6.c'; else $(CYGPATH_W) '$(srcdir)/name6.c'; fi` -lib_a-nsswitch.o: nsswitch.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsswitch.o `test -f 'nsswitch.c' || echo '$(srcdir)/'`nsswitch.c +lib_a-ns_addr.o: ns_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_addr.o `test -f 'ns_addr.c' || echo '$(srcdir)/'`ns_addr.c -lib_a-nsswitch.obj: nsswitch.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsswitch.obj `if test -f 'nsswitch.c'; then $(CYGPATH_W) 'nsswitch.c'; else $(CYGPATH_W) '$(srcdir)/nsswitch.c'; fi` +lib_a-ns_addr.obj: ns_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_addr.obj `if test -f 'ns_addr.c'; then $(CYGPATH_W) 'ns_addr.c'; else $(CYGPATH_W) '$(srcdir)/ns_addr.c'; fi` lib_a-ns_name.o: ns_name.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_name.o `test -f 'ns_name.c' || echo '$(srcdir)/'`ns_name.c @@ -915,6 +651,12 @@ lib_a-ns_netint.o: ns_netint.c lib_a-ns_netint.obj: ns_netint.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_netint.obj `if test -f 'ns_netint.c'; then $(CYGPATH_W) 'ns_netint.c'; else $(CYGPATH_W) '$(srcdir)/ns_netint.c'; fi` +lib_a-ns_ntoa.o: ns_ntoa.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ntoa.o `test -f 'ns_ntoa.c' || echo '$(srcdir)/'`ns_ntoa.c + +lib_a-ns_ntoa.obj: ns_ntoa.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ntoa.obj `if test -f 'ns_ntoa.c'; then $(CYGPATH_W) 'ns_ntoa.c'; else $(CYGPATH_W) '$(srcdir)/ns_ntoa.c'; fi` + lib_a-ns_parse.o: ns_parse.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_parse.o `test -f 'ns_parse.c' || echo '$(srcdir)/'`ns_parse.c @@ -927,47 +669,35 @@ lib_a-ns_print.o: ns_print.c lib_a-ns_print.obj: ns_print.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_print.obj `if test -f 'ns_print.c'; then $(CYGPATH_W) 'ns_print.c'; else $(CYGPATH_W) '$(srcdir)/ns_print.c'; fi` -lib_a-ns_samedomain.o: ns_samedomain.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_samedomain.o `test -f 'ns_samedomain.c' || echo '$(srcdir)/'`ns_samedomain.c - -lib_a-ns_samedomain.obj: ns_samedomain.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_samedomain.obj `if test -f 'ns_samedomain.c'; then $(CYGPATH_W) 'ns_samedomain.c'; else $(CYGPATH_W) '$(srcdir)/ns_samedomain.c'; fi` - lib_a-ns_ttl.o: ns_ttl.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ttl.o `test -f 'ns_ttl.c' || echo '$(srcdir)/'`ns_ttl.c lib_a-ns_ttl.obj: ns_ttl.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ns_ttl.obj `if test -f 'ns_ttl.c'; then $(CYGPATH_W) 'ns_ttl.c'; else $(CYGPATH_W) '$(srcdir)/ns_ttl.c'; fi` -lib_a-nsap_addr.o: nsap_addr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.o `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c - -lib_a-nsap_addr.obj: nsap_addr.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.obj `if test -f 'nsap_addr.c'; then $(CYGPATH_W) 'nsap_addr.c'; else $(CYGPATH_W) '$(srcdir)/nsap_addr.c'; fi` - -lib_a-proto-lookup.o: proto-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-proto-lookup.o `test -f 'proto-lookup.c' || echo '$(srcdir)/'`proto-lookup.c +lib_a-nsdispatch.o: nsdispatch.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsdispatch.o `test -f 'nsdispatch.c' || echo '$(srcdir)/'`nsdispatch.c -lib_a-proto-lookup.obj: proto-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-proto-lookup.obj `if test -f 'proto-lookup.c'; then $(CYGPATH_W) 'proto-lookup.c'; else $(CYGPATH_W) '$(srcdir)/proto-lookup.c'; fi` +lib_a-nsdispatch.obj: nsdispatch.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsdispatch.obj `if test -f 'nsdispatch.c'; then $(CYGPATH_W) 'nsdispatch.c'; else $(CYGPATH_W) '$(srcdir)/nsdispatch.c'; fi` -lib_a-opensock.o: opensock.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-opensock.o `test -f 'opensock.c' || echo '$(srcdir)/'`opensock.c +lib_a-nslexer.o: nslexer.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nslexer.o `test -f 'nslexer.c' || echo '$(srcdir)/'`nslexer.c -lib_a-opensock.obj: opensock.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-opensock.obj `if test -f 'opensock.c'; then $(CYGPATH_W) 'opensock.c'; else $(CYGPATH_W) '$(srcdir)/opensock.c'; fi` +lib_a-nslexer.obj: nslexer.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nslexer.obj `if test -f 'nslexer.c'; then $(CYGPATH_W) 'nslexer.c'; else $(CYGPATH_W) '$(srcdir)/nslexer.c'; fi` -lib_a-pwd-lookup.o: pwd-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-pwd-lookup.o `test -f 'pwd-lookup.c' || echo '$(srcdir)/'`pwd-lookup.c +lib_a-nsparser.o: nsparser.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsparser.o `test -f 'nsparser.c' || echo '$(srcdir)/'`nsparser.c -lib_a-pwd-lookup.obj: pwd-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-pwd-lookup.obj `if test -f 'pwd-lookup.c'; then $(CYGPATH_W) 'pwd-lookup.c'; else $(CYGPATH_W) '$(srcdir)/pwd-lookup.c'; fi` +lib_a-nsparser.obj: nsparser.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsparser.obj `if test -f 'nsparser.c'; then $(CYGPATH_W) 'nsparser.c'; else $(CYGPATH_W) '$(srcdir)/nsparser.c'; fi` -lib_a-recv.o: recv.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-recv.o `test -f 'recv.c' || echo '$(srcdir)/'`recv.c +lib_a-nsap_addr.o: nsap_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.o `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c -lib_a-recv.obj: recv.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-recv.obj `if test -f 'recv.c'; then $(CYGPATH_W) 'recv.c'; else $(CYGPATH_W) '$(srcdir)/recv.c'; fi` +lib_a-nsap_addr.obj: nsap_addr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nsap_addr.obj `if test -f 'nsap_addr.c'; then $(CYGPATH_W) 'nsap_addr.c'; else $(CYGPATH_W) '$(srcdir)/nsap_addr.c'; fi` lib_a-res_comp.o: res_comp.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_comp.o `test -f 'res_comp.c' || echo '$(srcdir)/'`res_comp.c @@ -987,30 +717,24 @@ lib_a-res_debug.o: res_debug.c lib_a-res_debug.obj: res_debug.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_debug.obj `if test -f 'res_debug.c'; then $(CYGPATH_W) 'res_debug.c'; else $(CYGPATH_W) '$(srcdir)/res_debug.c'; fi` -lib_a-res_hconf.o: res_hconf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_hconf.o `test -f 'res_hconf.c' || echo '$(srcdir)/'`res_hconf.c - -lib_a-res_hconf.obj: res_hconf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_hconf.obj `if test -f 'res_hconf.c'; then $(CYGPATH_W) 'res_hconf.c'; else $(CYGPATH_W) '$(srcdir)/res_hconf.c'; fi` - lib_a-res_init.o: res_init.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_init.o `test -f 'res_init.c' || echo '$(srcdir)/'`res_init.c lib_a-res_init.obj: res_init.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_init.obj `if test -f 'res_init.c'; then $(CYGPATH_W) 'res_init.c'; else $(CYGPATH_W) '$(srcdir)/res_init.c'; fi` -lib_a-res_libc.o: res_libc.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_libc.o `test -f 'res_libc.c' || echo '$(srcdir)/'`res_libc.c - -lib_a-res_libc.obj: res_libc.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_libc.obj `if test -f 'res_libc.c'; then $(CYGPATH_W) 'res_libc.c'; else $(CYGPATH_W) '$(srcdir)/res_libc.c'; fi` - lib_a-res_mkquery.o: res_mkquery.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkquery.o `test -f 'res_mkquery.c' || echo '$(srcdir)/'`res_mkquery.c lib_a-res_mkquery.obj: res_mkquery.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkquery.obj `if test -f 'res_mkquery.c'; then $(CYGPATH_W) 'res_mkquery.c'; else $(CYGPATH_W) '$(srcdir)/res_mkquery.c'; fi` +lib_a-res_mkupdate.o: res_mkupdate.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkupdate.o `test -f 'res_mkupdate.c' || echo '$(srcdir)/'`res_mkupdate.c + +lib_a-res_mkupdate.obj: res_mkupdate.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_mkupdate.obj `if test -f 'res_mkupdate.c'; then $(CYGPATH_W) 'res_mkupdate.c'; else $(CYGPATH_W) '$(srcdir)/res_mkupdate.c'; fi` + lib_a-res_query.o: res_query.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_query.o `test -f 'res_query.c' || echo '$(srcdir)/'`res_query.c @@ -1023,47 +747,23 @@ lib_a-res_send.o: res_send.c lib_a-res_send.obj: res_send.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_send.obj `if test -f 'res_send.c'; then $(CYGPATH_W) 'res_send.c'; else $(CYGPATH_W) '$(srcdir)/res_send.c'; fi` -lib_a-rexec.o: rexec.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rexec.o `test -f 'rexec.c' || echo '$(srcdir)/'`rexec.c - -lib_a-rexec.obj: rexec.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rexec.obj `if test -f 'rexec.c'; then $(CYGPATH_W) 'rexec.c'; else $(CYGPATH_W) '$(srcdir)/rexec.c'; fi` - -lib_a-rpc-lookup.o: rpc-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rpc-lookup.o `test -f 'rpc-lookup.c' || echo '$(srcdir)/'`rpc-lookup.c - -lib_a-rpc-lookup.obj: rpc-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rpc-lookup.obj `if test -f 'rpc-lookup.c'; then $(CYGPATH_W) 'rpc-lookup.c'; else $(CYGPATH_W) '$(srcdir)/rpc-lookup.c'; fi` - -lib_a-ruserpass.o: ruserpass.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ruserpass.o `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c +lib_a-res_update.o: res_update.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_update.o `test -f 'res_update.c' || echo '$(srcdir)/'`res_update.c -lib_a-ruserpass.obj: ruserpass.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ruserpass.obj `if test -f 'ruserpass.c'; then $(CYGPATH_W) 'ruserpass.c'; else $(CYGPATH_W) '$(srcdir)/ruserpass.c'; fi` +lib_a-res_update.obj: res_update.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-res_update.obj `if test -f 'res_update.c'; then $(CYGPATH_W) 'res_update.c'; else $(CYGPATH_W) '$(srcdir)/res_update.c'; fi` -lib_a-send.o: send.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-send.o `test -f 'send.c' || echo '$(srcdir)/'`send.c +lib_a-rthdr.o: rthdr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rthdr.o `test -f 'rthdr.c' || echo '$(srcdir)/'`rthdr.c -lib_a-send.obj: send.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-send.obj `if test -f 'send.c'; then $(CYGPATH_W) 'send.c'; else $(CYGPATH_W) '$(srcdir)/send.c'; fi` +lib_a-rthdr.obj: rthdr.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rthdr.obj `if test -f 'rthdr.c'; then $(CYGPATH_W) 'rthdr.c'; else $(CYGPATH_W) '$(srcdir)/rthdr.c'; fi` -lib_a-service-lookup.o: service-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-service-lookup.o `test -f 'service-lookup.c' || echo '$(srcdir)/'`service-lookup.c +lib_a-vars.o: vars.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vars.o `test -f 'vars.c' || echo '$(srcdir)/'`vars.c -lib_a-service-lookup.obj: service-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-service-lookup.obj `if test -f 'service-lookup.c'; then $(CYGPATH_W) 'service-lookup.c'; else $(CYGPATH_W) '$(srcdir)/service-lookup.c'; fi` - -lib_a-spwd-lookup.o: spwd-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-spwd-lookup.o `test -f 'spwd-lookup.c' || echo '$(srcdir)/'`spwd-lookup.c - -lib_a-spwd-lookup.obj: spwd-lookup.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-spwd-lookup.obj `if test -f 'spwd-lookup.c'; then $(CYGPATH_W) 'spwd-lookup.c'; else $(CYGPATH_W) '$(srcdir)/spwd-lookup.c'; fi` - -lib_a-ifname.o: ifname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.o `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c - -lib_a-ifname.obj: ifname.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ifname.obj `if test -f 'ifname.c'; then $(CYGPATH_W) 'ifname.c'; else $(CYGPATH_W) '$(srcdir)/ifname.c'; fi` +lib_a-vars.obj: vars.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vars.obj `if test -f 'vars.c'; then $(CYGPATH_W) 'vars.c'; else $(CYGPATH_W) '$(srcdir)/vars.c'; fi` libnet_la-addr2ascii.lo: addr2ascii.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-addr2ascii.lo `test -f 'addr2ascii.c' || echo '$(srcdir)/'`addr2ascii.c @@ -1071,197 +771,89 @@ libnet_la-addr2ascii.lo: addr2ascii.c libnet_la-ascii2addr.lo: ascii2addr.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ascii2addr.lo `test -f 'ascii2addr.c' || echo '$(srcdir)/'`ascii2addr.c -libnet_la-alias-lookup.lo: alias-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-alias-lookup.lo `test -f 'alias-lookup.c' || echo '$(srcdir)/'`alias-lookup.c - libnet_la-base64.lo: base64.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-base64.lo `test -f 'base64.c' || echo '$(srcdir)/'`base64.c -libnet_la-check_pf.lo: check_pf.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-check_pf.lo `test -f 'check_pf.c' || echo '$(srcdir)/'`check_pf.c - -libnet_la-digits_dots.lo: digits_dots.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-digits_dots.lo `test -f 'digits_dots.c' || echo '$(srcdir)/'`digits_dots.c - -libnet_la-ether_aton.lo: ether_aton.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_aton.lo `test -f 'ether_aton.c' || echo '$(srcdir)/'`ether_aton.c - -libnet_la-ether_aton_r.lo: ether_aton_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_aton_r.lo `test -f 'ether_aton_r.c' || echo '$(srcdir)/'`ether_aton_r.c - -libnet_la-ether_hton.lo: ether_hton.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_hton.lo `test -f 'ether_hton.c' || echo '$(srcdir)/'`ether_hton.c +libnet_la-bindresvport.lo: bindresvport.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-bindresvport.lo `test -f 'bindresvport.c' || echo '$(srcdir)/'`bindresvport.c -libnet_la-ether_line.lo: ether_line.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_line.lo `test -f 'ether_line.c' || echo '$(srcdir)/'`ether_line.c - -libnet_la-ether_ntoa.lo: ether_ntoa.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoa.lo `test -f 'ether_ntoa.c' || echo '$(srcdir)/'`ether_ntoa.c - -libnet_la-ether_ntoa_r.lo: ether_ntoa_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoa_r.lo `test -f 'ether_ntoa_r.c' || echo '$(srcdir)/'`ether_ntoa_r.c - -libnet_la-ether_ntoh.lo: ether_ntoh.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_ntoh.lo `test -f 'ether_ntoh.c' || echo '$(srcdir)/'`ether_ntoh.c - -libnet_la-ethers-lookup.lo: ethers-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ethers-lookup.lo `test -f 'ethers-lookup.c' || echo '$(srcdir)/'`ethers-lookup.c +libnet_la-ether_addr.lo: ether_addr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ether_addr.lo `test -f 'ether_addr.c' || echo '$(srcdir)/'`ether_addr.c libnet_la-getaddrinfo.lo: getaddrinfo.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaddrinfo.lo `test -f 'getaddrinfo.c' || echo '$(srcdir)/'`getaddrinfo.c -libnet_la-getaliasent.lo: getaliasent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasent.lo `test -f 'getaliasent.c' || echo '$(srcdir)/'`getaliasent.c - -libnet_la-getaliasent_r.lo: getaliasent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasent_r.lo `test -f 'getaliasent_r.c' || echo '$(srcdir)/'`getaliasent_r.c - -libnet_la-getaliasname.lo: getaliasname.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasname.lo `test -f 'getaliasname.c' || echo '$(srcdir)/'`getaliasname.c - -libnet_la-getaliasname_r.lo: getaliasname_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getaliasname_r.lo `test -f 'getaliasname_r.c' || echo '$(srcdir)/'`getaliasname_r.c +libnet_la-gethostbydns.lo: gethostbydns.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbydns.lo `test -f 'gethostbydns.c' || echo '$(srcdir)/'`gethostbydns.c -libnet_la-gethstbyad.lo: gethstbyad.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbyad.lo `test -f 'gethstbyad.c' || echo '$(srcdir)/'`gethstbyad.c +libnet_la-gethostbyht.lo: gethostbyht.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbyht.lo `test -f 'gethostbyht.c' || echo '$(srcdir)/'`gethostbyht.c -libnet_la-gethstbyad_r.lo: gethstbyad_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbyad_r.lo `test -f 'gethstbyad_r.c' || echo '$(srcdir)/'`gethstbyad_r.c +libnet_la-gethostbynis.lo: gethostbynis.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostbynis.lo `test -f 'gethostbynis.c' || echo '$(srcdir)/'`gethostbynis.c -libnet_la-gethstbynm2.lo: gethstbynm2.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm2.lo `test -f 'gethstbynm2.c' || echo '$(srcdir)/'`gethstbynm2.c +libnet_la-gethostnamadr.lo: gethostnamadr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethostnamadr.lo `test -f 'gethostnamadr.c' || echo '$(srcdir)/'`gethostnamadr.c -libnet_la-gethstbynm2_r.lo: gethstbynm2_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm2_r.lo `test -f 'gethstbynm2_r.c' || echo '$(srcdir)/'`gethstbynm2_r.c - -libnet_la-gethstbynm.lo: gethstbynm.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm.lo `test -f 'gethstbynm.c' || echo '$(srcdir)/'`gethstbynm.c - -libnet_la-gethstbynm_r.lo: gethstbynm_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstbynm_r.lo `test -f 'gethstbynm_r.c' || echo '$(srcdir)/'`gethstbynm_r.c - -libnet_la-gethstent.lo: gethstent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstent.lo `test -f 'gethstent.c' || echo '$(srcdir)/'`gethstent.c - -libnet_la-gethstent_r.lo: gethstent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-gethstent_r.lo `test -f 'gethstent_r.c' || echo '$(srcdir)/'`gethstent_r.c +libnet_la-getifaddrs.lo: getifaddrs.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getifaddrs.lo `test -f 'getifaddrs.c' || echo '$(srcdir)/'`getifaddrs.c libnet_la-getnameinfo.lo: getnameinfo.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnameinfo.lo `test -f 'getnameinfo.c' || echo '$(srcdir)/'`getnameinfo.c -libnet_la-getnetbyad.lo: getnetbyad.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyad.lo `test -f 'getnetbyad.c' || echo '$(srcdir)/'`getnetbyad.c - -libnet_la-getnetbyad_r.lo: getnetbyad_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyad_r.lo `test -f 'getnetbyad_r.c' || echo '$(srcdir)/'`getnetbyad_r.c - -libnet_la-getnetbynm.lo: getnetbynm.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynm.lo `test -f 'getnetbynm.c' || echo '$(srcdir)/'`getnetbynm.c +libnet_la-getnetbydns.lo: getnetbydns.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbydns.lo `test -f 'getnetbydns.c' || echo '$(srcdir)/'`getnetbydns.c -libnet_la-getnetbynm_r.lo: getnetbynm_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynm_r.lo `test -f 'getnetbynm_r.c' || echo '$(srcdir)/'`getnetbynm_r.c +libnet_la-getnetbyht.lo: getnetbyht.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbyht.lo `test -f 'getnetbyht.c' || echo '$(srcdir)/'`getnetbyht.c -libnet_la-getnetent.lo: getnetent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetent.lo `test -f 'getnetent.c' || echo '$(srcdir)/'`getnetent.c +libnet_la-getnetbynis.lo: getnetbynis.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetbynis.lo `test -f 'getnetbynis.c' || echo '$(srcdir)/'`getnetbynis.c -libnet_la-getnetent_r.lo: getnetent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetent_r.lo `test -f 'getnetent_r.c' || echo '$(srcdir)/'`getnetent_r.c - -libnet_la-getnetgrent.lo: getnetgrent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetgrent.lo `test -f 'getnetgrent.c' || echo '$(srcdir)/'`getnetgrent.c - -libnet_la-getnetgrent_r.lo: getnetgrent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetgrent_r.lo `test -f 'getnetgrent_r.c' || echo '$(srcdir)/'`getnetgrent_r.c - -libnet_la-getnssent.lo: getnssent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnssent.lo `test -f 'getnssent.c' || echo '$(srcdir)/'`getnssent.c - -libnet_la-getnssent_r.lo: getnssent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnssent_r.lo `test -f 'getnssent_r.c' || echo '$(srcdir)/'`getnssent_r.c +libnet_la-getnetnamadr.lo: getnetnamadr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getnetnamadr.lo `test -f 'getnetnamadr.c' || echo '$(srcdir)/'`getnetnamadr.c libnet_la-getproto.lo: getproto.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getproto.lo `test -f 'getproto.c' || echo '$(srcdir)/'`getproto.c -libnet_la-getproto_r.lo: getproto_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getproto_r.lo `test -f 'getproto_r.c' || echo '$(srcdir)/'`getproto_r.c - -libnet_la-getprtent.lo: getprtent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtent.lo `test -f 'getprtent.c' || echo '$(srcdir)/'`getprtent.c - -libnet_la-getprtent_r.lo: getprtent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtent_r.lo `test -f 'getprtent_r.c' || echo '$(srcdir)/'`getprtent_r.c - -libnet_la-getprtname.lo: getprtname.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtname.lo `test -f 'getprtname.c' || echo '$(srcdir)/'`getprtname.c +libnet_la-getprotoent.lo: getprotoent.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprotoent.lo `test -f 'getprotoent.c' || echo '$(srcdir)/'`getprotoent.c -libnet_la-getprtname_r.lo: getprtname_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprtname_r.lo `test -f 'getprtname_r.c' || echo '$(srcdir)/'`getprtname_r.c +libnet_la-getprotoname.lo: getprotoname.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getprotoname.lo `test -f 'getprotoname.c' || echo '$(srcdir)/'`getprotoname.c -libnet_la-getrpcbyname.lo: getrpcbyname.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbyname.lo `test -f 'getrpcbyname.c' || echo '$(srcdir)/'`getrpcbyname.c +libnet_la-getservbyname.lo: getservbyname.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservbyname.lo `test -f 'getservbyname.c' || echo '$(srcdir)/'`getservbyname.c -libnet_la-getrpcbyname_r.lo: getrpcbyname_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbyname_r.lo `test -f 'getrpcbyname_r.c' || echo '$(srcdir)/'`getrpcbyname_r.c - -libnet_la-getrpcbynumber.lo: getrpcbynumber.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbynumber.lo `test -f 'getrpcbynumber.c' || echo '$(srcdir)/'`getrpcbynumber.c - -libnet_la-getrpcbynumber_r.lo: getrpcbynumber_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcbynumber_r.lo `test -f 'getrpcbynumber_r.c' || echo '$(srcdir)/'`getrpcbynumber_r.c - -libnet_la-getrpcent.lo: getrpcent.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcent.lo `test -f 'getrpcent.c' || echo '$(srcdir)/'`getrpcent.c - -libnet_la-getrpcent_r.lo: getrpcent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getrpcent_r.lo `test -f 'getrpcent_r.c' || echo '$(srcdir)/'`getrpcent_r.c +libnet_la-getservbyport.lo: getservbyport.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservbyport.lo `test -f 'getservbyport.c' || echo '$(srcdir)/'`getservbyport.c libnet_la-getservent.lo: getservent.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservent.lo `test -f 'getservent.c' || echo '$(srcdir)/'`getservent.c -libnet_la-getservent_r.lo: getservent_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getservent_r.lo `test -f 'getservent_r.c' || echo '$(srcdir)/'`getservent_r.c - -libnet_la-getsrvbynm.lo: getsrvbynm.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbynm.lo `test -f 'getsrvbynm.c' || echo '$(srcdir)/'`getsrvbynm.c - -libnet_la-getsrvbynm_r.lo: getsrvbynm_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbynm_r.lo `test -f 'getsrvbynm_r.c' || echo '$(srcdir)/'`getsrvbynm_r.c +libnet_la-herror.lo: herror.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-herror.lo `test -f 'herror.c' || echo '$(srcdir)/'`herror.c -libnet_la-getsrvbypt.lo: getsrvbypt.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbypt.lo `test -f 'getsrvbypt.c' || echo '$(srcdir)/'`getsrvbypt.c - -libnet_la-getsrvbypt_r.lo: getsrvbypt_r.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-getsrvbypt_r.lo `test -f 'getsrvbypt_r.c' || echo '$(srcdir)/'`getsrvbypt_r.c - -libnet_la-grp-lookup.lo: grp-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-grp-lookup.lo `test -f 'grp-lookup.c' || echo '$(srcdir)/'`grp-lookup.c - -libnet_la-herrno.lo: herrno.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-herrno.lo `test -f 'herrno.c' || echo '$(srcdir)/'`herrno.c - -libnet_la-hosts-lookup.lo: hosts-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-hosts-lookup.lo `test -f 'hosts-lookup.c' || echo '$(srcdir)/'`hosts-lookup.c - -libnet_la-ifreq.lo: ifreq.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifreq.lo `test -f 'ifreq.c' || echo '$(srcdir)/'`ifreq.c - -libnet_la-in6_addr.lo: in6_addr.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-in6_addr.lo `test -f 'in6_addr.c' || echo '$(srcdir)/'`in6_addr.c - -libnet_la-inet6_option.lo: inet6_option.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet6_option.lo `test -f 'inet6_option.c' || echo '$(srcdir)/'`inet6_option.c +libnet_la-hesiod.lo: hesiod.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-hesiod.lo `test -f 'hesiod.c' || echo '$(srcdir)/'`hesiod.c libnet_la-inet_addr.lo: inet_addr.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_addr.lo `test -f 'inet_addr.c' || echo '$(srcdir)/'`inet_addr.c +libnet_la-ifname.lo: ifname.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifname.lo `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c + libnet_la-inet_lnaof.lo: inet_lnaof.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_lnaof.lo `test -f 'inet_lnaof.c' || echo '$(srcdir)/'`inet_lnaof.c -libnet_la-inet_mkadr.lo: inet_mkadr.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_mkadr.lo `test -f 'inet_mkadr.c' || echo '$(srcdir)/'`inet_mkadr.c +libnet_la-inet_makeaddr.lo: inet_makeaddr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_makeaddr.lo `test -f 'inet_makeaddr.c' || echo '$(srcdir)/'`inet_makeaddr.c -libnet_la-inet_net.lo: inet_net.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net.lo `test -f 'inet_net.c' || echo '$(srcdir)/'`inet_net.c +libnet_la-inet_net_ntop.lo: inet_net_ntop.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_ntop.lo `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c + +libnet_la-inet_net_pton.lo: inet_net_pton.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_pton.lo `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c libnet_la-inet_neta.lo: inet_neta.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_neta.lo `test -f 'inet_neta.c' || echo '$(srcdir)/'`inet_neta.c @@ -1269,11 +861,8 @@ libnet_la-inet_neta.lo: inet_neta.c libnet_la-inet_netof.lo: inet_netof.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_netof.lo `test -f 'inet_netof.c' || echo '$(srcdir)/'`inet_netof.c -libnet_la-inet_net_ntop.lo: inet_net_ntop.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_ntop.lo `test -f 'inet_net_ntop.c' || echo '$(srcdir)/'`inet_net_ntop.c - -libnet_la-inet_net_pton.lo: inet_net_pton.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_net_pton.lo `test -f 'inet_net_pton.c' || echo '$(srcdir)/'`inet_net_pton.c +libnet_la-inet_network.lo: inet_network.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_network.lo `test -f 'inet_network.c' || echo '$(srcdir)/'`inet_network.c libnet_la-inet_ntoa.lo: inet_ntoa.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_ntoa.lo `test -f 'inet_ntoa.c' || echo '$(srcdir)/'`inet_ntoa.c @@ -1284,20 +873,26 @@ libnet_la-inet_ntop.lo: inet_ntop.c libnet_la-inet_pton.lo: inet_pton.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-inet_pton.lo `test -f 'inet_pton.c' || echo '$(srcdir)/'`inet_pton.c +libnet_la-innetgr-stub.lo: innetgr-stub.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-innetgr-stub.lo `test -f 'innetgr-stub.c' || echo '$(srcdir)/'`innetgr-stub.c + +libnet_la-ip6opt.lo: ip6opt.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ip6opt.lo `test -f 'ip6opt.c' || echo '$(srcdir)/'`ip6opt.c + libnet_la-issetugid-stub.lo: issetugid-stub.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-issetugid-stub.lo `test -f 'issetugid-stub.c' || echo '$(srcdir)/'`issetugid-stub.c -libnet_la-key-lookup.lo: key-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-key-lookup.lo `test -f 'key-lookup.c' || echo '$(srcdir)/'`key-lookup.c +libnet_la-linkaddr.lo: linkaddr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-linkaddr.lo `test -f 'linkaddr.c' || echo '$(srcdir)/'`linkaddr.c -libnet_la-netgrp-lookup.lo: netgrp-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-netgrp-lookup.lo `test -f 'netgrp-lookup.c' || echo '$(srcdir)/'`netgrp-lookup.c +libnet_la-map_v4v6.lo: map_v4v6.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-map_v4v6.lo `test -f 'map_v4v6.c' || echo '$(srcdir)/'`map_v4v6.c -libnet_la-network-lookup.lo: network-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-network-lookup.lo `test -f 'network-lookup.c' || echo '$(srcdir)/'`network-lookup.c +libnet_la-name6.lo: name6.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-name6.lo `test -f 'name6.c' || echo '$(srcdir)/'`name6.c -libnet_la-nsswitch.lo: nsswitch.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsswitch.lo `test -f 'nsswitch.c' || echo '$(srcdir)/'`nsswitch.c +libnet_la-ns_addr.lo: ns_addr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_addr.lo `test -f 'ns_addr.c' || echo '$(srcdir)/'`ns_addr.c libnet_la-ns_name.lo: ns_name.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_name.lo `test -f 'ns_name.c' || echo '$(srcdir)/'`ns_name.c @@ -1305,32 +900,29 @@ libnet_la-ns_name.lo: ns_name.c libnet_la-ns_netint.lo: ns_netint.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_netint.lo `test -f 'ns_netint.c' || echo '$(srcdir)/'`ns_netint.c +libnet_la-ns_ntoa.lo: ns_ntoa.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_ntoa.lo `test -f 'ns_ntoa.c' || echo '$(srcdir)/'`ns_ntoa.c + libnet_la-ns_parse.lo: ns_parse.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_parse.lo `test -f 'ns_parse.c' || echo '$(srcdir)/'`ns_parse.c libnet_la-ns_print.lo: ns_print.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_print.lo `test -f 'ns_print.c' || echo '$(srcdir)/'`ns_print.c -libnet_la-ns_samedomain.lo: ns_samedomain.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_samedomain.lo `test -f 'ns_samedomain.c' || echo '$(srcdir)/'`ns_samedomain.c - libnet_la-ns_ttl.lo: ns_ttl.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ns_ttl.lo `test -f 'ns_ttl.c' || echo '$(srcdir)/'`ns_ttl.c -libnet_la-nsap_addr.lo: nsap_addr.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsap_addr.lo `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c +libnet_la-nsdispatch.lo: nsdispatch.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsdispatch.lo `test -f 'nsdispatch.c' || echo '$(srcdir)/'`nsdispatch.c -libnet_la-proto-lookup.lo: proto-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-proto-lookup.lo `test -f 'proto-lookup.c' || echo '$(srcdir)/'`proto-lookup.c +libnet_la-nslexer.lo: nslexer.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nslexer.lo `test -f 'nslexer.c' || echo '$(srcdir)/'`nslexer.c -libnet_la-opensock.lo: opensock.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-opensock.lo `test -f 'opensock.c' || echo '$(srcdir)/'`opensock.c +libnet_la-nsparser.lo: nsparser.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsparser.lo `test -f 'nsparser.c' || echo '$(srcdir)/'`nsparser.c -libnet_la-pwd-lookup.lo: pwd-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-pwd-lookup.lo `test -f 'pwd-lookup.c' || echo '$(srcdir)/'`pwd-lookup.c - -libnet_la-recv.lo: recv.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-recv.lo `test -f 'recv.c' || echo '$(srcdir)/'`recv.c +libnet_la-nsap_addr.lo: nsap_addr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-nsap_addr.lo `test -f 'nsap_addr.c' || echo '$(srcdir)/'`nsap_addr.c libnet_la-res_comp.lo: res_comp.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_comp.lo `test -f 'res_comp.c' || echo '$(srcdir)/'`res_comp.c @@ -1341,44 +933,29 @@ libnet_la-res_data.lo: res_data.c libnet_la-res_debug.lo: res_debug.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_debug.lo `test -f 'res_debug.c' || echo '$(srcdir)/'`res_debug.c -libnet_la-res_hconf.lo: res_hconf.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_hconf.lo `test -f 'res_hconf.c' || echo '$(srcdir)/'`res_hconf.c - libnet_la-res_init.lo: res_init.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_init.lo `test -f 'res_init.c' || echo '$(srcdir)/'`res_init.c -libnet_la-res_libc.lo: res_libc.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_libc.lo `test -f 'res_libc.c' || echo '$(srcdir)/'`res_libc.c - libnet_la-res_mkquery.lo: res_mkquery.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_mkquery.lo `test -f 'res_mkquery.c' || echo '$(srcdir)/'`res_mkquery.c +libnet_la-res_mkupdate.lo: res_mkupdate.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_mkupdate.lo `test -f 'res_mkupdate.c' || echo '$(srcdir)/'`res_mkupdate.c + libnet_la-res_query.lo: res_query.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_query.lo `test -f 'res_query.c' || echo '$(srcdir)/'`res_query.c libnet_la-res_send.lo: res_send.c $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_send.lo `test -f 'res_send.c' || echo '$(srcdir)/'`res_send.c -libnet_la-rexec.lo: rexec.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rexec.lo `test -f 'rexec.c' || echo '$(srcdir)/'`rexec.c +libnet_la-res_update.lo: res_update.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-res_update.lo `test -f 'res_update.c' || echo '$(srcdir)/'`res_update.c -libnet_la-rpc-lookup.lo: rpc-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rpc-lookup.lo `test -f 'rpc-lookup.c' || echo '$(srcdir)/'`rpc-lookup.c +libnet_la-rthdr.lo: rthdr.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-rthdr.lo `test -f 'rthdr.c' || echo '$(srcdir)/'`rthdr.c -libnet_la-ruserpass.lo: ruserpass.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ruserpass.lo `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c - -libnet_la-send.lo: send.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-send.lo `test -f 'send.c' || echo '$(srcdir)/'`send.c - -libnet_la-service-lookup.lo: service-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-service-lookup.lo `test -f 'service-lookup.c' || echo '$(srcdir)/'`service-lookup.c - -libnet_la-spwd-lookup.lo: spwd-lookup.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-spwd-lookup.lo `test -f 'spwd-lookup.c' || echo '$(srcdir)/'`spwd-lookup.c - -libnet_la-ifname.lo: ifname.c - $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-ifname.lo `test -f 'ifname.c' || echo '$(srcdir)/'`ifname.c +libnet_la-vars.lo: vars.c + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnet_la_CFLAGS) $(CFLAGS) -c -o libnet_la-vars.lo `test -f 'vars.c' || echo '$(srcdir)/'`vars.c mostlyclean-libtool: -rm -f *.lo diff --git a/newlib/libc/sys/linux/net/XXX-lookup.c b/newlib/libc/sys/linux/net/XXX-lookup.c deleted file mode 100644 index da0e6f451..000000000 --- a/newlib/libc/sys/linux/net/XXX-lookup.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "nsswitch.h" - -/*******************************************************************\ -|* Here we assume one symbol to be defined: *| -|* *| -|* DATABASE_NAME - name of the database the function accesses *| -|* (e.g., hosts, services, ...) *| -|* *| -|* One additional symbol may optionally be defined: *| -|* *| -|* ALTERNATE_NAME - name of another service which is examined in *| -|* case DATABASE_NAME is not found *| -|* *| -|* DEFAULT_CONFIG - string for default conf (e.g. "dns files") *| -|* *| -\*******************************************************************/ - -#define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup) -#define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post) -#define CONCAT3_2(Pre, Name, Post) Pre##Name##Post - -#define DATABASE_NAME_SYMBOL CONCAT3_1 (__nss_, DATABASE_NAME, _database) -#define DATABASE_NAME_STRING STRINGIFY1 (DATABASE_NAME) -#define STRINGIFY1(Name) STRINGIFY2 (Name) -#define STRINGIFY2(Name) #Name - -#ifdef ALTERNATE_NAME -#define ALTERNATE_NAME_STRING STRINGIFY1 (ALTERNATE_NAME) -#else -#define ALTERNATE_NAME_STRING NULL -#endif - -#ifndef DEFAULT_CONFIG -#define DEFAULT_CONFIG NULL -#endif - -service_user *DATABASE_NAME_SYMBOL attribute_hidden; - -extern int DB_LOOKUP_FCT (service_user **ni, const char *fct_name, - void **fctp) internal_function; -libc_hidden_proto (DB_LOOKUP_FCT) - -int -internal_function -DB_LOOKUP_FCT (service_user **ni, const char *fct_name, void **fctp) -{ - if (DATABASE_NAME_SYMBOL == NULL - && __nss_database_lookup (DATABASE_NAME_STRING, ALTERNATE_NAME_STRING, - DEFAULT_CONFIG, &DATABASE_NAME_SYMBOL) < 0) - return -1; - - *ni = DATABASE_NAME_SYMBOL; - - return __nss_lookup (ni, fct_name, fctp); -} -libc_hidden_def (DB_LOOKUP_FCT) diff --git a/newlib/libc/sys/linux/net/addr2ascii.3 b/newlib/libc/sys/linux/net/addr2ascii.3 new file mode 100644 index 000000000..10b1ac7f9 --- /dev/null +++ b/newlib/libc/sys/linux/net/addr2ascii.3 @@ -0,0 +1,222 @@ +.\" +.\" 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 +#include +#include +#include + +char * +inet_ntoa(struct in_addr addr) +{ + return addr2ascii(AF_INET, &addr, sizeof addr, 0); +} + +int +inet_aton(const char *ascii, struct in_addr *addr) +{ + return (ascii2addr(AF_INET, ascii, addr) + == sizeof(*addr)); +} +.Ed +.Pp +In actuality, this cannot be done because +.Fn addr2ascii +and +.Fn ascii2addr +are implemented in terms of the +.Xr inet 3 +functions, rather than the other way around. +.Sh ERRORS +When a failure is returned, +.Li errno +is set to one of the following values: +.Bl -tag -width Er +.It Bq Er ENAMETOOLONG +The +.Fn addr2ascii +routine was passed a +.Fa len +parameter which was inappropriate for the address family given by +.Fa af . +.It Bq Er EPROTONOSUPPORT +Either routine was passed an +.Fa af +parameter other than +.Dv AF_INET +or +.Dv AF_LINK . +.It Bq Er EINVAL +The string passed to +.Fn ascii2addr +was improperly formatted for address family +.Fa af . +.El +.Sh SEE ALSO +.Xr inet 3 , +.Xr linkaddr 3 , +.Xr inet 4 +.Sh HISTORY +An interface close to this one was originally suggested by Craig +Partridge. This particular interface originally appeared in the +.Tn INRIA +.Tn IPv6 +implementation. +.Sh AUTHORS +Code and documentation by +.An Garrett A. Wollman , +MIT Laboratory for Computer Science. +.Sh BUGS +The original implementations supported IPv6. This support should +eventually be resurrected. The +.Tn NRL +implementation also included support for the +.Dv AF_ISO +and +.Dv AF_NS +address families. +.Pp +The genericity of this interface is somewhat questionable. A truly +generic interface would provide a means for determining the length of +the buffer to be used so that it could be dynamically allocated, and +would always require a +.Dq Li "struct sockaddr" +to hold the binary address. Unfortunately, this is incompatible with existing +practice. This limitation means that a routine for printing network +addresses from arbitrary address families must still have internal +knowledge of the maximum buffer length needed and the appropriate part +of the address to use as the binary address. diff --git a/newlib/libc/sys/linux/net/alias-lookup.c b/newlib/libc/sys/linux/net/alias-lookup.c deleted file mode 100644 index 6aba466b3..000000000 --- a/newlib/libc/sys/linux/net/alias-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME aliases - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/aliases.h b/newlib/libc/sys/linux/net/aliases.h deleted file mode 100644 index 58dd8f0fc..000000000 --- a/newlib/libc/sys/linux/net/aliases.h +++ /dev/null @@ -1,64 +0,0 @@ -/* 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 - -#include - - -__BEGIN_DECLS - -/* Structure to represent one entry of the alias data base. */ -struct aliasent - { - char *alias_name; - size_t alias_members_len; - char **alias_members; - int alias_local; - }; - - -/* Open alias data base files. */ -extern void setaliasent (void) __THROW; - -/* Close alias data base files. */ -extern void endaliasent (void) __THROW; - -/* Get the next entry from the alias data base. */ -extern struct aliasent *getaliasent (void) __THROW; - -/* Get the next entry from the alias data base and put it in RESULT_BUF. */ -extern int getaliasent_r (struct aliasent *__restrict __result_buf, - char *__restrict __buffer, size_t __buflen, - struct aliasent **__restrict __result) __THROW; - -/* Get alias entry corresponding to NAME. */ -extern struct aliasent *getaliasbyname (__const char *__name) __THROW; - -/* Get alias entry corresponding to NAME and put it in RESULT_BUF. */ -extern int getaliasbyname_r (__const char *__restrict __name, - struct aliasent *__restrict __result_buf, - char *__restrict __buffer, size_t __buflen, - struct aliasent **__restrict __result) __THROW; - -__END_DECLS - -#endif /* aliases.h */ diff --git a/newlib/libc/sys/linux/net/base64.c b/newlib/libc/sys/linux/net/base64.c index 76c966fc3..35f7d867b 100644 --- a/newlib/libc/sys/linux/net/base64.c +++ b/newlib/libc/sys/linux/net/base64.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -40,10 +40,9 @@ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -#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 +#include #include #include #include @@ -58,8 +57,6 @@ static const char rcsid[] = "$BINDId: base64.c,v 8.7 1999/10/13 16:39:33 vixie E #include #include -#include "libc-symbols.h" - #define Assert(Cond) if (!(Cond)) abort() static const char Base64[] = @@ -114,9 +111,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 @@ -158,14 +155,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); @@ -188,7 +185,6 @@ 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) @@ -209,7 +205,7 @@ b64_pton(src, target, targsize) tarindex = 0; while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace((unsigned char)ch)) /* Skip whitespace anywhere. */ continue; if (ch == Pad64) @@ -279,7 +275,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(ch)) + if (!isspace((unsigned char)ch)) break; /* Make sure there is another trailing = sign. */ if (ch != Pad64) @@ -294,7 +290,7 @@ b64_pton(src, target, targsize) * whitespace after it? */ for ((void)NULL; ch != '\0'; ch = *src++) - if (!isspace(ch)) + if (!isspace((unsigned char)ch)) return (-1); /* diff --git a/newlib/libc/sys/linux/net/bindresvport.c b/newlib/libc/sys/linux/net/bindresvport.c new file mode 100644 index 000000000..7b595b4dc --- /dev/null +++ b/newlib/libc/sys/linux/net/bindresvport.c @@ -0,0 +1,160 @@ +/* $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 +#include + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + * + * Portions Copyright(C) 1996, Jason Downs. All rights reserved. + */ + +#include "namespace.h" +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include "un-namespace.h" + +/* + * Bind a socket to a privileged IP port + */ +int +bindresvport(sd, sin) + int sd; + struct sockaddr_in *sin; +{ + return bindresvport_sa(sd, (struct sockaddr *)sin); +} + +/* + * Bind a socket to a privileged IP port + */ +int +bindresvport_sa(sd, sa) + int sd; + struct sockaddr *sa; +{ + int old, error, af; + struct sockaddr_storage myaddr; + struct sockaddr_in *sin; +#ifdef INET6 + struct sockaddr_in6 *sin6; +#endif + int proto, portrange, portlow; + u_int16_t *portp; + socklen_t salen; + + if (sa == NULL) { + salen = sizeof(myaddr); + sa = (struct sockaddr *)&myaddr; + + if (getsockname(sd, sa, &salen) == -1) + return -1; /* errno is correctly set */ + + af = sa->sa_family; + memset(sa, 0, salen); + } else + af = sa->sa_family; + + switch (af) { + case AF_INET: + proto = IPPROTO_IP; + portrange = IP_PORTRANGE; + portlow = IP_PORTRANGE_LOW; + sin = (struct sockaddr_in *)sa; + salen = sizeof(struct sockaddr_in); + portp = &sin->sin_port; + break; +#ifdef INET6 + case AF_INET6: + proto = IPPROTO_IPV6; + portrange = IPV6_PORTRANGE; + portlow = IPV6_PORTRANGE_LOW; + sin6 = (struct sockaddr_in6 *)sa; + salen = sizeof(struct sockaddr_in6); + portp = &sin6->sin6_port; + break; +#endif + default: + errno = EPFNOSUPPORT; + return (-1); + } + sa->sa_family = af; + + if (*portp == 0) { + socklen_t oldlen = sizeof(old); + + error = getsockopt(sd, proto, portrange, &old, &oldlen); + if (error < 0) + return (error); + + error = setsockopt(sd, proto, portrange, &portlow, + sizeof(portlow)); + if (error < 0) + return (error); + } + + error = bind(sd, sa, salen); + + if (*portp == 0) { + int saved_errno = errno; + + if (error < 0) { + if (setsockopt(sd, proto, portrange, &old, + sizeof(old)) < 0) + errno = saved_errno; + return (error); + } + + if (sa != (struct sockaddr *)&myaddr) { + /* Hmm, what did the kernel assign? */ + if (getsockname(sd, sa, &salen) < 0) + errno = saved_errno; + return (error); + } + } + return (error); +} diff --git a/newlib/libc/sys/linux/net/byteorder.3 b/newlib/libc/sys/linux/net/byteorder.3 new file mode 100644 index 000000000..062ac9d70 --- /dev/null +++ b/newlib/libc/sys/linux/net/byteorder.3 @@ -0,0 +1,84 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/byteorder.3,v 1.9 2001/12/08 19:06:23 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt BYTEORDER 3 +.Os +.Sh NAME +.Nm htonl , +.Nm htons , +.Nm ntohl , +.Nm ntohs +.Nd convert values between host and network byte order +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In arpa/inet.h +.Ft uint32_t +.Fn htonl "uint32_t hostlong" +.Ft uint16_t +.Fn htons "uint16_t hostshort" +.Ft uint32_t +.Fn ntohl "uint32_t netlong" +.Ft uint16_t +.Fn ntohs "uint16_t netshort" +.Sh DESCRIPTION +These routines convert 16 and 32 bit quantities between network +byte order and host byte order. +On machines which have a byte order which is the same as the network +order, routines are defined as null macros. +.Pp +These routines are most often used in conjunction with Internet +addresses and ports as returned by +.Xr gethostbyname 3 +and +.Xr getservent 3 . +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr getservent 3 +.Sh STANDARDS +The +.Nm byteorder +functions are expected to conform with +.St -p1003.1-2001 . +.Sh HISTORY +The +.Nm byteorder +functions appeared in +.Bx 4.2 . +.Sh BUGS +On the +.Tn VAX +bytes are handled backwards from most everyone else in +the world. This is not expected to be fixed in the near future. diff --git a/newlib/libc/sys/linux/net/check_pf.c b/newlib/libc/sys/linux/net/check_pf.c deleted file mode 100644 index 086879e4e..000000000 --- a/newlib/libc/sys/linux/net/check_pf.c +++ /dev/null @@ -1,199 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "config.h" -#include "local.h" - -#define __ASSUME_NETLINK_SUPPORT 1 - -static int -make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6) -{ - struct - { - struct nlmsghdr nlh; - struct rtgenmsg g; - } req; - struct sockaddr_nl nladdr; - - req.nlh.nlmsg_len = sizeof (req); - req.nlh.nlmsg_type = RTM_GETADDR; - req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; - req.nlh.nlmsg_pid = 0; - req.nlh.nlmsg_seq = time (NULL); - req.g.rtgen_family = AF_UNSPEC; - - memset (&nladdr, '\0', sizeof (nladdr)); - nladdr.nl_family = AF_NETLINK; - - if (TEMP_FAILURE_RETRY (sendto (fd, (void *) &req, sizeof (req), 0, - (struct sockaddr *) &nladdr, - sizeof (nladdr))) < 0) - return -1; - - *seen_ipv4 = false; - *seen_ipv6 = false; - - bool done = false; - char buf[4096]; - struct iovec iov = { buf, sizeof (buf) }; - - do - { - struct msghdr msg = - { - (void *) &nladdr, sizeof (nladdr), - &iov, 1, - NULL, 0, - 0 - }; - - ssize_t read_len = TEMP_FAILURE_RETRY (recvmsg (fd, &msg, 0)); - if (read_len < 0) - return -1; - - if (msg.msg_flags & MSG_TRUNC) - return -1; - - struct nlmsghdr *nlmh; - for (nlmh = (struct nlmsghdr *) buf; - NLMSG_OK (nlmh, (size_t) read_len); - nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, read_len)) - { - if (nladdr.nl_pid != 0 || (pid_t) nlmh->nlmsg_pid != pid - || nlmh->nlmsg_seq != req.nlh.nlmsg_seq) - continue; - - if (nlmh->nlmsg_type == RTM_NEWADDR) - { - struct ifaddrmsg *ifam = (struct ifaddrmsg *) NLMSG_DATA (nlmh); - - switch (ifam->ifa_family) - { - case AF_INET: - *seen_ipv4 = true; - break; - case AF_INET6: - *seen_ipv6 = true; - break; - default: - /* Ignore. */ - break; - } - } - else if (nlmh->nlmsg_type == NLMSG_DONE) - /* We found the end, leave the loop. */ - done = true; - else ; - } - } - while (! done); - - close (fd); - - return 0; -} - - -/* We don't know if we have NETLINK support compiled in in our - Kernel. */ -#if __ASSUME_NETLINK_SUPPORT == 0 -/* Define in ifaddrs.h. */ -extern int __no_netlink_support attribute_hidden; -#else -# define __no_netlink_support 0 -#endif - - -void -attribute_hidden -__check_pf (bool *seen_ipv4, bool *seen_ipv6) -{ - if (! __no_netlink_support) - { - int fd = socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - - struct sockaddr_nl nladdr; - memset (&nladdr, '\0', sizeof (nladdr)); - nladdr.nl_family = AF_NETLINK; - - socklen_t addr_len = sizeof (nladdr); - - if (fd >= 0 - && bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0 - && getsockname (fd, (struct sockaddr *) &nladdr, &addr_len) == 0 - && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6) == 0) - /* It worked. */ - return; - - if (fd >= 0) - close (fd); - -#if __ASSUME_NETLINK_SUPPORT == 0 - /* Remember that there is no netlink support. */ - __no_netlink_support = 1; -#else - /* We cannot determine what interfaces are available. Be - pessimistic. */ - *seen_ipv4 = true; - *seen_ipv6 = true; -#endif - } - -#if __ASSUME_NETLINK_SUPPORT == 0 - /* No netlink. Get the interface list via getifaddrs. */ - struct ifaddrs *ifa = NULL; - if (getifaddrs (&ifa) != 0) - { - /* We cannot determine what interfaces are available. Be - pessimistic. */ - *seen_ipv4 = true; - *seen_ipv6 = true; - return; - } - - *seen_ipv4 = false; - *seen_ipv6 = false; - - struct ifaddrs *runp; - for (runp = ifa; runp != NULL; runp = runp->ifa_next) - if (runp->ifa_addr->sa_family == PF_INET) - *seen_ipv4 = true; - else if (runp->ifa_addr->sa_family == PF_INET6) - *seen_ipv6 = true; - - (void) freeifaddrs (ifa); -#endif -} diff --git a/newlib/libc/sys/linux/net/databases.def b/newlib/libc/sys/linux/net/databases.def deleted file mode 100644 index 27c15fc04..000000000 --- a/newlib/libc/sys/linux/net/databases.def +++ /dev/null @@ -1,40 +0,0 @@ -/* 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 , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This list must be kept sorted!!! */ - -DEFINE_DATABASE (aliases) -DEFINE_DATABASE (ethers) -DEFINE_DATABASE (group) -DEFINE_DATABASE (hosts) -DEFINE_DATABASE (netgroup) -DEFINE_DATABASE (networks) -DEFINE_DATABASE (passwd) -DEFINE_DATABASE (protocols) -DEFINE_DATABASE (publickey) -DEFINE_DATABASE (rpc) -DEFINE_DATABASE (services) -DEFINE_DATABASE (shadow) - -/* - Local Variables: - mode:C - End: - */ diff --git a/newlib/libc/sys/linux/net/digits_dots.c b/newlib/libc/sys/linux/net/digits_dots.c deleted file mode 100644 index 9576dd53b..000000000 --- a/newlib/libc/sys/linux/net/digits_dots.c +++ /dev/null @@ -1,317 +0,0 @@ -/* 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 , 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include "nsswitch.h" - -#ifdef USE_NSCD -# define inet_aton __inet_aton -# include -#endif - -int -__nss_hostname_digits_dots (const char *name, struct hostent *resbuf, - char **buffer, size_t *buffer_size, - size_t buflen, struct hostent **result, - enum nss_status *status, int af, int *h_errnop) -{ - int save; - - /* We have to test for the use of IPv6 which can only be done by - examining `_res'. */ - if (__res_maybe_init (&_res, 0) == -1) - { - if (h_errnop) - *h_errnop = NETDB_INTERNAL; - *result = NULL; - return -1; - } - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit (name[0]) || isxdigit (name[0]) || name[0] == ':') - { - const char *cp; - char *hostname; - typedef unsigned char host_addr_t[16]; - host_addr_t *host_addr; - typedef char *host_addr_list_t[2]; - host_addr_list_t *h_addr_ptrs; - char **h_alias_ptr; - size_t size_needed; - int addr_size; - - switch (af) - { - case AF_INET: - addr_size = INADDRSZ; - break; - - case AF_INET6: - addr_size = IN6ADDRSZ; - break; - - default: - af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET; - addr_size = af == AF_INET6 ? IN6ADDRSZ : INADDRSZ; - break; - } - - size_needed = (sizeof (*host_addr) - + sizeof (*h_addr_ptrs) + strlen (name) + 1); - - if (buffer_size == NULL) - { - if (buflen < size_needed) - { - if (h_errnop != NULL) - *h_errnop = TRY_AGAIN; - __set_errno (ERANGE); - goto done; - } - } - else if (buffer_size != NULL && *buffer_size < size_needed) - { - char *new_buf; - *buffer_size = size_needed; - new_buf = (char *) realloc (*buffer, *buffer_size); - - if (new_buf == NULL) - { - save = errno; - free (*buffer); - *buffer = NULL; - *buffer_size = 0; - __set_errno (save); - if (h_errnop != NULL) - *h_errnop = TRY_AGAIN; - *result = NULL; - goto done; - } - *buffer = new_buf; - } - - memset (*buffer, '\0', size_needed); - - host_addr = (host_addr_t *) *buffer; - h_addr_ptrs = (host_addr_list_t *) - ((char *) host_addr + sizeof (*host_addr)); - h_alias_ptr = (char **) ((char *) h_addr_ptrs + sizeof (*h_addr_ptrs)); - hostname = (char *) h_alias_ptr + sizeof (*h_alias_ptr); - - if (isdigit (name[0])) - { - for (cp = name;; ++cp) - { - if (*cp == '\0') - { - int ok; - - if (*--cp == '.') - break; - - /* All-numeric, no dot at the end. Fake up a hostent as if - we'd actually done a lookup. What if someone types - 255.255.255.255? The test below will succeed - spuriously... ??? */ - if (af == AF_INET) - ok = __inet_aton (name, (struct in_addr *) host_addr); - else - { - assert (af == AF_INET6); - ok = inet_pton (af, name, host_addr) > 0; - } - if (! ok) - { - *h_errnop = HOST_NOT_FOUND; - if (buffer_size) - *result = NULL; - goto done; - } - - resbuf->h_name = strcpy (hostname, name); - h_alias_ptr[0] = NULL; - resbuf->h_aliases = h_alias_ptr; - (*h_addr_ptrs)[0] = (char *) host_addr; - (*h_addr_ptrs)[1] = NULL; - resbuf->h_addr_list = *h_addr_ptrs; - if (af == AF_INET && (_res.options & RES_USE_INET6)) - { - /* We need to change the IP v4 address into the - IP v6 address. */ - char tmp[INADDRSZ]; - char *p = (char *) host_addr; - int i; - - /* Save a copy of the IP v4 address. */ - memcpy (tmp, host_addr, INADDRSZ); - /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Copy the IP v4 address. */ - memcpy (p, tmp, INADDRSZ); - resbuf->h_addrtype = AF_INET6; - resbuf->h_length = IN6ADDRSZ; - } - else - { - resbuf->h_addrtype = af; - resbuf->h_length = addr_size; - } - if (h_errnop != NULL) - *h_errnop = NETDB_SUCCESS; - if (buffer_size == NULL) - *status = NSS_STATUS_SUCCESS; - else - *result = resbuf; - goto done; - } - - if (!isdigit (*cp) && *cp != '.') - break; - } - } - - if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':') - { - const char *cp; - char *hostname; - typedef unsigned char host_addr_t[16]; - host_addr_t *host_addr; - typedef char *host_addr_list_t[2]; - host_addr_list_t *h_addr_ptrs; - size_t size_needed; - int addr_size; - - switch (af) - { - default: - af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET; - if (af == AF_INET6) - { - addr_size = IN6ADDRSZ; - break; - } - /* FALLTHROUGH */ - - case AF_INET: - /* This is not possible. We cannot represent an IPv6 address - in an `struct in_addr' variable. */ - *h_errnop = HOST_NOT_FOUND; - *result = NULL; - goto done; - - case AF_INET6: - addr_size = IN6ADDRSZ; - break; - } - - size_needed = (sizeof (*host_addr) - + sizeof (*h_addr_ptrs) + strlen (name) + 1); - - if (buffer_size == NULL && buflen < size_needed) - { - if (h_errnop != NULL) - *h_errnop = TRY_AGAIN; - __set_errno (ERANGE); - goto done; - } - else if (buffer_size != NULL && *buffer_size < size_needed) - { - char *new_buf; - *buffer_size = size_needed; - new_buf = realloc (*buffer, *buffer_size); - - if (new_buf == NULL) - { - save = errno; - free (*buffer); - __set_errno (save); - *buffer = NULL; - *buffer_size = 0; - *result = NULL; - goto done; - } - *buffer = new_buf; - } - - memset (*buffer, '\0', size_needed); - - host_addr = (host_addr_t *) *buffer; - h_addr_ptrs = (host_addr_list_t *) - ((char *) host_addr + sizeof (*host_addr)); - hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs); - - for (cp = name;; ++cp) - { - if (!*cp) - { - if (*--cp == '.') - break; - - /* All-IPv6-legal, no dot at the end. Fake up a - hostent as if we'd actually done a lookup. */ - if (inet_pton (AF_INET6, name, host_addr) <= 0) - { - *h_errnop = HOST_NOT_FOUND; - if (buffer_size) - *result = NULL; - goto done; - } - - resbuf->h_name = strcpy (hostname, name); - h_alias_ptr[0] = NULL; - resbuf->h_aliases = h_alias_ptr; - (*h_addr_ptrs)[0] = (char *) host_addr; - (*h_addr_ptrs)[1] = (char *) 0; - resbuf->h_addr_list = *h_addr_ptrs; - resbuf->h_addrtype = AF_INET6; - resbuf->h_length = addr_size; - *h_errnop = NETDB_SUCCESS; - if (buffer_size == NULL) - *status = NSS_STATUS_SUCCESS; - else - *result = resbuf; - goto done; - } - - if (!isxdigit (*cp) && *cp != ':' && *cp != '.') - break; - } - } - } - - return 0; - -done: - return 1; -} -libc_hidden_def (__nss_hostname_digits_dots) diff --git a/newlib/libc/sys/linux/net/ether_addr.c b/newlib/libc/sys/linux/net/ether_addr.c new file mode 100644 index 000000000..7d2b19f69 --- /dev/null +++ b/newlib/libc/sys/linux/net/ether_addr.c @@ -0,0 +1,231 @@ +/* + * Copyright (c) 1995 + * Bill Paul . 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 + * Center for Telecommunications Research + * Columbia University, New York City + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef YP +#include +#include +#include +#endif + +#ifndef _PATH_ETHERS +#define _PATH_ETHERS "/etc/ethers" +#endif + +/* + * Parse a string of text containing an ethernet address and hostname + * and separate it into its component parts. + */ +int +ether_line(l, e, hostname) + const char *l; + struct ether_addr *e; + char *hostname; +{ + int i, o[6]; + + i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2], + &o[3], &o[4], &o[5], + hostname); + if (i != 7) + return (i); + + for (i=0; i<6; i++) + e->octet[i] = o[i]; + return (0); +} + +/* + * Convert an ASCII representation of an ethernet address to + * binary form. + */ +struct +ether_addr *ether_aton(a) + const char *a; +{ + int i; + static struct ether_addr o; + unsigned int o0, o1, o2, o3, o4, o5; + + i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5); + + if (i != 6) + return (NULL); + + o.octet[0]=o0; + o.octet[1]=o1; + o.octet[2]=o2; + o.octet[3]=o3; + o.octet[4]=o4; + o.octet[5]=o5; + + return ((struct ether_addr *)&o); +} + +/* + * Convert a binary representation of an ethernet address to + * an ASCII string. + */ +char +*ether_ntoa(n) + const struct ether_addr *n; +{ + int i; + static char a[18]; + + i = sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x", + n->octet[0], n->octet[1], n->octet[2], + n->octet[3], n->octet[4], n->octet[5]); + if (i < 17) + return (NULL); + return ((char *)&a); +} + +/* + * Map an ethernet address to a hostname. Use either /etc/ethers or + * NIS/YP. + */ +int +ether_ntohost(hostname, e) + char *hostname; + const struct ether_addr *e; +{ + FILE *fp; + char buf[BUFSIZ + 2]; + struct ether_addr local_ether; + char local_host[MAXHOSTNAMELEN]; +#ifdef YP + char *result; + int resultlen; + char *ether_a; + char *yp_domain; +#endif + if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) + return (1); + + while (fgets(buf,BUFSIZ,fp)) { + if (buf[0] == '#') + continue; +#ifdef YP + if (buf[0] == '+') { + if (yp_get_default_domain(&yp_domain)) + continue; + ether_a = ether_ntoa(e); + if (yp_match(yp_domain, "ethers.byaddr", ether_a, + strlen(ether_a), &result, &resultlen)) { + continue; + } + strncpy(buf, result, resultlen); + buf[resultlen] = '\0'; + free(result); + } +#endif + if (!ether_line(buf, &local_ether, local_host)) { + if (!memcmp((char *)&local_ether.octet[0], + (char *)&e->octet[0], 6)) { + /* We have a match */ + strcpy(hostname, local_host); + fclose(fp); + return(0); + } + } + } + fclose(fp); + return (1); +} + +/* + * Map a hostname to an ethernet address using /etc/ethers or + * NIS/YP. + */ +int +ether_hostton(hostname, e) + const char *hostname; + struct ether_addr *e; +{ + FILE *fp; + char buf[BUFSIZ + 2]; + struct ether_addr local_ether; + char local_host[MAXHOSTNAMELEN]; +#ifdef YP + char *result; + int resultlen; + char *yp_domain; +#endif + if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) + return (1); + + while (fgets(buf,BUFSIZ,fp)) { + if (buf[0] == '#') + continue; +#ifdef YP + if (buf[0] == '+') { + if (yp_get_default_domain(&yp_domain)) + continue; + if (yp_match(yp_domain, "ethers.byname", hostname, + strlen(hostname), &result, &resultlen)) { + continue; + } + strncpy(buf, result, resultlen); + buf[resultlen] = '\0'; + free(result); + } +#endif + if (!ether_line(buf, &local_ether, local_host)) { + if (!strcmp(hostname, local_host)) { + /* We have a match */ + bcopy((char *)&local_ether.octet[0], + (char *)&e->octet[0], 6); + fclose(fp); + return(0); + } + } + } + fclose(fp); + return (1); +} diff --git a/newlib/libc/sys/linux/net/ether_aton.c b/newlib/libc/sys/linux/net/ether_aton.c deleted file mode 100644 index 071f329a6..000000000 --- a/newlib/libc/sys/linux/net/ether_aton.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -struct ether_addr * -ether_aton (const char *asc) -{ - static struct ether_addr result; - - return ether_aton_r (asc, &result); -} diff --git a/newlib/libc/sys/linux/net/ether_aton_r.c b/newlib/libc/sys/linux/net/ether_aton_r.c deleted file mode 100644 index 1e9f15a12..000000000 --- a/newlib/libc/sys/linux/net/ether_aton_r.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include - - -struct ether_addr * -ether_aton_r (const char *asc, struct ether_addr *addr) -{ - size_t cnt; - - for (cnt = 0; cnt < 6; ++cnt) - { - unsigned int number; - char ch; - - ch = _tolower (*asc++); - if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) - return NULL; - number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); - - ch = _tolower (*asc); - if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch))) - { - ++asc; - if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) - return NULL; - number <<= 4; - number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); - - ch = *asc; - if (cnt < 5 && ch != ':') - return NULL; - } - - /* Store result. */ - addr->ether_addr_octet[cnt] = (unsigned char) number; - - /* Skip ':'. */ - ++asc; - } - - return addr; -} -libc_hidden_def (ether_aton_r) diff --git a/newlib/libc/sys/linux/net/ether_hton.c b/newlib/libc/sys/linux/net/ether_hton.c deleted file mode 100644 index a226d9f5f..000000000 --- a/newlib/libc/sys/linux/net/ether_hton.c +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (C) 1996, 1999, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#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; -} diff --git a/newlib/libc/sys/linux/net/ether_line.c b/newlib/libc/sys/linux/net/ether_line.c deleted file mode 100644 index 8be593ea9..000000000 --- a/newlib/libc/sys/linux/net/ether_line.c +++ /dev/null @@ -1,81 +0,0 @@ -/* 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 -#include -#include -#include -#include - - -int -ether_line (const char *line, struct ether_addr *addr, char *hostname) -{ - size_t cnt; - char *cp; - - for (cnt = 0; cnt < 6; ++cnt) - { - unsigned int number; - char ch; - - ch = _tolower (*line++); - if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) - return -1; - number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); - - ch = _tolower (*line); - if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch))) - { - ++line; - if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) - return -1; - number <<= 4; - number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); - - ch = *line; - if (cnt < 5 && ch != ':') - return -1; - } - - /* Store result. */ - addr->ether_addr_octet[cnt] = (unsigned char) number; - - /* Skip ':'. */ - if (ch != '\0') - ++line; - } - - /* Remove trailing white space. */ - cp = strchr (line, '#'); - if (cp == NULL) - cp = line + strlen (line); - while (cp > line && isspace (cp[-1])) - --cp; - - if (cp == line) - /* No hostname. */ - return -1; - - /* XXX This can cause trouble because the hostname might be too long - but we have no possibility to check it here. */ - memcpy (hostname, line, cp - line); - hostname [cp - line] = '\0'; - - return 0; -} diff --git a/newlib/libc/sys/linux/net/ether_ntoa.c b/newlib/libc/sys/linux/net/ether_ntoa.c deleted file mode 100644 index 815aebe0f..000000000 --- a/newlib/libc/sys/linux/net/ether_ntoa.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include - - -char * -ether_ntoa (const struct ether_addr *addr) -{ - static char asc[18]; - - return ether_ntoa_r (addr, asc); -} diff --git a/newlib/libc/sys/linux/net/ether_ntoa_r.c b/newlib/libc/sys/linux/net/ether_ntoa_r.c deleted file mode 100644 index c5f347c63..000000000 --- a/newlib/libc/sys/linux/net/ether_ntoa_r.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1996,97,2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include - - -char * -ether_ntoa_r (const struct ether_addr *addr, char *buf) -{ - sprintf (buf, "%x:%x:%x:%x:%x:%x", - addr->ether_addr_octet[0], addr->ether_addr_octet[1], - addr->ether_addr_octet[2], addr->ether_addr_octet[3], - addr->ether_addr_octet[4], addr->ether_addr_octet[5]); - return buf; -} -libc_hidden_def (ether_ntoa_r) diff --git a/newlib/libc/sys/linux/net/ether_ntoh.c b/newlib/libc/sys/linux/net/ether_ntoh.c deleted file mode 100644 index de8c41ef7..000000000 --- a/newlib/libc/sys/linux/net/ether_ntoh.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#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; -} diff --git a/newlib/libc/sys/linux/net/etherent.h b/newlib/libc/sys/linux/net/etherent.h deleted file mode 100644 index 95a58b48c..000000000 --- a/newlib/libc/sys/linux/net/etherent.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Because the `ethers' lookup does not fit so well in the scheme we - define a dummy struct here which helps us to use the available - functions. */ -struct etherent -{ - const char *e_name; - struct ether_addr e_addr; -}; - diff --git a/newlib/libc/sys/linux/net/ethers-lookup.c b/newlib/libc/sys/linux/net/ethers-lookup.c deleted file mode 100644 index d31ea841a..000000000 --- a/newlib/libc/sys/linux/net/ethers-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME ethers - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/ethers.3 b/newlib/libc/sys/linux/net/ethers.3 new file mode 100644 index 000000000..7b7866fd9 --- /dev/null +++ b/newlib/libc/sys/linux/net/ethers.3 @@ -0,0 +1,197 @@ +.\" Copyright (c) 1995 +.\" Bill Paul . All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Bill Paul. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.19 2002/01/14 16:59:00 ru Exp $ +.\" +.Dd April 12, 1995 +.Dt ETHERS 3 +.Os +.Sh NAME +.Nm ethers , +.Nm ether_line , +.Nm ether_aton , +.Nm ether_ntoa , +.Nm ether_ntohost , +.Nm ether_hostton +.Nd Ethernet address conversion and lookup routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/ethernet.h +.Ft int +.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" +.Ft struct ether_addr * +.Fn ether_aton "const char *a" +.Ft char * +.Fn ether_ntoa "const struct ether_addr *n" +.Ft int +.Fn ether_ntohost "char *hostname" "const struct ether_addr *e" +.Ft int +.Fn ether_hostton "const char *hostname" "struct ether_addr *e" +.Sh DESCRIPTION +These functions operate on ethernet addresses using an +.Ar ether_addr +structure, which is defined in the header file +.Aq Pa netinet/if_ether.h : +.Bd -literal -offset indent +/* + * The number of bytes in an ethernet (MAC) address. + */ +#define ETHER_ADDR_LEN 6 + +/* + * Structure of a 48-bit Ethernet address. + */ +struct ether_addr { + u_char octet[ETHER_ADDR_LEN]; +}; +.Ed +.Pp +The function +.Fn ether_line +scans +.Ar l , +an +.Tn ASCII +string in +.Xr ethers 5 +format and sets +.Ar e +to the ethernet address specified in the string and +.Ar h +to the hostname. +This function is used to parse lines from +.Pa /etc/ethers +into their component parts. +.Pp +The +.Fn ether_aton +function converts an +.Tn ASCII +representation of an ethernet address into an +.Ar ether_addr +structure. +Likewise, +.Fn ether_ntoa +converts an ethernet address specified as an +.Ar ether_addr +structure into an +.Tn ASCII +string. +.Pp +The +.Fn ether_ntohost +and +.Fn ether_hostton +functions map ethernet addresses to their corresponding hostnames +as specified in the +.Pa /etc/ethers +database. +.Fn ether_ntohost +converts from ethernet address to hostname, and +.Fn ether_hostton +converts from hostname to ethernet address. +.Sh RETURN VALUES +.Fn ether_line +returns zero on success and non-zero if it was unable to parse +any part of the supplied line +.Ar l . +It returns the extracted ethernet address in the supplied +.Ar ether_addr +structure +.Ar e +and the hostname in the supplied string +.Ar h . +.Pp +On success, +.Fn ether_ntoa +returns a pointer to a string containing an +.Tn ASCII +representation of an ethernet address. +If it is unable to convert +the supplied +.Ar ether_addr +structure, it returns a +.Dv NULL +pointer. +Likewise, +.Fn ether_aton +returns a pointer to an +.Ar ether_addr +structure on success and a +.Dv NULL +pointer on failure. +.Pp +The +.Fn ether_ntohost +and +.Fn ether_hostton +functions both return zero on success or non-zero if they were +unable to find a match in the +.Pa /etc/ethers +database. +.Sh NOTES +The user must insure that the hostname strings passed to the +.Fn ether_line , +.Fn ether_ntohost +and +.Fn ether_hostton +functions are large enough to contain the returned hostnames. +.Sh NIS INTERACTION +If the +.Pa /etc/ethers +contains a line with a single + in it, the +.Fn ether_ntohost +and +.Fn ether_hostton +functions will attempt to consult the NIS +.Pa ethers.byname +and +.Pa ethers.byaddr +maps in addition to the data in the +.Pa /etc/ethers +file. +.Sh SEE ALSO +.Xr ethers 5 , +.Xr yp 8 +.Sh BUGS +The +.Fn ether_aton +and +.Fn ether_ntoa +functions returns values that are stored in static memory areas +which may be overwritten the next time they are called. +.Sh HISTORY +This particular implementation of the +.Nm +library functions were written for and first appeared in +.Fx 2.1 . diff --git a/newlib/libc/sys/linux/net/function.def b/newlib/libc/sys/linux/net/function.def deleted file mode 100644 index 59a06a2d3..000000000 --- a/newlib/libc/sys/linux/net/function.def +++ /dev/null @@ -1,78 +0,0 @@ -/* List of functions defined for static NSS in GNU C Library. - Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* - This is a minimal config. Only services `files' and `dns' are supported. -*/ - -/* aliases */ -DEFINE_ENT (files, alias) -DEFINE_GETBY (files, alias, name) - -/* ethers */ -DEFINE_ENT (files, ether) - -/* group */ -DEFINE_ENT (files, gr) -DEFINE_GET (files, grgid) -DEFINE_GET (files, grnam) - -/* hosts */ -DEFINE_ENT (files, host) -DEFINE_GETBY (files, host, addr) -DEFINE_GETBY (files, host, name) -DEFINE_GET (files, hostton) -DEFINE_GET (files, ntohost) -DEFINE_GETBY (dns, host, addr) -DEFINE_GETBY (dns, host, name) -DEFINE_GETBY (dns, host, name2) - -/* netgroup */ -DEFINE_ENT (files, netgr) - -/* networks */ -DEFINE_ENT (files, net) -DEFINE_GETBY (files, net, name) -DEFINE_GETBY (files, net, addr) -DEFINE_GETBY (dns, net, name) -DEFINE_GETBY (dns, net, addr) - -/* protocols */ -DEFINE_ENT (files, proto) -DEFINE_GETBY (files, proto, name) -DEFINE_GETBY (files, proto, number) - -/* passwd */ -DEFINE_ENT (files, pw) -DEFINE_GET (files, pwnam) -DEFINE_GET (files, pwuid) - -/* rpc */ -DEFINE_ENT (files, rpc) -DEFINE_GETBY (files, rpc, name) -DEFINE_GETBY (files, rpc, number) - -/* services */ -DEFINE_ENT (files, serv) -DEFINE_GETBY (files, serv, name) -DEFINE_GETBY (files, serv, port) - -/* shadow */ -DEFINE_ENT (files, sp) -DEFINE_GET (files, spnam) diff --git a/newlib/libc/sys/linux/net/getXXbyYY.c b/newlib/libc/sys/linux/net/getXXbyYY.c deleted file mode 100644 index 4fa25fa14..000000000 --- a/newlib/libc/sys/linux/net/getXXbyYY.c +++ /dev/null @@ -1,156 +0,0 @@ -/* 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 -#include -#define _IO_MTSAFE_IO -#include -#include -#include - -#include "nsswitch.h" - -/*******************************************************************\ -|* Here we assume several symbols to be defined: *| -|* *| -|* LOOKUP_TYPE - the return type of the function *| -|* *| -|* FUNCTION_NAME - name of the non-reentrant function *| -|* *| -|* DATABASE_NAME - name of the database the function accesses *| -|* (e.g., host, services, ...) *| -|* *| -|* ADD_PARAMS - additional parameter, can vary in number *| -|* *| -|* ADD_VARIABLES - names of additional parameter *| -|* *| -|* BUFLEN - length of buffer allocated for the non *| -|* reentrant version *| -|* *| -|* Optionally the following vars can be defined: *| -|* *| -|* NEED_H_ERRNO - an extra parameter will be passed to point to *| -|* the global `h_errno' variable. *| -|* *| -\*******************************************************************/ - -/* To make the real sources a bit prettier. */ -#define REENTRANT_NAME APPEND_R (FUNCTION_NAME) -#define APPEND_R(name) APPEND_R1 (name) -#define APPEND_R1(name) name##_r -#define INTERNAL(name) INTERNAL1 (name) -#define INTERNAL1(name) __##name - -/* Sometimes we need to store error codes in the `h_errno' variable. */ -#ifdef NEED_H_ERRNO -# define H_ERRNO_PARM , int *h_errnop -# define H_ERRNO_VAR , &h_errno_tmp -# define H_ERRNO_VAR_P &h_errno_tmp -#else -# define H_ERRNO_PARM -# define H_ERRNO_VAR -# define H_ERRNO_VAR_P NULL -#endif - -#ifdef HAVE_AF -# define AF_VAL af -#else -# define AF_VAL AF_INET -#endif - -/* Prototype for reentrant version we use here. */ -extern int INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, - char *buffer, size_t buflen, - LOOKUP_TYPE **result H_ERRNO_PARM); - -/* We need to protect the dynamic buffer handling. */ -__libc_lock_define_initialized (static, lock); - -/* This points to the static buffer used. */ -libc_freeres_ptr (static char *buffer); - - -LOOKUP_TYPE * -FUNCTION_NAME (ADD_PARAMS) -{ - static size_t buffer_size; - static LOOKUP_TYPE resbuf; - LOOKUP_TYPE *result; -#ifdef NEED_H_ERRNO - int h_errno_tmp = 0; -#endif - - /* Get lock. */ - __libc_lock_lock (lock); - - if (buffer == NULL) - { - buffer_size = BUFLEN; - buffer = (char *) malloc (buffer_size); - } - -#ifdef HANDLE_DIGITS_DOTS - if (buffer != NULL) - { - if (__nss_hostname_digits_dots (name, &resbuf, &buffer, - &buffer_size, 0, &result, NULL, AF_VAL, - H_ERRNO_VAR_P)) - goto done; - } -#endif - - while (buffer != NULL - && (INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, &resbuf, buffer, - buffer_size, &result H_ERRNO_VAR) - == ERANGE) -#ifdef NEED_H_ERRNO - && h_errno_tmp == NETDB_INTERNAL -#endif - ) - { - char *new_buf; - buffer_size *= 2; - new_buf = (char *) realloc (buffer, buffer_size); - if (new_buf == NULL) - { - /* We are out of memory. Free the current buffer so that the - process gets a chance for a normal termination. */ - free (buffer); - errno = (ENOMEM); - } - buffer = new_buf; - } - - if (buffer == NULL) - result = NULL; - -#ifdef HANDLE_DIGITS_DOTS -done: -#endif - /* Release lock. */ - __libc_lock_unlock (lock); - -#ifdef NEED_H_ERRNO - if (h_errno_tmp != 0) - h_errno = (h_errno_tmp); -#endif - - return result; -} - -static_link_warning (FUNCTION_NAME) diff --git a/newlib/libc/sys/linux/net/getXXbyYY_r.c b/newlib/libc/sys/linux/net/getXXbyYY_r.c deleted file mode 100644 index 326df94b7..000000000 --- a/newlib/libc/sys/linux/net/getXXbyYY_r.c +++ /dev/null @@ -1,292 +0,0 @@ -/* Copyright (C) 1996-2002, 2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include "nsswitch.h" -#ifdef USE_NSCD -# include -#endif -#ifdef NEED__RES_HCONF -# include "res_hconf.h" -#endif -#ifdef NEED__RES -# include -#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 -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2) -#define OLD(name) OLD1 (name) -#define OLD1(name) __old_##name - -int -attribute_compat_text_section -OLD (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, - size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM) -{ - int ret = INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, resbuf, buffer, - buflen, result H_ERRNO_VAR); - - if (ret != 0 || result == NULL) - ret = -1; - - return ret; -} - -#define do_symbol_version(real, name, version) \ - compat_symbol (libc, real, name, version) -do_symbol_version (OLD (REENTRANT_NAME), REENTRANT_NAME, GLIBC_2_0); -#endif - -/* As INTERNAL (REENTRANT_NAME) may be hidden, we need an alias - in between so that the REENTRANT_NAME@@GLIBC_2.1.2 is not - hidden too. */ -strong_alias (INTERNAL (REENTRANT_NAME), NEW (REENTRANT_NAME)); - -#define do_default_symbol_version(real, name, version) \ - versioned_symbol (libc, real, name, version) -do_default_symbol_version (NEW (REENTRANT_NAME), - REENTRANT_NAME, GLIBC_2_1_2); - -static_link_warning (REENTRANT_NAME) diff --git a/newlib/libc/sys/linux/net/getXXent.c b/newlib/libc/sys/linux/net/getXXent.c deleted file mode 100644 index a2d5f401b..000000000 --- a/newlib/libc/sys/linux/net/getXXent.c +++ /dev/null @@ -1,96 +0,0 @@ -/* 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 -#define _IO_MTSAFE_IO -#include -#include - -#include "nsswitch.h" - -/*******************************************************************\ -|* Here we assume several symbols to be defined: *| -|* *| -|* LOOKUP_TYPE - the return type of the function *| -|* *| -|* GETFUNC_NAME - name of the non-reentrant getXXXent function *| -|* *| -|* BUFLEN - size of static buffer *| -|* *| -|* Optionally the following vars can be defined: *| -|* *| -|* NEED_H_ERRNO - an extra parameter will be passed to point to *| -|* the global `h_errno' variable. *| -|* *| -\*******************************************************************/ - -/* To make the real sources a bit prettier. */ -#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME) -#define APPEND_R(name) APPEND_R1 (name) -#define APPEND_R1(name) name##_r -#define INTERNAL(name) INTERNAL1 (name) -#define INTERNAL1(name) __##name - -/* Sometimes we need to store error codes in the `h_errno' variable. */ -#ifdef NEED_H_ERRNO -# define H_ERRNO_PARM , int *h_errnop -# define H_ERRNO_VAR &h_errno -#else -# define H_ERRNO_PARM -# define H_ERRNO_VAR NULL -#endif - -/* Prototype of the reentrant version. */ -extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, - size_t buflen, LOOKUP_TYPE **result - H_ERRNO_PARM); - -/* We need to protect the dynamic buffer handling. */ -__libc_lock_define_initialized (static, lock); - -/* This points to the static buffer used. */ -libc_freeres_ptr (static char *buffer); - - -LOOKUP_TYPE * -GETFUNC_NAME (void) -{ - static size_t buffer_size; - static union - { - LOOKUP_TYPE l; - void *ptr; - } resbuf; - LOOKUP_TYPE *result; - int save; - - /* Get lock. */ - __libc_lock_lock (lock); - - result = (LOOKUP_TYPE *) - __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME), - &resbuf.ptr, &buffer, BUFLEN, &buffer_size, - H_ERRNO_VAR); - - save = errno; - __libc_lock_unlock (lock); - __set_errno (save); - return result; -} - -static_link_warning (GETFUNC_NAME) diff --git a/newlib/libc/sys/linux/net/getXXent_r.c b/newlib/libc/sys/linux/net/getXXent_r.c deleted file mode 100644 index e0228e40e..000000000 --- a/newlib/libc/sys/linux/net/getXXent_r.c +++ /dev/null @@ -1,209 +0,0 @@ -/* 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 , 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 -#define _IO_MTSAFE_IO -#include - -#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 -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2) -#define OLD(name) OLD1 (name) -#define OLD1(name) __old_##name - -int -attribute_compat_text_section -OLD (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen, - LOOKUP_TYPE **result H_ERRNO_PARM) -{ - int ret = INTERNAL (REENTRANT_GETNAME) (resbuf, buffer, buflen, - result H_ERRNO_VAR); - - if (ret != 0) - ret = -1; - - return ret; -} - -#define do_symbol_version(real, name, version) \ - compat_symbol (libc, real, name, version) -do_symbol_version (OLD (REENTRANT_GETNAME), REENTRANT_GETNAME, GLIBC_2_0); -#endif - -/* As INTERNAL (REENTRANT_GETNAME) may be hidden, we need an alias - in between so that the REENTRANT_GETNAME@@GLIBC_2.1.2 is not - hidden too. */ -strong_alias (INTERNAL (REENTRANT_GETNAME), NEW (REENTRANT_GETNAME)); - -#define do_default_symbol_version(real, name, version) \ - versioned_symbol (libc, real, name, version) -do_default_symbol_version (NEW (REENTRANT_GETNAME), - REENTRANT_GETNAME, GLIBC_2_1_2); - -static_link_warning (SETFUNC_NAME) -static_link_warning (ENDFUNC_NAME) -static_link_warning (REENTRANT_GETNAME) diff --git a/newlib/libc/sys/linux/net/getaddrinfo.3 b/newlib/libc/sys/linux/net/getaddrinfo.3 new file mode 100644 index 000000000..eca8b03b2 --- /dev/null +++ b/newlib/libc/sys/linux/net/getaddrinfo.3 @@ -0,0 +1,620 @@ +.\" $FreeBSD: src/lib/libc/net/getaddrinfo.3,v 1.18 2002/04/19 04:46:20 suz Exp $ +.\" $KAME: getaddrinfo.3,v 1.31 2001/08/05 18:19:38 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETADDRINFO 3 +.Os +.\" +.Sh NAME +.Nm getaddrinfo , +.Nm freeaddrinfo , +.Nm gai_strerror +.Nd nodename-to-address translation in protocol-independent manner +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft int +.Fn getaddrinfo "const char *nodename" "const char *servname" \ +"const struct addrinfo *hints" "struct addrinfo **res" +.Ft void +.Fn freeaddrinfo "struct addrinfo *ai" +.Ft "char *" +.Fn gai_strerror "int ecode" +.\" +.Sh DESCRIPTION +The +.Fn getaddrinfo +function is defined for protocol-independent nodename-to-address translation. +It performs the functionality of +.Xr gethostbyname 3 +and +.Xr getservbyname 3 , +but in a more sophisticated manner. +.Pp +The +.Li addrinfo +structure is defined as a result of including the +.Aq Pa netdb.h +header: +.Bd -literal -offset +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for nodename */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; +.Ed +.Pp +The +.Fa nodename +and +.Fa servname +arguments are pointers to null-terminated strings or +.Dv NULL . +One or both of these two arguments must be a +.Pf non Dv -NULL +pointer. +In the normal client scenario, both the +.Fa nodename +and +.Fa servname +are specified. +In the normal server scenario, only the +.Fa servname +is specified. +A +.Pf non Dv -NULL +.Fa nodename +string can be either a node name or a numeric host address string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +A +.Pf non Dv -NULL +.Fa servname +string can be either a service name or a decimal port number. +.Pp +The caller can optionally pass an +.Li addrinfo +structure, pointed to by the third argument, +to provide hints concerning the type of socket that the caller supports. +In this +.Fa hints +structure all members other than +.Fa ai_flags , +.Fa ai_family , +.Fa ai_socktype , +and +.Fa ai_protocol +must be zero or a +.Dv NULL +pointer. +A value of +.Dv PF_UNSPEC +for +.Fa ai_family +means the caller will accept any protocol family. +A value of 0 for +.Fa ai_socktype +means the caller will accept any socket type. +A value of 0 for +.Fa ai_protocol +means the caller will accept any protocol. +For example, if the caller handles only TCP and not UDP, then the +.Fa ai_socktype +member of the hints structure should be set to +.Dv SOCK_STREAM +when +.Fn getaddrinfo +is called. +If the caller handles only IPv4 and not IPv6, then the +.Fa ai_family +member of the +.Fa hints +structure should be set to +.Dv PF_INET +when +.Fn getaddrinfo +is called. +If the third argument to +.Fn getaddrinfo +is a +.Dv NULL +pointer, this is the same as if the caller had filled in an +.Li addrinfo +structure initialized to zero with +.Fa ai_family +set to +.Dv PF_UNSPEC . +.Pp +Upon successful return a pointer to a linked list of one or more +.Li addrinfo +structures is returned through the final argument. +The caller can process each +.Li addrinfo +structure in this list by following the +.Fa ai_next +pointer, until a +.Dv NULL +pointer is encountered. +In each returned +.Li addrinfo +structure the three members +.Fa ai_family , +.Fa ai_socktype , +and +.Fa ai_protocol +are the corresponding arguments for a call to the +.Fn socket +function. +In each +.Li addrinfo +structure the +.Fa ai_addr +member points to a filled-in socket address structure whose length is +specified by the +.Fa ai_addrlen +member. +.Pp +If the +.Dv AI_PASSIVE +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then the caller plans to use the returned socket address +structure in a call to +.Fn bind . +In this case, if the +.Fa nodename +argument is a +.Dv NULL +pointer, then the IP address portion of the socket +address structure will be set to +.Dv INADDR_ANY +for an IPv4 address or +.Dv IN6ADDR_ANY_INIT +for an IPv6 address. +.Pp +If the +.Dv AI_PASSIVE +bit is not set in the +.Fa ai_flags +member of the +.Fa hints +structure, then the returned socket address structure will be ready for a +call to +.Fn connect +(for a connection-oriented protocol) +or either +.Fn connect , +.Fn sendto , +or +.Fn sendmsg +(for a connectionless protocol). +In this case, if the +.Fa nodename +argument is a +.Dv NULL +pointer, then the IP address portion of the +socket address structure will be set to the loopback address. +.Pp +If the +.Dv AI_CANONNAME +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then upon successful return the +.Fa ai_canonname +member of the first +.Li addrinfo +structure in the linked list will point to a null-terminated string +containing the canonical name of the specified +.Fa nodename . +.Pp +If the +.Dv AI_NUMERICHOST +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then a +.Pf non Dv -NULL +.Fa nodename +string must be a numeric host address string. +Otherwise an error of +.Dv EAI_NONAME +is returned. +This flag prevents any type of name resolution service (e.g., the DNS) +from being called. +.Pp +The arguments to +.Fn getaddrinfo +must be sufficiently consistent and unambiguous. +Here are some problem cases you may encounter: +.Bl -bullet +.It +.Fn getaddrinfo +will fail if the members in the +.Fa hints +structure are not consistent. +For example, for internet address families, +.Fn getaddrinfo +will fail if you specify +.Dv SOCK_STREAM +to +.Fa ai_socktype +while you specify +.Dv IPPROTO_UDP +to +.Fa ai_protocol . +.It +If you specify a +.Fa servname +which is defined only for certain +.Fa ai_socktype , +.Fn getaddrinfo +will fail because the arguments are not consistent. +For example, +.Fn getaddrinfo +will return an error if you ask for +.Dq Li tftp +service on +.Dv SOCK_STREAM . +.It +For internet address families, if you specify +.Fa servname +while you set +.Fa ai_socktype +to +.Dv SOCK_RAW , +.Fn getaddrinfo +will fail, because service names are not defined for the internet +.Dv SOCK_RAW +space. +.It +If you specify numeric +.Fa servname , +while leaving +.Fa ai_socktype +and +.Fa ai_protocol +unspecified, +.Fn getaddrinfo +will fail. +This is because the numeric +.Fa servname +does not identify any socket type, and +.Fn getaddrinfo +is not allowed to glob the argument in such case. +.El +.Pp +All of the information returned by +.Fn getaddrinfo +is dynamically allocated: +the +.Li addrinfo +structures, the socket address structures, and canonical node name +strings pointed to by the addrinfo structures. +To return this information to the system the function +.Fn freeaddrinfo +is called. +The +.Fa addrinfo +structure pointed to by the +.Fa ai argument +is freed, along with any dynamic storage pointed to by the structure. +This operation is repeated until a +.Dv NULL +.Fa ai_next +pointer is encountered. +.Pp +To aid applications in printing error messages based on the +.Dv EAI_xxx +codes returned by +.Fn getaddrinfo , +.Fn gai_strerror +is defined. +The argument is one of the +.Dv EAI_xxx +values defined earlier and the return value points to a string describing +the error. +If the argument is not one of the +.Dv EAI_xxx +values, the function still returns a pointer to a string whose contents +indicate an unknown error. +.\" +.Sh EXTENSIONS +This implementation supports numeric IPv6 address notation with the +experimental scope identifier. +By appending a percent sign and scope identifier to the address, you +can specify the value of the +.Li sin6_scope_id +field of the socket address. +This makes management of scoped address easier, +and allows cut-and-paste input of scoped addresses. +.Pp +At the moment the code supports only link-local addresses in this format. +The scope identifier is hardcoded to name of hardware interface associated +with the link, +(such as +.Li ne0 ) . +For example, +.Dq Li fe80::1%ne0 , +which means +.Do +.Li fe80::1 +on the link associated with the +.Li ne0 +interface +.Dc . +.Pp +This implementation is still very experimental and non-standard. +The current implementation assumes a one-to-one relationship between +interfaces and links, which is not necessarily true according to the +specification. +.\" +.Sh EXAMPLES +The following code tries to connect to +.Dq Li www.kame.net +service +.Dq Li http . +via stream socket. +It loops through all the addresses available, regardless of the address family. +If the destination resolves to an IPv4 address, it will use an +.Dv AF_INET +socket. +Similarly, if it resolves to IPv6, an +.Dv AF_INET6 +socket is used. +Observe that there is no hardcoded reference to particular address family. +The code works even if +.Fn getaddrinfo +returns addresses that are not IPv4/v6. +.Bd -literal -offset indent +struct addrinfo hints, *res, *res0; +int error; +int s; +const char *cause = NULL; + +memset(&hints, 0, sizeof(hints)); +hints.ai_family = PF_UNSPEC; +hints.ai_socktype = SOCK_STREAM; +error = getaddrinfo("www.kame.net", "http", &hints, &res0); +if (error) { + errx(1, "%s", gai_strerror(error)); + /*NOTREACHED*/ +} +s = -1; +cause = "no addresses"; +errno = EADDRNOTAVAIL; +for (res = res0; res; res = res->ai_next) { + s = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s < 0) { + cause = "socket"; + continue; + } + + if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { + cause = "connect"; + close(s); + s = -1; + continue; + } + + break; /* okay we got one */ +} +if (s < 0) { + err(1, cause); + /*NOTREACHED*/ +} +freeaddrinfo(res0); +.Ed +.Pp +The following example tries to open a wildcard listening socket onto service +.Dq Li http , +for all the address families available. +.Bd -literal -offset indent +struct addrinfo hints, *res, *res0; +int error; +int s[MAXSOCK]; +int nsock; +const char *cause = NULL; + +memset(&hints, 0, sizeof(hints)); +hints.ai_family = PF_UNSPEC; +hints.ai_socktype = SOCK_STREAM; +hints.ai_flags = AI_PASSIVE; +error = getaddrinfo(NULL, "http", &hints, &res0); +if (error) { + errx(1, "%s", gai_strerror(error)); + /*NOTREACHED*/ +} +nsock = 0; +for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { + s[nsock] = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s[nsock] < 0) { + cause = "socket"; + continue; + } + + if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) { + cause = "bind"; + close(s[nsock]); + continue; + } + + if (listen(s[nsock], SOMAXCONN) < 0) { + cause = "listen"; + close(s[nsock]); + continue; + } + + nsock++; +} +if (nsock == 0) { + err(1, cause); + /*NOTREACHED*/ +} +freeaddrinfo(res0); +.Ed +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +Error return status from +.Fn getaddrinfo +is zero on success and non-zero on errors. +Non-zero error codes are defined in +.Aq Pa netdb.h , +and as follows: +.Pp +.Bl -tag -width EAI_ADDRFAMILY -compact +.It Dv EAI_ADDRFAMILY +Address family for +.Fa nodename +not supported. +.It Dv EAI_AGAIN +Temporary failure in name resolution. +.It Dv EAI_BADFLAGS +Invalid value for +.Fa ai_flags . +.It Dv EAI_FAIL +Non-recoverable failure in name resolution. +.It Dv EAI_FAMILY +.Fa ai_family +not supported. +.It Dv EAI_MEMORY +Memory allocation failure. +.It Dv EAI_NODATA +No address associated with +.Fa nodename . +.It Dv EAI_NONAME +.Fa nodename +nor +.Fa servname +provided, or not known. +.It Dv EAI_SERVICE +.Fa servname +not supported for +.Fa ai_socktype . +.It Dv EAI_SOCKTYPE +.Fa ai_socktype +not supported. +.It Dv EAI_SYSTEM +System error returned in +.Va errno . +.It Dv EAI_BADHINTS +Invalid value for +.Fa hints . +.It Dv EAI_PROTOCOL +Resolved protocol is unknown. +.It Dv EAI_MAX +Unknown error. +.El +.Pp +If called with an appropriate argument, +.Fn gai_strerror +returns a pointer to a string describing the given error code. +If the argument is not one of the +.Dv EAI_xxx +values, the function still returns a pointer to a string whose contents +indicate an unknown error. +.\" +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr getnameinfo 3 , +.Xr getservbyname 3 , +.Xr hosts 5 , +.Xr resolv.conf 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.Rs +.%A Tatsuya Jinmei +.%A Atsushi Onoe +.%T "An Extension of Format for IPv6 Scoped Addresses" +.%R internet draft +.%N draft-ietf-ipngwg-scopedaddr-format-02.txt +.%O work in progress material +.Re +.Rs +.%A Craig Metz +.%T Protocol Independence Using the Sockets API +.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" +.%D June 2000 +.Re +.\" +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.\" +.Sh STANDARDS +The +.Fn getaddrinfo +function is defined in +.St -p1003.1g-2000 , +and documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. diff --git a/newlib/libc/sys/linux/net/getaddrinfo.c b/newlib/libc/sys/linux/net/getaddrinfo.c index 742d46c8f..97ba36209 100644 --- a/newlib/libc/sys/linux/net/getaddrinfo.c +++ b/newlib/libc/sys/linux/net/getaddrinfo.c @@ -1,1699 +1,1979 @@ -/* The Inner Net License, Version 2.00 - - The author(s) grant permission for redistribution and use in source and -binary forms, with or without modification, of the software and documentation -provided that the following conditions are met: - -0. If you receive a version of the software that is specifically labelled - as not being for redistribution (check the version message and/or README), - you are not permitted to redistribute that version of the software in any - way or form. -1. All terms of the all other applicable copyrights and licenses must be - followed. -2. Redistributions of source code must retain the authors' copyright - notice(s), this list of conditions, and the following disclaimer. -3. Redistributions in binary form must reproduce the authors' copyright - notice(s), this list of conditions, and the following disclaimer in the - documentation and/or other materials provided with the distribution. -4. [The copyright holder has authorized the removal of this clause.] -5. Neither the name(s) of the author(s) nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS ``AS IS'' AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - If these license terms cause you a real problem, contact the author. */ - -/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */ - -#include +/* $KAME: getaddrinfo.c,v 1.15 2000/07/09 04:37:24 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator. + * + * Issues to be discussed: + * - Thread safe-ness must be checked. + * - Return values. There are nonstandard return values defined and used + * in the source code. This is because RFC2553 is silent about which error + * code must be returned for which situation. + * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is + * invalid. + * current code - SEGV on freeaddrinfo(NULL) + * Note: + * - We use getipnodebyname() just for thread-safeness. There's no intent + * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to + * getipnodebyname(). + * - The code filters out AFs that are not supported by the kernel, + * when globbing NULL hostname (to loopback, or wildcard). Is it the right + * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG + * in ai_flags? + * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. + * (1) what should we do against numeric hostname (2) what should we do + * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? + * non-loopback address configured? global address configured? + * - To avoid search order issue, we have a big amount of code duplicate + * from gethnamaddr.c and some other places. The issues that there's no + * lower layer function to lookup "IPv4 or IPv6" record. Calling + * gethostbyname2 from getaddrinfo will end up in wrong search order, as + * follows: + * - The code makes use of following calls when asked to resolver with + * ai_family = PF_UNSPEC: + * getipnodebyname(host, AF_INET6); + * getipnodebyname(host, AF_INET); + * This will result in the following queries if the node is configure to + * prefer /etc/hosts than DNS: + * lookup /etc/hosts for IPv6 address + * lookup DNS for IPv6 address + * lookup /etc/hosts for IPv4 address + * lookup DNS for IPv4 address + * which may not meet people's requirement. + * The right thing to happen is to have underlying layer which does + * PF_UNSPEC lookup (lookup both) and return chain of addrinfos. + * This would result in a bit of code duplicate with _dns_ghbyname() and + * friends. + */ +/* + * diffs with other KAME platforms: + * - other KAME platforms already nuked FAITH ($GAI), but as FreeBSD + * 4.0-RELEASE supplies it, we still have the code here. + * - AI_ADDRCONFIG support is supplied + * - some of FreeBSD style (#define tabify and others) + * - classful IPv4 numeric (127.1) is allowed. + */ + +#include +#include + +#include "namespace.h" #include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include #include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "local.h" - -#ifdef HAVE_LIBIDN -extern int __idna_to_ascii_lz (const char *input, char **output, int flags); -extern int __idna_to_unicode_lzlz (const char *input, char **output, - int flags); -# include +#include +#include +#ifdef DEBUG +#include #endif -#define GAIH_OKIFUNSPEC 0x0100 -#define GAIH_EAI ~(GAIH_OKIFUNSPEC) +#include +#include +#include +#include "un-namespace.h" -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 +#if defined(__KAME__) && defined(INET6) +# define FAITH #endif -struct gaih_service - { - const char *name; - int num; - }; - -struct gaih_servtuple - { - struct gaih_servtuple *next; - int socktype; - int protocol; - int port; - }; - -static const struct gaih_servtuple nullserv; - -struct gaih_addrtuple - { - struct gaih_addrtuple *next; - char *name; - int family; - uint32_t addr[4]; - uint32_t scopeid; - }; - -struct gaih_typeproto - { - int socktype; - int protocol; - char name[4]; - int protoflag; - }; - -/* Values for `protoflag'. */ -#define GAI_PROTO_NOSERVICE 1 -#define GAI_PROTO_PROTOANY 2 - -static const struct gaih_typeproto gaih_inet_typeproto[] = -{ - { 0, 0, "", 0 }, - { SOCK_STREAM, IPPROTO_TCP, "tcp", 0 }, - { SOCK_DGRAM, IPPROTO_UDP, "udp", 0 }, - { SOCK_RAW, 0, "raw", GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE }, - { 0, 0, "", 0 } +#define SUCCESS 0 +#define ANY 0 +#define YES 1 +#define NO 0 + +static const char in_addrany[] = { 0, 0, 0, 0 }; +static const char in6_addrany[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +static const char in_loopback[] = { 127, 0, 0, 1 }; +static const char in6_loopback[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; -struct gaih - { - int family; - int (*gaih)(const char *name, const struct gaih_service *service, - const struct addrinfo *req, struct addrinfo **pai); - }; - -static const struct addrinfo default_hints = - { - .ai_flags = AI_DEFAULT, - .ai_family = PF_UNSPEC, - .ai_socktype = 0, - .ai_protocol = 0, - .ai_addrlen = 0, - .ai_addr = NULL, - .ai_canonname = NULL, - .ai_next = NULL - }; - -#define s6_addr32 __u6_addr.__u6_addr32 +static const struct afd { + int a_af; + int a_addrlen; + int a_socklen; + int a_off; + const char *a_addrany; + const char *a_loopback; + int a_scoped; +} afdl [] = { +#ifdef INET6 +#define N_INET6 0 + {PF_INET6, sizeof(struct in6_addr), + sizeof(struct sockaddr_in6), + offsetof(struct sockaddr_in6, sin6_addr), + in6_addrany, in6_loopback, 1}, +#define N_INET 1 +#else +#define N_INET 0 +#endif + {PF_INET, sizeof(struct in_addr), + sizeof(struct sockaddr_in), + offsetof(struct sockaddr_in, sin_addr), + in_addrany, in_loopback, 0}, + {0, 0, 0, 0, NULL, NULL, 0}, +}; + +struct explore { + int e_af; + int e_socktype; + int e_protocol; + const char *e_protostr; + int e_wild; +#define WILD_AF(ex) ((ex)->e_wild & 0x01) +#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) +#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) +}; +static const struct explore explore[] = { #if 0 -/* Using Unix sockets this way is a security risk. */ -static int -gaih_local (const char *name, const struct gaih_service *service, - const struct addrinfo *req, struct addrinfo **pai) -{ - struct utsname utsname; - - if ((name != NULL) && (req->ai_flags & AI_NUMERICHOST)) - return GAIH_OKIFUNSPEC | -EAI_NONAME; - - if ((name != NULL) || (req->ai_flags & AI_CANONNAME)) - if (uname (&utsname) < 0) - return -EAI_SYSTEM; - - if (name != NULL) - { - if (strcmp(name, "localhost") && - strcmp(name, "local") && - strcmp(name, "unix") && - strcmp(name, utsname.nodename)) - return GAIH_OKIFUNSPEC | -EAI_NONAME; - } - - if (req->ai_protocol || req->ai_socktype) - { - const struct gaih_typeproto *tp = gaih_inet_typeproto + 1; - - while (tp->name[0] - && ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0 - || (req->ai_socktype != 0 && req->ai_socktype != tp->socktype) - || (req->ai_protocol != 0 - && !(tp->protoflag & GAI_PROTO_PROTOANY) - && req->ai_protocol != tp->protocol))) - ++tp; - - if (! tp->name[0]) - { - if (req->ai_socktype) - return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE); - else - return (GAIH_OKIFUNSPEC | -EAI_SERVICE); - } - } - - *pai = malloc (sizeof (struct addrinfo) + sizeof (struct sockaddr_un) - + ((req->ai_flags & AI_CANONNAME) - ? (strlen(utsname.nodename) + 1): 0)); - if (*pai == NULL) - return -EAI_MEMORY; - - (*pai)->ai_next = NULL; - (*pai)->ai_flags = req->ai_flags; - (*pai)->ai_family = AF_LOCAL; - (*pai)->ai_socktype = req->ai_socktype ? req->ai_socktype : SOCK_STREAM; - (*pai)->ai_protocol = req->ai_protocol; - (*pai)->ai_addrlen = sizeof (struct sockaddr_un); - (*pai)->ai_addr = (void *) (*pai) + sizeof (struct addrinfo); - -#if SALEN - ((struct sockaddr_un *) (*pai)->ai_addr)->sun_len = - sizeof (struct sockaddr_un); -#endif /* SALEN */ - - ((struct sockaddr_un *)(*pai)->ai_addr)->sun_family = AF_LOCAL; - memset(((struct sockaddr_un *)(*pai)->ai_addr)->sun_path, 0, UNIX_PATH_MAX); - - if (service) - { - struct sockaddr_un *sunp = (struct sockaddr_un *) (*pai)->ai_addr; - - if (strchr (service->name, '/') != NULL) - { - if (strlen (service->name) >= sizeof (sunp->sun_path)) - return GAIH_OKIFUNSPEC | -EAI_SERVICE; - - strcpy (sunp->sun_path, service->name); - } - else - { - if (strlen (P_tmpdir "/") + 1 + strlen (service->name) >= - sizeof (sunp->sun_path)) - return GAIH_OKIFUNSPEC | -EAI_SERVICE; + { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, +#endif +#ifdef INET6 + { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, +#endif + { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, + { PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 }, + { -1, 0, 0, NULL, 0 }, +}; - __stpcpy (__stpcpy (sunp->sun_path, P_tmpdir "/"), service->name); - } - } - else - { - /* This is a dangerous use of the interface since there is a time - window between the test for the file and the actual creation - (done by the caller) in which a file with the same name could - be created. */ - char *buf = ((struct sockaddr_un *) (*pai)->ai_addr)->sun_path; - - if (__builtin_expect (__path_search (buf, L_tmpnam, NULL, NULL, 0), - 0) != 0 - || __builtin_expect (__gen_tempname (buf, __GT_NOCREATE), 0) != 0) - return -EAI_SYSTEM; - } - - if (req->ai_flags & AI_CANONNAME) - (*pai)->ai_canonname = strcpy ((char *) *pai + sizeof (struct addrinfo) - + sizeof (struct sockaddr_un), - utsname.nodename); - else - (*pai)->ai_canonname = NULL; - return 0; -} -#endif /* 0 */ +#ifdef INET6 +#define PTON_MAX 16 +#else +#define PTON_MAX 4 +#endif -static int -gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp, - const struct addrinfo *req, struct gaih_servtuple *st) -{ - struct servent *s; - size_t tmpbuflen = 1024; - struct servent ts; - char *tmpbuf; - int r; - - do - { - tmpbuf = alloca (tmpbuflen); - - r = __getservbyname_r (servicename, tp->name, &ts, tmpbuf, tmpbuflen, - &s); - if (r != 0 || s == NULL) - { - if (r == ERANGE) - tmpbuflen *= 2; - else - return GAIH_OKIFUNSPEC | -EAI_SERVICE; - } - } - while (r); +static const ns_src default_dns_files[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NSSRC_DNS, NS_SUCCESS }, + { 0 } +}; + +#if PACKETSZ > 1024 +#define MAXPACKET PACKETSZ +#else +#define MAXPACKET 1024 +#endif + +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +struct res_target { + struct res_target *next; + const char *name; /* domain name */ + int qclass, qtype; /* class and type of query */ + u_char *answer; /* buffer to put answer */ + int anslen; /* size of answer buffer */ + int n; /* result length */ +}; - st->next = NULL; - st->socktype = tp->socktype; - st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY) - ? req->ai_protocol : tp->protocol); - st->port = s->s_port; +static int str_isnumber(const char *); +static int explore_fqdn(const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int explore_null(const struct addrinfo *, + const char *, struct addrinfo **); +static int explore_numeric(const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int explore_numeric_scope(const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int get_canonname(const struct addrinfo *, + struct addrinfo *, const char *); +static struct addrinfo *get_ai(const struct addrinfo *, + const struct afd *, const char *); +static int get_portmatch(const struct addrinfo *, const char *); +static int get_port(struct addrinfo *, const char *, int); +static const struct afd *find_afd(int); +static int addrconfig(struct addrinfo *); +#ifdef INET6 +static int ip6_str2scopeid(char *, struct sockaddr_in6 *); +#endif + +static struct addrinfo *getanswer(const querybuf *, int, const char *, int, + const struct addrinfo *); +static int _dns_getaddrinfo(void *, void *, va_list); +static void _sethtent(void); +static void _endhtent(void); +static struct addrinfo *_gethtent(const char *, const struct addrinfo *); +static int _files_getaddrinfo(void *, void *, va_list); +#ifdef YP +static struct addrinfo *_yphostent(char *, const struct addrinfo *); +static int _yp_getaddrinfo(void *, void *, va_list); +extern int _yp_check(char **); +#endif + +u_int16_t _getshort(const u_char *src); + +static int res_queryN(const char *, struct res_target *); +static int res_searchN(const char *, struct res_target *); +static int res_querydomainN(const char *, const char *, + struct res_target *); + +static char *ai_errlist[] = { + "Success", + "Address family for hostname not supported", /* EAI_ADDRFAMILY */ + "Temporary failure in name resolution", /* EAI_AGAIN */ + "Invalid value for ai_flags", /* EAI_BADFLAGS */ + "Non-recoverable failure in name resolution", /* EAI_FAIL */ + "ai_family not supported", /* EAI_FAMILY */ + "Memory allocation failure", /* EAI_MEMORY */ + "No address associated with hostname", /* EAI_NODATA */ + "hostname nor servname provided, or not known", /* EAI_NONAME */ + "servname not supported for ai_socktype", /* EAI_SERVICE */ + "ai_socktype not supported", /* EAI_SOCKTYPE */ + "System error returned in errno", /* EAI_SYSTEM */ + "Invalid value for hints", /* EAI_BADHINTS */ + "Resolved protocol is unknown", /* EAI_PROTOCOL */ + "Unknown error", /* EAI_MAX */ +}; - return 0; +/* XXX macros that make external reference is BAD. */ + +#define GET_AI(ai, afd, addr) \ +do { \ + /* external reference: pai, error, and label free */ \ + (ai) = get_ai(pai, (afd), (addr)); \ + if ((ai) == NULL) { \ + error = EAI_MEMORY; \ + goto free; \ + } \ +} while (/*CONSTCOND*/0) + +#define GET_PORT(ai, serv) \ +do { \ + /* external reference: error and label free */ \ + error = get_port((ai), (serv), 0); \ + if (error != 0) \ + goto free; \ +} while (/*CONSTCOND*/0) + +#define GET_CANONNAME(ai, str) \ +do { \ + /* external reference: pai, error and label free */ \ + error = get_canonname(pai, (ai), (str)); \ + if (error != 0) \ + goto free; \ +} while (/*CONSTCOND*/0) + +#define ERR(err) \ +do { \ + /* external reference: error, and label bad */ \ + error = (err); \ + goto bad; \ + /*NOTREACHED*/ \ +} while (/*CONSTCOND*/0) + +#define MATCH_FAMILY(x, y, w) \ + ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) +#define MATCH(x, y, w) \ + ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) + +char * +gai_strerror(ecode) + int ecode; +{ + if (ecode < 0 || ecode > EAI_MAX) + ecode = EAI_MAX; + return ai_errlist[ecode]; } -#define gethosts(_family, _type) \ - { \ - int i; \ - int herrno; \ - struct hostent th; \ - struct hostent *h; \ - char *localcanon = NULL; \ - no_data = 0; \ - while (1) { \ - rc = 0; \ - status = DL_CALL_FCT (fct, (name, _family, &th, tmpbuf, tmpbuflen, \ - &rc, &herrno, NULL, &localcanon)); \ - if (rc != ERANGE || herrno != NETDB_INTERNAL) \ - break; \ - tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); \ - } \ - if (status == NSS_STATUS_SUCCESS && rc == 0) \ - h = &th; \ - else \ - h = NULL; \ - if (rc != 0) \ - { \ - if (herrno == NETDB_INTERNAL) \ - { \ - h_errno = (herrno); \ - return -EAI_SYSTEM; \ - } \ - if (herrno == TRY_AGAIN) \ - no_data = EAI_AGAIN; \ - else \ - no_data = herrno == NO_DATA; \ - } \ - else if (h != NULL) \ - { \ - for (i = 0; h->h_addr_list[i]; i++) \ - { \ - if (*pat == NULL) \ - { \ - *pat = alloca (sizeof (struct gaih_addrtuple)); \ - (*pat)->scopeid = 0; \ - } \ - uint32_t *addr = (*pat)->addr; \ - (*pat)->next = NULL; \ - if (i == 0) \ - { \ - (*pat)->name = alloca (strlen (h->h_name) + 1); \ - strcpy ((*pat)->name, h->h_name); \ - } \ - else \ - (*pat)->name = NULL; \ - if (_family == AF_INET && req->ai_family == AF_INET6) \ - { \ - (*pat)->family = AF_INET6; \ - addr[3] = *(uint32_t *) h->h_addr_list[i]; \ - addr[2] = htonl (0xffff); \ - addr[1] = 0; \ - addr[0] = 0; \ - } \ - else \ - { \ - (*pat)->family = _family; \ - memcpy (addr, h->h_addr_list[i], sizeof(_type)); \ - } \ - pat = &((*pat)->next); \ - } \ - \ - if (localcanon != NULL && canon == NULL) \ - { \ - canon = alloca (strlen (localcanon) + 1); \ - strcpy (canon, localcanon); \ - } \ - \ - if (_family == AF_INET6 && i > 0) \ - got_ipv6 = true; \ - } \ - } - - -typedef enum nss_status (*nss_gethostbyname3_r) - (const char *name, int af, struct hostent *host, - char *buffer, size_t buflen, int *errnop, - int *h_errnop, int32_t *ttlp, char **canonp); -typedef enum nss_status (*nss_getcanonname_r) - (const char *name, char *buffer, size_t buflen, char **result, - int *errnop, int *h_errnop); -extern service_user *__nss_hosts_database attribute_hidden; +void +freeaddrinfo(ai) + struct addrinfo *ai; +{ + struct addrinfo *next; + + do { + next = ai->ai_next; + if (ai->ai_canonname) + free(ai->ai_canonname); + /* no need to free(ai->ai_addr) */ + free(ai); + ai = next; + } while (ai); +} static int -gaih_inet (const char *name, const struct gaih_service *service, - const struct addrinfo *req, struct addrinfo **pai) +str_isnumber(p) + const char *p; { - const struct gaih_typeproto *tp = gaih_inet_typeproto; - struct gaih_servtuple *st = (struct gaih_servtuple *) &nullserv; - struct gaih_addrtuple *at = NULL; - int rc; - bool got_ipv6 = false; - const char *canon = NULL; - const char *orig_name = name; - - if (req->ai_protocol || req->ai_socktype) - { - ++tp; - - while (tp->name[0] - && ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype) - || (req->ai_protocol != 0 - && !(tp->protoflag & GAI_PROTO_PROTOANY) - && req->ai_protocol != tp->protocol))) - ++tp; - - if (! tp->name[0]) - { - if (req->ai_socktype) - return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE); - else - return (GAIH_OKIFUNSPEC | -EAI_SERVICE); - } - } - - if (service != NULL) - { - if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0) - return (GAIH_OKIFUNSPEC | -EAI_SERVICE); - - if (service->num < 0) - { - if (tp->name[0]) - { - st = (struct gaih_servtuple *) - alloca (sizeof (struct gaih_servtuple)); - - if ((rc = gaih_inet_serv (service->name, tp, req, st))) - return rc; - } - else - { - struct gaih_servtuple **pst = &st; - for (tp++; tp->name[0]; tp++) - { - struct gaih_servtuple *newp; - - if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0) - continue; - - if (req->ai_socktype != 0 - && req->ai_socktype != tp->socktype) - continue; - if (req->ai_protocol != 0 - && !(tp->protoflag & GAI_PROTO_PROTOANY) - && req->ai_protocol != tp->protocol) - continue; - - newp = (struct gaih_servtuple *) - alloca (sizeof (struct gaih_servtuple)); - - if ((rc = gaih_inet_serv (service->name, tp, req, newp))) - { - if (rc & GAIH_OKIFUNSPEC) - continue; - return rc; - } + char *ep; + + if (*p == '\0') + return NO; + ep = NULL; + (void)strtoul(p, &ep, 10); + if (ep && *ep == '\0') + return YES; + else + return NO; +} - *pst = newp; - pst = &(newp->next); +int +getaddrinfo(hostname, servname, hints, res) + const char *hostname, *servname; + const struct addrinfo *hints; + struct addrinfo **res; +{ + struct addrinfo sentinel; + struct addrinfo *cur; + int error = 0; + struct addrinfo ai; + struct addrinfo ai0; + struct addrinfo *pai; + const struct explore *ex; + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + pai = &ai; + pai->ai_flags = 0; + pai->ai_family = PF_UNSPEC; + pai->ai_socktype = ANY; + pai->ai_protocol = ANY; + pai->ai_addrlen = 0; + pai->ai_canonname = NULL; + pai->ai_addr = NULL; + pai->ai_next = NULL; + + if (hostname == NULL && servname == NULL) + return EAI_NONAME; + if (hints) { + /* error check for hints */ + if (hints->ai_addrlen || hints->ai_canonname || + hints->ai_addr || hints->ai_next) + ERR(EAI_BADHINTS); /* xxx */ + if (hints->ai_flags & ~AI_MASK) + ERR(EAI_BADFLAGS); + switch (hints->ai_family) { + case PF_UNSPEC: + case PF_INET: +#ifdef INET6 + case PF_INET6: +#endif + break; + default: + ERR(EAI_FAMILY); + } + memcpy(pai, hints, sizeof(*pai)); + + /* + * if both socktype/protocol are specified, check if they + * are meaningful combination. + */ + if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) { + for (ex = explore; ex->e_af >= 0; ex++) { + if (pai->ai_family != ex->e_af) + continue; + if (ex->e_socktype == ANY) + continue; + if (ex->e_protocol == ANY) + continue; + if (pai->ai_socktype == ex->e_socktype + && pai->ai_protocol != ex->e_protocol) { + ERR(EAI_BADHINTS); + } + } } - if (st == (struct gaih_servtuple *) &nullserv) - return (GAIH_OKIFUNSPEC | -EAI_SERVICE); - } - } - else - { - if (req->ai_socktype || req->ai_protocol) - { - st = alloca (sizeof (struct gaih_servtuple)); - st->next = NULL; - st->socktype = tp->socktype; - st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY) - ? req->ai_protocol : tp->protocol); - st->port = htons (service->num); - } - else - { - /* Neither socket type nor protocol is set. Return all - socket types we know about. */ - struct gaih_servtuple **lastp = &st; - for (tp = gaih_inet_typeproto + 1; tp->name[0]; ++tp) - if ((tp->protoflag & GAI_PROTO_NOSERVICE) == 0) - { - struct gaih_servtuple *newp; - - newp = alloca (sizeof (struct gaih_servtuple)); - newp->next = NULL; - newp->socktype = tp->socktype; - newp->protocol = tp->protocol; - newp->port = htons (service->num); - - *lastp = newp; - lastp = &newp->next; - } - } - } - } - else if (req->ai_socktype || req->ai_protocol) - { - st = alloca (sizeof (struct gaih_servtuple)); - st->next = NULL; - st->socktype = tp->socktype; - st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY) - ? req->ai_protocol : tp->protocol); - st->port = 0; - } - else - { - /* Neither socket type nor protocol is set. Return all socket types - we know about. */ - struct gaih_servtuple **lastp = &st; - for (++tp; tp->name[0]; ++tp) - { - struct gaih_servtuple *newp; - - newp = alloca (sizeof (struct gaih_servtuple)); - newp->next = NULL; - newp->socktype = tp->socktype; - newp->protocol = tp->protocol; - newp->port = 0; - - *lastp = newp; - lastp = &newp->next; - } - } - - if (name != NULL) - { - at = alloca (sizeof (struct gaih_addrtuple)); - - at->family = AF_UNSPEC; - at->scopeid = 0; - at->next = NULL; - -#ifdef HAVE_LIBIDN - if (req->ai_flags & AI_IDN) - { - int idn_flags = 0; - if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED) - idn_flags |= IDNA_ALLOW_UNASSIGNED; - if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES) - idn_flags |= IDNA_USE_STD3_ASCII_RULES; - - char *p = NULL; - rc = __idna_to_ascii_lz (name, &p, idn_flags); - if (rc != IDNA_SUCCESS) - { - if (rc == IDNA_MALLOC_ERROR) - return -EAI_MEMORY; - if (rc == IDNA_DLOPEN_ERROR) - return -EAI_SYSTEM; - return -EAI_IDN_ENCODE; - } - /* In case the output string is the same as the input string - no new string has been allocated. */ - if (p != name) - { - name = alloca (strlen (p) + 1); - strcpy (name, p); - free (p); - } } -#endif - if (inet_aton (name, (struct in_addr *) at->addr) != 0) - { - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET) - at->family = AF_INET; - else if (req->ai_family == AF_INET6 && req->ai_flags & AI_V4MAPPED) - { - at->addr[3] = at->addr[0]; - at->addr[2] = htonl (0xffff); - at->addr[1] = 0; - at->addr[0] = 0; - at->family = AF_INET6; - } - else - return -EAI_ADDRFAMILY; - - dupname: - if (req->ai_flags & AI_CANONNAME) - { - canon = strdup (name); - if (canon == NULL) - return -EAI_MEMORY; - } + /* + * post-2553: AI_ALL and AI_V4MAPPED are effective only against + * AF_INET6 query. They needs to be ignored if specified in other + * occassions. + */ + switch (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) { + case AI_V4MAPPED: + case AI_ALL | AI_V4MAPPED: + if (pai->ai_family != AF_INET6) + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); + break; + case AI_ALL: +#if 1 + /* illegal */ + ERR(EAI_BADFLAGS); +#else + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); +#endif + break; } - if (at->family == AF_UNSPEC) - { - char *scope_delim; - char *namebuf = alloca (strlen (name) + 1); - strcpy (namebuf, name); - - scope_delim = strchr (namebuf, SCOPE_DELIMITER); - if (scope_delim != NULL) - *scope_delim = '\0'; - - if (inet_pton (AF_INET6, namebuf, at->addr) > 0) - { - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6) - at->family = AF_INET6; - else if (req->ai_family == AF_INET - && IN6_IS_ADDR_V4MAPPED ((struct in6_addr *)at->addr)) - { - at->addr[0] = at->addr[3]; - at->family = AF_INET; - } - else - return -EAI_ADDRFAMILY; - - if (scope_delim != NULL) - { - int try_numericscope = 0; - if (IN6_IS_ADDR_LINKLOCAL ((struct in6_addr *)at->addr) - || IN6_IS_ADDR_MC_LINKLOCAL ((struct in6_addr *)at->addr)) - { - at->scopeid = if_nametoindex (scope_delim + 1); - if (at->scopeid == 0) - try_numericscope = 1; - } - else - try_numericscope = 1; - - if (try_numericscope != 0) - { - char *end; - assert (sizeof (uint32_t) <= sizeof (unsigned long)); - at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end, - 10); - if (*end != '\0') - return GAIH_OKIFUNSPEC | -EAI_NONAME; - } + /* + * check for special cases. (1) numeric servname is disallowed if + * socktype/protocol are left unspecified. (2) servname is disallowed + * for raw and other inet{,6} sockets. + */ + if (MATCH_FAMILY(pai->ai_family, PF_INET, 1) +#ifdef PF_INET6 + || MATCH_FAMILY(pai->ai_family, PF_INET6, 1) +#endif + ) { + ai0 = *pai; /* backup *pai */ + + if (pai->ai_family == PF_UNSPEC) { +#ifdef PF_INET6 + pai->ai_family = PF_INET6; +#else + pai->ai_family = PF_INET; +#endif } + error = get_portmatch(pai, servname); + if (error) + ERR(error); - goto dupname; - } + *pai = ai0; } - if (at->family == AF_UNSPEC && (req->ai_flags & AI_NUMERICHOST) == 0) - { - struct gaih_addrtuple **pat = &at; - int no_data = 0; - int no_inet6_data = 0; - service_user *nip = NULL; - enum nss_status inet6_status = NSS_STATUS_UNAVAIL; - enum nss_status status = NSS_STATUS_UNAVAIL; - int no_more; - int old_res_options; - - /* If we do not have to look for IPv4 and IPv6 together, use - the simple, old functions. */ - if (req->ai_family == AF_INET || req->ai_family == AF_INET6) - { - int family = req->ai_family; - size_t tmpbuflen = 512; - char *tmpbuf = alloca (tmpbuflen); - int rc; - struct hostent th; - struct hostent *h; - int herrno; - - simple_again: - while (1) - { - rc = __gethostbyname2_r (name, family, &th, tmpbuf, - tmpbuflen, &h, &herrno); - if (rc != ERANGE || herrno != NETDB_INTERNAL) - break; - tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); - } - - if (rc == 0) - { - if (h == NULL) - { - if (req->ai_family == AF_INET6 - && (req->ai_flags & AI_V4MAPPED) - && family == AF_INET6) - { - /* Try again, this time looking for IPv4 - addresses. */ - family = AF_INET; - goto simple_again; - } - } - else - { - /* We found data, now convert it into the list. */ - int i = 0; - for (i = 0; h->h_addr_list[i]; ++i) - { - if (*pat == NULL) - { - *pat = alloca (sizeof (struct gaih_addrtuple)); - (*pat)->scopeid = 0; - } - (*pat)->next = NULL; - (*pat)->family = req->ai_family; - if (family == req->ai_family) - memcpy ((*pat)->addr, h->h_addr_list[i], - h->h_length); - else - { - int32_t *addr = (uint32_t *) (*pat)->addr; - addr[3] = *(uint32_t *) h->h_addr_list[i]; - addr[2] = htonl (0xffff); - addr[1] = 0; - addr[0] = 0; - } - pat = &((*pat)->next); - } - } - } - else - { - if (herrno == NETDB_INTERNAL) - { - h_errno = (herrno); - return -EAI_SYSTEM; - } - if (herrno == TRY_AGAIN) - { - return -EAI_AGAIN; - } - /* We made requests but they turned out no data. - The name is known, though. */ - return (GAIH_OKIFUNSPEC | -EAI_NODATA); - } + ai0 = *pai; - goto process_list; - } - -#ifdef USE_NSCD - if (__nss_not_use_nscd_hosts > 0 - && ++__nss_not_use_nscd_hosts > NSS_NSCD_RETRY) - __nss_not_use_nscd_hosts = 0; - - if (!__nss_not_use_nscd_hosts) - { - /* Try to use nscd. */ - struct nscd_ai_result *air = NULL; - int herrno; - int err = __nscd_getai (name, &air, &herrno); - if (air != NULL) - { - /* Transform into gaih_addrtuple list. */ - bool added_canon = (req->ai_flags & AI_CANONNAME) == 0; - char *addrs = air->addrs; - - for (int i = 0; i < air->naddrs; ++i) - { - socklen_t size = (air->family[i] == AF_INET - ? INADDRSZ : IN6ADDRSZ); - if (*pat == NULL) - { - *pat = alloca (sizeof (struct gaih_addrtuple)); - (*pat)->scopeid = 0; - } - uint32_t *pataddr = (*pat)->addr; - (*pat)->next = NULL; - if (added_canon || air->canon == NULL) - (*pat)->name = NULL; - else { - canon = (*pat)->name = alloca (strlen (air->canon) + 1); - strcpy (canon, air->canon); - } - - if (air->family[i] == AF_INET - && req->ai_family == AF_INET6 - && (req->ai_flags & AI_V4MAPPED)) - { - (*pat)->family = AF_INET6; - pataddr[3] = *(uint32_t *) addrs; - pataddr[2] = htonl (0xffff); - pataddr[1] = 0; - pataddr[0] = 0; - pat = &((*pat)->next); - added_canon = true; - } - else if (req->ai_family == AF_UNSPEC - || air->family[i] == req->ai_family) - { - (*pat)->family = air->family[i]; - memcpy (pataddr, addrs, size); - pat = &((*pat)->next); - added_canon = true; - if (air->family[i] == AF_INET6) - got_ipv6 = true; - } - addrs += size; - } + /* NULL hostname, or numeric hostname */ + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; - free (air); + /* PF_UNSPEC entries are prepared for DNS queries only */ + if (ex->e_af == PF_UNSPEC) + continue; - if (at->family == AF_UNSPEC) - return (GAIH_OKIFUNSPEC | -EAI_NONAME); + if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) + continue; + if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex))) + continue; + if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) + continue; - goto process_list; - } - else if (err != 0 && __nss_not_use_nscd_hosts == 0) - { - if (herrno == NETDB_INTERNAL && errno == ENOMEM) - return -EAI_MEMORY; - if (herrno == TRY_AGAIN) - return -EAI_AGAIN; - return -EAI_SYSTEM; - } - } -#endif + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; - if (__nss_hosts_database != NULL) - { - no_more = 0; - nip = __nss_hosts_database; - } - else - no_more = __nss_database_lookup ("hosts", NULL, - "dns [!UNAVAIL=return] files", - &nip); - - if (__res_maybe_init (&_res, 0) == -1) - no_more = 1; - - /* If we are looking for both IPv4 and IPv6 address we don't - want the lookup functions to automatically promote IPv4 - addresses to IPv6 addresses. Currently this is decided - by setting the RES_USE_INET6 bit in _res.options. */ - old_res_options = _res.options; - _res.options &= ~RES_USE_INET6; - - size_t tmpbuflen = 512; - char *tmpbuf = alloca (tmpbuflen); - - while (!no_more) - { - nss_gethostbyname3_r fct = NULL; - if (req->ai_flags & AI_CANONNAME) - /* No need to use this function if we do not look for - the canonical name. The function does not exist in - all NSS modules and therefore the lookup would - often fail. */ - fct = __nss_lookup_function (nip, "gethostbyname3_r"); - if (fct == NULL) - /* We are cheating here. The gethostbyname2_r function does - not have the same interface as gethostbyname3_r but the - extra arguments the latter takes are added at the end. - So the gethostbyname2_r code will just ignore them. */ - fct = __nss_lookup_function (nip, "gethostbyname2_r"); - - if (fct != NULL) - { - if (req->ai_family == AF_INET6 - || req->ai_family == AF_UNSPEC) - { - gethosts (AF_INET6, struct in6_addr); - no_inet6_data = no_data; - inet6_status = status; - } - if (req->ai_family == AF_INET - || req->ai_family == AF_UNSPEC - || (req->ai_family == AF_INET6 - && (req->ai_flags & AI_V4MAPPED) - /* Avoid generating the mapped addresses if we - know we are not going to need them. */ - && ((req->ai_flags & AI_ALL) || !got_ipv6))) - { - gethosts (AF_INET, struct in_addr); - - if (req->ai_family == AF_INET) - { - no_inet6_data = no_data; - inet6_status = status; - } - } - - /* If we found one address for AF_INET or AF_INET6, - don't continue the search. */ - if (inet6_status == NSS_STATUS_SUCCESS - || status == NSS_STATUS_SUCCESS) - { - if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL) - { - /* If we need the canonical name, get it - from the same service as the result. */ - nss_getcanonname_r cfct; - int herrno; - - cfct = __nss_lookup_function (nip, "getcanonname_r"); - if (cfct != NULL) - { - const size_t max_fqdn_len = 256; - char *buf = alloca (max_fqdn_len); - char *s; - - if (DL_CALL_FCT (cfct, (at->name ?: name, buf, - max_fqdn_len, &s, &rc, - &herrno)) - == NSS_STATUS_SUCCESS) - canon = s; - else - /* Set to name now to avoid using - gethostbyaddr. */ - canon = name; - } - } + if (hostname == NULL) + error = explore_null(pai, servname, &cur->ai_next); + else + error = explore_numeric_scope(pai, hostname, servname, &cur->ai_next); - break; - } + if (error) + goto free; - /* We can have different states for AF_INET and - AF_INET6. Try to find a useful one for both. */ - if (inet6_status == NSS_STATUS_TRYAGAIN) - status = NSS_STATUS_TRYAGAIN; - else if (status == NSS_STATUS_UNAVAIL && - inet6_status != NSS_STATUS_UNAVAIL) - status = inet6_status; - } + while (cur && cur->ai_next) + cur = cur->ai_next; + } - if (nss_next_action (nip, status) == NSS_ACTION_RETURN) - break; + /* + * XXX + * If numreic representation of AF1 can be interpreted as FQDN + * representation of AF2, we need to think again about the code below. + */ + if (sentinel.ai_next) + goto good; + + if (pai->ai_flags & AI_NUMERICHOST) + ERR(EAI_NONAME); + if (hostname == NULL) + ERR(EAI_NODATA); + + if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(&ai0)) + ERR(EAI_FAIL); + + /* + * hostname as alphabetical name. + * we would like to prefer AF_INET6 than AF_INET, so we'll make a + * outer loop by AFs. + */ + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; + + /* require exact match for family field */ + if (pai->ai_family != ex->e_af) + continue; - if (nip->next == NULL) - no_more = -1; - else - nip = nip->next; - } + if (!MATCH(pai->ai_socktype, ex->e_socktype, + WILD_SOCKTYPE(ex))) { + continue; + } + if (!MATCH(pai->ai_protocol, ex->e_protocol, + WILD_PROTOCOL(ex))) { + continue; + } - _res.options = old_res_options; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; - if (no_data != 0 && no_inet6_data != 0) - { - /* If both requests timed out report this. */ - if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN) - return -EAI_AGAIN; + error = explore_fqdn(pai, hostname, servname, + &cur->ai_next); - /* We made requests but they turned out no data. The name - is known, though. */ - return (GAIH_OKIFUNSPEC | -EAI_NODATA); - } + while (cur && cur->ai_next) + cur = cur->ai_next; } - process_list: - if (at->family == AF_UNSPEC) - return (GAIH_OKIFUNSPEC | -EAI_NONAME); - } - else - { - struct gaih_addrtuple *atr; - atr = at = alloca (sizeof (struct gaih_addrtuple)); - memset (at, '\0', sizeof (struct gaih_addrtuple)); - - if (req->ai_family == AF_UNSPEC) - { - at->next = alloca (sizeof (struct gaih_addrtuple)); - memset (at->next, '\0', sizeof (struct gaih_addrtuple)); + /* XXX */ + if (sentinel.ai_next) + error = 0; + + if (error) + goto free; + if (error == 0) { + if (sentinel.ai_next) { + good: + *res = sentinel.ai_next; + return SUCCESS; + } else + error = EAI_FAIL; } + free: + bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + *res = NULL; + return error; +} - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6) - { - at->family = AF_INET6; - if ((req->ai_flags & AI_PASSIVE) == 0) - memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr)); - atr = at->next; +/* + * FQDN hostname, DNS lookup + */ +static int +explore_fqdn(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + struct addrinfo *result; + struct addrinfo *cur; + int error = 0; + static const ns_dtab dtab[] = { + NS_FILES_CB(_files_getaddrinfo, NULL) + { NSSRC_DNS, _dns_getaddrinfo, NULL }, /* force -DHESIOD */ + NS_NIS_CB(_yp_getaddrinfo, NULL) + { 0 } + }; + + result = NULL; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + switch (nsdispatch(&result, dtab, NSDB_HOSTS, "getaddrinfo", + default_dns_files, hostname, pai)) { + case NS_TRYAGAIN: + error = EAI_AGAIN; + goto free; + case NS_UNAVAIL: + error = EAI_FAIL; + goto free; + case NS_NOTFOUND: + error = EAI_NODATA; + goto free; + case NS_SUCCESS: + error = 0; + for (cur = result; cur; cur = cur->ai_next) { + GET_PORT(cur, servname); + /* canonname should be filled already */ + } + break; } - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET) - { - atr->family = AF_INET; - if ((req->ai_flags & AI_PASSIVE) == 0) - atr->addr[0] = htonl (INADDR_LOOPBACK); - } - } - - if (pai == NULL) - return 0; - - { - struct gaih_servtuple *st2; - struct gaih_addrtuple *at2 = at; - size_t socklen; - sa_family_t family; - - /* - buffer is the size of an unformatted IPv6 address in printable format. - */ - while (at2 != NULL) - { - /* Only the first entry gets the canonical name. */ - if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0) - { - if (canon == NULL) - { - struct hostent *h = NULL; - int herrno; - struct hostent th; - size_t tmpbuflen = 512; - char *tmpbuf = NULL; - - do - { - tmpbuf = extend_alloca (tmpbuf, tmpbuflen, tmpbuflen * 2); - rc = __gethostbyaddr_r (at2->addr, - ((at2->family == AF_INET6) - ? sizeof (struct in6_addr) - : sizeof (struct in_addr)), - at2->family, &th, tmpbuf, - tmpbuflen, &h, &herrno); - } - while (rc == ERANGE && herrno == NETDB_INTERNAL); - - if (rc != 0 && herrno == NETDB_INTERNAL) - { - h_errno = (herrno); - return -EAI_SYSTEM; - } - - if (h != NULL) - canon = h->h_name; - else - { - assert (orig_name != NULL); - /* If the canonical name cannot be determined, use - the passed in string. */ - canon = orig_name; - } - } - -#ifdef HAVE_LIBIDN - if (req->ai_flags & AI_CANONIDN) - { - int idn_flags = 0; - if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED) - idn_flags |= IDNA_ALLOW_UNASSIGNED; - if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES) - idn_flags |= IDNA_USE_STD3_ASCII_RULES; - - char *out; - int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags); - if (rc != IDNA_SUCCESS) - { - if (rc == IDNA_MALLOC_ERROR) - return -EAI_MEMORY; - if (rc == IDNA_DLOPEN_ERROR) - return -EAI_SYSTEM; - return -EAI_IDN_ENCODE; - } - /* In case the output string is the same as the input - string no new string has been allocated. Otherwise - make a copy. */ - if (out == canon) - goto make_copy; - } - else -#endif - { -#ifdef HAVE_LIBIDN - make_copy: -#endif - canon = strdup (canon); - if (canon == NULL) - return -EAI_MEMORY; - } - } - - if (at2->family == AF_INET6) - { - family = AF_INET6; - socklen = sizeof (struct sockaddr_in6); - - /* If we looked up IPv4 mapped address discard them here if - the caller isn't interested in all address and we have - found at least one IPv6 address. */ - if (got_ipv6 - && (req->ai_flags & (AI_V4MAPPED|AI_ALL)) == AI_V4MAPPED - && IN6_IS_ADDR_V4MAPPED ((struct in6_addr *)at2->addr)) - goto ignore; - } - else - { - family = AF_INET; - socklen = sizeof (struct sockaddr_in); - } - - for (st2 = st; st2 != NULL; st2 = st2->next) - { - struct addrinfo *ai; - ai = *pai = malloc (sizeof (struct addrinfo) + socklen); - if (ai == NULL) - return -EAI_MEMORY; - - ai->ai_flags = req->ai_flags; - ai->ai_family = family; - ai->ai_socktype = st2->socktype; - ai->ai_protocol = st2->protocol; - ai->ai_addrlen = socklen; - ai->ai_addr = (void *) (ai + 1); - - /* We only add the canonical name once. */ - ai->ai_canonname = (char *) canon; - canon = NULL; - -#if SALEN - ai->ai_addr->sa_len = socklen; -#endif /* SALEN */ - ai->ai_addr->sa_family = family; - - if (family == AF_INET6) - { - struct sockaddr_in6 *sin6p = - (struct sockaddr_in6 *) ai->ai_addr; - - sin6p->sin6_port = st2->port; - sin6p->sin6_flowinfo = 0; - memcpy (&sin6p->sin6_addr, - at2->addr, sizeof (struct in6_addr)); - sin6p->sin6_scope_id = at2->scopeid; - } - else - { - struct sockaddr_in *sinp = - (struct sockaddr_in *) ai->ai_addr; - sinp->sin_port = st2->port; - memcpy (&sinp->sin_addr, - at2->addr, sizeof (struct in_addr)); - memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero)); - } - - pai = &(ai->ai_next); - } - *pai = NULL; - - ignore: - at2 = at2->next; - } - } - return 0; -} + *res = result; -static struct gaih gaih[] = - { - { PF_INET6, gaih_inet }, - { PF_INET, gaih_inet }, -#if 0 - { PF_LOCAL, gaih_local }, -#endif - { PF_UNSPEC, NULL } - }; + return 0; + +free: + if (result) + freeaddrinfo(result); + return error; +} -struct sort_result +/* + * hostname == NULL. + * passive socket -> anyaddr (0.0.0.0 or ::) + * non-passive socket -> localhost (127.0.0.1 or ::1) + */ +static int +explore_null(pai, servname, res) + const struct addrinfo *pai; + const char *servname; + struct addrinfo **res; { - struct addrinfo *dest_addr; - struct sockaddr_storage source_addr; - uint8_t source_addr_len; - bool got_source_addr; -}; + int s; + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + /* + * filter out AFs that are not supported by the kernel + * XXX errno? + */ + s = socket(pai->ai_family, SOCK_DGRAM, 0); + if (s < 0) { + if (errno != EMFILE) + return 0; + } else + close(s); + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + if (pai->ai_flags & AI_PASSIVE) { + GET_AI(cur->ai_next, afd, afd->a_addrany); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "anyaddr"); + */ + GET_PORT(cur->ai_next, servname); + } else { + GET_AI(cur->ai_next, afd, afd->a_loopback); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "localhost"); + */ + GET_PORT(cur->ai_next, servname); + } + cur = cur->ai_next; + + *res = sentinel.ai_next; + return 0; +free: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} +/* + * numeric hostname + */ static int -get_scope (const struct sockaddr_storage *ss) +explore_numeric(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; { - int scope; - if (ss->ss_family == PF_INET6) - { - const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) ss; - - if (! IN6_IS_ADDR_MULTICAST (&in6->sin6_addr)) - { - if (IN6_IS_ADDR_LINKLOCAL (&in6->sin6_addr)) - scope = 2; - else if (IN6_IS_ADDR_SITELOCAL (&in6->sin6_addr)) - scope = 5; - else - /* XXX Is this the correct default behavior? */ - scope = 14; + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + char pton[PTON_MAX]; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + switch (afd->a_af) { +#if 1 /*X/Open spec*/ + case AF_INET: + if (inet_aton(hostname, (struct in_addr *)pton) == 1) { + if (pai->ai_family == afd->a_af || + pai->ai_family == PF_UNSPEC /*?*/) { + GET_AI(cur->ai_next, afd, pton); + GET_PORT(cur->ai_next, servname); + while (cur && cur->ai_next) + cur = cur->ai_next; + } else + ERR(EAI_FAMILY); /*xxx*/ + } + break; +#endif + default: + if (inet_pton(afd->a_af, hostname, pton) == 1) { + if (pai->ai_family == afd->a_af || + pai->ai_family == PF_UNSPEC /*?*/) { + GET_AI(cur->ai_next, afd, pton); + GET_PORT(cur->ai_next, servname); + while (cur && cur->ai_next) + cur = cur->ai_next; + } else + ERR(EAI_FAMILY); /*xxx*/ + } + break; } - else - scope = in6->sin6_addr.s6_addr[1] & 0xf; - } - else if (ss->ss_family == PF_INET) - { - const struct sockaddr_in *in = (const struct sockaddr_in *) ss; - const uint8_t *addr = (const uint8_t *) &in->sin_addr; - - /* RFC 3484 specifies how to map IPv6 addresses to scopes. - 169.254/16 and 127/8 are link-local. */ - if ((addr[0] == 169 && addr[1] == 254) || addr[0] == 127) - scope = 2; - else if (addr[0] == 10 || (addr[0] == 172 && addr[1] == 16) - || (addr[0] == 192 && addr[1] == 168)) - scope = 5; - else - scope = 14; - } - else - /* XXX What is a good default? */ - scope = 15; - - return scope; -} + *res = sentinel.ai_next; + return 0; -/* XXX The system administrator should be able to install other - tables. We need to make this configurable. The problem is that - the kernel is also involved since it needs the same table. */ -static const struct prefixlist +free: +bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * numeric hostname with scope + */ +static int +explore_numeric_scope(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; { - struct in6_addr prefix; - unsigned int bits; - int val; -} default_labels[] = - { - /* See RFC 3484 for the details. */ - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0001 } } }, - 128, 0 }, - { { .__u6_addr = { .__u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 16, 2 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 96, 3 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0xffff, 0x0000, 0x0000 } } }, - 96, 4 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 0, 1 } - }; - - -static const struct prefixlist default_precedence[] = - { - /* See RFC 3484 for the details. */ - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0001 } } }, - 128, 50 }, - { { .__u6_addr = { .__u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 16, 30 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 96, 20 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0xffff, 0x0000, 0x0000 } } }, - 96, 10 }, - { { .__u6_addr = { .__u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 } } }, - 0, 40 } - }; +#if !defined(SCOPE_DELIMITER) || !defined(INET6) + return explore_numeric(pai, hostname, servname, res); +#else + const struct afd *afd; + struct addrinfo *cur; + int error; + char *cp, *hostname2 = NULL, *scope, *addr; + struct sockaddr_in6 *sin6; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + if (!afd->a_scoped) + return explore_numeric(pai, hostname, servname, res); + + cp = strchr(hostname, SCOPE_DELIMITER); + if (cp == NULL) + return explore_numeric(pai, hostname, servname, res); + + /* + * Handle special case of + */ + hostname2 = strdup(hostname); + if (hostname2 == NULL) + return EAI_MEMORY; + /* terminate at the delimiter */ + hostname2[cp - hostname] = '\0'; + addr = hostname2; + scope = cp + 1; + + error = explore_numeric(pai, addr, servname, res); + if (error == 0) { + int scopeid; + + for (cur = *res; cur; cur = cur->ai_next) { + if (cur->ai_family != AF_INET6) + continue; + sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr; + if ((scopeid = ip6_str2scopeid(scope, sin6)) == -1) { + free(hostname2); + return(EAI_NODATA); /* XXX: is return OK? */ + } + sin6->sin6_scope_id = scopeid; + } + } + free(hostname2); + + return error; +#endif +} static int -match_prefix (const struct sockaddr_storage *ss, const struct prefixlist *list, - int default_val) +get_canonname(pai, ai, str) + const struct addrinfo *pai; + struct addrinfo *ai; + const char *str; { - int idx; - struct sockaddr_in6 in6_mem; - const struct sockaddr_in6 *in6; - - if (ss->ss_family == PF_INET6) - in6 = (const struct sockaddr_in6 *) ss; - else if (ss->ss_family == PF_INET) - { - const struct sockaddr_in *in = (const struct sockaddr_in *) ss; - - /* Convert to IPv6 address. */ - in6_mem.sin6_family = PF_INET6; - in6_mem.sin6_port = in->sin_port; - in6_mem.sin6_flowinfo = 0; - if (in->sin_addr.s_addr == htonl (0x7f000001)) - in6_mem.sin6_addr = (struct in6_addr) IN6ADDR_LOOPBACK_INIT; - else - { - /* Construct a V4-to-6 mapped address. */ - memset (&in6_mem.sin6_addr, '\0', sizeof (in6_mem.sin6_addr)); - in6_mem.sin6_addr.__u6_addr.__u6_addr16[5] = 0xffff; - in6_mem.sin6_addr.__u6_addr.__u6_addr32[3] = in->sin_addr.s_addr; - in6_mem.sin6_scope_id = 0; + if ((pai->ai_flags & AI_CANONNAME) != 0) { + ai->ai_canonname = (char *)malloc(strlen(str) + 1); + if (ai->ai_canonname == NULL) + return EAI_MEMORY; + strcpy(ai->ai_canonname, str); } + return 0; +} - in6 = &in6_mem; - } - else - return default_val; - - for (idx = 0; ; ++idx) - { - unsigned int bits = list[idx].bits; - uint8_t *mask = list[idx].prefix.s6_addr; - uint8_t *val = in6->sin6_addr.s6_addr; - - while (bits > 8) - { - if (*mask != *val) - break; - - ++mask; - ++val; - bits -= 8; - } +static struct addrinfo * +get_ai(pai, afd, addr) + const struct addrinfo *pai; + const struct afd *afd; + const char *addr; +{ + char *p; + struct addrinfo *ai; +#ifdef FAITH + struct in6_addr faith_prefix; + char *fp_str; + int translate = 0; +#endif - if (bits < 8) - { - if ((*mask & (0xff00 >> bits)) == (*val & (0xff00 >> bits))) - /* Match! */ - break; +#ifdef FAITH + /* + * Transfrom an IPv4 addr into a special IPv6 addr format for + * IPv6->IPv4 translation gateway. (only TCP is supported now) + * + * +-----------------------------------+------------+ + * | faith prefix part (12 bytes) | embedded | + * | | IPv4 addr part (4 bytes) + * +-----------------------------------+------------+ + * + * faith prefix part is specified as ascii IPv6 addr format + * in environmental variable GAI. + * For FAITH to work correctly, routing to faith prefix must be + * setup toward a machine where a FAITH daemon operates. + * Also, the machine must enable some mechanizm + * (e.g. faith interface hack) to divert those packet with + * faith prefixed destination addr to user-land FAITH daemon. + */ + fp_str = getenv("GAI"); + if (fp_str && inet_pton(AF_INET6, fp_str, &faith_prefix) == 1 && + afd->a_af == AF_INET && pai->ai_socktype == SOCK_STREAM) { + u_int32_t v4a; + u_int8_t v4a_top; + + memcpy(&v4a, addr, sizeof v4a); + v4a_top = v4a >> IN_CLASSA_NSHIFT; + if (!IN_MULTICAST(v4a) && !IN_EXPERIMENTAL(v4a) && + v4a_top != 0 && v4a != IN_LOOPBACKNET) { + afd = &afdl[N_INET6]; + memcpy(&faith_prefix.s6_addr[12], addr, + sizeof(struct in_addr)); + translate = 1; + } } - } +#endif - return list[idx].val; + ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) + + (afd->a_socklen)); + if (ai == NULL) + return NULL; + + memcpy(ai, pai, sizeof(struct addrinfo)); + ai->ai_addr = (struct sockaddr *)(void *)(ai + 1); + memset(ai->ai_addr, 0, (size_t)afd->a_socklen); + ai->ai_addrlen = afd->a_socklen; + ai->ai_addr->sa_family = ai->ai_family = afd->a_af; + p = (char *)(void *)(ai->ai_addr); +#ifdef FAITH + if (translate == 1) + memcpy(p + afd->a_off, &faith_prefix, (size_t)afd->a_addrlen); + else +#endif + memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen); + return ai; } - static int -get_label (const struct sockaddr_storage *ss) +get_portmatch(ai, servname) + const struct addrinfo *ai; + const char *servname; { - /* XXX What is a good default value? */ - return match_prefix (ss, default_labels, INT_MAX); -} + /* get_port does not touch first argument. when matchonly == 1. */ + /* LINTED const cast */ + return get_port((struct addrinfo *)ai, servname, 1); +} static int -get_precedence (const struct sockaddr_storage *ss) +get_port(ai, servname, matchonly) + struct addrinfo *ai; + const char *servname; + int matchonly; { - /* XXX What is a good default value? */ - return match_prefix (ss, default_precedence, 0); -} + const char *proto; + struct servent *sp; + int port; + int allownumeric; + + if (servname == NULL) + return 0; + switch (ai->ai_family) { + case AF_INET: +#ifdef AF_INET6 + case AF_INET6: +#endif + break; + default: + return 0; + } + switch (ai->ai_socktype) { + case SOCK_RAW: + return EAI_SERVICE; + case SOCK_DGRAM: + case SOCK_STREAM: + allownumeric = 1; + break; + case ANY: + allownumeric = 0; + break; + default: + return EAI_SOCKTYPE; + } -static int -rfc3484_sort (const void *p1, const void *p2) -{ - const struct sort_result *a1 = (const struct sort_result *) p1; - const struct sort_result *a2 = (const struct sort_result *) p2; + if (str_isnumber(servname)) { + if (!allownumeric) + return EAI_SERVICE; + port = htons(atoi(servname)); + if (port < 0 || port > 65535) + return EAI_SERVICE; + } else { + switch (ai->ai_socktype) { + case SOCK_DGRAM: + proto = "udp"; + break; + case SOCK_STREAM: + proto = "tcp"; + break; + default: + proto = NULL; + break; + } - /* Rule 1: Avoid unusable destinations. - We have the got_source_addr flag set if the destination is reachable. */ - if (a1->got_source_addr && ! a2->got_source_addr) - return -1; - if (! a1->got_source_addr && a2->got_source_addr) - return 1; + if ((sp = getservbyname(servname, proto)) == NULL) + return EAI_SERVICE; + port = sp->s_port; + } + if (!matchonly) { + switch (ai->ai_family) { + case AF_INET: + ((struct sockaddr_in *)(void *) + ai->ai_addr)->sin_port = port; + break; +#ifdef INET6 + case AF_INET6: + ((struct sockaddr_in6 *)(void *) + ai->ai_addr)->sin6_port = port; + break; +#endif + } + } - /* Rule 2: Prefer matching scope. Only interesting if both - destination addresses are IPv6. */ - int a1_dst_scope - = get_scope ((struct sockaddr_storage *) a1->dest_addr->ai_addr); + return 0; +} - int a2_dst_scope - = get_scope ((struct sockaddr_storage *) a2->dest_addr->ai_addr); +static const struct afd * +find_afd(af) + int af; +{ + const struct afd *afd; - if (a1->got_source_addr) - { - int a1_src_scope = get_scope (&a1->source_addr); - int a2_src_scope = get_scope (&a2->source_addr); + if (af == PF_UNSPEC) + return NULL; + for (afd = afdl; afd->a_af; afd++) { + if (afd->a_af == af) + return afd; + } + return NULL; +} - if (a1_dst_scope == a1_src_scope && a2_dst_scope != a2_src_scope) - return -1; - if (a1_dst_scope != a1_src_scope && a2_dst_scope == a2_src_scope) +/* + * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend + * will take care of it. + * the semantics of AI_ADDRCONFIG is not defined well. we are not sure + * if the code is right or not. + * + * XXX PF_UNSPEC -> PF_INET6 + PF_INET mapping needs to be in sync with + * _dns_getaddrinfo. + */ +static int +addrconfig(pai) + struct addrinfo *pai; +{ + int s, af; + + /* + * TODO: + * Note that implementation dependent test for address + * configuration should be done everytime called + * (or apropriate interval), + * because addresses will be dynamically assigned or deleted. + */ + af = pai->ai_family; + if (af == AF_UNSPEC) { + if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + af = AF_INET; + else { + close(s); + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + af = AF_INET6; + else + close(s); + } + } + if (af != AF_UNSPEC) { + if ((s = socket(af, SOCK_DGRAM, 0)) < 0) + return 0; + close(s); + } + pai->ai_family = af; return 1; - } +} +#ifdef INET6 +/* convert a string to a scope identifier. XXX: IPv6 specific */ +static int +ip6_str2scopeid(scope, sin6) + char *scope; + struct sockaddr_in6 *sin6; +{ + int scopeid; + struct in6_addr *a6 = &sin6->sin6_addr; + char *ep; + + /* empty scopeid portion is invalid */ + if (*scope == '\0') + return -1; + + if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) { + /* + * We currently assume a one-to-one mapping between links + * and interfaces, so we simply use interface indices for + * like-local scopes. + */ + scopeid = if_nametoindex(scope); + if (scopeid == 0) + goto trynumeric; + return(scopeid); + } - /* Rule 3: Avoid deprecated addresses. - That's something only the kernel could decide. */ + /* still unclear about literal, allow numeric only - placeholder */ + if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6)) + goto trynumeric; + if (IN6_IS_ADDR_MC_ORGLOCAL(a6)) + goto trynumeric; + else + goto trynumeric; /* global */ - /* Rule 4: Prefer home addresses. - Another thing only the kernel can decide. */ + /* try to convert to a numeric id as a last resort */ + trynumeric: + scopeid = (int)strtoul(scope, &ep, 10); + if (*ep == '\0') + return scopeid; + else + return -1; +} +#endif - /* Rule 5: Prefer matching label. */ - if (a1->got_source_addr) - { - int a1_dst_label - = get_label ((struct sockaddr_storage *) a1->dest_addr->ai_addr); - int a1_src_label = get_label (&a1->source_addr); +#ifdef DEBUG +static const char AskedForGot[] = + "gethostby*.getanswer: asked for \"%s\", got \"%s\""; +#endif +static FILE *hostf = NULL; + +static struct addrinfo * +getanswer(answer, anslen, qname, qtype, pai) + const querybuf *answer; + int anslen; + const char *qname; + int qtype; + const struct addrinfo *pai; +{ + struct addrinfo sentinel, *cur; + struct addrinfo ai; + const struct afd *afd; + char *canonname; + const HEADER *hp; + const u_char *cp; + int n; + const u_char *eom; + char *bp; + int type, class, buflen, ancount, qdcount; + int haveanswer, had_error; + char tbuf[MAXDNAME]; + int (*name_ok)(const char *); + char hostbuf[8*1024]; + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + canonname = NULL; + eom = answer->buf + anslen; + switch (qtype) { + case T_A: + case T_AAAA: + case T_ANY: /*use T_ANY only for T_A/T_AAAA lookup*/ + name_ok = res_hnok; + break; + default: + return (NULL); /* XXX should be abort(); */ + } + /* + * find first satisfactory answer + */ + hp = &answer->hdr; + ancount = ntohs(hp->ancount); + qdcount = ntohs(hp->qdcount); + bp = hostbuf; + buflen = sizeof hostbuf; + cp = answer->buf + HFIXEDSZ; + if (qdcount != 1) { + h_errno = NO_RECOVERY; + return (NULL); + } + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !(*name_ok)(bp)) { + h_errno = NO_RECOVERY; + return (NULL); + } + cp += n + QFIXEDSZ; + if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) { + /* res_send() has already verified that the query name is the + * same as the one we sent; this just gets the expanded name + * (i.e., with the succeeding search-domain tacked on). + */ + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + h_errno = NO_RECOVERY; + return (NULL); + } + canonname = bp; + bp += n; + buflen -= n; + /* The qname can be abbreviated, but h_name is now absolute. */ + qname = canonname; + } + haveanswer = 0; + had_error = 0; + while (ancount-- > 0 && cp < eom && !had_error) { + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !(*name_ok)(bp)) { + had_error++; + continue; + } + cp += n; /* name */ + type = _getshort(cp); + cp += INT16SZ; /* type */ + class = _getshort(cp); + cp += INT16SZ + INT32SZ; /* class, TTL */ + n = _getshort(cp); + cp += INT16SZ; /* len */ + if (class != C_IN) { + /* XXX - debug? syslog? */ + cp += n; + continue; /* XXX - had_error++ ? */ + } + if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) && + type == T_CNAME) { + n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + if ((n < 0) || !(*name_ok)(tbuf)) { + had_error++; + continue; + } + cp += n; + /* Get canonical name. */ + n = strlen(tbuf) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } + strcpy(bp, tbuf); + canonname = bp; + bp += n; + buflen -= n; + continue; + } + if (qtype == T_ANY) { + if (!(type == T_A || type == T_AAAA)) { + cp += n; + continue; + } + } else if (type != qtype) { +#ifdef DEBUG + if (type != T_KEY && type != T_SIG) + syslog(LOG_NOTICE|LOG_AUTH, + "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", + qname, p_class(C_IN), p_type(qtype), + p_type(type)); +#endif + cp += n; + continue; /* XXX - had_error++ ? */ + } + switch (type) { + case T_A: + case T_AAAA: + if (strcasecmp(canonname, bp) != 0) { +#ifdef DEBUG + syslog(LOG_NOTICE|LOG_AUTH, + AskedForGot, canonname, bp); +#endif + cp += n; + continue; /* XXX - had_error++ ? */ + } + if (type == T_A && n != INADDRSZ) { + cp += n; + continue; + } + if (type == T_AAAA && n != IN6ADDRSZ) { + cp += n; + continue; + } +#ifdef FILTER_V4MAPPED + if (type == T_AAAA) { + struct in6_addr in6; + memcpy(&in6, cp, sizeof(in6)); + if (IN6_IS_ADDR_V4MAPPED(&in6)) { + cp += n; + continue; + } + } +#endif + if (!haveanswer) { + int nn; - int a2_dst_label - = get_label ((struct sockaddr_storage *) a2->dest_addr->ai_addr); - int a2_src_label = get_label (&a2->source_addr); + canonname = bp; + nn = strlen(bp) + 1; /* for the \0 */ + bp += nn; + buflen -= nn; + } - if (a1_dst_label == a1_src_label && a2_dst_label != a2_src_label) - return -1; - if (a1_dst_label != a1_src_label && a2_dst_label == a2_src_label) - return 1; - } + /* don't overwrite pai */ + ai = *pai; + ai.ai_family = (type == T_A) ? AF_INET : AF_INET6; + afd = find_afd(ai.ai_family); + if (afd == NULL) { + cp += n; + continue; + } + cur->ai_next = get_ai(&ai, afd, (const char *)cp); + if (cur->ai_next == NULL) + had_error++; + while (cur && cur->ai_next) + cur = cur->ai_next; + cp += n; + break; + default: + abort(); + } + if (!had_error) + haveanswer++; + } + if (haveanswer) { + if (!canonname) + (void)get_canonname(pai, sentinel.ai_next, qname); + else + (void)get_canonname(pai, sentinel.ai_next, canonname); + h_errno = NETDB_SUCCESS; + return sentinel.ai_next; + } + h_errno = NO_RECOVERY; + return NULL; +} - /* Rule 6: Prefer higher precedence. */ - int a1_prec - = get_precedence ((struct sockaddr_storage *) a1->dest_addr->ai_addr); - int a2_prec - = get_precedence ((struct sockaddr_storage *) a2->dest_addr->ai_addr); +/*ARGSUSED*/ +static int +_dns_getaddrinfo(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + struct addrinfo *ai; + querybuf buf, buf2; + const char *name; + const struct addrinfo *pai; + struct addrinfo sentinel, *cur; + struct res_target q, q2; + + name = va_arg(ap, char *); + pai = va_arg(ap, const struct addrinfo *); + + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + switch (pai->ai_family) { + case AF_UNSPEC: + /* prefer IPv6 */ + q.qclass = C_IN; + q.qtype = T_AAAA; + q.answer = buf.buf; + q.anslen = sizeof(buf); + q.next = &q2; + q2.qclass = C_IN; + q2.qtype = T_A; + q2.answer = buf2.buf; + q2.anslen = sizeof(buf2); + break; + case AF_INET: + q.qclass = C_IN; + q.qtype = T_A; + q.answer = buf.buf; + q.anslen = sizeof(buf); + break; + case AF_INET6: + q.qclass = C_IN; + q.qtype = T_AAAA; + q.answer = buf.buf; + q.anslen = sizeof(buf); + break; + default: + return NS_UNAVAIL; + } + if (res_searchN(name, &q) < 0) + return NS_NOTFOUND; + ai = getanswer(&buf, q.n, q.name, q.qtype, pai); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + if (q.next) { + ai = getanswer(&buf2, q2.n, q2.name, q2.qtype, pai); + if (ai) + cur->ai_next = ai; + } + if (sentinel.ai_next == NULL) + switch (h_errno) { + case HOST_NOT_FOUND: + return NS_NOTFOUND; + case TRY_AGAIN: + return NS_TRYAGAIN; + default: + return NS_UNAVAIL; + } + *((struct addrinfo **)rv) = sentinel.ai_next; + return NS_SUCCESS; +} - if (a1_prec > a2_prec) - return -1; - if (a1_prec < a2_prec) - return 1; +static void +_sethtent() +{ + if (!hostf) + hostf = fopen(_PATH_HOSTS, "r" ); + else + rewind(hostf); +} +static void +_endhtent() +{ + if (hostf) { + (void) fclose(hostf); + hostf = NULL; + } +} - /* Rule 7: Prefer native transport. - XXX How to recognize tunnels? */ +static struct addrinfo * +_gethtent(name, pai) + const char *name; + const struct addrinfo *pai; +{ + char *p; + char *cp, *tname, *cname; + struct addrinfo hints, *res0, *res; + int error; + const char *addr; + char hostbuf[8*1024]; + + if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) + return (NULL); + again: + if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) + return (NULL); + if (*p == '#') + goto again; + if (!(cp = strpbrk(p, "#\n"))) + goto again; + *cp = '\0'; + if (!(cp = strpbrk(p, " \t"))) + goto again; + *cp++ = '\0'; + addr = p; + cname = NULL; + /* if this is not something we're looking for, skip it. */ + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + tname = cp; + if (cname == NULL) + cname = cp; + if ((cp = strpbrk(cp, " \t")) != NULL) + *cp++ = '\0'; + if (strcasecmp(name, tname) == 0) + goto found; + } + goto again; + +found: + hints = *pai; + hints.ai_flags = AI_NUMERICHOST; + error = getaddrinfo(addr, NULL, &hints, &res0); + if (error) + goto again; +#ifdef FILTER_V4MAPPED + /* XXX should check all items in the chain */ + if (res0->ai_family == AF_INET6 && + IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)res0->ai_addr)->sin6_addr)) { + freeaddrinfo(res0); + goto again; + } +#endif + for (res = res0; res; res = res->ai_next) { + /* cover it up */ + res->ai_flags = pai->ai_flags; + + if (pai->ai_flags & AI_CANONNAME) { + if (get_canonname(pai, res, cname) != 0) { + freeaddrinfo(res0); + goto again; + } + } + } + return res0; +} +/*ARGSUSED*/ +static int +_files_getaddrinfo(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + const char *name; + const struct addrinfo *pai; + struct addrinfo sentinel, *cur; + struct addrinfo *p; + + name = va_arg(ap, char *); + pai = va_arg(ap, struct addrinfo *); + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + _sethtent(); + while ((p = _gethtent(name, pai)) != NULL) { + cur->ai_next = p; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + _endhtent(); - /* Rule 8: Prefer smaller scope. */ - if (a1_dst_scope < a2_dst_scope) - return -1; - if (a1_dst_scope > a2_dst_scope) - return 1; + *((struct addrinfo **)rv) = sentinel.ai_next; + if (sentinel.ai_next == NULL) + return NS_NOTFOUND; + return NS_SUCCESS; +} +#ifdef YP +static char *__ypdomain; - /* Rule 9: Use longest matching prefix. */ - if (a1->got_source_addr - && a1->dest_addr->ai_family == a2->dest_addr->ai_family) - { - int bit1 = 0; - int bit2 = 0; +/*ARGSUSED*/ +static struct addrinfo * +_yphostent(line, pai) + char *line; + const struct addrinfo *pai; +{ + struct addrinfo sentinel, *cur; + struct addrinfo hints, *res, *res0; + int error; + char *p = line; + const char *addr, *canonname; + char *nextline; + char *cp; + + addr = canonname = NULL; + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + +nextline: + /* terminate line */ + cp = strchr(p, '\n'); + if (cp) { + *cp++ = '\0'; + nextline = cp; + } else + nextline = NULL; + + cp = strpbrk(p, " \t"); + if (cp == NULL) { + if (canonname == NULL) + return (NULL); + else + goto done; + } + *cp++ = '\0'; - if (a1->dest_addr->ai_family == PF_INET) - { - assert (a1->source_addr.ss_family == PF_INET); - assert (a2->source_addr.ss_family == PF_INET); + addr = p; - struct sockaddr_in *in1_dst; - struct sockaddr_in *in1_src; - struct sockaddr_in *in2_dst; - struct sockaddr_in *in2_src; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (!canonname) + canonname = cp; + if ((cp = strpbrk(cp, " \t")) != NULL) + *cp++ = '\0'; + } - in1_dst = (struct sockaddr_in *) a1->dest_addr->ai_addr; - in1_src = (struct sockaddr_in *) &a1->source_addr; - in2_dst = (struct sockaddr_in *) a2->dest_addr->ai_addr; - in2_src = (struct sockaddr_in *) &a2->source_addr; + hints = *pai; + hints.ai_flags = AI_NUMERICHOST; + error = getaddrinfo(addr, NULL, &hints, &res0); + if (error == 0) { + for (res = res0; res; res = res->ai_next) { + /* cover it up */ + res->ai_flags = pai->ai_flags; - bit1 = ffs (in1_dst->sin_addr.s_addr ^ in1_src->sin_addr.s_addr); - bit2 = ffs (in2_dst->sin_addr.s_addr ^ in2_src->sin_addr.s_addr); + if (pai->ai_flags & AI_CANONNAME) + (void)get_canonname(pai, res, canonname); + } + } else + res0 = NULL; + if (res0) { + cur->ai_next = res0; + while (cur && cur->ai_next) + cur = cur->ai_next; } - else if (a1->dest_addr->ai_family == PF_INET6) - { - assert (a1->source_addr.ss_family == PF_INET6); - assert (a2->source_addr.ss_family == PF_INET6); - - struct sockaddr_in6 *in1_dst; - struct sockaddr_in6 *in1_src; - struct sockaddr_in6 *in2_dst; - struct sockaddr_in6 *in2_src; - - in1_dst = (struct sockaddr_in6 *) a1->dest_addr->ai_addr; - in1_src = (struct sockaddr_in6 *) &a1->source_addr; - in2_dst = (struct sockaddr_in6 *) a2->dest_addr->ai_addr; - in2_src = (struct sockaddr_in6 *) &a2->source_addr; - - int i; - for (i = 0; i < 4; ++i) - if (in1_dst->sin6_addr.s6_addr32[i] - != in1_src->sin6_addr.s6_addr32[i] - || (in2_dst->sin6_addr.s6_addr32[i] - != in2_src->sin6_addr.s6_addr32[i])) - break; - - if (i < 4) - { - bit1 = ffs (in1_dst->sin6_addr.s6_addr32[i] - ^ in1_src->sin6_addr.s6_addr32[i]); - bit2 = ffs (in2_dst->sin6_addr.s6_addr32[i] - ^ in2_src->sin6_addr.s6_addr32[i]); - } + + if (nextline) { + p = nextline; + goto nextline; } - if (bit1 > bit2) - return -1; - if (bit1 < bit2) - return 1; - } +done: + return sentinel.ai_next; +} + +/*ARGSUSED*/ +static int +_yp_getaddrinfo(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + struct addrinfo sentinel, *cur; + struct addrinfo *ai = NULL; + static char *__ypcurrent; + int __ypcurrentlen, r; + const char *name; + const struct addrinfo *pai; + + name = va_arg(ap, char *); + pai = va_arg(ap, const struct addrinfo *); + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + if (!__ypdomain) { + if (_yp_check(&__ypdomain) == 0) + return NS_UNAVAIL; + } + if (__ypcurrent) + free(__ypcurrent); + __ypcurrent = NULL; + + /* hosts.byname is only for IPv4 (Solaris8) */ + if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) { + r = yp_match(__ypdomain, "hosts.byname", name, + (int)strlen(name), &__ypcurrent, &__ypcurrentlen); + if (r == 0) { + struct addrinfo ai4; + + ai4 = *pai; + ai4.ai_family = AF_INET; + ai = _yphostent(__ypcurrent, &ai4); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + } + } + /* ipnodes.byname can hold both IPv4/v6 */ + r = yp_match(__ypdomain, "ipnodes.byname", name, + (int)strlen(name), &__ypcurrent, &__ypcurrentlen); + if (r == 0) { + ai = _yphostent(__ypcurrent, pai); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + } - /* Rule 10: Otherwise, leave the order unchanged. */ - return 0; + if (sentinel.ai_next == NULL) { + h_errno = HOST_NOT_FOUND; + return NS_NOTFOUND; + } + *((struct addrinfo **)rv) = sentinel.ai_next; + return NS_SUCCESS; } +#endif - -int -getaddrinfo (const char *name, const char *service, - const struct addrinfo *hints, struct addrinfo **pai) +/* resolver logic */ + +extern const char *__hostalias(const char *); +extern int h_errno; + +/* + * Formulate a normal query, send, and await answer. + * Returned answer is placed in supplied buffer "answer". + * Perform preliminary check of answer, returning success only + * if no error is indicated and the answer count is nonzero. + * Return the size of the response on success, -1 on error. + * Error number is left in h_errno. + * + * Caller must parse answer and determine whether it answers the question. + */ +static int +res_queryN(name, target) + const char *name; /* domain name */ + struct res_target *target; { - int i = 0, j = 0, last_i = 0; - int nresults = 0; - struct addrinfo *p = NULL, **end; - struct gaih *g = gaih, *pg = NULL; - struct gaih_service gaih_service, *pservice; - struct addrinfo local_hints; - - if (name != NULL && name[0] == '*' && name[1] == 0) - name = NULL; - - if (service != NULL && service[0] == '*' && service[1] == 0) - service = NULL; - - if (name == NULL && service == NULL) - return EAI_NONAME; - - if (hints == NULL) - hints = &default_hints; - - if (hints->ai_flags - & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|AI_ADDRCONFIG|AI_V4MAPPED -#ifdef HAVE_LIBIDN - |AI_IDN|AI_CANONIDN|AI_IDN_ALLOW_UNASSIGNED - |AI_IDN_USE_STD3_ASCII_RULES -#endif - |AI_NUMERICSERV|AI_ALL)) - return EAI_BADFLAGS; - - if ((hints->ai_flags & AI_CANONNAME) && name == NULL) - return EAI_BADFLAGS; - - if (hints->ai_flags & AI_ADDRCONFIG) - { - /* Determine whether we have IPv4 or IPv6 interfaces or both. - We cannot cache the results since new interfaces could be - added at any time. */ - bool seen_ipv4; - bool seen_ipv6; - __check_pf (&seen_ipv4, &seen_ipv6); - - /* Now make a decision on what we return, if anything. */ - if (hints->ai_family == PF_UNSPEC && (seen_ipv4 || seen_ipv6)) - { - /* If we haven't seen both IPv4 and IPv6 interfaces we can - narrow down the search. */ - if (! seen_ipv4 || ! seen_ipv6) - { - local_hints = *hints; - local_hints.ai_family = seen_ipv4 ? PF_INET : PF_INET6; - hints = &local_hints; - } - } - else if ((hints->ai_family == PF_INET && ! seen_ipv4) - || (hints->ai_family == PF_INET6 && ! seen_ipv6)) - /* We cannot possibly return a valid answer. */ - return EAI_NONAME; - } - - if (service && service[0]) - { - char *c; - gaih_service.name = service; - gaih_service.num = strtoul (gaih_service.name, &c, 10); - if (*c != '\0') - { - if (hints->ai_flags & AI_NUMERICSERV) - return EAI_NONAME; - - gaih_service.num = -1; + u_char buf[MAXPACKET]; + HEADER *hp; + int n; + struct res_target *t; + int rcode; + int ancount; + + rcode = NOERROR; + ancount = 0; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); } - pservice = &gaih_service; - } - else - pservice = NULL; - - if (pai) - end = &p; - else - end = NULL; - - while (g->gaih) - { - if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC) - { - j++; - if (pg == NULL || pg->gaih != g->gaih) - { - pg = g; - i = g->gaih (name, pservice, hints, end); - if (i != 0) - { - /* EAI_NODATA is a more specific result as it says that - we found a result but it is not usable. */ - if (last_i != (GAIH_OKIFUNSPEC | -EAI_NODATA)) - last_i = i; - - if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC)) - { - ++g; - continue; - } - - freeaddrinfo (p); - - return -(i & GAIH_EAI); + for (t = target; t; t = t->next) { + int class, type; + u_char *answer; + int anslen; + + hp = (HEADER *)(void *)t->answer; + hp->rcode = NOERROR; /* default */ + + /* make it easier... */ + class = t->qclass; + type = t->qtype; + answer = t->answer; + anslen = t->anslen; +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf(";; res_query(%s, %d, %d)\n", name, class, type); +#endif + + n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, + buf, sizeof(buf)); + if (n > 0 && (_res.options & RES_USE_EDNS0) != 0) + n = res_opt(n, buf, sizeof(buf), anslen); + if (n <= 0) { +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf(";; res_query: mkquery failed\n"); +#endif + h_errno = NO_RECOVERY; + return (n); + } + n = res_send(buf, n, answer, anslen); +#if 0 + if (n < 0) { +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf(";; res_query: send error\n"); +#endif + h_errno = TRY_AGAIN; + return (n); + } +#endif + + if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { + rcode = hp->rcode; /* record most recent error */ +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf(";; rcode = %d, ancount=%d\n", hp->rcode, + ntohs(hp->ancount)); +#endif + continue; } - if (end) - while (*end) - { - end = &((*end)->ai_next); - ++nresults; - } - } + + ancount += ntohs(hp->ancount); + + t->n = n; } - ++g; - } - - if (j == 0) - return EAI_FAMILY; - - if (nresults > 1) - { - /* Sort results according to RFC 3484. */ - struct sort_result results[nresults]; - struct addrinfo *q; - struct addrinfo *last = NULL; - char *canonname = NULL; - - for (i = 0, q = p; q != NULL; ++i, last = q, q = q->ai_next) - { - results[i].dest_addr = q; - results[i].got_source_addr = false; - - /* If we just looked up the address for a different - protocol, reuse the result. */ - if (last != NULL && last->ai_addrlen == q->ai_addrlen - && memcmp (last->ai_addr, q->ai_addr, q->ai_addrlen) == 0) - { - memcpy (&results[i].source_addr, &results[i - 1].source_addr, - results[i - 1].source_addr_len); - results[i].source_addr_len = results[i - 1].source_addr_len; - results[i].got_source_addr = results[i - 1].got_source_addr; - } - else - { - /* We overwrite the type with SOCK_DGRAM since we do not - want connect() to connect to the other side. If we - cannot determine the source address remember this - fact. */ - int fd = socket (q->ai_family, SOCK_DGRAM, IPPROTO_IP); - socklen_t sl = sizeof (results[i].source_addr); - if (fd != -1 - && connect (fd, q->ai_addr, q->ai_addrlen) == 0 - && getsockname (fd, - (struct sockaddr *) &results[i].source_addr, - &sl) == 0) - { - results[i].source_addr_len = sl; - results[i].got_source_addr = true; + + if (ancount == 0) { + switch (rcode) { + case NXDOMAIN: + h_errno = HOST_NOT_FOUND; + break; + case SERVFAIL: + h_errno = TRY_AGAIN; + break; + case NOERROR: + h_errno = NO_DATA; + break; + case FORMERR: + case NOTIMP: + case REFUSED: + default: + h_errno = NO_RECOVERY; + break; } - else - /* Just make sure that if we have to process the same - address again we do not copy any memory. */ - results[i].source_addr_len = 0; - - if (fd != -1) - close_not_cancel_no_status (fd); - } - - /* Remember the canonical name. */ - if (q->ai_canonname != NULL) - { - assert (canonname == NULL); - canonname = q->ai_canonname; - q->ai_canonname = NULL; - } + return (-1); } + return (ancount); +} - /* We got all the source addresses we can get, now sort using - the information. */ - qsort (results, nresults, sizeof (results[0]), rfc3484_sort); +/* + * Formulate a normal query, send, and retrieve answer in supplied buffer. + * Return the size of the response on success, -1 on error. + * If enabled, implement search rules until answer or unrecoverable failure + * is detected. Error code, if any, is left in h_errno. + */ +static int +res_searchN(name, target) + const char *name; /* domain name */ + struct res_target *target; +{ + const char *cp, * const *domain; + HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ + u_int dots; + int trailing_dot, ret, saved_herrno; + int got_nodata = 0, got_servfail = 0, tried_as_is = 0; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } - /* Queue the results up as they come out of sorting. */ - q = p = results[0].dest_addr; - for (i = 1; i < nresults; ++i) - q = q->ai_next = results[i].dest_addr; - q->ai_next = NULL; + errno = 0; + h_errno = HOST_NOT_FOUND; /* default, if we never query */ + dots = 0; + for (cp = name; *cp; cp++) + dots += (*cp == '.'); + trailing_dot = 0; + if (cp > name && *--cp == '.') + trailing_dot++; + + /* + * if there aren't any dots, it could be a user-level alias + */ + if (!dots && (cp = __hostalias(name)) != NULL) + return (res_queryN(cp, target)); + + /* + * If there are dots in the name already, let's just give it a try + * 'as is'. The threshold can be set with the "ndots" option. + */ + saved_herrno = -1; + if (dots >= _res.ndots) { + ret = res_querydomainN(name, NULL, target); + if (ret > 0) + return (ret); + saved_herrno = h_errno; + tried_as_is++; + } - /* Fill in the canonical name into the new first entry. */ - p->ai_canonname = canonname; - } + /* + * We do at least one level of search if + * - there is no dot and RES_DEFNAME is set, or + * - there is at least one dot, there is no trailing dot, + * and RES_DNSRCH is set. + */ + if ((!dots && (_res.options & RES_DEFNAMES)) || + (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { + int done = 0; + + for (domain = (const char * const *)_res.dnsrch; + *domain && !done; + domain++) { + + ret = res_querydomainN(name, *domain, target); + if (ret > 0) + return (ret); + + /* + * If no server present, give up. + * If name isn't found in this domain, + * keep trying higher domains in the search list + * (if that's enabled). + * On a NO_DATA error, keep trying, otherwise + * a wildcard entry of another type could keep us + * from finding this entry higher in the domain. + * If we get some other error (negative answer or + * server failure), then stop searching up, + * but try the input name below in case it's + * fully-qualified. + */ + if (errno == ECONNREFUSED) { + h_errno = TRY_AGAIN; + return (-1); + } - if (p) - { - *pai = p; - return 0; - } + switch (h_errno) { + case NO_DATA: + got_nodata++; + /* FALLTHROUGH */ + case HOST_NOT_FOUND: + /* keep trying */ + break; + case TRY_AGAIN: + if (hp->rcode == SERVFAIL) { + /* try next search element, if any */ + got_servfail++; + break; + } + /* FALLTHROUGH */ + default: + /* anything else implies that we're done */ + done++; + } + /* + * if we got here for some reason other than DNSRCH, + * we only wanted one iteration of the loop, so stop. + */ + if (!(_res.options & RES_DNSRCH)) + done++; + } + } - if (pai == NULL && last_i == 0) - return 0; + /* + * if we have not already tried the name "as is", do that now. + * note that we do this regardless of how many dots were in the + * name or whether it ends with a dot. + */ + if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) { + ret = res_querydomainN(name, NULL, target); + if (ret > 0) + return (ret); + } - return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME; + /* + * if we got here, we didn't satisfy the search. + * if we did an initial full query, return that query's h_errno + * (note that we wouldn't be here if that query had succeeded). + * else if we ever got a nodata, send that back as the reason. + * else send back meaningless h_errno, that being the one from + * the last DNSRCH we did. + */ + if (saved_herrno != -1) + h_errno = saved_herrno; + else if (got_nodata) + h_errno = NO_DATA; + else if (got_servfail) + h_errno = TRY_AGAIN; + return (-1); } -libc_hidden_def (getaddrinfo) -static_link_warning (getaddrinfo) - -void -freeaddrinfo (struct addrinfo *ai) +/* + * Perform a call on res_query on the concatenation of name and domain, + * removing a trailing dot from name if domain is NULL. + */ +static int +res_querydomainN(name, domain, target) + const char *name, *domain; + struct res_target *target; { - struct addrinfo *p; - - while (ai != NULL) - { - p = ai; - ai = ai->ai_next; - free (p->ai_canonname); - free (p); - } + char nbuf[MAXDNAME]; + const char *longname = nbuf; + size_t n, d; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf(";; res_querydomain(%s, %s)\n", + name, domain?domain:""); +#endif + if (domain == NULL) { + /* + * Check for trailing '.'; + * copy without '.' if present. + */ + n = strlen(name); + if (n >= MAXDNAME) { + h_errno = NO_RECOVERY; + return (-1); + } + if (n > 0 && name[--n] == '.') { + strncpy(nbuf, name, n); + nbuf[n] = '\0'; + } else + longname = name; + } else { + n = strlen(name); + d = strlen(domain); + if (n + d + 1 >= MAXDNAME) { + h_errno = NO_RECOVERY; + return (-1); + } + sprintf(nbuf, "%s.%s", name, domain); + } + return (res_queryN(longname, target)); } -libc_hidden_def (freeaddrinfo) diff --git a/newlib/libc/sys/linux/net/getaliasent.c b/newlib/libc/sys/linux/net/getaliasent.c deleted file mode 100644 index e3234752e..000000000 --- a/newlib/libc/sys/linux/net/getaliasent.c +++ /dev/null @@ -1,26 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct aliasent -#define GETFUNC_NAME getaliasent -#define BUFLEN 1024 - -#include "getXXent.c" diff --git a/newlib/libc/sys/linux/net/getaliasent_r.c b/newlib/libc/sys/linux/net/getaliasent_r.c deleted file mode 100644 index 70dbc26b1..000000000 --- a/newlib/libc/sys/linux/net/getaliasent_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct aliasent -#define SETFUNC_NAME setaliasent -#define GETFUNC_NAME getaliasent -#define ENDFUNC_NAME endaliasent -#define DATABASE_NAME aliases - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getaliasname.c b/newlib/libc/sys/linux/net/getaliasname.c deleted file mode 100644 index 2ad315f9f..000000000 --- a/newlib/libc/sys/linux/net/getaliasname.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct aliasent -#define FUNCTION_NAME getaliasbyname -#define DATABASE_NAME aliases -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getaliasname_r.c b/newlib/libc/sys/linux/net/getaliasname_r.c deleted file mode 100644 index ec3519d57..000000000 --- a/newlib/libc/sys/linux/net/getaliasname_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct aliasent -#define FUNCTION_NAME getaliasbyname -#define DATABASE_NAME aliases -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/gethostbydns.c b/newlib/libc/sys/linux/net/gethostbydns.c new file mode 100644 index 000000000..9c80539f2 --- /dev/null +++ b/newlib/libc/sys/linux/net/gethostbydns.c @@ -0,0 +1,815 @@ +/* + * ++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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "res_config.h" + +#define SPRINTF(x) ((size_t)sprintf x) + +static const char AskedForGot[] = + "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; + +#ifdef RESOLVSORT +static void addrsort(char **, int); +#endif + +u_int32_t _getlong(const u_char *src); +u_int16_t _getshort(const u_char *src); + +#ifdef DEBUG +static void dbgprintf(char *, int); +#endif + +#if PACKETSZ > 1024 +#define MAXPACKET PACKETSZ +#else +#define MAXPACKET 1024 +#endif + +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +typedef union { + int32_t al; + char ac; +} align; + +extern int h_errno; +int _dns_ttl_; + +#ifdef DEBUG +static void +dbgprintf(msg, num) + char *msg; + int num; +{ + if (_res.options & RES_DEBUG) { + int save = errno; + + printf(msg, num); + errno = save; + } +} +#else +# define dbgprintf(msg, num) /*nada*/ +#endif + +#define BOUNDED_INCR(x) \ + do { \ + cp += x; \ + if (cp > eom) { \ + *herr = NO_RECOVERY; \ + return (NULL); \ + } \ + } while (0) + +#define BOUNDS_CHECK(ptr, count) \ + do { \ + if ((ptr) + (count) > eom) { \ + *herr = NO_RECOVERY; \ + return (NULL); \ + } \ + } while (0) + +static struct hostent * +gethostanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr) + const querybuf *answer; + int anslen; + const char *qname; + int qtype; + struct hostent *host; + char *hostbuf; + int hostbuflen; + int *herr; +{ + const HEADER *hp; + const u_char *cp; + int n; + const u_char *eom, *erdata; + char *bp, **ap, **hap; + int type, class, buflen, ancount, qdcount; + int haveanswer, had_error; + int toobig = 0; + char tbuf[MAXDNAME]; + const char *tname; + int (*name_ok)(const char *); + + tname = qname; + host->h_name = NULL; + eom = answer->buf + anslen; + switch (qtype) { + case T_A: + case T_AAAA: + name_ok = res_hnok; + break; + case T_PTR: + name_ok = res_dnok; + break; + default: + *herr = NO_RECOVERY; + return (NULL); /* XXX should be abort(); */ + } + /* + * find first satisfactory answer + */ + hp = &answer->hdr; + ancount = ntohs(hp->ancount); + qdcount = ntohs(hp->qdcount); + bp = hostbuf; + buflen = hostbuflen; + cp = answer->buf; + BOUNDED_INCR(HFIXEDSZ); + if (qdcount != 1) { + *herr = NO_RECOVERY; + return (NULL); + } + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !(*name_ok)(bp)) { + *herr = NO_RECOVERY; + return (NULL); + } + BOUNDED_INCR(n + QFIXEDSZ); + if (qtype == T_A || qtype == T_AAAA) { + /* res_send() has already verified that the query name is the + * same as the one we sent; this just gets the expanded name + * (i.e., with the succeeding search-domain tacked on). + */ + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + *herr = NO_RECOVERY; + return (NULL); + } + host->h_name = bp; + bp += n; + buflen -= n; + /* The qname can be abbreviated, but h_name is now absolute. */ + qname = host->h_name; + } + ap = host->__host_aliases; + *ap = NULL; + host->h_aliases = host->__host_aliases; + hap = host->__host_addrs; + *hap = NULL; + host->h_addr_list = host->__host_addrs; + haveanswer = 0; + had_error = 0; + _dns_ttl_ = -1; + while (ancount-- > 0 && cp < eom && !had_error) { + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !(*name_ok)(bp)) { + had_error++; + continue; + } + cp += n; /* name */ + BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ); + type = _getshort(cp); + cp += INT16SZ; /* type */ + class = _getshort(cp); + cp += INT16SZ; /* class */ + if (qtype == T_A && type == T_A) + _dns_ttl_ = _getlong(cp); + cp += INT32SZ; /* TTL */ + n = _getshort(cp); + cp += INT16SZ; /* len */ + BOUNDS_CHECK(cp, n); + erdata = cp + n; + if (class != C_IN) { + /* XXX - debug? syslog? */ + cp += n; + continue; /* XXX - had_error++ ? */ + } + if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { + if (ap >= &host->__host_aliases[MAXALIASES-1]) + continue; + n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + if ((n < 0) || !(*name_ok)(tbuf)) { + had_error++; + continue; + } + cp += n; + if (cp != erdata) { + *herr = NO_RECOVERY; + return (NULL); + } + /* Store alias. */ + *ap++ = bp; + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } + bp += n; + buflen -= n; + /* Get canonical name. */ + n = strlen(tbuf) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } + strcpy(bp, tbuf); + host->h_name = bp; + bp += n; + buflen -= n; + continue; + } + if (qtype == T_PTR && type == T_CNAME) { + n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + if (n < 0 || !res_dnok(tbuf)) { + had_error++; + continue; + } + cp += n; + if (cp != erdata) { + *herr = NO_RECOVERY; + return (NULL); + } + /* Get canonical name. */ + n = strlen(tbuf) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } + strcpy(bp, tbuf); + tname = bp; + bp += n; + buflen -= n; + continue; + } + if (type != qtype) { + if (type != T_SIG) + syslog(LOG_NOTICE|LOG_AUTH, + "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"", + qname, p_class(C_IN), p_type(qtype), + p_type(type)); + cp += n; + continue; /* XXX - had_error++ ? */ + } + switch (type) { + case T_PTR: + if (strcasecmp(tname, bp) != 0) { + syslog(LOG_NOTICE|LOG_AUTH, + AskedForGot, qname, bp); + cp += n; + continue; /* XXX - had_error++ ? */ + } + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !res_hnok(bp)) { + had_error++; + break; + } +#if MULTI_PTRS_ARE_ALIASES + cp += n; + if (cp != erdata) { + *herr = NO_RECOVERY; + return (NULL); + } + if (!haveanswer) + host->h_name = bp; + else if (ap < &host->__host_aliases[MAXALIASES-1]) + *ap++ = bp; + else + n = -1; + if (n != -1) { + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + break; + } + bp += n; + buflen -= n; + } + break; +#else + host->h_name = bp; + if (_res.options & RES_USE_INET6) { + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + break; + } + bp += n; + buflen -= n; + _map_v4v6_hostent(host, &bp, &buflen); + } + *herr = NETDB_SUCCESS; + return host; +#endif + case T_A: + case T_AAAA: + if (strcasecmp(host->h_name, bp) != 0) { + syslog(LOG_NOTICE|LOG_AUTH, + AskedForGot, host->h_name, bp); + cp += n; + continue; /* XXX - had_error++ ? */ + } + if (n != host->h_length) { + cp += n; + continue; + } + if (!haveanswer) { + int nn; + + host->h_name = bp; + nn = strlen(bp) + 1; /* for the \0 */ + bp += nn; + buflen -= nn; + } + + bp += sizeof(align) - ((u_long)bp % sizeof(align)); + + if (bp + n >= &hostbuf[hostbuflen]) { + dbgprintf("size (%d) too big\n", n); + had_error++; + continue; + } + if (hap >= &host->__host_addrs[MAXADDRS-1]) { + if (!toobig++) + dbgprintf("Too many addresses (%d)\n", + MAXADDRS); + cp += n; + continue; + } + bcopy(cp, *hap++ = bp, n); + bp += n; + buflen -= n; + cp += n; + if (cp != erdata) { + *herr = NO_RECOVERY; + return (NULL); + } + break; + default: + dbgprintf("Impossible condition (type=%d)\n", type); + *herr = NO_RECOVERY; + return (NULL); + /* BIND has abort() here, too risky on bad data */ + } + if (!had_error) + haveanswer++; + } + if (haveanswer) { + *ap = NULL; + *hap = NULL; +# if defined(RESOLVSORT) + /* + * Note: we sort even if host can take only one address + * in its return structures - should give it the "best" + * address in that case, not some random one + */ + if (_res.nsort && haveanswer > 1 && qtype == T_A) + addrsort(host->__host_addrs, haveanswer); +# endif /*RESOLVSORT*/ + if (!host->h_name) { + n = strlen(qname) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) + goto no_recovery; + strcpy(bp, qname); + host->h_name = bp; + bp += n; + buflen -= n; + } + if (_res.options & RES_USE_INET6) + _map_v4v6_hostent(host, &bp, &buflen); + *herr = NETDB_SUCCESS; + return host; + } + no_recovery: + *herr = NO_RECOVERY; + return (NULL); +} + +struct hostent * +__dns_getanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr) + const char *answer; + int anslen; + const char *qname; + int qtype; + struct hostent *host; + char *hostbuf; + int hostbuflen; + int *herr; +{ + switch(qtype) { + case T_AAAA: + host->h_addrtype = AF_INET6; + host->h_length = IN6ADDRSZ; + break; + case T_A: + default: + host->h_addrtype = AF_INET; + host->h_length = INADDRSZ; + break; + } + + return(gethostanswer((const querybuf *)answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr)); +} + +int +_dns_gethostbyname(void *rval, void *cb_data, va_list ap) +{ + const char *name; + int af; + querybuf buf; + const char *cp; + char *bp; + int n, size, type, len; + struct hostent *resultbuf; + char *hostbuf; + int buflen; + int *herr; + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + hostbuf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + *herr = NETDB_INTERNAL; + return NS_UNAVAIL; + } + + switch (af) { + case AF_INET: + size = INADDRSZ; + type = T_A; + break; + case AF_INET6: + size = IN6ADDRSZ; + type = T_AAAA; + break; + default: + *herr = NETDB_INTERNAL; + errno = EAFNOSUPPORT; + return NS_UNAVAIL; + } + + resultbuf->h_addrtype = af; + resultbuf->h_length = size; + + /* + * if there aren't any dots, it could be a user-level alias. + * this is also done in res_query() since we are not the only + * function that looks up host names. + */ + if (!strchr(name, '.') && (cp = __hostalias(name))) + name = cp; + + /* + * disallow names consisting only of digits/dots, unless + * they end in a dot. + */ + if (isdigit((unsigned char)name[0])) + for (cp = name;; ++cp) { + if (!*cp) { + if (*--cp == '.') + break; + /* + * All-numeric, no dot at the end. + * Fake up a hostent as if we'd actually + * done a lookup. + */ + if (inet_pton(af, name, resultbuf->__host_addr) <= 0) { + *herr = HOST_NOT_FOUND; + return NS_NOTFOUND; + } + strncpy(hostbuf, name, MAXDNAME); + hostbuf[MAXDNAME] = '\0'; + bp = hostbuf + MAXDNAME; + len = buflen - MAXDNAME; + resultbuf->h_name = hostbuf; + resultbuf->h_aliases = resultbuf->__host_aliases; + resultbuf->__host_aliases[0] = NULL; + resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; + resultbuf->__host_addrs[1] = NULL; + resultbuf->h_addr_list = resultbuf->__host_addrs; + if (_res.options & RES_USE_INET6) + _map_v4v6_hostent(resultbuf, &bp, &len); + *herr = NETDB_SUCCESS; + *(struct hostent **)rval = resultbuf; + return NS_SUCCESS; + } + if (!isdigit((unsigned char)*cp) && *cp != '.') + break; + } + if ((isxdigit((unsigned char)name[0]) && strchr(name, ':') != NULL) || + name[0] == ':') + for (cp = name;; ++cp) { + if (!*cp) { + if (*--cp == '.') + break; + /* + * All-IPv6-legal, no dot at the end. + * Fake up a hostent as if we'd actually + * done a lookup. + */ + if (inet_pton(af, name, resultbuf->__host_addr) <= 0) { + *herr = HOST_NOT_FOUND; + return NS_NOTFOUND; + } + strncpy(hostbuf, name, MAXDNAME); + hostbuf[MAXDNAME] = '\0'; + bp = hostbuf + MAXDNAME; + len = buflen - MAXDNAME; + resultbuf->h_name = hostbuf; + resultbuf->h_aliases = resultbuf->__host_aliases; + resultbuf->__host_aliases[0] = NULL; + resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; + resultbuf->__host_addrs[1] = NULL; + resultbuf->h_addr_list = resultbuf->__host_addrs; + *herr = NETDB_SUCCESS; + *(struct hostent **)rval = resultbuf; + return NS_SUCCESS; + } + if (!isxdigit((unsigned char)*cp) && *cp != ':' && *cp != '.') + break; + } + + if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) { + dbgprintf("res_search failed (%d)\n", n); + return NS_UNAVAIL; + } + *(struct hostent **)rval = gethostanswer(&buf, n, name, type, resultbuf, hostbuf, buflen, herr); + return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +int +_dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) +{ + const char *addr; /* XXX should have been def'd as u_char! */ + int len, af; + const u_char *uaddr; + static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; + static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; + int n, size; + querybuf buf; + struct hostent *hp; + char qbuf[MAXDNAME+1], *qp; +#ifdef SUNSECURITY + struct hostent *rhp; + char **haddr; + u_long old_options; + char hname2[MAXDNAME+1]; +#endif /*SUNSECURITY*/ + struct hostent *resultbuf; + char *hostbuf; + int buflen; + int *herr; + + addr = va_arg(ap, const char *); + uaddr = (const u_char *)addr; + len = va_arg(ap, int); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + hostbuf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + *herr = NETDB_INTERNAL; + return NS_UNAVAIL; + } + if (af == AF_INET6 && len == IN6ADDRSZ && + (!memcmp(uaddr, mapped, sizeof mapped) || + !memcmp(uaddr, tunnelled, sizeof tunnelled))) { + /* Unmap. */ + addr += sizeof mapped; + uaddr += sizeof mapped; + af = AF_INET; + len = INADDRSZ; + } + switch (af) { + case AF_INET: + size = INADDRSZ; + break; + case AF_INET6: + size = IN6ADDRSZ; + break; + default: + errno = EAFNOSUPPORT; + *herr = NETDB_INTERNAL; + return NS_UNAVAIL; + } + if (size != len) { + errno = EINVAL; + *herr = NETDB_INTERNAL; + return NS_UNAVAIL; + } + switch (af) { + case AF_INET: + (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", + (uaddr[3] & 0xff), + (uaddr[2] & 0xff), + (uaddr[1] & 0xff), + (uaddr[0] & 0xff)); + break; + case AF_INET6: + qp = qbuf; + for (n = IN6ADDRSZ - 1; n >= 0; n--) { + qp += SPRINTF((qp, "%x.%x.", + uaddr[n] & 0xf, + (uaddr[n] >> 4) & 0xf)); + } + strcpy(qp, "ip6.int"); + break; + default: + abort(); + } + n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf); + if (n < 0) { + dbgprintf("res_query failed (%d)\n", n); + return NS_UNAVAIL; + } + if (n > sizeof buf.buf) { + dbgprintf("static buffer is too small (%d)\n", n); + return NS_UNAVAIL; + } + if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR, resultbuf, hostbuf, buflen, herr))) + return NS_NOTFOUND; /* *herr was set by gethostanswer() */ +#ifdef SUNSECURITY + if (af == AF_INET) { + /* + * turn off search as the name should be absolute, + * 'localhost' should be matched by defnames + */ + strncpy(hname2, hp->h_name, MAXDNAME); + hname2[MAXDNAME] = '\0'; + old_options = _res.options; + _res.options &= ~RES_DNSRCH; + _res.options |= RES_DEFNAMES; + if (!(rhp = gethostbyname(hname2))) { + syslog(LOG_NOTICE|LOG_AUTH, + "gethostbyaddr: No A record for %s (verifying [%s])", + hname2, inet_ntoa(*((struct in_addr *)addr))); + _res.options = old_options; + *herr = HOST_NOT_FOUND; + return NS_NOTFOUND; + } + _res.options = old_options; + for (haddr = rhp->h_addr_list; *haddr; haddr++) + if (!memcmp(*haddr, addr, INADDRSZ)) + break; + if (!*haddr) { + syslog(LOG_NOTICE|LOG_AUTH, + "gethostbyaddr: A record of %s != PTR record [%s]", + hname2, inet_ntoa(*((struct in_addr *)addr))); + *herr = HOST_NOT_FOUND; + return NS_NOTFOUND; + } + } +#endif /*SUNSECURITY*/ + hp->h_addrtype = af; + hp->h_length = len; + bcopy(addr, resultbuf->__host_addr, len); + resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; + resultbuf->__host_addrs[1] = NULL; + if (af == AF_INET && (_res.options & RES_USE_INET6)) { + _map_v4v6_address((char*)resultbuf->__host_addr, (char*)resultbuf->__host_addr); + hp->h_addrtype = AF_INET6; + hp->h_length = IN6ADDRSZ; + } + *herr = NETDB_SUCCESS; + *(struct hostent **)rval = hp; + return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +#ifdef RESOLVSORT +static void +addrsort(ap, num) + char **ap; + int num; +{ + int i, j; + char **p; + short aval[MAXADDRS]; + int needsort = 0; + + p = ap; + for (i = 0; i < num; i++, p++) { + for (j = 0 ; (unsigned)j < _res.nsort; j++) + if (_res.sort_list[j].addr.s_addr == + (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) + break; + aval[i] = j; + if (needsort == 0 && i > 0 && j < aval[i-1]) + needsort = i; + } + if (!needsort) + return; + + while (needsort < num) { + for (j = needsort - 1; j >= 0; j--) { + if (aval[j] > aval[j+1]) { + char *hp; + + i = aval[j]; + aval[j] = aval[j+1]; + aval[j+1] = i; + + hp = ap[j]; + ap[j] = ap[j+1]; + ap[j+1] = hp; + + } else + break; + } + needsort++; + } +} +#endif +void +_sethostdnsent(stayopen) + int stayopen; +{ + if ((_res.options & RES_INIT) == 0 && res_init() == -1) + return; + if (stayopen) + _res.options |= RES_STAYOPEN | RES_USEVC; +} + +void +_endhostdnsent() +{ + _res.options &= ~(RES_STAYOPEN | RES_USEVC); + res_close(); +} diff --git a/newlib/libc/sys/linux/net/gethostbyht.c b/newlib/libc/sys/linux/net/gethostbyht.c new file mode 100644 index 000000000..4a15293dd --- /dev/null +++ b/newlib/libc/sys/linux/net/gethostbyht.c @@ -0,0 +1,285 @@ +/*- + * 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* XXX */ +#include /* XXX */ +#include +#include +#include + +static FILE *hostf = NULL; +static int stayopen = 0; +__LOCK_INIT(static, host_lock); + +void +_sethosthtent_r(int f, FILE **hostfile, int *hstayopen) +{ + if (!*hostfile) + *hostfile = fopen(_PATH_HOSTS, "r" ); + else + rewind(*hostfile); + *hstayopen = f; +} + +void +_endhosthtent_r(FILE **hostfile, int *hstayopen) +{ + if (*hostfile && !*hstayopen) { + (void) fclose(*hostfile); + *hostfile = NULL; + } +} + +void +_sethosthtent(f) + int f; +{ + _sethosthtent_r(f, &hostf, &stayopen); +} + +void +_endhosthtent() +{ + _endhosthtent_r(&hostf, &stayopen); +} + +struct hostent * +gethostent() +{ + static struct hostent hp; + static char buffer[BUFSIZ+1]; + static int len = BUFSIZ; + static int herr; + +#ifdef HAVE_DD_LOCK + __lock_acquire(host_lock); +#endif + gethostent_r(&hp, buffer, len, &herr, &hostf); +#ifdef HAVE_DD_LOCK + __lock_release(host_lock); +#endif + return &hp; +} + +int +gethostent_r(struct hostent *hp, char *buffer, int buflen, int *herr, FILE **hostfile) +{ + char *p; + char *cp, **q; + int af, len; + + if (!*hostfile && !(*hostfile = fopen(_PATH_HOSTS, "r" ))) { + *herr = NETDB_INTERNAL; + return -1; + } + again: + if (!(p = fgets(buffer, buflen, *hostfile))) { + *herr = HOST_NOT_FOUND; + return -1; + } + if (*p == '#') + goto again; + if (!(cp = strpbrk(p, "#\n"))) + goto again; + *cp = '\0'; + if (!(cp = strpbrk(p, " \t"))) + goto again; + *cp++ = '\0'; + + hp->h_addr_list = hp->__host_addrs; + hp->__host_addrs[0] = (char *)hp->__host_addr; + + if (inet_pton(AF_INET6, p, hp->h_addr_list[0]) > 0) { + af = AF_INET6; + len = IN6ADDRSZ; + } else if (inet_pton(AF_INET, p, hp->h_addr_list[0]) > 0) { + if (_res.options & RES_USE_INET6) { + _map_v4v6_address(hp->h_addr_list[0], hp->h_addr_list[0]); + af = AF_INET6; + len = IN6ADDRSZ; + } else { + af = AF_INET; + len = INADDRSZ; + } + } else { + goto again; + } + + + hp->h_addr_list[1] = NULL; + hp->h_addr = hp->__host_addrs[0]; + hp->h_length = len; + hp->h_addrtype = af; + + while (*cp == ' ' || *cp == '\t') + cp++; + hp->h_name = cp; + q = hp->h_aliases = hp->__host_aliases; + if ((cp = strpbrk(cp, " \t")) != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &hp->h_aliases[MAXALIASES - 1]) + *q++ = cp; + if ((cp = strpbrk(cp, " \t")) != NULL) + *cp++ = '\0'; + } + *q = NULL; + + *herr = NETDB_SUCCESS; + return 0; +} + +int +_ht_gethostbyname(void *rval, void *cb_data, va_list ap) +{ + char **cp; + const char *name; + int af; + struct hostent *resultbuf; + char *buf; + int buflen; + int *herr; + FILE *hostfile = NULL; + int stayopen; + int p; + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + buf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + sethostent_r(0, &hostfile, &stayopen); + while ((p = gethostent_r(resultbuf, buf, buflen, herr, &hostfile)) != -1) { + if (resultbuf->h_addrtype != af) + continue; + if (strcasecmp(resultbuf->h_name, name) == 0) + break; + for (cp = resultbuf->h_aliases; *cp != 0; cp++) + if (strcasecmp(*cp, name) == 0) + goto found; + } +found: + endhostent_r(&hostfile, &stayopen); + + if (p == -1) + { + *(struct hostent **)rval = NULL; + return NS_NOTFOUND; + } + else + { + *(struct hostent **)rval = resultbuf; + return NS_SUCCESS; + } +} + +int +_ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) +{ + const char *addr; + int len, af; + struct hostent *resultbuf; + char *buf; + int buflen; + int *herr; + FILE *hostfile = NULL; + int stayopen; + int p; + + addr = va_arg(ap, const char *); + len = va_arg(ap, int); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + buf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + sethostent_r(0, &hostfile, &stayopen); + while ((p = gethostent_r(resultbuf, buf, buflen, herr, &hostfile)) != -1) + if (resultbuf->h_addrtype == af && !memcmp(resultbuf->h_addr, addr, len)) + break; + endhostent_r(&hostfile, &stayopen); + + if (p == -1) + { + *(struct hostent **)rval = NULL; + return NS_NOTFOUND; + } + else + { + *(struct hostent **)rval = resultbuf; + return NS_SUCCESS; + } +} diff --git a/newlib/libc/sys/linux/net/gethostbyname.3 b/newlib/libc/sys/linux/net/gethostbyname.3 new file mode 100644 index 000000000..51ed2f864 --- /dev/null +++ b/newlib/libc/sys/linux/net/gethostbyname.3 @@ -0,0 +1,380 @@ +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" $FreeBSD: src/lib/libc/net/gethostbyname.3,v 1.26 2002/01/14 16:59:00 ru Exp $ +.\" +.Dd May 25, 1995 +.Dt GETHOSTBYNAME 3 +.Os +.Sh NAME +.Nm gethostbyname , +.Nm gethostbyname2 , +.Nm gethostbyaddr , +.Nm gethostent , +.Nm sethostent , +.Nm endhostent , +.Nm herror , +.Nm hstrerror +.Nd get network host entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Vt extern int h_errno ; +.Ft struct hostent * +.Fn gethostbyname "const char *name" +.Ft struct hostent * +.Fn gethostbyname2 "const char *name" "int af" +.Ft struct hostent * +.Fn gethostbyaddr "const char *addr" "int len" "int type" +.Ft struct hostent * +.Fn gethostent void +.Ft void +.Fn sethostent "int stayopen" +.Ft void +.Fn endhostent void +.Ft void +.Fn herror "const char *string" +.Ft const char * +.Fn hstrerror "int err" +.Sh DESCRIPTION +.Bf -symbolic +The +.Xr getaddrinfo 3 +and +.Xr getnameinfo 3 +functions are preferred over the +.Fn gethostbyname , +.Fn gethostbyname2 , +and +.Fn gethostbyaddr +functions. +.Ef +.Pp +The +.Fn gethostbyname , +.Fn gethostbyname2 +and +.Fn gethostbyaddr +functions +each return a pointer to an object with the +following structure describing an internet host +referenced by name or by address, respectively. +.Pp +The +.Fa name +parameter passed to +.Fn gethostbyname +or +.Fn gethostbyname2 +should point to a +.Dv NUL Ns -terminated +hostname. +The +.Fa addr +parameter passed to +.Fn gethostbyaddr +should point to an address which is +.Fa len +bytes long, +in binary form +(i.e. not an IP address in human readable +.Tn ASCII +form). +The +.Fa type +parameter specifies the address family +(e.g.\& +.Dv AF_INET , AF_INET6 , +etc.) of this address. +.Pp +The structure returned contains either the information obtained from the name +server, +.Xr named 8 , +broken-out fields from a line in +.Pa /etc/hosts , +or database entries supplied by the +.Xr yp 8 +system. +The order of the lookups is controlled by the +.Sq hosts +entry in +.Xr nsswitch.conf 5 . +.Bd -literal +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +}; +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +.Ed +.Pp +The members of this structure are: +.Bl -tag -width h_addr_list +.It Va h_name +Official name of the host. +.It Va h_aliases +A +.Dv NULL Ns -terminated +array of alternate names for the host. +.It Va h_addrtype +The type of address being returned; usually +.Dv AF_INET . +.It Va h_length +The length, in bytes, of the address. +.It Va h_addr_list +A +.Dv NULL Ns -terminated +array of network addresses for the host. +Host addresses are returned in network byte order. +.It Va h_addr +The first address in +.Va h_addr_list ; +this is for backward compatibility. +.El +.Pp +When using the nameserver, +.Fn gethostbyname +and +.Fn gethostbyname2 +will search for the named host in the current domain and its parents +unless the name ends in a dot. +If the name contains no dot, and if the environment variable +.Dq Ev HOSTALIASES +contains the name of an alias file, the alias file will first be searched +for an alias matching the input name. +See +.Xr hostname 7 +for the domain search procedure and the alias file format. +.Pp +The +.Fn gethostbyname2 +function is an evolution of +.Fn gethostbyname +which is intended to allow lookups in address families other than +.Dv AF_INET , +for example +.Dv AF_INET6 . +.Pp +The +.Fn sethostent +function +may be used to request the use of a connected +.Tn TCP +socket for queries. +If the +.Fa stayopen +flag is non-zero, +this sets the option to send all queries to the name server using +.Tn TCP +and to retain the connection after each call to +.Fn gethostbyname , +.Fn gethostbyname2 +or +.Fn gethostbyaddr . +Otherwise, queries are performed using +.Tn UDP +datagrams. +.Pp +The +.Fn endhostent +function +closes the +.Tn TCP +connection. +.Pp +The +.Fn herror +function writes a message to the diagnostic output consisting of the +string parameter +.Fa s , +the constant string +.Qq Li ":\ " , +and a message corresponding to the value of +.Va h_errno . +.Pp +The +.Fn hstrerror +function returns a string which is the message text corresponding to the +value of the +.Fa err +parameter. +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.Sh EXAMPLES +Print out the hostname associated with a specific IP address: +.Bd -literal -offset indent +const char *ipstr = "127.0.0.1"; +struct in_addr ip; +struct hostent *hp; + +if (!inet_aton(ipstr, &ip)) + errx(1, "can't parse IP address %s", ipstr); + +if ((hp = gethostbyaddr((const char *)&ip, + sizeof ip, AF_INET)) == NULL) + errx(1, "no name associated with %s", ipstr); + +printf("name associated with %s is %s\en", ipstr, hp->h_name); +.Ed +.Sh DIAGNOSTICS +Error return status from +.Fn gethostbyname , +.Fn gethostbyname2 +and +.Fn gethostbyaddr +is indicated by return of a +.Dv NULL +pointer. +The external integer +.Va h_errno +may then be checked to see whether this is a temporary failure +or an invalid or unknown host. +The routine +.Fn herror +can be used to print an error message describing the failure. +If its argument +.Fa string +is +.Pf non- Dv NULL , +it is printed, followed by a colon and a space. +The error message is printed with a trailing newline. +.Pp +The variable +.Va h_errno +can have the following values: +.Bl -tag -width HOST_NOT_FOUND +.It Dv HOST_NOT_FOUND +No such host is known. +.It Dv TRY_AGAIN +This is usually a temporary error +and means that the local server did not receive +a response from an authoritative server. +A retry at some later time may succeed. +.It Dv NO_RECOVERY +Some unexpected server failure was encountered. +This is a non-recoverable error. +.It Dv NO_DATA +The requested name is valid but does not have an IP address; +this is not a temporary error. +This means that the name is known to the name server but there is no address +associated with this name. +Another type of request to the name server using this domain name +will result in an answer; +for example, a mail-forwarder may be registered for this domain. +.El +.Sh SEE ALSO +.Xr getaddrinfo 3 , +.Xr getnameinfo 3 , +.Xr inet_aton 3 , +.Xr resolver 3 , +.Xr hosts 5 , +.Xr hostname 7 , +.Xr named 8 +.Sh CAVEAT +The +.Fn gethostent +function +is defined, and +.Fn sethostent +and +.Fn endhostent +are redefined, +when +.Xr libc 3 +is built to use only the routines to lookup in +.Pa /etc/hosts +and not the name server. +.Pp +The +.Fn gethostent +function +reads the next line of +.Pa /etc/hosts , +opening the file if necessary. +.Pp +The +.Fn sethostent +function +opens and/or rewinds the file +.Pa /etc/hosts . +If the +.Fa stayopen +argument is non-zero, +the file will not be closed after each call to +.Fn gethostbyname , +.Fn gethostbyname2 +or +.Fn gethostbyaddr . +.Pp +The +.Fn endhostent +function +closes the file. +.Sh HISTORY +The +.Fn herror +function appeared in +.Bx 4.3 . +The +.Fn endhostent , +.Fn gethostbyaddr , +.Fn gethostbyname , +.Fn gethostent , +and +.Fn sethostent +functions appeared in +.Bx 4.2 . +The +.Fn gethostbyname2 +function first appeared in +.Tn BIND +version 4.9.4. +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Only the Internet +address format is currently understood. +.Pp +.Fn gethostbyname2 +cannot perform +.Dv AF_INET6 +lookups over NIS. +.Xr getaddrinfo 3 +must be used instead. diff --git a/newlib/libc/sys/linux/net/gethostbynis.c b/newlib/libc/sys/linux/net/gethostbynis.c new file mode 100644 index 000000000..917e9409d --- /dev/null +++ b/newlib/libc/sys/linux/net/gethostbynis.c @@ -0,0 +1,281 @@ +/*- + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef YP +#include +#include +#include +#endif + +#ifdef YP +static char *host_aliases[MAXALIASES]; +static char hostaddr[MAXADDRS]; +static char *host_addrs[2]; + +static struct hostent * +_gethostbynis(name, map, af) + const char *name; + char *map; + int af; +{ + char *cp, **q; + char *result; + int resultlen,size; + static struct hostent h; + static char *domain = (char *)NULL; + static char ypbuf[YPMAXRECORD + 2]; + + switch(af) { + case AF_INET: + size = NS_INADDRSZ; + break; + default: + case AF_INET6: + size = NS_IN6ADDRSZ; + errno = EAFNOSUPPORT; + h_errno = NETDB_INTERNAL; + return NULL; + } + + if (domain == (char *)NULL) + if (yp_get_default_domain (&domain)) { + h_errno = NETDB_INTERNAL; + return ((struct hostent *)NULL); + } + + if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) { + h_errno = HOST_NOT_FOUND; + return ((struct hostent *)NULL); + } + + /* avoid potential memory leak */ + bcopy((char *)result, (char *)&ypbuf, resultlen); + ypbuf[resultlen] = '\0'; + free(result); + result = (char *)&ypbuf; + + if ((cp = index(result, '\n'))) + *cp = '\0'; + + cp = strpbrk(result, " \t"); + *cp++ = '\0'; + h.h_addr_list = host_addrs; + h.h_addr = hostaddr; + *((u_long *)h.h_addr) = inet_addr(result); + h.h_length = size; + h.h_addrtype = AF_INET; + while (*cp == ' ' || *cp == '\t') + cp++; + h.h_name = cp; + q = h.h_aliases = host_aliases; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &host_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + *q = NULL; + return (&h); +} + +static struct hostent * +_gethostbynis_r(name, map, af, hp, buffer, buflen, herr) + const char *name; + char *map; + int af; + struct hostent *hp; + char *buffer; + int buflen; + int *herr; +{ + char *cp, **q; + char *result; + int resultlen,size; + char *domain = (char *)NULL; + + switch(af) { + case AF_INET: + size = NS_INADDRSZ; + break; + default: + case AF_INET6: + size = NS_IN6ADDRSZ; + errno = EAFNOSUPPORT; + *herr = NETDB_INTERNAL; + return NULL; + } + + if (domain == (char *)NULL) + if (yp_get_default_domain (&domain)) { + *herr = NETDB_INTERNAL; + return ((struct hostent *)NULL); + } + + if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) { + *herr = HOST_NOT_FOUND; + return ((struct hostent *)NULL); + } + + /* avoid potential memory leak */ + bcopy((char *)result, buffer, resultlen); + buffer[resultlen] = '\0'; + free(result); + result = buffer; + + if ((cp = index(result, '\n'))) + *cp = '\0'; + + cp = strpbrk(result, " \t"); + *cp++ = '\0'; + *((u_long *)hp->__host_addrs[0]) = inet_addr(result); + hp->__host_addrs[1] = NULL; + hp->h_addr_list = hp->__host_addrs; + hp->h_addr = hp->__host_addrs[0]; + hp->h_length = size; + hp->h_addrtype = AF_INET; + while (*cp == ' ' || *cp == '\t') + cp++; + hp->h_name = cp; + q = hp->__host_aliases; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &hp->__host_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + hp->h_aliases = hp->__host_aliases; + *q = NULL; + return (&hp); +} +#endif /* YP */ + +/* XXX _gethostbynisname/_gethostbynisaddr only used by getaddrinfo */ +struct hostent * +_gethostbynisname(const char *name, int af) +{ +#ifdef YP + return _gethostbynis(name, "hosts.byname", af); +#else + return NULL; +#endif +} + +struct hostent * +_gethostbynisaddr(const char *addr, int len, int af) +{ +#ifdef YP + return _gethostbynis(inet_ntoa(*(struct in_addr *)addr), + "hosts.byaddr", af); +#else + return NULL; +#endif +} + + +int +_nis_gethostbyname(void *rval, void *cb_data, va_list ap) +{ +#ifdef YP + const char *name; + int af; + struct hostent *resultbuf; + char *buf; + int buflen; + int *herr; + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + buf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + *(struct hostent **)rval = _gethostbynis_r(name, "hosts.byname", af, resultbuf, buf, buflen, herr); + + return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +#else + return NS_UNAVAIL; +#endif +} + +int +_nis_gethostbyaddr(void *rval, void *cb_data, va_list ap) +{ +#ifdef YP + const char *addr; + int len; + int af; + struct hostent *resultbuf; + char *buf; + int buflen; + int *herr; + + addr = va_arg(ap, const char *); + len = va_arg(ap, int); + af = va_arg(ap, int); + resultbuf = va_arg(ap, struct hostent *); + buf = va_arg(ap, char *); + buflen = va_arg(ap, int); + herr = va_arg(ap, int *); + + *(struct hostent **)rval = _gethostbynis_r(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af); + return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +#else + return NS_UNAVAIL; +#endif +} diff --git a/newlib/libc/sys/linux/net/gethostnamadr.c b/newlib/libc/sys/linux/net/gethostnamadr.c new file mode 100644 index 000000000..de1efd8ed --- /dev/null +++ b/newlib/libc/sys/linux/net/gethostnamadr.c @@ -0,0 +1,221 @@ +/*- + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* XXX hack for _res */ +#include /* XXX hack for _res */ +#include + +extern int _ht_gethostbyname(void *, void *, va_list); +extern int _dns_gethostbyname(void *, void *, va_list); +extern int _nis_gethostbyname(void *, void *, va_list); +extern int _ht_gethostbyaddr(void *, void *, va_list); +extern int _dns_gethostbyaddr(void *, void *, va_list); +extern int _nis_gethostbyaddr(void *, void *, va_list); + +/* Host lookup order if nsswitch.conf is broken or nonexistant */ +static const ns_src default_src[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NSSRC_DNS, NS_SUCCESS }, + { 0 } +}; + +__LOCK_INIT(static, name_lock); +__LOCK_INIT(static, addr_lock); + +struct hostent * +gethostbyname(const char *name) +{ + struct hostent *hp = NULL; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (NULL); + } + if (_res.options & RES_USE_INET6) { /* XXX */ + hp = gethostbyname2(name, AF_INET6); /* XXX */ + if (hp) /* XXX */ + return (hp); /* XXX */ + } /* XXX */ + return (gethostbyname2(name, AF_INET)); +} + +struct hostent * +gethostbyname2(const char *name, int type) +{ + static struct hostent host, *hp; + static char hostbuf[BUFSIZ]; + static int herr; + int rval; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_gethostbyname, NULL) + { NSSRC_DNS, _dns_gethostbyname, NULL }, + NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */ + { 0 } + }; + +#ifdef HAVE_DD_LOCK + __lock_acquire(name_lock); +#endif + rval = nsdispatch((void *)&hp, dtab, NSDB_HOSTS, "gethostbyname", + default_src, name, type, &host, hostbuf, BUFSIZ, &herr); + +#ifdef HAVE_DD_LOCK + __lock_release(name_lock); +#endif + if (rval != NS_SUCCESS) + return NULL; + else + return hp; +} + +int +__gethostbyname_r(const char *name, struct hostent *result, + void *buffer, int buflen, struct hostent **hp, int *herr) +{ + int rval; + int type; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_gethostbyname, NULL) + { NSSRC_DNS, _dns_gethostbyname, NULL }, + NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */ + { 0 } + }; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return HOST_NOT_FOUND; + } + + if (_res.options & RES_USE_INET6) + type = AF_INET6; + else + type = AF_INET; + + rval = nsdispatch((void *)hp, dtab, NSDB_HOSTS, "gethostbyname", + default_src, name, type, result, buffer, buflen, herr); + + if (rval != NS_SUCCESS) + return rval; + else + return 0; +} + +struct hostent * +gethostbyaddr(const char *addr, int len, int type) +{ + static struct hostent host, *hp; + static char hostbuf[BUFSIZ]; + static int herr; + int rval; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_gethostbyaddr, NULL) + { NSSRC_DNS, _dns_gethostbyaddr, NULL }, + NS_NIS_CB(_nis_gethostbyaddr, NULL) /* force -DHESIOD */ + { 0 } + }; + +#ifdef HAVE_DD_LOCK + __lock_acquire(addr_lock); +#endif + rval = nsdispatch((void *)&hp, dtab, NSDB_HOSTS, "gethostbyaddr", + default_src, addr, len, type, &host, hostbuf, BUFSIZ, &herr); + +#ifdef HAVE_DD_LOCK + __lock_release(addr_lock); +#endif + if (rval != NS_SUCCESS) + return NULL; + else + return hp; +} + +int +__gethostbyaddr_r (const char *addr, int len, int type, + struct hostent *result, void *buffer, int buflen, + struct hostent **hp, int *herr) +{ + int rval; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_gethostbyaddr, NULL) + { NSSRC_DNS, _dns_gethostbyaddr, NULL }, + NS_NIS_CB(_nis_gethostbyaddr, NULL) /* force -DHESIOD */ + { 0 } + }; + + rval = nsdispatch((void *)hp, dtab, NSDB_HOSTS, "gethostbyaddr", + default_src, addr, len, type, result, buffer, buflen, herr); + + if(rval != NS_SUCCESS) + return rval; + else + return 0; +} + +void +sethostent(stayopen) + int stayopen; +{ + _sethosthtent(stayopen); + _sethostdnsent(stayopen); +} + +void +endhostent() +{ + _endhosthtent(); + _endhostdnsent(); +} + +void +sethostent_r(int f, FILE **hostfile, int *stayopen) +{ + _sethosthtent_r(f, hostfile, stayopen); + _sethostdnsent(f); +} + +void +endhostent_r(FILE **hostfile, int *stayopen) +{ + _endhosthtent_r(hostfile, stayopen); + _endhostdnsent(); +} diff --git a/newlib/libc/sys/linux/net/gethstbyad.c b/newlib/libc/sys/linux/net/gethstbyad.c deleted file mode 100644 index 97992ad8d..000000000 --- a/newlib/libc/sys/linux/net/gethstbyad.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct hostent -#define FUNCTION_NAME gethostbyaddr -#define DATABASE_NAME hosts -#define ADD_PARAMS const void *addr, socklen_t len, int type -#define ADD_VARIABLES addr, len, type -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/gethstbyad_r.c b/newlib/libc/sys/linux/net/gethstbyad_r.c deleted file mode 100644 index 244828e8d..000000000 --- a/newlib/libc/sys/linux/net/gethstbyad_r.c +++ /dev/null @@ -1,53 +0,0 @@ -/* 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 , 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 -#include - - -#define LOOKUP_TYPE struct hostent -#define FUNCTION_NAME gethostbyaddr -#define DATABASE_NAME hosts -#define ADD_PARAMS const void *addr, socklen_t len, int type -#define ADD_VARIABLES addr, len, type -#define NEED_H_ERRNO 1 -#define NEED__RES 1 -#define NEED__RES_HCONF 1 -/* If the addr parameter is the IPv6 unspecified address no query must - be performed. */ -#define PREPROCESS \ - if (len == sizeof (struct in6_addr) \ - && __builtin_expect (memcmp (&in6addr_any, addr, \ - sizeof (struct in6_addr)), 1) == 0) \ - { \ - *h_errnop = HOST_NOT_FOUND; \ - *result = NULL; \ - return ENOENT; \ - } -#define POSTPROCESS \ - if (status == NSS_STATUS_SUCCESS) \ - { \ - _res_hconf_reorder_addrs (resbuf); \ - _res_hconf_trim_domains (resbuf); \ - } - -/* Special name for the lookup function. */ -#define DB_LOOKUP_FCT __nss_hosts_lookup - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/gethstbynm.c b/newlib/libc/sys/linux/net/gethstbynm.c deleted file mode 100644 index e94eb0a0f..000000000 --- a/newlib/libc/sys/linux/net/gethstbynm.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#include -#include - - -#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 diff --git a/newlib/libc/sys/linux/net/gethstbynm2.c b/newlib/libc/sys/linux/net/gethstbynm2.c deleted file mode 100644 index b365511a8..000000000 --- a/newlib/libc/sys/linux/net/gethstbynm2.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#include -#include - - -#define LOOKUP_TYPE struct hostent -#define FUNCTION_NAME gethostbyname2 -#define DATABASE_NAME hosts -#define ADD_PARAMS const char *name, int af -#define ADD_VARIABLES name, af -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#define HANDLE_DIGITS_DOTS 1 -#define HAVE_AF 1 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/gethstbynm2_r.c b/newlib/libc/sys/linux/net/gethstbynm2_r.c deleted file mode 100644 index c7a2201c2..000000000 --- a/newlib/libc/sys/linux/net/gethstbynm2_r.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#include -#include - - -#define LOOKUP_TYPE struct hostent -#define FUNCTION_NAME gethostbyname2 -#define DATABASE_NAME hosts -#define ADD_PARAMS const char *name, int af -#define ADD_VARIABLES name, af -#define NEED_H_ERRNO 1 -#define NEED__RES_HCONF 1 -#define POSTPROCESS \ - if (status == NSS_STATUS_SUCCESS) \ - _res_hconf_reorder_addrs (resbuf); - -#define HANDLE_DIGITS_DOTS 1 -#define HAVE_LOOKUP_BUFFER 1 -#define HAVE_AF 1 - -/* Special name for the lookup function. */ -#define DB_LOOKUP_FCT __nss_hosts_lookup - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/gethstbynm_r.c b/newlib/libc/sys/linux/net/gethstbynm_r.c deleted file mode 100644 index ccdd6c2a4..000000000 --- a/newlib/libc/sys/linux/net/gethstbynm_r.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#include -#include - - -#define LOOKUP_TYPE struct hostent -#define FUNCTION_NAME gethostbyname -#define DATABASE_NAME hosts -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define NEED_H_ERRNO 1 -#define NEED__RES_HCONF 1 -#define POSTPROCESS \ - if (status == NSS_STATUS_SUCCESS) \ - _res_hconf_reorder_addrs (resbuf); - -#define HANDLE_DIGITS_DOTS 1 -#define HAVE_LOOKUP_BUFFER 1 - -/* Special name for the lookup function. */ -#define DB_LOOKUP_FCT __nss_hosts_lookup - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/gethstent.c b/newlib/libc/sys/linux/net/gethstent.c deleted file mode 100644 index eab9f8f79..000000000 --- a/newlib/libc/sys/linux/net/gethstent.c +++ /dev/null @@ -1,27 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct hostent -#define GETFUNC_NAME gethostent -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#include "getXXent.c" diff --git a/newlib/libc/sys/linux/net/gethstent_r.c b/newlib/libc/sys/linux/net/gethstent_r.c deleted file mode 100644 index c8afa8128..000000000 --- a/newlib/libc/sys/linux/net/gethstent_r.c +++ /dev/null @@ -1,35 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct hostent -#define SETFUNC_NAME sethostent -#define GETFUNC_NAME gethostent -#define ENDFUNC_NAME endhostent -#define DATABASE_NAME hosts -#define STAYOPEN int stayopen -#define STAYOPEN_VAR stayopen -#define NEED_H_ERRNO 1 -#define NEED__RES 1 - -/* Special name for the lookup function. */ -#define DB_LOOKUP_FCT __nss_hosts_lookup - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getifaddrs.3 b/newlib/libc/sys/linux/net/getifaddrs.3 new file mode 100644 index 000000000..47e50049d --- /dev/null +++ b/newlib/libc/sys/linux/net/getifaddrs.3 @@ -0,0 +1,164 @@ +.\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.6 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun Exp $ +.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp +.\" +.\" Copyright (c) 1995, 1999 +.\" Berkeley Software Design, Inc. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.Dd October 12, 1995 +.Dt GETIFADDRS 3 +.Os +.Sh NAME +.Nm getifaddrs +.Nd get interface addresses +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In ifaddrs.h +.Ft int +.Fn getifaddrs "struct ifaddrs **ifap" +.Ft void +.Fn freeifaddrs "struct ifaddrs *ifp" +.Sh DESCRIPTION +The +.Fn getifaddrs +function stores a reference to a linked list of the network interfaces +on the local machine in the memory referenced by +.Fa ifap . +The list consists of +.Nm ifaddrs +structures, as defined in the include file +.Aq Pa ifaddrs.h . +The +.Nm ifaddrs +structure contains at least the following entries: +.Bd -literal + struct ifaddrs *ifa_next; /* Pointer to next struct */ + char *ifa_name; /* Interface name */ + u_int ifa_flags; /* Interface flags */ + struct sockaddr *ifa_addr; /* Interface address */ + struct sockaddr *ifa_netmask; /* Interface netmask */ + struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ + struct sockaddr *ifa_dstaddr; /* P2P interface destination */ + void *ifa_data; /* Address specific data */ +.Ed +.Pp +The +.Li ifa_next +field contains a pointer to the next structure on the list. +This field is +.Dv NULL +in last structure on the list. +.Pp +The +.Li ifa_name +field contains the interface name. +.Pp +The +.Li ifa_flags +field contains the interface flags, as set by +.Xr ifconfig 8 +utility. +.Pp +The +.Li ifa_addr +field references either the address of the interface or the link level +address of the interface, if one exists, otherwise it is NULL. +(The +.Li sa_family +field of the +.Li ifa_addr +field should be consulted to determine the format of the +.Li ifa_addr +address.) +.Pp +The +.Li ifa_netmask +field references the netmask associated with +.Li ifa_addr , +if one is set, otherwise it is NULL. +.Pp +The +.Li ifa_broadaddr +field, +which should only be referenced for non-P2P interfaces, +references the broadcast address associated with +.Li ifa_addr , +if one exists, otherwise it is NULL. +.Pp +The +.Li ifa_dstaddr +field references the destination address on a P2P interface, +if one exists, otherwise it is NULL. +.Pp +The +.Li ifa_data +field references address family specific data. For +.Dv AF_LINK +addresses it contains a pointer to the +.Fa struct if_data +(as defined in include file +.Aq Pa net/if.h ) +which contains various interface attributes and statistics. +For all other address families, it contains a pointer to the +.Fa struct ifa_data +(as defined in include file +.Aq Pa net/if.h ) +which contains per-address interface statistics. +.Pp +The data returned by +.Fn getifaddrs +is dynamically allocated and should be freed using +.Fn freeifaddrs +when no longer needed. +.Sh RETURN VALUES +.Rv -std getifaddrs +.Sh ERRORS +The +.Fn getifaddrs +may fail and set +.Va errno +for any of the errors specified for the library routines +.Xr ioctl 2 , +.Xr socket 2 , +.Xr malloc 3 +or +.Xr sysctl 3 . +.Sh BUGS +If both +.Aq Pa net/if.h +and +.Aq Pa ifaddrs.h +are being included, +.Aq Pa net/if.h +.Em must +be included before +.Aq Pa ifaddrs.h . +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr socket 2 , +.Xr sysctl 3 , +.Xr networking 4 , +.Xr ifconfig 8 +.Sh HISTORY +The +.Nm +implementation first appeared in BSDi +.Bsx . diff --git a/newlib/libc/sys/linux/net/getifaddrs.c b/newlib/libc/sys/linux/net/getifaddrs.c new file mode 100644 index 000000000..fdb8c9b9d --- /dev/null +++ b/newlib/libc/sys/linux/net/getifaddrs.c @@ -0,0 +1,401 @@ +/* $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 +#include +#include +#include +#include + +#include "namespace.h" +#include +#include +#include +#include +#ifdef NET_RT_IFLIST +#include +#include +#include +#include +#endif + +#include +#include +#include +#include "un-namespace.h" + +#if !defined(AF_LINK) +#define SA_LEN(sa) sizeof(struct sockaddr) +#endif + +#if !defined(SA_LEN) +#define SA_LEN(sa) sizeof(struct sockaddr) +#endif + +#define SALIGN (sizeof(long) - 1) +#define SA_RLEN(sa) (sizeof(struct sockaddr) ? ((sizeof(struct sockaddr) + SALIGN) & ~SALIGN) : (SALIGN + 1)) + +#ifndef ALIGNBYTES +/* + * On systems with a routing socket, ALIGNBYTES should match the value + * that the kernel uses when building the messages. + */ +#define ALIGNBYTES XXX +#endif +#ifndef ALIGN +#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES) +#endif + +#if _BSDI_VERSION >= 199701 +#define HAVE_IFM_DATA +#endif + +#if _BSDI_VERSION >= 199802 +/* ifam_data is very specific to recent versions of bsdi */ +#define HAVE_IFAM_DATA +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) +#define HAVE_IFM_DATA +#endif + +int +getifaddrs(struct ifaddrs **pif) +{ + int icnt = 1; + int dcnt = 0; + int ncnt = 0; +#ifdef NET_RT_IFLIST + int mib[6]; + size_t needed; + char *buf; + char *next; + struct ifaddrs *cif = 0; + char *p, *p0; + struct rt_msghdr *rtm; + struct if_msghdr *ifm; + struct ifa_msghdr *ifam; + struct sockaddr_dl *dl; + struct sockaddr *sa; + struct ifaddrs *ifa, *ift; + u_short idx = 0; +#else /* NET_RT_IFLIST */ + struct ifaddrs *ifa, *ift; + char buf[1024]; + int m, sock; + struct ifconf ifc; + struct ifreq *ifr; + struct ifreq *lifr; +#endif /* NET_RT_IFLIST */ + int i; + size_t len, alen; + char *data; + char *names; + +#ifdef NET_RT_IFLIST + mib[0] = CTL_NET; + mib[1] = PF_ROUTE; + mib[2] = 0; /* protocol */ + mib[3] = 0; /* wildcard address family */ + mib[4] = NET_RT_IFLIST; + mib[5] = 0; /* no flags */ + if (__sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) + return (-1); + if ((buf = malloc(needed)) == NULL) + return (-1); + if (__sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { + free(buf); + return (-1); + } + + for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { + rtm = (struct rt_msghdr *)(void *)next; + if (rtm->rtm_version != RTM_VERSION) + continue; + switch (rtm->rtm_type) { + case RTM_IFINFO: + ifm = (struct if_msghdr *)(void *)rtm; + if (ifm->ifm_addrs & RTA_IFP) { + idx = ifm->ifm_index; + ++icnt; + dl = (struct sockaddr_dl *)(void *)(ifm + 1); + dcnt += SA_RLEN((struct sockaddr *)(void*)dl) + + ALIGNBYTES; +#ifdef HAVE_IFM_DATA + dcnt += sizeof(ifm->ifm_data); +#endif /* HAVE_IFM_DATA */ + ncnt += dl->sdl_nlen + 1; + } else + idx = 0; + break; + + case RTM_NEWADDR: + ifam = (struct ifa_msghdr *)(void *)rtm; + if (idx && ifam->ifam_index != idx) + abort(); /* this cannot happen */ + +#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) + if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) + break; + p = (char *)(void *)(ifam + 1); + ++icnt; +#ifdef HAVE_IFAM_DATA + dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES; +#endif /* HAVE_IFAM_DATA */ + /* Scan to look for length of address */ + alen = 0; + for (p0 = p, i = 0; i < RTAX_MAX; i++) { + if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) + == 0) + continue; + sa = (struct sockaddr *)(void *)p; + len = SA_RLEN(sa); + if (i == RTAX_IFA) { + alen = len; + break; + } + p += len; + } + for (p = p0, i = 0; i < RTAX_MAX; i++) { + if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) + == 0) + continue; + sa = (struct sockaddr *)(void *)p; + len = SA_RLEN(sa); + if (i == RTAX_NETMASK && SA_LEN(sa) == 0) + dcnt += alen; + else + dcnt += len; + p += len; + } + break; + } + } +#else /* NET_RT_IFLIST */ + ifc.ifc_buf = buf; + ifc.ifc_len = sizeof(buf); + + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return (-1); + i = ioctl(sock, SIOCGIFCONF, (char *)&ifc); + close(sock); + if (i < 0) + return (-1); + + ifr = ifc.ifc_req; + lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; + + while (ifr < lifr) { + struct sockaddr *sa; + + sa = &ifr->ifr_addr; + ++icnt; + dcnt += SA_RLEN(sa); + ncnt += sizeof(ifr->ifr_name) + 1; + + if (SA_LEN(sa) < sizeof(*sa)) + ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa)); + else + ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa)); + } +#endif /* NET_RT_IFLIST */ + + if (icnt + dcnt + ncnt == 1) { + *pif = NULL; + free(buf); + return (0); + } + data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); + if (data == NULL) { + free(buf); + return(-1); + } + + ifa = (struct ifaddrs *)(void *)data; + data += sizeof(struct ifaddrs) * icnt; + names = data + dcnt; + + memset(ifa, 0, sizeof(struct ifaddrs) * icnt); + ift = ifa; + +#ifdef NET_RT_IFLIST + idx = 0; + for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { + rtm = (struct rt_msghdr *)(void *)next; + if (rtm->rtm_version != RTM_VERSION) + continue; + switch (rtm->rtm_type) { + case RTM_IFINFO: + ifm = (struct if_msghdr *)(void *)rtm; + if (ifm->ifm_addrs & RTA_IFP) { + idx = ifm->ifm_index; + dl = (struct sockaddr_dl *)(void *)(ifm + 1); + + cif = ift; + ift->ifa_name = names; + ift->ifa_flags = (int)ifm->ifm_flags; + memcpy(names, dl->sdl_data, + (size_t)dl->sdl_nlen); + names[dl->sdl_nlen] = 0; + names += dl->sdl_nlen + 1; + + ift->ifa_addr = (struct sockaddr *)(void *)data; + memcpy(data, dl, + (size_t)SA_LEN((struct sockaddr *) + (void *)dl)); + data += SA_RLEN((struct sockaddr *)(void *)dl); + +#ifdef HAVE_IFM_DATA + /* ifm_data needs to be aligned */ + ift->ifa_data = data = (void *)ALIGN(data); + memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data)); + data += sizeof(ifm->ifm_data); +#else /* HAVE_IFM_DATA */ + ift->ifa_data = NULL; +#endif /* HAVE_IFM_DATA */ + + ift = (ift->ifa_next = ift + 1); + } else + idx = 0; + break; + + case RTM_NEWADDR: + ifam = (struct ifa_msghdr *)(void *)rtm; + if (idx && ifam->ifam_index != idx) + abort(); /* this cannot happen */ + + if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) + break; + ift->ifa_name = cif->ifa_name; + ift->ifa_flags = cif->ifa_flags; + ift->ifa_data = NULL; + p = (char *)(void *)(ifam + 1); + /* Scan to look for length of address */ + alen = 0; + for (p0 = p, i = 0; i < RTAX_MAX; i++) { + if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) + == 0) + continue; + sa = (struct sockaddr *)(void *)p; + len = SA_RLEN(sa); + if (i == RTAX_IFA) { + alen = len; + break; + } + p += len; + } + for (p = p0, i = 0; i < RTAX_MAX; i++) { + if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) + == 0) + continue; + sa = (struct sockaddr *)(void *)p; + len = SA_RLEN(sa); + switch (i) { + case RTAX_IFA: + ift->ifa_addr = + (struct sockaddr *)(void *)data; + memcpy(data, p, len); + data += len; + break; + + case RTAX_NETMASK: + ift->ifa_netmask = + (struct sockaddr *)(void *)data; + if (SA_LEN(sa) == 0) { + memset(data, 0, alen); + data += alen; + break; + } + memcpy(data, p, len); + data += len; + break; + + case RTAX_BRD: + ift->ifa_broadaddr = + (struct sockaddr *)(void *)data; + memcpy(data, p, len); + data += len; + break; + } + p += len; + } + +#ifdef HAVE_IFAM_DATA + /* ifam_data needs to be aligned */ + ift->ifa_data = data = (void *)ALIGN(data); + memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data)); + data += sizeof(ifam->ifam_data); +#endif /* HAVE_IFAM_DATA */ + + ift = (ift->ifa_next = ift + 1); + break; + } + } + + free(buf); +#else /* NET_RT_IFLIST */ + ifr = ifc.ifc_req; + lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; + + while (ifr < lifr) { + struct sockaddr *sa; + + ift->ifa_name = names; + names[sizeof(ifr->ifr_name)] = 0; + strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name)); + while (*names++) + ; + + ift->ifa_addr = (struct sockaddr *)data; + sa = &ifr->ifr_addr; + memcpy(data, sa, SA_LEN(sa)); + data += SA_RLEN(sa); + + ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa)); + ift = (ift->ifa_next = ift + 1); + } +#endif /* NET_RT_IFLIST */ + if (--ift >= ifa) { + ift->ifa_next = NULL; + *pif = ifa; + } else { + *pif = NULL; + free(ifa); + } + return (0); +} + +void +freeifaddrs(struct ifaddrs *ifp) +{ + + free(ifp); +} diff --git a/newlib/libc/sys/linux/net/getipnodebyname.3 b/newlib/libc/sys/linux/net/getipnodebyname.3 new file mode 100644 index 000000000..5b8ea1ecb --- /dev/null +++ b/newlib/libc/sys/linux/net/getipnodebyname.3 @@ -0,0 +1,461 @@ +.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETIPNODEBYNAME 3 +.Os +.\" +.Sh NAME +.Nm getipnodebyname , +.Nm getipnodebyaddr , +.Nm freehostent +.Nd nodename-to-address and address-to-nodename translation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft "struct hostent *" +.Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num" +.Ft "struct hostent *" +.Fn getipnodebyaddr "const void *src" "size_t len" "int af" "int *error_num" +.Ft void +.Fn freehostent "struct hostent *ptr" +.\" +.Sh DESCRIPTION +.Fn getipnodebyname +and +.Fn getipnodebyaddr +functions are very similar to +.Xr gethostbyname 3 , +.Xr gethostbyname2 3 +and +.Xr gethostbyaddr 3 . +The functions cover all the functionalities provided by the older ones, +and provide better interface to programmers. +The functions require additional arguments, +.Ar af , +and +.Ar flags , +for specifying address family and operation mode. +The additional arguments allow programmer to get address for a nodename, +for specific address family +(such as +.Dv AF_INET +or +.Dv AF_INET6 ) . +The functions also require an additional pointer argument, +.Ar error_num +to return the appropriate error code, +to support thread safe error code returns. +.Pp +The type and usage of the return value, +.Li "struct hostent" +is described in +.Xr gethostbyname 3 . +.Pp +For +.Fn getipnodebyname , +the +.Ar name +argument can be either a node name or a numeric address +string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +The +.Ar af +argument specifies the address family, either +.Dv AF_INET +or +.Dv AF_INET6 . +The +.Ar flags +argument specifies the types of addresses that are searched for, +and the types of addresses that are returned. +We note that a special flags value of +.Dv AI_DEFAULT +(defined below) +should handle most applications. +That is, porting simple applications to use IPv6 replaces the call +.Bd -literal -offset + hptr = gethostbyname(name); +.Ed +.Pp +with +.Bd -literal -offset + hptr = getipnodebyname(name, AF_INET6, AI_DEFAULT, &error_num); +.Ed +.Pp +Applications desiring finer control over the types of addresses +searched for and returned, can specify other combinations of the +.Ar flags +argument. +.Pp +A +.Ar flags +of +.Li 0 +implies a strict interpretation of the +.Ar af +argument: +.Bl -bullet +.It +If +.Ar flags +is 0 and +.Ar af +is +.Dv AF_INET , +then the caller wants only IPv4 addresses. +A query is made for +.Li A +records. +If successful, the IPv4 addresses are returned and the +.Li h_length +member of the +.Li hostent +structure will be 4, else the function returns a +.Dv NULL +pointer. +.It +If +.Ar flags +is 0 and if +.Ar af +is +.Li AF_INET6 , +then the caller wants only IPv6 addresses. +A query is made for +.Li AAAA +records. +If successful, the IPv6 addresses are returned and the +.Li h_length +member of the +.Li hostent +structure will be 16, else the function returns a +.Dv NULL +pointer. +.El +.Pp +Other constants can be logically-ORed into the +.Ar flags +argument, to modify the behavior of the function. +.Bl -bullet +.It +If the +.Dv AI_V4MAPPED +flag is specified along with an +.Ar af +of +.Dv AF_INET6 , +then the caller will accept IPv4-mapped IPv6 addresses. +That is, if no +.Li AAAA +records are found then a query is made for +.Li A +records and any found are returned as IPv4-mapped IPv6 addresses +.Li ( h_length +will be 16). +The +.Dv AI_V4MAPPED +flag is ignored unless +.Ar af +equals +.Dv AF_INET6 . +.It +The +.Dv AI_V4MAPPED_CFG +flag is exact same as the +.Dv AI_V4MAPPED +flag only if the kernel supports IPv4-mapped IPv6 address. +.It +If the +.Dv AI_ALL +flag is used in conjunction with the +.Dv AI_V4MAPPED +flag, and only used with the IPv6 address family. +When +.Dv AI_ALL +is logically or'd with +.Dv AI_V4MAPPED +flag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6. +A query is first made for +.Li AAAA +records and if successful, the +IPv6 addresses are returned. Another query is then made for +.Li A +records and any found are returned as IPv4-mapped IPv6 addresses. +.Li h_length +will be 16. Only if both queries fail does the function +return a +.Dv NULL +pointer. This flag is ignored unless af equals +AF_INET6. If both +.Dv AI_ALL +and +.Dv AI_V4MAPPED +are specified, +.Dv AI_ALL +takes precedence. +.It +The +.Dv AI_ADDRCONFIG +flag specifies that a query for +.Li AAAA +records +should occur only if the node has at least one IPv6 source +address configured and a query for +.Li A +records should occur only if the node has at least one IPv4 source address +configured. +.Pp +For example, if the node has no IPv6 source addresses configured, +and +.Ar af +equals AF_INET6, and the node name being looked up has both +.Li AAAA +and +.Li A +records, then: +(a) if only +.Dv AI_ADDRCONFIG +is +specified, the function returns a +.Dv NULL +pointer; +(b) if +.Dv AI_ADDRCONFIG +| +.Dv AI_V4MAPPED +is specified, the +.Li A +records are returned as IPv4-mapped IPv6 addresses; +.El +.Pp +The special flags value of +.Dv AI_DEFAULT +is defined as +.Bd -literal -offset + #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) +.Ed +.Pp +We noted that the +.Fn getipnodebyname +function must allow the +.Ar name +argument to be either a node name or a literal address string +(i.e., a dotted-decimal IPv4 address or an IPv6 hex address). +This saves applications from having to call +.Xr inet_pton 3 +to handle literal address strings. +When the +.Ar name +argument is a literal address string, +the +.Ar flags +argument is always ignored. +.Pp +There are four scenarios based on the type of literal address string +and the value of the +.Ar af +argument. +The two simple cases are when +.Ar name +is a dotted-decimal IPv4 address and +.Ar af +equals +.Dv AF_INET , +or when +.Ar name +is an IPv6 hex address and +.Ar af +equals +.Dv AF_INET6 . +The members of the +returned hostent structure are: +.Li h_name +points to a copy of the +.Ar name +argument, +.Li h_aliases +is a +.Dv NULL +pointer, +.Li h_addrtype +is a copy of the +.Ar af +argument, +.Li h_length +is either 4 +(for +.Dv AF_INET ) +or 16 +(for +.Dv AF_INET6 ) , +.Li h_addr_list[0] +is a pointer to the 4-byte or 16-byte binary address, +and +.Li h_addr_list[1] +is a +.Dv NULL +pointer. +.Pp +When +.Ar name +is a dotted-decimal IPv4 address and +.Ar af +equals +.Dv AF_INET6 , +and +.Dv AI_V4MAPPED +is specified, +an IPv4-mapped IPv6 address is returned: +.Li h_name +points to an IPv6 hex address containing the IPv4-mapped IPv6 address, +.Li h_aliases +is a +.Dv NULL +pointer, +.Li h_addrtype +is +.Dv AF_INET6 , +.Li h_length +is 16, +.Li h_addr_list[0] +is a pointer to the 16-byte binary address, and +.Li h_addr_list[1] +is a +.Dv NULL +pointer. +.Pp +It is an error when +.Ar name +is an IPv6 hex address and +.Ar af +equals +.Dv AF_INET . +The function's return value is a +.Dv NULL +pointer and the value pointed to by +.Ar error_num +equals +.Dv HOST_NOT_FOUND . +.Pp +.Fn getipnodebyaddr +takes almost the same argument as +.Xr gethostbyaddr 3 , +but adds a pointer to return an error number. +Additionally it takes care of IPv4-mapped IPv6 addresses, +and IPv4-compatible IPv6 addresses. +.Pp +.Fn getipnodebyname +and +.Fn getipnodebyaddr +dynamically allocate the structure to be returned to the caller. +.Fn freehostent +reclaims memory region allocated and returned by +.Fn getipnodebyname +or +.Fn getipnodebyaddr . +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +returns +.Dv NULL +on errors. +The integer values pointed to by +.Ar error_num +may then be checked to see whether this is a temporary failure +or an invalid or unknown host. +The meanings of each error code are described in +.Xr gethostbyname 3 . +.\" +.Sh SEE ALSO +.Xr gethostbyaddr 3 , +.Xr gethostbyname 3 , +.Xr hosts 5 , +.Xr nsswitch.conf 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +are documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +.Fn getipnodebyname +and +.Fn getipnodebyaddr +do not handle scoped IPv6 address properly. +If you use these functions, +your program will not be able to handle scoped IPv6 addresses. +For IPv6 address manipulation, +.Fn getaddrinfo 3 +and +.Fn getnameinfo 3 +are recommended. +.Pp +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. diff --git a/newlib/libc/sys/linux/net/getnameinfo.3 b/newlib/libc/sys/linux/net/getnameinfo.3 new file mode 100644 index 000000000..d7afa2f40 --- /dev/null +++ b/newlib/libc/sys/linux/net/getnameinfo.3 @@ -0,0 +1,311 @@ +.\" $FreeBSD: src/lib/libc/net/getnameinfo.3,v 1.11 2001/10/01 16:08:55 ru Exp $ +.\" $KAME: getnameinfo.3,v 1.17 2000/08/09 21:16:17 itojun Exp $ +.\" +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" +.Dd May 25, 1995 +.Dt GETNAMEINFO 3 +.Os +.\" +.Sh NAME +.Nm getnameinfo +.Nd address-to-nodename translation in protocol-independent manner +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netdb.h +.Ft int +.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" \ +"char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags" +.\" +.Sh DESCRIPTION +The +.Fn getnameinfo +function is defined for protocol-independent address-to-nodename translation. +Its functionality is a reverse conversion of +.Xr getaddrinfo 3 , +and implements similar functionality with +.Xr gethostbyaddr 3 +and +.Xr getservbyport 3 +in more sophisticated manner. +.Pp +This function looks up an IP address and port number provided by the +caller in the DNS and system-specific database, and returns text +strings for both in buffers provided by the caller. +The function indicates successful completion by a zero return value; +a non-zero return value indicates failure. +.Pp +The first argument, +.Fa sa , +points to either a +.Li sockaddr_in +structure (for IPv4) or a +.Li sockaddr_in6 +structure (for IPv6) that holds the IP address and port number. +The +.Fa salen +argument gives the length of the +.Li sockaddr_in +or +.Li sockaddr_in6 +structure. +.Pp +The function returns the nodename associated with the IP address in +the buffer pointed to by the +.Fa host +argument. +The caller provides the size of this buffer via the +.Fa hostlen +argument. +The service name associated with the port number is returned in the buffer +pointed to by +.Fa serv , +and the +.Fa servlen +argument gives the length of this buffer. +The caller specifies not to return either string by providing a zero +value for the +.Fa hostlen +or +.Fa servlen +arguments. +Otherwise, the caller must provide buffers large enough to hold the +nodename and the service name, including the terminating null characters. +.Pp +Unfortunately most systems do not provide constants that specify the +maximum size of either a fully-qualified domain name or a service name. +Therefore to aid the application in allocating buffers for these two +returned strings the following constants are defined in +.Aq Pa netdb.h : +.Bd -literal -offset +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +.Ed +.Pp +The first value is actually defined as the constant +.Dv MAXDNAME +in recent versions of BIND's +.Aq Pa arpa/nameser.h +header +(older versions of BIND define this constant to be 256) +and the second is a guess based on the services listed in the current +Assigned Numbers RFC. +.Pp +The final argument is a +.Fa flag +that changes the default actions of this function. +By default the fully-qualified domain name (FQDN) for the host is +looked up in the DNS and returned. +If the flag bit +.Dv NI_NOFQDN +is set, only the nodename portion of the FQDN is returned for local hosts. +.Pp +If the +.Fa flag +bit +.Dv NI_NUMERICHOST +is set, or if the host's name cannot be located in the DNS, +the numeric form of the host's address is returned instead of its name +(e.g., by calling +.Fn inet_ntop +instead of +.Fn getnodebyaddr ) . +If the +.Fa flag +bit +.Dv NI_NAMEREQD +is set, an error is returned if the host's name cannot be located in the DNS. +.Pp +If the flag bit +.Dv NI_NUMERICSERV +is set, the numeric form of the service address is returned +(e.g., its port number) +instead of its name. +The two +.Dv NI_NUMERICxxx +flags are required to support the +.Fl n +flag that many commands provide. +.Pp +A fifth flag bit, +.Dv NI_DGRAM , +specifies that the service is a datagram service, and causes +.Fn getservbyport +to be called with a second argument of +.Dq udp +instead of its default of +.Dq tcp . +This is required for the few ports (512-514) +that have different services for UDP and TCP. +.Pp +These +.Dv NI_xxx +flags are defined in +.Aq Pa netdb.h . +.\" +.Sh EXTENSION +The implementation allows experimental numeric IPv6 address notation with +scope identifier. +IPv6 link-local address will appear as string like +.Dq Li fe80::1%ne0 , +if +.Dv NI_WITHSCOPEID +bit is enabled in +.Ar flags +argument. +Refer to +.Xr getaddrinfo 3 +for the notation. +.\" +.Sh EXAMPLES +The following code tries to get numeric hostname, and service name, +for given socket address. +Observe that there is no hardcoded reference to particular address family. +.Bd -literal -offset indent +struct sockaddr *sa; /* input */ +char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; + +if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, + sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { + errx(1, "could not get numeric hostname"); + /*NOTREACHED*/ +} +printf("host=%s, serv=%s\\n", hbuf, sbuf); +.Ed +.Pp +The following version checks if the socket address has reverse address mapping. +.Bd -literal -offset indent +struct sockaddr *sa; /* input */ +char hbuf[NI_MAXHOST]; + +if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, + NI_NAMEREQD)) { + errx(1, "could not resolve hostname"); + /*NOTREACHED*/ +} +printf("host=%s\\n", hbuf); +.Ed +.\" +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/hosts +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.\" +.Sh DIAGNOSTICS +The function indicates successful completion by a zero return value; +a non-zero return value indicates failure. +Error codes are as below: +.Bl -tag -width Er +.It Bq Er EAI_AGAIN +The name could not be resolved at this time. +Future attempts may succeed. +.It Bq Er EAI_BADFLAGS +The flags had an invalid value. +.It Bq Er EAI_FAIL +A non-recoverable error occurred. +.It Bq Er EAI_FAMILY +The address family was not recognized or the address length was invalid +for the specified family. +.It Bq Er EAI_MEMORY +There was a memory allocation failure. +.It Bq Er EAI_NONAME +The name does not resolve for the supplied parameters. +.Dv NI_NAMEREQD +is set and the host's name cannot be located, +or both nodename and servname were null. +.It Bq Er EAI_SYSTEM +A system error occurred. +The error code can be found in errno. +.El +.\" +.Sh SEE ALSO +.Xr getaddrinfo 3 , +.Xr gethostbyaddr 3 , +.Xr getservbyport 3 , +.Xr hosts 5 , +.Xr services 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC2553 +.%D March 1999 +.Re +.Rs +.%A Tatsuya Jinmei +.%A Atsushi Onoe +.%T "An Extension of Format for IPv6 Scoped Addresses" +.%R internet draft +.%N draft-ietf-ipngwg-scopedaddr-format-02.txt +.%O work in progress material +.Re +.Rs +.%A Craig Metz +.%T Protocol Independence Using the Sockets API +.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" +.%D June 2000 +.Re +.\" +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.\" +.Sh STANDARDS +The +.Fn getaddrinfo +function is defined in +.St -p1003.1g-2000 , +and documented in +.Dq Basic Socket Interface Extensions for IPv6 +(RFC2553). +.\" +.Sh BUGS +The current implementation is not thread-safe. +.Pp +The text was shamelessly copied from RFC2553. +.Pp +The type of the 2nd argument should be +.Li socklen_t +for RFC2553 conformance. +The current code is based on pre-RFC2553 specification. diff --git a/newlib/libc/sys/linux/net/getnameinfo.c b/newlib/libc/sys/linux/net/getnameinfo.c index f79bc317f..e2f9631c1 100644 --- a/newlib/libc/sys/linux/net/getnameinfo.c +++ b/newlib/libc/sys/linux/net/getnameinfo.c @@ -1,456 +1,372 @@ -/* The Inner Net License, Version 2.00 - - The author(s) grant permission for redistribution and use in source and -binary forms, with or without modification, of the software and documentation -provided that the following conditions are met: - -0. If you receive a version of the software that is specifically labelled - as not being for redistribution (check the version message and/or README), - you are not permitted to redistribute that version of the software in any - way or form. -1. All terms of the all other applicable copyrights and licenses must be - followed. -2. Redistributions of source code must retain the authors' copyright - notice(s), this list of conditions, and the following disclaimer. -3. Redistributions in binary form must reproduce the authors' copyright - notice(s), this list of conditions, and the following disclaimer in the - documentation and/or other materials provided with the distribution. -4. [The copyright holder has authorized the removal of this clause.] -5. Neither the name(s) of the author(s) nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS ``AS IS'' AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - If these license terms cause you a real problem, contact the author. */ - -/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */ +/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Issues to be discussed: + * - Thread safe-ness must be checked + * - RFC2553 says that we should raise error on short buffer. X/Open says + * we need to truncate the result. We obey RFC2553 (and X/Open should be + * modified). ipngwg rough consensus seems to follow RFC2553. + * - What is "local" in NI_FQDN? + * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. + * - (KAME extension) NI_WITHSCOPEID when called with global address, + * and sin6_scope_id filled + */ + +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include -#include -#include -#include -#include -#include -#define _IO_MTSAFE_IO -#include -#include -#include "local.h" +#include +#include +#include +#include +#include +#include +#include -#ifdef HAVE_LIBIDN -# include -extern int __idna_to_unicode_lzlz (const char *input, char **output, - int flags); +#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}, +}; -#ifndef min -# define min(x,y) (((x) > (y)) ? (y) : (x)) -#endif /* min */ +struct sockinet { + u_char si_len; + u_char si_family; + u_short si_port; +}; -libc_freeres_ptr (static char *domain); +#ifdef INET6 +static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, + size_t, int); +static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); +#endif +/* 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 -static char * -internal_function -nrl_domainname (void) +int +getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) + const struct sockaddr *sa; + socklen_t salen; + char *host; + size_t hostlen; + char *serv; + size_t servlen; + int flags; { - static int not_first; - - if (! not_first) - { - __libc_lock_define_initialized (static, lock); - __libc_lock_lock (lock); - - if (! not_first) - { - char *c; - struct hostent *h, th; - size_t tmpbuflen = 1024; - char *tmpbuf = alloca (tmpbuflen); - int herror; - - not_first = 1; + struct afd *afd; + struct servent *sp; + struct hostent *hp; + u_short port; + int family, i; + const char *addr; + u_int32_t v4a; + int h_error; + char numserv[512]; + char numaddr[512]; + + if (sa == NULL) + return ENI_NOSOCKET; + + family = sa->sa_family; + for (i = 0; afdl[i].a_af; i++) + if (afdl[i].a_af == family) { + afd = &afdl[i]; + goto found; + } + return ENI_FAMILY; + + found: + if (salen != afd->a_socklen) + return ENI_SALEN; + + /* network byte order */ + port = ((const struct sockinet *)sa)->si_port; + addr = (const char *)sa + afd->a_off; + + if (serv == NULL || servlen == 0) { + /* + * do nothing in this case. + * in case you are wondering if "&&" is more correct than + * "||" here: RFC2553 says that serv == NULL OR servlen == 0 + * means that the caller does not want the result. + */ + } else { + if (flags & NI_NUMERICSERV) + sp = NULL; + else { + sp = getservbyport(port, + (flags & NI_DGRAM) ? "udp" : "tcp"); + } + if (sp) { + if (strlen(sp->s_name) + 1 > servlen) + return ENI_MEMORY; + strcpy(serv, sp->s_name); + } else { + snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); + if (strlen(numserv) + 1 > servlen) + return ENI_MEMORY; + strcpy(serv, numserv); + } + } - while (__gethostbyname_r ("localhost", &th, tmpbuf, tmpbuflen, &h, - &herror)) - { - if (herror == NETDB_INTERNAL && errno == ERANGE) - tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); - else + 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; - } - - if (h && (c = strchr (h->h_name, '.'))) - domain = strdup (++c); - else +#ifdef INET6 + case AF_INET6: { - /* 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 + const struct sockaddr_in6 *sin6; + sin6 = (const struct sockaddr_in6 *)sa; + switch (sin6->sin6_addr.s6_addr[0]) { + case 0x00: + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) + ; + else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) + ; + else + flags |= NI_NUMERICHOST; break; - } - - 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; + default: + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { + flags |= NI_NUMERICHOST; } - - if (h && (c = strchr (h->h_name, '.'))) - domain = strdup (++c); - } + else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) + flags |= NI_NUMERICHOST; + break; } } + break; +#endif } + if (host == NULL || hostlen == 0) { + /* + * do nothing in this case. + * in case you are wondering if "&&" is more correct than + * "||" here: RFC2553 says that host == NULL OR hostlen == 0 + * means that the caller does not want the result. + */ + } else if (flags & NI_NUMERICHOST) { + int numaddrlen; + + /* NUMERICHOST and NAMEREQD conflicts with each other */ + if (flags & NI_NAMEREQD) + return ENI_NOHOSTNAME; + + switch(afd->a_af) { +#ifdef INET6 + case AF_INET6: + { + int error; - __libc_lock_unlock (lock); - } - - return domain; -}; + 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); + + if (hp) { +#if 0 + /* + * commented out, since "for local host" is not + * implemented here - see RFC2553 p30 + */ + if (flags & NI_NOFQDN) { + char *p; + p = strchr(hp->h_name, '.'); + if (p) + *p = '\0'; + } +#endif + if (strlen(hp->h_name) + 1 > hostlen) { + freehostent(hp); + return ENI_MEMORY; + } + strcpy(host, hp->h_name); + freehostent(hp); + } else { + if (flags & NI_NAMEREQD) + return ENI_NOHOSTNAME; + switch(afd->a_af) { +#ifdef INET6 + case AF_INET6: + { + int error; + if ((error = ip6_parsenumeric(sa, addr, host, + hostlen, + flags)) != 0) + return(error); + break; + } +#endif + default: + if (inet_ntop(afd->a_af, addr, host, + hostlen) == NULL) + return ENI_SYSTEM; + break; + } + } + } + return SUCCESS; +} -int -getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host, - socklen_t hostlen, char *serv, socklen_t servlen, - unsigned int flags) +#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 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 + 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 - )) - 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'; + ((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 + */ + memcpy(host + numaddrlen + 1, scopebuf, + scopelen); + host[numaddrlen] = SCOPE_DELIMITER; + host[numaddrlen + 1 + scopelen] = '\0'; + } + } +#endif /* NI_WITHSCOPEID */ -#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; + return 0; +} - 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; - } +/* 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; - if (out != h->h_name) - { - h->h_name = strdupa (out); - free (out); - } - } +#ifdef NI_NUMERICSCOPE + if (flags & NI_NUMERICSCOPE) { + return(snprintf(buf, bufsiz, "%d", sa6->sin6_scope_id)); + } #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; - }; - }; - - if (flags & NI_NAMEREQD) - { - __set_errno (serrno); - return EAI_NONAME; - } - - strncpy (host, "localhost", hostlen); - break; - - default: - return EAI_FAMILY; - } - - if (serv && (servlen > 0)) - switch (sa->sa_family) - { - case AF_INET: - case AF_INET6: - if (!(flags & NI_NUMERICSERV)) - { - struct servent *s, ts; - while (__getservbyport_r (((const struct sockaddr_in *) sa)->sin_port, - ((flags & NI_DGRAM) ? "udp" : "tcp"), - &ts, tmpbuf, tmpbuflen, &s)) - { - if (herrno == NETDB_INTERNAL) - { - if (errno == ERANGE) - tmpbuf = extend_alloca (tmpbuf, tmpbuflen, - 2 * tmpbuflen); - else - { - __set_errno (serrno); - return EAI_SYSTEM; - } - } - else - { - break; - } - } - if (s) - { - strncpy (serv, s->s_name, servlen); - break; - } - } - - if (snprintf (serv, servlen, "%d", - ntohs (((const struct sockaddr_in *) sa)->sin_port)) - + 1 > servlen) - return EAI_OVERFLOW; - - break; - - case AF_LOCAL: - strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen); - break; - } + /* 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)); + } + } - if (host && (hostlen > 0)) - host[hostlen-1] = 0; - if (serv && (servlen > 0)) - serv[servlen-1] = 0; - errno = serrno; - return 0; + /* last resort */ + return(snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id)); } -libc_hidden_def (getnameinfo) +#endif /* INET6 */ diff --git a/newlib/libc/sys/linux/net/getnetbyad.c b/newlib/libc/sys/linux/net/getnetbyad.c deleted file mode 100644 index 73ae203e8..000000000 --- a/newlib/libc/sys/linux/net/getnetbyad.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include - - -#define LOOKUP_TYPE struct netent -#define FUNCTION_NAME getnetbyaddr -#define DATABASE_NAME networks -#define ADD_PARAMS uint32_t net, int type -#define ADD_VARIABLES net, type -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getnetbyad_r.c b/newlib/libc/sys/linux/net/getnetbyad_r.c deleted file mode 100644 index 7af3cb40b..000000000 --- a/newlib/libc/sys/linux/net/getnetbyad_r.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1996, 1997, 2000, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include - - -#define LOOKUP_TYPE struct netent -#define FUNCTION_NAME getnetbyaddr -#define DATABASE_NAME networks -#define ADD_PARAMS uint32_t net, int type -#define ADD_VARIABLES net, type -#define NEED__RES 1 -#define NEED_H_ERRNO 1 - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getnetbydns.c b/newlib/libc/sys/linux/net/getnetbydns.c new file mode 100644 index 000000000..2cc4fce54 --- /dev/null +++ b/newlib/libc/sys/linux/net/getnetbydns.c @@ -0,0 +1,327 @@ +/*- + * 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 +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "res_config.h" + +extern int h_errno; + +#define BYADDR 0 +#define BYNAME 1 +#define MAXALIASES 35 + +#if PACKETSZ > 1024 +#define MAXPACKET PACKETSZ +#else +#define MAXPACKET 1024 +#endif + +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +typedef union { + long al; + char ac; +} align; + +static struct netent * +getnetanswer(answer, anslen, net_i) + querybuf *answer; + int anslen; + int net_i; +{ + + HEADER *hp; + u_char *cp; + int n; + u_char *eom; + int type, class, buflen, ancount, qdcount, haveanswer, i, nchar; + char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN]; + char *in, *st, *pauxt, *bp, **ap; + char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0; +static struct netent net_entry; +static char *net_aliases[MAXALIASES], netbuf[PACKETSZ]; + + /* + * find first satisfactory answer + * + * answer --> +------------+ ( MESSAGE ) + * | Header | + * +------------+ + * | Question | the question for the name server + * +------------+ + * | Answer | RRs answering the question + * +------------+ + * | Authority | RRs pointing toward an authority + * | Additional | RRs holding additional information + * +------------+ + */ + eom = answer->buf + anslen; + hp = &answer->hdr; + ancount = ntohs(hp->ancount); /* #/records in the answer section */ + qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ + bp = netbuf; + buflen = sizeof(netbuf); + cp = answer->buf + HFIXEDSZ; + if (!qdcount) { + if (hp->aa) + h_errno = HOST_NOT_FOUND; + else + h_errno = TRY_AGAIN; + return (NULL); + } + while (qdcount-- > 0) + cp += __dn_skipname(cp, eom) + QFIXEDSZ; + ap = net_aliases; + *ap = NULL; + net_entry.n_aliases = net_aliases; + haveanswer = 0; + while (--ancount >= 0 && cp < eom) { + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !res_dnok(bp)) + break; + cp += n; + ans[0] = '\0'; + (void)strncpy(&ans[0], bp, sizeof(ans) - 1); + ans[sizeof(ans) - 1] = '\0'; + GETSHORT(type, cp); + GETSHORT(class, cp); + cp += INT32SZ; /* TTL */ + GETSHORT(n, cp); + if (class == C_IN && type == T_PTR) { + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !res_hnok(bp)) { + cp += n; + return (NULL); + } + cp += n; + *ap++ = bp; + bp += strlen(bp) + 1; + net_entry.n_addrtype = + (class == C_IN) ? AF_INET : AF_UNSPEC; + haveanswer++; + } + } + if (haveanswer) { + *ap = NULL; + switch (net_i) { + case BYADDR: + net_entry.n_name = *net_entry.n_aliases; + net_entry.n_net = 0L; + break; + case BYNAME: + in = *net_entry.n_aliases; + net_entry.n_name = &ans[0]; + aux2[0] = '\0'; + for (i = 0; i < 4; i++) { + for (st = in, nchar = 0; + *st != '.'; + st++, nchar++) + ; + if (nchar != 1 || *in != '0' || flag) { + flag = 1; + (void)strncpy(paux1, + (i==0) ? in : in-1, + (i==0) ?nchar : nchar+1); + paux1[(i==0) ? nchar : nchar+1] = '\0'; + pauxt = paux2; + paux2 = strcat(paux1, paux2); + paux1 = pauxt; + } + in = ++st; + } + net_entry.n_net = inet_network(paux2); + break; + } + net_entry.n_aliases++; + return (&net_entry); + } + h_errno = TRY_AGAIN; + return (NULL); +} + +int +_dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) +{ + unsigned long net; + int net_type; + unsigned int netbr[4]; + int nn, anslen; + querybuf buf; + char qbuf[MAXDNAME]; + unsigned long net2; + struct netent *net_entry; + + net = va_arg(ap, unsigned long); + net_type = va_arg(ap, int); + + *(struct netent **)rval = NULL; + + if (net_type != AF_INET) + return NS_UNAVAIL; + + for (nn = 4, net2 = net; net2; net2 >>= 8) + netbr[--nn] = net2 & 0xff; + switch (nn) { + case 3: /* Class A */ + sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]); + break; + case 2: /* Class B */ + sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]); + break; + case 1: /* Class C */ + sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], + netbr[1]); + break; + case 0: /* Class D - E */ + sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], + netbr[1], netbr[0]); + break; + } + anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + if (anslen < 0) { +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf("res_query failed\n"); +#endif + return NS_UNAVAIL; + } + net_entry = getnetanswer(&buf, anslen, BYADDR); + if (net_entry) { + unsigned u_net = net; /* maybe net should be unsigned ? */ + + /* Strip trailing zeros */ + while ((u_net & 0xff) == 0 && u_net != 0) + u_net >>= 8; + net_entry->n_net = u_net; + *(struct netent **)rval = net_entry; + return NS_SUCCESS; + } + return NS_NOTFOUND; +} + +int +_dns_getnetbyname(void *rval, void *cb_data, va_list ap) +{ + const char *net; + int anslen; + querybuf buf; + char qbuf[MAXDNAME]; + + net = va_arg(ap, const char *); + + *(struct netent**)rval = NULL; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return NS_UNAVAIL; + } + strncpy(qbuf, net, sizeof(qbuf) - 1); + qbuf[sizeof(qbuf) - 1] = '\0'; + anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + if (anslen < 0) { +#ifdef DEBUG + if (_res.options & RES_DEBUG) + printf("res_query failed\n"); +#endif + return NS_UNAVAIL; + } + *(struct netent**)rval = getnetanswer(&buf, anslen, BYNAME); + return (*(struct netent**)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +void +_setnetdnsent(stayopen) + int stayopen; +{ + if (stayopen) + _res.options |= RES_STAYOPEN | RES_USEVC; +} + +void +_endnetdnsent() +{ + _res.options &= ~(RES_STAYOPEN | RES_USEVC); + res_close(); +} diff --git a/newlib/libc/sys/linux/net/getnetbyht.c b/newlib/libc/sys/linux/net/getnetbyht.c new file mode 100644 index 000000000..8e4a16f1c --- /dev/null +++ b/newlib/libc/sys/linux/net/getnetbyht.c @@ -0,0 +1,183 @@ +/* + * 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXALIASES 35 + +static FILE *netf; +static char line[BUFSIZ+1]; +static struct netent net; +static char *net_aliases[MAXALIASES]; +static int _net_stayopen; + +void +_setnethtent(f) + int f; +{ + + if (netf == NULL) + netf = fopen(_PATH_NETWORKS, "r" ); + else + rewind(netf); + _net_stayopen |= f; +} + +void +_endnethtent() +{ + + if (netf) { + fclose(netf); + netf = NULL; + } + _net_stayopen = 0; +} + +struct netent * +getnetent() +{ + char *p; + char *cp, **q; + + if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) + return (NULL); +again: + p = fgets(line, sizeof line, netf); + if (p == NULL) + return (NULL); + if (*p == '#') + goto again; + cp = strpbrk(p, "#\n"); + if (cp == NULL) + goto again; + *cp = '\0'; + net.n_name = p; + cp = strpbrk(p, " \t"); + if (cp == NULL) + goto again; + *cp++ = '\0'; + while (*cp == ' ' || *cp == '\t') + cp++; + p = strpbrk(cp, " \t"); + if (p != NULL) + *p++ = '\0'; + net.n_net = inet_network(cp); + net.n_addrtype = AF_INET; + q = net.n_aliases = net_aliases; + if (p != NULL) + cp = p; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &net_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + *q = NULL; + return (&net); +} + +int +_ht_getnetbyname(void *rval, void *cb_data, va_list ap) +{ + const char *name; + struct netent *p; + char **cp; + + name = va_arg(ap, const char *); + + setnetent(_net_stayopen); + while ( (p = getnetent()) ) { + if (strcasecmp(p->n_name, name) == 0) + break; + for (cp = p->n_aliases; *cp != 0; cp++) + if (strcasecmp(*cp, name) == 0) + goto found; + } +found: + if (!_net_stayopen) + endnetent(); + *(struct netent **)rval = p; + return (p != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +int +_ht_getnetbyaddr(void *rval, void *cb_data, va_list ap) +{ + unsigned long net; + int type; + struct netent *p; + + net = va_arg(ap, unsigned long); + type = va_arg(ap, int); + + setnetent(_net_stayopen); + while ( (p = getnetent()) ) + if (p->n_addrtype == type && p->n_net == net) + break; + if (!_net_stayopen) + endnetent(); + *(struct netent **)rval = p; + return (p != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} diff --git a/newlib/libc/sys/linux/net/getnetbynis.c b/newlib/libc/sys/linux/net/getnetbynis.c new file mode 100644 index 000000000..6d222e60f --- /dev/null +++ b/newlib/libc/sys/linux/net/getnetbynis.c @@ -0,0 +1,190 @@ +/*- + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef YP +#include +#include +#include +#endif + +#define MAXALIASES 35 +#define MAXADDRS 35 + +#ifdef YP +static char *host_aliases[MAXALIASES]; + +static struct netent * +_getnetbynis(const char *name, char *map, int af) +{ + char *cp, **q; + static char *result; + int resultlen; + static struct netent h; + static char *domain = (char *)NULL; + static char ypbuf[YPMAXRECORD + 2]; + + switch(af) { + case AF_INET: + break; + default: + case AF_INET6: + errno = EAFNOSUPPORT; + return NULL; + } + + if (domain == (char *)NULL) + if (yp_get_default_domain (&domain)) + return (NULL); + + if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) + return (NULL); + + bcopy((char *)result, (char *)&ypbuf, resultlen); + ypbuf[resultlen] = '\0'; + free(result); + result = (char *)&ypbuf; + + if ((cp = index(result, '\n'))) + *cp = '\0'; + + cp = strpbrk(result, " \t"); + *cp++ = '\0'; + h.n_name = result; + + while (*cp == ' ' || *cp == '\t') + cp++; + + h.n_net = inet_network(cp); + h.n_addrtype = AF_INET; + + q = h.n_aliases = host_aliases; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &host_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + *q = NULL; + return (&h); +} +#endif /* YP */ + +int +_nis_getnetbyname(void *rval, void *cb_data, va_list ap) +{ +#ifdef YP + const char *name; + + name = va_arg(ap, const char *); + + *(struct netent **)rval = _getnetbynis(name, "networks.byname", AF_INET); + return (*(struct netent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +#else + return NS_UNAVAIL; +#endif + +} + +int +_nis_getnetbyaddr(void *rval, void *cb_data, va_list ap) +{ +#ifdef YP + unsigned long addr; + int af; + char *str, *cp; + unsigned long net2; + int nn; + unsigned int netbr[4]; + char buf[MAXDNAME]; + + addr = va_arg(ap, unsigned long); + af = va_arg(ap, int); + + *(struct netent **)rval = NULL; + + if (af != AF_INET) { + errno = EAFNOSUPPORT; + return NS_UNAVAIL; + } + + for (nn = 4, net2 = addr; net2; net2 >>= 8) { + netbr[--nn] = net2 & 0xff; + } + + switch (nn) { + case 3: /* Class A */ + sprintf(buf, "%u", netbr[3]); + break; + case 2: /* Class B */ + sprintf(buf, "%u.%u", netbr[2], netbr[3]); + break; + case 1: /* Class C */ + sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]); + break; + case 0: /* Class D - E */ + sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1], + netbr[2], netbr[3]); + break; + } + + str = (char *)&buf; + cp = str + (strlen(str) - 2); + + while(!strcmp(cp, ".0")) { + *cp = '\0'; + cp = str + (strlen(str) - 2); + } + + *(struct netent **)rval = _getnetbynis(str, "networks.byaddr", af); + return (*(struct netent**)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +#else + return NS_UNAVAIL; +#endif /* YP */ +} diff --git a/newlib/libc/sys/linux/net/getnetbynm.c b/newlib/libc/sys/linux/net/getnetbynm.c deleted file mode 100644 index cacf14899..000000000 --- a/newlib/libc/sys/linux/net/getnetbynm.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct netent -#define FUNCTION_NAME getnetbyname -#define DATABASE_NAME networks -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getnetbynm_r.c b/newlib/libc/sys/linux/net/getnetbynm_r.c deleted file mode 100644 index 3acd2d3e6..000000000 --- a/newlib/libc/sys/linux/net/getnetbynm_r.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct netent -#define FUNCTION_NAME getnetbyname -#define DATABASE_NAME networks -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define NEED__RES 1 -#define NEED_H_ERRNO 1 - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getnetent.3 b/newlib/libc/sys/linux/net/getnetent.3 new file mode 100644 index 000000000..6801e9707 --- /dev/null +++ b/newlib/libc/sys/linux/net/getnetent.3 @@ -0,0 +1,172 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.17 2002/01/14 16:59:01 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETNETENT 3 +.Os +.Sh NAME +.Nm getnetent , +.Nm getnetbyaddr , +.Nm getnetbyname , +.Nm setnetent , +.Nm endnetent +.Nd get network entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct netent * +.Fn getnetent void +.Ft struct netent * +.Fn getnetbyname "const char *name" +.Ft struct netent * +.Fn getnetbyaddr "unsigned long net" "int type" +.Ft void +.Fn setnetent "int stayopen" +.Ft void +.Fn endnetent void +.Sh DESCRIPTION +The +.Fn getnetent , +.Fn getnetbyname , +and +.Fn getnetbyaddr +functions +each return a pointer to an object with the +following structure describing an internet network. +This structure contains either the information obtained +from the nameserver, +.Xr named 8 , +broken-out fields of a line in the network data base +.Pa /etc/networks , +or entries supplied by the +.Xr yp 8 +system. The order of the lookups is controlled by the +`networks' entry in +.Xr nsswitch.conf 5 . +.Pp +.Bd -literal -offset indent +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net number type */ + unsigned long n_net; /* net number */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width n_addrtype +.It Fa n_name +The official name of the network. +.It Fa n_aliases +A zero terminated list of alternate names for the network. +.It Fa n_addrtype +The type of the network number returned; currently only AF_INET. +.It Fa n_net +The network number. Network numbers are returned in machine byte +order. +.El +.Pp +The +.Fn getnetent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setnetent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getnetbyname +or +.Fn getnetbyaddr . +.Pp +The +.Fn endnetent +function +closes the file. +.Pp +The +.Fn getnetbyname +function +and +.Fn getnetbyaddr +sequentially search from the beginning +of the file until a matching +net name or +net address and type is found, +or until +.Dv EOF +is encountered. +The +.Fa type +must be +.Dv AF_INET . +Network numbers are supplied in host order. +.Sh FILES +.Bl -tag -width /etc/nsswitch.conf -compact +.It Pa /etc/networks +.It Pa /etc/nsswitch.conf +.It Pa /etc/resolv.conf +.El +.Sh DIAGNOSTICS +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh SEE ALSO +.Xr networks 5 +.Pp +.%T RFC 1101 +.Sh HISTORY +The +.Fn getnetent , +.Fn getnetbyaddr , +.Fn getnetbyname , +.Fn setnetent , +and +.Fn endnetent +functions appeared in +.Bx 4.2 . +.Sh BUGS +The data space used by +these functions is static; if future use requires the data, it should be +copied before any subsequent calls to these functions overwrite it. +Only Internet network +numbers are currently understood. +Expecting network numbers to fit +in no more than 32 bits is probably +naive. diff --git a/newlib/libc/sys/linux/net/getnetent.c b/newlib/libc/sys/linux/net/getnetent.c deleted file mode 100644 index b42ef165e..000000000 --- a/newlib/libc/sys/linux/net/getnetent.c +++ /dev/null @@ -1,27 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct netent -#define GETFUNC_NAME getnetent -#define BUFLEN 1024 -#define NEED_H_ERRNO 1 - -#include "getXXent.c" diff --git a/newlib/libc/sys/linux/net/getnetent_r.c b/newlib/libc/sys/linux/net/getnetent_r.c deleted file mode 100644 index bb698196c..000000000 --- a/newlib/libc/sys/linux/net/getnetent_r.c +++ /dev/null @@ -1,32 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct netent -#define SETFUNC_NAME setnetent -#define GETFUNC_NAME getnetent -#define ENDFUNC_NAME endnetent -#define DATABASE_NAME networks -#define STAYOPEN int stayopen -#define STAYOPEN_VAR stayopen -#define NEED__RES 1 -#define NEED_H_ERRNO 1 - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getnetgrent.c b/newlib/libc/sys/linux/net/getnetgrent.c deleted file mode 100644 index 050af800f..000000000 --- a/newlib/libc/sys/linux/net/getnetgrent.c +++ /dev/null @@ -1,52 +0,0 @@ -/* 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 -#include -#include -#define _IO_MTSAFE_IO -#include -#include "libc-symbols.h" - -/* Static buffer for return value. We allocate it when needed. */ -libc_freeres_ptr (static char *buffer); -/* All three strings should fit in a block of 1kB size. */ -#define BUFSIZE 1024 - - - -static void -allocate (void) -{ - buffer = (char *) malloc (BUFSIZE); -} - -int -getnetgrent (char **hostp, char **userp, char **domainp) -{ - __libc_once_define (static, once); - __libc_once (once, allocate); - - if (buffer == NULL) - { - __set_errno (ENOMEM); - return -1; - } - - return __getnetgrent_r (hostp, userp, domainp, buffer, BUFSIZE); -} diff --git a/newlib/libc/sys/linux/net/getnetgrent_r.c b/newlib/libc/sys/linux/net/getnetgrent_r.c deleted file mode 100644 index ebc2ac5ea..000000000 --- a/newlib/libc/sys/linux/net/getnetgrent_r.c +++ /dev/null @@ -1,446 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include "netgroup.h" -#include "nsswitch.h" -#include "libc-symbols.h" - - -/* Protect above variable against multiple uses at the same time. */ -__libc_lock_define_initialized (static, lock) - -/* The whole information for the set/get/endnetgrent functions are - kept in this structure. */ -static struct __netgrent dataset; - -/* The lookup function for the first entry of this service. */ -extern int __nss_netgroup_lookup (service_user **nip, const char *name, - void **fctp) internal_function; - - -/* Set up NIP to run through the services. If ALL is zero, use NIP's - current location if it's not nil. Return nonzero if there are no - services (left). */ -static enum nss_status -setup (void **fctp, const char *func_name, int all, service_user **nipp) -{ - /* Remember the first service_entry, it's always the same. */ - static service_user *startp; - int no_more; - - if (startp == NULL) - { - /* Executing this more than once at the same time must yield the - same result every time. So we need no locking. */ - no_more = __nss_netgroup_lookup (nipp, func_name, fctp); - startp = no_more ? (service_user *) -1 : *nipp; - } - else if (startp == (service_user *) -1) - /* No services at all. */ - return 1; - else - { - if (all || *nipp == NULL) - /* Reset to the beginning of the service list. */ - *nipp = startp; - /* Look up the first function. */ - no_more = __nss_lookup (nipp, func_name, fctp); - } - return no_more; -} - -/* Free used memory. */ -static void -free_memory (struct __netgrent *data) -{ - while (data->known_groups != NULL) - { - struct name_list *tmp = data->known_groups; - data->known_groups = data->known_groups->next; - free (tmp); - } - - while (data->needed_groups != NULL) - { - struct name_list *tmp = data->needed_groups; - data->needed_groups = data->needed_groups->next; - free (tmp); - } -} - -static int -internal_function -__internal_setnetgrent_reuse (const char *group, struct __netgrent *datap, - int *errnop) -{ - union - { - enum nss_status (*f) (const char *, struct __netgrent *); - void *ptr; - } fct; - enum nss_status status = NSS_STATUS_UNAVAIL; - struct name_list *new_elem; - - /* Cycle through all the services and run their setnetgrent functions. */ - int no_more = setup (&fct.ptr, "setnetgrent", 1, &datap->nip); - while (! no_more) - { - /* Ignore status, we force check in `__nss_next'. */ - status = (*fct.f) (group, datap); - - no_more = __nss_next (&datap->nip, "setnetgrent", &fct.ptr, status, 0); - } - - /* Add the current group to the list of known groups. */ - size_t group_len = strlen (group) + 1; - new_elem = (struct name_list *) malloc (sizeof (struct name_list) - + group_len); - if (new_elem == NULL) - { - *errnop = errno; - status = NSS_STATUS_TRYAGAIN; - } - else - { - new_elem->next = datap->known_groups; - memcpy (new_elem->name, group, group_len); - datap->known_groups = new_elem; - } - - return status == NSS_STATUS_SUCCESS; -} - -int internal_setnetgrent (const char *group, struct __netgrent *datap); -libc_hidden_proto (internal_setnetgrent) - -int -internal_setnetgrent (const char *group, struct __netgrent *datap) -{ - /* Free list of all netgroup names from last run. */ - free_memory (datap); - - return __internal_setnetgrent_reuse (group, datap, &errno); -} -libc_hidden_def (internal_setnetgrent) -strong_alias (internal_setnetgrent, __internal_setnetgrent) - -int -setnetgrent (const char *group) -{ - int result; - - __libc_lock_lock (lock); - - result = internal_setnetgrent (group, &dataset); - - __libc_lock_unlock (lock); - - return result; -} - - -void internal_endnetgrent (struct __netgrent *datap); -libc_hidden_proto (internal_endnetgrent) - -void -internal_endnetgrent (struct __netgrent *datap) -{ - service_user *old_nip; - union - { - enum nss_status (*f) (struct __netgrent *); - void *ptr; - } fct; - - /* Remember which was the last used service. */ - old_nip = datap->nip; - - /* Cycle through all the services and run their endnetgrent functions. */ - int no_more = setup (&fct.ptr, "endnetgrent", 1, &datap->nip); - while (! no_more) - { - /* Ignore status, we force check in `__nss_next'. */ - (void) (*fct.f) (datap); - - no_more = (datap->nip == old_nip - || __nss_next (&datap->nip, "endnetgrent", &fct.ptr, 0, 1)); - } - - /* Now free list of all netgroup names from last run. */ - free_memory (datap); -} -libc_hidden_def (internal_endnetgrent) -strong_alias (internal_endnetgrent, __internal_endnetgrent) - - -void -endnetgrent (void) -{ - __libc_lock_lock (lock); - - internal_endnetgrent (&dataset); - - __libc_lock_unlock (lock); -} - - -int internal_getnetgrent_r (char **hostp, char **userp, char **domainp, - struct __netgrent *datap, - char *buffer, size_t buflen, int *errnop); -libc_hidden_proto (internal_getnetgrent_r) - -int -internal_getnetgrent_r (char **hostp, char **userp, char **domainp, - struct __netgrent *datap, - char *buffer, size_t buflen, int *errnop) -{ - union - { - enum nss_status (*f) (struct __netgrent *, char *, size_t, int *); - void *ptr; - } fct; - - /* Initialize status to return if no more functions are found. */ - enum nss_status status = NSS_STATUS_NOTFOUND; - - /* Run through available functions, starting with the same function last - run. We will repeat each function as long as it succeeds, and then go - on to the next service action. */ - int no_more = setup (&fct.ptr, "getnetgrent_r", 0, &datap->nip); - while (! no_more) - { - status = (*fct.f) (datap, buffer, buflen, &errno); - - if (status == NSS_STATUS_RETURN) - { - /* This was the last one for this group. Look at next group - if available. */ - int found = 0; - while (datap->needed_groups != NULL && ! found) - { - struct name_list *tmp = datap->needed_groups; - datap->needed_groups = datap->needed_groups->next; - tmp->next = datap->known_groups; - datap->known_groups = tmp; - - found = __internal_setnetgrent_reuse (datap->known_groups->name, - datap, errnop); - } - - if (found) - continue; - } - else if (status == NSS_STATUS_SUCCESS && datap->type == group_val) - { - /* The last entry was a name of another netgroup. */ - struct name_list *namep; - - /* Ignore if we've seen the name before. */ - for (namep = datap->known_groups; namep != NULL; - namep = namep->next) - if (strcmp (datap->val.group, namep->name) == 0) - break; - if (namep != NULL) - /* Really ignore. */ - continue; - - size_t group_len = strlen (datap->val.group) + 1; - namep = (struct name_list *) malloc (sizeof (struct name_list) - + group_len); - if (namep == NULL) - /* We are out of memory. */ - status = NSS_STATUS_RETURN; - else - { - namep->next = datap->needed_groups; - memcpy (namep->name, datap->val.group, group_len); - datap->needed_groups = namep; - /* And get the next entry. */ - continue; - } - } - - no_more = __nss_next (&datap->nip, "getnetgrent_r", &fct.ptr, status, 0); - } - - if (status == NSS_STATUS_SUCCESS) - { - *hostp = (char *) datap->val.triple.host; - *userp = (char *) datap->val.triple.user; - *domainp = (char *) datap->val.triple.domain; - } - - return status == NSS_STATUS_SUCCESS ? 1 : 0; -} -libc_hidden_def (internal_getnetgrent_r) -strong_alias (internal_getnetgrent_r, __internal_getnetgrent_r) - -/* The real entry point. */ -int -__getnetgrent_r (char **hostp, char **userp, char **domainp, - char *buffer, size_t buflen) -{ - enum nss_status status; - - __libc_lock_lock (lock); - - status = internal_getnetgrent_r (hostp, userp, domainp, &dataset, - buffer, buflen, &errno); - - __libc_lock_unlock (lock); - - return status; -} -weak_alias (__getnetgrent_r, getnetgrent_r) - -/* Test whether given (host,user,domain) triple is in NETGROUP. */ -int -innetgr (const char *netgroup, const char *host, const char *user, - const char *domain) -{ - union - { - int (*f) (const char *, struct __netgrent *); - void *ptr; - } setfct; - union - { - void (*f) (struct __netgrent *); - void *ptr; - } endfct; - union - { - int (*f) (struct __netgrent *, char *, size_t, int *); - void *ptr; - } getfct; - struct __netgrent entry; - int result = 0; - const char *current_group = netgroup; - int real_entry = 0; - - memset (&entry, '\0', sizeof (entry)); - - /* Walk through the services until we found an answer or we shall - not work further. We can do some optimization here. Since all - services must provide the `setnetgrent' function we can do all - the work during one walk through the service list. */ - while (1) - { - int no_more = setup (&setfct.ptr, "setnetgrent", 1, &entry.nip); - while (! no_more) - { - /* Open netgroup. */ - enum nss_status status = (*setfct.f) (current_group, &entry); - - if (status == NSS_STATUS_SUCCESS - && __nss_lookup (&entry.nip, "getnetgrent_r", &getfct.ptr) == 0) - { - char buffer[1024]; - - while ((*getfct.f) (&entry, buffer, sizeof buffer, &errno) - == NSS_STATUS_SUCCESS) - { - if (entry.type == group_val) - { - /* Make sure we haven't seen the name before. */ - struct name_list *namep; - - for (namep = entry.known_groups; namep != NULL; - namep = namep->next) - if (strcmp (entry.val.group, namep->name) == 0) - break; - if (namep == NULL - && strcmp (netgroup, entry.val.group) != 0) - { - size_t group_len = strlen (entry.val.group) + 1; - namep = - (struct name_list *) malloc (sizeof (*namep) - + group_len); - if (namep == NULL) - { - /* Out of memory, simply return. */ - result = -1; - break; - } - - namep->next = entry.needed_groups; - memcpy (namep->name, entry.val.group, group_len); - entry.needed_groups = namep; - } - } - else - { - real_entry = 1; - - if ((entry.val.triple.host == NULL || host == NULL - || strcasecmp (entry.val.triple.host, host) == 0) - && (entry.val.triple.user == NULL || user == NULL - || strcmp (entry.val.triple.user, user) == 0) - && (entry.val.triple.domain == NULL || domain == NULL - || strcasecmp (entry.val.triple.domain, - domain) == 0)) - { - result = 1; - break; - } - } - } - - if (result != 0) - break; - - /* If we found one service which does know the given - netgroup we don't try further. */ - status = NSS_STATUS_RETURN; - } - - /* Free all resources of the service. */ - if (__nss_lookup (&entry.nip, "endnetgrent", &endfct.ptr) == 0) - (*endfct.f) (&entry); - - /* Look for the next service. */ - no_more = __nss_next (&entry.nip, "setnetgrent", - &setfct.ptr, status, 0); - } - - if (result == 0 && entry.needed_groups != NULL) - { - struct name_list *tmp = entry.needed_groups; - entry.needed_groups = tmp->next; - tmp->next = entry.known_groups; - entry.known_groups = tmp; - current_group = entry.known_groups->name; - continue; - } - - /* No way out. */ - break; - } - - /* Free the memory. */ - free_memory (&entry); - - return result; -} -libc_hidden_def (innetgr) diff --git a/newlib/libc/sys/linux/net/getnetnamadr.c b/newlib/libc/sys/linux/net/getnetnamadr.c new file mode 100644 index 000000000..180ab14e2 --- /dev/null +++ b/newlib/libc/sys/linux/net/getnetnamadr.c @@ -0,0 +1,113 @@ +/*- + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern int _ht_getnetbyname(void *, void *, va_list); +extern int _dns_getnetbyname(void *, void *, va_list); +extern int _nis_getnetbyname(void *, void *, va_list); +extern int _ht_getnetbyaddr(void *, void *, va_list); +extern int _dns_getnetbyaddr(void *, void *, va_list); +extern int _nis_getnetbyaddr(void *, void *, va_list); + +/* Network lookup order if nsswitch.conf is broken or nonexistant */ +static const ns_src default_src[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NSSRC_DNS, NS_SUCCESS }, + { 0 } +}; + +struct netent * +getnetbyname(const char *name) +{ + struct netent *hp = 0; + int rval; + + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_getnetbyname, NULL) + { NSSRC_DNS, _dns_getnetbyname, NULL }, + NS_NIS_CB(_nis_getnetbyname, NULL) /* force -DHESIOD */ + { 0 } + }; + + rval = nsdispatch((void *)&hp, dtab, NSDB_NETWORKS, "getnetbyname", + default_src, name); + + if (rval != NS_SUCCESS) + return NULL; + else + return hp; +} + +struct netent * +getnetbyaddr(u_long addr, int af) +{ + struct netent *hp = 0; + int rval; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_ht_getnetbyaddr, NULL) + { NSSRC_DNS, _dns_getnetbyaddr, NULL }, + NS_NIS_CB(_nis_getnetbyaddr, NULL) /* force -DHESIOD */ + { 0 } + }; + + rval = nsdispatch((void *)&hp, dtab, NSDB_NETWORKS, "getnetbyaddr", + default_src, addr, af); + + if (rval != NS_SUCCESS) + return NULL; + else + return hp; +} + +void +setnetent(stayopen) + int stayopen; +{ + _setnethtent(stayopen); + _setnetdnsent(stayopen); +} + +void +endnetent() +{ + _endnethtent(); + _endnetdnsent(); +} diff --git a/newlib/libc/sys/linux/net/getnssent.c b/newlib/libc/sys/linux/net/getnssent.c deleted file mode 100644 index 1f7573da7..000000000 --- a/newlib/libc/sys/linux/net/getnssent.c +++ /dev/null @@ -1,58 +0,0 @@ -/* 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 -#include -#include -#include "nsswitch.h" - -void * -__nss_getent (getent_r_function func, void **resbuf, char **buffer, - size_t buflen, size_t *buffer_size, int *h_errnop) -{ - void *result; - - if (*buffer == NULL) - { - *buffer_size = buflen; - *buffer = malloc (*buffer_size); - } - - while (buffer != NULL - && func (resbuf, *buffer, *buffer_size, &result, h_errnop) == ERANGE - && (h_errnop == NULL || *h_errnop == NETDB_INTERNAL)) - { - char *new_buf; - *buffer_size *= 2; - new_buf = realloc (*buffer, *buffer_size); - if (new_buf == NULL) - { - /* We are out of memory. Free the current buffer so that the - process gets a chance for a normal termination. */ - int save = errno; - free (*buffer); - __set_errno (save); - } - *buffer = new_buf; - } - - if (*buffer == NULL) - result = NULL; - - return result; -} diff --git a/newlib/libc/sys/linux/net/getnssent_r.c b/newlib/libc/sys/linux/net/getnssent_r.c deleted file mode 100644 index 517f19d02..000000000 --- a/newlib/libc/sys/linux/net/getnssent_r.c +++ /dev/null @@ -1,218 +0,0 @@ -/* 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 -#include -#include "nsswitch.h" - -/* Set up NIP to run through the services. If ALL is zero, use NIP's - current location if it's not nil. Return nonzero if there are no - services (left). */ -static int -setup (const char *func_name, db_lookup_function lookup_fct, - void **fctp, service_user **nip, service_user **startp, int all) -{ - int no_more; - if (*startp == NULL) - { - no_more = lookup_fct (nip, func_name, fctp); - *startp = no_more ? (service_user *) -1l : *nip; - } - else if (*startp == (service_user *) -1l) - /* No services at all. */ - return 1; - else - { - if (all || !*nip) - /* Reset to the beginning of the service list. */ - *nip = *startp; - /* Look up the first function. */ - no_more = __nss_lookup (nip, func_name, fctp); - } - return no_more; -} - -void -__nss_setent (const char *func_name, db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int stayopen, int *stayopen_tmp, - int res) -{ - union - { - setent_function f; - void *ptr; - } fct; - int no_more; - - if (res && __res_maybe_init (&_res, 0) == -1) - { - h_errno = (NETDB_INTERNAL); - return; - } - - /* Cycle through the services and run their `setXXent' functions until - we find an available service. */ - no_more = setup (func_name, lookup_fct, &fct.ptr, nip, - startp, 1); - while (! no_more) - { - int is_last_nip = *nip == *last_nip; - enum nss_status status; - - if (stayopen_tmp) - status = DL_CALL_FCT (fct.f, (*stayopen_tmp)); - else - status = DL_CALL_FCT (fct.f, (0)); - - no_more = __nss_next (nip, func_name, &fct.ptr, - status, 0); - if (is_last_nip) - *last_nip = *nip; - } - - if (stayopen_tmp) - *stayopen_tmp = stayopen; -} - - -void -__nss_endent (const char *func_name, db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int res) -{ - union - { - endent_function f; - void *ptr; - } fct; - int no_more; - - if (res && __res_maybe_init (&_res, 0) == -1) - { - h_errno = (NETDB_INTERNAL); - return; - } - - /* Cycle through all the services and run their endXXent functions. */ - no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1); - while (! no_more) - { - /* Ignore status, we force check in __NSS_NEXT. */ - DL_CALL_FCT (fct.f, ()); - - if (*nip == *last_nip) - /* We have processed all services which were used. */ - break; - - no_more = __nss_next (nip, func_name, &fct.ptr, 0, 1); - } - *last_nip = *nip = NULL; -} - - -int -__nss_getent_r (const char *getent_func_name, - const char *setent_func_name, - db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int *stayopen_tmp, int res, - void *resbuf, char *buffer, size_t buflen, - void **result, int *h_errnop) -{ - union - { - getent_function f; - void *ptr; - } fct; - int no_more; - enum nss_status status; - - if (res && __res_maybe_init (&_res, 0) == -1) - { - *h_errnop = NETDB_INTERNAL; - *result = NULL; - return errno; - } - - /* Initialize status to return if no more functions are found. */ - status = NSS_STATUS_NOTFOUND; - - /* Run through available functions, starting with the same function last - run. We will repeat each function as long as it succeeds, and then go - on to the next service action. */ - no_more = setup (getent_func_name, lookup_fct, &fct.ptr, nip, - startp, 0); - while (! no_more) - { - int is_last_nip = *nip == *last_nip; - - status = DL_CALL_FCT (fct.f, - (resbuf, buffer, buflen, &errno, &h_errno)); - - /* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the - provided buffer is too small. In this case we should give - the user the possibility to enlarge the buffer and we should - not simply go on with the next service (even if the TRYAGAIN - action tells us so). */ - if (status == NSS_STATUS_TRYAGAIN - && (h_errnop == NULL || *h_errnop == NETDB_INTERNAL) - && errno == ERANGE) - break; - - do - { - no_more = __nss_next (nip, getent_func_name, &fct.ptr, - status, 0); - - if (is_last_nip) - *last_nip = *nip; - - if (! no_more) - { - /* Call the `setXXent' function. This wasn't done before. */ - union - { - setent_function f; - void *ptr; - } sfct; - - no_more = __nss_lookup (nip, setent_func_name, - &sfct.ptr); - - if (! no_more) - { - if (stayopen_tmp) - status = DL_CALL_FCT (sfct.f, (*stayopen_tmp)); - else - status = DL_CALL_FCT (sfct.f, (0)); - } - else - status = NSS_STATUS_NOTFOUND; - } - } - while (! no_more && status != NSS_STATUS_SUCCESS); - } - - *result = status == NSS_STATUS_SUCCESS ? resbuf : NULL; - return (status == NSS_STATUS_SUCCESS ? 0 - : status != NSS_STATUS_TRYAGAIN ? ENOENT - /* h_errno functions only set errno if h_errno is NETDB_INTERNAL. */ - : (h_errnop == NULL || *h_errnop == NETDB_INTERNAL) ? errno - : EAGAIN); -} diff --git a/newlib/libc/sys/linux/net/getproto.c b/newlib/libc/sys/linux/net/getproto.c index 750c1097f..937c30732 100644 --- a/newlib/libc/sys/linux/net/getproto.c +++ b/newlib/libc/sys/linux/net/getproto.c @@ -1,30 +1,57 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. +/* + * 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. + */ - 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. */ +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include #include +extern int _proto_stayopen; -#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 +struct protoent * +getprotobynumber(proto) + int proto; +{ + struct protoent *p; -#include "getXXbyYY.c" + setprotoent(_proto_stayopen); + while ( (p = getprotoent()) ) + if (p->p_proto == proto) + break; + if (!_proto_stayopen) + endprotoent(); + return (p); +} diff --git a/newlib/libc/sys/linux/net/getproto_r.c b/newlib/libc/sys/linux/net/getproto_r.c deleted file mode 100644 index 486df1d4e..000000000 --- a/newlib/libc/sys/linux/net/getproto_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct protoent -#define FUNCTION_NAME getprotobynumber -#define DATABASE_NAME protocols -#define ADD_PARAMS int proto -#define ADD_VARIABLES proto - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getprotoent.3 b/newlib/libc/sys/linux/net/getprotoent.3 new file mode 100644 index 000000000..18b56541b --- /dev/null +++ b/newlib/libc/sys/linux/net/getprotoent.3 @@ -0,0 +1,149 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/getprotoent.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt GETPROTOENT 3 +.Os +.Sh NAME +.Nm getprotoent , +.Nm getprotobynumber , +.Nm getprotobyname , +.Nm setprotoent , +.Nm endprotoent +.Nd get protocol entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct protoent * +.Fn getprotoent void +.Ft struct protoent * +.Fn getprotobyname "const char *name" +.Ft struct protoent * +.Fn getprotobynumber "int proto" +.Ft void +.Fn setprotoent "int stayopen" +.Ft void +.Fn endprotoent void +.Sh DESCRIPTION +The +.Fn getprotoent , +.Fn getprotobyname , +and +.Fn getprotobynumber +functions +each return a pointer to an object with the +following structure +containing the broken-out +fields of a line in the network protocol data base, +.Pa /etc/protocols . +.Bd -literal -offset indent +.Pp +struct protoent { + char *p_name; /* official name of protocol */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol number */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width p_aliases +.It Fa p_name +The official name of the protocol. +.It Fa p_aliases +A zero terminated list of alternate names for the protocol. +.It Fa p_proto +The protocol number. +.El +.Pp +The +.Fn getprotoent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setprotoent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getprotobyname +or +.Fn getprotobynumber . +.Pp +The +.Fn endprotoent +function +closes the file. +.Pp +The +.Fn getprotobyname +function +and +.Fn getprotobynumber +sequentially search from the beginning +of the file until a matching +protocol name or +protocol number is found, +or until +.Dv EOF +is encountered. +.Sh RETURN VALUES +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh FILES +.Bl -tag -width /etc/protocols -compact +.It Pa /etc/protocols +.El +.Sh SEE ALSO +.Xr protocols 5 +.Sh HISTORY +The +.Fn getprotoent , +.Fn getprotobynumber , +.Fn getprotobyname , +.Fn setprotoent , +and +.Fn endprotoent +functions appeared in +.Bx 4.2 . +.Sh BUGS +These functions use a static data space; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Only the Internet +protocols are currently understood. diff --git a/newlib/libc/sys/linux/net/getprotoent.c b/newlib/libc/sys/linux/net/getprotoent.c new file mode 100644 index 000000000..422eeacea --- /dev/null +++ b/newlib/libc/sys/linux/net/getprotoent.c @@ -0,0 +1,121 @@ +/* + * 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 +#include + +#include +#include +#include +#include +#include +#include + +#define MAXALIASES 35 + +static FILE *protof = NULL; +static char line[BUFSIZ+1]; +static struct protoent proto; +static char *proto_aliases[MAXALIASES]; +int _proto_stayopen; + +void +setprotoent(f) + int f; +{ + if (protof == NULL) + protof = fopen(_PATH_PROTOCOLS, "r" ); + else + rewind(protof); + _proto_stayopen |= f; +} + +void +endprotoent() +{ + if (protof) { + fclose(protof); + protof = NULL; + } + _proto_stayopen = 0; +} + +struct protoent * +getprotoent() +{ + char *p; + char *cp, **q; + + if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) + return (NULL); +again: + if ((p = fgets(line, BUFSIZ, protof)) == NULL) + return (NULL); + if (*p == '#') + goto again; + cp = strpbrk(p, "#\n"); + if (cp == NULL) + goto again; + *cp = '\0'; + proto.p_name = p; + cp = strpbrk(p, " \t"); + if (cp == NULL) + goto again; + *cp++ = '\0'; + while (*cp == ' ' || *cp == '\t') + cp++; + p = strpbrk(cp, " \t"); + if (p != NULL) + *p++ = '\0'; + proto.p_proto = atoi(cp); + q = proto.p_aliases = proto_aliases; + if (p != NULL) { + cp = p; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &proto_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + } + *q = NULL; + return (&proto); +} diff --git a/newlib/libc/sys/linux/net/getprotoname.c b/newlib/libc/sys/linux/net/getprotoname.c new file mode 100644 index 000000000..f25883fe8 --- /dev/null +++ b/newlib/libc/sys/linux/net/getprotoname.c @@ -0,0 +1,64 @@ +/* + * 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 +#include + +#include +#include + +extern int _proto_stayopen; + +struct protoent * +getprotobyname(name) + const char *name; +{ + struct protoent *p; + char **cp; + + setprotoent(_proto_stayopen); + while ( (p = getprotoent()) ) { + if (strcmp(p->p_name, name) == 0) + break; + for (cp = p->p_aliases; *cp != 0; cp++) + if (strcmp(*cp, name) == 0) + goto found; + } +found: + if (!_proto_stayopen) + endprotoent(); + return (p); +} diff --git a/newlib/libc/sys/linux/net/getprtent.c b/newlib/libc/sys/linux/net/getprtent.c deleted file mode 100644 index 16a7e57bc..000000000 --- a/newlib/libc/sys/linux/net/getprtent.c +++ /dev/null @@ -1,26 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct protoent -#define GETFUNC_NAME getprotoent -#define BUFLEN 1024 - -#include "getXXent.c" diff --git a/newlib/libc/sys/linux/net/getprtent_r.c b/newlib/libc/sys/linux/net/getprtent_r.c deleted file mode 100644 index 2f0ca473b..000000000 --- a/newlib/libc/sys/linux/net/getprtent_r.c +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct protoent -#define SETFUNC_NAME setprotoent -#define GETFUNC_NAME getprotoent -#define ENDFUNC_NAME endprotoent -#define DATABASE_NAME protocols -#define STAYOPEN int stayopen -#define STAYOPEN_VAR stayopen - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getprtname.c b/newlib/libc/sys/linux/net/getprtname.c deleted file mode 100644 index 1222daeea..000000000 --- a/newlib/libc/sys/linux/net/getprtname.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct protoent -#define FUNCTION_NAME getprotobyname -#define DATABASE_NAME protocols -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getprtname_r.c b/newlib/libc/sys/linux/net/getprtname_r.c deleted file mode 100644 index b0dee382e..000000000 --- a/newlib/libc/sys/linux/net/getprtname_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct protoent -#define FUNCTION_NAME getprotobyname -#define DATABASE_NAME protocols -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getrpcbyname.c b/newlib/libc/sys/linux/net/getrpcbyname.c deleted file mode 100644 index 266967aed..000000000 --- a/newlib/libc/sys/linux/net/getrpcbyname.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct rpcent -#define FUNCTION_NAME getrpcbyname -#define DATABASE_NAME rpc -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getrpcbyname_r.c b/newlib/libc/sys/linux/net/getrpcbyname_r.c deleted file mode 100644 index 3e7c2df74..000000000 --- a/newlib/libc/sys/linux/net/getrpcbyname_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct rpcent -#define FUNCTION_NAME getrpcbyname -#define DATABASE_NAME rpc -#define ADD_PARAMS const char *name -#define ADD_VARIABLES name - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getrpcbynumber.c b/newlib/libc/sys/linux/net/getrpcbynumber.c deleted file mode 100644 index f9513eb62..000000000 --- a/newlib/libc/sys/linux/net/getrpcbynumber.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct rpcent -#define FUNCTION_NAME getrpcbynumber -#define DATABASE_NAME rpc -#define ADD_PARAMS int number -#define ADD_VARIABLES number -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getrpcbynumber_r.c b/newlib/libc/sys/linux/net/getrpcbynumber_r.c deleted file mode 100644 index 839442214..000000000 --- a/newlib/libc/sys/linux/net/getrpcbynumber_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct rpcent -#define FUNCTION_NAME getrpcbynumber -#define DATABASE_NAME rpc -#define ADD_PARAMS int number -#define ADD_VARIABLES number - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getrpcent.c b/newlib/libc/sys/linux/net/getrpcent.c deleted file mode 100644 index 1b4eb03a2..000000000 --- a/newlib/libc/sys/linux/net/getrpcent.c +++ /dev/null @@ -1,26 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct rpcent -#define GETFUNC_NAME getrpcent -#define BUFLEN 1024 - -#include "getXXent.c" diff --git a/newlib/libc/sys/linux/net/getrpcent_r.c b/newlib/libc/sys/linux/net/getrpcent_r.c deleted file mode 100644 index e212b5f2e..000000000 --- a/newlib/libc/sys/linux/net/getrpcent_r.c +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct rpcent -#define SETFUNC_NAME setrpcent -#define GETFUNC_NAME getrpcent -#define ENDFUNC_NAME endrpcent -#define DATABASE_NAME rpc -#define STAYOPEN int stayopen -#define STAYOPEN_VAR stayopen - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getservbyname.c b/newlib/libc/sys/linux/net/getservbyname.c new file mode 100644 index 000000000..ced03d617 --- /dev/null +++ b/newlib/libc/sys/linux/net/getservbyname.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include + +extern int _serv_stayopen; + +struct servent * +getservbyname(name, proto) + const char *name, *proto; +{ + struct servent *p; + char **cp; + +#ifdef YP + extern char *___getservbyname_yp; + extern char *___getservbyproto_yp; + + ___getservbyname_yp = (char *)name; + ___getservbyproto_yp = (char *)proto; +#endif + + setservent(_serv_stayopen); + while ( (p = getservent()) ) { + if (strcmp(name, p->s_name) == 0) + goto gotname; + for (cp = p->s_aliases; *cp; cp++) + if (strcmp(name, *cp) == 0) + goto gotname; + continue; +gotname: + if (proto == 0 || strcmp(p->s_proto, proto) == 0) + break; + } + if (!_serv_stayopen) + endservent(); + +#ifdef YP + ___getservbyname_yp = NULL; + ___getservbyproto_yp = NULL; +#endif + + return (p); +} diff --git a/newlib/libc/sys/linux/net/getservbyport.c b/newlib/libc/sys/linux/net/getservbyport.c new file mode 100644 index 000000000..88b684da4 --- /dev/null +++ b/newlib/libc/sys/linux/net/getservbyport.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include + +extern int _serv_stayopen; + +struct servent * +getservbyport(port, proto) + int port; + const char *proto; +{ + struct servent *p; + +#ifdef YP + extern int ___getservbyport_yp; + extern char *___getservbyproto_yp; + + ___getservbyport_yp = port; + ___getservbyproto_yp = (char *)proto; +#endif + + setservent(_serv_stayopen); + while ( (p = getservent()) ) { + if (p->s_port != port) + continue; + if (proto == 0 || strcmp(p->s_proto, proto) == 0) + break; + } + if (!_serv_stayopen) + endservent(); + +#ifdef YP + ___getservbyport_yp = 0; + ___getservbyproto_yp = NULL; +#endif + + return (p); +} diff --git a/newlib/libc/sys/linux/net/getservent.3 b/newlib/libc/sys/linux/net/getservent.3 new file mode 100644 index 000000000..3d398bdb1 --- /dev/null +++ b/newlib/libc/sys/linux/net/getservent.3 @@ -0,0 +1,158 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94 +.\" $FreeBSD: src/lib/libc/net/getservent.3,v 1.12 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd July 9, 1995 +.Dt GETSERVENT 3 +.Os +.Sh NAME +.Nm getservent , +.Nm getservbyport , +.Nm getservbyname , +.Nm setservent , +.Nm endservent +.Nd get service entry +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In netdb.h +.Ft struct servent * +.Fn getservent +.Ft struct servent * +.Fn getservbyname "const char *name" "const char *proto" +.Ft struct servent * +.Fn getservbyport "int port" "const char *proto" +.Ft void +.Fn setservent "int stayopen" +.Ft void +.Fn endservent void +.Sh DESCRIPTION +The +.Fn getservent , +.Fn getservbyname , +and +.Fn getservbyport +functions +each return a pointer to an object with the +following structure +containing the broken-out +fields of a line in the network services data base, +.Pa /etc/services . +.Bd -literal -offset indent +struct servent { + char *s_name; /* official name of service */ + char **s_aliases; /* alias list */ + int s_port; /* port service resides at */ + char *s_proto; /* protocol to use */ +}; +.Ed +.Pp +The members of this structure are: +.Bl -tag -width s_aliases +.It Fa s_name +The official name of the service. +.It Fa s_aliases +A zero terminated list of alternate names for the service. +.It Fa s_port +The port number at which the service resides. +Port numbers are returned in network byte order. +.It Fa s_proto +The name of the protocol to use when contacting the +service. +.El +.Pp +The +.Fn getservent +function +reads the next line of the file, opening the file if necessary. +.Pp +The +.Fn setservent +function +opens and rewinds the file. If the +.Fa stayopen +flag is non-zero, +the net data base will not be closed after each call to +.Fn getservbyname +or +.Fn getservbyport . +.Pp +The +.Fn endservent +function +closes the file. +.Pp +The +.Fn getservbyname +and +.Fn getservbyport +functions +sequentially search from the beginning +of the file until a matching +protocol name or +port number (which must be specified in +network byte order) is found, +or until +.Dv EOF +is encountered. +If a protocol name is also supplied (non- +.Dv NULL ) , +searches must also match the protocol. +.Sh FILES +.Bl -tag -width /etc/services -compact +.It Pa /etc/services +.El +.Sh DIAGNOSTICS +Null pointer +(0) returned on +.Dv EOF +or error. +.Sh SEE ALSO +.Xr getprotoent 3 , +.Xr services 5 +.Sh HISTORY +The +.Fn getservent , +.Fn getservbyport , +.Fn getservbyname , +.Fn setservent , +and +.Fn endservent +functions appeared in +.Bx 4.2 . +.Sh BUGS +These functions use static data storage; +if the data is needed for future use, it should be +copied before any subsequent calls overwrite it. +Expecting port numbers to fit in a 32 bit +quantity is probably naive. diff --git a/newlib/libc/sys/linux/net/getservent.c b/newlib/libc/sys/linux/net/getservent.c index 76a0ead8e..1c26df75c 100644 --- a/newlib/libc/sys/linux/net/getservent.c +++ b/newlib/libc/sys/linux/net/getservent.c @@ -1,26 +1,282 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. +/* + * 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. + */ - 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. +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include +#include - 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. +#include +#include +#include +#include +#include +#include +#include +#ifdef YP +#include +#include +#include +static int serv_stepping_yp = 0; +extern int _yp_check( char ** ); +#endif - 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 +#define MAXALIASES 35 + +static FILE *servf = NULL; +static char line[BUFSIZ+1]; +static struct servent serv; +static char *serv_aliases[MAXALIASES]; +int _serv_stayopen; + +#ifdef YP +char *___getservbyname_yp = NULL; +char *___getservbyproto_yp = NULL; +int ___getservbyport_yp = 0; +static char *yp_domain = NULL; + +static int +_getservbyport_yp(line) + char *line; +{ + char *result; + int resultlen; + char buf[YPMAXRECORD + 2]; + int rv; + + snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp), + ___getservbyproto_yp); + + ___getservbyport_yp = 0; + ___getservbyproto_yp = NULL; + + if(!yp_domain) { + if(yp_get_default_domain(&yp_domain)) + return (0); + } + + /* + * We have to be a little flexible here. Ideally you're supposed + * to have both a services.byname and a services.byport map, but + * some systems have only services.byname. FreeBSD cheats a little + * by putting the services.byport information in the same map as + * services.byname so that either case will work. We allow for both + * possibilities here: if there is no services.byport map, we try + * services.byname instead. + */ + if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf), + &result, &resultlen))) { + if (rv == YPERR_MAP) { + if (yp_match(yp_domain, "services.byname", buf, + strlen(buf), &result, &resultlen)) + return(0); + } else + return(0); + } + + /* getservent() expects lines terminated with \n -- make it happy */ + snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); + + free(result); + return(1); +} + +static int +_getservbyname_yp(line) + char *line; +{ + char *result; + int resultlen; + char buf[YPMAXRECORD + 2]; + + if(!yp_domain) { + if(yp_get_default_domain(&yp_domain)) + return (0); + } + + snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp, + ___getservbyproto_yp); + + ___getservbyname_yp = 0; + ___getservbyproto_yp = NULL; + + if (yp_match(yp_domain, "services.byname", buf, strlen(buf), + &result, &resultlen)) { + return(0); + } + + /* getservent() expects lines terminated with \n -- make it happy */ + snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); + + free(result); + return(1); +} + +static int +_getservent_yp(line) + char *line; +{ + static char *key = NULL; + static int keylen; + char *lastkey, *result; + int resultlen; + int rv; + + if(!yp_domain) { + if(yp_get_default_domain(&yp_domain)) + return (0); + } + + if (!serv_stepping_yp) { + if (key) + free(key); + if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen, + &result, &resultlen))) { + serv_stepping_yp = 0; + return(0); + } + serv_stepping_yp = 1; + } else { + lastkey = key; + rv = yp_next(yp_domain, "services.byname", key, keylen, &key, + &keylen, &result, &resultlen); + free(lastkey); + if (rv) { + serv_stepping_yp = 0; + return (0); + } + } + + /* getservent() expects lines terminated with \n -- make it happy */ + snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); + + free(result); + + return(1); +} +#endif + +void +setservent(f) + int f; +{ + if (servf == NULL) + servf = fopen(_PATH_SERVICES, "r" ); + else + rewind(servf); + _serv_stayopen |= f; +} +void +endservent() +{ + if (servf) { + fclose(servf); + servf = NULL; + } + _serv_stayopen = 0; +} -#define LOOKUP_TYPE struct servent -#define GETFUNC_NAME getservent -#define BUFLEN 1024 +struct servent * +getservent() +{ + char *p; + char *cp, **q; -#include "getXXent.c" +#ifdef YP + if (serv_stepping_yp && _getservent_yp(line)) { + p = (char *)&line; + goto unpack; + } +tryagain: +#endif + if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) + return (NULL); +again: + if ((p = fgets(line, BUFSIZ, servf)) == NULL) + return (NULL); +#ifdef YP + if (*p == '+' && _yp_check(NULL)) { + if (___getservbyname_yp != NULL) { + if (!_getservbyname_yp(line)) + goto tryagain; + } + else if (___getservbyport_yp != 0) { + if (!_getservbyport_yp(line)) + goto tryagain; + } + else if (!_getservent_yp(line)) + goto tryagain; + } +unpack: +#endif + if (*p == '#') + goto again; + cp = strpbrk(p, "#\n"); + if (cp == NULL) + goto again; + *cp = '\0'; + serv.s_name = p; + p = strpbrk(p, " \t"); + if (p == NULL) + goto again; + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + cp = strpbrk(p, ",/"); + if (cp == NULL) + goto again; + *cp++ = '\0'; + serv.s_port = htons((u_short)atoi(p)); + serv.s_proto = cp; + q = serv.s_aliases = serv_aliases; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &serv_aliases[MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + *q = NULL; + return (&serv); +} diff --git a/newlib/libc/sys/linux/net/getservent_r.c b/newlib/libc/sys/linux/net/getservent_r.c deleted file mode 100644 index 93708bdc2..000000000 --- a/newlib/libc/sys/linux/net/getservent_r.c +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 - - -#define LOOKUP_TYPE struct servent -#define SETFUNC_NAME setservent -#define GETFUNC_NAME getservent -#define ENDFUNC_NAME endservent -#define DATABASE_NAME services -#define STAYOPEN int stayopen -#define STAYOPEN_VAR stayopen - -#include "getXXent_r.c" diff --git a/newlib/libc/sys/linux/net/getsrvbynm.c b/newlib/libc/sys/linux/net/getsrvbynm.c deleted file mode 100644 index c3d2b2a21..000000000 --- a/newlib/libc/sys/linux/net/getsrvbynm.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct servent -#define FUNCTION_NAME getservbyname -#define DATABASE_NAME services -#define ADD_PARAMS const char *name, const char *proto -#define ADD_VARIABLES name, proto -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getsrvbynm_r.c b/newlib/libc/sys/linux/net/getsrvbynm_r.c deleted file mode 100644 index 3abf99774..000000000 --- a/newlib/libc/sys/linux/net/getsrvbynm_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct servent -#define FUNCTION_NAME getservbyname -#define DATABASE_NAME services -#define ADD_PARAMS const char *name, const char *proto -#define ADD_VARIABLES name, proto - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/getsrvbypt.c b/newlib/libc/sys/linux/net/getsrvbypt.c deleted file mode 100644 index f6b383d6b..000000000 --- a/newlib/libc/sys/linux/net/getsrvbypt.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct servent -#define FUNCTION_NAME getservbyport -#define DATABASE_NAME services -#define ADD_PARAMS int port, const char *proto -#define ADD_VARIABLES port, proto -#define BUFLEN 1024 - -#include "getXXbyYY.c" diff --git a/newlib/libc/sys/linux/net/getsrvbypt_r.c b/newlib/libc/sys/linux/net/getsrvbypt_r.c deleted file mode 100644 index 100a9b25e..000000000 --- a/newlib/libc/sys/linux/net/getsrvbypt_r.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 - - -#define LOOKUP_TYPE struct servent -#define FUNCTION_NAME getservbyport -#define DATABASE_NAME services -#define ADD_PARAMS int port, const char *proto -#define ADD_VARIABLES port, proto - -#include "getXXbyYY_r.c" diff --git a/newlib/libc/sys/linux/net/grp-lookup.c b/newlib/libc/sys/linux/net/grp-lookup.c deleted file mode 100644 index 9373045b5..000000000 --- a/newlib/libc/sys/linux/net/grp-lookup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME group -#define DEFAULT_CONFIG "compat [NOTFOUND=return] files" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/herrno.c b/newlib/libc/sys/linux/net/herrno.c deleted file mode 100644 index bb6d3f598..000000000 --- a/newlib/libc/sys/linux/net/herrno.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int *__h_errno_location() { - return &(_REENT->_new._reent._h_errno); -} - diff --git a/newlib/libc/sys/linux/net/herror.c b/newlib/libc/sys/linux/net/herror.c new file mode 100644 index 000000000..0edec9890 --- /dev/null +++ b/newlib/libc/sys/linux/net/herror.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Portions Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +const char *h_errlist[] = { + "Resolver Error 0 (no error)", + "Unknown host", /* 1 HOST_NOT_FOUND */ + "Host name lookup failure", /* 2 TRY_AGAIN */ + "Unknown server error", /* 3 NO_RECOVERY */ + "No address associated with name", /* 4 NO_ADDRESS */ +}; +int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; + +int h_errno; + +/* + * herror -- + * print the error indicated by the h_errno value. + */ +void +herror(s) + const char *s; +{ + char *ptr; + if (s && *s) { + write(STDERR_FILENO, s, strlen(s)); + write(STDERR_FILENO, ": ", 2); + } + ptr = (char *)hstrerror(h_errno); + write(STDERR_FILENO, ptr, strlen(ptr)); + write(STDERR_FILENO, "\n", 1); +} + +const char * +hstrerror(err) + int err; +{ + if (err < 0) + return ("Resolver internal error"); + else if (err < h_nerr) + return (h_errlist[err]); + return ("Unknown resolver error"); +} diff --git a/newlib/libc/sys/linux/net/hesiod.3 b/newlib/libc/sys/linux/net/hesiod.3 new file mode 100644 index 000000000..8de1f9247 --- /dev/null +++ b/newlib/libc/sys/linux/net/hesiod.3 @@ -0,0 +1,159 @@ +.\" $NetBSD: hesiod.3,v 1.1 1999/01/25 03:43:04 lukem Exp $ +.\" $FreeBSD: src/lib/libc/net/hesiod.3,v 1.3 2001/10/01 16:08:55 ru Exp $ +.\" +.\" from: #Id: hesiod.3,v 1.9.2.1 1997/01/03 21:02:23 ghudson Exp # +.\" +.\" Copyright 1988, 1996 by the Massachusetts Institute of Technology. +.\" +.\" Permission to use, copy, modify, and distribute this +.\" software and its documentation for any purpose and without +.\" fee is hereby granted, provided that the above copyright +.\" notice appear in all copies and that both that copyright +.\" notice and this permission notice appear in supporting +.\" documentation, and that the name of M.I.T. not be used in +.\" advertising or publicity pertaining to distribution of the +.\" software without specific, written prior permission. +.\" M.I.T. makes no representations about the suitability of +.\" this software for any purpose. It is provided "as is" +.\" without express or implied warranty. +.\" +.Dd November 30, 1996 +.Dt HESIOD 3 +.Os +.Sh NAME +.Nm hesiod , +.Nm hesiod_init , +.Nm hesiod_resolve , +.Nm hesiod_free_list , +.Nm hesiod_to_bind , +.Nm hesiod_end +.Nd Hesiod name server interface library +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In hesiod.h +.Ft int +.Fn hesiod_init "void **context" +.Ft char ** +.Fn hesiod_resolve "void *context" "const char *name" "const char *type" +.Ft void +.Fn hesiod_free_list "void *context" "char **list" +.Ft char * +.Fn hesiod_to_bind "void *context" "const char *name" "const char *type" +.Ft void +.Fn hesiod_end "void *context" +.Sh DESCRIPTION +This family of functions allows you to perform lookups of Hesiod +information, which is stored as text records in the Domain Name +Service. +To perform lookups, you must first initialize a +.Fa context , +an opaque object which stores information used internally by the +library between calls. +.Fn hesiod_init +initializes a context, storing a pointer to the context in the +location pointed to by the +.Fa context +argument. +.Fn hesiod_end +frees the resources used by a context. +.Pp +.Fn hesiod_resolve +is the primary interface to the library. +If successful, it returns a +list of one or more strings giving the records matching +.Fa name +and +.Fa type . +The last element of the list is followed by a +.Dv NULL +pointer. +It is the +caller's responsibility to call +.Fn hesiod_free_list +to free the resources used by the returned list. +.Pp +.Fn hesiod_to_bind +converts +.Fa name +and +.Fa type +into the DNS name used by +.Fn hesiod_resolve . +It is the caller's responsibility to free the returned string using +.Fn free . +.Sh RETURN VALUES +.Rv -std hesiod_init +On failure, +.Fn hesiod_resolve +and +.Fn hesiod_to_bind +return +.Dv NULL +and set the global variable +.Va errno +to indicate the error. +.Sh ENVIRONMENT +.Bl -tag -width HESIOD_CONFIG +.It Ev HES_DOMAIN +If the environment variable +.Ev HES_DOMAIN +is set, it will override the domain in the Hesiod configuration file. +.It Ev HESIOD_CONFIG +If the environment variable +.Ev HESIOD_CONFIG +is set, it specifies the location of the Hesiod configuration file. +.El +.Sh SEE ALSO +.Xr hesiod.conf 5 , +.Xr named 8 +.Rs +.%T "Hesiod - Project Athena Technical Plan -- Name Service" +.Re +.Sh ERRORS +Hesiod calls may fail because of: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory was available to carry out the requested +operation. +.It Bq Er ENOEXEC +.Fn hesiod_init +failed because the Hesiod configuration file was invalid. +.It Bq Er ECONNREFUSED +.Fn hesiod_resolve +failed because no name server could be contacted to answer the query. +.It Bq Er EMSGSIZE +.Fn hesiod_resolve +or +.Fn hesiod_to_bind +failed because the query or response was too big to fit into the +packet buffers. +.It Bq Er ENOENT +.Fn hesiod_resolve +failed because the name server had no text records matching +.Fa name +and +.Fa type , +or +.Fn hesiod_to_bind +failed because the +.Fa name +argument had a domain extension which could not be resolved with type +.Dq rhs\-extension +in the local Hesiod domain. +.El +.Sh AUTHORS +.An Steve Dyer , +IBM/Project Athena +.An Greg Hudson , +MIT Team Athena +.Pp +Copyright 1987, 1988, 1995, 1996 by the Massachusetts Institute of Technology. +.Sh BUGS +The strings corresponding to the +.Va errno +values set by the Hesiod functions are not particularly indicative of +what went wrong, especially for +.Er ENOEXEC +and +.Er ENOENT . diff --git a/newlib/libc/sys/linux/net/hesiod.c b/newlib/libc/sys/linux/net/hesiod.c new file mode 100644 index 000000000..909c09440 --- /dev/null +++ b/newlib/libc/sys/linux/net/hesiod.c @@ -0,0 +1,600 @@ +/* $NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb Exp $ */ + +/* Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* Copyright 1996 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +/* This file is part of the hesiod library. It implements the core + * portion of the hesiod resolver. + * + * This file is loosely based on an interim version of hesiod.c from + * the BIND IRS library, which was in turn based on an earlier version + * of this file. Extensive changes have been made on each step of the + * path. + * + * This implementation is not truly thread-safe at the moment because + * it uses res_send() and accesses _res. + */ + +#include + +#if 0 +static char *orig_rcsid = "$NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb Exp $"; +#endif +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +struct hesiod_p { + char *lhs; /* normally ".ns" */ + char *rhs; /* AKA the default hesiod domain */ + int classes[2]; /* The class search order. */ +}; + +#define MAX_HESRESP 1024 + +static int read_config_file(struct hesiod_p *, const char *); +static char **get_txt_records(int, const char *); +static int init_context(void); +static void translate_errors(void); + + +/* + * hesiod_init -- + * initialize a hesiod_p. + */ +int +hesiod_init(context) + void **context; +{ + struct hesiod_p *ctx; + const char *p, *configname; + + ctx = malloc(sizeof(struct hesiod_p)); + if (ctx) { + *context = ctx; + if (!issetugid()) + configname = getenv("HESIOD_CONFIG"); + else + configname = NULL; + if (!configname) + configname = _PATH_HESIOD_CONF; + if (read_config_file(ctx, configname) >= 0) { + /* + * The default rhs can be overridden by an + * environment variable. + */ + if (!issetugid()) + p = getenv("HES_DOMAIN"); + else + p = NULL; + if (p) { + if (ctx->rhs) + free(ctx->rhs); + ctx->rhs = malloc(strlen(p) + 2); + if (ctx->rhs) { + *ctx->rhs = '.'; + strcpy(ctx->rhs + 1, + (*p == '.') ? p + 1 : p); + return 0; + } else + errno = ENOMEM; + } else + return 0; + } + } else + errno = ENOMEM; + + if (ctx->lhs) + free(ctx->lhs); + if (ctx->rhs) + free(ctx->rhs); + if (ctx) + free(ctx); + return -1; +} + +/* + * hesiod_end -- + * Deallocates the hesiod_p. + */ +void +hesiod_end(context) + void *context; +{ + struct hesiod_p *ctx = (struct hesiod_p *) context; + + free(ctx->rhs); + if (ctx->lhs) + free(ctx->lhs); + free(ctx); +} + +/* + * hesiod_to_bind -- + * takes a hesiod (name, type) and returns a DNS + * name which is to be resolved. + */ +char * +hesiod_to_bind(void *context, const char *name, const char *type) +{ + struct hesiod_p *ctx = (struct hesiod_p *) context; + char bindname[MAXDNAME], *p, *ret, **rhs_list = NULL; + const char *rhs; + int len; + size_t bindnamelen; + + if (strlcpy(bindname, name, sizeof(bindname)) >= sizeof(bindname)) { + errno = EMSGSIZE; + return NULL; + } + + /* + * Find the right right hand side to use, possibly + * truncating bindname. + */ + p = strchr(bindname, '@'); + if (p) { + *p++ = 0; + if (strchr(p, '.')) + rhs = name + (p - bindname); + else { + rhs_list = hesiod_resolve(context, p, "rhs-extension"); + if (rhs_list) + rhs = *rhs_list; + else { + errno = ENOENT; + return NULL; + } + } + } else + rhs = ctx->rhs; + + /* See if we have enough room. */ + len = strlen(bindname) + 1 + strlen(type); + if (ctx->lhs) + len += strlen(ctx->lhs) + ((ctx->lhs[0] != '.') ? 1 : 0); + len += strlen(rhs) + ((rhs[0] != '.') ? 1 : 0); + if (len > sizeof(bindname) - 1) { + if (rhs_list) + hesiod_free_list(context, rhs_list); + errno = EMSGSIZE; + return NULL; + } + /* Put together the rest of the domain. */ + strcat(bindname, "."); + strcat(bindname, type); + /* Only append lhs if it isn't empty. */ + if (ctx->lhs && ctx->lhs[0] != '\0' ) { + if (ctx->lhs[0] != '.') + strcat(bindname, "."); + strcat(bindname, ctx->lhs); + } + if (rhs[0] != '.') + strcat(bindname, "."); + strcat(bindname, rhs); + + /* rhs_list is no longer needed, since we're done with rhs. */ + if (rhs_list) + hesiod_free_list(context, rhs_list); + + /* Make a copy of the result and return it to the caller. */ + bindnamelen = strlen (bindname) + 1; + ret = malloc (bindnamelen); + if (!ret) + errno = ENOMEM; + else + memcpy (ret, bindname, bindnamelen); + return ret; +} + +/* + * hesiod_resolve -- + * Given a hesiod name and type, return an array of strings returned + * by the resolver. + */ +char ** +hesiod_resolve(context, name, type) + void *context; + const char *name; + const char *type; +{ + struct hesiod_p *ctx = (struct hesiod_p *) context; + char *bindname, **retvec; + + bindname = hesiod_to_bind(context, name, type); + if (!bindname) + return NULL; + + retvec = get_txt_records(ctx->classes[0], bindname); + if (retvec == NULL && errno == ENOENT && ctx->classes[1]) + retvec = get_txt_records(ctx->classes[1], bindname); + + free(bindname); + return retvec; +} + +/*ARGSUSED*/ +void +hesiod_free_list(context, list) + void *context; + char **list; +{ + char **p; + + if (list == NULL) + return; + for (p = list; *p; p++) + free(*p); + free(list); +} + + +/* read_config_file -- + * Parse the /etc/hesiod.conf file. Returns 0 on success, + * -1 on failure. On failure, it might leave values in ctx->lhs + * or ctx->rhs which need to be freed by the caller. + */ +static int +read_config_file(ctx, filename) + struct hesiod_p *ctx; + const char *filename; +{ + char *key, *data, *p, **which; + char buf[MAXDNAME + 7]; + int n; + FILE *fp; + + /* Set default query classes. */ + ctx->classes[0] = C_IN; + ctx->classes[1] = C_HS; + + /* Try to open the configuration file. */ + fp = fopen(filename, "r"); + if (!fp) { + size_t len; + /* Use compiled in default domain names. */ + len = strlen (DEF_LHS) + 1; + ctx->lhs = malloc (len); + if (ctx->lhs) { + memcpy (ctx->lhs, DEF_LHS, len); + len = strlen (DEF_RHS) + 1; + ctx->rhs = malloc (len); + if (ctx->rhs) + memcpy (ctx->rhs, DEF_RHS, len); + } + if (ctx->lhs && ctx->rhs) + return 0; + else { + errno = ENOMEM; + return -1; + } + } + ctx->lhs = NULL; + ctx->rhs = NULL; + while (fgets(buf, sizeof(buf), fp) != NULL) { + p = buf; + if (*p == '#' || *p == '\n' || *p == '\r') + continue; + while (*p == ' ' || *p == '\t') + p++; + key = p; + while (*p != ' ' && *p != '\t' && *p != '=') + p++; + *p++ = 0; + + while (isspace(*p) || *p == '=') + p++; + data = p; + while (!isspace(*p)) + p++; + *p = 0; + + if (strcasecmp(key, "lhs") == 0 || + strcasecmp(key, "rhs") == 0) { + size_t len; + which = (strcasecmp(key, "lhs") == 0) + ? &ctx->lhs : &ctx->rhs; + len = strlen (data) + 1; + *which = malloc (len); + if (!*which) { + errno = ENOMEM; + return -1; + } + else + memcpy (*which, data, len); + } else { + if (strcasecmp(key, "classes") == 0) { + n = 0; + while (*data && n < 2) { + p = data; + while (*p && *p != ',') + p++; + if (*p) + *p++ = 0; + if (strcasecmp(data, "IN") == 0) + ctx->classes[n++] = C_IN; + else + if (strcasecmp(data, "HS") == 0) + ctx->classes[n++] = + C_HS; + data = p; + } + while (n < 2) + ctx->classes[n++] = 0; + } + } + } + fclose(fp); + + if (!ctx->rhs || ctx->classes[0] == 0 || + ctx->classes[0] == ctx->classes[1]) { + errno = ENOEXEC; + return -1; + } + return 0; +} + +/* + * get_txt_records -- + * Given a DNS class and a DNS name, do a lookup for TXT records, and + * return a list of them. + */ +static char ** +get_txt_records(qclass, name) + int qclass; + const char *name; +{ + HEADER *hp; + unsigned char qbuf[PACKETSZ], abuf[MAX_HESRESP], *p, *eom, *eor; + char *dst, **list; + int ancount, qdcount, i, j, n, skip, type, class, len; + + /* Make sure the resolver is initialized. */ + if ((_res.options & RES_INIT) == 0 && res_init() == -1) + return NULL; + + /* Construct the query. */ + n = res_mkquery(QUERY, name, qclass, T_TXT, NULL, 0, + NULL, qbuf, PACKETSZ); + if (n < 0) + return NULL; + + /* Send the query. */ + n = res_send(qbuf, n, abuf, MAX_HESRESP); + if (n < 0) { + errno = ECONNREFUSED; + return NULL; + } + /* Parse the header of the result. */ + hp = (HEADER *) (void *) abuf; + ancount = ntohs(hp->ancount); + qdcount = ntohs(hp->qdcount); + p = abuf + sizeof(HEADER); + eom = abuf + n; + + /* + * Skip questions, trying to get to the answer section + * which follows. + */ + for (i = 0; i < qdcount; i++) { + skip = dn_skipname(p, eom); + if (skip < 0 || p + skip + QFIXEDSZ > eom) { + errno = EMSGSIZE; + return NULL; + } + p += skip + QFIXEDSZ; + } + + /* Allocate space for the text record answers. */ + list = malloc((ancount + 1) * sizeof(char *)); + if (!list) { + errno = ENOMEM; + return NULL; + } + /* Parse the answers. */ + j = 0; + for (i = 0; i < ancount; i++) { + /* Parse the header of this answer. */ + skip = dn_skipname(p, eom); + if (skip < 0 || p + skip + 10 > eom) + break; + type = p[skip + 0] << 8 | p[skip + 1]; + class = p[skip + 2] << 8 | p[skip + 3]; + len = p[skip + 8] << 8 | p[skip + 9]; + p += skip + 10; + if (p + len > eom) { + errno = EMSGSIZE; + break; + } + /* Skip entries of the wrong class and type. */ + if (class != qclass || type != T_TXT) { + p += len; + continue; + } + /* Allocate space for this answer. */ + list[j] = malloc((size_t)len); + if (!list[j]) { + errno = ENOMEM; + break; + } + dst = list[j++]; + + /* Copy answer data into the allocated area. */ + eor = p + len; + while (p < eor) { + n = (unsigned char) *p++; + if (p + n > eor) { + errno = EMSGSIZE; + break; + } + memcpy(dst, p, (size_t)n); + p += n; + dst += n; + } + if (p < eor) { + errno = EMSGSIZE; + break; + } + *dst = 0; + } + + /* + * If we didn't terminate the loop normally, something + * went wrong. + */ + if (i < ancount) { + for (i = 0; i < j; i++) + free(list[i]); + free(list); + return NULL; + } + if (j == 0) { + errno = ENOENT; + free(list); + return NULL; + } + list[j] = NULL; + return list; +} + + /* + * COMPATIBILITY FUNCTIONS + */ + +static int inited = 0; +static void *context; +static int errval = HES_ER_UNINIT; + +int +hes_init() +{ + init_context(); + return errval; +} + +char * +hes_to_bind(name, type) + const char *name; + const char *type; +{ + static char *bindname; + if (init_context() < 0) + return NULL; + if (bindname) + free(bindname); + bindname = hesiod_to_bind(context, name, type); + if (!bindname) + translate_errors(); + return bindname; +} + +char ** +hes_resolve(name, type) + const char *name; + const char *type; +{ + static char **list; + + if (init_context() < 0) + return NULL; + + /* + * In the old Hesiod interface, the caller was responsible for + * freeing the returned strings but not the vector of strings itself. + */ + if (list) + free(list); + + list = hesiod_resolve(context, name, type); + if (!list) + translate_errors(); + return list; +} + +int +hes_error() +{ + return errval; +} + +void +hes_free(hp) + char **hp; +{ + hesiod_free_list(context, hp); +} + +static int +init_context() +{ + if (!inited) { + inited = 1; + if (hesiod_init(&context) < 0) { + errval = HES_ER_CONFIG; + return -1; + } + errval = HES_ER_OK; + } + return 0; +} + +static void +translate_errors() +{ + switch (errno) { + case ENOENT: + errval = HES_ER_NOTFOUND; + break; + case ECONNREFUSED: + case EMSGSIZE: + errval = HES_ER_NET; + break; + case ENOMEM: + default: + /* Not a good match, but the best we can do. */ + errval = HES_ER_CONFIG; + break; + } +} diff --git a/newlib/libc/sys/linux/net/hosts-lookup.c b/newlib/libc/sys/linux/net/hosts-lookup.c deleted file mode 100644 index 8dff71f7c..000000000 --- a/newlib/libc/sys/linux/net/hosts-lookup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME hosts -#define DEFAULT_CONFIG "dns [!UNAVAIL=return] files" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/if_indextoname.3 b/newlib/libc/sys/linux/net/if_indextoname.3 new file mode 100644 index 000000000..4b5bff5aa --- /dev/null +++ b/newlib/libc/sys/linux/net/if_indextoname.3 @@ -0,0 +1,142 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.7 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd May 21, 1998 +.Dt IF_NAMETOINDEX 3 +.Os +.Sh NAME +.Nm if_nametoindex , +.Nm if_indextoname , +.Nm if_nameindex , +.Nm if_freenameindex +.Nd convert interface index to name, and vice versa +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/if.h +.Ft "unsigned int" +.Fn if_nametoindex "const char *ifname" +.Ft "char *" +.Fn if_indextoname "unsigned int ifindex" "char *ifname" +.Ft "struct if_nameindex *" +.Fn if_nameindex "void" +.Ft "void" +.Fn if_freenameindex "struct if_nameindex *ptr" +.Sh DESCRIPTION +The functions map interface index to readable interface name +(such as +.Dq Li lo0 ) , +and vice versa. +.Pp +.Fn if_nametoindex +converts readable interface name to interface index +.Pp positive integer value . +If the specified interface does not exist, 0 will be returned. +.Pp +.Fn if_indextoname +converts interface index to readable interface name. +The +.Fa ifname +argument must point to a buffer of at least +.Dv IF_NAMESIZE +bytes into which the interface name corresponding to the specified index is +returned. +.Dv ( IF_NAMESIZE +is also defined in +.Aq Pa net/if.h +and its value includes a terminating null byte at the end of the +interface name.) +This pointer is also the return value of the function. +If there is no interface corresponding to the specified index, +.Dv NULL +is returned. +.Pp +.Fn if_nameindex +returns an array of +.Fa if_nameindex +structures. +.Fa if_nametoindex +is also defined in +.Aq Pa net/if.h , +and is as follows: +.Bd -literal -offset +struct if_nameindex { + unsigned int if_index; /* 1, 2, ... */ + char *if_name; /* null terminated name: "le0", ... */ +}; +.Ed +.Pp +The end of the array of structures is indicated by a structure with +an +.Fa if_index +of 0 and an +.Fa if_name +of +.Dv NULL . +The function returns a +.Dv NULL +pointer upon an error. +The memory used for this array of structures along with the interface +names pointed to by the +.Fa if_name +members is obtained dynamically. +This memory is freed by the +.Fn if_freenameindex +function. +.Pp +.Fn if_freenameindex +takes a pointer that was returned by +.Fn if_nameindex +as argument +.Pq Fa ptr , +and it reclaims the region allocated. +.Sh DIAGNOSTICS +.Fn if_nametoindex +returns 0 on error, positive integer on success. +.Fn if_indextoname +and +.Fn if_nameindex +return +.Dv NULL +on errors. +.Sh SEE ALSO +R. Gilligan, S. Thomson, J. Bound, and W. Stevens, +``Basic Socket Interface Extensions for IPv6,'' RFC2553, March 1999. +.Sh HISTORY +The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. +.Sh STANDARDS +These functions are defined in ``Basic Socket Interface Extensions for IPv6'' +(RFC2533). diff --git a/newlib/libc/sys/linux/net/ifaddrs.h b/newlib/libc/sys/linux/net/ifaddrs.h deleted file mode 100644 index ba6a1554b..000000000 --- a/newlib/libc/sys/linux/net/ifaddrs.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ifaddrs.h -- declarations for getting network interface addresses - Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _IFADDRS_H -#define _IFADDRS_H 1 - -#include -#include - -__BEGIN_DECLS - -/* The `getifaddrs' function generates a linked list of these structures. - Each element of the list describes one network interface. */ -struct ifaddrs -{ - struct ifaddrs *ifa_next; /* Pointer to the next structure. */ - - char *ifa_name; /* Name of this network interface. */ - unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */ - - struct sockaddr *ifa_addr; /* Network address of this interface. */ - struct sockaddr *ifa_netmask; /* Netmask of this interface. */ - union - { - /* At most one of the following two is valid. If the IFF_BROADCAST - bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the - IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid. - It is never the case that both these bits are set at once. */ - struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ - struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ - } ifa_ifu; - /* These very same macros are defined by for `struct ifaddr'. - So if they are defined already, the existing definitions will be fine. */ -# ifndef ifa_broadaddr -# define ifa_broadaddr ifa_ifu.ifu_broadaddr -# endif -# ifndef ifa_dstaddr -# define ifa_dstaddr ifa_ifu.ifu_dstaddr -# endif - - void *ifa_data; /* Address-specific data (may be unused). */ -}; - - -/* Create a linked list of `struct ifaddrs' structures, one for each - network interface on the host machine. If successful, store the - list in *IFAP and return 0. On errors, return -1 and set `errno'. - - The storage returned in *IFAP is allocated dynamically and can - only be properly freed by passing it to `freeifaddrs'. */ -extern int getifaddrs (struct ifaddrs **__ifap) __THROW; - -/* Reclaim the storage allocated by a previous `getifaddrs' call. */ -extern void freeifaddrs (struct ifaddrs *__ifa) __THROW; - -__END_DECLS - -#endif /* ifaddrs.h */ diff --git a/newlib/libc/sys/linux/net/ifreq.c b/newlib/libc/sys/linux/net/ifreq.c deleted file mode 100644 index 9d6a6121b..000000000 --- a/newlib/libc/sys/linux/net/ifreq.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Andreas Jaeger . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include "ifreq.h" - -/* Variable to signal whether SIOCGIFCONF is not available. */ -#if __ASSUME_SIOCGIFNAME == 0 || 1 -static int old_siocgifconf; -#else -# define old_siocgifconf 0 -#endif - - -void -__ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd) -{ - int fd = sockfd; - struct ifconf ifc; - int rq_len; - int nifs; -# define RQ_IFS 4 - - if (fd < 0) - fd = __opensock (); - if (fd < 0) - { - *num_ifs = 0; - *ifreqs = NULL; - return; - } - - ifc.ifc_buf = NULL; - - /* We may be able to get the needed buffer size directly, rather than - guessing. */ - if (! old_siocgifconf) - { - ifc.ifc_buf = NULL; - ifc.ifc_len = 0; - if (ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0) - { -# if __ASSUME_SIOCGIFNAME == 0 - old_siocgifconf = 1; -# endif - rq_len = RQ_IFS * sizeof (struct ifreq); - } - else - rq_len = ifc.ifc_len; - } - else - rq_len = RQ_IFS * sizeof (struct ifreq); - - /* Read all the interfaces out of the kernel. */ - while (1) - { - ifc.ifc_len = rq_len; - void *newp = realloc (ifc.ifc_buf, ifc.ifc_len); - if (newp == NULL - || (ifc.ifc_buf = newp, ioctl (fd, SIOCGIFCONF, &ifc)) < 0) - { - free (ifc.ifc_buf); - - if (fd != sockfd) - close (fd); - - *num_ifs = 0; - *ifreqs = NULL; - return; - } - - if (!old_siocgifconf || ifc.ifc_len < rq_len) - break; - - rq_len *= 2; - } - - nifs = ifc.ifc_len / sizeof (struct ifreq); - - if (fd != sockfd) - close (fd); - - *num_ifs = nifs; - *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq)); -} diff --git a/newlib/libc/sys/linux/net/ifreq.h b/newlib/libc/sys/linux/net/ifreq.h deleted file mode 100644 index ba55a39eb..000000000 --- a/newlib/libc/sys/linux/net/ifreq.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Andreas Jaeger . - - 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 -#include -#include -#include -#include -#include - - -extern void __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd); - -static inline struct ifreq * -__if_nextreq (struct ifreq *ifr) -{ - return ifr + 1; -} - -static inline void -__if_freereq (struct ifreq *ifreqs, int num_ifs) -{ - free (ifreqs); -} diff --git a/newlib/libc/sys/linux/net/in6_addr.c b/newlib/libc/sys/linux/net/in6_addr.c deleted file mode 100644 index a75b64ebc..000000000 --- a/newlib/libc/sys/linux/net/in6_addr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 1997, 1998, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Philip Blundell , 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 -#include "libc-symbols.h" - -const struct in6_addr in6addr_any = -{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; -libc_hidden_data_def (in6addr_any) -const struct in6_addr in6addr_loopback = -{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }; -libc_hidden_data_def (in6addr_loopback) diff --git a/newlib/libc/sys/linux/net/inet.3 b/newlib/libc/sys/linux/net/inet.3 new file mode 100644 index 000000000..7a6fcf370 --- /dev/null +++ b/newlib/libc/sys/linux/net/inet.3 @@ -0,0 +1,271 @@ +.\" Copyright (c) 1983, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.22 2001/12/01 03:43:01 mike Exp $ +.\" +.Dd June 17, 1996 +.Dt INET 3 +.Os +.Sh NAME +.Nm inet_aton , +.Nm inet_addr , +.Nm inet_network , +.Nm inet_ntoa , +.Nm inet_ntop , +.Nm inet_pton , +.Nm inet_makeaddr , +.Nm inet_lnaof , +.Nm inet_netof +.Nd Internet address manipulation routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netinet/in.h +.In arpa/inet.h +.Ft int +.Fn inet_aton "const char *cp" "struct in_addr *pin" +.Ft in_addr_t +.Fn inet_addr "const char *cp" +.Ft in_addr_t +.Fn inet_network "const char *cp" +.Ft char * +.Fn inet_ntoa "struct in_addr in" +.Ft const char * +.Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size" +.Ft int +.Fn inet_pton "int af" "const char *src" "void *dst" +.Ft struct in_addr +.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" +.Ft in_addr_t +.Fn inet_lnaof "struct in_addr in" +.Ft in_addr_t +.Fn inet_netof "struct in_addr in" +.Sh DESCRIPTION +The routines +.Fn inet_aton , +.Fn inet_addr +and +.Fn inet_network +interpret character strings representing +numbers expressed in the Internet standard +.Ql .\& +notation. +.Pp +The +.Fn inet_pton +function converts a presentation format address (that is, printable form +as held in a character string) to network format (usually a +.Ft struct in_addr +or some other internal binary representation, in network byte order). +It returns 1 if the address was valid for the specified address family, or +0 if the address wasn't parseable in the specified address family, or -1 +if some system error occurred (in which case +.Va errno +will have been set). +This function is presently valid for +.Dv AF_INET +and +.Dv AF_INET6 . +.Pp +The +.Fn inet_aton +routine interprets the specified character string as an Internet address, +placing the address into the structure provided. +It returns 1 if the string was successfully interpreted, +or 0 if the string is invalid. +The +.Fn inet_addr +and +.Fn inet_network +functions return numbers suitable for use +as Internet addresses and Internet network +numbers, respectively. +.Pp +The function +.Fn inet_ntop +converts an address from network format (usually a +.Ft struct in_addr +or some other binary form, in network byte order) to presentation format +(suitable for external display purposes). +It returns NULL if a system error occurs (in which case, +.Va errno +will have been set), or it returns a pointer to the destination string. +This function is presently valid for +.Dv AF_INET +and +.Dv AF_INET6 . +.Pp +The routine +.Fn inet_ntoa +takes an Internet address and returns an +.Tn ASCII +string representing the address in +.Ql .\& +notation. The routine +.Fn inet_makeaddr +takes an Internet network number and a local +network address and constructs an Internet address +from it. The routines +.Fn inet_netof +and +.Fn inet_lnaof +break apart Internet host addresses, returning +the network number and local network address part, +respectively. +.Pp +All Internet addresses are returned in network +order (bytes ordered from left to right). +All network numbers and local address parts are +returned as machine byte order integer values. +.Sh INTERNET ADDRESSES +Values specified using the +.Ql .\& +notation take one +of the following forms: +.Bd -literal -offset indent +a.b.c.d +a.b.c +a.b +a +.Ed +.Pp +When four parts are specified, each is interpreted +as a byte of data and assigned, from left to right, +to the four bytes of an Internet address. Note +that when an Internet address is viewed as a 32-bit +integer quantity on the +.Tn VAX +the bytes referred to +above appear as +.Dq Li d.c.b.a . +That is, +.Tn VAX +bytes are +ordered from right to left. +.Pp +When a three part address is specified, the last +part is interpreted as a 16-bit quantity and placed +in the right-most two bytes of the network address. +This makes the three part address format convenient +for specifying Class B network addresses as +.Dq Li 128.net.host . +.Pp +When a two part address is supplied, the last part +is interpreted as a 24-bit quantity and placed in +the right most three bytes of the network address. +This makes the two part address format convenient +for specifying Class A network addresses as +.Dq Li net.host . +.Pp +When only one part is given, the value is stored +directly in the network address without any byte +rearrangement. +.Pp +All numbers supplied as +.Dq parts +in a +.Ql .\& +notation +may be decimal, octal, or hexadecimal, as specified +in the C language (i.e., a leading 0x or 0X implies +hexadecimal; otherwise, a leading 0 implies octal; +otherwise, the number is interpreted as decimal). +.Pp +The +.Fn inet_aton +and +.Fn inet_ntoa +functions are semi-deprecated in favor of the +.Xr addr2ascii 3 +family. However, since those functions are not yet widely implemented, +portable programs cannot rely on their presence and will continue +to use the +.Xr inet 3 +functions for some time. +.Sh DIAGNOSTICS +The constant +.Dv INADDR_NONE +is returned by +.Fn inet_addr +and +.Fn inet_network +for malformed requests. +.Sh SEE ALSO +.Xr addr2ascii 3 , +.Xr byteorder 3 , +.Xr gethostbyname 3 , +.Xr getnetent 3 , +.Xr inet_net 3 , +.Xr hosts 5 , +.Xr networks 5 +.Rs +.%R RFC +.%N 2373 +.%D July 1998 +.%T "IP Version 6 Addressing Architecture" +.Re +.Sh STANDARDS +The +.Fn inet_ntop +and +.Fn inet_pton +functions conform to +.St -xns5.2 . +Note that +.Fn inet_pton +does not accept 1-, 2-, or 3-part dotted addresses; all four parts +must be specified and are interpreted only as decimal values. +This is a narrower input set than that accepted by +.Fn inet_aton . +.Sh HISTORY +These +functions appeared in +.Bx 4.2 . +.Sh BUGS +The value +.Dv INADDR_NONE +(0xffffffff) is a valid broadcast address, but +.Fn inet_addr +cannot return that value without indicating failure. +The newer +.Fn inet_aton +function does not share this problem. +The problem of host byte ordering versus network byte ordering is +confusing. +The string returned by +.Fn inet_ntoa +resides in a static memory area. +.Pp +Inet_addr should return a +.Fa struct in_addr . diff --git a/newlib/libc/sys/linux/net/inet6_option.c b/newlib/libc/sys/linux/net/inet6_option.c deleted file mode 100644 index 182cfe942..000000000 --- a/newlib/libc/sys/linux/net/inet6_option.c +++ /dev/null @@ -1,346 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include "libc-symbols.h" - -#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) - -static void -internal_function -add_pad (struct cmsghdr *cmsg, int len) -{ - unsigned char *p = CMSG_DATA (cmsg) + cmsg->cmsg_len - CMSG_LEN (0); - - if (len == 1) - /* Special handling for 1, a one-byte solution. */ - *p++ = IP6OPT_PAD1; - else if (len != 0) - { - /* Multibyte padding. */ - *p++ = IP6OPT_PADN; - *p++ = len - 2; /* Discount the two header bytes. */ - /* The rest is filled with zero. */ - memset (p, '\0', len - 2); - p += len - 2; - } - - /* Account for the bytes. */ - cmsg->cmsg_len += len; -} - - -static int -get_opt_end (const uint8_t **result, const uint8_t *startp, - const uint8_t *endp) -{ - if (startp >= endp) - /* Out of bounds. */ - return -1; - - if (*startp == IP6OPT_PAD1) - { - /* Just this one byte. */ - *result = startp + 1; - return 0; - } - - /* Now we know there must be at least two bytes. */ - if (startp + 2 > endp - /* Now we can get the length byte. */ - || startp + startp[1] + 2 > endp) - return -1; - - *result = startp + startp[1] + 2; - - return 0; -} - - -/* RFC 2292, 6.3.1 - - This function returns the number of bytes required to hold an option - when it is stored as ancillary data, including the cmsghdr structure - at the beginning, and any padding at the end (to make its size a - multiple of 8 bytes). The argument is the size of the structure - defining the option, which must include any pad bytes at the - beginning (the value y in the alignment term "xn + y"), the type - byte, the length byte, and the option data. */ -int -inet6_option_space (nbytes) - int nbytes; -{ - /* Add room for the extension header. */ - nbytes += sizeof (struct ip6_ext); - - return CMSG_SPACE (roundup (nbytes, 8)); -} - - -/* RFC 2292, 6.3.2 - - This function is called once per ancillary data object that will - contain either Hop-by-Hop or Destination options. It returns 0 on - success or -1 on an error. */ -int -inet6_option_init (bp, cmsgp, type) - void *bp; - struct cmsghdr **cmsgp; - int type; -{ - /* Only Hop-by-Hop or Destination options allowed. */ - if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) - return -1; - - /* BP is a pointer to the previously allocated space. */ - struct cmsghdr *newp = (struct cmsghdr *) bp; - - /* Initialize the message header. - - Length: No data yet, only the cmsghdr struct. */ - newp->cmsg_len = CMSG_LEN (0); - /* Originating protocol: obviously IPv6. */ - newp->cmsg_level = IPPROTO_IPV6; - /* Message type. */ - newp->cmsg_type = type; - - /* Pass up the result. */ - *cmsgp = newp; - - return 0; -} - - -/* RFC 2292, 6.3.3 - - This function appends a Hop-by-Hop option or a Destination option - into an ancillary data object that has been initialized by - inet6_option_init(). This function returns 0 if it succeeds or -1 on - an error. */ -int -inet6_option_append (cmsg, typep, multx, plusy) - struct cmsghdr *cmsg; - const uint8_t *typep; - int multx; - int plusy; -{ - /* typep is a pointer to the 8-bit option type. It is assumed that this - field is immediately followed by the 8-bit option data length field, - which is then followed immediately by the option data. - - The option types IP6OPT_PAD1 and IP6OPT_PADN also must be handled. */ - int len = typep[0] == IP6OPT_PAD1 ? 1 : typep[1] + 2; - - /* Get the pointer to the space in the message. */ - uint8_t *ptr = inet6_option_alloc (cmsg, len, multx, plusy); - if (ptr == NULL) - /* Some problem with the parameters. */ - return -1; - - /* Copy the content. */ - memcpy (ptr, typep, len); - - return 0; -} - - -/* RFC 2292, 6.3.4 - - This function appends a Hop-by-Hop option or a Destination option - into an ancillary data object that has been initialized by - inet6_option_init(). This function returns a pointer to the 8-bit - option type field that starts the option on success, or NULL on an - error. */ -uint8_t * -inet6_option_alloc (cmsg, datalen, multx, plusy) - struct cmsghdr *cmsg; - int datalen; - int multx; - int plusy; -{ - /* The RFC limits the value of the alignment values. */ - if ((multx != 1 && multx != 2 && multx != 4 && multx != 8) - || ! (plusy >= 0 && plusy <= 7)) - return NULL; - - /* Current data size. */ - int dsize = cmsg->cmsg_len - CMSG_LEN (0); - - /* The first two bytes of the option are for the extended header. */ - if (__builtin_expect (dsize == 0, 0)) - { - cmsg->cmsg_len += sizeof (struct ip6_ext); - dsize = sizeof (struct ip6_ext); - } - - /* First add padding. */ - add_pad (cmsg, ((multx - (dsize & (multx - 1))) & (multx - 1)) + plusy); - - /* Return the pointer to the start of the option space. */ - uint8_t *result = CMSG_DATA (cmsg) + cmsg->cmsg_len - CMSG_LEN (0); - cmsg->cmsg_len += datalen; - - /* The extended option header length is measured in 8-byte groups. - To represent the current length we might have to add padding. */ - dsize = cmsg->cmsg_len - CMSG_LEN (0); - add_pad (cmsg, (8 - (dsize & (8 - 1))) & (8 - 1)); - - /* Record the new length of the option. */ - assert (((cmsg->cmsg_len - CMSG_LEN (0)) % 8) == 0); - int len8b = (cmsg->cmsg_len - CMSG_LEN (0)) / 8 - 1; - if (len8b >= 256) - /* Too long. */ - return NULL; - - ((struct ip6_ext *) CMSG_DATA (cmsg))->ip6e_len = len8b; - - return result; -} -libc_hidden_def (inet6_option_alloc) - - -/* RFC 2292, 6.3.5 - - This function processes the next Hop-by-Hop option or Destination - option in an ancillary data object. If another option remains to be - processed, the return value of the function is 0 and *tptrp points to - the 8-bit option type field (which is followed by the 8-bit option - data length, followed by the option data). If no more options remain - to be processed, the return value is -1 and *tptrp is NULL. If an - error occurs, the return value is -1 and *tptrp is not NULL. */ -int -inet6_option_next (cmsg, tptrp) - const struct cmsghdr *cmsg; - uint8_t **tptrp; -{ - /* Make sure it is an option of the right type. */ - if (cmsg->cmsg_level != IPPROTO_IPV6 - || (cmsg->cmsg_type != IPV6_HOPOPTS && cmsg->cmsg_type != IPV6_DSTOPTS)) - return -1; - - /* Pointer to the extension header. We only compute the address, we - don't access anything yet. */ - const struct ip6_ext *ip6e = (const struct ip6_ext *) CMSG_DATA (cmsg); - - /* Make sure the message is long enough. */ - if (cmsg->cmsg_len < CMSG_LEN (sizeof (struct ip6_ext)) - /* Now we can access the extension header. */ - || cmsg->cmsg_len < CMSG_LEN ((ip6e->ip6e_len + 1) * 8)) - /* Too small. */ - return -1; - - /* Determine the address of the byte past the message. */ - const uint8_t *endp = CMSG_DATA (cmsg) + (ip6e->ip6e_len + 1) * 8; - - const uint8_t *result; - if (tptrp == NULL) - /* This is the first call, return the first option if there is one. */ - result = (const uint8_t *) (ip6e + 1); - else - { - /* Make sure *TPTRP points to a beginning of a new option in - the message. The upper limit is checked in get_opt_end. */ - if (*tptrp < (const uint8_t *) (ip6e + 1)) - return -1; - - /* Get the beginning of the next option. */ - if (get_opt_end (&result, *tptrp, endp) != 0) - return -1; - } - - /* We know where the next option starts. */ - *tptrp = (uint8_t *) result; - - /* Check the option is fully represented in the message. */ - return get_opt_end (&result, result, endp); -} - - -/* RFC 2292, 6.3.6 - - This function is similar to the previously described - inet6_option_next() function, except this function lets the caller - specify the option type to be searched for, instead of always - returning the next option in the ancillary data object. cmsg is a - pointer to cmsghdr structure of which cmsg_level equals IPPROTO_IPV6 - and cmsg_type equals either IPV6_HOPOPTS or IPV6_DSTOPTS. */ -int -inet6_option_find (cmsg, tptrp, type) - const struct cmsghdr *cmsg; - uint8_t **tptrp; - int type; -{ - /* Make sure it is an option of the right type. */ - if (cmsg->cmsg_level != IPPROTO_IPV6 - || (cmsg->cmsg_type != IPV6_HOPOPTS && cmsg->cmsg_type != IPV6_DSTOPTS)) - return -1; - - /* Pointer to the extension header. We only compute the address, we - don't access anything yet. */ - const struct ip6_ext *ip6e = (const struct ip6_ext *) CMSG_DATA (cmsg); - - /* Make sure the message is long enough. */ - if (cmsg->cmsg_len < CMSG_LEN (sizeof (struct ip6_ext)) - /* Now we can access the extension header. */ - || cmsg->cmsg_len < CMSG_LEN ((ip6e->ip6e_len + 1) * 8)) - /* Too small. */ - return -1; - - /* Determine the address of the byte past the message. */ - const uint8_t *endp = CMSG_DATA (cmsg) + (ip6e->ip6e_len + 1) * 8; - - const uint8_t *next; - if (tptrp == NULL) - /* This is the first call, return the first option if there is one. */ - next = (const uint8_t *) (ip6e + 1); - else - { - /* Make sure *TPTRP points to a beginning of a new option in - the message. The upper limit is checked in get_opt_end. */ - if (*tptrp < (const uint8_t *) (ip6e + 1)) - return -1; - - /* Get the beginning of the next option. */ - if (get_opt_end (&next, *tptrp, endp) != 0) - return -1; - } - - /* Now search for the appropriate typed entry. */ - const uint8_t *result; - do - { - result = next; - - /* Get the end of this entry. */ - if (get_opt_end (&next, result, endp) != 0) - return -1; - } - while (*result != type); - - /* We know where the next option starts. */ - *tptrp = (uint8_t *) result; - - /* Success. */ - return 0; -} diff --git a/newlib/libc/sys/linux/net/inet6_option_space.3 b/newlib/libc/sys/linux/net/inet6_option_space.3 new file mode 100644 index 000000000..328c70f48 --- /dev/null +++ b/newlib/libc/sys/linux/net/inet6_option_space.3 @@ -0,0 +1,445 @@ +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $Id$ +.\" $FreeBSD: src/lib/libc/net/inet6_option_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd December 10, 1999 +.Dt INET6_OPTION_SPACE 3 +.Os +.\" +.Sh NAME +.Nm inet6_option_space , +.Nm inet6_option_init , +.Nm inet6_option_append , +.Nm inet6_option_alloc , +.Nm inet6_option_next , +.Nm inet6_option_find +.Nd IPv6 Hop-by-Hop and Destination Options manipulation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.Ft "int" +.Fn inet6_option_space "int nbytes" +.Ft "int" +.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" +.Ft "int" +.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" +.Ft "u_int8_t *" +.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" +.Ft "int" +.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" +.Ft "int" +.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" +.\" +.Sh DESCRIPTION +.\" +Building and parsing the Hop-by-Hop and Destination options is +complicated due to alignment constranints, padding and +ancillary data manipulation. +RFC2292 defines a set of functions to help the application. +The function prototypes for +these functions are all in the +.Aq Li netinet/in.h +header. +.\" +.Ss inet6_option_space +.Fn inet6_option_space +returns the number of bytes required to hold an option when it is stored as +ancillary data, including the +.Li cmsghdr +structure at the beginning, +and any padding at the end +(to make its size a multiple of 8 bytes). +The argument is the size of the structure defining the option, +which must include any pad bytes at the beginning +(the value +.Li y +in the alignment term +.Dq Li "xn + y" ) , +the type byte, the length byte, and the option data. +.Pp +Note: If multiple options are stored in a single ancillary data +object, which is the recommended technique, this function +overestimates the amount of space required by the size of +.Li N-1 +.Li cmsghdr +structures, +where +.Li N +is the number of options to be stored in the object. +This is of little consequence, since it is assumed that most +Hop-by-Hop option headers and Destination option headers carry only +one option +(appendix B of [RFC-2460]). +.\" +.Ss inet6_option_init +.Fn inet6_option_init +is called once per ancillary data object that will +contain either Hop-by-Hop or Destination options. +It returns +.Li 0 +on success or +.Li -1 +on an error. +.Pp +.Fa bp +is a pointer to previously allocated space that will contain the +ancillary data object. +It must be large enough to contain all the +individual options to be added by later calls to +.Fn inet6_option_append +and +.Fn inet6_option_alloc . +.Pp +.Fa cmsgp +is a pointer to a pointer to a +.Li cmsghdr +structure. +.Fa *cmsgp +is initialized by this function to point to the +.Li cmsghdr +structure constructed by this function in the buffer pointed to by +.Fa bp . +.Pp +.Fa type +is either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +This +.Fa type +is stored in the +.Li cmsg_type +member of the +.Li cmsghdr +structure pointed to by +.Fa *cmsgp . +.\" +.Ss inet6_option_append +This function appends a Hop-by-Hop option or a Destination option +into an ancillary data object that has been initialized by +.Fn inet6_option_init . +This function returns +.Li 0 +if it succeeds or +.Li -1 +on an error. +.Pp +.Fa cmsg +is a pointer to the +.Li cmsghdr +structure that must have been +initialized by +.Fn inet6_option_init . +.Pp +.Fa typep +is a pointer to the 8-bit option type. +It is assumed that this +field is immediately followed by the 8-bit option data length field, +which is then followed immediately by the option data. +The caller +initializes these three fields +(the type-length-value, or TLV) +before calling this function. +.Pp +The option type must have a value from +.Li 2 +to +.Li 255 , +inclusive. +.Li ( 0 +and +.Li 1 +are reserved for the +.Li Pad1 +and +.Li PadN +options, respectively.) +.Pp +The option data length must have a value between +.Li 0 +and +.Li 255 , +inclusive, and is the length of the option data that follows. +.Pp +.Fa multx +is the value +.Li x +in the alignment term +.Dq Li xn + y . +It must have a value of +.Li 1 , +.Li 2 , +.Li 4 , +or +.Li 8 . +.Pp +.Fa plusy +is the value +.Li y +in the alignment term +.Dq Li xn + y . +It must have a value between +.Li 0 +and +.Li 7 , +inclusive. +.\" +.Ss inet6_option_alloc +This function appends a Hop-by-Hop option or a Destination option +into an ancillary data object that has been initialized by +.Fn inet6_option_init . +This function returns a pointer to the 8-bit +option type field that starts the option on success, or +.Dv NULL +on an error. +.Pp +The difference between this function and +.Fn inet6_option_append +is that the latter copies the contents of a previously built option into +the ancillary data object while the current function returns a +pointer to the space in the data object where the option's TLV must +then be built by the caller. +.Pp +.Fa cmsg +is a pointer to the +.Li cmsghdr +structure that must have been +initialized by +.Fn inet6_option_init . +.Pp +.Fa datalen +is the value of the option data length byte for this option. +This value is required as an argument to allow the function to +determine if padding must be appended at the end of the option. +(The +.Fn inet6_option_append +function does not need a data length argument +since the option data length must already be stored by the caller.) +.Pp +.Fa multx +is the value +.Li x +in the alignment term +.Dq Li xn + y . +It must have a value of +.Li 1 , +.Li 2 , +.Li 4 , +or +.Li 8 . +.Pp +.Fa plusy +is the value +.Li y +in the alignment term +.Dq Li xn + y . +It must have a value between +.Li 0 +and +.Li 7 , +inclusive. +.\" +.Ss inet6_option_next +This function processes the next Hop-by-Hop option or Destination +option in an ancillary data object. +If another option remains to be +processed, the return value of the function is +.Li 0 +and +.Fa *tptrp +points to +the 8-bit option type field +(which is followed by the 8-bit option +data length, followed by the option data). +If no more options remain +to be processed, the return value is +.Li -1 +and +.Fa *tptrp +is +.Dv NULL . +If an error occurs, the return value is +.Li -1 +and +.Fa *tptrp +is not +.Dv NULL . +.Pp +.Fa cmsg +is a pointer to +.Li cmsghdr +structure of which +.Li cmsg_level +equals +.Dv IPPROTO_IPV6 +and +.Li cmsg_type +equals either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +.Pp +.Fa tptrp +is a pointer to a pointer to an 8-bit byte and +.Fa *tptrp +is used +by the function to remember its place in the ancillary data object +each time the function is called. +The first time this function is +called for a given ancillary data object, +.Fa *tptrp +must be set to +.Dv NULL . +.Pp +Each time this function returns success, +.Fa *tptrp +points to the 8-bit +option type field for the next option to be processed. +.\" +.Ss inet6_option_find +This function is similar to the previously described +.Fn inet6_option_next +function, except this function lets the caller +specify the option type to be searched for, instead of always +returning the next option in the ancillary data object. +.Fa cmsg +is a +pointer to +.Li cmsghdr +structure of which +.Li cmsg_level +equals +.Dv IPPROTO_IPV6 +and +.Li cmsg_type +equals either +.Dv IPV6_HOPOPTS +or +.Dv IPV6_DSTOPTS . +.Pp +.Fa tptrp +is a pointer to a pointer to an 8-bit byte and +.Fa *tptrp +is used +by the function to remember its place in the ancillary data object +each time the function is called. +The first time this function is +called for a given ancillary data object, +.Fa *tptrp +must be set to +.Dv NULL . +.Pa +This function starts searching for an option of the specified type +beginning after the value of +.Fa *tptrp . +If an option of the specified +type is located, this function returns +.Li 0 +and +.Fa *tptrp +points to the 8- +bit option type field for the option of the specified type. +If an +option of the specified type is not located, the return value is +.Li -1 +and +.Fa *tptrp +is +.Dv NULL . +If an error occurs, the return value is +.Li -1 +and +.Fa *tptrp +is not +.Dv NULL . +.\" +.Sh DIAGNOSTICS +.Fn inet6_option_init +and +.Fn inet6_option_append +return +.Li 0 +on success or +.Li -1 +on an error. +.Pp +.Fn inet6_option_alloc +returns +.Dv NULL +on an error. +.Pp +On errors, +.Fn inet6_option_next +and +.Fn inet6_option_find +return +.Li -1 +setting +.Fa *tptrp +to non +.Dv NULL +value. +.\" +.Sh EXAMPLES +RFC2292 gives comprehensive examples in chapter 6. +.\" +.Sh SEE ALSO +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Sockets API for IPv6" +.%N RFC2292 +.%D February 1998 +.Re +.Rs +.%A S. Deering +.%A R. Hinden +.%T "Internet Protocol, Version 6 (IPv6) Specification" +.%N RFC2460 +.%D December 1998 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +The functions +are documented in +.Dq Advanced Sockets API for IPv6 +(RFC2292). +.\" +.Sh BUGS +The text was shamelessly copied from RFC2292. diff --git a/newlib/libc/sys/linux/net/inet6_rthdr_space.3 b/newlib/libc/sys/linux/net/inet6_rthdr_space.3 new file mode 100644 index 000000000..d2c575dca --- /dev/null +++ b/newlib/libc/sys/linux/net/inet6_rthdr_space.3 @@ -0,0 +1,323 @@ +.\" Copyright (c) 1983, 1987, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $Id$ +.\" $FreeBSD: src/lib/libc/net/inet6_rthdr_space.3,v 1.8 2001/10/01 16:08:55 ru Exp $ +.\" +.Dd December 10, 1999 +.Dt INET6_RTHDR_SPACE 3 +.Os +.\" +.Sh NAME +.Nm inet6_rthdr_space , +.Nm inet6_rthdr_init , +.Nm inet6_rthdr_add , +.Nm inet6_rthdr_lasthop , +.Nm inet6_rthdr_reverse , +.Nm inet6_rthdr_segments , +.Nm inet6_rthdr_getaddr , +.Nm inet6_rthdr_getflags +.Nd IPv6 Routing Header Options manipulation +.\" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.Ft size_t +.Fn inet6_rthdr_space "int type" "int segments" +.Ft "struct cmsghdr *" +.Fn inet6_rthdr_init "void *bp" "int type" +.Ft int +.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags" +.Ft int +.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags" +.Ft int +.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out" +.Ft int +.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg" +.Ft "struct in6_addr *" +.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index" +.Ft int +.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index" +.\" +.Sh DESCRIPTION +RFC2292 IPv6 advanced API defines eight +functions that the application calls to build and examine a Routing +header. Four functions build a Routing header: +.Bl -hang +.It Fn inet6_rthdr_space +return #bytes required for ancillary data +.It Fn inet6_rthdr_init +initialize ancillary data for Routing header +.It Fn inet6_rthdr_add +add IPv6 address & flags to Routing header +.It Fn inet6_rthdr_lasthop +specify the flags for the final hop +.El +.Pp +Four functions deal with a returned Routing header: +.Bl -hang +.It Fn inet6_rthdr_reverse +reverse a Routing header +.It Fn inet6_rthdr_segments +return #segments in a Routing header +.It Fn inet6_rthdr_getaddr +fetch one address from a Routing header +.It Fn inet6_rthdr_getflags +fetch one flag from a Routing header +.El +.Pp +The function prototypes for these functions are all in the +.Aq Li netinet/in.h +header. +.\" +.Ss inet6_rthdr_space +This function returns the number of bytes required to hold a Routing +header of the specified +.Fa type +containing the specified number of +.Fa segments +(addresses). +For an IPv6 Type 0 Routing header, the number +of segments must be between 1 and 23, inclusive. The return value +includes the size of the cmsghdr structure that precedes the Routing +header, and any required padding. +.Pp +If the return value is 0, then either the type of the Routing header +is not supported by this implementation or the number of segments is +invalid for this type of Routing header. +.Pp +Note: This function returns the size but does not allocate the space +required for the ancillary data. +This allows an application to +allocate a larger buffer, if other ancillary data objects are +desired, since all the ancillary data objects must be specified to +.Xr sendmsg 2 +as a single +.Li msg_control +buffer. +.\" +.Ss inet6_rthdr_init +This function initializes the buffer pointed to by +.Fa bp +to contain a +.Li cmsghdr +structure followed by a Routing header of the specified +.Fa type . +The +.Li cmsg_len +member of the +.Li cmsghdr +structure is initialized to the +size of the structure plus the amount of space required by the +Routing header. +The +.Li cmsg_level +and +.Li cmsg_type +members are also initialized as required. +.Pp +The caller must allocate the buffer and its size can be determined by +calling +.Fn inet6_rthdr_space . +.Pp +Upon success the return value is the pointer to the +.Li cmsghdr +structure, and this is then used as the first argument to the next +two functions. +Upon an error the return value is +.Dv NULL . +.\" +.Ss inet6_rthdr_add +This function adds the address pointed to by +.Fa addr +to the end of the +Routing header being constructed and sets the type of this hop to the +value of +.Fa flags . +For an IPv6 Type 0 Routing header, +.Fa flags +must be +either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +If successful, the +.Li cmsg_len +member of the +.Li cmsghdr +structure is +updated to account for the new address in the Routing header and the +return value of the function is 0. +Upon an error the return value of +the function is -1. +.\" +.Ss inet6_rthdr_lasthop +This function specifies the Strict/Loose flag for the final hop of a +Routing header. +For an IPv6 Type 0 Routing header, +.Fa flags +must be either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +The return value of the function is 0 upon success, or -1 upon an error. +.Pp +Notice that a Routing header specifying +.Li N +intermediate nodes requires +.Li N+1 +Strict/Loose flags. +This requires +.Li N +calls to +.Fn inet6_rthdr_add +followed by one call to +.Fn inet6_rthdr_lasthop . +.\" +.Ss inet6_rthdr_reverse +This function is not yet implemented. +When implemented, this should behave as follows. +.Pp +This function takes a Routing header that was received as ancillary +data +(pointed to by the first argument, +.Fa in ) +and writes a new Routing +header that sends datagrams along the reverse of that route. +Both +arguments are allowed to point to the same buffer +(that is, the reversal can occur in place). +.Pp +The return value of the function is 0 on success, or -1 upon an +error. +.\" +.Ss inet6_rthdr_segments +This function returns the number of segments +(addresses) +contained in +the Routing header described by +.Fa cmsg . +On success the return value is +between 1 and 23, inclusive. +The return value of the function is -1 upon an error. +.\" +.Ss inet6_rthdr_getaddr +This function returns a pointer to the IPv6 address specified by +.Fa index +(which must have a value between 1 and the value returned by +.Fn inet6_rthdr_segments ) +in the Routing header described by +.Fa cmsg . +An +application should first call +.Fn inet6_rthdr_segments +to obtain the number of segments in the Routing header. +.Pp +Upon an error the return value of the function is +.Dv NULL . +.\" +.Ss inet6_rthdr_getflags +This function returns the flags value specified by +.Fa index +(which must +have a value between 0 and the value returned by +.Fn inet6_rthdr_segments ) +in the Routing header described by +.Fa cmsg . +For an IPv6 Type 0 Routing header the return value will be either +.Dv IPV6_RTHDR_LOOSE +or +.Dv IPV6_RTHDR_STRICT . +.Pp +Upon an error the return value of the function is -1. +.Pp +Note: Addresses are indexed starting at 1, and flags starting at 0, +to maintain consistency with the terminology and figures in RFC2460. +.\" +.Sh DIAGNOSTICS +.Fn inet6_rthdr_space +returns 0 on errors. +.Pp +.Fn inet6_rthdr_add , +.Fn inet6_rthdr_lasthop +and +.Fn inet6_rthdr_reverse +return 0 on success, and returns -1 on error. +.Pp +.Fn inet6_rthdr_init +and +.Fn inet6_rthdr_getaddr +return +.Dv NULL +on error. +.Pp +.Fn inet6_rthdr_segments +and +.Fn inet6_rthdr_getflags +return -1 on error. +.\" +.Sh EXAMPLES +RFC2292 gives comprehensive examples in chapter 8. +.\" +.Sh SEE ALSO +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Sockets API for IPv6" +.%N RFC2292 +.%D February 1998 +.Re +.Rs +.%A S. Deering +.%A R. Hinden +.%T "Internet Protocol, Version 6 (IPv6) Specification" +.%N RFC2460 +.%D December 1998 +.Re +.\" +.Sh HISTORY +The implementation first appeared in KAME advanced networking kit. +.\" +.Sh STANDARDS +The functions +are documented in +.Dq Advanced Sockets API for IPv6 +(RFC2292). +.\" +.Sh BUGS +The text was shamelessly copied from RFC2292. +.Pp +.Fn inet6_rthdr_reverse +is not implemented yet. diff --git a/newlib/libc/sys/linux/net/inet_lnaof.c b/newlib/libc/sys/linux/net/inet_lnaof.c index 0e115a442..c6c999dd1 100644 --- a/newlib/libc/sys/linux/net/inet_lnaof.c +++ b/newlib/libc/sys/linux/net/inet_lnaof.c @@ -10,6 +10,10 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -30,6 +34,9 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include +#include +#include #include #include @@ -44,7 +51,7 @@ in_addr_t inet_lnaof(in) struct in_addr in; { - register u_int32_t i = ntohl(in.s_addr); + in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return ((i)&IN_CLASSA_HOST); @@ -53,3 +60,10 @@ inet_lnaof(in) else return ((i)&IN_CLASSC_HOST); } + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_lnaof +__weak_reference(__inet_lnaof, inet_lnaof); diff --git a/newlib/libc/sys/linux/net/inet_makeaddr.c b/newlib/libc/sys/linux/net/inet_makeaddr.c new file mode 100644 index 000000000..339b2d5a7 --- /dev/null +++ b/newlib/libc/sys/linux/net/inet_makeaddr.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include +#include + +#include +#include +#include + +/* + * Formulate an Internet address from network + host. Used in + * building addresses stored in the ifnet structure. + */ +struct in_addr +inet_makeaddr(net, host) + in_addr_t net, host; +{ + in_addr_t addr; + + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + else if (net < 16777216L) + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + else + addr = net | host; + addr = htonl(addr); + return (*(struct in_addr *)&addr); +} + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_makeaddr +__weak_reference(__inet_makeaddr, inet_makeaddr); diff --git a/newlib/libc/sys/linux/net/inet_mkadr.c b/newlib/libc/sys/linux/net/inet_mkadr.c deleted file mode 100644 index 26d54f244..000000000 --- a/newlib/libc/sys/linux/net/inet_mkadr.c +++ /dev/null @@ -1,60 +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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include "libc-symbols.h" - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(net, host) - in_addr_t net, host; -{ - struct in_addr in; - - if (net < 128) - in.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - in.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); - else if (net < 16777216L) - in.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); - else - in.s_addr = net | host; - in.s_addr = htonl(in.s_addr); - return in; -} -libc_hidden_def (inet_makeaddr) diff --git a/newlib/libc/sys/linux/net/inet_net.3 b/newlib/libc/sys/linux/net/inet_net.3 new file mode 100644 index 000000000..1d43bcc1d --- /dev/null +++ b/newlib/libc/sys/linux/net/inet_net.3 @@ -0,0 +1,157 @@ +.\" $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Luke Mewburn. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.1 2001/08/31 10:54:44 ru Exp $ +.\" +.Dd June 18, 1997 +.Dt INET_NET 3 +.Os +.Sh NAME +.Nm inet_net_ntop , +.Nm inet_net_pton +.Nd Internet network number manipulation routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In netinet/in.h +.In arpa/inet.h +.Ft char * +.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" +.Ft int +.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" +.Sh DESCRIPTION +The +.Fn inet_net_ntop +function converts an Internet network number from network format (usually a +.Vt "struct in_addr" +or some other binary form, in network byte order) to CIDR presentation format +(suitable for external display purposes). +.Fa bits +is the number of bits in +.Fa src +that are the network number. +It returns +.Dv NULL +if a system error occurs (in which case, +.Va errno +will have been set), or it returns a pointer to the destination string. +.Pp +The +.Fn inet_net_pton +function converts a presentation format Internet network number (that is, +printable form as held in a character string) to network format (usually a +.Vt "struct in_addr" +or some other internal binary representation, in network byte order). +It returns the number of bits (either computed based on the class, or +specified with /CIDR), or \-1 if a failure occurred +(in which case +.Va errno +will have been set. +It will be set to +.Er ENOENT +if the Internet network number was not valid). +.Pp +The only value for +.Fa af +currently supported is +.Dv AF_INET . +.Fa size +is the size of the result buffer +.Fa dst . +.Pp +.Sh NETWORK NUMBERS (IP VERSION 4) +Internet network numbers may be specified in one of the following forms: +.Bd -literal -offset indent +a.b.c.d/bits +a.b.c.d +a.b.c +a.b +a +.Ed +.Pp +When four parts are specified, each is interpreted +as a byte of data and assigned, from left to right, +to the four bytes of an Internet network number. +Note +that when an Internet network number is viewed as a 32-bit +integer quantity on a system that uses little-endian +byte order (such as the +.Tn Intel 386 , 486 , +and +.Tn Pentium +processors) the bytes referred to above appear as +.Dq Li d.c.b.a . +That is, little-endian bytes are ordered from right to left. +.Pp +When a three part number is specified, the last +part is interpreted as a 16-bit quantity and placed +in the rightmost two bytes of the Internet network number. +This makes the three part number format convenient +for specifying Class B network numbers as +.Dq Li 128.net.host . +.Pp +When a two part number is supplied, the last part +is interpreted as a 24-bit quantity and placed in +the rightmost three bytes of the Internet network number. +This makes the two part number format convenient +for specifying Class A network numbers as +.Dq Li net.host . +.Pp +When only one part is given, the value is stored +directly in the Internet network number without any byte +rearrangement. +.Pp +All numbers supplied as +.Dq parts +in a +.Ql \&. +notation +may be decimal, octal, or hexadecimal, as specified +in the C language (i.e., a leading 0x or 0X implies +hexadecimal; otherwise, a leading 0 implies octal; +otherwise, the number is interpreted as decimal). +.Sh SEE ALSO +.Xr byteorder 3 , +.Xr inet 3 , +.Xr networks 5 +.Sh HISTORY +The +.Fn inet_net_ntop +and +.Fn inet_net_pton +functions appeared in BIND 4.9.4. diff --git a/newlib/libc/sys/linux/net/inet_net.c b/newlib/libc/sys/linux/net/inet_net.c deleted file mode 100644 index e9331c592..000000000 --- a/newlib/libc/sys/linux/net/inet_net.c +++ /dev/null @@ -1,95 +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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include - -/* - * Internet network address interpretation routine. - * The library routines call this routine to interpret - * network numbers. - */ -u_int32_t -inet_network(cp) - register const char *cp; -{ - register u_int32_t val, base, n, i; - register char c; - u_int32_t parts[4], *pp = parts; - int digit; - -again: - val = 0; base = 10; digit = 0; - if (*cp == '0') - digit = 1, base = 8, cp++; - if (*cp == 'x' || *cp == 'X') - base = 16, cp++; - while ((c = *cp) != 0) { - if (isdigit(c)) { - if (base == 8 && (c == '8' || c == '9')) - return (INADDR_NONE); - val = (val * base) + (c - '0'); - cp++; - digit = 1; - continue; - } - if (base == 16 && isxdigit(c)) { - val = (val << 4) + (tolower (c) + 10 - 'a'); - cp++; - digit = 1; - continue; - } - break; - } - if (!digit) - return (INADDR_NONE); - if (pp >= parts + 4 || val > 0xff) - return (INADDR_NONE); - if (*cp == '.') { - *pp++ = val, cp++; - goto again; - } - if (*cp && !isspace(*cp)) - return (INADDR_NONE); - if (pp >= parts + 4 || val > 0xff) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - for (val = 0, i = 0; i < n; i++) { - val <<= 8; - val |= parts[i] & 0xff; - } - return (val); -} diff --git a/newlib/libc/sys/linux/net/inet_netof.c b/newlib/libc/sys/linux/net/inet_netof.c index 3035f3402..e2e84d340 100644 --- a/newlib/libc/sys/linux/net/inet_netof.c +++ b/newlib/libc/sys/linux/net/inet_netof.c @@ -10,6 +10,10 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -30,11 +34,13 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include +#include +#include #include #include #include -#include "libc-symbols.h" /* * Return the network number from an internet @@ -44,7 +50,7 @@ in_addr_t inet_netof(in) struct in_addr in; { - register u_int32_t i = ntohl(in.s_addr); + in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); @@ -53,4 +59,10 @@ inet_netof(in) else return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); } -libc_hidden_def (inet_netof) + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_netof +__weak_reference(__inet_netof, inet_netof); diff --git a/newlib/libc/sys/linux/net/inet_network.c b/newlib/libc/sys/linux/net/inet_network.c new file mode 100644 index 000000000..caf1d7869 --- /dev/null +++ b/newlib/libc/sys/linux/net/inet_network.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include +#include + +/* + * Internet network address interpretation routine. + * The library routines call this routine to interpret + * network numbers. + */ +in_addr_t +inet_network(cp) + const char *cp; +{ + in_addr_t val, base, n; + char c; + in_addr_t parts[4], *pp = parts; + int i; + +again: + val = 0; base = 10; + if (*cp == '0') + base = 8, cp++; + if (*cp == 'x' || *cp == 'X') + base = 16, cp++; + while ((c = *cp) != 0) { + if (isdigit((unsigned char)c)) { + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit((unsigned char)c)) { + val = (val << 4) + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + if (pp >= parts + 3) + return (INADDR_NONE); + *pp++ = val, cp++; + goto again; + } + if (*cp && !isspace((unsigned char)*cp)) + return (INADDR_NONE); + *pp++ = val; + n = pp - parts; + for (val = 0, i = 0; i < n; i++) { + val <<= 8; + val |= parts[i] & 0xff; + } + return (val); +} + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_network +__weak_reference(__inet_network, inet_network); diff --git a/newlib/libc/sys/linux/net/inet_ntoa.c b/newlib/libc/sys/linux/net/inet_ntoa.c index b0b7a1535..dedc4768d 100644 --- a/newlib/libc/sys/linux/net/inet_ntoa.c +++ b/newlib/libc/sys/linux/net/inet_ntoa.c @@ -1,98 +1,67 @@ -/* Convert Inet number to ASCII representation. - Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include #include -#include - -/* The interface of this function is completely stupid, it requires a - static buffer. We relax this a bit in that we allow at least one - buffer for each thread. */ - -/* This is the key for the thread specific memory. */ -static __libc_key_t key; - -/* If nonzero the key allocation failed and we should better use a - static buffer than fail. */ -static char local_buf[18]; -static char *static_buf; - -/* Destructor for the thread-specific data. */ -static void init (void); -static void free_key_mem (void *mem); - +#include +#include +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + */ char * -inet_ntoa (struct in_addr in) +inet_ntoa(in) + struct in_addr in; { - __libc_once_define (static, once); - char *buffer; - unsigned char *bytes; + static char ret[18]; - /* If we have not yet initialized the buffer do it now. */ - __libc_once (once, init); - - if (static_buf != NULL) - buffer = static_buf; - else - { - /* We don't use the static buffer and so we have a key. Use it - to get the thread-specific buffer. */ - buffer = __libc_getspecific (key); - if (buffer == NULL) - { - /* No buffer allocated so far. */ - buffer = malloc (18); - if (buffer == NULL) - /* No more memory available. We use the static buffer. */ - buffer = local_buf; - else - __libc_setspecific (key, buffer); - } - } - - bytes = (unsigned char *) ∈ - snprintf (buffer, 18, "%d.%d.%d.%d", - bytes[0], bytes[1], bytes[2], bytes[3]); - - return buffer; -} - - -/* Initialize buffer. */ -static void -init (void) -{ - if (__libc_key_create (&key, free_key_mem)) - /* Creating the key failed. This means something really went - wrong. In any case use a static buffer which is better than - nothing. */ - static_buf = local_buf; + strcpy(ret, "[inet_ntoa error]"); + (void) inet_ntop(AF_INET, &in, ret, sizeof ret); + return (ret); } - -/* Free the thread specific data, this is done if a thread terminates. */ -static void -free_key_mem (void *mem) -{ - free (mem); - __libc_setspecific (key, NULL); -} +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_ntoa +__weak_reference(__inet_ntoa, inet_ntoa); diff --git a/newlib/libc/sys/linux/net/innetgr-stub.c b/newlib/libc/sys/linux/net/innetgr-stub.c new file mode 100644 index 000000000..690d82e14 --- /dev/null +++ b/newlib/libc/sys/linux/net/innetgr-stub.c @@ -0,0 +1,7 @@ +int +innetgr(const char *netgroup, const char *host, const char *user, + const char *domain) +{ + return 0; +} + diff --git a/newlib/libc/sys/linux/net/ip6opt.c b/newlib/libc/sys/linux/net/ip6opt.c new file mode 100644 index 000000000..f3f51d507 --- /dev/null +++ b/newlib/libc/sys/linux/net/ip6opt.c @@ -0,0 +1,387 @@ +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +static int ip6optlen(u_int8_t *opt, u_int8_t *lim); +static void inet6_insert_padopt(u_char *p, int len); + +/* + * This function returns the number of bytes required to hold an option + * when it is stored as ancillary data, including the cmsghdr structure + * at the beginning, and any padding at the end (to make its size a + * multiple of 8 bytes). The argument is the size of the structure + * defining the option, which must include any pad bytes at the + * beginning (the value y in the alignment term "xn + y"), the type + * byte, the length byte, and the option data. + */ +int +inet6_option_space(nbytes) + int nbytes; +{ + nbytes += 2; /* we need space for nxt-hdr and length fields */ + return(CMSG_SPACE((nbytes + 7) & ~7)); +} + +/* + * This function is called once per ancillary data object that will + * contain either Hop-by-Hop or Destination options. It returns 0 on + * success or -1 on an error. + */ +int +inet6_option_init(bp, cmsgp, type) + void *bp; + struct cmsghdr **cmsgp; + int type; +{ + struct cmsghdr *ch = (struct cmsghdr *)bp; + + /* argument validation */ + if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) + return(-1); + + ch->cmsg_level = IPPROTO_IPV6; + ch->cmsg_type = type; + ch->cmsg_len = CMSG_LEN(0); + + *cmsgp = ch; + return(0); +} + +/* + * This function appends a Hop-by-Hop option or a Destination option + * into an ancillary data object that has been initialized by + * inet6_option_init(). This function returns 0 if it succeeds or -1 on + * an error. + * multx is the value x in the alignment term "xn + y" described + * earlier. It must have a value of 1, 2, 4, or 8. + * plusy is the value y in the alignment term "xn + y" described + * earlier. It must have a value between 0 and 7, inclusive. + */ +int +inet6_option_append(cmsg, typep, multx, plusy) + struct cmsghdr *cmsg; + const u_int8_t *typep; + int multx; + int plusy; +{ + int padlen, optlen, off; + u_char *bp = (u_char *)cmsg + cmsg->cmsg_len; + struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); + + /* argument validation */ + if (multx != 1 && multx != 2 && multx != 4 && multx != 8) + return(-1); + if (plusy < 0 || plusy > 7) + return(-1); + if (typep[0] > 255) + return(-1); + + /* + * If this is the first option, allocate space for the + * first 2 bytes(for next header and length fields) of + * the option header. + */ + if (bp == (u_char *)eh) { + bp += 2; + cmsg->cmsg_len += 2; + } + + /* calculate pad length before the option. */ + off = bp - (u_char *)eh; + padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - + (off % multx); + padlen += plusy; + /* insert padding */ + inet6_insert_padopt(bp, padlen); + cmsg->cmsg_len += padlen; + bp += padlen; + + /* copy the option */ + if (typep[0] == IP6OPT_PAD1) + optlen = 1; + else + optlen = typep[1] + 2; + memcpy(bp, typep, optlen); + bp += optlen; + cmsg->cmsg_len += optlen; + + /* calculate pad length after the option and insert the padding */ + off = bp - (u_char *)eh; + padlen = ((off + 7) & ~7) - off; + inet6_insert_padopt(bp, padlen); + bp += padlen; + cmsg->cmsg_len += padlen; + + /* update the length field of the ip6 option header */ + eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; + + return(0); +} + +/* + * This function appends a Hop-by-Hop option or a Destination option + * into an ancillary data object that has been initialized by + * inet6_option_init(). This function returns a pointer to the 8-bit + * option type field that starts the option on success, or NULL on an + * error. + * The difference between this function and inet6_option_append() is + * that the latter copies the contents of a previously built option into + * the ancillary data object while the current function returns a + * pointer to the space in the data object where the option's TLV must + * then be built by the caller. + * + */ +u_int8_t * +inet6_option_alloc(cmsg, datalen, multx, plusy) + struct cmsghdr *cmsg; + int datalen; + int multx; + int plusy; +{ + int padlen, off; + u_int8_t *bp = (u_char *)cmsg + cmsg->cmsg_len; + u_int8_t *retval; + struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); + + /* argument validation */ + if (multx != 1 && multx != 2 && multx != 4 && multx != 8) + return(NULL); + if (plusy < 0 || plusy > 7) + return(NULL); + + /* + * If this is the first option, allocate space for the + * first 2 bytes(for next header and length fields) of + * the option header. + */ + if (bp == (u_char *)eh) { + bp += 2; + cmsg->cmsg_len += 2; + } + + /* calculate pad length before the option. */ + off = bp - (u_char *)eh; + padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - + (off % multx); + padlen += plusy; + /* insert padding */ + inet6_insert_padopt(bp, padlen); + cmsg->cmsg_len += padlen; + bp += padlen; + + /* keep space to store specified length of data */ + retval = bp; + bp += datalen; + cmsg->cmsg_len += datalen; + + /* calculate pad length after the option and insert the padding */ + off = bp - (u_char *)eh; + padlen = ((off + 7) & ~7) - off; + inet6_insert_padopt(bp, padlen); + bp += padlen; + cmsg->cmsg_len += padlen; + + /* update the length field of the ip6 option header */ + eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; + + return(retval); +} + +/* + * This function processes the next Hop-by-Hop option or Destination + * option in an ancillary data object. If another option remains to be + * processed, the return value of the function is 0 and *tptrp points to + * the 8-bit option type field (which is followed by the 8-bit option + * data length, followed by the option data). If no more options remain + * to be processed, the return value is -1 and *tptrp is NULL. If an + * error occurs, the return value is -1 and *tptrp is not NULL. + * (RFC 2292, 6.3.5) + */ +int +inet6_option_next(cmsg, tptrp) + const struct cmsghdr *cmsg; + u_int8_t **tptrp; +{ + struct ip6_ext *ip6e; + int hdrlen, optlen; + u_int8_t *lim; + + if (cmsg->cmsg_level != IPPROTO_IPV6 || + (cmsg->cmsg_type != IPV6_HOPOPTS && + cmsg->cmsg_type != IPV6_DSTOPTS)) + return(-1); + + /* message length validation */ + if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) + return(-1); + ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); + hdrlen = (ip6e->ip6e_len + 1) << 3; + if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) + return(-1); + + /* + * If the caller does not specify the starting point, + * simply return the 1st option. + * Otherwise, search the option list for the next option. + */ + lim = (u_int8_t *)ip6e + hdrlen; + if (*tptrp == NULL) + *tptrp = (u_int8_t *)(ip6e + 1); + else { + if ((optlen = ip6optlen(*tptrp, lim)) == 0) + return(-1); + + *tptrp = *tptrp + optlen; + } + if (*tptrp >= lim) { /* there is no option */ + *tptrp = NULL; + return(-1); + } + /* + * Finally, checks if the next option is safely stored in the + * cmsg data. + */ + if (ip6optlen(*tptrp, lim) == 0) + return(-1); + else + return(0); +} + +/* + * This function is similar to the inet6_option_next() function, + * except this function lets the caller specify the option type to be + * searched for, instead of always returning the next option in the + * ancillary data object. + * Note: RFC 2292 says the type of tptrp is u_int8_t *, but we think + * it's a typo. The variable should be type of u_int8_t **. + */ +int +inet6_option_find(cmsg, tptrp, type) + const struct cmsghdr *cmsg; + u_int8_t **tptrp; + int type; +{ + struct ip6_ext *ip6e; + int hdrlen, optlen; + u_int8_t *optp, *lim; + + if (cmsg->cmsg_level != IPPROTO_IPV6 || + (cmsg->cmsg_type != IPV6_HOPOPTS && + cmsg->cmsg_type != IPV6_DSTOPTS)) + return(-1); + + /* message length validation */ + if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) + return(-1); + ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); + hdrlen = (ip6e->ip6e_len + 1) << 3; + if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) + return(-1); + + /* + * If the caller does not specify the starting point, + * search from the beginning of the option list. + * Otherwise, search from *the next option* of the specified point. + */ + lim = (u_int8_t *)ip6e + hdrlen; + if (*tptrp == NULL) + *tptrp = (u_int8_t *)(ip6e + 1); + else { + if ((optlen = ip6optlen(*tptrp, lim)) == 0) + return(-1); + + *tptrp = *tptrp + optlen; + } + for (optp = *tptrp; optp < lim; optp += optlen) { + if (*optp == type) { + *tptrp = optp; + return(0); + } + if ((optlen = ip6optlen(optp, lim)) == 0) + return(-1); + } + + /* search failed */ + *tptrp = NULL; + return(-1); +} + +/* + * Calculate the length of a given IPv6 option. Also checks + * if the option is safely stored in user's buffer according to the + * calculated length and the limitation of the buffer. + */ +static int +ip6optlen(opt, lim) + u_int8_t *opt, *lim; +{ + int optlen; + + if (*opt == IP6OPT_PAD1) + optlen = 1; + else { + /* is there enough space to store type and len? */ + if (opt + 2 > lim) + return(0); + optlen = *(opt + 1) + 2; + } + if (opt + optlen <= lim) + return(optlen); + + return(0); +} + +static void +inet6_insert_padopt(u_char *p, int len) +{ + switch(len) { + case 0: + return; + case 1: + p[0] = IP6OPT_PAD1; + return; + default: + p[0] = IP6OPT_PADN; + p[1] = len - 2; + memset(&p[2], 0, len - 2); + return; + } +} diff --git a/newlib/libc/sys/linux/net/iso_addr.3 b/newlib/libc/sys/linux/net/iso_addr.3 new file mode 100644 index 000000000..dc843c315 --- /dev/null +++ b/newlib/libc/sys/linux/net/iso_addr.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)iso_addr.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/iso_addr.3,v 1.7 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt ISO_ADDR 3 +.Os +.Sh NAME +.Nm iso_addr , +.Nm iso_ntoa +.Nd "elementary network address conversion routines for Open System Interconnection +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netiso/iso.h +.Ft struct iso_addr * +.Fn iso_addr "char *cp" +.Ft char * +.Fn iso_ntoa "struct iso_addr *isoa" +.Sh DESCRIPTION +The routine +.Fn iso_addr +interprets character strings representing +.Tn OSI +addresses, returning binary information suitable +for use in system calls. +The routine +.Fn iso_ntoa +takes +.Tn OSI +addresses and returns +.Tn ASCII +strings representing NSAPs (network service +access points) in a +notation inverse to that accepted by +.Fn iso_addr . +.Pp +Unfortunately, no universal standard exists for representing +.Tn OSI +network addresses. +.Pp +The format employed by +.Fn iso_addr +is a sequence of hexadecimal +.Dq digits +(optionally separated by periods), +of the form: +.Bd -ragged -offset indent +.. +.Ed +.Pp +Each pair of hexadecimal digits represents a byte +with the leading digit indicating the higher-ordered bits. +A period following an even number of bytes has no +effect (but may be used to increase legibility). +A period following an odd number of bytes has the +effect of causing the byte of address being translated +to have its higher order bits filled with zeros. +.Sh RETURN VALUES +.Fn iso_ntoa +always returns a null terminated string. +.Fn iso_addr +always returns a pointer to a struct iso_addr. +(See +.Sx BUGS . ) +.Sh SEE ALSO +.Xr iso 4 +.Sh HISTORY +The +.Fn iso_addr +and +.Fn iso_ntoa +functions appeared in +.Bx 4.3 Reno . +.Sh BUGS +The returned values +reside in a static memory area. +.Pp +The function +.Fn iso_addr +should diagnose improperly formed input, and there should be an unambiguous +way to recognize this. diff --git a/newlib/libc/sys/linux/net/iso_addr.c b/newlib/libc/sys/linux/net/iso_addr.c new file mode 100644 index 000000000..e943122f8 --- /dev/null +++ b/newlib/libc/sys/linux/net/iso_addr.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)iso_addr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include + +/* States*/ +#define VIRGIN 0 +#define GOTONE 1 +#define GOTTWO 2 +/* Inputs */ +#define DIGIT (4*0) +#define END (4*1) +#define DELIM (4*2) + +struct iso_addr * +iso_addr(addr) + const char *addr; +{ + static struct iso_addr out_addr; + char *cp = out_addr.isoa_genaddr; + char *cplim = cp + sizeof(out_addr.isoa_genaddr); + int byte = 0, state = VIRGIN, new; + + bzero((char *)&out_addr, sizeof(out_addr)); + do { + if ((*addr >= '0') && (*addr <= '9')) { + new = *addr - '0'; + } else if ((*addr >= 'a') && (*addr <= 'f')) { + new = *addr - 'a' + 10; + } else if ((*addr >= 'A') && (*addr <= 'F')) { + new = *addr - 'A' + 10; + } else if (*addr == 0) + state |= END; + else + state |= DELIM; + addr++; + switch (state /* | INPUT */) { + case GOTTWO | DIGIT: + *cp++ = byte; /*FALLTHROUGH*/ + case VIRGIN | DIGIT: + state = GOTONE; byte = new; continue; + case GOTONE | DIGIT: + state = GOTTWO; byte = new + (byte << 4); continue; + default: /* | DELIM */ + state = VIRGIN; *cp++ = byte; byte = 0; continue; + case GOTONE | END: + case GOTTWO | END: + *cp++ = byte; /* FALLTHROUGH */ + case VIRGIN | END: + break; + } + break; + } while (cp < cplim); + out_addr.isoa_len = cp - out_addr.isoa_genaddr; + return (&out_addr); +} + +static char hexlist[] = "0123456789abcdef"; + +char * +iso_ntoa(isoa) + const struct iso_addr *isoa; +{ + static char tmpbuf[sizeof(isoa->isoa_genaddr)*3]; + const u_char *binary; + char *cp; + int i; + + binary = isoa->isoa_genaddr; + cp = tmpbuf; + + for (i = 0; i < isoa->isoa_len; i++) { + *cp++ = hexlist[*binary >> 4]; + *cp++ = hexlist[*binary++ & 0xf]; + + if ((((i % 2) == 0) && ((i + 1) < isoa->isoa_len))) + *cp++ = '.'; + } + *cp = '\0'; + return tmpbuf; +} diff --git a/newlib/libc/sys/linux/net/key-lookup.c b/newlib/libc/sys/linux/net/key-lookup.c deleted file mode 100644 index e2c4c14a6..000000000 --- a/newlib/libc/sys/linux/net/key-lookup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME publickey -#define DEFAULT_CONFIG "nis nisplus" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/linkaddr.3 b/newlib/libc/sys/linux/net/linkaddr.3 new file mode 100644 index 000000000..1d664630b --- /dev/null +++ b/newlib/libc/sys/linux/net/linkaddr.3 @@ -0,0 +1,140 @@ +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Donn Seeley at BSDI. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93 +.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.12 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 17, 1996 +.Dt LINK_ADDR 3 +.Os +.Sh NAME +.Nm link_addr , +.Nm link_ntoa +.Nd elementary address specification routines for link level access +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/if_dl.h +.Ft void +.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" +.Ft char * +.Fn link_ntoa "const struct sockaddr_dl *sdl" +.Sh DESCRIPTION +The routine +.Fn link_addr +interprets character strings representing +link-level addresses, returning binary information suitable +for use in system calls. +The routine +.Fn link_ntoa +takes +a link-level +address and returns an +.Tn ASCII +string representing some of the information present, +including the link level address itself, and the interface name +or number, if present. +This facility is experimental and is +still subject to change. +.Pp +For +.Fn link_addr , +the string +.Fa addr +may contain +an optional network interface identifier of the form +.Dq "name unit-number" , +suitable for the first argument to +.Xr ifconfig 8 , +followed in all cases by a colon and +an interface address in the form of +groups of hexadecimal digits +separated by periods. +Each group represents a byte of address; +address bytes are filled left to right from +low order bytes through high order bytes. +.Pp +.\" A regular expression may make this format clearer: +.\" .Bd -literal -offset indent +.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* +.\" .Ed +.\" .Pp +Thus +.Li le0:8.0.9.13.d.30 +represents an ethernet address +to be transmitted on the first Lance ethernet interface. +.Pp +The direct use of these functions is deprecated in favor of the +.Xr addr2ascii 3 +interface; however, portable programs cannot rely on the latter as it is +not yet widely implemented. +.Sh RETURN VALUES +.Fn link_ntoa +always returns a null terminated string. +.Fn link_addr +has no return value. +(See +.Sx BUGS . ) +.Sh SEE ALSO +.Xr addr2ascii 3 +.\" .Xr iso 4 +.Sh HISTORY +The +.Fn link_addr +and +.Fn link_ntoa +functions appeared in +.Bx 4.3 Reno . +.Sh BUGS +The returned values for link_ntoa +reside in a static memory area. +.Pp +The function +.Fn link_addr +should diagnose improperly formed input, and there should be an unambiguous +way to recognize this. +.Pp +If the +.Va sdl_len +field of the link socket address +.Fa sdl +is 0, +.Fn link_ntoa +will not insert a colon before the interface address bytes. +If this translated address is given to +.Fn link_addr +without inserting an initial colon, +the latter will not interpret it correctly. diff --git a/newlib/libc/sys/linux/net/linkaddr.c b/newlib/libc/sys/linux/net/linkaddr.c new file mode 100644 index 000000000..deeaa09ea --- /dev/null +++ b/newlib/libc/sys/linux/net/linkaddr.c @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include +#include + +/* States*/ +#define NAMING 0 +#define GOTONE 1 +#define GOTTWO 2 +#define RESET 3 +/* Inputs */ +#define DIGIT (4*0) +#define END (4*1) +#define DELIM (4*2) +#define LETTER (4*3) + +void +link_addr(addr, sdl) + const char *addr; + struct sockaddr_dl *sdl; +{ + char *cp = sdl->sdl_data; + char *cplim = sdl->sdl_len + (char *)sdl; + int byte = 0, state = NAMING, new = 0; + + bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); + sdl->sdl_family = AF_INET; + do { + state &= ~LETTER; + if ((*addr >= '0') && (*addr <= '9')) { + new = *addr - '0'; + } else if ((*addr >= 'a') && (*addr <= 'f')) { + new = *addr - 'a' + 10; + } else if ((*addr >= 'A') && (*addr <= 'F')) { + new = *addr - 'A' + 10; + } else if (*addr == 0) { + state |= END; + } else if (state == NAMING && + (((*addr >= 'A') && (*addr <= 'Z')) || + ((*addr >= 'a') && (*addr <= 'z')))) + state |= LETTER; + else + state |= DELIM; + addr++; + switch (state /* | INPUT */) { + case NAMING | DIGIT: + case NAMING | LETTER: + *cp++ = addr[-1]; + continue; + case NAMING | DELIM: + state = RESET; + sdl->sdl_nlen = cp - sdl->sdl_data; + continue; + case GOTTWO | DIGIT: + *cp++ = byte; + /* FALLTHROUGH */ + case RESET | DIGIT: + state = GOTONE; + byte = new; + continue; + case GOTONE | DIGIT: + state = GOTTWO; + byte = new + (byte << 4); + continue; + default: /* | DELIM */ + state = RESET; + *cp++ = byte; + byte = 0; + continue; + case GOTONE | END: + case GOTTWO | END: + *cp++ = byte; + /* FALLTHROUGH */ + case RESET | END: + break; + } + break; + } while (cp < cplim); + sdl->sdl_alen = cp - LLADDR(sdl); + new = cp - (char *)sdl; + if (new > sizeof(*sdl)) + sdl->sdl_len = new; + return; +} + +static char hexlist[] = "0123456789abcdef"; + +char * +link_ntoa(sdl) + const struct sockaddr_dl *sdl; +{ + static char obuf[64]; + char *out = obuf; + int i; + u_char *in = (u_char *)LLADDR(sdl); + u_char *inlim = in + sdl->sdl_alen; + int firsttime = 1; + + if (sdl->sdl_nlen) { + bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); + out += sdl->sdl_nlen; + if (sdl->sdl_alen) + *out++ = ':'; + } + while (in < inlim) { + if (firsttime) + firsttime = 0; + else + *out++ = '.'; + i = *in++; + if (i > 0xf) { + out[1] = hexlist[i & 0xf]; + i >>= 4; + out[0] = hexlist[i]; + out += 2; + } else + *out++ = hexlist[i]; + } + *out = 0; + return (obuf); +} diff --git a/newlib/libc/sys/linux/net/local.h b/newlib/libc/sys/linux/net/local.h deleted file mode 100644 index 9380d7c55..000000000 --- a/newlib/libc/sys/linux/net/local.h +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include "libc-symbols.h" - -# define extend_alloca(buf, len, newlen) \ - (__typeof (buf)) ({ size_t __newlen = (newlen); \ - char *__newbuf = alloca (__newlen); \ - if (__newbuf > (char *)buf) \ - if ((char *)buf + len == __newbuf) { \ - len += __newlen; \ - __newbuf = buf; \ - } \ - else { \ - if (__newbuf + newlen == (char *)buf) \ - len += __newlen; \ - else \ - len = __newlen; \ - } \ - __newbuf; }) - -#define __fsetlocking(fp, x) fp - -extern const char *_res_opcodes[]; -libresolv_hidden_proto (_res_opcodes) - diff --git a/newlib/libc/sys/linux/net/map_v4v6.c b/newlib/libc/sys/linux/net/map_v4v6.c new file mode 100644 index 000000000..f746a8088 --- /dev/null +++ b/newlib/libc/sys/linux/net/map_v4v6.c @@ -0,0 +1,128 @@ +/* + * ++Copyright++ 1985, 1988, 1993 + * - + * Copyright (c) 1985, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +typedef union { + int32_t al; + char ac; +} align; + +void +_map_v4v6_address(src, dst) + const char *src; + char *dst; +{ + u_char *p = (u_char *)dst; + char tmp[INADDRSZ]; + int i; + + /* Stash a temporary copy so our caller can update in place. */ + bcopy(src, tmp, INADDRSZ); + /* Mark this ipv6 addr as a mapped ipv4. */ + for (i = 0; i < 10; i++) + *p++ = 0x00; + *p++ = 0xff; + *p++ = 0xff; + /* Retrieve the saved copy and we're done. */ + bcopy(tmp, (void*)p, INADDRSZ); +} + +void +_map_v4v6_hostent(hp, bpp, lenp) + struct hostent *hp; + char **bpp; + int *lenp; +{ + char **ap; + + if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) + return; + hp->h_addrtype = AF_INET6; + hp->h_length = IN6ADDRSZ; + for (ap = hp->h_addr_list; *ap; ap++) { + int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); + + if (*lenp < (i + IN6ADDRSZ)) { + /* Out of memory. Truncate address list here. XXX */ + *ap = NULL; + return; + } + *bpp += i; + *lenp -= i; + _map_v4v6_address(*ap, *bpp); + *ap = *bpp; + *bpp += IN6ADDRSZ; + *lenp -= IN6ADDRSZ; + } +} diff --git a/newlib/libc/sys/linux/net/name6.c b/newlib/libc/sys/linux/net/name6.c new file mode 100644 index 000000000..f220e213c --- /dev/null +++ b/newlib/libc/sys/linux/net/name6.c @@ -0,0 +1,1812 @@ +/* $KAME: name6.c,v 1.25 2000/06/26 16:44:40 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * ++Copyright++ 1985, 1988, 1993 + * - + * Copyright (c) 1985, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- + */ + +/* + * Atsushi Onoe + */ + +/* + * TODO for thread safe + * use mutex for _hostconf, _hostconf_init. + * rewrite resolvers to be thread safe + */ + +#include +#include +#include +#include +#include + +#include "namespace.h" +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#ifndef _PATH_HOSTS +#define _PATH_HOSTS "/etc/hosts" +#endif + +#ifndef MAXALIASES +#define MAXALIASES 35 +#endif +#ifndef MAXADDRS +#define MAXADDRS 2 +#endif +#ifndef MAXDNAME +#define MAXDNAME 1025 +#endif + +#ifdef INET6 +#define ADDRLEN(af) ((af) == AF_INET6 ? sizeof(struct in6_addr) : \ + sizeof(struct in_addr)) +#else +#define ADDRLEN(af) sizeof(struct in_addr) +#endif + +#define MAPADDR(ab, ina) \ +do { \ + memcpy(&(ab)->map_inaddr, ina, sizeof(struct in_addr)); \ + memset((ab)->map_zero, 0, sizeof((ab)->map_zero)); \ + memset((ab)->map_one, 0xff, sizeof((ab)->map_one)); \ +} while (0) +#define MAPADDRENABLED(flags) \ + (((flags) & AI_V4MAPPED) || \ + (((flags) & AI_V4MAPPED_CFG) && _mapped_addr_enabled())) + +union inx_addr { + struct in_addr in_addr; +#ifdef INET6 + struct in6_addr in6_addr; +#endif + struct { + u_char mau_zero[10]; + u_char mau_one[2]; + struct in_addr mau_inaddr; + } map_addr_un; +#define map_zero map_addr_un.mau_zero +#define map_one map_addr_un.mau_one +#define map_inaddr map_addr_un.mau_inaddr +}; + +u_int16_t _getshort(const u_char *src); + +static struct hostent *_hpcopy(struct hostent *hp, int *errp); +static struct hostent *_hpaddr(int af, const char *name, void *addr, int *errp); +static struct hostent *_hpmerge(struct hostent *hp1, struct hostent *hp2, int *errp); +#ifdef INET6 +static struct hostent *_hpmapv6(struct hostent *hp, int *errp); +#endif +static struct hostent *_hpsort(struct hostent *hp); +static struct hostent *_ghbyname(const char *name, int af, int flags, int *errp); +static char *_hgetword(char **pp); +static int _mapped_addr_enabled(void); + +static FILE *_files_open(int *errp); +static int _files_ghbyname(void *, void *, va_list); +static int _files_ghbyaddr(void *, void *, va_list); +#if 0 // keep gcc happy +static void _files_shent(int stayopen); +static void _files_ehent(void); +#endif +#ifdef YP +static int _nis_ghbyname(void *, void *, va_list); +static int _nis_ghbyaddr(void *, void *, va_list); +#endif +static int _dns_ghbyname(void *, void *, va_list); +static int _dns_ghbyaddr(void *, void *, va_list); +#if 0 // keep gcc happy +static void _dns_shent(int stayopen); +static void _dns_ehent(void); +#endif + +#ifdef ICMPNL +static int _icmp_ghbyaddr(void *, void *, va_list); +#endif /* ICMPNL */ + +/* Host lookup order if nsswitch.conf is broken or nonexistant */ +static const ns_src default_src[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NSSRC_DNS, NS_SUCCESS }, +#ifdef ICMPNL +#define NSSRC_ICMP "icmp" + { NSSRC_ICMP, NS_SUCCESS }, +#endif + { 0 } +}; + +/* + * Check if kernel supports mapped address. + * implementation dependent + */ +#ifdef __KAME__ +#include +#endif /* __KAME__ */ + +static int +_mapped_addr_enabled(void) +{ + /* implementation dependent check */ +#if defined(__KAME__) && defined(IPV6CTL_MAPPED_ADDR) + int mib[4]; + size_t len; + int val; + + mib[0] = CTL_NET; + mib[1] = PF_INET6; + mib[2] = IPPROTO_IPV6; + mib[3] = IPV6CTL_MAPPED_ADDR; + len = sizeof(val); + if (__sysctl(mib, 4, &val, &len, 0, 0) == 0 && val != 0) + return 1; +#endif /* __KAME__ && IPV6CTL_MAPPED_ADDR */ + return 0; +} + +/* + * Functions defined in RFC2553 + * getipnodebyname, getipnodebyaddr, freehostent + */ + +static struct hostent * +_ghbyname(const char *name, int af, int flags, int *errp) +{ + struct hostent *hp; + int rval; + + static const ns_dtab dtab[] = { + NS_FILES_CB(_files_ghbyname, NULL) + { NSSRC_DNS, _dns_ghbyname, NULL }, + NS_NIS_CB(_nis_ghbyname, NULL) + { 0 } + }; + + if (flags & AI_ADDRCONFIG) { + int s; + + /* + * TODO: + * Note that implementation dependent test for address + * configuration should be done everytime called + * (or apropriate interval), + * because addresses will be dynamically assigned or deleted. + */ + if (af == AF_UNSPEC) { + if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + af = AF_INET; + else { + close(s); + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + af = AF_INET6; + else + close(s); + } + + } + if (af != AF_UNSPEC) { + if ((s = socket(af, SOCK_DGRAM, 0)) < 0) + return NULL; + close(s); + } + } + + rval = nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyname", default_src, + name, af, errp); + return (rval == NS_SUCCESS) ? hp : NULL; +} + +/* getipnodebyname() internal routine for multiple query(PF_UNSPEC) support. */ +struct hostent * +_getipnodebyname_multi(const char *name, int af, int flags, int *errp) +{ + struct hostent *hp; + union inx_addr addrbuf; + + /* XXX: PF_UNSPEC is only supposed to be passed from getaddrinfo() */ + if (af != AF_INET +#ifdef INET6 + && af != AF_INET6 +#endif + && af != PF_UNSPEC + ) + { + *errp = NO_RECOVERY; + return NULL; + } + +#ifdef INET6 + /* special case for literal address */ + if (inet_pton(AF_INET6, name, &addrbuf) == 1) { + if (af != AF_INET6) { + *errp = HOST_NOT_FOUND; + return NULL; + } + return _hpaddr(af, name, &addrbuf, errp); + } +#endif + if (inet_aton(name, (struct in_addr *)&addrbuf) == 1) { + if (af != AF_INET) { + if (MAPADDRENABLED(flags)) { + MAPADDR(&addrbuf, &addrbuf.in_addr); + } else { + *errp = HOST_NOT_FOUND; + return NULL; + } + } + return _hpaddr(af, name, &addrbuf, errp); + } + + *errp = HOST_NOT_FOUND; + hp = _ghbyname(name, af, flags, errp); + +#ifdef INET6 + if (af == AF_INET6 + && ((flags & AI_ALL) || hp == NULL) + && (MAPADDRENABLED(flags))) { + struct hostent *hp2 = _ghbyname(name, AF_INET, flags, errp); + if (hp == NULL) + hp = _hpmapv6(hp2, errp); + else { + if (hp2 && strcmp(hp->h_name, hp2->h_name) != 0) { + freehostent(hp2); + hp2 = NULL; + } + hp = _hpmerge(hp, hp2, errp); + } + } +#endif + return _hpsort(hp); +} + +struct hostent * +getipnodebyname(const char *name, int af, int flags, int *errp) +{ + if (af != AF_INET +#ifdef INET6 + && af != AF_INET6 +#endif + ) + { + *errp = NO_RECOVERY; + return NULL; + } + return(_getipnodebyname_multi(name, af ,flags, errp)); +} + +struct hostent * +getipnodebyaddr(const void *src, size_t len, int af, int *errp) +{ + struct hostent *hp; + int rval; +#ifdef INET6 + struct in6_addr addrbuf; +#else + struct in_addr addrbuf; +#endif + + static const ns_dtab dtab[] = { + NS_FILES_CB(_files_ghbyaddr, NULL) + { NSSRC_DNS, _dns_ghbyaddr, NULL }, + NS_NIS_CB(_nis_ghbyaddr, NULL) +#ifdef ICMPNL + { NSSRC_ICMP, _icmp_ghbyaddr, NULL }, +#endif + { 0 } + }; + + *errp = HOST_NOT_FOUND; + + switch (af) { + case AF_INET: + if (len != sizeof(struct in_addr)) { + *errp = NO_RECOVERY; + return NULL; + } + if ((long)src & ~(sizeof(struct in_addr) - 1)) { + memcpy(&addrbuf, src, len); + src = &addrbuf; + } + if (((struct in_addr *)src)->s_addr == 0) + return NULL; + break; +#ifdef INET6 + case AF_INET6: + if (len != sizeof(struct in6_addr)) { + *errp = NO_RECOVERY; + return NULL; + } + if ((long)src & ~(sizeof(struct in6_addr) / 2 - 1)) { /*XXX*/ + memcpy(&addrbuf, src, len); + src = &addrbuf; + } + if (IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *)src)) + return NULL; + if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src) + || IN6_IS_ADDR_V4COMPAT((struct in6_addr *)src)) { + src = (char *)src + + (sizeof(struct in6_addr) - sizeof(struct in_addr)); + af = AF_INET; + len = sizeof(struct in_addr); + } + break; +#endif + default: + *errp = NO_RECOVERY; + return NULL; + } + + rval = nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyaddr", default_src, + src, len, af, errp); + return (rval == NS_SUCCESS) ? hp : NULL; +} + +void +freehostent(struct hostent *ptr) +{ + free(ptr); +} + +#if 0 + +/* XXX: should be deprecated */ +struct hostent * +getnodebyname(const char *name, int af, int flags) +{ + return getipnodebyname(name, af, flags, &h_errno); +} + +#ifdef __warn_references +__warn_references(getnodebyname, + "warning: getnodebyname() deprecated, " + "should use getaddrinfo() or getipnodebyname()"); +#endif + +struct hostent * +getnodebyaddr(const void *src, size_t len, int af) +{ + return getipnodebyaddr(src, len, af, &h_errno); +} + +#ifdef __warn_references +__warn_references(getnodebyaddr, + "warning: getnodebyaddr() deprecated, " + "should use getnameinfo() or getipnodebyaddr()"); +#endif + +#endif + +/* + * Private utility functions + */ + +/* + * _hpcopy: allocate and copy hostent structure + */ +static struct hostent * +_hpcopy(struct hostent *hp, int *errp) +{ + struct hostent *nhp; + char *cp, **pp; + int size, addrsize; + int nalias = 0, naddr = 0; + int al_off; + int i; + + if (hp == NULL) + return hp; + + /* count size to be allocated */ + size = sizeof(struct hostent); + if (hp->h_name != NULL) + size += strlen(hp->h_name) + 1; + if ((pp = hp->h_aliases) != NULL) { + for (i = 0; *pp != NULL; i++, pp++) { + if (**pp != '\0') { + size += strlen(*pp) + 1; + nalias++; + } + } + } + /* adjust alignment */ +#ifdef ALIGN + size = ALIGN(size); +#endif + al_off = size; + size += sizeof(char *) * (nalias + 1); +#ifdef ALIGN + addrsize = ALIGN(hp->h_length); +#else + addrsize = hp->h_length; +#endif + + if ((pp = hp->h_addr_list) != NULL) { + while (*pp++ != NULL) + naddr++; + } + size += addrsize * naddr; + size += sizeof(char *) * (naddr + 1); + + /* copy */ + if ((nhp = (struct hostent *)malloc(size)) == NULL) { + *errp = TRY_AGAIN; + return NULL; + } + cp = (char *)&nhp[1]; + if (hp->h_name != NULL) { + nhp->h_name = cp; + strcpy(cp, hp->h_name); + cp += strlen(cp) + 1; + } else + nhp->h_name = NULL; + nhp->h_aliases = (char **)((char *)nhp + al_off); + if ((pp = hp->h_aliases) != NULL) { + for (i = 0; *pp != NULL; pp++) { + if (**pp != '\0') { + nhp->h_aliases[i++] = cp; + strcpy(cp, *pp); + cp += strlen(cp) + 1; + } + } + } + nhp->h_aliases[nalias] = NULL; + cp = (char *)&nhp->h_aliases[nalias + 1]; + nhp->h_addrtype = hp->h_addrtype; + nhp->h_length = hp->h_length; + nhp->h_addr_list = (char **)cp; + if ((pp = hp->h_addr_list) != NULL) { + cp = (char *)&nhp->h_addr_list[naddr + 1]; + for (i = 0; *pp != NULL; pp++) { + nhp->h_addr_list[i++] = cp; + memcpy(cp, *pp, hp->h_length); + cp += addrsize; + } + } + nhp->h_addr_list[naddr] = NULL; + return nhp; +} + +/* + * _hpaddr: construct hostent structure with one address + */ +static struct hostent * +_hpaddr(int af, const char *name, void *addr, int *errp) +{ + struct hostent *hp, hpbuf; + char *addrs[2]; + + hp = &hpbuf; + hp->h_name = (char *)name; + hp->h_aliases = NULL; + hp->h_addrtype = af; + hp->h_length = ADDRLEN(af); + hp->h_addr_list = addrs; + addrs[0] = (char *)addr; + addrs[1] = NULL; + return _hpcopy(hp, errp); +} + +/* + * _hpmerge: merge 2 hostent structure, arguments will be freed + */ +static struct hostent * +_hpmerge(struct hostent *hp1, struct hostent *hp2, int *errp) +{ + int i, j; + int naddr, nalias; + char **pp; + struct hostent *hp, hpbuf; + char *aliases[MAXALIASES + 1], *addrs[MAXADDRS + 1]; + union inx_addr addrbuf[MAXADDRS]; + + if (hp1 == NULL) + return hp2; + if (hp2 == NULL) + return hp1; + +#define HP(i) (i == 1 ? hp1 : hp2) + hp = &hpbuf; + hp->h_name = (hp1->h_name != NULL ? hp1->h_name : hp2->h_name); + hp->h_aliases = aliases; + nalias = 0; + for (i = 1; i <= 2; i++) { + if ((pp = HP(i)->h_aliases) == NULL) + continue; + for (; nalias < MAXALIASES && *pp != NULL; pp++) { + /* check duplicates */ + for (j = 0; j < nalias; j++) + if (strcasecmp(*pp, aliases[j]) == 0) + break; + if (j == nalias) + aliases[nalias++] = *pp; + } + } + aliases[nalias] = NULL; +#ifdef INET6 + if (hp1->h_length != hp2->h_length) { + hp->h_addrtype = AF_INET6; + hp->h_length = sizeof(struct in6_addr); + } else { +#endif + hp->h_addrtype = hp1->h_addrtype; + hp->h_length = hp1->h_length; +#ifdef INET6 + } +#endif + hp->h_addr_list = addrs; + naddr = 0; + for (i = 1; i <= 2; i++) { + if ((pp = HP(i)->h_addr_list) == NULL) + continue; + if (HP(i)->h_length == hp->h_length) { + while (naddr < MAXADDRS && *pp != NULL) + addrs[naddr++] = *pp++; + } else { + /* copy IPv4 addr as mapped IPv6 addr */ + while (naddr < MAXADDRS && *pp != NULL) { + MAPADDR(&addrbuf[naddr], *pp++); + addrs[naddr] = (char *)&addrbuf[naddr]; + naddr++; + } + } + } + addrs[naddr] = NULL; + hp = _hpcopy(hp, errp); + freehostent(hp1); + freehostent(hp2); + return hp; +} + +/* + * _hpmapv6: convert IPv4 hostent into IPv4-mapped IPv6 addresses + */ +#ifdef INET6 +static struct hostent * +_hpmapv6(struct hostent *hp, int *errp) +{ + struct hostent *hp6; + + if (hp == NULL) + return NULL; + if (hp->h_addrtype == AF_INET6) + return hp; + + /* make dummy hostent to convert IPv6 address */ + if ((hp6 = (struct hostent *)malloc(sizeof(struct hostent))) == NULL) { + *errp = TRY_AGAIN; + return NULL; + } + hp6->h_name = NULL; + hp6->h_aliases = NULL; + hp6->h_addrtype = AF_INET6; + hp6->h_length = sizeof(struct in6_addr); + hp6->h_addr_list = NULL; + return _hpmerge(hp6, hp, errp); +} +#endif + +/* + * _hpsort: sort address by sortlist + */ +static struct hostent * +_hpsort(struct hostent *hp) +{ + int i, j, n; + u_char *ap, *sp, *mp, **pp; + char t; + char order[MAXADDRS]; + int nsort = _res.nsort; + + if (hp == NULL || hp->h_addr_list[1] == NULL || nsort == 0) + return hp; + for (i = 0; (ap = (u_char *)hp->h_addr_list[i]); i++) { + for (j = 0; j < nsort; j++) { +#ifdef INET6 + if (_res_ext.sort_list[j].af != hp->h_addrtype) + continue; + sp = (u_char *)&_res_ext.sort_list[j].addr; + mp = (u_char *)&_res_ext.sort_list[j].mask; +#else + sp = (u_char *)&_res.sort_list[j].addr; + mp = (u_char *)&_res.sort_list[j].mask; +#endif + for (n = 0; n < hp->h_length; n++) { + if ((ap[n] & mp[n]) != sp[n]) + break; + } + if (n == hp->h_length) + break; + } + order[i] = j; + } + n = i; + pp = (u_char **)hp->h_addr_list; + for (i = 0; i < n - 1; i++) { + for (j = i + 1; j < n; j++) { + if (order[i] > order[j]) { + ap = pp[i]; + pp[i] = pp[j]; + pp[j] = ap; + t = order[i]; + order[i] = order[j]; + order[j] = t; + } + } + } + return hp; +} + +static char * +_hgetword(char **pp) +{ + char c, *p, *ret; + const char *sp; + static const char sep[] = "# \t\n"; + + ret = NULL; + for (p = *pp; (c = *p) != '\0'; p++) { + for (sp = sep; *sp != '\0'; sp++) { + if (c == *sp) + break; + } + if (c == '#') + p[1] = '\0'; /* ignore rest of line */ + if (ret == NULL) { + if (*sp == '\0') + ret = p; + } else { + if (*sp != '\0') { + *p++ = '\0'; + break; + } + } + } + *pp = p; + if (ret == NULL || *ret == '\0') + return NULL; + return ret; +} + +/* + * FILES (/etc/hosts) + */ + +static FILE * +_files_open(int *errp) +{ + FILE *fp; + fp = fopen(_PATH_HOSTS, "r"); + if (fp == NULL) + *errp = NO_RECOVERY; + return fp; +} + +static int +_files_ghbyname(void *rval, void *cb_data, va_list ap) +{ + const char *name; + int af; + int *errp; + int match, nalias; + char *p, *line, *addrstr, *cname; + FILE *fp; + struct hostent *rethp, *hp, hpbuf; + char *aliases[MAXALIASES + 1], *addrs[2]; + union inx_addr addrbuf; + char buf[BUFSIZ]; + int af0; + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + errp = va_arg(ap, int *); + + *(struct hostent **)rval = NULL; + + if ((fp = _files_open(errp)) == NULL) + return NS_UNAVAIL; + rethp = hp = NULL; + + af0 = af; + while (fgets(buf, sizeof(buf), fp)) { + line = buf; + if ((addrstr = _hgetword(&line)) == NULL + || (cname = _hgetword(&line)) == NULL) + continue; + match = (strcasecmp(cname, name) == 0); + nalias = 0; + while ((p = _hgetword(&line)) != NULL) { + if (!match) + match = (strcasecmp(p, name) == 0); + if (nalias < MAXALIASES) + aliases[nalias++] = p; + } + if (!match) + continue; + switch (af0) { + case AF_INET: + if (inet_aton(addrstr, (struct in_addr *)&addrbuf) + != 1) { + *errp = NO_DATA; /* name found */ + continue; + } + af = af0; + break; +#ifdef INET6 + case AF_INET6: + if (inet_pton(af, addrstr, &addrbuf) != 1) { + *errp = NO_DATA; /* name found */ + continue; + } + af = af0; + break; +#endif + case AF_UNSPEC: + if (inet_aton(addrstr, (struct in_addr *)&addrbuf) + == 1) { + af = AF_INET; + break; + } +#ifdef INET6 + if (inet_pton(AF_INET6, addrstr, &addrbuf) == 1) { + af = AF_INET6; + break; + } +#endif + *errp = NO_DATA; /* name found */ + continue; + /* NOTREACHED */ + } + hp = &hpbuf; + hp->h_name = cname; + hp->h_aliases = aliases; + aliases[nalias] = NULL; + hp->h_addrtype = af; + hp->h_length = ADDRLEN(af); + hp->h_addr_list = addrs; + addrs[0] = (char *)&addrbuf; + addrs[1] = NULL; + hp = _hpcopy(hp, errp); + rethp = _hpmerge(rethp, hp, errp); + } + fclose(fp); + *(struct hostent **)rval = rethp; + return (rethp != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +static int +_files_ghbyaddr(void *rval, void *cb_data, va_list ap) +{ + const void *addr; + int addrlen; + int af; + int *errp; + int nalias; + char *p, *line; + FILE *fp; + struct hostent *hp, hpbuf; + char *aliases[MAXALIASES + 1], *addrs[2]; + union inx_addr addrbuf; + char buf[BUFSIZ]; + + addr = va_arg(ap, const void *); + addrlen = va_arg(ap, int); + af = va_arg(ap, int); + errp = va_arg(ap, int *); + + *(struct hostent**)rval = NULL; + + if ((fp = _files_open(errp)) == NULL) + return NS_UNAVAIL; + hp = NULL; + while (fgets(buf, sizeof(buf), fp)) { + line = buf; + if ((p = _hgetword(&line)) == NULL + || (af == AF_INET + ? inet_aton(p, (struct in_addr *)&addrbuf) + : inet_pton(af, p, &addrbuf)) != 1 + || memcmp(addr, &addrbuf, addrlen) != 0 + || (p = _hgetword(&line)) == NULL) + continue; + hp = &hpbuf; + hp->h_name = p; + hp->h_aliases = aliases; + nalias = 0; + while ((p = _hgetword(&line)) != NULL) { + if (nalias < MAXALIASES) + aliases[nalias++] = p; + } + aliases[nalias] = NULL; + hp->h_addrtype = af; + hp->h_length = addrlen; + hp->h_addr_list = addrs; + addrs[0] = (char *)&addrbuf; + addrs[1] = NULL; + hp = _hpcopy(hp, errp); + break; + } + fclose(fp); + *(struct hostent **)rval = hp; + return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +#ifdef YP +/* + * NIS + * + * XXX actually a hack, these are INET4 specific. + */ +static int +_nis_ghbyname(void *rval, void *cb_data, va_list ap) +{ + const char *name; + int af; + int *errp; + struct hostent *hp = NULL; + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + errp = va_arg(ap, int *); + + if (af == AF_UNSPEC) + af = AF_INET; + if (af == AF_INET) { + hp = _gethostbynisname(name, af); + if (hp != NULL) + hp = _hpcopy(hp, errp); + } + + *(struct hostent **)rval = hp; + return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND; + +} + +static int +_nis_ghbyaddr(void *rval, void *cb_data, va_list ap) +{ + const void *addr; + int addrlen; + int af; + int *errp; + struct hostent *hp = NULL; + + addr = va_arg(ap, const void *); + addrlen = va_arg(ap, int); + af = va_arg(ap, int); + + if (af == AF_INET) { + hp = _gethostbynisaddr(addr, addrlen, af); + if (hp != NULL) + hp = _hpcopy(hp, errp); + } + *(struct hostent **)rval = hp; + return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} +#endif +typedef struct __res_type_list res_type_list; + +struct __res_type_list { + res_type_list * rtl_entry; + int rtl_type; +}; + +#if PACKETSZ > 1024 +#define MAXPACKET PACKETSZ +#else +#define MAXPACKET 1024 +#endif + +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +static struct hostent *getanswer(const querybuf *, int, const char *, int, + struct hostent *, int *); + +/* + * we don't need to take care about sorting, nor IPv4 mapped address here. + */ +static struct hostent * +getanswer(answer, anslen, qname, qtype, template, errp) + const querybuf *answer; + int anslen; + const char *qname; + int qtype; + struct hostent *template; + int *errp; +{ + const HEADER *hp; + const u_char *cp; + int n; + const u_char *eom, *erdata; + char *bp, **ap, **hap; + int type, class, buflen, ancount, qdcount; + int haveanswer, had_error; + char tbuf[MAXDNAME]; + const char *tname; + int (*name_ok)(const char *); + static char *h_addr_ptrs[MAXADDRS + 1]; + static char *host_aliases[MAXALIASES]; + static char hostbuf[8*1024]; + +#define BOUNDED_INCR(x) \ + do { \ + cp += x; \ + if (cp > eom) { \ + *errp = NO_RECOVERY; \ + return (NULL); \ + } \ + } while (0) + +#define BOUNDS_CHECK(ptr, count) \ + do { \ + if ((ptr) + (count) > eom) { \ + *errp = NO_RECOVERY; \ + return (NULL); \ + } \ + } while (0) + +/* XXX do {} while (0) cannot be put here */ +#define DNS_ASSERT(x) \ + { \ + if (!(x)) { \ + cp += n; \ + continue; \ + } \ + } + +/* XXX do {} while (0) cannot be put here */ +#define DNS_FATAL(x) \ + { \ + if (!(x)) { \ + had_error++; \ + continue; \ + } \ + } + + tname = qname; + template->h_name = NULL; + eom = answer->buf + anslen; + switch (qtype) { + case T_A: + case T_AAAA: + name_ok = res_hnok; + break; + case T_PTR: + name_ok = res_dnok; + break; + default: + return (NULL); /* XXX should be abort(); */ + } + /* + * find first satisfactory answer + */ + hp = &answer->hdr; + ancount = ntohs(hp->ancount); + qdcount = ntohs(hp->qdcount); + bp = hostbuf; + buflen = sizeof hostbuf; + cp = answer->buf; + BOUNDED_INCR(HFIXEDSZ); + if (qdcount != 1) { + *errp = NO_RECOVERY; + return (NULL); + } + n = dn_expand(answer->buf, eom, cp, bp, buflen); + if ((n < 0) || !(*name_ok)(bp)) { + *errp = NO_RECOVERY; + return (NULL); + } + BOUNDED_INCR(n + QFIXEDSZ); + if (qtype == T_A || qtype == T_AAAA) { + /* res_send() has already verified that the query name is the + * same as the one we sent; this just gets the expanded name + * (i.e., with the succeeding search-domain tacked on). + */ + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + *errp = NO_RECOVERY; + return (NULL); + } + template->h_name = bp; + bp += n; + buflen -= n; + /* The qname can be abbreviated, but h_name is now absolute. */ + qname = template->h_name; + } + ap = host_aliases; + *ap = NULL; + template->h_aliases = host_aliases; + hap = h_addr_ptrs; + *hap = NULL; + template->h_addr_list = h_addr_ptrs; + haveanswer = 0; + had_error = 0; + while (ancount-- > 0 && cp < eom && !had_error) { + n = dn_expand(answer->buf, eom, cp, bp, buflen); + DNS_FATAL(n >= 0); + DNS_FATAL((*name_ok)(bp)); + cp += n; /* name */ + BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ); + type = _getshort(cp); + cp += INT16SZ; /* type */ + class = _getshort(cp); + cp += INT16SZ + INT32SZ; /* class, TTL */ + n = _getshort(cp); + cp += INT16SZ; /* len */ + BOUNDS_CHECK(cp, n); + erdata = cp + n; + DNS_ASSERT(class == C_IN); + if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { + if (ap >= &host_aliases[MAXALIASES-1]) + continue; + n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + DNS_FATAL(n >= 0); + DNS_FATAL((*name_ok)(tbuf)); + cp += n; + if (cp != erdata) { + *errp = NO_RECOVERY; + return (NULL); + } + /* Store alias. */ + *ap++ = bp; + n = strlen(bp) + 1; /* for the \0 */ + DNS_FATAL(n < MAXHOSTNAMELEN); + bp += n; + buflen -= n; + /* Get canonical name. */ + n = strlen(tbuf) + 1; /* for the \0 */ + DNS_FATAL(n <= buflen); + DNS_FATAL(n < MAXHOSTNAMELEN); + strcpy(bp, tbuf); + template->h_name = bp; + bp += n; + buflen -= n; + continue; + } + if (qtype == T_PTR && type == T_CNAME) { + n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + if (n < 0 || !res_dnok(tbuf)) { + had_error++; + continue; + } + cp += n; + if (cp != erdata) { + *errp = NO_RECOVERY; + return (NULL); + } + /* Get canonical name. */ + n = strlen(tbuf) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } + strcpy(bp, tbuf); + tname = bp; + bp += n; + buflen -= n; + continue; + } + DNS_ASSERT(type == qtype); + switch (type) { + case T_PTR: + DNS_ASSERT(strcasecmp(tname, bp) == 0); + n = dn_expand(answer->buf, eom, cp, bp, buflen); + DNS_FATAL(n >= 0); + DNS_FATAL(res_hnok(bp)); +#if MULTI_PTRS_ARE_ALIASES + cp += n; + if (cp != erdata) { + *errp = NO_RECOVERY; + return (NULL); + } + if (!haveanswer) + template->h_name = bp; + else if (ap < &host_aliases[MAXALIASES-1]) + *ap++ = bp; + else + n = -1; + if (n != -1) { + n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + break; + } + bp += n; + buflen -= n; + } + break; +#else + template->h_name = bp; + *errp = NETDB_SUCCESS; + return (template); +#endif + case T_A: + case T_AAAA: + DNS_ASSERT(strcasecmp(template->h_name, bp) == 0); + DNS_ASSERT(n == template->h_length); + if (!haveanswer) { + int nn; + + template->h_name = bp; + nn = strlen(bp) + 1; /* for the \0 */ + bp += nn; + buflen -= nn; + } +#ifdef ALIGN + bp = (char *)ALIGN(bp); +#else + bp = (char *)(bp); +#endif + + DNS_FATAL(bp + n < &hostbuf[sizeof hostbuf]); + DNS_ASSERT(hap < &h_addr_ptrs[MAXADDRS-1]); +#ifdef FILTER_V4MAPPED + if (type == T_AAAA) { + struct in6_addr in6; + memcpy(&in6, cp, sizeof(in6)); + DNS_ASSERT(IN6_IS_ADDR_V4MAPPED(&in6) == 0); + } +#endif + bcopy(cp, *hap++ = bp, n); + bp += n; + buflen -= n; + cp += n; + if (cp != erdata) { + *errp = NO_RECOVERY; + return (NULL); + } + break; + default: + abort(); + } + if (!had_error) + haveanswer++; + } + if (haveanswer) { + *ap = NULL; + *hap = NULL; + if (!template->h_name) { + n = strlen(qname) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) + goto no_recovery; + strcpy(bp, qname); + template->h_name = bp; + bp += n; + buflen -= n; + } + *errp = NETDB_SUCCESS; + return (template); + } + no_recovery: + *errp = NO_RECOVERY; + return (NULL); + +#undef BOUNDED_INCR +#undef BOUNDS_CHECK +#undef DNS_ASSERT +#undef DNS_FATAL +} + +/* res_search() variant with multiple query support. */ +static struct hostent * +_res_search_multi(name, rtl, errp) + const char *name; /* domain name */ + struct __res_type_list *rtl; /* list of query types */ + int *errp; +{ + const char *cp, * const *domain; + struct hostent *hp0 = NULL, *hp; + struct hostent hpbuf; + u_int dots; + int trailing_dot, ret, saved_herrno; + int got_nodata = 0, got_servfail = 0, tried_as_is = 0; + struct __res_type_list *rtl0 = rtl; + querybuf buf; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + *errp = NETDB_INTERNAL; + return (NULL); + } + dots = 0; + for (cp = name; *cp; cp++) + dots += (*cp == '.'); + trailing_dot = 0; + if (cp > name && *--cp == '.') + trailing_dot++; + + /* If there aren't any dots, it could be a user-level alias */ + if (!dots && (cp = hostalias(name)) != NULL) { + for(rtl = rtl0; rtl != NULL; + rtl = rtl->rtl_entry) { + ret = res_query(cp, C_IN, rtl->rtl_type, buf.buf, + sizeof(buf.buf)); + if (ret > 0) { + hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA) + ? AF_INET6 : AF_INET; + hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype); + hp = getanswer(&buf, ret, name, rtl->rtl_type, + &hpbuf, errp); + if (!hp) + continue; + hp = _hpcopy(&hpbuf, errp); + hp0 = _hpmerge(hp0, hp, errp); + } + } + return (hp0); + } + + /* + * If there are dots in the name already, let's just give it a try + * 'as is'. The threshold can be set with the "ndots" option. + */ + saved_herrno = -1; + if (dots >= _res.ndots) { + for(rtl = rtl0; rtl != NULL; + rtl = rtl->rtl_entry) { + ret = res_querydomain(name, NULL, C_IN, rtl->rtl_type, + buf.buf, sizeof(buf.buf)); + if (ret > 0) { + hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA) + ? AF_INET6 : AF_INET; + hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype); + hp = getanswer(&buf, ret, name, rtl->rtl_type, + &hpbuf, errp); + if (!hp) + continue; + hp = _hpcopy(&hpbuf, errp); + hp0 = _hpmerge(hp0, hp, errp); + } + } + if (hp0 != NULL) + return (hp0); + saved_herrno = *errp; + tried_as_is++; + } + + /* + * We do at least one level of search if + * - there is no dot and RES_DEFNAME is set, or + * - there is at least one dot, there is no trailing dot, + * and RES_DNSRCH is set. + */ + if ((!dots && (_res.options & RES_DEFNAMES)) || + (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { + int done = 0; + + for (domain = (const char * const *)_res.dnsrch; + *domain && !done; + domain++) { + + for(rtl = rtl0; rtl != NULL; + rtl = rtl->rtl_entry) { + ret = res_querydomain(name, *domain, C_IN, + rtl->rtl_type, + buf.buf, sizeof(buf.buf)); + if (ret > 0) { + hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA) + ? AF_INET6 : AF_INET; + hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype); + hp = getanswer(&buf, ret, name, + rtl->rtl_type, &hpbuf, errp); + if (!hp) + continue; + hp = _hpcopy(&hpbuf, errp); + hp0 = _hpmerge(hp0, hp, errp); + } + } + if (hp0 != NULL) + return (hp0); + + /* + * If no server present, give up. + * If name isn't found in this domain, + * keep trying higher domains in the search list + * (if that's enabled). + * On a NO_DATA error, keep trying, otherwise + * a wildcard entry of another type could keep us + * from finding this entry higher in the domain. + * If we get some other error (negative answer or + * server failure), then stop searching up, + * but try the input name below in case it's + * fully-qualified. + */ + if (errno == ECONNREFUSED) { + *errp = TRY_AGAIN; + return (NULL); + } + + switch (*errp) { + case NO_DATA: + got_nodata++; + /* FALLTHROUGH */ + case HOST_NOT_FOUND: + /* keep trying */ + break; + case TRY_AGAIN: + if (buf.hdr.rcode == SERVFAIL) { + /* try next search element, if any */ + got_servfail++; + break; + } + /* FALLTHROUGH */ + default: + /* anything else implies that we're done */ + done++; + } + + /* if we got here for some reason other than DNSRCH, + * we only wanted one iteration of the loop, so stop. + */ + if (!(_res.options & RES_DNSRCH)) + done++; + } + } + + /* + * If we have not already tried the name "as is", do that now. + * note that we do this regardless of how many dots were in the + * name or whether it ends with a dot unless NOTLDQUERY is set. + */ + if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) { + for(rtl = rtl0; rtl != NULL; + rtl = rtl->rtl_entry) { + ret = res_querydomain(name, NULL, C_IN, rtl->rtl_type, + buf.buf, sizeof(buf.buf)); + if (ret > 0) { + hpbuf.h_addrtype = (rtl->rtl_type == T_AAAA) + ? AF_INET6 : AF_INET; + hpbuf.h_length = ADDRLEN(hpbuf.h_addrtype); + hp = getanswer(&buf, ret, name, rtl->rtl_type, + &hpbuf, errp); + if (!hp) + continue; + hp = _hpcopy(&hpbuf, errp); + hp0 = _hpmerge(hp0, hp, errp); + } + } + if (hp0 != NULL) + return (hp0); + } + + /* if we got here, we didn't satisfy the search. + * if we did an initial full query, return that query's h_errno + * (note that we wouldn't be here if that query had succeeded). + * else if we ever got a nodata, send that back as the reason. + * else send back meaningless h_errno, that being the one from + * the last DNSRCH we did. + */ + if (saved_herrno != -1) + *errp = saved_herrno; + else if (got_nodata) + *errp = NO_DATA; + else if (got_servfail) + *errp = TRY_AGAIN; + return (NULL); +} + +static int +_dns_ghbyname(void *rval, void *cb_data, va_list ap) +{ + const char *name; + int af; + int *errp; + res_type_list *rtl, rtl4; +#ifdef INET6 + res_type_list rtl6; +#endif + + name = va_arg(ap, const char *); + af = va_arg(ap, int); + errp = va_arg(ap, int *); + +#ifdef INET6 + switch (af) { + case AF_UNSPEC: + rtl4.rtl_entry = NULL; rtl4.rtl_type = T_A; + rtl6.rtl_entry = &rtl4; rtl6.rtl_type = T_AAAA; + rtl = &rtl6; + break; + case AF_INET6: + rtl6.rtl_entry = NULL; rtl6.rtl_type = T_AAAA; + rtl = &rtl6; + break; + case AF_INET: + rtl4.rtl_entry = NULL; rtl4.rtl_type = T_A; + rtl = &rtl4; + break; + } +#else + (&rtl4)->rtl_entry = NULL; + rtl4.rtl_type = T_A; + rtl = &rtl4; +#endif + *(struct hostent **)rval = _res_search_multi(name, rtl, errp); + return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; +} + +static int +_dns_ghbyaddr(void *rval, void *cb_data, va_list ap) +{ + const void *addr; + int addrlen; + int af; + int *errp; + int n; + struct hostent *hp; + u_char c, *cp; + char *bp; + struct hostent hbuf; + int na; +#ifdef INET6 + static const char hex[] = "0123456789abcdef"; +#endif + querybuf buf; + char qbuf[MAXDNAME+1]; + char *hlist[2]; + + addr = va_arg(ap, const void *); + addrlen = va_arg(ap, int); + af = va_arg(ap, int); + errp = va_arg(ap, int *); + + *(struct hostent **)rval = NULL; + +#ifdef INET6 + /* XXX */ + if (af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr)) + return NS_NOTFOUND; +#endif + + if ((_res.options & RES_INIT) == 0) { + if (res_init() < 0) { + *errp = h_errno; + return NS_UNAVAIL; + } + } + memset(&hbuf, 0, sizeof(hbuf)); + hbuf.h_name = NULL; + hbuf.h_addrtype = af; + hbuf.h_length = addrlen; + na = 0; + + /* XXX assumes that MAXDNAME is big enough */ + n = 0; + bp = qbuf; + cp = (u_char *)addr+addrlen-1; + switch (af) { +#ifdef INET6 + case AF_INET6: + for (; n < addrlen; n++, cp--) { + c = *cp; + *bp++ = hex[c & 0xf]; + *bp++ = '.'; + *bp++ = hex[c >> 4]; + *bp++ = '.'; + } + strcpy(bp, "ip6.int"); + break; +#endif + default: + for (; n < addrlen; n++, cp--) { + c = *cp; + if (c >= 100) + *bp++ = '0' + c / 100; + if (c >= 10) + *bp++ = '0' + (c % 100) / 10; + *bp++ = '0' + c % 10; + *bp++ = '.'; + } + strcpy(bp, "in-addr.arpa"); + break; + } + + n = res_query(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf); + if (n < 0) { + *errp = h_errno; + return NS_UNAVAIL; + } + hp = getanswer(&buf, n, qbuf, T_PTR, &hbuf, errp); + if (!hp) + return NS_NOTFOUND; + hbuf.h_addrtype = af; + hbuf.h_length = addrlen; + hbuf.h_addr_list = hlist; + hlist[0] = (char *)addr; + hlist[1] = NULL; + *(struct hostent **)rval = _hpcopy(&hbuf, errp); + return NS_SUCCESS; +} + +#if 0 // keep gcc happy +static void +_dns_shent(int stayopen) +{ + if ((_res.options & RES_INIT) == 0) { + if (res_init() < 0) + return; + } + if (stayopen) + _res.options |= RES_STAYOPEN | RES_USEVC; +} + +static void +_dns_ehent(void) +{ + _res.options &= ~(RES_STAYOPEN | RES_USEVC); + res_close(); +} +#endif + +#ifdef ICMPNL + +/* + * experimental: + * draft-ietf-ipngwg-icmp-namelookups-02.txt + * ifindex is assumed to be encoded in addr. + */ +#include +#include +#include + +struct _icmp_host_cache { + struct _icmp_host_cache *hc_next; + int hc_ifindex; + struct in6_addr hc_addr; + char *hc_name; +}; + +static char * +_icmp_fqdn_query(const struct in6_addr *addr, int ifindex) +{ + int s; + struct icmp6_filter filter; + struct msghdr msg; + struct cmsghdr *cmsg; + struct in6_pktinfo *pkt; + char cbuf[256]; + char buf[1024]; + int cc; + struct icmp6_fqdn_query *fq; + struct icmp6_fqdn_reply *fr; + struct _icmp_host_cache *hc; + struct sockaddr_in6 sin6; + struct iovec iov; + fd_set s_fds, fds; + struct timeval tout; + int len; + char *name; + static int pid; + static struct _icmp_host_cache *hc_head; + + for (hc = hc_head; hc; hc = hc->hc_next) { + if (hc->hc_ifindex == ifindex + && IN6_ARE_ADDR_EQUAL(&hc->hc_addr, addr)) + return hc->hc_name; + } + + if (pid == 0) + pid = getpid(); + + ICMP6_FILTER_SETBLOCKALL(&filter); + ICMP6_FILTER_SETPASS(ICMP6_FQDN_REPLY, &filter); + + FD_ZERO(&s_fds); + tout.tv_sec = 0; + tout.tv_usec = 200000; /*XXX: 200ms*/ + + fq = (struct icmp6_fqdn_query *)buf; + fq->icmp6_fqdn_type = ICMP6_FQDN_QUERY; + fq->icmp6_fqdn_code = 0; + fq->icmp6_fqdn_cksum = 0; + fq->icmp6_fqdn_id = (u_short)pid; + fq->icmp6_fqdn_unused = 0; + fq->icmp6_fqdn_cookie[0] = 0; + fq->icmp6_fqdn_cookie[1] = 0; + + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = *addr; + + memset(&msg, 0, sizeof(msg)); + msg.msg_name = (caddr_t)&sin6; + msg.msg_namelen = sizeof(sin6); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + iov.iov_base = (caddr_t)buf; + iov.iov_len = sizeof(struct icmp6_fqdn_query); + + if (ifindex) { + msg.msg_control = cbuf; + msg.msg_controllen = sizeof(cbuf); + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); + cmsg->cmsg_level = IPPROTO_IPV6; + cmsg->cmsg_type = IPV6_PKTINFO; + pkt = (struct in6_pktinfo *)&cmsg[1]; + memset(&pkt->ipi6_addr, 0, sizeof(struct in6_addr)); + pkt->ipi6_ifindex = ifindex; + cmsg = CMSG_NXTHDR(&msg, cmsg); + msg.msg_controllen = (char *)cmsg - cbuf; + } + + if ((s = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) + return NULL; + (void)setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, + (char *)&filter, sizeof(filter)); + cc = _sendmsg(s, &msg, 0); + if (cc < 0) { + close(s); + return NULL; + } + FD_SET(s, &s_fds); + for (;;) { + fds = s_fds; + if (select(s + 1, &fds, NULL, NULL, &tout) <= 0) { + close(s); + return NULL; + } + len = sizeof(sin6); + cc = _recvfrom(s, buf, sizeof(buf), 0, + (struct sockaddr *)&sin6, &len); + if (cc <= 0) { + close(s); + return NULL; + } + if (cc < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) + continue; + if (!IN6_ARE_ADDR_EQUAL(addr, &sin6.sin6_addr)) + continue; + fr = (struct icmp6_fqdn_reply *)(buf + sizeof(struct ip6_hdr)); + if (fr->icmp6_fqdn_type == ICMP6_FQDN_REPLY) + break; + } + close(s); + if (fr->icmp6_fqdn_cookie[1] != 0) { + /* rfc1788 type */ + name = buf + sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr) + 4; + len = (buf + cc) - name; + } else { + len = fr->icmp6_fqdn_namelen; + name = fr->icmp6_fqdn_name; + } + if (len <= 0) + return NULL; + name[len] = 0; + + if ((hc = (struct _icmp_host_cache *)malloc(sizeof(*hc))) == NULL) + return NULL; + /* XXX: limit number of cached entries */ + hc->hc_ifindex = ifindex; + hc->hc_addr = *addr; + hc->hc_name = strdup(name); + hc->hc_next = hc_head; + hc_head = hc; + return hc->hc_name; +} + +static struct hostent * +_icmp_ghbyaddr(const void *addr, int addrlen, int af, int *errp) +{ + char *hname; + int ifindex; + struct in6_addr addr6; + + if (af != AF_INET6) { + /* + * Note: rfc1788 defines Who Are You for IPv4, + * but no one implements it. + */ + return NULL; + } + + memcpy(&addr6, addr, addrlen); + ifindex = (addr6.s6_addr[2] << 8) | addr6.s6_addr[3]; + addr6.s6_addr[2] = addr6.s6_addr[3] = 0; + + if (!IN6_IS_ADDR_LINKLOCAL(&addr6)) + return NULL; /*XXX*/ + + if ((hname = _icmp_fqdn_query(&addr6, ifindex)) == NULL) + return NULL; + return _hpaddr(af, hname, &addr6, errp); +} +#endif /* ICMPNL */ diff --git a/newlib/libc/sys/linux/net/namespace.h b/newlib/libc/sys/linux/net/namespace.h new file mode 100644 index 000000000..291aad580 --- /dev/null +++ b/newlib/libc/sys/linux/net/namespace.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libc/include/namespace.h,v 1.9 2002/03/29 22:43:42 markm Exp $ + */ + +#ifndef _NAMESPACE_H_ +#define _NAMESPACE_H_ + +/* + * Adjust names so that headers declare "hidden" names. + */ + +/* + * ISO C (C90) section. Most names in libc aren't in ISO C, so they + * should be here. Most aren't here... + */ +#define err _err +#define warn _warn + +/* + * Prototypes for syscalls/functions that need to be overridden + * in libc_r/libpthread. + */ +#define accept _accept +#define __acl_aclcheck_fd ___acl_aclcheck_fd +#define __acl_delete_fd ___acl_delete_fd +#define __acl_get_fd ___acl_get_fd +#define __acl_set_fd ___acl_set_fd +#define bind _bind +#define __cap_get_fd ___cap_get_fd +#define __cap_set_fd ___cap_set_fd +#define close _close +#define connect _connect +#define dup _dup +#define dup2 _dup2 +#define execve _execve +#define fcntl _fcntl +/*#define flock _flock */ +#define fstat _fstat +#define fstatfs _fstatfs +#define fsync _fsync +#define getdirentries _getdirentries +#define getlogin _getlogin +#define getpeername _getpeername +#define getprogname _getprogname +#define getsockname _getsockname +#define getsockopt _getsockopt +#define ioctl _ioctl +#define listen _listen +#define nanosleep _nanosleep +#define open _open +#define poll _poll +#define pthread_cond_signal _pthread_cond_signal +#define pthread_cond_wait _pthread_cond_wait +#define pthread_cond_init _pthread_cond_init +#define pthread_exit _pthread_exit +#define pthread_getspecific _pthread_getspecific +#define pthread_key_create _pthread_key_create +#define pthread_key_delete _pthread_key_delete +#define pthread_main_np _pthread_main_np +#define pthread_mutex_destroy _pthread_mutex_destroy +#define pthread_mutex_init _pthread_mutex_init +#define pthread_mutex_lock _pthread_mutex_lock +#define pthread_mutex_trylock _pthread_mutex_trylock +#define pthread_mutex_unlock _pthread_mutex_unlock +#define pthread_mutexattr_init _pthread_mutexattr_init +#define pthread_mutexattr_destroy _pthread_mutexattr_destroy +#define pthread_mutexattr_settype _pthread_mutexattr_settype +#define pthread_once _pthread_once +#define pthread_rwlock_init _pthread_rwlock_init +#define pthread_rwlock_rdlock _pthread_rwlock_rdlock +#define pthread_rwlock_wrlock _pthread_rwlock_wrlock +#define pthread_rwlock_unlock _pthread_rwlock_unlock +#define pthread_self _pthread_self +#define pthread_setspecific _pthread_setspecific +#define pthread_sigmask _pthread_sigmask +#define read _read +#define readv _readv +#define recvfrom _recvfrom +#define recvmsg _recvmsg +#define select _select +#define sendmsg _sendmsg +#define sendto _sendto +#define setsockopt _setsockopt +/*#define sigaction _sigaction*/ +#define sigprocmask _sigprocmask +#define sigsuspend _sigsuspend +#define socket _socket +#define socketpair _socketpair +#define wait4 _wait4 +#define write _write +#define writev _writev + + +/* + * Other hidden syscalls/functions that libc_r needs to override + * but are not used internally by libc. + * + * XXX - When modifying libc to use one of the following, remove + * the prototype from below and place it in the list above. + */ +#if 0 +#define creat _creat +#define fchflags _fchflags +#define fchmod _fchmod +#define fpathconf _fpathconf +#define msync _msync +#define nfssvc _nfssvc +#define pause _pause +#define pthread_rwlock_destroy _pthread_rwlock_destroy +#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock +#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock +#define pthread_rwlockattr_init _pthread_rwlockattr_init +#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy +#define sched_yield _sched_yield +#define sendfile _sendfile +#define shutdown _shutdown +#define sigaltstack _sigaltstack +#define sigpending _sigpending +#define sigreturn _sigreturn +#define sigsetmask _sigsetmask +#define sleep _sleep +#define system _system +#define tcdrain _tcdrain +#define wait _wait +#define waitpid _waitpid +#endif + +#endif /* _NAMESPACE_H_ */ diff --git a/newlib/libc/sys/linux/net/netgroup.h b/newlib/libc/sys/linux/net/netgroup.h deleted file mode 100644 index c6b77ba52..000000000 --- a/newlib/libc/sys/linux/net/netgroup.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Internal header for netgroup related functions. - Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _NETGROUP_H -#define _NETGROUP_H 1 - -#include - -/* A netgroup can consist of names of other netgroups. We have to - track which netgroups were read and which still have to be read. */ -struct name_list -{ - struct name_list *next; - char name[0]; -}; - - -/* Dataset for iterating netgroups. */ -struct __netgrent -{ - enum { triple_val, group_val } type; - - union - { - struct - { - const char *host; - const char *user; - const char *domain; - } - triple; - - const char *group; - } val; - - /* Room for the data kept between the calls to the netgroup - functions. We must avoid global variables. */ - char *data; - size_t data_size; - union - { - char *cursor; - unsigned long int position; - }; - int first; - - struct name_list *known_groups; - struct name_list *needed_groups; - - /* This handle for the NSS data base is shared between all - set/get/endXXXent functions. */ - service_user *nip; -}; - - -/* The internal netgroup handling functions might be called from outside. */ -extern int __internal_setnetgrent (const char *group, - struct __netgrent *datap); -extern void __internal_endnetgrent (struct __netgrent *datap); -extern int __internal_getnetgrent_r (char **hostp, char **userp, - char **domainp, struct __netgrent *datap, - char *buffer, size_t buflen, int *errnop); - -#endif /* netgroup.h */ diff --git a/newlib/libc/sys/linux/net/netgrp-lookup.c b/newlib/libc/sys/linux/net/netgrp-lookup.c deleted file mode 100644 index 526755a53..000000000 --- a/newlib/libc/sys/linux/net/netgrp-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME netgroup - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/network-lookup.c b/newlib/libc/sys/linux/net/network-lookup.c deleted file mode 100644 index 8bfaab8dd..000000000 --- a/newlib/libc/sys/linux/net/network-lookup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME networks -#define DEFAULT_CONFIG "dns [!UNAVAIL=return] files" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/not-cancel.h b/newlib/libc/sys/linux/net/not-cancel.h deleted file mode 100644 index 9dd7d30bb..000000000 --- a/newlib/libc/sys/linux/net/not-cancel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Uncancelable versions of cancelable interfaces. Linux version. - Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* Uncancelable open. */ -#define open_not_cancel(name, flags, mode) open((name), (flags), (mode)) -#define open_not_cancel_2(name, flags) open((name), (flags)) - -/* Uncancelable close. */ -#define close_not_cancel(fd) close((fd)) -#define close_not_cancel_no_status(fd) (void)close((fd)) - -/* Uncancelable read. */ -#define read_not_cancel(fd, buf, n) read((fd), (buf), (n)) - -/* Uncancelable write. */ -#define write_not_cancel(fd, buf, n) write((fd), (buf), (n)) - -/* Uncancelable writev. */ -#define writev_not_cancel_no_status(fd, iov, n) \ - (void) writev((fd), (iov), (n)) - -/* Uncancelable fcntl. */ -#define fcntl_not_cancel(fd, cmd, val) fcntl((fd), (cmd), (val)) - -/* Uncancelable waitpid. */ -#ifdef __NR_waitpid -# define waitpid_not_cancel(pid, stat_loc, options) \ - waitpid((pid), (stat_loc), (options)) -#else -# define waitpid_not_cancel(pid, stat_loc, options) \ - wait4((pid), (stat_loc), (options), NULL) -#endif diff --git a/newlib/libc/sys/linux/net/ns.3 b/newlib/libc/sys/linux/net/ns.3 new file mode 100644 index 000000000..be8d155c3 --- /dev/null +++ b/newlib/libc/sys/linux/net/ns.3 @@ -0,0 +1,133 @@ +.\" Copyright (c) 1986, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)ns.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/ns.3,v 1.10 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt NS 3 +.Os +.Sh NAME +.Nm ns_addr , +.Nm ns_ntoa +.Nd Xerox +.Tn NS Ns (tm) +address conversion routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netns/ns.h +.Ft struct ns_addr +.Fn ns_addr "char *cp" +.Ft char * +.Fn ns_ntoa "struct ns_addr ns" +.Sh DESCRIPTION +The routine +.Fn ns_addr +interprets character strings representing +.Tn XNS +addresses, returning binary information suitable +for use in system calls. +The routine +.Fn ns_ntoa +takes +.Tn XNS +addresses and returns +.Tn ASCII +strings representing the address in a +notation in common use in the Xerox Development Environment: +.Bd -ragged -offset indent +.. +.Ed +.Pp +Trailing zero fields are suppressed, and each number is printed in hexadecimal, +in a format suitable for input to +.Fn ns_addr . +Any fields lacking super-decimal digits will have a +trailing +.Ql H +appended. +.Pp +Unfortunately, no universal standard exists for representing +.Tn XNS +addresses. +An effort has been made to insure that +.Fn ns_addr +be compatible with most formats in common use. +It will first separate an address into 1 to 3 fields using a single delimiter +chosen from +period +.Ql \&. , +colon +.Ql \&: +or pound-sign +.Ql \&# . +Each field is then examined for byte separators (colon or period). +If there are byte separators, each subfield separated is taken to be +a small hexadecimal number, and the entirety is taken as a network-byte-ordered +quantity to be zero extended in the high-network-order bytes. +Next, the field is inspected for hyphens, in which case +the field is assumed to be a number in decimal notation +with hyphens separating the millenia. +Next, the field is assumed to be a number: +It is interpreted +as hexadecimal if there is a leading +.Ql 0x +(as in C), +a trailing +.Ql H +(as in Mesa), or there are any super-decimal digits present. +It is interpreted as octal is there is a leading +.Ql 0 +and there are no super-octal digits. +Otherwise, it is converted as a decimal number. +.Sh RETURN VALUES +None. (See +.Sx BUGS . ) +.Sh SEE ALSO +.Xr hosts 5 , +.Xr networks 5 +.Sh HISTORY +The +.Fn ns_addr +and +.Fn ns_toa +functions appeared in +.Bx 4.3 . +.Sh BUGS +The string returned by +.Fn ns_ntoa +resides in a static memory area. +The function +.Fn ns_addr +should diagnose improperly formed input, and there should be an unambiguous +way to recognize this. diff --git a/newlib/libc/sys/linux/net/ns_addr.c b/newlib/libc/sys/linux/net/ns_addr.c new file mode 100644 index 000000000..a86cf31b7 --- /dev/null +++ b/newlib/libc/sys/linux/net/ns_addr.c @@ -0,0 +1,239 @@ +/* + * Copyright (c) 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * J.Q. Johnson. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include + +#include +#include +#include +#include +#include + +static struct ns_addr addr, zero_addr; + +static void Field(), cvtbase(); + +struct ns_addr +ns_addr(name) + const char *name; +{ + char separator; + char *hostname, *socketname, *cp; + char buf[50]; + + (void)strncpy(buf, name, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + + /* + * First, figure out what he intends as a field separtor. + * Despite the way this routine is written, the preferred + * form 2-272.AA001234H.01777, i.e. XDE standard. + * Great efforts are made to insure backward compatibility. + */ + if ((hostname = strchr(buf, '#')) != NULL) + separator = '#'; + else { + hostname = strchr(buf, '.'); + if ((cp = strchr(buf, ':')) && + ((hostname && cp < hostname) || (hostname == 0))) { + hostname = cp; + separator = ':'; + } else + separator = '.'; + } + if (hostname) + *hostname++ = 0; + + addr = zero_addr; + Field(buf, addr.x_net.c_net, 4); + if (hostname == 0) + return (addr); /* No separator means net only */ + + socketname = strchr(hostname, separator); + if (socketname) { + *socketname++ = 0; + Field(socketname, (u_char *)&addr.x_port, 2); + } + + Field(hostname, addr.x_host.c_host, 6); + + return (addr); +} + +static void +Field(buf, out, len) + char *buf; + u_char *out; + int len; +{ + char *bp = buf; + int i, ibase, base16 = 0, base10 = 0, clen = 0; + int hb[6], *hp; + + /* + * first try 2-273#2-852-151-014#socket + */ + if ((*buf != '-') && + (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d", + &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) { + cvtbase(1000L, 256, hb, i, out, len); + return; + } + /* + * try form 8E1#0.0.AA.0.5E.E6#socket + */ + if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x", + &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { + cvtbase(256L, 256, hb, i, out, len); + return; + } + /* + * try form 8E1#0:0:AA:0:5E:E6#socket + */ + if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x", + &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { + cvtbase(256L, 256, hb, i, out, len); + return; + } + /* + * This is REALLY stretching it but there was a + * comma notation separting shorts -- definitely non standard + */ + if (1 < (i = sscanf(buf,"%x,%x,%x", + &hb[0], &hb[1], &hb[2]))) { + hb[0] = htons(hb[0]); hb[1] = htons(hb[1]); + hb[2] = htons(hb[2]); + cvtbase(65536L, 256, hb, i, out, len); + return; + } + + /* Need to decide if base 10, 16 or 8 */ + while (*bp) switch (*bp++) { + + case '0': case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '-': + break; + + case '8': case '9': + base10 = 1; + break; + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + base16 = 1; + break; + + case 'x': case 'X': + *--bp = '0'; + base16 = 1; + break; + + case 'h': case 'H': + base16 = 1; + /* fall into */ + + default: + *--bp = 0; /* Ends Loop */ + } + if (base16) { + ibase = 4096; + } else if (base10 == 0 && *buf == '0') { + ibase = 512; + } else { + base10 = 1; + ibase = 1000; + } + + for (bp = buf; *bp++; ) clen++; + if (clen == 0) clen++; + if (clen > 18) clen = 18; + i = ((clen - 1) / 3) + 1; + bp = clen + buf - 3; + hp = hb + i - 1; + + while (hp > hb) { + if (base16) + (void)sscanf(bp, "%3x", hp); + else if (base10) + (void)sscanf(bp, "%3d", hp); + else + (void)sscanf(bp, "%3o", hp); + + bp[0] = 0; + hp--; + bp -= 3; + } + if (base16) + (void)sscanf(buf, "%3x", hp); + else if (base10) + (void)sscanf(buf, "%3d", hp); + else + (void)sscanf(buf, "%3o", hp); + + cvtbase((long)ibase, 256, hb, i, out, len); +} + +static void +cvtbase(oldbase,newbase,input,inlen,result,reslen) + long oldbase; + int newbase; + int input[]; + int inlen; + unsigned char result[]; + int reslen; +{ + int d, e; + long sum; + + e = 1; + while (e > 0 && reslen > 0) { + d = 0; e = 0; sum = 0; + /* long division: input=input/newbase */ + while (d < inlen) { + sum = sum*oldbase + (long) input[d]; + e += (sum > 0); + input[d++] = sum / newbase; + sum %= newbase; + } + result[--reslen] = sum; /* accumulate remainder */ + } + for (d=0; d < reslen; d++) + result[d] = 0; +} diff --git a/newlib/libc/sys/linux/net/ns_name.c b/newlib/libc/sys/linux/net/ns_name.c index d6c4cc8b5..609df14f5 100644 --- a/newlib/libc/sys/linux/net/ns_name.c +++ b/newlib/libc/sys/linux/net/ns_name.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,25 +15,21 @@ * SOFTWARE. */ -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_name.c,v 8.15 2000/03/30 22:53:46 vixie Exp $"; -#endif +#include +#include #include #include #include -#include #include #include #include -#include -#include "libc-symbols.h" /* Data. */ -static const char digits[] = "0123456789"; +static char digits[] = "0123456789"; /* Forward. */ @@ -66,57 +62,34 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { eom = dst + dstsiz; while ((n = *cp++) != 0) { - if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) { + if ((n & NS_CMPRSFLGS) != 0) { /* Some kind of compression pointer. */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } if (dn != dst) { if (dn >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = '.'; } - - if (n == 0x41) { - n = *cp++ / 8; - if (dn + n * 2 + 4 >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - *dn++ = '\\'; - *dn++ = '['; - *dn++ = 'x'; - - while (n-- > 0) { - c = *cp++; - unsigned u = c >> 4; - *dn++ = u > 9 ? 'a' + u - 10 : '0' + u; - u = c & 0xf; - *dn++ = u > 9 ? 'a' + u - 10 : '0' + u; - } - - *dn++ = ']'; - continue; - } - if (dn + n >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } for ((void)NULL; n > 0; n--) { c = *cp++; if (special(c)) { if (dn + 1 >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = '\\'; *dn++ = (char)c; } else if (!printable(c)) { if (dn + 3 >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = '\\'; @@ -125,7 +98,7 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { *dn++ = digits[c % 10]; } else { if (dn >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = (char)c; @@ -134,19 +107,18 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { } if (dn == dst) { if (dn >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = '.'; } if (dn >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *dn++ = '\0'; return (dn - dst); } -libresolv_hidden_def (ns_name_ntop) /* * ns_name_pton(src, dst, dstsiz) @@ -176,56 +148,21 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { n = (cp - digits) * 100; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } n += (cp - digits) * 10; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } n += (cp - digits); if (n > 255) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } c = n; - } else if (c == '[' && label == bp - 1 && *src == 'x') { - /* Theoretically we would have to handle \[o - as well but we do not since we do not need - it internally. */ - *label = 0x41; - label = bp++; - ++src; - while (isxdigit (*src)) { - n = *src > '9' ? *src - 'a' + 10 : *src - '0'; - ++src; - if (! isxdigit(*src)) { - __set_errno (EMSGSIZE); - return (-1); - } - n <<= 4; - n += *src > '9' ? *src - 'a' + 10 : *src - '0'; - if (bp + 1 >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - *bp++ = n; - ++src; - } - *label = (bp - label - 1) * 8; - if (*src++ != ']' || *src++ != '.') { - __set_errno (EMSGSIZE); - return (-1); - } - escaped = 0; - label = bp++; - if (bp >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - continue; } escaped = 0; } else if (c == '\\') { @@ -234,11 +171,11 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { } else if (c == '.') { c = (bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } if (label >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *label = c; @@ -246,97 +183,54 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { if (*src == '\0') { if (c != 0) { if (bp >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *bp++ = '\0'; } if ((bp - dst) > MAXCDNAME) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } return (1); } - if (c == 0 || *src == '.') { - __set_errno (EMSGSIZE); + if (c == 0) { + errno = EMSGSIZE; return (-1); } label = bp++; continue; } if (bp >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *bp++ = (u_char)c; } c = (bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } if (label >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *label = c; if (c != 0) { if (bp >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *bp++ = 0; } if ((bp - dst) > MAXCDNAME) { /* src too big */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } return (0); } -/* - * ns_name_ntol(src, dst, dstsiz) - * Convert a network strings labels into all lowercase. - * return: - * Number of bytes written to buffer, or -1 (with errno set) - * notes: - * Enforces label and domain length limits. - */ - -int -ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) { - const u_char *cp; - u_char *dn, *eom; - u_char c; - u_int n; - - cp = src; - dn = dst; - eom = dst + dstsiz; - - while ((n = *cp++) != 0) { - if ((n & NS_CMPRSFLGS) != 0) { - /* Some kind of compression pointer. */ - __set_errno (EMSGSIZE); - return (-1); - } - *dn++ = n; - if (dn + n >= eom) { - __set_errno (EMSGSIZE); - return (-1); - } - for ((void)NULL; n > 0; n--) { - c = *cp++; - if (isupper(c)) - *dn++ = tolower(c); - else - *dn++ = c; - } - } - *dn++ = '\0'; - return (dn - dst); -} - /* * ns_name_unpack(msg, eom, src, dst, dstsiz) * Unpack a domain name from a message, source may be compressed. @@ -357,48 +251,36 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, srcp = src; dstlim = dst + dstsiz; if (srcp < msg || srcp >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } /* Fetch next label in domain name. */ while ((n = *srcp++) != 0) { /* Check for indirection. */ switch (n & NS_CMPRSFLGS) { - case 0x40: - if (n == 0x41) { - if (dstp + 1 >= dstlim) { - __set_errno (EMSGSIZE); - return (-1); - } - *dstp++ = 0x41; - n = *srcp++ / 8; - ++checked; - } else { - __set_errno (EMSGSIZE); - return (-1); /* flag error */ - } - /* FALLTHROUGH */ case 0: /* Limit checks. */ if (dstp + n + 1 >= dstlim || srcp + n >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } checked += n + 1; - dstp = mempcpy(dstp, srcp - 1, n + 1); + *dstp++ = n; + memcpy(dstp, srcp, n); + dstp += n; srcp += n; break; case NS_CMPRSFLGS: if (srcp >= eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } if (len < 0) len = srcp - src + 1; srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); if (srcp < msg || srcp >= eom) { /* Out of range. */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } checked += 2; @@ -408,13 +290,13 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, * there must be a loop. */ if (checked >= eom - msg) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } break; default: - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); /* flag error */ } } @@ -423,7 +305,6 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, len = srcp - src; return (len); } -libresolv_hidden_def (ns_name_unpack) /* * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr) @@ -449,7 +330,7 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, u_char *dstp; const u_char **cpp, **lpp, *eob, *msg; const u_char *srcp; - int n, l, first = 1; + int n, l; srcp = src; dstp = dst; @@ -468,31 +349,29 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, l = 0; do { n = *srcp; - if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) { - __set_errno (EMSGSIZE); + if ((n & NS_CMPRSFLGS) != 0) { + errno = EMSGSIZE; return (-1); } - if (n == 0x41) - n = *++srcp / 8; l += n + 1; if (l > MAXCDNAME) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } srcp += n + 1; } while (n != 0); - /* from here on we need to reset compression pointer array on error */ srcp = src; do { /* Look to see if we can use pointers. */ n = *srcp; - if (n != 0 && n != 0x41 && msg != NULL) { + if (n != 0 && msg != NULL) { l = dn_find(srcp, msg, (const u_char * const *)dnptrs, (const u_char * const *)lpp); if (l >= 0) { if (dstp + 1 >= eob) { - goto cleanup; + errno = EMSGSIZE; + return (-1); } *dstp++ = (l >> 8) | NS_CMPRSFLGS; *dstp++ = l % 256; @@ -500,24 +379,19 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, } /* Not found, save it. */ if (lastdnptr != NULL && cpp < lastdnptr - 1 && - (dstp - msg) < 0x4000 && first) { + (dstp - msg) < 0x4000) { *cpp++ = dstp; *cpp = NULL; - first = 0; } } /* copy label to buffer */ - if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) { /* Should not happen. */ - goto cleanup; - } - if (n == 0x41) { - n = *++srcp / 8; - if (dstp + 1 >= eob) - goto cleanup; - *dstp++ = 0x41; + if (n & NS_CMPRSFLGS) { /* Should not happen. */ + errno = EMSGSIZE; + return (-1); } if (dstp + 1 + n >= eob) { - goto cleanup; + errno = EMSGSIZE; + return (-1); } memcpy(dstp, srcp, n + 1); srcp += n + 1; @@ -525,12 +399,11 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, } while (n != 0); if (dstp > eob) { -cleanup: if (msg != NULL) *lpp = NULL; - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); - } + } return (dstp - dst); } @@ -548,7 +421,7 @@ ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src, { u_char tmp[NS_MAXCDNAME]; int n; - + if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1) return (-1); if (ns_name_ntop(tmp, dst, dstsiz) == -1) @@ -581,23 +454,6 @@ ns_name_compress(const char *src, u_char *dst, size_t dstsiz, return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr)); } -/* - * Reset dnptrs so that there are no active references to pointers at or - * after src. - */ -void -ns_name_rollback(const u_char *src, const u_char **dnptrs, - const u_char **lastdnptr) -{ - while (dnptrs < lastdnptr && *dnptrs != NULL) { - if (*dnptrs >= src) { - *dnptrs = NULL; - break; - } - dnptrs++; - } -} - /* * ns_name_skip(ptrptr, eom) * Advance *ptrptr to skip over the compressed name it points at. @@ -620,13 +476,13 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) { cp++; break; default: /* illegal type */ - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } break; } if (cp > eom) { - __set_errno (EMSGSIZE); + errno = EMSGSIZE; return (-1); } *ptrptr = cp; @@ -700,49 +556,37 @@ dn_find(const u_char *domain, const u_char *msg, u_int n; for (cpp = dnptrs; cpp < lastdnptr; cpp++) { - sp = *cpp; - /* - * terminate search on: - * root label - * compression pointer - * unusable offset - */ - while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 && - (sp - msg) < 0x4000) { - dn = domain; - cp = sp; - while ((n = *cp++) != 0) { - /* - * check for indirection - */ - switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ - if (n != *dn++) - goto next; - for ((void)NULL; n > 0; n--) - if (mklower(*dn++) != - mklower(*cp++)) - goto next; - /* Is next root for both ? */ - if (*dn == '\0' && *cp == '\0') - return (sp - msg); - if (*dn) - continue; + dn = domain; + sp = cp = *cpp; + while ((n = *cp++) != 0) { + /* + * check for indirection + */ + switch (n & NS_CMPRSFLGS) { + case 0: /* normal case, n == len */ + if (n != *dn++) goto next; - - case NS_CMPRSFLGS: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - - default: /* illegal type */ - __set_errno (EMSGSIZE); - return (-1); - } + for ((void)NULL; n > 0; n--) + if (mklower(*dn++) != mklower(*cp++)) + goto next; + /* Is next root for both ? */ + if (*dn == '\0' && *cp == '\0') + return (sp - msg); + if (*dn) + continue; + goto next; + + case NS_CMPRSFLGS: /* indirection */ + cp = msg + (((n & 0x3f) << 8) | *cp); + break; + + default: /* illegal type */ + errno = EMSGSIZE; + return (-1); } - next: - sp += *sp + 1; } + next: ; } - __set_errno (ENOENT); + errno = ENOENT; return (-1); } diff --git a/newlib/libc/sys/linux/net/ns_netint.c b/newlib/libc/sys/linux/net/ns_netint.c index 16282e5a1..18c9cccd6 100644 --- a/newlib/libc/sys/linux/net/ns_netint.c +++ b/newlib/libc/sys/linux/net/ns_netint.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,17 +15,16 @@ * SOFTWARE. */ -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_netint.c,v 8.4 1999/10/13 16:39:35 vixie Exp $"; -#endif +#include +#include /* Import. */ -#include -#include -#include "libc-symbols.h" +#include +#include -/* Public. */ +#include +#include u_int ns_get16(const u_char *src) { @@ -34,7 +33,6 @@ ns_get16(const u_char *src) { NS_GET16(dst, src); return (dst); } -libresolv_hidden_def (ns_get16) u_long ns_get32(const u_char *src) { @@ -43,7 +41,6 @@ ns_get32(const u_char *src) { NS_GET32(dst, src); return (dst); } -libresolv_hidden_def (ns_get32) void ns_put16(u_int src, u_char *dst) { diff --git a/newlib/libc/sys/linux/net/ns_ntoa.c b/newlib/libc/sys/linux/net/ns_ntoa.c new file mode 100644 index 000000000..b6a6c4c22 --- /dev/null +++ b/newlib/libc/sys/linux/net/ns_ntoa.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +#include +#include + +#include +#include +#include +#include + +static char *spectHex(char *p0); + +char * +ns_ntoa(addr) + struct ns_addr addr; +{ + static char obuf[40]; + union { union ns_net net_e; u_long long_e; } net; + u_short port = htons(addr.x_port); + char *cp; + char *cp2; + u_char *up = addr.x_host.c_host; + u_char *uplim = up + 6; + + net.net_e = addr.x_net; + sprintf(obuf, "%lx", (u_long)ntohl(net.long_e)); + cp = spectHex(obuf); + cp2 = cp + 1; + while (*up==0 && up < uplim) up++; + if (up == uplim) { + if (port) { + sprintf(cp, ".0"); + cp += 2; + } + } else { + sprintf(cp, ".%x", *up++); + while (up < uplim) { + while (*cp) cp++; + sprintf(cp, "%02x", *up++); + } + cp = spectHex(cp2); + } + if (port) { + sprintf(cp, ".%x", port); + spectHex(cp + 1); + } + return (obuf); +} + +static char * +spectHex(p0) + char *p0; +{ + int ok = 0; + int nonzero = 0; + char *p = p0; + for (; *p; p++) switch (*p) { + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + *p += ('A' - 'a'); + /* fall into . . . */ + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + ok = 1; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + nonzero = 1; + } + if (nonzero && !ok) { *p++ = 'H'; *p = 0; } + return (p); +} diff --git a/newlib/libc/sys/linux/net/ns_parse.c b/newlib/libc/sys/linux/net/ns_parse.c index 5311e2496..38a684b87 100644 --- a/newlib/libc/sys/linux/net/ns_parse.c +++ b/newlib/libc/sys/linux/net/ns_parse.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,11 +15,8 @@ * SOFTWARE. */ -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_parse.c,v 8.13 1999/10/13 16:39:35 vixie Exp $"; -#endif - -/* Import. */ +#include +#include #include @@ -30,18 +27,6 @@ static const char rcsid[] = "$BINDId: ns_parse.c,v 8.13 1999/10/13 16:39:35 vixi #include #include -#include "libc-symbols.h" - -/* Forward. */ - -static void setsection(ns_msg *msg, ns_sect sect); - -/* Macros. */ - -#define RETERR(err) do { __set_errno (err); return (-1); } while (0) - -/* Public. */ - /* These need to be in the same order as the nres.h:ns_flag enum. */ struct _ns_flagdata _ns_flagdata[16] = { { 0x8000, 15 }, /* qr. */ @@ -62,8 +47,8 @@ struct _ns_flagdata _ns_flagdata[16] = { { 0x0000, 0 }, /* expansion (6/6). */ }; -int -ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { +static int +skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { const u_char *optr = ptr; for ((void)NULL; count > 0; count--) { @@ -71,19 +56,24 @@ ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { b = dn_skipname(ptr, eom); if (b < 0) - RETERR(EMSGSIZE); + goto emsgsize; ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/; if (section != ns_s_qd) { - if (ptr + NS_INT32SZ + NS_INT16SZ > eom) - RETERR(EMSGSIZE); + if (ptr + NS_INT32SZ > eom) + goto emsgsize; ptr += NS_INT32SZ/*TTL*/; + if (ptr + NS_INT16SZ > eom) + goto emsgsize; NS_GET16(rdlength, ptr); ptr += rdlength/*RData*/; } } if (ptr > eom) - RETERR(EMSGSIZE); + goto emsgsize; return (ptr - optr); + emsgsize: + errno = EMSGSIZE; + return (-1); } int @@ -95,22 +85,22 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { handle->_msg = msg; handle->_eom = eom; if (msg + NS_INT16SZ > eom) - RETERR(EMSGSIZE); + goto emsgsize; NS_GET16(handle->_id, msg); if (msg + NS_INT16SZ > eom) - RETERR(EMSGSIZE); + goto emsgsize; NS_GET16(handle->_flags, msg); for (i = 0; i < ns_s_max; i++) { if (msg + NS_INT16SZ > eom) - RETERR(EMSGSIZE); + goto emsgsize; NS_GET16(handle->_counts[i], msg); } for (i = 0; i < ns_s_max; i++) if (handle->_counts[i] == 0) handle->_sections[i] = NULL; else { - int b = ns_skiprr(msg, eom, (ns_sect)i, - handle->_counts[i]); + int b = skiprr(msg, eom, (ns_sect)i, + handle->_counts[i]); if (b < 0) return (-1); @@ -118,9 +108,14 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { msg += b; } if (msg != eom) - RETERR(EMSGSIZE); - setsection(handle, ns_s_max); + goto emsgsize; + handle->_sect = ns_s_max; + handle->_rrnum = -1; + handle->_ptr = NULL; return (0); + emsgsize: + errno = EMSGSIZE; + return (-1); } int @@ -129,26 +124,29 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { /* Make section right. */ if (section < 0 || section >= ns_s_max) - RETERR(ENODEV); - if (section != handle->_sect) - setsection(handle, section); + goto enodev; + if ((int)section != (int)handle->_sect) { + handle->_sect = section; + handle->_rrnum = 0; + handle->_ptr = handle->_sections[(int)section]; + } /* Make rrnum right. */ if (rrnum == -1) rrnum = handle->_rrnum; if (rrnum < 0 || rrnum >= handle->_counts[(int)section]) - RETERR(ENODEV); - if (rrnum < handle->_rrnum) - setsection(handle, section); - if (rrnum > handle->_rrnum) { - b = ns_skiprr(handle->_ptr, handle->_eom, section, - rrnum - handle->_rrnum); - - if (b < 0) - return (-1); - handle->_ptr += b; - handle->_rrnum = rrnum; + goto enodev; + if (rrnum < handle->_rrnum) { + handle->_rrnum = 0; + handle->_ptr = handle->_sections[(int)section]; } + + b = skiprr(handle->_msg, handle->_eom, section, + rrnum - handle->_rrnum); + if (b < 0) + return (-1); + handle->_ptr += b; + handle->_rrnum = rrnum; /* Do the parse. */ b = dn_expand(handle->_msg, handle->_eom, @@ -156,41 +154,36 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { if (b < 0) return (-1); handle->_ptr += b; - if (handle->_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) - RETERR(EMSGSIZE); + if (handle->_ptr + NS_INT16SZ > handle->_eom) + goto emsgsize; NS_GET16(rr->type, handle->_ptr); + if (handle->_ptr + NS_INT16SZ > handle->_eom) + goto emsgsize; NS_GET16(rr->rr_class, handle->_ptr); if (section == ns_s_qd) { rr->ttl = 0; rr->rdlength = 0; rr->rdata = NULL; } else { - if (handle->_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) - RETERR(EMSGSIZE); + if (handle->_ptr + NS_INT32SZ > handle->_eom) + goto emsgsize; NS_GET32(rr->ttl, handle->_ptr); + if (handle->_ptr + NS_INT16SZ > handle->_eom) + goto emsgsize; NS_GET16(rr->rdlength, handle->_ptr); if (handle->_ptr + rr->rdlength > handle->_eom) - RETERR(EMSGSIZE); + goto emsgsize; rr->rdata = handle->_ptr; handle->_ptr += rr->rdlength; } - if (++handle->_rrnum > handle->_counts[(int)section]) - setsection(handle, (ns_sect)((int)section + 1)); + handle->_rrnum++; /* All done. */ return (0); -} - -/* Private. */ - -static void -setsection(ns_msg *msg, ns_sect sect) { - msg->_sect = sect; - if (sect == ns_s_max) { - msg->_rrnum = -1; - msg->_ptr = NULL; - } else { - msg->_rrnum = 0; - msg->_ptr = msg->_sections[(int)sect]; - } + enodev: + errno = ENODEV; + return (-1); + emsgsize: + errno = EMSGSIZE; + return (-1); } diff --git a/newlib/libc/sys/linux/net/ns_print.c b/newlib/libc/sys/linux/net/ns_print.c index bc11aa362..7cce6d7aa 100644 --- a/newlib/libc/sys/linux/net/ns_print.c +++ b/newlib/libc/sys/linux/net/ns_print.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,9 +15,10 @@ * SOFTWARE. */ -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_print.c,v 8.18 2000/02/29 05:48:12 vixie Exp $"; -#endif +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +#include +#include /* Import. */ @@ -34,13 +35,7 @@ static const char rcsid[] = "$BINDId: ns_print.c,v 8.18 2000/02/29 05:48:12 vixi #include #include -#include "libc-symbols.h" - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif +#define SPRINTF(x) ((size_t)sprintf x) /* Forward. */ @@ -56,12 +51,6 @@ static int addstr(const char *src, size_t len, static int addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen); -/* Proto. */ - -#ifndef _LIBC -u_int16_t dst_s_dns_key_id(const u_char *, const int); -#endif - /* Macros. */ #define T(x) \ @@ -119,7 +108,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* * Owner. */ - if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) { + if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) { T(addstr("\t\t\t", 3, &buf, &buflen)); } else { len = prune_origin(name, origin); @@ -127,10 +116,9 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(addstr("@\t\t\t", 4, &buf, &buflen)); } else { T(addstr(name, len, &buf, &buflen)); - /* Origin not used or not root, and no trailing dot? */ - if (((origin == NULL || origin[0] == '\0') || - (origin[0] != '.' && origin[1] != '\0' && - name[len] == '\0')) && name[len - 1] != '.') { + /* Origin not used and no trailing dot? */ + if ((!origin || !origin[0] || name[len] == '\0') && + name[len - 1] != '.') { T(addstr(".", 1, &buf, &buflen)); len++; } @@ -176,11 +164,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, rdata += len; T(addstr(" ", 1, &buf, &buflen)); - - /* Second word, optional in ISDN records. */ - if (type == ns_t_isdn && rdata == edata) - break; - + /* Second word. */ T(len = charstr(rdata, edata, &buf, &buflen)); if (len == 0) goto formerr; @@ -311,9 +295,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; case ns_t_nsap: { - /* 2*255 for hex digits, 128 for '.' and '\0', 2 for - 0x if inet_nsap_ntoa starts using it. */ - char t[255*2 + 128 + 2]; + char t[255*3]; (void) inet_nsap_ntoa(rdlen, rdata, t); T(addstr(t, strlen(t), &buf, &buflen)); @@ -449,9 +431,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, } case ns_t_key: { -#ifndef _LIBC char base64_key[NS_MD5RSA_MAX_BASE64]; - u_int keyflags, protocol, algorithm, key_id; + u_int keyflags, protocol, algorithm; const char *leader; int n; @@ -459,7 +440,6 @@ ns_sprintrrf(const u_char *msg, size_t msglen, goto formerr; /* Key flags, Protocol, Algorithm. */ - key_id = dst_s_dns_key_id(rdata, edata-rdata); keyflags = ns_get16(rdata); rdata += NS_INT16SZ; protocol = *rdata++; algorithm = *rdata++; @@ -485,15 +465,11 @@ ns_sprintrrf(const u_char *msg, size_t msglen, } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); - n = SPRINTF((tmp, " ; key_tag= %u", key_id)); - T(addstr(tmp, n, &buf, &buflen)); -#endif /* !_LIBC */ break; } case ns_t_sig: { -#ifndef _LIBC char base64_key[NS_MD5RSA_MAX_BASE64]; u_int type, algorithm, labels, footprint; const char *leader; @@ -508,10 +484,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen, algorithm = *rdata++; labels = *rdata++; t = ns_get32(rdata); rdata += NS_INT32SZ; - len = SPRINTF((tmp, "%s %d %d %lu ", - p_type(type), algorithm, labels, t)); + len = SPRINTF((tmp, " %s %d %lu ", + p_type(type), algorithm, t)); T(addstr(tmp, len, &buf, &buflen)); - if (labels > (u_int)dn_count_labels(name)) + if (labels != (u_int)dn_count_labels(name)) goto formerr; /* Signature expiry. */ @@ -550,7 +526,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); -#endif /* !_LIBC */ + break; } @@ -570,63 +546,6 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; } - case ns_t_cert: { - u_int c_type, key_tag, alg; - int n, siz; - char base64_cert[8192], *leader, tmp[40]; - - c_type = ns_get16(rdata); rdata += NS_INT16SZ; - key_tag = ns_get16(rdata); rdata += NS_INT16SZ; - alg = (u_int) *rdata++; - - len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg)); - T(addstr(tmp, len, &buf, &buflen)); - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ - if (siz > sizeof(base64_cert) * 3/4) { - char *str = "record too long to print"; - T(addstr(str, strlen(str), &buf, &buflen)); - } - else { - len = b64_ntop(rdata, edata-rdata, base64_cert, siz); - - if (len < 0) - goto formerr; - else if (len > 15) { - T(addstr(" (", 2, &buf, &buflen)); - leader = "\n\t\t"; - spaced = 0; - } - else - leader = " "; - - for (n = 0; n < len; n += 48) { - T(addstr(leader, strlen(leader), - &buf, &buflen)); - T(addstr(base64_cert + n, MIN(len - n, 48), - &buf, &buflen)); - } - if (len > 15) - T(addstr(" )", 2, &buf, &buflen)); - } - break; - } - - case ns_t_tsig: { - /* BEW - need to complete this */ - int n; - - T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); - rdata += 8; /* time */ - n = ns_get16(rdata); rdata += INT16SZ; - rdata += n; /* sig */ - n = ns_get16(rdata); rdata += INT16SZ; /* original id */ - sprintf(buf, "%d", ns_get16(rdata)); - rdata += INT16SZ; - addlen(strlen(buf), &buf, &buflen); - break; - } - default: comment = "unknown RR type"; goto hexify; @@ -682,7 +601,7 @@ prune_origin(const char *name, const char *origin) { const char *oname = name; while (*name != '\0') { - if (origin != NULL && ns_samename(name, origin) == 1) + if (origin != NULL && strcasecmp(name, origin) == 0) return (name - oname - (name > oname)); while (*name != '\0') { if (*name == '\\') { @@ -739,7 +658,7 @@ charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) { goto enospc; return (rdata - odata); enospc: - __set_errno (ENOSPC); + errno = ENOSPC; *buf = save_buf; *buflen = save_buflen; return (-1); @@ -758,29 +677,27 @@ addname(const u_char *msg, size_t msglen, if (n < 0) goto enospc; /* Guess. */ newlen = prune_origin(*buf, origin); + if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') && + (newlen == 0 || (*buf)[newlen - 1] != '.')) { + /* No trailing dot. */ + if (newlen + 2 > *buflen) + goto enospc; /* No room for ".\0". */ + (*buf)[newlen++] = '.'; + (*buf)[newlen] = '\0'; + } if (newlen == 0) { /* Use "@" instead of name. */ if (newlen + 2 > *buflen) goto enospc; /* No room for "@\0". */ (*buf)[newlen++] = '@'; (*buf)[newlen] = '\0'; - } else { - if (((origin == NULL || origin[0] == '\0') || - (origin[0] != '.' && origin[1] != '\0' && - (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') { - /* No trailing dot. */ - if (newlen + 2 > *buflen) - goto enospc; /* No room for ".\0". */ - (*buf)[newlen++] = '.'; - (*buf)[newlen] = '\0'; - } } *pp += n; addlen(newlen, buf, buflen); **buf = '\0'; return (newlen); enospc: - __set_errno (ENOSPC); + errno = ENOSPC; *buf = save_buf; *buflen = save_buflen; return (-1); @@ -795,8 +712,8 @@ addlen(size_t len, char **buf, size_t *buflen) { static int addstr(const char *src, size_t len, char **buf, size_t *buflen) { - if (len >= *buflen) { - __set_errno (ENOSPC); + if (len > *buflen) { + errno = ENOSPC; return (-1); } memcpy(*buf, src, len); diff --git a/newlib/libc/sys/linux/net/ns_samedomain.c b/newlib/libc/sys/linux/net/ns_samedomain.c deleted file mode 100644 index 964863719..000000000 --- a/newlib/libc/sys/linux/net/ns_samedomain.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 1995,1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_samedomain.c,v 8.9 1999/10/15 21:06:51 vixie Exp $"; -#endif - -#include -#include -#include -#include - -#include "libc-symbols.h" - -/* - * int - * ns_samedomain(a, b) - * Check whether a name belongs to a domain. - * Inputs: - * a - the domain whose ancestory is being verified - * b - the potential ancestor we're checking against - * Return: - * boolean - is a at or below b? - * Notes: - * Trailing dots are first removed from name and domain. - * Always compare complete subdomains, not only whether the - * domain name is the trailing string of the given name. - * - * "host.foobar.top" lies in "foobar.top" and in "top" and in "" - * but NOT in "bar.top" - */ - -int -ns_samedomain(const char *a, const char *b) { - size_t la, lb; - int diff, i, escaped; - const char *cp; - - la = strlen(a); - lb = strlen(b); - - /* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */ - if (la != 0 && a[la - 1] == '.') { - escaped = 0; - /* Note this loop doesn't get executed if la==1. */ - for (i = la - 2; i >= 0; i--) - if (a[i] == '\\') { - if (escaped) - escaped = 0; - else - escaped = 1; - } else - break; - if (!escaped) - la--; - } - - /* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */ - if (lb != 0 && b[lb - 1] == '.') { - escaped = 0; - /* note this loop doesn't get executed if lb==1 */ - for (i = lb - 2; i >= 0; i--) - if (b[i] == '\\') { - if (escaped) - escaped = 0; - else - escaped = 1; - } else - break; - if (!escaped) - lb--; - } - - /* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */ - if (lb == 0) - return (1); - - /* 'b' longer than 'a' means 'a' can't be in 'b'. */ - if (lb > la) - return (0); - - /* 'a' and 'b' being equal at this point indicates sameness. */ - if (lb == la) - return (strncasecmp(a, b, lb) == 0); - - /* Ok, we know la > lb. */ - - diff = la - lb; - - /* - * If 'a' is only 1 character longer than 'b', then it can't be - * a subdomain of 'b' (because of the need for the '.' label - * separator). - */ - if (diff < 2) - return (0); - - /* - * If the character before the last 'lb' characters of 'b' - * isn't '.', then it can't be a match (this lets us avoid - * having "foobar.com" match "bar.com"). - */ - if (a[diff - 1] != '.') - return (0); - - /* - * We're not sure about that '.', however. It could be escaped - * and thus not a really a label separator. - */ - escaped = 0; - for (i = diff - 2; i >= 0; i--) - if (a[i] == '\\') - if (escaped) - escaped = 0; - else - escaped = 1; - else - break; - if (escaped) - return (0); - - /* Now compare aligned trailing substring. */ - cp = a + diff; - return (strncasecmp(cp, b, lb) == 0); -} - -/* - * int - * ns_subdomain(a, b) - * is "a" a subdomain of "b"? - */ -int -ns_subdomain(const char *a, const char *b) { - return (ns_samename(a, b) != 1 && ns_samedomain(a, b)); -} - -/* - * int - * ns_makecanon(src, dst, dstsize) - * make a canonical copy of domain name "src" - * notes: - * foo -> foo. - * foo. -> foo. - * foo.. -> foo. - * foo\. -> foo\.. - * foo\\. -> foo\\. - */ - -int -ns_makecanon(const char *src, char *dst, size_t dstsize) { - size_t n = strlen(src); - - if (n + sizeof "." > dstsize) { - __set_errno (EMSGSIZE); - return (-1); - } - strcpy(dst, src); - while (n > 0 && dst[n - 1] == '.') /* Ends in "." */ - if (n > 1 && dst[n - 2] == '\\' && /* Ends in "\." */ - (n < 2 || dst[n - 3] != '\\')) /* But not "\\." */ - break; - else - dst[--n] = '\0'; - dst[n++] = '.'; - dst[n] = '\0'; - return (0); -} - -/* - * int - * ns_samename(a, b) - * determine whether domain name "a" is the same as domain name "b" - * return: - * -1 on error - * 0 if names differ - * 1 if names are the same - */ - -int -ns_samename(const char *a, const char *b) { - char ta[NS_MAXDNAME], tb[NS_MAXDNAME]; - - if (ns_makecanon(a, ta, sizeof ta) < 0 || - ns_makecanon(b, tb, sizeof tb) < 0) - return (-1); - if (strcasecmp(ta, tb) == 0) - return (1); - else - return (0); -} diff --git a/newlib/libc/sys/linux/net/ns_ttl.c b/newlib/libc/sys/linux/net/ns_ttl.c index 87cd7b1ed..63dbefb59 100644 --- a/newlib/libc/sys/linux/net/ns_ttl.c +++ b/newlib/libc/sys/linux/net/ns_ttl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,9 +15,8 @@ * SOFTWARE. */ -#if !defined(_LIBC) && !defined(lint) -static const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $"; -#endif +#include +#include /* Import. */ @@ -28,13 +27,7 @@ static const char rcsid[] = "$BINDId: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie E #include #include -#include "libc-symbols.h" - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif +#define SPRINTF(x) ((size_t)sprintf x) /* Forward. */ @@ -91,9 +84,6 @@ ns_format_ttl(u_long src, char *dst, size_t dstlen) { return (dst - odst); } -#ifndef SHARED -// Seems not to be needed. It's not exported from the DSO. Some libresolv.a -// might depend on it so we let it in. int ns_parse_ttl(const char *src, u_long *dst) { u_long ttl, tmp; @@ -139,10 +129,9 @@ ns_parse_ttl(const char *src, u_long *dst) { return (0); einval: - __set_errno (EINVAL); + errno = EINVAL; return (-1); } -#endif /* Private. */ diff --git a/newlib/libc/sys/linux/net/nsap_addr.c b/newlib/libc/sys/linux/net/nsap_addr.c index 5c0855f60..b6651488b 100644 --- a/newlib/libc/sys/linux/net/nsap_addr.c +++ b/newlib/libc/sys/linux/net/nsap_addr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,30 +15,31 @@ * SOFTWARE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$BINDId: nsap_addr.c,v 8.10 1999/10/13 16:39:28 vixie Exp $"; -#endif /* LIBC_SCCS and not lint */ +#include +#include #include #include #include - #include #include #include - #include #include -#include "libc-symbols.h" - static char -xtob(int c) { +xtob(c) + int c; +{ return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); } u_int -inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) { +inet_nsap_addr(ascii, binary, maxlen) + const char *ascii; + u_char *binary; + int maxlen; +{ u_char c, nib; u_int len = 0; @@ -47,7 +48,8 @@ inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) { continue; if (!isascii(c)) return (0); - c = toupper(c); + if (islower(c)) + c = toupper(c); if (isxdigit(c)) { nib = xtob(c); c = *ascii++; @@ -69,10 +71,14 @@ inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) { } char * -inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { +inet_nsap_ntoa(binlen, binary, ascii) + int binlen; + const u_char *binary; + char *ascii; +{ int nib; int i; - static char tmpbuf[255*2 + 128]; + static char tmpbuf[255*3]; char *start; if (ascii) @@ -96,3 +102,12 @@ inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { *ascii = '\0'; return (start); } + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef inet_nsap_addr +__weak_reference(__inet_nsap_addr, inet_nsap_addr); +#undef inet_nsap_ntoa +__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa); diff --git a/newlib/libc/sys/linux/net/nscd-types.h b/newlib/libc/sys/linux/net/nscd-types.h deleted file mode 100644 index dbe43b8bc..000000000 --- a/newlib/libc/sys/linux/net/nscd-types.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Types for the NSCD implementation. Generic version. - Copyright (c) 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -typedef int32_t nscd_ssize_t; diff --git a/newlib/libc/sys/linux/net/nscd/nscd-client.h b/newlib/libc/sys/linux/net/nscd/nscd-client.h deleted file mode 100644 index 0ba8a2198..000000000 --- a/newlib/libc/sys/linux/net/nscd/nscd-client.h +++ /dev/null @@ -1,312 +0,0 @@ -/* Copyright (c) 1998, 1999, 2000, 2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Thorsten Kukuk , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This file defines everything that client code should need to - know to talk to the nscd daemon. */ - -#ifndef _NSCD_CLIENT_H -#define _NSCD_CLIENT_H 1 - -#include -#include -#include -#include -#include - - -/* Version number of the daemon interface */ -#define NSCD_VERSION 2 - -/* Path of the file where the PID of the running system is stored. */ -#define _PATH_NSCDPID "/var/run/nscd/nscd.pid" - -/* Path for the Unix domain socket. */ -#define _PATH_NSCDSOCKET "/var/run/nscd/socket" - -/* Path for the configuration file. */ -#define _PATH_NSCDCONF "/etc/nscd.conf" - - -/* Available services. */ -typedef enum -{ - GETPWBYNAME, - GETPWBYUID, - GETGRBYNAME, - GETGRBYGID, - GETHOSTBYNAME, - GETHOSTBYNAMEv6, - GETHOSTBYADDR, - GETHOSTBYADDRv6, - LASTDBREQ = GETHOSTBYADDRv6, - SHUTDOWN, /* Shut the server down. */ - GETSTAT, /* Get the server statistic. */ - INVALIDATE, /* Invalidate one special cache. */ - GETFDPW, - GETFDGR, - GETFDHST, - GETAI, - INITGROUPS, - LASTREQ -} request_type; - - -/* Header common to all requests */ -typedef struct -{ - int32_t version; /* Version number of the daemon interface. */ - request_type type; /* Service requested. */ - int32_t key_len; /* Key length. */ -} request_header; - - -/* Structure sent in reply to password query. Note that this struct is - sent also if the service is disabled or there is no record found. */ -typedef struct -{ - int32_t version; - int32_t found; - nscd_ssize_t pw_name_len; - nscd_ssize_t pw_passwd_len; - uid_t pw_uid; - gid_t pw_gid; - nscd_ssize_t pw_gecos_len; - nscd_ssize_t pw_dir_len; - nscd_ssize_t pw_shell_len; -} pw_response_header; - - -/* Structure sent in reply to group query. Note that this struct is - sent also if the service is disabled or there is no record found. */ -typedef struct -{ - int32_t version; - int32_t found; - nscd_ssize_t gr_name_len; - nscd_ssize_t gr_passwd_len; - gid_t gr_gid; - nscd_ssize_t gr_mem_cnt; -} gr_response_header; - - -/* Structure sent in reply to host query. Note that this struct is - sent also if the service is disabled or there is no record found. */ -typedef struct -{ - int32_t version; - int32_t found; - nscd_ssize_t h_name_len; - nscd_ssize_t h_aliases_cnt; - int32_t h_addrtype; - int32_t h_length; - nscd_ssize_t h_addr_list_cnt; - int32_t error; -} hst_response_header; - - -/* Structure sent in reply to addrinfo query. Note that this struct is - sent also if the service is disabled or there is no record found. */ -typedef struct -{ - int32_t version; - int32_t found; - nscd_ssize_t naddrs; - nscd_ssize_t addrslen; - nscd_ssize_t canonlen; - int32_t error; -} ai_response_header; - -/* Structure filled in by __nscd_getai. */ -struct nscd_ai_result -{ - int naddrs; - char *canon; - uint8_t *family; - char *addrs; -}; - -/* Structure sent in reply to initgroups query. Note that this struct is - sent also if the service is disabled or there is no record found. */ -typedef struct -{ - int32_t version; - int32_t found; - nscd_ssize_t ngrps; -} initgr_response_header; - - -/* Type for offsets in data part of database. */ -typedef uint32_t ref_t; -/* Value for invalid/no reference. */ -#define ENDREF UINT32_MAX - -/* Timestamp type. */ -typedef uint64_t nscd_time_t; - -/* Alignment requirement of the beginning of the data region. */ -#define ALIGN 16 - - -/* Head of record in data part of database. */ -struct datahead -{ - nscd_ssize_t allocsize; /* Allocated Bytes. */ - nscd_ssize_t recsize; /* Size of the record. */ - nscd_time_t timeout; /* Time when this entry becomes invalid. */ - uint8_t notfound; /* Nonzero if data has not been found. */ - uint8_t nreloads; /* Reloads without use. */ - uint8_t usable; /* False if the entry must be ignored. */ - uint64_t :40; /* Alignment. */ - - /* We need to have the following element aligned for the response - header data types and their use in the 'struct dataset' types - defined in the XXXcache.c files. */ - union - { - pw_response_header pwdata; - gr_response_header grdata; - hst_response_header hstdata; - ai_response_header aidata; - initgr_response_header initgrdata; - nscd_ssize_t align1; - nscd_time_t align2; - } data[0]; -}; - - -/* Structure for one hash table entry. */ -struct hashentry -{ - request_type type:8; /* Which type of dataset. */ - bool first; /* True if this was the original key. */ - nscd_ssize_t len; /* Length of key. */ - ref_t key; /* Pointer to key. */ - int32_t owner; /* If secure table, this is the owner. */ - ref_t next; /* Next entry in this hash bucket list. */ - ref_t packet; /* Records for the result. */ - union - { - struct hashentry *dellist; /* Next record to be deleted. This can be a - pointer since only nscd uses this field. */ - ref_t *prevp; /* Pointer to field containing forward - reference. */ - }; -}; - - -/* Current persistent database version. */ -#define DB_VERSION 1 - -/* Maximum time allowed between updates of the timestamp. */ -#define MAPPING_TIMEOUT (5 * 60) - - -/* Header of persistent database file. */ -struct database_pers_head -{ - int32_t version; - int32_t header_size; - volatile int32_t gc_cycle; - volatile int32_t nscd_certainly_running; - volatile nscd_time_t timestamp; - - nscd_ssize_t module; - nscd_ssize_t data_size; - - nscd_ssize_t first_free; /* Offset of first free byte in data area. */ - - nscd_ssize_t nentries; - nscd_ssize_t maxnentries; - nscd_ssize_t maxnsearched; - - uint64_t poshit; - uint64_t neghit; - uint64_t posmiss; - uint64_t negmiss; - - uint64_t rdlockdelayed; - uint64_t wrlockdelayed; - - uint64_t addfailed; - - ref_t array[0]; -}; - - -/* Mapped database record. */ -struct mapped_database -{ - const struct database_pers_head *head; - const char *data; - size_t mapsize; - int counter; /* > 0 indicates it is usable. */ -}; -#define NO_MAPPING ((struct mapped_database *) -1l) - -struct locked_map_ptr -{ - int lock; - struct mapped_database *mapped; -}; -#define libc_locked_map_ptr(class, name) class struct locked_map_ptr name - - -/* Open socket connection to nscd server. */ -extern int __nscd_open_socket (const char *key, size_t keylen, - request_type type, void *response, - size_t responselen) attribute_hidden; - -/* Get reference of mapping. */ -extern struct mapped_database *__nscd_get_map_ref (request_type type, - const char *name, - struct locked_map_ptr *mapptr, - int *gc_cyclep); - -/* Unmap database. */ -extern void __nscd_unmap (struct mapped_database *mapped); - -/* Drop reference of mapping. */ -static inline int __nscd_drop_map_ref (struct mapped_database *map, - int *gc_cycle) -{ - if (map != NO_MAPPING) - { - int now_cycle = map->head->gc_cycle; - if (__builtin_expect (now_cycle != *gc_cycle, 0)) - { - /* We might have read inconsistent data. */ - *gc_cycle = now_cycle; - return -1; - } - - if (atomic_decrement_and_test (&map->counter) == 0) - __nscd_unmap (map); - } - - return 0; -} - - -/* Search the mapped database. */ -extern const struct datahead *__nscd_cache_search (request_type type, - const char *key, - size_t keylen, - const struct mapped_database *mapped); - -#endif /* nscd.h */ diff --git a/newlib/libc/sys/linux/net/nscd/nscd_proto.h b/newlib/libc/sys/linux/net/nscd/nscd_proto.h deleted file mode 100644 index 64d9bd004..000000000 --- a/newlib/libc/sys/linux/net/nscd/nscd_proto.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Thorsten Kukuk , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _NSCD_PROTO_H -#define _NSCD_PROTO_H 1 - -#include -#include -#include - -/* Interval in which we transfer retry to contact the NSCD. */ -#define NSS_NSCD_RETRY 100 - -/* Type needed in the interfaces. */ -struct nscd_ai_result; - - -/* Variables for communication between NSCD handler functions and NSS. */ -extern int __nss_not_use_nscd_passwd attribute_hidden; -extern int __nss_not_use_nscd_group attribute_hidden; -extern int __nss_not_use_nscd_hosts attribute_hidden; - -extern int __nscd_getpwnam_r (const char *name, struct passwd *resultbuf, - char *buffer, size_t buflen, - struct passwd **result); -extern int __nscd_getpwuid_r (uid_t uid, struct passwd *resultbuf, - char *buffer, size_t buflen, - struct passwd **result); -extern int __nscd_getgrnam_r (const char *name, struct group *resultbuf, - char *buffer, size_t buflen, - struct group **result); -extern int __nscd_getgrgid_r (gid_t gid, struct group *resultbuf, - char *buffer, size_t buflen, - struct group **result); -extern int __nscd_gethostbyname_r (const char *name, - struct hostent *resultbuf, - char *buffer, size_t buflen, - struct hostent **result, int *h_errnop); -extern int __nscd_gethostbyname2_r (const char *name, int af, - struct hostent *resultbuf, - char *buffer, size_t buflen, - struct hostent **result, int *h_errnop); -extern int __nscd_gethostbyaddr_r (const void *addr, socklen_t len, int type, - struct hostent *resultbuf, - char *buffer, size_t buflen, - struct hostent **result, int *h_errnop); -extern int __nscd_getai (const char *key, struct nscd_ai_result **result, - int *h_errnop); -extern int __nscd_getgrouplist (const char *user, gid_t group, long int *size, - gid_t **groupsp, long int limit); -#endif /* _NSCD_PROTO_H */ diff --git a/newlib/libc/sys/linux/net/nsdispatch.3 b/newlib/libc/sys/linux/net/nsdispatch.3 new file mode 100644 index 000000000..708f97cba --- /dev/null +++ b/newlib/libc/sys/linux/net/nsdispatch.3 @@ -0,0 +1,231 @@ +.\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $ +.\" $FreeBSD: src/lib/libc/net/nsdispatch.3,v 1.5 2001/10/01 16:08:56 ru Exp $ +.\" +.\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Luke Mewburn. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd January 19, 1999 +.Dt NSDISPATCH 3 +.Os +.Sh NAME +.Nm nsdispatch +.Nd name-service switch dispatcher routine +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In nsswitch.h +.Ft int +.Fo nsdispatch +.Fa "void *retval" +.Fa "const ns_dtab dtab[]" +.Fa "const char *database" +.Fa "const char *method" +.Fa "const ns_src defaults[]" +.Fa "..." +.Fc +.Sh DESCRIPTION +The +.Fn nsdispatch +function invokes the callback functions specified in +.Va dtab +in the order given in +.Pa /etc/nsswitch.conf +for the database +.Va database +until a successful entry is found. +.Pp +.Va retval +is passed to each callback function to modify as necessary +(to pass back to the caller of +.Fn nsdispatch ) +.Pp +.Va dtab +is an array of +.Va ns_dtab +structures, which have the following format: +.Bd -literal -offset indent +typedef struct { + const char *src; + int (*cb)(void *retval, void *cb_data, va_list ap); + void *cb_data; +} ns_dtab; +.Ed +.Pp +.Bd -ragged -offset indent +For each source type that is implemented, an entry with +.Va src +set to the name of the source, +.Va cb +defined as a function which handles that source, and +.Va cb_data +is used to pass arbritrary data to the callback function. +The last entry in +.Va dtab +should contain +.Dv NULL +values for +.Va src , +.Va cb , +and +.Va cb_data . +.Ed +.Pp +.Va method +is usually the name of the function calling +.Fn nsdispatch . +When dynamic loading is supported, a symbol constructed from +.Va database , +the current source, and +.Va method +will be used as the name to invoke the dynamically loaded function. +.Pp +.Va defaults +contains a list of default sources to try in the case of +a missing or corrupt +.Xr nsswitch.conf 5 , +or if there isn't a relevant entry for +.Va database . +It is an array of +.Va ns_src +structures, which have the following format: +.Bd -literal -offset indent +typedef struct { + const char *src; + u_int32_t flags; +} ns_src; +.Ed +.Pp +.Bd -ragged -offset indent +For each default source type, an entry with +.Va src +set to the name of the source, and +.Va flags +set to the relevant flags +(usually +.Dv NS_SUCCESS ; +refer to +.Sx Callback return values +for more information). +The last entry in +.Va defaults +should have +.Va src +set to +.Dv NULL +and +.Va flags +set to 0. +.Pp +For convenience, a global variable defined as: +.Dl extern const ns_src __nsdefaultsrc[]; +exists which contains a single default entry for +.Sq files +for use by callers which don't require complicated default rules. +.Ed +.Pp +.Sq Va ... +are optional extra arguments, which +are passed to the appropriate callback function as a variable argument +list of the type +.Va va_list . +.Ss Valid source types +Whilst there is support for arbitrary sources, the following +#defines for commonly implementated sources are available: +.Bl -column NS_COMPAT COMPAT -offset indent +.It Sy "#define value" +.It "NSSRC_FILES ""files""" +.It "NSSRC_DNS ""dns""" +.It "NSSRC_NIS ""nis""" +.It "NSSRC_COMPAT ""compat""" +.El +.Pp +Refer to +.Xr nsswitch.conf 5 +for a complete description of what each source type is. +.Pp +.Ss Callback return values +The callback functions should return one of the following values +depending upon status of the lookup: +.Bl -column NS_NOTFOUND -offset indent +.It Sy "Return value Status code" +.It "NS_SUCCESS success" +.It "NS_NOTFOUND notfound" +.It "NS_UNAVAIL unavail" +.It "NS_TRYAGAIN tryagain" +.El +.Pp +Refer to +.Xr nsswitch.conf 5 +for a complete description of what each status code is. +.Pp +.Nm +returns the value of the callback that caused the dispatcher to finish, +or NS_NOTFOUND otherwise. +.Sh SEE ALSO +.Xr hesiod 3 , +.Xr stdarg 3 , +.Xr ypclnt 3 , +.Xr nsswitch.conf 5 +.Sh HISTORY +The +.Nm +routines first appeared in +.Fx 4.1 . +They were imported from the +.Nx +Project, +where they appeared first in +.Nx 1.4 . +.Sh AUTHORS +Luke Mewburn +.Aq lukem@netbsd.org +wrote this freely distributable name-service switch implementation, +using ideas from the +.Tn ULTRIX +.Xr svc.conf 5 +and +.Tn Solaris +.Xr nsswitch.conf 4 +manual pages. +.Sh BUGS +The +.Nm +routines are not thread safe. +This will be rectified in the future. +.Pp +Currently there is no support for dynamically loadable dispatcher callback +functions. +It is anticipated that this will be added in the future in the back-end +without requiring changes to code that invokes +.Fn nsdispatch . diff --git a/newlib/libc/sys/linux/net/nsdispatch.c b/newlib/libc/sys/linux/net/nsdispatch.c new file mode 100644 index 000000000..ea5fc6d4b --- /dev/null +++ b/newlib/libc/sys/linux/net/nsdispatch.c @@ -0,0 +1,266 @@ +/* $NetBSD: nsdispatch.c,v 1.9 1999/01/25 00:16:17 lukem Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +#include +#define _NS_PRIVATE +#include +#include +#include +#include +#include + +/* + * default sourcelist: `files' + */ +const ns_src __nsdefaultsrc[] = { + { NSSRC_FILES, NS_SUCCESS }, + { 0 }, +}; + + +static int _nsmapsize = 0; +static ns_dbt *_nsmap = NULL; + +/* + * size of dynamic array chunk for _nsmap and _nsmap[x].srclist + */ +#define NSELEMSPERCHUNK 8 + + +int _nscmp(const void *, const void *); + + +int +_nscmp(a, b) + const void *a; + const void *b; +{ + return (strcasecmp(((const ns_dbt *)a)->name, + ((const ns_dbt *)b)->name)); +} + + +void +_nsdbtaddsrc(dbt, src) + ns_dbt *dbt; + const ns_src *src; +{ + if ((dbt->srclistsize % NSELEMSPERCHUNK) == 0) { + dbt->srclist = (ns_src *)realloc(dbt->srclist, + (dbt->srclistsize + NSELEMSPERCHUNK) * sizeof(ns_src)); + if (dbt->srclist == NULL) + printf("nsdispatch: memory allocation failure\n"); + } + memmove(&dbt->srclist[dbt->srclistsize++], src, sizeof(ns_src)); +} + + +void +_nsdbtdump(dbt) + const ns_dbt *dbt; +{ + int i; + + printf("%s (%d source%s):", dbt->name, dbt->srclistsize, + dbt->srclistsize == 1 ? "" : "s"); + for (i = 0; i < dbt->srclistsize; i++) { + printf(" %s", dbt->srclist[i].name); + if (!(dbt->srclist[i].flags & + (NS_UNAVAIL|NS_NOTFOUND|NS_TRYAGAIN)) && + (dbt->srclist[i].flags & NS_SUCCESS)) + continue; + printf(" ["); + if (!(dbt->srclist[i].flags & NS_SUCCESS)) + printf(" SUCCESS=continue"); + if (dbt->srclist[i].flags & NS_UNAVAIL) + printf(" UNAVAIL=return"); + if (dbt->srclist[i].flags & NS_NOTFOUND) + printf(" NOTFOUND=return"); + if (dbt->srclist[i].flags & NS_TRYAGAIN) + printf(" TRYAGAIN=return"); + printf(" ]"); + } + printf("\n"); +} + + +const ns_dbt * +_nsdbtget(name) + const char *name; +{ + static time_t confmod; + + struct stat statbuf; + ns_dbt dbt; + + extern FILE *_nsyyin; + extern int _nsyyparse(void); + + dbt.name = name; + + if (confmod) { + if (stat(_PATH_NS_CONF, &statbuf) == -1) + return (NULL); + if (confmod < statbuf.st_mtime) { + int i, j; + + for (i = 0; i < _nsmapsize; i++) { + for (j = 0; j < _nsmap[i].srclistsize; j++) { + if (_nsmap[i].srclist[j].name != NULL) { + /*LINTED const cast*/ + free((void *) + _nsmap[i].srclist[j].name); + } + } + if (_nsmap[i].srclist) + free(_nsmap[i].srclist); + if (_nsmap[i].name) { + /*LINTED const cast*/ + free((void *)_nsmap[i].name); + } + } + if (_nsmap) + free(_nsmap); + _nsmap = NULL; + _nsmapsize = 0; + confmod = 0; + } + } + if (!confmod) { + if (stat(_PATH_NS_CONF, &statbuf) == -1) + return (NULL); + _nsyyin = fopen(_PATH_NS_CONF, "r"); + if (_nsyyin == NULL) + return (NULL); + _nsyyparse(); + (void)fclose(_nsyyin); + qsort(_nsmap, (size_t)_nsmapsize, sizeof(ns_dbt), _nscmp); + confmod = statbuf.st_mtime; + } + return (bsearch(&dbt, _nsmap, (size_t)_nsmapsize, sizeof(ns_dbt), + _nscmp)); +} + + +void +_nsdbtput(dbt) + const ns_dbt *dbt; +{ + int i; + + for (i = 0; i < _nsmapsize; i++) { + if (_nscmp(dbt, &_nsmap[i]) == 0) { + /* overwrite existing entry */ + if (_nsmap[i].srclist != NULL) + free(_nsmap[i].srclist); + memmove(&_nsmap[i], dbt, sizeof(ns_dbt)); + return; + } + } + + if ((_nsmapsize % NSELEMSPERCHUNK) == 0) { + _nsmap = (ns_dbt *)realloc(_nsmap, + (_nsmapsize + NSELEMSPERCHUNK) * sizeof(ns_dbt)); + if (_nsmap == NULL) + printf("nsdispatch: memory allocation failure\n"); + } + memmove(&_nsmap[_nsmapsize++], dbt, sizeof(ns_dbt)); +} + + +int +#if __STDC__ +nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, + const char *method, const ns_src defaults[], ...) +#else +nsdispatch(retval, disp_tab, database, method, defaults, va_alist) + void *retval; + const ns_dtab disp_tab[]; + const char *database; + const char *method; + const ns_src defaults[]; + va_dcl +#endif +{ + va_list ap; + int i, curdisp, result; + const ns_dbt *dbt; + const ns_src *srclist; + int srclistsize; + + dbt = _nsdbtget(database); + if (dbt != NULL) { + srclist = dbt->srclist; + srclistsize = dbt->srclistsize; + } else { + srclist = defaults; + srclistsize = 0; + while (srclist[srclistsize].name != NULL) + srclistsize++; + } + result = 0; + + for (i = 0; i < srclistsize; i++) { + for (curdisp = 0; disp_tab[curdisp].src != NULL; curdisp++) + if (strcasecmp(disp_tab[curdisp].src, + srclist[i].name) == 0) + break; + result = 0; + if (disp_tab[curdisp].callback) { +#if __STDC__ + va_start(ap, defaults); +#else + va_start(ap); +#endif + result = disp_tab[curdisp].callback(retval, + disp_tab[curdisp].cb_data, ap); + va_end(ap); + if (result & srclist[i].flags) { + break; + } + } + } + return (result ? result : NS_NOTFOUND); +} diff --git a/newlib/libc/sys/linux/net/nslexer.c b/newlib/libc/sys/linux/net/nslexer.c new file mode 100644 index 000000000..3f6ba4dcd --- /dev/null +++ b/newlib/libc/sys/linux/net/nslexer.c @@ -0,0 +1,1712 @@ +#define yy_create_buffer _nsyy_create_buffer +#define yy_delete_buffer _nsyy_delete_buffer +#define yy_scan_buffer _nsyy_scan_buffer +#define yy_scan_string _nsyy_scan_string +#define yy_scan_bytes _nsyy_scan_bytes +#define yy_flex_debug _nsyy_flex_debug +#define yy_init_buffer _nsyy_init_buffer +#define yy_flush_buffer _nsyy_flush_buffer +#define yy_load_buffer_state _nsyy_load_buffer_state +#define yy_switch_to_buffer _nsyy_switch_to_buffer +#define yyin _nsyyin +#define yyleng _nsyyleng +#define yylex _nsyylex +#define yyout _nsyyout +#define yyrestart _nsyyrestart +#define yytext _nsyytext +#define yylineno _nsyylineno +#define yywrap _nsyywrap + +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + * $Header$ + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + +#include +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include +#include +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 1024 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + +static YY_BUFFER_STATE yy_current_buffer = 0; + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart YY_PROTO(( FILE *input_file )); + +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) + +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + + +#define YY_USES_REJECT +typedef unsigned char YY_CHAR; +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +typedef int yy_state_type; +extern int yylineno; +int yylineno = 1; +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 13 +#define YY_END_OF_BUFFER 14 +static yyconst short int yy_acclist[83] = + { 0, + 14, 12, 13, 1, 12, 13, 4, 13, 2, 12, + 13, 11, 12, 13, 11, 12, 13, 11, 12, 13, + 11, 12, 13, 11, 12, 13, 11, 12, 13, 11, + 12, 13, 12, 13, 1, 2, 11, 11, 11, 11, + 11, 11, 11, 3, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 9, 11, 11, 11, 11, 11, + 11, 5, 11, 11, 6, 11, 10, 11, 7, 11, + 8, 11 + } ; + +static yyconst short int yy_accept[60] = + { 0, + 1, 1, 1, 2, 4, 7, 9, 12, 15, 18, + 21, 24, 27, 30, 33, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, + 71, 72, 74, 75, 77, 79, 81, 83, 83 + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 1, 4, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, + 1, 1, 1, 1, 6, 7, 8, 9, 10, 11, + 12, 7, 13, 7, 7, 14, 7, 15, 16, 7, + 7, 17, 18, 19, 20, 21, 7, 7, 22, 7, + 1, 23, 1, 1, 5, 1, 6, 7, 8, 9, + + 10, 11, 12, 7, 13, 7, 7, 14, 7, 15, + 16, 7, 7, 17, 18, 19, 20, 21, 7, 7, + 22, 7, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[24] = + { 0, + 1, 1, 2, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 1 + } ; + +static yyconst short int yy_base[61] = + { 0, + 0, 0, 68, 69, 65, 69, 0, 0, 50, 49, + 54, 43, 45, 46, 57, 57, 0, 0, 43, 38, + 37, 47, 32, 47, 69, 33, 40, 30, 41, 42, + 26, 33, 29, 27, 33, 30, 35, 25, 19, 23, + 19, 30, 22, 14, 18, 0, 14, 18, 16, 19, + 19, 0, 12, 0, 0, 0, 0, 69, 23, 22 + } ; + +static yyconst short int yy_def[61] = + { 0, + 58, 1, 58, 58, 58, 58, 59, 60, 60, 60, + 60, 60, 60, 60, 58, 58, 59, 60, 60, 60, + 60, 60, 60, 60, 58, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 0, 58, 58 + } ; + +static yyconst short int yy_nxt[93] = + { 0, + 4, 5, 6, 7, 4, 8, 8, 9, 8, 8, + 8, 8, 8, 8, 10, 8, 11, 12, 13, 14, + 8, 8, 15, 17, 18, 17, 57, 56, 55, 54, + 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, + 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, + 33, 32, 31, 30, 29, 28, 27, 26, 16, 25, + 24, 23, 22, 21, 20, 19, 16, 58, 3, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58 + + } ; + +static yyconst short int yy_chk[93] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 59, 60, 59, 53, 51, 50, 49, + 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, + 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, + 27, 26, 24, 23, 22, 21, 20, 19, 16, 15, + 14, 13, 12, 11, 10, 9, 5, 3, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58 + + } ; + +static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr; +static char *yy_full_match; +static int yy_lp; +#define REJECT \ +{ \ +*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \ +yy_cp = yy_full_match; /* restore poss. backed-over text */ \ +++yy_lp; \ +goto find_rule; \ +} +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "nslexer.l" +#define INITIAL 0 +#line 2 "nslexer.l" +/* $NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = + "$FreeBSD: src/lib/libc/net/nslexer.l,v 1.3 2001/11/11 02:48:09 bde Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#define _NS_PRIVATE +#include +#include + +#include "nsparser.h" + +#define YY_NO_UNPUT + + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +#ifndef YY_NO_UNPUT +static void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( yy_current_buffer->yy_is_interactive ) \ + { \ + int c = '*', n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ + && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yylex YY_PROTO(( void )) +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp = NULL, *yy_bp = NULL; + register int yy_act; + +#line 65 "nslexer.l" + + + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 59 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 69 ); + +yy_find_action: + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; +find_rule: /* we branch to this label when backing up */ + for ( ; ; ) /* until we find what rule we matched */ + { + if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[yy_lp]; + { + yy_full_match = yy_cp; + break; + } + } + --yy_cp; + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + if ( yy_act != YY_END_OF_BUFFER ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + ++yylineno; + } + +do_action: /* This label is used only to access EOF actions. */ + + + switch ( yy_act ) + { /* beginning of action switch */ +case 1: +YY_RULE_SETUP +#line 67 "nslexer.l" +; /* skip whitespace */ + YY_BREAK +case 2: +YY_RULE_SETUP +#line 69 "nslexer.l" +; /* skip comments */ + YY_BREAK +case 3: +YY_RULE_SETUP +#line 71 "nslexer.l" +; /* allow continuation */ + YY_BREAK +case 4: +YY_RULE_SETUP +#line 73 "nslexer.l" +return NL; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 75 "nslexer.l" +return SUCCESS; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 76 "nslexer.l" +return UNAVAIL; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 77 "nslexer.l" +return NOTFOUND; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 78 "nslexer.l" +return TRYAGAIN; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 80 "nslexer.l" +return RETURN; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 81 "nslexer.l" +return CONTINUE; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 83 "nslexer.l" +{ + char *p; + int i; + size_t len; + + len = strlen (yytext) + 1; + if ((p = malloc (len)) == NULL) + printf("nsdispatch: memory allocation failure\n"); + else + memcpy (p, yytext, len); + + for (i = 0; i < strlen(p); i++) { + if (isupper((unsigned char)p[i])) + p[i] = tolower((unsigned char)p[i]); + } + _nsyylval.str = p; + return STRING; + } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 99 "nslexer.l" +return yytext[0]; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 101 "nslexer.l" +ECHO; + YY_BREAK + case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +static yy_state_type yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 59 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +yy_state_type yy_current_state; +#endif + { + register int yy_is_jam; + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 59 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 58); + if ( ! yy_is_jam ) + *yy_state_ptr++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; + } + + +#ifndef YY_NO_UNPUT +#ifdef YY_USE_PROTOS +static void yyunput( int c, register char *yy_bp ) +#else +static void yyunput( c, yy_bp ) +int c; +register char *yy_bp; +#endif + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + if ( c == '\n' ) + --yylineno; + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } +#endif /* ifndef YY_NO_UNPUT */ + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + if ( c == '\n' ) + ++yylineno; + + return c; + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif + } + + +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } +#endif + + +#ifndef YY_NO_SCAN_STRING +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) +#else +YY_BUFFER_STATE yy_scan_string( yy_str ) +yyconst char *yy_str; +#endif + { + int len; + for ( len = 0; yy_str[len]; ++len ) + ; + + return yy_scan_bytes( yy_str, len ); + } +#endif + + +#ifndef YY_NO_SCAN_BYTES +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +#endif + + +#ifndef YY_NO_PUSH_STATE +#ifdef YY_USE_PROTOS +static void yy_push_state( int new_state ) +#else +static void yy_push_state( new_state ) +int new_state; +#endif + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +static void yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +static int yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +#ifdef YY_USE_PROTOS +static void yy_fatal_error( yyconst char msg[] ) +#else +static void yy_fatal_error( msg ) +char msg[]; +#endif + { + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); + } + + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 101 "nslexer.l" + + +#undef _nsyywrap +int +_nsyywrap() +{ + return 1; +} /* _nsyywrap */ + +void +_nsyyerror(msg) + const char *msg; +{ + + printf("Error in nslexer\n"); +} /* _nsyyerror */ diff --git a/newlib/libc/sys/linux/net/nslexer.l b/newlib/libc/sys/linux/net/nslexer.l new file mode 100644 index 000000000..0b66b6c66 --- /dev/null +++ b/newlib/libc/sys/linux/net/nslexer.l @@ -0,0 +1,114 @@ +%{ +/* $NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = + "$FreeBSD: src/lib/libc/net/nslexer.l,v 1.3 2001/11/11 02:48:09 bde Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#define _NS_PRIVATE +#include +#include + +#include "nsparser.h" + +#define YY_NO_UNPUT + +%} + +%option yylineno + +BLANK [ \t] +CR \n +STRING [a-zA-Z][a-zA-Z0-9_]* + +%% + +{BLANK}+ ; /* skip whitespace */ + +#.* ; /* skip comments */ + +\\{CR} ; /* allow continuation */ + +{CR} return NL; + +[sS][uU][cC][cC][eE][sS][sS] return SUCCESS; +[uU][nN][aA][vV][aA][iI][lL] return UNAVAIL; +[nN][oO][tT][fF][oO][uU][nN][dD] return NOTFOUND; +[tT][rR][yY][aA][gG][aA][iI][nN] return TRYAGAIN; + +[rR][eE][tT][uU][rR][nN] return RETURN; +[cC][oO][nN][tT][iI][nN][uU][eE] return CONTINUE; + +{STRING} { + char *p; + int i; + + if ((p = strdup(yytext)) == NULL) + printf("nsdispatch: memory allocation failure\n"); + + for (i = 0; i < strlen(p); i++) { + if (isupper((unsigned char)p[i])) + p[i] = tolower((unsigned char)p[i]); + } + _nsyylval.str = p; + return STRING; + } + +. return yytext[0]; + +%% + +#undef _nsyywrap +int +_nsyywrap() +{ + return 1; +} /* _nsyywrap */ + +void +_nsyyerror(msg) + const char *msg; +{ + + printf("Error in nslexer\n"); +} /* _nsyyerror */ diff --git a/newlib/libc/sys/linux/net/nsparser.c b/newlib/libc/sys/linux/net/nsparser.c new file mode 100644 index 000000000..b4701aed1 --- /dev/null +++ b/newlib/libc/sys/linux/net/nsparser.c @@ -0,0 +1,541 @@ +#ifndef lint +static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 +#define yyclearin (yychar=(-1)) +#define yyerrok (yyerrflag=0) +#define YYRECOVERING (yyerrflag!=0) +#define yyparse _nsyyparse +#define yylex _nsyylex +#define yyerror _nsyyerror +#define yychar _nsyychar +#define yyval _nsyyval +#define yylval _nsyylval +#define yydebug _nsyydebug +#define yynerrs _nsyynerrs +#define yyerrflag _nsyyerrflag +#define yyss _nsyyss +#define yyssp _nsyyssp +#define yyvs _nsyyvs +#define yyvsp _nsyyvsp +#define yylhs _nsyylhs +#define yylen _nsyylen +#define yydefred _nsyydefred +#define yydgoto _nsyydgoto +#define yysindex _nsyysindex +#define yyrindex _nsyyrindex +#define yygindex _nsyygindex +#define yytable _nsyytable +#define yycheck _nsyycheck +#define yyname _nsyyname +#define yyrule _nsyyrule +#define YYPREFIX "_nsyy" +#line 2 "nsparser.y" +/* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = + "$FreeBSD: src/lib/libc/net/nsparser.y,v 1.3 2002/03/21 22:47:17 obrien Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#define _NS_PRIVATE +#include +#include +#include + + +static void _nsaddsrctomap(const char *); + +static ns_dbt curdbt; +static ns_src cursrc; +#line 59 "nsparser.y" +typedef union { + char *str; + int mapval; +} YYSTYPE; +#line 97 "y.tab.c" +#define NL 257 +#define SUCCESS 258 +#define UNAVAIL 259 +#define NOTFOUND 260 +#define TRYAGAIN 261 +#define RETURN 262 +#define CONTINUE 263 +#define STRING 264 +#define YYERRCODE 256 +short _nsyylhs[] = { -1, + 0, 0, 3, 3, 4, 4, 4, 4, 5, 6, + 6, 7, 9, 7, 8, 8, 10, 1, 1, 1, + 1, 2, 2, +}; +short _nsyylen[] = { 2, + 0, 1, 1, 2, 1, 3, 4, 2, 1, 1, + 2, 1, 0, 5, 1, 2, 3, 1, 1, 1, + 1, 1, 1, +}; +short _nsyydefred[] = { 0, + 0, 5, 9, 0, 0, 3, 0, 8, 4, 0, + 6, 0, 0, 10, 13, 7, 11, 0, 18, 19, + 20, 21, 0, 0, 15, 0, 14, 16, 22, 23, + 17, +}; +short _nsyydgoto[] = { 4, + 23, 31, 5, 6, 7, 13, 14, 24, 18, 25, +}; +short _nsyysindex[] = { -255, + -249, 0, 0, 0, -255, 0, -41, 0, 0, -254, + 0, -73, -253, 0, 0, 0, 0, -245, 0, 0, + 0, 0, -42, -93, 0, -256, 0, 0, 0, 0, + 0, +}; +short _nsyyrindex[] = { 20, + 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, + 0, -252, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, +}; +short _nsyygindex[] = { 0, + 0, 0, 0, 17, 0, 0, 10, 0, 0, 1, +}; +#define YYTABLESIZE 168 +short _nsyytable[] = { 27, + 1, 2, 11, 16, 12, 29, 30, 8, 3, 12, + 12, 12, 19, 20, 21, 22, 10, 15, 26, 1, + 2, 9, 17, 0, 28, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 19, 20, 21, 22, +}; +short _nsyycheck[] = { 93, + 256, 257, 257, 257, 257, 262, 263, 257, 264, 264, + 264, 264, 258, 259, 260, 261, 58, 91, 61, 0, + 0, 5, 13, -1, 24, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 258, 259, 260, 261, +}; +#define YYFINAL 4 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 264 +#if YYDEBUG +char *_nsyyname[] = { +"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,"'='",0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'",0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NL","SUCCESS", +"UNAVAIL","NOTFOUND","TRYAGAIN","RETURN","CONTINUE","STRING", +}; +char *_nsyyrule[] = { +"$accept : File", +"File :", +"File : Lines", +"Lines : Entry", +"Lines : Lines Entry", +"Entry : NL", +"Entry : Database ':' NL", +"Entry : Database ':' Srclist NL", +"Entry : error NL", +"Database : STRING", +"Srclist : Item", +"Srclist : Srclist Item", +"Item : STRING", +"$$1 :", +"Item : STRING '[' $$1 Criteria ']'", +"Criteria : Criterion", +"Criteria : Criteria Criterion", +"Criterion : Status '=' Action", +"Status : SUCCESS", +"Status : UNAVAIL", +"Status : NOTFOUND", +"Status : TRYAGAIN", +"Action : RETURN", +"Action : CONTINUE", +}; +#endif +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif +int yydebug; +int yynerrs; +int yyerrflag; +int yychar; +short *yyssp; +YYSTYPE *yyvsp; +YYSTYPE yyval; +YYSTYPE yylval; +short yyss[YYSTACKSIZE]; +YYSTYPE yyvs[YYSTACKSIZE]; +#define yystacksize YYSTACKSIZE +#line 150 "nsparser.y" + +static void +_nsaddsrctomap(elem) + const char *elem; +{ + int i, lineno; + extern int _nsyylineno; + extern char * _nsyytext; + + lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); + if (curdbt.srclistsize > 0) { + if ((strcasecmp(elem, NSSRC_COMPAT) == 0) || + (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { + /* XXX: syslog the following */ + printf("line %d 'compat' used with other sources", + lineno); + return; + } + } + for (i = 0; i < curdbt.srclistsize; i++) { + if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { + /* XXX: syslog the following */ + printf("%s line %d: duplicate source '%s'", + lineno, elem); + return; + } + } + cursrc.name = elem; + _nsdbtaddsrc(&curdbt, &cursrc); +} +#line 276 "y.tab.c" +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab +int +yyparse() +{ + register int yym, yyn, yystate; +#if YYDEBUG + register char *yys; + extern char *getenv(); + + if (yys = getenv("YYDEBUG")) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = (-1); + + yyssp = yyss; + yyvsp = yyvs; + *yyssp = yystate = 0; + +yyloop: + if (yyn = yydefred[yystate]) goto yyreduce; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + yychar = (-1); + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; +#ifdef lint + goto yynewerror; +#endif +yynewerror: + yyerror("syntax error"); +#ifdef lint + goto yyerrlab; +#endif +yyerrlab: + ++yynerrs; +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yyssp); +#endif + if (yyssp <= yyss) goto yyabort; + --yyssp; + --yyvsp; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = (-1); + goto yyloop; + } +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + yyval = yyvsp[1-yym]; + switch (yyn) + { +case 7: +#line 87 "nsparser.y" +{ + _nsdbtput(&curdbt); + } +break; +case 8: +#line 91 "nsparser.y" +{ + yyerrok; + } +break; +case 9: +#line 98 "nsparser.y" +{ + curdbt.name = yylval.str; + curdbt.srclist = NULL; + curdbt.srclistsize = 0; + } +break; +case 12: +#line 112 "nsparser.y" +{ + cursrc.flags = NS_SUCCESS; + _nsaddsrctomap(yyvsp[0].str); + } +break; +case 13: +#line 116 "nsparser.y" +{ cursrc.flags = NS_SUCCESS; } +break; +case 14: +#line 117 "nsparser.y" +{ + _nsaddsrctomap(yyvsp[-4].str); + } +break; +case 17: +#line 129 "nsparser.y" +{ + if (yyvsp[0].mapval) /* if action == RETURN set RETURN bit */ + cursrc.flags |= yyvsp[-2].mapval; + else /* else unset it */ + cursrc.flags &= ~yyvsp[-2].mapval; + } +break; +case 18: +#line 138 "nsparser.y" +{ yyval.mapval = NS_SUCCESS; } +break; +case 19: +#line 139 "nsparser.y" +{ yyval.mapval = NS_UNAVAIL; } +break; +case 20: +#line 140 "nsparser.y" +{ yyval.mapval = NS_NOTFOUND; } +break; +case 21: +#line 141 "nsparser.y" +{ yyval.mapval = NS_TRYAGAIN; } +break; +case 22: +#line 145 "nsparser.y" +{ yyval.mapval = 1L; } +break; +case 23: +#line 146 "nsparser.y" +{ yyval.mapval = 0L; } +break; +#line 487 "y.tab.c" + } + yyssp -= yym; + yystate = *yyssp; + yyvsp -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yyssp = YYFINAL; + *++yyvsp = yyval; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yyssp, yystate); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate; + *++yyvsp = yyval; + goto yyloop; +yyoverflow: + yyerror("yacc stack overflow"); +yyabort: + return (1); +yyaccept: + return (0); +} diff --git a/newlib/libc/sys/linux/net/nsparser.h b/newlib/libc/sys/linux/net/nsparser.h new file mode 100644 index 000000000..6a6fae0be --- /dev/null +++ b/newlib/libc/sys/linux/net/nsparser.h @@ -0,0 +1,13 @@ +#define NL 257 +#define SUCCESS 258 +#define UNAVAIL 259 +#define NOTFOUND 260 +#define TRYAGAIN 261 +#define RETURN 262 +#define CONTINUE 263 +#define STRING 264 +typedef union { + char *str; + int mapval; +} YYSTYPE; +extern YYSTYPE _nsyylval; diff --git a/newlib/libc/sys/linux/net/nsparser.y b/newlib/libc/sys/linux/net/nsparser.y new file mode 100644 index 000000000..42f63a8a5 --- /dev/null +++ b/newlib/libc/sys/linux/net/nsparser.y @@ -0,0 +1,178 @@ +%{ +/* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = + "$FreeBSD: src/lib/libc/net/nsparser.y,v 1.3 2002/03/21 22:47:17 obrien Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#define _NS_PRIVATE +#include +#include +#include + + +static void _nsaddsrctomap(const char *); + +static ns_dbt curdbt; +static ns_src cursrc; +%} + +%union { + char *str; + int mapval; +} + +%token NL +%token SUCCESS UNAVAIL NOTFOUND TRYAGAIN +%token RETURN CONTINUE +%token STRING + +%type Status Action + +%% + +File + : /* empty */ + | Lines + ; + +Lines + : Entry + | Lines Entry + ; + +Entry + : NL + | Database ':' NL + | Database ':' Srclist NL + { + _nsdbtput(&curdbt); + } + | error NL + { + yyerrok; + } + ; + +Database + : STRING + { + curdbt.name = yylval.str; + curdbt.srclist = NULL; + curdbt.srclistsize = 0; + } + ; + +Srclist + : Item + | Srclist Item + ; + +Item + : STRING + { + cursrc.flags = NS_SUCCESS; + _nsaddsrctomap($1); + } + | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' + { + _nsaddsrctomap($1); + } + ; + +Criteria + : Criterion + | Criteria Criterion + ; + +Criterion + : Status '=' Action + { + if ($3) /* if action == RETURN set RETURN bit */ + cursrc.flags |= $1; + else /* else unset it */ + cursrc.flags &= ~$1; + } + ; + +Status + : SUCCESS { $$ = NS_SUCCESS; } + | UNAVAIL { $$ = NS_UNAVAIL; } + | NOTFOUND { $$ = NS_NOTFOUND; } + | TRYAGAIN { $$ = NS_TRYAGAIN; } + ; + +Action + : RETURN { $$ = 1L; } + | CONTINUE { $$ = 0L; } + ; + +%% + +static void +_nsaddsrctomap(elem) + const char *elem; +{ + int i, lineno; + extern int _nsyylineno; + extern char * _nsyytext; + + lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); + if (curdbt.srclistsize > 0) { + if ((strcasecmp(elem, NSSRC_COMPAT) == 0) || + (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { + /* XXX: syslog the following */ + printf("line %d 'compat' used with other sources", + lineno); + return; + } + } + for (i = 0; i < curdbt.srclistsize; i++) { + if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { + /* XXX: syslog the following */ + printf("%s line %d: duplicate source '%s'", + lineno, elem); + return; + } + } + cursrc.name = elem; + _nsdbtaddsrc(&curdbt, &cursrc); +} diff --git a/newlib/libc/sys/linux/net/nss.h b/newlib/libc/sys/linux/net/nss.h deleted file mode 100644 index f5c12afab..000000000 --- a/newlib/libc/sys/linux/net/nss.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Define interface to NSS. This is meant for the interface functions - and for implementors of new services. */ - -#ifndef _NSS_H -#define _NSS_H 1 - -#include - - -__BEGIN_DECLS - -/* Possible results of lookup using a nss_* function. */ -enum nss_status -{ - NSS_STATUS_TRYAGAIN = -2, - NSS_STATUS_UNAVAIL, - NSS_STATUS_NOTFOUND, - NSS_STATUS_SUCCESS, - NSS_STATUS_RETURN -}; - - -/* Overwrite service selection for database DBNAME using specification - in STRING. - This function should only be used by system programs which have to - work around non-existing services (e.e., while booting). - Attention: Using this function repeatedly will slowly eat up the - whole memory since previous selection data cannot be freed. */ -extern int __nss_configure_lookup (__const char *__dbname, - __const char *__string) __THROW; - -__END_DECLS - -#endif /* nss.h */ diff --git a/newlib/libc/sys/linux/net/nsswitch.c b/newlib/libc/sys/linux/net/nsswitch.c deleted file mode 100644 index 6c5d1f8e9..000000000 --- a/newlib/libc/sys/linux/net/nsswitch.c +++ /dev/null @@ -1,772 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "local.h" - -#if !defined DO_STATIC_NSS || defined SHARED -# include -#endif - -#include "nsswitch.h" -#include "nscd/nscd_proto.h" - -/* Prototypes for the local functions. */ -static name_database *nss_parse_file (const char *fname) internal_function; -static name_database_entry *nss_getline (char *line) internal_function; -static service_user *nss_parse_service_list (const char *line) - internal_function; -static service_library *nss_new_service (name_database *database, - const char *name) internal_function; - - -/* Declare external database variables. */ -#define DEFINE_DATABASE(name) \ - extern service_user *__nss_##name##_database attribute_hidden; \ - weak_extern (__nss_##name##_database) -#include "databases.def" -#undef DEFINE_DATABASE - -/* Structure to map database name to variable. */ -static struct -{ - const char *name; - service_user **dbp; -} databases[] = -{ -#define DEFINE_DATABASE(name) \ - { #name, &__nss_##name##_database }, -#include "databases.def" -#undef DEFINE_DATABASE -}; - - -__libc_lock_define_initialized (static, lock) - -#if !defined DO_STATIC_NSS || defined SHARED -/* String with revision number of the shared object files. */ -static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15; -#endif - -/* The root of the whole data base. */ -static name_database *service_table; - - -/* -1 == database not found - 0 == database entry pointer stored */ -int -__nss_database_lookup (const char *database, const char *alternate_name, - const char *defconfig, service_user **ni) -{ - /* Prevent multiple threads to change the service table. */ - __libc_lock_lock (lock); - - /* Reconsider database variable in case some other thread called - `__nss_configure_lookup' while we waited for the lock. */ - if (*ni != NULL) - { - __libc_lock_unlock (lock); - return 0; - } - - /* Are we initialized yet? */ - if (service_table == NULL) - /* Read config file. */ - service_table = nss_parse_file (_PATH_NSSWITCH_CONF); - - /* Test whether configuration data is available. */ - if (service_table != NULL) - { - /* Return first `service_user' entry for DATABASE. */ - name_database_entry *entry; - - /* XXX Could use some faster mechanism here. But each database is - only requested once and so this might not be critical. */ - for (entry = service_table->entry; entry != NULL; entry = entry->next) - if (strcmp (database, entry->name) == 0) - *ni = entry->service; - - if (*ni == NULL && alternate_name != NULL) - /* We haven't found an entry so far. Try to find it with the - alternative name. */ - for (entry = service_table->entry; entry != NULL; entry = entry->next) - if (strcmp (alternate_name, entry->name) == 0) - *ni = entry->service; - } - - /* No configuration data is available, either because nsswitch.conf - doesn't exist or because it doesn't has a line for this database. - - DEFCONFIG specifies the default service list for this database, - or null to use the most common default. */ - if (*ni == NULL) - *ni = nss_parse_service_list (defconfig - ?: "nis [NOTFOUND=return] files"); - - __libc_lock_unlock (lock); - - return 0; -} -libc_hidden_def (__nss_database_lookup) - - -/* -1 == not found - 0 == function found - 1 == finished */ -int -__nss_lookup (service_user **ni, const char *fct_name, void **fctp) -{ - *fctp = __nss_lookup_function (*ni, fct_name); - - while (*fctp == NULL - && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE - && (*ni)->next != NULL) - { - *ni = (*ni)->next; - - *fctp = __nss_lookup_function (*ni, fct_name); - } - - return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1; -} - - -/* -1 == not found - 0 == adjusted for next function - 1 == finished */ -int -__nss_next (service_user **ni, const char *fct_name, void **fctp, int status, - int all_values) -{ - if (all_values) - { - if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN - && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN - && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN - && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN) - return 1; - } - else - { - /* This is really only for debugging. */ - if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN) - { - fprintf (stderr, "illegal status in __nss_next"); - abort(); - } - - if (nss_next_action (*ni, status) == NSS_ACTION_RETURN) - return 1; - } - - if ((*ni)->next == NULL) - return -1; - - do - { - *ni = (*ni)->next; - - *fctp = __nss_lookup_function (*ni, fct_name); - } - while (*fctp == NULL - && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE - && (*ni)->next != NULL); - - return *fctp != NULL ? 0 : -1; -} -libc_hidden_def (__nss_next) - - -int -__nss_configure_lookup (const char *dbname, const char *service_line) -{ - service_user *new_db; - size_t cnt; - - for (cnt = 0; cnt < sizeof databases; ++cnt) - { - int cmp = strcmp (dbname, databases[cnt].name); - if (cmp == 0) - break; - if (cmp < 0) - { - __set_errno (EINVAL); - return -1; - } - } - - if (cnt == sizeof databases) - { - __set_errno (EINVAL); - return -1; - } - - /* Test whether it is really used. */ - if (databases[cnt].dbp == NULL) - /* Nothing to do, but we could do. */ - return 0; - - /* Try to generate new data. */ - new_db = nss_parse_service_list (service_line); - if (new_db == NULL) - { - /* Illegal service specification. */ - __set_errno (EINVAL); - return -1; - } - - /* Prevent multiple threads to change the service table. */ - __libc_lock_lock (lock); - - /* Install new rules. */ - *databases[cnt].dbp = new_db; - - __libc_lock_unlock (lock); - - return 0; -} - - -/* Comparison function for searching NI->known tree. */ -static int -known_compare (const void *p1, const void *p2) -{ - return p1 == p2 ? 0 : strcmp (*(const char *const *) p1, - *(const char *const *) p2); -} - - -void * -__nss_lookup_function (service_user *ni, const char *fct_name) -{ - void **found, *result; - - /* We now modify global data. Protect it. */ - __libc_lock_lock (lock); - - /* Search the tree of functions previously requested. Data in the - tree are `known_function' structures, whose first member is a - `const char *', the lookup key. The search returns a pointer to - the tree node structure; the first member of the is a pointer to - our structure (i.e. what will be a `known_function'); since the - first member of that is the lookup key string, &FCT_NAME is close - enough to a pointer to our structure to use as a lookup key that - will be passed to `known_compare' (above). */ - - found = tsearch (&fct_name, (void **) &ni->known, &known_compare); - if (*found != &fct_name) - /* The search found an existing structure in the tree. */ - result = ((known_function *) *found)->fct_ptr; - else - { - /* This name was not known before. Now we have a node in the tree - (in the proper sorted position for FCT_NAME) that points to - &FCT_NAME instead of any real `known_function' structure. - Allocate a new structure and fill it in. */ - - known_function *known = malloc (sizeof *known); - if (! known) - { - remove_from_tree: - /* Oops. We can't instantiate this node properly. - Remove it from the tree. */ - tdelete (&fct_name, (void **) &ni->known, &known_compare); - result = NULL; - } - else - { - /* Point the tree node at this new structure. */ - *found = known; - known->fct_name = fct_name; - - if (ni->library == NULL) - { - /* This service has not yet been used. Fetch the service - library for it, creating a new one if need be. If there - is no service table from the file, this static variable - holds the head of the service_library list made from the - default configuration. */ - static name_database default_table; - ni->library = nss_new_service (service_table ?: &default_table, - ni->name); - if (ni->library == NULL) - { - /* This only happens when out of memory. */ - free (known); - goto remove_from_tree; - } - } - -#if !defined DO_STATIC_NSS || defined SHARED - if (ni->library->lib_handle == NULL) - { - /* Load the shared library. */ - size_t shlen = (7 + strlen (ni->library->name) + 3 - + strlen (__nss_shlib_revision) + 1); - int saved_errno = errno; - char shlib_name[shlen]; - - /* Construct shared object name. */ - stpcpy (stpcpy (stpcpy (stpcpy (shlib_name, - "libnss_"), - ni->library->name), - ".so"), - __nss_shlib_revision); - - ni->library->lib_handle = __libc_dlopen (shlib_name); - if (ni->library->lib_handle == NULL) - { - /* Failed to load the library. */ - ni->library->lib_handle = (void *) -1l; - __set_errno (saved_errno); - } - } - - if (ni->library->lib_handle == (void *) -1l) - /* Library not found => function not found. */ - result = NULL; - else - { - /* Get the desired function. */ - size_t namlen = (5 + strlen (ni->library->name) + 1 - + strlen (fct_name) + 1); - char name[namlen]; - - /* Construct the function name. */ - stpcpy (stpcpy (stpcpy (stpcpy (name, "_nss_"), - ni->library->name), - "_"), - fct_name); - - /* Look up the symbol. */ - result = __libc_dlsym (ni->library->lib_handle, name); - } -#else - /* We can't get function address dynamically in static linking. */ - { -# define DEFINE_ENT(h,nm) \ - { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \ - { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \ - { #h"_set"#nm"ent", _nss_##h##_set##nm##ent }, -# define DEFINE_GET(h,nm) \ - { #h"_get"#nm"_r", _nss_##h##_get##nm##_r }, -# define DEFINE_GETBY(h,nm,ky) \ - { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r }, - static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] = - { -# include "function.def" - { NULL, NULL } - }; - size_t namlen = (5 + strlen (ni->library->name) + 1 - + strlen (fct_name) + 1); - char name[namlen]; - - /* Construct the function name. */ - stpcpy (stpcpy (stpcpy (name, ni->library->name), - "_"), - fct_name); - - result = NULL; - for (tp = &tbl[0]; tp->fname; tp++) - if (strcmp (tp->fname, name) == 0) - { - result = tp->fp; - break; - } - } -#endif - - /* Remember function pointer for later calls. Even if null, we - record it so a second try needn't search the library again. */ - known->fct_ptr = result; - } - } - - /* Remove the lock. */ - __libc_lock_unlock (lock); - - return result; -} -libc_hidden_def (__nss_lookup_function) - - -static name_database * -internal_function -nss_parse_file (const char *fname) -{ - FILE *fp; - name_database *result; - name_database_entry *last; - char *line; - size_t len; - - /* Open the configuration file. */ - fp = fopen (fname, "rc"); - if (fp == NULL) - return NULL; - - /* No threads use this stream. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - result = (name_database *) malloc (sizeof (name_database)); - if (result == NULL) - return NULL; - - result->entry = NULL; - result->library = NULL; - last = NULL; - line = NULL; - len = 0; - do - { - name_database_entry *this; - ssize_t n; - char *tmp; - - n = __getline (&line, &len, fp); - if (n < 0) - break; - if (line[n - 1] == '\n') - line[n - 1] = '\0'; - - /* Because the file format does not know any form of quoting we - can search forward for the next '#' character and if found - make it terminating the line. */ - tmp = strchr (line, '#'); - if (tmp == NULL) - tmp = line + strlen (line); - *tmp = '\0'; - - /* If the line is blank it is ignored. */ - if (line[0] == '\0') - continue; - - /* Each line completely specifies the actions for a database. */ - this = nss_getline (line); - if (this != NULL) - { - if (last != NULL) - last->next = this; - else - result->entry = this; - - last = this; - } - } - while (!feof (fp)); - - /* Free the buffer. */ - free (line); - /* Close configuration file. */ - fclose (fp); - - return result; -} - - -/* Read the source names: - `( ( "[" "!"? ( "=" )+ "]" )? )*' - */ -static service_user * -internal_function -nss_parse_service_list (const char *line) -{ - service_user *result = NULL, **nextp = &result; - - while (1) - { - service_user *new_service; - const char *name; - - while (isspace (line[0])) - ++line; - if (line[0] == '\0') - /* No source specified. */ - return result; - - /* Read identifier. */ - name = line; - while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[') - ++line; - if (name == line) - return result; - - - new_service = (service_user *) malloc (sizeof (service_user) - + (line - name + 1)); - if (new_service == NULL) - return result; - - *((char *) mempcpy (new_service->name, name, line - name)) = '\0'; - - /* Set default actions. */ - new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE; - new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE; - new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE; - new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN; - new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN; - new_service->library = NULL; - new_service->known = NULL; - new_service->next = NULL; - - while (isspace (line[0])) - ++line; - - if (line[0] == '[') - { - /* Read criterions. */ - do - ++line; - while (line[0] != '\0' && isspace (line[0])); - - do - { - int not; - enum nss_status status; - lookup_actions action; - - /* Grok ! before name to mean all statii but that one. */ - not = line[0] == '!'; - if (not) - ++line; - - /* Read status name. */ - name = line; - while (line[0] != '\0' && !isspace (line[0]) && line[0] != '=' - && line[0] != ']') - ++line; - - /* Compare with known statii. */ - if (line - name == 7) - { - if (strncasecmp (name, "SUCCESS", 7) == 0) - status = NSS_STATUS_SUCCESS; - else if (strncasecmp (name, "UNAVAIL", 7) == 0) - status = NSS_STATUS_UNAVAIL; - else - return result; - } - else if (line - name == 8) - { - if (strncasecmp (name, "NOTFOUND", 8) == 0) - status = NSS_STATUS_NOTFOUND; - else if (strncasecmp (name, "TRYAGAIN", 8) == 0) - status = NSS_STATUS_TRYAGAIN; - else - return result; - } - else - return result; - - while (isspace (line[0])) - ++line; - if (line[0] != '=') - return result; - do - ++line; - while (isspace (line[0])); - - name = line; - while (line[0] != '\0' && !isspace (line[0]) && line[0] != '=' - && line[0] != ']') - ++line; - - if (line - name == 6 && strncasecmp (name, "RETURN", 6) == 0) - action = NSS_ACTION_RETURN; - else if (line - name == 8 - && strncasecmp (name, "CONTINUE", 8) == 0) - action = NSS_ACTION_CONTINUE; - else - return result; - - if (not) - { - /* Save the current action setting for this status, - set them all to the given action, and reset this one. */ - const lookup_actions save = new_service->actions[2 + status]; - new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action; - new_service->actions[2 + NSS_STATUS_UNAVAIL] = action; - new_service->actions[2 + NSS_STATUS_NOTFOUND] = action; - new_service->actions[2 + NSS_STATUS_SUCCESS] = action; - new_service->actions[2 + status] = save; - } - else - new_service->actions[2 + status] = action; - - /* Skip white spaces. */ - while (isspace (line[0])) - ++line; - } - while (line[0] != ']'); - - /* Skip the ']'. */ - ++line; - } - - *nextp = new_service; - nextp = &new_service->next; - } -} - -static name_database_entry * -internal_function -nss_getline (char *line) -{ - const char *name; - name_database_entry *result; - size_t len; - - /* Ignore leading white spaces. ATTENTION: this is different from - what is implemented in Solaris. The Solaris man page says a line - beginning with a white space character is ignored. We regard - this as just another misfeature in Solaris. */ - while (isspace (line[0])) - ++line; - - /* Recognize ` ":"'. */ - name = line; - while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':') - ++line; - if (line[0] == '\0' || name == line) - /* Syntax error. */ - return NULL; - *line++ = '\0'; - - len = strlen (name) + 1; - - result = (name_database_entry *) malloc (sizeof (name_database_entry) + len); - if (result == NULL) - return NULL; - - /* Save the database name. */ - memcpy (result->name, name, len); - - /* Parse the list of services. */ - result->service = nss_parse_service_list (line); - - result->next = NULL; - return result; -} - - -static service_library * -internal_function -nss_new_service (name_database *database, const char *name) -{ - service_library **currentp = &database->library; - - while (*currentp != NULL) - { - if (strcmp ((*currentp)->name, name) == 0) - return *currentp; - currentp = &(*currentp)->next; - } - - /* We have to add the new service. */ - *currentp = (service_library *) malloc (sizeof (service_library)); - if (*currentp == NULL) - return NULL; - - (*currentp)->name = name; - (*currentp)->lib_handle = NULL; - (*currentp)->next = NULL; - - return *currentp; -} - - -#ifdef USE_NSCD -/* Called by nscd and nscd alone. */ -void -__nss_disable_nscd (void) -{ - /* Disable all uses of NSCD. */ - __nss_not_use_nscd_passwd = -1; - __nss_not_use_nscd_group = -1; - __nss_not_use_nscd_hosts = -1; -} -#endif - - -/* Free all resources if necessary. */ -libc_freeres_fn (free_mem) -{ - name_database *top = service_table; - name_database_entry *entry; - service_library *library; - - if (top == NULL) - /* Maybe we have not read the nsswitch.conf file. */ - return; - - /* Don't disturb ongoing other threads (if there are any). */ - service_table = NULL; - - entry = top->entry; - while (entry != NULL) - { - name_database_entry *olde = entry; - service_user *service = entry->service; - - while (service != NULL) - { - service_user *olds = service; - - if (service->known != NULL) - tdestroy (service->known, free); - - service = service->next; - free (olds); - } - - entry = entry->next; - free (olde); - } - - library = top->library; - while (library != NULL) - { - service_library *oldl = library; - - if (library->lib_handle && library->lib_handle != (void *) -1l) - __libc_dlclose (library->lib_handle); - - library = library->next; - free (oldl); - } - - free (top); -} diff --git a/newlib/libc/sys/linux/net/nsswitch.h b/newlib/libc/sys/linux/net/nsswitch.h deleted file mode 100644 index 7ee6d5e4b..000000000 --- a/newlib/libc/sys/linux/net/nsswitch.h +++ /dev/null @@ -1,180 +0,0 @@ -/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _NSSWITCH_H -#define _NSSWITCH_H 1 - -/* This is an *internal* header. */ - -#include -#include -#include -#include -#include -#include -#include - -/* Actions performed after lookup finished. */ -typedef enum -{ - NSS_ACTION_CONTINUE, - NSS_ACTION_RETURN -} lookup_actions; - - -typedef struct service_library -{ - /* Name of service (`files', `dns', `nis', ...). */ - const char *name; - /* Pointer to the loaded shared library. */ - void *lib_handle; - /* And the link to the next entry. */ - struct service_library *next; -} service_library; - - -/* For mapping a function name to a function pointer. It is known in - nsswitch.c:nss_lookup_function that a string pointer for the lookup key - is the first member. */ -typedef struct -{ - const char *fct_name; - void *fct_ptr; -} known_function; - - -typedef struct service_user -{ - /* And the link to the next entry. */ - struct service_user *next; - /* Action according to result. */ - lookup_actions actions[5]; - /* Link to the underlying library object. */ - service_library *library; - /* Collection of known functions. */ - struct entry *known; - /* Name of the service (`files', `dns', `nis', ...). */ - char name[0]; -} service_user; - -/* To access the action based on the status value use this macro. */ -#define nss_next_action(ni, status) ((ni)->actions[2 + status]) - - -typedef struct name_database_entry -{ - /* And the link to the next entry. */ - struct name_database_entry *next; - /* List of service to be used. */ - service_user *service; - /* Name of the database. */ - char name[0]; -} name_database_entry; - - -typedef struct name_database -{ - /* List of all known databases. */ - name_database_entry *entry; - /* List of libraries with service implementation. */ - service_library *library; -} name_database; - - -/* Interface functions for NSS. */ - -/* Get the data structure representing the specified database. - If there is no configuration for this database in the file, - parse a service list from DEFCONFIG and use that. More - than one function can use the database. */ -extern int __nss_database_lookup (const char *database, - const char *alternative_name, - const char *defconfig, service_user **ni); -libc_hidden_proto (__nss_database_lookup) - -/* Put first function with name FCT_NAME for SERVICE in FCTP. The - position is remembered in NI. The function returns a value < 0 if - an error occurred or no such function exists. */ -extern int __nss_lookup (service_user **ni, const char *fct_name, void **fctp); - -/* Determine the next step in the lookup process according to the - result STATUS of the call to the last function returned by - `__nss_lookup' or `__nss_next'. NI specifies the last function - examined. The function return a value > 0 if the process should - stop with the last result of the last function call to be the - result of the entire lookup. The returned value is 0 if there is - another function to use and < 0 if an error occurred. - - If ALL_VALUES is nonzero, the return value will not be > 0 as long as - there is a possibility the lookup process can ever use following - services. In other words, only if all four lookup results have - the action RETURN associated the lookup process stops before the - natural end. */ -extern int __nss_next (service_user **ni, const char *fct_name, void **fctp, - int status, int all_values); -libc_hidden_proto (__nss_next) - -/* Search for the service described in NI for a function named FCT_NAME - and return a pointer to this function if successful. */ -extern void *__nss_lookup_function (service_user *ni, const char *fct_name); -libc_hidden_proto (__nss_lookup_function) - - -/* Called by NSCD to disable recursive calls. */ -extern void __nss_disable_nscd (void); - - -typedef int (*db_lookup_function) (service_user **, const char *, void **) - internal_function; -typedef enum nss_status (*setent_function) (int); -typedef enum nss_status (*endent_function) (void); -typedef enum nss_status (*getent_function) (void *, char *, size_t, - int *, int *); -typedef int (*getent_r_function) (void *, char *, size_t, - void **result, int *); - -extern void __nss_setent (const char *func_name, - db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int stayon, - int *stayon_tmp, int res); -extern void __nss_endent (const char *func_name, - db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int res); -extern int __nss_getent_r (const char *getent_func_name, - const char *setent_func_name, - db_lookup_function lookup_fct, - service_user **nip, service_user **startp, - service_user **last_nip, int *stayon_tmp, - int res, - void *resbuf, char *buffer, size_t buflen, - void **result, int *h_errnop); -extern void *__nss_getent (getent_r_function func, - void **resbuf, char **buffer, size_t buflen, - size_t *buffer_size, int *h_errnop); -struct hostent; -extern int __nss_hostname_digits_dots (const char *name, - struct hostent *resbuf, char **buffer, - size_t *buffer_size, size_t buflen, - struct hostent **result, - enum nss_status *status, int af, - int *h_errnop); -libc_hidden_proto (__nss_hostname_digits_dots) - -#endif /* nsswitch.h */ diff --git a/newlib/libc/sys/linux/net/opensock.c b/newlib/libc/sys/linux/net/opensock.c deleted file mode 100644 index 7ff3f69ed..000000000 --- a/newlib/libc/sys/linux/net/opensock.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include -#include -#include -#include -#include "libc-symbols.h" - -/* Return a socket of any type. The socket can be used in subsequent - ioctl calls to talk to the kernel. */ -int internal_function -__opensock (void) -{ - static int last_family; /* Available socket family we will use. */ - static int last_type; - static const struct - { - int family; - const char procname[15]; - } afs[] = - { - /* The 2.2 kernels cannot handle ioctl(SIOCGIFCONF) on AF_UNIX sockets. - Give the kernel a chance to user inet sockets on old kernels. */ -#if __LINUX_KERNEL_VERSION < 132096 - { AF_INET, "" }, - { AF_UNIX, "net/unix" }, -#else - { AF_UNIX, "net/unix" }, - { AF_INET, "" }, -#endif - { AF_INET6, "net/if_inet6" }, - { AF_AX25, "net/ax25" }, - { AF_NETROM, "net/nr" }, - { AF_ROSE, "net/rose" }, - { AF_IPX, "net/ipx" }, - { AF_APPLETALK, "net/appletalk" }, - { AF_ECONET, "sys/net/econet" }, - { AF_ASH, "sys/net/ash" }, - { AF_X25, "net/x25" } - }; -#define nafs (sizeof (afs) / sizeof (afs[0])) - char fname[sizeof "/proc/" + 14]; - int result; - int has_proc; - size_t cnt; - - /* We already know which family to use from the last call. Use it - again. */ - if (last_family != 0) - { - assert (last_type != 0); - - result = socket (last_family, last_type, 0); - if (result != -1 || errno != EAFNOSUPPORT) - /* Maybe the socket type isn't supported anymore (module is - unloaded). In this case again try to find the type. */ - return result; - - /* Reset the values. They seem not valid anymore. */ - last_family = 0; - last_type = 0; - } - - /* Check whether the /proc filesystem is available. */ - has_proc = access ("/proc/net", R_OK) != -1; - strcpy (fname, "/proc/"); - - /* Iterate over the interface families and find one which is - available. */ - for (cnt = 0; cnt < nafs; ++cnt) - { - int type = SOCK_DGRAM; - - if (has_proc && afs[cnt].procname[0] != '\0') - { - strcpy (fname + 6, afs[cnt].procname); - if (access (fname, R_OK) == -1) - /* The /proc entry is not available. I.e., we cannot - create a socket of this type (without loading the - module). Don't look for it since this might trigger - loading the module. */ - continue; - } - - if (afs[cnt].family == AF_NETROM || afs[cnt].family == AF_X25) - type = SOCK_SEQPACKET; - - result = socket (afs[cnt].family, type, 0); - if (result != -1) - { - /* Found an available family. */ - last_type = type; - last_family = afs[cnt].family; - return result; - } - } - - /* None of the protocol families is available. It is unclear what kind - of error is returned. ENOENT seems like a reasonable choice. */ - __set_errno (ENOENT); - return -1; -} diff --git a/newlib/libc/sys/linux/net/proto-lookup.c b/newlib/libc/sys/linux/net/proto-lookup.c deleted file mode 100644 index 8f98158b3..000000000 --- a/newlib/libc/sys/linux/net/proto-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME protocols - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/pwd-lookup.c b/newlib/libc/sys/linux/net/pwd-lookup.c deleted file mode 100644 index 1def3a08c..000000000 --- a/newlib/libc/sys/linux/net/pwd-lookup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME passwd -#define DEFAULT_CONFIG "compat [NOTFOUND=return] files" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/rcmd.3 b/newlib/libc/sys/linux/net/rcmd.3 new file mode 100644 index 000000000..9479a237d --- /dev/null +++ b/newlib/libc/sys/linux/net/rcmd.3 @@ -0,0 +1,298 @@ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/rcmd.3,v 1.20 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd March 3, 2000 +.Dt RCMD 3 +.Os +.Sh NAME +.Nm rcmd , +.Nm rresvport , +.Nm iruserok , +.Nm ruserok , +.Nm rcmd_af , +.Nm rresvport_af , +.Nm iruserok_sa +.Nd routines for returning a stream to a remote command +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" +.Ft int +.Fn rresvport "int *port" +.Ft int +.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" +.Ft int +.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" +.Ft int +.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" +.Ft int +.Fn rresvport_af "int *port" "int af" +.Ft int +.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser" +.Sh DESCRIPTION +The +.Fn rcmd +function +is used by the super-user to execute a command on +a remote machine using an authentication scheme based +on reserved port numbers. +The +.Fn rresvport +function +returns a descriptor to a socket +with an address in the privileged port space. +The +.Fn ruserok +function +is used by servers +to authenticate clients requesting service with +.Fn rcmd . +All three functions are present in the same file and are used +by the +.Xr rshd 8 +server (among others). +.Pp +The +.Fn rcmd +function +looks up the host +.Fa *ahost +using +.Xr gethostbyname 3 , +returning -1 if the host does not exist. +Otherwise +.Fa *ahost +is set to the standard name of the host +and a connection is established to a server +residing at the well-known Internet port +.Fa inport . +.Pp +If the connection succeeds, +a socket in the Internet domain of type +.Dv SOCK_STREAM +is returned to the caller, and given to the remote +command as +.Em stdin +and +.Em stdout . +If +.Fa fd2p +is non-zero, then an auxiliary channel to a control +process will be set up, and a descriptor for it will be placed +in +.Fa *fd2p . +The control process will return diagnostic +output from the command (unit 2) on this channel, and will also +accept bytes on this channel as being +.Tn UNIX +signal numbers, to be +forwarded to the process group of the command. +If +.Fa fd2p +is 0, then the +.Em stderr +(unit 2 of the remote +command) will be made the same as the +.Em stdout +and no +provision is made for sending arbitrary signals to the remote process, +although you may be able to get its attention by using out-of-band data. +.Pp +The protocol is described in detail in +.Xr rshd 8 . +.Pp +The +.Fn rresvport +function is used to obtain a socket to which an address with a Privileged +Internet port is bound. +This socket is suitable for use by +.Fn rcmd +and several other functions. +Privileged Internet ports are those in the range 0 to 1023. +Only the super-user is allowed to bind an address of this sort +to a socket. +.Pp +The +.Fn iruserok +and +.Fn ruserok +functions take a remote host's IP address or name, as returned by the +.Xr gethostbyname 3 +routines, two user names and a flag indicating whether the local user's +name is that of the super-user. +Then, if the user is +.Em NOT +the super-user, it checks the +.Pa /etc/hosts.equiv +file. +If that lookup is not done, or is unsuccessful, the +.Pa .rhosts +in the local user's home directory is checked to see if the request for +service is allowed. +.Pp +If this file does not exist, is not a regular file, is owned by anyone +other than the user or the super-user, or is writable by anyone other +than the owner, the check automatically fails. +Zero is returned if the machine name is listed in the +.Dq Pa hosts.equiv +file, or the host and remote user name are found in the +.Dq Pa .rhosts +file; otherwise +.Fn iruserok +and +.Fn ruserok +return -1. +If the local domain (as obtained from +.Xr gethostname 3 ) +is the same as the remote domain, only the machine name need be specified. +.Pp +The +.Fn iruserok +function is strongly preferred for security reasons. +It requires trusting the local DNS at most, while the +.Fn ruserok +function requires trusting the entire DNS, which can be spoofed. +.Pp +The functions with an +.Dq Li _af +or +.Dq Li _sa +suffix, i.e., +.Fn rcmd_af , +.Fn rresvport_af +and +.Fn iruserok_sa , +work the same as the corresponding functions without a +suffix, except that they are capable of handling both IPv6 and IPv4 ports. +.Pp +The +.Dq Li _af +suffix means that the function has an additional +.Fa af +argument which is used to specify the address family, +(see below). +The +.Fa af +argument extension is implemented for functions +that have no binary address argument. +Instead, the +.Fa af +argument specifies which address family is desired. +.Pp +The +.Dq Li _sa +suffix means that the function has general socket address and +length arguments. +As the socket address is a protocol independent data structure, +IPv4 and IPv6 socket address can be passed as desired. +The +.Fa sa +argument extension is implemented for functions +that pass a protocol dependent binary address argument. +The argument needs to be replaced with a more general address structure +to support multiple address families in a general way. +.Pp +The functions with neither an +.Dq Li _af +suffix nor an +.Dq Li _sa +suffix work for IPv4 only, except for +.Fn ruserok +which can handle both IPv6 and IPv4. +To switch the address family, the +.Fa af +argument must be filled with +.Dv AF_INET , +or +.Dv AF_INET6 . +For +.Fn rcmd_af , +.Dv PF_UNSPEC +is also allowed. +.Sh DIAGNOSTICS +The +.Fn rcmd +function +returns a valid socket descriptor on success. +It returns -1 on error and prints a diagnostic message +on the standard error. +.Pp +The +.Fn rresvport +function +returns a valid, bound socket descriptor on success. +It returns -1 on error with the global value +.Va errno +set according to the reason for failure. +The error code +.Er EAGAIN +is overloaded to mean ``All network ports in use.'' +.Sh SEE ALSO +.Xr rlogin 1 , +.Xr rsh 1 , +.Xr intro 2 , +.Xr rexec 3 , +.Xr rexecd 8 , +.Xr rlogind 8 , +.Xr rshd 8 +.Pp +.Rs +.%A W. Stevens +.%A M. Thomas +.%T "Advanced Socket API for IPv6" +.%O RFC2292 +.Re +.Rs +.%A W. Stevens +.%A M. Thomas +.%A E. Nordmark +.%T "Advanced Socket API for IPv6" +.%O draft-ietf-ipngwg-rfc2292bis-01.txt +.Re +.Sh HISTORY +Most of these +functions appeared in +.Bx 4.2 . +.Fn rresvport_af +appeared in RFC2292, and was implemented by the WIDE project +for the Hydrangea IPv6 protocol stack kit. +.Fn rcmd_af +appeared in draft-ietf-ipngwg-rfc2292bis-01.txt, +and was implemented in the WIDE/KAME IPv6 protocol stack kit. +.Fn iruserok_sa +appeared in discussion on the IETF ipngwg mailing list, +and was implemented in +.Fx 4.0 . diff --git a/newlib/libc/sys/linux/net/rcmd.c b/newlib/libc/sys/linux/net/rcmd.c index ab3ade89b..708b69d1b 100644 --- a/newlib/libc/sys/linux/net/rcmd.c +++ b/newlib/libc/sys/linux/net/rcmd.c @@ -1,31 +1,3 @@ -/* - * Copyright (C) 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ /* * Copyright (c) 1983, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -38,6 +10,10 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -58,51 +34,55 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #endif /* LIBC_SCCS and not lint */ +#include +#include +#include +#include +#include "namespace.h" #include -#include #include #include #include #include -#include #include #include #include +#include #include #include #include #include -#include #include #include -#include -#include -#include -#include +#ifdef YP +#include +#include +#include +#endif +#include +#include "un-namespace.h" -#include "local.h" +/* wrapper for KAME-special getnameinfo() */ +#ifndef NI_WITHSCOPEID +#define NI_WITHSCOPEID 0 +#endif +extern int innetgr( const char *, const char *, const char *, const char * ); +extern int rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, const char *cmd, const char *rshprog); +int rresvport_af(int *alport, int family); -int __ivaliduser (FILE *, u_int32_t, const char *, const char *); -static int __validuser2_sa (FILE *, struct sockaddr *, size_t, - const char *, const char *, const char *); -static int ruserok2_sa (struct sockaddr *ra, size_t ralen, - int superuser, const char *ruser, - const char *luser, const char *rhost); -static int ruserok_sa (struct sockaddr *ra, size_t ralen, - int superuser, const char *ruser, - const char *luser); -int iruserok_af (const void *raddr, int superuser, const char *ruser, - const char *luser, sa_family_t af); -int iruserok (u_int32_t raddr, int superuser, const char *ruser, - const char *luser); +#define max(a, b) ((a > b) ? a : b) -libc_hidden_proto (iruserok_af) +int __ivaliduser(FILE *, u_int32_t, const char *, const char *); +int __ivaliduser_af(FILE *,const void *, const char *, const char *, int, int); +int __ivaliduser_sa(FILE *, const struct sockaddr *, socklen_t, const char *, + const char *); +static int __icheckhost(const struct sockaddr *, socklen_t, const char *); -libc_freeres_ptr(static char *ahostbuf); +char paddr[NI_MAXHOST]; int rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) @@ -110,300 +90,242 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) u_short rport; const char *locuser, *remuser, *cmd; int *fd2p; - sa_family_t af; + int af; { - char paddr[INET6_ADDRSTRLEN]; struct addrinfo hints, *res, *ai; struct sockaddr_storage from; - struct pollfd pfd[2]; - int32_t oldmask; + fd_set reads; + sigset_t oldmask, newmask; pid_t pid; - int s, lport, timo, error; - char c; - int refused; + int s, aport, lport, timo, error; + char c, *p; + int refused, nres; char num[8]; - ssize_t n; + static char canonnamebuf[MAXDNAME]; /* is it proper here? */ - if (af != AF_INET && af != AF_INET6 && af != AF_UNSPEC) - { - __set_errno (EAFNOSUPPORT); - return -1; - } + /* call rcmdsh() with specified remote shell if appropriate. */ + if (!issetugid() && (p = getenv("RSH"))) { + struct servent *sp = getservbyname("shell", "tcp"); - pid = __getpid(); + if (sp && sp->s_port == rport) + return (rcmdsh(ahost, rport, locuser, remuser, + cmd, p)); + } + + /* use rsh(1) if non-root and remote port is shell. */ + if (geteuid()) { + struct servent *sp = getservbyname("shell", "tcp"); + + if (sp && sp->s_port == rport) + return (rcmdsh(ahost, rport, locuser, remuser, + cmd, NULL)); + } - memset(&hints, '\0', sizeof(hints)); + pid = getpid(); + + memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; hints.ai_family = af; hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = 0; (void)snprintf(num, sizeof(num), "%d", ntohs(rport)); error = getaddrinfo(*ahost, num, &hints, &res); if (error) { - if (error == EAI_NONAME && *ahost != NULL) { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"%s: Unknown host\n", - *ahost); - else - fprintf(stderr, "%s: Unknown host\n", *ahost); - } else { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"rcmd: getaddrinfo: %s\n", - gai_strerror(error)); - else - fprintf(stderr, "rcmd: getaddrinfo: %s\n", - gai_strerror(error)); - } - return (-1); + fprintf(stderr, "rcmd: getaddrinfo: %s\n", + gai_strerror(error)); + if (error == EAI_SYSTEM) + fprintf(stderr, "rcmd: getaddrinfo: %s\n", + strerror(errno)); + return (-1); } - pfd[0].events = POLLIN; - pfd[1].events = POLLIN; - - if (res->ai_canonname){ - free (ahostbuf); - ahostbuf = strdup (res->ai_canonname); - if (ahostbuf == NULL) { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"%s", - _("rcmd: Cannot allocate memory\n")); - else - fputs(_("rcmd: Cannot allocate memory\n"), - stderr); - return (-1); - } - *ahost = ahostbuf; - } else - *ahost = NULL; + if (res->ai_canonname + && strlen(res->ai_canonname) + 1 < sizeof(canonnamebuf)) { + strncpy(canonnamebuf, res->ai_canonname, sizeof(canonnamebuf)); + *ahost = canonnamebuf; + } + nres = 0; + for (ai = res; ai; ai = ai->ai_next) + nres++; ai = res; refused = 0; - oldmask = __sigblock(sigmask(SIGURG)); + sigemptyset(&newmask); + sigaddset(&newmask, SIGURG); + sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); for (timo = 1, lport = IPPORT_RESERVED - 1;;) { - char errbuf[200]; - s = rresvport_af(&lport, ai->ai_family); if (s < 0) { - if (errno == EAGAIN) { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"%s", - _("rcmd: socket: All ports in use\n")); - else - fputs(_("rcmd: socket: All ports in use\n"), - stderr); - } else { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, - L"rcmd: socket: %m\n"); - else - fprintf(stderr, "rcmd: socket: %m\n"); + if (errno != EAGAIN && ai->ai_next) { + ai = ai->ai_next; + continue; } - __sigsetmask(oldmask); + if (errno == EAGAIN) + (void)fprintf(stderr, + "rcmd: socket: All ports in use\n"); + else + (void)fprintf(stderr, "rcmd: socket: %s\n", + strerror(errno)); freeaddrinfo(res); - return -1; + sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + NULL); + return (-1); } - __fcntl(s, F_SETOWN, pid); - if (__connect(s, ai->ai_addr, ai->ai_addrlen) >= 0) + fcntl(s, F_SETOWN, pid); + if (connect(s, ai->ai_addr, ai->ai_addrlen) >= 0) break; - (void)__close(s); + (void)close(s); if (errno == EADDRINUSE) { lport--; continue; } if (errno == ECONNREFUSED) refused = 1; - if (ai->ai_next != NULL) { + if (ai->ai_next == NULL && (!refused || timo > 16)) { + (void)fprintf(stderr, "%s: %s\n", + *ahost, strerror(errno)); + freeaddrinfo(res); + sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + NULL); + return (-1); + } + if (nres > 1) { int oerrno = errno; - char *buf = NULL; getnameinfo(ai->ai_addr, ai->ai_addrlen, paddr, sizeof(paddr), NULL, 0, - NI_NUMERICHOST); - - if (__asprintf (&buf, _("connect to address %s: "), - paddr) >= 0) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } - __set_errno (oerrno); + NI_NUMERICHOST|NI_WITHSCOPEID); + (void)fprintf(stderr, "connect to address %s: ", + paddr); + errno = oerrno; perror(0); - ai = ai->ai_next; - getnameinfo(ai->ai_addr, ai->ai_addrlen, - paddr, sizeof(paddr), - NULL, 0, - NI_NUMERICHOST); - if (__asprintf (&buf, _("Trying %s...\n"), paddr) >= 0) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } - continue; } - if (refused && timo <= 16) { - (void)sleep(timo); + if ((ai = ai->ai_next) == NULL) { + /* refused && timo <= 16 */ + struct timespec time_to_sleep, time_remaining; + + time_to_sleep.tv_sec = timo; + time_to_sleep.tv_nsec = 0; + (void)nanosleep(&time_to_sleep, &time_remaining); timo *= 2; ai = res; refused = 0; - continue; } - freeaddrinfo(res); - if (_IO_fwide (stderr, 0) > 0) - (void)__fwprintf(stderr, L"%s: %s\n", *ahost, - strerror_r(errno, - errbuf, sizeof (errbuf))); - else - (void)fprintf(stderr, "%s: %s\n", *ahost, - strerror_r(errno, - errbuf, sizeof (errbuf))); - __sigsetmask(oldmask); - return -1; + if (nres > 1) { + getnameinfo(ai->ai_addr, ai->ai_addrlen, + paddr, sizeof(paddr), + NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID); + fprintf(stderr, "Trying %s...\n", paddr); + } } lport--; if (fd2p == 0) { - __write(s, "", 1); + write(s, "", 1); lport = 0; } else { char num[8]; int s2 = rresvport_af(&lport, ai->ai_family), s3; - socklen_t len = ai->ai_addrlen; + int len = ai->ai_addrlen; + int nfds; if (s2 < 0) goto bad; listen(s2, 1); (void)snprintf(num, sizeof(num), "%d", lport); - if (__write(s, num, strlen(num)+1) != (ssize_t)strlen(num)+1) { - char *buf = NULL; - - if (__asprintf (&buf, _("\ -rcmd: write (setting up stderr): %m\n")) >= 0) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf(stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } - (void)__close(s2); + if (write(s, num, strlen(num)+1) != strlen(num)+1) { + (void)fprintf(stderr, + "rcmd: write (setting up stderr): %s\n", + strerror(errno)); + (void)close(s2); goto bad; } - pfd[0].fd = s; - pfd[1].fd = s2; - __set_errno (0); - if (__poll (pfd, 2, -1) < 1 || (pfd[1].revents & POLLIN) == 0){ - char *buf = NULL; - - if ((errno != 0 - && __asprintf(&buf, _("\ -rcmd: poll (setting up stderr): %m\n")) >= 0) - || (errno == 0 - && __asprintf(&buf, _("\ -poll: protocol failure in circuit setup\n")) >= 0)) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } - (void)__close(s2); + nfds = max(s, s2)+1; + if(nfds > FD_SETSIZE) { + fprintf(stderr, "rcmd: too many files\n"); + (void)close(s2); goto bad; } - s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from, - &len)); +again: + FD_ZERO(&reads); + FD_SET(s, &reads); + FD_SET(s2, &reads); + errno = 0; + if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){ + if (errno != 0) + (void)fprintf(stderr, + "rcmd: select (setting up stderr): %s\n", + strerror(errno)); + else + (void)fprintf(stderr, + "select: protocol failure in circuit setup\n"); + (void)close(s2); + goto bad; + } + s3 = accept(s2, (struct sockaddr *)&from, &len); switch (from.ss_family) { case AF_INET: - rport = ntohs(((struct sockaddr_in *)&from)->sin_port); + aport = ntohs(((struct sockaddr_in *)&from)->sin_port); break; +#ifdef INET6 case AF_INET6: - rport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port); + aport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port); break; +#endif default: - rport = 0; + aport = 0; /* error */ break; } - (void)__close(s2); + /* + * XXX careful for ftp bounce attacks. If discovered, shut them + * down and check for the real auxiliary channel to connect. + */ + if (aport == 20) { + close(s3); + goto again; + } + (void)close(s2); if (s3 < 0) { - if (_IO_fwide (stderr, 0) > 0) - (void)__fwprintf(stderr, - L"rcmd: accept: %m\n"); - else - (void)fprintf(stderr, - "rcmd: accept: %m\n"); + (void)fprintf(stderr, + "rcmd: accept: %s\n", strerror(errno)); lport = 0; goto bad; } *fd2p = s3; - - if (rport >= IPPORT_RESERVED || rport < IPPORT_RESERVED / 2){ - char *buf = NULL; - - if (__asprintf(&buf, _("\ -socket: protocol failure in circuit setup\n")) >= 0) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } + if (aport >= IPPORT_RESERVED || aport < IPPORT_RESERVED / 2) { + (void)fprintf(stderr, + "socket: protocol failure in circuit setup.\n"); goto bad2; } } - struct iovec iov[3] = - { - [0] = { .iov_base = (void *) locuser, - .iov_len = strlen (locuser) + 1 }, - [1] = { .iov_base = (void *) remuser, - .iov_len = strlen (remuser) + 1 }, - [2] = { .iov_base = (void *) cmd, - .iov_len = strlen (cmd) + 1 } - }; - (void) TEMP_FAILURE_RETRY (writev (s, iov, 3)); - n = TEMP_FAILURE_RETRY (read(s, &c, 1)); - if (n != 1) { - char *buf = NULL; - - if ((n == 0 - && asprintf(&buf, _("rcmd: %s: short read"), - *ahost) >= 0) - || (n != 0 - && asprintf(&buf, "rcmd: %s: %m\n", *ahost) >= 0)) - { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - free (buf); - } + (void)write(s, locuser, strlen(locuser)+1); + (void)write(s, remuser, strlen(remuser)+1); + (void)write(s, cmd, strlen(cmd)+1); + if (read(s, &c, 1) != 1) { + (void)fprintf(stderr, + "rcmd: %s: %s\n", *ahost, strerror(errno)); goto bad2; } if (c != 0) { - while (__read(s, &c, 1) == 1) { - (void)__write(STDERR_FILENO, &c, 1); + while (read(s, &c, 1) == 1) { + (void)write(STDERR_FILENO, &c, 1); if (c == '\n') break; } goto bad2; } - __sigsetmask(oldmask); + sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); - return s; + return (s); bad2: if (lport) - (void)__close(*fd2p); + (void)close(*fd2p); bad: - (void)__close(s); - __sigsetmask(oldmask); + (void)close(s); + sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); - return -1; + return (-1); } -libc_hidden_def (rcmd_af) int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) @@ -412,155 +334,90 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) const char *locuser, *remuser, *cmd; int *fd2p; { - return rcmd_af (ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); + return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); +} + +int +rresvport(port) + int *port; +{ + return rresvport_af(port, AF_INET); } int rresvport_af(alport, family) - int *alport; - sa_family_t family; + int *alport, family; { - struct sockaddr_storage ss; int s; - size_t len; - uint16_t *sport; + struct sockaddr_storage ss; + u_short *sport; - switch(family){ + memset(&ss, 0, sizeof(ss)); + ss.ss_family = family; + switch (family) { case AF_INET: - len = sizeof(struct sockaddr_in); sport = &((struct sockaddr_in *)&ss)->sin_port; + ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY; break; +#ifdef INET6 case AF_INET6: - len = sizeof(struct sockaddr_in6); sport = &((struct sockaddr_in6 *)&ss)->sin6_port; + ((struct sockaddr_in6 *)&ss)->sin6_addr = in6addr_any; break; +#endif default: - __set_errno (EAFNOSUPPORT); + errno = EAFNOSUPPORT; return -1; } - s = __socket(family, SOCK_STREAM, 0); - if (s < 0) - return -1; - memset (&ss, '\0', sizeof(ss)); -#ifdef SALEN - ss.__ss_len = len; + s = socket(ss.ss_family, SOCK_STREAM, 0); + if (s < 0) + return (-1); +#if 0 /* compat_exact_traditional_rresvport_semantics */ + sin.sin_port = htons((u_short)*alport); + if (_bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) + return (s); + if (errno != EADDRINUSE) { + (void)close(s); + return (-1); + } #endif - ss.ss_family = family; - - /* Ignore invalid values. */ - if (*alport < IPPORT_RESERVED / 2) - *alport = IPPORT_RESERVED / 2; - else if (*alport >= IPPORT_RESERVED) - *alport = IPPORT_RESERVED - 1; - - int start = *alport; - do { - *sport = htons((uint16_t) *alport); - if (__bind(s, (struct sockaddr *)&ss, len) >= 0) - return s; - if (errno != EADDRINUSE) { - (void)__close(s); - return -1; - } - if ((*alport)-- == IPPORT_RESERVED/2) - *alport = IPPORT_RESERVED - 1; - } while (*alport != start); - (void)__close(s); - __set_errno (EAGAIN); - return -1; -} -libc_hidden_def (rresvport_af) - -int -rresvport(alport) - int *alport; -{ - return rresvport_af(alport, AF_INET); + *sport = 0; + if (bindresvport_sa(s, (struct sockaddr *)&ss) == -1) { + (void)close(s); + return (-1); + } + *alport = (int)ntohs(*sport); + return (s); } int __check_rhosts_file = 1; char *__rcmd_errstr; -int -ruserok_af(rhost, superuser, ruser, luser, af) - const char *rhost, *ruser, *luser; - int superuser; - sa_family_t af; -{ - struct addrinfo hints, *res, *res0; - int gai; - int ret; - - memset (&hints, '\0', sizeof(hints)); - hints.ai_family = af; - gai = getaddrinfo(rhost, NULL, &hints, &res0); - if (gai) - return -1; - ret = -1; - for (res=res0; res; res=res->ai_next) - if (ruserok2_sa(res->ai_addr, res->ai_addrlen, - superuser, ruser, luser, rhost) == 0){ - ret = 0; - break; - } - freeaddrinfo(res0); - return (ret); -} -libc_hidden_def (ruserok_af) - int ruserok(rhost, superuser, ruser, luser) const char *rhost, *ruser, *luser; int superuser; { - return ruserok_af(rhost, superuser, ruser, luser, AF_INET); -} - -/* Extremely paranoid file open function. */ -static FILE * -iruserfopen (const char *file, uid_t okuser) -{ - struct stat64 st; - char *cp = NULL; - FILE *res = NULL; - - /* If not a regular file, if owned by someone other than user or - root, if writeable by anyone but the owner, or if hardlinked - anywhere, quit. */ - cp = NULL; - if (__lxstat64 (_STAT_VER, file, &st)) - cp = _("lstat failed"); - else if (!S_ISREG (st.st_mode)) - cp = _("not regular file"); - else - { - res = fopen (file, "rc"); - if (!res) - cp = _("cannot open"); - else if (__fxstat64 (_STAT_VER, fileno (res), &st) < 0) - cp = _("fstat failed"); - else if (st.st_uid && st.st_uid != okuser) - cp = _("bad owner"); - else if (st.st_mode & (S_IWGRP|S_IWOTH)) - cp = _("writeable by other than owner"); - else if (st.st_nlink > 1) - cp = _("hard linked somewhere"); - } - - /* If there were any problems, quit. */ - if (cp != NULL) - { - __rcmd_errstr = cp; - if (res) - fclose (res); - return NULL; - } - - /* No threads use this stream. */ - __fsetlocking (res, FSETLOCKING_BYCALLER); - - return res; + struct addrinfo hints, *res, *r; + int error; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + error = getaddrinfo(rhost, "0", &hints, &res); + if (error) + return (-1); + + for (r = res; r; r = r->ai_next) { + if (iruserok_sa(r->ai_addr, r->ai_addrlen, superuser, ruser, + luser) == 0) { + freeaddrinfo(res); + return (0); + } + } + freeaddrinfo(res); + return (-1); } /* @@ -572,127 +429,110 @@ iruserfopen (const char *file, uid_t okuser) * * Returns 0 if ok, -1 if not ok. */ -static int -ruserok2_sa (ra, ralen, superuser, ruser, luser, rhost) - struct sockaddr *ra; - size_t ralen; - int superuser; - const char *ruser, *luser, *rhost; +int +iruserok(raddr, superuser, ruser, luser) + unsigned long raddr; + int superuser; + const char *ruser, *luser; { - FILE *hostf = NULL; - int isbad = -1; - - if (!superuser) - hostf = iruserfopen (_PATH_HEQUIV, 0); - - if (hostf) - { - isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost); - fclose (hostf); - - if (!isbad) - return 0; - } - - if (__check_rhosts_file || superuser) - { - char *pbuf; - struct passwd pwdbuf, *pwd; - size_t dirlen; - size_t buflen = __sysconf (_SC_GETPW_R_SIZE_MAX); - char *buffer = __alloca (buflen); - uid_t uid; - - if (__getpwnam_r (luser, &pwdbuf, buffer, buflen, &pwd) != 0 - || pwd == NULL) - return -1; - - dirlen = strlen (pwd->pw_dir); - pbuf = alloca (dirlen + sizeof "/.rhosts"); - __mempcpy (__mempcpy (pbuf, pwd->pw_dir, dirlen), - "/.rhosts", sizeof "/.rhosts"); - - /* Change effective uid while reading .rhosts. If root and - reading an NFS mounted file system, can't read files that - are protected read/write owner only. */ - uid = __geteuid (); - seteuid (pwd->pw_uid); - hostf = iruserfopen (pbuf, pwd->pw_uid); - - if (hostf != NULL) - { - isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost); - fclose (hostf); - } - - seteuid (uid); - return isbad; - } - return -1; + struct sockaddr_in sin; + int sin_len; + + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin_len = sizeof(struct sockaddr_in); + memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr)); + return iruserok_sa((struct sockaddr *)&sin, sin_len, superuser, + ruser, luser); } + /* - * ruserok_sa() is now discussed on ipng, so - * currently disabled for external use + * AF independent extension of iruserok. + * + * Returns 0 if ok, -1 if not ok. */ -static int ruserok_sa(ra, ralen, superuser, ruser, luser) - struct sockaddr *ra; - size_t ralen; - int superuser; - const char *ruser, *luser; -{ - return ruserok2_sa(ra, ralen, superuser, ruser, luser, "-"); -} - -/* This is the exported version. */ int -iruserok_af (raddr, superuser, ruser, luser, af) - const void *raddr; - int superuser; - const char *ruser, *luser; - sa_family_t af; +iruserok_sa(ra, rlen, superuser, ruser, luser) + const void *ra; + int rlen; + int superuser; + const char *ruser, *luser; { - struct sockaddr_storage ra; - size_t ralen; - - memset (&ra, '\0', sizeof(ra)); - switch (af){ - case AF_INET: - ((struct sockaddr_in *)&ra)->sin_family = AF_INET; - memcpy (&(((struct sockaddr_in *)&ra)->sin_addr), raddr, - sizeof(struct in_addr)); - ralen = sizeof(struct sockaddr_in); - break; - case AF_INET6: - ((struct sockaddr_in6 *)&ra)->sin6_family = AF_INET6; - memcpy (&(((struct sockaddr_in6 *)&ra)->sin6_addr), raddr, - sizeof(struct in6_addr)); - ralen = sizeof(struct sockaddr_in6); - break; - default: - return 0; - } - return ruserok_sa ((struct sockaddr *)&ra, ralen, superuser, ruser, luser); -} -libc_hidden_def (iruserok_af) + char *cp; + struct stat sbuf; + struct passwd *pwd; + FILE *hostf; + uid_t uid; + int first; + char pbuf[MAXPATHLEN]; + const struct sockaddr *raddr; + struct sockaddr_storage ss; -int -iruserok (raddr, superuser, ruser, luser) - u_int32_t raddr; - int superuser; - const char *ruser, *luser; -{ - return iruserok_af (&raddr, superuser, ruser, luser, AF_INET); + /* avoid alignment issue */ + if (rlen > sizeof(ss)) + return(-1); + memcpy(&ss, ra, rlen); + raddr = (struct sockaddr *)&ss; + + first = 1; + hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); +again: + if (hostf) { + if (__ivaliduser_sa(hostf, raddr, rlen, luser, ruser) == 0) { + (void)fclose(hostf); + return (0); + } + (void)fclose(hostf); + } + if (first == 1 && (__check_rhosts_file || superuser)) { + first = 0; + if ((pwd = getpwnam(luser)) == NULL) + return (-1); + (void)strcpy(pbuf, pwd->pw_dir); + (void)strcat(pbuf, "/.rhosts"); + + /* + * Change effective uid while opening .rhosts. If root and + * reading an NFS mounted file system, can't read files that + * are protected read/write owner only. + */ + uid = geteuid(); + (void)seteuid(pwd->pw_uid); + hostf = fopen(pbuf, "r"); + (void)seteuid(uid); + + if (hostf == NULL) + return (-1); + /* + * If not a regular file, or is owned by someone other than + * user or root or if writeable by anyone but the owner, quit. + */ + cp = NULL; + if (lstat(pbuf, &sbuf) < 0) + cp = ".rhosts lstat failed"; + else if (!S_ISREG(sbuf.st_mode)) + cp = ".rhosts not regular file"; + else if (fstat(fileno(hostf), &sbuf) < 0) + cp = ".rhosts fstat failed"; + else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) + cp = "bad .rhosts owner"; + else if (sbuf.st_mode & (S_IWGRP|S_IWOTH)) + cp = ".rhosts writeable by other than owner"; + /* If there were any problems, quit. */ + if (cp) { + __rcmd_errstr = cp; + (void)fclose(hostf); + return (-1); + } + goto again; + } + return (-1); } /* * XXX * Don't make static, used by lpd(8). * - * This function is not used anymore. It is only present because lpd(8) - * calls it (!?!). We simply call __invaliduser2() with an illegal rhost - * argument. This means that netgroups won't work in .rhost/hosts.equiv - * files. If you want lpd to work with netgroups, fix lpd to use ruserok() - * or PAM. * Returns 0 if ok, -1 if not ok. */ int @@ -701,185 +541,239 @@ __ivaliduser(hostf, raddr, luser, ruser) u_int32_t raddr; const char *luser, *ruser; { - struct sockaddr_in ra; - memset(&ra, '\0', sizeof(ra)); - ra.sin_family = AF_INET; - ra.sin_addr.s_addr = raddr; - return __validuser2_sa(hostf, (struct sockaddr *)&ra, sizeof(ra), - luser, ruser, "-"); + struct sockaddr_in sin; + int sin_len; + + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin_len = sizeof(struct sockaddr_in); + memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr)); + return __ivaliduser_sa(hostf, (struct sockaddr *)&sin, sin_len, + luser, ruser); } - -/* Returns 1 on positive match, 0 on no match, -1 on negative match. */ -static int -internal_function -__checkhost_sa (struct sockaddr *ra, size_t ralen, char *lhost, - const char *rhost) +/* + * Returns 0 if ok, -1 if not ok. + * + * XXX obsolete API. + */ +int +__ivaliduser_af(hostf, raddr, luser, ruser, af, len) + FILE *hostf; + const void *raddr; + const char *luser, *ruser; + int af, len; { - struct addrinfo hints, *res0, *res; - char raddr[INET6_ADDRSTRLEN]; - int match; - int negate=1; /* Multiply return with this to get -1 instead of 1 */ - - /* Check nis netgroup. */ - if (strncmp ("+@", lhost, 2) == 0) - return innetgr (&lhost[2], rhost, NULL, NULL); - - if (strncmp ("-@", lhost, 2) == 0) - return -innetgr (&lhost[2], rhost, NULL, NULL); - - /* -host */ - if (strncmp ("-", lhost,1) == 0) { - negate = -1; - lhost++; - } else if (strcmp ("+",lhost) == 0) { - return 1; /* asking for trouble, but ok.. */ - } + struct sockaddr *sa = NULL; + struct sockaddr_in *sin = NULL; +#ifdef INET6 + struct sockaddr_in6 *sin6 = NULL; +#endif + struct sockaddr_storage ss; - /* Try for raw ip address first. */ - /* XXX */ - if (getnameinfo(ra, ralen, - raddr, sizeof(raddr), NULL, 0, - NI_NUMERICHOST) == 0 - && strcmp(raddr, lhost) == 0) - return negate; - - /* Better be a hostname. */ - match = 0; - memset(&hints, '\0', sizeof(hints)); - hints.ai_family = ra->sa_family; - if (getaddrinfo(lhost, NULL, &hints, &res0) == 0){ - /* Spin through ip addresses. */ - for (res = res0; res; res = res->ai_next) - { - if (res->ai_family == ra->sa_family - && !memcmp(res->ai_addr, ra, res->ai_addrlen)) - { - match = 1; - break; - } - } - freeaddrinfo (res0); + memset(&ss, 0, sizeof(ss)); + switch (af) { + case AF_INET: + if (len != sizeof(sin->sin_addr)) + return -1; + sin = (struct sockaddr_in *)&ss; + sin->sin_family = AF_INET; + memcpy(&sin->sin_addr, raddr, sizeof(sin->sin_addr)); + break; +#ifdef INET6 + case AF_INET6: + if (len != sizeof(sin6->sin6_addr)) + return -1; + /* you will lose scope info */ + sin6 = (struct sockaddr_in6 *)&ss; + sin6->sin6_family = AF_INET6; + memcpy(&sin6->sin6_addr, raddr, sizeof(sin6->sin6_addr)); + break; +#endif + default: + return -1; } - return negate * match; -} - -/* Returns 1 on positive match, 0 on no match, -1 on negative match. */ -static int -internal_function -__icheckuser (const char *luser, const char *ruser) -{ - /* - luser is user entry from .rhosts/hosts.equiv file - ruser is user id on remote host - */ - - /* [-+]@netgroup */ - if (strncmp ("+@", luser, 2) == 0) - return innetgr (&luser[2], NULL, ruser, NULL); - - if (strncmp ("-@", luser,2) == 0) - return -innetgr (&luser[2], NULL, ruser, NULL); - /* -user */ - if (strncmp ("-", luser, 1) == 0) - return -(strcmp (&luser[1], ruser) == 0); - - /* + */ - if (strcmp ("+", luser) == 0) - return 1; - - /* simple string match */ - return strcmp (ruser, luser) == 0; + sa = (struct sockaddr *)&ss; + return __ivaliduser_sa(hostf, sa, 0, luser, ruser); } -/* - * Returns 1 for blank lines (or only comment lines) and 0 otherwise - */ -static int -__isempty (char *p) +int +__ivaliduser_sa(hostf, raddr, salen, luser, ruser) + FILE *hostf; + const struct sockaddr *raddr; + socklen_t salen; + const char *luser, *ruser; { - while (*p && isspace (*p)) { - ++p; - } - - return (*p == '\0' || *p == '#') ? 1 : 0 ; + char *user, *p; + int ch; + char buf[MAXHOSTNAMELEN + 128]; /* host + login */ + char hname[MAXHOSTNAMELEN]; + /* Presumed guilty until proven innocent. */ + int userok = 0, hostok = 0; +#ifdef YP + char *ypdomain; + + if (yp_get_default_domain(&ypdomain)) + ypdomain = NULL; +#else +#define ypdomain NULL +#endif + /* We need to get the damn hostname back for netgroup matching. */ + if (getnameinfo(raddr, salen, hname, sizeof(hname), NULL, 0, + NI_NAMEREQD) != 0) + return (-1); + + while (fgets(buf, sizeof(buf), hostf)) { + p = buf; + /* Skip lines that are too long. */ + if (strchr(p, '\n') == NULL) { + while ((ch = getc(hostf)) != '\n' && ch != EOF); + continue; + } + if (*p == '\n' || *p == '#') { + /* comment... */ + continue; + } + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { + *p = isupper((unsigned char)*p) ? tolower((unsigned char)*p) : *p; + p++; + } + if (*p == ' ' || *p == '\t') { + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + user = p; + while (*p != '\n' && *p != ' ' && + *p != '\t' && *p != '\0') + p++; + } else + user = p; + *p = '\0'; + /* + * Do +/- and +@/-@ checking. This looks really nasty, + * but it matches SunOS's behavior so far as I can tell. + */ + switch(buf[0]) { + case '+': + if (!buf[1]) { /* '+' matches all hosts */ + hostok = 1; + break; + } + if (buf[1] == '@') /* match a host by netgroup */ + hostok = innetgr((char *)&buf[2], + (char *)&hname, NULL, ypdomain); + else /* match a host by addr */ + hostok = __icheckhost(raddr, salen, + (char *)&buf[1]); + break; + case '-': /* reject '-' hosts and all their users */ + if (buf[1] == '@') { + if (innetgr((char *)&buf[2], + (char *)&hname, NULL, ypdomain)) + return(-1); + } else { + if (__icheckhost(raddr, salen, + (char *)&buf[1])) + return(-1); + } + break; + default: /* if no '+' or '-', do a simple match */ + hostok = __icheckhost(raddr, salen, buf); + break; + } + switch(*user) { + case '+': + if (!*(user+1)) { /* '+' matches all users */ + userok = 1; + break; + } + if (*(user+1) == '@') /* match a user by netgroup */ + userok = innetgr(user+2, NULL, ruser, ypdomain); + else /* match a user by direct specification */ + userok = !(strcmp(ruser, user+1)); + break; + case '-': /* if we matched a hostname, */ + if (hostok) { /* check for user field rejections */ + if (!*(user+1)) + return(-1); + if (*(user+1) == '@') { + if (innetgr(user+2, NULL, + ruser, ypdomain)) + return(-1); + } else { + if (!strcmp(ruser, user+1)) + return(-1); + } + } + break; + default: /* no rejections: try to match the user */ + if (hostok) + userok = !(strcmp(ruser,*user ? user : luser)); + break; + } + if (hostok && userok) + return(0); + } + return (-1); } /* - * Returns 0 if positive match, -1 if _not_ ok. + * Returns "true" if match, 0 if no match. + * + * NI_WITHSCOPEID is useful for comparing sin6_scope_id portion + * if af == AF_INET6. */ static int -__validuser2_sa(hostf, ra, ralen, luser, ruser, rhost) - FILE *hostf; - struct sockaddr *ra; - size_t ralen; - const char *luser, *ruser, *rhost; +__icheckhost(raddr, salen, lhost) + const struct sockaddr *raddr; + socklen_t salen; + const char *lhost; { - register const char *user; - register char *p; - int hcheck, ucheck; - char *buf = NULL; - size_t bufsize = 0; - int retval = -1; - - while (__getline (&buf, &bufsize, hostf) > 0) { - buf[bufsize - 1] = '\0'; /* Make sure it's terminated. */ - p = buf; - - /* Skip empty or comment lines */ - if (__isempty (p)) { - continue; - } - - for (;*p && !isspace(*p); ++p) { - *p = _tolower (*p); + struct sockaddr_in sin; + struct sockaddr_in6 *sin6; + struct addrinfo hints, *res, *r; + int error; + char h1[NI_MAXHOST], h2[NI_MAXHOST]; + + if (raddr->sa_family == AF_INET6) { + sin6 = (struct sockaddr_in6 *)raddr; + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[12], + sizeof(sin.sin_addr)); + raddr = (struct sockaddr *)&sin; + salen = sizeof(struct sockaddr_in); + } } - /* Next we want to find the permitted name for the remote user. */ - if (*p == ' ' || *p == '\t') { - /* terminate hostname and skip spaces */ - for (*p++='\0'; *p && isspace (*p); ++p); - - user = p; /* this is the user's name */ - while (*p && !isspace (*p)) - ++p; /* find end of user's name */ - } else - user = p; - - *p = '\0'; /* terminate username (+host?) */ - - /* buf -> host(?) ; user -> username(?) */ - - /* First check host part */ - hcheck = __checkhost_sa (ra, ralen, buf, rhost); - - if (hcheck < 0) - break; - - if (hcheck) { - /* Then check user part */ - if (! (*user)) - user = luser; - - ucheck = __icheckuser (user, ruser); - - /* Positive 'host user' match? */ - if (ucheck > 0) { - retval = 0; - break; - } - - /* Negative 'host -user' match? */ - if (ucheck < 0) - break; - - /* Neither, go on looking for match */ + h1[0] = '\0'; + if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, + NI_NUMERICHOST | NI_WITHSCOPEID) != 0) + return (0); + + /* Resolve laddr into sockaddr */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = raddr->sa_family; + hints.ai_socktype = SOCK_DGRAM; /*XXX dummy*/ + res = NULL; + error = getaddrinfo(lhost, "0", &hints, &res); + if (error) + return (0); + + for (r = res; r ; r = r->ai_next) { + h2[0] = '\0'; + if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), + NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) != 0) + continue; + if (strcmp(h1, h2) == 0) { + freeaddrinfo(res); + return (1); + } } - } - - if (buf != NULL) - free (buf); - return retval; + /* No match. */ + freeaddrinfo(res); + return (0); } diff --git a/newlib/libc/sys/linux/net/rcmdsh.3 b/newlib/libc/sys/linux/net/rcmdsh.3 new file mode 100644 index 000000000..43e6a8daa --- /dev/null +++ b/newlib/libc/sys/linux/net/rcmdsh.3 @@ -0,0 +1,116 @@ +.\" $OpenBSD: rcmdsh.3,v 1.6 1999/07/05 04:41:00 aaron Exp $ +.\" +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libc/net/rcmdsh.3,v 1.2 2001/11/09 15:19:25 ru Exp $ +.\" +.Dd September 1, 1996 +.Dt RCMDSH 3 +.Os +.Sh NAME +.Nm rcmdsh +.Nd return a stream to a remote command without superuser +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fo rcmdsh +.Fa "char **ahost" +.Fa "int inport" +.Fa "const char *locuser" +.Fa "const char *remuser" +.Fa "const char *cmd" +.Fa "const char *rshprog" +.Fc +.Sh DESCRIPTION +The +.Fn rcmdsh +function +is used by normal users to execute a command on +a remote machine using an authentication scheme based +on reserved port numbers using +.Xr rshd 8 +or the value of +.Fa rshprog +(if +.No non- Ns Dv NULL ) . +.Pp +The +.Fn rcmdsh +function +looks up the host +.Fa *ahost +using +.Xr gethostbyname 3 , +returning \-1 if the host does not exist. +Otherwise +.Fa *ahost +is set to the standard name of the host +and a connection is established to a server +residing at the well-known Internet port +.Dq Li shell/tcp +(or whatever port is used by +.Fa rshprog ) . +The parameter +.Fa inport +is ignored; it is only included to provide an interface similar to +.Xr rcmd 3 . +.Pp +If the connection succeeds, +a socket in the +.Ux +domain of type +.Dv SOCK_STREAM +is returned to the caller, and given to the remote +command as stdin, stdout, and stderr. +.Sh RETURN VALUES +The +.Fn rcmdsh +function +returns a valid socket descriptor on success. +Otherwise, \-1 is returned +and a diagnostic message is printed on the standard error. +.Sh SEE ALSO +.Xr rsh 1 , +.Xr socketpair 2 , +.Xr rcmd 3 , +.Xr rshd 8 +.Sh BUGS +If +.Xr rsh 1 +encounters an error, a file descriptor is still returned instead of \-1. +.Sh HISTORY +The +.Fn rcmdsh +function first appeared in +.Ox 2.0 , +and made its way into +.Fx 5.0 . diff --git a/newlib/libc/sys/linux/net/res_comp.c b/newlib/libc/sys/linux/net/res_comp.c index 51211f743..12ea02c6d 100644 --- a/newlib/libc/sys/linux/net/res_comp.c +++ b/newlib/libc/sys/linux/net/res_comp.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -48,7 +52,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,9 +69,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$BINDId: res_comp.c,v 8.15 1999/10/13 16:39:39 vixie Exp $"; +static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; +static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $"; #endif /* LIBC_SCCS and not lint */ +#include +#include #include #include @@ -78,7 +84,8 @@ static const char rcsid[] = "$BINDId: res_comp.c,v 8.15 1999/10/13 16:39:39 vixi #include #include #include -#include "libc-symbols.h" + +#define BIND_4_COMPAT /* * Expand compressed domain name 'comp_dn' to full domain name. @@ -97,7 +104,6 @@ dn_expand(const u_char *msg, const u_char *eom, const u_char *src, dst[0] = '\0'; return (n); } -libresolv_hidden_def (dn_expand) /* * Pack domain name 'exp_dn' in presentation form into 'comp_dn'. @@ -112,7 +118,6 @@ dn_comp(const char *src, u_char *dst, int dstsiz, (const u_char **)dnptrs, (const u_char **)lastdnptr)); } -libresolv_hidden_def (dn_comp) /* * Skip over a compressed domain name. Return the size or -1. @@ -125,7 +130,6 @@ dn_skipname(const u_char *ptr, const u_char *eom) { return (-1); return (ptr - saveptr); } -libresolv_hidden_def (dn_skipname) /* * Verify that a domain name uses an acceptable character set. @@ -139,7 +143,6 @@ libresolv_hidden_def (dn_skipname) */ #define PERIOD 0x2e #define hyphenchar(c) ((c) == 0x2d) -#define underscorechar(c) ((c) == 0x5f) #define bslashchar(c) ((c) == 0x5c) #define periodchar(c) ((c) == PERIOD) #define asterchar(c) ((c) == 0x2a) @@ -148,11 +151,13 @@ libresolv_hidden_def (dn_skipname) #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) #define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) +#define middlechar(c) (borderchar(c) || hyphenchar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int -res_hnok(const char *dn) { +res_hnok(dn) + const char *dn; +{ int ppch = '\0', pch = PERIOD, ch = *dn++; while (ch != '\0') { @@ -174,14 +179,15 @@ res_hnok(const char *dn) { } return (1); } -libresolv_hidden_def (res_hnok) /* * hostname-like (A, MX, WKS) owners can have "*" as their first label * but must otherwise be as a host name. */ int -res_ownok(const char *dn) { +res_ownok(dn) + const char *dn; +{ if (asterchar(dn[0])) { if (periodchar(dn[1])) return (res_hnok(dn+2)); @@ -196,7 +202,9 @@ res_ownok(const char *dn) { * label, but the rest of the name has to look like a host name. */ int -res_mailok(const char *dn) { +res_mailok(dn) + const char *dn; +{ int ch, escaped = 0; /* "." is a valid missing representation */ @@ -224,7 +232,9 @@ res_mailok(const char *dn) { * recommendations. */ int -res_dnok(const char *dn) { +res_dnok(dn) + const char *dn; +{ int ch; while ((ch = *dn++) != '\0') @@ -232,31 +242,27 @@ res_dnok(const char *dn) { return (0); return (1); } -libresolv_hidden_def (res_dnok) #ifdef BIND_4_COMPAT /* * This module must export the following externally-visible symbols: - * ___putlong - * ___putshort - * __getlong - * __getshort + * ___putlong + * ___putshort + * __getlong + * __getshort * Note that one _ comes from C and the others come from us. */ void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); } -libresolv_hidden_def (__putlong) void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); } -libresolv_hidden_def (__putshort) -#ifndef __ultrix__ u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); } u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); } -#endif /*__ultrix__*/ #endif /*BIND_4_COMPAT*/ - -#include - -#if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2) -# undef dn_expand -weak_alias (__dn_expand, dn_expand); -#endif +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef dn_comp +__weak_reference(__dn_comp, dn_comp); +#undef dn_expand +__weak_reference(__dn_expand, dn_expand); diff --git a/newlib/libc/sys/linux/net/res_config.h b/newlib/libc/sys/linux/net/res_config.h new file mode 100644 index 000000000..b7deb38f9 --- /dev/null +++ b/newlib/libc/sys/linux/net/res_config.h @@ -0,0 +1,10 @@ +/* $FreeBSD: src/lib/libc/net/res_config.h,v 1.8 2002/03/22 23:41:54 obrien Exp $ */ + +#define DEBUG 1 /* enable debugging code (needed for dig) */ +#define RESOLVSORT /* allow sorting of addresses in gethostbyname */ +#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/ +#undef USELOOPBACK /* res_init() bind to localhost */ +#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */ +#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */ +#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */ +#define BIND_UPDATE 1 /* update support */ diff --git a/newlib/libc/sys/linux/net/res_data.c b/newlib/libc/sys/linux/net/res_data.c index cb140eeb7..7db548078 100644 --- a/newlib/libc/sys/linux/net/res_data.c +++ b/newlib/libc/sys/linux/net/res_data.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-1999 by Internet Software Consortium. + * Copyright (c) 1995,1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,30 +15,24 @@ * SOFTWARE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$BINDId: res_data.c,v 8.17 1999/10/13 17:11:31 vixie Exp $"; -#endif /* LIBC_SCCS and not lint */ +#include +#include #include #include #include #include - #include #include #include - #include -#include #include -#ifdef BIND_UPDATE -#include -#endif #include #include #include #include -#include "libc-symbols.h" + +#include "res_config.h" const char *_res_opcodes[] = { "QUERY", @@ -58,278 +52,31 @@ const char *_res_opcodes[] = { "ZONEINIT", "ZONEREF", }; -libresolv_hidden_data_def (_res_opcodes) + +const char *_res_resultcodes[] = { + "NOERROR", + "FORMERR", + "SERVFAIL", + "NXDOMAIN", + "NOTIMP", + "REFUSED", + "YXDOMAIN", + "YXRRSET", + "NXRRSET", + "NOTAUTH", + "ZONEERR", + "11", + "12", + "13", + "14", + "NOCHANGE", +}; #ifdef BIND_UPDATE -const char *_res_sectioncodes[] attribute_hidden = { +const char *_res_sectioncodes[] = { "ZONE", "PREREQUISITES", "UPDATE", "ADDITIONAL", }; #endif - -#ifndef __BIND_NOSTATIC -#ifdef _LIBC -/* The definition has been moved to res_libc.c. */ -#else -#undef _res -struct __res_state _res -# if defined(__BIND_RES_TEXT) - = { RES_TIMEOUT, } /* Motorola, et al. */ -# endif - ; -#endif - -/* Proto. */ -#ifndef _LIBC -int res_ourserver_p(const res_state, const struct sockaddr_in *); -void res_pquery(const res_state, const u_char *, int, FILE *); -#endif - -#ifndef _LIBC -/* Moved to res_libc.c since res_init() should go into libc.so but the - rest of this file not. */ -int -res_init(void) { - extern int __res_vinit(res_state, int); - - /* - * These three fields used to be statically initialized. This made - * it hard to use this code in a shared library. It is necessary, - * now that we're doing dynamic initialization here, that we preserve - * the old semantics: if an application modifies one of these three - * fields of _res before res_init() is called, res_init() will not - * alter them. Of course, if an application is setting them to - * _zero_ before calling res_init(), hoping to override what used - * to be the static default, we can't detect it and unexpected results - * will follow. Zero for any of these fields would make no sense, - * so one can safely assume that the applications were already getting - * unexpected results. - * - * _res.options is tricky since some apps were known to diddle the bits - * before res_init() was first called. We can't replicate that semantic - * with dynamic initialization (they may have turned bits off that are - * set in RES_DEFAULT). Our solution is to declare such applications - * "broken". They could fool us by setting RES_INIT but none do (yet). - */ - if (!_res.retrans) - _res.retrans = RES_TIMEOUT; - if (!_res.retry) - _res.retry = 4; - if (!(_res.options & RES_INIT)) - _res.options = RES_DEFAULT; - - /* - * This one used to initialize implicitly to zero, so unless the app - * has set it to something in particular, we can randomize it now. - */ - if (!_res.id) - _res.id = res_randomid(); - - return (__res_vinit(&_res, 1)); -} -#endif - -void -p_query(const u_char *msg) { - fp_query(msg, stdout); -} - -void -fp_query(const u_char *msg, FILE *file) { - fp_nquery(msg, PACKETSZ, file); -} -libresolv_hidden_def (fp_query) - -void -fp_nquery(const u_char *msg, int len, FILE *file) { - if (__res_maybe_init (&_res, 0) == -1) - return; - - res_pquery(&_res, msg, len, file); -} -libresolv_hidden_def (fp_nquery) - -int -res_mkquery(int op, /* opcode of query */ - const char *dname, /* domain name */ - int class, int type, /* class and type of query */ - const u_char *data, /* resource record data */ - int datalen, /* length of data */ - const u_char *newrr_in, /* new rr for modify or append */ - u_char *buf, /* buffer to put query */ - int buflen) /* size of buffer */ -{ - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - return (res_nmkquery(&_res, op, dname, class, type, - data, datalen, - newrr_in, buf, buflen)); -} - -#ifdef BIND_UPDATE -int -res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - - return (res_nmkupdate(&_res, rrecp_in, buf, buflen)); -} -#endif - -int -res_query(const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer buffer */ -{ - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - return (res_nquery(&_res, name, class, type, answer, anslen)); -} - -void -res_send_setqhook(res_send_qhook hook) { - _res.qhook = hook; -} - -void -res_send_setrhook(res_send_rhook hook) { - _res.rhook = hook; -} - -int -res_isourserver(const struct sockaddr_in *inp) { - return (res_ourserver_p(&_res, (const struct sockaddr_in6 *) inp)); -} - -int -res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { - if (__res_maybe_init (&_res, 1) == -1) { - /* errno should have been set by res_init() in this case. */ - return (-1); - } - - return (res_nsend(&_res, buf, buflen, ans, anssiz)); -} - -#ifndef _LIBC -int -res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, - u_char *ans, int anssiz) -{ - if (__res_maybe_init (&_res, 1) == -1) { - /* errno should have been set by res_init() in this case. */ - return (-1); - } - - return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz)); -} -#endif - -void -res_close(void) { -#ifdef _LIBC - /* - * Some stupid programs out there call res_close() before res_init(). - * Since _res._vcsock isn't explicitly initialized, these means that - * we could do a close(0), which might lead to some security problems. - * Therefore we check if res_init() was called before by looking at - * the RES_INIT bit in _res.options. If it hasn't been set we bail out - * early. */ - if ((_res.options & RES_INIT) == 0) - return; -#endif - res_nclose(&_res); -} - -#ifdef BIND_UPDATE -int -res_update(ns_updrec *rrecp_in) { - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - - return (res_nupdate(&_res, rrecp_in, NULL)); -} -#endif - -int -res_search(const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ -{ - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - - return (res_nsearch(&_res, name, class, type, answer, anslen)); -} - -int -res_querydomain(const char *name, - const char *domain, - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ -{ - if (__res_maybe_init (&_res, 1) == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); - return (-1); - } - - return (res_nquerydomain(&_res, name, domain, - class, type, - answer, anslen)); -} - -const char * -hostalias(const char *name) { - static char abuf[MAXDNAME]; - - return (res_hostalias(&_res, name, abuf, sizeof abuf)); -} -libresolv_hidden_def (hostalias) - -#ifdef ultrix -int -local_hostname_length(const char *hostname) { - int len_host, len_domain; - - if (!*_res.defdname) - res_init(); - len_host = strlen(hostname); - len_domain = strlen(_res.defdname); - if (len_host > len_domain && - !strcasecmp(hostname + len_host - len_domain, _res.defdname) && - hostname[len_host - len_domain - 1] == '.') - return (len_host - len_domain - 1); - return (0); -} -#endif /*ultrix*/ - -#endif - - -#include - -#if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2) -# undef res_mkquery -# undef res_query -# undef res_querydomain -# undef res_search -weak_alias (__res_mkquery, res_mkquery); -weak_alias (__res_query, res_query); -weak_alias (__res_querydomain, res_querydomain); -weak_alias (__res_search, res_search); -#endif diff --git a/newlib/libc/sys/linux/net/res_debug.c b/newlib/libc/sys/linux/net/res_debug.c index cd50fe546..786f633f4 100644 --- a/newlib/libc/sys/linux/net/res_debug.c +++ b/newlib/libc/sys/linux/net/res_debug.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -73,7 +77,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -90,9 +94,10 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$BINDId: res_debug.c,v 8.34 2000/02/29 05:30:55 vixie Exp $"; +static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include +#include #include #include @@ -111,24 +116,23 @@ static const char rcsid[] = "$BINDId: res_debug.c,v 8.34 2000/02/29 05:30:55 vix #include #include #include -#include "local.h" -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) sprintf x -#endif +#define SPRINTF(x) sprintf x -extern const char *_res_sectioncodes[] attribute_hidden; +extern const char *_res_opcodes[]; +extern const char *_res_resultcodes[]; +extern const char *_res_sectioncodes[]; /* * Print the current options. */ void -fp_resstat(const res_state statp, FILE *file) { +fp_resstat(struct __res_state *statp, FILE *file) { u_long mask; fprintf(file, ";; res options:"); + if (!statp) + statp = &_res; for (mask = 1; mask != 0; mask <<= 1) if (statp->options & mask) fprintf(file, " %s", p_option(mask)); @@ -136,30 +140,20 @@ fp_resstat(const res_state statp, FILE *file) { } static void -do_section(const res_state statp, - ns_msg *handle, ns_sect section, - int pflag, FILE *file) -{ +do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) { int n, sflag, rrnum; - static int buflen = 2048; - char *buf; + char buf[2048]; /* XXX need to malloc */ ns_opcode opcode; ns_rr rr; /* * Print answer records. */ - sflag = (statp->pfcode & pflag); - if (statp->pfcode && !sflag) + sflag = (_res.pfcode & pflag); + if (_res.pfcode && !sflag) return; - buf = malloc(buflen); - if (buf == NULL) { - fprintf(file, ";; memory allocation failure\n"); - return; - } - - opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode); + opcode = ns_msg_getflag(*handle, ns_f_opcode); rrnum = 0; for (;;) { if (ns_parserr(handle, section, rrnum, &rr)) { @@ -167,11 +161,11 @@ do_section(const res_state statp, fprintf(file, ";; ns_parserr: %s\n", strerror(errno)); else if (rrnum > 0 && sflag != 0 && - (statp->pfcode & RES_PRF_HEAD1)) + (_res.pfcode & RES_PRF_HEAD1)) putc('\n', file); - goto cleanup; + return; } - if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) + if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", p_section(section, opcode)); if (section == ns_s_qd) @@ -181,32 +175,27 @@ do_section(const res_state statp, p_class(ns_rr_class(rr))); else { n = ns_sprintrr(handle, &rr, NULL, NULL, - buf, buflen); + buf, sizeof buf); if (n < 0) { - if (errno == ENOSPC) { - free(buf); - buf = NULL; - if (buflen < 131072) - buf = malloc(buflen += 1024); - if (buf == NULL) { - fprintf(file, - ";; memory allocation failure\n"); - return; - } - continue; - } fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno)); - goto cleanup; + return; } fputs(buf, file); fputc('\n', file); } rrnum++; } - cleanup: - if (buf != NULL) - free(buf); +} + +void +p_query(const u_char *msg) { + fp_query(msg, stdout); +} + +void +fp_query(const u_char *msg, FILE *file) { + fp_nquery(msg, PACKETSZ, file); } /* @@ -214,11 +203,14 @@ do_section(const res_state statp, * This is intended to be primarily a debugging routine. */ void -res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { +fp_nquery(const u_char *msg, int len, FILE *file) { ns_msg handle; int qdcount, ancount, nscount, arcount; u_int opcode, rcode, id; + if ((_res.options & RES_INIT) == 0 && res_init() == -1) + return; + if (ns_initparse(msg, len, &handle) < 0) { fprintf(file, ";; ns_initparse: %s\n", strerror(errno)); return; @@ -234,13 +226,13 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { /* * Print header fields. */ - if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode) + if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode) fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", - _res_opcodes[opcode], p_rcode(rcode), id); - if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) + _res_opcodes[opcode], _res_resultcodes[rcode], id); + if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) putc(';', file); - if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) { + if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { fprintf(file, "; flags:"); if (ns_msg_getflag(handle, ns_f_qr)) fprintf(file, " qr"); @@ -259,7 +251,7 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { if (ns_msg_getflag(handle, ns_f_cd)) fprintf(file, " cd"); } - if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) { + if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { fprintf(file, "; %s: %d", p_section(ns_s_qd, opcode), qdcount); fprintf(file, ", %s: %d", @@ -269,17 +261,17 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { fprintf(file, ", %s: %d", p_section(ns_s_ar, opcode), arcount); } - if ((!statp->pfcode) || (statp->pfcode & + if ((!_res.pfcode) || (_res.pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { putc('\n',file); } /* * Print the various sections. */ - do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file); - do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file); - do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file); - do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file); + do_section(&handle, ns_s_qd, RES_PRF_QUES, file); + do_section(&handle, ns_s_an, RES_PRF_ANS, file); + do_section(&handle, ns_s_ns, RES_PRF_AUTH, file); + do_section(&handle, ns_s_ar, RES_PRF_ADD, file); if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) putc('\n', file); @@ -298,7 +290,6 @@ p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) { fputs(name, file); return (cp + n); } -libresolv_hidden_def (p_cdnname) const u_char * p_cdname(const u_char *cp, const u_char *msg, FILE *file) { @@ -328,7 +319,6 @@ p_fqnname(cp, msg, msglen, name, namelen) } return (cp + n); } -libresolv_hidden_def (p_fqnname) /* XXX: the rest of these functions need to become length-limited, too. */ @@ -349,8 +339,6 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) { * that C_ANY is a qclass but not a class. (You can ask for records of class * C_ANY, but you can't have any records of that class in the database.) */ -extern const struct res_sym __p_class_syms[]; -libresolv_hidden_proto (__p_class_syms) const struct res_sym __p_class_syms[] = { {C_IN, "IN"}, {C_CHAOS, "CHAOS"}, @@ -360,12 +348,11 @@ const struct res_sym __p_class_syms[] = { {C_NONE, "NONE"}, {C_IN, (char *)0} }; -libresolv_hidden_data_def (__p_class_syms) /* * Names of message sections. */ -const struct res_sym __p_default_section_syms[] attribute_hidden = { +const struct res_sym __p_default_section_syms[] = { {ns_s_qd, "QUERY"}, {ns_s_an, "ANSWER"}, {ns_s_ns, "AUTHORITY"}, @@ -373,7 +360,7 @@ const struct res_sym __p_default_section_syms[] attribute_hidden = { {0, (char *)0} }; -const struct res_sym __p_update_section_syms[] attribute_hidden = { +const struct res_sym __p_update_section_syms[] = { {S_ZONE, "ZONE"}, {S_PREREQ, "PREREQUISITE"}, {S_UPDATE, "UPDATE"}, @@ -381,101 +368,54 @@ const struct res_sym __p_update_section_syms[] attribute_hidden = { {0, (char *)0} }; -const struct res_sym __p_key_syms[] attribute_hidden = { - {NS_ALG_MD5RSA, "RSA", "RSA KEY with MD5 hash"}, - {NS_ALG_DH, "DH", "Diffie Hellman"}, - {NS_ALG_DSA, "DSA", "Digital Signature Algorithm"}, - {NS_ALG_EXPIRE_ONLY, "EXPIREONLY", "No algorithm"}, - {NS_ALG_PRIVATE_OID, "PRIVATE", "Algorithm obtained from OID"}, - {0, NULL, NULL} -}; - -const struct res_sym __p_cert_syms[] attribute_hidden = { - {cert_t_pkix, "PKIX", "PKIX (X.509v3) Certificate"}, - {cert_t_spki, "SPKI", "SPKI certificate"}, - {cert_t_pgp, "PGP", "PGP certificate"}, - {cert_t_url, "URL", "URL Private"}, - {cert_t_oid, "OID", "OID Private"}, - {0, NULL, NULL} -}; - /* * Names of RR types and qtypes. Types and qtypes are the same, except * that T_ANY is a qtype but not a type. (You can ask for records of type * T_ANY, but you can't have any records of that type in the database.) */ -extern const struct res_sym __p_type_syms[]; -libresolv_hidden_proto (__p_type_syms) const struct res_sym __p_type_syms[] = { - {ns_t_a, "A", "address"}, - {ns_t_ns, "NS", "name server"}, - {ns_t_md, "MD", "mail destination (deprecated)"}, - {ns_t_mf, "MF", "mail forwarder (deprecated)"}, - {ns_t_cname, "CNAME", "canonical name"}, - {ns_t_soa, "SOA", "start of authority"}, - {ns_t_mb, "MB", "mailbox"}, - {ns_t_mg, "MG", "mail group member"}, - {ns_t_mr, "MR", "mail rename"}, - {ns_t_null, "NULL", "null"}, - {ns_t_wks, "WKS", "well-known service (deprecated)"}, - {ns_t_ptr, "PTR", "domain name pointer"}, - {ns_t_hinfo, "HINFO", "host information"}, - {ns_t_minfo, "MINFO", "mailbox information"}, - {ns_t_mx, "MX", "mail exchanger"}, - {ns_t_txt, "TXT", "text"}, - {ns_t_rp, "RP", "responsible person"}, - {ns_t_afsdb, "AFSDB", "DCE or AFS server"}, - {ns_t_x25, "X25", "X25 address"}, - {ns_t_isdn, "ISDN", "ISDN address"}, - {ns_t_rt, "RT", "router"}, - {ns_t_nsap, "NSAP", "nsap address"}, - {ns_t_nsap_ptr, "NSAP_PTR", "domain name pointer"}, - {ns_t_sig, "SIG", "signature"}, - {ns_t_key, "KEY", "key"}, - {ns_t_px, "PX", "mapping information"}, - {ns_t_gpos, "GPOS", "geographical position (withdrawn)"}, - {ns_t_aaaa, "AAAA", "IPv6 address"}, - {ns_t_loc, "LOC", "location"}, - {ns_t_nxt, "NXT", "next valid name (unimplemented)"}, - {ns_t_eid, "EID", "endpoint identifier (unimplemented)"}, - {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"}, - {ns_t_srv, "SRV", "server selection"}, - {ns_t_atma, "ATMA", "ATM address (unimplemented)"}, - {ns_t_tsig, "TSIG", "transaction signature"}, - {ns_t_ixfr, "IXFR", "incremental zone transfer"}, - {ns_t_axfr, "AXFR", "zone transfer"}, - {ns_t_zxfr, "ZXFR", "compressed zone transfer"}, - {ns_t_mailb, "MAILB", "mailbox-related data (deprecated)"}, - {ns_t_maila, "MAILA", "mail agent (deprecated)"}, - {ns_t_naptr, "NAPTR", "URN Naming Authority"}, - {ns_t_kx, "KX", "Key Exchange"}, - {ns_t_cert, "CERT", "Certificate"}, - {ns_t_any, "ANY", "\"any\""}, + {T_A, "A", "address"}, + {T_NS, "NS", "name server"}, + {T_MD, "MD", "mail destination (deprecated)"}, + {T_MF, "MF", "mail forwarder (deprecated)"}, + {T_CNAME, "CNAME", "canonical name"}, + {T_SOA, "SOA", "start of authority"}, + {T_MB, "MB", "mailbox"}, + {T_MG, "MG", "mail group member"}, + {T_MR, "MR", "mail rename"}, + {T_NULL, "NULL", "null"}, + {T_WKS, "WKS", "well-known service (deprecated)"}, + {T_PTR, "PTR", "domain name pointer"}, + {T_HINFO, "HINFO", "host information"}, + {T_MINFO, "MINFO", "mailbox information"}, + {T_MX, "MX", "mail exchanger"}, + {T_TXT, "TXT", "text"}, + {T_RP, "RP", "responsible person"}, + {T_AFSDB, "AFSDB", "DCE or AFS server"}, + {T_X25, "X25", "X25 address"}, + {T_ISDN, "ISDN", "ISDN address"}, + {T_RT, "RT", "router"}, + {T_NSAP, "NSAP", "nsap address"}, + {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"}, + {T_SIG, "SIG", "signature"}, + {T_KEY, "KEY", "key"}, + {T_PX, "PX", "mapping information"}, + {T_GPOS, "GPOS", "geographical position (withdrawn)"}, + {T_AAAA, "AAAA", "IPv6 address"}, + {T_LOC, "LOC", "location"}, + {T_NXT, "NXT", "next valid name (unimplemented)"}, + {T_EID, "EID", "endpoint identifier (unimplemented)"}, + {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"}, + {T_SRV, "SRV", "server selection"}, + {T_ATMA, "ATMA", "ATM address (unimplemented)"}, + {T_IXFR, "IXFR", "incremental zone transfer"}, + {T_AXFR, "AXFR", "zone transfer"}, + {T_MAILB, "MAILB", "mailbox-related data (deprecated)"}, + {T_MAILA, "MAILA", "mail agent (deprecated)"}, + {T_NAPTR, "NAPTR", "URN Naming Authority"}, + {T_ANY, "ANY", "\"any\""}, {0, NULL, NULL} }; -libresolv_hidden_data_def (__p_type_syms) - -/* - * Names of DNS rcodes. - */ -const struct res_sym __p_rcode_syms[] attribute_hidden = { - {ns_r_noerror, "NOERROR", "no error"}, - {ns_r_formerr, "FORMERR", "format error"}, - {ns_r_servfail, "SERVFAIL", "server failed"}, - {ns_r_nxdomain, "NXDOMAIN", "no such domain name"}, - {ns_r_notimpl, "NOTIMP", "not implemented"}, - {ns_r_refused, "REFUSED", "refused"}, - {ns_r_yxdomain, "YXDOMAIN", "domain name exists"}, - {ns_r_yxrrset, "YXRRSET", "rrset exists"}, - {ns_r_nxrrset, "NXRRSET", "rrset doesn't exist"}, - {ns_r_notauth, "NOTAUTH", "not authoritative"}, - {ns_r_notzone, "NOTZONE", "Not in zone"}, - {ns_r_max, "", ""}, - {ns_r_badsig, "BADSIG", "bad signature"}, - {ns_r_badkey, "BADKEY", "bad key"}, - {ns_r_badtime, "BADTIME", "bad time"}, - {0, NULL, NULL} -}; int sym_ston(const struct res_sym *syms, const char *name, int *success) { @@ -503,12 +443,11 @@ sym_ntos(const struct res_sym *syms, int number, int *success) { } } - sprintf(unname, "%d", number); /* XXX nonreentrant */ + sprintf(unname, "%d", number); if (success) *success = 0; return (unname); } -libresolv_hidden_def (sym_ntos) const char * sym_ntop(const struct res_sym *syms, int number, int *success) { @@ -521,7 +460,7 @@ sym_ntop(const struct res_sym *syms, int number, int *success) { return (syms->humanname); } } - sprintf(unname, "%d", number); /* XXX nonreentrant */ + sprintf(unname, "%d", number); if (success) *success = 0; return (unname); @@ -534,7 +473,6 @@ const char * p_type(int type) { return (sym_ntos(__p_type_syms, type, (int *)0)); } -libresolv_hidden_def (p_type) /* * Return a string for the type. @@ -561,7 +499,6 @@ const char * p_class(int class) { return (sym_ntos(__p_class_syms, class, (int *)0)); } -libresolv_hidden_def (p_class) /* * Return a mnemonic for an option @@ -583,37 +520,27 @@ p_option(u_long option) { case RES_DNSRCH: return "dnsrch"; case RES_INSECURE1: return "insecure1"; case RES_INSECURE2: return "insecure2"; + case RES_NOALIASES: return "noaliases"; case RES_USE_INET6: return "inet6"; - case RES_ROTATE: return "rotate"; - case RES_NOCHECKNAME: return "no-check-names"; - case RES_USEBSTRING: return "ip6-bytstring"; - /* XXX nonreentrant */ + case RES_NOTLDQUERY: return "no-tld-query"; + case RES_USE_EDNS0: return "edns0"; default: sprintf(nbuf, "?0x%lx?", (u_long)option); return (nbuf); } } -libresolv_hidden_def (p_option) /* * Return a mnemonic for a time to live. */ const char * p_time(u_int32_t value) { - static char nbuf[40]; /* XXX nonreentrant */ + static char nbuf[40]; if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0) sprintf(nbuf, "%u", value); return (nbuf); } -/* - * Return a string for the rcode. - */ -const char * -p_rcode(int rcode) { - return (sym_ntos(__p_rcode_syms, rcode, (int *)0)); -} -libresolv_hidden_def (p_rcode) /* * routines to convert between on-the-wire RR format and zone file format. @@ -621,16 +548,15 @@ libresolv_hidden_def (p_rcode) * by 60*60*1000 for that. */ -static const unsigned int poweroften[10]= - { 1, 10, 100, 1000, 10000, 100000, - 1000000,10000000,100000000,1000000000}; +static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, + 1000000,10000000,100000000,1000000000}; /* takes an XeY precision/size value, returns a string representation. */ static const char * precsize_ntoa(prec) u_int8_t prec; { - static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */ + static char retbuf[sizeof "90000000.00"]; unsigned long val; int mantissa, exponent; @@ -646,24 +572,24 @@ precsize_ntoa(prec) /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ static u_int8_t precsize_aton(strptr) - const char **strptr; + char **strptr; { unsigned int mval = 0, cmval = 0; u_int8_t retval = 0; - const char *cp; + char *cp; int exponent; int mantissa; cp = *strptr; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) mval = mval * 10 + (*cp++ - '0'); if (*cp == '.') { /* centimeters */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { cmval = (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { cmval += (*cp++ - '0'); } } @@ -688,53 +614,53 @@ precsize_aton(strptr) /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ static u_int32_t latlon2ul(latlonstrptr,which) - const char **latlonstrptr; + char **latlonstrptr; int *which; { - const char *cp; + char *cp; u_int32_t retval; int deg = 0, min = 0, secs = 0, secsfrac = 0; cp = *latlonstrptr; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) deg = deg * 10 + (*cp++ - '0'); - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; - if (!(isdigit(*cp))) + if (!(isdigit((unsigned char)*cp))) goto fndhemi; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) min = min * 10 + (*cp++ - '0'); - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; - if (!(isdigit(*cp))) + if (!(isdigit((unsigned char)*cp))) goto fndhemi; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) secs = secs * 10 + (*cp++ - '0'); if (*cp == '.') { /* decimal seconds */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac = (*cp++ - '0') * 100; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac += (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac += (*cp++ - '0'); } } } } - while (!isspace(*cp)) /* if any trailing garbage */ + while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ cp++; - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; fndhemi: @@ -772,10 +698,10 @@ latlon2ul(latlonstrptr,which) cp++; /* skip the hemisphere */ - while (!isspace(*cp)) /* if any trailing garbage */ + while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ cp++; - while (isspace(*cp)) /* move to next field */ + while (isspace((unsigned char)*cp)) /* move to next field */ cp++; *latlonstrptr = cp; @@ -829,18 +755,18 @@ loc_aton(ascii, binary) altsign = -1; cp++; } - + if (*cp == '+') cp++; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) altmeters = altmeters * 10 + (*cp++ - '0'); if (*cp == '.') { /* decimal meters */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { altfrac = (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { altfrac += (*cp++ - '0'); } } @@ -848,21 +774,21 @@ loc_aton(ascii, binary) alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) goto defaults; siz = precsize_aton(&cp); - - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) @@ -870,10 +796,10 @@ loc_aton(ascii, binary) hp = precsize_aton(&cp); - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) @@ -891,7 +817,7 @@ loc_aton(ascii, binary) PUTLONG(latit,bcp); PUTLONG(longit,bcp); PUTLONG(alt,bcp); - + return (16); /* size of RR in octets */ } @@ -902,8 +828,6 @@ loc_ntoa(binary, ascii) char *ascii; { static char *error = "?"; - static char tmpbuf[sizeof -"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"]; const u_char *cp = binary; int latdeg, latmin, latsec, latsecfrac; @@ -916,13 +840,12 @@ loc_ntoa(binary, ascii) int32_t latval, longval, altval; u_int32_t templ; u_int8_t sizeval, hpval, vpval, versionval; - + char *sizestr, *hpstr, *vpstr; - versionval = *cp++; + size_t len; - if (ascii == NULL) - ascii = tmpbuf; + versionval = *cp++; if (versionval) { (void) sprintf(ascii, "; error: unknown LOC RR version"); @@ -980,12 +903,21 @@ loc_ntoa(binary, ascii) altfrac = altval % 100; altmeters = (altval / 100) * altsign; - if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL) + len = strlen (precsize_ntoa(sizeval)) + 1; + if ((sizestr = malloc(len)) == NULL) sizestr = error; - if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL) + else + memcpy (sizestr, precsize_ntoa(sizeval), len); + len = strlen (precsize_ntoa(hpval)) + 1; + if ((hpstr = malloc (len)) == NULL) hpstr = error; - if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) + else + memcpy (hpstr, precsize_ntoa(hpval), len); + len = strlen (precsize_ntoa(vpval)) + 1; + if ((vpstr = malloc (len)) == NULL) vpstr = error; + else + memcpy (vpstr, precsize_ntoa(vpval), len); sprintf(ascii, "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm", @@ -1002,7 +934,6 @@ loc_ntoa(binary, ascii) return (ascii); } -libresolv_hidden_def (loc_ntoa) /* Return the number of DNS hierarchy levels in the name. */ @@ -1031,24 +962,17 @@ dn_count_labels(const char *name) { } -/* - * Make dates expressed in seconds-since-Jan-1-1970 easy to read. +/* + * Make dates expressed in seconds-since-Jan-1-1970 easy to read. * SIG records are required to be printed like this, by the Secure DNS RFC. */ char * p_secstodate (u_long secs) { - /* XXX nonreentrant */ static char output[15]; /* YYYYMMDDHHMMSS and null */ time_t clock = secs; struct tm *time; - -#ifdef HAVE_TIME_R - struct tm timebuf; - - time = gmtime_r(&clock, &timebuf); -#else + time = gmtime(&clock); -#endif time->tm_year += 1900; time->tm_mon += 1; sprintf(output, "%04d%02d%02d%02d%02d%02d", @@ -1056,3 +980,24 @@ p_secstodate (u_long secs) { time->tm_hour, time->tm_min, time->tm_sec); return (output); } + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef fp_resstat +__weak_reference(__fp_resstat, fp_resstat); +#undef p_query +__weak_reference(__p_query, p_query); +#undef p_fqnname +__weak_reference(__p_fqnname, p_fqnname); +#undef sym_ston +__weak_reference(__sym_ston, sym_ston); +#undef sym_ntos +__weak_reference(__sym_ntos, sym_ntos); +#undef sym_ntop +__weak_reference(__sym_ntop, sym_ntop); +#undef dn_count_labels +__weak_reference(__dn_count_labels, dn_count_labels); +#undef p_secstodate +__weak_reference(__p_secstodate, p_secstodate); diff --git a/newlib/libc/sys/linux/net/res_debug.h b/newlib/libc/sys/linux/net/res_debug.h deleted file mode 100644 index 4a0aa99ab..000000000 --- a/newlib/libc/sys/linux/net/res_debug.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#ifndef _RES_DEBUG_H_ -#define _RES_DEBUG_H_ - -#ifndef DEBUG -# define Dprint(cond, args) /*empty*/ -# define DprintQ(cond, args, query, size) /*empty*/ -# define Aerror(statp, file, string, error, address) /*empty*/ -# define Perror(statp, file, string, error) /*empty*/ -#else -# define Dprint(cond, args) if (cond) {fprintf args;} else {} -# define DprintQ(cond, args, query, size) if (cond) {\ - fprintf args;\ - res_pquery(statp, query, size, stdout);\ - } else {} -#endif - -#endif /* _RES_DEBUG_H_ */ diff --git a/newlib/libc/sys/linux/net/res_hconf.c b/newlib/libc/sys/linux/net/res_hconf.c deleted file mode 100644 index ad1594040..000000000 --- a/newlib/libc/sys/linux/net/res_hconf.c +++ /dev/null @@ -1,676 +0,0 @@ -/* Copyright (C) 1993, 1995-2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by David Mosberger (davidm@azstarnet.com). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This file provides a Linux /etc/host.conf compatible front end to - the various name resolvers (/etc/hosts, named, NIS server, etc.). - Though mostly compatibly, the following differences exist compared - to the original implementation: - - - new command "spoof" takes an arguments like RESOLV_SPOOF_CHECK - environment variable (i.e., `off', `nowarn', or `warn'). - - - line comments can appear anywhere (not just at the beginning of - a line) -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _IO_MTSAFE_IO -#include -#include "ifreq.h" -#include "res_hconf.h" -#include "local.h" -#ifdef USE_IN_LIBIO -# include -#endif - -#define _PATH_HOSTCONF "/etc/host.conf" - -/* Environment vars that all user to override default behavior: */ -#define ENV_HOSTCONF "RESOLV_HOST_CONF" -#define ENV_SERVORDER "RESOLV_SERV_ORDER" -#define ENV_SPOOF "RESOLV_SPOOF_CHECK" -#define ENV_TRIM_OVERR "RESOLV_OVERRIDE_TRIM_DOMAINS" -#define ENV_TRIM_ADD "RESOLV_ADD_TRIM_DOMAINS" -#define ENV_MULTI "RESOLV_MULTI" -#define ENV_REORDER "RESOLV_REORDER" - -static const char *arg_service_list (const char *, int, const char *, - unsigned int); -static const char *arg_trimdomain_list (const char *, int, const char *, - unsigned int); -static const char *arg_spoof (const char *, int, const char *, unsigned int); -static const char *arg_bool (const char *, int, const char *, unsigned int); - -static struct cmd -{ - const char *name; - const char *(*parse_args) (const char * filename, int line_num, - const char * args, unsigned int arg); - unsigned int arg; -} cmd[] = -{ - {"order", arg_service_list, 0}, - {"trim", arg_trimdomain_list, 0}, - {"spoof", arg_spoof, 0}, - {"multi", arg_bool, HCONF_FLAG_MULTI}, - {"nospoof", arg_bool, HCONF_FLAG_SPOOF}, - {"spoofalert", arg_bool, HCONF_FLAG_SPOOFALERT}, - {"reorder", arg_bool, HCONF_FLAG_REORDER} -}; - -/* Structure containing the state. */ -struct hconf _res_hconf; - -/* Skip white space. */ -static const char * -skip_ws (const char *str) -{ - while (isspace (*str)) ++str; - return str; -} - - -/* Skip until whitespace, comma, end of line, or comment character. */ -static const char * -skip_string (const char *str) -{ - while (*str && !isspace (*str) && *str != '#' && *str != ',') - ++str; - return str; -} - - -static const char * -arg_service_list (const char *fname, int line_num, const char *args, - unsigned int arg) -{ - enum Name_Service service; - const char *start; - size_t len; - size_t i; - static struct - { - const char * name; - enum Name_Service service; - } svcs[] = - { - {"bind", SERVICE_BIND}, - {"hosts", SERVICE_HOSTS}, - {"nis", SERVICE_NIS}, - }; - - do - { - start = args; - args = skip_string (args); - len = args - start; - - service = SERVICE_NONE; - for (i = 0; i < sizeof (svcs) / sizeof (svcs[0]); ++i) - { - if (strncasecmp (start, svcs[i].name, len) == 0 - && len == strlen (svcs[i].name)) - { - service = svcs[i].service; - break; - } - } - if (service == SERVICE_NONE) - { - char *buf; - - if (asprintf (&buf, - _("%s: line %d: expected service, found `%s'\n"), - fname, line_num, start) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - if (_res_hconf.num_services >= SERVICE_MAX) - { - char *buf; - - if (asprintf (&buf, _("\ -%s: line %d: cannot specify more than %d services"), - fname, line_num, SERVICE_MAX) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - _res_hconf.service[_res_hconf.num_services++] = service; - - args = skip_ws (args); - switch (*args) - { - case ',': - case ';': - case ':': - args = skip_ws (++args); - if (!*args || *args == '#') - { - char *buf; - - if (asprintf (&buf, _("\ -%s: line %d: list delimiter not followed by keyword"), - fname, line_num) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - default: - break; - } - } - while (*args && *args != '#'); - return args; -} - - -static const char * -arg_trimdomain_list (const char *fname, int line_num, const char *args, - unsigned int flag) -{ - const char * start; - size_t len; - - do - { - start = args; - args = skip_string (args); - len = args - start; - - if (_res_hconf.num_trimdomains >= TRIMDOMAINS_MAX) - { - char *buf; - - if (asprintf (&buf, _("\ -%s: line %d: cannot specify more than %d trim domains"), - fname, line_num, TRIMDOMAINS_MAX) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - _res_hconf.trimdomain[_res_hconf.num_trimdomains++] = - strndup (start, len); - args = skip_ws (args); - switch (*args) - { - case ',': case ';': case ':': - args = skip_ws (++args); - if (!*args || *args == '#') - { - char *buf; - - if (asprintf (&buf, _("\ -%s: line %d: list delimiter not followed by domain"), - fname, line_num) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - default: - break; - } - } - while (*args && *args != '#'); - return args; -} - - -static const char * -arg_spoof (const char *fname, int line_num, const char *args, unsigned flag) -{ - const char *start = args; - size_t len; - - args = skip_string (args); - len = args - start; - - if (len == 3 && strncasecmp (start, "off", len) == 0) - _res_hconf.flags &= ~(HCONF_FLAG_SPOOF | HCONF_FLAG_SPOOFALERT); - else - { - _res_hconf.flags |= (HCONF_FLAG_SPOOF | HCONF_FLAG_SPOOFALERT); - if ((len == 6 && strncasecmp (start, "nowarn", len) == 0) - || !(len == 4 && strncasecmp (start, "warn", len) == 0)) - _res_hconf.flags &= ~HCONF_FLAG_SPOOFALERT; - } - return args; -} - - -static const char * -arg_bool (const char *fname, int line_num, const char *args, unsigned flag) -{ - if (strncasecmp (args, "on", 2) == 0) - { - args += 2; - _res_hconf.flags |= flag; - } - else if (strncasecmp (args, "off", 3) == 0) - { - args += 3; - _res_hconf.flags &= ~flag; - } - else - { - char *buf; - - if (asprintf (&buf, - _("%s: line %d: expected `on' or `off', found `%s'\n"), - fname, line_num, args) < 0) - return 0; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return 0; - } - return args; -} - - -static void -parse_line (const char *fname, int line_num, const char *str) -{ - const char *start; - struct cmd *c = 0; - size_t len; - size_t i; - - str = skip_ws (str); - - /* skip line comment and empty lines: */ - if (*str == '\0' || *str == '#') return; - - start = str; - str = skip_string (str); - len = str - start; - - for (i = 0; i < sizeof (cmd) / sizeof (cmd[0]); ++i) - { - if (strncasecmp (start, cmd[i].name, len) == 0 - && strlen (cmd[i].name) == len) - { - c = &cmd[i]; - break; - } - } - if (c == NULL) - { - char *buf; - - if (asprintf (&buf, _("%s: line %d: bad command `%s'\n"), - fname, line_num, start) < 0) - return; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - return; - } - - /* process args: */ - str = skip_ws (str); - str = (*c->parse_args) (fname, line_num, str, c->arg); - if (!str) - return; - - /* rest of line must contain white space or comment only: */ - while (*str) - { - if (!isspace (*str)) { - if (*str != '#') - { - char *buf; - - if (asprintf (&buf, - _("%s: line %d: ignoring trailing garbage `%s'\n"), - fname, line_num, str) < 0) - break; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else -#endif - fputs (buf, stderr); - - free (buf); - } - break; - } - ++str; - } -} - - -static void -do_init (void) -{ - const char *hconf_name; - int line_num = 0; - char buf[256], *envval; - FILE *fp; - - memset (&_res_hconf, '\0', sizeof (_res_hconf)); - - hconf_name = getenv (ENV_HOSTCONF); - if (hconf_name == NULL) - hconf_name = _PATH_HOSTCONF; - - fp = fopen (hconf_name, "rc"); - if (!fp) - /* make up something reasonable: */ - _res_hconf.service[_res_hconf.num_services++] = SERVICE_BIND; - else - { - /* No threads using this stream. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - while (fgets (buf, sizeof (buf), fp)) - { - char *tmp; - ++line_num; - tmp = strchr (buf, '\n'); - if (tmp != NULL) - *tmp = '\0'; - parse_line (hconf_name, line_num, buf); - } - fclose (fp); - } - - envval = getenv (ENV_SERVORDER); - if (envval) - { - _res_hconf.num_services = 0; - arg_service_list (ENV_SERVORDER, 1, envval, 0); - } - - envval = getenv (ENV_SPOOF); - if (envval) - arg_spoof (ENV_SPOOF, 1, envval, 0); - - envval = getenv (ENV_MULTI); - if (envval) - arg_bool (ENV_MULTI, 1, envval, HCONF_FLAG_MULTI); - - envval = getenv (ENV_REORDER); - if (envval) - arg_bool (ENV_REORDER, 1, envval, HCONF_FLAG_REORDER); - - envval = getenv (ENV_TRIM_ADD); - if (envval) - arg_trimdomain_list (ENV_TRIM_ADD, 1, envval, 0); - - envval = getenv (ENV_TRIM_OVERR); - if (envval) - { - _res_hconf.num_trimdomains = 0; - arg_trimdomain_list (ENV_TRIM_OVERR, 1, envval, 0); - } - - _res_hconf.initialized = 1; -} - - -/* Initialize hconf datastructure by reading host.conf file and - environment variables. */ -void -_res_hconf_init (void) -{ - __libc_once_define (static, once); - - __libc_once (once, do_init); -} - - -/* List of known interfaces. */ -libc_freeres_ptr ( -static struct netaddr -{ - int addrtype; - union - { - struct - { - u_int32_t addr; - u_int32_t mask; - } ipv4; - } u; -} *ifaddrs); - -/* We need to protect the dynamic buffer handling. */ -__libc_lock_define_initialized (static, lock); - -/* Reorder addresses returned in a hostent such that the first address - is an address on the local subnet, if there is such an address. - Otherwise, nothing is changed. - - Note that this function currently only handles IPv4 addresses. */ - -void -_res_hconf_reorder_addrs (struct hostent *hp) -{ -#if defined SIOCGIFCONF && defined SIOCGIFNETMASK - int i, j; - /* Number of interfaces. */ - static int num_ifs = -1; - - /* Only reorder if we're supposed to. */ - if ((_res_hconf.flags & HCONF_FLAG_REORDER) == 0) - return; - - /* Can't deal with anything but IPv4 for now... */ - if (hp->h_addrtype != AF_INET) - return; - - if (num_ifs <= 0) - { - struct ifreq *ifr, *cur_ifr; - int sd, num, i; - /* Save errno. */ - int save = errno; - - /* Initialize interface table. */ - - num_ifs = 0; - - /* The SIOCGIFNETMASK ioctl will only work on an AF_INET socket. */ - sd = socket (AF_INET, SOCK_DGRAM, 0); - if (sd < 0) - return; - - /* Get lock. */ - __libc_lock_lock (lock); - - /* Get a list of interfaces. */ - __ifreq (&ifr, &num, sd); - if (!ifr) - goto cleanup; - - ifaddrs = malloc (num * sizeof (ifaddrs[0])); - if (!ifaddrs) - goto cleanup1; - - /* Copy usable interfaces in ifaddrs structure. */ - for (cur_ifr = ifr, i = 0; i < num; cur_ifr = __if_nextreq (cur_ifr), ++i) - { - if (cur_ifr->ifr_addr.sa_family != AF_INET) - continue; - - ifaddrs[num_ifs].addrtype = AF_INET; - ifaddrs[num_ifs].u.ipv4.addr = - ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr; - - if (ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0) - continue; - - ifaddrs[num_ifs].u.ipv4.mask = - ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr; - - /* Now we're committed to this entry. */ - ++num_ifs; - } - /* Just keep enough memory to hold all the interfaces we want. */ - ifaddrs = realloc (ifaddrs, num_ifs * sizeof (ifaddrs[0])); - assert (ifaddrs != NULL); - - cleanup1: - __if_freereq (ifr, num); - - cleanup: - /* Release lock, preserve error value, and close socket. */ - save = errno; - __libc_lock_unlock (lock); - close (sd); - } - - if (num_ifs == 0) - return; - - /* Find an address for which we have a direct connection. */ - for (i = 0; hp->h_addr_list[i]; ++i) - { - struct in_addr *haddr = (struct in_addr *) hp->h_addr_list[i]; - - for (j = 0; j < num_ifs; ++j) - { - u_int32_t if_addr = ifaddrs[j].u.ipv4.addr; - u_int32_t if_netmask = ifaddrs[j].u.ipv4.mask; - - if (((haddr->s_addr ^ if_addr) & if_netmask) == 0) - { - void *tmp; - - tmp = hp->h_addr_list[i]; - hp->h_addr_list[i] = hp->h_addr_list[0]; - hp->h_addr_list[0] = tmp; - return; - } - } - } -#endif /* defined(SIOCGIFCONF) && ... */ -} - - -/* If HOSTNAME has a postfix matching any of the trimdomains, trim away - that postfix. Notice that HOSTNAME is modified inplace. Also, the - original code applied all trimdomains in order, meaning that the - same domainname could be trimmed multiple times. I believe this - was unintentional. */ -void -_res_hconf_trim_domain (char *hostname) -{ - size_t hostname_len, trim_len; - int i; - - hostname_len = strlen (hostname); - - for (i = 0; i < _res_hconf.num_trimdomains; ++i) - { - const char *trim = _res_hconf.trimdomain[i]; - - trim_len = strlen (trim); - if (hostname_len > trim_len - && strcasecmp (&hostname[hostname_len - trim_len], trim) == 0) - { - hostname[hostname_len - trim_len] = '\0'; - break; - } - } -} - - -/* Trim all hostnames/aliases in HP according to the trimdomain list. - Notice that HP is modified inplace! */ -void -_res_hconf_trim_domains (struct hostent *hp) -{ - int i; - - if (_res_hconf.num_trimdomains == 0) - return; - - _res_hconf_trim_domain (hp->h_name); - for (i = 0; hp->h_aliases[i]; ++i) - _res_hconf_trim_domain (hp->h_aliases[i]); -} diff --git a/newlib/libc/sys/linux/net/res_hconf.h b/newlib/libc/sys/linux/net/res_hconf.h deleted file mode 100644 index 77eeca4de..000000000 --- a/newlib/libc/sys/linux/net/res_hconf.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by David Mosberger (davidm@azstarnet.com). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _RES_HCONF_H_ -#define _RES_HCONF_H_ - -#include - -#define TRIMDOMAINS_MAX 4 - -enum Name_Service -{ - SERVICE_NONE = 0, - SERVICE_BIND, SERVICE_HOSTS, SERVICE_NIS, - SERVICE_MAX -}; - -struct hconf -{ - int initialized; - int num_services; - enum Name_Service service[SERVICE_MAX]; - int num_trimdomains; - const char *trimdomain[TRIMDOMAINS_MAX]; - unsigned int flags; -# define HCONF_FLAG_INITED (1 << 0) /* initialized? */ -# define HCONF_FLAG_SPOOF (1 << 1) /* refuse spoofed addresses */ -# define HCONF_FLAG_SPOOFALERT (1 << 2) /* syslog warning of spoofed */ -# define HCONF_FLAG_REORDER (1 << 3) /* list best address first */ -# define HCONF_FLAG_MULTI (1 << 4) /* see comments for gethtbyname() */ -}; -extern struct hconf _res_hconf; - -extern void _res_hconf_init (void); -extern void _res_hconf_trim_domain (char *domain); -extern void _res_hconf_trim_domains (struct hostent *hp); -extern void _res_hconf_reorder_addrs (struct hostent *hp); - -#endif /* _RES_HCONF_H_ */ diff --git a/newlib/libc/sys/linux/net/res_init.c b/newlib/libc/sys/linux/net/res_init.c index 81b06e710..21f2696cd 100644 --- a/newlib/libc/sys/linux/net/res_init.c +++ b/newlib/libc/sys/linux/net/res_init.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985, 1989, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -48,7 +52,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,56 +69,53 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $"; +static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; +static char orig_rcsid[] = "From: Id: res_init.c,v 8.7 1996/11/18 09:10:04 vixie Exp $"; #endif /* LIBC_SCCS and not lint */ - +#include #include +#include + #include #include #include - #include #include #include - #include +#include #include -#include #include #include #include +#include -#include -#include "local.h" -#include - -/* Options. Should all be left alone. */ -#define RESOLVSORT -#define RFC1535 -/* #undef DEBUG */ +#include "res_config.h" -static void res_setoptions (res_state, const char *, const char *) - internal_function; +static void res_setoptions(char *, char *); #ifdef RESOLVSORT -static const char sort_mask_chars[] = "/&"; -#define ISSORTMASK(ch) (strchr(sort_mask_chars, ch) != NULL) -static u_int32_t net_mask (struct in_addr) __THROW; +static const char sort_mask[] = "/&"; +#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) +static u_int32_t net_mask(struct in_addr); #endif -#if !defined(isascii) /* XXX - could be a function */ +#if !defined(isascii) /* XXX - could be a function */ # define isascii(c) (!(c & 0200)) #endif -#ifdef _LIBC -unsigned long long int __res_initstamp attribute_hidden; -#endif - /* * Resolver state default settings. */ +struct __res_state _res +# if defined(__BIND_RES_TEXT) + = { RES_TIMEOUT, } /* Motorola, et al. */ +# endif + ; + +struct __res_state_ext _res_ext; + /* * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to @@ -125,7 +126,7 @@ unsigned long long int __res_initstamp attribute_hidden; * since it was noted that INADDR_ANY actually meant ``the first interface * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, * it had to be "up" in order for you to reach your own name server. It - * was later decided that since the recommended practice is to always + * was later decided that since the recommended practice is to always * install local static routes through 127.0.0.1 for all your network * interfaces, that we could solve this problem without a code change. * @@ -137,26 +138,13 @@ unsigned long long int __res_initstamp attribute_hidden; * Return 0 if completes successfully, -1 on error */ int -res_ninit(res_state statp) { - extern int __res_vinit(res_state, int); - - return (__res_vinit(statp, 0)); -} -#ifdef _LIBC -libc_hidden_def (__res_ninit) -#endif - -/* This function has to be reachable by res_data.c but not publically. */ -int -__res_vinit(res_state statp, int preinit) { - register FILE *fp; - register char *cp, **pp; - register int n; - char buf[BUFSIZ]; +res_init() +{ + FILE *fp; + char *cp, **pp; + int n; + char buf[MAXDNAME]; int nserv = 0; /* number of nameserver records read from file */ -#ifdef _LIBC - int nservall = 0; /* number of NS records read, nserv IPv4 only */ -#endif int haveenv = 0; int havesearch = 0; #ifdef RESOLVSORT @@ -166,45 +154,59 @@ __res_vinit(res_state statp, int preinit) { #ifndef RFC1535 int dots; #endif -#ifdef _LIBC - statp->_u._ext.initstamp = __res_initstamp; -#endif - - if (!preinit) { - statp->retrans = RES_TIMEOUT; - statp->retry = RES_DFLRETRY; - statp->options = RES_DEFAULT; - statp->id = res_randomid(); - } + int sin_len; + + /* + * These three fields used to be statically initialized. This made + * it hard to use this code in a shared library. It is necessary, + * now that we're doing dynamic initialization here, that we preserve + * the old semantics: if an application modifies one of these three + * fields of _res before res_init() is called, res_init() will not + * alter them. Of course, if an application is setting them to + * _zero_ before calling res_init(), hoping to override what used + * to be the static default, we can't detect it and unexpected results + * will follow. Zero for any of these fields would make no sense, + * so one can safely assume that the applications were already getting + * unexpected results. + * + * _res.options is tricky since some apps were known to diddle the bits + * before res_init() was first called. We can't replicate that semantic + * with dynamic initialization (they may have turned bits off that are + * set in RES_DEFAULT). Our solution is to declare such applications + * "broken". They could fool us by setting RES_INIT but none do (yet). + */ + if (!_res.retrans) + _res.retrans = RES_TIMEOUT; + if (!_res.retry) + _res.retry = 4; + if (!(_res.options & RES_INIT)) + _res.options = RES_DEFAULT; + + /* + * This one used to initialize implicitly to zero, so unless the app + * has set it to something in particular, we can randomize it now. + */ + if (!_res.id) + _res.id = res_randomid(); #ifdef USELOOPBACK - statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); + _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); #else - statp->nsaddr.sin_addr.s_addr = INADDR_ANY; -#endif - statp->nsaddr.sin_family = AF_INET; - statp->nsaddr.sin_port = htons(NAMESERVER_PORT); - statp->nscount = 1; - statp->ndots = 1; - statp->pfcode = 0; - statp->_vcsock = -1; - statp->_flags = 0; - statp->qhook = NULL; - statp->rhook = NULL; - statp->_u._ext.nsinit = 0; - statp->_u._ext.nscount = 0; -#ifdef _LIBC - statp->_u._ext.nscount6 = 0; - for (n = 0; n < MAXNS; n++) { - statp->_u._ext.nsaddrs[n] = NULL; - statp->_u._ext.nsmap[n] = MAXNS; - } + _res.nsaddr.sin_addr.s_addr = INADDR_ANY; #endif + _res.nsaddr.sin_family = AF_INET; + _res.nsaddr.sin_port = htons(NAMESERVER_PORT); + sin_len = sizeof(struct sockaddr_in); + if (sizeof(_res_ext.nsaddr) >= sin_len) + memcpy(&_res_ext.nsaddr, &_res.nsaddr, sin_len); + _res.nscount = 1; + _res.ndots = 1; + _res.pfcode = 0; /* Allow user to override the local domain definition */ - if ((cp = getenv("LOCALDOMAIN")) != NULL) { - (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); - statp->defdname[sizeof(statp->defdname) - 1] = '\0'; + if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { + (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; haveenv++; /* @@ -214,10 +216,10 @@ __res_vinit(res_state statp, int preinit) { * one that they want to use as an individual (even more * important now that the rfc1535 stuff restricts searches) */ - cp = statp->defdname; - pp = statp->dnsrch; + cp = _res.defdname; + pp = _res.dnsrch; *pp++ = cp; - for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { + for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { if (*cp == '\n') /* silly backwards compat */ break; else if (*cp == ' ' || *cp == '\t') { @@ -241,9 +243,7 @@ __res_vinit(res_state statp, int preinit) { (line[sizeof(name) - 1] == ' ' || \ line[sizeof(name) - 1] == '\t')) - if ((fp = fopen(_PATH_RESCONF, "rc")) != NULL) { - /* No threads use this stream. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); + if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { /* read the config file */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ @@ -258,9 +258,9 @@ __res_vinit(res_state statp, int preinit) { cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); - statp->defdname[sizeof(statp->defdname) - 1] = '\0'; - if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL) + strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; continue; @@ -274,18 +274,18 @@ __res_vinit(res_state statp, int preinit) { cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); - statp->defdname[sizeof(statp->defdname) - 1] = '\0'; - if ((cp = strchr(statp->defdname, '\n')) != NULL) + strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* * Set search list to be blank-separated strings * on rest of line. */ - cp = statp->defdname; - pp = statp->dnsrch; + cp = _res.defdname; + pp = _res.dnsrch; *pp++ = cp; - for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { + for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { if (*cp == ' ' || *cp == '\t') { *cp = 0; n = 1; @@ -303,53 +303,54 @@ __res_vinit(res_state statp, int preinit) { continue; } /* read nameservers to query */ -#ifdef _LIBC - if (MATCH(buf, "nameserver") && nservall < MAXNS) { -#else if (MATCH(buf, "nameserver") && nserv < MAXNS) { -#endif - struct in_addr a; + char *q; + struct addrinfo hints, *res; + char pbuf[NI_MAXSERV]; cp = buf + sizeof("nameserver") - 1; while (*cp == ' ' || *cp == '\t') cp++; - if ((*cp != '\0') && (*cp != '\n') - && inet_aton(cp, &a)) { - statp->nsaddr_list[nserv].sin_addr = a; - statp->nsaddr_list[nserv].sin_family = AF_INET; - statp->nsaddr_list[nserv].sin_port = - htons(NAMESERVER_PORT); + if ((*cp == '\0') || (*cp == '\n')) + continue; + for (q = cp; *q; q++) { + if (isspace(*q)) { + *q = '\0'; + break; + } + } + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_NUMERICHOST; + hints.ai_socktype = SOCK_DGRAM; + snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT); + if (getaddrinfo(cp, pbuf, &hints, &res) == 0 && + res->ai_next == NULL) { + if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) { + memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr, + res->ai_addrlen); + } else { + memset(&_res_ext.nsaddr_list[nserv], 0, + sizeof(_res_ext.nsaddr_list[nserv])); + } + if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) { + memcpy(&_res.nsaddr_list[nserv], res->ai_addr, + res->ai_addrlen); + } else { + memset(&_res.nsaddr_list[nserv], 0, + sizeof(_res.nsaddr_list[nserv])); + } nserv++; -#ifdef _LIBC - nservall++; - } else { - struct in6_addr a6; - char *el; - - if ((el = strchr(cp, '\n')) != NULL) - *el = '\0'; - if ((*cp != '\0') && - (inet_pton(AF_INET6, cp, &a6) > 0)) { - struct sockaddr_in6 *sa6; - - sa6 = malloc(sizeof(*sa6)); - if (sa6 != NULL) { - sa6->sin6_addr = a6; - sa6->sin6_family = AF_INET6; - sa6->sin6_port = htons(NAMESERVER_PORT); - statp->_u._ext.nsaddrs[nservall] = sa6; - statp->_u._ext.nssocks[nservall] = -1; - statp->_u._ext.nsmap[nservall] = MAXNS + 1; - nservall++; - } - } -#endif } + if (res) + freeaddrinfo(res); continue; } #ifdef RESOLVSORT if (MATCH(buf, "sortlist")) { struct in_addr a; + struct in6_addr a6; + int m, i; + u_char *u; cp = buf + sizeof("sortlist") - 1; while (nsort < MAXRESOLVSORT) { @@ -364,7 +365,7 @@ __res_vinit(res_state statp, int preinit) { n = *cp; *cp = 0; if (inet_aton(net, &a)) { - statp->sort_list[nsort].addr = a; + _res.sort_list[nsort].addr = a; if (ISSORTMASK(n)) { *cp++ = n; net = cp; @@ -374,15 +375,65 @@ __res_vinit(res_state statp, int preinit) { n = *cp; *cp = 0; if (inet_aton(net, &a)) { - statp->sort_list[nsort].mask = a.s_addr; + _res.sort_list[nsort].mask = a.s_addr; } else { - statp->sort_list[nsort].mask = - net_mask(statp->sort_list[nsort].addr); + _res.sort_list[nsort].mask = + net_mask(_res.sort_list[nsort].addr); } } else { - statp->sort_list[nsort].mask = - net_mask(statp->sort_list[nsort].addr); + _res.sort_list[nsort].mask = + net_mask(_res.sort_list[nsort].addr); + } + _res_ext.sort_list[nsort].af = AF_INET; + _res_ext.sort_list[nsort].addr.ina = + _res.sort_list[nsort].addr; + _res_ext.sort_list[nsort].mask.ina.s_addr = + _res.sort_list[nsort].mask; + nsort++; + } + else if (inet_pton(AF_INET6, net, &a6) == 1) { + + _res_ext.sort_list[nsort].af = AF_INET6; + _res_ext.sort_list[nsort].addr.in6a = a6; + u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a; + *cp++ = n; + net = cp; + while (*cp && *cp != ';' && + isascii(*cp) && !isspace(*cp)) + cp++; + m = n; + n = *cp; + *cp = 0; + switch (m) { + case '/': + m = atoi(net); + break; + case '&': + if (inet_pton(AF_INET6, net, u) == 1) { + m = -1; + break; + } + /*FALLTHROUGH*/ + default: + m = sizeof(struct in6_addr) * NBBY; + break; } + if (m >= 0) { + for (i = 0; i < sizeof(struct in6_addr); i++) { + if (m <= 0) { + *u = 0; + } else { + m -= NBBY; + *u = (u_char)~0; + if (m < 0) + *u <<= -m; + } + u++; + } + } + _res.sort_list[nsort].addr.s_addr = + (u_int32_t)0xffffffff; + _res.sort_list[nsort].mask = (u_int32_t)0xffffffff; nsort++; } *cp = n; @@ -391,50 +442,46 @@ __res_vinit(res_state statp, int preinit) { } #endif if (MATCH(buf, "options")) { - res_setoptions(statp, buf + sizeof("options") - 1, "conf"); + res_setoptions(buf + sizeof("options") - 1, "conf"); continue; } } - if (nserv > 1) - statp->nscount = nserv; -#ifdef _LIBC - if (nservall - nserv > 0) - statp->_u._ext.nscount6 = nservall - nserv; -#endif + if (nserv > 1) + _res.nscount = nserv; #ifdef RESOLVSORT - statp->nsort = nsort; + _res.nsort = nsort; #endif (void) fclose(fp); } - if (statp->defdname[0] == 0 && - __gethostname(buf, sizeof(statp->defdname) - 1) == 0 && + if (_res.defdname[0] == 0 && + gethostname(buf, sizeof(_res.defdname) - 1) == 0 && (cp = strchr(buf, '.')) != NULL) - strcpy(statp->defdname, cp + 1); + strcpy(_res.defdname, cp + 1); /* find components of local domain that might be searched */ if (havesearch == 0) { - pp = statp->dnsrch; - *pp++ = statp->defdname; + pp = _res.dnsrch; + *pp++ = _res.defdname; *pp = NULL; #ifndef RFC1535 dots = 0; - for (cp = statp->defdname; *cp; cp++) + for (cp = _res.defdname; *cp; cp++) dots += (*cp == '.'); - cp = statp->defdname; - while (pp < statp->dnsrch + MAXDFLSRCH) { + cp = _res.defdname; + while (pp < _res.dnsrch + MAXDFLSRCH) { if (dots < LOCALDOMAINPARTS) break; - cp = memchr(cp, '.') + 1; /* we know there is one */ + cp = strchr(cp, '.') + 1; /* we know there is one */ *pp++ = cp; dots--; } *pp = NULL; #ifdef DEBUG - if (statp->options & RES_DEBUG) { + if (_res.options & RES_DEBUG) { printf(";; res_init()... default dnsrch list:\n"); - for (pp = statp->dnsrch; *pp; pp++) + for (pp = _res.dnsrch; *pp; pp++) printf(";;\t%s\n", *pp); printf(";;\t..END..\n"); } @@ -442,20 +489,23 @@ __res_vinit(res_state statp, int preinit) { #endif /* !RFC1535 */ } - if ((cp = getenv("RES_OPTIONS")) != NULL) - res_setoptions(statp, cp, "env"); - statp->options |= RES_INIT; + if (issetugid()) + _res.options |= RES_NOALIASES; + else if ((cp = getenv("RES_OPTIONS")) != NULL) + res_setoptions(cp, "env"); + _res.options |= RES_INIT; return (0); } static void -internal_function -res_setoptions(res_state statp, const char *options, const char *source) { - const char *cp = options; +res_setoptions(options, source) + char *options, *source; +{ + char *cp = options; int i; #ifdef DEBUG - if (statp->options & RES_DEBUG) + if (_res.options & RES_DEBUG) printf(";; res_setoptions(\"%s\", \"%s\")...\n", options, source); #endif @@ -467,50 +517,32 @@ res_setoptions(res_state statp, const char *options, const char *source) { if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { i = atoi(cp + sizeof("ndots:") - 1); if (i <= RES_MAXNDOTS) - statp->ndots = i; + _res.ndots = i; else - statp->ndots = RES_MAXNDOTS; + _res.ndots = RES_MAXNDOTS; #ifdef DEBUG - if (statp->options & RES_DEBUG) - printf(";;\tndots=%d\n", statp->ndots); + if (_res.options & RES_DEBUG) + printf(";;\tndots=%d\n", _res.ndots); #endif - } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) { - i = atoi(cp + sizeof("timeout:") - 1); - if (i <= RES_MAXRETRANS) - statp->retrans = i; - else - statp->retrans = RES_MAXRETRANS; - } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ - i = atoi(cp + sizeof("attempts:") - 1); - if (i <= RES_MAXRETRY) - statp->retry = i; - else - statp->retry = RES_MAXRETRY; } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { #ifdef DEBUG - if (!(statp->options & RES_DEBUG)) { + if (!(_res.options & RES_DEBUG)) { printf(";; res_setoptions(\"%s\", \"%s\")..\n", options, source); - statp->options |= RES_DEBUG; + _res.options |= RES_DEBUG; } printf(";;\tdebug\n"); #endif } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { - statp->options |= RES_USE_INET6; - } else if (!strncmp(cp, "ip6-bytestring", - sizeof("ip6-bytestring") - 1)) { - statp->options |= RES_USEBSTRING; - } else if (!strncmp(cp, "no-ip6-dotint", - sizeof("no-ip6-dotint") - 1)) { - statp->options |= RES_NOIP6DOTINT; - } else if (!strncmp(cp, "ip6-dotint", - sizeof("ip6-dotint") - 1)) { - statp->options &= ~RES_NOIP6DOTINT; - } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) { - statp->options |= RES_ROTATE; - } else if (!strncmp(cp, "no-check-names", - sizeof("no-check-names") - 1)) { - statp->options |= RES_NOCHECKNAME; + _res.options |= RES_USE_INET6; + } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) { + _res.options |= RES_INSECURE1; + } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) { + _res.options |= RES_INSECURE2; + } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) { + _res.options |= RES_NOTLDQUERY; + } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { + _res.options |= RES_USE_EDNS0; } else { /* XXX - print a warning here? */ } @@ -526,7 +558,7 @@ static u_int32_t net_mask(in) /* XXX - should really use system's version of this */ struct in_addr in; { - register u_int32_t i = ntohl(in.s_addr); + u_int32_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (htonl(IN_CLASSA_NET)); @@ -537,72 +569,17 @@ net_mask(in) /* XXX - should really use system's version of this */ #endif u_int -res_randomid(void) { +res_randomid() +{ struct timeval now; gettimeofday(&now, NULL); return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); } -#ifdef _LIBC -libc_hidden_def (__res_randomid) -#endif - /* - * This routine is for closing the socket if a virtual circuit is used and - * the program wants to close it. This provides support for endhostent() - * which expects to close the socket. - * - * This routine is not expected to be user visible. + * Weak aliases for applications that use certain private entry points, + * and fail to include . */ -void -res_nclose(res_state statp) { - int ns; - - if (statp->_vcsock >= 0) { - close_not_cancel_no_status(statp->_vcsock); - statp->_vcsock = -1; - statp->_flags &= ~(RES_F_VC | RES_F_CONN); - } -#ifdef _LIBC - for (ns = 0; ns < MAXNS; ns++) -#else - for (ns = 0; ns < statp->_u._ext.nscount; ns++) -#endif - if (statp->_u._ext.nsaddrs[ns] - && statp->_u._ext.nssocks[ns] != -1) { - close_not_cancel_no_status(statp->_u._ext.nssocks[ns]); - statp->_u._ext.nssocks[ns] = -1; - } - statp->_u._ext.nsinit = 0; -} -#ifdef _LIBC -libc_hidden_def (__res_nclose) -#endif - -#ifdef _LIBC -# ifdef _LIBC_REENTRANT -/* This is called when a thread is exiting to free resources held in _res. */ -static void __attribute__ ((section ("__libc_thread_freeres_fn"))) -res_thread_freeres (void) -{ - if (_res.nscount == 0) - /* Never called res_ninit. */ - return; - - __res_nclose (&_res); /* Close any VC sockets. */ - - for (int ns = 0; ns < MAXNS; ns++) - if (_res._u._ext.nsaddrs[ns] != NULL) - { - free (_res._u._ext.nsaddrs[ns]); - _res._u._ext.nsaddrs[ns] = NULL; - } - - /* Make sure we do a full re-initialization the next time. */ - _res.options = 0; -} -text_set_element (__libc_thread_subfreeres, res_thread_freeres); -text_set_element (__libc_subfreeres, res_thread_freeres); -# endif -#endif +#undef res_init +__weak_reference(__res_init, res_init); diff --git a/newlib/libc/sys/linux/net/res_libc.c b/newlib/libc/sys/linux/net/res_libc.c deleted file mode 100644 index 739a51f58..000000000 --- a/newlib/libc/sys/linux/net/res_libc.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1995-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libc-symbols.h" - - -/* The following bit is copied from res_data.c (where it is #ifdef'ed - out) since res_init() should go into libc.so but the rest of that - file should not. */ - -extern unsigned long long int __res_initstamp attribute_hidden; -/* We have atomic increment operations on 64-bit platforms. */ -#if __WORDSIZE == 64 -# define atomicinclock(lock) (void) 0 -# define atomicincunlock(lock) (void) 0 -# define atomicinc(var) atomic_increment (&(var)) -#else -__libc_lock_define_initialized (static, lock); -# define atomicinclock(lock) __libc_lock_lock (lock) -# define atomicincunlock(lock) __libc_lock_unlock (lock) -# define atomicinc(var) ++var -#endif - -int -res_init(void) { - extern int __res_vinit(res_state, int); - - /* - * These three fields used to be statically initialized. This made - * it hard to use this code in a shared library. It is necessary, - * now that we're doing dynamic initialization here, that we preserve - * the old semantics: if an application modifies one of these three - * fields of _res before res_init() is called, res_init() will not - * alter them. Of course, if an application is setting them to - * _zero_ before calling res_init(), hoping to override what used - * to be the static default, we can't detect it and unexpected results - * will follow. Zero for any of these fields would make no sense, - * so one can safely assume that the applications were already getting - * unexpected results. - * - * _res.options is tricky since some apps were known to diddle the bits - * before res_init() was first called. We can't replicate that semantic - * with dynamic initialization (they may have turned bits off that are - * set in RES_DEFAULT). Our solution is to declare such applications - * "broken". They could fool us by setting RES_INIT but none do (yet). - */ - if (!_res.retrans) - _res.retrans = RES_TIMEOUT; - if (!_res.retry) - _res.retry = 4; - if (!(_res.options & RES_INIT)) - _res.options = RES_DEFAULT; - else if (_res.nscount > 0) { - __res_nclose (&_res); /* Close any VC sockets. */ - int ns; - for (ns = 0; ns < MAXNS; ns++) { - free (_res._u._ext.nsaddrs[ns]); - _res._u._ext.nsaddrs[ns] = NULL; - } - } - - /* - * This one used to initialize implicitly to zero, so unless the app - * has set it to something in particular, we can randomize it now. - */ - if (!_res.id) - _res.id = res_randomid(); - - atomicinclock (lock); - /* Request all threads to re-initialize their resolver states, - resolv.conf might have changed. */ - atomicinc (__res_initstamp); - atomicincunlock (lock); - - return (__res_vinit(&_res, 1)); -} - -/* Initialize resp if RES_INIT is not yet set or if res_init in some other - thread requested re-initializing. */ -int -__res_maybe_init (res_state resp, int preinit) -{ - if (resp->options & RES_INIT) { - if (__res_initstamp != resp->_u._ext.initstamp) { - if (resp->nscount > 0) { - __res_nclose (resp); - int ns; - for (ns = 0; ns < MAXNS; ns++) { - free (resp->_u._ext.nsaddrs[ns]); - resp->_u._ext.nsaddrs[ns] = NULL; - } - return __res_vinit (resp, 1); - } - } - return 0; - } else if (preinit) { - if (!resp->retrans) - resp->retrans = RES_TIMEOUT; - if (!resp->retry) - resp->retry = 4; - resp->options = RES_DEFAULT; - if (!resp->id) - resp->id = res_randomid (); - return __res_vinit (resp, 1); - } else - return __res_ninit (resp); -} -libc_hidden_def (__res_maybe_init) - -/* This needs to be after the use of _res in res_init, above. */ -#undef _res - -/* The resolver state for use by single-threaded programs. - This differs from plain `struct __res_state _res;' in that it doesn't - create a common definition, but a plain symbol that resides in .bss, - which can have an alias. */ -struct __res_state _res __attribute__((section (".bss"))); - -#define USE___THREAD 1 - -#if USE___THREAD -#undef __resp -__thread struct __res_state *__resp = &_res; -extern __thread struct __res_state *__libc_resp - __attribute__ ((alias ("__resp"))) attribute_hidden; -#endif - -/* We declare this with compat_symbol so that it's not - visible at link time. Programs must use the accessor functions. */ -#if defined HAVE_ELF && defined SHARED && defined DO_VERSIONING -# include -compat_symbol (libc, _res, _res, GLIBC_2_0); -#endif - -#include - -#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2) -# undef res_init -extern int __res_init_weak (void); -weak_extern (__res_init_weak); -strong_alias (__res_init, __res_init_weak); -compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0); -#endif diff --git a/newlib/libc/sys/linux/net/res_mkquery.c b/newlib/libc/sys/linux/net/res_mkquery.c index fa1ccd87f..0c6cca9c4 100644 --- a/newlib/libc/sys/linux/net/res_mkquery.c +++ b/newlib/libc/sys/linux/net/res_mkquery.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -48,7 +52,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,9 +69,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$BINDId: res_mkquery.c,v 8.12 1999/10/13 16:39:40 vixie Exp $"; +static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; +static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $"; #endif /* LIBC_SCCS and not lint */ +#include +#include +#include #include #include @@ -77,43 +84,37 @@ static const char rcsid[] = "$BINDId: res_mkquery.c,v 8.12 1999/10/13 16:39:40 v #include #include #include -#include -#include "local.h" - -/* Options. Leave them on. */ -/* #define DEBUG */ -#ifdef _LIBC -# include -# if HP_TIMING_AVAIL -# define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; } -# endif -#endif +#include "res_config.h" /* * Form all types of queries. * Returns the size of the result or -1. */ int -res_nmkquery(res_state statp, - int op, /* opcode of query */ - const char *dname, /* domain name */ - int class, int type, /* class and type of query */ - const u_char *data, /* resource record data */ - int datalen, /* length of data */ - const u_char *newrr_in, /* new rr for modify or append */ - u_char *buf, /* buffer to put query */ - int buflen) /* size of buffer */ +res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) + int op; /* opcode of query */ + const char *dname; /* domain name */ + int class, type; /* class and type of query */ + const u_char *data; /* resource record data */ + int datalen; /* length of data */ + const u_char *newrr_in; /* new rr for modify or append */ + u_char *buf; /* buffer to put query */ + int buflen; /* size of buffer */ { - register HEADER *hp; - register u_char *cp; - register int n; + HEADER *hp; + u_char *cp; + int n; u_char *dnptrs[20], **dpp, **lastdnptr; + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } #ifdef DEBUG - if (statp->options & RES_DEBUG) - printf(";; res_nmkquery(%s, %s, %s, %s)\n", - _res_opcodes[op], dname, p_class(class), p_type(type)); + if (_res.options & RES_DEBUG) + printf(";; res_mkquery(%d, %s, %d, %d)\n", + op, dname, class, type); #endif /* * Initialize header fields. @@ -122,30 +123,9 @@ res_nmkquery(res_state statp, return (-1); memset(buf, 0, HFIXEDSZ); hp = (HEADER *) buf; - /* We randomize the IDs every time. The old code just - incremented by one after the initial randomization which - still predictable if the application does multiple - requests. */ -#if 0 - hp->id = htons(++statp->id); -#else - hp->id = htons(statp->id); - int randombits; - do - { -#ifdef RANDOM_BITS - RANDOM_BITS (randombits); -#else - struct timeval tv; - gettimeofday (&tv, NULL); - randombits = (tv.tv_sec << 8) ^ tv.tv_usec; -#endif - } - while ((randombits & 0xffff) == 0); - statp->id = (statp->id + randombits) & 0xffff; -#endif + hp->id = htons(++_res.id); hp->opcode = op; - hp->rd = (statp->options & RES_RECURSE) != 0; + hp->rd = (_res.options & RES_RECURSE) != 0; hp->rcode = NOERROR; cp = buf + HFIXEDSZ; buflen -= HFIXEDSZ; @@ -219,4 +199,47 @@ res_nmkquery(res_state statp, } return (cp - buf); } -libresolv_hidden_def (res_nmkquery) + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef res_mkquery +__weak_reference(__res_mkquery, res_mkquery); + +/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */ +int +res_opt(n0, buf, buflen, anslen) + int n0; + u_char *buf; /* buffer to put query */ + int buflen; /* size of buffer */ + int anslen; /* answer buffer length */ +{ + HEADER *hp; + u_char *cp; + + hp = (HEADER *) buf; + cp = buf + n0; + buflen -= n0; + + if (buflen < 1 + RRFIXEDSZ) + return -1; + + *cp++ = 0; /* "." */ + buflen--; + + __putshort(T_OPT, cp); /* TYPE */ + cp += INT16SZ; + __putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */ + cp += INT16SZ; + *cp++ = NOERROR; /* extended RCODE */ + *cp++ = 0; /* EDNS version */ + __putshort(0, cp); /* MBZ */ + cp += INT16SZ; + __putshort(0, cp); /* RDLEN */ + cp += INT16SZ; + hp->arcount = htons(ntohs(hp->arcount) + 1); + buflen -= RRFIXEDSZ; + + return cp - buf; +} diff --git a/newlib/libc/sys/linux/net/res_mkupdate.c b/newlib/libc/sys/linux/net/res_mkupdate.c new file mode 100644 index 000000000..4e21fe8cf --- /dev/null +++ b/newlib/libc/sys/linux/net/res_mkupdate.c @@ -0,0 +1,412 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Based on the Dynamic DNS reference implementation by Viraj Bais + * + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "res_config.h" + +static int getnum_str(u_char **, u_char *); +static int getword_str(char *, int, u_char **, u_char *); + +#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2); + +/* + * Form update packets. + * Returns the size of the resulting packet if no error + * On error, + * returns -1 if error in reading a word/number in rdata + * portion for update packets + * -2 if length of buffer passed is insufficient + * -3 if zone section is not the first section in + * the linked list, or section order has a problem + * -4 on a number overflow + * -5 unknown operation or no records + */ +int +res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { + ns_updrec *rrecp_start = rrecp_in; + HEADER *hp; + u_char *cp, *sp1, *sp2, *startp, *endp; + int n, i, soanum, multiline; + ns_updrec *rrecp; + struct in_addr ina; + char buf2[MAXDNAME]; + int section, numrrs = 0, counts[ns_s_max]; + u_int16_t rtype, rclass; + u_int32_t n1, rttl; + u_char *dnptrs[20], **dpp, **lastdnptr; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } + + /* + * Initialize header fields. + */ + if ((buf == NULL) || (buflen < HFIXEDSZ)) + return (-1); + memset(buf, 0, HFIXEDSZ); + hp = (HEADER *) buf; + hp->id = htons(++_res.id); + hp->opcode = ns_o_update; + hp->rcode = NOERROR; + sp1 = buf + 2*INT16SZ; /* save pointer to zocount */ + cp = buf + HFIXEDSZ; + buflen -= HFIXEDSZ; + dpp = dnptrs; + *dpp++ = buf; + *dpp++ = NULL; + lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + + if (rrecp_start == NULL) + return (-5); + else if (rrecp_start->r_section != S_ZONE) + return (-3); + + memset(counts, 0, sizeof counts); + for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) { + numrrs++; + section = rrecp->r_section; + if (section < 0 || section >= ns_s_max) + return (-1); + counts[section]++; + for (i = section + 1; i < ns_s_max; i++) + if (counts[i]) + return (-3); + rtype = rrecp->r_type; + rclass = rrecp->r_class; + rttl = rrecp->r_ttl; + /* overload class and type */ + if (section == S_PREREQ) { + rttl = 0; + switch (rrecp->r_opcode) { + case YXDOMAIN: + rclass = C_ANY; + rtype = T_ANY; + rrecp->r_size = 0; + break; + case NXDOMAIN: + rclass = C_NONE; + rtype = T_ANY; + rrecp->r_size = 0; + break; + case NXRRSET: + rclass = C_NONE; + rrecp->r_size = 0; + break; + case YXRRSET: + if (rrecp->r_size == 0) + rclass = C_ANY; + break; + default: + fprintf(stderr, + "res_mkupdate: incorrect opcode: %d\n", + rrecp->r_opcode); + fflush(stderr); + return (-1); + } + } else if (section == S_UPDATE) { + switch (rrecp->r_opcode) { + case DELETE: + rclass = rrecp->r_size == 0 ? C_ANY : C_NONE; + break; + case ADD: + break; + default: + fprintf(stderr, + "res_mkupdate: incorrect opcode: %d\n", + rrecp->r_opcode); + fflush(stderr); + return (-1); + } + } + + /* + * XXX appending default domain to owner name is omitted, + * fqdn must be provided + */ + if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs, + lastdnptr)) < 0) + return (-1); + cp += n; + ShrinkBuffer(n + 2*INT16SZ); + PUTSHORT(rtype, cp); + PUTSHORT(rclass, cp); + if (section == S_ZONE) { + if (numrrs != 1 || rrecp->r_type != T_SOA) + return (-3); + continue; + } + ShrinkBuffer(INT32SZ + INT16SZ); + PUTLONG(rttl, cp); + sp2 = cp; /* save pointer to length byte */ + cp += INT16SZ; + if (rrecp->r_size == 0) { + if (section == S_UPDATE && rclass != C_ANY) + return (-1); + else { + PUTSHORT(0, sp2); + continue; + } + } + startp = rrecp->r_data; + endp = startp + rrecp->r_size - 1; + /* XXX this should be done centrally. */ + switch (rrecp->r_type) { + case T_A: + if (!getword_str(buf2, sizeof buf2, &startp, endp)) + return (-1); + if (!inet_aton(buf2, &ina)) + return (-1); + n1 = ntohl(ina.s_addr); + ShrinkBuffer(INT32SZ); + PUTLONG(n1, cp); + break; + case T_CNAME: + case T_MB: + case T_MG: + case T_MR: + case T_NS: + case T_PTR: + if (!getword_str(buf2, sizeof buf2, &startp, endp)) + return (-1); + n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr); + if (n < 0) + return (-1); + cp += n; + ShrinkBuffer(n); + break; + case T_MINFO: + case T_SOA: + case T_RP: + for (i = 0; i < 2; i++) { + if (!getword_str(buf2, sizeof buf2, &startp, + endp)) + return (-1); + n = dn_comp(buf2, cp, buflen, + dnptrs, lastdnptr); + if (n < 0) + return (-1); + cp += n; + ShrinkBuffer(n); + } + if (rrecp->r_type == T_SOA) { + ShrinkBuffer(5 * INT32SZ); + while (isspace(*startp) || !*startp) + startp++; + if (*startp == '(') { + multiline = 1; + startp++; + } else + multiline = 0; + /* serial, refresh, retry, expire, minimum */ + for (i = 0; i < 5; i++) { + soanum = getnum_str(&startp, endp); + if (soanum < 0) + return (-1); + PUTLONG(soanum, cp); + } + if (multiline) { + while (isspace(*startp) || !*startp) + startp++; + if (*startp != ')') + return (-1); + } + } + break; + case T_MX: + case T_AFSDB: + case T_RT: + n = getnum_str(&startp, endp); + if (n < 0) + return (-1); + PUTSHORT(n, cp); + ShrinkBuffer(INT16SZ); + if (!getword_str(buf2, sizeof buf2, &startp, endp)) + return (-1); + n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr); + if (n < 0) + return (-1); + cp += n; + ShrinkBuffer(n); + break; + case T_PX: + n = getnum_str(&startp, endp); + if (n < 0) + return (-1); + PUTSHORT(n, cp); + ShrinkBuffer(INT16SZ); + for (i = 0; i < 2; i++) { + if (!getword_str(buf2, sizeof buf2, &startp, + endp)) + return (-1); + n = dn_comp(buf2, cp, buflen, dnptrs, + lastdnptr); + if (n < 0) + return (-1); + cp += n; + ShrinkBuffer(n); + } + break; + case T_WKS: + case T_HINFO: + case T_TXT: + case T_X25: + case T_ISDN: + case T_NSAP: + case T_LOC: + /* XXX - more fine tuning needed here */ + ShrinkBuffer(rrecp->r_size); + memcpy(cp, rrecp->r_data, rrecp->r_size); + cp += rrecp->r_size; + break; + default: + return (-1); + } /*switch*/ + n = (u_int16_t)((cp - sp2) - INT16SZ); + PUTSHORT(n, sp2); + } /*for*/ + + hp->qdcount = htons(counts[0]); + hp->ancount = htons(counts[1]); + hp->nscount = htons(counts[2]); + hp->arcount = htons(counts[3]); + return (cp - buf); +} + +/* + * Get a whitespace delimited word from a string (not file) + * into buf. modify the start pointer to point after the + * word in the string. + */ +static int +getword_str(char *buf, int size, u_char **startpp, u_char *endp) { + char *cp; + int c; + + for (cp = buf; *startpp <= endp; ) { + c = **startpp; + if (isspace(c) || c == '\0') { + if (cp != buf) /* trailing whitespace */ + break; + else { /* leading whitespace */ + (*startpp)++; + continue; + } + } + (*startpp)++; + if (cp >= buf+size-1) + break; + *cp++ = (u_char)c; + } + *cp = '\0'; + return (cp != buf); +} + +/* + * Get a whitespace delimited number from a string (not file) into buf + * update the start pointer to point after the number in the string. + */ +static int +getnum_str(u_char **startpp, u_char *endp) { + int c, n; + int seendigit = 0; + int m = 0; + + for (n = 0; *startpp <= endp; ) { + c = **startpp; + if (isspace(c) || c == '\0') { + if (seendigit) /* trailing whitespace */ + break; + else { /* leading whitespace */ + (*startpp)++; + continue; + } + } + if (c == ';') { + while ((*startpp <= endp) && + ((c = **startpp) != '\n')) + (*startpp)++; + if (seendigit) + break; + continue; + } + if (!isdigit(c)) { + if (c == ')' && seendigit) { + (*startpp)--; + break; + } + return (-1); + } + (*startpp)++; + n = n * 10 + (c - '0'); + seendigit = 1; + } + return (n + m); +} + +/* + * Allocate a resource record buffer & save rr info. + */ +ns_updrec * +res_mkupdrec(int section, const char *dname, + u_int class, u_int type, u_long ttl) { + ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec)); + + if (!rrecp || !(rrecp->r_dname = strdup(dname))) + return (NULL); + rrecp->r_class = class; + rrecp->r_type = type; + rrecp->r_ttl = ttl; + rrecp->r_section = section; + return (rrecp); +} + +/* + * Free a resource record buffer created by res_mkupdrec. + */ +void +res_freeupdrec(ns_updrec *rrecp) { + /* Note: freeing r_dp is the caller's responsibility. */ + if (rrecp->r_dname != NULL) + free(rrecp->r_dname); + free(rrecp); +} diff --git a/newlib/libc/sys/linux/net/res_query.c b/newlib/libc/sys/linux/net/res_query.c index fcb624e8e..ee6775d99 100644 --- a/newlib/libc/sys/linux/net/res_query.c +++ b/newlib/libc/sys/linux/net/res_query.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -48,7 +52,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,9 +69,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $"; +static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; +static char orig_rcsid = "From: Id: res_query.c,v 8.14 1997/06/09 17:47:05 halley Exp $"; #endif /* LIBC_SCCS and not lint */ +#include +#include #include #include @@ -81,190 +87,144 @@ static const char rcsid[] = "$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vix #include #include #include -#include "libc-symbols.h" -/* Options. Leave them on. */ -/* #undef DEBUG */ +#include "res_config.h" -#if PACKETSZ > 65536 +#if PACKETSZ > 1024 #define MAXPACKET PACKETSZ #else -#define MAXPACKET 65536 +#define MAXPACKET 1024 #endif -#define QUERYSIZE (HFIXEDSZ + QFIXEDSZ + MAXCDNAME + 1) - -static int -__libc_res_nquerydomain(res_state statp, const char *name, const char *domain, - int class, int type, u_char *answer, int anslen, - u_char **answerp); - /* * Formulate a normal query, send, and await answer. * Returned answer is placed in supplied buffer "answer". * Perform preliminary check of answer, returning success only * if no error is indicated and the answer count is nonzero. * Return the size of the response on success, -1 on error. - * Error number is left in H_ERRNO. + * Error number is left in h_errno. * * Caller must parse answer and determine whether it answers the question. */ int -__libc_res_nquery(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen, /* size of answer buffer */ - u_char **answerp) /* if buffer needs to be enlarged */ +res_query(name, class, type, answer, anslen) + const char *name; /* domain name */ + int class, type; /* class and type of query */ + u_char *answer; /* buffer to put answer */ + int anslen; /* size of answer buffer */ { - u_char *buf; + u_char buf[MAXPACKET]; HEADER *hp = (HEADER *) answer; - int n, use_malloc = 0; + int n; hp->rcode = NOERROR; /* default */ - buf = alloca (QUERYSIZE); - + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } #ifdef DEBUG - if (statp->options & RES_DEBUG) + if (_res.options & RES_DEBUG) printf(";; res_query(%s, %d, %d)\n", name, class, type); #endif - n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL, - buf, QUERYSIZE); - if (__builtin_expect (n <= 0, 0)) { - /* Retry just in case res_nmkquery failed because of too - short buffer. Shouldn't happen. */ - buf = malloc (MAXPACKET); - if (buf != NULL) { - use_malloc = 1; - n = res_nmkquery(statp, QUERY, name, class, type, NULL, - 0, NULL, buf, MAXPACKET); - } - } - if (__builtin_expect (n <= 0, 0)) { + n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, + buf, sizeof(buf)); + if (n > 0 && (_res.options & RES_USE_EDNS0) != 0) + n = res_opt(n, buf, sizeof(buf), anslen); + if (n <= 0) { #ifdef DEBUG - if (statp->options & RES_DEBUG) + if (_res.options & RES_DEBUG) printf(";; res_query: mkquery failed\n"); #endif - RES_SET_H_ERRNO(statp, NO_RECOVERY); - if (use_malloc) - free (buf); + h_errno = NO_RECOVERY; return (n); } - n = __libc_res_nsend(statp, buf, n, answer, anslen, answerp); - if (use_malloc) - free (buf); + n = res_send(buf, n, answer, anslen); if (n < 0) { #ifdef DEBUG - if (statp->options & RES_DEBUG) + if (_res.options & RES_DEBUG) printf(";; res_query: send error\n"); #endif - RES_SET_H_ERRNO(statp, TRY_AGAIN); + h_errno = TRY_AGAIN; return (n); } if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { #ifdef DEBUG - if (statp->options & RES_DEBUG) + if (_res.options & RES_DEBUG) printf(";; rcode = %d, ancount=%d\n", hp->rcode, ntohs(hp->ancount)); #endif switch (hp->rcode) { case NXDOMAIN: - RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); + h_errno = HOST_NOT_FOUND; break; case SERVFAIL: - RES_SET_H_ERRNO(statp, TRY_AGAIN); + h_errno = TRY_AGAIN; break; case NOERROR: - RES_SET_H_ERRNO(statp, NO_DATA); + h_errno = NO_DATA; break; case FORMERR: case NOTIMP: case REFUSED: default: - RES_SET_H_ERRNO(statp, NO_RECOVERY); + h_errno = NO_RECOVERY; break; } return (-1); } return (n); } -libresolv_hidden_def (__libc_res_nquery) - -int -res_nquery(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer buffer */ -{ - return __libc_res_nquery(statp, name, class, type, answer, anslen, - NULL); -} -libresolv_hidden_def (res_nquery) /* * Formulate a normal query, send, and retrieve answer in supplied buffer. * Return the size of the response on success, -1 on error. * If enabled, implement search rules until answer or unrecoverable failure - * is detected. Error code, if any, is left in H_ERRNO. + * is detected. Error code, if any, is left in h_errno. */ int -__libc_res_nsearch(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen, /* size of answer */ - u_char **answerp) +res_search(name, class, type, answer, anslen) + const char *name; /* domain name */ + int class, type; /* class and type of query */ + u_char *answer; /* buffer to put answer */ + int anslen; /* size of answer */ { const char *cp, * const *domain; HEADER *hp = (HEADER *) answer; - char tmp[NS_MAXDNAME]; u_int dots; int trailing_dot, ret, saved_herrno; - int got_nodata = 0, got_servfail = 0, root_on_list = 0; - int tried_as_is = 0; - - __set_errno (0); - RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */ + int got_nodata = 0, got_servfail = 0, tried_as_is = 0; + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } + errno = 0; + h_errno = HOST_NOT_FOUND; /* default, if we never query */ dots = 0; - for (cp = name; *cp != '\0'; cp++) + for (cp = name; *cp; cp++) dots += (*cp == '.'); trailing_dot = 0; if (cp > name && *--cp == '.') trailing_dot++; - /* If there aren't any dots, it could be a user-level alias. */ - if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL) - return (__libc_res_nquery(statp, cp, class, type, answer, - anslen, answerp)); - -#ifdef DEBUG - if (statp->options & RES_DEBUG) - printf("dots=%d, statp->ndots=%d, trailing_dot=%d, name=%s\n", - (int)dots,(int)statp->ndots,(int)trailing_dot,name); -#endif + /* If there aren't any dots, it could be a user-level alias */ + if (!dots && (cp = hostalias(name)) != NULL) + return (res_query(cp, class, type, answer, anslen)); /* - * If there are enough dots in the name, let's just give it a - * try 'as is'. The threshold can be set with the "ndots" option. - * Also, query 'as is', if there is a trailing dot in the name. + * If there are dots in the name already, let's just give it a try + * 'as is'. The threshold can be set with the "ndots" option. */ saved_herrno = -1; - if (dots >= statp->ndots || trailing_dot) { - ret = __libc_res_nquerydomain(statp, name, NULL, class, type, - answer, anslen, answerp); - if (ret > 0 || trailing_dot) + if (dots >= _res.ndots) { + ret = res_querydomain(name, NULL, class, type, answer, anslen); + if (ret > 0) return (ret); saved_herrno = h_errno; tried_as_is++; - if (answerp && *answerp != answer) { - answer = *answerp; - anslen = MAXPACKET; - } } /* @@ -273,29 +233,19 @@ __libc_res_nsearch(res_state statp, * - there is at least one dot, there is no trailing dot, * and RES_DNSRCH is set. */ - if ((!dots && (statp->options & RES_DEFNAMES) != 0) || - (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0)) { + if ((!dots && (_res.options & RES_DEFNAMES)) || + (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { int done = 0; - for (domain = (const char * const *)statp->dnsrch; + for (domain = (const char * const *)_res.dnsrch; *domain && !done; domain++) { - if (domain[0][0] == '\0' || - (domain[0][0] == '.' && domain[0][1] == '\0')) - root_on_list++; - - ret = __libc_res_nquerydomain(statp, name, *domain, - class, type, - answer, anslen, answerp); + ret = res_querydomain(name, *domain, class, type, + answer, anslen); if (ret > 0) return (ret); - if (answerp && *answerp != answer) { - answer = *answerp; - anslen = MAXPACKET; - } - /* * If no server present, give up. * If name isn't found in this domain, @@ -310,11 +260,11 @@ __libc_res_nsearch(res_state statp, * fully-qualified. */ if (errno == ECONNREFUSED) { - RES_SET_H_ERRNO(statp, TRY_AGAIN); + h_errno = TRY_AGAIN; return (-1); } - switch (statp->res_h_errno) { + switch (h_errno) { case NO_DATA: got_nodata++; /* FALLTHROUGH */ @@ -336,72 +286,60 @@ __libc_res_nsearch(res_state statp, /* if we got here for some reason other than DNSRCH, * we only wanted one iteration of the loop, so stop. */ - if ((statp->options & RES_DNSRCH) == 0) + if (!(_res.options & RES_DNSRCH)) done++; } } /* - * If the name has any dots at all, and no earlier 'as-is' query - * for the name, and "." is not on the search list, then try an as-is - * query now. + * If we have not already tried the name "as is", do that now. + * note that we do this regardless of how many dots were in the + * name or whether it ends with a dot unless NOTLDQUERY is set. */ - if (dots && !(tried_as_is || root_on_list)) { - ret = __libc_res_nquerydomain(statp, name, NULL, class, type, - answer, anslen, answerp); + if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) { + ret = res_querydomain(name, NULL, class, type, answer, anslen); if (ret > 0) return (ret); } /* if we got here, we didn't satisfy the search. - * if we did an initial full query, return that query's H_ERRNO + * if we did an initial full query, return that query's h_errno * (note that we wouldn't be here if that query had succeeded). * else if we ever got a nodata, send that back as the reason. - * else send back meaningless H_ERRNO, that being the one from + * else send back meaningless h_errno, that being the one from * the last DNSRCH we did. */ if (saved_herrno != -1) - RES_SET_H_ERRNO(statp, saved_herrno); + h_errno = saved_herrno; else if (got_nodata) - RES_SET_H_ERRNO(statp, NO_DATA); + h_errno = NO_DATA; else if (got_servfail) - RES_SET_H_ERRNO(statp, TRY_AGAIN); + h_errno = TRY_AGAIN; return (-1); } -libresolv_hidden_def (__libc_res_nsearch) - -int -res_nsearch(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ -{ - return __libc_res_nsearch(statp, name, class, type, answer, - anslen, NULL); -} -libresolv_hidden_def (res_nsearch) /* * Perform a call on res_query on the concatenation of name and domain, * removing a trailing dot from name if domain is NULL. */ -static int -__libc_res_nquerydomain(res_state statp, - const char *name, - const char *domain, - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen, /* size of answer */ - u_char **answerp) +int +res_querydomain(name, domain, class, type, answer, anslen) + const char *name, *domain; + int class, type; /* class and type of query */ + u_char *answer; /* buffer to put answer */ + int anslen; /* size of answer */ { char nbuf[MAXDNAME]; const char *longname = nbuf; int n, d; + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } #ifdef DEBUG - if (statp->options & RES_DEBUG) - printf(";; res_nquerydomain(%s, %s, %d, %d)\n", + if (_res.options & RES_DEBUG) + printf(";; res_querydomain(%s, %s, %d, %d)\n", name, domain?domain:"", class, type); #endif if (domain == NULL) { @@ -411,7 +349,7 @@ __libc_res_nquerydomain(res_state statp, */ n = strlen(name); if (n >= MAXDNAME) { - RES_SET_H_ERRNO(statp, NO_RECOVERY); + h_errno = NO_RECOVERY; return (-1); } n--; @@ -424,35 +362,27 @@ __libc_res_nquerydomain(res_state statp, n = strlen(name); d = strlen(domain); if (n + d + 1 >= MAXDNAME) { - RES_SET_H_ERRNO(statp, NO_RECOVERY); + h_errno = NO_RECOVERY; return (-1); } sprintf(nbuf, "%s.%s", name, domain); } - return (__libc_res_nquery(statp, longname, class, type, answer, - anslen, answerp)); + return (res_query(longname, class, type, answer, anslen)); } -int -res_nquerydomain(res_state statp, - const char *name, - const char *domain, - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ -{ - return __libc_res_nquerydomain(statp, name, domain, class, type, - answer, anslen, NULL); -} -libresolv_hidden_def (res_nquerydomain) - const char * -res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { - char *file, *cp1, *cp2; - char buf[BUFSIZ]; +hostalias(name) + const char *name; +{ + char *cp1, *cp2; FILE *fp; + char *file; + char buf[BUFSIZ]; + static char abuf[MAXDNAME]; - if (statp->options & RES_NOALIASES) + if (_res.options & RES_NOALIASES) + return (NULL); + if (issetugid()) return (NULL); file = getenv("HOSTALIASES"); if (file == NULL || (fp = fopen(file, "r")) == NULL) @@ -460,26 +390,35 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { setbuf(fp, NULL); buf[sizeof(buf) - 1] = '\0'; while (fgets(buf, sizeof(buf), fp)) { - for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1) + for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1) ; if (!*cp1) break; *cp1 = '\0'; - if (ns_samename(buf, name) == 1) { - while (isspace(*++cp1)) + if (!strcasecmp(buf, name)) { + while (isspace((unsigned char)*++cp1)) ; if (!*cp1) break; - for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) + for (cp2 = cp1 + 1; *cp2 && !isspace((unsigned char)*cp2); ++cp2) ; - *cp2 = '\0'; - strncpy(dst, cp1, siz - 1); - dst[siz - 1] = '\0'; + abuf[sizeof(abuf) - 1] = *cp2 = '\0'; + strncpy(abuf, cp1, sizeof(abuf) - 1); fclose(fp); - return (dst); + return (abuf); } } fclose(fp); return (NULL); } -libresolv_hidden_def (res_hostalias) + +/* + * Weak aliases for applications that use certain private entry points, + * and fail to include . + */ +#undef res_query +__weak_reference(__res_query, res_query); +#undef res_search +__weak_reference(__res_search, res_search); +#undef res_querydomain +__weak_reference(__res_querydomain, res_querydomain); diff --git a/newlib/libc/sys/linux/net/res_send.c b/newlib/libc/sys/linux/net/res_send.c index 5c2bcf746..153d2f5d9 100644 --- a/newlib/libc/sys/linux/net/res_send.c +++ b/newlib/libc/sys/linux/net/res_send.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985, 1989, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -10,10 +10,14 @@ * 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 @@ -29,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -48,7 +52,7 @@ */ /* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,136 +69,144 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixie Exp $"; +static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; +static char orig_rcsid[] = "From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $"; #endif /* LIBC_SCCS and not lint */ +#include +#include +#include -#define s6_addr32 __u6_addr.__u6_addr32 /* * Send query to name server and wait for reply. */ -#include #include +#include +#include #include #include #include #include -#include #include #include #include -#include #include -#include #include #include -#include #include #include #include #include -#include "libc-symbols.h" - -#if PACKETSZ > 65536 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 65536 -#endif +#include "res_config.h" -/* From ev_streams.c. */ +static int s = -1; /* socket used for communications */ +static int connected = 0; /* is the socket connected */ +static int vc = 0; /* is the socket a virtual circuit? */ +static int af = 0; /* address family of socket */ +static res_send_qhook Qhook = NULL; +static res_send_rhook Rhook = NULL; -static inline void -__attribute ((always_inline)) -evConsIovec(void *buf, size_t cnt, struct iovec *vec) { - memset(vec, 0xf5, sizeof (*vec)); - vec->iov_base = buf; - vec->iov_len = cnt; -} - -/* From ev_timers.c. */ -#define BILLION 1000000000 +#define CAN_RECONNECT 1 -static inline void -evConsTime(struct timespec *res, time_t sec, long nsec) { - res->tv_sec = sec; - res->tv_nsec = nsec; -} +#ifndef DEBUG +# define Dprint(cond, args) /*empty*/ +# define DprintQ(cond, args, query, size) /*empty*/ +# define Aerror(file, string, error, address) /*empty*/ +# define Perror(file, string, error) /*empty*/ +#else +# define Dprint(cond, args) if (cond) {fprintf args;} else {} +# define DprintQ(cond, args, query, size) if (cond) {\ + fprintf args;\ + __fp_nquery(query, size, stdout);\ + } else {} +static char abuf[NI_MAXHOST]; +static char pbuf[NI_MAXSERV]; +static void Aerror(FILE *, char *, int, struct sockaddr *); +static void Perror(FILE *, char *, int); + + static void + Aerror(file, string, error, address) + FILE *file; + char *string; + int error; + struct sockaddr *address; + { + int save = errno; -static inline void -evAddTime(struct timespec *res, const struct timespec *addend1, - const struct timespec *addend2) { - res->tv_sec = addend1->tv_sec + addend2->tv_sec; - res->tv_nsec = addend1->tv_nsec + addend2->tv_nsec; - if (res->tv_nsec >= BILLION) { - res->tv_sec++; - res->tv_nsec -= BILLION; + if (_res.options & RES_DEBUG) { + if (getnameinfo(address, 0, abuf, sizeof(abuf), + pbuf, sizeof(pbuf), + NI_NUMERICHOST|NI_NUMERICSERV|NI_WITHSCOPEID) != 0) { + strncpy(abuf, "?", sizeof(abuf)); + strncpy(pbuf, "?", sizeof(pbuf)); + } + fprintf(file, "res_send: %s ([%s].%s): %s\n", + string, abuf, pbuf, strerror(error)); } -} + errno = save; + } + static void + Perror(file, string, error) + FILE *file; + char *string; + int error; + { + int save = errno; -static inline void -evSubTime(struct timespec *res, const struct timespec *minuend, - const struct timespec *subtrahend) { - res->tv_sec = minuend->tv_sec - subtrahend->tv_sec; - if (minuend->tv_nsec >= subtrahend->tv_nsec) - res->tv_nsec = minuend->tv_nsec - subtrahend->tv_nsec; - else { - res->tv_nsec = (BILLION - - subtrahend->tv_nsec + minuend->tv_nsec); - res->tv_sec--; + if (_res.options & RES_DEBUG) { + fprintf(file, "res_send: %s: %s\n", + string, strerror(error)); } -} + errno = save; + } +#endif -static inline int -evCmpTime(struct timespec a, struct timespec b) { - long x = a.tv_sec - b.tv_sec; +void +res_send_setqhook(hook) + res_send_qhook hook; +{ - if (x == 0L) - x = a.tv_nsec - b.tv_nsec; - return (x < 0L ? (-1) : x > 0L ? (1) : (0)); + Qhook = hook; } -static inline void -evNowTime(struct timespec *res) { - struct timeval now; +void +res_send_setrhook(hook) + res_send_rhook hook; +{ - if (gettimeofday(&now, NULL) < 0) - evConsTime(res, 0, 0); - else - TIMEVAL_TO_TIMESPEC (&now, res); + Rhook = hook; } +static struct sockaddr * get_nsaddr(size_t); -/* Options. Leave them on. */ -/* #undef DEBUG */ -#include "res_debug.h" - -#define EXT(res) ((res)->_u._ext) - -/* Forward. */ - -static int send_vc(res_state, const u_char *, int, - u_char **, int *, int *, int, u_char **); -static int send_dg(res_state, const u_char *, int, - u_char **, int *, int *, int, - int *, int *, u_char **); -#ifdef DEBUG -static void Aerror(const res_state, FILE *, const char *, int, - const struct sockaddr *); -static void Perror(const res_state, FILE *, const char *, int); -#endif -static int sock_eq(struct sockaddr_in6 *, struct sockaddr_in6 *); - -/* Reachover. */ - -static void convaddr4to6(struct sockaddr_in6 *sa); -void res_pquery(const res_state, const u_char *, int, FILE *); +/* + * pick appropriate nsaddr_list for use. see res_init() for initialization. + */ +static struct sockaddr * +get_nsaddr(n) + size_t n; +{ -/* Public. */ + if (!_res.nsaddr_list[n].sin_family) { + /* + * - _res_ext.nsaddr_list[n] holds an address that is larger + * than struct sockaddr, and + * - user code did not update _res.nsaddr_list[n]. + */ + return (struct sockaddr *)&_res_ext.nsaddr_list[n]; + } else { + /* + * - user code updated _res.nsaddr_list[n], or + * - _res.nsaddr_list[n] has the same content as + * _res_ext.nsaddr_list[n]. + */ + return (struct sockaddr *)&_res.nsaddr_list[n]; + } +} /* int * res_isourserver(ina) @@ -206,38 +218,44 @@ void res_pquery(const res_state, const u_char *, int, FILE *); * paul vixie, 29may94 */ int -res_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp) +res_isourserver(inp) + const struct sockaddr_in *inp; { - int ns; - - if (inp->sin6_family == AF_INET) { - struct sockaddr_in *in4p = (struct sockaddr_in *) inp; - in_port_t port = in4p->sin_port; - in_addr_t addr = in4p->sin_addr.s_addr; - - for (ns = 0; ns < MAXNS; ns++) { - const struct sockaddr_in *srv = - (struct sockaddr_in *)EXT(statp).nsaddrs[ns]; - - if ((srv != NULL) && (srv->sin_family == AF_INET) && - (srv->sin_port == port) && - (srv->sin_addr.s_addr == INADDR_ANY || - srv->sin_addr.s_addr == addr)) - return (1); - } - } else if (inp->sin6_family == AF_INET6) { - for (ns = 0; ns < MAXNS; ns++) { - const struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns]; - if ((srv != NULL) && (srv->sin6_family == AF_INET6) && - (srv->sin6_port == inp->sin6_port) && - !(memcmp(&srv->sin6_addr, &in6addr_any, - sizeof (struct in6_addr)) && - memcmp(&srv->sin6_addr, &inp->sin6_addr, - sizeof (struct in6_addr)))) - return (1); - } - } - return (0); + const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp; + const struct sockaddr_in6 *srv6; + const struct sockaddr_in *srv; + int ns, ret; + + ret = 0; + switch (inp->sin_family) { + case AF_INET6: + for (ns = 0; ns < _res.nscount; ns++) { + srv6 = (struct sockaddr_in6 *)get_nsaddr(ns); + if (srv6->sin6_family == in6p->sin6_family && + srv6->sin6_port == in6p->sin6_port && + srv6->sin6_scope_id == in6p->sin6_scope_id && + (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) || + IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, + &in6p->sin6_addr))) { + ret++; + break; + } + } + break; + case AF_INET: + for (ns = 0; ns < _res.nscount; ns++) { + srv = (struct sockaddr_in *)get_nsaddr(ns); + if (srv->sin_family == inp->sin_family && + srv->sin_port == inp->sin_port && + (srv->sin_addr.s_addr == INADDR_ANY || + srv->sin_addr.s_addr == inp->sin_addr.s_addr)) { + ret++; + break; + } + } + break; + } + return (ret); } /* int @@ -253,8 +271,10 @@ res_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp) * paul vixie, 29may94 */ int -res_nameinquery(const char *name, int type, int class, - const u_char *buf, const u_char *eom) +res_nameinquery(name, type, class, buf, eom) + const char *name; + int type, class; + const u_char *buf, *eom; { const u_char *cp = buf + HFIXEDSZ; int qdcount = ntohs(((HEADER*)buf)->qdcount); @@ -271,13 +291,13 @@ res_nameinquery(const char *name, int type, int class, return (-1); ttype = ns_get16(cp); cp += INT16SZ; tclass = ns_get16(cp); cp += INT16SZ; - if (ttype == type && tclass == class && - ns_samename(tname, name) == 1) + if (ttype == type && + tclass == class && + strcasecmp(tname, name) == 0) return (1); } return (0); } -libresolv_hidden_def (res_nameinquery) /* int * res_queriesmatch(buf1, eom1, buf2, eom2) @@ -291,8 +311,9 @@ libresolv_hidden_def (res_nameinquery) * paul vixie, 29may94 */ int -res_queriesmatch(const u_char *buf1, const u_char *eom1, - const u_char *buf2, const u_char *eom2) +res_queriesmatch(buf1, eom1, buf2, eom2) + const u_char *buf1, *eom1; + const u_char *buf2, *eom2; { const u_char *cp = buf1 + HFIXEDSZ; int qdcount = ntohs(((HEADER*)buf1)->qdcount); @@ -304,8 +325,8 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, * Only header section present in replies to * dynamic update packets. */ - if ((((HEADER *)buf1)->opcode == ns_o_update) && - (((HEADER *)buf2)->opcode == ns_o_update)) + if ( (((HEADER *)buf1)->opcode == ns_o_update) && + (((HEADER *)buf2)->opcode == ns_o_update) ) return (1); if (qdcount != ntohs(((HEADER*)buf2)->qdcount)) @@ -327,172 +348,75 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, } return (1); } -libresolv_hidden_def (res_queriesmatch) int -__libc_res_nsend(res_state statp, const u_char *buf, int buflen, - u_char *ans, int anssiz, u_char **ansp) +res_send(buf, buflen, ans, anssiz) + const u_char *buf; + int buflen; + u_char *ans; + int anssiz; { - int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; + HEADER *hp = (HEADER *) buf; + HEADER *anhp = (HEADER *) ans; + int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns, n; + int kq; + u_int badns; /* XXX NSMAX can't exceed #/bits in this variable */ - if (statp->nscount == 0) { - __set_errno (ESRCH); + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + /* errno should have been set by res_init() in this case. */ return (-1); } - if (anssiz < HFIXEDSZ) { - __set_errno (EINVAL); + errno = EINVAL; return (-1); } - - if ((statp->qhook || statp->rhook) && anssiz < MAXPACKET && ansp) { - u_char *buf = malloc (MAXPACKET); - if (buf == NULL) - return (-1); - memcpy (buf, ans, HFIXEDSZ); - *ansp = buf; - ans = buf; - anssiz = MAXPACKET; - } - - DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY), + DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), (stdout, ";; res_send()\n"), buf, buflen); - v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ; + v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; gotsomewhere = 0; + connreset = 0; terrno = ETIMEDOUT; + badns = 0; /* - * If the ns_addr_list in the resolver context has changed, then - * invalidate our cached copy and the associated timing data. + * Send request, RETRY times, or until successful */ - if (EXT(statp).nsinit) { - int needclose = 0; - - if (EXT(statp).nscount != statp->nscount) - needclose++; + for (try = 0; try < _res.retry; try++) { + for (ns = 0; ns < _res.nscount; ns++) { + struct sockaddr *nsap = get_nsaddr(ns); + socklen_t salen; + + if (nsap->sa_family == AF_INET6) + salen = sizeof(struct sockaddr_in6); + else if (nsap->sa_family == AF_INET) + salen = sizeof(struct sockaddr_in); else - for (ns = 0; ns < MAXNS; ns++) { - unsigned int map = EXT(statp).nsmap[ns]; - if (map < MAXNS - && !sock_eq((struct sockaddr_in6 *) - &statp->nsaddr_list[map], - EXT(statp).nsaddrs[ns])) - { - needclose++; - break; - } - } - if (needclose) - res_nclose(statp); - } - - /* - * Maybe initialize our private copy of the ns_addr_list. - */ - if (EXT(statp).nsinit == 0) { - unsigned char map[MAXNS]; + salen = 0; /*unknown, die on connect*/ - memset (map, MAXNS, sizeof (map)); - for (n = 0; n < MAXNS; n++) { - ns = EXT(statp).nsmap[n]; - if (ns < statp->nscount) - map[ns] = n; - else if (ns < MAXNS) { - free(EXT(statp).nsaddrs[n]); - EXT(statp).nsaddrs[n] = NULL; - EXT(statp).nsmap[n] = MAXNS; - } - } - n = statp->nscount; - if (statp->nscount > EXT(statp).nscount) - for (n = EXT(statp).nscount, ns = 0; - n < statp->nscount; n++) { - while (ns < MAXNS - && EXT(statp).nsmap[ns] != MAXNS) - ns++; - if (ns == MAXNS) - break; - EXT(statp).nsmap[ns] = n; - map[n] = ns++; - } - EXT(statp).nscount = n; - for (ns = 0; ns < EXT(statp).nscount; ns++) { - n = map[ns]; - if (EXT(statp).nsaddrs[n] == NULL) - EXT(statp).nsaddrs[n] = - malloc(sizeof (struct sockaddr_in6)); - if (EXT(statp).nsaddrs[n] != NULL) { - memcpy(EXT(statp).nsaddrs[n], - &statp->nsaddr_list[ns], - sizeof (struct sockaddr_in)); - EXT(statp).nssocks[n] = -1; - n++; - } - } - EXT(statp).nsinit = 1; - } - - /* - * Some resolvers want to even out the load on their nameservers. - * Note that RES_BLAST overrides RES_ROTATE. - */ - if ((statp->options & RES_ROTATE) != 0 && - (statp->options & RES_BLAST) == 0) { - struct sockaddr_in6 *ina; - unsigned int map; - - n = 0; - while (n < MAXNS && EXT(statp).nsmap[n] == MAXNS) - n++; - if (n < MAXNS) { - ina = EXT(statp).nsaddrs[n]; - map = EXT(statp).nsmap[n]; - for (;;) { - ns = n + 1; - while (ns < MAXNS - && EXT(statp).nsmap[ns] == MAXNS) - ns++; - if (ns == MAXNS) - break; - EXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns]; - EXT(statp).nsmap[n] = EXT(statp).nsmap[ns]; - n = ns; - } - EXT(statp).nsaddrs[n] = ina; - EXT(statp).nsmap[n] = map; + same_ns: + if (badns & (1 << ns)) { + res_close(); + goto next_ns; } - } - - /* - * Send request, RETRY times, or until successful. - */ - for (try = 0; try < statp->retry; try++) { - for (ns = 0; ns < MAXNS; ns++) - { - struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; - if (nsap == NULL) - goto next_ns; - same_ns: - if (statp->qhook) { + if (Qhook) { int done = 0, loops = 0; do { res_sendhookact act; - struct sockaddr_in *nsap4; - nsap4 = (struct sockaddr_in *) nsap; - act = (*statp->qhook)(&nsap4, &buf, &buflen, - ans, anssiz, &resplen); - nsap = (struct sockaddr_in6 *) nsap4; + act = (*Qhook)((struct sockaddr_in **)&nsap, + &buf, &buflen, + ans, anssiz, &resplen); switch (act) { case res_goahead: done = 1; break; case res_nextns: - res_nclose(statp); + res_close(); goto next_ns; case res_done: + close(kq); return (resplen); case res_modified: /* give the hook another try */ @@ -502,77 +426,473 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen, case res_error: /*FALLTHROUGH*/ default: + close(kq); return (-1); } } while (!done); } -#ifdef DEBUG - char tmpbuf[40]; -#endif - Dprint(statp->options & RES_DEBUG, + Dprint((_res.options & RES_DEBUG) && + getnameinfo(nsap, salen, abuf, sizeof(abuf), + NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0, (stdout, ";; Querying server (# %d) address = %s\n", - ns + 1, inet_ntop(AF_INET6, &nsap->sin6_addr, - tmpbuf, sizeof (tmpbuf)))); + ns + 1, abuf)); if (v_circuit) { - /* Use VC; at most one attempt per server. */ - try = statp->retry; - n = send_vc(statp, buf, buflen, &ans, &anssiz, &terrno, - ns, ansp); - if (n < 0) - return (-1); - if (n == 0) + int truncated; + u_short len; + u_char *cp; + ssize_t rc; + + /* + * Use virtual circuit; + * at most one attempt per server. + */ + try = _res.retry; + truncated = 0; + if (s < 0 || !vc || hp->opcode == ns_o_update || + af != nsap->sa_family) { + if (s >= 0) + res_close(); + + af = nsap->sa_family; + s = socket(af, SOCK_STREAM, 0); + if (s < 0) { + terrno = errno; + Perror(stderr, "socket(vc)", errno); + badns |= (1 << ns); + res_close(); + goto next_ns; + } + errno = 0; + if (connect(s, nsap, salen) < 0) { + terrno = errno; + Aerror(stderr, "connect/vc", + errno, nsap); + badns |= (1 << ns); + res_close(); + goto next_ns; + } + vc = 1; + } + /* + * Send length & message + */ + putshort((u_short)buflen, (u_char*)&len); +#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2 + { + struct iovec iov[2]; + iov[0].iov_base = (caddr_t)&len; + iov[0].iov_len = INT16SZ; + iov[1].iov_base = (caddr_t)buf; + iov[1].iov_len = buflen; + rc = writev(s, iov, 2); + } +#else /* EL/IX level 1 */ + { + char *tmpbuf; + tmpbuf = malloc (INT16SZ + buflen); + memcpy (tmpbuf, &len, INT16SZ); + memcpy (tmpbuf + INT16SZ, buf, buflen); + rc = write (s, tmpbuf, INT16SZ + buflen); + } +#endif /* EL/IX level 1 */ + if (rc != (INT16SZ + buflen)) { + terrno = errno; + Perror(stderr, "write failed", errno); + badns |= (1 << ns); + res_close(); goto next_ns; - resplen = n; - } else { - /* Use datagrams. */ - n = send_dg(statp, buf, buflen, &ans, &anssiz, &terrno, - ns, &v_circuit, &gotsomewhere, ansp); - if (n < 0) - return (-1); - if (n == 0) + } + /* + * Receive length & response + */ + read_len: + cp = ans; + len = INT16SZ; + while ((n = read(s, (char *)cp, (int)len)) > 0) { + cp += n; + if ((len -= n) <= 0) + break; + } + if (n <= 0) { + terrno = errno; + Perror(stderr, "read failed", errno); + res_close(); + /* + * A long running process might get its TCP + * connection reset if the remote server was + * restarted. Requery the server instead of + * trying a new one. When there is only one + * server, this means that a query might work + * instead of failing. We only allow one reset + * per query to prevent looping. + */ + if (terrno == ECONNRESET && !connreset) { + connreset = 1; + res_close(); + goto same_ns; + } + res_close(); goto next_ns; - if (v_circuit) - goto same_ns; - resplen = n; - } + } + resplen = ns_get16(ans); + if (resplen > anssiz) { + Dprint(_res.options & RES_DEBUG, + (stdout, ";; response truncated\n") + ); + truncated = 1; + len = anssiz; + } else + len = resplen; + if (len < HFIXEDSZ) { + /* + * Undersized message. + */ + Dprint(_res.options & RES_DEBUG, + (stdout, ";; undersized: %d\n", len)); + terrno = EMSGSIZE; + badns |= (1 << ns); + res_close(); + goto next_ns; + } + cp = ans; + while (len != 0 && + (n = read(s, (char *)cp, (int)len)) > 0) { + cp += n; + len -= n; + } + if (n <= 0) { + terrno = errno; + Perror(stderr, "read(vc)", errno); + res_close(); + goto next_ns; + } + if (truncated) { + /* + * Flush rest of answer + * so connection stays in synch. + */ + anhp->tc = 1; + len = resplen - anssiz; + while (len != 0) { + char junk[PACKETSZ]; + + n = (len > sizeof(junk) + ? sizeof(junk) + : len); + if ((n = read(s, junk, n)) > 0) + len -= n; + else + break; + } + } + /* + * The calling applicating has bailed out of + * a previous call and failed to arrange to have + * the circuit closed or the server has got + * itself confused. Anyway drop the packet and + * wait for the correct one. + */ + if (hp->id != anhp->id) { + DprintQ((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY), + (stdout, ";; old answer (unexpected):\n"), + ans, (resplen>anssiz)?anssiz:resplen); + goto read_len; + } + } else { + /* + * Use datagrams. + */ + struct pollfd pfd[1]; + int ptimeout; + struct timespec ts; + struct timeval timeout, ctv; + struct sockaddr_storage from; + int fromlen; + + if (s < 0 || vc || af != nsap->sa_family) { + if (vc) + res_close(); + af = nsap->sa_family; + s = socket(af, SOCK_DGRAM, 0); + if (s < 0) { +#ifndef CAN_RECONNECT + bad_dg_sock: +#endif + terrno = errno; + Perror(stderr, "socket(dg)", errno); + badns |= (1 << ns); + res_close(); + goto next_ns; + } + connected = 0; + } +#ifndef CANNOT_CONNECT_DGRAM + /* + * On a 4.3BSD+ machine (client and server, + * actually), sending to a nameserver datagram + * port with no nameserver will cause an + * ICMP port unreachable message to be returned. + * If our datagram socket is "connected" to the + * server, we get an ECONNREFUSED error on the next + * socket operation, and select returns if the + * error message is received. We can thus detect + * the absence of a nameserver without timing out. + * If we have sent queries to at least two servers, + * however, we don't want to remain connected, + * as we wish to receive answers from the first + * server to respond. + * + * When the option "insecure1" is specified, we'd + * rather expect to see responses from an "unknown" + * address. In order to let the kernel accept such + * responses, do not connect the socket here. + * XXX: or do we need an explicit option to disable + * connecting? + */ + if (!(_res.options & RES_INSECURE1) && + (_res.nscount == 1 || (try == 0 && ns == 0))) { + /* + * Connect only if we are sure we won't + * receive a response from another server. + */ + if (!connected) { + if (connect(s, nsap, salen) < 0) { + Aerror(stderr, + "connect(dg)", + errno, nsap); + badns |= (1 << ns); + res_close(); + goto next_ns; + } + connected = 1; + } - Dprint((statp->options & RES_DEBUG) || - ((statp->pfcode & RES_PRF_REPLY) && - (statp->pfcode & RES_PRF_HEAD1)), - (stdout, ";; got answer:\n")); + if (send(s, (char*)buf, buflen, 0) != buflen) { + Perror(stderr, "send", errno); + badns |= (1 << ns); + res_close(); + goto next_ns; + } + } else { + /* + * Disconnect if we want to listen + * for responses from more than one server. + */ + if (connected) { +#ifdef CAN_RECONNECT + /* XXX: any errornous address */ + struct sockaddr_in no_addr; + + no_addr.sin_family = AF_INET; + no_addr.sin_addr.s_addr = INADDR_ANY; + no_addr.sin_port = 0; + (void) connect(s, + (struct sockaddr *) + &no_addr, + sizeof no_addr); +#else + int s1 = socket(af, SOCK_DGRAM,0); + if (s1 < 0) + goto bad_dg_sock; + (void)_dup2(s1, s); + (void)close(s1); + Dprint(_res.options & RES_DEBUG, + (stdout, ";; new DG socket\n")) +#endif /* CAN_RECONNECT */ + connected = 0; + errno = 0; + } +#endif /* !CANNOT_CONNECT_DGRAM */ + if (sendto(s, (char*)buf, buflen, 0, + nsap, salen) != buflen) { + Aerror(stderr, "sendto", errno, nsap); + badns |= (1 << ns); + res_close(); + goto next_ns; + } +#ifndef CANNOT_CONNECT_DGRAM + } +#endif /* !CANNOT_CONNECT_DGRAM */ + + /* + * Wait for reply + */ - DprintQ((statp->options & RES_DEBUG) || - (statp->pfcode & RES_PRF_REPLY), - (stdout, "%s", ""), - ans, (resplen > anssiz) ? anssiz : resplen); + timeout.tv_sec = (_res.retrans << try); + if (try > 0) + timeout.tv_sec /= _res.nscount; + if ((long) timeout.tv_sec <= 0) + timeout.tv_sec = 1; + timeout.tv_usec = 0; + TIMEVAL_TO_TIMESPEC(&timeout, &ts); + (void) gettimeofday(&ctv, NULL); + timeradd(&timeout, &ctv, &timeout); + + /* Convert struct timespec in milliseconds. */ + ptimeout = timeout.tv_sec * 1000 + timeout.tv_usec / 1000; + wait: + pfd[0].fd = s; + pfd[0].events = POLLIN; + n = poll (pfd, 1, ptimeout); + + if (s < 0) { + Perror(stderr, "s out-of-bounds", EMFILE); + res_close(); + goto next_ns; + } + if (n < 0) { + if (errno == EINTR) { + (void) gettimeofday(&ctv, NULL); + if (timercmp(&ctv, &timeout, <)) { + timersub(&timeout, &ctv, &ctv); + TIMEVAL_TO_TIMESPEC(&ctv, &ts); + goto wait; + } + } + Perror(stderr, "poll", errno); + res_close(); + goto next_ns; + } + + if (n == 0) { + /* + * timeout + */ + Dprint(_res.options & RES_DEBUG, + (stdout, ";; timeout\n")); + gotsomewhere = 1; + res_close(); + goto next_ns; + } + errno = 0; + fromlen = sizeof(from); + resplen = recvfrom(s, (char*)ans, anssiz, 0, + (struct sockaddr *)&from, &fromlen); + if (resplen <= 0) { + Perror(stderr, "recvfrom", errno); + res_close(); + goto next_ns; + } + gotsomewhere = 1; + if (resplen < HFIXEDSZ) { + /* + * Undersized message. + */ + Dprint(_res.options & RES_DEBUG, + (stdout, ";; undersized: %d\n", + resplen)); + terrno = EMSGSIZE; + badns |= (1 << ns); + res_close(); + goto next_ns; + } + if (hp->id != anhp->id) { + /* + * response from old query, ignore it. + * XXX - potential security hazard could + * be detected here. + */ + DprintQ((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY), + (stdout, ";; old answer:\n"), + ans, (resplen>anssiz)?anssiz:resplen); + goto wait; + } +#ifdef CHECK_SRVR_ADDR + if (!(_res.options & RES_INSECURE1) && + !res_isourserver((struct sockaddr_in *)&from)) { + /* + * response from wrong server? ignore it. + * XXX - potential security hazard could + * be detected here. + */ + DprintQ((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY), + (stdout, ";; not our server:\n"), + ans, (resplen>anssiz)?anssiz:resplen); + goto wait; + } +#endif + if (!(_res.options & RES_INSECURE2) && + !res_queriesmatch(buf, buf + buflen, + ans, ans + anssiz)) { + /* + * response contains wrong query? ignore it. + * XXX - potential security hazard could + * be detected here. + */ + DprintQ((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY), + (stdout, ";; wrong query name:\n"), + ans, (resplen>anssiz)?anssiz:resplen); + goto wait; + } + if (anhp->rcode == SERVFAIL || + anhp->rcode == NOTIMP || + anhp->rcode == REFUSED) { + DprintQ(_res.options & RES_DEBUG, + (stdout, "server rejected query:\n"), + ans, (resplen>anssiz)?anssiz:resplen); + badns |= (1 << ns); + res_close(); + /* don't retry if called from dig */ + if (!_res.pfcode) + goto next_ns; + } + if (!(_res.options & RES_IGNTC) && anhp->tc) { + /* + * get rest of answer; + * use TCP with same server. + */ + Dprint(_res.options & RES_DEBUG, + (stdout, ";; truncated answer\n")); + v_circuit = 1; + res_close(); + goto same_ns; + } + } /*if vc/dg*/ + Dprint((_res.options & RES_DEBUG) || + ((_res.pfcode & RES_PRF_REPLY) && + (_res.pfcode & RES_PRF_HEAD1)), + (stdout, ";; got answer:\n")); +#if 0 + DprintQ((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY), + (stdout, ""), + ans, (resplen>anssiz)?anssiz:resplen); +#endif /* + * If using virtual circuits, we assume that the first server + * is preferred over the rest (i.e. it is on the local + * machine) and only keep that one open. * If we have temporarily opened a virtual circuit, * or if we haven't been asked to keep a socket open, * close the socket. */ - if ((v_circuit && (statp->options & RES_USEVC) == 0) || - (statp->options & RES_STAYOPEN) == 0) { - res_nclose(statp); + if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) || + !(_res.options & RES_STAYOPEN)) { + res_close(); } - if (statp->rhook) { + if (Rhook) { int done = 0, loops = 0; do { res_sendhookact act; - act = (*statp->rhook)((struct sockaddr_in *) - nsap, buf, buflen, - ans, anssiz, &resplen); + act = (*Rhook)((struct sockaddr_in *)nsap, + buf, buflen, + ans, anssiz, &resplen); switch (act) { case res_goahead: case res_done: done = 1; break; case res_nextns: - res_nclose(statp); + res_close(); goto next_ns; case res_modified: /* give the hook another try */ @@ -582,535 +902,53 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen, case res_error: /*FALLTHROUGH*/ default: + close(kq); return (-1); } } while (!done); } + close(kq); return (resplen); - next_ns: ; + next_ns: ; } /*foreach ns*/ } /*foreach retry*/ - res_nclose(statp); + res_close(); + close(kq); if (!v_circuit) { if (!gotsomewhere) - __set_errno (ECONNREFUSED); /* no nameservers found */ + errno = ECONNREFUSED; /* no nameservers found */ else - __set_errno (ETIMEDOUT); /* no answer obtained */ + errno = ETIMEDOUT; /* no answer obtained */ } else - __set_errno (terrno); + errno = terrno; return (-1); } -int -res_nsend(res_state statp, - const u_char *buf, int buflen, u_char *ans, int anssiz) -{ - return __libc_res_nsend(statp, buf, buflen, ans, anssiz, NULL); -} -libresolv_hidden_def (res_nsend) - -/* Private */ - -static int -send_vc(res_state statp, - const u_char *buf, int buflen, u_char **ansp, int *anssizp, - int *terrno, int ns, u_char **anscp) -{ - const HEADER *hp = (HEADER *) buf; - u_char *ans = *ansp; - int anssiz = *anssizp; - HEADER *anhp = (HEADER *) ans; - struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; - int truncating, connreset, resplen, n; - struct iovec iov[2]; - u_short len; - u_char *cp; - - connreset = 0; - same_ns: - truncating = 0; - - /* Are we still talking to whom we want to talk to? */ - if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { - struct sockaddr_in6 peer; - int size = sizeof peer; - - if (getpeername(statp->_vcsock, - (struct sockaddr *)&peer, &size) < 0 || - !sock_eq(&peer, nsap)) { - res_nclose(statp); - statp->_flags &= ~RES_F_VC; - } - } - - if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { - if (statp->_vcsock >= 0) - res_nclose(statp); - - statp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0); - if (statp->_vcsock < 0) { - *terrno = errno; - Perror(statp, stderr, "socket(vc)", errno); - return (-1); - } - __set_errno (0); - if (connect(statp->_vcsock, (struct sockaddr *)nsap, - sizeof *nsap) < 0) { - *terrno = errno; - Aerror(statp, stderr, "connect/vc", errno, - (struct sockaddr *) nsap); - res_nclose(statp); - return (0); - } - statp->_flags |= RES_F_VC; - } - - /* - * Send length & message - */ - putshort((u_short)buflen, (u_char*)&len); - evConsIovec(&len, INT16SZ, &iov[0]); - evConsIovec((void*)buf, buflen, &iov[1]); - if (TEMP_FAILURE_RETRY (writev(statp->_vcsock, iov, 2)) - != (INT16SZ + buflen)) { - *terrno = errno; - Perror(statp, stderr, "write failed", errno); - res_nclose(statp); - return (0); - } - /* - * Receive length & response - */ - read_len: - cp = ans; - len = INT16SZ; - while ((n = TEMP_FAILURE_RETRY (read(statp->_vcsock, (char *)cp, - (int)len))) > 0) { - cp += n; - if ((len -= n) <= 0) - break; - } - if (n <= 0) { - *terrno = errno; - Perror(statp, stderr, "read failed", errno); - res_nclose(statp); - /* - * A long running process might get its TCP - * connection reset if the remote server was - * restarted. Requery the server instead of - * trying a new one. When there is only one - * server, this means that a query might work - * instead of failing. We only allow one reset - * per query to prevent looping. - */ - if (*terrno == ECONNRESET && !connreset) { - connreset = 1; - res_nclose(statp); - goto same_ns; - } - res_nclose(statp); - return (0); - } - resplen = ns_get16(ans); - if (resplen > anssiz) { - if (anscp) { - ans = malloc (MAXPACKET); - if (ans == NULL) { - *terrno = ENOMEM; - res_nclose(statp); - return (0); - } - anssiz = MAXPACKET; - *anssizp = MAXPACKET; - *ansp = ans; - *anscp = ans; - anhp = (HEADER *) ans; - len = resplen; - } else { - Dprint(statp->options & RES_DEBUG, - (stdout, ";; response truncated\n") - ); - truncating = 1; - len = anssiz; - } - } else - len = resplen; - if (len < HFIXEDSZ) { - /* - * Undersized message. - */ - Dprint(statp->options & RES_DEBUG, - (stdout, ";; undersized: %d\n", len)); - *terrno = EMSGSIZE; - res_nclose(statp); - return (0); - } - cp = ans; - while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0){ - cp += n; - len -= n; - } - if (n <= 0) { - *terrno = errno; - Perror(statp, stderr, "read(vc)", errno); - res_nclose(statp); - return (0); - } - if (truncating) { - /* - * Flush rest of answer so connection stays in synch. - */ - anhp->tc = 1; - len = resplen - anssiz; - while (len != 0) { - char junk[PACKETSZ]; - - n = read(statp->_vcsock, junk, - (len > sizeof junk) ? sizeof junk : len); - if (n > 0) - len -= n; - else - break; - } - } - /* - * If the calling applicating has bailed out of - * a previous call and failed to arrange to have - * the circuit closed or the server has got - * itself confused, then drop the packet and - * wait for the correct one. - */ - if (hp->id != anhp->id) { - DprintQ((statp->options & RES_DEBUG) || - (statp->pfcode & RES_PRF_REPLY), - (stdout, ";; old answer (unexpected):\n"), - ans, (resplen > anssiz) ? anssiz: resplen); - goto read_len; - } - - /* - * All is well, or the error is fatal. Signal that the - * next nameserver ought not be tried. - */ - return (resplen); -} - -static int -send_dg(res_state statp, - const u_char *buf, int buflen, u_char **ansp, int *anssizp, - int *terrno, int ns, int *v_circuit, int *gotsomewhere, u_char **anscp) -{ - const HEADER *hp = (HEADER *) buf; - u_char *ans = *ansp; - int anssiz = *anssizp; - HEADER *anhp = (HEADER *) ans; - struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; - struct timespec now, timeout, finish; - struct pollfd pfd[1]; - int ptimeout; - struct sockaddr_in6 from; - static int socket_pf = 0; - int fromlen, resplen, seconds, n; - - if (EXT(statp).nssocks[ns] == -1) { - /* only try IPv6 if IPv6 NS and if not failed before */ - if ((EXT(statp).nscount6 > 0) && (socket_pf != PF_INET)) { - EXT(statp).nssocks[ns] = - socket(PF_INET6, SOCK_DGRAM, 0); - socket_pf = EXT(statp).nssocks[ns] < 0 ? PF_INET - : PF_INET6; - } - if (EXT(statp).nssocks[ns] < 0) - EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0); - if (EXT(statp).nssocks[ns] < 0) { - *terrno = errno; - Perror(statp, stderr, "socket(dg)", errno); - return (-1); - } - /* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */ - if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET)) - convaddr4to6(nsap); - /* - * On a 4.3BSD+ machine (client and server, - * actually), sending to a nameserver datagram - * port with no nameserver will cause an - * ICMP port unreachable message to be returned. - * If our datagram socket is "connected" to the - * server, we get an ECONNREFUSED error on the next - * socket operation, and select returns if the - * error message is received. We can thus detect - * the absence of a nameserver without timing out. - */ - if (connect(EXT(statp).nssocks[ns], (struct sockaddr *)nsap, - sizeof *nsap) < 0) { - Aerror(statp, stderr, "connect(dg)", errno, - (struct sockaddr *) nsap); - res_nclose(statp); - return (0); - } - /* Make socket non-blocking. */ - int fl = fcntl (EXT(statp).nssocks[ns], F_GETFL); - if (fl != -1) - fcntl (EXT(statp).nssocks[ns], F_SETFL, - fl | O_NONBLOCK); - Dprint(statp->options & RES_DEBUG, - (stdout, ";; new DG socket\n")) - } - - /* - * Compute time for the total operation. - */ - seconds = (statp->retrans << ns); - if (ns > 0) - seconds /= statp->nscount; - if (seconds <= 0) - seconds = 1; - evNowTime(&now); - evConsTime(&timeout, seconds, 0); - evAddTime(&finish, &now, &timeout); - int need_recompute = 0; - int nwritten = 0; - pfd[0].fd = EXT(statp).nssocks[ns]; - pfd[0].events = POLLOUT; - wait: - if (need_recompute) { - evNowTime(&now); - if (evCmpTime(finish, now) <= 0) { - Perror(statp, stderr, "select", errno); - res_nclose(statp); - return (0); - } - evSubTime(&timeout, &finish, &now); - } - /* Convert struct timespec in milliseconds. */ - ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000; - - n = 0; - if (nwritten == 0) - n = poll (pfd, 1, 0); - if (__builtin_expect (n == 0, 0)) { - n = poll (pfd, 1, ptimeout); - need_recompute = 1; - } - if (n == 0) { - Dprint(statp->options & RES_DEBUG, (stdout, - ";; timeout sending\n")); - *gotsomewhere = 1; - return (0); - } - if (n < 0) { - if (errno == EINTR) { - recompute_resend: - evNowTime(&now); - if (evCmpTime(finish, now) > 0) { - evSubTime(&timeout, &finish, &now); - goto wait; - } - } - Perror(statp, stderr, "poll", errno); - res_nclose(statp); - return (0); - } - __set_errno (0); - if (pfd[0].revents & POLLOUT) { - if (send(pfd[0].fd, (char*)buf, buflen, 0) != buflen) { - if (errno == EINTR || errno == EAGAIN) - goto recompute_resend; - Perror(statp, stderr, "send", errno); - res_nclose(statp); - return (0); - } - pfd[0].events = POLLIN; - ++nwritten; - goto wait; - } else if (pfd[0].revents & POLLIN) { - fromlen = sizeof(struct sockaddr_in6); - if (anssiz < MAXPACKET - && anscp - && (ioctl (pfd[0].fd, FIONREAD, &resplen) < 0 - || anssiz < resplen)) { - ans = malloc (MAXPACKET); - if (ans == NULL) - ans = *ansp; - else { - anssiz = MAXPACKET; - *anssizp = MAXPACKET; - *ansp = ans; - *anscp = ans; - anhp = (HEADER *) ans; - } - } - resplen = recvfrom(pfd[0].fd, (char*)ans, anssiz,0, - (struct sockaddr *)&from, &fromlen); - if (resplen <= 0) { - if (errno == EINTR || errno == EAGAIN) { - need_recompute = 1; - goto wait; - } - Perror(statp, stderr, "recvfrom", errno); - res_nclose(statp); - return (0); - } - *gotsomewhere = 1; - if (resplen < HFIXEDSZ) { - /* - * Undersized message. - */ - Dprint(statp->options & RES_DEBUG, - (stdout, ";; undersized: %d\n", - resplen)); - *terrno = EMSGSIZE; - res_nclose(statp); - return (0); - } - if (hp->id != anhp->id) { - /* - * response from old query, ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((statp->options & RES_DEBUG) || - (statp->pfcode & RES_PRF_REPLY), - (stdout, ";; old answer:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); - goto wait; - } - if (!(statp->options & RES_INSECURE1) && - !res_ourserver_p(statp, &from)) { - /* - * response from wrong server? ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((statp->options & RES_DEBUG) || - (statp->pfcode & RES_PRF_REPLY), - (stdout, ";; not our server:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); - goto wait; - } - if (!(statp->options & RES_INSECURE2) && - !res_queriesmatch(buf, buf + buflen, - ans, ans + anssiz)) { - /* - * response contains wrong query? ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((statp->options & RES_DEBUG) || - (statp->pfcode & RES_PRF_REPLY), - (stdout, ";; wrong query name:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); - goto wait; - } - if (anhp->rcode == SERVFAIL || - anhp->rcode == NOTIMP || - anhp->rcode == REFUSED) { - DprintQ(statp->options & RES_DEBUG, - (stdout, "server rejected query:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); - res_nclose(statp); - /* don't retry if called from dig */ - if (!statp->pfcode) - return (0); - } - if (!(statp->options & RES_IGNTC) && anhp->tc) { - /* - * To get the rest of answer, - * use TCP with same server. - */ - Dprint(statp->options & RES_DEBUG, - (stdout, ";; truncated answer\n")); - *v_circuit = 1; - res_nclose(statp); - return (1); - } - /* - * All is well, or the error is fatal. Signal that the - * next nameserver ought not be tried. - */ - return (resplen); - } else if (pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { - /* Something went wrong. We can stop trying. */ - res_nclose(statp); - return (0); - } -} - -#ifdef DEBUG -static void -Aerror(const res_state statp, FILE *file, const char *string, int error, - const struct sockaddr *address) +/* + * This routine is for closing the socket if a virtual circuit is used and + * the program wants to close it. This provides support for endhostent() + * which expects to close the socket. + * + * This routine is not expected to be user visible. + */ +void +res_close() { - int save = errno; - - if ((statp->options & RES_DEBUG) != 0) { - char tmp[sizeof "xxxx.xxxx.xxxx.255.255.255.255"]; - - fprintf(file, "res_send: %s ([%s].%u): %s\n", - string, - inet_ntop(address->sa_family, address->sa_data, - tmp, sizeof tmp), - (address->sa_family == AF_INET - ? ntohs(((struct sockaddr_in *) address)->sin_port) - : address->sa_family == AF_INET6 - ? ntohs(((struct sockaddr_in6 *) address)->sin6_port) - : 0), - strerror(error)); + if (s >= 0) { + (void)close(s); + s = -1; + connected = 0; + vc = 0; + af = 0; } - __set_errno (save); -} - -static void -Perror(const res_state statp, FILE *file, const char *string, int error) { - int save = errno; - - if ((statp->options & RES_DEBUG) != 0) - fprintf(file, "res_send: %s: %s\n", - string, strerror(error)); - __set_errno (save); -} -#endif - -static int -sock_eq(struct sockaddr_in6 *a1, struct sockaddr_in6 *a2) { - if (a1->sin6_family == a2->sin6_family) { - if (a1->sin6_family == AF_INET) - return ((((struct sockaddr_in *)a1)->sin_port == - ((struct sockaddr_in *)a2)->sin_port) && - (((struct sockaddr_in *)a1)->sin_addr.s_addr == - ((struct sockaddr_in *)a2)->sin_addr.s_addr)); - else - return ((a1->sin6_port == a2->sin6_port) && - !memcmp(&a1->sin6_addr, &a2->sin6_addr, - sizeof (struct in6_addr))); - } - if (a1->sin6_family == AF_INET) { - struct sockaddr_in6 *sap = a1; - a1 = a2; - a2 = sap; - } /* assumes that AF_INET and AF_INET6 are the only possibilities */ - return ((a1->sin6_port == ((struct sockaddr_in *)a2)->sin_port) && - IN6_IS_ADDR_V4MAPPED(&a1->sin6_addr) && - (a1->sin6_addr.s6_addr32[3] == - ((struct sockaddr_in *)a2)->sin_addr.s_addr)); } /* - * Converts IPv4 family, address and port to - * IPv6 family, IPv4-mapped IPv6 address and port. + * Weak aliases for applications that use certain private entry points, + * and fail to include . */ -static void -convaddr4to6(struct sockaddr_in6 *sa) -{ - struct sockaddr_in *sa4p = (struct sockaddr_in *) sa; - in_port_t port = sa4p->sin_port; - in_addr_t addr = sa4p->sin_addr.s_addr; - - sa->sin6_family = AF_INET6; - sa->sin6_port = port; - sa->sin6_addr.s6_addr32[0] = 0; - sa->sin6_addr.s6_addr32[1] = 0; - sa->sin6_addr.s6_addr32[2] = htonl(0xFFFF); - sa->sin6_addr.s6_addr32[3] = addr; -} +#undef res_close +__weak_reference(__res_close, _res_close); +#undef res_send +__weak_reference(__res_send, res_send); diff --git a/newlib/libc/sys/linux/net/res_update.c b/newlib/libc/sys/linux/net/res_update.c new file mode 100644 index 000000000..b427bf819 --- /dev/null +++ b/newlib/libc/sys/linux/net/res_update.c @@ -0,0 +1,515 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Based on the Dynamic DNS reference implementation by Viraj Bais + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Separate a linked list of records into groups so that all records + * in a group will belong to a single zone on the nameserver. + * Create a dynamic update packet for each zone and send it to the + * nameservers for that zone, and await answer. + * Abort if error occurs in updating any zone. + * Return the number of zones updated on success, < 0 on error. + * + * On error, caller must deal with the unsynchronized zones + * eg. an A record might have been successfully added to the forward + * zone but the corresponding PTR record would be missing if error + * was encountered while updating the reverse zone. + */ + +#define NSMAX 16 + +struct ns1 { + char nsname[MAXDNAME]; + struct in_addr nsaddr1; +}; + +struct zonegrp { + char z_origin[MAXDNAME]; + int16_t z_class; + char z_soardata[MAXDNAME + 5 * INT32SZ]; + struct ns1 z_ns[NSMAX]; + int z_nscount; + ns_updrec * z_rr; + struct zonegrp *z_next; +}; + + +int +res_update(ns_updrec *rrecp_in) { + ns_updrec *rrecp, *tmprrecp; + u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ]; + char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME], + mailaddr[MAXDNAME]; + u_char soardata[2*MAXCDNAME+5*INT32SZ]; + char *dname, *svdname, *cp1, *target; + u_char *cp, *eom; + HEADER *hp = (HEADER *) answer; + struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL; + int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize, + newgroup, done, myzone, seen_before, numzones = 0; + u_int16_t dlen, class, qclass, type, qtype; + u_int32_t ttl; + + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return (-1); + } + + for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) { + dname = rrecp->r_dname; + n = strlen(dname); + if (dname[n-1] == '.') + dname[n-1] = '\0'; + qtype = T_SOA; + qclass = rrecp->r_class; + done = 0; + seen_before = 0; + + while (!done && dname) { + if (qtype == T_SOA) { + for (tmpzptr = zgrp_start; + tmpzptr && !seen_before; + tmpzptr = tmpzptr->z_next) { + if (strcasecmp(dname, + tmpzptr->z_origin) == 0 && + tmpzptr->z_class == qclass) + seen_before++; + for (tmprrecp = tmpzptr->z_rr; + tmprrecp && !seen_before; + tmprrecp = tmprrecp->r_grpnext) + if (strcasecmp(dname, tmprrecp->r_dname) == 0 + && tmprrecp->r_class == qclass) { + seen_before++; + break; + } + if (seen_before) { + /* + * Append to the end of + * current group. + */ + for (tmprrecp = tmpzptr->z_rr; + tmprrecp->r_grpnext; + tmprrecp = tmprrecp->r_grpnext) + (void)NULL; + tmprrecp->r_grpnext = rrecp; + rrecp->r_grpnext = NULL; + done = 1; + break; + } + } + } else if (qtype == T_A) { + for (tmpzptr = zgrp_start; + tmpzptr && !done; + tmpzptr = tmpzptr->z_next) + for (i = 0; i < tmpzptr->z_nscount; i++) + if (tmpzptr->z_class == qclass && + strcasecmp(tmpzptr->z_ns[i].nsname, + dname) == 0 && + tmpzptr->z_ns[i].nsaddr1.s_addr != 0) { + zptr->z_ns[k].nsaddr1.s_addr = + tmpzptr->z_ns[i].nsaddr1.s_addr; + done = 1; + break; + } + } + if (done) + break; + n = res_mkquery(QUERY, dname, qclass, qtype, NULL, + 0, NULL, buf, sizeof buf); + if (n <= 0) { + fprintf(stderr, "res_update: mkquery failed\n"); + return (n); + } + n = res_send(buf, n, answer, sizeof answer); + if (n < 0) { + fprintf(stderr, "res_update: send error for %s\n", + rrecp->r_dname); + return (n); + } + if (n < HFIXEDSZ) + return (-1); + ancount = ntohs(hp->ancount); + nscount = ntohs(hp->nscount); + arcount = ntohs(hp->arcount); + rcode = hp->rcode; + cp = answer + HFIXEDSZ; + eom = answer + n; + /* skip the question section */ + n = dn_skipname(cp, eom); + if (n < 0 || cp + n + 2 * INT16SZ > eom) + return (-1); + cp += n + 2 * INT16SZ; + + if (qtype == T_SOA) { + if (ancount == 0 && nscount == 0 && arcount == 0) { + /* + * if (rcode == NOERROR) then the dname exists but + * has no soa record associated with it. + * if (rcode == NXDOMAIN) then the dname does not + * exist and the server is replying out of NCACHE. + * in either case, proceed with the next try + */ + dname = strchr(dname, '.'); + if (dname != NULL) + dname++; + continue; + } else if ((rcode == NOERROR || rcode == NXDOMAIN) && + ancount == 0 && + nscount == 1 && arcount == 0) { + /* + * name/data does not exist, soa record supplied in the + * authority section + */ + /* authority section must contain the soa record */ + if ((n = dn_expand(answer, eom, cp, zname, + sizeof zname)) < 0) + return (n); + cp += n; + if (cp + 2 * INT16SZ > eom) + return (-1); + GETSHORT(type, cp); + GETSHORT(class, cp); + if (type != T_SOA || class != qclass) { + fprintf(stderr, "unknown answer\n"); + return (-1); + } + myzone = 0; + svdname = dname; + while (dname) + if (strcasecmp(dname, zname) == 0) { + myzone = 1; + break; + } else if ((dname = strchr(dname, '.')) != NULL) + dname++; + if (!myzone) { + dname = strchr(svdname, '.'); + if (dname != NULL) + dname++; + continue; + } + nscount = 0; + /* fallthrough */ + } else if (rcode == NOERROR && ancount == 1) { + /* + * found the zone name + * new servers will supply NS records for the zone + * in authority section and A records for those + * nameservers in the additional section + * older servers have to be explicitly queried for + * NS records for the zone + */ + /* answer section must contain the soa record */ + if ((n = dn_expand(answer, eom, cp, zname, + sizeof zname)) < 0) + return (n); + else + cp += n; + if (cp + 2 * INT16SZ > eom) + return (-1); + GETSHORT(type, cp); + GETSHORT(class, cp); + if (type == T_CNAME) { + dname = strchr(dname, '.'); + if (dname != NULL) + dname++; + continue; + } + if (strcasecmp(dname, zname) != 0 || + type != T_SOA || + class != rrecp->r_class) { + fprintf(stderr, "unknown answer\n"); + return (-1); + } + /* FALLTHROUGH */ + } else { + fprintf(stderr, + "unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n", + ancount, nscount, arcount, hp->rcode); + return (-1); + } + if (cp + INT32SZ + INT16SZ > eom) + return (-1); + /* continue processing the soa record */ + GETLONG(ttl, cp); + GETSHORT(dlen, cp); + if (cp + dlen > eom) + return (-1); + newgroup = 1; + zptr = zgrp_start; + prevzptr = NULL; + while (zptr) { + if (strcasecmp(zname, zptr->z_origin) == 0 && + type == T_SOA && class == qclass) { + newgroup = 0; + break; + } + prevzptr = zptr; + zptr = zptr->z_next; + } + if (!newgroup) { + for (tmprrecp = zptr->z_rr; + tmprrecp->r_grpnext; + tmprrecp = tmprrecp->r_grpnext) + ; + tmprrecp->r_grpnext = rrecp; + rrecp->r_grpnext = NULL; + done = 1; + cp += dlen; + break; + } else { + if ((n = dn_expand(answer, eom, cp, primary, + sizeof primary)) < 0) + return (n); + cp += n; + /* + * We don't have to bounds check here because the + * next use of 'cp' is in dn_expand(). + */ + cp1 = (char *)soardata; + strcpy(cp1, primary); + cp1 += strlen(cp1) + 1; + if ((n = dn_expand(answer, eom, cp, mailaddr, + sizeof mailaddr)) < 0) + return (n); + cp += n; + strcpy(cp1, mailaddr); + cp1 += strlen(cp1) + 1; + if (cp + 5*INT32SZ > eom) + return (-1); + memcpy(cp1, cp, 5*INT32SZ); + cp += 5*INT32SZ; + cp1 += 5*INT32SZ; + rdatasize = (u_char *)cp1 - soardata; + zptr = calloc(1, sizeof(struct zonegrp)); + if (zptr == NULL) + return (-1); + if (zgrp_start == NULL) + zgrp_start = zptr; + else + prevzptr->z_next = zptr; + zptr->z_rr = rrecp; + rrecp->r_grpnext = NULL; + strcpy(zptr->z_origin, zname); + zptr->z_class = class; + memcpy(zptr->z_soardata, soardata, rdatasize); + /* fallthrough to process NS and A records */ + } + } else if (qtype == T_NS) { + if (rcode == NOERROR && ancount > 0) { + strcpy(zname, dname); + for (zptr = zgrp_start; zptr; zptr = zptr->z_next) { + if (strcasecmp(zname, zptr->z_origin) == 0) + break; + } + if (zptr == NULL) + /* should not happen */ + return (-1); + if (nscount > 0) { + /* + * answer and authority sections contain + * the same information, skip answer section + */ + for (j = 0; j < ancount; j++) { + n = dn_skipname(cp, eom); + if (n < 0) + return (-1); + n += 2*INT16SZ + INT32SZ; + if (cp + n + INT16SZ > eom) + return (-1); + cp += n; + GETSHORT(dlen, cp); + cp += dlen; + } + } else + nscount = ancount; + /* fallthrough to process NS and A records */ + } else { + fprintf(stderr, "cannot determine nameservers for %s:\ +ans=%d, auth=%d, add=%d, rcode=%d\n", + dname, ancount, nscount, arcount, hp->rcode); + return (-1); + } + } else if (qtype == T_A) { + if (rcode == NOERROR && ancount > 0) { + arcount = ancount; + ancount = nscount = 0; + /* fallthrough to process A records */ + } else { + fprintf(stderr, "cannot determine address for %s:\ +ans=%d, auth=%d, add=%d, rcode=%d\n", + dname, ancount, nscount, arcount, hp->rcode); + return (-1); + } + } + /* process NS records for the zone */ + j = 0; + for (i = 0; i < nscount; i++) { + if ((n = dn_expand(answer, eom, cp, name, + sizeof name)) < 0) + return (n); + cp += n; + if (cp + 3 * INT16SZ + INT32SZ > eom) + return (-1); + GETSHORT(type, cp); + GETSHORT(class, cp); + GETLONG(ttl, cp); + GETSHORT(dlen, cp); + if (cp + dlen > eom) + return (-1); + if (strcasecmp(name, zname) == 0 && + type == T_NS && class == qclass) { + if ((n = dn_expand(answer, eom, cp, + name, sizeof name)) < 0) + return (n); + target = zptr->z_ns[j++].nsname; + strcpy(target, name); + } + cp += dlen; + } + if (zptr->z_nscount == 0) + zptr->z_nscount = j; + /* get addresses for the nameservers */ + for (i = 0; i < arcount; i++) { + if ((n = dn_expand(answer, eom, cp, name, + sizeof name)) < 0) + return (n); + cp += n; + if (cp + 3 * INT16SZ + INT32SZ > eom) + return (-1); + GETSHORT(type, cp); + GETSHORT(class, cp); + GETLONG(ttl, cp); + GETSHORT(dlen, cp); + if (cp + dlen > eom) + return (-1); + if (type == T_A && dlen == INT32SZ && class == qclass) { + for (j = 0; j < zptr->z_nscount; j++) + if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) { + memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp, + INT32SZ); + break; + } + } + cp += dlen; + } + if (zptr->z_nscount == 0) { + dname = zname; + qtype = T_NS; + continue; + } + done = 1; + for (k = 0; k < zptr->z_nscount; k++) + if (zptr->z_ns[k].nsaddr1.s_addr == 0) { + done = 0; + dname = zptr->z_ns[k].nsname; + qtype = T_A; + } + + } /* while */ + } + + _res.options |= RES_DEBUG; + for (zptr = zgrp_start; zptr; zptr = zptr->z_next) { + + /* append zone section */ + rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin, + zptr->z_class, ns_t_soa, 0); + if (rrecp == NULL) { + fprintf(stderr, "saverrec error\n"); + fflush(stderr); + return (-1); + } + rrecp->r_grpnext = zptr->z_rr; + zptr->z_rr = rrecp; + + n = res_mkupdate(zptr->z_rr, packet, sizeof packet); + if (n < 0) { + fprintf(stderr, "res_mkupdate error\n"); + fflush(stderr); + return (-1); + } else + fprintf(stdout, "res_mkupdate: packet size = %d\n", n); + + /* + * Override the list of NS records from res_init() with + * the authoritative nameservers for the zone being updated. + * Sort primary to be the first in the list of nameservers. + */ + for (i = 0; i < zptr->z_nscount; i++) { + if (strcasecmp(zptr->z_ns[i].nsname, + zptr->z_soardata) == 0) { + struct in_addr tmpaddr; + + if (i != 0) { + strcpy(zptr->z_ns[i].nsname, + zptr->z_ns[0].nsname); + strcpy(zptr->z_ns[0].nsname, + zptr->z_soardata); + tmpaddr = zptr->z_ns[i].nsaddr1; + zptr->z_ns[i].nsaddr1 = + zptr->z_ns[0].nsaddr1; + zptr->z_ns[0].nsaddr1 = tmpaddr; + } + break; + } + } + for (i = 0; i < MAXNS; i++) { + _res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1; + _res.nsaddr_list[i].sin_family = AF_INET; + _res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT); + } + _res.nscount = (zptr->z_nscount < MAXNS) ? + zptr->z_nscount : MAXNS; + n = res_send(packet, n, answer, sizeof(answer)); + if (n < 0) { + fprintf(stderr, "res_send: send error, n=%d\n", n); + break; + } else + numzones++; + } + + /* free malloc'ed memory */ + while(zgrp_start) { + zptr = zgrp_start; + zgrp_start = zgrp_start->z_next; + res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */ + free((char *)zptr); + } + + return (numzones); +} diff --git a/newlib/libc/sys/linux/net/resolver.3 b/newlib/libc/sys/linux/net/resolver.3 new file mode 100644 index 000000000..141759855 --- /dev/null +++ b/newlib/libc/sys/linux/net/resolver.3 @@ -0,0 +1,422 @@ +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)resolver.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/lib/libc/net/resolver.3,v 1.21 2001/10/01 16:08:56 ru Exp $ +.\" +.Dd June 4, 1993 +.Dt RESOLVER 3 +.Os +.Sh NAME +.Nm res_query , +.Nm res_search , +.Nm res_mkquery , +.Nm res_send , +.Nm res_init , +.Nm dn_comp , +.Nm dn_expand , +.Nm dn_skipname , +.Nm ns_get16 , +.Nm ns_get32 , +.Nm ns_put16 , +.Nm ns_put32 +.Nd resolver routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In netinet/in.h +.In arpa/nameser.h +.In resolv.h +.Ft int +.Fo res_query +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fo res_search +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fo res_mkquery +.Fa "int op" +.Fa "const char *dname" +.Fa "int class" +.Fa "int type" +.Fa "const u_char *data" +.Fa "int datalen" +.Fa "const u_char *newrr_in" +.Fa "u_char *buf" +.Fa "int buflen" +.Fc +.Ft int +.Fo res_send +.Fa "const u_char *msg" +.Fa "int msglen" +.Fa "u_char *answer" +.Fa "int anslen" +.Fc +.Ft int +.Fn res_init +.Ft int +.Fo dn_comp +.Fa "const char *exp_dn" +.Fa "u_char *comp_dn" +.Fa "int length" +.Fa "u_char **dnptrs" +.Fa "u_char **lastdnptr" +.Fc +.Ft int +.Fo dn_expand +.Fa "const u_char *msg" +.Fa "const u_char *eomorig" +.Fa "const u_char *comp_dn" +.Fa "char *exp_dn" +.Fa "int length" +.Fc +.Ft int +.Fn dn_skipname "const u_char *comp_dn" "const u_char *eom" +.Ft u_int +.Fn ns_get16 "const u_char *src" +.Ft u_long +.Fn ns_get32 "const u_char *src" +.Ft void +.Fn ns_put16 "u_int src" "u_char *dst" +.Ft void +.Fn ns_put32 "u_long src" "u_char *dst" +.Sh DESCRIPTION +These routines are used for making, sending and interpreting +query and reply messages with Internet domain name servers. +.Pp +Global configuration and state information that is used by the +resolver routines is kept in the structure +.Em _res . +Most of the values have reasonable defaults and can be ignored. +Options +stored in +.Em _res.options +are defined in +.Pa resolv.h +and are as follows. +Options are stored as a simple bit mask containing the bitwise ``or'' +of the options enabled. +.Bl -tag -width RES_USE_INET6 +.It Dv RES_INIT +True if the initial name server address and default domain name are +initialized (i.e., +.Fn res_init +has been called). +.It Dv RES_DEBUG +Print debugging messages. +.It Dv RES_AAONLY +Accept authoritative answers only. +With this option, +.Fn res_send +should continue until it finds an authoritative answer or finds an error. +Currently this is not implemented. +.It Dv RES_USEVC +Use +.Tn TCP +connections for queries instead of +.Tn UDP +datagrams. +.It Dv RES_STAYOPEN +Used with +.Dv RES_USEVC +to keep the +.Tn TCP +connection open between +queries. +This is useful only in programs that regularly do many queries. +.Tn UDP +should be the normal mode used. +.It Dv RES_IGNTC +Unused currently (ignore truncation errors, i.e., don't retry with +.Tn TCP ) . +.It Dv RES_RECURSE +Set the recursion-desired bit in queries. +This is the default. +.Pf ( Fn res_send +does not do iterative queries and expects the name server +to handle recursion.) +.It Dv RES_DEFNAMES +If set, +.Fn res_search +will append the default domain name to single-component names +(those that do not contain a dot). +This option is enabled by default. +.It Dv RES_DNSRCH +If this option is set, +.Fn res_search +will search for host names in the current domain and in parent domains; see +.Xr hostname 7 . +This is used by the standard host lookup routine +.Xr gethostbyname 3 . +This option is enabled by default. +.It Dv RES_NOALIASES +This option turns off the user level aliasing feature controlled by the +.Dq Ev HOSTALIASES +environment variable. Network daemons should set this option. +.It Dv RES_USE_INET6 +Enables support for IPv6-only applications. +This causes IPv4 addresses to be returned as an IPv4 mapped address. +For example, +.Li 10.1.1.1 +will be returned as +.Li ::ffff:10.1.1.1 . +The option is meaningful with certain kernel configuration only. +.It Dv RES_USE_EDNS0 +Enables support for OPT pseudo-RR for EDNS0 extension. +With the option, resolver code will attach OPT pseudo-RR into DNS queries, +to inform of our receive buffer size. +The option will allow DNS servers to take advantage of non-default receive +buffer size, and to send larger replies. +DNS query packets with EDNS0 extension is not compatible with +non-EDNS0 DNS servers. +.El +.Pp +The +.Fn res_init +routine +reads the configuration file (if any; see +.Xr resolver 5 ) +to get the default domain name, +search list and +the Internet address of the local name server(s). +If no server is configured, the host running +the resolver is tried. +The current domain name is defined by the hostname +if not specified in the configuration file; +it can be overridden by the environment variable +.Ev LOCALDOMAIN . +This environment variable may contain several blank-separated +tokens if you wish to override the +.Em "search list" +on a per-process basis. This is similar to the +.Em search +command in the configuration file. +Another environment variable +.Dq Ev RES_OPTIONS +can be set to +override certain internal resolver options which are otherwise +set by changing fields in the +.Em _res +structure or are inherited from the configuration file's +.Em options +command. The syntax of the +.Dq Ev RES_OPTIONS +environment variable is explained in +.Xr resolver 5 . +Initialization normally occurs on the first call +to one of the following routines. +.Pp +The +.Fn res_query +function provides an interface to the server query mechanism. +It constructs a query, sends it to the local server, +awaits a response, and makes preliminary checks on the reply. +The query requests information of the specified +.Fa type +and +.Fa class +for the specified fully-qualified domain name +.Fa dname . +The reply message is left in the +.Fa answer +buffer with length +.Fa anslen +supplied by the caller. +.Pp +The +.Fn res_search +routine makes a query and awaits a response like +.Fn res_query , +but in addition, it implements the default and search rules +controlled by the +.Dv RES_DEFNAMES +and +.Dv RES_DNSRCH +options. +It returns the first successful reply. +.Pp +The remaining routines are lower-level routines used by +.Fn res_query . +The +.Fn res_mkquery +function +constructs a standard query message and places it in +.Fa buf . +It returns the size of the query, or \-1 if the query is +larger than +.Fa buflen . +The query type +.Fa op +is usually +.Dv QUERY , +but can be any of the query types defined in +.Aq Pa arpa/nameser.h . +The domain name for the query is given by +.Fa dname . +.Fa Newrr +is currently unused but is intended for making update messages. +.Pp +The +.Fn res_send +routine +sends a pre-formatted query and returns an answer. +It will call +.Fn res_init +if +.Dv RES_INIT +is not set, send the query to the local name server, and +handle timeouts and retries. +The length of the reply message is returned, or +\-1 if there were errors. +.Pp +The +.Fn dn_comp +function +compresses the domain name +.Fa exp_dn +and stores it in +.Fa comp_dn . +The size of the compressed name is returned or \-1 if there were errors. +The size of the array pointed to by +.Fa comp_dn +is given by +.Fa length . +The compression uses +an array of pointers +.Fa dnptrs +to previously-compressed names in the current message. +The first pointer points to +the beginning of the message and the list ends with +.Dv NULL . +The limit to the array is specified by +.Fa lastdnptr . +A side effect of +.Fn dn_comp +is to update the list of pointers for +labels inserted into the message +as the name is compressed. +If +.Em dnptr +is +.Dv NULL , +names are not compressed. +If +.Fa lastdnptr +is +.Dv NULL , +the list of labels is not updated. +.Pp +The +.Fn dn_expand +entry +expands the compressed domain name +.Fa comp_dn +to a full domain name +The compressed name is contained in a query or reply message; +.Fa msg +is a pointer to the beginning of the message. +The uncompressed name is placed in the buffer indicated by +.Fa exp_dn +which is of size +.Fa length . +The size of compressed name is returned or \-1 if there was an error. +.Pp +The +.Fn dn_skipname +function skips over a compressed domain name, which starts at a location +pointed to by +.Fa comp_dn . +The compressed name is contained in a query or reply message; +.Fa eom +is a pointer to the end of the message. +The size of compressed name is returned or \-1 if there was +an error. +.Pp +The +.Fn ns_get16 +function gets a 16-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_get32 +function gets a 32-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_put16 +function puts a 16-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Pp +The +.Fn ns_put32 +function puts a 32-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Sh FILES +.Bl -tag -width /etc/resolv.conf +.It Pa /etc/resolv.conf +The configuration file, +see +.Xr resolver 5 . +.El +.Sh SEE ALSO +.Xr gethostbyname 3 , +.Xr resolver 5 , +.Xr hostname 7 , +.Xr named 8 +.Pp +.%T RFC1032 , +.%T RFC1033 , +.%T RFC1034 , +.%T RFC1035 , +.%T RFC974 +.Rs +.%T "Name Server Operations Guide for BIND" +.Re +.Sh HISTORY +The +.Nm +function appeared in +.Bx 4.3 . diff --git a/newlib/libc/sys/linux/net/rexec.c b/newlib/libc/sys/linux/net/rexec.c deleted file mode 100644 index f6ae42d6f..000000000 --- a/newlib/libc/sys/linux/net/rexec.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rexec.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc-symbols.h" - -int rexecoptions; -libc_freeres_ptr (static char *ahostbuf); - -int -rexec_af(ahost, rport, name, pass, cmd, fd2p, af) - char **ahost; - int rport; - const char *name, *pass, *cmd; - int *fd2p; - sa_family_t af; -{ - struct sockaddr_storage sa2, from; - struct addrinfo hints, *res0; - const char *orig_name = name; - const char *orig_pass = pass; - u_short port = 0; - int s, timo = 1, s3; - char c; - int gai; - char servbuff[NI_MAXSERV]; - - snprintf(servbuff, sizeof(servbuff), "%d", ntohs(rport)); - servbuff[sizeof(servbuff) - 1] = '\0'; - - memset(&hints, '\0', sizeof(hints)); - hints.ai_family = af; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - gai = getaddrinfo(*ahost, servbuff, &hints, &res0); - if (gai){ - /* XXX: set errno? */ - return -1; - } - - if (res0->ai_canonname){ - free (ahostbuf); - ahostbuf = strdup (res0->ai_canonname); - if (ahostbuf == NULL) { - perror ("rexec: strdup"); - return (-1); - } - *ahost = ahostbuf; - } else - *ahost = NULL; - ruserpass(res0->ai_canonname, &name, &pass); -retry: - s = socket(res0->ai_family, res0->ai_socktype, 0); - if (s < 0) { - perror("rexec: socket"); - return (-1); - } - if (connect(s, res0->ai_addr, res0->ai_addrlen) < 0) { - if (errno == ECONNREFUSED && timo <= 16) { - (void) __close(s); - sleep(timo); - timo *= 2; - goto retry; - } - perror(res0->ai_canonname); - return (-1); - } - if (fd2p == 0) { - (void) write(s, "", 1); - port = 0; - } else { - char num[32]; - int s2, sa2len; - - s2 = socket(res0->ai_family, res0->ai_socktype, 0); - if (s2 < 0) { - (void) __close(s); - return (-1); - } - listen(s2, 1); - sa2len = sizeof (sa2); - if (getsockname(s2, (struct sockaddr *)&sa2, &sa2len) < 0) { - perror("getsockname"); - (void) __close(s2); - goto bad; -#ifdef SA_LEN - } else if (sa2len != SA_LEN((struct sockaddr *)&sa2)) { - __set_errno(EINVAL); - (void) __close(s2); - goto bad; -#endif - } - port = 0; - if (!getnameinfo((struct sockaddr *)&sa2, sa2len, - NULL, 0, servbuff, sizeof(servbuff), - NI_NUMERICSERV)) - port = atoi(servbuff); - (void) sprintf(num, "%u", port); - (void) __write(s, num, strlen(num)+1); - { int len = sizeof (from); - s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from, - &len)); - __close(s2); - if (s3 < 0) { - perror("accept"); - port = 0; - goto bad; - } - } - *fd2p = s3; - } - - struct iovec iov[3] = - { - [0] = { .iov_base = (void *) name, .iov_len = strlen (name) + 1 }, - /* should public key encypt the password here */ - [1] = { .iov_base = (void *) pass, .iov_len = strlen (pass) + 1 }, - [2] = { .iov_base = (void *) cmd, .iov_len = strlen (cmd) + 1 } - }; - (void) TEMP_FAILURE_RETRY (writev (s, iov, 3)); - - /* We don't need the memory allocated for the name and the password - in ruserpass anymore. */ - if (name != orig_name) - free ((char *) name); - if (pass != orig_pass) - free ((char *) pass); - - if (__read(s, &c, 1) != 1) { - perror(*ahost); - goto bad; - } - if (c != 0) { - while (__read(s, &c, 1) == 1) { - (void) __write(2, &c, 1); - if (c == '\n') - break; - } - goto bad; - } - freeaddrinfo(res0); - return (s); -bad: - if (port) - (void) __close(*fd2p); - (void) __close(s); - freeaddrinfo(res0); - return (-1); -} -libc_hidden_def (rexec_af) - -int -rexec(ahost, rport, name, pass, cmd, fd2p) - char **ahost; - int rport; - const char *name, *pass, *cmd; - int *fd2p; -{ - return rexec_af(ahost, rport, name, pass, cmd, fd2p, AF_INET); -} diff --git a/newlib/libc/sys/linux/net/rpc-lookup.c b/newlib/libc/sys/linux/net/rpc-lookup.c deleted file mode 100644 index 2de497c01..000000000 --- a/newlib/libc/sys/linux/net/rpc-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME rpc - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/rthdr.c b/newlib/libc/sys/linux/net/rthdr.c new file mode 100644 index 000000000..e5f7814b1 --- /dev/null +++ b/newlib/libc/sys/linux/net/rthdr.c @@ -0,0 +1,319 @@ +/* $KAME: rthdr.c,v 1.8 2001/08/20 02:32:40 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +/* to define items, should talk with KAME guys first, for *BSD compatibility */ + +#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ +#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ +#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ + +size_t +inet6_rthdr_space(type, seg) + int type, seg; +{ + switch(type) { + case IPV6_RTHDR_TYPE_0: + if (seg < 1 || seg > 23) + return(0); + return(CMSG_SPACE(sizeof(struct in6_addr) * (seg - 1) + + sizeof(struct ip6_rthdr0))); + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_space: unknown type(%d)\n", type); +#endif + return(0); + } +} + +struct cmsghdr * +inet6_rthdr_init(bp, type) + void *bp; + int type; +{ + struct cmsghdr *ch = (struct cmsghdr *)bp; + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(ch); + + ch->cmsg_level = IPPROTO_IPV6; + ch->cmsg_type = IPV6_RTHDR; + + switch(type) { + case IPV6_RTHDR_TYPE_0: + ch->cmsg_len = CMSG_LEN(sizeof(struct ip6_rthdr0) - sizeof(struct in6_addr)); + bzero(rthdr, sizeof(struct ip6_rthdr0)); + rthdr->ip6r_type = IPV6_RTHDR_TYPE_0; + return(ch); + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_init: unknown type(%d)\n", type); +#endif + return(NULL); + } +} + +int +inet6_rthdr_add(cmsg, addr, flags) + struct cmsghdr *cmsg; + const struct in6_addr *addr; + u_int flags; +{ + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); + + switch(rthdr->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + { + struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr; + if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_add: unsupported flag(%d)\n", flags); +#endif + return(-1); + } + if (rt0->ip6r0_segleft == 23) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_add: segment overflow\n"); +#endif + return(-1); + } + if (flags == IPV6_RTHDR_STRICT) { + int c, b; + c = rt0->ip6r0_segleft / 8; + b = rt0->ip6r0_segleft % 8; + rt0->ip6r0_slmap[c] |= (1 << (7 - b)); + } + rt0->ip6r0_segleft++; + bcopy(addr, (caddr_t)rt0 + ((rt0->ip6r0_len + 1) << 3), + sizeof(struct in6_addr)); + rt0->ip6r0_len += sizeof(struct in6_addr) >> 3; + cmsg->cmsg_len = CMSG_LEN((rt0->ip6r0_len + 1) << 3); + break; + } + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_add: unknown type(%d)\n", + rthdr->ip6r_type); +#endif + return(-1); + } + + return(0); +} + +int +inet6_rthdr_lasthop(cmsg, flags) + struct cmsghdr *cmsg; + unsigned int flags; +{ + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); + + switch(rthdr->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + { + struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr; + if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_lasthop: unsupported flag(%d)\n", flags); +#endif + return(-1); + } + if (rt0->ip6r0_segleft > 23) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_add: segment overflow\n"); +#endif + return(-1); + } + if (flags == IPV6_RTHDR_STRICT) { + int c, b; + c = rt0->ip6r0_segleft / 8; + b = rt0->ip6r0_segleft % 8; + rt0->ip6r0_slmap[c] |= (1 << (7 - b)); + } + break; + } + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_lasthop: unknown type(%d)\n", + rthdr->ip6r_type); +#endif + return(-1); + } + + return(0); +} + +#if 0 +int +inet6_rthdr_reverse(in, out) + const struct cmsghdr *in; + struct cmsghdr *out; +{ +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_reverse: not implemented yet\n"); +#endif + return -1; +} +#endif + +int +inet6_rthdr_segments(cmsg) + const struct cmsghdr *cmsg; +{ + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); + + switch(rthdr->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + { + struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr; + + if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_segments: invalid size(%d)\n", + rt0->ip6r0_len); +#endif + return -1; + } + + return (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + } + + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_segments: unknown type(%d)\n", + rthdr->ip6r_type); +#endif + return -1; + } +} + +struct in6_addr * +inet6_rthdr_getaddr(cmsg, idx) + struct cmsghdr *cmsg; + int idx; +{ + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); + + switch(rthdr->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + { + struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr; + int naddr; + + if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getaddr: invalid size(%d)\n", + rt0->ip6r0_len); +#endif + return NULL; + } + naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + if (idx <= 0 || naddr < idx) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getaddr: invalid idx(%d)\n", idx); +#endif + return NULL; + } + return &rt0->ip6r0_addr[idx - 1]; + } + + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getaddr: unknown type(%d)\n", + rthdr->ip6r_type); +#endif + return NULL; + } +} + +int +inet6_rthdr_getflags(cmsg, idx) + const struct cmsghdr *cmsg; + int idx; +{ + struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); + + switch(rthdr->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + { + struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr; + int naddr; + + if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getflags: invalid size(%d)\n", + rt0->ip6r0_len); +#endif + return -1; + } + naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + if (idx < 0 || naddr < idx) { +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getflags: invalid idx(%d)\n", idx); +#endif + return -1; + } + if (rt0->ip6r0_slmap[idx / 8] & (0x80 >> (idx % 8))) + return IPV6_RTHDR_STRICT; + else + return IPV6_RTHDR_LOOSE; + } + + default: +#ifdef DEBUG + fprintf(stderr, "inet6_rthdr_getflags: unknown type(%d)\n", + rthdr->ip6r_type); +#endif + return -1; + } +} diff --git a/newlib/libc/sys/linux/net/ruserpass.c b/newlib/libc/sys/linux/net/ruserpass.c deleted file mode 100644 index 5c429b072..000000000 --- a/newlib/libc/sys/linux/net/ruserpass.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (c) 1985, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ruserpass.c 8.3 (Berkeley) 4/2/94"; -#endif /* not lint */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "local.h" - -/* #include "ftp_var.h" */ - -static int token (void); -static FILE *cfile; - -#define DEFAULT 1 -#define LOGIN 2 -#define PASSWD 3 -#define ACCOUNT 4 -#define MACDEF 5 -#define ID 10 -#define MACHINE 11 - -static char tokval[100]; - -static const char tokstr[] = -{ -#define TOK_DEFAULT_IDX 0 - "default\0" -#define TOK_LOGIN_IDX (TOK_DEFAULT_IDX + sizeof "default") - "login\0" -#define TOK_PASSWORD_IDX (TOK_LOGIN_IDX + sizeof "login") - "password\0" -#define TOK_PASSWD_IDX (TOK_PASSWORD_IDX + sizeof "password") - "passwd\0" -#define TOK_ACCOUNT_IDX (TOK_PASSWD_IDX + sizeof "passwd") - "account\0" -#define TOK_MACHINE_IDX (TOK_ACCOUNT_IDX + sizeof "account") - "machine\0" -#define TOK_MACDEF_IDX (TOK_MACHINE_IDX + sizeof "machine") - "macdef" -}; - -static const struct toktab { - int tokstr_off; - int tval; -} toktab[]= { - { TOK_DEFAULT_IDX, DEFAULT }, - { TOK_LOGIN_IDX, LOGIN }, - { TOK_PASSWORD_IDX, PASSWD }, - { TOK_PASSWD_IDX, PASSWD }, - { TOK_ACCOUNT_IDX, ACCOUNT }, - { TOK_MACHINE_IDX, MACHINE }, - { TOK_MACDEF_IDX, MACDEF } -}; - - -#define warnx(x) fprintf(stderr, x) -#define warnx2(x, y) fprintf(stderr, x, y) - -int -ruserpass(host, aname, apass) - const char *host, **aname, **apass; -{ - char *hdir, *buf, *tmp; - char myname[1024], *mydomain; - int t, usedefault = 0; - struct stat64 stb; - - hdir = getenv("HOME"); - if (hdir == NULL) { - /* If we can't get HOME, fail instead of trying ".", - which is no improvement. This really should call - getpwuid(getuid()). */ - /*hdir = ".";*/ - return -1; - } - - buf = alloca (strlen (hdir) + 8); - - stpcpy (stpcpy (buf, hdir), "/.netrc"); - cfile = fopen(buf, "rc"); - if (cfile == NULL) { - if (errno != ENOENT) { - char *t = asprintf("%s", buf); - perror(t); - } - return (0); - } - /* No threads use this stream. */ - __fsetlocking (cfile, FSETLOCKING_BYCALLER); - if (__gethostname(myname, sizeof(myname)) < 0) - myname[0] = '\0'; - tmp = strchr(myname, '.'); - if (tmp == NULL) - tmp = myname + strlen(myname); - mydomain = tmp; -next: - while ((t = token())) switch(t) { - - case DEFAULT: - usedefault = 1; - /* FALL THROUGH */ - - case MACHINE: - if (!usedefault) { - if (token() != ID) - continue; - /* - * Allow match either for user's input host name - * or official hostname. Also allow match of - * incompletely-specified host in local domain. - */ - if (strcasecmp(host, tokval) == 0) - goto match; -/* if (strcasecmp(hostname, tokval) == 0) - goto match; - if ((tmp = strchr(hostname, '.')) != NULL && - strcasecmp(tmp, mydomain) == 0 && - strncasecmp(hostname, tokval, tmp-hostname) == 0 && - tokval[tmp - hostname] == '\0') - goto match; */ - if ((tmp = strchr(host, '.')) != NULL && - strcasecmp(tmp, mydomain) == 0 && - strncasecmp(host, tokval, tmp - host) == 0 && - tokval[tmp - host] == '\0') - goto match; - continue; - } - match: - while ((t = token()) && t != MACHINE && t != DEFAULT) switch(t) { - - case LOGIN: - if (token()) { - if (*aname == 0) { - char *newp; - newp = malloc((unsigned) strlen(tokval) + 1); - if (newp == NULL) - { - warnx(_("out of memory")); - goto bad; - } - *aname = strcpy(newp, tokval); - } else { - if (strcmp(*aname, tokval)) - goto next; - } - } - break; - case PASSWD: - if (strcmp(*aname, "anonymous") && - fstat64(fileno(cfile), &stb) >= 0 && - (stb.st_mode & 077) != 0) { - warnx(_("Error: .netrc file is readable by others.")); - warnx(_("Remove password or make file unreadable by others.")); - goto bad; - } - if (token() && *apass == 0) { - char *newp; - newp = malloc((unsigned) strlen(tokval) + 1); - if (newp == NULL) - { - warnx(_("out of memory")); - goto bad; - } - *apass = strcpy(newp, tokval); - } - break; - case ACCOUNT: -#if 0 - if (fstat64(fileno(cfile), &stb) >= 0 - && (stb.st_mode & 077) != 0) { - warnx("Error: .netrc file is readable by others."); - warnx("Remove account or make file unreadable by others."); - goto bad; - } - if (token() && *aacct == 0) { - *aacct = malloc((unsigned) strlen(tokval) + 1); - (void) strcpy(*aacct, tokval); - } -#endif - break; - case MACDEF: -#if 0 - if (proxy) { - (void) fclose(cfile); - return (0); - } - while ((c=getc_unlocked(cfile)) != EOF && c == ' ' - || c == '\t'); - if (c == EOF || c == '\n') { - printf("Missing macdef name argument.\n"); - goto bad; - } - if (macnum == 16) { - printf("Limit of 16 macros have already been defined\n"); - goto bad; - } - tmp = macros[macnum].mac_name; - *tmp++ = c; - for (i=0; i < 8 && (c=getc_unlocked(cfile)) != EOF && - !isspace(c); ++i) { - *tmp++ = c; - } - if (c == EOF) { - printf("Macro definition missing null line terminator.\n"); - goto bad; - } - *tmp = '\0'; - if (c != '\n') { - while ((c=getc_unlocked(cfile)) != EOF - && c != '\n'); - } - if (c == EOF) { - printf("Macro definition missing null line terminator.\n"); - goto bad; - } - if (macnum == 0) { - macros[macnum].mac_start = macbuf; - } - else { - macros[macnum].mac_start = macros[macnum-1].mac_end + 1; - } - tmp = macros[macnum].mac_start; - while (tmp != macbuf + 4096) { - if ((c=getc_unlocked(cfile)) == EOF) { - printf("Macro definition missing null line terminator.\n"); - goto bad; - } - *tmp = c; - if (*tmp == '\n') { - if (*(tmp-1) == '\0') { - macros[macnum++].mac_end = tmp - 1; - break; - } - *tmp = '\0'; - } - tmp++; - } - if (tmp == macbuf + 4096) { - printf("4K macro buffer exceeded\n"); - goto bad; - } -#endif - break; - default: - warnx2(_("Unknown .netrc keyword %s"), tokval); - break; - } - goto done; - } -done: - (void) fclose(cfile); - return (0); -bad: - (void) fclose(cfile); - return (-1); -} -libc_hidden_def (ruserpass) - -static int -token() -{ - char *cp; - int c; - int i; - - if (feof(cfile) || ferror(cfile)) - return (0); - while ((c = getc_unlocked(cfile)) != EOF && - (c == '\n' || c == '\t' || c == ' ' || c == ',')) - continue; - if (c == EOF) - return (0); - cp = tokval; - if (c == '"') { - while ((c = getc_unlocked(cfile)) != EOF && c != '"') { - if (c == '\\') - c = getc_unlocked(cfile); - *cp++ = c; - } - } else { - *cp++ = c; - while ((c = getc_unlocked(cfile)) != EOF - && c != '\n' && c != '\t' && c != ' ' && c != ',') { - if (c == '\\') - c = getc_unlocked(cfile); - *cp++ = c; - } - } - *cp = 0; - if (tokval[0] == 0) - return (0); - for (i = 0; i < (int) (sizeof (toktab) / sizeof (toktab[0])); ++i) - if (!strcmp(&tokstr[toktab[i].tokstr_off], tokval)) - return toktab[i].tval; - return (ID); -} diff --git a/newlib/libc/sys/linux/net/send.c b/newlib/libc/sys/linux/net/send.c index 658c92b71..8ff65d015 100644 --- a/newlib/libc/sys/linux/net/send.c +++ b/newlib/libc/sys/linux/net/send.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; #include #include +#include "namespace.h" #include #include diff --git a/newlib/libc/sys/linux/net/service-lookup.c b/newlib/libc/sys/linux/net/service-lookup.c deleted file mode 100644 index 67d401e08..000000000 --- a/newlib/libc/sys/linux/net/service-lookup.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME services - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/spwd-lookup.c b/newlib/libc/sys/linux/net/spwd-lookup.c deleted file mode 100644 index 40c2f613c..000000000 --- a/newlib/libc/sys/linux/net/spwd-lookup.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define DATABASE_NAME shadow -#define ALTERNATE_NAME passwd -#define DEFAULT_CONFIG "compat [NOTFOUND=return] files" - -#include "XXX-lookup.c" diff --git a/newlib/libc/sys/linux/net/vars.c b/newlib/libc/sys/linux/net/vars.c new file mode 100644 index 000000000..c91a04bd1 --- /dev/null +++ b/newlib/libc/sys/linux/net/vars.c @@ -0,0 +1,45 @@ +/* $KAME: vars.c,v 1.2 2001/08/20 02:32:41 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include + +/* + * Definitions of some costant IPv6 addresses. + */ +const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; +const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; +const struct in6_addr in6addr_nodelocal_allnodes = IN6ADDR_NODELOCAL_ALLNODES_INIT; +const struct in6_addr in6addr_linklocal_allnodes = IN6ADDR_LINKLOCAL_ALLNODES_INIT; + -- cgit v1.2.3