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 "mbox.h"
28 #include "net/af.h"
29 #include "net/gnrc.h"
30 #include "net/gnrc/netreg.h"
31 #include "net/iana/portrange.h"
32 #include "net/sock/ip.h"
33 
34 #include "sock_types.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #define GNRC_SOCK_DYN_PORTRANGE_MIN (IANA_DYNAMIC_PORTRANGE_MIN)
44 
47 #define GNRC_SOCK_DYN_PORTRANGE_MAX (IANA_DYNAMIC_PORTRANGE_MAX)
48 
52 #define GNRC_SOCK_DYN_PORTRANGE_NUM (GNRC_SOCK_DYN_PORTRANGE_MAX - GNRC_SOCK_DYN_PORTRANGE_MIN + 1)
53 
58 #define GNRC_SOCK_DYN_PORTRANGE_ERR (0)
59 
66 #define GNRC_SOCK_DYN_PORTRANGE_OFF (17U)
67 
77 static inline bool gnrc_af_not_supported(int af)
78 {
79  /* TODO: add AF_INET support */
80  return (af != AF_INET6);
81 }
82 
87 static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
88 {
89  assert(ep != NULL);
90  const uint8_t *p = (uint8_t *)&ep->addr;
91  for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
92  if (p[i] != 0) {
93  return false;
94  }
95  }
96  return true;
97 }
98 
103 void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
104 
109 ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
110  sock_ip_ep_t *remote);
111 
116 ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local,
117  const sock_ip_ep_t *remote, uint8_t nh);
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* GNRC_SOCK_INTERNAL_H */
128 
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.
Mailbox API.
sock Network protocol registry info
Definition: sock_types.h:47
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.
union sock_ip_ep_t::@180 addr
address
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Includes all essential GNRC network stack base modules.
GNRC-specific types and function definitions.
internetwork address family with IPv6: UDP, TCP, etc.
Definition: af.h:38
Definitions to register network protocol PIDs to use with GNRC communication interface.
static bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
Check if end point points to any address.
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.