1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="TCP/IP Library Reference"
23 HREF="tcpip-library-reference.html"><LINK
26 HREF="net-common-tcpip-manpages-connect.html"><LINK
29 HREF="net-common-tcpip-manpages-getsockname.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-common-tcpip-manpages-connect.html"
65 >Chapter 38. TCP/IP Library Reference</TD
71 HREF="net-common-tcpip-manpages-getsockname.html"
85 NAME="NET-COMMON-TCPIP-MANPAGES-GETPEERNAME">getpeername</H1
94 >GETPEERNAME(2) System Calls Manual GETPEERNAME(2)
97 getpeername - get name of connected peer
100 #include <sys/types.h>
101 #include <sys/socket.h>
104 getpeername(int s, struct sockaddr *name, socklen_t *namelen);
107 getpeername() returns the address information of the peer connected to
108 socket s. One common use occurs when a process inherits an open socket,
109 such as TCP servers forked from inetd(8). In this scenario,
110 getpeername() is used to determine the connecting client's IP address.
112 getpeername() takes three parameters:
114 s Contains the file descriptor of the socket whose peer should be looked
117 name Points to a sockaddr structure that will hold the address informa-
118 tion for the connected peer. Normal use requires one to use a structure
119 specific to the protocol family in use, such as sockaddr_in (IPv4) or
120 sockaddr_in6 (IPv6), cast to a (struct sockaddr *).
122 For greater portability, especially with the newer protocol families, the
123 new struct sockaddr_storage should be used. sockaddr_storage is large
124 enough to hold any of the other sockaddr_* variants. On return, it can
125 be cast to the correct sockaddr type, based the protocol family contained
126 in its ss_family field.
128 namelen Indicates the amount of space pointed to by name, in bytes.
130 If address information for the local end of the socket is required, the
131 getsockname(2) function should be used instead.
133 If name does not point to enough space to hold the entire socket address,
134 the result will be truncated to namelen bytes.
137 If the call succeeds, a 0 is returned and namelen is set to the actual
138 size of the socket address returned in name. Otherwise, errno is set and
139 a value of -1 is returned.
142 On failure, errno is set to one of the following:
144 [EBADF] The argument s is not a valid descriptor.
146 [ENOTSOCK] The argument s is a file, not a socket.
148 [ENOTCONN] The socket is not connected.
150 [ENOBUFS] Insufficient resources were available in the system to
151 perform the operation.
153 [EFAULT] The name parameter points to memory not in a valid
154 part of the process address space.
157 accept(2), bind(2), getsockname(2), getpeereid(2), socket(2)
160 The getpeername() function call appeared in 4.2BSD.
162 BSD July 17, 1999 BSD
173 SUMMARY="Footer navigation table"
184 HREF="net-common-tcpip-manpages-connect.html"
202 HREF="net-common-tcpip-manpages-getsockname.html"
218 HREF="tcpip-library-reference.html"