FireSync API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kPacketUtils.h
Go to the documentation of this file.
1 
8 #ifndef K_PACKET_UTILS_H
9 #define K_PACKET_UTILS_H
10 
11 #include <kFireSync/kFsDef.h>
12 
13 #define kPACKET_UTILS_ETHERNET_HEADER_SIZE (14) //< Ethernet header size.
14 #define kPACKET_UTILS_ARP_HEADER_SIZE (28) //< ARP header size.
15 #define kPACKET_UTILS_IP_HEADER_SIZE (20) //< IP header size.
16 #define kPACKET_UTILS_UDP_HEADER_SIZE (8) //< UDP header size.
17 #define kPACKET_UTILS_DHCP_HEADER_SIZE (240) //< DHCP header size.
18 
19 #define kPACKET_UTILS_DHCP_CHADDR_LEN (16) //< Length of DHCP hardware address.
20 #define kPACKET_UTILS_DHCP_SERVERNAME_LEN (64) //< Length of DHCP server name.
21 #define kPACKET_UTILS_DHCP_FILENAME_LEN (128) //< Length of DHCP boot file name.
22 
23 #define kPACKET_UTILS_ETHERNET_PROTO_IP (0x0800) //< IPv4 ethernet protocol type.
24 #define kPACKET_UTILS_ETHERNET_PROTO_ARP (0x806) //< ARP ethernet protocol type.
25 
26 #define kPACKET_UTILS_ETHERNET_IP_PROTO_UDP (17) //< UDP IPv4 protocol type.
27 
28 //< Minimal DHCP packet size (without any DHCP options).
29 #define kPACKET_UTILS_DHCP_MIN_FRAME_SIZE (kPACKET_UTILS_ETHERNET_HEADER_SIZE + kPACKET_UTILS_IP_HEADER_SIZE + kPACKET_UTILS_UDP_HEADER_SIZE + kPACKET_UTILS_DHCP_HEADER_SIZE)
30 
31 //< Gives the position of the DHCP options in an ethernet frame.
32 #define kPACKET_UTILS_DHCP_OPTIONS_POS(b) ((kByte*)b + kPACKET_UTILS_DHCP_MIN_FRAME_SIZE)
33 
40 typedef struct kEthernetHeader
41 {
42  kMacAddress destAddress; //< Destination MAC address
43  kMacAddress sourceAddress; //< Source MAC address
44  k16u protocol; //< Protocol type, e.g. 0x0800 for IPv4.
46 
53 typedef struct kArpHeader
54 {
55  k16u hardwareType; //< Hardware type, e.g. 1 for Ethernet (10Mb).
56  k16u protocolType; //< Protocol type.
57  k8u hardwareSize; //< Size of hardware address.
58  k8u protocolSize; //< Size of protocol address.
59  k16u operationCode; //< Operation code.
60  kMacAddress sourceMac; //< Source MAC address.
61  kIpAddress sourceIp; //< Source IP address.
62  kMacAddress destMac; //< Destination MAC address.
63  kIpAddress destIp; //< Destination IP address.
64 } kArpHeader;
65 
72 typedef struct kIpHeader
73 {
74  k8u ihl4Version; //< Version and internet header length.
75  k8u tos; //< Type of service.
76  k16u totalLength; //< Total length in bytes of header and data.
77  k16u id; //< Identification.
78  k16u fragment; //< Flags.
79  k8u ttl; //< Time To Live.
80  k8u protocol; //< Protocol.
81  k16u checksum; //< Header checksum.
82  kIpAddress sourceIp; //< Source IP address.
83  kIpAddress destIp; //< Destination IP address.
84 } kIpHeader;
85 
92 typedef struct kUdpHeader
93 {
94  k16u sourcePort; //< Source port.
95  k16u destinationPort; //< Destination port.
96  k16u length; //< Total length in bytes of header and data.
97  k16u checksum; //< Checksum.
98 } kUdpHeader;
99 
106 typedef struct kDhcpHeader
107 {
108  k8u opcode; //< Operation code.
109  k8u htype; //< Hardware type.
110  k8u hlen; //< Hardware address length.
111  k8u hops; //< Number of relays agents that have forwarded this message.
112  k32u xid; //< Transaction identifier.
113  k16u secs; //< Elapsed time in seconds since client began negotiation process.
114  k16u flags; //< Broadcast flag.
115  kIpAddress clientIp; //< Client's IP address; set by the client.
116  kIpAddress yourIp; //< Client's IP address; set by the server to inform client.
117  kIpAddress serverIp; //< Server address.
118  kIpAddress relayIp; //< Relay agent IP address.
119  kMacAddress clientMac; //< Client's hardware address.
120  kChar serverName[kPACKET_UTILS_DHCP_SERVERNAME_LEN]; //< Name of the server.
121  kChar fileName[kPACKET_UTILS_DHCP_FILENAME_LEN]; //< Name of the boot file name.
122  k32u magicCookie; //< DHCP magic cookie.
123 } kDhcpHeader;
124 
134 kFsFx(kStatus) kPacketUtils_ReadEthernetHeader(const kByte* frame, kSize size, kEthernetHeader* header);
135 
145 kFsFx(kStatus) kPacketUtils_WriteEthernetHeader(kByte* frame, kSize size, const kEthernetHeader* header);
146 
156 kFsFx(kStatus) kPacketUtils_ReadArpHeader(const kByte* frame, kSize size, kArpHeader* header);
157 
167 kFsFx(kStatus) kPacketUtils_WriteArpHeader(kByte* frame, kSize size, const kArpHeader* header);
168 
178 kFsFx(kStatus) kPacketUtils_ReadIpHeader(const kByte* frame, kSize size, kIpHeader* header);
179 
192 kFsFx(kStatus) kPacketUtils_WriteIpHeader(kByte* frame, kSize size, const kIpHeader* header);
193 
203 kFsFx(kStatus) kPacketUtils_ReadUdpHeader(const kByte* frame, kSize size, kUdpHeader* header);
204 
214 kFsFx(kStatus) kPacketUtils_WriteUdpHeader(kByte* frame, kSize size, const kUdpHeader* header);
215 
225 kFsFx(kStatus) kPacketUtils_ReadDhcpHeader(const kByte* frame, kSize size, kDhcpHeader* header);
226 
236 kFsFx(kStatus) kPacketUtils_WriteDhcpHeader(kByte* frame, kSize size, const kDhcpHeader* header);
237 
238 #include <kFireSync/Net/kPacketUtils.x.h>
239 
240 #endif
Represents an Arp message.
Definition: kPacketUtils.h:53
Represents an Ethernet frame header.
Definition: kPacketUtils.h:40
Essential API declarations for the kFireSync library.
Represents an IPv4 frame header.
Definition: kPacketUtils.h:72
Represents an DHCP message header.
Definition: kPacketUtils.h:106
Represents an UDP frame header.
Definition: kPacketUtils.h:92