|
Lines 86-91
__FBSDID("$FreeBSD: src/usr.bin/fstat/fs
Link Here
|
| 86 |
#include <netinet/ip.h> |
86 |
#include <netinet/ip.h> |
| 87 |
#include <netinet/in_pcb.h> |
87 |
#include <netinet/in_pcb.h> |
| 88 |
|
88 |
|
|
|
89 |
#include <arpa/inet.h> |
| 90 |
|
| 89 |
#include <ctype.h> |
91 |
#include <ctype.h> |
| 90 |
#include <err.h> |
92 |
#include <err.h> |
| 91 |
#include <fcntl.h> |
93 |
#include <fcntl.h> |
|
Lines 151-156
int nfs_filestat(struct vnode *vp, stru
Link Here
|
| 151 |
int devfs_filestat(struct vnode *vp, struct filestat *fsp); |
153 |
int devfs_filestat(struct vnode *vp, struct filestat *fsp); |
| 152 |
char *getmnton(struct mount *m); |
154 |
char *getmnton(struct mount *m); |
| 153 |
void pipetrans(struct pipe *pi, int i, int flag); |
155 |
void pipetrans(struct pipe *pi, int i, int flag); |
|
|
156 |
const char *inet6_addrstr(struct in6_addr *); |
| 154 |
void socktrans(struct socket *sock, int i); |
157 |
void socktrans(struct socket *sock, int i); |
| 155 |
void getinetproto(int number); |
158 |
void getinetproto(int number); |
| 156 |
int getfname(const char *filename); |
159 |
int getfname(const char *filename); |
|
Lines 757-762
bad:
Link Here
|
| 757 |
printf("* error\n"); |
760 |
printf("* error\n"); |
| 758 |
} |
761 |
} |
| 759 |
|
762 |
|
|
|
763 |
const char * |
| 764 |
inet6_addrstr(struct in6_addr *p) |
| 765 |
{ |
| 766 |
struct sockaddr_in6 sin6; |
| 767 |
static char hbuf[NI_MAXHOST]; |
| 768 |
const int niflags = NI_NUMERICHOST; |
| 769 |
|
| 770 |
memset(&sin6, 0, sizeof(sin6)); |
| 771 |
sin6.sin6_family = AF_INET6; |
| 772 |
sin6.sin6_len = sizeof(struct sockaddr_in6); |
| 773 |
sin6.sin6_addr = *p; |
| 774 |
if (IN6_IS_ADDR_LINKLOCAL(p) && |
| 775 |
*(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { |
| 776 |
sin6.sin6_scope_id = |
| 777 |
ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); |
| 778 |
sin6.sin6_addr.s6_addr[2] = sin6.sin6_addr.s6_addr[3] = 0; |
| 779 |
} |
| 780 |
|
| 781 |
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, |
| 782 |
hbuf, sizeof(hbuf), NULL, 0, niflags)) |
| 783 |
return "invalid"; |
| 784 |
|
| 785 |
return hbuf; |
| 786 |
} |
| 787 |
|
| 760 |
void |
788 |
void |
| 761 |
socktrans(struct socket *sock, int i) |
789 |
socktrans(struct socket *sock, int i) |
| 762 |
{ |
790 |
{ |
|
Lines 776-781
socktrans(struct socket *sock, int i)
Link Here
|
| 776 |
struct unpcb unpcb; |
804 |
struct unpcb unpcb; |
| 777 |
int len; |
805 |
int len; |
| 778 |
char dname[32]; |
806 |
char dname[32]; |
|
|
807 |
char xaddrbuf[NI_MAXHOST + 2]; |
| 779 |
|
808 |
|
| 780 |
PREFIX(i); |
809 |
PREFIX(i); |
| 781 |
|
810 |
|
|
Lines 826-844
socktrans(struct socket *sock, int i)
Link Here
|
| 826 |
*/ |
855 |
*/ |
| 827 |
switch(dom.dom_family) { |
856 |
switch(dom.dom_family) { |
| 828 |
case AF_INET: |
857 |
case AF_INET: |
|
|
858 |
getinetproto(proto.pr_protocol); |
| 859 |
if (proto.pr_protocol == IPPROTO_TCP || |
| 860 |
proto.pr_protocol == IPPROTO_UDP) { |
| 861 |
if (so.so_pcb == NULL) |
| 862 |
break; |
| 863 |
if (kvm_read(kd, (u_long)so.so_pcb, |
| 864 |
(char *)&inpcb, sizeof(struct inpcb)) |
| 865 |
!= sizeof(struct inpcb)) { |
| 866 |
dprintf(stderr, |
| 867 |
"can't read inpcb at %p\n", |
| 868 |
(void *)so.so_pcb); |
| 869 |
goto bad; |
| 870 |
} |
| 871 |
if (proto.pr_protocol == IPPROTO_TCP) |
| 872 |
printf(" %lx", (u_long)inpcb.inp_ppcb); |
| 873 |
else |
| 874 |
printf(" %lx", (u_long)so.so_pcb); |
| 875 |
printf(" %s:%hu", |
| 876 |
inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" : |
| 877 |
inet_ntoa(inpcb.inp_laddr), |
| 878 |
ntohs(inpcb.inp_lport)); |
| 879 |
if (inpcb.inp_fport) { |
| 880 |
printf(" <-> %s:%hu", |
| 881 |
inpcb.inp_faddr.s_addr == INADDR_ANY ? |
| 882 |
"*" : inet_ntoa(inpcb.inp_faddr), |
| 883 |
ntohs(inpcb.inp_fport)); |
| 884 |
} |
| 885 |
} |
| 886 |
else if (so.so_pcb) |
| 887 |
printf(" %lx", (u_long)so.so_pcb); |
| 888 |
break; |
| 829 |
case AF_INET6: |
889 |
case AF_INET6: |
| 830 |
getinetproto(proto.pr_protocol); |
890 |
getinetproto(proto.pr_protocol); |
| 831 |
if (proto.pr_protocol == IPPROTO_TCP ) { |
891 |
if (proto.pr_protocol == IPPROTO_TCP || |
| 832 |
if (so.so_pcb) { |
892 |
proto.pr_protocol == IPPROTO_UDP) { |
| 833 |
if (kvm_read(kd, (u_long)so.so_pcb, |
893 |
if (so.so_pcb == NULL) |
| 834 |
(char *)&inpcb, sizeof(struct inpcb)) |
894 |
break; |
| 835 |
!= sizeof(struct inpcb)) { |
895 |
if (kvm_read(kd, (u_long)so.so_pcb, |
| 836 |
dprintf(stderr, |
896 |
(char *)&inpcb, sizeof(struct inpcb)) |
| 837 |
"can't read inpcb at %p\n", |
897 |
!= sizeof(struct inpcb)) { |
| 838 |
(void *)so.so_pcb); |
898 |
dprintf(stderr, |
| 839 |
goto bad; |
899 |
"can't read inpcb at %p\n", |
| 840 |
} |
900 |
(void *)so.so_pcb); |
|
|
901 |
goto bad; |
| 902 |
} |
| 903 |
if (proto.pr_protocol == IPPROTO_TCP) |
| 841 |
printf(" %lx", (u_long)inpcb.inp_ppcb); |
904 |
printf(" %lx", (u_long)inpcb.inp_ppcb); |
|
|
905 |
else |
| 906 |
printf(" %lx", (u_long)so.so_pcb); |
| 907 |
snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]", |
| 908 |
inet6_addrstr(&inpcb.in6p_laddr)); |
| 909 |
printf(" %s:%hu", |
| 910 |
IN6_IS_ADDR_UNSPECIFIED(&inpcb.in6p_laddr) ? |
| 911 |
"*" : xaddrbuf, |
| 912 |
ntohs(inpcb.in6p_lport)); |
| 913 |
if (inpcb.in6p_fport) { |
| 914 |
snprintf(xaddrbuf, sizeof(xaddrbuf), |
| 915 |
"[%s]", inet6_addrstr(&inpcb.in6p_faddr)); |
| 916 |
printf(" <-> %s:%hu", |
| 917 |
IN6_IS_ADDR_UNSPECIFIED(&inpcb.in6p_faddr)? |
| 918 |
"*" : xaddrbuf, |
| 919 |
ntohs(inpcb.in6p_fport)); |
| 842 |
} |
920 |
} |
| 843 |
} |
921 |
} |
| 844 |
else if (so.so_pcb) |
922 |
else if (so.so_pcb) |