Loading...
Searching...
No Matches
gnrc_sock_internal.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Martine Lenders <mlenders@inf.fu-berlin.de>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
18
19#include <stdbool.h>
20#include <stdint.h>
21#include <string.h>
22#include "mbox.h"
23#include "net/af.h"
24#include "net/gnrc.h"
25#include "net/gnrc/netreg.h"
26#include "net/iana/portrange.h"
27#include "net/sock/ip.h"
28
29#include "sock_types.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
38#define GNRC_SOCK_DYN_PORTRANGE_MIN (IANA_DYNAMIC_PORTRANGE_MIN)
42#define GNRC_SOCK_DYN_PORTRANGE_MAX (IANA_DYNAMIC_PORTRANGE_MAX)
43
47#define GNRC_SOCK_DYN_PORTRANGE_NUM (GNRC_SOCK_DYN_PORTRANGE_MAX - GNRC_SOCK_DYN_PORTRANGE_MIN + 1)
48
53#define GNRC_SOCK_DYN_PORTRANGE_ERR (0)
54
59#ifndef CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR
60#define CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR (1)
61#endif
62
69typedef struct {
70#if IS_USED(MODULE_SOCK_AUX_LOCAL) || DOXYGEN
77#endif
78#if IS_USED(MODULE_SOCK_AUX_TIMESTAMP) || DOXYGEN
79 uint64_t *timestamp;
80#endif
81#if IS_USED(MODULE_SOCK_AUX_RSSI) || DOXYGEN
82 int16_t *rssi;
83#endif
87 uint8_t flags;
89
90#define GNRC_SOCK_RECV_AUX_FLAG_TIMESTAMP 0x01
91#define GNRC_SOCK_RECV_AUX_FLAG_RSSI 0x02
92
102static inline bool gnrc_af_not_supported(int af)
103{
104 /* TODO: add AF_INET support */
105 return (af != AF_INET6);
106}
107
112static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
113{
114 assert(ep != NULL);
115 const uint8_t *p = (uint8_t *)&ep->addr;
116 for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
117 if (p[i] != 0) {
118 return false;
119 }
120 }
121 return true;
122}
123
129static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
130 size_t in_size)
131{
132 memcpy(out, in, in_size);
133 if (out->netif != SOCK_ADDR_ANY_NETIF) {
134 return;
135 }
136
137 /* set interface implicitly */
138 gnrc_netif_t *netif = gnrc_netif_iter(NULL);
139 if ((netif != NULL) &&
140 (gnrc_netif_highlander() || (gnrc_netif_iter(netif) == NULL))) {
141 out->netif = netif->pid;
142 }
143}
144
149void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
150
155ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
156 sock_ip_ep_t *remote, gnrc_sock_recv_aux_t *aux);
157
163 const sock_ip_ep_t *remote, uint8_t nh);
167
168#ifdef __cplusplus
169}
170#endif
171
Global UNIX address family definitions.
#define AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition af.h:37
#define assert(cond)
abort the program if assertion is false
Definition assert.h:143
Includes all essential GNRC network stack base modules.
static bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
Check if end point points to any address.
ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local, const sock_ip_ep_t *remote, uint8_t nh)
Send a packet internally.
static bool gnrc_af_not_supported(int af)
Checks if address family is not supported.
static void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in, size_t in_size)
Initializes a sock end-point from a given and sets the network interface implicitly if there is only ...
ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout, sock_ip_ep_t *remote, gnrc_sock_recv_aux_t *aux)
Receive a packet internally.
void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx)
Create a sock internally.
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.
static bool gnrc_netif_highlander(void)
Check if there can only be one gnrc_netif_t interface.
Definition netif.h:440
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition nettype.h:48
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
struct gnrc_sock_reg gnrc_sock_reg_t
Forward declaration.
Definition sock_types.h:71
#define SOCK_ADDR_ANY_NETIF
Special netif ID for "any interface".
Definition sock.h:150
Raw IPv4/IPv6 sock definitions.
Mailbox API.
Definitions to register network protocol PIDs to use with GNRC communication interface.
Service Name and Transport Protocol Port Number Registry.
Representation of a network interface.
Definition netif.h:137
kernel_pid_t pid
PID of the network interface's thread.
Definition netif.h:225
Structure to retrieve auxiliary data from gnrc_sock_recv.
sock_ip_ep_t * local
local IP address PDU was received on
uint64_t * timestamp
timestamp PDU was received at in nanoseconds
int16_t * rssi
RSSI value of received PDU.
Abstract IP end point and end point for a raw IP sock object.
Definition sock.h:174
uint16_t netif
stack-specific network interface ID
Definition sock.h:205
union sock_ip_ep_t::@163366306165260125235131003334220031213173223254 addr
address
GNRC-specific types and function definitions.