[dovecot-cvs] dovecot/src/lib network.c, 1.22, 1.23 network.h, 1.10, 1.11

cras at procontrol.fi cras at procontrol.fi
Mon May 31 21:56:45 EEST 2004


Update of /home/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv6437/lib

Modified Files:
	network.c network.h 
Log Message:
Added net_getpeername()



Index: network.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- a/network.c	27 Apr 2004 20:25:53 -0000	1.22
+++ b/network.c	31 May 2004 18:56:43 -0000	1.23
@@ -487,6 +487,23 @@
 	return 0;
 }
 
+int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port)
+{
+	union sockaddr_union so;
+	socklen_t addrlen;
+
+	i_assert(fd >= 0);
+
+	addrlen = sizeof(so);
+	if (getpeername(fd, (struct sockaddr *) &so, &addrlen) == -1)
+		return -1;
+
+        if (addr != NULL) sin_get_ip(&so, addr);
+	if (port != NULL) *port = sin_get_port(&so);
+
+	return 0;
+}
+
 const char *net_ip2addr(const struct ip_addr *ip)
 {
 #ifdef HAVE_IPV6

Index: network.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- a/network.h	18 May 2003 16:37:04 -0000	1.10
+++ b/network.h	31 May 2004 18:56:43 -0000	1.11
@@ -87,8 +87,10 @@
    some error with name server) */
 int net_hosterror_notfound(int error);
 
-/* Get socket address/port */
+/* Get socket local address/port */
 int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port);
+/* Get socket remote address/port */
+int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port);
 
 /* Returns ip_addr as string, or NULL if ip is invalid. */
 const char *net_ip2addr(const struct ip_addr *ip);



More information about the dovecot-cvs mailing list