Allow to use IPv4 addr with --bindhost
This commit is contained in:
parent
4f1a6aead2
commit
73f1d44c92
@ -74,7 +74,7 @@ struct custom_option custom_opts[] = {
|
||||
{{"hostname", required_argument, NULL, 'H'}, "UTS name (hostname) of the jail (default: 'NSJAIL')"},
|
||||
{{"cwd", required_argument, NULL, 'D'}, "Directory in the namespace the process will run (default: '/')"},
|
||||
{{"port", required_argument, NULL, 'p'}, "TCP port to bind to (enables MODE_LISTEN_TCP) (default: 0)"},
|
||||
{{"bindhost", required_argument, NULL, 0x604}, "IP address port to bind to (only in [MODE_LISTEN_TCP]), '::ffff:127.0.0.1' for locahost (default: '::')"},
|
||||
{{"bindhost", required_argument, NULL, 0x604}, "IP address to bind the port to (only in [MODE_LISTEN_TCP]), (default: '::')"},
|
||||
{{"max_conns_per_ip", required_argument, NULL, 'i'}, "Maximum number of connections per one IP (only in [MODE_LISTEN_TCP]), (default: 0 (unlimited))"},
|
||||
{{"log", required_argument, NULL, 'l'}, "Log file (default: use log_fd)"},
|
||||
{{"log_fd", required_argument, NULL, 'L'}, "Log FD (default: 2)"},
|
||||
|
14
net.c
14
net.c
@ -195,9 +195,17 @@ int netGetRecvSocket(const char *bindhost, int port)
|
||||
port);
|
||||
}
|
||||
|
||||
char bindaddr[128];
|
||||
snprintf(bindaddr, sizeof(bindaddr), "%s", bindhost);
|
||||
struct in_addr in4a;
|
||||
if (inet_pton(AF_INET, bindaddr, &in4a) == 1) {
|
||||
snprintf(bindaddr, sizeof(bindaddr), "::ffff:%s", bindhost);
|
||||
}
|
||||
|
||||
struct in6_addr in6a;
|
||||
if (inet_pton(AF_INET6, bindhost, &in6a) != 1) {
|
||||
PLOG_E("Couldn't convert '%s' into AF_INET6 address", bindhost);
|
||||
if (inet_pton(AF_INET6, bindaddr, &in6a) != 1) {
|
||||
PLOG_E("Couldn't convert '%s' (orig:'%s') into AF_INET6 address", bindaddr,
|
||||
bindhost);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -220,7 +228,7 @@ int netGetRecvSocket(const char *bindhost, int port)
|
||||
};
|
||||
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
close(sockfd);
|
||||
PLOG_E("bind(host:[%s], port:%d)", bindhost, port);
|
||||
PLOG_E("bind(host:[%s (orig:'%s')], port:%d)", bindaddr, bindhost, port);
|
||||
return -1;
|
||||
}
|
||||
if (listen(sockfd, SOMAXCONN) == -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user