Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/netstat/inet.c
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <libxo/xo.h> | #include <libxo/xo.h> | ||||
#include "netstat.h" | #include "netstat.h" | ||||
#include "nl_defs.h" | #include "nl_defs.h" | ||||
#define max(a, b) (((a) > (b)) ? (a) : (b)) | |||||
#ifdef INET | #ifdef INET | ||||
static void inetprint(const char *, struct in_addr *, int, const char *, int, | static void inetprint(const char *, struct in_addr *, int, const char *, int, | ||||
const int); | const int); | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
static int udp_done, tcp_done, sdp_done; | static int udp_done, tcp_done, sdp_done; | ||||
#endif /* INET6 */ | #endif /* INET6 */ | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | protopr(u_long off, const char *name, int af1, int proto) | ||||
static int first = 1; | static int first = 1; | ||||
int istcp; | int istcp; | ||||
char *buf; | char *buf; | ||||
const char *vchar; | const char *vchar; | ||||
struct xtcpcb *tp; | struct xtcpcb *tp; | ||||
struct xinpcb *inp; | struct xinpcb *inp; | ||||
struct xinpgen *xig, *oxig; | struct xinpgen *xig, *oxig; | ||||
struct xsocket *so; | struct xsocket *so; | ||||
int fnamelen, cnamelen; | |||||
istcp = 0; | istcp = 0; | ||||
switch (proto) { | switch (proto) { | ||||
case IPPROTO_TCP: | case IPPROTO_TCP: | ||||
#ifdef INET6 | #ifdef INET6 | ||||
if (strncmp(name, "sdp", 3) != 0) { | if (strncmp(name, "sdp", 3) != 0) { | ||||
if (tcp_done != 0) | if (tcp_done != 0) | ||||
return; | return; | ||||
Show All 16 Lines | else | ||||
udp_done = 1; | udp_done = 1; | ||||
#endif | #endif | ||||
break; | break; | ||||
} | } | ||||
if (!pcblist_sysctl(proto, name, &buf)) | if (!pcblist_sysctl(proto, name, &buf)) | ||||
return; | return; | ||||
if (cflag || Cflag) { | |||||
fnamelen = strlen("Stack"); | |||||
cnamelen = strlen("CC"); | |||||
oxig = xig = (struct xinpgen *)buf; | oxig = xig = (struct xinpgen *)buf; | ||||
for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); | for (xig = (struct xinpgen*)((char *)xig + xig->xig_len); | ||||
xig->xig_len > sizeof(struct xinpgen); | xig->xig_len > sizeof(struct xinpgen); | ||||
xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { | xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { | ||||
if (istcp) { | if (istcp) { | ||||
tp = (struct xtcpcb *)xig; | tp = (struct xtcpcb *)xig; | ||||
inp = &tp->xt_inp; | inp = &tp->xt_inp; | ||||
} else { | } else { | ||||
continue; | |||||
} | |||||
if (so->xso_protocol != proto) | |||||
continue; | |||||
if (inp->inp_gencnt > oxig->xig_gen) | |||||
continue; | |||||
fnamelen = max(fnamelen, (int)strlen(tp->xt_stack)); | |||||
cnamelen = max(cnamelen, (int)strlen(tp->xt_cc)); | |||||
} | |||||
} | |||||
oxig = xig = (struct xinpgen *)buf; | |||||
for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); | |||||
xig->xig_len > sizeof(struct xinpgen); | |||||
xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { | |||||
if (istcp) { | |||||
tp = (struct xtcpcb *)xig; | |||||
inp = &tp->xt_inp; | |||||
} else { | |||||
inp = (struct xinpcb *)xig; | inp = (struct xinpcb *)xig; | ||||
} | } | ||||
so = &inp->xi_socket; | so = &inp->xi_socket; | ||||
/* Ignore sockets for protocols other than the desired one. */ | /* Ignore sockets for protocols other than the desired one. */ | ||||
if (so->xso_protocol != proto) | if (so->xso_protocol != proto) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%-45.45s}"), | ||||
xo_emit(" {T:/%7.7s} {T:/%7.7s} {T:/%7.7s} " | xo_emit(" {T:/%7.7s} {T:/%7.7s} {T:/%7.7s} " | ||||
"{T:/%7.7s} {T:/%7.7s} {T:/%7.7s}", | "{T:/%7.7s} {T:/%7.7s} {T:/%7.7s}", | ||||
"rexmt", "persist", "keep", "2msl", | "rexmt", "persist", "keep", "2msl", | ||||
"delack", "rcvtime"); | "delack", "rcvtime"); | ||||
} else if (Rflag) { | } else if (Rflag) { | ||||
xo_emit(" {T:/%8.8s} {T:/%5.5s}", | xo_emit(" {T:/%8.8s} {T:/%5.5s}", | ||||
"flowid", "ftype"); | "flowid", "ftype"); | ||||
} | } | ||||
if (cflag) { | |||||
xo_emit(" {T:/%-*.*s}", | |||||
fnamelen, fnamelen, "Stack"); | |||||
} | |||||
if (Cflag) | if (Cflag) | ||||
xo_emit(" {T:/%-*.*s}", TCP_CA_NAME_MAX, | xo_emit(" {T:/%-*.*s} {T:/%10.10s}" | ||||
TCP_CA_NAME_MAX, "CC"); | " {T:/%10.10s} {T:/%5.5s}" | ||||
" {T:/%3.3s}", cnamelen, | |||||
cnamelen, "CC", | |||||
"cwin", | |||||
"ssthresh", | |||||
"MSS", | |||||
"ECN"); | |||||
if (Pflag) | if (Pflag) | ||||
xo_emit(" {T:/%s}", "Log ID"); | xo_emit(" {T:/%s}", "Log ID"); | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
first = 0; | first = 0; | ||||
} | } | ||||
if (Lflag && so->so_qlimit == 0) | if (Lflag && so->so_qlimit == 0) | ||||
continue; | continue; | ||||
xo_open_instance("socket"); | xo_open_instance("socket"); | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ | ||||
} | } | ||||
if (Rflag) { | if (Rflag) { | ||||
/* XXX: is this right Alfred */ | /* XXX: is this right Alfred */ | ||||
xo_emit(" {:flow-id/%08x} {:flow-type/%5d}", | xo_emit(" {:flow-id/%08x} {:flow-type/%5d}", | ||||
inp->inp_flowid, | inp->inp_flowid, | ||||
inp->inp_flowtype); | inp->inp_flowtype); | ||||
} | } | ||||
if (istcp) { | if (istcp) { | ||||
if (cflag) | |||||
xo_emit(" {:stack/%-*.*s}", | |||||
fnamelen, fnamelen, tp->xt_stack); | |||||
if (Cflag) | if (Cflag) | ||||
xo_emit(" {:cc/%-*.*s}", TCP_CA_NAME_MAX, | xo_emit(" {:cc/%-*.*s}" | ||||
TCP_CA_NAME_MAX, tp->xt_cc); | " {:snd-cwnd/%10lu}" | ||||
" {:snd-ssthresh/%10lu}" | |||||
" {:t-maxseg/%5u} {:ecn/%3s}", | |||||
cnamelen, cnamelen, tp->xt_cc, | |||||
tp->t_snd_cwnd, tp->t_snd_ssthresh, | |||||
tp->t_maxseg, | |||||
(tp->t_state >= TCPS_ESTABLISHED ? | |||||
(tp->xt_ecn > 0 ? | |||||
(tp->xt_ecn == 1 ? | |||||
"ecn" : "ace") | |||||
: "off") | |||||
: "n/a")); | |||||
if (Pflag) | if (Pflag) | ||||
xo_emit(" {:log-id/%s}", | xo_emit(" {:log-id/%s}", | ||||
tp->xt_logid[0] == '\0' ? | tp->xt_logid[0] == '\0' ? | ||||
"-" : tp->xt_logid); | "-" : tp->xt_logid); | ||||
} | } | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
xo_close_instance("socket"); | xo_close_instance("socket"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 922 Lines • Show Last 20 Lines |