getpeername(2) CLIX getpeername(2)
NAME
getpeername - Gets name of connected peer
LIBRARY
Berkeley Software Distribution Library (libbsd.a)
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
int getpeername(
int s ,
struct sockaddr *name ,
int *namelen );
PARAMETERS
s Represents a socket descriptor.
name Points to a structure that is filled in with the name of the
peer upon return.
namelen Points to the actual size of the name.
DESCRIPTION
The getpeername() function returns the name of the peer connected to
socket s. The namelen parameter should be initialized to indicate the
amount of space pointed to by name. On return namelen contains the actual
size of the name returned (in bytes). The name is truncated if the buffer
provided is too small.
EXAMPLES
To get the peer of sd which is an Internet domain socket:
struct socketaddr_in sin;
int size;
if (getpeername(sd, (struct sockaddr *)&sin, &size) == -1)
perror("Getpeername failed");
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value
of -1 is returned and errno is set to indicate the error.
2/94 - Intergraph Corporation 1
getpeername(2) CLIX getpeername(2)
ERRORS
The getpeername() function fails if one or more of the following is true:
[EBADF] The descriptor is not valid.
[ENOTSOCK] The descriptor references a file, not a socket.
[ENOTCONN] The socket is not connected.
[EFAULT] The name parameter points to memory not in a valid part of
the user address space.
RELATED INFORMATION
Functions: accept(2), bind(2), socket(2), getsockname(2)
2 Intergraph Corporation - 2/94