File getnameinfo.patch of Package arpwatch.18007

Index: arpwatch-2.1a15/db.c
===================================================================
--- arpwatch-2.1a15.orig/db.c	2019-01-22 13:34:02.942536296 +0100
+++ arpwatch-2.1a15/db.c	2019-01-22 13:38:54.099329959 +0100
@@ -269,6 +269,7 @@ elist_alloc(register u_int32_t a, regist
 	register u_int size;
 	static struct einfo *elist = NULL;
 	static int eleft = 0;
+	char free_hostname = 0;
 
 	if (eleft <= 0) {
 		/* Allocate some more */
@@ -285,12 +286,16 @@ elist_alloc(register u_int32_t a, regist
 	ep = elist++;
 	--eleft;
 	BCOPY(e, ep->e, 6);
-	if (h == NULL && !initializing)
+	if (h == NULL && !initializing) {
 		h = getsname(a);
+		free_hostname = 1;
+	}
 	if (h != NULL && !isdigit((int)*h)) {
 		memset(ep->h, 0, sizeof(ep->h));
 		strncpy(ep->h, h, sizeof(ep->h)-1);
 	}
+	if (free_hostname)
+	    free(h);
 	ep->t = t;
 	return (ep);
 }
@@ -313,6 +318,7 @@ check_hname(register struct ainfo *ap)
 		memset(ep->h, 0, sizeof(ep->h));
 		strncpy(ep->h, h, sizeof(ep->h)-1);
 	}
+	free(h);
 }
 
 int
Index: arpwatch-2.1a15/dns.c
===================================================================
--- arpwatch-2.1a15.orig/dns.c	2000-10-14 03:50:52.000000000 +0200
+++ arpwatch-2.1a15/dns.c	2019-01-22 13:39:31.043941461 +0100
@@ -137,24 +137,30 @@ gethinfo(register char *hostname, regist
 	return (0);
 }
 
-/* Return the cannonical name of the host */
+/* Return the cannonical name of the host
+   Returned value needs to be free'd
+*/
 char *
 gethname(u_int32_t a)
 {
-	register int32_t options;
-	register struct hostent *hp;
+	struct sockaddr_in sa;
+	char node[NI_MAXHOST];
+	struct in_addr addr;
 
-	options = _res.options;
-	_res.options |= RES_AAONLY;
-	_res.options &= ~(RES_DEFNAMES | RES_DNSRCH);
-	hp = gethostbyaddr((char *)&a, sizeof(a), AF_INET);
-	_res.options = options;
-	if (hp == NULL)
-		return (intoa(a));
-	return (hp->h_name);
+	addr.s_addr   = a;
+	sa.sin_family = AF_INET;
+	sa.sin_addr   = addr;
+
+	int res = getnameinfo((struct sockaddr*)&sa, sizeof(sa), node, sizeof(node), NULL, 0, 0 );
+	if (res)
+	    return strdup(intoa(a));
+
+	return strdup(node);
 }
 
-/* Return the simple name of the host */
+/* Return the simple name of the host
+   Returned value needs to be free'd
+*/
 char *
 getsname(register u_int32_t a)
 {
Index: arpwatch-2.1a15/report.c
===================================================================
--- arpwatch-2.1a15.orig/report.c	2019-01-22 13:34:02.962536621 +0100
+++ arpwatch-2.1a15/report.c	2019-01-22 13:37:04.081507637 +0100
@@ -311,6 +311,7 @@ report(register char *title, register u_
 		(void)fprintf(f, "Subject: %s (%s)\n", title, hn);
 	else {
 		(void)fprintf(f, "Subject: %s\n", title);
+		free( hn );
 		hn = unknown;
 	}
 	(void)putc('\n', f);
@@ -324,6 +325,8 @@ report(register char *title, register u_
 		(void)sprintf(buf, "%s %s", cpu, os);
 		(void)fprintf(f, fmt, "dns cpu & os", buf);
 	}
+	if (hn != unknown)
+	    free(hn);
 	if (e2) {
 		(void)fprintf(f, fmt, "old mac address", e2str(e2));
 		if ((cp = ec_find(e2)) == NULL)
openSUSE Build Service is sponsored by