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
35 extern "C" {
36 #endif
37 
41 #define GNRC_SOCK_DYN_PORTRANGE_MIN (IANA_DYNAMIC_PORTRANGE_MIN)
42 
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 
64 #define GNRC_SOCK_DYN_PORTRANGE_OFF (17U)
65 
75 static inline bool gnrc_af_not_supported(int af)
76 {
77  /* TODO: add AF_INET support */
78  return (af != AF_INET6);
79 }
80 
85 static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
86 {
87  assert(ep != NULL);
88  const uint8_t *p = (uint8_t *)&ep->addr;
89  for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
90  if (p[i] != 0) {
91  return false;
92  }
93  }
94  return true;
95 }
96 
102 static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
103  size_t in_size)
104 {
105  memcpy(out, in, in_size);
106 #if GNRC_NETIF_NUMOF == 1
107  /* set interface implicitly */
108  gnrc_netif_t *netif = gnrc_netif_iter(NULL);
109 
110  if (netif != NULL) {
111  out->netif = netif->pid;
112  }
113 #endif
114 }
115 
120 void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
121 
126 ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
127  sock_ip_ep_t *remote);
128 
133 ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local,
134  const sock_ip_ep_t *remote, uint8_t nh);
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* GNRC_SOCK_INTERNAL_H */
145 
uint16_t netif
stack-specific network interface ID
Definition: sock.h:207
Mailbox API.
sock Network protocol registry info
Definition: sock_types.h:47
void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx)
Create a sock internally.
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.
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 ...
Raw IPv4/IPv6 sock definitions.
union sock_ip_ep_t::@255 addr
address
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:176
internetwork address family with IPv6: UDP, TCP, etc.
Definition: af.h:38
Includes all essential GNRC network stack base modules.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Definitions to register network protocol PIDs to use with GNRC communication interface.
kernel_pid_t pid
PID of the network interface&#39;s thread.
Definition: netif.h:126
static bool gnrc_af_not_supported(int af)
Internal helper functions for GNRC.
Representation of a network interface.
Definition: netif.h:74
static bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
Check if end point points to any address.
Global UNIX address family definitions.
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:107
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
Service Name and Transport Protocol Port Number Registry.
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.
GNRC-specific types and function definitions.
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.