mikroSDK Reference Manual
ip.h
Go to the documentation of this file.
1
31#ifndef _IP_H
32#define _IP_H
33
34//Dependencies
35#include "ipv4/ipv4.h"
36#include "ipv6/ipv6.h"
37
38//C++ guard
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43
48typedef enum
49{
50 IP_PROTOCOL_TCP = 6,
51 IP_PROTOCOL_UDP = 17
53
54
59typedef enum
60{
61 IP_FLAG_DONT_ROUTE = 0x0400,
62 IP_FLAG_TTL = 0x00FF,
63 IP_FLAG_HOP_LIMIT = 0x00FF
64} IpFlags;
65
66
71typedef struct
72{
73 size_t length;
74 union
75 {
76#if (IPV4_SUPPORT == ENABLED)
77 Ipv4Addr ipv4Addr;
78#endif
79#if (IPV6_SUPPORT == ENABLED)
80 Ipv6Addr ipv6Addr;
81#endif
82 };
83} IpAddr;
84
85
90typedef struct
91{
92 size_t length;
93 union
94 {
95#if (IPV4_SUPPORT == ENABLED)
96 Ipv4PseudoHeader ipv4Data;
97#endif
98#if (IPV6_SUPPORT == ENABLED)
99 Ipv6PseudoHeader ipv6Data;
100#endif
101 uint8_t data[4];
102 };
104
105
106//IP related constants
107extern const IpAddr IP_ADDR_ANY;
108extern const IpAddr IP_ADDR_UNSPECIFIED;
109
110//IP related functions
111error_t ipSendDatagram(NetInterface *interface,
112 const IpPseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset,
113 NetTxAncillary *ancillary);
114
115error_t ipSelectSourceAddr(NetInterface **interface, const IpAddr *destAddr,
116 IpAddr *srcAddr);
117
118bool_t ipIsUnspecifiedAddr(const IpAddr *ipAddr);
119bool_t ipIsLinkLocalAddr(const IpAddr *ipAddr);
120bool_t ipIsMulticastAddr(const IpAddr *ipAddr);
121
122bool_t ipCompAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2);
123
124bool_t ipCompPrefix(const IpAddr *ipAddr1, const IpAddr *ipAddr2,
125 size_t length);
126
127error_t ipJoinMulticastGroup(NetInterface *interface, const IpAddr *groupAddr);
128error_t ipLeaveMulticastGroup(NetInterface *interface, const IpAddr *groupAddr);
129
130uint16_t ipCalcChecksum(const void *data, size_t length);
131uint16_t ipCalcChecksumEx(const NetBuffer *buffer, size_t offset, size_t length);
132
133uint16_t ipCalcUpperLayerChecksum(const void *pseudoHeader,
134 size_t pseudoHeaderLen, const void *data, size_t dataLen);
135
136uint16_t ipCalcUpperLayerChecksumEx(const void *pseudoHeader,
137 size_t pseudoHeaderLen, const NetBuffer *buffer, size_t offset, size_t length);
138
139NetBuffer *ipAllocBuffer(size_t length, size_t *offset);
140
141error_t ipStringToAddr(const char_t *str, IpAddr *ipAddr);
142char_t *ipAddrToString(const IpAddr *ipAddr, char_t *str);
143
144//C++ guard
145#ifdef __cplusplus
146}
147#endif
148
149#endif
error_t
Error codes.
Definition error.h:43
IpProtocol
IP supported protocols.
Definition ip.h:49
IpFlags
Flags used by I/O functions.
Definition ip.h:60
IPv4 (Internet Protocol Version 4)
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
IPv6 (Internet Protocol Version 6)
IP network address.
Definition ip.h:72
IP pseudo header.
Definition ip.h:91
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89