1getpeerucred(3C)         Standard C Library Functions         getpeerucred(3C)
2
3
4

NAME

6       getpeerucred - get connected socket or stream peer's credentials
7

SYNOPSIS

9       #include <ucred.h>
10
11       int getpeerucred(int fd, ucred_t **ucred);
12
13

DESCRIPTION

15       The  getpeerucred()  function  returns the credentials of the peer end‐
16       point of a connection-oriented socket (SOCK_STREAM) or stream fd at the
17       time  the  endpoint  was  created or the connection was established.  A
18       process that initiates a connection retrieves the  credentials  of  its
19       peer  at  the time the peer's endpoint was created. A process that lis‐
20       tens for connections retrieves the credentials of the peer at the  time
21       the peer initiated the connection.
22
23
24       When  successful,  getpeerucred() stores the pointer to a freshly allo‐
25       cated ucred_t in the memory location pointed to by the  ucred  argument
26       if  that memory location contains the null pointer. If the memory loca‐
27       tion is non-null, it will reuse the existing ucred_t.
28
29
30       When ucred is no longer needed, a  credential  allocated  by  getpeeru‐
31       cred() should be freed with ucred_free(3C).
32
33
34       It  is possible that all fields of the ucred_t are not available to all
35       peer endpoints and all callers.
36

RETURN VALUES

38       Upon successful completion, getpeerucred()  returns  0.  Otherwise,  it
39       returns −1 and errno is set to indicate the error.
40

ERRORS

42       The getpeerucred() function will fail if:
43
44       EAGAIN      There is not enough memory available to allocate sufficient
45                   memory to hold the user credential. The application can try
46                   again later.
47
48
49       EBADF       The fd argument is not a valid file descriptor.
50
51
52       EFAULT      The  pointer location pointed to by the ucred_t ** argument
53                   points to an invalid, non-null address.
54
55
56       EINVAL      The socket  is  connected  but  the  peer  credentials  are
57                   unknown.
58
59
60       ENOMEM      The  physical limits of the system are exceeded by the mem‐
61                   ory allocation needed to hold the user credential.
62
63
64       ENOTCONN    The socket or stream is not connected or the stream's  peer
65                   is unknown.
66
67
68       ENOTSUP     This operation is not supported on this file descriptor.
69
70

ATTRIBUTES

72       See attributes(5) for descriptions of the following attributes:
73
74
75
76
77       ┌─────────────────────────────┬─────────────────────────────┐
78       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
79       ├─────────────────────────────┼─────────────────────────────┤
80       │Interface Stability          │Evolving                     │
81       ├─────────────────────────────┼─────────────────────────────┤
82       │MT-Level                     │MT-Safe                      │
83       └─────────────────────────────┴─────────────────────────────┘
84

SEE ALSO

86       door_ucred(3C), ucred_get(3C), attributes(5), connld(7M)
87

NOTES

89       The  system  currently  supports both sides of connection endpoints for
90       local AF_UNIX, AF_INET, and AF_INET6  sockets,  /dev/tcp,  /dev/ticots,
91       and  /dev/ticotsord XTI/TLI connections, and pipe file descriptors sent
92       using I_SENDFD as a result of  the  open  of  a  named  pipe  with  the
93       "connld" module pushed.
94
95
96
97SunOS 5.11                        26 May 2004                 getpeerucred(3C)
Impressum