Browse Source

Deal better with displaying IPv6 addresses

tags/v0.9
Přemysl Janouch 5 years ago
parent
commit
3afd81df9b
3 changed files with 30 additions and 12 deletions
  1. +9
    -0
      common.c
  2. +17
    -11
      kike.c
  3. +4
    -1
      zyklonb.c

+ 9
- 0
common.c View File

@@ -1604,6 +1604,15 @@ xssl_get_error (SSL *ssl, int result, const char **error_info)
}
}

static char *
format_host_port_pair (const char *host, const char *port)
{
// IPv6 addresses mess with the "colon notation"; let's go with RFC 2732
if (strchr (host, ':'))
return xstrdup_printf ("[%s]:%s", host, port);
return xstrdup_printf ("%s:%s", host, port);
}

// --- Regular expressions -----------------------------------------------------

static regex_t *

+ 17
- 11
kike.c View File

@@ -2661,7 +2661,10 @@ on_irc_client_available (const struct pollfd *pfd, void *user_data)
host, sizeof host, port, sizeof port, NI_NUMERICSERV);
if (err)
print_debug ("%s: %s", "getnameinfo", gai_strerror (err));
print_debug ("accepted connection from %s:%s", host, port);

char *address = format_host_port_pair (host, port);
print_debug ("accepted connection from %s", address);
free (address);

struct client *c = xmalloc (sizeof *c);
client_init (c);
@@ -2922,26 +2925,27 @@ irc_listen (struct addrinfo *gai_iter)
soft_assert (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
&yes, sizeof yes) != -1);

char real_host[NI_MAXHOST], real_port[NI_MAXSERV];
real_host[0] = real_port[0] = '\0';
char host[NI_MAXHOST], port[NI_MAXSERV];
host[0] = port[0] = '\0';
int err = getnameinfo (gai_iter->ai_addr, gai_iter->ai_addrlen,
real_host, sizeof real_host, real_port, sizeof real_port,
host, sizeof host, port, sizeof port,
NI_NUMERICHOST | NI_NUMERICSERV);
if (err)
print_debug ("%s: %s", "getnameinfo", gai_strerror (err));

char *address = format_host_port_pair (host, port);
if (bind (fd, gai_iter->ai_addr, gai_iter->ai_addrlen))
print_error ("bind to %s:%s failed: %s",
real_host, real_port, strerror (errno));
print_error ("bind to %s failed: %s", address, strerror (errno));
else if (listen (fd, 16 /* arbitrary number */))
print_error ("listen on %s:%s failed: %s",
real_host, real_port, strerror (errno));
print_error ("listen on %s failed: %s", address, strerror (errno));
else
{
print_status ("listening on %s:%s", real_host, real_port);
print_status ("listening on %s", address);
free (address);
return fd;
}

free (address);
xclose (fd);
return -1;
}
@@ -2954,8 +2958,10 @@ irc_listen_resolve (struct server_context *ctx,
int err = getaddrinfo (host, port, gai_hints, &gai_result);
if (err)
{
print_error ("bind to %s:%s failed: %s: %s",
host, port, "getaddrinfo", gai_strerror (err));
char *address = format_host_port_pair (host, port);
print_error ("bind to %s failed: %s: %s",
address, "getaddrinfo", gai_strerror (err));
free (address);
return;
}


+ 4
- 1
zyklonb.c View File

@@ -355,7 +355,10 @@ irc_establish_connection (struct bot_context *ctx,
real_host = buf;

// XXX: we shouldn't mix these statuses with `struct error'; choose 1!
print_status ("connecting to `%s:%s'...", real_host, port);
char *address = format_host_port_pair (real_host, port);
print_status ("connecting to %s...", address);
free (address);

if (!connect (sockfd, gai_iter->ai_addr, gai_iter->ai_addrlen))
break;


Loading…
Cancel
Save