]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add program_name field in the netdissect_options structure
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 7 Sep 2015 17:04:50 +0000 (19:04 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 7 Sep 2015 17:13:42 +0000 (19:13 +0200)
A program that use the library should set it. Done for tcpdump.
ndo_error() and ndo_warning() print now 'ndo->program_name'.

Moreover:
Fix indent

netdissect.h
print.c
tcpdump.c

index 94c91c07a2cfce2abc2b1ce1d08c4e3ed891226e..458732b8d7cdb9d3b050c3bc6622432fc046fd63 100644 (file)
@@ -111,14 +111,15 @@ struct netdissect_options {
   int ndo_Hflag;               /* dissect 802.11s draft mesh standard */
   int ndo_packet_number;       /* print a packet number in the beginning of line */
   int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */
-  int ndo_tstamp_precision;   /* requested time stamp precision */
+  int ndo_tstamp_precision;    /* requested time stamp precision */
   const char *ndo_dltname;
+  const char *program_name;    /* Name of the program using the library */
 
   char *ndo_espsecret;
   struct sa_list *ndo_sa_list_head;  /* used by print-esp.c */
   struct sa_list *ndo_sa_default;
 
-  char *ndo_sigsecret;         /* Signature verification secret key */
+  char *ndo_sigsecret;         /* Signature verification secret key */
 
   int   ndo_packettype;        /* as specified by -T */
 
@@ -130,7 +131,7 @@ struct netdissect_options {
 
   /* 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 *,
diff --git a/print.c b/print.c
index 66a07ee1b7bcb74ad381337707df20af2b807027..0d831daad063f3bd888c1753e541a8a9cea7821f 100644 (file)
--- a/print.c
+++ b/print.c
@@ -422,11 +422,12 @@ ndo_default_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
 /* VARARGS */
 static void
-ndo_error(netdissect_options *ndo _U_, const char *fmt, ...)
+ndo_error(netdissect_options *ndo, const char *fmt, ...)
 {
        va_list ap;
 
-       (void)fprintf(stderr, "%s: ", program_name);
+       if(ndo->program_name)
+               (void)fprintf(stderr, "%s: ", ndo->program_name);
        va_start(ap, fmt);
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
@@ -441,11 +442,13 @@ ndo_error(netdissect_options *ndo _U_, const char *fmt, ...)
 
 /* VARARGS */
 static void
-ndo_warning(netdissect_options *ndo _U_, const char *fmt, ...)
+ndo_warning(netdissect_options *ndo, const char *fmt, ...)
 {
        va_list ap;
 
-       (void)fprintf(stderr, "%s: WARNING: ", program_name);
+       if(ndo->program_name)
+               (void)fprintf(stderr, "%s: ", ndo->program_name);
+       (void)fprintf(stderr, "WARNING: ");
        va_start(ap, fmt);
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
index f50ff5f886ce74ac4158ff68623686b2a890cf7b..28ad53f8291fd6e3b55351e0b25622e51ee87a63 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -760,9 +760,9 @@ main(int argc, char **argv)
        WFileName = NULL;
        dlt = -1;
        if ((cp = strrchr(argv[0], '/')) != NULL)
-               program_name = cp + 1;
+               ndo->program_name = program_name = cp + 1;
        else
-               program_name = argv[0];
+               ndo->program_name = program_name = argv[0];
 
        /*
         * On platforms where the CPU doesn't support unaligned loads,