getsockname

Returns the current name of a socket.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <sys/socket.h> 
     
  int getsockname (
     int                s,
     struct sockaddr   *addr,
     size_t            *len);
  

Parameters

s

(IN) Specifies the socket file handle connected to the peer for which the name is to be returned.

addr

(OUT) Points to the location of the name for the peer connected to the socket. For IPv4, addr points to a sockaddr structure; for IPv6, to a sockaddr_in6 structure. The first two bytes in the structures identify the protocol family, and hence the structure.

len

(OUT) Points to the size of the name pointed to by addr.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The socket parameter is not a valid socket file handle.

38

ENOTSOCK

The socket parameter is not a valid socket file handle.

45

EOPNOTSUPP

The operation is not supported by this socket's protocol.

55

ENOBUFS

Insufficient resources were available in the system to perform the operation.

57

ENOTCONN

The socket is not connected.

See Also