Loading...
Searching...
No Matches
gnrc_sock_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Martine Lenders <mlenders@inf.fu-berlin.de>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
19#ifndef GNRC_SOCK_INTERNAL_H
20#define GNRC_SOCK_INTERNAL_H
21
22#include <stdbool.h>
23#include <stdint.h>
24#include <string.h>
25#include "mbox.h"
26#include "net/af.h"
27#include "net/gnrc.h"
28#include "net/gnrc/netreg.h"
29#include "net/iana/portrange.h"
30#include "net/sock/ip.h"
31
32#include "sock_types.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
41#define GNRC_SOCK_DYN_PORTRANGE_MIN (IANA_DYNAMIC_PORTRANGE_MIN)
45#define GNRC_SOCK_DYN_PORTRANGE_MAX (IANA_DYNAMIC_PORTRANGE_MAX)
46
50#define GNRC_SOCK_DYN_PORTRANGE_NUM (GNRC_SOCK_DYN_PORTRANGE_MAX - GNRC_SOCK_DYN_PORTRANGE_MIN + 1)
51
56#define GNRC_SOCK_DYN_PORTRANGE_ERR (0)
57
62#ifndef CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR
63#define CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR (1)
64#endif
65
72typedef struct {
73#if IS_USED(MODULE_SOCK_AUX_LOCAL) || DOXYGEN
80#endif
81#if IS_USED(MODULE_SOCK_AUX_TIMESTAMP) || DOXYGEN
82 uint64_t *timestamp;
83#endif
84#if IS_USED(MODULE_SOCK_AUX_RSSI) || DOXYGEN
85 int16_t *rssi;
86#endif
90 uint8_t flags;
92
93#define GNRC_SOCK_RECV_AUX_FLAG_TIMESTAMP 0x01
94#define GNRC_SOCK_RECV_AUX_FLAG_RSSI 0x02
105static inline bool gnrc_af_not_supported(int af)
106{
107 /* TODO: add AF_INET support */
108 return (af != AF_INET6);
109}
110
115static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
116{
117 assert(ep != NULL);
118 const uint8_t *p = (uint8_t *)&ep->addr;
119 for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
120 if (p[i] != 0) {
121 return false;
122 }
123 }
124 return true;
125}
126
132static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
133 size_t in_size)
134{
135 memcpy(out, in, in_size);
136 if (out->netif != SOCK_ADDR_ANY_NETIF) {
137 return;
138 }
139
140 /* set interface implicitly */
141 gnrc_netif_t *netif = gnrc_netif_iter(NULL);
142 if ((netif != NULL) &&
143 (gnrc_netif_highlander() || (gnrc_netif_iter(netif) == NULL))) {
144 out->netif = netif->pid;
145 }
146}
147
152void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
153
158ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
159 sock_ip_ep_t *remote, gnrc_sock_recv_aux_t *aux);
160
166 const sock_ip_ep_t *remote, uint8_t nh);
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* GNRC_SOCK_INTERNAL_H */
Global UNIX address family definitions.
#define AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition af.h:40
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
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)
Internal helper functions for GNRC.
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:51
#define SOCK_ADDR_ANY_NETIF
Special netif ID for "any interface".
Definition sock.h:154
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:135
kernel_pid_t pid
PID of the network interface's thread.
Definition netif.h:226
Type to represent parts (either headers or payload) of a packet, called snips.
Definition pkt.h:108
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.
sock Network protocol registry info
Definition sock_types.h:90
Abstract IP end point and end point for a raw IP sock object.
Definition sock.h:178
uint16_t netif
stack-specific network interface ID
Definition sock.h:209
union sock_ip_ep_t::@383 addr
address
GNRC-specific types and function definitions.