1166b5c38f4ea29c4761f45518e6079ea3ecf963
[ghc-hetmet.git] / ghc / lib / misc / cbits / getPeerName.c
1 #if 0
2 %
3 % (c) The GRASP/AQUA Project, Glasgow University, 1996
4 %
5 \subsection[getPeerName.lc]{Return name of peer process}
6
7 Returns name of peer process connected to a socket.
8
9 \begin{code}
10 #endif
11
12 #define NON_POSIX_SOURCE
13 #include "rtsdefs.h"
14 #include "ghcSockets.h"
15
16 StgInt
17 getPeerName(I_ sockfd, A_ peer, A_ namelen)
18 {
19     StgInt name;
20     
21     while ((name = getpeername((int) sockfd, (struct sockaddr *) peer, (int *) namelen)) < 0) {
22       if (errno != EINTR) {
23           cvtErrno();
24           stdErrno();
25           return -1;
26       }
27     }
28     return name;
29 }