Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Overview of SOCKETS(POSIX) functions

&pagelevel(3)&pagelevel

The following overview of the SOCKETS interface functions collects several functions together into task-oriented groups. The columns IPv4 and IPv6 indicate the address family (AF_INET and/or AF_INET6) in which the function involved is supported.

Function

DescriptionIPv4IPv6

Setting up and shutting down connections over sockets

socket()

Create socket

x

x

bind()

Assign a name to a socket

x

x

connect()

Initiate a connection over a socket

x

x

listen()

Test socket for pending connections

x

x

accept()

Accept connection over a socket

x

x

close()

Close socket

x

x

shutdown()

Close full duplex connection

x

x

socketpair()

Create a pair of connected sockets

x


Transferring data between two sockets

read(), readv()

Receive a message from a connected socket

x

x

recv()

Receive a message from a connected socket

x

x

recvfrom()

Receive a message from a socket

x

x

recvmsg()

Receive a message from a socket

x

x

send()

Send a message from socket to socket over a connection

x

x

sendto()

Send a message from socket to socket

x

x

sendmsg()

Send a message from socket to socket

x

x

write(), writev()

Send a message from socket to socket over a connection

x

x

poll()

Multiplex input/output

x

x

select()

Multiplex input/output

x

x

Receiving information about sockets

getsockopt()

Get socket options

x

x

setsockopt()

Set socket options

x

x

getpeername()

Get name of communications partner

x

x

getsockname()

Get name of socket

x

x

Test configuration values

gai_strerror()

Get description of a getaddrinfo() error code

x

x

getaddrinfo()

Get information about host name, host address and services

x

x

gethostbyaddr()

Get names of reachable hosts

x


gethostbyname()

Get addresses of reachable hosts

x


gethostname()

Get name of current host

x

x

getipnodebyaddr()

Get host name belonging to an IPv4 or IPv6 address

x

x

getipnodebyname()

Get IPv4 or IPv6 addresses belonging to a host name

x

x

getnameinfo()

Get host and service name corresponding to IP address and port number

x

x

getnetbyaddr()

Get name of a net

x

x

getnetbyname()

Get net address

x

x

getprotobyname()

Get number of a protocol

x

x

getprotobynumber()

Get name of a protocol

x

x

getservbyname()

Get port number of a service

x

x

getservbyport()

Get name of a service

x

x

sethostent()

Open host database

x

x

gethostent()

Read entry from host database

x

x

endhostent()

Close host database

x

x

setnetent()

Open network database

x

x

getnetent()

Read entry from network database

x

x

endnetent()

Close network database

x

x

setprotoent()

Open protocol database

x

x

getprotoent()

Read entry from protocol database

x

x

endprotoent()

Close protocol database

x

x

setservent()

Open services database

x

x

getservent()

Read entry from services database

x

x

endservent()

Close services database

x

x

Manipulate Internet address

inet_addr()

Convert character string from dotted notation to integer value (Internet address)

x


inet_network()

Convert character string from dotted notation to integer value (subnetwork section)

x


inet_makeaddr()

Create Internet address from subnetwork section and subnetwork local address section

x


inet_lnaof()

Extract local network address in byte order of host from Internet host address

x


inet_netof()

Extract network number in byte order of host from Internet host address

x


inet_ntoa()

Convert Internet host address into a string conforming to normal Internet dotted notation

x


inet_pton()

Converts an IP address in dotted or colon notation to the corresponding binary address

x

x

inet_ntop()

Converts a binary IP address to dotted or colon notation

x

x

Utility functions

freeaddrinfo()

Release memory area for an addrinfo structure

x

x

freehostent()

Release memory area for a hostent structure

x

x

htonl()

Convert 32-bit fields from host to network byte order

x


htons()

Convert 16-bit fields from host to network byte order

x

x

ntohl()

Convert 32-bit fields from network to host byte order

x


ntohs()

Convert 16-bit fields from network to host byte order

x

x

Control functions

fcntl()

Control sockets

x

x

ioctl()

Control sockets

x

x

Test macros for AF_INET6

The following test macros for the AF_INET6 address family are defined in <netinet/in.h>.

The parameters p, p1 and p2 are in6_addr structures.

Function

Description

IN6_IS_ADDR_UNSPECIFIED (p)

IPv6 address = unspecified (0) ?

IN6_IS_ADDR_LOOPBACK (p)

IPv6 address = loopback ?

IN6_IS_ADDR_LINKLOCAL (p)

IPv6 address = linklocal ?

IN6_IS_ADDR_SITELOCAL (p)

IPv6 address = sitelocal ?

IN6_IS_ADDR_V4MAPPED (p)

IPv6 address = IPv4-mapped ?

IN6_IS_ADDR_V4COMPAT (p)

IPv6 address = IPv4-compatible ?

IN6_ARE_ADDR_EQUAL (p1, p2)

IPv6 address1 = IPv6 address2 ?