aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/net/sockname.c
blob: a8e9aadb9f8a68d0836c3d963295c56c92162252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}