2 * netstat This file contains an implementation of the command
3 * that helps in debugging the networking modules.
5 * NET-TOOLS A collection of programs that form the base set of the
6 * NET-3 Networking Distribution for the LINUX operating
9 * Version: $Id: netstat.c,v 1.44 2001/08/26 05:25:21 ak Exp $
11 * Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
12 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
13 * Phil Packer, <pep@wicked.demon.co.uk>
14 * Johannes Stille, <johannes@titan.os.open.de>
15 * Bernd Eckenfels, <net-tools@lina.inka.de>
16 * Phil Blundell <philb@gnu.org>
17 * Tuan Hoang <tqhoang@bigfoot.com>
20 * Alan Cox, <A.Cox@swansea.ac.uk>
21 * Copyright (c) 1993 Fred Baumgarten
25 *960116 {1.01} Bernd Eckenfels: verbose, cleanups
26 *960204 {1.10} Bernd Eckenfels: aftrans, usage, new route_info,
28 *960204 {1.11} Bernd Eckenfels: netlink support
29 *960204 {1.12} Bernd Eckenfels: route_init()
30 *960215 {1.13} Bernd Eckenfels: netlink_print honors HAVE_
31 *960217 {1.14} Bernd Eckenfels: masq_info from Jos Vos and
32 * ax25_info from Jonathan Naylor.
33 *960218 {1.15} Bernd Eckenfels: ipx_info rewritten, -e for tcp/ipx
34 *960220 {1.16} Bernd Eckenfels: minor output reformats, -a for -x
35 *960221 {1.17} Bernd Eckenfels: route_init->getroute_init
36 *960426 {1.18} Bernd Eckenfels: new RTACTION, SYM/NUM, FIB/CACHE
37 *960517 {1.19} Bernd Eckenfels: usage() spelling fix and --unix inode,
38 * ':' is part of sock_addr for --inet
39 *960822 {x.xx} Frank Strauss: INET6 support
41 *970406 {1.33} Philip Copeland Added snmp reporting support module -s
42 * code provided by Andi Kleen
43 * (relly needs to be kernel hooked but
44 * this will do in the meantime)
45 * minor header file misplacement tidy up.
46 *980815 {1.xx} Stephane Fillod: X.25 support
47 *980411 {1.34} Arnaldo Carvalho i18n: catgets -> gnu gettext, substitution
48 * of sprintf for snprintf
49 *10/1998 Andi Kleen Use new interface primitives.
50 *990101 {1.36} Bernd Eckenfels usage updated to include -s and -C -F,
51 * fixed netstat -rC output (lib/inet_gr.c)
52 * removed broken NETLINK Support
53 * fixed format for /proc/net/udp|tcp|raw
54 * added -w,-t,-u TcpExt support to -s
55 *990131 {1.37} Jan Kratochvil added -p for prg_cache() & friends
56 * Flames to <short@ucw.cz>.
57 * Tuan Hoang added IGMP support for IPv4 and IPv6
59 *990420 {1.38} Tuan Hoang removed a useless assignment from igmp_do_one()
60 *20010404 {1.39} Arnaldo Carvalho de Melo - use setlocale
62 * This program is free software; you can redistribute it
63 * and/or modify it under the terms of the GNU General
64 * Public License as published by the Free Software
65 * Foundation; either version 2 of the License, or (at
66 * your option) any later version.
81 #include <sys/param.h>
82 #include <sys/socket.h>
83 #include <arpa/inet.h>
84 #include <netinet/in.h>
85 #include <sys/ioctl.h>
89 #include "net-support.h"
90 #include "pathnames.h"
95 #include "interface.h"
98 #define PROGNAME_WIDTH 20
100 #if !defined(s6_addr32) && defined(in6a_words)
101 #define s6_addr32 in6a_words /* libinet6 */
104 /* prototypes for statistics.c */
105 void parsesnmp(int, int, int);
109 SS_FREE
= 0, /* not allocated */
110 SS_UNCONNECTED
, /* unconnected to any socket */
111 SS_CONNECTING
, /* in process of connecting */
112 SS_CONNECTED
, /* connected to socket */
113 SS_DISCONNECTING
/* in process of disconnecting */
116 #define SO_ACCEPTCON (1<<16) /* performed a listen */
117 #define SO_WAITDATA (1<<17) /* wait data to read */
118 #define SO_NOSPACE (1<<18) /* no space to write */
120 #define DFLT_AF "inet"
122 #define FEATURE_NETSTAT
123 #include "lib/net-features.h"
125 char *Release
= RELEASE
, *Version
= "netstat 1.42 (2001-04-15)", *Signature
= "Fred Baumgarten, Alan Cox, Bernd Eckenfels, Phil Blundell, Tuan Hoang and others";
155 #define INFO_GUTS1(file,name,proc) \
156 procinfo = fopen((file), "r"); \
157 if (procinfo == NULL) { \
158 if (errno != ENOENT) { \
162 if (flag_arg || flag_ver) \
163 ESYSNOT("netstat", (name)); \
168 if (fgets(buffer, sizeof(buffer), procinfo)) \
169 (proc)(lnr++, buffer); \
170 } while (!feof(procinfo)); \
175 #define INFO_GUTS2(file,proc) \
177 procinfo = fopen((file), "r"); \
178 if (procinfo != NULL) { \
180 if (fgets(buffer, sizeof(buffer), procinfo)) \
181 (proc)(lnr++, buffer); \
182 } while (!feof(procinfo)); \
186 #define INFO_GUTS2(file,proc)
192 #define INFO_GUTS6(file,file6,name,proc) \
196 if (!flag_arg || flag_inet) { \
197 INFO_GUTS1(file,name,proc) \
199 if (!flag_arg || flag_inet6) { \
200 INFO_GUTS2(file6,proc) \
204 #define INFO_GUTS(file,name,proc) \
208 INFO_GUTS1(file,name,proc) \
211 #define PROGNAME_WIDTHs PROGNAME_WIDTH1(PROGNAME_WIDTH)
212 #define PROGNAME_WIDTH1(s) PROGNAME_WIDTH2(s)
213 #define PROGNAME_WIDTH2(s) #s
215 #define PRG_HASH_SIZE 211
217 static struct prg_node
{
218 struct prg_node
*next
;
220 char name
[PROGNAME_WIDTH
];
221 } *prg_hash
[PRG_HASH_SIZE
];
223 static char prg_cache_loaded
= 0;
225 #define PRG_HASHIT(x) ((x) % PRG_HASH_SIZE)
227 #define PROGNAME_BANNER "PID/Program name"
229 #define print_progname_banner() do { if (flag_prg) printf("%-" PROGNAME_WIDTHs "s"," " PROGNAME_BANNER); } while (0)
231 #define PRG_LOCAL_ADDRESS "local_address"
232 #define PRG_INODE "inode"
233 #define PRG_SOCKET_PFX "socket:["
234 #define PRG_SOCKET_PFXl (strlen(PRG_SOCKET_PFX))
235 #define PRG_SOCKET_PFX2 "[0000]:"
236 #define PRG_SOCKET_PFX2l (strlen(PRG_SOCKET_PFX2))
240 #define LINE_MAX 4096
243 #define PATH_PROC "/proc"
244 #define PATH_FD_SUFF "fd"
245 #define PATH_FD_SUFFl strlen(PATH_FD_SUFF)
246 #define PATH_PROC_X_FD PATH_PROC "/%s/" PATH_FD_SUFF
247 #define PATH_CMDLINE "cmdline"
248 #define PATH_CMDLINEl strlen(PATH_CMDLINE)
249 /* NOT working as of glibc-2.0.7: */
250 #undef DIRENT_HAVE_D_TYPE_WORKS
252 static void prg_cache_add(int inode
, char *name
)
254 unsigned hi
= PRG_HASHIT(inode
);
255 struct prg_node
**pnp
,*pn
;
258 for (pnp
=prg_hash
+hi
;(pn
=*pnp
);pnp
=&pn
->next
) {
259 if (pn
->inode
==inode
) {
260 /* Some warning should be appropriate here
261 as we got multiple processes for one i-node */
265 if (!(*pnp
=malloc(sizeof(**pnp
))))
270 if (strlen(name
)>sizeof(pn
->name
)-1)
271 name
[sizeof(pn
->name
)-1]='\0';
272 strcpy(pn
->name
,name
);
275 static const char *prg_cache_get(int inode
)
277 unsigned hi
=PRG_HASHIT(inode
);
280 for (pn
=prg_hash
[hi
];pn
;pn
=pn
->next
)
281 if (pn
->inode
==inode
) return(pn
->name
);
285 static void prg_cache_clear(void)
287 struct prg_node
**pnp
,*pn
;
289 if (prg_cache_loaded
== 2)
290 for (pnp
=prg_hash
;pnp
<prg_hash
+PRG_HASH_SIZE
;pnp
++)
298 static void extract_type_1_socket_inode(const char lname
[], long * inode_p
) {
300 /* If lname is of the form "socket:[12345]", extract the "12345"
301 as *inode_p. Otherwise, return -1 as *inode_p.
304 if (strlen(lname
) < PRG_SOCKET_PFXl
+3) *inode_p
= -1;
305 else if (memcmp(lname
, PRG_SOCKET_PFX
, PRG_SOCKET_PFXl
)) *inode_p
= -1;
306 else if (lname
[strlen(lname
)-1] != ']') *inode_p
= -1;
308 char inode_str
[strlen(lname
+ 1)]; /* e.g. "12345" */
309 const int inode_str_len
= strlen(lname
) - PRG_SOCKET_PFXl
- 1;
312 strncpy(inode_str
, lname
+PRG_SOCKET_PFXl
, inode_str_len
);
313 inode_str
[inode_str_len
] = '\0';
314 *inode_p
= strtol(inode_str
,&serr
,0);
315 if (!serr
|| *serr
|| *inode_p
< 0 || *inode_p
>= INT_MAX
)
322 static void extract_type_2_socket_inode(const char lname
[], long * inode_p
) {
324 /* If lname is of the form "[0000]:12345", extract the "12345"
325 as *inode_p. Otherwise, return -1 as *inode_p.
328 if (strlen(lname
) < PRG_SOCKET_PFX2l
+1) *inode_p
= -1;
329 else if (memcmp(lname
, PRG_SOCKET_PFX2
, PRG_SOCKET_PFX2l
)) *inode_p
= -1;
333 *inode_p
=strtol(lname
+ PRG_SOCKET_PFX2l
,&serr
,0);
334 if (!serr
|| *serr
|| *inode_p
< 0 || *inode_p
>= INT_MAX
)
341 static void prg_cache_load(void)
343 char line
[LINE_MAX
],eacces
=0;
344 int procfdlen
,fd
,cmdllen
,lnamelen
;
345 char lname
[30],cmdlbuf
[512],finbuf
[PROGNAME_WIDTH
];
347 const char *cs
,*cmdlp
;
348 DIR *dirproc
=NULL
,*dirfd
=NULL
;
349 struct dirent
*direproc
,*direfd
;
351 if (prg_cache_loaded
|| !flag_prg
) return;
353 cmdlbuf
[sizeof(cmdlbuf
)-1]='\0';
354 if (!(dirproc
=opendir(PATH_PROC
))) goto fail
;
355 while (errno
=0,direproc
=readdir(dirproc
)) {
356 #ifdef DIRENT_HAVE_D_TYPE_WORKS
357 if (direproc
->d_type
!=DT_DIR
) continue;
359 for (cs
=direproc
->d_name
;*cs
;cs
++)
364 procfdlen
=snprintf(line
,sizeof(line
),PATH_PROC_X_FD
,direproc
->d_name
);
365 if (procfdlen
<=0 || procfdlen
>=sizeof(line
)-5)
374 line
[procfdlen
] = '/';
376 while ((direfd
= readdir(dirfd
))) {
377 #ifdef DIRENT_HAVE_D_TYPE_WORKS
378 if (direfd
->d_type
!=DT_LNK
)
381 if (procfdlen
+1+strlen(direfd
->d_name
)+1>sizeof(line
))
383 memcpy(line
+ procfdlen
- PATH_FD_SUFFl
, PATH_FD_SUFF
"/",
385 strcpy(line
+ procfdlen
+ 1, direfd
->d_name
);
386 lnamelen
=readlink(line
,lname
,sizeof(lname
)-1);
387 lname
[lnamelen
] = '\0'; /*make it a null-terminated string*/
389 extract_type_1_socket_inode(lname
, &inode
);
391 if (inode
< 0) extract_type_2_socket_inode(lname
, &inode
);
393 if (inode
< 0) continue;
396 if (procfdlen
- PATH_FD_SUFFl
+ PATH_CMDLINEl
>=
399 strcpy(line
+ procfdlen
-PATH_FD_SUFFl
, PATH_CMDLINE
);
400 fd
= open(line
, O_RDONLY
);
403 cmdllen
= read(fd
, cmdlbuf
, sizeof(cmdlbuf
) - 1);
408 if (cmdllen
< sizeof(cmdlbuf
) - 1)
409 cmdlbuf
[cmdllen
]='\0';
410 if ((cmdlp
= strrchr(cmdlbuf
, '/')))
416 snprintf(finbuf
, sizeof(finbuf
), "%s/%s", direproc
->d_name
, cmdlp
);
417 prg_cache_add(inode
, finbuf
);
428 if (prg_cache_loaded
== 1) {
430 fprintf(stderr
,_("(No info could be read for \"-p\": geteuid()=%d but you should be root.)\n"),
434 fprintf(stderr
, _("(Not all processes could be identified, non-owned process info\n"
435 " will not be shown, you would have to be root to see it all.)\n"));
439 static const char *netrom_state
[] =
447 static int netrom_info(void)
450 char buffer
[256], dev
[16];
451 int st
, vs
, vr
, sendq
, recvq
, ret
;
453 f
= fopen(_PATH_PROCNET_NR
, "r");
455 if (errno
!= ENOENT
) {
456 perror(_PATH_PROCNET_NR
);
459 if (flag_arg
|| flag_ver
)
460 ESYSNOT("netstat", "AF NETROM");
466 printf(_("Active NET/ROM sockets\n"));
467 printf(_("User Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
468 fgets(buffer
, 256, f
);
470 while (fgets(buffer
, 256, f
)) {
474 ret
= sscanf(buffer
+ 30, "%s %*x/%*x %*x/%*x %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d %d %d %*d",
475 dev
, &st
, &vs
, &vr
, &sendq
, &recvq
);
477 printf(_("Problem reading data from %s\n"), _PATH_PROCNET_NR
);
480 printf("%-9s %-9s %-9s %-6s %-11s %03d/%03d %-6d %-6d\n",
481 buffer
, buffer
+ 10, buffer
+ 20,
484 vr
, vs
, sendq
, recvq
);
491 /* These enums are used by IPX too. :-( */
503 TCP_CLOSING
/* now a valid state */
506 #if HAVE_AFINET || HAVE_AFINET6
508 static const char *tcp_state
[] =
524 static void finish_this_one(int uid
, unsigned long inode
, const char *timers
)
529 if (!(flag_not
& FLAG_NUM_USER
) && ((pw
= getpwuid(uid
)) != NULL
))
530 printf("%-10s ", pw
->pw_name
);
532 printf("%-10d ", uid
);
533 printf("%-10ld ",inode
);
536 printf("%-" PROGNAME_WIDTHs
"s",prg_cache_get(inode
));
538 printf("%s", timers
);
542 static void igmp_do_one(int lnr
, const char *line
)
544 char mcast_addr
[128];
546 struct sockaddr_in6 mcastaddr
;
547 char addr6
[INET6_ADDRSTRLEN
];
549 extern struct aftype inet6_aftype
;
551 struct sockaddr_in mcastaddr
;
554 static int idx_flag
= 0;
555 static int igmp6_flag
= 0;
556 static char device
[16];
557 int num
, idx
, refcnt
;
561 /* igmp6 file does not have any comments on first line */
562 if ( strstr( line
, "Device" ) == NULL
) {
566 /* 2.1.x kernels and up have Idx field */
567 /* 2.0.x and below do not have Idx field */
568 if ( strncmp( line
, "Idx", strlen("Idx") ) == 0 )
576 if (igmp6_flag
) { /* IPV6 */
578 num
= sscanf( line
, "%d %15s %64[0-9A-Fa-f] %d", &idx
, device
, mcast_addr
, &refcnt
);
580 /* Demangle what the kernel gives us */
581 sscanf(mcast_addr
, "%08X%08X%08X%08X",
582 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
583 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
584 in6
.s6_addr32
[0] = htonl(in6
.s6_addr32
[0]);
585 in6
.s6_addr32
[1] = htonl(in6
.s6_addr32
[1]);
586 in6
.s6_addr32
[2] = htonl(in6
.s6_addr32
[2]);
587 in6
.s6_addr32
[3] = htonl(in6
.s6_addr32
[3]);
588 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
589 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &mcastaddr
);
590 mcastaddr
.sin6_family
= AF_INET6
;
592 fprintf(stderr
, _("warning, got bogus igmp6 line %d.\n"), lnr
);
596 if ((ap
= get_afntype(((struct sockaddr
*) &mcastaddr
)->sa_family
)) == NULL
) {
597 fprintf(stderr
, _("netstat: unsupported address family %d !\n"),
598 ((struct sockaddr
*) &mcastaddr
)->sa_family
);
601 safe_strncpy(mcast_addr
, ap
->sprint((struct sockaddr
*) &mcastaddr
,
602 flag_not
), sizeof(mcast_addr
));
603 printf("%-15s %-6d %s\n", device
, refcnt
, mcast_addr
);
607 if (line
[0] != '\t') {
609 if ((num
= sscanf( line
, "%d\t%10c", &idx
, device
)) < 2) {
610 fprintf(stderr
, _("warning, got bogus igmp line %d.\n"), lnr
);
614 if ( (num
= sscanf( line
, "%10c", device
)) < 1 ) {
615 fprintf(stderr
, _("warning, got bogus igmp line %d.\n"), lnr
);
621 } else if ( line
[0] == '\t' ) {
622 if ( (num
= sscanf(line
, "\t%8[0-9A-Fa-f] %d", mcast_addr
, &refcnt
)) < 2 ) {
623 fprintf(stderr
, _("warning, got bogus igmp line %d.\n"), lnr
);
626 sscanf( mcast_addr
, "%X",
627 &((struct sockaddr_in
*) &mcastaddr
)->sin_addr
.s_addr
);
628 ((struct sockaddr
*) &mcastaddr
)->sa_family
= AF_INET
;
630 fprintf(stderr
, _("warning, got bogus igmp line %d.\n"), lnr
);
634 if ((ap
= get_afntype(((struct sockaddr
*) &mcastaddr
)->sa_family
)) == NULL
) {
635 fprintf(stderr
, _("netstat: unsupported address family %d !\n"),
636 ((struct sockaddr
*) &mcastaddr
)->sa_family
);
639 safe_strncpy(mcast_addr
, ap
->sprint((struct sockaddr
*) &mcastaddr
,
640 flag_not
), sizeof(mcast_addr
));
641 printf("%-15s %-6d %s\n", device
, refcnt
, mcast_addr
);
647 static int x25_info(void)
649 FILE *f
=fopen(_PATH_PROCNET_X25
, "r");
650 char buffer
[256],dev
[16];
651 int st
,vs
,vr
,sendq
,recvq
,lci
;
652 static char *x25_state
[5]=
660 if(!(f
=fopen(_PATH_PROCNET_X25
, "r")))
662 if (errno
!= ENOENT
) {
663 perror(_PATH_PROCNET_X25
);
666 if (flag_arg
|| flag_ver
)
667 ESYSNOT("netstat","AF X25");
673 printf( _("Active X.25 sockets\n"));
674 /* IMHO, Vr/Vs is not very usefull --SF */
675 printf( _("Dest Source Device LCI State Vr/Vs Send-Q Recv-Q\n"));
677 while(fgets(buffer
,256,f
))
681 sscanf(buffer
+22,"%s %d %d %d %d %*d %*d %*d %*d %*d %*d %d %d %*d",
682 dev
,&lci
,&st
,&vs
,&vr
,&sendq
,&recvq
);
683 if (!(flag_all
|| lci
))
685 printf("%-15s %-15s %-7s %-3d %-11s %02d/%02d %-6d %-6d\n",
697 static int igmp_info(void)
699 INFO_GUTS6(_PATH_PROCNET_IGMP
, _PATH_PROCNET_IGMP6
, "AF INET (igmp)",
703 static void tcp_do_one(int lnr
, const char *line
)
705 unsigned long rxq
, txq
, time_len
, retr
, inode
;
706 int num
, local_port
, rem_port
, d
, state
, uid
, timer_run
, timeout
;
707 char rem_addr
[128], local_addr
[128], timers
[64], buffer
[1024], more
[512];
710 struct sockaddr_in6 localaddr
, remaddr
;
711 char addr6
[INET6_ADDRSTRLEN
];
713 extern struct aftype inet6_aftype
;
715 struct sockaddr_in localaddr
, remaddr
;
722 "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
723 &d
, local_addr
, &local_port
, rem_addr
, &rem_port
, &state
,
724 &txq
, &rxq
, &timer_run
, &time_len
, &retr
, &uid
, &timeout
, &inode
, more
);
726 if (strlen(local_addr
) > 8) {
728 /* Demangle what the kernel gives us */
729 sscanf(local_addr
, "%08X%08X%08X%08X",
730 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
731 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
732 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
733 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &localaddr
);
734 sscanf(rem_addr
, "%08X%08X%08X%08X",
735 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
736 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
737 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
738 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &remaddr
);
739 localaddr
.sin6_family
= AF_INET6
;
740 remaddr
.sin6_family
= AF_INET6
;
743 sscanf(local_addr
, "%X",
744 &((struct sockaddr_in
*) &localaddr
)->sin_addr
.s_addr
);
745 sscanf(rem_addr
, "%X",
746 &((struct sockaddr_in
*) &remaddr
)->sin_addr
.s_addr
);
747 ((struct sockaddr
*) &localaddr
)->sa_family
= AF_INET
;
748 ((struct sockaddr
*) &remaddr
)->sa_family
= AF_INET
;
752 fprintf(stderr
, _("warning, got bogus tcp line.\n"));
755 if ((ap
= get_afntype(((struct sockaddr
*) &localaddr
)->sa_family
)) == NULL
) {
756 fprintf(stderr
, _("netstat: unsupported address family %d !\n"),
757 ((struct sockaddr
*) &localaddr
)->sa_family
);
760 if (state
== TCP_LISTEN
) {
766 safe_strncpy(local_addr
, ap
->sprint((struct sockaddr
*) &localaddr
,
767 flag_not
), sizeof(local_addr
));
768 safe_strncpy(rem_addr
, ap
->sprint((struct sockaddr
*) &remaddr
, flag_not
),
770 if (flag_all
|| (flag_lst
&& !rem_port
) || (!flag_lst
&& rem_port
)) {
771 snprintf(buffer
, sizeof(buffer
), "%s",
772 get_sname(htons(local_port
), "tcp",
773 flag_not
& FLAG_NUM_PORT
));
775 if ((strlen(local_addr
) + strlen(buffer
)) > 22)
776 local_addr
[22 - strlen(buffer
)] = '\0';
778 strcat(local_addr
, ":");
779 strcat(local_addr
, buffer
);
780 snprintf(buffer
, sizeof(buffer
), "%s",
781 get_sname(htons(rem_port
), "tcp", flag_not
& FLAG_NUM_PORT
));
783 if ((strlen(rem_addr
) + strlen(buffer
)) > 22)
784 rem_addr
[22 - strlen(buffer
)] = '\0';
786 strcat(rem_addr
, ":");
787 strcat(rem_addr
, buffer
);
793 snprintf(timers
, sizeof(timers
), _("off (0.00/%ld/%d)"), retr
, timeout
);
797 snprintf(timers
, sizeof(timers
), _("on (%2.2f/%ld/%d)"),
798 (double) time_len
/ HZ
, retr
, timeout
);
802 snprintf(timers
, sizeof(timers
), _("keepalive (%2.2f/%ld/%d)"),
803 (double) time_len
/ HZ
, retr
, timeout
);
807 snprintf(timers
, sizeof(timers
), _("timewait (%2.2f/%ld/%d)"),
808 (double) time_len
/ HZ
, retr
, timeout
);
812 snprintf(timers
, sizeof(timers
), _("unkn-%d (%2.2f/%ld/%d)"),
813 timer_run
, (double) time_len
/ HZ
, retr
, timeout
);
816 printf("tcp %6ld %6ld %-*s %-*s %-12s",
817 rxq
, txq
, max(23,strlen(local_addr
)+1), local_addr
, max(23,strlen(rem_addr
)), rem_addr
, _(tcp_state
[state
]));
819 finish_this_one(uid
,inode
,timers
);
823 static int tcp_info(void)
825 INFO_GUTS6(_PATH_PROCNET_TCP
, _PATH_PROCNET_TCP6
, "AF INET (tcp)",
829 static void udp_do_one(int lnr
, const char *line
)
831 char buffer
[8192], local_addr
[64], rem_addr
[64];
832 char *udp_state
, timers
[64], more
[512];
833 int num
, local_port
, rem_port
, d
, state
, timer_run
, uid
, timeout
;
835 struct sockaddr_in6 localaddr
, remaddr
;
836 char addr6
[INET6_ADDRSTRLEN
];
838 extern struct aftype inet6_aftype
;
840 struct sockaddr_in localaddr
, remaddr
;
843 unsigned long rxq
, txq
, time_len
, retr
, inode
;
850 "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
851 &d
, local_addr
, &local_port
,
852 rem_addr
, &rem_port
, &state
,
853 &txq
, &rxq
, &timer_run
, &time_len
, &retr
, &uid
, &timeout
, &inode
, more
);
855 if (strlen(local_addr
) > 8) {
857 sscanf(local_addr
, "%08X%08X%08X%08X",
858 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
859 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
860 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
861 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &localaddr
);
862 sscanf(rem_addr
, "%08X%08X%08X%08X",
863 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
864 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
865 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
866 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &remaddr
);
867 localaddr
.sin6_family
= AF_INET6
;
868 remaddr
.sin6_family
= AF_INET6
;
871 sscanf(local_addr
, "%X",
872 &((struct sockaddr_in
*) &localaddr
)->sin_addr
.s_addr
);
873 sscanf(rem_addr
, "%X",
874 &((struct sockaddr_in
*) &remaddr
)->sin_addr
.s_addr
);
875 ((struct sockaddr
*) &localaddr
)->sa_family
= AF_INET
;
876 ((struct sockaddr
*) &remaddr
)->sa_family
= AF_INET
;
884 fprintf(stderr
, _("warning, got bogus udp line.\n"));
887 if ((ap
= get_afntype(((struct sockaddr
*) &localaddr
)->sa_family
)) == NULL
) {
888 fprintf(stderr
, _("netstat: unsupported address family %d !\n"),
889 ((struct sockaddr
*) &localaddr
)->sa_family
);
893 case TCP_ESTABLISHED
:
894 udp_state
= _("ESTABLISHED");
902 udp_state
= _("UNKNOWN");
907 #define notnull(A) (((A.sin6_family == AF_INET6) && \
908 ((A.sin6_addr.s6_addr32[0]) || \
909 (A.sin6_addr.s6_addr32[1]) || \
910 (A.sin6_addr.s6_addr32[2]) || \
911 (A.sin6_addr.s6_addr32[3]))) || \
912 ((A.sin6_family == AF_INET) && \
913 ((struct sockaddr_in *) &A)->sin_addr.s_addr))
915 #define notnull(A) (A.sin_addr.s_addr)
918 if (flag_all
|| (notnull(remaddr
) && !flag_lst
) || (!notnull(remaddr
) && flag_lst
))
920 safe_strncpy(local_addr
, ap
->sprint((struct sockaddr
*) &localaddr
,
921 flag_not
), sizeof(local_addr
));
922 snprintf(buffer
, sizeof(buffer
), "%s",
923 get_sname(htons(local_port
), "udp",
924 flag_not
& FLAG_NUM_PORT
));
925 if ((strlen(local_addr
) + strlen(buffer
)) > 22)
926 local_addr
[22 - strlen(buffer
)] = '\0';
927 strcat(local_addr
, ":");
928 strcat(local_addr
, buffer
);
930 snprintf(buffer
, sizeof(buffer
), "%s",
931 get_sname(htons(rem_port
), "udp", flag_not
& FLAG_NUM_PORT
));
932 safe_strncpy(rem_addr
, ap
->sprint((struct sockaddr
*) &remaddr
,
933 flag_not
), sizeof(rem_addr
));
934 if ((strlen(rem_addr
) + strlen(buffer
)) > 22)
935 rem_addr
[22 - strlen(buffer
)] = '\0';
936 strcat(rem_addr
, ":");
937 strcat(rem_addr
, buffer
);
943 snprintf(timers
, sizeof(timers
), _("off (0.00/%ld/%d)"), retr
, timeout
);
948 snprintf(timers
, sizeof(timers
), _("on%d (%2.2f/%ld/%d)"), timer_run
, (double) time_len
/ 100, retr
, timeout
);
952 snprintf(timers
, sizeof(timers
), _("unkn-%d (%2.2f/%ld/%d)"), timer_run
, (double) time_len
/ 100,
956 printf("udp %6ld %6ld %-23s %-23s %-12s",
957 rxq
, txq
, local_addr
, rem_addr
, udp_state
);
959 finish_this_one(uid
,inode
,timers
);
963 static int udp_info(void)
965 INFO_GUTS6(_PATH_PROCNET_UDP
, _PATH_PROCNET_UDP6
, "AF INET (udp)",
969 static void raw_do_one(int lnr
, const char *line
)
971 char buffer
[8192], local_addr
[64], rem_addr
[64];
972 char timers
[64], more
[512];
973 int num
, local_port
, rem_port
, d
, state
, timer_run
, uid
, timeout
;
975 struct sockaddr_in6 localaddr
, remaddr
;
976 char addr6
[INET6_ADDRSTRLEN
];
978 extern struct aftype inet6_aftype
;
980 struct sockaddr_in localaddr
, remaddr
;
983 unsigned long rxq
, txq
, time_len
, retr
, inode
;
990 "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
991 &d
, local_addr
, &local_port
, rem_addr
, &rem_port
, &state
,
992 &txq
, &rxq
, &timer_run
, &time_len
, &retr
, &uid
, &timeout
, &inode
, more
);
994 if (strlen(local_addr
) > 8) {
996 sscanf(local_addr
, "%08X%08X%08X%08X",
997 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
998 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
999 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
1000 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &localaddr
);
1001 sscanf(rem_addr
, "%08X%08X%08X%08X",
1002 &in6
.s6_addr32
[0], &in6
.s6_addr32
[1],
1003 &in6
.s6_addr32
[2], &in6
.s6_addr32
[3]);
1004 inet_ntop(AF_INET6
, &in6
, addr6
, sizeof(addr6
));
1005 inet6_aftype
.input(1, addr6
, (struct sockaddr
*) &remaddr
);
1006 localaddr
.sin6_family
= AF_INET6
;
1007 remaddr
.sin6_family
= AF_INET6
;
1010 sscanf(local_addr
, "%X",
1011 &((struct sockaddr_in
*) &localaddr
)->sin_addr
.s_addr
);
1012 sscanf(rem_addr
, "%X",
1013 &((struct sockaddr_in
*) &remaddr
)->sin_addr
.s_addr
);
1014 ((struct sockaddr
*) &localaddr
)->sa_family
= AF_INET
;
1015 ((struct sockaddr
*) &remaddr
)->sa_family
= AF_INET
;
1018 if ((ap
= get_afntype(localaddr
.sin6_family
)) == NULL
) {
1019 fprintf(stderr
, _("netstat: unsupported address family %d !\n"), localaddr
.sin6_family
);
1023 if ((ap
= get_afntype(localaddr
.sin_family
)) == NULL
) {
1024 fprintf(stderr
, _("netstat: unsupported address family %d !\n"), localaddr
.sin_family
);
1033 fprintf(stderr
, _("warning, got bogus raw line.\n"));
1037 if (flag_all
|| (notnull(remaddr
) && !flag_lst
) || (!notnull(remaddr
) && flag_lst
))
1039 snprintf(buffer
, sizeof(buffer
), "%s",
1040 get_sname(htons(local_port
), "raw",
1041 flag_not
& FLAG_NUM_PORT
));
1042 safe_strncpy(local_addr
, ap
->sprint((struct sockaddr
*) &localaddr
,
1043 flag_not
), sizeof(local_addr
));
1044 if ((strlen(local_addr
) + strlen(buffer
)) > 22)
1045 local_addr
[22 - strlen(buffer
)] = '\0';
1046 strcat(local_addr
, ":");
1047 strcat(local_addr
, buffer
);
1049 snprintf(buffer
, sizeof(buffer
), "%s",
1050 get_sname(htons(rem_port
), "raw", flag_not
& FLAG_NUM_PORT
));
1051 safe_strncpy(rem_addr
, ap
->sprint((struct sockaddr
*) &remaddr
,
1052 flag_not
), sizeof(rem_addr
));
1053 if ((strlen(rem_addr
) + strlen(buffer
)) > 22)
1054 rem_addr
[22 - strlen(buffer
)] = '\0';
1055 strcat(rem_addr
, ":");
1056 strcat(rem_addr
, buffer
);
1060 switch (timer_run
) {
1062 snprintf(timers
, sizeof(timers
), _("off (0.00/%ld/%d)"), retr
, timeout
);
1067 snprintf(timers
, sizeof(timers
), _("on%d (%2.2f/%ld/%d)"), timer_run
, (double) time_len
/ 100,
1072 snprintf(timers
, sizeof(timers
), _("unkn-%d (%2.2f/%ld/%d)"),
1073 timer_run
, (double) time_len
/ 100,
1077 printf("raw %6ld %6ld %-23s %-23s %-12d",
1078 rxq
, txq
, local_addr
, rem_addr
, state
);
1080 finish_this_one(uid
,inode
,timers
);
1084 static int raw_info(void)
1086 INFO_GUTS6(_PATH_PROCNET_RAW
, _PATH_PROCNET_RAW6
, "AF INET (raw)",
1097 static void unix_do_one(int nr
, const char *line
)
1100 char path
[MAXPATHLEN
], ss_flags
[32];
1101 char *ss_proto
, *ss_state
, *ss_type
;
1102 int num
, state
, type
, inode
;
1104 unsigned long refcnt
, proto
, flags
;
1107 if (strstr(line
, "Inode"))
1112 num
= sscanf(line
, "%p: %lX %lX %lX %X %X %d %s",
1113 &d
, &refcnt
, &proto
, &flags
, &type
, &state
, &inode
, path
);
1115 fprintf(stderr
, _("warning, got bogus unix line.\n"));
1118 if (!(has
& HAS_INODE
))
1119 snprintf(path
,sizeof(path
),"%d",inode
);
1122 if ((state
== SS_UNCONNECTED
) && (flags
& SO_ACCEPTCON
)) {
1142 ss_type
= _("STREAM");
1146 ss_type
= _("DGRAM");
1157 case SOCK_SEQPACKET
:
1158 ss_type
= _("SEQPACKET");
1162 ss_type
= _("UNKNOWN");
1167 ss_state
= _("FREE");
1170 case SS_UNCONNECTED
:
1172 * Unconnected sockets may be listening
1175 if (flags
& SO_ACCEPTCON
) {
1176 ss_state
= _("LISTENING");
1183 ss_state
= _("CONNECTING");
1187 ss_state
= _("CONNECTED");
1190 case SS_DISCONNECTING
:
1191 ss_state
= _("DISCONNECTING");
1195 ss_state
= _("UNKNOWN");
1198 strcpy(ss_flags
, "[ ");
1199 if (flags
& SO_ACCEPTCON
)
1200 strcat(ss_flags
, "ACC ");
1201 if (flags
& SO_WAITDATA
)
1202 strcat(ss_flags
, "W ");
1203 if (flags
& SO_NOSPACE
)
1204 strcat(ss_flags
, "N ");
1206 strcat(ss_flags
, "]");
1208 printf("%-5s %-6ld %-11s %-10s %-13s ",
1209 ss_proto
, refcnt
, ss_flags
, ss_type
, ss_state
);
1210 if (has
& HAS_INODE
)
1211 printf("%-6d ",inode
);
1215 printf("%-" PROGNAME_WIDTHs
"s",(has
& HAS_INODE
?prg_cache_get(inode
):"-"));
1219 static int unix_info(void)
1222 printf(_("Active UNIX domain sockets "));
1224 printf(_("(servers and established)"));
1227 printf(_("(only servers)"));
1229 printf(_("(w/o servers)"));
1232 printf(_("\nProto RefCnt Flags Type State I-Node"));
1233 print_progname_banner();
1234 printf(_(" Path\n")); /* xxx */
1237 INFO_GUTS(_PATH_PROCNET_UNIX
, "AF UNIX", unix_do_one
);
1244 static int ax25_info(void)
1247 char buffer
[256], buf
[16];
1248 char *src
, *dst
, *dev
, *p
;
1249 int st
, vs
, vr
, sendq
, recvq
, ret
;
1250 int new = -1; /* flag for new (2.1.x) kernels */
1251 static char *ax25_state
[5] =
1259 if (!(f
= fopen(_PATH_PROCNET_AX25
, "r"))) {
1260 if (errno
!= ENOENT
) {
1261 perror(_PATH_PROCNET_AX25
);
1264 if (flag_arg
|| flag_ver
)
1265 ESYSNOT("netstat", "AF AX25");
1271 printf(_("Active AX.25 sockets\n"));
1272 printf(_("Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
1273 while (fgets(buffer
, 256, f
)) {
1275 if (!strncmp(buffer
, "dest_addr", 9)) {
1277 continue; /* old kernels have a header line */
1282 * In a network connection with no user socket the Snd-Q, Rcv-Q
1283 * and Inode fields are empty in 2.0.x and '*' in 2.1.x
1292 ret
= sscanf(buffer
+ 20, "%s %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d %*d %*d %d %d %*d",
1293 buf
, &st
, &vs
, &vr
, &sendq
, &recvq
);
1294 if (ret
!= 4 && ret
!= 6) {
1295 printf(_("Problem reading data from %s\n"), _PATH_PROCNET_AX25
);
1301 while (*p
!= ' ') p
++;
1304 while (*p
!= ' ') p
++;
1307 while (*p
!= ' ') p
++;
1310 while (*p
!= ' ') p
++;
1312 ret
= sscanf(p
, "%d %d %d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d %d %*d",
1313 &st
, &vs
, &vr
, &sendq
, &recvq
);
1314 if (ret
!= 3 && ret
!= 5) {
1315 printf(_("problem reading data from %s\n"), _PATH_PROCNET_AX25
);
1319 * FIXME: digipeaters should be handled somehow.
1320 * For now we just strip them.
1323 while (*p
&& *p
!= ',') p
++;
1326 printf("%-9s %-9s %-6s %-11s %03d/%03d %-6d %-6d\n",
1330 vr
, vs
, sendq
, recvq
);
1339 static int ipx_info(void)
1343 unsigned long txq
, rxq
;
1350 char sad
[50], dad
[50];
1352 unsigned sport
= 0, dport
= 0;
1354 if (!(f
= fopen(_PATH_PROCNET_IPX
, "r"))) {
1355 if (errno
!= ENOENT
) {
1356 perror(_PATH_PROCNET_IPX
);
1359 if (flag_arg
|| flag_ver
)
1360 ESYSNOT("netstat", "AF IPX");
1366 printf(_("Active IPX sockets\nProto Recv-Q Send-Q Local Address Foreign Address State")); /* xxx */
1368 printf(_(" User")); /* xxx */
1370 if ((ap
= get_afntype(AF_IPX
)) == NULL
) {
1371 EINTERN("netstat.c", "AF_IPX missing");
1376 while (fgets(buf
, 255, f
) != NULL
) {
1377 sscanf(buf
, "%s %s %lX %lX %d %d",
1378 sad
, dad
, &txq
, &rxq
, &state
, &uid
);
1379 if ((st
= rindex(sad
, ':'))) {
1381 sscanf(st
, "%X", &sport
); /* net byt order */
1382 sport
= ntohs(sport
);
1384 EINTERN("netstat.c", _PATH_PROCNET_IPX
" sport format error");
1388 if (strcmp(dad
, "Not_Connected") != 0) {
1389 if ((st
= rindex(dad
, ':'))) {
1391 sscanf(st
, "%X", &dport
); /* net byt order */
1392 dport
= ntohs(dport
);
1394 EINTERN("netstat.c", _PATH_PROCNET_IPX
" dport format error");
1401 case TCP_ESTABLISHED
:
1414 /* Fetch and resolve the Source */
1415 (void) ap
->input(4, sad
, &sa
);
1416 safe_strncpy(buf
, ap
->sprint(&sa
, flag_not
), sizeof(buf
));
1417 snprintf(sad
, sizeof(sad
), "%s:%04X", buf
, sport
);
1420 /* Fetch and resolve the Destination */
1421 (void) ap
->input(4, dad
, &sa
);
1422 safe_strncpy(buf
, ap
->sprint(&sa
, flag_not
), sizeof(buf
));
1423 snprintf(dad
, sizeof(dad
), "%s:%04X", buf
, dport
);
1427 printf("IPX %6ld %6ld %-26s %-26s %-5s", txq
, rxq
, sad
, dad
, st
);
1429 if (!(flag_not
& FLAG_NUM_USER
) && ((pw
= getpwuid(uid
)) != NULL
))
1430 printf(" %-10s", pw
->pw_name
);
1432 printf(" %-10d", uid
);
1441 static int iface_info(void)
1444 if ((skfd
= sockets_open(0)) < 0) {
1448 printf(_("Kernel Interface table\n"));
1452 printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
1455 if (for_all_interfaces(do_if_print
, &flag_all
) < 0) {
1456 perror(_("missing interface information"));
1460 free_interface_list();
1470 static void version(void)
1472 printf("%s\n%s\n%s\n%s\n", Release
, Version
, Signature
, Features
);
1477 static void usage(void)
1479 fprintf(stderr
, _("usage: netstat [-veenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}\n"));
1480 fprintf(stderr
, _(" netstat [-vnNcaeol] [<Socket> ...]\n"));
1481 fprintf(stderr
, _(" netstat { [-veenNac] -i | [-cnNe] -M | -s }\n\n"));
1483 fprintf(stderr
, _(" -r, --route display routing table\n"));
1484 fprintf(stderr
, _(" -i, --interfaces display interface table\n"));
1485 fprintf(stderr
, _(" -g, --groups display multicast group memberships\n"));
1486 fprintf(stderr
, _(" -s, --statistics display networking statistics (like SNMP)\n"));
1487 #if HAVE_FW_MASQUERADE
1488 fprintf(stderr
, _(" -M, --masquerade display masqueraded connections\n\n"));
1490 fprintf(stderr
, _(" -v, --verbose be verbose\n"));
1491 fprintf(stderr
, _(" -n, --numeric don't resolve names\n"));
1492 fprintf(stderr
, _(" --numeric-hosts don't resolve host names\n"));
1493 fprintf(stderr
, _(" --numeric-ports don't resolve port names\n"));
1494 fprintf(stderr
, _(" --numeric-users don't resolve user names\n"));
1495 fprintf(stderr
, _(" -N, --symbolic resolve hardware names\n"));
1496 fprintf(stderr
, _(" -e, --extend display other/more information\n"));
1497 fprintf(stderr
, _(" -p, --programs display PID/Program name for sockets\n"));
1498 fprintf(stderr
, _(" -c, --continuous continuous listing\n\n"));
1499 fprintf(stderr
, _(" -l, --listening display listening server sockets\n"));
1500 fprintf(stderr
, _(" -a, --all, --listening display all sockets (default: connected)\n"));
1501 fprintf(stderr
, _(" -o, --timers display timers\n"));
1502 fprintf(stderr
, _(" -F, --fib display Forwarding Information Base (default)\n"));
1503 fprintf(stderr
, _(" -C, --cache display routing cache instead of FIB\n\n"));
1505 fprintf(stderr
, _(" <Socket>={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom\n"));
1506 fprintf(stderr
, _(" <AF>=Use '-A <af>' or '--<af>'; default: %s\n"), DFLT_AF
);
1507 fprintf(stderr
, _(" List of possible address families (which support routing):\n"));
1508 print_aflist(1); /* 1 = routeable */
1514 (int argc
, char *argv
[]) {
1517 static struct option longopts
[] =
1520 {"version", 0, 0, 'V'},
1521 {"interfaces", 0, 0, 'i'},
1522 {"help", 0, 0, 'h'},
1523 {"route", 0, 0, 'r'},
1524 #if HAVE_FW_MASQUERADE
1525 {"masquerade", 0, 0, 'M'},
1527 {"protocol", 1, 0, 'A'},
1531 {"unix", 0, 0, 'x'},
1532 {"listening", 0, 0, 'l'},
1534 {"timers", 0, 0, 'o'},
1535 {"continuous", 0, 0, 'c'},
1536 {"extend", 0, 0, 'e'},
1537 {"programs", 0, 0, 'p'},
1538 {"verbose", 0, 0, 'v'},
1539 {"statistics", 0, 0, 's'},
1540 {"numeric", 0, 0, 'n'},
1541 {"numeric-hosts", 0, 0, '!'},
1542 {"numeric-ports", 0, 0, '@'},
1543 {"numeric-users", 0, 0, '#'},
1544 {"symbolic", 0, 0, 'N'},
1545 {"cache", 0, 0, 'C'},
1547 {"groups", 0, 0, 'g'},
1552 setlocale (LC_ALL
, "");
1553 bindtextdomain("net-tools", "/usr/share/locale");
1554 textdomain("net-tools");
1556 getroute_init(); /* Set up AF routing support */
1559 while ((i
= getopt_long(argc
, argv
, "MCFA:acdegphinNorstuVv?wxl", longopts
, &lop
)) != EOF
)
1564 if (lop
< 0 || lop
>= AFTRANS_CNT
) {
1565 EINTERN("netstat.c", "longopts 1 range");
1568 if (aftrans_opt(longopts
[lop
].name
))
1572 if (aftrans_opt(optarg
))
1604 flag_not
|= FLAG_NUM
;
1607 flag_not
|= FLAG_NUM_HOST
;
1610 flag_not
|= FLAG_NUM_PORT
;
1613 flag_not
|= FLAG_NUM_USER
;
1616 flag_not
|= FLAG_SYM
;
1619 flag_cf
|= FLAG_CACHE
;
1622 flag_cf
|= FLAG_FIB
;
1631 flag_ver
|= FLAG_VERBOSE
;
1648 if (aftrans_opt("unix"))
1658 if (flag_int
+ flag_rou
+ flag_mas
+ flag_sta
> 1)
1661 if ((flag_inet
|| flag_inet6
|| flag_sta
) && !(flag_tcp
|| flag_udp
|| flag_raw
))
1662 flag_tcp
= flag_udp
= flag_raw
= 1;
1664 if ((flag_tcp
|| flag_udp
|| flag_raw
|| flag_igmp
) && !(flag_inet
|| flag_inet6
))
1665 flag_inet
= flag_inet6
= 1;
1667 flag_arg
= flag_tcp
+ flag_udp
+ flag_raw
+ flag_unx
+ flag_ipx
1668 + flag_ax25
+ flag_netrom
+ flag_igmp
+ flag_x25
;
1671 #if HAVE_FW_MASQUERADE && HAVE_AFINET
1672 #if MORE_THAN_ONE_MASQ_AF
1674 strcpy(afname
, DFLT_AF
);
1677 i
= ip_masq_info(flag_not
& FLAG_NUM_HOST
,
1678 flag_not
& FLAG_NUM_PORT
, flag_exp
);
1684 ENOSUPP("netstat.c", "FW_MASQUERADE");
1692 parsesnmp(flag_raw
, flag_tcp
, flag_udp
);
1700 strcpy(afname
, DFLT_AF
);
1704 else if (flag_exp
== 1)
1707 options
= (flag_exp
& FLAG_EXT
) | flag_not
| flag_cf
| flag_ver
;
1709 options
|= FLAG_FIB
;
1712 i
= route_info(afname
, options
);
1729 if (!flag_arg
|| flag_tcp
|| flag_udp
|| flag_raw
) {
1732 printf(_("Active Internet connections ")); /* xxx */
1735 printf(_("(servers and established)"));
1738 printf(_("(only servers)"));
1740 printf(_("(w/o servers)"));
1742 printf(_("\nProto Recv-Q Send-Q Local Address Foreign Address State ")); /* xxx */
1744 printf(_(" User Inode "));
1745 print_progname_banner();
1747 printf(_(" Timer")); /* xxx */
1752 ENOSUPP("netstat", "AF INET");
1757 if (!flag_arg
|| flag_tcp
) {
1762 if (!flag_arg
|| flag_udp
) {
1767 if (!flag_arg
|| flag_raw
) {
1777 printf( _("IPv4 Group Memberships\n") );
1778 printf( _("Interface RefCnt Group\n") );
1779 printf( "--------------- ------ ---------------------\n" );
1786 if (!flag_arg
|| flag_unx
) {
1795 ENOSUPP("netstat", "AF UNIX");
1799 if (!flag_arg
|| flag_ipx
) {
1807 ENOSUPP("netstat", "AF IPX");
1811 if (!flag_arg
|| flag_ax25
) {
1819 ENOSUPP("netstat", "AF AX25");
1823 if(!flag_arg
|| flag_x25
) {
1832 ENOSUPP("netstat", "AF X25");
1836 if (!flag_arg
|| flag_netrom
) {
1844 ENOSUPP("netstat", "AF NETROM");