Implementation of raw protocol PCBs for low-level handling of different types of protocols besides (or overriding) those already available in lwIP.
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/memp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/raw.h"
#include "lwip/stats.h"
#include "arch/perf.h"
#include <string.h>
Functions | |
err_t | raw_bind (struct raw_pcb *pcb, ip_addr_t *ipaddr) |
Bind a RAW PCB. More... | |
err_t | raw_connect (struct raw_pcb *pcb, ip_addr_t *ipaddr) |
Connect an RAW PCB. More... | |
u8_t | raw_input (struct pbuf *p, struct netif *inp) |
Determine if in incoming IP packet is covered by a RAW PCB and if so, pass it to a user-provided receive callback function. More... | |
struct raw_pcb * | raw_new (u8_t proto) |
Create a RAW PCB. More... | |
void | raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg) |
Set the callback function for received packets that match the raw PCB's protocol and binding. More... | |
void | raw_remove (struct raw_pcb *pcb) |
Remove an RAW PCB. More... | |
err_t | raw_send (struct raw_pcb *pcb, struct pbuf *p) |
Send the raw IP packet to the address given by raw_connect() More... | |
err_t | raw_sendto (struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr) |
Send the raw IP packet to the given address. More... | |
Variables | |
static struct raw_pcb * | raw_pcbs |
The list of RAW PCBs. More... | |
Bind a RAW PCB.
pcb | RAW PCB to be bound with a local address ipaddr. |
ipaddr | local IP address to bind with. Use IP_ADDR_ANY to bind to all local interfaces. |
References ERR_OK, and ip_addr_set.
Referenced by do_bind().
Connect an RAW PCB.
This function is required by upper layers of lwip. Using the raw api you could use raw_sendto() instead
This will associate the RAW PCB with the remote address.
pcb | RAW PCB to be connected with remote address ipaddr and port. |
ipaddr | remote IP address to connect with. |
References ERR_OK, and ip_addr_set.
Referenced by do_connect().
Determine if in incoming IP packet is covered by a RAW PCB and if so, pass it to a user-provided receive callback function.
Given an incoming IP datagram (as a chain of pbufs) this function finds a corresponding RAW PCB and calls the corresponding receive callback function.
p | pbuf to be demultiplexed to a RAW PCB. |
inp | network interface on which the datagram was received. |
References current_iphdr_dest, ip_addr_cmp, ip_addr_isany, ip_addr_isbroadcast, ip_current_src_addr, IPH_PROTO, iphdr, LWIP_UNUSED_ARG, raw_pcb::next, NULL, pbuf::payload, raw_pcb::protocol, raw_pcbs, raw_pcb::recv, raw_pcb::recv_arg, and SOF_BROADCAST.
Referenced by ip_input().
Create a RAW PCB.
proto | the protocol number of the IPs payload (e.g. IP_PROTO_ICMP) |
References LWIP_DBG_TRACE, LWIP_DEBUGF, memp_malloc(), raw_pcb::next, NULL, raw_pcb::protocol, RAW_DEBUG, raw_pcbs, and RAW_TTL.
Referenced by pcb_new().
void raw_recv | ( | struct raw_pcb * | pcb, |
raw_recv_fn | recv, | ||
void * | recv_arg | ||
) |
Set the callback function for received packets that match the raw PCB's protocol and binding.
The callback function MUST either
References raw_pcb::recv, recv, and raw_pcb::recv_arg.
Referenced by pcb_new().
Remove an RAW PCB.
pcb | RAW PCB to be removed. The PCB is removed from the list of RAW PCB's and the data structure is freed from memory. |
References memp_free(), raw_pcb::next, and NULL.
Referenced by do_delconn().
Send the raw IP packet to the address given by raw_connect()
pcb | the raw pcb which to send |
p | the IP payload to send |
References raw_sendto().
Referenced by do_send().
Send the raw IP packet to the given address.
Note that actually you cannot modify the IP headers (this is inconsistent with the receive callback where you actually get the IP headers), you can only specify the IP payload here. It requires some more changes in lwIP. (there will be a raw_send() function then.)
pcb | the raw pcb which to send |
p | the IP payload to send |
ipaddr | the destination address of the IP packet |
References ERR_MEM, ERR_RTE, ERR_VAL, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_isany, ip_addr_isbroadcast, IP_HLEN, ip_output_if(), ip_route(), LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_TRACE, LWIP_DEBUGF, NULL, pbuf_alloc(), pbuf_chain(), pbuf_free(), pbuf_header(), PBUF_IP, PBUF_RAM, raw_pcb::protocol, RAW_DEBUG, SOF_BROADCAST, pbuf::tot_len, and U16_F.
Referenced by do_send(), lwip_sendto(), and raw_send().
|
static |
The list of RAW PCBs.
Referenced by raw_input(), and raw_new().