|
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) |