1/* |
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[] = |
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> |
48#ifdef HAVE_MALLOC_H 49#include <malloc.h> 50#endif 51#ifdef HAVE_MEMORY_H 52#include <memory.h> 53#endif |
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" |
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. |
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) |
224 */ |
225 if (!nflag && 226 (addr & f_netmask) == f_localnet && 227 (aflag || 228 !((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff))) { |
229 if (!setjmp(getname_env)) { |
230 (void)setsignal(SIGALRM, nohostname); |
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"); |
320 memcpy((char *)tp->e_nsap, (char *)nsap, nlen + 1); |
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 |
710init_addrtoname(u_int32_t localnet, u_int32_t mask) |
711{ 712 netmask = mask; 713 if (fflag) { 714 f_localnet = localnet; 715 f_netmask = mask; 716 } 717 if (nflag) 718 /* --- 49 unchanged lines hidden --- |