Zephyr Project API 4.0.0
A Scalable Open Source RTOS
|
Application network context. More...
Data Structures | |
struct | net_context |
Note that we do not store the actual source IP address in the context because the address is already set in the network interface struct. More... | |
Macros | |
#define | NET_CONTEXT_IN_USE BIT(0) |
Is this context used or not. | |
#define | NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5)) |
The address family, connection type and IP protocol are stored into a bit field to save space. | |
#define | NET_CONTEXT_TYPE (BIT(6) | BIT(7)) |
Type of the connection (datagram / stream / raw) | |
#define | NET_CONTEXT_REMOTE_ADDR_SET BIT(8) |
Remote address set. | |
#define | NET_CONTEXT_ACCEPTING_SOCK BIT(9) |
Is the socket accepting connections. | |
#define | NET_CONTEXT_CLOSING_SOCK BIT(10) |
Is the socket closing / closed. | |
#define | NET_CONTEXT_BOUND_TO_IFACE BIT(11) |
Context is bound to a specific interface. | |
#define | net_context_setup_pools(context, tx_pool, data_pool) |
Set custom network buffer pools for context send operations. | |
Typedefs | |
typedef void(* | net_context_recv_cb_t) (struct net_context *context, struct net_pkt *pkt, union net_ip_header *ip_hdr, union net_proto_header *proto_hdr, int status, void *user_data) |
Network data receive callback. | |
typedef void(* | net_context_send_cb_t) (struct net_context *context, int status, void *user_data) |
Network data send callback. | |
typedef void(* | net_tcp_accept_cb_t) (struct net_context *new_context, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data) |
Accept callback. | |
typedef void(* | net_context_connect_cb_t) (struct net_context *context, int status, void *user_data) |
Connection callback. | |
typedef struct k_mem_slab *(* | net_pkt_get_slab_func_t) (void) |
Function that is called to get the slab that is used for net_pkt allocations. | |
typedef struct net_buf_pool *(* | net_pkt_get_pool_func_t) (void) |
Function that is called to get the pool that is used for net_buf allocations. | |
typedef void(* | net_context_cb_t) (struct net_context *context, void *user_data) |
Callback used while iterating over network contexts. | |
Enumerations | |
enum | net_context_option { NET_OPT_PRIORITY = 1 , NET_OPT_TXTIME = 2 , NET_OPT_SOCKS5 = 3 , NET_OPT_RCVTIMEO = 4 , NET_OPT_SNDTIMEO = 5 , NET_OPT_RCVBUF = 6 , NET_OPT_SNDBUF = 7 , NET_OPT_DSCP_ECN = 8 , NET_OPT_REUSEADDR = 9 , NET_OPT_REUSEPORT = 10 , NET_OPT_IPV6_V6ONLY = 11 , NET_OPT_RECV_PKTINFO = 12 , NET_OPT_MCAST_TTL = 13 , NET_OPT_MCAST_HOP_LIMIT = 14 , NET_OPT_UNICAST_HOP_LIMIT = 15 , NET_OPT_TTL = 16 , NET_OPT_ADDR_PREFERENCES = 17 , NET_OPT_TIMESTAMPING = 18 } |
Network context options. More... | |
Functions | |
static bool | net_context_is_used (struct net_context *context) |
Is this context used or not. | |
static bool | net_context_is_bound_to_iface (struct net_context *context) |
Is this context bound to a network interface. | |
static bool | net_context_is_accepting (struct net_context *context) |
Is this context is accepting data now. | |
static void | net_context_set_accepting (struct net_context *context, bool accepting) |
Set this context to accept data now. | |
static bool | net_context_is_closing (struct net_context *context) |
Is this context closing. | |
static void | net_context_set_closing (struct net_context *context, bool closing) |
Set this context to closing. | |
static enum net_context_state | net_context_get_state (struct net_context *context) |
Get state for this network context. | |
static void | net_context_set_state (struct net_context *context, enum net_context_state state) |
Set state for this network context. | |
static sa_family_t | net_context_get_family (struct net_context *context) |
Get address family for this network context. | |
static void | net_context_set_family (struct net_context *context, sa_family_t family) |
Set address family for this network context. | |
static enum net_sock_type | net_context_get_type (struct net_context *context) |
Get context type for this network context. | |
static void | net_context_set_type (struct net_context *context, enum net_sock_type type) |
Set context type for this network context. | |
static void | net_context_set_can_filter_id (struct net_context *context, int filter_id) |
Set CAN filter id for this network context. | |
static int | net_context_get_can_filter_id (struct net_context *context) |
Get CAN filter id for this network context. | |
static uint16_t | net_context_get_proto (struct net_context *context) |
Get context IP protocol for this network context. | |
static void | net_context_set_proto (struct net_context *context, uint16_t proto) |
Set context IP protocol for this network context. | |
static struct net_if * | net_context_get_iface (struct net_context *context) |
Get network interface for this context. | |
static void | net_context_set_iface (struct net_context *context, struct net_if *iface) |
Set network interface for this context. | |
static void | net_context_bind_iface (struct net_context *context, struct net_if *iface) |
Bind network interface to this context. | |
static uint8_t | net_context_get_ipv4_ttl (struct net_context *context) |
Get IPv4 TTL (time-to-live) value for this context. | |
static void | net_context_set_ipv4_ttl (struct net_context *context, uint8_t ttl) |
Set IPv4 TTL (time-to-live) value for this context. | |
static uint8_t | net_context_get_ipv4_mcast_ttl (struct net_context *context) |
Get IPv4 multicast TTL (time-to-live) value for this context. | |
static void | net_context_set_ipv4_mcast_ttl (struct net_context *context, uint8_t ttl) |
Set IPv4 multicast TTL (time-to-live) value for this context. | |
static uint8_t | net_context_get_ipv6_hop_limit (struct net_context *context) |
Get IPv6 hop limit value for this context. | |
static void | net_context_set_ipv6_hop_limit (struct net_context *context, uint8_t hop_limit) |
Set IPv6 hop limit value for this context. | |
static uint8_t | net_context_get_ipv6_mcast_hop_limit (struct net_context *context) |
Get IPv6 multicast hop limit value for this context. | |
static void | net_context_set_ipv6_mcast_hop_limit (struct net_context *context, uint8_t hop_limit) |
Set IPv6 multicast hop limit value for this context. | |
static void | net_context_set_proxy_enabled (struct net_context *context, bool enable) |
Enable or disable socks proxy support for this context. | |
static bool | net_context_is_proxy_enabled (struct net_context *context) |
Is socks proxy support enabled or disabled for this context. | |
int | net_context_get (sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context) |
Get network context. | |
int | net_context_put (struct net_context *context) |
Close and unref a network context. | |
int | net_context_ref (struct net_context *context) |
Take a reference count to a net_context, preventing destruction. | |
int | net_context_unref (struct net_context *context) |
Decrement the reference count to a network context. | |
static int | net_context_create_ipv4_new (struct net_context *context, struct net_pkt *pkt, const struct in_addr *src, const struct in_addr *dst) |
Create IPv4 packet in provided net_pkt from context. | |
static int | net_context_create_ipv6_new (struct net_context *context, struct net_pkt *pkt, const struct in6_addr *src, const struct in6_addr *dst) |
Create IPv6 packet in provided net_pkt from context. | |
int | net_context_bind (struct net_context *context, const struct sockaddr *addr, socklen_t addrlen) |
Assign a socket a local address. | |
int | net_context_listen (struct net_context *context, int backlog) |
Mark the context as a listening one. | |
int | net_context_connect (struct net_context *context, const struct sockaddr *addr, socklen_t addrlen, net_context_connect_cb_t cb, k_timeout_t timeout, void *user_data) |
Create a network connection. | |
int | net_context_accept (struct net_context *context, net_tcp_accept_cb_t cb, k_timeout_t timeout, void *user_data) |
Accept a network connection attempt. | |
int | net_context_send (struct net_context *context, const void *buf, size_t len, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data) |
Send data to a peer. | |
int | net_context_sendto (struct net_context *context, const void *buf, size_t len, const struct sockaddr *dst_addr, socklen_t addrlen, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data) |
Send data to a peer specified by address. | |
int | net_context_sendmsg (struct net_context *context, const struct msghdr *msghdr, int flags, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data) |
Send data in iovec to a peer specified in msghdr struct. | |
int | net_context_recv (struct net_context *context, net_context_recv_cb_t cb, k_timeout_t timeout, void *user_data) |
Receive network data from a peer specified by context. | |
int | net_context_update_recv_wnd (struct net_context *context, int32_t delta) |
Update TCP receive window for context. | |
int | net_context_set_option (struct net_context *context, enum net_context_option option, const void *value, size_t len) |
Set an connection option for this context. | |
int | net_context_get_option (struct net_context *context, enum net_context_option option, void *value, size_t *len) |
Get connection option value for this context. | |
void | net_context_foreach (net_context_cb_t cb, void *user_data) |
Go through all the network connections and call callback for each network context. | |
bool | net_context_port_in_use (enum net_ip_protocol ip_proto, uint16_t local_port, const struct sockaddr *local_addr) |
Check if a port is in use (bound) | |
Application network context.
#define NET_CONTEXT_ACCEPTING_SOCK BIT(9) |
#include <include/zephyr/net/net_context.h>
Is the socket accepting connections.
#define NET_CONTEXT_BOUND_TO_IFACE BIT(11) |
#include <include/zephyr/net/net_context.h>
Context is bound to a specific interface.
#define NET_CONTEXT_CLOSING_SOCK BIT(10) |
#include <include/zephyr/net/net_context.h>
Is the socket closing / closed.
#include <include/zephyr/net/net_context.h>
The address family, connection type and IP protocol are stored into a bit field to save space.
Protocol family of this connection
#define NET_CONTEXT_IN_USE BIT(0) |
#include <include/zephyr/net/net_context.h>
Is this context used or not.
#define NET_CONTEXT_REMOTE_ADDR_SET BIT(8) |
#include <include/zephyr/net/net_context.h>
Remote address set.
#define net_context_setup_pools | ( | context, | |
tx_pool, | |||
data_pool | |||
) |
#include <include/zephyr/net/net_context.h>
Set custom network buffer pools for context send operations.
Set custom network buffer pools used by the IP stack to allocate network buffers used by the context when sending data to the network. Using dedicated buffers may help make send operations on a given context more reliable, e.g. not be subject to buffer starvation due to operations on other network contexts. Buffer pools are set per context, but several contexts may share the same buffers. Note that there's no support for per-context custom receive packet pools.
context | Context that will use the given net_buf pools. |
tx_pool | Pointer to the function that will return TX pool to the caller. The TX pool is used when sending data to network. There is one TX net_pkt for each network packet that is sent. |
data_pool | Pointer to the function that will return DATA pool to the caller. The DATA pool is used to store data that is sent to the network. |
#include <include/zephyr/net/net_context.h>
Type of the connection (datagram / stream / raw)
net_context_cb_t |
#include <include/zephyr/net/net_context.h>
Callback used while iterating over network contexts.
context | A valid pointer on current network context |
user_data | A valid pointer on some user data or NULL |
net_context_connect_cb_t |
#include <include/zephyr/net/net_context.h>
Connection callback.
The connect callback is called after a connection is being established. For TCP connections, this callback is called by RX thread so its stack and execution context is used here. The callback is called after the TCP connection was established or if the connection failed. Keep processing in the callback minimal to reduce the time spent blocked while handling packets. For UDP connections, this callback is called immediately by net_context_connect() function. UDP is a connectionless protocol so the connection can be thought of being established immediately.
context | The context to use. |
status | Status of the connection establishment. This is 0 if the connection was established successfully, <0 if there was an error. |
user_data | The user data given in net_context_connect() call. |
net_context_recv_cb_t |
#include <include/zephyr/net/net_context.h>
Network data receive callback.
The recv callback is called after a network data packet is received. This callback is called by RX thread so its stack and execution context is used here. Keep processing in the callback minimal to reduce the time spent blocked while handling packets.
context | The context to use. |
pkt | Network buffer that is received. If the pkt is not NULL, then the callback will own the buffer and it needs to unref the pkt as soon as it has finished working with it. On EOF, pkt will be NULL. |
ip_hdr | a pointer to relevant IP (v4 or v6) header. |
proto_hdr | a pointer to relevant protocol (udp or tcp) header. |
status | Value is set to 0 if some data or the connection is at EOF, <0 if there was an error receiving data, in this case the pkt parameter is set to NULL. |
user_data | The user data given in net_recv() call. |
net_context_send_cb_t |
#include <include/zephyr/net/net_context.h>
Network data send callback.
The send callback is called after a network data packet is sent. This callback is called by TX thread so its stack and execution context is used here. Keep processing in the callback minimal to reduce the time spent blocked while handling packets.
context | The context to use. |
status | Value is set to >= 0: amount of data that was sent, < 0 there was an error sending data. |
user_data | The user data given in net_send() call. |
net_pkt_get_pool_func_t |
#include <include/zephyr/net/net_context.h>
Function that is called to get the pool that is used for net_buf allocations.
net_pkt_get_slab_func_t |
#include <include/zephyr/net/net_context.h>
Function that is called to get the slab that is used for net_pkt allocations.
net_tcp_accept_cb_t |
#include <include/zephyr/net/net_context.h>
Accept callback.
The accept callback is called after a successful connection was established or if there was an error while we were waiting for a connection attempt. This callback is called by RX thread so its stack and execution context is used here. Keep processing in the callback minimal to reduce the time spent blocked while handling packets.
new_context | The context to use. |
addr | The peer address. |
addrlen | Length of the peer address. |
status | The status code, 0 on success, < 0 otherwise |
user_data | The user data given in net_context_accept() call. |
enum net_context_option |
#include <include/zephyr/net/net_context.h>
Network context options.
These map to BSD socket option values.
int net_context_accept | ( | struct net_context * | context, |
net_tcp_accept_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Accept a network connection attempt.
Accept a connection being established. This function will return immediately if the timeout is set to K_NO_WAIT. In this case the context will call the supplied callback when ever there is a connection established to this context. This is "a register handler and forget" type of call (async). If the timeout is set to K_FOREVER, the function will wait until the connection is established. Timeout value > 0, will wait as many ms. After the connection is established a caller-supplied callback is called. The callback is called even if timeout was set to K_FOREVER, the callback is called before this function will return in this case. The callback is not called if the timeout expires. This is similar as BSD accept() function.
context | The context to use. |
cb | Caller-supplied callback function. |
timeout | Timeout for the connection. Possible values are K_FOREVER, K_NO_WAIT, >0. |
user_data | Caller-supplied user data. |
int net_context_bind | ( | struct net_context * | context, |
const struct sockaddr * | addr, | ||
socklen_t | addrlen | ||
) |
#include <include/zephyr/net/net_context.h>
Assign a socket a local address.
This is similar as BSD bind() function.
context | The context to be assigned. |
addr | Address to assigned. |
addrlen | Length of the address. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Bind network interface to this context.
This function binds network interface to this context.
context | Network context. |
iface | Network interface. |
int net_context_connect | ( | struct net_context * | context, |
const struct sockaddr * | addr, | ||
socklen_t | addrlen, | ||
net_context_connect_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Create a network connection.
The net_context_connect function creates a network connection to the host specified by addr. After the connection is established, the user-supplied callback (cb) is executed. cb is called even if the timeout was set to K_FOREVER. cb is not called if the timeout expires. For datagram sockets (SOCK_DGRAM), this function only sets the peer address. This function is similar to the BSD connect() function.
context | The network context. |
addr | The peer address to connect to. |
addrlen | Peer address length. |
cb | Callback function. Set to NULL if not required. |
timeout | The timeout value for the connection. Possible values:
|
user_data | Data passed to the callback function. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Create IPv4 packet in provided net_pkt from context.
context | Network context for a connection |
pkt | Network packet |
src | Source address, or NULL to choose a default |
dst | Destination IPv4 address |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Create IPv6 packet in provided net_pkt from context.
context | Network context for a connection |
pkt | Network packet |
src | Source address, or NULL to choose a default from context |
dst | Destination IPv6 address |
void net_context_foreach | ( | net_context_cb_t | cb, |
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Go through all the network connections and call callback for each network context.
cb | User-supplied callback function to call. |
user_data | User specified data. |
int net_context_get | ( | sa_family_t | family, |
enum net_sock_type | type, | ||
uint16_t | ip_proto, | ||
struct net_context ** | context | ||
) |
#include <include/zephyr/net/net_context.h>
Get network context.
Network context is used to define the connection 5-tuple (protocol, remote address, remote port, source address and source port). Random free port number will be assigned to source port when context is created. This is similar as BSD socket() function. The context will be created with a reference count of 1.
family | IP address family (AF_INET or AF_INET6) |
type | Type of the socket, SOCK_STREAM or SOCK_DGRAM |
ip_proto | IP protocol, IPPROTO_UDP or IPPROTO_TCP. For raw socket access, the value is the L2 protocol value from IEEE 802.3 (see ethernet.h) |
context | The allocated context is returned to the caller. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get CAN filter id for this network context.
This function gets the CAN filter id of the context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get address family for this network context.
This function returns the address family (IPv4 or IPv6) of the context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get network interface for this context.
This function returns the used network interface.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get IPv4 multicast TTL (time-to-live) value for this context.
This function returns the IPv4 multicast TTL (time-to-live) value that is set to this context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get IPv4 TTL (time-to-live) value for this context.
This function returns the IPv4 TTL (time-to-live) value that is set to this context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get IPv6 hop limit value for this context.
This function returns the IPv6 hop limit value that is set to this context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get IPv6 multicast hop limit value for this context.
This function returns the IPv6 multicast hop limit value that is set to this context.
context | Network context. |
int net_context_get_option | ( | struct net_context * | context, |
enum net_context_option | option, | ||
void * | value, | ||
size_t * | len | ||
) |
#include <include/zephyr/net/net_context.h>
Get connection option value for this context.
context | The network context to use. |
option | Option to set |
value | Option value |
len | Option length (returned to caller) |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get context IP protocol for this network context.
This function returns the IP protocol (UDP / TCP / IEEE 802.3 protocol value) of the context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get state for this network context.
This function returns the state of the context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Get context type for this network context.
This function returns the context type (stream, datagram or raw) of the context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Is this context is accepting data now.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Is this context bound to a network interface.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Is this context closing.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Is socks proxy support enabled or disabled for this context.
This function returns current socks proxy status for this context.
context | Network context. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Is this context used or not.
context | Network context. |
int net_context_listen | ( | struct net_context * | context, |
int | backlog | ||
) |
#include <include/zephyr/net/net_context.h>
Mark the context as a listening one.
This is similar as BSD listen() function.
context | The context to use. |
backlog | The size of the pending connections backlog. |
bool net_context_port_in_use | ( | enum net_ip_protocol | ip_proto, |
uint16_t | local_port, | ||
const struct sockaddr * | local_addr | ||
) |
#include <include/zephyr/net/net_context.h>
Check if a port is in use (bound)
This function checks if a port is bound with respect to the specified ip_proto
and local_addr
.
ip_proto | the IP protocol |
local_port | the port to check |
local_addr | the network address |
int net_context_put | ( | struct net_context * | context | ) |
#include <include/zephyr/net/net_context.h>
Close and unref a network context.
This releases the context. It is not possible to send or receive data via this context after this call. This is similar as BSD shutdown() function. For legacy compatibility, this function will implicitly decrement the reference count and possibly destroy the context either now or when it reaches a final state.
context | The context to be closed. |
int net_context_recv | ( | struct net_context * | context, |
net_context_recv_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Receive network data from a peer specified by context.
This function can be used to register a callback function that is called by the network stack when network data has been received for this context. As this function registers a callback, then there is no need to call this function multiple times if timeout is set to K_NO_WAIT. If callback function or user data changes, then the function can be called multiple times to register new values. This function will return immediately if the timeout is set to K_NO_WAIT. If the timeout is set to K_FOREVER, the function will wait until the network buffer is received. Timeout value > 0 will wait as many ms. After the network buffer is received, a caller-supplied callback is called. The callback is called even if timeout was set to K_FOREVER, the callback is called before this function will return in this case. The callback is not called if the timeout expires. The timeout functionality can be compiled out if synchronous behavior is not needed. The sync call logic requires some memory that can be saved if only async way of call is used. If CONFIG_NET_CONTEXT_SYNC_RECV is not set, then the timeout parameter value is ignored. This is similar as BSD recv() function. Note that net_context_bind() should be called before net_context_recv(). Default random port number is assigned to local port. Only bind() will update connection information from context. If recv() is called before bind() call, it may refuse to bind to a context which already has a connection associated.
context | The network context to use. |
cb | Caller-supplied callback function. |
timeout | Caller-supplied timeout. Possible values are K_FOREVER, K_NO_WAIT, >0. |
user_data | Caller-supplied user data. |
int net_context_ref | ( | struct net_context * | context | ) |
#include <include/zephyr/net/net_context.h>
Take a reference count to a net_context, preventing destruction.
Network contexts are not recycled until their reference count reaches zero. Note that this does not prevent any "close" behavior that results from errors or net_context_put. It simply prevents the context from being recycled for further use.
context | The context on which to increment the reference count |
int net_context_send | ( | struct net_context * | context, |
const void * | buf, | ||
size_t | len, | ||
net_context_send_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Send data to a peer.
This function can be used to send network data to a peer connection. After the network buffer is sent, a caller-supplied callback is called. Note that the callback might be called after this function has returned. For context of type SOCK_DGRAM, the destination address must have been set by the call to net_context_connect(). This is similar as BSD send() function.
context | The network context to use. |
buf | The data buffer to send |
len | Length of the buffer |
cb | Caller-supplied callback function. |
timeout | Currently this value is not used. |
user_data | Caller-supplied user data. |
int net_context_sendmsg | ( | struct net_context * | context, |
const struct msghdr * | msghdr, | ||
int | flags, | ||
net_context_send_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Send data in iovec to a peer specified in msghdr struct.
This function has similar semantics as Posix sendmsg() call. For unconnected socket, the msg_name field in msghdr must be set. For connected socket the msg_name should be set to NULL, and msg_namelen to 0. After the network buffer is sent, a caller-supplied callback is called. Note that the callback might be called after this function has returned.
context | The network context to use. |
msghdr | The data to send |
flags | Flags for the sending. |
cb | Caller-supplied callback function. |
timeout | Currently this value is not used. |
user_data | Caller-supplied user data. |
int net_context_sendto | ( | struct net_context * | context, |
const void * | buf, | ||
size_t | len, | ||
const struct sockaddr * | dst_addr, | ||
socklen_t | addrlen, | ||
net_context_send_cb_t | cb, | ||
k_timeout_t | timeout, | ||
void * | user_data | ||
) |
#include <include/zephyr/net/net_context.h>
Send data to a peer specified by address.
This function can be used to send network data to a peer specified by address. This variant can only be used for datagram connections of type SOCK_DGRAM. After the network buffer is sent, a caller-supplied callback is called. Note that the callback might be called after this function has returned. This is similar as BSD sendto() function.
context | The network context to use. |
buf | The data buffer to send |
len | Length of the buffer |
dst_addr | Destination address. |
addrlen | Length of the address. |
cb | Caller-supplied callback function. |
timeout | Currently this value is not used. |
user_data | Caller-supplied user data. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set this context to accept data now.
context | Network context. |
accepting | True if accepting, False if not |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set CAN filter id for this network context.
This function sets the CAN filter id of the context.
context | Network context. |
filter_id | CAN filter id |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set this context to closing.
context | Network context. |
closing | True if closing, False if not |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set address family for this network context.
This function sets the address family (IPv4, IPv6 or AF_PACKET) of the context.
context | Network context. |
family | Address family (AF_INET, AF_INET6, AF_PACKET, AF_CAN) |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set network interface for this context.
This function binds network interface to this context.
context | Network context. |
iface | Network interface. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set IPv4 multicast TTL (time-to-live) value for this context.
This function sets the IPv4 multicast TTL (time-to-live) value for this context.
context | Network context. |
ttl | IPv4 multicast time-to-live value. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set IPv4 TTL (time-to-live) value for this context.
This function sets the IPv4 TTL (time-to-live) value for this context.
context | Network context. |
ttl | IPv4 time-to-live value. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set IPv6 hop limit value for this context.
This function sets the IPv6 hop limit value for this context.
context | Network context. |
hop_limit | IPv6 hop limit value. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set IPv6 multicast hop limit value for this context.
This function sets the IPv6 multicast hop limit value for this context.
context | Network context. |
hop_limit | IPv6 multicast hop limit value. |
int net_context_set_option | ( | struct net_context * | context, |
enum net_context_option | option, | ||
const void * | value, | ||
size_t | len | ||
) |
#include <include/zephyr/net/net_context.h>
Set an connection option for this context.
context | The network context to use. |
option | Option to set |
value | Option value |
len | Option length |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set context IP protocol for this network context.
This function sets the context IP protocol (UDP / TCP) of the context.
context | Network context. |
proto | Context IP protocol (IPPROTO_UDP, IPPROTO_TCP or IEEE 802.3 protocol value) |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Enable or disable socks proxy support for this context.
This function either enables or disables socks proxy support for this context.
context | Network context. |
enable | Enable socks proxy or disable it. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set state for this network context.
This function sets the state of the context.
context | Network context. |
state | New network context state. |
|
inlinestatic |
#include <include/zephyr/net/net_context.h>
Set context type for this network context.
This function sets the context type (stream or datagram) of the context.
context | Network context. |
type | Context type (SOCK_STREAM or SOCK_DGRAM) |
int net_context_unref | ( | struct net_context * | context | ) |
#include <include/zephyr/net/net_context.h>
Decrement the reference count to a network context.
Decrements the refcount. If it reaches zero, the context will be recycled. Note that this does not cause any network-visible "close" behavior (i.e. future packets to this connection may see TCP RST or ICMP port unreachable responses). See net_context_put() for that.
context | The context on which to decrement the reference count |
int net_context_update_recv_wnd | ( | struct net_context * | context, |
int32_t | delta | ||
) |
#include <include/zephyr/net/net_context.h>
Update TCP receive window for context.
This function should be used by an application which doesn't fully process incoming data in its receive callback, but for example, queues it. In this case, receive callback should decrease the window (call this function with a negative value) by the size of queued data, and function(s) which dequeue data - with positive value corresponding to the dequeued size. For example, if receive callback gets a packet with the data size of 256 and queues it, it should call this function with delta of -256. If a function extracts 10 bytes of the queued data, it should call it with delta of 10.
context | The TCP network context to use. |
delta | Size, in bytes, by which to increase TCP receive window (negative value to decrease). |