mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-04 00:12:33 +02:00
httpserver: Collapse make_addrinfo into my_bind_socket_with_handle
This commit is contained in:
parent
d0a1e5bfd6
commit
a0427096a2
@ -354,35 +354,6 @@ bind_socket_ai(struct evutil_addrinfo *aitop, int reuse)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static struct evutil_addrinfo *
|
||||
make_addrinfo(const char *address, ev_uint16_t port)
|
||||
{
|
||||
struct evutil_addrinfo *ai = NULL;
|
||||
|
||||
struct evutil_addrinfo hints;
|
||||
char strport[NI_MAXSERV];
|
||||
int ai_result;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
/* turn NULL hostname into INADDR_ANY, and skip looking up any address
|
||||
* types we don't have an interface to connect to. */
|
||||
hints.ai_flags = EVUTIL_AI_PASSIVE|EVUTIL_AI_ADDRCONFIG;
|
||||
evutil_snprintf(strport, sizeof(strport), "%d", port);
|
||||
if ((ai_result = evutil_getaddrinfo(address, strport, &hints, &ai))
|
||||
!= 0) {
|
||||
if (ai_result == EVUTIL_EAI_SYSTEM)
|
||||
event_warn("getaddrinfo");
|
||||
else
|
||||
event_warnx("getaddrinfo: %s",
|
||||
evutil_gai_strerror(ai_result));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (ai);
|
||||
}
|
||||
|
||||
static struct evhttp_bound_socket *
|
||||
my_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port)
|
||||
{
|
||||
@ -396,7 +367,25 @@ my_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t
|
||||
if (address == NULL && port == 0) {
|
||||
fd = bind_socket_ai(NULL, 0);
|
||||
} else {
|
||||
aitop = make_addrinfo(address, port);
|
||||
struct evutil_addrinfo hints;
|
||||
char strport[NI_MAXSERV];
|
||||
int ai_result;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
/* turn NULL hostname into INADDR_ANY, and skip looking up any address
|
||||
* types we don't have an interface to connect to. */
|
||||
hints.ai_flags = EVUTIL_AI_PASSIVE|EVUTIL_AI_ADDRCONFIG;
|
||||
evutil_snprintf(strport, sizeof(strport), "%d", port);
|
||||
if ((ai_result = evutil_getaddrinfo(address, strport, &hints, &aitop)) != 0) {
|
||||
if (ai_result == EVUTIL_EAI_SYSTEM) {
|
||||
event_warn("getaddrinfo");
|
||||
} else {
|
||||
event_warnx("getaddrinfo: %s", evutil_gai_strerror(ai_result));
|
||||
}
|
||||
aitop = nullptr;
|
||||
}
|
||||
|
||||
if (aitop == NULL) {
|
||||
return nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user