View | Details | Raw Unified | Return to bug 116643 | Differences between
and this patch

Collapse All | Expand All

(-)fstat.1 (-1 / +13 lines)
Lines 40-46 Link Here
40
.Nd identify active files
40
.Nd identify active files
41
.Sh SYNOPSIS
41
.Sh SYNOPSIS
42
.Nm
42
.Nm
43
.Op Fl fmnv
43
.Op Fl fimnv
44
.Op Fl M Ar core
44
.Op Fl M Ar core
45
.Op Fl N Ar system
45
.Op Fl N Ar system
46
.Op Fl p Ar pid
46
.Op Fl p Ar pid
Lines 68-73 directory Link Here
68
.Pa /usr/src
68
.Pa /usr/src
69
resides, type
69
resides, type
70
.Dq Li fstat -f /usr/src .
70
.Dq Li fstat -f /usr/src .
71
.It Fl i
72
Print extended socket informations for internet sockets.
71
.It Fl M
73
.It Fl M
72
Extract values associated with the name list from the specified core
74
Extract values associated with the name list from the specified core
73
instead of the default
75
instead of the default
Lines 213-218 connected unix domain stream socket. Link Here
213
A unidirectional unix domain socket indicates the direction of flow with
215
A unidirectional unix domain socket indicates the direction of flow with
214
an arrow (``<-'' or ``->''), and a full duplex socket shows a double arrow
216
an arrow (``<-'' or ``->''), and a full duplex socket shows a double arrow
215
(``<->'').
217
(``<->'').
218
.Pp
219
For internet sockets,
220
the
221
.Fl i
222
flag will make
223
.Nm
224
mimic other BSDs behaviour that is attempt to print the internet address and
225
port for the local connection.
226
If a socket is connected it also prints the remote internet address and port.
227
An asterisk (``*'') is used to indicate an INADDR_ANY binding.
216
.Sh SEE ALSO
228
.Sh SEE ALSO
217
.Xr netstat 1 ,
229
.Xr netstat 1 ,
218
.Xr nfsstat 1 ,
230
.Xr nfsstat 1 ,
(-)fstat.c (-11 / +97 lines)
Lines 87-92 __FBSDID("$FreeBSD: src/usr.bin/fstat/fs Link Here
87
#include <netinet/ip.h>
87
#include <netinet/ip.h>
88
#include <netinet/in_pcb.h>
88
#include <netinet/in_pcb.h>
89
89
90
#include <arpa/inet.h>
91
90
#include <ctype.h>
92
#include <ctype.h>
91
#include <err.h>
93
#include <err.h>
92
#include <fcntl.h>
94
#include <fcntl.h>
Lines 126-131 int checkfile; /* true if restricting t Link Here
126
int	nflg;	/* (numerical) display f.s. and rdev as dev_t */
128
int	nflg;	/* (numerical) display f.s. and rdev as dev_t */
127
int	vflg;	/* display errors in locating kernel data objects etc... */
129
int	vflg;	/* display errors in locating kernel data objects etc... */
128
int	mflg;	/* include memory-mapped files */
130
int	mflg;	/* include memory-mapped files */
131
int	iflg;	/* display inet socket details */
129
132
130
133
131
struct file **ofiles;	/* buffer of pointers to file structures */
134
struct file **ofiles;	/* buffer of pointers to file structures */
Lines 153-158 int nfs_filestat(struct vnode *vp, stru Link Here
153
int  devfs_filestat(struct vnode *vp, struct filestat *fsp);
156
int  devfs_filestat(struct vnode *vp, struct filestat *fsp);
154
char *getmnton(struct mount *m);
157
char *getmnton(struct mount *m);
155
void pipetrans(struct pipe *pi, int i, int flag);
158
void pipetrans(struct pipe *pi, int i, int flag);
159
const char *inet6_addrstr(struct in6_addr *);
156
void socktrans(struct socket *sock, int i);
160
void socktrans(struct socket *sock, int i);
157
void ptstrans(struct tty *tp, int i, int flag);
161
void ptstrans(struct tty *tp, int i, int flag);
158
void getinetproto(int number);
162
void getinetproto(int number);
Lines 169-179 main(int argc, char **argv) Link Here
169
	arg = 0;
173
	arg = 0;
170
	what = KERN_PROC_PROC;
174
	what = KERN_PROC_PROC;
171
	nlistf = memf = NULL;
175
	nlistf = memf = NULL;
172
	while ((ch = getopt(argc, argv, "fmnp:u:vN:M:")) != -1)
176
	while ((ch = getopt(argc, argv, "fimnp:u:vN:M:")) != -1)
173
		switch((char)ch) {
177
		switch((char)ch) {
174
		case 'f':
178
		case 'f':
175
			fsflg = 1;
179
			fsflg = 1;
176
			break;
180
			break;
181
		case 'i':
182
			iflg = 1;
183
			break;
177
		case 'M':
184
		case 'M':
178
			memf = optarg;
185
			memf = optarg;
179
			break;
186
			break;
Lines 772-777 bad: Link Here
772
	printf("* error\n");
779
	printf("* error\n");
773
}
780
}
774
781
782
const char *
783
inet6_addrstr(struct in6_addr *p)
784
{
785
	struct sockaddr_in6 sin6;
786
	static char hbuf[NI_MAXHOST];
787
	const int niflags = NI_NUMERICHOST;
788
789
	memset(&sin6, 0, sizeof(sin6));
790
	sin6.sin6_family = AF_INET6;
791
	sin6.sin6_len = sizeof(struct sockaddr_in6);
792
	sin6.sin6_addr = *p;
793
	if (IN6_IS_ADDR_LINKLOCAL(p) &&
794
	    *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) {
795
		sin6.sin6_scope_id =
796
		    ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
797
		sin6.sin6_addr.s6_addr[2] = sin6.sin6_addr.s6_addr[3] = 0;
798
	    }
799
800
	    if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
801
		hbuf, sizeof(hbuf), NULL, 0, niflags))
802
		    return "invalid";
803
804
	    return hbuf;
805
}
806
775
void
807
void
776
socktrans(struct socket *sock, int i)
808
socktrans(struct socket *sock, int i)
777
{
809
{
Lines 791-796 socktrans(struct socket *sock, int i) Link Here
791
	struct unpcb	unpcb;
823
	struct unpcb	unpcb;
792
	int len;
824
	int len;
793
	char dname[32];
825
	char dname[32];
826
	char xaddrbuf[NI_MAXHOST + 2];
794
827
795
	PREFIX(i);
828
	PREFIX(i);
796
829
Lines 841-859 socktrans(struct socket *sock, int i) Link Here
841
	 */
874
	 */
842
	switch(dom.dom_family) {
875
	switch(dom.dom_family) {
843
	case AF_INET:
876
	case AF_INET:
877
		getinetproto(proto.pr_protocol);
878
		if (proto.pr_protocol == IPPROTO_TCP ||
879
		    proto.pr_protocol == IPPROTO_UDP) {
880
			if (so.so_pcb == NULL)
881
				break;
882
			if (kvm_read(kd, (u_long)so.so_pcb,
883
			    (char *)&inpcb, sizeof(struct inpcb))
884
			    != sizeof(struct inpcb)) {
885
				dprintf(stderr,
886
				    "can't read inpcb at %p\n",
887
				    (void *)so.so_pcb);
888
				goto bad;
889
			}
890
			if (proto.pr_protocol == IPPROTO_TCP)
891
				printf(" %lx", (u_long)inpcb.inp_ppcb);
892
			else
893
				printf(" %lx", (u_long)so.so_pcb);
894
			if (!iflg)
895
				break;
896
			printf(" %s:%hu",
897
			    inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" :
898
			    inet_ntoa(inpcb.inp_laddr),
899
			    ntohs(inpcb.inp_lport));
900
			if (inpcb.inp_fport) {
901
				printf(" <-> %s:%hu",
902
				    inpcb.inp_faddr.s_addr == INADDR_ANY ?
903
				    "*" : inet_ntoa(inpcb.inp_faddr),
904
				    ntohs(inpcb.inp_fport));
905
			}
906
		}
907
		else if (so.so_pcb)
908
			printf(" %lx", (u_long)so.so_pcb);
909
		break;
844
	case AF_INET6:
910
	case AF_INET6:
845
		getinetproto(proto.pr_protocol);
911
		getinetproto(proto.pr_protocol);
846
		if (proto.pr_protocol == IPPROTO_TCP ) {
912
		if (proto.pr_protocol == IPPROTO_TCP ||
847
			if (so.so_pcb) {
913
		    proto.pr_protocol == IPPROTO_UDP) {
848
				if (kvm_read(kd, (u_long)so.so_pcb,
914
			if (so.so_pcb == NULL)
849
				    (char *)&inpcb, sizeof(struct inpcb))
915
				break;
850
				    != sizeof(struct inpcb)) {
916
			if (kvm_read(kd, (u_long)so.so_pcb,
851
					dprintf(stderr,
917
			    (char *)&inpcb, sizeof(struct inpcb))
852
					    "can't read inpcb at %p\n",
918
			    != sizeof(struct inpcb)) {
853
					    (void *)so.so_pcb);
919
				dprintf(stderr,
854
					goto bad;
920
				    "can't read inpcb at %p\n",
855
				}
921
				    (void *)so.so_pcb);
922
				goto bad;
923
			}
924
			if (proto.pr_protocol == IPPROTO_TCP)
856
				printf(" %lx", (u_long)inpcb.inp_ppcb);
925
				printf(" %lx", (u_long)inpcb.inp_ppcb);
926
			else
927
				printf(" %lx", (u_long)so.so_pcb);
928
			if (!iflg)
929
				break;
930
			snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]",
931
			    inet6_addrstr(&inpcb.in6p_laddr));
932
			printf(" %s:%hu",
933
			    IN6_IS_ADDR_UNSPECIFIED(&inpcb.in6p_laddr) ?
934
			    "*" : xaddrbuf,
935
			    ntohs(inpcb.inp_lport));
936
			if (inpcb.inp_fport) {
937
				snprintf(xaddrbuf, sizeof(xaddrbuf),
938
				    "[%s]", inet6_addrstr(&inpcb.in6p_faddr));
939
				printf(" <-> %s:%hu",
940
				    IN6_IS_ADDR_UNSPECIFIED(&inpcb.in6p_faddr)?
941
				    "*" : xaddrbuf,
942
				    ntohs(inpcb.inp_fport));
857
			}
943
			}
858
		}
944
		}
859
		else if (so.so_pcb)
945
		else if (so.so_pcb)

Return to bug 116643