getsockname

Returns the name associated with a socket.

Format

#include  <socket.h>

int getsockname  (int s, struct sockaddr *name,
                 int *namelen);
Routine Variants This socket routine has a variant named __bsd44_getsockname. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.

Arguments

s
A socket descriptor created with socket and bound to the socket name with bind.
name
A pointer to the buffer in which getsockname should return the socket name.
namelen
A pointer to an integer specifying the size of the buffer pointed to by name. On return, the integer contains the actual size of the name returned, in bytes.

Description

This routine returns the current name for the specified socket descriptor. The name is a format specific to the address family (AF_ INET) assigned to the socket.

bind makes the association of the name to the socket, not getsockname.

See also bind and socket in this appendix.

Return Values
Indicates success. 
-1  Indicates an error; errno is set to one of the following:

  • EBADF - The descriptor is invalid.

  • ENOTSOCK - The socket descriptor references a file, not a socket.

  • ENOBUFS - Resources were insufficient in the system to perform the operation.

  • EFAULT - The name parameter is not a valid part of the user address space.
 


Previous Page | Next Page | Table of Contents | Index