socket

Top  Previous  Next

The socket function creates a socket that is bound to a specific transport service provider.

Sockets created with the socket function are initially unnamed.

 

Syntax

int socket(

int family,

int type,

int protocol

);

 

Parameters

family

Specifies the protocol family of the created socket.

The only value supported is AF_INET which means the Internet Protocol version 4 (IPv4) address family.

 

type

The type specification for the new socket.  The following table lists the values supported:

 

Type

Meaning

SOCK_STREAM

reliable stream-oriented service (TCP)

SOCK_DGRAM

unreliable datagram service (UDP)

SOCK_RAW

raw protocols

 

protocol

The protocol to be used.  The table below lists the values supported:

 

Type

Meaning

IPPROTO_TCP

TCP protocol

IPPROTO_UDP

UDP protocol

 

Return value

If no error occurs, socket returns a descriptor referencing the new socket.  Otherwise -1 is returned and errno is set to indicate the error.