Jump to main content

##

# socket Function

## C

    SOCKET socket(
        int af,
        int type,
        int protocol
    );

## Description

This function creates a new BSD socket for the Microchip TCP/IP stack. The return socket descriptor is used for the subsequent BSD operations.

## Preconditions

The BerkeleySocketInit() function should be called.

## Parameters

Parameters | Description
--- | ---
af | Address family - AF_INET for IPv4 and AF_INET6 for IPv6.
type | Socket type SOCK_DGRAM or SOCK_STREAM.
protocol | IP protocol IPPROTO_UDP or IPPROTO_TCP.

## Returns

- If the function is successful, a new socket descriptor is returned.
- A return value of SOCKET_ERROR (-1) indicates an error and errno is set accordingly.

## Remarks

None.