diff options
| author | Robert Griebl <griebl@gmx.de> | 2002-07-24 00:56:56 +0000 |
|---|---|---|
| committer | Robert Griebl <griebl@gmx.de> | 2002-07-24 00:56:56 +0000 |
| commit | 31a2e20bd3ee9795f3d1256bc42df6987d29d3f4 (patch) | |
| tree | 0ee035d50605370ff0848c5880ce656b11e92a22 | |
| parent | 41369af3f2bd415c58266618aa3fd1fe6badacfa (diff) | |
| download | busybox-w32-31a2e20bd3ee9795f3d1256bc42df6987d29d3f4.tar.gz busybox-w32-31a2e20bd3ee9795f3d1256bc42df6987d29d3f4.tar.bz2 busybox-w32-31a2e20bd3ee9795f3d1256bc42df6987d29d3f4.zip | |
Commited patch from bug #1182
Although ssrat@mailbag.com says this is not GNU behaviour, it really *is*
(man nslookup)
| -rw-r--r-- | networking/nslookup.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/networking/nslookup.c b/networking/nslookup.c index 02d18461e..edbc65650 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c | |||
| @@ -5,6 +5,9 @@ | |||
| 5 | * Copyright (C) 1999,2000 by Lineo, inc. and John Beppu | 5 | * Copyright (C) 1999,2000 by Lineo, inc. and John Beppu |
| 6 | * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> | 6 | * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> |
| 7 | * | 7 | * |
| 8 | * Correct default name server display and explicit name server option | ||
| 9 | * added by Ben Zeckel <bzeckel@hmc.edu> June 2001 | ||
| 10 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or | 13 | * the Free Software Foundation; either version 2 of the License, or |
| @@ -38,9 +41,6 @@ | |||
| 38 | /* | 41 | /* |
| 39 | | I'm only implementing non-interactive mode; | 42 | | I'm only implementing non-interactive mode; |
| 40 | | I totally forgot nslookup even had an interactive mode. | 43 | | I totally forgot nslookup even had an interactive mode. |
| 41 | | | ||
| 42 | | [ TODO ] | ||
| 43 | | + find out how to use non-default name servers | ||
| 44 | */ | 44 | */ |
| 45 | 45 | ||
| 46 | /* only works for IPv4 */ | 46 | /* only works for IPv4 */ |
| @@ -138,6 +138,19 @@ static inline void server_print(void) | |||
| 138 | printf("\n"); | 138 | printf("\n"); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | /* alter the global _res nameserver structure to use | ||
| 142 | an explicit dns server instead of what is in /etc/resolv.h */ | ||
| 143 | static inline void set_default_dns(char *server) | ||
| 144 | { | ||
| 145 | struct in_addr server_in_addr; | ||
| 146 | |||
| 147 | if(inet_aton(server,&server_in_addr)) | ||
| 148 | { | ||
| 149 | _res.nscount = 1; | ||
| 150 | _res.nsaddr_list[0].sin_addr = server_in_addr; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 141 | /* naive function to check whether char *s is an ip address */ | 154 | /* naive function to check whether char *s is an ip address */ |
| 142 | static int is_ip_address(const char *s) | 155 | static int is_ip_address(const char *s) |
| 143 | { | 156 | { |
| @@ -156,11 +169,26 @@ int nslookup_main(int argc, char **argv) | |||
| 156 | { | 169 | { |
| 157 | struct hostent *host; | 170 | struct hostent *host; |
| 158 | 171 | ||
| 159 | if (argc < 2 || *argv[1]=='-') { | 172 | /* |
| 173 | * initialize DNS structure _res used in printing the default | ||
| 174 | * name server and in the explicit name server option feature. | ||
| 175 | */ | ||
| 176 | |||
| 177 | res_init(); | ||
| 178 | |||
| 179 | /* | ||
| 180 | * We allow 1 or 2 arguments. | ||
| 181 | * The first is the name to be looked up and the second is an | ||
| 182 | * optional DNS server with which to do the lookup. | ||
| 183 | * More than 3 arguments is an error to follow the pattern of the | ||
| 184 | * standard nslookup | ||
| 185 | */ | ||
| 186 | |||
| 187 | if (argc < 2 || *argv[1]=='-' || argc > 3) | ||
| 160 | show_usage(); | 188 | show_usage(); |
| 161 | } | 189 | else if(argc == 3) |
| 190 | set_default_dns(argv[2]); | ||
| 162 | 191 | ||
| 163 | res_init(); | ||
| 164 | server_print(); | 192 | server_print(); |
| 165 | if (is_ip_address(argv[1])) { | 193 | if (is_ip_address(argv[1])) { |
| 166 | host = gethostbyaddr_wrapper(argv[1]); | 194 | host = gethostbyaddr_wrapper(argv[1]); |
| @@ -171,4 +199,4 @@ int nslookup_main(int argc, char **argv) | |||
| 171 | return EXIT_SUCCESS; | 199 | return EXIT_SUCCESS; |
| 172 | } | 200 | } |
| 173 | 201 | ||
| 174 | /* $Id: nslookup.c,v 1.28 2002/04/27 04:06:55 andersen Exp $ */ | 202 | /* $Id: nslookup.c,v 1.29 2002/07/24 00:56:56 sandman Exp $ */ |
