interface.h revision 1.72
1/* $OpenBSD: interface.h,v 1.72 2018/02/10 10:00:32 dlg Exp $ */ 2 3/* 4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 * 23 * @(#) $Id: interface.h,v 1.72 2018/02/10 10:00:32 dlg Exp $ (LBL) 24 */ 25 26#ifndef tcpdump_interface_h 27#define tcpdump_interface_h 28 29#ifdef HAVE_OS_PROTO_H 30#include "os-proto.h" 31#endif 32 33struct tok { 34 int v; /* value */ 35 char *s; /* string */ 36}; 37 38extern int aflag; /* translate network and broadcast addresses */ 39extern int dflag; /* print filter code */ 40extern int eflag; /* print ethernet header */ 41extern int fflag; /* don't translate "foreign" IP address */ 42extern int Iflag; /* include interface in output */ 43extern int nflag; /* leave addresses as numbers */ 44extern int Nflag; /* remove domains from printed host names */ 45extern int oflag; /* OS fingerprint */ 46extern int qflag; /* quick (shorter) output */ 47extern int Sflag; /* print raw TCP sequence numbers */ 48extern int tflag; /* print packet arrival time */ 49extern int vflag; /* verbose */ 50extern int xflag; /* print packet in hex */ 51extern int Xflag; /* print packet in hex/ascii */ 52 53extern int packettype; /* as specified by -T */ 54extern char *device; /* as specified by -i */ 55#define PT_VAT 1 /* Visual Audio Tool */ 56#define PT_WB 2 /* distributed White Board */ 57#define PT_RPC 3 /* Remote Procedure Call */ 58#define PT_RTP 4 /* Real-Time Applications protocol */ 59#define PT_RTCP 5 /* Real-Time Applications control protocol */ 60#define PT_CNFP 6 /* Cisco NetFlow protocol */ 61#define PT_VRRP 7 /* Virtual Router Redundancy protocol */ 62#define PT_TCP 8 /* TCP */ 63 64#ifndef min 65#define min(a,b) ((a)>(b)?(b):(a)) 66#endif 67#ifndef max 68#define max(a,b) ((b)>(a)?(b):(a)) 69#endif 70 71/* 72 * The default snapshot length. This value allows most printers to print 73 * useful information while keeping the amount of unwanted data down. 74 * In particular, it allows ethernet, tcp/ip headers, and a small amount 75 * of data, or to capture IPv6 and TCP headers after pflog encapsulation. 76 */ 77#define DEFAULT_SNAPLEN 116 78#define IEEE802_11_SNAPLEN (DEFAULT_SNAPLEN + 30) 79#define IEEE802_11_RADIO_SNAPLEN (IEEE802_11_SNAPLEN + 64) 80 81#ifndef BIG_ENDIAN 82#define BIG_ENDIAN 4321 83#define LITTLE_ENDIAN 1234 84#endif 85 86#ifdef ETHER_HEADER_HAS_EA 87#define ESRC(ep) ((ep)->ether_shost.ether_addr_octet) 88#define EDST(ep) ((ep)->ether_dhost.ether_addr_octet) 89#else 90#define ESRC(ep) ((ep)->ether_shost) 91#define EDST(ep) ((ep)->ether_dhost) 92#endif 93 94#ifdef ETHER_ARP_HAS_X 95#define SHA(ap) ((ap)->arp_xsha) 96#define THA(ap) ((ap)->arp_xtha) 97#define SPA(ap) ((ap)->arp_xspa) 98#define TPA(ap) ((ap)->arp_xtpa) 99#else 100#ifdef ETHER_ARP_HAS_EA 101#define SHA(ap) ((ap)->arp_sha.ether_addr_octet) 102#define THA(ap) ((ap)->arp_tha.ether_addr_octet) 103#else 104#define SHA(ap) ((ap)->arp_sha) 105#define THA(ap) ((ap)->arp_tha) 106#endif 107#define SPA(ap) ((ap)->arp_spa) 108#define TPA(ap) ((ap)->arp_tpa) 109#endif 110 111#ifndef NTOHL 112#define NTOHL(x) (x) = ntohl(x) 113#define NTOHS(x) (x) = ntohs(x) 114#define HTONL(x) (x) = htonl(x) 115#define HTONS(x) (x) = htons(x) 116#endif 117#endif 118 119extern char *program_name; /* used to generate self-identifying messages */ 120 121extern int32_t thiszone; /* seconds offset from gmt to local time */ 122 123extern int snaplen; 124/* global pointers to beginning and end of current packet (during printing) */ 125extern const u_char *packetp; 126extern const u_char *snapend; 127 128/* 129 * True if "l" bytes of "var" were captured. 130 * 131 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 132 * that "snapend - (l)" underflows. 133 * 134 * The check is for <= rather than < because "l" might be 0. 135 */ 136#define TTEST2(var, l) (snapend - (l) <= snapend && \ 137 (const u_char *)&(var) <= snapend - (l)) 138 139/* True if "var" was captured */ 140#define TTEST(var) TTEST2(var, sizeof(var)) 141 142/* Bail if "l" bytes of "var" were not captured */ 143#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 144 145/* Bail if "var" was not captured */ 146#define TCHECK(var) TCHECK2(var, sizeof(var)) 147 148struct timeval; 149struct bpf_timeval; 150 151extern void ts_print(const struct bpf_timeval *); 152 153extern int fn_print(const u_char *, const u_char *); 154extern int fn_printn(const u_char *, u_int, const u_char *); 155extern void relts_print(int); 156extern const char *tok2str(const struct tok *, const char *, int); 157extern char *dnaddr_string(u_short); 158extern void safeputs(const char *); 159extern void safeputchar(int); 160extern void printb(char *, unsigned short, char *); 161 162extern void wrapup(int); 163 164extern __dead void error(const char *, ...) 165 __attribute__((__format__ (printf, 1, 2))); 166extern void warning(const char *, ...) 167 __attribute__ ((__format__ (printf, 1, 2))); 168 169extern char *read_infile(char *); 170extern char *copy_argv(char * const *); 171 172extern char *isonsap_string(const u_char *); 173extern char *llcsap_string(u_char); 174extern char *protoid_string(const u_char *); 175extern char *dnname_string(u_short); 176extern char *dnnum_string(u_short); 177 178/* The printer routines. */ 179 180struct pcap_pkthdr; 181 182extern int ether_encap_print(u_short, const u_char *, u_int, u_int); 183extern int llc_print(const u_char *, u_int, u_int, const u_char *, 184 const u_char *); 185extern int pppoe_if_print(u_short, const u_char *, u_int, u_int); 186extern void aarp_print(const u_char *, u_int); 187extern void arp_print(const u_char *, u_int, u_int); 188extern void atalk_print(const u_char *, u_int); 189extern void atalk_print_llap(const u_char *, u_int); 190extern void atm_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 191extern void bootp_print(const u_char *, u_int, u_short, u_short); 192extern void bgp_print(const u_char *, int); 193extern void decnet_print(const u_char *, u_int, u_int); 194extern void default_print(const u_char *, u_int); 195extern void default_print_unaligned(const u_char *, u_int); 196extern void dvmrp_print(const u_char *, u_int); 197extern void egp_print(const u_char *, u_int, const u_char *); 198extern void enc_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 199extern void pflog_if_print(u_char *, const struct pcap_pkthdr *, 200 const u_char *); 201extern void pflog_old_if_print(u_char *, const struct pcap_pkthdr *, 202 const u_char *); 203extern void pfsync_if_print(u_char *, const struct pcap_pkthdr *, 204 const u_char *); 205extern void pfsync_ip_print(const u_char *, u_int, const u_char *); 206extern void ether_if_print(u_char *, const struct pcap_pkthdr *, 207 const u_char *); 208extern void ether_tryprint(const u_char *, u_int, int); 209extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 210extern void ppp_ether_if_print(u_char *, const struct pcap_pkthdr *, 211 const u_char *); 212extern void gre_print(const u_char *, u_int); 213extern void icmp_print(const u_char *, u_int, const u_char *); 214extern void ieee802_11_if_print(u_char *, const struct pcap_pkthdr *, 215 const u_char *); 216extern void ieee802_11_radio_if_print(u_char *, const struct pcap_pkthdr *, 217 const u_char *); 218extern void iapp_print(const u_char *, u_int); 219extern void igrp_print(const u_char *, u_int, const u_char *); 220extern void ip_print(const u_char *, u_int); 221extern void ipx_print(const u_char *, u_int); 222extern void isoclns_print(const u_char *, u_int, u_int, const u_char *, 223 const u_char *); 224extern void krb_print(const u_char *, u_int); 225extern void netbeui_print(u_short, const u_char *, const u_char *); 226extern void ipx_netbios_print(const u_char *, const u_char *); 227extern void nbt_tcp_print(const u_char *, int); 228extern void nbt_udp137_print(const u_char *data, int); 229extern void nbt_udp138_print(const u_char *data, int); 230extern char *smb_errstr(int, int); 231extern void print_data(const unsigned char *, int); 232extern void l2tp_print(const u_char *dat, u_int length); 233extern void vrrp_print(const u_char *bp, u_int len, int ttl); 234extern void carp_print(const u_char *bp, u_int len, int ttl); 235extern void hsrp_print(const u_char *, u_int); 236extern void vqp_print(const u_char *, u_int); 237extern void nfsreply_print(const u_char *, u_int, const u_char *); 238extern void nfsreq_print(const u_char *, u_int, const u_char *); 239extern void ns_print(const u_char *, u_int, int); 240extern void ntp_print(const u_char *, u_int); 241extern void loop_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 242extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 243extern void ospf_print(const u_char *, u_int, const u_char *); 244extern void mobile_print(const u_char *, u_int); 245extern void pim_print(const u_char *, u_int); 246extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 247extern void ppp_hdlc_if_print(u_char *, const struct pcap_pkthdr *, 248 const u_char *); 249extern void ppp_print(const u_char *, u_int); 250extern void ppp_hdlc_print(const u_char *, u_int); 251extern void raw_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 252extern void rip_print(const u_char *, u_int); 253extern void sl_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 254extern void sl_bsdos_if_print(u_char *, const struct pcap_pkthdr *, 255 const u_char *); 256extern void snmp_print(const u_char *, u_int); 257extern void sunrpcrequest_print(const u_char *, u_int, const u_char *); 258extern void cnfp_print(const u_char *, u_int, const u_char *); 259extern void tcp_print(const u_char *, u_int, const u_char *); 260extern void tftp_print(const u_char *, u_int); 261extern void timed_print(const u_char *, u_int); 262extern void udp_print(const u_char *, u_int, const u_char *); 263extern void wb_print(const void *, u_int); 264extern void ike_print(const u_char *, u_int); 265extern void udpencap_print(const u_char *, u_int, const u_char *); 266extern void ah_print(const u_char *, u_int, const u_char *); 267extern void esp_print(const u_char *, u_int, const u_char *); 268extern void cdp_print(const u_char *, u_int, u_int, const u_char *, 269 const u_char *); 270extern void stp_print(const u_char *, u_int); 271extern void radius_print(const u_char *, u_int); 272extern void lwres_print(const u_char *, u_int); 273extern void ether_print(const u_char *, u_int); 274extern void etherip_print(const u_char *, u_int, u_int); 275extern void ipcomp_print(const u_char *, u_int, const u_char *); 276extern void mpls_print(const u_char *, u_int); 277extern void lldp_print(const u_char *, u_int); 278extern void slow_print(const u_char *, u_int); 279extern void gtp_print(const u_char *, u_int, u_short, u_short); 280extern void ofp_print(const u_char *, u_int); 281extern void ofp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); 282extern void usbpcap_if_print(u_char *, const struct pcap_pkthdr *, 283 const u_char *); 284 285#ifdef INET6 286extern void ip6_print(const u_char *, u_int); 287extern void ip6_opt_print(const u_char *, int); 288extern int hbhopt_print(const u_char *); 289extern int dstopt_print(const u_char *); 290extern int frag6_print(const u_char *, const u_char *); 291extern void icmp6_print(const u_char *, u_int, const u_char *); 292extern void ripng_print(const u_char *, int); 293extern int rt6_print(const u_char *, const u_char *); 294extern void ospf6_print(const u_char *, u_int); 295extern void dhcp6_print(const u_char *, u_int, u_short, u_short); 296#endif /*INET6*/ 297 298extern u_short in_cksum(const u_short *addr, int len, int csum); 299extern u_int16_t in_cksum_shouldbe(u_int16_t, u_int16_t); 300