aboutsummaryrefslogtreecommitdiff
path: root/networking/netstat.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-11-10 11:22:46 +0000
committerEric Andersen <andersen@codepoet.org>2001-11-10 11:22:46 +0000
commitcd8c436d811a5a077a0b61a6616c900173e2dcfb (patch)
tree94163bfef63fec4c2638d5f56be310b7176464d7 /networking/netstat.c
parent94f19a838518293810a0fc0c4dca926ca8caff57 (diff)
downloadbusybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.tar.gz
busybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.tar.bz2
busybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.zip
Latest patch from vodz:
-- reverse resolve network name and cache in route and ifconfig applets, fix print nslookup server name if compile without uClibc, fix route crashe 'route add', fix warnings compile networking and pwd_grp applets
Diffstat (limited to 'networking/netstat.c')
-rw-r--r--networking/netstat.c33
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
98char *itoa(unsigned int i) 95static 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
111char *inet_sprint(struct sockaddr* addr, int num) 108static 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
128char *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
143void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) 123static 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';