|
Lines 84-89
Link Here
|
| 84 |
{ |
84 |
{ |
| 85 |
int ch, i, j, error; |
85 |
int ch, i, j, error; |
| 86 |
int use_qnichost, flags; |
86 |
int use_qnichost, flags; |
|
|
87 |
int found = 0; |
| 87 |
char *host; |
88 |
char *host; |
| 88 |
char *qnichost; |
89 |
char *qnichost; |
| 89 |
struct addrinfo hints, *res; |
90 |
struct addrinfo hints, *res; |
|
Lines 160-188
Link Here
|
| 160 |
free(qnichost); |
161 |
free(qnichost); |
| 161 |
qnichost = NULL; |
162 |
qnichost = NULL; |
| 162 |
} |
163 |
} |
| 163 |
for (i = j = 0; (*argv)[i]; i++) { |
164 |
for (i = 0; (*argv)[i]; i++); |
| 164 |
if ((*argv)[i] == '.') { |
165 |
if (i <= 1) { |
| 165 |
j = i; |
166 |
errx(EX_NOHOST, |
| 166 |
} |
167 |
"Can't search for the null string."); |
| 167 |
} |
168 |
} |
| 168 |
if (j != 0) { |
169 |
if (*argv[i] == '.') i--; |
| 169 |
qnichost = (char *) calloc(i - j + 1 + |
170 |
for (j = 0; (*argv)[j]; j++) { |
| 170 |
strlen(QNICHOST_TAIL), sizeof(char)); |
171 |
if (((*argv)[j] == '.') && !found) { |
| 171 |
if (!qnichost) { |
172 |
qnichost = (char *) calloc(i - j + 1 + |
| 172 |
err(1, "calloc"); |
173 |
strlen(QNICHOST_TAIL), |
|
|
174 |
sizeof(char)); |
| 175 |
if (!qnichost) { |
| 176 |
err(1, "calloc"); |
| 177 |
} |
| 178 |
strcpy(qnichost, *argv + j + 1); |
| 179 |
strcat(qnichost, QNICHOST_TAIL); |
| 180 |
|
| 181 |
memset(&hints, 0, sizeof(hints)); |
| 182 |
hints.ai_flags = 0; |
| 183 |
hints.ai_family = AF_UNSPEC; |
| 184 |
hints.ai_socktype = SOCK_STREAM; |
| 185 |
error = getaddrinfo(qnichost, "whois", |
| 186 |
&hints, &res); |
| 187 |
if (error == 0) { |
| 188 |
found = 1; |
| 189 |
} else { |
| 190 |
free(qnichost); |
| 191 |
qnichost = NULL; |
| 192 |
} |
| 173 |
} |
193 |
} |
| 174 |
strcpy(qnichost, *argv + j + 1); |
|
|
| 175 |
strcat(qnichost, QNICHOST_TAIL); |
| 176 |
|
194 |
|
| 177 |
memset(&hints, 0, sizeof(hints)); |
195 |
} |
| 178 |
hints.ai_flags = 0; |
196 |
if (!found) { |
| 179 |
hints.ai_family = AF_UNSPEC; |
197 |
errx(EX_NOHOST, |
| 180 |
hints.ai_socktype = SOCK_STREAM; |
198 |
"Cannot locate whois server for %s", |
| 181 |
error = getaddrinfo(qnichost, "whois", |
199 |
*argv); |
| 182 |
&hints, &res); |
|
|
| 183 |
if (error != 0) |
| 184 |
errx(EX_NOHOST, "%s: %s", qnichost, |
| 185 |
gai_strerror(error)); |
| 186 |
} |
200 |
} |
| 187 |
} |
201 |
} |
| 188 |
if (!qnichost) { |
202 |
if (!qnichost) { |