summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump
diff options
context:
space:
mode:
authorLawrence Teo <lteo@cvs.openbsd.org>2012-07-08 17:48:38 +0000
committerLawrence Teo <lteo@cvs.openbsd.org>2012-07-08 17:48:38 +0000
commitdf50ded746489291faeb0bfbad7a6c48b26dd5be (patch)
treeba12fb5f99c7ed99bac03accd2b05273efff37ea /usr.sbin/tcpdump
parent1416753cd220ebfd02ade01e94570b11fd6d1816 (diff)
New attempt to make the -P flag work with -ss, so that states can be
printed with port names if desired. tcpdump's pf_print_state.c has diverged significantly from pfctl's, so the change to tcpdump's pf_print_state.c is not exactly the same as pfctl's. ok henning sthen
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r--usr.sbin/tcpdump/pf_print_state.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/usr.sbin/tcpdump/pf_print_state.c b/usr.sbin/tcpdump/pf_print_state.c
index 08b54985b9c..c6971fcdba5 100644
--- a/usr.sbin/tcpdump/pf_print_state.c
+++ b/usr.sbin/tcpdump/pf_print_state.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_print_state.c,v 1.10 2011/10/13 18:32:30 claudio Exp $ */
+/* $OpenBSD: pf_print_state.c,v 1.11 2012/07/08 17:48:37 lteo Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -130,8 +130,11 @@ print_name(struct pf_addr *addr, sa_family_t af)
void
print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
- int opts)
+ const char *proto, int opts)
{
+ struct servent *s = NULL;
+ char ps[6];
+
if (rdom)
printf("(%u) ", ntohs(rdom));
@@ -152,10 +155,13 @@ print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
}
if (port) {
+ snprintf(ps, sizeof(ps), "%u", ntohs(port));
+ if (opts & PF_OPT_PORTNAMES)
+ s = getservbyport(port, proto);
if (af == AF_INET)
- printf(":%u", ntohs(port));
+ printf(":%s", s ? s->s_name : ps);
else
- printf("[%u]", ntohs(port));
+ printf("[%s]", s ? s->s_name : ps);
}
}
@@ -200,23 +206,24 @@ print_state(struct pfsync_state *s, int opts)
else
sidx = 0, didx = 1;
- print_host(&nk->addr[didx], nk->port[didx], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[didx], nk->port[didx], nk->af, nk->rdomain, NULL, opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[1], &sk->addr[1], nk->af) ||
nk->port[1] != sk->port[1]) {
printf(" (");
print_host(&sk->addr[1], sk->port[1], sk->af, sk->rdomain,
- opts);
+ NULL, opts);
printf(")");
}
if (s->direction == PF_OUT)
printf(" -> ");
else
printf(" <- ");
- print_host(&nk->addr[sidx], nk->port[sidx], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[sidx], nk->port[sidx], nk->af, nk->rdomain, NULL,
+ opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[0], &sk->addr[0], nk->af) ||
nk->port[0] != sk->port[0]) {
printf(" (");
- print_host(&sk->addr[0], sk->port[0], sk->af, sk->rdomain,
+ print_host(&sk->addr[0], sk->port[0], sk->af, sk->rdomain, NULL,
opts);
printf(")");
}