The structure 'netdissect_options' can hold if_printer.
Thus the structure 'print_info' is useless now.
Moreover:
Delete useless blank lines
Fix indent
/* snprintf et al */
#include <stdarg.h>
+#include <pcap.h>
#include "ip.h" /* struct ip for nextproto4_cksum() */
typedef struct netdissect_options netdissect_options;
+typedef u_int (*if_printer)(netdissect_options *ndo,
+ const struct pcap_pkthdr *, const u_char *);
+
struct netdissect_options {
int ndo_bflag; /* print 4 byte ASes in ASDOT notation */
int ndo_eflag; /* print ethernet header */
const u_char *ndo_packetp;
const u_char *ndo_snapend;
+ /* pointer to the if_printer function */
+ if_printer ndo_if_printer;
+
/* pointer to void function to output stuff */
void (*ndo_default_print)(netdissect_options *,
- register const u_char *bp, register u_int length);
+ register const u_char *bp, register u_int length);
/* pointer to function to do regular output */
int (*ndo_printf)(netdissect_options *,
/* The printer routines. */
-#include <pcap.h>
-
extern char *q922_string(netdissect_options *ndo, const u_char *, u_int);
-typedef u_int (*if_printer)(struct netdissect_options *ndo,
- const struct pcap_pkthdr *, const u_char *);
-
extern if_printer lookup_printer(int);
extern void eap_print(netdissect_options *,const u_char *, u_int);
{ NULL, 0 },
};
-
static void ndo_default_print(netdissect_options *ndo, const u_char *bp,
u_int length);
int
has_printer(int type)
{
-
return (lookup_printer(type) != NULL);
}
-struct print_info
-get_print_info(netdissect_options *ndo, int type)
+if_printer
+get_if_printer(netdissect_options *ndo, int type)
{
const char *dltname;
- struct print_info printinfo;
+ if_printer printer;
- printinfo.ndo = ndo;
- printinfo.printer = lookup_printer(type);
- if (printinfo.printer == NULL) {
+ printer = lookup_printer(type);
+ if (printer == NULL) {
dltname = pcap_datalink_val_to_name(type);
if (dltname != NULL)
(*ndo->ndo_error)(ndo,
(*ndo->ndo_error)(ndo,
"packet printing is not supported for link type %d: use -w", type);
}
- return (printinfo);
+ return printer;
}
void
-pretty_print_packet(struct print_info *print_info, const struct pcap_pkthdr *h,
+pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h,
const u_char *sp, u_int packets_captured)
{
u_int hdrlen;
- netdissect_options *ndo;
-
- ndo = print_info->ndo;
if(ndo->ndo_packet_number)
ND_PRINT((ndo, "%5u ", packets_captured));
*/
ndo->ndo_snapend = sp + h->caplen;
- hdrlen = (*print_info->printer)(print_info->ndo, h, sp);
+ hdrlen = (ndo->ndo_if_printer)(ndo, h, sp);
/*
* Restore the original snapend, as a printer might have
void
ndo_set_function_pointers(netdissect_options *ndo)
{
-
ndo->ndo_default_print=ndo_default_print;
ndo->ndo_printf=ndo_printf;
ndo->ndo_error=ndo_error;
#ifndef print_h
#define print_h
-struct print_info {
- netdissect_options *ndo;
- if_printer printer;
-};
-
void init_print(netdissect_options *ndo, u_int32_t localnet, u_int32_t mask,
uint32_t timezone_offset);
int has_printer(int type);
-struct print_info get_print_info(netdissect_options *ndo, int type);
+if_printer get_if_printer(netdissect_options *ndo, int type);
-void pretty_print_packet(struct print_info *print_info,
+void pretty_print_packet(netdissect_options *ndo,
const struct pcap_pkthdr *h, const u_char *sp,
u_int packets_captured);
int timezone_offset = 0;
register char *cp, *infile, *cmdbuf, *device, *RFileName, *VFileName, *WFileName;
pcap_handler callback;
- int type;
int dlt;
int new_dlt;
const char *dlt_name;
#ifndef _WIN32
RETSIGTYPE (*oldhandler)(int);
#endif
- struct print_info printinfo;
struct dump_info dumpinfo;
u_char *pcap_userdata;
char ebuf[PCAP_ERRBUF_SIZE];
pcap_dump_flush(p);
#endif
} else {
- type = pcap_datalink(pd);
- printinfo = get_print_info(ndo, type);
+ dlt = pcap_datalink(pd);
+ ndo->ndo_if_printer = get_if_printer(ndo, dlt);
callback = print_packet;
- pcap_userdata = (u_char *)&printinfo;
+ pcap_userdata = (u_char *)ndo;
}
#ifdef SIGNAL_REQ_INFO
new_dlt = pcap_datalink(pd);
if (WFileName && new_dlt != dlt)
error("%s: new dlt does not match original", RFileName);
- printinfo = get_print_info(ndo, new_dlt);
+ ndo->ndo_if_printer = get_if_printer(ndo, new_dlt);
dlt_name = pcap_datalink_val_to_name(new_dlt);
if (dlt_name == NULL) {
fprintf(stderr, "reading from file %s, link-type %u\n",
static void
print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
{
- struct print_info *print_info;
-
++packets_captured;
++infodelay;
- print_info = (struct print_info *)user;
-
- pretty_print_packet(print_info, h, sp, packets_captured);
+ pretty_print_packet((netdissect_options *)user, h, sp, packets_captured);
--infodelay;
if (infoprint)