|
Lines 79-84
Link Here
|
| 79 |
|
79 |
|
| 80 |
const char *ip_whois[] = { RNICHOST, PNICHOST, NULL }; |
80 |
const char *ip_whois[] = { RNICHOST, PNICHOST, NULL }; |
| 81 |
|
81 |
|
|
|
82 |
static char *choose_server(const char *); |
| 82 |
static void usage(void); |
83 |
static void usage(void); |
| 83 |
static void whois(char *, struct addrinfo *, int); |
84 |
static void whois(char *, struct addrinfo *, int); |
| 84 |
|
85 |
|
|
Lines 88-94
Link Here
|
| 88 |
struct addrinfo hints, *res; |
89 |
struct addrinfo hints, *res; |
| 89 |
const char *host; |
90 |
const char *host; |
| 90 |
char *qnichost; |
91 |
char *qnichost; |
| 91 |
int ch, error, flags, i, j, use_qnichost; |
92 |
int ch, error, flags, use_qnichost; |
| 92 |
|
93 |
|
| 93 |
#ifdef SOCKS |
94 |
#ifdef SOCKS |
| 94 |
SOCKSinit(argv[0]); |
95 |
SOCKSinit(argv[0]); |
|
Lines 159-179
Link Here
|
| 159 |
} |
160 |
} |
| 160 |
while (argc--) { |
161 |
while (argc--) { |
| 161 |
if (use_qnichost) { |
162 |
if (use_qnichost) { |
| 162 |
for (i = j = 0; (*argv)[i]; i++) |
163 |
if ((qnichost = choose_server(*argv)) != NULL) { |
| 163 |
if ((*argv)[i] == '.') |
|
|
| 164 |
j = i; |
| 165 |
if (j != 0) { |
| 166 |
if (isdigit(*(*argv + j + 1))) { |
| 167 |
asprintf(&qnichost, "%s", ANICHOST); |
| 168 |
if (qnichost == NULL) |
| 169 |
err(1, "asprintf()"); |
| 170 |
} else { |
| 171 |
asprintf(&qnichost, "%s%s", |
| 172 |
*argv + j + 1, QNICHOST_TAIL); |
| 173 |
if (qnichost == NULL) |
| 174 |
err(1, "asprintf()"); |
| 175 |
} |
| 176 |
|
| 177 |
memset(&hints, 0, sizeof(hints)); |
164 |
memset(&hints, 0, sizeof(hints)); |
| 178 |
hints.ai_flags = 0; |
165 |
hints.ai_flags = 0; |
| 179 |
hints.ai_family = AF_UNSPEC; |
166 |
hints.ai_family = AF_UNSPEC; |
|
Lines 202-207
Link Here
|
| 202 |
freeaddrinfo(res); |
189 |
freeaddrinfo(res); |
| 203 |
} |
190 |
} |
| 204 |
exit(0); |
191 |
exit(0); |
|
|
192 |
} |
| 193 |
|
| 194 |
/* |
| 195 |
* Returns a pointer to newly allocated memory containing the whois server to |
| 196 |
* be queried, or a NULL pointer, if the correct server couldn't be determined. |
| 197 |
* The caller must remember to free(3) the allocated memory. |
| 198 |
*/ |
| 199 |
static char * |
| 200 |
choose_server(const char *domain) |
| 201 |
{ |
| 202 |
size_t len; |
| 203 |
char *buf, *pos, *retval; |
| 204 |
|
| 205 |
if ((buf = strdup(domain)) == NULL) |
| 206 |
err(1, "strdup()"); |
| 207 |
len = strlen(buf); |
| 208 |
while (len && buf[len - 1] == '.') |
| 209 |
buf[--len] = '\0'; |
| 210 |
if ((pos = strrchr(buf, '.')) == NULL) { |
| 211 |
free(buf); |
| 212 |
return (NULL); |
| 213 |
} |
| 214 |
pos++; |
| 215 |
if (isdigit(*pos)) { |
| 216 |
asprintf(&retval, "%s", ANICHOST); |
| 217 |
if (retval == NULL) |
| 218 |
err(1, "asprintf()"); |
| 219 |
} else { |
| 220 |
asprintf(&retval, "%s%s", pos, QNICHOST_TAIL); |
| 221 |
if (retval == NULL) |
| 222 |
err(1, "asprintf()"); |
| 223 |
} |
| 224 |
free(buf); |
| 225 |
return (retval); |
| 205 |
} |
226 |
} |
| 206 |
|
227 |
|
| 207 |
static void |
228 |
static void |