|
|
@ -144,6 +144,7 @@ start(cfg_t *cfg) { |
|
|
|
for (f2b_port_t *port = cfg->ports; port != 0; port = port->next) { |
|
|
|
for (f2b_port_t *port = cfg->ports; port != 0; port = port->next) { |
|
|
|
port->sock = -1; |
|
|
|
port->sock = -1; |
|
|
|
int ret = getaddrinfo(port->host, port->port, &hints, &result); |
|
|
|
int ret = getaddrinfo(port->host, port->port, &hints, &result); |
|
|
|
|
|
|
|
int opt = 1; |
|
|
|
if (ret != 0) { |
|
|
|
if (ret != 0) { |
|
|
|
snprintf(cfg->error, sizeof(cfg->error), "getaddrinfo: %s", gai_strerror(ret)); |
|
|
|
snprintf(cfg->error, sizeof(cfg->error), "getaddrinfo: %s", gai_strerror(ret)); |
|
|
|
cfg->errcb(cfg->error); |
|
|
|
cfg->errcb(cfg->error); |
|
|
@ -153,6 +154,7 @@ start(cfg_t *cfg) { |
|
|
|
port->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
|
|
|
port->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
|
|
|
if (port->sock == -1) |
|
|
|
if (port->sock == -1) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
setsockopt(port->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); |
|
|
|
if (bind(port->sock, rp->ai_addr, rp->ai_addrlen) == 0) { |
|
|
|
if (bind(port->sock, rp->ai_addr, rp->ai_addrlen) == 0) { |
|
|
|
if (listen(port->sock, 5) == 0) /* TODO: hardcoded */ |
|
|
|
if (listen(port->sock, 5) == 0) /* TODO: hardcoded */ |
|
|
|
break; /* success */ |
|
|
|
break; /* success */ |
|
|
|