*
* NOTE: ap is *NOT* necessarily part of the packet data (not even if
* this is being called with the "ipaddr_string()" macro), so you
- * *CANNOT* use the TCHECK{2}/TTEST{2} macros on it. Furthermore,
+ * *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it. Furthermore,
* even in cases where it *is* part of the packet data, the caller
* would still have to check for a null return value, even if it's
* just printing the return value with "%s" - not all versions of
extern int32_t thiszone; /* seconds offset from gmt to local time */
-/*
- * True if "l" bytes of "var" were captured.
- *
- * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
- * that "snapend - (l)" underflows.
- *
- * The check is for <= rather than < because "l" might be 0.
- *
- * We cast the pointers to uintptr_t to make sure that the compiler
- * doesn't optimize away any of these tests (which it is allowed to
- * do, as adding an integer to, or subtracting an integer from, a
- * pointer assumes that the pointer is a pointer to an element of an
- * array and that the result of the addition or subtraction yields a
- * pointer to another member of the array, so that, for example, if
- * you subtract a positive integer from a pointer, the result is
- * guaranteed to be less than the original pointer value). See
- *
- * http://www.kb.cert.org/vuls/id/162289
- */
-#define TTEST2(var, l) \
- ((uintptr_t)snapend - (l) <= (uintptr_t)snapend && \
- (uintptr_t)&(var) <= (uintptr_t)snapend - (l))
-
-/* True if "var" was captured */
-#define TTEST(var) TTEST2(var, sizeof(var))
-
-/* Bail if "l" bytes of "var" were not captured */
-#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc
-
-/* Bail if "var" was not captured */
-#define TCHECK(var) TCHECK2(var, sizeof(var))
-
extern int mask2plen(uint32_t);
extern const char *tok2strary_internal(const char **, int, const char *, int);
#define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
extern char *q922_string(netdissect_options *ndo, const u_char *, u_int);
-typedef u_int (*if_ndo_printer)(struct netdissect_options *ndo,
+typedef u_int (*if_printer)(struct netdissect_options *ndo,
const struct pcap_pkthdr *, const u_char *);
-typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *);
-extern if_ndo_printer lookup_ndo_printer(int);
extern if_printer lookup_printer(int);
extern void eap_print(netdissect_options *,const u_char *, u_int);
uint32_t dlt, hdrlen, rectype;
u_int caplen = h->caplen;
u_int length = h->len;
- if_ndo_printer ndo_printer;
- if_printer printer;
+ if_printer printer;
pktap_header_t *hdr;
if (caplen < sizeof(pktap_header_t) || length < sizeof(pktap_header_t)) {
case PKT_REC_PACKET:
if ((printer = lookup_printer(dlt)) != NULL) {
- printer(h, p);
- } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
- ndo_printer(ndo, h, p);
+ printer(ndo, h, p);
} else {
if (!ndo->ndo_eflag)
pktap_header_print(ndo, (u_char *)hdr,
ppi_print(netdissect_options *ndo,
const struct pcap_pkthdr *h, const u_char *p)
{
- if_ndo_printer ndo_printer;
- if_printer printer;
+ if_printer printer;
ppi_header_t *hdr;
u_int caplen = h->caplen;
u_int length = h->len;
p += len;
if ((printer = lookup_printer(dlt)) != NULL) {
- printer(h, p);
- } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
- ndo_printer(ndo, h, p);
+ printer(ndo, h, p);
} else {
if (!ndo->ndo_eflag)
ppi_header_print(ndo, (u_char *)hdr, length + len);
static u_int packets_captured;
struct printer {
- if_printer f;
- int type;
-};
-
-
-struct ndo_printer {
- if_ndo_printer f;
+ if_printer f;
int type;
};
static const struct printer printers[] = {
- { NULL, 0 },
-};
-
-static const struct ndo_printer ndo_printers[] = {
{ ether_if_print, DLT_EN10MB },
#ifdef DLT_IPNET
{ ipnet_if_print, DLT_IPNET },
if (type == p->type)
return p->f;
- return NULL;
- /* NOTREACHED */
-}
-
-if_ndo_printer
-lookup_ndo_printer(int type)
-{
- const struct ndo_printer *p;
-
- for (p = ndo_printers; p->f; ++p)
- if (type == p->type)
- return p->f;
-
#if defined(DLT_USER2) && defined(DLT_PKTAP)
/*
* Apple incorrectly chose to use DLT_USER2 for their PKTAP
* that.
*/
if (type == DLT_USER2) {
- for (p = ndo_printers; p->f; ++p)
+ for (p = printers; p->f; ++p)
if (DLT_PKTAP == p->type)
return p->f;
}
struct print_info {
netdissect_options *ndo;
- union {
- if_printer printer;
- if_ndo_printer ndo_printer;
- } p;
- int ndo_type;
+ if_printer printer;
};
struct dump_info {
/*
* OK, does tcpdump handle that type?
*/
- if (lookup_printer(dlts[n_dlts]) == NULL
- && lookup_ndo_printer(dlts[n_dlts]) == NULL)
+ if (lookup_printer(dlts[n_dlts]) == NULL)
(void) fprintf(stderr, " (printing not supported)");
fprintf(stderr, "\n");
} else {
{
struct print_info printinfo;
- printinfo.ndo_type = 1;
printinfo.ndo = gndo;
- printinfo.p.ndo_printer = lookup_ndo_printer(type);
- if (printinfo.p.ndo_printer == NULL) {
- printinfo.p.printer = lookup_printer(type);
- printinfo.ndo_type = 0;
- if (printinfo.p.printer == NULL) {
- gndo->ndo_dltname = pcap_datalink_val_to_name(type);
- if (gndo->ndo_dltname != NULL)
- error("packet printing is not supported for link type %s: use -w",
- gndo->ndo_dltname);
- else
- error("packet printing is not supported for link type %d: use -w", type);
- }
+ printinfo.printer = lookup_printer(type);
+ if (printinfo.printer == NULL) {
+ gndo->ndo_dltname = pcap_datalink_val_to_name(type);
+ if (gndo->ndo_dltname != NULL)
+ error("packet printing is not supported for link type %s: use -w",
+ gndo->ndo_dltname);
+ else
+ error("packet printing is not supported for link type %d: use -w", type);
}
return (printinfo);
}
*/
ndo->ndo_snapend = sp + h->caplen;
- if(print_info->ndo_type) {
- hdrlen = (*print_info->p.ndo_printer)(print_info->ndo, h, sp);
- } else {
- hdrlen = (*print_info->p.printer)(h, sp);
- }
+ hdrlen = (*print_info->printer)(print_info->ndo, h, sp);
/*
* Restore the original snapend, as a printer might have