Skip to content

Commit b80f964

Browse files
committed
Add the -g option, causing IPv4 output in verbose mode to be on one line.
This may make it easlier to parse IPv4 output. From Apple's tcpdump, until they decided to get rid of it for some unknown reason. Fix up man page not to split some options between in the SYNOPSIS section (at least with 80-column output).
1 parent e27d41d commit b80f964

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

netdissect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct netdissect_options {
217217
int ndo_bflag; /* print 4 byte ASes in ASDOT notation */
218218
int ndo_eflag; /* print ethernet header */
219219
int ndo_fflag; /* don't translate "foreign" IP address */
220+
int ndo_gflag; /* don't split IP output into two lines in verbose mode */
220221
int ndo_Kflag; /* don't check IP, TCP or UDP checksums */
221222
int ndo_nflag; /* leave addresses as numbers */
222223
int ndo_Nflag; /* remove domains from printed host names */

print-ip.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ ip_print(netdissect_options *ndo,
437437
}
438438
}
439439

440-
ND_PRINT(")\n ");
440+
if (ndo->ndo_gflag)
441+
ND_PRINT(") ");
442+
else
443+
ND_PRINT(")\n ");
441444
if (truncated) {
442445
ND_PRINT("%s > %s: ",
443446
GET_IPADDR_STRING(ip->ip_src),

tcpdump.1.in

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ tcpdump \- dump traffic on a network
2727
.na
2828
.B tcpdump
2929
[
30-
.B \-AbdDefhHIJKlLnNOpqStuUvxX#
30+
.B \-AbdDefghHIJKlLnNOpqStuUvxX#
3131
] [
3232
.B \-B
3333
.I buffer_size
3434
]
35+
.br
3536
.ti +8
3637
[
3738
.B \-c
@@ -44,11 +45,13 @@ tcpdump \- dump traffic on a network
4445
.B \-C
4546
.I file_size
4647
]
48+
.br
4749
.ti +8
4850
[
4951
.B \-E
5052
.I spi@ipaddr algo:secret,...
5153
]
54+
.br
5255
.ti +8
5356
[
5457
.B \-F
@@ -62,6 +65,7 @@ tcpdump \- dump traffic on a network
6265
.B \-i
6366
.I interface
6467
]
68+
.br
6569
.ti +8
6670
[
6771
.B \-\-immediate\-mode
@@ -70,14 +74,14 @@ tcpdump \- dump traffic on a network
7074
.B \-j
7175
.I tstamp_type
7276
]
73-
.ti +8
7477
[
7578
.BI \-\-lengths
7679
]
7780
[
7881
.B \-m
7982
.I module
8083
]
84+
.br
8185
.ti +8
8286
[
8387
.B \-M
@@ -89,11 +93,12 @@ tcpdump \- dump traffic on a network
8993
[
9094
.B \-\-print
9195
]
92-
.ti +8
9396
[
9497
.B \-\-print\-sampling
9598
.I nth
9699
]
100+
.br
101+
.ti +8
97102
[
98103
.B \-Q
99104
.I in|out|inout
@@ -102,7 +107,6 @@ tcpdump \- dump traffic on a network
102107
.B \-r
103108
.I file
104109
]
105-
.ti +8
106110
[
107111
.B \-s
108112
.I snaplen
@@ -111,14 +115,15 @@ tcpdump \- dump traffic on a network
111115
.B \-\-skip
112116
.I count
113117
]
118+
.br
119+
.ti +8
114120
[
115121
.B \-T
116122
.I type
117123
]
118124
[
119125
.B \-\-version
120126
]
121-
.ti +8
122127
[
123128
.B \-V
124129
.I file
@@ -131,11 +136,12 @@ tcpdump \- dump traffic on a network
131136
.B \-W
132137
.I filecount
133138
]
139+
.br
140+
.ti +8
134141
[
135142
.B \-y
136143
.I datalinktype
137144
]
138-
.ti +8
139145
[
140146
.B \-z
141147
.I postrotate-command
@@ -144,17 +150,18 @@ tcpdump \- dump traffic on a network
144150
.B \-Z
145151
.I user
146152
]
153+
.br
147154
.ti +8
148155
[
149156
.BI \-\-time\-stamp\-precision= tstamp_precision
150157
]
151-
.ti +8
152158
[
153159
.BI \-\-micro
154160
]
155161
[
156162
.BI \-\-nano
157163
]
164+
.br
158165
.ti +8
159166
[
160167
.I expression
@@ -442,6 +449,13 @@ the interface.
442449
Use \fIfile\fP as input for the filter expression.
443450
An additional expression given on the command line is ignored.
444451
.TP
452+
.B \-g
453+
.PD 0
454+
.TP
455+
.BI \-\-ip\-oneline
456+
.PD
457+
Do not insert a line break after the IP header in verbose mode.
458+
.TP
445459
.BI \-G " rotate_seconds"
446460
If specified, rotates the dump file specified with the
447461
.B \-w

tcpdump.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ show_remote_devices_and_exit(void)
636636
#define M_FLAG_USAGE
637637
#endif
638638

639-
#define SHORTOPTS "aAbB:c:C:dDe" E_FLAG "fF:G:hHi:I" j_FLAG J_FLAG "KlLm:" M_FLAG "nNOpqQ:r:s:StT:uUvV:w:W:xXy:Y" z_FLAG "Z:#"
639+
#define SHORTOPTS "aAbB:c:C:dDe" E_FLAG "fF:gG:hHi:I" j_FLAG J_FLAG "KlLm:" M_FLAG "nNOpqQ:r:s:StT:uUvV:w:W:xXy:Y" z_FLAG "Z:#"
640640

641641
/*
642642
* Long options.
@@ -713,6 +713,7 @@ static const struct option longopts[] = {
713713
{ "print-sampling", required_argument, NULL, OPTION_PRINT_SAMPLING },
714714
{ "lengths", no_argument, NULL, OPTION_LENGTHS },
715715
{ "time-t-size", no_argument, NULL, OPTION_TIME_T_SIZE },
716+
{ "ip-oneline", no_argument, NULL, 'g' },
716717
{ "skip", required_argument, NULL, OPTION_SKIP },
717718
{ "version", no_argument, NULL, OPTION_VERSION },
718719
{ NULL, 0, NULL, 0 }
@@ -1801,6 +1802,10 @@ main(int argc, char **argv)
18011802
infile = optarg;
18021803
break;
18031804

1805+
case 'g':
1806+
++ndo->ndo_gflag;
1807+
break;
1808+
18041809
case 'G':
18051810
Gflag = parse_int("number of seconds", optarg, NULL, 0,
18061811
INT_MAX, 10);
@@ -3479,7 +3484,7 @@ print_usage(FILE *f)
34793484
{
34803485
print_version(f);
34813486
(void)fprintf(f,
3482-
"Usage: %s [-AbdDefhHI" J_FLAG "KlLnNOpqStuUvxX#] [ -B size ] [ -c count ] [--count]\n", program_name);
3487+
"Usage: %s [-AbdDefghHI" J_FLAG "KlLnNOpqStuUvxX#] [ -B size ] [ -c count ] [--count]\n", program_name);
34833488
(void)fprintf(f,
34843489
"\t\t[ -C file_size ] " E_FLAG_USAGE "[ -F file ] [ -G seconds ]\n");
34853490
(void)fprintf(f,

0 commit comments

Comments
 (0)