Classes | Defines | Functions | Variables

alexb/lib/lwip/contrib/src/include/ipv4/lwip/ip.h File Reference

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/netif.h"

Classes

struct  ip_pcb
struct  ip_hdr

Defines

#define IP_OPTIONS_SEND   LWIP_IGMP
 Currently, the function ip_output_if_opt() is only used with IGMP.
#define IP_HLEN   20
#define IP_PROTO_ICMP   1
#define IP_PROTO_IGMP   2
#define IP_PROTO_UDP   17
#define IP_PROTO_UDPLITE   136
#define IP_PROTO_TCP   6
#define IP_HDRINCL   NULL
#define IP_PCB_ADDRHINT
#define IP_PCB
#define SOF_ACCEPTCONN   (u8_t)0x02U
#define SOF_REUSEADDR   (u8_t)0x04U
#define SOF_KEEPALIVE   (u8_t)0x08U
#define SOF_BROADCAST   (u8_t)0x20U
#define SOF_LINGER   (u8_t)0x80U
#define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
#define IP_RF   0x8000U
#define IP_DF   0x4000U
#define IP_MF   0x2000U
#define IP_OFFMASK   0x1fffU
#define IPH_V(hdr)   (ntohs((hdr)->_v_hl_tos) >> 12)
#define IPH_HL(hdr)   ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
#define IPH_TOS(hdr)   (ntohs((hdr)->_v_hl_tos) & 0xff)
#define IPH_LEN(hdr)   ((hdr)->_len)
#define IPH_ID(hdr)   ((hdr)->_id)
#define IPH_OFFSET(hdr)   ((hdr)->_offset)
#define IPH_TTL(hdr)   ((hdr)->_ttl)
#define IPH_PROTO(hdr)   ((hdr)->_proto)
#define IPH_CHKSUM(hdr)   ((hdr)->_chksum)
#define IPH_VHLTOS_SET(hdr, v, hl, tos)   (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
#define IPH_LEN_SET(hdr, len)   (hdr)->_len = (len)
#define IPH_ID_SET(hdr, id)   (hdr)->_id = (id)
#define IPH_OFFSET_SET(hdr, off)   (hdr)->_offset = (off)
#define IPH_TTL_SET(hdr, ttl)   (hdr)->_ttl = (u8_t)(ttl)
#define IPH_PROTO_SET(hdr, proto)   (hdr)->_proto = (u8_t)(proto)
#define IPH_CHKSUM_SET(hdr, chksum)   (hdr)->_chksum = (chksum)
#define ip_init()
#define ip_current_netif()   (current_netif)
 Get the interface that received the current packet.
#define ip_current_header()   (current_header)
 Get the IP header of the current packet.
#define ip_current_src_addr()   (&current_iphdr_src)
 Source IP address of current_header.
#define ip_current_dest_addr()   (&current_iphdr_dest)
 Destination IP address of current_header.
#define ip_debug_print(p)

Functions

struct netifip_route (ip_addr_t *dest)
 Finds the appropriate network interface for a given IP address.
err_t ip_input (struct pbuf *p, struct netif *inp)
 This function is called by the network interface device driver when an IP packet is received.
err_t ip_output (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto)
 Simple interface to ip_output_if.
err_t ip_output_if (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto, struct netif *netif)
 Sends an IP packet on a network interface.

Variables

PACK_STRUCT_BEGIN struct ip_hdr PACK_STRUCT_STRUCT
struct netifcurrent_netif
 The interface that provided the packet for the current callback invocation.
struct ip_hdrcurrent_header
 Header of the input packet currently being processed.
ip_addr_t current_iphdr_src
 Source IP address of current_header.
ip_addr_t current_iphdr_dest
 Destination IP address of current_header.

Define Documentation

#define ip_current_dest_addr (  )     (&current_iphdr_dest)

Destination IP address of current_header.

#define ip_current_header (  )     (current_header)

Get the IP header of the current packet.

This function must only be called from a receive callback (udp_recv, raw_recv, tcp_accept). It will return NULL otherwise.

#define ip_current_netif (  )     (current_netif)

Get the interface that received the current packet.

This function must only be called from a receive callback (udp_recv, raw_recv, tcp_accept). It will return NULL otherwise.

#define ip_current_src_addr (  )     (&current_iphdr_src)

Source IP address of current_header.

#define ip_debug_print (   p  ) 
#define IP_DF   0x4000U
#define IP_HDRINCL   NULL
#define IP_HLEN   20
#define ip_init (   void  ) 
#define IP_MF   0x2000U
#define IP_OFFMASK   0x1fffU
#define IP_OPTIONS_SEND   LWIP_IGMP

Currently, the function ip_output_if_opt() is only used with IGMP.

#define IP_PCB
Value:
/* ip addresses in network byte order */ \
  ip_addr_t local_ip; \
  ip_addr_t remote_ip; \
   /* Socket options */  \
  u8_t so_options;      \
   /* Type Of Service */ \
  u8_t tos;              \
  /* Time To Live */     \
  u8_t ttl               \
  /* link layer address resolution hint */ \
  IP_PCB_ADDRHINT
#define IP_PCB_ADDRHINT
#define IP_PROTO_ICMP   1
#define IP_PROTO_IGMP   2
#define IP_PROTO_TCP   6
#define IP_PROTO_UDP   17
#define IP_PROTO_UDPLITE   136
#define IP_RF   0x8000U
#define IPH_CHKSUM (   hdr  )     ((hdr)->_chksum)
#define IPH_CHKSUM_SET (   hdr,
  chksum 
)    (hdr)->_chksum = (chksum)
#define IPH_HL (   hdr  )     ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
#define IPH_ID (   hdr  )     ((hdr)->_id)
#define IPH_ID_SET (   hdr,
  id 
)    (hdr)->_id = (id)
#define IPH_LEN (   hdr  )     ((hdr)->_len)
#define IPH_LEN_SET (   hdr,
  len 
)    (hdr)->_len = (len)
#define IPH_OFFSET (   hdr  )     ((hdr)->_offset)
#define IPH_OFFSET_SET (   hdr,
  off 
)    (hdr)->_offset = (off)
#define IPH_PROTO (   hdr  )     ((hdr)->_proto)
#define IPH_PROTO_SET (   hdr,
  proto 
)    (hdr)->_proto = (u8_t)(proto)
#define IPH_TOS (   hdr  )     (ntohs((hdr)->_v_hl_tos) & 0xff)
#define IPH_TTL (   hdr  )     ((hdr)->_ttl)
#define IPH_TTL_SET (   hdr,
  ttl 
)    (hdr)->_ttl = (u8_t)(ttl)
#define IPH_V (   hdr  )     (ntohs((hdr)->_v_hl_tos) >> 12)
#define IPH_VHLTOS_SET (   hdr,
  v,
  hl,
  tos 
)    (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
#define SOF_ACCEPTCONN   (u8_t)0x02U
#define SOF_BROADCAST   (u8_t)0x20U
#define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
#define SOF_KEEPALIVE   (u8_t)0x08U
#define SOF_LINGER   (u8_t)0x80U
#define SOF_REUSEADDR   (u8_t)0x04U

Function Documentation

err_t ip_input ( struct pbuf p,
struct netif inp 
)

This function is called by the network interface device driver when an IP packet is received.

The function does the basic checks of the IP header such as packet size being at least larger than the header size etc. If the packet was not destined for us, the packet is forwarded (using ip_forward). The IP checksum is always checked.

Finally, the packet is sent to the upper layer protocol input function.

Parameters:
p the received IP packet (p->payload points to IP header)
inp the netif on which this packet was received
Returns:
ERR_OK if the packet was processed (could return ERR_* if it wasn't processed, but currently always returns ERR_OK)
err_t ip_output ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  ttl,
u8_t  tos,
u8_t  proto 
)

Simple interface to ip_output_if.

It finds the outgoing network interface and calls upon ip_output_if to do the actual work.

Parameters:
p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == IP_HDRINCL, p already includes an IP header and p->payload points to that IP header)
src the source IP address to send from (if src == IP_ADDR_ANY, the IP address of the netif used to send is used as source address)
dest the destination IP address to send the packet to
ttl the TTL value to be set in the IP header
tos the TOS value to be set in the IP header
proto the PROTOCOL to be set in the IP header
Returns:
ERR_RTE if no route is found see ip_output_if() for more return values
err_t ip_output_if ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  ttl,
u8_t  tos,
u8_t  proto,
struct netif netif 
)

Sends an IP packet on a network interface.

This function constructs the IP header and calculates the IP header checksum. If the source IP address is NULL, the IP address of the outgoing network interface is filled in as source address. If the destination IP address is IP_HDRINCL, p is assumed to already include an IP header and p->payload points to it instead of the data.

Parameters:
p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == IP_HDRINCL, p already includes an IP header and p->payload points to that IP header)
src the source IP address to send from (if src == IP_ADDR_ANY, the IP address of the netif used to send is used as source address)
dest the destination IP address to send the packet to
ttl the TTL value to be set in the IP header
tos the TOS value to be set in the IP header
proto the PROTOCOL to be set in the IP header
netif the netif on which to send this packet
Returns:
ERR_OK if the packet was sent OK ERR_BUF if p doesn't have enough space for IP/LINK headers returns errors returned by netif->output
Note:
ip_id: RFC791 "some host may be able to simply use unique identifiers independent of destination"
struct netif* ip_route ( ip_addr_t dest  )  [read]

Finds the appropriate network interface for a given IP address.

It searches the list of network interfaces linearly. A match is found if the masked IP address of the network interface equals the masked IP address given to the function.

Parameters:
dest the destination IP address for which to find the route
Returns:
the netif on which to send to reach dest

Variable Documentation

Header of the input packet currently being processed.

Destination IP address of current_header.

Source IP address of current_header.

The interface that provided the packet for the current callback invocation.

PACK_STRUCT_BEGIN struct ip_hdr PACK_STRUCT_STRUCT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines