From 539f5d7682b0afcf4f79c048666ade37da387272 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Oct 2019 21:29:37 +0100 Subject: [PATCH] test: udp-preload: Fix inet_ntop calling convention inet_ntop has a weird error return protocol. And our code for calling it never worked properly because we didn't strip the leading directory names from the bound socket name. Signed-off-by: Ian Jackson --- test/udp-preload.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/udp-preload.c b/test/udp-preload.c index b4c0879..49457ad 100644 --- a/test/udp-preload.c +++ b/test/udp-preload.c @@ -150,7 +150,10 @@ static int str2addrport(char *str, char *comma=strchr(str,','); if (!comma) { errno=ESRCH; return -1; } *comma++=0; - if (inet_pton(af,str,iav)) return -1; + int r=inet_pton(af,str,iav); +//fprintf(stderr,"inet_pton(%d,\"%s\",)=%d\n",af,str,r); + if (r<0) return -1; + if (r==0) { errno=ENOTTY; return -1; } char *ep; errno=0; @@ -244,7 +247,9 @@ WRAP(getsockname) { // (unsigned long)sunlen); errno=EDOM; return -1; } - if (str2addrport(sun.sun_path,addr,addrlen)) return -1; + char *slash=strrchr(sun.sun_path,'/'); + if (str2addrport(slash ? slash+1 : sun.sun_path, + addr,addrlen)) return -1; return 0; } -- 2.30.2