r4449 - in trunk/varnish-cache: include lib/libvarnish

phk at projects.linpro.no phk at projects.linpro.no
Wed Jan 13 11:58:24 CET 2010


Author: phk
Date: 2010-01-13 11:58:23 +0100 (Wed, 13 Jan 2010)
New Revision: 4449

Modified:
   trunk/varnish-cache/include/libvarnish.h
   trunk/varnish-cache/lib/libvarnish/tcp.c
Log:
Add TCP_hisname() function



Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2010-01-13 09:19:49 UTC (rev 4448)
+++ trunk/varnish-cache/include/libvarnish.h	2010-01-13 10:58:23 UTC (rev 4449)
@@ -61,6 +61,7 @@
 #define TCP_PORTBUFSIZE		16
 
 void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen);
+void TCP_hisname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen);
 int TCP_filter_http(int sock);
 void TCP_blocking(int sock);
 void TCP_nonblocking(int sock);

Modified: trunk/varnish-cache/lib/libvarnish/tcp.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/tcp.c	2010-01-13 09:19:49 UTC (rev 4448)
+++ trunk/varnish-cache/lib/libvarnish/tcp.c	2010-01-13 10:58:23 UTC (rev 4449)
@@ -98,7 +98,24 @@
 	AZ(getsockname(sock, addr, &l));
 	TCP_name(addr, l, abuf, alen, pbuf, plen);
 }
+/*--------------------------------------------------------------------*/
 
+void
+TCP_hisname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
+{
+	struct sockaddr_storage addr_s;
+	struct sockaddr	*addr = (void*)&addr_s;
+	socklen_t l;
+
+	l = sizeof addr_s;
+	if (!getpeername(sock, addr, &l))
+		TCP_name(addr, l, abuf, alen, pbuf, plen);
+	else {
+		strlcpy(abuf, "<none>", alen);
+		strlcpy(pbuf, "<none>", plen);
+	}
+}
+
 /*--------------------------------------------------------------------*/
 
 int



More information about the varnish-commit mailing list