raw_socket.h
Go to the documentation of this file.
1 /**
2  * @file raw_socket.h
3  * @brief TCP/IP raw sockets
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _RAW_SOCKET_H
32 #define _RAW_SOCKET_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ip.h"
37 #include "core/socket.h"
38 
39 //Raw socket support
40 #ifndef RAW_SOCKET_SUPPORT
41  #define RAW_SOCKET_SUPPORT DISABLED
42 #elif (RAW_SOCKET_SUPPORT != ENABLED && RAW_SOCKET_SUPPORT != DISABLED)
43  #error RAW_SOCKET_SUPPORT parameter is not valid
44 #endif
45 
46 //Receive queue depth for raw sockets
47 #ifndef RAW_SOCKET_RX_QUEUE_SIZE
48  #define RAW_SOCKET_RX_QUEUE_SIZE 4
49 #elif (RAW_SOCKET_RX_QUEUE_SIZE < 1)
50  #error RAW_SOCKET_RX_QUEUE_SIZE parameter is not valid
51 #endif
52 
53 //C++ guard
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 //Raw socket related functions
60  IpPseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
61 
62 void rawSocketProcessEthPacket(NetInterface *interface, EthHeader *header,
63  const uint8_t *data, size_t length);
64 
66  const void *data, size_t length, size_t *written, uint_t flags);
67 
69  size_t length, size_t *written);
70 
72  IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags);
73 
75  size_t *received, uint_t flags);
76 
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
uint8_t length
Definition: dtls_misc.h:149
error_t rawSocketReceiveEthPacket(Socket *socket, void *data, size_t size, size_t *received, uint_t flags)
Receive an Ethernet packet from a raw socket.
Definition: raw_socket.c:718
IP network address.
Definition: ip.h:71
void rawSocketProcessEthPacket(NetInterface *interface, EthHeader *header, const uint8_t *data, size_t length)
Process incoming Ethernet packet.
Definition: raw_socket.c:274
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
error_t rawSocketSendEthPacket(Socket *socket, const void *data, size_t length, size_t *written)
Send an raw Ethernet packet.
Definition: raw_socket.c:524
Ipv4Addr srcIpAddr
Definition: ipcp.h:77
IP pseudo header.
Definition: ip.h:90
error_t rawSocketSendIpPacket(Socket *socket, const IpAddr *destIpAddr, const void *data, size_t length, size_t *written, uint_t flags)
Send an raw IP packet.
Definition: raw_socket.c:411
error_t
Error codes.
Definition: error.h:42
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:108
error_t rawSocketProcessIpPacket(NetInterface *interface, IpPseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Process incoming IP packet.
Definition: raw_socket.c:64
#define NetInterface
Definition: net.h:36
void rawSocketUpdateEvents(Socket *socket)
Update event state for raw sockets.
Definition: raw_socket.c:780
uint8_t flags
Definition: tcp.h:314
IPv4 and IPv6 common routines.
#define Socket
Definition: socket.h:36
Socket API.
unsigned int uint_t
Definition: compiler_port.h:45
__start_packed struct @110 EthHeader
Ethernet frame header.
TCP/IP stack core.
uint8_t data[]
Definition: dtls_misc.h:176
error_t rawSocketReceiveIpPacket(Socket *socket, IpAddr *srcIpAddr, IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags)
Receive an IP packet from a raw socket.
Definition: raw_socket.c:644
Ipv4Addr destIpAddr
Definition: ipcp.h:78