Microchip® Advanced Software Framework

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"

Data Structures

struct  ip_hdr
 
struct  ip_pcb
 

Macros

#define ip_current_dest_addr()   (&current_iphdr_dest)
 Destination IP address of current_header. More...
 
#define ip_current_header()   (current_header)
 Get the IP header of the current packet. More...
 
#define ip_current_netif()   (current_netif)
 Get the interface that received the current packet. More...
 
#define ip_current_src_addr()   (&current_iphdr_src)
 Source IP address of current_header. More...
 
#define ip_debug_print(p)
 
#define IP_DF   0x4000U /* dont fragment flag */
 
#define ip_get_option(pcb, opt)   ((pcb)->so_options & (opt))
 Gets an IP pcb option (SOF_* flags) More...
 
#define IP_HDRINCL   NULL
 
#define IP_HLEN   20
 
#define ip_init()   /* Compatibility define, not init needed. */
 
#define IP_MF   0x2000U /* more fragments flag */
 
#define IP_OFFMASK   0x1fffU /* mask for fragmenting bits */
 
#define IP_OPTIONS_SEND   LWIP_IGMP
 Currently, the function ip_output_if_opt() is only used with IGMP. More...
 
#define IP_PCB
 
#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_reset_option(pcb, opt)   ((pcb)->so_options &= ~(opt))
 Resets an IP pcb option (SOF_* flags) More...
 
#define IP_RF   0x8000U /* reserved fragment flag */
 
#define ip_set_option(pcb, opt)   ((pcb)->so_options |= (opt))
 Sets an IP pcb option (SOF_* flags) More...
 
#define IPH_CHKSUM(hdr)   ((hdr)->_chksum)
 
#define IPH_CHKSUM_SET(hdr, chksum)   (hdr)->_chksum = (chksum)
 
#define IPH_HL(hdr)   ((hdr)->_v_hl & 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)   ((hdr)->_tos)
 
#define IPH_TOS_SET(hdr, tos)   (hdr)->_tos = (tos)
 
#define IPH_TTL(hdr)   ((hdr)->_ttl)
 
#define IPH_TTL_SET(hdr, ttl)   (hdr)->_ttl = (u8_t)(ttl)
 
#define IPH_V(hdr)   ((hdr)->_v_hl >> 4)
 
#define IPH_VHL_SET(hdr, v, hl)   (hdr)->_v_hl = (((v) << 4) | (hl))
 
#define SOF_ACCEPTCONN   0x02U /* socket has had listen() */
 
#define SOF_BROADCAST   0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
 
#define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
 
#define SOF_KEEPALIVE   0x08U /* keep connections alive */
 
#define SOF_LINGER   0x80U /* linger on close if data present */
 
#define SOF_REUSEADDR   0x04U /* allow local address reuse */
 

Functions

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. More...
 
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. More...
 
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. More...
 
struct netifip_route (ip_addr_t *dest)
 Finds the appropriate network interface for a given IP address. More...
 

Variables

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

#define ip_current_dest_addr ( )    (&current_iphdr_dest)

Destination IP address of current_header.

Referenced by icmp_input(), tcp_input(), tcp_listen_input(), tcp_process(), tcp_timewait_input(), and udp_input().

#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.

Referenced by icmp_input(), tcp_input(), tcp_listen_input(), tcp_process(), tcp_timewait_input(), and udp_input().

#define ip_debug_print (   p)

Referenced by ip_input().

#define IP_DF   0x4000U /* dont fragment flag */
#define ip_get_option (   pcb,
  opt 
)    ((pcb)->so_options & (opt))

Gets an IP pcb option (SOF_* flags)

Referenced by tcp_bind(), tcp_connect(), tcp_listen_with_backlog(), tcp_slowtmr(), udp_bind(), and udp_input().

#define IP_HDRINCL   NULL

Referenced by icmp_input().

#define ip_init ( )    /* Compatibility define, not init needed. */

Referenced by lwip_init().

#define IP_MF   0x2000U /* more fragments flag */

Referenced by ip_frag(), ip_input(), and ip_reass().

#define IP_OFFMASK   0x1fffU /* mask for fragmenting bits */
#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 */ \
uint8_t u8_t
Definition: cc.h:44
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
ip_addr_t uses a struct for convenience only, so that the same defines can operate both on ip_addr_t ...
Definition: ip_addr.h:64
#define IP_PCB_ADDRHINT
Definition: ip.h:69
#define IP_PCB_ADDRHINT
#define IP_PROTO_ICMP   1
#define IP_PROTO_IGMP   2

Referenced by ip_input().

#define IP_PROTO_UDP   17

Referenced by ip_input(), and udp_input().

#define IP_PROTO_UDPLITE   136

Referenced by ip_input(), and udp_input().

#define ip_reset_option (   pcb,
  opt 
)    ((pcb)->so_options &= ~(opt))

Resets an IP pcb option (SOF_* flags)

#define IP_RF   0x8000U /* reserved fragment flag */
#define ip_set_option (   pcb,
  opt 
)    ((pcb)->so_options |= (opt))

Sets an IP pcb option (SOF_* flags)

Referenced by tcp_listen_with_backlog().

#define IPH_CHKSUM (   hdr)    ((hdr)->_chksum)
#define IPH_CHKSUM_SET (   hdr,
  chksum 
)    (hdr)->_chksum = (chksum)

Referenced by icmp_input(), ip_frag(), and ip_reass().

#define IPH_HL (   hdr)    ((hdr)->_v_hl & 0x0f)
#define IPH_ID (   hdr)    ((hdr)->_id)

Referenced by ip_input(), and ip_reass().

#define IPH_ID_SET (   hdr,
  id 
)    (hdr)->_id = (id)
#define IPH_LEN (   hdr)    ((hdr)->_len)
#define IPH_LEN_SET (   hdr,
  len 
)    (hdr)->_len = (len)

Referenced by ip_frag(), and ip_reass().

#define IPH_OFFSET (   hdr)    ((hdr)->_offset)
#define IPH_OFFSET_SET (   hdr,
  off 
)    (hdr)->_offset = (off)

Referenced by ip_frag(), and ip_reass().

#define IPH_PROTO (   hdr)    ((hdr)->_proto)

Referenced by ip_input(), and udp_input().

#define IPH_PROTO_SET (   hdr,
  proto 
)    (hdr)->_proto = (u8_t)(proto)
#define IPH_TOS (   hdr)    ((hdr)->_tos)
#define IPH_TOS_SET (   hdr,
  tos 
)    (hdr)->_tos = (tos)
#define IPH_TTL (   hdr)    ((hdr)->_ttl)
#define IPH_TTL_SET (   hdr,
  ttl 
)    (hdr)->_ttl = (u8_t)(ttl)

Referenced by icmp_input().

#define IPH_V (   hdr)    ((hdr)->_v_hl >> 4)

Referenced by ip_input().

#define IPH_VHL_SET (   hdr,
  v,
  hl 
)    (hdr)->_v_hl = (((v) << 4) | (hl))
#define SOF_ACCEPTCONN   0x02U /* socket has had listen() */

Referenced by tcp_listen_with_backlog().

#define SOF_BROADCAST   0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */

Referenced by udp_input().

#define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)

Referenced by tcp_listen_input().

#define SOF_KEEPALIVE   0x08U /* keep connections alive */

Referenced by tcp_slowtmr().

#define SOF_LINGER   0x80U /* linger on close if data present */
#define SOF_REUSEADDR   0x04U /* allow local address reuse */

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
pthe received IP packet (p->payload points to IP header)
inpthe 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)

References current_iphdr_dest, current_iphdr_src, ERR_OK, netif::flags, icmp_dest_unreach(), ICMP_DUR_PROTO, icmp_input(), if(), inet_chksum(), ip4_addr_get_u32, netif::ip_addr, ip_addr_cmp, ip_addr_copy, ip_addr_isany, ip_addr_isbroadcast, ip_addr_ismulticast, ip_addr_set_any, IP_DEBUG, ip_debug_print, IP_HLEN, IP_MF, IP_OFFMASK, IP_PROTO_ICMP, IP_PROTO_IGMP, IP_PROTO_TCP, IP_PROTO_UDP, IP_PROTO_UDPLITE, ip_reass(), IP_STATS_INC, IPH_HL, IPH_ID, IPH_LEN, IPH_OFFSET, IPH_PROTO, IPH_V, iphdr, pbuf::len, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NETIF_FLAG_IGMP, netif_is_up, netif_list, netif::netmask, netif::next, ntohs, NULL, pbuf::payload, pbuf_free(), pbuf_realloc(), PP_HTONS, snmp_inc_ipinaddrerrors, snmp_inc_ipindelivers, snmp_inc_ipindiscards, snmp_inc_ipinhdrerrors, snmp_inc_ipinreceives, snmp_inc_ipinunknownprotos, tcp_input(), pbuf::tot_len, udp_input(), X16_F, and X32_F.

Referenced by ethernet_input(), and netif_init().

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
pthe 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)
srcthe 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)
destthe destination IP address to send the packet to
ttlthe TTL value to be set in the IP header
tosthe TOS value to be set in the IP header
protothe PROTOCOL to be set in the IP header
Returns
ERR_RTE if no route is found see ip_output_if() for more return values

References ERR_RTE, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, IP_DEBUG, ip_output_if(), ip_route(), IP_STATS_INC, LWIP_ASSERT, LWIP_DEBUGF, NULL, and pbuf::ref.

Referenced by icmp_send_response(), tcp_keepalive(), tcp_output_segment(), tcp_rst(), tcp_send_empty_ack(), and tcp_zero_window_probe().

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
pthe 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)
srcthe 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)
destthe destination IP address to send the packet to
ttlthe TTL value to be set in the IP header
tosthe TOS value to be set in the IP header
protothe PROTOCOL to be set in the IP header
netifthe 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"

References NULL.

Referenced by icmp_input(), and ip_output().

struct netif* ip_route ( ip_addr_t dest)

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
destthe destination IP address for which to find the route
Returns
the netif on which to send to reach dest

References ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_netcmp, IP_DEBUG, IP_STATS_INC, LWIP_DBG_LEVEL_SERIOUS, LWIP_DEBUGF, netif_default, netif_is_up, netif_list, netif::netmask, netif::next, NULL, snmp_inc_ipoutnoroutes, and U16_F.

Referenced by etharp_update_arp_entry(), ip_output(), tcp_connect(), tcp_eff_send_mss(), tcp_output_segment(), and udp_connect().

struct ip_hdr* current_header

Header of the input packet currently being processed.

ip_addr_t current_iphdr_dest

Destination IP address of current_header.

Referenced by icmp_input(), ip_input(), tcp_input(), tcp_listen_input(), and udp_input().

ip_addr_t current_iphdr_src

Source IP address of current_header.

Referenced by ip_input(), tcp_input(), tcp_listen_input(), and udp_input().

struct netif* current_netif

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

PACK_STRUCT_BEGIN struct ip_hdr PACK_STRUCT_STRUCT