Ticket #2401: Make AI_ADDRCONFIG optional for RFC 3493 non-compliant systems

Unfortunately not all systems claiming POSIX support actually define
AI_ADDRCONFIG macro, and those who define it not always implement it
(this is indeed optional). This patch makes ftpfs only set AI_ADDRCONFIG
flag to speed up lookups if it is defined, and in this case, retry the
lookup if it was rejected due to unimplemented flags.

Based upon the code by Joe Orton <jorton@redhat.com> from APR:

Copyright (C) 2003 Red Hat, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
Yury V. Zaytsev 2011-01-22 23:04:17 +01:00
parent 22cdf545f4
commit afd8ec8934

View File

@ -153,11 +153,6 @@ int ftpfs_ignore_chattr_errors = 1;
#define INADDR_NONE 0xffffffff
#endif
/* for uclibc < 0.9.29 */
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x0020
#endif
#define RFC_AUTODETECT 0
#define RFC_DARING 1
#define RFC_STRICT 2
@ -805,11 +800,27 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
tty_enable_interrupt_key (); /* clear the interrupt flag */
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG;
#ifdef AI_ADDRCONFIG
/* By default, only look up addresses using address types for
* which a local interface is configured (i.e. no IPv6 if no IPv6
* interfaces, likewise for IPv4 (see RFC 3493 for details). */
hints.ai_flags = AI_ADDRCONFIG;
#endif
e = getaddrinfo (host, port, &hints, &res);
#ifdef AI_ADDRCONFIG
if (e == EAI_BADFLAGS)
{
/* Retry with no flags if AI_ADDRCONFIG was rejected. */
hints.ai_flags = 0;
e = getaddrinfo (host, port, &hints, &res);
}
#endif
g_free (port);
port = NULL;