summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-01-05 21:15:40 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2019-01-18 11:40:28 +0100
commit0c68d46eaaed4558119a7c9a29ebaac6ea579126 (patch)
tree26aca1275c204759eaf9931d1be70cab47d94c9a
parent2ff91c09a03daaa21a0188fdbcdc62f1fb8874e5 (diff)
afb-hsrv: Avoid call to getnameinfo
Calling getnameinfo may block the program a long time (5s) when address is zero. Bug-AGL: SPEC-2133 Change-Id: Id52b2989c5e996363fd4b6f39049f059a6ee97a2 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-hsrv.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/afb-hsrv.c b/src/afb-hsrv.c
index 2a08a2e3..0d0bd061 100644
--- a/src/afb-hsrv.c
+++ b/src/afb-hsrv.c
@@ -540,13 +540,19 @@ static int hsrv_itf_connect(struct hsrv_itf *itf)
}
fdev_set_events(itf->fdev, EPOLLIN);
fdev_set_callback(itf->fdev, hsrv_itf_callback, itf);
+ memset(&addr, 0, sizeof addr);
lenaddr = (socklen_t)sizeof addr;
getsockname(fdev_fd(itf->fdev), &addr, &lenaddr);
- rgni = getnameinfo(&addr, lenaddr, hbuf, sizeof hbuf, sbuf, sizeof sbuf, NI_NUMERICSERV);
- if (rgni != 0) {
- ERROR("getnameinfo returned %d: %s", rgni, gai_strerror(rgni));
- hbuf[0] = sbuf[0] = '?';
- hbuf[1] = sbuf[1] = 0;
+ if (addr.sa_family == AF_INET && !((struct sockaddr_in*)&addr)->sin_addr.s_addr) {
+ strncpy(hbuf, "*", NI_MAXHOST);
+ sprintf(sbuf, "%d", (int)ntohs(((struct sockaddr_in*)&addr)->sin_port));
+ } else {
+ rgni = getnameinfo(&addr, lenaddr, hbuf, sizeof hbuf, sbuf, sizeof sbuf, NI_NUMERICSERV);
+ if (rgni != 0) {
+ ERROR("getnameinfo returned %d: %s", rgni, gai_strerror(rgni));
+ hbuf[0] = sbuf[0] = '?';
+ hbuf[1] = sbuf[1] = 0;
+ }
}
NOTICE("Listening interface %s:%s", hbuf, sbuf);
return 1;
@@ -583,4 +589,4 @@ int afb_hsrv_add_interface_tcp(struct afb_hsrv *hsrv, const char *itf, uint16_t
return 0;
}
return afb_hsrv_add_interface(hsrv, buffer);
-} \ No newline at end of file
+}