<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>getpeername</TITLE
|
>getpeername</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="connect"
|
TITLE="connect"
|
HREF="net-common-tcpip-manpages-connect.html"><LINK
|
HREF="net-common-tcpip-manpages-connect.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="getsockname"
|
TITLE="getsockname"
|
HREF="net-common-tcpip-manpages-getsockname.html"></HEAD
|
HREF="net-common-tcpip-manpages-getsockname.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-connect.html"
|
HREF="net-common-tcpip-manpages-connect.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 38. TCP/IP Library Reference</TD
|
>Chapter 38. TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-getsockname.html"
|
HREF="net-common-tcpip-manpages-getsockname.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="NET-COMMON-TCPIP-MANPAGES-GETPEERNAME">getpeername</H1
|
NAME="NET-COMMON-TCPIP-MANPAGES-GETPEERNAME">getpeername</H1
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>GETPEERNAME(2) System Calls Manual GETPEERNAME(2)
|
>GETPEERNAME(2) System Calls Manual GETPEERNAME(2)
|
|
|
NAME
|
NAME
|
getpeername - get name of connected peer
|
getpeername - get name of connected peer
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/socket.h>
|
#include <sys/socket.h>
|
|
|
int
|
int
|
getpeername(int s, struct sockaddr *name, socklen_t *namelen);
|
getpeername(int s, struct sockaddr *name, socklen_t *namelen);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
getpeername() returns the address information of the peer connected to
|
getpeername() returns the address information of the peer connected to
|
socket s. One common use occurs when a process inherits an open socket,
|
socket s. One common use occurs when a process inherits an open socket,
|
such as TCP servers forked from inetd(8). In this scenario,
|
such as TCP servers forked from inetd(8). In this scenario,
|
getpeername() is used to determine the connecting client's IP address.
|
getpeername() is used to determine the connecting client's IP address.
|
|
|
getpeername() takes three parameters:
|
getpeername() takes three parameters:
|
|
|
s Contains the file descriptor of the socket whose peer should be looked
|
s Contains the file descriptor of the socket whose peer should be looked
|
up.
|
up.
|
|
|
name Points to a sockaddr structure that will hold the address informa-
|
name Points to a sockaddr structure that will hold the address informa-
|
tion for the connected peer. Normal use requires one to use a structure
|
tion for the connected peer. Normal use requires one to use a structure
|
specific to the protocol family in use, such as sockaddr_in (IPv4) or
|
specific to the protocol family in use, such as sockaddr_in (IPv4) or
|
sockaddr_in6 (IPv6), cast to a (struct sockaddr *).
|
sockaddr_in6 (IPv6), cast to a (struct sockaddr *).
|
|
|
For greater portability, especially with the newer protocol families, the
|
For greater portability, especially with the newer protocol families, the
|
new struct sockaddr_storage should be used. sockaddr_storage is large
|
new struct sockaddr_storage should be used. sockaddr_storage is large
|
enough to hold any of the other sockaddr_* variants. On return, it can
|
enough to hold any of the other sockaddr_* variants. On return, it can
|
be cast to the correct sockaddr type, based the protocol family contained
|
be cast to the correct sockaddr type, based the protocol family contained
|
in its ss_family field.
|
in its ss_family field.
|
|
|
namelen Indicates the amount of space pointed to by name, in bytes.
|
namelen Indicates the amount of space pointed to by name, in bytes.
|
|
|
If address information for the local end of the socket is required, the
|
If address information for the local end of the socket is required, the
|
getsockname(2) function should be used instead.
|
getsockname(2) function should be used instead.
|
|
|
If name does not point to enough space to hold the entire socket address,
|
If name does not point to enough space to hold the entire socket address,
|
the result will be truncated to namelen bytes.
|
the result will be truncated to namelen bytes.
|
|
|
RETURN VALUES
|
RETURN VALUES
|
If the call succeeds, a 0 is returned and namelen is set to the actual
|
If the call succeeds, a 0 is returned and namelen is set to the actual
|
size of the socket address returned in name. Otherwise, errno is set and
|
size of the socket address returned in name. Otherwise, errno is set and
|
a value of -1 is returned.
|
a value of -1 is returned.
|
|
|
ERRORS
|
ERRORS
|
On failure, errno is set to one of the following:
|
On failure, errno is set to one of the following:
|
|
|
[EBADF] The argument s is not a valid descriptor.
|
[EBADF] The argument s is not a valid descriptor.
|
|
|
[ENOTSOCK] The argument s is a file, not a socket.
|
[ENOTSOCK] The argument s is a file, not a socket.
|
|
|
[ENOTCONN] The socket is not connected.
|
[ENOTCONN] The socket is not connected.
|
|
|
[ENOBUFS] Insufficient resources were available in the system to
|
[ENOBUFS] Insufficient resources were available in the system to
|
perform the operation.
|
perform the operation.
|
|
|
[EFAULT] The name parameter points to memory not in a valid
|
[EFAULT] The name parameter points to memory not in a valid
|
part of the process address space.
|
part of the process address space.
|
|
|
SEE ALSO
|
SEE ALSO
|
accept(2), bind(2), getsockname(2), getpeereid(2), socket(2)
|
accept(2), bind(2), getsockname(2), getpeereid(2), socket(2)
|
|
|
HISTORY
|
HISTORY
|
The getpeername() function call appeared in 4.2BSD.
|
The getpeername() function call appeared in 4.2BSD.
|
|
|
BSD July 17, 1999 BSD
|
BSD July 17, 1999 BSD
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-connect.html"
|
HREF="net-common-tcpip-manpages-connect.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-getsockname.html"
|
HREF="net-common-tcpip-manpages-getsockname.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>connect</TD
|
>connect</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>getsockname</TD
|
>getsockname</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|