nametoaddr.c (146771) | nametoaddr.c (147897) |
---|---|
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 --- 7 unchanged lines hidden (view full) --- 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 * | 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 --- 7 unchanged lines hidden (view full) --- 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 146771 2005-05-29 18:09:04Z sam $ | 24 * $FreeBSD: head/contrib/libpcap/nametoaddr.c 147897 2005-07-11 03:43:25Z sam $ |
25 */ 26 27#ifndef lint 28static const char rcsid[] _U_ = | 25 */ 26 27#ifndef lint 28static const char rcsid[] _U_ = |
29 "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.77 2005/03/27 22:26:25 guy Exp $ (LBL)"; | 29 "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.77.2.3 2005/04/20 11:13:51 guy Exp $ (LBL)"; |
30#endif 31 32#ifdef HAVE_CONFIG_H 33#include "config.h" 34#endif 35 36#ifdef WIN32 37#include <pcap-stdinc.h> --- 33 unchanged lines hidden (view full) --- 71#endif /* HAVE_ETHER_HOSTTON */ 72#include <arpa/inet.h> 73#include <netdb.h> 74#endif /* WIN32 */ 75 76#include <ctype.h> 77#include <errno.h> 78#include <stdlib.h> | 30#endif 31 32#ifdef HAVE_CONFIG_H 33#include "config.h" 34#endif 35 36#ifdef WIN32 37#include <pcap-stdinc.h> --- 33 unchanged lines hidden (view full) --- 71#endif /* HAVE_ETHER_HOSTTON */ 72#include <arpa/inet.h> 73#include <netdb.h> 74#endif /* WIN32 */ 75 76#include <ctype.h> 77#include <errno.h> 78#include <stdlib.h> |
79#include <memory.h> | 79#include <string.h> |
80#include <stdio.h> 81 82#include "pcap-int.h" 83 84#include "gencode.h" 85#include <pcap-namedb.h> 86 87#ifdef HAVE_OS_PROTO_H --- 125 unchanged lines hidden (view full) --- 213 *port = 2049; 214 *proto = PROTO_UNDEF; 215 return 1; 216 } 217#endif 218 return 0; 219} 220 | 80#include <stdio.h> 81 82#include "pcap-int.h" 83 84#include "gencode.h" 85#include <pcap-namedb.h> 86 87#ifdef HAVE_OS_PROTO_H --- 125 unchanged lines hidden (view full) --- 213 *port = 2049; 214 *proto = PROTO_UNDEF; 215 return 1; 216 } 217#endif 218 return 0; 219} 220 |
221/* 222 * Convert a string in the form PPP-PPP, where correspond to ports, to 223 * a starting and ending port in a port range. 224 * Return 0 on failure. 225 */ |
|
221int | 226int |
227pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto) 228{ 229 u_int p1, p2; 230 char *off, *cpy; 231 int save_proto; 232 233 if (sscanf(name, "%d-%d", &p1, &p2) != 2) { 234 if ((cpy = strdup(name)) == NULL) 235 return 0; 236 237 if ((off = strchr(cpy, '-')) == NULL) { 238 free(cpy); 239 return 0; 240 } 241 242 *off = '\0'; 243 244 if (pcap_nametoport(cpy, port1, proto) == 0) { 245 free(cpy); 246 return 0; 247 } 248 save_proto = *proto; 249 250 if (pcap_nametoport(off + 1, port2, proto) == 0) { 251 free(cpy); 252 return 0; 253 } 254 255 if (*proto != save_proto) 256 *proto = PROTO_UNDEF; 257 } else { 258 *port1 = p1; 259 *port2 = p2; 260 *proto = PROTO_UNDEF; 261 } 262 263 return 1; 264} 265 266int |
|
222pcap_nametoproto(const char *str) 223{ 224 struct protoent *p; 225 226 p = getprotobyname(str); 227 if (p != 0) 228 return p->p_proto; 229 else --- 189 unchanged lines hidden (view full) --- 419 break; 420 } 421 } 422 return (NULL); 423} 424#else 425 426#if !defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON | 267pcap_nametoproto(const char *str) 268{ 269 struct protoent *p; 270 271 p = getprotobyname(str); 272 if (p != 0) 273 return p->p_proto; 274 else --- 189 unchanged lines hidden (view full) --- 464 break; 465 } 466 } 467 return (NULL); 468} 469#else 470 471#if !defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON |
472#ifndef HAVE_STRUCT_ETHER_ADDR 473struct ether_addr { 474 unsigned char ether_addr_octet[6]; 475}; 476#endif |
|
427extern int ether_hostton(const char *, struct ether_addr *); 428#endif 429 430/* Use the os supplied routines */ 431u_char * 432pcap_ether_hostton(const char *name) 433{ 434 register u_char *ap; --- 32 unchanged lines hidden --- | 477extern int ether_hostton(const char *, struct ether_addr *); 478#endif 479 480/* Use the os supplied routines */ 481u_char * 482pcap_ether_hostton(const char *name) 483{ 484 register u_char *ap; --- 32 unchanged lines hidden --- |