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 
67 static inline bool gnrc_af_not_supported(int af)
68 {
69  /* TODO: add AF_INET support */
70  return (af != AF_INET6);
71 }
72 
77 static inline bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
78 {
79  assert(ep != NULL);
80  const uint8_t *p = (uint8_t *)&ep->addr;
81  for (uint8_t i = 0; i < sizeof(ep->addr); i++) {
82  if (p[i] != 0) {
83  return false;
84  }
85  }
86  return true;
87 }
88 
94 static inline void gnrc_ep_set(sock_ip_ep_t *out, const sock_ip_ep_t *in,
95  size_t in_size)
96 {
97  memcpy(out, in, in_size);
98  if (gnrc_netif_highlander()) {
99  /* set interface implicitly */
100  gnrc_netif_t *netif = gnrc_netif_iter(NULL);
101 
102  if (netif != NULL) {
103  out->netif = netif->pid;
104  }
105  }
106 }
107 
112 void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx);
113 
118 ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt, uint32_t timeout,
119  sock_ip_ep_t *remote);
120 
125 ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local,
126  const sock_ip_ep_t *remote, uint8_t nh);
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* GNRC_SOCK_INTERNAL_H */
137 
gnrc.h
Includes all essential GNRC network stack base modules.
sock_ip_ep_t::addr
union sock_ip_ep_t::@290 addr
address
assert
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
sock_types.h
GNRC-specific types and function definitions.
gnrc_sock_send
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_sock_reg
sock Network protocol registry info
Definition: sock_types.h:86
gnrc_netif_highlander
static bool gnrc_netif_highlander(void)
Check if there can only be one gnrc_netif_t interface.
Definition: netif.h:347
gnrc_af_not_supported
static bool gnrc_af_not_supported(int af)
Internal helper functions for GNRC.
Definition: gnrc_sock_internal.h:67
gnrc_ep_set
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 ...
Definition: gnrc_sock_internal.h:94
mbox.h
Mailbox API.
sock_ip_ep_t::netif
uint16_t netif
stack-specific network interface ID
Definition: sock.h:207
gnrc_netif_t
Representation of a network interface.
Definition: netif.h:115
gnrc_sock_recv
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.
gnrc_netif_t::pid
kernel_pid_t pid
PID of the network interface's thread.
Definition: netif.h:188
gnrc_nettype_t
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
af.h
Global UNIX address family definitions.
AF_INET6
@ AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition: af.h:38
ip.h
Raw IPv4/IPv6 sock definitions.
gnrc_netif_iter
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.
portrange.h
Service Name and Transport Protocol Port Number Registry.
gnrc_sock_create
void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_ctx)
Create a sock internally.
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
netreg.h
Definitions to register network protocol PIDs to use with GNRC communication interface.
gnrc_ep_addr_any
static bool gnrc_ep_addr_any(const sock_ip_ep_t *ep)
Check if end point points to any address.
Definition: gnrc_sock_internal.h:77
sock_ip_ep_t
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:176