|
Lines 75-91
Link Here
|
| 75 |
#define WHOIS_INIC_FALLBACK 0x02 |
75 |
#define WHOIS_INIC_FALLBACK 0x02 |
| 76 |
#define WHOIS_QUICK 0x04 |
76 |
#define WHOIS_QUICK 0x04 |
| 77 |
|
77 |
|
| 78 |
static void usage __P((void)); |
78 |
static void usage(void); |
| 79 |
static void whois __P((char *, struct addrinfo *, int)); |
79 |
static void whois(char *, struct addrinfo *, int); |
| 80 |
|
80 |
|
| 81 |
int |
81 |
int |
| 82 |
main(argc, argv) |
82 |
main(int argc, char *argv[]) |
| 83 |
int argc; |
|
|
| 84 |
char **argv; |
| 85 |
{ |
83 |
{ |
| 86 |
int ch, i, j, error; |
84 |
int ch, i, j, error; |
| 87 |
int use_qnichost, flags; |
85 |
int use_qnichost, flags; |
| 88 |
char *host; |
86 |
const char *host; |
| 89 |
char *qnichost; |
87 |
char *qnichost; |
| 90 |
struct addrinfo hints, *res; |
88 |
struct addrinfo hints, *res; |
| 91 |
|
89 |
|
|
Lines 157-166
Link Here
|
| 157 |
} |
155 |
} |
| 158 |
while (argc--) { |
156 |
while (argc--) { |
| 159 |
if (use_qnichost) { |
157 |
if (use_qnichost) { |
| 160 |
if (qnichost) { |
|
|
| 161 |
free(qnichost); |
| 162 |
qnichost = NULL; |
| 163 |
} |
| 164 |
for (i = j = 0; (*argv)[i]; i++) { |
158 |
for (i = j = 0; (*argv)[i]; i++) { |
| 165 |
if ((*argv)[i] == '.') { |
159 |
if ((*argv)[i] == '.') { |
| 166 |
j = i; |
160 |
j = i; |
|
Lines 168-184
Link Here
|
| 168 |
} |
162 |
} |
| 169 |
if (j != 0) { |
163 |
if (j != 0) { |
| 170 |
if (isdigit(*(*argv + j + 1))) { |
164 |
if (isdigit(*(*argv + j + 1))) { |
| 171 |
(void) asprintf(&qnichost, "%s", |
165 |
qnichost = strdup(ANICHOST); |
| 172 |
ANICHOST); |
166 |
if (qnichost == NULL) { |
|
|
167 |
err(1, "strdup"); |
| 168 |
} |
| 173 |
} else { |
169 |
} else { |
| 174 |
qnichost = (char *) calloc(i - j |
170 |
(void)asprintf(&qnichost, "%s%s", |
| 175 |
+ 1 + strlen(QNICHOST_TAIL), |
171 |
*argv + j + 1, QNICHOST_TAIL); |
| 176 |
sizeof(char)); |
172 |
if (qnichost == NULL) { |
| 177 |
if (!qnichost) { |
173 |
err(1, "asprintf"); |
| 178 |
err(1, "calloc"); |
|
|
| 179 |
} |
174 |
} |
| 180 |
strcpy(qnichost, *argv + j + 1); |
|
|
| 181 |
strcat(qnichost, QNICHOST_TAIL); |
| 182 |
} |
175 |
} |
| 183 |
|
176 |
|
| 184 |
memset(&hints, 0, sizeof(hints)); |
177 |
memset(&hints, 0, sizeof(hints)); |
|
Lines 186-195
Link Here
|
| 186 |
hints.ai_family = AF_UNSPEC; |
179 |
hints.ai_family = AF_UNSPEC; |
| 187 |
hints.ai_socktype = SOCK_STREAM; |
180 |
hints.ai_socktype = SOCK_STREAM; |
| 188 |
error = getaddrinfo(qnichost, "whois", |
181 |
error = getaddrinfo(qnichost, "whois", |
| 189 |
&hints, &res); |
182 |
&hints, &res); |
| 190 |
if (error != 0) |
183 |
if (error != 0) |
| 191 |
errx(EX_NOHOST, "%s: %s", qnichost, |
184 |
errx(EX_NOHOST, "%s: %s", qnichost, |
| 192 |
gai_strerror(error)); |
185 |
gai_strerror(error)); |
| 193 |
} |
186 |
} |
| 194 |
} |
187 |
} |
| 195 |
if (!qnichost) { |
188 |
if (!qnichost) { |
|
Lines 203-208
Link Here
|
| 203 |
gai_strerror(error)); |
196 |
gai_strerror(error)); |
| 204 |
} |
197 |
} |
| 205 |
|
198 |
|
|
|
199 |
free(qnichost); |
| 200 |
qnichost = NULL; |
| 206 |
whois(*argv++, res, flags); |
201 |
whois(*argv++, res, flags); |
| 207 |
freeaddrinfo(res); |
202 |
freeaddrinfo(res); |
| 208 |
} |
203 |
} |
|
Lines 210-219
Link Here
|
| 210 |
} |
205 |
} |
| 211 |
|
206 |
|
| 212 |
static void |
207 |
static void |
| 213 |
whois(name, res, flags) |
208 |
whois(char *name, struct addrinfo *res, int flags) |
| 214 |
char *name; |
|
|
| 215 |
struct addrinfo *res; |
| 216 |
int flags; |
| 217 |
{ |
209 |
{ |
| 218 |
FILE *sfi, *sfo; |
210 |
FILE *sfi, *sfo; |
| 219 |
char *buf, *p, *nhost; |
211 |
char *buf, *p, *nhost; |
|
Lines 277-283
Link Here
|
| 277 |
/* Do second lookup as needed */ |
269 |
/* Do second lookup as needed */ |
| 278 |
if (nomatch && !nhost) { |
270 |
if (nomatch && !nhost) { |
| 279 |
(void)printf("Looking up %s at %s.\n\n", name, INICHOST); |
271 |
(void)printf("Looking up %s at %s.\n\n", name, INICHOST); |
| 280 |
nhost = INICHOST; |
272 |
nhost = strdup(INICHOST); |
|
|
273 |
if (nhost == NULL) { |
| 274 |
err(1, "strdup"); |
| 275 |
} |
| 281 |
} |
276 |
} |
| 282 |
if (nhost) { |
277 |
if (nhost) { |
| 283 |
struct addrinfo hints, *res2; |
278 |
struct addrinfo hints, *res2; |
|
Lines 301-307
Link Here
|
| 301 |
} |
296 |
} |
| 302 |
|
297 |
|
| 303 |
static void |
298 |
static void |
| 304 |
usage() |
299 |
usage(void) |
| 305 |
{ |
300 |
{ |
| 306 |
(void)fprintf(stderr, |
301 |
(void)fprintf(stderr, |
| 307 |
"usage: whois [-adgimpQrR6] [-h hostname] name ...\n"); |
302 |
"usage: whois [-adgimpQrR6] [-h hostname] name ...\n"); |