/CONNECT, /SERVER: added -4 and -6 options for specifying if we should

connect to IPv4 or IPv6 address of the server. If -host or /SET
hostname is set irssi determines from it if it should use IPv4 or v6.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1192 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-02-09 21:26:50 +00:00 committed by cras
commit 8938a0f42b
8 changed files with 39 additions and 22 deletions

View file

@ -137,10 +137,12 @@ int sin_get_port(union sockaddr_union *so)
GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip)
{
IPADDR ip;
int family;
g_return_val_if_fail(addr != NULL, NULL);
if (net_gethostbyname(addr, &ip) == -1)
family = my_ip == NULL ? 0 : my_ip->family;
if (net_gethostbyname(addr, &ip, family) == -1)
return NULL;
return net_connect_ip(&ip, port, my_ip);
@ -332,11 +334,11 @@ int net_getsockname(GIOChannel *handle, IPADDR *addr, int *port)
/* Get IP address for host, returns 0 = ok,
others = error code for net_gethosterror() */
int net_gethostbyname(const char *addr, IPADDR *ip)
int net_gethostbyname(const char *addr, IPADDR *ip, int family)
{
#ifdef HAVE_IPV6
union sockaddr_union *so;
struct addrinfo req, *ai;
struct addrinfo hints, *ai;
char hbuf[NI_MAXHOST];
int host_error;
#else
@ -347,11 +349,13 @@ int net_gethostbyname(const char *addr, IPADDR *ip)
#ifdef HAVE_IPV6
memset(ip, 0, sizeof(IPADDR));
memset(&req, 0, sizeof(struct addrinfo));
req.ai_socktype = SOCK_STREAM;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = family;
/* save error to host_error for later use */
host_error = getaddrinfo(addr, NULL, &req, &ai);
host_error = getaddrinfo(addr, NULL, &hints, &ai);
if (host_error != 0)
return host_error;