1/* 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 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 --- 6 unchanged lines hidden (view full) --- 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Name to id translation routines used by the scanner. 22 * These functions are not time critical. |
23 * 24 * $FreeBSD: head/contrib/libpcap/nametoaddr.c 56891 2000-01-30 00:43:38Z fenner $ |
25 */ 26 27#ifndef lint 28static const char rcsid[] = |
29 "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.51 1999/11/25 08:25:35 itojun Exp $ (LBL)"; |
30#endif 31 32#include <sys/param.h> 33#include <sys/types.h> /* concession to AIX */ 34#include <sys/socket.h> 35#include <sys/time.h> 36 37#if __STDC__ 38struct mbuf; 39struct rtentry; 40#endif 41 42#include <net/if.h> 43#include <net/ethernet.h> 44#include <netinet/in.h> 45#include <arpa/inet.h> |
46#ifdef INET6 47#include <netdb.h> 48#include <sys/socket.h> 49#endif /*INET6*/ |
50 51#include <ctype.h> 52#include <errno.h> 53#include <stdlib.h> 54#include <memory.h> 55#include <netdb.h> 56#include <stdio.h> 57 --- 13 unchanged lines hidden (view full) --- 71#endif 72 73static inline int xdtoi(int); 74 75/* 76 * Convert host name to internet address. 77 * Return 0 upon failure. 78 */ |
79#ifndef INET6 |
80bpf_u_int32 ** 81pcap_nametoaddr(const char *name) 82{ 83#ifndef h_addr 84 static bpf_u_int32 *hlist[2]; 85#endif 86 bpf_u_int32 **p; 87 struct hostent *hp; --- 7 unchanged lines hidden (view full) --- 95 for (p = (bpf_u_int32 **)hp->h_addr_list; *p; ++p) 96 NTOHL(**p); 97 return (bpf_u_int32 **)hp->h_addr_list; 98#endif 99 } 100 else 101 return 0; 102} |
103#else 104struct addrinfo * 105pcap_nametoaddr(const char *name) 106{ 107 struct addrinfo hints, *res; 108 int error; |
109 |
110 memset(&hints, 0, sizeof(hints)); 111 hints.ai_family = PF_UNSPEC; 112 hints.ai_socktype = SOCK_STREAM; /*not really*/ 113 error = getaddrinfo(name, NULL, &hints, &res); 114 if (error) 115 return NULL; 116 else 117 return res; 118} 119#endif /*INET6*/ 120 |
121/* 122 * Convert net name to internet address. 123 * Return 0 upon failure. 124 */ 125bpf_u_int32 126pcap_nametonetaddr(const char *name) 127{ 128 struct netent *np; --- 72 unchanged lines hidden (view full) --- 201 202struct eproto { 203 char *s; 204 u_short p; 205}; 206 207/* Static data base of ether protocol types. */ 208struct eproto eproto_db[] = { |
209#if 0 210 /* The FreeBSD elf linker generates a request to copy this array 211 * (including its size) when you link with -lpcap. In order to 212 * not bump the major version number of this libpcap.so, we need 213 * to ensure that the array stays the same size. Since PUP is 214 * likely never seen in real life any more, it's the first to 215 * be sacrificed (in favor of ip6). 216 */ |
217 { "pup", ETHERTYPE_PUP }, |
218#endif |
219 { "xns", ETHERTYPE_NS }, 220 { "ip", ETHERTYPE_IP }, |
221#ifdef INET6 222 { "ip6", ETHERTYPE_IPV6 }, 223#endif |
224 { "arp", ETHERTYPE_ARP }, 225 { "rarp", ETHERTYPE_REVARP }, 226 { "sprite", ETHERTYPE_SPRITE }, 227 { "mopdl", ETHERTYPE_MOPDL }, 228 { "moprc", ETHERTYPE_MOPRC }, 229 { "decnet", ETHERTYPE_DN }, 230 { "lat", ETHERTYPE_LAT }, 231 { "sca", ETHERTYPE_SCA }, --- 129 unchanged lines hidden (view full) --- 361 } 362 break; 363 } 364 } 365 return (NULL); 366} 367#else 368 |
369#if !defined(sgi) && !defined(__NetBSD__) |
370extern int ether_hostton(char *, struct ether_addr *); 371#endif 372 373/* Use the os supplied routines */ 374u_char * 375pcap_ether_hostton(const char *name) 376{ 377 register u_char *ap; --- 31 unchanged lines hidden --- |