S2OPC OPCUA Toolkit
|
A platform independent API to use sockets. More...
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "sopc_buffer.h"
#include "sopc_enums.h"
#include "sopc_raw_sockets.h"
Go to the source code of this file.
Functions | |
SOPC_Socket_AddressInfo * | SOPC_UDP_SocketAddress_Create (bool IPv6, const char *node, const char *service) |
Create a new UDP socket address using getaddrinfo. More... | |
void | SOPC_UDP_SocketAddress_Delete (SOPC_Socket_AddressInfo **addr) |
SOPC_ReturnStatus | SOPC_UDP_Socket_CreateToReceive (SOPC_Socket_AddressInfo *listenAddress, const char *interfaceName, bool setReuseAddr, bool setNonBlocking, Socket *sock) |
Create a new UDP socket and bind it. More... | |
SOPC_ReturnStatus | SOPC_UDP_Socket_CreateToSend (SOPC_Socket_AddressInfo *destAddress, const char *interfaceName, bool setNonBlocking, Socket *sock) |
Create a new UDP socket and bind it. More... | |
SOPC_ReturnStatus | SOPC_UDP_Socket_SendTo (Socket sock, const SOPC_Socket_AddressInfo *destAddr, SOPC_Buffer *buffer) |
Send data through the UDP socket to given IP address and port. More... | |
SOPC_ReturnStatus | SOPC_UDP_Socket_ReceiveFrom (Socket sock, SOPC_Buffer *buffer) |
Receive data on the UDP socket from given IP address and port. More... | |
SOPC_ReturnStatus | SOPC_UDP_Socket_Set_MulticastTTL (Socket sock, uint8_t TTL_scope) |
Set the Multicast TTL configuration value (default value is 1) Controls the live time of datagram (decremented by 1 by each router). In IPv4 multicasting is also used as threshold: More... | |
void | SOPC_UDP_Socket_Close (Socket *sock) |
Close the socket connection and/or clear the socket If the socket was automatically added to a multicast group at creation (see SOPC_UDP_Socket_CreateToReceive), then the multicast group is dropped before closing the socket. More... | |
A platform independent API to use sockets.
SOPC_Socket_AddressInfo* SOPC_UDP_SocketAddress_Create | ( | bool | IPv6, |
const char * | node, | ||
const char * | service | ||
) |
Create a new UDP socket address using getaddrinfo.
IPv6 | Flag to activate IPv6 protocol |
node | An IPv4 or IPv6 address or hostname. For default local address set to NULL. |
service | The port to use. |
void SOPC_UDP_SocketAddress_Delete | ( | SOPC_Socket_AddressInfo ** | addr | ) |
SOPC_ReturnStatus SOPC_UDP_Socket_CreateToReceive | ( | SOPC_Socket_AddressInfo * | listenAddress, |
const char * | interfaceName, | ||
bool | setReuseAddr, | ||
bool | setNonBlocking, | ||
Socket * | sock | ||
) |
Create a new UDP socket and bind it.
listenAddress | Address on which the socket shall listen for input data. If listenAddress is a multicast address, then the socket will automatically be added in a dedicated multicast group. | |
interfaceName | The name of the interface to use, or null if unspecified. The name shall be a null-terminated string if defined. | |
setReuseAddr | If value is not false (0) the socket is configured to be reused | |
setNonBlocking | If set the socket is non-blocking for reception | |
[out] | sock | Value pointed is set with the newly created socket |
SOPC_ReturnStatus SOPC_UDP_Socket_CreateToSend | ( | SOPC_Socket_AddressInfo * | destAddress, |
const char * | interfaceName, | ||
bool | setNonBlocking, | ||
Socket * | sock | ||
) |
Create a new UDP socket and bind it.
destAddress | Destination IP address, used to determine version of the protocol | |
interfaceName | The name of the interface to use, or null if unspecified. The name shall be a null-terminated string if defined. | |
setNonBlocking | If set the socket is non-blocking for sending | |
[out] | sock | Value pointed is set with the newly created socket |
SOPC_ReturnStatus SOPC_UDP_Socket_SendTo | ( | Socket | sock, |
const SOPC_Socket_AddressInfo * | destAddr, | ||
SOPC_Buffer * | buffer | ||
) |
Send data through the UDP socket to given IP address and port.
sock | The socket used for sending |
destAddr | The destination IPv4 address |
buffer | The buffer containing data to be sent. Buffer considered with buffer->position 0 and containing buffer->length bytes. |
SOPC_ReturnStatus SOPC_UDP_Socket_ReceiveFrom | ( | Socket | sock, |
SOPC_Buffer * | buffer | ||
) |
Receive data on the UDP socket from given IP address and port.
sock | The socket used for receiving |
buffer | The buffer with buffer->current_size bytes |
SOPC_ReturnStatus SOPC_UDP_Socket_Set_MulticastTTL | ( | Socket | sock, |
uint8_t | TTL_scope | ||
) |
Set the Multicast TTL configuration value (default value is 1) Controls the live time of datagram (decremented by 1 by each router). In IPv4 multicasting is also used as threshold:
sock | The socket to configure |
TTL_scope | The TTL value to set |
void SOPC_UDP_Socket_Close | ( | Socket * | sock | ) |
Close the socket connection and/or clear the socket If the socket was automatically added to a multicast group at creation (see SOPC_UDP_Socket_CreateToReceive), then the multicast group is dropped before closing the socket.
sock | The socket to disconnect and/or clear |