Socket Native¶
| Spice | |
|---|---|
Functions¶
getNativeAddressFamily¶
| Spice | |
|---|---|
Returns the address family constant (AF_INET or AF_INET6) of the given address
Parameters
| Name | Type | Description |
|---|---|---|
address |
const IpAddress& |
IP address |
Returns: int — Address family
openNativeSocket¶
| Spice | |
|---|---|
Opens a socket of the family of the given address and connects it to the given address and port. For a datagram socket, connecting only fixes the peer, so that plain reads and writes can be used and the kernel drops datagrams from any other sender.
Parameters
| Name | Type | Description |
|---|---|---|
address |
const IpAddress& |
Address to connect to |
port |
unsigned short |
Port to connect to |
socketType |
int |
SOCK_STREAM or SOCK_DGRAM |
timeoutMs |
unsigned long |
Timeout for the single reads and writes on the socket in milliseconds, 0 for none |
Returns: Result<int> — File descriptor of the connected socket
setNativeSocketTimeout¶
| Spice | |
|---|---|
Limits how long a single read or write on the given socket may block
Parameters
| Name | Type | Description |
|---|---|---|
sockFd |
int |
Socket file descriptor |
timeoutMs |
unsigned long |
Timeout in milliseconds, 0 to block indefinitely |
Returns: bool — Setting the timeout was successful or not
fillNativeRandomBytes¶
| Spice | |
|---|---|
Fills the given buffer with random bytes from the kernel, that are fit for values an attacker must not be able to predict (like the IDs of DNS queries)
Parameters
| Name | Type | Description |
|---|---|---|
buffer |
byte* |
Buffer to fill |
size |
unsigned long |
Number of bytes to fill |
Returns: bool — Filling the buffer was successful or not
readNativeSocket¶
| Spice | |
|---|---|
Reads from the given socket. Blocks until data arrives, the timeout of the socket expires or the connection breaks.
Parameters
| Name | Type | Description |
|---|---|---|
sockFd |
int |
Socket file descriptor |
buffer |
byte* |
Buffer to read into |
size |
unsigned long |
Size of the buffer |
Returns: long — Number of bytes read, 0 or less on timeout, error or end of the connection
writeNativeSocket¶
| Spice | |
|---|---|
Writes to the given socket. A single call may write only a part of the buffer.
Parameters
| Name | Type | Description |
|---|---|---|
sockFd |
int |
Socket file descriptor |
buffer |
byte* |
Buffer to write |
size |
unsigned long |
Number of bytes to write |
Returns: long — Number of bytes written, 0 or less on timeout or error
closeNativeSocket¶
| Spice | |
|---|---|
Closes the given socket
Parameters
| Name | Type | Description |
|---|---|---|
sockFd |
int |
Socket file descriptor |
getNativeHostsFilePath¶
| Spice | |
|---|---|
Returns the path of the hosts file of the system
Returns: String — Path of the hosts file
readNativeResolverConfig¶
| Spice | |
|---|---|
Reads the resolver configuration of the system in the format of resolv.conf(5)
Returns: Result<String> — Content of /etc/resolv.conf
getNativeMonotonicMillis¶
| Spice | |
|---|---|
Returns the time of a monotonic clock, that is not affected by changes of the system time. Only the difference between two values has a meaning.
Returns: long — Monotonic time in milliseconds