Mercurial > dovecot > core-2.2
changeset 2098:24e382b88232 HEAD
Added net_getpeername()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 31 May 2004 21:56:43 +0300 |
parents | 4e77cb0aff21 |
children | eac49325fa23 |
files | src/lib/network.c src/lib/network.h |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/network.c Mon May 31 21:04:46 2004 +0300 +++ b/src/lib/network.c Mon May 31 21:56:43 2004 +0300 @@ -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
--- a/src/lib/network.h Mon May 31 21:04:46 2004 +0300 +++ b/src/lib/network.h Mon May 31 21:56:43 2004 +0300 @@ -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);