2 * IPRT - Network Protocols.
6 * Copyright (C) 2008-2016 Oracle Corporation
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.
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.
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.
29 #include <iprt/cdefs.h>
30 #include <iprt/types.h>
31 #include <iprt/assert.h>
36 /** @defgroup grp_rt_net RTNet - Network Protocols
42 * Converts an stringified Ethernet MAC address into the RTMAC representation.
44 * @todo This should be move to some generic part of the runtime.
46 * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on
49 * @param pszAddr The address string to convert.
50 * @param pMacAddr Where to store the result.
52 RTDECL(int) RTNetStrToMacAddr(const char *pszAddr
, PRTMAC pMacAddr
);
57 typedef RTUINT32U RTNETADDRIPV4
;
58 AssertCompileSize(RTNETADDRIPV4
, 4);
59 /** Pointer to a IPv4 address. */
60 typedef RTNETADDRIPV4
*PRTNETADDRIPV4
;
61 /** Pointer to a const IPv4 address. */
62 typedef RTNETADDRIPV4
const *PCRTNETADDRIPV4
;
65 * Tests if the given string is an IPv4 address.
68 * @param pcszAddr String which may be an IPv4 address.
70 RTDECL(bool) RTNetIsIPv4AddrStr(const char *pcszAddr
);
73 * Tests if the given string is a wildcard IPv4 address.
76 * @param pcszAddr String which may be an IPv4 address.
78 RTDECL(bool) RTNetStrIsIPv4AddrAny(const char *pcszAddr
);
81 * Parses dotted-decimal IPv4 address into RTNETADDRIPV4 representation.
83 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
86 * @param pcszAddr The value to convert.
87 * @param ppszNext Where to store the pointer to the first char
88 * following the address. (Optional)
89 * @param pAddr Where to store the result.
91 RTDECL(int) RTNetStrToIPv4AddrEx(const char *pcszAddr
, PRTNETADDRIPV4 pAddr
, char **ppszNext
);
94 * Parses dotted-decimal IPv4 address into RTNETADDRIPV4 representation.
95 * Leading and trailing whitespace is ignored.
97 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
100 * @param pcszAddr The value to convert.
101 * @param pAddr Where to store the result.
103 RTDECL(int) RTNetStrToIPv4Addr(const char *pcszAddr
, PRTNETADDRIPV4 pAddr
);
106 * Verifies that RTNETADDRIPV4 is a valid contiguous netmask and
107 * computes its prefix length.
109 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
112 * @param pMask The netmask to verify and convert.
113 * @param piPrefix Where to store the prefix length. (Optional)
115 RTDECL(int) RTNetMaskToPrefixIPv4(PCRTNETADDRIPV4 pMask
, int *piPrefix
);
118 * Computes netmask corresponding to the prefix length.
120 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
123 * @param iPrefix The prefix to convert.
124 * @param pMask Where to store the netmask.
126 RTDECL(int) RTNetPrefixToMaskIPv4(int iPrefix
, PRTNETADDRIPV4 pMask
);
132 typedef RTUINT128U RTNETADDRIPV6
;
133 AssertCompileSize(RTNETADDRIPV6
, 16);
134 /** Pointer to a IPv6 address. */
135 typedef RTNETADDRIPV6
*PRTNETADDRIPV6
;
136 /** Pointer to a const IPv6 address. */
137 typedef RTNETADDRIPV6
const *PCRTNETADDRIPV6
;
140 * Tests if the given string is a valid IPv6 address.
142 * @returns @c true if it is, @c false if not.
143 * @param pszAddress String which may be an IPv6 address.
145 RTDECL(bool) RTNetIsIPv6AddrStr(const char *pszAddress
);
148 * Tests if the given string is a wildcard IPv6 address.
150 * @returns @c true if it is, @c false if not.
151 * @param pszAddress String which may be an IPv6 address.
153 RTDECL(bool) RTNetStrIsIPv6AddrAny(const char *pszAddress
);
156 * Parses IPv6 address into RTNETADDRIPV6 representation.
158 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
161 * @param pcszAddr The value to convert.
162 * @param ppszNext Where to store the pointer to the first char
163 * following the address. (Optional)
164 * @param pAddr Where to store the result.
166 RTDECL(int) RTNetStrToIPv6AddrEx(const char *pcszAddr
, PRTNETADDRIPV6 pAddr
, char **ppszNext
);
169 * Parses IPv6 address into RTNETADDRIPV6 representation.
170 * Leading and trailing whitespace is ignored.
172 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
175 * @param pcszAddr The value to convert.
176 * @param ppszZone Where to store the pointer to the first char
177 * of the zone id. NULL is stored if there is
179 * @param pAddr Where to store the result.
181 RTDECL(int) RTNetStrToIPv6Addr(const char *pcszAddr
, PRTNETADDRIPV6 pAddr
, char **ppszZone
);
184 * Verifies that RTNETADDRIPV6 is a valid contiguous netmask and
185 * computes its prefix length.
187 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
190 * @param pMask The netmask to verify and convert.
191 * @param piPrefix Where to store the prefix length. (Optional)
193 RTDECL(int) RTNetMaskToPrefixIPv6(PCRTNETADDRIPV6 pMask
, int *piPrefix
);
196 * Computes netmask corresponding to the prefix length.
198 * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
201 * @param iPrefix The prefix to convert.
202 * @param pMask Where to store the netmask.
204 RTDECL(int) RTNetPrefixToMaskIPv6(int iPrefix
, PRTNETADDRIPV6 pMask
);
211 typedef struct RTNETADDRIPX
213 /** The network ID. */
215 /** The node ID. (Defaults to the MAC address apparently.) */
219 AssertCompileSize(RTNETADDRIPX
, 4+6);
220 /** Pointer to an IPX address. */
221 typedef RTNETADDRIPX
*PRTNETADDRIPX
;
222 /** Pointer to a const IPX address. */
223 typedef RTNETADDRIPX
const *PCRTNETADDRIPX
;
226 * Network address union.
228 * @remarks The size of this structure may change in the future.
230 typedef union RTNETADDRU
242 #ifndef IPv6 /* Work around X11 and RDP defining IPv6 to 1. */
248 /** MAC address view. */
251 AssertCompileSize(RTNETADDRU
, 16);
252 /** Pointer to an address union. */
253 typedef RTNETADDRU
*PRTNETADDRU
;
254 /** Pointer to a const address union. */
255 typedef RTNETADDRU
const *PCRTNETADDRU
;
258 * Network address type.
260 * @remarks The value assignments may change in the future.
262 typedef enum RTNETADDRTYPE
264 /** The invalid 0 entry. */
265 RTNETADDRTYPE_INVALID
= 0,
274 /** The end of the valid values. */
276 /** The usual 32-bit hack. */
277 RTNETADDRTYPE_32_BIT_HACK
= 0x7fffffff
279 /** Pointer to a network address type. */
280 typedef RTNETADDRTYPE
*PRTNETADDRTYPE
;
281 /** Pointer to a const network address type. */
282 typedef RTNETADDRTYPE
const *PCRTNETADDRTYPE
;
287 * @remarks The size and type values may change.
289 typedef struct RTNETADDR
291 /** The address union. */
293 /** Indicates which view of @a u that is valid. */
294 RTNETADDRTYPE enmType
;
295 /** The port number for IPv4 and IPv6 addresses. This is set to
296 * RTNETADDR_NA_PORT if not applicable. */
299 /** Pointer to a network address. */
300 typedef RTNETADDR
*PRTNETADDR
;
301 /** Pointer to a const network address. */
302 typedef RTNETADDR
const *PCRTNETADDR
;
304 /** The not applicable value of RTNETADDR::uPort value use to inid. */
305 #define RTNETADDR_PORT_NA UINT32_MAX
311 typedef struct RTNETETHERHDR
315 /** Ethernet frame type or frame size, depending on the kind of ethernet.
316 * This is big endian on the wire. */
320 AssertCompileSize(RTNETETHERHDR
, 14);
321 /** Pointer to an ethernet header. */
322 typedef RTNETETHERHDR
*PRTNETETHERHDR
;
323 /** Pointer to a const ethernet header. */
324 typedef RTNETETHERHDR
const *PCRTNETETHERHDR
;
326 /** @name EtherType (RTNETETHERHDR::EtherType)
328 #define RTNET_ETHERTYPE_IPV4 UINT16_C(0x0800)
329 #define RTNET_ETHERTYPE_ARP UINT16_C(0x0806)
330 #define RTNET_ETHERTYPE_IPV6 UINT16_C(0x86dd)
331 #define RTNET_ETHERTYPE_VLAN UINT16_C(0x8100)
332 #define RTNET_ETHERTYPE_IPX_1 UINT16_C(0x8037)
333 #define RTNET_ETHERTYPE_IPX_2 UINT16_C(0x8137)
334 #define RTNET_ETHERTYPE_IPX_3 UINT16_C(0x8138)
340 * All is bigendian on the wire.
343 typedef struct RTNETIPV4
346 unsigned int ip_v
: 4;
347 unsigned int ip_hl
: 4;
348 unsigned int ip_tos
: 8;
349 unsigned int ip_len
: 16;
351 /** 00:0 - Header length given as a 32-bit word count. */
352 unsigned int ip_hl
: 4;
353 /** 00:4 - Header version. */
354 unsigned int ip_v
: 4;
355 /** 01 - Type of service. */
356 unsigned int ip_tos
: 8;
357 /** 02 - Total length (header + data). */
358 unsigned int ip_len
: 16;
360 /** 04 - Packet idenficiation. */
362 /** 06 - Offset if fragmented. */
364 /** 08 - Time to live. */
366 /** 09 - Protocol. */
368 /** 0a - Header check sum. */
370 /** 0c - Source address. */
371 RTNETADDRIPV4 ip_src
;
372 /** 10 - Destination address. */
373 RTNETADDRIPV4 ip_dst
;
374 /** 14 - Options (optional). */
375 uint32_t ip_options
[1];
378 AssertCompileSize(RTNETIPV4
, 6 * 4);
379 /** Pointer to a IPv4 header. */
380 typedef RTNETIPV4
*PRTNETIPV4
;
381 /** Pointer to a const IPv4 header. */
382 typedef RTNETIPV4
const *PCRTNETIPV4
;
384 /** The minimum IPv4 header length (in bytes).
385 * Up to and including RTNETIPV4::ip_dst. */
386 #define RTNETIPV4_MIN_LEN (20)
389 /** @name IPv4 Protocol Numbers
392 #define RTNETIPV4_PROT_ICMP (1)
394 #define RTNETIPV4_PROT_TCP (6)
396 #define RTNETIPV4_PROT_UDP (17)
399 /** @name Common IPv4 Port Assignments
402 /** Boostrap Protocol / DHCP) Server. */
403 #define RTNETIPV4_PORT_BOOTPS (67)
404 /** Boostrap Protocol / DHCP) Client. */
405 #define RTNETIPV4_PORT_BOOTPC (68)
410 /** IPv4: Don't fragment */
411 #define RTNETIPV4_FLAGS_DF (0x4000)
412 /** IPv4: More fragments */
413 #define RTNETIPV4_FLAGS_MF (0x2000)
416 RTDECL(uint16_t) RTNetIPv4HdrChecksum(PCRTNETIPV4 pIpHdr
);
417 RTDECL(bool) RTNetIPv4IsHdrValid(PCRTNETIPV4 pIpHdr
, size_t cbHdrMax
, size_t cbPktMax
, bool fChecksum
);
418 RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr
);
419 RTDECL(uint32_t) RTNetIPv4PseudoChecksumBits(RTNETADDRIPV4 SrcAddr
, RTNETADDRIPV4 DstAddr
, uint8_t bProtocol
, uint16_t cbPkt
);
420 RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData
, size_t cbData
, uint32_t u32Sum
, bool *pfOdd
);
421 RTDECL(uint16_t) RTNetIPv4FinalizeChecksum(uint32_t u32Sum
);
426 * All is bigendian on the wire.
429 typedef struct RTNETIPV6
431 /** Version (4 bits), Traffic Class (8 bits) and Flow Lable (20 bits).
432 * @todo this is probably mislabeled - ip6_flow vs. ip6_vfc, fix later. */
434 /** 04 - Payload length, including extension headers. */
436 /** 06 - Next header type (RTNETIPV4_PROT_XXX). */
438 /** 07 - Hop limit. */
440 /** xx - Source address. */
441 RTNETADDRIPV6 ip6_src
;
442 /** xx - Destination address. */
443 RTNETADDRIPV6 ip6_dst
;
446 AssertCompileSize(RTNETIPV6
, 8 + 16 + 16);
447 /** Pointer to a IPv6 header. */
448 typedef RTNETIPV6
*PRTNETIPV6
;
449 /** Pointer to a const IPv6 header. */
450 typedef RTNETIPV6
const *PCRTNETIPV6
;
452 /** The minimum IPv6 header length (in bytes).
453 * Up to and including RTNETIPV6::ip6_dst. */
454 #define RTNETIPV6_MIN_LEN (40)
455 #define RTNETIPV6_ICMPV6_ND_WITH_LLA_OPT_MIN_LEN (32)
457 RTDECL(uint32_t) RTNetIPv6PseudoChecksum(PCRTNETIPV6 pIpHdr
);
458 RTDECL(uint32_t) RTNetIPv6PseudoChecksumEx(PCRTNETIPV6 pIpHdr
, uint8_t bProtocol
, uint16_t cbPkt
);
459 RTDECL(uint32_t) RTNetIPv6PseudoChecksumBits(PCRTNETADDRIPV6 pSrcAddr
, PCRTNETADDRIPV6 pDstAddr
,
460 uint8_t bProtocol
, uint16_t cbPkt
);
467 typedef struct RTNETUDP
469 /** The source port. */
471 /** The destination port. */
473 /** The length of the UDP header and associated data. */
475 /** The checksum of the pseudo header, the UDP header and the data. */
479 AssertCompileSize(RTNETUDP
, 8);
480 /** Pointer to an UDP header. */
481 typedef RTNETUDP
*PRTNETUDP
;
482 /** Pointer to a const UDP header. */
483 typedef RTNETUDP
const *PCRTNETUDP
;
485 /** The minimum UDP packet length (in bytes). (RTNETUDP::uh_ulen) */
486 #define RTNETUDP_MIN_LEN (8)
488 RTDECL(uint16_t) RTNetUDPChecksum(uint32_t u32Sum
, PCRTNETUDP pUdpHdr
);
489 RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr
, uint32_t u32Sum
);
490 RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr
, PCRTNETUDP pUdpHdr
, void const *pvData
);
491 RTDECL(bool) RTNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr
, PCRTNETUDP pUdpHdr
, size_t cbPktMax
);
492 RTDECL(bool) RTNetIPv4IsUDPValid(PCRTNETIPV4 pIpHdr
, PCRTNETUDP pUdpHdr
, void const *pvData
, size_t cbPktMax
, bool fChecksum
);
496 * IPv4 BOOTP / DHCP packet.
499 typedef struct RTNETBOOTP
501 /** 00 - The packet opcode (RTNETBOOTP_OP_*). */
503 /** 01 - Hardware address type. Same as RTNETARPHDR::ar_htype. */
505 /** 02 - Hardware address length. */
507 /** 03 - Gateway hops. */
509 /** 04 - Transaction ID. */
511 /** 08 - Seconds since boot started. */
513 /** 0a - Unused (BOOTP) / Flags (DHCP) (RTNET_DHCP_FLAGS_*). */
515 /** 0c - Client IPv4 address. */
516 RTNETADDRIPV4 bp_ciaddr
;
517 /** 10 - Your IPv4 address. */
518 RTNETADDRIPV4 bp_yiaddr
;
519 /** 14 - Server IPv4 address. */
520 RTNETADDRIPV4 bp_siaddr
;
521 /** 18 - Gateway IPv4 address. */
522 RTNETADDRIPV4 bp_giaddr
;
523 /** 1c - Client hardware address. */
529 /** 2c - Server name. */
530 uint8_t bp_sname
[64];
531 /** 6c - File name / more DHCP options. */
532 uint8_t bp_file
[128];
533 /** ec - Vendor specific area (BOOTP) / Options (DHCP).
534 * @remark This is really 312 bytes in the DHCP version. */
540 /** ec - The DHCP cookie (RTNET_DHCP_COOKIE). */
541 uint32_t dhcp_cookie
;
542 /** f0 - The DHCP options. */
543 uint8_t dhcp_opts
[124];
549 AssertCompileSize(RTNETBOOTP
, 0xec + 128);
550 /** Pointer to a BOOTP / DHCP packet. */
551 typedef RTNETBOOTP
*PRTNETBOOTP
;
552 /** Pointer to a const BOOTP / DHCP packet. */
553 typedef RTNETBOOTP
const *PCRTNETBOOTP
;
555 /** Minimum BOOTP packet length. For quick validation, no standard thing really. */
556 #define RTNETBOOTP_MIN_LEN 0xec
557 /** Minimum DHCP packet length. For quick validation, no standard thing really. */
558 #define RTNETBOOTP_DHCP_MIN_LEN 0xf1
560 /** The normal size of the a DHCP packet (i.e. a RTNETBOOTP).
561 * Same as RTNET_DHCP_OPT_SIZE, just expressed differently. */
562 #define RTNET_DHCP_NORMAL_SIZE (0xec + 4 + RTNET_DHCP_OPT_SIZE)
563 /** The normal size of RTNETBOOTP::bp_vend::Dhcp::dhcp_opts. */
564 #define RTNET_DHCP_OPT_SIZE (312 - 4)
566 /** @name BOOTP packet opcode values
568 #define RTNETBOOTP_OP_REQUEST 1
569 #define RTNETBOOTP_OP_REPLY 2
572 /** @name DHCP flags (RTNETBOOTP::bp_flags)
574 #define RTNET_DHCP_FLAGS_NO_BROADCAST UINT16_C(0x8000) /** @todo check test!!! */
577 /** The DHCP cookie (network endian). */
578 #define RTNET_DHCP_COOKIE UINT32_C(0x63825363)
581 * An IPv4 DHCP option header.
583 typedef struct RTNETDHCPOPT
585 /** 00 - The DHCP option. */
587 /** 01 - The data length (excluding this header). */
589 /* 02 - The option data follows here, optional and of variable length. */
591 AssertCompileSize(RTNETDHCPOPT
, 2);
592 /** Pointer to a DHCP option header. */
593 typedef RTNETDHCPOPT
*PRTNETDHCPOPT
;
594 /** Pointer to a const DHCP option header. */
595 typedef RTNETDHCPOPT
const *PCRTNETDHCPOPT
;
597 /** @name DHCP options
599 /** 1 byte padding, this has no dhcp_len field. */
600 #define RTNET_DHCP_OPT_PAD 0
602 /** The subnet mask. */
603 #define RTNET_DHCP_OPT_SUBNET_MASK 1
604 /** The time offset. */
605 #define RTNET_DHCP_OPT_TIME_OFFSET 2
606 /** The routers for the subnet. */
607 #define RTNET_DHCP_OPT_ROUTERS 3
608 /** Domain Name Server. */
609 #define RTNET_DHCP_OPT_DNS 6
611 #define RTNET_DHCP_OPT_HOST_NAME 12
613 #define RTNET_DHCP_OPT_DOMAIN_NAME 15
615 /** The requested address. */
616 #define RTNET_DHCP_OPT_REQ_ADDR 50
617 /** The lease time in seconds. */
618 #define RTNET_DHCP_OPT_LEASE_TIME 51
620 * Indicates that the bp_file and/or bp_sname holds contains DHCP options. */
621 #define RTNET_DHCP_OPT_OPTION_OVERLOAD 52
622 /** Have a 8-bit message type value as data, see RTNET_DHCP_MT_*. */
623 #define RTNET_DHCP_OPT_MSG_TYPE 53
625 #define RTNET_DHCP_OPT_SERVER_ID 54
626 /** Parameter request list. */
627 #define RTNET_DHCP_OPT_PARAM_REQ_LIST 55
628 /** The maximum DHCP message size a client is willing to accept. */
629 #define RTNET_DHCP_OPT_MAX_DHCP_MSG_SIZE 57
631 #define RTNET_DHCP_OPT_CLIENT_ID 61
632 /** TFTP server name. */
633 #define RTNET_DHCP_OPT_TFTP_SERVER_NAME 66
634 /** Bootfile name. */
635 #define RTNET_DHCP_OPT_BOOTFILE_NAME 67
637 /** Marks the end of the DHCP options, this has no dhcp_len field. */
638 #define RTNET_DHCP_OPT_END 255
641 /** @name DHCP Message Types (option 53)
643 #define RTNET_DHCP_MT_DISCOVER 1
644 #define RTNET_DHCP_MT_OFFER 2
645 #define RTNET_DHCP_MT_REQUEST 3
646 #define RTNET_DHCP_MT_DECLINE 4
647 #define RTNET_DHCP_MT_ACK 5
648 #define RTNET_DHCP_MT_NAC 6
649 #define RTNET_DHCP_MT_RELEASE 7
650 #define RTNET_DHCP_MT_INFORM 8
655 #define RTNET_DHCP_FLAG_BROADCAST 0x8000
658 RTDECL(bool) RTNetIPv4IsDHCPValid(PCRTNETUDP pUdpHdr
, PCRTNETBOOTP pDhcp
, size_t cbDhcp
, uint8_t *pMsgType
);
663 * @deprecated Use RTNETBOOTP.
666 typedef struct RTNETDHCP
668 /** 00 - The packet opcode. */
670 /** Hardware address type. */
672 /** Hardware address length. */
678 /** Client IPv4 address. */
679 RTNETADDRIPV4 CIAddr
;
680 /** Your IPv4 address. */
681 RTNETADDRIPV4 YIAddr
;
682 /** Server IPv4 address. */
683 RTNETADDRIPV4 SIAddr
;
684 /** Gateway IPv4 address. */
685 RTNETADDRIPV4 GIAddr
;
686 /** Client hardware address. */
693 uint8_t DhcpLen
; /* 1 */
695 uint8_t abOptions
[57];
698 /** @todo AssertCompileSize(RTNETDHCP, ); */
699 /** Pointer to a DHCP packet. */
700 typedef RTNETDHCP
*PRTNETDHCP
;
701 /** Pointer to a const DHCP packet. */
702 typedef RTNETDHCP
const *PCRTNETDHCP
;
709 typedef struct RTNETTCP
711 /** 00 - The source port. */
713 /** 02 - The destination port. */
715 /** 04 - The sequence number. */
717 /** 08 - The acknowledgement number. */
720 unsigned int th_win
: 16;
721 unsigned int th_flags
: 8;
722 unsigned int th_off
: 4;
723 unsigned int th_x2
: 4;
725 /** 0c:0 - Reserved. */
726 unsigned int th_x2
: 4;
727 /** 0c:4 - The data offset given as a dword count from the start of this header. */
728 unsigned int th_off
: 4;
730 unsigned int th_flags
: 8;
731 /** 0e - The window. */
732 unsigned int th_win
: 16;
734 /** 10 - The checksum of the pseudo header, the TCP header and the data. */
736 /** 12 - The urgent pointer. */
738 /* (options follows here and then the data (aka text).) */
741 AssertCompileSize(RTNETTCP
, 20);
742 /** Pointer to a TCP packet. */
743 typedef RTNETTCP
*PRTNETTCP
;
744 /** Pointer to a const TCP packet. */
745 typedef RTNETTCP
const *PCRTNETTCP
;
747 /** The minimum TCP header length (in bytes). (RTNETTCP::th_off * 4) */
748 #define RTNETTCP_MIN_LEN (20)
750 /** @name TCP flags (RTNETTCP::th_flags)
752 #define RTNETTCP_F_FIN 0x01
753 #define RTNETTCP_F_SYN 0x02
754 #define RTNETTCP_F_RST 0x04
755 #define RTNETTCP_F_PSH 0x08
756 #define RTNETTCP_F_ACK 0x10
757 #define RTNETTCP_F_URG 0x20
758 #define RTNETTCP_F_ECE 0x40
759 #define RTNETTCP_F_CWR 0x80
762 RTDECL(uint16_t) RTNetTCPChecksum(uint32_t u32Sum
, PCRTNETTCP pTcpHdr
, void const *pvData
, size_t cbData
);
763 RTDECL(uint32_t) RTNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr
, uint32_t u32Sum
);
764 RTDECL(uint16_t) RTNetIPv4TCPChecksum(PCRTNETIPV4 pIpHdr
, PCRTNETTCP pTcpHdr
, void const *pvData
);
765 RTDECL(bool) RTNetIPv4IsTCPSizeValid(PCRTNETIPV4 pIpHdr
, PCRTNETTCP pTcpHdr
, size_t cbHdrMax
, size_t cbPktMax
);
766 RTDECL(bool) RTNetIPv4IsTCPValid(PCRTNETIPV4 pIpHdr
, PCRTNETTCP pTcpHdr
, size_t cbHdrMax
, void const *pvData
,
767 size_t cbPktMax
, bool fChecksum
);
771 * IPv4 ICMP packet header.
774 typedef struct RTNETICMPV4HDR
776 /** 00 - The ICMP message type. */
778 /** 01 - Type specific code that further qualifies the message. */
780 /** 02 - Checksum of the ICMP message. */
784 AssertCompileSize(RTNETICMPV4HDR
, 4);
785 /** Pointer to an ICMP packet header. */
786 typedef RTNETICMPV4HDR
*PRTNETICMPV4HDR
;
787 /** Pointer to a const ICMP packet header. */
788 typedef RTNETICMPV4HDR
const *PCRTNETICMPV4HDR
;
790 /** @name ICMP (v4) message types.
792 #define RTNETICMPV4_TYPE_ECHO_REPLY 0
793 #define RTNETICMPV4_TYPE_ECHO_REQUEST 8
794 #define RTNETICMPV4_TYPE_TRACEROUTE 30
798 * IPv4 ICMP ECHO Reply & Request packet.
801 typedef struct RTNETICMPV4ECHO
803 /** 00 - The ICMP header. */
805 /** 04 - The identifier to help the requestor match up the reply.
806 * Can be 0. Typically fixed value. */
808 /** 06 - The sequence number to help the requestor match up the reply.
809 * Can be 0. Typically incrementing between requests. */
811 /** 08 - Variable length data that is to be returned unmodified in the reply. */
812 uint8_t icmp_data
[1];
815 AssertCompileSize(RTNETICMPV4ECHO
, 9);
816 /** Pointer to an ICMP ECHO packet. */
817 typedef RTNETICMPV4ECHO
*PRTNETICMPV4ECHO
;
818 /** Pointer to a const ICMP ECHO packet. */
819 typedef RTNETICMPV4ECHO
const *PCRTNETICMPV4ECHO
;
822 * IPv4 ICMP TRACEROUTE packet.
823 * This is an reply to an IP packet with the traceroute option set.
826 typedef struct RTNETICMPV4TRACEROUTE
828 /** 00 - The ICMP header. */
830 /** 04 - Identifier copied from the traceroute option's ID number. */
832 /** 06 - Unused. (Possibly an icmp_seq?) */
834 /** 08 - Outbound hop count. From the IP packet causing this message. */
836 /** 0a - Return hop count. From the IP packet causing this message. */
838 /** 0c - Output link speed, 0 if not known. */
840 /** 10 - Output link MTU, 0 if not known. */
842 } RTNETICMPV4TRACEROUTE
;
844 AssertCompileSize(RTNETICMPV4TRACEROUTE
, 20);
845 /** Pointer to an ICMP TRACEROUTE packet. */
846 typedef RTNETICMPV4TRACEROUTE
*PRTNETICMPV4TRACEROUTE
;
847 /** Pointer to a const ICMP TRACEROUTE packet. */
848 typedef RTNETICMPV4TRACEROUTE
const *PCRTNETICMPV4TRACEROUTE
;
850 /** @todo add more ICMPv4 as needed. */
853 * IPv4 ICMP union packet.
855 typedef union RTNETICMPV4
858 RTNETICMPV4ECHO Echo
;
859 RTNETICMPV4TRACEROUTE Traceroute
;
861 /** Pointer to an ICMP union packet. */
862 typedef RTNETICMPV4
*PRTNETICMPV4
;
863 /** Pointer to a const ICMP union packet. */
864 typedef RTNETICMPV4
const *PCRTNETICMPV4
;
868 * IPv6 ICMP packet header.
871 typedef struct RTNETICMPV6HDR
873 /** 00 - The ICMPv6 message type. */
875 /** 01 - Type specific code that further qualifies the message. */
877 /** 02 - Checksum of the ICMPv6 message. */
878 uint16_t icmp6_cksum
;
881 AssertCompileSize(RTNETICMPV6HDR
, 4);
882 /** Pointer to an ICMPv6 packet header. */
883 typedef RTNETICMPV6HDR
*PRTNETICMPV6HDR
;
884 /** Pointer to a const ICMP packet header. */
885 typedef RTNETICMPV6HDR
const *PCRTNETICMPV6HDR
;
887 #define RTNETIPV6_PROT_ICMPV6 (58)
889 /** @name Internet Control Message Protocol version 6 (ICMPv6) message types.
891 #define RTNETIPV6_ICMP_TYPE_RS 133
892 #define RTNETIPV6_ICMP_TYPE_RA 134
893 #define RTNETIPV6_ICMP_TYPE_NS 135
894 #define RTNETIPV6_ICMP_TYPE_NA 136
895 #define RTNETIPV6_ICMP_TYPE_RDR 137
898 /** @name Neighbor Discovery option types
900 #define RTNETIPV6_ICMP_ND_SLLA_OPT (1)
901 #define RTNETIPV6_ICMP_ND_TLLA_OPT (2)
904 /** ICMPv6 ND Source/Target Link Layer Address option */
906 typedef struct RTNETNDP_LLA_OPT
914 AssertCompileSize(RTNETNDP_LLA_OPT
, 1+1+6);
916 typedef RTNETNDP_LLA_OPT
*PRTNETNDP_LLA_OPT
;
917 typedef RTNETNDP_LLA_OPT
const *PCRTNETNDP_LLA_OPT
;
919 /** ICMPv6 ND Neighbor Sollicitation */
921 typedef struct RTNETNDP
923 /** 00 - The ICMPv6 header. */
927 /** 08 - target address */
928 RTNETADDRIPV6 target_address
;
931 AssertCompileSize(RTNETNDP
, 4+4+16);
932 /** Pointer to a NDP ND packet. */
933 typedef RTNETNDP
*PRTNETNDP
;
934 /** Pointer to a const NDP NS packet. */
935 typedef RTNETNDP
const *PCRTNETNDP
;
939 * Ethernet ARP header.
942 typedef struct RTNETARPHDR
944 /** The hardware type. */
946 /** The protocol type (ethertype). */
948 /** The hardware address length. */
950 /** The protocol address length. */
952 /** The operation. */
956 AssertCompileSize(RTNETARPHDR
, 8);
957 /** Pointer to an ethernet ARP header. */
958 typedef RTNETARPHDR
*PRTNETARPHDR
;
959 /** Pointer to a const ethernet ARP header. */
960 typedef RTNETARPHDR
const *PCRTNETARPHDR
;
962 /** ARP hardware type - ethernet. */
963 #define RTNET_ARP_ETHER UINT16_C(1)
965 /** @name ARP operations
967 #define RTNET_ARPOP_REQUEST UINT16_C(1) /**< Request hardware address given a protocol address (ARP). */
968 #define RTNET_ARPOP_REPLY UINT16_C(2)
969 #define RTNET_ARPOP_REVREQUEST UINT16_C(3) /**< Request protocol address given a hardware address (RARP). */
970 #define RTNET_ARPOP_REVREPLY UINT16_C(4)
971 #define RTNET_ARPOP_INVREQUEST UINT16_C(8) /**< Inverse ARP. */
972 #define RTNET_ARPOP_INVREPLY UINT16_C(9)
973 /** Check if an ARP operation is a request or not. */
974 #define RTNET_ARPOP_IS_REQUEST(Op) ((Op) & 1)
975 /** Check if an ARP operation is a reply or not. */
976 #define RTNET_ARPOP_IS_REPLY(Op) (!RTNET_ARPOP_IS_REQUEST(Op))
981 * Ethernet IPv4 + 6-byte MAC ARP request packet.
984 typedef struct RTNETARPIPV4
988 /** The sender hardware address. */
990 /** The sender protocol address. */
991 RTNETADDRIPV4 ar_spa
;
992 /** The target hardware address. */
994 /** The target protocol address. */
995 RTNETADDRIPV4 ar_tpa
;
998 AssertCompileSize(RTNETARPIPV4
, 8+6+4+6+4);
999 /** Pointer to an ethernet IPv4+MAC ARP request packet. */
1000 typedef RTNETARPIPV4
*PRTNETARPIPV4
;
1001 /** Pointer to a const ethernet IPv4+MAC ARP request packet. */
1002 typedef RTNETARPIPV4
const *PCRTNETARPIPV4
;