VirtualBox

source: vbox/trunk/include/iprt/net.h@ 28718

Last change on this file since 28718 was 28024, checked in by vboxsync, 15 years ago

iprt: ipv6 header and pseudo checksumming; tcp flags; tcp/udp checksumming additions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.7 KB
Line 
1/** @file
2 * IPRT - Network Protocols.
3 */
4
5/*
6 * Copyright (C) 2008 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_net_h
31#define ___iprt_net_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#include <iprt/assert.h>
36
37
38RT_C_DECLS_BEGIN
39
40/** @defgroup grp_rt_net RTNet - Network Protocols
41 * @ingroup grp_rt
42 * @{
43 */
44
45/**
46 * IPv4 address.
47 */
48typedef RTUINT32U RTNETADDRIPV4;
49AssertCompileSize(RTNETADDRIPV4, 4);
50/** Pointer to a IPv4 address. */
51typedef RTNETADDRIPV4 *PRTNETADDRIPV4;
52/** Pointer to a const IPv4 address. */
53typedef RTNETADDRIPV4 const *PCRTNETADDRIPV4;
54
55/**
56 * IPv6 address.
57 */
58typedef RTUINT128U RTNETADDRIPV6;
59AssertCompileSize(RTNETADDRIPV6, 16);
60/** Pointer to a IPv6 address. */
61typedef RTNETADDRIPV6 *PRTNETADDRIPV6;
62/** Pointer to a const IPv6 address. */
63typedef RTNETADDRIPV6 const *PCRTNETADDRIPV6;
64
65/**
66 * IPX address.
67 */
68#pragma pack(1)
69typedef struct RTNETADDRIPX
70{
71 /** The network ID. */
72 uint32_t Network;
73 /** The node ID. (Defaults to the MAC address apparently.) */
74 RTMAC Node;
75} RTNETADDRIPX;
76#pragma pack()
77AssertCompileSize(RTNETADDRIPX, 4+6);
78/** Pointer to an IPX address. */
79typedef RTNETADDRIPX *PRTNETADDRIPX;
80/** Pointer to a const IPX address. */
81typedef RTNETADDRIPX const *PCRTNETADDRIPX;
82
83/**
84 * Network address union.
85 *
86 * @remarks The size of this structure may change in the future.
87 */
88typedef union RTNETADDRU
89{
90 /** 64-bit view. */
91 uint64_t au64[2];
92 /** 32-bit view. */
93 uint32_t au32[4];
94 /** 16-bit view. */
95 uint16_t au16[8];
96 /** 8-bit view. */
97 uint8_t au8[16];
98 /** IPv4 view. */
99 RTNETADDRIPV4 IPv4;
100 /** IPv6 view. */
101 RTNETADDRIPV6 IPv6;
102 /** IPX view. */
103 RTNETADDRIPX Ipx;
104 /** MAC address view. */
105 RTMAC Mac;
106} RTNETADDRU;
107AssertCompileSize(RTNETADDRU, 16);
108/** Pointer to an address union. */
109typedef RTNETADDRU *PRTNETADDRU;
110/** Pointer to a const address union. */
111typedef RTNETADDRU const *PCRTNETADDRU;
112
113/**
114 * Network address type.
115 *
116 * @remarks The value assignments may change in the future.
117 */
118typedef enum RTNETADDRTYPE
119{
120 /** The invalid 0 entry. */
121 RTNETADDRTYPE_INVALID = 0,
122 /** IP version 4. */
123 RTNETADDRTYPE_IPV4,
124 /** IP version 6. */
125 RTNETADDRTYPE_IPV6,
126 /** IPX. */
127 RTNETADDRTYPE_IPX,
128 /** MAC address. */
129 RTNETADDRTYPE_MAC,
130 /** The end of the valid values. */
131 RTNETADDRTYPE_END,
132 /** The usual 32-bit hack. */
133 RTNETADDRTYPE_32_BIT_HACK = 0x7fffffff
134} RTNETADDRTYPE;
135/** Pointer to a network address type. */
136typedef RTNETADDRTYPE *PRTNETADDRTYPE;
137/** Pointer to a const network address type. */
138typedef RTNETADDRTYPE const *PCRTNETADDRTYPE;
139
140/**
141 * Network address.
142 *
143 * @remarks The size and type values may change.
144 */
145typedef struct RTNETADDR
146{
147 /** The address union. */
148 RTNETADDRU uAddr;
149 /** Indicates which view of @a u that is valid. */
150 RTNETADDRTYPE enmType;
151 /** The port number for IPv4 and IPv6 addresses. This is set to
152 * RTNETADDR_NA_PORT if not applicable. */
153 uint32_t uPort;
154} RTNETADDR;
155/** Pointer to a network address. */
156typedef RTNETADDR *PRTNETADDR;
157/** Pointer to a const network address. */
158typedef RTNETADDR const *PCRTNETADDR;
159
160/** The not applicable value of RTNETADDR::uPort value use to inid. */
161#define RTNETADDR_PORT_NA UINT32_MAX
162
163/**
164 * Ethernet header.
165 */
166#pragma pack(1)
167typedef struct RTNETETHERHDR
168{
169 RTMAC DstMac;
170 RTMAC SrcMac;
171 /** Ethernet frame type or frame size, depending on the kind of ethernet.
172 * This is big endian on the wire. */
173 uint16_t EtherType;
174} RTNETETHERHDR;
175#pragma pack()
176AssertCompileSize(RTNETETHERHDR, 14);
177/** Pointer to an ethernet header. */
178typedef RTNETETHERHDR *PRTNETETHERHDR;
179/** Pointer to a const ethernet header. */
180typedef RTNETETHERHDR const *PCRTNETETHERHDR;
181
182/** @name EtherType (RTNETETHERHDR::EtherType)
183 * @{ */
184#define RTNET_ETHERTYPE_IPV4 UINT16_C(0x0800)
185#define RTNET_ETHERTYPE_ARP UINT16_C(0x0806)
186#define RTNET_ETHERTYPE_IPV6 UINT16_C(0x86dd)
187#define RTNET_ETHERTYPE_VLAN UINT16_C(0x8100)
188#define RTNET_ETHERTYPE_IPX_1 UINT16_C(0x8037)
189#define RTNET_ETHERTYPE_IPX_2 UINT16_C(0x8137)
190#define RTNET_ETHERTYPE_IPX_3 UINT16_C(0x8138)
191/** @} */
192
193
194/**
195 * IPv4 header.
196 * All is bigendian on the wire.
197 */
198#pragma pack(1)
199typedef struct RTNETIPV4
200{
201#ifdef RT_BIG_ENDIAN
202 unsigned int ip_v : 4;
203 unsigned int ip_hl : 4;
204 unsigned int ip_tos : 8;
205 unsigned int ip_len : 16;
206#else
207 /** 00:0 - Header length given as a 32-bit word count. */
208 unsigned int ip_hl : 4;
209 /** 00:4 - Header version. */
210 unsigned int ip_v : 4;
211 /** 01 - Type of service. */
212 unsigned int ip_tos : 8;
213 /** 02 - Total length (header + data). */
214 unsigned int ip_len : 16;
215#endif
216 /** 04 - Packet idenficiation. */
217 uint16_t ip_id;
218 /** 06 - Offset if fragmented. */
219 uint16_t ip_off;
220 /** 08 - Time to live. */
221 uint8_t ip_ttl;
222 /** 09 - Protocol. */
223 uint8_t ip_p;
224 /** 0a - Header check sum. */
225 uint16_t ip_sum;
226 /** 0c - Source address. */
227 RTNETADDRIPV4 ip_src;
228 /** 10 - Destination address. */
229 RTNETADDRIPV4 ip_dst;
230 /** 14 - Options (optional). */
231 uint32_t ip_options[1];
232} RTNETIPV4;
233#pragma pack()
234AssertCompileSize(RTNETIPV4, 6 * 4);
235/** Pointer to a IPv4 header. */
236typedef RTNETIPV4 *PRTNETIPV4;
237/** Pointer to a const IPv4 header. */
238typedef RTNETIPV4 const *PCRTNETIPV4;
239
240/** The minimum IPv4 header length (in bytes).
241 * Up to and including RTNETIPV4::ip_dst. */
242#define RTNETIPV4_MIN_LEN (20)
243
244
245/** @name IPv4 Protocol Numbers
246 * @{ */
247/** IPv4: ICMP */
248#define RTNETIPV4_PROT_ICMP (1)
249/** IPv4: TCP */
250#define RTNETIPV4_PROT_TCP (6)
251/** IPv4: UDP */
252#define RTNETIPV4_PROT_UDP (17)
253/** @} */
254
255/** @name Common IPv4 Port Assignments
256 * @{
257 */
258/** Boostrap Protocol / DHCP) Server. */
259#define RTNETIPV4_PORT_BOOTPS (67)
260/** Boostrap Protocol / DHCP) Client. */
261#define RTNETIPV4_PORT_BOOTPC (68)
262/** @} */
263
264RTDECL(uint16_t) RTNetIPv4HdrChecksum(PCRTNETIPV4 pIpHdr);
265RTDECL(bool) RTNetIPv4IsHdrValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax, bool fChecksum);
266RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr);
267RTDECL(uint32_t) RTNetIPv4PseudoChecksumBits(RTNETADDRIPV4 SrcAddr, RTNETADDRIPV4 DstAddr, uint8_t bProtocol, uint16_t cbPkt);
268RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t u32Sum, bool *pfOdd);
269RTDECL(uint16_t) RTNetIPv4FinalizeChecksum(uint32_t u32Sum);
270
271
272/**
273 * IPv6 header.
274 * All is bigendian on the wire.
275 */
276#pragma pack(1)
277typedef struct RTNETIPV6
278{
279 /** Version (4 bits), Traffic Class (8 bits) and Flow Lable (20 bits).
280 * @todo this is probably mislabeled - ip6_flow vs. ip6_vfc, fix later. */
281 uint32_t ip6_vfc;
282 /** 04 - Payload length, including extension headers. */
283 uint16_t ip6_plen;
284 /** 06 - Next header type (RTNETIPV4_PROT_XXX). */
285 uint8_t ip6_nxt;
286 /** 07 - Hop limit. */
287 uint8_t ip6_hlim;
288 /** xx - Source address. */
289 RTNETADDRIPV6 ip6_src;
290 /** xx - Destination address. */
291 RTNETADDRIPV6 ip6_dst;
292} RTNETIPV6;
293#pragma pack()
294AssertCompileSize(RTNETIPV6, 8 + 16 + 16);
295/** Pointer to a IPv6 header. */
296typedef RTNETIPV6 *PRTNETIPV6;
297/** Pointer to a const IPv6 header. */
298typedef RTNETIPV6 const *PCRTNETIPV6;
299
300/** The minimum IPv6 header length (in bytes).
301 * Up to and including RTNETIPV6::ip6_dst. */
302#define RTNETIPV6_MIN_LEN (40)
303
304RTDECL(uint32_t) RTNetIPv6PseudoChecksum(PCRTNETIPV6 pIpHdr);
305RTDECL(uint32_t) RTNetIPv6PseudoChecksumEx(PCRTNETIPV6 pIpHdr, uint8_t bProtocol, uint16_t cbPkt);
306RTDECL(uint32_t) RTNetIPv6PseudoChecksumBits(PCRTNETADDRIPV6 pSrcAddr, PCRTNETADDRIPV6 pDstAddr,
307 uint8_t bProtocol, uint16_t cbPkt);
308
309
310/**
311 * UDP header.
312 */
313#pragma pack(1)
314typedef struct RTNETUDP
315{
316 /** The source port. */
317 uint16_t uh_sport;
318 /** The destination port. */
319 uint16_t uh_dport;
320 /** The length of the UDP header and associated data. */
321 uint16_t uh_ulen;
322 /** The checksum of the pseudo header, the UDP header and the data. */
323 uint16_t uh_sum;
324} RTNETUDP;
325#pragma pack()
326AssertCompileSize(RTNETUDP, 8);
327/** Pointer to an UDP header. */
328typedef RTNETUDP *PRTNETUDP;
329/** Pointer to a const UDP header. */
330typedef RTNETUDP const *PCRTNETUDP;
331
332/** The minimum UDP packet length (in bytes). (RTNETUDP::uh_ulen) */
333#define RTNETUDP_MIN_LEN (8)
334
335RTDECL(uint16_t) RTNetUDPChecksum(uint32_t u32Sum, PCRTNETUDP pUdpHdr);
336RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t u32Sum);
337RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData);
338RTDECL(bool) RTNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, size_t cbPktMax);
339RTDECL(bool) RTNetIPv4IsUDPValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData, size_t cbPktMax, bool fChecksum);
340
341/**
342 * IPv4 BOOTP / DHCP packet.
343 */
344#pragma pack(1)
345typedef struct RTNETBOOTP
346{
347 /** 00 - The packet opcode (RTNETBOOTP_OP_*). */
348 uint8_t bp_op;
349 /** 01 - Hardware address type. Same as RTNETARPHDR::ar_htype. */
350 uint8_t bp_htype;
351 /** 02 - Hardware address length. */
352 uint8_t bp_hlen;
353 /** 03 - Gateway hops. */
354 uint8_t bp_hops;
355 /** 04 - Transaction ID. */
356 uint32_t bp_xid;
357 /** 08 - Seconds since boot started. */
358 uint16_t bp_secs;
359 /** 0a - Unused (BOOTP) / Flags (DHCP) (RTNET_DHCP_FLAGS_*). */
360 uint16_t bp_flags;
361 /** 0c - Client IPv4 address. */
362 RTNETADDRIPV4 bp_ciaddr;
363 /** 10 - Your IPv4 address. */
364 RTNETADDRIPV4 bp_yiaddr;
365 /** 14 - Server IPv4 address. */
366 RTNETADDRIPV4 bp_siaddr;
367 /** 18 - Gateway IPv4 address. */
368 RTNETADDRIPV4 bp_giaddr;
369 /** 1c - Client hardware address. */
370 union
371 {
372 uint8_t au8[16];
373 RTMAC Mac;
374 } bp_chaddr;
375 /** 2c - Server name. */
376 uint8_t bp_sname[64];
377 /** 6c - File name / more DHCP options. */
378 uint8_t bp_file[128];
379 /** ec - Vendor specific area (BOOTP) / Options (DHCP).
380 * @remark This is really 312 bytes in the DHCP version. */
381 union
382 {
383 uint8_t au8[128];
384 struct DHCP
385 {
386 /** ec - The DHCP cookie (RTNET_DHCP_COOKIE). */
387 uint32_t dhcp_cookie;
388 /** f0 - The DHCP options. */
389 uint8_t dhcp_opts[124];
390 } Dhcp;
391 } bp_vend;
392
393} RTNETBOOTP;
394#pragma pack()
395AssertCompileSize(RTNETBOOTP, 0xec + 128);
396/** Pointer to a BOOTP / DHCP packet. */
397typedef RTNETBOOTP *PRTNETBOOTP;
398/** Pointer to a const BOOTP / DHCP packet. */
399typedef RTNETBOOTP const *PCRTNETBOOTP;
400
401/** Minimum BOOTP packet length. For quick validation, no standard thing really. */
402#define RTNETBOOTP_MIN_LEN 0xec
403/** Minimum DHCP packet length. For quick validation, no standard thing really. */
404#define RTNETBOOTP_DHCP_MIN_LEN 0xf1
405
406/** The normal size of the a DHCP packet (i.e. a RTNETBOOTP).
407 * Same as RTNET_DHCP_OPT_SIZE, just expressed differently. */
408#define RTNET_DHCP_NORMAL_SIZE (0xec + 4 + RTNET_DHCP_OPT_SIZE)
409/** The normal size of RTNETBOOTP::bp_vend::Dhcp::dhcp_opts. */
410#define RTNET_DHCP_OPT_SIZE (312 - 4)
411
412/** @name BOOTP packet opcode values
413 * @{ */
414#define RTNETBOOTP_OP_REQUEST 1
415#define RTNETBOOTP_OP_REPLY 2
416/** @} */
417
418/** @name DHCP flags (RTNETBOOTP::bp_flags)
419 * @{ */
420#define RTNET_DHCP_FLAGS_NO_BROADCAST UINT16_C(0x8000) /** @todo check test!!! */
421/** @} */
422
423/** The DHCP cookie (network endian). */
424#define RTNET_DHCP_COOKIE UINT32_C(0x63825363)
425
426/**
427 * An IPv4 DHCP option header.
428 */
429typedef struct RTNETDHCPOPT
430{
431 /** 00 - The DHCP option. */
432 uint8_t dhcp_opt;
433 /** 01 - The data length (excluding this header). */
434 uint8_t dhcp_len;
435 /* 02 - The option data follows here, optional and of variable length. */
436} RTNETDHCPOPT;
437AssertCompileSize(RTNETDHCPOPT, 2);
438/** Pointer to a DHCP option header. */
439typedef RTNETDHCPOPT *PRTNETDHCPOPT;
440/** Pointer to a const DHCP option header. */
441typedef RTNETDHCPOPT const *PCRTNETDHCPOPT;
442
443/** @name DHCP options
444 * @{ */
445/** 1 byte padding, this has no dhcp_len field. */
446#define RTNET_DHCP_OPT_PAD 0
447
448/** The subnet mask. */
449#define RTNET_DHCP_OPT_SUBNET_MASK 1
450/** The time offset. */
451#define RTNET_DHCP_OPT_TIME_OFFSET 2
452/** The routers for the subnet. */
453#define RTNET_DHCP_OPT_ROUTERS 3
454/** Domain Name Server. */
455#define RTNET_DHCP_OPT_DNS 6
456/** Host name. */
457#define RTNET_DHCP_OPT_HOST_NAME 12
458/** Domain name. */
459#define RTNET_DHCP_OPT_DOMAIN_NAME 15
460
461/** The requested address. */
462#define RTNET_DHCP_OPT_REQ_ADDR 50
463/** The lease time in seconds. */
464#define RTNET_DHCP_OPT_LEASE_TIME 51
465/** Option overload.
466 * Indicates that the bp_file and/or bp_sname holds contains DHCP options. */
467#define RTNET_DHCP_OPT_OPTION_OVERLOAD 52
468/** Have a 8-bit message type value as data, see RTNET_DHCP_MT_*. */
469#define RTNET_DHCP_OPT_MSG_TYPE 53
470/** Server ID. */
471#define RTNET_DHCP_OPT_SERVER_ID 54
472/** Parameter request list. */
473#define RTNET_DHCP_OPT_PARAM_REQ_LIST 55
474/** The maximum DHCP message size a client is willing to accept. */
475#define RTNET_DHCP_OPT_MAX_DHCP_MSG_SIZE 57
476/** Client ID. */
477#define RTNET_DHCP_OPT_CLIENT_ID 61
478/** TFTP server name. */
479#define RTNET_DHCP_OPT_TFTP_SERVER_NAME 66
480/** Bootfile name. */
481#define RTNET_DHCP_OPT_BOOTFILE_NAME 67
482
483/** Marks the end of the DHCP options, this has no dhcp_len field. */
484#define RTNET_DHCP_OPT_END 255
485/** @} */
486
487/** @name DHCP Message Types (option 53)
488 * @{ */
489#define RTNET_DHCP_MT_DISCOVER 1
490#define RTNET_DHCP_MT_OFFER 2
491#define RTNET_DHCP_MT_REQUEST 3
492#define RTNET_DHCP_MT_DECLINE 4
493#define RTNET_DHCP_MT_ACK 5
494#define RTNET_DHCP_MT_NAC 6
495#define RTNET_DHCP_MT_RELEASE 7
496#define RTNET_DHCP_MT_INFORM 8
497/** @} */
498
499/** @name DHCP Flags
500 * @{ */
501#define RTNET_DHCP_FLAG_BROADCAST 0x8000
502/** @} */
503
504RTDECL(bool) RTNetIPv4IsDHCPValid(PCRTNETUDP pUdpHdr, PCRTNETBOOTP pDhcp, size_t cbDhcp, uint8_t *pMsgType);
505
506
507/**
508 * IPv4 DHCP packet.
509 * @deprecated Use RTNETBOOTP.
510 */
511#pragma pack(1)
512typedef struct RTNETDHCP
513{
514 /** 00 - The packet opcode. */
515 uint8_t Op;
516 /** Hardware address type. */
517 uint8_t HType;
518 /** Hardware address length. */
519 uint8_t HLen;
520 uint8_t Hops;
521 uint32_t XID;
522 uint16_t Secs;
523 uint16_t Flags;
524 /** Client IPv4 address. */
525 RTNETADDRIPV4 CIAddr;
526 /** Your IPv4 address. */
527 RTNETADDRIPV4 YIAddr;
528 /** Server IPv4 address. */
529 RTNETADDRIPV4 SIAddr;
530 /** Gateway IPv4 address. */
531 RTNETADDRIPV4 GIAddr;
532 /** Client hardware address. */
533 uint8_t CHAddr[16];
534 /** Server name. */
535 uint8_t SName[64];
536 uint8_t File[128];
537 uint8_t abMagic[4];
538 uint8_t DhcpOpt;
539 uint8_t DhcpLen; /* 1 */
540 uint8_t DhcpReq;
541 uint8_t abOptions[57];
542} RTNETDHCP;
543#pragma pack()
544/** @todo AssertCompileSize(RTNETDHCP, ); */
545/** Pointer to a DHCP packet. */
546typedef RTNETDHCP *PRTNETDHCP;
547/** Pointer to a const DHCP packet. */
548typedef RTNETDHCP const *PCRTNETDHCP;
549
550
551/**
552 * TCP packet.
553 */
554#pragma pack(1)
555typedef struct RTNETTCP
556{
557 /** 00 - The source port. */
558 uint16_t th_sport;
559 /** 02 - The destination port. */
560 uint16_t th_dport;
561 /** 04 - The sequence number. */
562 uint32_t th_seq;
563 /** 08 - The acknowledgement number. */
564 uint32_t th_ack;
565#ifdef RT_BIG_ENDIAN
566 unsigned int th_win : 16;
567 unsigned int th_flags : 8;
568 unsigned int th_off : 4;
569 unsigned int th_x2 : 4;
570#else
571 /** 0c:0 - Reserved. */
572 unsigned int th_x2 : 4;
573 /** 0c:4 - The data offset given as a dword count from the start of this header. */
574 unsigned int th_off : 4;
575 /** 0d - flags. */
576 unsigned int th_flags : 8;
577 /** 0e - The window. */
578 unsigned int th_win : 16;
579#endif
580 /** 10 - The checksum of the pseudo header, the TCP header and the data. */
581 uint16_t th_sum;
582 /** 12 - The urgent pointer. */
583 uint16_t th_urp;
584 /* (options follows here and then the data (aka text).) */
585} RTNETTCP;
586#pragma pack()
587AssertCompileSize(RTNETTCP, 20);
588/** Pointer to a TCP packet. */
589typedef RTNETTCP *PRTNETTCP;
590/** Pointer to a const TCP packet. */
591typedef RTNETTCP const *PCRTNETTCP;
592
593/** The minimum TCP header length (in bytes). (RTNETTCP::th_off * 4) */
594#define RTNETTCP_MIN_LEN (20)
595
596/** @name TCP flags (RTNETTCP::th_flags)
597 * @{ */
598#define RTNETTCP_F_FIN 0x01
599#define RTNETTCP_F_SYN 0x02
600#define RTNETTCP_F_RST 0x04
601#define RTNETTCP_F_PSH 0x08
602#define RTNETTCP_F_ACK 0x10
603#define RTNETTCP_F_URG 0x20
604#define RTNETTCP_F_ECE 0x40
605#define RTNETTCP_F_CWR 0x80
606/** @} */
607
608RTDECL(uint16_t) RTNetTCPChecksum(uint32_t u32Sum, PCRTNETTCP pTcpHdr, void const *pvData, size_t cbData);
609RTDECL(uint32_t) RTNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr, uint32_t u32Sum);
610RTDECL(uint16_t) RTNetIPv4TCPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, void const *pvData);
611RTDECL(bool) RTNetIPv4IsTCPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, size_t cbHdrMax, size_t cbPktMax);
612RTDECL(bool) RTNetIPv4IsTCPValid(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, size_t cbHdrMax, void const *pvData,
613 size_t cbPktMax, bool fChecksum);
614
615
616/**
617 * IPv4 ICMP packet header.
618 */
619#pragma pack(1)
620typedef struct RTNETICMPV4HDR
621{
622 /** 00 - The ICMP message type. */
623 uint8_t icmp_type;
624 /** 01 - Type specific code that further qualifies the message. */
625 uint8_t icmp_code;
626 /** 02 - Checksum of the ICMP message. */
627 uint16_t icmp_cksum;
628} RTNETICMPV4HDR;
629#pragma pack()
630AssertCompileSize(RTNETICMPV4HDR, 4);
631/** Pointer to an ICMP packet header. */
632typedef RTNETICMPV4HDR *PRTNETICMPV4HDR;
633/** Pointer to a const ICMP packet header. */
634typedef RTNETICMPV4HDR const *PCRTNETICMPV4HDR;
635
636/** @name ICMP (v4) message types.
637 * @{ */
638#define RTNETICMPV4_TYPE_ECHO_REPLY 0
639#define RTNETICMPV4_TYPE_ECHO_REQUEST 8
640#define RTNETICMPV4_TYPE_TRACEROUTE 30
641/** @} */
642
643/**
644 * IPv4 ICMP ECHO Reply & Request packet.
645 */
646#pragma pack(1)
647typedef struct RTNETICMPV4ECHO
648{
649 /** 00 - The ICMP header. */
650 RTNETICMPV4HDR Hdr;
651 /** 04 - The identifier to help the requestor match up the reply.
652 * Can be 0. Typically fixed value. */
653 uint16_t icmp_id;
654 /** 06 - The sequence number to help the requestor match up the reply.
655 * Can be 0. Typically incrementing between requests. */
656 uint16_t icmp_seq;
657 /** 08 - Variable length data that is to be returned unmodified in the reply. */
658 uint8_t icmp_data[1];
659} RTNETICMPV4ECHO;
660#pragma pack()
661AssertCompileSize(RTNETICMPV4ECHO, 9);
662/** Pointer to an ICMP ECHO packet. */
663typedef RTNETICMPV4ECHO *PRTNETICMPV4ECHO;
664/** Pointer to a const ICMP ECHO packet. */
665typedef RTNETICMPV4ECHO const *PCRTNETICMPV4ECHO;
666
667/**
668 * IPv4 ICMP TRACEROUTE packet.
669 * This is an reply to an IP packet with the traceroute option set.
670 */
671#pragma pack(1)
672typedef struct RTNETICMPV4TRACEROUTE
673{
674 /** 00 - The ICMP header. */
675 RTNETICMPV4HDR Hdr;
676 /** 04 - Identifier copied from the traceroute option's ID number. */
677 uint16_t icmp_id;
678 /** 06 - Unused. (Possibly an icmp_seq?) */
679 uint16_t icmp_void;
680 /** 08 - Outbound hop count. From the IP packet causing this message. */
681 uint16_t icmp_ohc;
682 /** 0a - Return hop count. From the IP packet causing this message. */
683 uint16_t icmp_rhc;
684 /** 0c - Output link speed, 0 if not known. */
685 uint32_t icmp_speed;
686 /** 10 - Output link MTU, 0 if not known. */
687 uint32_t icmp_mtu;
688} RTNETICMPV4TRACEROUTE;
689#pragma pack()
690AssertCompileSize(RTNETICMPV4TRACEROUTE, 20);
691/** Pointer to an ICMP TRACEROUTE packet. */
692typedef RTNETICMPV4TRACEROUTE *PRTNETICMPV4TRACEROUTE;
693/** Pointer to a const ICMP TRACEROUTE packet. */
694typedef RTNETICMPV4TRACEROUTE const *PCRTNETICMPV4TRACEROUTE;
695
696/** @todo add more ICMPv4 as needed. */
697
698/**
699 * IPv4 ICMP union packet.
700 */
701typedef union RTNETICMPV4
702{
703 RTNETICMPV4HDR Hdr;
704 RTNETICMPV4ECHO Echo;
705 RTNETICMPV4TRACEROUTE Traceroute;
706} RTNETICMPV4;
707/** Pointer to an ICMP union packet. */
708typedef RTNETICMPV4 *PRTNETICMPV4;
709/** Pointer to a const ICMP union packet. */
710typedef RTNETICMPV4 const *PCRTNETICMPV4;
711
712
713/** @todo add ICMPv6 when needed. */
714
715
716/**
717 * Ethernet ARP header.
718 */
719#pragma pack(1)
720typedef struct RTNETARPHDR
721{
722 /** The hardware type. */
723 uint16_t ar_htype;
724 /** The protocol type (ethertype). */
725 uint16_t ar_ptype;
726 /** The hardware address length. */
727 uint8_t ar_hlen;
728 /** The protocol address length. */
729 uint8_t ar_plen;
730 /** The operation. */
731 uint16_t ar_oper;
732} RTNETARPHDR;
733#pragma pack()
734AssertCompileSize(RTNETARPHDR, 8);
735/** Pointer to an ethernet ARP header. */
736typedef RTNETARPHDR *PRTNETARPHDR;
737/** Pointer to a const ethernet ARP header. */
738typedef RTNETARPHDR const *PCRTNETARPHDR;
739
740/** ARP hardware type - ethernet. */
741#define RTNET_ARP_ETHER UINT16_C(1)
742
743/** @name ARP operations
744 * @{ */
745#define RTNET_ARPOP_REQUEST UINT16_C(1) /**< Request hardware address given a protocol address (ARP). */
746#define RTNET_ARPOP_REPLY UINT16_C(2)
747#define RTNET_ARPOP_REVREQUEST UINT16_C(3) /**< Request protocol address given a hardware address (RARP). */
748#define RTNET_ARPOP_REVREPLY UINT16_C(4)
749#define RTNET_ARPOP_INVREQUEST UINT16_C(8) /**< Inverse ARP. */
750#define RTNET_ARPOP_INVREPLY UINT16_C(9)
751/** Check if an ARP operation is a request or not. */
752#define RTNET_ARPOP_IS_REQUEST(Op) ((Op) & 1)
753/** Check if an ARP operation is a reply or not. */
754#define RTNET_ARPOP_IS_REPLY(Op) (!RTNET_ARPOP_IS_REQUEST(Op))
755/** @} */
756
757
758/**
759 * Ethernet IPv4 + 6-byte MAC ARP request packet.
760 */
761#pragma pack(1)
762typedef struct RTNETARPIPV4
763{
764 /** ARP header. */
765 RTNETARPHDR Hdr;
766 /** The sender hardware address. */
767 RTMAC ar_sha;
768 /** The sender protocol address. */
769 RTNETADDRIPV4 ar_spa;
770 /** The target hardware address. */
771 RTMAC ar_tha;
772 /** The arget protocol address. */
773 RTNETADDRIPV4 ar_tpa;
774} RTNETARPIPV4;
775#pragma pack()
776AssertCompileSize(RTNETARPIPV4, 8+6+4+6+4);
777/** Pointer to an ethernet IPv4+MAC ARP request packet. */
778typedef RTNETARPIPV4 *PRTNETARPIPV4;
779/** Pointer to a const ethernet IPv4+MAC ARP request packet. */
780typedef RTNETARPIPV4 const *PCRTNETARPIPV4;
781
782
783/** @todo RTNETNDP (IPv6)*/
784
785
786/** @} */
787
788RT_C_DECLS_END
789
790#endif
791
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette