146
151
return Rgethostbyname2(name, AF_INET);
157
Rgetaddrinfo(nodename, servname, hints, res)
158
const char *nodename;
159
const char *servname;
160
const struct addrinfo *hints;
161
struct addrinfo **res;
163
const char *function = "Rgetaddrinfo()";
164
struct addrinfo fakehints;
165
struct in_addr ipindex;
166
char addrstr[INET6_ADDRSTRLEN];
167
char addrbuf[sizeof(struct in6_addr)];
173
if (nodename != NULL)
174
slog(LOG_DEBUG, "%s: %s", function, nodename);
179
|| (hints != NULL && hints->ai_flags & AI_NUMERICHOST)) {
182
} else if (hints == NULL || hints->ai_protocol == PF_UNSPEC) {
183
#if HAVE_IPV6_SUPPORT
184
if (inet_pton(AF_INET6, nodename, addrbuf) == 1
185
|| inet_pton(AF_INET, nodename, addrbuf) == 1)
187
#else /* HAVE_IPV6_SUPPORT */
188
if (inet_pton(AF_INET, nodename, addrbuf) == 1)
190
#endif /* HAVE_IPV6_SUPPORT */
192
#if HAVE_IPV6_SUPPORT
193
} else if (hints->ai_protocol == PF_INET6) {
194
if (inet_pton(AF_INET6, nodename, addrbuf) == 1)
196
#endif /* HAVE_IPV6_SUPPORT */
198
} else if (hints->ai_protocol == PF_INET) {
199
if (inet_pton(AF_INET, nodename, addrbuf) == 1)
203
switch (sockscf.resolveprotocol) {
204
case RESOLVEPROTOCOL_TCP:
205
case RESOLVEPROTOCOL_UDP:
206
gaierr = getaddrinfo(nodename, servname, hints, res);
207
if (gaierr == 0 || !fakeip_flag)
211
case RESOLVEPROTOCOL_FAKE:
213
return getaddrinfo(nodename, servname, hints, res);
217
SERRX(sockscf.resolveprotocol);
220
if (!fakeip_flag || nodename == NULL)
223
if (sockscf.resolveprotocol != RESOLVEPROTOCOL_FAKE)
224
slog(LOG_DEBUG, "%s: getaddrinfo(%s): %s",
225
function, nodename, gai_strerror(gaierr));
227
if ((ipindex.s_addr = socks_addfakeip(nodename)) == htonl(INADDR_NONE))
229
strcpy(addrstr, inet_ntoa(ipindex));
232
fakehints.ai_flags = AI_NUMERICHOST;
233
fakehints.ai_family = PF_INET;
234
fakehints.ai_socktype = 0;
235
fakehints.ai_protocol = 0;
237
fakehints.ai_flags = hints->ai_flags | AI_NUMERICHOST;
238
fakehints.ai_family = hints->ai_family;
239
fakehints.ai_socktype = hints->ai_socktype;
240
fakehints.ai_protocol = hints->ai_protocol;
242
fakehints.ai_addrlen = 0;
243
fakehints.ai_canonname = NULL;
244
fakehints.ai_addr = NULL;
245
fakehints.ai_next = NULL;
247
return getaddrinfo(addrstr, servname, &fakehints, res);
250
#endif /* HAVE_GETADDRINFO */
252
#if HAVE_GETIPNODEBYNAME
254
* Solaris appears to implement getaddrinfo() by calling
255
* getipnodebyname(), but since they are in different libraries, they
256
* must be implemented independently.
262
Rgetipnodebyname2(name, af, flags, error_num)
268
const char *function = "Rgetipnodebyname2()";
270
struct in_addr ipindex;
271
struct hostent *hostent;
273
/* needs to be done before getipnodebyname calls. */
276
slog(LOG_DEBUG, "%s: %s", function, name);
278
switch (sockscf.resolveprotocol) {
279
case RESOLVEPROTOCOL_TCP:
280
case RESOLVEPROTOCOL_UDP:
281
slog(LOG_DEBUG, "%s: using udp/tcp", function);
282
if ((hostent = getipnodebyname(name, af, flags,
287
case RESOLVEPROTOCOL_FAKE:
288
slog(LOG_DEBUG, "%s: using fake", function);
290
h_errno = NO_RECOVERY;
294
SERRX(sockscf.resolveprotocol);
297
if (h_errno != NO_RECOVERY)
300
hostent = (struct hostent *) malloc(sizeof(struct hostent));
302
/* anything that fails from here is due to resource shortage. */
305
if ((hostent->h_name = strdup(name)) == NULL) {
310
hostent->h_aliases = NULL;
311
hostent->h_addrtype = af;
313
/* * 2; NULL terminated. */
314
if ((addrlist = (char **)malloc(sizeof(addrlist) * 2)) == NULL) {
315
free(hostent->h_name);
322
static char ipv4[INET_ADDRSTRLEN];
324
slog(LOG_DEBUG, "%s: AF_INET", function);
325
hostent->h_length = sizeof(ipv4);
331
static char ipv6[INET6_ADDRSTRLEN];
333
slog(LOG_DEBUG, "%s: AF_INET6", function);
334
hostent->h_length = sizeof(ipv6);
341
slog(LOG_DEBUG, "%s: AF_????? (%d)", function, af);
343
free(hostent->h_name);
348
if ((ipindex.s_addr = socks_addfakeip(name)) == htonl(INADDR_NONE)) {
349
free(hostent->h_name);
358
memcpy(*addrlist, &ipindex.s_addr, sizeof(in_addr_t));
363
unsigned char ff[] = {0xff,0xff};
364
memset(*addrlist, 0, 10);
365
memcpy(*addrlist+10, ff, 2);
366
memcpy(*addrlist+12, &ipindex.s_addr,
373
slog(LOG_DEBUG, "%s: AF_????? (%d)", function, af);
375
free(hostent->h_name);
382
slog(LOG_DEBUG, "%s: after inet_pton (0x%x, %s)", function, (unsigned int)*addrlist, inet_ntoa(ipindex));
383
hostent->h_addr_list = addrlist++;
390
Rgetipnodebyname(name, af, flags, error_num)
396
struct hostent *hent;
397
const char *function = "Rgetipnodebyname()";
399
slog(LOG_DEBUG, "%s: %s, %d", function, name, af);
401
if ((hent = Rgetipnodebyname2(name, af, flags, error_num)) == NULL)
402
*error_num = h_errno;
414
if(socks_getfakeip(ptr->h_name, &addr)) {
416
free(*(ptr->h_addr_list));
417
free(ptr->h_addr_list);
419
} else freehostent(ptr);
422
#endif /* HAVE_GETIPNODEBYNAME */