interface.h revision 147904
117680Spst/* 298527Sfenner * Copyright (c) 1988-2002 317680Spst * The Regents of the University of California. All rights reserved. 417680Spst * 517680Spst * Redistribution and use in source and binary forms, with or without 617680Spst * modification, are permitted provided that: (1) source code distributions 717680Spst * retain the above copyright notice and this paragraph in its entirety, (2) 817680Spst * distributions including binary code include the above copyright notice and 917680Spst * this paragraph in its entirety in the documentation or other materials 1017680Spst * provided with the distribution, and (3) all advertising materials mentioning 1117680Spst * features or use of this software display the following acknowledgement: 1217680Spst * ``This product includes software developed by the University of California, 1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1417680Spst * the University nor the names of its contributors may be used to endorse 1517680Spst * or promote products derived from this software without specific prior 1617680Spst * written permission. 1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2017680Spst * 2198527Sfenner * 22146778Ssam * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.244 2005/04/06 21:33:27 mcr Exp $ (LBL) 2353146Sbrian * $FreeBSD: head/contrib/tcpdump/interface.h 147904 2005-07-11 04:14:02Z sam $ 2417680Spst */ 2517680Spst 2617680Spst#ifndef tcpdump_interface_h 2717680Spst#define tcpdump_interface_h 2817680Spst 2917680Spst#ifdef HAVE_OS_PROTO_H 3017680Spst#include "os-proto.h" 3117680Spst#endif 3217680Spst 3375118Sfenner#ifndef HAVE___ATTRIBUTE__ 3475118Sfenner#define __attribute__(x) 3575118Sfenner#endif 3675118Sfenner 3775118Sfenner/* snprintf et al */ 3875118Sfenner 3975118Sfenner#include <stdarg.h> 4075118Sfenner 41147904Ssam#if HAVE_STDINT_H 42147904Ssam#include <stdint.h> 43147904Ssam#endif 44147904Ssam 4575118Sfenner#if !defined(HAVE_SNPRINTF) 4698527Sfennerint snprintf(char *, size_t, const char *, ...) 4798527Sfenner __attribute__((format(printf, 3, 4))); 4875118Sfenner#endif 4975118Sfenner 5075118Sfenner#if !defined(HAVE_VSNPRINTF) 5198527Sfennerint vsnprintf(char *, size_t, const char *, va_list) 5298527Sfenner __attribute__((format(printf, 3, 0))); 5375118Sfenner#endif 5475118Sfenner 5575118Sfenner#ifndef HAVE_STRLCAT 5698527Sfennerextern size_t strlcat(char *, const char *, size_t); 5775118Sfenner#endif 5875118Sfenner#ifndef HAVE_STRLCPY 5998527Sfennerextern size_t strlcpy(char *, const char *, size_t); 6075118Sfenner#endif 6175118Sfenner 6298527Sfenner#ifndef HAVE_STRDUP 6398527Sfennerextern char *strdup(const char *); 6498527Sfenner#endif 6598527Sfenner 66127675Sbms#ifndef HAVE_STRSEP 67127675Sbmsextern char *strsep(char **, const char *); 68127675Sbms#endif 69127675Sbms 7017680Spst#define PT_VAT 1 /* Visual Audio Tool */ 7117680Spst#define PT_WB 2 /* distributed White Board */ 7217680Spst#define PT_RPC 3 /* Remote Procedure Call */ 7317680Spst#define PT_RTP 4 /* Real-Time Applications protocol */ 7417680Spst#define PT_RTCP 5 /* Real-Time Applications control protocol */ 7556896Sfenner#define PT_SNMP 6 /* Simple Network Management Protocol */ 7675118Sfenner#define PT_CNFP 7 /* Cisco NetFlow protocol */ 77127675Sbms#define PT_TFTP 8 /* trivial file transfer protocol */ 78127675Sbms#define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ 7917680Spst 8026180Sfenner#ifndef min 8126180Sfenner#define min(a,b) ((a)>(b)?(b):(a)) 8226180Sfenner#endif 8326180Sfenner#ifndef max 8426180Sfenner#define max(a,b) ((b)>(a)?(b):(a)) 8526180Sfenner#endif 8626180Sfenner 8726180Sfenner/* 8826180Sfenner * The default snapshot length. This value allows most printers to print 8926180Sfenner * useful information while keeping the amount of unwanted data down. 9026180Sfenner */ 9198527Sfenner#ifndef INET6 9298527Sfenner#define DEFAULT_SNAPLEN 68 /* ether + IPv4 + TCP + 14 */ 9356896Sfenner#else 9498527Sfenner#define DEFAULT_SNAPLEN 96 /* ether + IPv6 + TCP + 22 */ 9556896Sfenner#endif 9626180Sfenner 9726180Sfenner#ifndef BIG_ENDIAN 9826180Sfenner#define BIG_ENDIAN 4321 9926180Sfenner#define LITTLE_ENDIAN 1234 10026180Sfenner#endif 10126180Sfenner 10226180Sfenner#define ESRC(ep) ((ep)->ether_shost) 10326180Sfenner#define EDST(ep) ((ep)->ether_dhost) 10426180Sfenner 10526180Sfenner#ifndef NTOHL 10626180Sfenner#define NTOHL(x) (x) = ntohl(x) 10726180Sfenner#define NTOHS(x) (x) = ntohs(x) 10826180Sfenner#define HTONL(x) (x) = htonl(x) 10926180Sfenner#define HTONS(x) (x) = htons(x) 11026180Sfenner#endif 11126180Sfenner#endif 11226180Sfenner 11317680Spstextern char *program_name; /* used to generate self-identifying messages */ 11417680Spst 11517680Spstextern int32_t thiszone; /* seconds offset from gmt to local time */ 11617680Spst 11798348Sfenner/* 11898348Sfenner * True if "l" bytes of "var" were captured. 11998348Sfenner * 12098348Sfenner * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 12198348Sfenner * that "snapend - (l)" underflows. 12298348Sfenner * 12398348Sfenner * The check is for <= rather than < because "l" might be 0. 12498348Sfenner */ 12598348Sfenner#define TTEST2(var, l) (snapend - (l) <= snapend && \ 12698348Sfenner (const u_char *)&(var) <= snapend - (l)) 12726180Sfenner 12826180Sfenner/* True if "var" was captured */ 12926180Sfenner#define TTEST(var) TTEST2(var, sizeof(var)) 13026180Sfenner 13126180Sfenner/* Bail if "l" bytes of "var" were not captured */ 13226180Sfenner#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 13326180Sfenner 13426180Sfenner/* Bail if "var" was not captured */ 13517680Spst#define TCHECK(var) TCHECK2(var, sizeof(var)) 13617680Spst 13717680Spstextern void ts_print(const struct timeval *); 13856896Sfennerextern void relts_print(int); 13917680Spst 14017680Spstextern int fn_print(const u_char *, const u_char *); 14117680Spstextern int fn_printn(const u_char *, u_int, const u_char *); 142147904Ssamextern int fn_printzp(const u_char *, u_int, const u_char *); 143127675Sbmsextern int mask2plen(u_int32_t); 14498527Sfennerextern const char *tok2strary_internal(const char **, int, const char *, int); 14598527Sfenner#define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) 14617680Spst 14798527Sfennerextern const char *dnaddr_string(u_short); 14817680Spst 14975118Sfennerextern void error(const char *, ...) 15075118Sfenner __attribute__((noreturn, format (printf, 1, 2))); 15117680Spstextern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2))); 15217680Spst 15317680Spstextern char *read_infile(char *); 15417680Spstextern char *copy_argv(char **); 15517680Spst 15675118Sfennerextern void safeputchar(int); 15775118Sfennerextern void safeputs(const char *); 15875118Sfenner 159146778Ssamextern const char *isonsap_string(const u_char *, register u_int); 16098527Sfennerextern const char *llcsap_string(u_char); 16198527Sfennerextern const char *protoid_string(const u_char *); 16298527Sfennerextern const char *ipxsap_string(u_short); 16398527Sfennerextern const char *dnname_string(u_short); 16498527Sfennerextern const char *dnnum_string(u_short); 16517680Spst 16617680Spst/* The printer routines. */ 16717680Spst 16898527Sfenner#include <pcap.h> 16917680Spst 170127675Sbmsextern int print_unknown_data(const u_char *, const char *,int); 171146778Ssamextern void ascii_print_with_offset(const char *, const u_char *, u_int, u_int); 172146778Ssamextern void ascii_print(const char *, const u_char *, u_int); 173146778Ssamextern void hex_print_with_offset(const char *, const u_char *, u_int, u_int); 174127675Sbmsextern void telnet_print(const u_char *, u_int); 175146778Ssamextern void hex_print(const char *, const u_char *, u_int); 17675118Sfennerextern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *); 17726180Sfennerextern int llc_print(const u_char *, u_int, u_int, const u_char *, 17875118Sfenner const u_char *, u_short *); 179147904Ssamextern int snap_print(const u_char *, u_int, u_int, u_short *, u_int); 18026180Sfennerextern void aarp_print(const u_char *, u_int); 181127675Sbmsextern void aodv_print(const u_char *, u_int, int); 18217680Spstextern void atalk_print(const u_char *, u_int); 183127675Sbmsextern void atm_print(u_int, u_int, u_int, const u_char *, u_int, u_int); 184127675Sbmsextern u_int atm_if_print(const struct pcap_pkthdr *, const u_char *); 185127675Sbmsextern u_int sunatm_if_print(const struct pcap_pkthdr *, const u_char *); 186147904Ssamextern int oam_print(const u_char *, u_int, u_int); 187127675Sbmsextern void bootp_print(const u_char *, u_int); 18856896Sfennerextern void bgp_print(const u_char *, int); 18998527Sfennerextern void beep_print(const u_char *, u_int); 190127675Sbmsextern void cnfp_print(const u_char *, const u_char *); 19117680Spstextern void decnet_print(const u_char *, u_int, u_int); 19226180Sfennerextern void default_print(const u_char *, u_int); 19326180Sfennerextern void dvmrp_print(const u_char *, u_int); 194146778Ssamextern void egp_print(const u_char *, u_int); 195127675Sbmsextern u_int enc_if_print(const struct pcap_pkthdr *, const u_char *); 196127675Sbmsextern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *); 197127675Sbmsextern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *); 198127675Sbmsextern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *); 199127675Sbmsextern void ether_print(const u_char *, u_int, u_int); 200127675Sbmsextern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *); 201127675Sbmsextern u_int token_print(const u_char *, u_int, u_int); 202127675Sbmsextern u_int token_if_print(const struct pcap_pkthdr *, const u_char *); 203127675Sbmsextern void fddi_print(const u_char *, u_int, u_int); 204127675Sbmsextern u_int fddi_if_print(const struct pcap_pkthdr *, const u_char *); 205127675Sbmsextern u_int fr_if_print(const struct pcap_pkthdr *, const u_char *); 206147904Ssamextern u_int fr_print(register const u_char *, u_int); 207127675Sbmsextern u_int ieee802_11_if_print(const struct pcap_pkthdr *, const u_char *); 208127675Sbmsextern u_int ieee802_11_radio_if_print(const struct pcap_pkthdr *, 20998527Sfenner const u_char *); 210127675Sbmsextern u_int ap1394_if_print(const struct pcap_pkthdr *, const u_char *); 21126180Sfennerextern void gre_print(const u_char *, u_int); 212127675Sbmsextern void icmp_print(const u_char *, u_int, const u_char *, int); 21398527Sfennerextern void igmp_print(const u_char *, u_int); 21426180Sfennerextern void igrp_print(const u_char *, u_int, const u_char *); 21575118Sfennerextern void ipN_print(const u_char *, u_int); 216127675Sbmsextern u_int ipfc_if_print(const struct pcap_pkthdr *, const u_char *); 21717680Spstextern void ipx_print(const u_char *, u_int); 218127675Sbmsextern void isoclns_print(const u_char *, u_int, u_int); 219127675Sbmsextern void krb_print(const u_char *); 220127675Sbmsextern u_int llap_print(const u_char *, u_int); 221127675Sbmsextern u_int ltalk_if_print(const struct pcap_pkthdr *, const u_char *); 22298527Sfennerextern void msdp_print(const unsigned char *, u_int); 22317680Spstextern void nfsreply_print(const u_char *, u_int, const u_char *); 22417680Spstextern void nfsreq_print(const u_char *, u_int, const u_char *); 225127675Sbmsextern void ns_print(const u_char *, u_int, int); 22617680Spstextern void ntp_print(const u_char *, u_int); 227127675Sbmsextern u_int null_if_print(const struct pcap_pkthdr *, const u_char *); 22817680Spstextern void ospf_print(const u_char *, u_int, const u_char *); 22956896Sfennerextern void pimv1_print(const u_char *, u_int); 23056896Sfennerextern void cisco_autorp_print(const u_char *, u_int); 231127675Sbmsextern void rsvp_print(const u_char *, u_int); 232127675Sbmsextern void ldp_print(const u_char *, u_int); 233146778Ssamextern void lmp_print(const u_char *, u_int); 234146778Ssamextern void lspping_print(const u_char *, u_int); 235146778Ssamextern void eigrp_print(const u_char *, u_int); 23656896Sfennerextern void mobile_print(const u_char *, u_int); 23726180Sfennerextern void pim_print(const u_char *, u_int); 238127675Sbmsextern u_int pppoe_print(const u_char *, u_int); 239127675Sbmsextern u_int ppp_print(register const u_char *, u_int); 240127675Sbmsextern u_int ppp_if_print(const struct pcap_pkthdr *, const u_char *); 241127675Sbmsextern u_int ppp_hdlc_if_print(const struct pcap_pkthdr *, const u_char *); 242127675Sbmsextern u_int ppp_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); 243127675Sbmsextern u_int pppoe_if_print(const struct pcap_pkthdr *, const u_char *); 244127675Sbmsextern u_int prism_if_print(const struct pcap_pkthdr *, const u_char *); 245146778Ssamextern void q933_print(const u_char *, u_int); 246127675Sbmsextern int vjc_print(register const char *, u_short); 247127675Sbmsextern u_int raw_if_print(const struct pcap_pkthdr *, const u_char *); 24817680Spstextern void rip_print(const u_char *, u_int); 249127675Sbmsextern u_int sl_if_print(const struct pcap_pkthdr *, const u_char *); 250127675Sbmsextern void lane_print(const u_char *, u_int, u_int); 251127675Sbmsextern u_int lane_if_print(const struct pcap_pkthdr *, const u_char *); 252127675Sbmsextern u_int cip_if_print(const struct pcap_pkthdr *, const u_char *); 253127675Sbmsextern u_int sl_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); 254127675Sbmsextern u_int chdlc_if_print(const struct pcap_pkthdr *, const u_char *); 255146778Ssamextern u_int juniper_atm1_print(const struct pcap_pkthdr *, const u_char *); 256146778Ssamextern u_int juniper_atm2_print(const struct pcap_pkthdr *, const u_char *); 257147904Ssamextern u_int juniper_mfr_print(const struct pcap_pkthdr *, register const u_char *); 258146778Ssamextern u_int juniper_mlfr_print(const struct pcap_pkthdr *, const u_char *); 259146778Ssamextern u_int juniper_mlppp_print(const struct pcap_pkthdr *, const u_char *); 260147904Ssamextern u_int juniper_pppoe_print(const struct pcap_pkthdr *, const u_char *); 261147904Ssamextern u_int juniper_pppoe_atm_print(const struct pcap_pkthdr *, const u_char *); 262147904Ssamextern u_int juniper_ggsn_print(const struct pcap_pkthdr *, const u_char *); 263147904Ssamextern u_int juniper_es_print(const struct pcap_pkthdr *, const u_char *); 264147904Ssamextern u_int juniper_monitor_print(const struct pcap_pkthdr *, const u_char *); 265147904Ssamextern u_int juniper_services_print(const struct pcap_pkthdr *, const u_char *); 266127675Sbmsextern u_int sll_if_print(const struct pcap_pkthdr *, const u_char *); 26717680Spstextern void snmp_print(const u_char *, u_int); 26817680Spstextern void sunrpcrequest_print(const u_char *, u_int, const u_char *); 269146778Ssamextern u_int symantec_if_print(const struct pcap_pkthdr *, const u_char *); 27075118Sfennerextern void tcp_print(const u_char *, u_int, const u_char *, int); 27117680Spstextern void tftp_print(const u_char *, u_int); 272127675Sbmsextern void timed_print(const u_char *); 27375118Sfennerextern void udp_print(const u_char *, u_int, const u_char *, int); 27417680Spstextern void wb_print(const void *, u_int); 275127675Sbmsextern int ah_print(register const u_char *); 276127675Sbmsextern int ipcomp_print(register const u_char *, int *); 27756896Sfennerextern void rx_print(register const u_char *, int, int, int, u_char *); 27898527Sfennerextern void netbeui_print(u_short, const u_char *, int); 27998527Sfennerextern void ipx_netbios_print(const u_char *, u_int); 28056896Sfennerextern void nbt_tcp_print(const u_char *, int); 28198527Sfennerextern void nbt_udp137_print(const u_char *, int); 28298527Sfennerextern void nbt_udp138_print(const u_char *, int); 28356896Sfennerextern char *smb_errstr(int, int); 284146778Ssamextern const char *nt_errstr(u_int32_t); 28556896Sfennerextern void print_data(const unsigned char *, int); 28656896Sfennerextern void l2tp_print(const u_char *, u_int); 28798527Sfennerextern void vrrp_print(const u_char *, u_int, int); 288147904Ssamextern void pgm_print(const u_char *, u_int, const u_char *); 289127675Sbmsextern void cdp_print(const u_char *, u_int, u_int); 29098527Sfennerextern void stp_print(const u_char *, u_int); 29175118Sfennerextern void radius_print(const u_char *, u_int); 29298527Sfennerextern void lwres_print(const u_char *, u_int); 293127675Sbmsextern void pptp_print(const u_char *); 29498527Sfennerextern void sctp_print(const u_char *, const u_char *, u_int); 29598527Sfennerextern void mpls_print(const u_char *, u_int); 296127675Sbmsextern void mpls_lsp_ping_print(const u_char *, u_int); 29798527Sfennerextern void zephyr_print(const u_char *, int); 29898527Sfennerextern void hsrp_print(const u_char *, u_int); 299127675Sbmsextern void bfd_print(const u_char *, u_int, u_int); 300146778Ssamextern void sip_print(const u_char *, u_int); 301146778Ssamextern void syslog_print(const u_char *, u_int); 30256896Sfenner 30356896Sfenner#ifdef INET6 30498527Sfennerextern void ip6_print(const u_char *, u_int); 30556896Sfennerextern void ip6_opt_print(const u_char *, int); 30656896Sfennerextern int hbhopt_print(const u_char *); 30756896Sfennerextern int dstopt_print(const u_char *); 30856896Sfennerextern int frag6_print(const u_char *, const u_char *); 309127675Sbmsextern int mobility_print(const u_char *, const u_char *); 310127675Sbmsextern void icmp6_print(const u_char *, u_int, const u_char *, int); 31198527Sfennerextern void ripng_print(const u_char *, unsigned int); 31256896Sfennerextern int rt6_print(const u_char *, const u_char *); 31356896Sfennerextern void ospf6_print(const u_char *, u_int); 314127675Sbmsextern void dhcp6_print(const u_char *, u_int); 31556896Sfenner#endif /*INET6*/ 31698527Sfennerextern u_short in_cksum(const u_short *, register u_int, int); 317127675Sbmsextern u_int16_t in_cksum_shouldbe(u_int16_t, u_int16_t); 31898527Sfenner 31998527Sfenner#ifndef HAVE_BPF_DUMP 32098527Sfennerstruct bpf_program; 32198527Sfenner 32298527Sfennerextern void bpf_dump(struct bpf_program *, int); 323146778Ssam 32498527Sfenner#endif 325146778Ssam 326146778Ssam#include "netdissect.h" 327146778Ssam 328146778Ssam/* forward compatibility */ 329146778Ssam 330147904Ssamextern netdissect_options *gndo; 331146778Ssam 332146778Ssam#define eflag gndo->ndo_eflag 333146778Ssam#define fflag gndo->ndo_fflag 334146778Ssam#define nflag gndo->ndo_nflag 335146778Ssam#define Nflag gndo->ndo_Nflag 336146778Ssam#define Oflag gndo->ndo_Oflag 337146778Ssam#define pflag gndo->ndo_pflag 338146778Ssam#define qflag gndo->ndo_qflag 339146778Ssam#define Rflag gndo->ndo_Rflag 340146778Ssam#define sflag gndo->ndo_sflag 341146778Ssam#define Sflag gndo->ndo_Sflag 342146778Ssam#define tflag gndo->ndo_tflag 343146778Ssam#define Uflag gndo->ndo_Uflag 344146778Ssam#define uflag gndo->ndo_uflag 345146778Ssam#define vflag gndo->ndo_vflag 346146778Ssam#define xflag gndo->ndo_xflag 347146778Ssam#define Xflag gndo->ndo_Xflag 348146778Ssam#define Cflag gndo->ndo_Cflag 349146778Ssam#define Aflag gndo->ndo_Aflag 350146778Ssam#define packettype gndo->ndo_packettype 351146778Ssam#define tcpmd5secret gndo->ndo_tcpmd5secret 352146778Ssam#define Wflag gndo->ndo_Wflag 353146778Ssam#define WflagChars gndo->ndo_WflagChars 354146778Ssam#define Cflag_count gndo->ndo_Cflag_count 355146778Ssam#define snaplen gndo->ndo_snaplen 356146778Ssam#define snapend gndo->ndo_snapend 357146778Ssam 358