|
Lines 117-122
Link Here
|
| 117 |
WHOIS_REFERRAL("Whois Server:"), |
117 |
WHOIS_REFERRAL("Whois Server:"), |
| 118 |
WHOIS_REFERRAL("Registrar WHOIS Server:"), /* corporatedomains.com */ |
118 |
WHOIS_REFERRAL("Registrar WHOIS Server:"), /* corporatedomains.com */ |
| 119 |
WHOIS_REFERRAL("ReferralServer: whois://"), /* ARIN */ |
119 |
WHOIS_REFERRAL("ReferralServer: whois://"), /* ARIN */ |
|
|
120 |
WHOIS_REFERRAL("ReferralServer: rwhois://"), /* ARIN */ |
| 120 |
WHOIS_REFERRAL("descr: region. Please query"), /* AfriNIC */ |
121 |
WHOIS_REFERRAL("descr: region. Please query"), /* AfriNIC */ |
| 121 |
{ NULL, 0 } |
122 |
{ NULL, 0 } |
| 122 |
}; |
123 |
}; |
|
Lines 156-165
Link Here
|
| 156 |
static const char *port = DEFAULT_PORT; |
157 |
static const char *port = DEFAULT_PORT; |
| 157 |
|
158 |
|
| 158 |
static const char *choose_server(char *); |
159 |
static const char *choose_server(char *); |
| 159 |
static struct addrinfo *gethostinfo(char const *host, int exitnoname); |
160 |
static struct addrinfo *gethostinfo(const char *, const char *, int); |
| 160 |
static void s_asprintf(char **ret, const char *format, ...) __printflike(2, 3); |
161 |
static void s_asprintf(char **ret, const char *format, ...) __printflike(2, 3); |
| 161 |
static void usage(void); |
162 |
static void usage(void); |
| 162 |
static void whois(const char *, const char *, int); |
163 |
static void whois(const char *, const char *, const char *, int); |
| 163 |
|
164 |
|
| 164 |
int |
165 |
int |
| 165 |
main(int argc, char *argv[]) |
166 |
main(int argc, char *argv[]) |
|
Lines 255-265
Link Here
|
| 255 |
if (country != NULL) { |
256 |
if (country != NULL) { |
| 256 |
char *qnichost; |
257 |
char *qnichost; |
| 257 |
s_asprintf(&qnichost, "%s%s", country, QNICHOST_TAIL); |
258 |
s_asprintf(&qnichost, "%s%s", country, QNICHOST_TAIL); |
| 258 |
whois(*argv, qnichost, flags); |
259 |
whois(*argv, qnichost, port, flags); |
| 259 |
free(qnichost); |
260 |
free(qnichost); |
| 260 |
} else |
261 |
} else |
| 261 |
whois(*argv, host != NULL ? host : |
262 |
whois(*argv, host != NULL ? host : |
| 262 |
choose_server(*argv), flags); |
263 |
choose_server(*argv), port, flags); |
| 263 |
reset_rir(); |
264 |
reset_rir(); |
| 264 |
argv++; |
265 |
argv++; |
| 265 |
} |
266 |
} |
|
Lines 283-289
Link Here
|
| 283 |
} |
284 |
} |
| 284 |
|
285 |
|
| 285 |
static struct addrinfo * |
286 |
static struct addrinfo * |
| 286 |
gethostinfo(char const *host, int exit_on_noname) |
287 |
gethostinfo(const char *host, const char *hport, int exit_on_noname) |
| 287 |
{ |
288 |
{ |
| 288 |
struct addrinfo hints, *res; |
289 |
struct addrinfo hints, *res; |
| 289 |
int error; |
290 |
int error; |
|
Lines 293-299
Link Here
|
| 293 |
hints.ai_family = AF_UNSPEC; |
294 |
hints.ai_family = AF_UNSPEC; |
| 294 |
hints.ai_socktype = SOCK_STREAM; |
295 |
hints.ai_socktype = SOCK_STREAM; |
| 295 |
res = NULL; |
296 |
res = NULL; |
| 296 |
error = getaddrinfo(host, port, &hints, &res); |
297 |
error = getaddrinfo(host, hport, &hints, &res); |
| 297 |
if (error && (exit_on_noname || error != EAI_NONAME)) |
298 |
if (error && (exit_on_noname || error != EAI_NONAME)) |
| 298 |
err(EX_NOHOST, "%s: %s", host, gai_strerror(error)); |
299 |
err(EX_NOHOST, "%s: %s", host, gai_strerror(error)); |
| 299 |
return (res); |
300 |
return (res); |
|
Lines 444-458
Link Here
|
| 444 |
} |
445 |
} |
| 445 |
|
446 |
|
| 446 |
static void |
447 |
static void |
| 447 |
whois(const char *query, const char *hostname, int flags) |
448 |
whois(const char *query, const char *hostname, const char *hostport, int flags) |
| 448 |
{ |
449 |
{ |
| 449 |
FILE *fp; |
450 |
FILE *fp; |
| 450 |
struct addrinfo *hostres; |
451 |
struct addrinfo *hostres; |
| 451 |
char *buf, *host, *nhost, *p; |
452 |
char *buf, *host, *nhost, *nport, *p; |
| 452 |
int comment, s, f; |
453 |
int comment, s, f; |
| 453 |
size_t len, i; |
454 |
size_t len, i; |
| 454 |
|
455 |
|
| 455 |
hostres = gethostinfo(hostname, 1); |
456 |
hostres = gethostinfo(hostname, hostport, 1); |
| 456 |
s = connect_to_any_host(hostres); |
457 |
s = connect_to_any_host(hostres); |
| 457 |
if (s == -1) |
458 |
if (s == -1) |
| 458 |
err(EX_OSERR, "connect()"); |
459 |
err(EX_OSERR, "connect()"); |
|
Lines 532-545
Link Here
|
| 532 |
SCAN(p, buf+len, *p == ' '); |
533 |
SCAN(p, buf+len, *p == ' '); |
| 533 |
host = p; |
534 |
host = p; |
| 534 |
SCAN(p, buf+len, ishost(*p)); |
535 |
SCAN(p, buf+len, ishost(*p)); |
| 535 |
if (p > host) |
536 |
if (p > host) { |
|
|
537 |
char *pstr; |
| 538 |
|
| 536 |
s_asprintf(&nhost, "%.*s", |
539 |
s_asprintf(&nhost, "%.*s", |
| 537 |
(int)(p - host), host); |
540 |
(int)(p - host), host); |
|
|
541 |
|
| 542 |
if (*p != ':') { |
| 543 |
s_asprintf(&nport, "%s", port); |
| 544 |
break; |
| 545 |
} |
| 546 |
|
| 547 |
pstr = ++p; |
| 548 |
SCAN(p, buf+len, isdigit(*p)); |
| 549 |
if (p > pstr && (p - pstr) < 6) { |
| 550 |
s_asprintf(&nport, "%.*s", |
| 551 |
(int)(p - pstr), pstr); |
| 552 |
break; |
| 553 |
} |
| 554 |
|
| 555 |
/* Invalid port; don't recurse */ |
| 556 |
free(nhost); |
| 557 |
nhost = NULL; |
| 558 |
} |
| 538 |
break; |
559 |
break; |
| 539 |
} |
560 |
} |
| 540 |
for (i = 0; actually_arin[i] != NULL; i++) { |
561 |
for (i = 0; actually_arin[i] != NULL; i++) { |
| 541 |
if (strncmp(buf, actually_arin[i], len) == 0) { |
562 |
if (strncmp(buf, actually_arin[i], len) == 0) { |
| 542 |
s_asprintf(&nhost, "%s", ANICHOST); |
563 |
s_asprintf(&nhost, "%s", ANICHOST); |
|
|
564 |
s_asprintf(&nport, "%s", port); |
| 543 |
break; |
565 |
break; |
| 544 |
} |
566 |
} |
| 545 |
} |
567 |
} |
|
Lines 567-572
Link Here
|
| 567 |
strcasecmp(try_rir[i].host, nhost) == 0) { |
589 |
strcasecmp(try_rir[i].host, nhost) == 0) { |
| 568 |
free(nhost); |
590 |
free(nhost); |
| 569 |
nhost = NULL; |
591 |
nhost = NULL; |
|
|
592 |
free(nport); |
| 570 |
f = 1; |
593 |
f = 1; |
| 571 |
} |
594 |
} |
| 572 |
} |
595 |
} |
|
Lines 576-581
Link Here
|
| 576 |
if (try_rir[i].loop == 0) { |
599 |
if (try_rir[i].loop == 0) { |
| 577 |
s_asprintf(&nhost, "%s", |
600 |
s_asprintf(&nhost, "%s", |
| 578 |
try_rir[i].host); |
601 |
try_rir[i].host); |
|
|
602 |
s_asprintf(&nport, "%s", |
| 603 |
port); |
| 579 |
break; |
604 |
break; |
| 580 |
} |
605 |
} |
| 581 |
} |
606 |
} |
|
Lines 584-592
Link Here
|
| 584 |
/* Ignore self-referrals */ |
609 |
/* Ignore self-referrals */ |
| 585 |
if (strcasecmp(hostname, nhost) != 0) { |
610 |
if (strcasecmp(hostname, nhost) != 0) { |
| 586 |
printf("# %s\n\n", nhost); |
611 |
printf("# %s\n\n", nhost); |
| 587 |
whois(query, nhost, flags); |
612 |
whois(query, nhost, nport, flags); |
| 588 |
} |
613 |
} |
| 589 |
free(nhost); |
614 |
free(nhost); |
|
|
615 |
free(nport); |
| 590 |
} |
616 |
} |
| 591 |
} |
617 |
} |
| 592 |
|
618 |
|