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
64typedef struct {
65#if IS_USED(MODULE_SOCK_AUX_LOCAL) || DOXYGEN
72#endif
73#if IS_USED(MODULE_SOCK_AUX_TIMESTAMP) || DOXYGEN
74 uint64_t *timestamp;
75#endif
76#if IS_USED(MODULE_SOCK_AUX_RSSI) || DOXYGEN
77 int16_t *rssi;
78#endif
82 uint8_t flags;
84
85#define GNRC_SOCK_RECV_AUX_FLAG_TIMESTAMP 0x01
86#define GNRC_SOCK_RECV_AUX_FLAG_RSSI 0x02
97static inline bool gnrc_af_not_supported(int af)
98{
99 /* TODO: add AF_INET support */
100 return (af != AF_INET6);
101}
102
107static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
108{
109 assert(ep != NULL);
110 const uint8_t *p = (uint8_t *)&ep->addr;
111 for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
112 if (p[i] != 0) {
113 return false;
114 }
115 }
116 return true;
117}
118
124static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
125 size_t in_size)
126{
127 memcpy(out, in, in_size);
128 if (out->netif != SOCK_ADDR_ANY_NETIF) {
129 return;
130 }
131
132 /* set interface implicitly */
133 gnrc_netif_t *netif = gnrc_netif_iter(NULL);
134 if ((netif != NULL) &&
135 (gnrc_netif_highlander() || (gnrc_netif_iter(netif) == NULL))) {
136 out->netif = netif->pid;
137 }
138}
139
144void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
145
150ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
151 sock_ip_ep_t *remote, gnrc_sock_recv_aux_t *aux);
152
158 const sock_ip_ep_t *remote, uint8_t nh);
163#ifdef __cplusplus
164}
165#endif
166
167#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:137
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::@385 addr
address
GNRC-specific types and function definitions.