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 
22 #ifndef GNRC_SOCK_INTERNAL_H
23 #define GNRC_SOCK_INTERNAL_H
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <string.h>
28 #include "mbox.h"
29 #include "net/af.h"
30 #include "net/gnrc.h"
31 #include "net/gnrc/netreg.h"
32 #include "net/iana/portrange.h"
33 #include "net/sock/ip.h"
34 
35 #include "sock_types.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
44 #define GNRC_SOCK_DYN_PORTRANGE_MIN (IANA_DYNAMIC_PORTRANGE_MIN)
45 
48 #define GNRC_SOCK_DYN_PORTRANGE_MAX (IANA_DYNAMIC_PORTRANGE_MAX)
49 
53 #define GNRC_SOCK_DYN_PORTRANGE_NUM (GNRC_SOCK_DYN_PORTRANGE_MAX - GNRC_SOCK_DYN_PORTRANGE_MIN + 1)
54 
59 #define GNRC_SOCK_DYN_PORTRANGE_ERR (0)
60 
67 #define GNRC_SOCK_DYN_PORTRANGE_OFF (17U)
68 
78 static inline bool gnrc_af_not_supported(int af)
79 {
80  /* TODO: add AF_INET support */
81  return (af != AF_INET6);
82 }
83 
88 static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
89 {
90  assert(ep != NULL);
91  const uint8_t *p = (uint8_t *)&ep->addr;
92  for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
93  if (p[i] != 0) {
94  return false;
95  }
96  }
97  return true;
98 }
99 
105 static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
106  size_t in_size)
107 {
108  memcpy(out, in, in_size);
109 #if GNRC_NETIF_NUMOF == 1
110  /* set interface implicitly */
111  gnrc_netif_t *netif = gnrc_netif_iter(NULL);
112 
113  if (netif != NULL) {
114  out->netif = netif->pid;
115  }
116 #endif
117 }
118 
123 void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
124 
129 ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
130  sock_ip_ep_t *remote);
131 
137  const sock_ip_ep_t *remote, uint8_t nh);
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* GNRC_SOCK_INTERNAL_H */
148 
ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout, sock_ip_ep_t *remote)
Receive a packet internally.
uint16_t netif
stack-specific network interface ID
Definition: sock.h:189
Mailbox API.
sock Network protocol registry info
Definition: sock_types.h:47
union sock_ip_ep_t::@202 addr
address
Raw IPv4/IPv6 sock definitions.
void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx)
Create a sock internally.
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:158
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.
signed int ssize_t
Used for a count of bytes or an error indication.
Definition: msp430_types.h:89
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Includes all essential GNRC network stack base modules.
internetwork address family with IPv6: UDP, TCP, etc.
Definition: af.h:38
GNRC-specific types and function definitions.
Definitions to register network protocol PIDs to use with GNRC communication interface.
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 ...
static bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
Check if end point points to any address.
kernel_pid_t pid
PID of the network interface&#39;s thread.
Definition: gnrc/netif.h:99
Representation of a network interface.
Definition: gnrc/netif.h:62
static bool gnrc_af_not_supported(int af)
Internal helper functions for GNRC.
Global UNIX address family definitions.
Type to represent parts (either headers or payload) of a packet, called snips.
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
Service Name and Transport Protocol Port Number Registry.
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.