From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- sdk/net/sockname.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sdk/net/sockname.c (limited to 'sdk/net/sockname.c') diff --git a/sdk/net/sockname.c b/sdk/net/sockname.c new file mode 100644 index 0000000..a8e9aad --- /dev/null +++ b/sdk/net/sockname.c @@ -0,0 +1,62 @@ +/* + * Portable socket and peer name services. + * $Id$ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include + +char *homename(SOCKET so) +{ + struct hostent *hp; + struct sockaddr_in sin; + int len = sizeof(sin); + + if(getsockname(so, (struct sockaddr *)&sin, &len) < 0) + return NULL; + + hp = gethostbyaddr((char *)&sin.sin_addr, sizeof(struct in_addr), AF_INET); + if(hp) + return (char *)hp->h_name; + else + return inet_ntoa(sin.sin_addr); +} + +char *homeaddr(SOCKET so) +{ + struct sockaddr_in sin; + int len = sizeof(sin); + + if(getsockname(so, (struct sockaddr *)&sin, &len) < 0) + return NULL; + + return inet_ntoa(sin.sin_addr); +} + +char *peername(SOCKET so) +{ + struct hostent *hp; + struct sockaddr_in sin; + int len = sizeof(sin); + + if(getpeername(so, (struct sockaddr *)&sin, &len) < 0) + return NULL; + + hp = gethostbyaddr((char *)&sin.sin_addr, sizeof(struct in_addr), AF_INET); + if(hp) + return (char *)hp->h_name; + else + return inet_ntoa(sin.sin_addr); +} + +char *peeraddr(SOCKET so) +{ + struct sockaddr_in sin; + int len = sizeof(sin); + + if(getpeername(so, (struct sockaddr *)&sin, &len) < 0) + return NULL; + + return inet_ntoa(sin.sin_addr); +} -- cgit v1.2.3-54-g00ecf