]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added net_getpeername()
authorTimo Sirainen <tss@iki.fi>
Mon, 31 May 2004 18:56:43 +0000 (21:56 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 31 May 2004 18:56:43 +0000 (21:56 +0300)
--HG--
branch : HEAD

src/lib/network.c
src/lib/network.h

index 6f317e78ae18ddc31370b804ab6793cb42b0b842..fbb8d3ba1ff35b93893f66e3bffdf8c0115c617b 100644 (file)
@@ -487,6 +487,23 @@ int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
        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 b48c0399007cc4dcf860e753bed3a2aca6dd7fc6..50635a716f89f5d3bf75daf33db5048f36affe4b 100644 (file)
@@ -87,8 +87,10 @@ const char *net_gethosterror(int error);
    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);