aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-12 22:21:24 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-12 22:21:24 +0000
commitdab3d46b9d35e0a0279b3700fe411f876bb25781 (patch)
tree929770563fe1fb9df68e8cb70fdc62f24dbeb68c
parent583e3ca45609dd3cb208b9134b7b96f581b4baf1 (diff)
downloadbusybox-w32-dab3d46b9d35e0a0279b3700fe411f876bb25781.tar.gz
busybox-w32-dab3d46b9d35e0a0279b3700fe411f876bb25781.tar.bz2
busybox-w32-dab3d46b9d35e0a0279b3700fe411f876bb25781.zip
A patch from Benjamin Zeckel <bzeckel@cisco.com> to allow
nslookup.c to display the correct default nameservers.
-rw-r--r--networking/nslookup.c79
-rw-r--r--nslookup.c79
2 files changed, 80 insertions, 78 deletions
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 8791b5efe..1c75bb570 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -31,6 +31,8 @@
31#include <sys/socket.h> 31#include <sys/socket.h>
32#include <sys/types.h> 32#include <sys/types.h>
33#include <netinet/in.h> 33#include <netinet/in.h>
34#include <resolv.h>
35#include <arpa/inet.h>
34#include "busybox.h" 36#include "busybox.h"
35 37
36/* 38/*
@@ -39,19 +41,8 @@
39 | 41 |
40 | [ TODO ] 42 | [ TODO ]
41 | + find out how to use non-default name servers 43 | + find out how to use non-default name servers
42 | + find out how the real nslookup gets the default name server
43 */ 44 */
44 45
45/* I have to see how the real nslookup does this.
46 * I could dig through /etc/resolv.conf, but is there a
47 * better (programatic) way?
48 */
49static inline void server_print(void)
50{
51 printf("Server: %s\n", "default");
52 printf("Address: %s\n\n", "default");
53}
54
55/* only works for IPv4 */ 46/* only works for IPv4 */
56static int addr_fprint(char *addr) 47static int addr_fprint(char *addr)
57{ 48{
@@ -68,24 +59,6 @@ static int addr_fprint(char *addr)
68 return 0; 59 return 0;
69} 60}
70 61
71/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
72 * into a u_int32_t
73 */
74static u_int32_t str_to_addr(const char *addr)
75{
76 u_int32_t split[4];
77 u_int32_t ip;
78
79 sscanf(addr, "%d.%d.%d.%d",
80 &split[0], &split[1], &split[2], &split[3]);
81
82 /* assuming sscanf worked */
83 ip = (split[0] << 24) |
84 (split[1] << 16) | (split[2] << 8) | (split[3]);
85
86 return htonl(ip);
87}
88
89/* takes the NULL-terminated array h_addr_list, and 62/* takes the NULL-terminated array h_addr_list, and
90 * prints its contents appropriately 63 * prints its contents appropriately
91 */ 64 */
@@ -116,15 +89,6 @@ static int addr_list_fprint(char **h_addr_list)
116 return 0; 89 return 0;
117} 90}
118 91
119/* gethostbyaddr wrapper */
120static struct hostent *gethostbyaddr_wrapper(const char *address)
121{
122 struct in_addr addr;
123
124 addr.s_addr = str_to_addr(address);
125 return gethostbyaddr((char *) &addr, 4, AF_INET); /* IPv4 only for now */
126}
127
128/* print the results as nslookup would */ 92/* print the results as nslookup would */
129static struct hostent *hostent_fprint(struct hostent *host) 93static struct hostent *hostent_fprint(struct hostent *host)
130{ 94{
@@ -137,6 +101,42 @@ static struct hostent *hostent_fprint(struct hostent *host)
137 return host; 101 return host;
138} 102}
139 103
104/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
105 * into a u_int32_t
106 */
107static u_int32_t str_to_addr(const char *addr)
108{
109 u_int32_t split[4];
110 u_int32_t ip;
111
112 sscanf(addr, "%d.%d.%d.%d",
113 &split[0], &split[1], &split[2], &split[3]);
114
115 /* assuming sscanf worked */
116 ip = (split[0] << 24) |
117 (split[1] << 16) | (split[2] << 8) | (split[3]);
118
119 return htonl(ip);
120}
121
122/* gethostbyaddr wrapper */
123static struct hostent *gethostbyaddr_wrapper(const char *address)
124{
125 struct in_addr addr;
126
127 addr.s_addr = str_to_addr(address);
128 return gethostbyaddr((char *) &addr, 4, AF_INET); /* IPv4 only for now */
129}
130
131/* lookup the default nameserver and display it */
132static inline void server_print(void)
133{
134 struct sockaddr_in def = _res.nsaddr_list[0];
135 char *ip = inet_ntoa(def.sin_addr);
136
137 hostent_fprint(gethostbyaddr_wrapper(ip));
138 printf("\n");
139}
140 140
141/* naive function to check whether char *s is an ip address */ 141/* naive function to check whether char *s is an ip address */
142static int is_ip_address(const char *s) 142static int is_ip_address(const char *s)
@@ -160,6 +160,7 @@ int nslookup_main(int argc, char **argv)
160 show_usage(); 160 show_usage();
161 } 161 }
162 162
163 res_init();
163 server_print(); 164 server_print();
164 if (is_ip_address(argv[1])) { 165 if (is_ip_address(argv[1])) {
165 host = gethostbyaddr_wrapper(argv[1]); 166 host = gethostbyaddr_wrapper(argv[1]);
@@ -170,4 +171,4 @@ int nslookup_main(int argc, char **argv)
170 return EXIT_SUCCESS; 171 return EXIT_SUCCESS;
171} 172}
172 173
173/* $Id: nslookup.c,v 1.22 2001/02/20 06:14:08 andersen Exp $ */ 174/* $Id: nslookup.c,v 1.23 2001/06/12 22:21:24 andersen Exp $ */
diff --git a/nslookup.c b/nslookup.c
index 8791b5efe..1c75bb570 100644
--- a/nslookup.c
+++ b/nslookup.c
@@ -31,6 +31,8 @@
31#include <sys/socket.h> 31#include <sys/socket.h>
32#include <sys/types.h> 32#include <sys/types.h>
33#include <netinet/in.h> 33#include <netinet/in.h>
34#include <resolv.h>
35#include <arpa/inet.h>
34#include "busybox.h" 36#include "busybox.h"
35 37
36/* 38/*
@@ -39,19 +41,8 @@
39 | 41 |
40 | [ TODO ] 42 | [ TODO ]
41 | + find out how to use non-default name servers 43 | + find out how to use non-default name servers
42 | + find out how the real nslookup gets the default name server
43 */ 44 */
44 45
45/* I have to see how the real nslookup does this.
46 * I could dig through /etc/resolv.conf, but is there a
47 * better (programatic) way?
48 */
49static inline void server_print(void)
50{
51 printf("Server: %s\n", "default");
52 printf("Address: %s\n\n", "default");
53}
54
55/* only works for IPv4 */ 46/* only works for IPv4 */
56static int addr_fprint(char *addr) 47static int addr_fprint(char *addr)
57{ 48{
@@ -68,24 +59,6 @@ static int addr_fprint(char *addr)
68 return 0; 59 return 0;
69} 60}
70 61
71/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
72 * into a u_int32_t
73 */
74static u_int32_t str_to_addr(const char *addr)
75{
76 u_int32_t split[4];
77 u_int32_t ip;
78
79 sscanf(addr, "%d.%d.%d.%d",
80 &split[0], &split[1], &split[2], &split[3]);
81
82 /* assuming sscanf worked */
83 ip = (split[0] << 24) |
84 (split[1] << 16) | (split[2] << 8) | (split[3]);
85
86 return htonl(ip);
87}
88
89/* takes the NULL-terminated array h_addr_list, and 62/* takes the NULL-terminated array h_addr_list, and
90 * prints its contents appropriately 63 * prints its contents appropriately
91 */ 64 */
@@ -116,15 +89,6 @@ static int addr_list_fprint(char **h_addr_list)
116 return 0; 89 return 0;
117} 90}
118 91
119/* gethostbyaddr wrapper */
120static struct hostent *gethostbyaddr_wrapper(const char *address)
121{
122 struct in_addr addr;
123
124 addr.s_addr = str_to_addr(address);
125 return gethostbyaddr((char *) &addr, 4, AF_INET); /* IPv4 only for now */
126}
127
128/* print the results as nslookup would */ 92/* print the results as nslookup would */
129static struct hostent *hostent_fprint(struct hostent *host) 93static struct hostent *hostent_fprint(struct hostent *host)
130{ 94{
@@ -137,6 +101,42 @@ static struct hostent *hostent_fprint(struct hostent *host)
137 return host; 101 return host;
138} 102}
139 103
104/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
105 * into a u_int32_t
106 */
107static u_int32_t str_to_addr(const char *addr)
108{
109 u_int32_t split[4];
110 u_int32_t ip;
111
112 sscanf(addr, "%d.%d.%d.%d",
113 &split[0], &split[1], &split[2], &split[3]);
114
115 /* assuming sscanf worked */
116 ip = (split[0] << 24) |
117 (split[1] << 16) | (split[2] << 8) | (split[3]);
118
119 return htonl(ip);
120}
121
122/* gethostbyaddr wrapper */
123static struct hostent *gethostbyaddr_wrapper(const char *address)
124{
125 struct in_addr addr;
126
127 addr.s_addr = str_to_addr(address);
128 return gethostbyaddr((char *) &addr, 4, AF_INET); /* IPv4 only for now */
129}
130
131/* lookup the default nameserver and display it */
132static inline void server_print(void)
133{
134 struct sockaddr_in def = _res.nsaddr_list[0];
135 char *ip = inet_ntoa(def.sin_addr);
136
137 hostent_fprint(gethostbyaddr_wrapper(ip));
138 printf("\n");
139}
140 140
141/* naive function to check whether char *s is an ip address */ 141/* naive function to check whether char *s is an ip address */
142static int is_ip_address(const char *s) 142static int is_ip_address(const char *s)
@@ -160,6 +160,7 @@ int nslookup_main(int argc, char **argv)
160 show_usage(); 160 show_usage();
161 } 161 }
162 162
163 res_init();
163 server_print(); 164 server_print();
164 if (is_ip_address(argv[1])) { 165 if (is_ip_address(argv[1])) {
165 host = gethostbyaddr_wrapper(argv[1]); 166 host = gethostbyaddr_wrapper(argv[1]);
@@ -170,4 +171,4 @@ int nslookup_main(int argc, char **argv)
170 return EXIT_SUCCESS; 171 return EXIT_SUCCESS;
171} 172}
172 173
173/* $Id: nslookup.c,v 1.22 2001/02/20 06:14:08 andersen Exp $ */ 174/* $Id: nslookup.c,v 1.23 2001/06/12 22:21:24 andersen Exp $ */