📄 lib-libc-net
字号:
#!/bin/sh# This is a shell archive (produced by GNU sharutils 4.1).# To extract the files from this archive, save it to some FILE, remove# everything before the `!/bin/sh' line above, then type `sh FILE'.## Made on 1994-12-12 10:17 PST by <vixie@gw.home.vix.com>.# Source directory was `/a4/vixie/2.0b1/src/lib/libc/net'.## Existing files will *not* be overwritten unless `-c' is specified.## This shar contains:# length mode name# ------ ---------- ------------------------------------------# 114437 -rw-rw-r-- diffs# 3693 -rw-rw-r-- nsap_addr.c#touch -am 1231235999 $$.touch >/dev/null 2>&1if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touchelse shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echofirm -f 1231235999 $$.touch## ============= diffs ==============if test -f 'diffs' && test X"$1" != X"-c"; then echo 'x - skipping diffs (file already exists)'else echo 'x - extracting diffs (text)' sed 's/^X//' << 'SHAR_EOF' > 'diffs' &&*** ../net-2.0b1/Makefile.inc Wed Nov 9 12:57:47 1994--- Makefile.inc Mon Dec 12 00:05:27 1994****************** 7,17 ****X X SRCS+= gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \! getnetnamadr.c getproto.c getprotoent.c getprotoname.c getservbyname.c \! getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \! inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c iso_addr.c \! link_addr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c res_debug.c \! res_init.c res_mkquery.c res_query.c res_send.c send.c sethostent.c! ! CFLAGS+=-DRESOLVSORT -DRFC1535X X # machine-dependent net sources--- 7,16 ----X X SRCS+= gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \! getnetnamadr.c getproto.c getprotoent.c getprotoname.c \! getservbyname.c getservbyport.c getservent.c herror.c inet_addr.c \! inet_lnaof.c inet_makeaddr.c inet_netof.c inet_network.c \! inet_ntoa.c iso_addr.c link_addr.c nsap_addr.c ns_addr.c ns_ntoa.c \! rcmd.c recv.c res_comp.c res_debug.c res_init.c res_mkquery.c \! res_query.c res_send.c send.c sethostent.cX X # machine-dependent net sources*** ../net-2.0b1/gethostnamadr.c Mon Nov 7 10:54:16 1994--- gethostnamadr.c Mon Dec 12 00:11:04 1994****************** 58,62 ****X #if defined(LIBC_SCCS) && !defined(lint)X static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";! static char rcsid[] = "=Id: gethnamaddr.c,v 4.9.1.7 1993/11/12 01:23:34 vixie Exp =";X #endif /* LIBC_SCCS and not lint */X --- 58,62 ----X #if defined(LIBC_SCCS) && !defined(lint)X static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";! static char rcsid[] = "=Id: gethnamaddr.c,v 4.9.1.22 1994/12/11 19:05:40 vixie Exp =";X #endif /* LIBC_SCCS and not lint */X ****************** 72,97 ****X #include <ctype.h>X #include <errno.h>X #include <string.h>X ! #ifdef SUNSECURITY! #include <syslog.h>X #endifX X #define MAXALIASES 35X #define MAXADDRS 35X X static char *h_addr_ptrs[MAXADDRS + 1];X X static struct hostent host;X static char *host_aliases[MAXALIASES];! static char hostbuf[BUFSIZ+1];X static struct in_addr host_addr;X static FILE *hostf = NULL;- static char hostaddr[MAXADDRS];- static char *host_addrs[2];X static int stayopen = 0;X X #ifdef RESOLVSORT! static int qcomp __P((void *, void *));X #endifX --- 72,103 ----X #include <ctype.h>X #include <errno.h>+ #include <syslog.h>X #include <string.h>X ! #ifndef LOG_AUTH! # define LOG_AUTH 0X #endifX + #define MULTI_PTRS_ARE_ALIASES 1+ #define RESOLVSORT 1+ #define DEBUG 1+ X #define MAXALIASES 35X #define MAXADDRS 35X + static const char AskedForGot[] =+ "gethostby*.getanswer: asked for \"%s\", got \"%s\"";+ X static char *h_addr_ptrs[MAXADDRS + 1];X X static struct hostent host;X static char *host_aliases[MAXALIASES];! static char hostbuf[8*1024];X static struct in_addr host_addr;X static FILE *hostf = NULL;X static int stayopen = 0;X X #ifdef RESOLVSORT! static void addrsort __P((char **, int));X #endifX ****************** 114,132 ****X extern int h_errno;X X static struct hostent *! getanswer(answer, anslen, iquery)! querybuf *answer;X int anslen;! int iquery;X {! register HEADER *hp;! register u_char *cp;X register int n;! u_char *eom;! char *bp, **ap;X int type, class, buflen, ancount, qdcount;! int haveanswer, getclass = C_ANY;! char **hap;X X eom = answer->buf + anslen;X /*--- 120,158 ----X extern int h_errno;X + #ifdef DEBUG+ static void+ dprintf(msg, num)+ char *msg;+ int num;+ {+ if (_res.options & RES_DEBUG) {+ int save = errno;+ + printf(msg, num);+ errno = save;+ }+ }+ #else+ # define dprintf(msg, num) /*nada*/+ #endif+ X static struct hostent *! getanswer(answer, anslen, qname, qclass, qtype)! const querybuf *answer;X int anslen;! const char *qname;! int qclass, qtype;X {! register const HEADER *hp;! register const u_char *cp;X register int n;! const u_char *eom;! char *bp, **ap, **hap;X int type, class, buflen, ancount, qdcount;! int haveanswer, had_error;! int toobig = 0;! char tbuf[MAXDNAME+1];X + host.h_name = NULL;X eom = answer->buf + anslen;X /******************* 137,165 ****X qdcount = ntohs(hp->qdcount);X bp = hostbuf;! buflen = sizeof(hostbuf);! cp = answer->buf + sizeof(HEADER);! if (qdcount) {! if (iquery) {! if ((n = dn_expand((u_char *)answer->buf,! (u_char *)eom, (u_char *)cp, (u_char *)bp,! buflen)) < 0) {! h_errno = NO_RECOVERY;! return ((struct hostent *) NULL);! }! cp += n + QFIXEDSZ;! host.h_name = bp;! n = strlen(bp) + 1;! bp += n;! buflen -= n;! } else! cp += __dn_skipname(cp, eom) + QFIXEDSZ;! while (--qdcount > 0)! cp += __dn_skipname(cp, eom) + QFIXEDSZ;! } else if (iquery) {! if (hp->aa)! h_errno = HOST_NOT_FOUND;! else! h_errno = TRY_AGAIN;! return ((struct hostent *) NULL);X }X ap = host_aliases;--- 163,188 ----X qdcount = ntohs(hp->qdcount);X bp = hostbuf;! buflen = sizeof hostbuf;! cp = answer->buf + HFIXEDSZ;! if (qdcount != 1) {! h_errno = NO_RECOVERY;! return (NULL);! }! if ((n = dn_expand(answer->buf, eom, cp, bp, buflen)) < 0) {! h_errno = NO_RECOVERY;! return (NULL);! }! cp += n + QFIXEDSZ;! if (qtype == T_A) {! /* 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 */! host.h_name = bp;! bp += n;! buflen -= n;! /* The qname can be abbreviated, but h_name is now absolute. */! qname = host.h_name;X }X ap = host_aliases;****************** 172,263 ****X #endifX haveanswer = 0;! while (--ancount >= 0 && cp < eom) {! if ((n = dn_expand((u_char *)answer->buf, (u_char *)eom,! (u_char *)cp, (u_char *)bp, buflen)) < 0)! break;! cp += n;X type = _getshort(cp);! cp += sizeof(u_int16_t);X class = _getshort(cp);! cp += sizeof(u_int16_t) + sizeof(u_int32_t);X n = _getshort(cp);! cp += sizeof(u_int16_t);! if (type == T_CNAME) {X cp += n;X if (ap >= &host_aliases[MAXALIASES-1])X continue;X *ap++ = bp;! n = strlen(bp) + 1;X bp += n;X buflen -= n;X continue;X }! if (iquery && type == T_PTR) {! if ((n = dn_expand((u_char *)answer->buf,! (u_char *)eom, (u_char *)cp, (u_char *)bp,! buflen)) < 0)! break;X cp += n;! host.h_name = bp;! return(&host);X }! if (iquery || type != T_A) {! #ifdef DEBUG! if (_res.options & RES_DEBUG)! printf("unexpected answer type %d, size %d\n",! type, n);! #endif! cp += n;! continue;! }! if (haveanswer) {! if (n != host.h_length) {X cp += n;! continue;X }! if (class != getclass) {X cp += n;! continue;X }! } else {! host.h_length = n;! getclass = class;! host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC;! if (!iquery) {X host.h_name = bp;! bp += strlen(bp) + 1;X }- }X ! bp += sizeof(align) - ((u_int32_t)bp % sizeof(align));X ! if (bp + n >= &hostbuf[sizeof(hostbuf)]) {! #ifdef DEBUG! if (_res.options & RES_DEBUG)! printf("size (%d) too big\n", n);! #endifX break;! }! bcopy(cp, *hap++ = bp, n);! bp +=n;! cp += n;! haveanswer++;! }X if (haveanswer) {X *ap = NULL;- #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */X *hap = NULL;! #ifdef RESOLVSORT! if (_res.nsort)! qsort(host.h_addr_list, haveanswer,! sizeof(struct in_addr), qcomp);! #endifX #elseX host.h_addr = h_addr_ptrs[0];X #endif /*BSD*/X return (&host);X } else {X h_errno = TRY_AGAIN;! return ((struct hostent *) NULL);X }X }--- 195,368 ----X #endifX haveanswer = 0;! had_error = 0;! while (ancount-- > 0 && cp < eom && !had_error) {! n = dn_expand(answer->buf, eom, cp, bp, buflen);! if (n < 0) {! had_error++;! continue;! }! cp += n; /* name */X type = _getshort(cp);! cp += INT16SZ; /* type */X class = _getshort(cp);! cp += INT16SZ + INT32SZ; /* class, TTL */X n = _getshort(cp);! cp += INT16SZ; /* len */! if (class != qclass) {! /* XXX - debug? syslog? */X cp += n;+ continue; /* XXX - had_error++ ? */+ }+ if (qtype == T_A && type == T_CNAME) {X if (ap >= &host_aliases[MAXALIASES-1])X continue;+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);+ if (n < 0) {+ had_error++;+ continue;+ }+ cp += n;+ if (host.h_name && strcasecmp(host.h_name, bp) != 0) {+ syslog(LOG_NOTICE|LOG_AUTH,+ "gethostby*.getanswer: asked for \"%s\", got CNAME for \"%s\"",+ host.h_name, bp);+ continue; /* XXX - had_error++ ? */+ }+ /* Store alias. */X *ap++ = bp;! n = strlen(bp) + 1; /* for the \0 */! bp += n;! buflen -= n;! /* Get canonical name. */! n = strlen(tbuf) + 1; /* for the \0 */! if (n > buflen) {! had_error++;! continue;! }! strcpy(bp, tbuf);! host.h_name = bp;X bp += n;X buflen -= n;X continue;X }! if (type != qtype) {! syslog(LOG_NOTICE|LOG_AUTH,! "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",! qname, p_class(qclass), p_type(qtype),! p_type(type));X cp += n;! continue; /* XXX - had_error++ ? */X }! switch (type) {! case T_PTR:! if (strcasecmp(qname, bp) != 0) {! syslog(LOG_NOTICE|LOG_AUTH,! AskedForGot, qname, bp);X cp += n;! continue; /* XXX - had_error++ ? */! }! n = dn_expand(answer->buf, eom, cp, bp, buflen);! if (n < 0) {! had_error++;! break;X }! #if MULTI_PTRS_ARE_ALIASES! cp += n;! if (!haveanswer)! host.h_name = bp;! else if (ap < &host_aliases[MAXALIASES-1])! *ap++ = bp;! else! n = -1;! if (n != -1) {! n = strlen(bp) + 1; /* for the \0 */! bp += n;! buflen -= n;! }! break;! #else! host.h_name = bp;! h_errno = NETDB_SUCCESS;! return (&host);! #endif! case T_A:! if (strcasecmp(host.h_name, bp) != 0) {! syslog(LOG_NOTICE|LOG_AUTH,! AskedForGot, host.h_name, bp);X cp += n;! continue; /* XXX - had_error++ ? */X }! if (haveanswer) {! if (n != host.h_length) {! cp += n;! continue;! }! } else {! register int nn;! ! host.h_length = n;! host.h_addrtype = (class == C_IN)! ? AF_INET! : AF_UNSPEC;X host.h_name = bp;! nn = strlen(bp) + 1; /* for the \0 */! bp += nn;! buflen -= nn;X }X ! bp += sizeof(align) - ((u_long)bp % sizeof(align));X ! if (bp + n >= &hostbuf[sizeof hostbuf]) {! dprintf("size (%d) too big\n", n);! had_error++;! continue;! }! if (hap >= &h_addr_ptrs[MAXADDRS-1]) {! if (!toobig++)! dprintf("Too many addresses (%d)\n",! MAXADDRS);! cp += n;! continue;! }! bcopy(cp, *hap++ = bp, n);! bp += n;! cp += n;X break;! default:! dprintf("Impossible condition (type=%d)\n", type);! h_errno = NO_RECOVERY;! return (NULL);! } /*switch*/! if (!had_error)! haveanswer++;! } /*while*/X if (haveanswer) {X *ap = NULL;X *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 &&! qclass == C_IN && qtype == T_A)! addrsort(h_addr_ptrs, haveanswer);! # endif /*RESOLVSORT*/! #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */! /* nothing */X #elseX host.h_addr = h_addr_ptrs[0];X #endif /*BSD*/+ if (!host.h_name) {+ n = strlen(qname) + 1; /* for the \0 */+ strcpy(bp, qname);+ host.h_name = bp;+ }+ h_errno = NETDB_SUCCESS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -