addrtoname.c (26183) | addrtoname.c (39300) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 | 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
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: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning --- 7 unchanged lines hidden (view full) --- 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Internet, ethernet, port, and protocol string to address 22 * and address to string conversion routines 23 */ 24#ifndef lint 25static const char rcsid[] = | 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: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning --- 7 unchanged lines hidden (view full) --- 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Internet, ethernet, port, and protocol string to address 22 * and address to string conversion routines 23 */ 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: addrtoname.c,v 1.54 96/12/05 22:10:19 leres Exp $ (LBL)"; | 26 "@(#) $Header: addrtoname.c,v 1.61 97/06/15 13:20:18 leres Exp $ (LBL)"; |
27#endif 28 29#include <sys/types.h> 30#include <sys/socket.h> 31#include <sys/time.h> 32 33#if __STDC__ 34struct mbuf; --- 5 unchanged lines hidden (view full) --- 40#include <net/ethernet.h> 41 42#include <arpa/inet.h> 43 44#include <ctype.h> 45#include <netdb.h> 46#include <pcap.h> 47#include <pcap-namedb.h> | 27#endif 28 29#include <sys/types.h> 30#include <sys/socket.h> 31#include <sys/time.h> 32 33#if __STDC__ 34struct mbuf; --- 5 unchanged lines hidden (view full) --- 40#include <net/ethernet.h> 41 42#include <arpa/inet.h> 43 44#include <ctype.h> 45#include <netdb.h> 46#include <pcap.h> 47#include <pcap-namedb.h> |
48#ifdef HAVE_MALLOC_H 49#include <malloc.h> 50#endif 51#ifdef HAVE_MEMORY_H 52#include <memory.h> 53#endif |
|
48#include <signal.h> 49#include <stdio.h> 50#include <string.h> 51#include <stdlib.h> 52#include <unistd.h> 53 54#include "interface.h" 55#include "addrtoname.h" 56#include "llc.h" | 54#include <signal.h> 55#include <stdio.h> 56#include <string.h> 57#include <stdlib.h> 58#include <unistd.h> 59 60#include "interface.h" 61#include "addrtoname.h" 62#include "llc.h" |
63#include "savestr.h" 64#include "setsignal.h" |
|
57 58/* Forwards */ 59static RETSIGTYPE nohostname(int); 60 61/* 62 * hash tables for whatever-to-name translations 63 */ 64 --- 138 unchanged lines hidden (view full) --- 203 return (p->name); 204 } 205 p->addr = addr; 206 p->nxt = newhnamemem(); 207 208 /* 209 * Only print names when: 210 * (1) -n was not given. | 65 66/* Forwards */ 67static RETSIGTYPE nohostname(int); 68 69/* 70 * hash tables for whatever-to-name translations 71 */ 72 --- 138 unchanged lines hidden (view full) --- 211 return (p->name); 212 } 213 p->addr = addr; 214 p->nxt = newhnamemem(); 215 216 /* 217 * Only print names when: 218 * (1) -n was not given. |
211 * (2) Address is foreign and -f was given. If -f was not 212 * present, f_netmask and f_local are 0 and the second 213 * test will succeed. 214 * (3) The host portion is not 0 (i.e., a network address). 215 * (4) The host portion is not broadcast. | 219 * (2) Address is foreign and -f was given. (If -f was not 220 * give, f_netmask and f_local are 0 and the test 221 * evaluates to true) 222 * (3) -a was given or the host portion is not all ones 223 * nor all zeros (i.e. not a network or broadcast address) |
216 */ | 224 */ |
217 if (!nflag && (addr & f_netmask) == f_localnet 218 && (addr &~ netmask) != 0 && (addr | netmask) != 0xffffffff) { | 225 if (!nflag && 226 (addr & f_netmask) == f_localnet && 227 (aflag || 228 !((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff))) { |
219 if (!setjmp(getname_env)) { | 229 if (!setjmp(getname_env)) { |
220 (void)signal(SIGALRM, nohostname); | 230 (void)setsignal(SIGALRM, nohostname); |
221 (void)alarm(20); 222 hp = gethostbyaddr((char *)&addr, 4, AF_INET); 223 (void)alarm(0); 224 if (hp) { 225 char *dotp; 226 227 p->name = savestr(hp->h_name); 228 if (Nflag) { --- 73 unchanged lines hidden (view full) --- 302 else 303 tp = tp->e_nxt; 304 tp->e_addr0 = i; 305 tp->e_addr1 = j; 306 tp->e_addr2 = k; 307 tp->e_nsap = (u_char *)malloc(nlen + 1); 308 if (tp->e_nsap == NULL) 309 error("lookup_nsap: malloc"); | 231 (void)alarm(20); 232 hp = gethostbyaddr((char *)&addr, 4, AF_INET); 233 (void)alarm(0); 234 if (hp) { 235 char *dotp; 236 237 p->name = savestr(hp->h_name); 238 if (Nflag) { --- 73 unchanged lines hidden (view full) --- 312 else 313 tp = tp->e_nxt; 314 tp->e_addr0 = i; 315 tp->e_addr1 = j; 316 tp->e_addr2 = k; 317 tp->e_nsap = (u_char *)malloc(nlen + 1); 318 if (tp->e_nsap == NULL) 319 error("lookup_nsap: malloc"); |
310 memcpy(tp->e_nsap, nsap, nlen + 1); | 320 memcpy((char *)tp->e_nsap, (char *)nsap, nlen + 1); |
311 tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); 312 if (tp->e_nxt == NULL) 313 error("lookup_nsap: calloc"); 314 315 return tp; 316} 317 318/* Find the hash node that corresponds the protoid 'pi'. */ --- 373 unchanged lines hidden (view full) --- 692 693/* 694 * Initialize the address to name translation machinery. We map all 695 * non-local IP addresses to numeric addresses if fflag is true (i.e., 696 * to prevent blocking on the nameserver). localnet is the IP address 697 * of the local network. mask is its subnet mask. 698 */ 699void | 321 tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); 322 if (tp->e_nxt == NULL) 323 error("lookup_nsap: calloc"); 324 325 return tp; 326} 327 328/* Find the hash node that corresponds the protoid 'pi'. */ --- 373 unchanged lines hidden (view full) --- 702 703/* 704 * Initialize the address to name translation machinery. We map all 705 * non-local IP addresses to numeric addresses if fflag is true (i.e., 706 * to prevent blocking on the nameserver). localnet is the IP address 707 * of the local network. mask is its subnet mask. 708 */ 709void |
700init_addrtoname(int fflag, u_int32_t localnet, u_int32_t mask) | 710init_addrtoname(u_int32_t localnet, u_int32_t mask) |
701{ 702 netmask = mask; 703 if (fflag) { 704 f_localnet = localnet; 705 f_netmask = mask; 706 } 707 if (nflag) 708 /* --- 49 unchanged lines hidden --- | 711{ 712 netmask = mask; 713 if (fflag) { 714 f_localnet = localnet; 715 f_netmask = mask; 716 } 717 if (nflag) 718 /* --- 49 unchanged lines hidden --- |