}
/* Relocate external jumps by reloc. */
-void ssfilter_patch(char *a, int len, int reloc)
+static void ssfilter_patch(char *a, int len, int reloc)
{
while (len > 0) {
struct tcpdiag_bc_op *op = (struct tcpdiag_bc_op*)a;
abort();
}
-int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
+static int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
{
switch (f->type) {
case SSF_S_AUTO:
}
}
-int remember_he(struct aafilter *a, struct hostent *he)
+static int remember_he(struct aafilter *a, struct hostent *he)
{
char **ptr = he->h_addr_list;
int cnt = 0;
return cnt;
}
-int get_dns_host(struct aafilter *a, char *addr, int fam)
+static int get_dns_host(struct aafilter *a, const char *addr, int fam)
{
static int notfirst;
int cnt = 0;
return !cnt;
}
-int xll_initted = 0;
+static int xll_initted = 0;
-void xll_init(void)
+static void xll_init(void)
{
struct rtnl_handle rth;
rtnl_open(&rth, 0);
xll_initted = 1;
}
-const char *xll_index_to_name(int index)
+static const char *xll_index_to_name(int index)
{
if (!xll_initted)
xll_init();
return ll_index_to_name(index);
}
-int xll_name_to_index(char *dev)
+static int xll_name_to_index(const char *dev)
{
if (!xll_initted)
xll_init();
return res;
}
-int tcp_show_line(char *line, struct filter *f, int family)
+static int tcp_show_line(char *line, struct filter *f, int family)
{
struct tcpstat s;
char *loc, *rem, *data;
return 0;
}
-int generic_record_read(int fd, char *buf, int bufsize,
+static int generic_record_read(int fd, char *buf, int bufsize,
int (*worker)(char*, struct filter *, int),
struct filter *f, int fam)
{
outerr:
return -1;
}
+
+static char *sprint_bw(char *buf, double bw)
+{
+ if (bw > 1000000.)
+ sprintf(buf,"%.1fM", bw / 1000000.);
+ else if (bw > 1000.)
+ sprintf(buf,"%.1fK", bw / 1000.);
+ else
+ sprintf(buf, "%g", bw);
+
+ return buf;
+}
-void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r)
+static void tcp_show_info(const struct nlmsghdr *nlh, struct tcpdiagmsg *r)
{
struct rtattr * tb[TCPDIAG_MAX+1];
+ char b1[64];
+ double rtt = 0;
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, TCPDIAG_MAX, (struct rtattr*)(r+1),
} else
info = RTA_DATA(tb[TCPDIAG_INFO]);
- if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
- printf(" ts");
- if (info->tcpi_options & TCPI_OPT_SACK)
- printf(" sack");
+ if (show_options) {
+ if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
+ printf(" ts");
+ if (info->tcpi_options & TCPI_OPT_SACK)
+ printf(" sack");
+ if (info->tcpi_options & TCPI_OPT_ECN)
+ printf(" ecn");
+ }
if (info->tcpi_options & TCPI_OPT_WSCALE)
printf(" wscale:%d,%d", info->tcpi_snd_wscale,
info->tcpi_rcv_wscale);
- if (info->tcpi_options & TCPI_OPT_ECN)
- printf(" ecn");
if (info->tcpi_rto && info->tcpi_rto != 3000000)
printf(" rto:%g", (double)info->tcpi_rto/1000);
if (info->tcpi_rtt)
if (info->tcpi_snd_ssthresh < 0xFFFF)
printf(" ssthresh:%d", info->tcpi_snd_ssthresh);
-#if LINUX_VERSION_CODE >= 0x20607
- if (info->tcpi_rcv_rtt)
- printf(" rcv_rtt:%g", (double) info->tcpi_rcv_rtt/1000);
- if (info->tcpi_rcv_space)
- printf(" rcv_space:%d", info->tcpi_rcv_space);
-
+ rtt = (double) info->tcpi_rtt;
if (tb[TCPDIAG_VEGASINFO]) {
const struct tcpvegas_info *vinfo
= RTA_DATA(tb[TCPDIAG_VEGASINFO]);
printf(" vegas");
if (vinfo->tcpv_rtt &&
- vinfo->tcpv_rtt != 0x7fffffff &&
- info->tcpi_snd_mss &&
- info->tcpi_snd_cwnd) {
- printf(" bw:%g",
- (double) info->tcpi_snd_cwnd *
- (double) info->tcpi_snd_mss *
- 8000000. / (double) vinfo->tcpv_rtt);
- }
+ vinfo->tcpv_rtt != 0x7fffffff)
+ rtt = vinfo->tcpv_rtt;
+ }
+
+ if (rtt > 0 && info->tcpi_snd_mss && info->tcpi_snd_cwnd) {
+ printf(" send %sbps",
+ sprint_bw(b1, (double) info->tcpi_snd_cwnd *
+ (double) info->tcpi_snd_mss * 8000000.
+ / rtt));
}
-#endif
+
+ if (info->tcpi_rcv_rtt)
+ printf(" rcv_rtt:%g", (double) info->tcpi_rcv_rtt/1000);
+ if (info->tcpi_rcv_space)
+ printf(" rcv_space:%d", info->tcpi_rcv_space);
+
}
}
req.r.tcpdiag_states = f->states;
if (show_mem)
req.r.tcpdiag_ext |= (1<<(TCPDIAG_MEMINFO-1));
+
if (show_tcpinfo) {
req.r.tcpdiag_ext |= (1<<(TCPDIAG_INFO-1));
-#ifdef TCPDIAG_VEGASINFO
req.r.tcpdiag_ext |= (1<<(TCPDIAG_VEGASINFO-1));
-#endif
}
iov[0] = (struct iovec){ &req, sizeof(req) };
return (1<<SS_CLOSE);
if (strcasecmp(state, "syn-rcv") == 0)
return (1<<SS_SYN_RECV);
- if (matches(state, "established") == 0)
+ if (strcasecmp(state, "established") == 0)
return (1<<SS_ESTABLISHED);
if (strcasecmp(state, "all") == 0)
return SS_ALL;
if (strcasecmp(state, "connected") == 0)
return SS_ALL & ~((1<<SS_CLOSE)|(1<<SS_LISTEN));
- if (matches(state, "synchronized") == 0)
+ if (strcasecmp(state, "synchronized") == 0)
return SS_ALL & ~((1<<SS_CLOSE)|(1<<SS_LISTEN)|(1<<SS_SYN_SENT));
if (strcasecmp(state, "bucket") == 0)
return (1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT);
if (strcasecmp(state, "big") == 0)
return SS_ALL & ~((1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT));
for (i=0; i<SS_MAX; i++) {
- if (matches(state, sstate_namel[i]) == 0)
+ if (strcasecmp(state, sstate_namel[i]) == 0)
return (1<<i);
}
return 0;
current_filter.dbs |= (1<<RAW_DB);
} else if (strcmp(p, "unix") == 0) {
current_filter.dbs |= UNIX_DBM;
- } else if (matches(p, "unix_stream") == 0 ||
+ } else if (strcasecmp(p, "unix_stream") == 0 ||
strcmp(p, "u_str") == 0) {
current_filter.dbs |= (1<<UNIX_ST_DB);
- } else if (matches(p, "unix_dgram") == 0 ||
+ } else if (strcasecmp(p, "unix_dgram") == 0 ||
strcmp(p, "u_dgr") == 0) {
current_filter.dbs |= (1<<UNIX_DG_DB);
} else if (strcmp(p, "packet") == 0) {