diff options
Diffstat (limited to 'networking/netstat.c')
-rw-r--r-- | networking/netstat.c | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/networking/netstat.c b/networking/netstat.c index e33a89a64..28ae9bc32 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
@@ -30,10 +30,7 @@ | |||
30 | #include <dirent.h> | 30 | #include <dirent.h> |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #include <pwd.h> | 32 | #include <pwd.h> |
33 | #include <sys/socket.h> | 33 | #include "inet_common.h" |
34 | #include <netinet/in.h> | ||
35 | #include <arpa/inet.h> | ||
36 | |||
37 | #include "busybox.h" | 34 | #include "busybox.h" |
38 | 35 | ||
39 | #define NETSTAT_CONNECTED 0x01 | 36 | #define NETSTAT_CONNECTED 0x01 |
@@ -95,7 +92,7 @@ typedef enum { | |||
95 | #define SO_WAITDATA (1<<17) /* wait data to read */ | 92 | #define SO_WAITDATA (1<<17) /* wait data to read */ |
96 | #define SO_NOSPACE (1<<18) /* no space to write */ | 93 | #define SO_NOSPACE (1<<18) /* no space to write */ |
97 | 94 | ||
98 | char *itoa(unsigned int i) | 95 | static char *itoa(unsigned int i) |
99 | { | 96 | { |
100 | /* 21 digits plus null terminator, good for 64-bit or smaller ints */ | 97 | /* 21 digits plus null terminator, good for 64-bit or smaller ints */ |
101 | static char local[22]; | 98 | static char local[22]; |
@@ -108,24 +105,7 @@ char *itoa(unsigned int i) | |||
108 | return p + 1; | 105 | return p + 1; |
109 | } | 106 | } |
110 | 107 | ||
111 | char *inet_sprint(struct sockaddr* addr, int num) | 108 | static char *get_sname(int port, const char *proto, int num) |
112 | { | ||
113 | char *str; | ||
114 | str=inet_ntoa(((struct sockaddr_in*)addr)->sin_addr); | ||
115 | if (!strcmp(str,"0.0.0.0")) { | ||
116 | str="*"; | ||
117 | } | ||
118 | if (num) | ||
119 | { | ||
120 | } else { | ||
121 | struct hostent *he=gethostbyaddr(&((struct sockaddr_in*)addr)->sin_addr,4,AF_INET); | ||
122 | if (he) | ||
123 | str=he->h_name; | ||
124 | } | ||
125 | return str; | ||
126 | } | ||
127 | |||
128 | char *get_sname(int port, const char *proto, int num) | ||
129 | { | 109 | { |
130 | char *str=itoa(ntohs(port)); | 110 | char *str=itoa(ntohs(port)); |
131 | if (num) { | 111 | if (num) { |
@@ -140,10 +120,13 @@ char *get_sname(int port, const char *proto, int num) | |||
140 | return str; | 120 | return str; |
141 | } | 121 | } |
142 | 122 | ||
143 | void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) | 123 | static void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) |
144 | { | 124 | { |
145 | char *port_name; | 125 | char *port_name; |
146 | safe_strncpy(ip_port, inet_sprint(addr, numeric), size); | 126 | |
127 | INET_rresolve(ip_port, size, (struct sockaddr_in *)addr, | ||
128 | 0x4000 | ((numeric&NETSTAT_NUMERIC) ? 0x0fff : 0), | ||
129 | 0xffffffff); | ||
147 | port_name=get_sname(htons(port), proto, numeric); | 130 | port_name=get_sname(htons(port), proto, numeric); |
148 | if ((strlen(ip_port) + strlen(port_name)) > 22) | 131 | if ((strlen(ip_port) + strlen(port_name)) > 22) |
149 | ip_port[22 - strlen(port_name)] = '\0'; | 132 | ip_port[22 - strlen(port_name)] = '\0'; |