1/*-
2 * Copyright (c) 1983, 1988, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 24 unchanged lines hidden (view full) ---
33
34#if 0
35#ifndef lint
36static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
37#endif /* not lint */
38#endif
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/usr.bin/netstat/inet.c 179027 2008-05-15 20:18:44Z gnn $");
42
43#include <sys/param.h>
44#include <sys/queue.h>
45#include <sys/domain.h>
46#include <sys/socket.h>
47#include <sys/socketvar.h>
48#include <sys/sysctl.h>
49#include <sys/protosw.h>
--- 87 unchanged lines hidden (view full) ---
137 * nested structures that aren't used to avoid extra work.
138 */
139static void
140sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
141{
142 xsb->sb_cc = sb->sb_cc;
143 xsb->sb_hiwat = sb->sb_hiwat;
144 xsb->sb_mbcnt = sb->sb_mbcnt;
145 xsb->sb_mcnt = sb->sb_mcnt;
146 xsb->sb_ccnt = sb->sb_ccnt;
147 xsb->sb_mbmax = sb->sb_mbmax;
148 xsb->sb_lowat = sb->sb_lowat;
149 xsb->sb_flags = sb->sb_flags;
150 xsb->sb_timeo = sb->sb_timeo;
151}
152
153int
154sotoxsocket(struct socket *so, struct xsocket *xso)
--- 247 unchanged lines hidden (view full) ---
402 printf(
403 "Current listen queue sizes (qlen/incqlen/maxqlen)");
404 putchar('\n');
405 if (Aflag)
406 printf("%-8.8s ", "Tcpcb");
407 if (Lflag)
408 printf("%-5.5s %-14.14s %-22.22s\n",
409 "Proto", "Listen", "Local Address");
410 printf((Aflag && !Wflag) ?
411 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s" :
412 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s",
413 "Proto", "Recv-Q", "Send-Q",
414 "Local Address", "Foreign Address");
415 if (xflag)
416 printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %s\n",
417 "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS",
418 "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA",
419 "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX",
420 "(state)");
421 else
422 printf("(state)\n");
423 first = 0;
424 }
425 if (Lflag && so->so_qlimit == 0)
426 continue;
427 if (Aflag) {
428 if (istcp)
429 printf("%8lx ", (u_long)inp->inp_ppcb);
430 else
--- 10 unchanged lines hidden (view full) ---
441 printf("%-3.3s%-2.2s ", name, vchar);
442 if (Lflag) {
443 char buf1[15];
444
445 snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
446 so->so_incqlen, so->so_qlimit);
447 printf("%-14.14s ", buf1);
448 } else {
449 printf("%6u %6u ",
450 so->so_rcv.sb_cc, so->so_snd.sb_cc);
451 }
452 if (numeric_port) {
453 if (inp->inp_vflag & INP_IPV4) {
454 inetprint(&inp->inp_laddr, (int)inp->inp_lport,
455 name, 1);
456 if (!Lflag)
457 inetprint(&inp->inp_faddr,
458 (int)inp->inp_fport, name, 1);
--- 39 unchanged lines hidden (view full) ---
498 (int)inp->inp_lport, name, 0);
499 if (!Lflag)
500 inet6print(&inp->in6p_faddr,
501 (int)inp->inp_fport, name,
502 inp->inp_lport != inp->inp_fport);
503 } /* else nothing printed now */
504#endif /* INET6 */
505 }
506 if (xflag) {
507 if (Lflag)
508 printf("%21s %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u ",
509 " ",
510 so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
511 so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
512 so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
513 so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
514 so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
515 so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
516 else
517 printf("%6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u ",
518 so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
519 so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
520 so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
521 so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
522 so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
523 so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
524 }
525 if (istcp && !Lflag) {
526 if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
527 printf("%d", tp->t_state);
528 else {
529 printf("%s", tcpstates[tp->t_state]);
530#if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
531 /* Show T/TCP `hidden state' */
532 if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN))
533 putchar('*');
534#endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */
535 }
536 }
537 putchar('\n');
538 }
539 if (xig != oxig && xig->xig_gen != oxig->xig_gen) {
540 if (oxig->xig_count > xig->xig_count) {
541 printf("Some %s sockets may have been deleted.\n",
542 name);
543 } else if (oxig->xig_count < xig->xig_count) {
544 printf("Some %s sockets may have been created.\n",
--- 609 unchanged lines hidden ---
2 * Copyright (c) 1983, 1988, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 24 unchanged lines hidden (view full) ---
33
34#if 0
35#ifndef lint
36static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
37#endif /* not lint */
38#endif
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/usr.bin/netstat/inet.c 179027 2008-05-15 20:18:44Z gnn $");
42
43#include <sys/param.h>
44#include <sys/queue.h>
45#include <sys/domain.h>
46#include <sys/socket.h>
47#include <sys/socketvar.h>
48#include <sys/sysctl.h>
49#include <sys/protosw.h>
--- 87 unchanged lines hidden (view full) ---
137 * nested structures that aren't used to avoid extra work.
138 */
139static void
140sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
141{
142 xsb->sb_cc = sb->sb_cc;
143 xsb->sb_hiwat = sb->sb_hiwat;
144 xsb->sb_mbcnt = sb->sb_mbcnt;
145 xsb->sb_mcnt = sb->sb_mcnt;
146 xsb->sb_ccnt = sb->sb_ccnt;
147 xsb->sb_mbmax = sb->sb_mbmax;
148 xsb->sb_lowat = sb->sb_lowat;
149 xsb->sb_flags = sb->sb_flags;
150 xsb->sb_timeo = sb->sb_timeo;
151}
152
153int
154sotoxsocket(struct socket *so, struct xsocket *xso)
--- 247 unchanged lines hidden (view full) ---
402 printf(
403 "Current listen queue sizes (qlen/incqlen/maxqlen)");
404 putchar('\n');
405 if (Aflag)
406 printf("%-8.8s ", "Tcpcb");
407 if (Lflag)
408 printf("%-5.5s %-14.14s %-22.22s\n",
409 "Proto", "Listen", "Local Address");
410 printf((Aflag && !Wflag) ?
411 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s" :
412 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s",
413 "Proto", "Recv-Q", "Send-Q",
414 "Local Address", "Foreign Address");
415 if (xflag)
416 printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %s\n",
417 "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS",
418 "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA",
419 "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX",
420 "(state)");
421 else
422 printf("(state)\n");
423 first = 0;
424 }
425 if (Lflag && so->so_qlimit == 0)
426 continue;
427 if (Aflag) {
428 if (istcp)
429 printf("%8lx ", (u_long)inp->inp_ppcb);
430 else
--- 10 unchanged lines hidden (view full) ---
441 printf("%-3.3s%-2.2s ", name, vchar);
442 if (Lflag) {
443 char buf1[15];
444
445 snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
446 so->so_incqlen, so->so_qlimit);
447 printf("%-14.14s ", buf1);
448 } else {
449 printf("%6u %6u ",
450 so->so_rcv.sb_cc, so->so_snd.sb_cc);
451 }
452 if (numeric_port) {
453 if (inp->inp_vflag & INP_IPV4) {
454 inetprint(&inp->inp_laddr, (int)inp->inp_lport,
455 name, 1);
456 if (!Lflag)
457 inetprint(&inp->inp_faddr,
458 (int)inp->inp_fport, name, 1);
--- 39 unchanged lines hidden (view full) ---
498 (int)inp->inp_lport, name, 0);
499 if (!Lflag)
500 inet6print(&inp->in6p_faddr,
501 (int)inp->inp_fport, name,
502 inp->inp_lport != inp->inp_fport);
503 } /* else nothing printed now */
504#endif /* INET6 */
505 }
506 if (xflag) {
507 if (Lflag)
508 printf("%21s %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u ",
509 " ",
510 so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
511 so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
512 so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
513 so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
514 so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
515 so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
516 else
517 printf("%6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u ",
518 so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
519 so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
520 so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
521 so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
522 so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
523 so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
524 }
525 if (istcp && !Lflag) {
526 if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
527 printf("%d", tp->t_state);
528 else {
529 printf("%s", tcpstates[tp->t_state]);
530#if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
531 /* Show T/TCP `hidden state' */
532 if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN))
533 putchar('*');
534#endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */
535 }
536 }
537 putchar('\n');
538 }
539 if (xig != oxig && xig->xig_gen != oxig->xig_gen) {
540 if (oxig->xig_count > xig->xig_count) {
541 printf("Some %s sockets may have been deleted.\n",
542 name);
543 } else if (oxig->xig_count < xig->xig_count) {
544 printf("Some %s sockets may have been created.\n",
--- 609 unchanged lines hidden ---