Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
System Calls and Libraries: Sections 2 and 3 (Ref Pages Vol 3) > g

getsockname(2)

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

getsockname — get socket address

SYNOPSIS

#include <sys/socket.h>

AF_CCITT only:

#include <x25/x25addrstr.h>

int getsockname(int s, void *addr, int *addrlen);

_XOPEN_SOURCE_EXTENDED only

int getsockname(int s, struct sockaddr *addr, size_t *addrlen);

DESCRIPTION

getsockname() returns the local address of the socket indicated by s, where s is a socket descriptor. addr points to a socket address structure in which this address is returned. addrlen points to an int which should be initialized to indicate the size of the address structure. On return it contains the actual size of the address returned (in bytes). If addr does not point to enough space to contain the whole address of the socket, only the first addrlen bytes of the address are returned.

AF_CCITT only:

The x25_host[] field of the addr struct returns the X.25 addressing information of the local socket s. The x25ifname[] field of the addr struct contains the name of the local X.25 interface through which the call arrived.

RETURN VALUE

Upon successful completion, getsockname() returns 0; otherwise, it returns -1 and sets errno to indicate the error.

ERRORS

getsockname() fails if any of the following conditions are encountered:

[EBADF]

s is not a valid file descriptor.

[ENOTSOCK]

s is a valid file descriptor, but it is not a socket.

[ENOBUFS]

No buffer space is available to perform the operation.

[EFAULT]

addr or addrlen are not valid pointers.

[EINVAL]

The socket has been shut down.

[EOPNOTSUPP]

Operation not supported for AF_UNIX sockets.

FUTURE DIRECTION

The default behavior in this release is still the classic HP-UX BSD Sockets, however it will be changed to X/Open Sockets in some future release. At that time, any HP-UX BSD Sockets behavior which is incompatible with X/Open Sockets may be obsoleted. HP customers are advised to migrate their applications to conform to X/Open specification (see xopen_networking(7)).

MULTITHREAD USAGE

The getsockname() system call is safe to be called by multithreaded applications, and it is thread-safe for both POSIX Threads and DCE User Threads. It has a cancellation point. It is async-cancel safe, async-signal safe, and fork-safe.

AUTHOR

getsockname() was developed by the University of California, Berkeley.

STANDARDS CONFORMANCE

getsockname(): XPG4

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.