Google is committed to advancing racial equity for Black communities. See how.

fuchsia.posix.socket

PROTOCOLS

BaseSocket

Defined in fuchsia.posix.socket/socket.fidl

A network socket.

Once a socket has been retrieved from a Provider, this interface is then used to further configure and use the socket. This interface is essentially POSIX. Its implementation must support Linux-specific arguments to {Get,Set}SockOpt.

All methods on this type are nonblocking; their exact behaviors match their Linux counterparts.

Warning: This protocol is not yet ready for direct use by clients. Instead, clients should use the BSD sockets API to interact with sockets. We plan to change this protocol substantially and clients that couple directly to this protocol will make those changes more difficult.

Bind

Sets the local address used for the socket.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Bind_Result

Clone

Create another connection to the same remote object.

flags may be any of:

  • OPEN_RIGHT_*
  • OPEN_FLAG_APPEND
  • OPEN_FLAG_NO_REMOTE
  • OPEN_FLAG_DESCRIBE
  • CLONE_FLAG_SAME_RIGHTS

All other flags are ignored.

The OPEN_RIGHT_* bits in flags request corresponding rights over the resulting cloned object. The cloned object must have rights less than or equal to the original object. Alternatively, pass CLONE_FLAG_SAME_RIGHTS to inherit the rights on the source connection. It is invalid to pass any of the OPEN_RIGHT_* flags together with CLONE_FLAG_SAME_RIGHTS.

Request

NameType
flags uint32
object request<fuchsia.io/Node>

Close

Terminates connection with object.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

Connect

Initiates a connection to a remote address.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Connect_Result

Describe

Returns extra information about the type of the object. If the Describe operation fails, the connection is closed.

This method does not require any rights.

Request

NameType

Response

NameType
info fuchsia.io/NodeInfo

GetAttr

Acquires information about the node.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status
attributes fuchsia.io/NodeAttributes

GetPeerName

Retrieves the remote socket address.

Request

NameType

Response

NameType
result BaseSocket_GetPeerName_Result

GetSockName

Retrieves the local socket address.

Request

NameType

Response

NameType
result BaseSocket_GetSockName_Result

GetSockOpt

Retrieves the value of a socket option.

Request

NameType
level int16
optname int16

Response

NameType
result BaseSocket_GetSockOpt_Result

NodeGetFlags

Acquires the Directory.Open rights and flags used to access this file.

This method does not require any rights. This method has the same functionality as GetFlags for File and is meant as an in-progress replacement.

Request

NameType

Response

NameType
s zx/status
flags uint32

NodeSetFlags

Changes the Directory.Open flags used to access the file. Supported flags which can be turned on / off:

  • OPEN_FLAG_APPEND

This method does not require any rights. This method has the same functionality as SetFlags for File and is meant as an in-progress replacement.

Request

NameType
flags uint32

Response

NameType
s zx/status

OnOpen

An event produced eagerly by a FIDL server if requested by OPEN_FLAG_DESCRIBE.

Indicates the success or failure of the open operation, and optionally describes the object. If the status is ZX_OK, info contains descriptive information about the object (the same as would be returned by Describe).

Response

NameType
s zx/status
info fuchsia.io/NodeInfo?

SetAttr

Updates information about the node. flags may be any of NODE_ATTRIBUTE_FLAG_*.

This method requires following rights: OPEN_RIGHT_WRITABLE.

Request

NameType
flags uint32
attributes fuchsia.io/NodeAttributes

Response

NameType
s zx/status

SetSockOpt

Sets the value of a socket option.

Request

NameType
level int16
optname int16
optval sockopt

Response

NameType
result BaseSocket_SetSockOpt_Result

Sync

Synchronizes updates to the node to the underlying media, if it exists.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

DatagramSocket

Defined in fuchsia.posix.socket/socket.fidl

A datagram socket.

This type's fuchsia.io.Node/Describe method returns an eventpair which is used to signal additional information about the state of the socket such as readiness or shutdown-ness.

All methods on this type are nonblocking; their exact behaviors match their Linux counterparts.

Bind

Sets the local address used for the socket.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Bind_Result

Clone

Create another connection to the same remote object.

flags may be any of:

  • OPEN_RIGHT_*
  • OPEN_FLAG_APPEND
  • OPEN_FLAG_NO_REMOTE
  • OPEN_FLAG_DESCRIBE
  • CLONE_FLAG_SAME_RIGHTS

All other flags are ignored.

The OPEN_RIGHT_* bits in flags request corresponding rights over the resulting cloned object. The cloned object must have rights less than or equal to the original object. Alternatively, pass CLONE_FLAG_SAME_RIGHTS to inherit the rights on the source connection. It is invalid to pass any of the OPEN_RIGHT_* flags together with CLONE_FLAG_SAME_RIGHTS.

Request

NameType
flags uint32
object request<fuchsia.io/Node>

Close

Terminates connection with object.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

Connect

Initiates a connection to a remote address.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Connect_Result

Describe

Returns extra information about the type of the object. If the Describe operation fails, the connection is closed.

This method does not require any rights.

Request

NameType

Response

NameType
info fuchsia.io/NodeInfo

GetAttr

Acquires information about the node.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status
attributes fuchsia.io/NodeAttributes

GetPeerName

Retrieves the remote socket address.

Request

NameType

Response

NameType
result BaseSocket_GetPeerName_Result

GetSockName

Retrieves the local socket address.

Request

NameType

Response

NameType
result BaseSocket_GetSockName_Result

GetSockOpt

Retrieves the value of a socket option.

Request

NameType
level int16
optname int16

Response

NameType
result BaseSocket_GetSockOpt_Result

NodeGetFlags

Acquires the Directory.Open rights and flags used to access this file.

This method does not require any rights. This method has the same functionality as GetFlags for File and is meant as an in-progress replacement.

Request

NameType

Response

NameType
s zx/status
flags uint32

NodeSetFlags

Changes the Directory.Open flags used to access the file. Supported flags which can be turned on / off:

  • OPEN_FLAG_APPEND

This method does not require any rights. This method has the same functionality as SetFlags for File and is meant as an in-progress replacement.

Request

NameType
flags uint32

Response

NameType
s zx/status

OnOpen

An event produced eagerly by a FIDL server if requested by OPEN_FLAG_DESCRIBE.

Indicates the success or failure of the open operation, and optionally describes the object. If the status is ZX_OK, info contains descriptive information about the object (the same as would be returned by Describe).

Response

NameType
s zx/status
info fuchsia.io/NodeInfo?

RecvMsg

Receives a message from the socket.

Request

NameType
addr_len uint32
data_len uint32
control_len uint32
flags int16

Response

NameType
result DatagramSocket_RecvMsg_Result

SendMsg

Sends a message on the socket.

Request

NameType
addr sockaddr
data vector<vector>
control vector<uint8>
flags int16

Response

NameType
result DatagramSocket_SendMsg_Result

SendMsg2

Sends a message on the socket.

Request

NameType
addr sockaddr
data vector<uint8>
control vector<uint8>
flags int16

Response

NameType
result DatagramSocket_SendMsg2_Result

SetAttr

Updates information about the node. flags may be any of NODE_ATTRIBUTE_FLAG_*.

This method requires following rights: OPEN_RIGHT_WRITABLE.

Request

NameType
flags uint32
attributes fuchsia.io/NodeAttributes

Response

NameType
s zx/status

SetSockOpt

Sets the value of a socket option.

Request

NameType
level int16
optname int16
optval sockopt

Response

NameType
result BaseSocket_SetSockOpt_Result

Shutdown

Shuts down part of the socket.

Request

NameType
how int16

Response

NameType
result DatagramSocket_Shutdown_Result

Sync

Synchronizes updates to the node to the underlying media, if it exists.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

Provider

Defined in fuchsia.posix.socket/socket.fidl

Provider implements the POSIX sockets API.

InterfaceIndexToName

Looks up an interface by its index and returns its name. Returns ZX_ERR_NOT_FOUND if the specified index doesn't exist.

Request

NameType
index uint64

Response

NameType
result Provider_InterfaceIndexToName_Result

InterfaceNameToIndex

Looks up an interface by its name and returns its index. Returns ZX_ERR_NOT_FOUND if the specified name doesn't exist.

Request

NameType
name interface_name

Response

NameType
result Provider_InterfaceNameToIndex_Result

Socket2

Requests a socket with the specified parameters. Error values are defined in errno.h.

Request

NameType
domain int16
type int16
protocol int16

Response

NameType
result Provider_Socket2_Result

StreamSocket

Defined in fuchsia.posix.socket/socket.fidl

A stream socket.

This type's fuchsia.io.Node/Describe method returns a socket which is used to transfer data to and from the caller. Signals are used to communicate additional information about the state of the socket such as connectedness and the presence of incoming connections in the case of a listening socket.

All methods on this type are nonblocking; their exact behaviors match their Linux counterparts.

Accept

Accepts a buffered incoming connection.

Request

NameType
flags int16

Response

NameType
result StreamSocket_Accept_Result

Bind

Sets the local address used for the socket.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Bind_Result

Clone

Create another connection to the same remote object.

flags may be any of:

  • OPEN_RIGHT_*
  • OPEN_FLAG_APPEND
  • OPEN_FLAG_NO_REMOTE
  • OPEN_FLAG_DESCRIBE
  • CLONE_FLAG_SAME_RIGHTS

All other flags are ignored.

The OPEN_RIGHT_* bits in flags request corresponding rights over the resulting cloned object. The cloned object must have rights less than or equal to the original object. Alternatively, pass CLONE_FLAG_SAME_RIGHTS to inherit the rights on the source connection. It is invalid to pass any of the OPEN_RIGHT_* flags together with CLONE_FLAG_SAME_RIGHTS.

Request

NameType
flags uint32
object request<fuchsia.io/Node>

Close

Terminates connection with object.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

Connect

Initiates a connection to a remote address.

Request

NameType
addr sockaddr

Response

NameType
result BaseSocket_Connect_Result

Describe

Returns extra information about the type of the object. If the Describe operation fails, the connection is closed.

This method does not require any rights.

Request

NameType

Response

NameType
info fuchsia.io/NodeInfo

GetAttr

Acquires information about the node.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status
attributes fuchsia.io/NodeAttributes

GetPeerName

Retrieves the remote socket address.

Request

NameType

Response

NameType
result BaseSocket_GetPeerName_Result

GetSockName

Retrieves the local socket address.

Request

NameType

Response

NameType
result BaseSocket_GetSockName_Result

GetSockOpt

Retrieves the value of a socket option.

Request

NameType
level int16
optname int16

Response

NameType
result BaseSocket_GetSockOpt_Result

Listen

Begins listening for new incoming connections. At most backlog connections will be buffered.

Request

NameType
backlog int16

Response

NameType
result StreamSocket_Listen_Result

NodeGetFlags

Acquires the Directory.Open rights and flags used to access this file.

This method does not require any rights. This method has the same functionality as GetFlags for File and is meant as an in-progress replacement.

Request

NameType

Response

NameType
s zx/status
flags uint32

NodeSetFlags

Changes the Directory.Open flags used to access the file. Supported flags which can be turned on / off:

  • OPEN_FLAG_APPEND

This method does not require any rights. This method has the same functionality as SetFlags for File and is meant as an in-progress replacement.

Request

NameType
flags uint32

Response

NameType
s zx/status

OnOpen

An event produced eagerly by a FIDL server if requested by OPEN_FLAG_DESCRIBE.

Indicates the success or failure of the open operation, and optionally describes the object. If the status is ZX_OK, info contains descriptive information about the object (the same as would be returned by Describe).

Response

NameType
s zx/status
info fuchsia.io/NodeInfo?

SetAttr

Updates information about the node. flags may be any of NODE_ATTRIBUTE_FLAG_*.

This method requires following rights: OPEN_RIGHT_WRITABLE.

Request

NameType
flags uint32
attributes fuchsia.io/NodeAttributes

Response

NameType
s zx/status

SetSockOpt

Sets the value of a socket option.

Request

NameType
level int16
optname int16
optval sockopt

Response

NameType
result BaseSocket_SetSockOpt_Result

Sync

Synchronizes updates to the node to the underlying media, if it exists.

This method does not require any rights.

Request

NameType

Response

NameType
s zx/status

STRUCTS

BaseSocket_Bind_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault

BaseSocket_Connect_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault

BaseSocket_GetPeerName_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
addr sockaddr No default

BaseSocket_GetSockName_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
addr sockaddr No default

BaseSocket_GetSockOpt_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
optval sockopt No default

BaseSocket_SetSockOpt_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault

DatagramSocket_RecvMsg_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
addr sockaddr No default
data vector<uint8> No default
control vector<uint8> No default
truncated uint32 No default

DatagramSocket_SendMsg2_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
len int64 No default

DatagramSocket_SendMsg_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
len int64 No default

DatagramSocket_Shutdown_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault

Provider_InterfaceIndexToName_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
name interface_name No default

Provider_InterfaceNameToIndex_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
index uint64 No default

Provider_Socket2_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
s BaseSocket No default

StreamSocket_Accept_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault
s StreamSocket No default

StreamSocket_Listen_Response

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescriptionDefault

UNIONS

BaseSocket_Bind_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_Bind_Response
err int32

BaseSocket_Connect_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_Connect_Response
err int32

BaseSocket_GetPeerName_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_GetPeerName_Response
err int32

BaseSocket_GetSockName_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_GetSockName_Response
err int32

BaseSocket_GetSockOpt_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_GetSockOpt_Response
err int32

BaseSocket_SetSockOpt_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response BaseSocket_SetSockOpt_Response
err int32

DatagramSocket_RecvMsg_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response DatagramSocket_RecvMsg_Response
err int32

DatagramSocket_SendMsg2_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response DatagramSocket_SendMsg2_Response
err int32

DatagramSocket_SendMsg_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response DatagramSocket_SendMsg_Response
err int32

DatagramSocket_Shutdown_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response DatagramSocket_Shutdown_Response
err int32

Provider_InterfaceIndexToName_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response Provider_InterfaceIndexToName_Response
err zx/status

Provider_InterfaceNameToIndex_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response Provider_InterfaceNameToIndex_Response
err zx/status

Provider_Socket2_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response Provider_Socket2_Response
err int32

StreamSocket_Accept_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response StreamSocket_Accept_Response
err int32

StreamSocket_Listen_Result

Defined in fuchsia.posix.socket/socket.fidl

NameTypeDescription
response StreamSocket_Listen_Response
err int32

CONSTANTS

NameValueTypeDescription
INTERFACE_NAME_LENGTH 15 uint8

The maximum length of an interface name.

TYPE ALIASES

NameValueDescription
interface_name string[INTERFACE_NAME_LENGTH]

An interface name as a sequence of bytes.

sockaddr vector

Chosen to match sizeof(struct sockaddr_storage).

sockopt vector

Chosen to be large enough to hold whatever we might want to cram in it. So long as we support socket options, we don't have a good sense of what we might want to send as payload.