summaryrefslogtreecommitdiff
path: root/src/plugins/relay/relay-server.c
diff options
context:
space:
mode:
authorMantas Mikulėnas <grawity@gmail.com>2013-05-30 08:03:21 +0200
committerSebastien Helleu <flashcode@flashtux.org>2013-05-30 08:03:21 +0200
commit1e49718398277f334e498c6ce50d1a98acd473e6 (patch)
tree7aab8975a72d5602d42811619ab8e340a57910d8 /src/plugins/relay/relay-server.c
parentc103c8d35677feda74fe386e0cf43519510fc500 (diff)
downloadweechat-1e49718398277f334e498c6ce50d1a98acd473e6.zip
relay: fix binding to an IP address (bug #39119)
Diffstat (limited to 'src/plugins/relay/relay-server.c')
-rw-r--r--src/plugins/relay/relay-server.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c
index d71ef6316..0606a4741 100644
--- a/src/plugins/relay/relay-server.c
+++ b/src/plugins/relay/relay-server.c
@@ -338,8 +338,11 @@ relay_server_create_socket (struct t_relay_server *server)
int domain, set, max_clients, addr_size;
struct sockaddr_in server_addr;
struct sockaddr_in6 server_addr6;
+ const char *bind_address;
void *ptr_addr;
+ bind_address = weechat_config_string (relay_config_network_bind_address);
+
if (server->ipv6)
{
domain = AF_INET6;
@@ -347,6 +350,18 @@ relay_server_create_socket (struct t_relay_server *server)
server_addr6.sin6_family = domain;
server_addr6.sin6_port = htons (server->port);
server_addr6.sin6_addr = in6addr_any;
+ if (bind_address && bind_address[0])
+ {
+ if (!inet_pton (domain, bind_address, &server_addr6.sin6_addr))
+ {
+ weechat_printf (NULL,
+ /* TRANSLATORS: second "%s" is "IPv4" or "IPv6" */
+ _("%s%s: invalid bind address \"%s\" for %s"),
+ weechat_prefix ("error"), RELAY_PLUGIN_NAME,
+ bind_address, "IPv6");
+ return 0;
+ }
+ }
ptr_addr = &server_addr6;
addr_size = sizeof (struct sockaddr_in6);
}
@@ -356,25 +371,22 @@ relay_server_create_socket (struct t_relay_server *server)
memset (&server_addr, 0, sizeof (struct sockaddr_in));
server_addr.sin_family = domain;
server_addr.sin_port = htons (server->port);
- if (weechat_config_string (relay_config_network_bind_address)
- && weechat_config_string (relay_config_network_bind_address)[0])
- {
- server_addr.sin_addr.s_addr = inet_addr (weechat_config_string (relay_config_network_bind_address));
- }
- else
+ server_addr.sin_addr.s_addr = INADDR_ANY;
+ if (bind_address && bind_address[0])
{
- server_addr.sin_addr.s_addr = INADDR_ANY;
+ if (!inet_pton (domain, bind_address, &server_addr.sin_addr))
+ {
+ weechat_printf (NULL,
+ /* TRANSLATORS: second "%s" is "IPv4" or "IPv6" */
+ _("%s%s: invalid bind address \"%s\" for %s"),
+ weechat_prefix ("error"), RELAY_PLUGIN_NAME,
+ bind_address, "IPv4");
+ return 0;
+ }
}
ptr_addr = &server_addr;
addr_size = sizeof (struct sockaddr_in);
}
- if (weechat_config_string (relay_config_network_bind_address)
- && weechat_config_string (relay_config_network_bind_address)[0])
- {
- inet_pton (domain,
- weechat_config_string (relay_config_network_bind_address),
- ptr_addr);
- }
/* create socket */
server->sock = socket (domain, SOCK_STREAM, 0);