Deleted Added
full compact
1/*-
2 * Copyright (c) 1985, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 38 unchanged lines hidden (view full) ---

47 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
48 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 * SOFTWARE.
50 * -
51 * --Copyright--
52 */
53
54#if defined(LIBC_SCCS) && !defined(lint)
55static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
56static char rcsid[] = "$Id: gethnamaddr.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
57#endif /* LIBC_SCCS and not lint */
58
59#include <sys/param.h>
60#include <sys/socket.h>
61#include <netinet/in.h>
62#include <arpa/inet.h>
63#include <arpa/nameser.h>
64#include <netdb.h>
65#include <resolv.h>
66#include <stdio.h>
67#include <ctype.h>
68#include <errno.h>
69#include <string.h>
70
71#define MAXALIASES 35
72#define MAXADDRS 35
73
74static char *h_addr_ptrs[MAXADDRS + 1];
75
76static struct hostent host;
77static char *host_aliases[MAXALIASES];
78static char hostbuf[BUFSIZ+1];
79static struct in_addr host_addr;
80static FILE *hostf = NULL;
81static char hostaddr[MAXADDRS];
82static char *host_addrs[2];
83static int stayopen = 0;
84char *strpbrk();
85
86#if PACKETSZ > 1024
87#define MAXPACKET PACKETSZ
88#else
89#define MAXPACKET 1024
90#endif
91
92typedef union {
93 HEADER hdr;
94 u_char buf[MAXPACKET];
95} querybuf;
96
97typedef union {
98 int32_t al;
99 char ac;
100} align;
101
102extern int h_errno;
103
104static struct hostent *
105getanswer(answer, anslen, iquery)
106 querybuf *answer;
107 int anslen;
108 int iquery;
109{
110 register HEADER *hp;
111 register u_char *cp;

--- 129 unchanged lines hidden (view full) ---

241 return (&host);
242 } else {
243 h_errno = TRY_AGAIN;
244 return ((struct hostent *) NULL);
245 }
246}
247
248struct hostent *
249gethostbyname(name)
250 const char *name;
251{
252 querybuf buf;
253 register const char *cp;
254 int n;
255 extern struct hostent *_gethtbyname();
256
257 /*

--- 32 unchanged lines hidden (view full) ---

290 break;
291 }
292
293 if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) {
294#ifdef DEBUG
295 if (_res.options & RES_DEBUG)
296 printf("res_search failed\n");
297#endif
298 if (errno == ECONNREFUSED)
299 return (_gethtbyname(name));
300 else
301 return ((struct hostent *) NULL);
302 }
303 return (getanswer(&buf, n, 0));
304}
305
306struct hostent *
307gethostbyaddr(addr, len, type)
308 const char *addr;
309 int len, type;
310{
311 int n;
312 querybuf buf;
313 register struct hostent *hp;
314 char qbuf[MAXDNAME];
315 extern struct hostent *_gethtbyaddr();

--- 6 unchanged lines hidden (view full) ---

322 ((unsigned)addr[1] & 0xff),
323 ((unsigned)addr[0] & 0xff));
324 n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof(buf));
325 if (n < 0) {
326#ifdef DEBUG
327 if (_res.options & RES_DEBUG)
328 printf("res_query failed\n");
329#endif
330 if (errno == ECONNREFUSED)
331 return (_gethtbyaddr(addr, len, type));
332 return ((struct hostent *) NULL);
333 }
334 hp = getanswer(&buf, n, 1);
335 if (hp == NULL)
336 return ((struct hostent *) NULL);
337 hp->h_addrtype = type;
338 hp->h_length = len;
339 h_addr_ptrs[0] = (char *)&host_addr;

--- 105 unchanged lines hidden (view full) ---

445
446 _sethtent(0);
447 while (p = _gethtent())
448 if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
449 break;
450 _endhtent();
451 return (p);
452}