Tinycsocket¶
Crossplatform header-only low-level socket C library.
Repository: https://gitlab.com/dosshell/tinycsocket/
Online documentation: https://tinycsocket.readthedocs.io/
Download: latest
// Put the following define in exactly one of your c/cpp files before including.
#define TINYCSOCKET_IMPLEMENTATION
#include "tinycsocket.h"
int main(int argc, const char* argv[])
{
tcs_lib_init();
TcsSocket client_socket = TCS_NULLSOCKET;
tcs_create(&client_socket, TCS_TYPE_TCP_IP4);
tcs_connect(client_socket, "example.com", 80);
uint8_t send_buffer[] = "GET / HTTP/1.1\nHost: example.com\n\n";
tcs_send(client_socket, send_buffer, sizeof(send_buffer), TCS_MSG_SENDALL, NULL);
uint8_t recv_buffer[8192] = {0};
size_t bytes_received = 0;
tcs_receive(client_socket, recv_buffer, 8192, TCS_NO_FLAGS, &bytes_received);
tcs_shutdown(client_socket, TCS_SD_BOTH);
tcs_destroy(&client_socket);
tcs_lib_free();
}
Tinycsocket is a thin cross-platform header-only low-level socket library written in C99 (with C++ compatibility).
It focuses on a minimal footprint to get crossplatform sockets, fast compilations and to be intuitive to use.
When working with sockets, you notice that almost all of the popular desktop and server operating systems implement “BSD sockets”. But the implementations differs and they have their own extensions. If you make #ifdef
for all differences (which many are non obvious), make a general error handling and implement the different poll systems… you get tinycsocket! Oh, and also add some common low-level functions outside BSD sockets, such as list all available network interfaces on your machine.
The API is a superset of the BSD sockets API with some differences. All functions return an error-code. The advantage is that the error handling is simple to understand and to handle for all platforms. The disadvantage is that the functions can not be easily integrated in expressions. Note that the TcsSocket
type is your native OS socket type. You can call any OS specific code that expects native sockets or vice versa.
This library does NOT provide any event system or any high level abstractions.
See the example folder for information of how to use tinycsocket.
Currently support platforms: - Windows NT 5.0 SP1 (Windows 2000 SP1) or newer. - POSIX.1-2001 compliant systems (Linux, FreeBSD and Solaris etc.)
Note that MacOS is currently not tested or officially supported (but it “should” work (TM)).
Installation instructions¶
The library supports both header-only and the cmake build system. When using cmake build system you do not need to define the implementation definition.
Use the header only¶
This is how I use it most of the times. Download the latest header from the include directory in this repository.
Download latest
You need to define TINYCSOCKET_IMPLEMENTATION
in exactly one translation unit (c/cpp file) before including the header file. You can put this in a separate translation unit to not pollute your namespace with OS socket symbols.
In exactly one translation unit:
#define TINYCSOCKET_IMPLEMENTATION
#include "tinycsocket.h"
In the others:
#include "tinycsocket.h"
I want to use CMake and submodules¶
If you are using a cmake project, you can add tinycsocket to your build system. Add this repo as a submodule and add tinycsocket to your CMakeLists.txt.
git submodule add https://gitlab.com/dosshell/tinycsocket.git
add_subdirectory(tinycsocket)
target_link_libraries(your_target PRIVATE tinycsocket)
You can read more about how to use submodules here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
I just want the lib files and link by my self¶
You can also build this project to get a lib directory and an include directory. Generate a build-system out of tinycsocket with cmake and build the install target. Don’t forget that if you are targeting Windows you also need to link to wsock32.lib, ws2_32.lib and iphlpapi.lib.
The following commands will create these include- and lib folders in a folder named install:
git clone https://gitlab.com/dosshell/tinycsocket.git
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:Path=../install ../tinycsocket
cmake --build . --target INSTALL --config Release
You can now remove the build directory and the tinycsocket directory if you like.
Tested platforms in CI¶
These platforms are always tested for every commit.
OS |
Compiler |
Comments |
---|---|---|
Windows 10 (1809) |
MSVC v19.26 |
WINVER=0x502 |
Windows 10 (1809) |
x86_64-w64-mingw32-gcc v9.3 |
WINVER=0x502 |
Windows 10 (1809) |
x86_64-w64-mingw32-g++ v9.3 |
WINVER=0x502 |
Windows 10 (1809) |
i686-w64-mingw32-gcc v9.3 |
WINVER=0x501 |
Windows 10 (1809) |
i686-w64-mingw32-g++ v9.3 |
WINVER=0x501 |
Windows 10 (1809) |
x86_64-w64-mingw32-gcc v9.3 |
WINVER=0x603 |
Windows 10 (1809) |
x86_64-w64-mingw32-g++ v9.3 |
WINVER=0x603 |
Windows 10 (1809) |
i686-w64-mingw32-gcc v9.3 |
WINVER=0x603 |
Windows 10 (1809) |
i686-w64-mingw32-g++ v9.3 |
WINVER=0x603 |
Linux Alpine 3.12 x86-64 |
gcc v9.3 |
|
Linux Alpine 3.12 x86-64 |
g++ v9.3 |
|
Linux Alpine 3.12 x86 |
gcc v9.3 |
|
Linux Alpine 3.12 x86 |
g++ v9.3 |
Function Reference Index¶
List of all available functions in TinyCSocket:
symbol |
description |
---|---|
Platform independent utility function to compose an IPv4 address from 4 bytes. |
|
Platform independent parsing of a string to an IPv4 address. |
|
Platform independent parsing of an IPv4 address to a string. |
|
Call this to initialize the library, eg. call this before any other function. |
|
Call this when you are done with tinycsocket lib to free resources. |
|
Creates a new socket. |
|
Creates a new socket with BSD-style options such family, type and protocol. |
|
Binds a socket to local_port on all interfaces. |
|
Binds a socket to a local address. |
|
Connect a socket to a remote hostname and port. |
|
Connects a socket to a remote address. |
|
Let a socket start listening for incoming connections. |
|
Bind a socket to a local portnumber and start listening to new connections. |
|
Accept a socket from a listening socket. |
|
Sends data on a socket, blocking. |
|
Sends data to an address, useful with UDP sockets. |
|
Receive data from a socket to your buffer. |
|
Receive data from an address, useful with UDP sockets. |
|
Create a context used for waiting on several sockets. |
|
Frees all resources bound to the pool. |
|
Add a socket to the pool. |
|
Remove a socket from the pool. |
|
Remove a socket from the pool. |
|
Set parameters on a socket. It is recommended to use tcs_set_xxx instead. |
|
Get parameters on a socket. It is recommended to use tcs_get_xxx instead. |
|
Turn off communication with a 3-way handshaking for the socket. |
|
Closes the socket, call this when you are done with the socket. |
|
Get addresses you can connect to given a computer name. |
|
Get local addresses of your computer. |
|
Constant Reference Index¶
List of all available constants in TinyCSocket:
symbol |
description |
---|---|
char* TCS_VERSION_TXT |
|
char* TCS_LICENSE_TXT |
|
struct TcsAddress TCS_ADDRESS_NULL |
|
uint32_t TCS_ADDRESS_ANY_IP4 |
|
uint32_t TCS_ADDRESS_LOOPBACK_IP4 |
|
uint32_t TCS_ADDRESS_BROADCAST_IP4 |
|
uint32_t TCS_ADDRESS_NONE_IP4 |
|
TcsSocket TCS_NULLSOCKET |
An empty socket, you should always define your new sockets to this value |
uint32_t TCS_NO_FLAGS |
|
int TCS_SOCK_STREAM |
Use for streaming types like TCP |
int TCS_SOCK_DGRAM |
Use for datagrams types like UDP |
int TCS_IPPROTO_TCP |
Use TCP protocol (use with TCS_SOCK_STREAM for normal cases) |
int TCS_IPPROTO_UDP |
Use UDP protocol (use with TCS_SOCK_DGRAM for normal cases) |
uint32_t TCS_AI_PASSIVE |
Use this flag for pure listening sockets |
uint32_t TCS_MSG_PEEK |
|
uint32_t TCS_MSG_OOB |
|
uint32_t TCS_MSG_WAITALL |
|
uint32_t TCS_MSG_SENDALL |
|
int TCS_BACKLOG_SOMAXCONN |
Max number of queued sockets when listening |
int TCS_SOL_SOCKET |
Socket option level for socket options |
int TCS_SOL_IP |
IP option level for socket options |
int TCS_SO_BROADCAST |
|
int TCS_SO_KEEPALIVE |
|
int TCS_SO_LINGER |
|
int TCS_SO_REUSEADDR |
This is a tricky one for crossplatform independency! |
int TCS_SO_RCVBUF |
Byte size of receiving buffer |
int TCS_SO_RCVTIMEO |
|
int TCS_SO_SNDBUF |
Byte size of receiving buffer |
int TCS_SO_OOBINLINE |
|
int TCS_SO_IP_NODELAY |
|
int TCS_SO_IP_MEMBERSHIP_ADD |
|
int TCS_SO_IP_MEMBERSHIP_DROP |
|
int TCS_SO_IP_MULTICAST_LOOP |
|
int TCS_INF |
|
struct TcsPollEvent TCS_NULLEVENT |
Reference Details¶
This section contains details of all functions. Note that this is also available in source code as doxygen comments.
tcs_util_ipv4_args¶
Platform independent utility function to compose an IPv4 address from 4 bytes.
TcsReturnCode tcs_util_ipv4_args(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint32_t *out_address)
Parameters:
type |
name |
description |
---|---|---|
uint8_t |
a |
Is the first byte |
uint8_t |
b |
Is the second byte |
uint8_t |
c |
Is the third byte |
uint8_t |
d |
Is the forth byte |
uint32_t * |
out_address |
is your ipv4 address stored as an unsigned 32bit integer. This parameter can not be NULL. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_util_string_to_address¶
Platform independent parsing of a string to an IPv4 address.
TcsReturnCode tcs_util_string_to_address(const char str[], struct TcsAddress *out_address)
Parameters:
type |
name |
description |
---|---|---|
const char |
str |
is a valid pointer to an IPv4 NULL terminated string address, with optional local_port number. Such as “192.168.0.1:1212”. |
struct TcsAddress * |
out_address |
out pointer to save address. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_util_address_to_string¶
Platform independent parsing of an IPv4 address to a string.
TcsReturnCode tcs_util_address_to_string(const struct TcsAddress *address, char out_str[40])
Parameters:
type |
name |
description |
---|---|---|
const struct TcsAddress * |
address |
|
char |
out_str |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_lib_init¶
Call this to initialize the library, eg. call this before any other function.
TcsReturnCode tcs_lib_init(void)
Parameters:
type |
name |
description |
---|---|---|
void |
None |
None |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_lib_free¶
Call this when you are done with tinycsocket lib to free resources.
TcsReturnCode tcs_lib_free(void)
Parameters:
type |
name |
description |
---|---|---|
void |
None |
None |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_create¶
Creates a new socket.
TcsReturnCode tcs_create(TcsSocket *socket_ctx, TcsType socket_type)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket * |
socket_ctx |
is your in-out pointer to the socket context, you must initialize the socket to TCS_NULLSOCKET before use. |
TcsType |
socket_type |
specifies the internet and transport layer, for example TCS_TYPE_TCP_IP4 or TCS_TYPE_UDP_IP6. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_destroy()
tcs_lib_init()
tcs_create_ext¶
Creates a new socket with BSD-style options such family, type and protocol.
TcsReturnCode tcs_create_ext(TcsSocket *socket_ctx, TcsAddressFamily family, int type, int protocol)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket * |
socket_ctx |
is your in-out pointer to the socket context, you must initialize the socket to TCS_NULLSOCKET before use. |
TcsAddressFamily |
family |
only supports TCS_AF_IP4 for now. |
int |
type |
specifies the type of the socket, for example TCS_SOCK_STREAM or TCS_SOCK_DGRAM. |
int |
protocol |
specifies the protocol, for example TCS_IPPROTO_TCP or TCS_IPPROTO_UDP. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_destroy()
tcs_lib_init()
tcs_bind¶
Binds a socket to local_port on all interfaces.
TcsReturnCode tcs_bind(TcsSocket socket_ctx, uint16_t local_port)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context you want bind. |
uint16_t |
local_port |
is your local portnumber you want to bind to. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_bind_address()
tcs_listen()
tcs_bind_address¶
Binds a socket to a local address.
TcsReturnCode tcs_bind_address(TcsSocket socket_ctx, const struct TcsAddress *local_address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context you want to bind. |
const struct TcsAddress * |
local_address |
is your local address you want to bind to. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_bind()
tcs_get_interfaces()
tcs_listen()
tcs_connect¶
Connect a socket to a remote hostname and port.
TcsReturnCode tcs_connect(TcsSocket socket_ctx, const char *hostname, uint16_t port)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context you want to connect. |
const char * |
hostname |
name of host or ip |
uint16_t |
port |
to connect to |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_bind()
tcs_get_interfaces()
tcs_listen()
tcs_connect_address¶
Connects a socket to a remote address.
TcsReturnCode tcs_connect_address(TcsSocket socket_ctx, const struct TcsAddress *address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
const struct TcsAddress * |
address |
is the remote address to connect to. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_shutdown()
tcs_listen¶
Let a socket start listening for incoming connections.
TcsReturnCode tcs_listen(TcsSocket socket_ctx, int backlog)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
int |
backlog |
is the maximum number of queued incoming sockets. Use TCS_BACKLOG_SOMAXCONN to set it to max. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_accept()
tcs_listen_to¶
Bind a socket to a local portnumber and start listening to new connections.
TcsReturnCode tcs_listen_to(TcsSocket socket_ctx, uint16_t local_port)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
uint16_t |
local_port |
None |
Returns:
<documentation is not available>
tcs_accept¶
Accept a socket from a listening socket.
TcsReturnCode tcs_accept(TcsSocket socket_ctx, TcsSocket *child_socket_ctx, struct TcsAddress *address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your listening socket you used when you called tcs_listen_to(). |
TcsSocket * |
child_socket_ctx |
is your accepted socket. Must have the in value of TCS_NULLSOCKET. |
struct TcsAddress * |
address |
is an optional pointer to a buffer where the remote address of the accepted socket can be stored. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_send¶
Sends data on a socket, blocking.
TcsReturnCode tcs_send(TcsSocket socket_ctx, const uint8_t *buffer, size_t buffer_size, uint32_t flags, size_t *bytes_sent)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
const uint8_t * |
buffer |
is a pointer to your data you want to send. |
size_t |
buffer_size |
is number of bytes of the data you want to send. |
uint32_t |
flags |
is currently not in use. |
size_t * |
bytes_sent |
is how many bytes that was successfully sent. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_receive()
tcs_send_to¶
Sends data to an address, useful with UDP sockets.
TcsReturnCode tcs_send_to(TcsSocket socket_ctx, const uint8_t *buffer, size_t buffer_size, uint32_t flags, const struct TcsAddress *destination_address, size_t *bytes_sent)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
const uint8_t * |
buffer |
is a pointer to your data you want to send. |
size_t |
buffer_size |
is number of bytes of the data you want to send. |
uint32_t |
flags |
is currently not in use. |
const struct TcsAddress * |
destination_address |
is the address to send to. |
size_t * |
bytes_sent |
is how many bytes that was successfully sent. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_receive_from()
tcs_getaddrinfo()
tcs_receive¶
Receive data from a socket to your buffer.
TcsReturnCode tcs_receive(TcsSocket socket_ctx, uint8_t *buffer, size_t buffer_size, uint32_t flags, size_t *bytes_received)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
uint8_t * |
buffer |
is a pointer to your buffer where you want to store the incoming data to. |
size_t |
buffer_size |
is the byte size of your buffer, for preventing overflows. |
uint32_t |
flags |
is currently not in use. |
size_t * |
bytes_received |
is how many bytes that was successfully written to your buffer. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_send()
tcs_receive_from¶
Receive data from an address, useful with UDP sockets.
TcsReturnCode tcs_receive_from(TcsSocket socket_ctx, uint8_t *buffer, size_t buffer_size, uint32_t flags, struct TcsAddress *source_address, size_t *bytes_received)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
uint8_t * |
buffer |
is a pointer to your buffer where you want to store the incoming data to. |
size_t |
buffer_size |
is the byte size of your buffer, for preventing overflows. |
uint32_t |
flags |
is currently not in use. |
struct TcsAddress * |
source_address |
is the address to receive from. |
size_t * |
bytes_received |
is how many bytes that was successfully written to your buffer. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_send_to()
tcs_getaddrinfo()
tcs_pool_create¶
Create a context used for waiting on several sockets.
TcsReturnCode tcs_pool_create(struct TcsPool **pool)
Parameters:
type |
name |
description |
---|---|---|
struct TcsPool ** |
pool |
is your out pool context pointer. Initiate a TcsPool pointer to NULL and use the address of this pointer. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_pool_destory()
tcs_pool_destory¶
Frees all resources bound to the pool.
TcsReturnCode tcs_pool_destory(struct TcsPool **pool)
Parameters:
type |
name |
description |
---|---|---|
struct TcsPool ** |
pool |
is your in-out pool context pointer created with tcs_pool_create() |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_pool_create()
tcs_pool_add¶
Add a socket to the pool.
TcsReturnCode tcs_pool_add(struct TcsPool *pool, TcsSocket socket_ctx, void *user_data, bool poll_can_read, bool poll_can_write, bool poll_error)
Parameters:
type |
name |
description |
---|---|---|
struct TcsPool * |
pool |
is your in-out pool context pointer created with tcs_pool_create() |
TcsSocket |
socket_ctx |
will be added to the pool. Note that you can still use it outside of the pool. |
void * |
user_data |
is a pointer of your choice that is associated with the socket. Use NULL if not used. |
bool |
poll_can_read |
true if you want to poll socket_ctx for to be able to read. |
bool |
poll_can_write |
true if you want to poll socket_ctx for to be able to write. |
bool |
poll_error |
true if you want to poll if any error has happened to socket_ctx. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_pool_remove()
tcs_pool_remove¶
Remove a socket from the pool.
TcsReturnCode tcs_pool_remove(struct TcsPool *pool, TcsSocket socket_ctx)
Parameters:
type |
name |
description |
---|---|---|
struct TcsPool * |
pool |
is a context pointer created with tcs_pool_create() |
TcsSocket |
socket_ctx |
will be removed from the pool. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_pool_remove()
tcs_pool_poll¶
Remove a socket from the pool.
TcsReturnCode tcs_pool_poll(struct TcsPool *pool, struct TcsPollEvent *events, size_t events_count, size_t *events_populated, int64_t timeout_in_ms)
Parameters:
type |
name |
description |
---|---|---|
struct TcsPool * |
pool |
is your in-out pool context pointer created with tcs_pool_create(). |
struct TcsPollEvent * |
events |
is an array with in-out events. Assign each element to TCS_NULLEVENT. |
size_t |
events_count |
number of in elements in your events array. Does not make sense to have more events than number of sockets int the pool. If to short, all events may not be returned. |
size_t * |
events_populated |
will contain the number of events the parameter ev has been populated with by the call. |
int64_t |
timeout_in_ms |
is the maximum wait time for any event. If any event happens before this time, the call will return immediately. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
See Also:
tcs_pool_remove()
tcs_set_option¶
Set parameters on a socket. It is recommended to use tcs_set_xxx instead.
TcsReturnCode tcs_set_option(TcsSocket socket_ctx, int32_t level, int32_t option_name, const void *option_value, size_t option_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
int32_t |
level |
is the definition level. |
int32_t |
option_name |
is the option name. |
const void * |
option_value |
is a pointer to the option value. |
size_t |
option_size |
is the byte size of the data pointed by option_value. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_get_option¶
Get parameters on a socket. It is recommended to use tcs_get_xxx instead.
TcsReturnCode tcs_get_option(TcsSocket socket_ctx, int32_t level, int32_t option_name, void *option_value, size_t *option_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
int32_t |
level |
is the definition level. |
int32_t |
option_name |
is the option name. |
void * |
option_value |
is a pointer to the option value. |
size_t * |
option_size |
is a pointer the byte size of the data pointed by option_value. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_shutdown¶
Turn off communication with a 3-way handshaking for the socket.
TcsReturnCode tcs_shutdown(TcsSocket socket_ctx, TcsSocketDirection direction)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
is your in-out socket context. |
TcsSocketDirection |
direction |
defines in which direction you want to turn off the communication. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_destroy¶
Closes the socket, call this when you are done with the socket.
TcsReturnCode tcs_destroy(TcsSocket *socket_ctx)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket * |
socket_ctx |
is your in-out socket context. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_resolve_hostname¶
Get addresses you can connect to given a computer name.
TcsReturnCode tcs_resolve_hostname(const char *hostname, TcsAddressFamily address_family, struct TcsAddress found_addresses[], size_t found_addresses_max_length, size_t *no_of_found_addresses)
Parameters:
type |
name |
description |
---|---|---|
const char * |
hostname |
null terminated string |
TcsAddressFamily |
address_family |
filters which address family you want, for example if you only are interested in IPv6. Use TCS_AF_ANY to not filter. |
struct TcsAddress |
found_addresses |
is a pointer to your array which will be populated with found addresses. |
size_t |
found_addresses_max_length |
is number of elements your found_addresses array can store. |
size_t * |
no_of_found_addresses |
will output the number of addresses that was populated in found_addresses. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_local_interfaces¶
Get local addresses of your computer.
TcsReturnCode tcs_local_interfaces(struct TcsInterface found_interfaces[], size_t found_interfaces_length, size_t *no_of_found_interfaces)
Parameters:
type |
name |
description |
---|---|---|
struct TcsInterface |
found_interfaces |
is a pointer to your array which will be populated with found interfaces. |
size_t |
found_interfaces_length |
is number of elements your found_interfaces array can store. |
size_t * |
no_of_found_interfaces |
will output the number of addresses that was populated in found_interfaces. |
Returns:
TCS_SUCCESS if successful, otherwise the error code.
tcs_set_broadcast¶
TcsReturnCode tcs_set_broadcast(TcsSocket socket_ctx, bool do_allow_broadcast)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
do_allow_broadcast |
None |
Returns:
<documentation is not available>
tcs_get_broadcast¶
TcsReturnCode tcs_get_broadcast(TcsSocket socket_ctx, bool *is_broadcast_allowed)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
is_broadcast_allowed |
None |
Returns:
<documentation is not available>
tcs_set_keep_alive¶
TcsReturnCode tcs_set_keep_alive(TcsSocket socket_ctx, bool do_keep_alive)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
do_keep_alive |
None |
Returns:
<documentation is not available>
tcs_get_keep_alive¶
TcsReturnCode tcs_get_keep_alive(TcsSocket socket_ctx, bool *is_keep_alive_enabled)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
is_keep_alive_enabled |
None |
Returns:
<documentation is not available>
tcs_set_reuse_address¶
TcsReturnCode tcs_set_reuse_address(TcsSocket socket_ctx, bool do_allow_reuse_address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
do_allow_reuse_address |
None |
Returns:
<documentation is not available>
tcs_get_reuse_address¶
TcsReturnCode tcs_get_reuse_address(TcsSocket socket_ctx, bool *is_reuse_address_allowed)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
is_reuse_address_allowed |
None |
Returns:
<documentation is not available>
tcs_set_send_buffer_size¶
TcsReturnCode tcs_set_send_buffer_size(TcsSocket socket_ctx, size_t send_buffer_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
size_t |
send_buffer_size |
None |
Returns:
<documentation is not available>
tcs_get_send_buffer_size¶
TcsReturnCode tcs_get_send_buffer_size(TcsSocket socket_ctx, size_t *send_buffer_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
size_t * |
send_buffer_size |
None |
Returns:
<documentation is not available>
tcs_set_receive_buffer_size¶
TcsReturnCode tcs_set_receive_buffer_size(TcsSocket socket_ctx, size_t receive_buffer_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
size_t |
receive_buffer_size |
None |
Returns:
<documentation is not available>
tcs_get_receive_buffer_size¶
TcsReturnCode tcs_get_receive_buffer_size(TcsSocket socket_ctx, size_t *receive_buffer_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
size_t * |
receive_buffer_size |
None |
Returns:
<documentation is not available>
tcs_set_receive_timeout¶
TcsReturnCode tcs_set_receive_timeout(TcsSocket socket_ctx, int timeout_ms)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
int |
timeout_ms |
None |
Returns:
<documentation is not available>
tcs_get_receive_timeout¶
TcsReturnCode tcs_get_receive_timeout(TcsSocket socket_ctx, int *timeout_ms)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
int * |
timeout_ms |
None |
Returns:
<documentation is not available>
tcs_set_linger¶
TcsReturnCode tcs_set_linger(TcsSocket socket_ctx, bool do_linger, int timeout_seconds)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
do_linger |
None |
int |
timeout_seconds |
None |
Returns:
<documentation is not available>
tcs_get_linger¶
TcsReturnCode tcs_get_linger(TcsSocket socket_ctx, bool *do_linger, int *timeout_seconds)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
do_linger |
None |
int * |
timeout_seconds |
None |
Returns:
<documentation is not available>
tcs_set_ip_no_delay¶
TcsReturnCode tcs_set_ip_no_delay(TcsSocket socket_ctx, bool use_no_delay)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
use_no_delay |
None |
Returns:
<documentation is not available>
tcs_get_ip_no_delay¶
TcsReturnCode tcs_get_ip_no_delay(TcsSocket socket_ctx, bool *is_no_delay_used)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
is_no_delay_used |
None |
Returns:
<documentation is not available>
tcs_set_out_of_band_inline¶
TcsReturnCode tcs_set_out_of_band_inline(TcsSocket socket_ctx, bool enable_oob)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool |
enable_oob |
None |
Returns:
<documentation is not available>
tcs_get_out_of_band_inline¶
TcsReturnCode tcs_get_out_of_band_inline(TcsSocket socket_ctx, bool *is_oob_enabled)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
bool * |
is_oob_enabled |
None |
Returns:
<documentation is not available>
tcs_set_ip_multicast_add¶
TcsReturnCode tcs_set_ip_multicast_add(TcsSocket socket_ctx, const struct TcsAddress *local_address, const struct TcsAddress *multicast_address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
const struct TcsAddress * |
local_address |
None |
const struct TcsAddress * |
multicast_address |
None |
Returns:
<documentation is not available>
tcs_set_ip_multicast_drop¶
TcsReturnCode tcs_set_ip_multicast_drop(TcsSocket socket_ctx, const struct TcsAddress *local_address, const struct TcsAddress *multicast_address)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
const struct TcsAddress * |
local_address |
None |
const struct TcsAddress * |
multicast_address |
None |
Returns:
<documentation is not available>
tcs_receive_netstring¶
TcsReturnCode tcs_receive_netstring(TcsSocket socket_ctx, uint8_t *buffer, size_t buffer_size, size_t *bytes_received)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
uint8_t * |
buffer |
None |
size_t |
buffer_size |
None |
size_t * |
bytes_received |
None |
Returns:
<documentation is not available>
tcs_send_netstring¶
TcsReturnCode tcs_send_netstring(TcsSocket socket_ctx, const uint8_t *buffer, size_t buffer_size)
Parameters:
type |
name |
description |
---|---|---|
TcsSocket |
socket_ctx |
None |
const uint8_t * |
buffer |
None |
size_t |
buffer_size |
None |
Returns:
<documentation is not available>