aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/net/sockname.c
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2025-01-14 16:06:02 -0600
committerWilliam Harrington <kb0iic@berzerkula.org>2025-01-14 16:06:02 -0600
commit0cc9b20c15460213e488bf5e70963b941482f628 (patch)
treebb0143245583ec846630f39bfa2258dba640ccd7 /sdk/net/sockname.c
parent0e084ade5069756d487b5c948c48b777e37c00c9 (diff)
Add source.
Diffstat (limited to 'sdk/net/sockname.c')
-rw-r--r--sdk/net/sockname.c62
1 files changed, 62 insertions, 0 deletions
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 <net/socket.h>
+
+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);
+}