[10960] | 1 | /** @file
|
---|
| 2 | * IPRT - Network Protocols.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[76553] | 6 | * Copyright (C) 2008-2019 Oracle Corporation
|
---|
[10960] | 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 |
|
---|
[76557] | 26 | #ifndef IPRT_INCLUDED_net_h
|
---|
| 27 | #define IPRT_INCLUDED_net_h
|
---|
[76507] | 28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 29 | # pragma once
|
---|
| 30 | #endif
|
---|
[10960] | 31 |
|
---|
| 32 | #include <iprt/cdefs.h>
|
---|
| 33 | #include <iprt/types.h>
|
---|
| 34 | #include <iprt/assert.h>
|
---|
| 35 |
|
---|
| 36 |
|
---|
[20374] | 37 | RT_C_DECLS_BEGIN
|
---|
[10960] | 38 |
|
---|
| 39 | /** @defgroup grp_rt_net RTNet - Network Protocols
|
---|
| 40 | * @ingroup grp_rt
|
---|
| 41 | * @{
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
[49326] | 45 | * Converts an stringified Ethernet MAC address into the RTMAC representation.
|
---|
| 46 | *
|
---|
| 47 | * @todo This should be move to some generic part of the runtime.
|
---|
| 48 | *
|
---|
| 49 | * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on
|
---|
| 50 | * failure.
|
---|
| 51 | *
|
---|
[57926] | 52 | * @param pszAddr The address string to convert.
|
---|
| 53 | * @param pMacAddr Where to store the result.
|
---|
[49326] | 54 | */
|
---|
| 55 | RTDECL(int) RTNetStrToMacAddr(const char *pszAddr, PRTMAC pMacAddr);
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
[10960] | 58 | * IPv4 address.
|
---|
| 59 | */
|
---|
| 60 | typedef RTUINT32U RTNETADDRIPV4;
|
---|
| 61 | AssertCompileSize(RTNETADDRIPV4, 4);
|
---|
| 62 | /** Pointer to a IPv4 address. */
|
---|
| 63 | typedef RTNETADDRIPV4 *PRTNETADDRIPV4;
|
---|
| 64 | /** Pointer to a const IPv4 address. */
|
---|
| 65 | typedef RTNETADDRIPV4 const *PCRTNETADDRIPV4;
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
[43214] | 68 | * Tests if the given string is an IPv4 address.
|
---|
| 69 | *
|
---|
| 70 | * @returns boolean.
|
---|
[50418] | 71 | * @param pcszAddr String which may be an IPv4 address.
|
---|
[43214] | 72 | */
|
---|
[50418] | 73 | RTDECL(bool) RTNetIsIPv4AddrStr(const char *pcszAddr);
|
---|
[43214] | 74 |
|
---|
[45115] | 75 | /**
|
---|
[58438] | 76 | * Tests if the given string is a wildcard IPv4 address.
|
---|
| 77 | *
|
---|
| 78 | * @returns boolean.
|
---|
| 79 | * @param pcszAddr String which may be an IPv4 address.
|
---|
| 80 | */
|
---|
| 81 | RTDECL(bool) RTNetStrIsIPv4AddrAny(const char *pcszAddr);
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
[50418] | 84 | * Parses dotted-decimal IPv4 address into RTNETADDRIPV4 representation.
|
---|
[45115] | 85 | *
|
---|
| 86 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 87 | * failure.
|
---|
| 88 | *
|
---|
[50418] | 89 | * @param pcszAddr The value to convert.
|
---|
| 90 | * @param ppszNext Where to store the pointer to the first char
|
---|
| 91 | * following the address. (Optional)
|
---|
[45115] | 92 | * @param pAddr Where to store the result.
|
---|
| 93 | */
|
---|
[50418] | 94 | RTDECL(int) RTNetStrToIPv4AddrEx(const char *pcszAddr, PRTNETADDRIPV4 pAddr, char **ppszNext);
|
---|
[43214] | 95 |
|
---|
[50418] | 96 | /**
|
---|
| 97 | * Parses dotted-decimal IPv4 address into RTNETADDRIPV4 representation.
|
---|
| 98 | * Leading and trailing whitespace is ignored.
|
---|
| 99 | *
|
---|
| 100 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 101 | * failure.
|
---|
| 102 | *
|
---|
| 103 | * @param pcszAddr The value to convert.
|
---|
| 104 | * @param pAddr Where to store the result.
|
---|
| 105 | */
|
---|
| 106 | RTDECL(int) RTNetStrToIPv4Addr(const char *pcszAddr, PRTNETADDRIPV4 pAddr);
|
---|
[45120] | 107 |
|
---|
[43214] | 108 | /**
|
---|
[76061] | 109 | * Parses dotted-decimal IPv4 CIDR notation into RTNETADDRIPV4
|
---|
| 110 | * representation and prefix length. Missing prefix specification is
|
---|
| 111 | * treated as exact address specification (prefix length 32). Leading
|
---|
| 112 | * and trailing whitespace is ignored.
|
---|
| 113 | *
|
---|
| 114 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 115 | * failure.
|
---|
| 116 | *
|
---|
| 117 | * @param pcszAddr The value to convert.
|
---|
| 118 | * @param pAddr Where to store the address.
|
---|
| 119 | * @param piPrefix Where to store the prefix length;
|
---|
| 120 | */
|
---|
| 121 | RTDECL(int) RTNetStrToIPv4Cidr(const char *pcszAddr, PRTNETADDRIPV4 pAddr, int *piPrefix);
|
---|
| 122 |
|
---|
| 123 | /**
|
---|
[65579] | 124 | * Verifies that RTNETADDRIPV4 is a valid contiguous netmask and
|
---|
| 125 | * computes its prefix length.
|
---|
| 126 | *
|
---|
| 127 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 128 | * failure.
|
---|
| 129 | *
|
---|
| 130 | * @param pMask The netmask to verify and convert.
|
---|
| 131 | * @param piPrefix Where to store the prefix length. (Optional)
|
---|
| 132 | */
|
---|
| 133 | RTDECL(int) RTNetMaskToPrefixIPv4(PCRTNETADDRIPV4 pMask, int *piPrefix);
|
---|
| 134 |
|
---|
| 135 | /**
|
---|
| 136 | * Computes netmask corresponding to the prefix length.
|
---|
| 137 | *
|
---|
| 138 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 139 | * failure.
|
---|
| 140 | *
|
---|
| 141 | * @param iPrefix The prefix to convert.
|
---|
| 142 | * @param pMask Where to store the netmask.
|
---|
| 143 | */
|
---|
| 144 | RTDECL(int) RTNetPrefixToMaskIPv4(int iPrefix, PRTNETADDRIPV4 pMask);
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | /**
|
---|
[10960] | 148 | * IPv6 address.
|
---|
| 149 | */
|
---|
| 150 | typedef RTUINT128U RTNETADDRIPV6;
|
---|
| 151 | AssertCompileSize(RTNETADDRIPV6, 16);
|
---|
[26588] | 152 | /** Pointer to a IPv6 address. */
|
---|
[10960] | 153 | typedef RTNETADDRIPV6 *PRTNETADDRIPV6;
|
---|
[26588] | 154 | /** Pointer to a const IPv6 address. */
|
---|
[10960] | 155 | typedef RTNETADDRIPV6 const *PCRTNETADDRIPV6;
|
---|
| 156 |
|
---|
| 157 | /**
|
---|
[43214] | 158 | * Tests if the given string is a valid IPv6 address.
|
---|
| 159 | *
|
---|
| 160 | * @returns @c true if it is, @c false if not.
|
---|
| 161 | * @param pszAddress String which may be an IPv6 address.
|
---|
| 162 | */
|
---|
| 163 | RTDECL(bool) RTNetIsIPv6AddrStr(const char *pszAddress);
|
---|
| 164 |
|
---|
[50456] | 165 | /**
|
---|
[58438] | 166 | * Tests if the given string is a wildcard IPv6 address.
|
---|
| 167 | *
|
---|
| 168 | * @returns @c true if it is, @c false if not.
|
---|
| 169 | * @param pszAddress String which may be an IPv6 address.
|
---|
| 170 | */
|
---|
| 171 | RTDECL(bool) RTNetStrIsIPv6AddrAny(const char *pszAddress);
|
---|
| 172 |
|
---|
| 173 | /**
|
---|
[50456] | 174 | * Parses IPv6 address into RTNETADDRIPV6 representation.
|
---|
| 175 | *
|
---|
| 176 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 177 | * failure.
|
---|
| 178 | *
|
---|
| 179 | * @param pcszAddr The value to convert.
|
---|
| 180 | * @param ppszNext Where to store the pointer to the first char
|
---|
| 181 | * following the address. (Optional)
|
---|
| 182 | * @param pAddr Where to store the result.
|
---|
| 183 | */
|
---|
| 184 | RTDECL(int) RTNetStrToIPv6AddrEx(const char *pcszAddr, PRTNETADDRIPV6 pAddr, char **ppszNext);
|
---|
[43214] | 185 |
|
---|
| 186 | /**
|
---|
[50456] | 187 | * Parses IPv6 address into RTNETADDRIPV6 representation.
|
---|
| 188 | * Leading and trailing whitespace is ignored.
|
---|
| 189 | *
|
---|
| 190 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 191 | * failure.
|
---|
| 192 | *
|
---|
| 193 | * @param pcszAddr The value to convert.
|
---|
| 194 | * @param ppszZone Where to store the pointer to the first char
|
---|
| 195 | * of the zone id. NULL is stored if there is
|
---|
| 196 | * no zone id.
|
---|
| 197 | * @param pAddr Where to store the result.
|
---|
| 198 | */
|
---|
| 199 | RTDECL(int) RTNetStrToIPv6Addr(const char *pcszAddr, PRTNETADDRIPV6 pAddr, char **ppszZone);
|
---|
| 200 |
|
---|
| 201 | /**
|
---|
[67414] | 202 | * Verifies that RTNETADDRIPV6 is a valid contiguous netmask and
|
---|
| 203 | * computes its prefix length.
|
---|
| 204 | *
|
---|
| 205 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 206 | * failure.
|
---|
| 207 | *
|
---|
| 208 | * @param pMask The netmask to verify and convert.
|
---|
| 209 | * @param piPrefix Where to store the prefix length. (Optional)
|
---|
| 210 | */
|
---|
| 211 | RTDECL(int) RTNetMaskToPrefixIPv6(PCRTNETADDRIPV6 pMask, int *piPrefix);
|
---|
| 212 |
|
---|
| 213 | /**
|
---|
| 214 | * Computes netmask corresponding to the prefix length.
|
---|
| 215 | *
|
---|
| 216 | * @returns VINF_SUCCESS on success, VERR_INVALID_PARAMETER on
|
---|
| 217 | * failure.
|
---|
| 218 | *
|
---|
| 219 | * @param iPrefix The prefix to convert.
|
---|
| 220 | * @param pMask Where to store the netmask.
|
---|
| 221 | */
|
---|
| 222 | RTDECL(int) RTNetPrefixToMaskIPv6(int iPrefix, PRTNETADDRIPV6 pMask);
|
---|
| 223 |
|
---|
| 224 |
|
---|
| 225 | /**
|
---|
[10960] | 226 | * IPX address.
|
---|
| 227 | */
|
---|
| 228 | #pragma pack(1)
|
---|
| 229 | typedef struct RTNETADDRIPX
|
---|
| 230 | {
|
---|
| 231 | /** The network ID. */
|
---|
| 232 | uint32_t Network;
|
---|
| 233 | /** The node ID. (Defaults to the MAC address apparently.) */
|
---|
[10963] | 234 | RTMAC Node;
|
---|
[10960] | 235 | } RTNETADDRIPX;
|
---|
[11546] | 236 | #pragma pack()
|
---|
[10960] | 237 | AssertCompileSize(RTNETADDRIPX, 4+6);
|
---|
| 238 | /** Pointer to an IPX address. */
|
---|
| 239 | typedef RTNETADDRIPX *PRTNETADDRIPX;
|
---|
| 240 | /** Pointer to a const IPX address. */
|
---|
| 241 | typedef RTNETADDRIPX const *PCRTNETADDRIPX;
|
---|
| 242 |
|
---|
| 243 | /**
|
---|
[26588] | 244 | * Network address union.
|
---|
| 245 | *
|
---|
| 246 | * @remarks The size of this structure may change in the future.
|
---|
[10960] | 247 | */
|
---|
| 248 | typedef union RTNETADDRU
|
---|
| 249 | {
|
---|
| 250 | /** 64-bit view. */
|
---|
| 251 | uint64_t au64[2];
|
---|
| 252 | /** 32-bit view. */
|
---|
| 253 | uint32_t au32[4];
|
---|
| 254 | /** 16-bit view. */
|
---|
| 255 | uint16_t au16[8];
|
---|
| 256 | /** 8-bit view. */
|
---|
| 257 | uint8_t au8[16];
|
---|
| 258 | /** IPv4 view. */
|
---|
| 259 | RTNETADDRIPV4 IPv4;
|
---|
[42956] | 260 | #ifndef IPv6 /* Work around X11 and RDP defining IPv6 to 1. */
|
---|
[10960] | 261 | /** IPv6 view. */
|
---|
| 262 | RTNETADDRIPV6 IPv6;
|
---|
[42956] | 263 | #endif
|
---|
[10960] | 264 | /** IPX view. */
|
---|
| 265 | RTNETADDRIPX Ipx;
|
---|
| 266 | /** MAC address view. */
|
---|
[10963] | 267 | RTMAC Mac;
|
---|
[10960] | 268 | } RTNETADDRU;
|
---|
| 269 | AssertCompileSize(RTNETADDRU, 16);
|
---|
| 270 | /** Pointer to an address union. */
|
---|
| 271 | typedef RTNETADDRU *PRTNETADDRU;
|
---|
| 272 | /** Pointer to a const address union. */
|
---|
| 273 | typedef RTNETADDRU const *PCRTNETADDRU;
|
---|
| 274 |
|
---|
[26588] | 275 | /**
|
---|
| 276 | * Network address type.
|
---|
| 277 | *
|
---|
| 278 | * @remarks The value assignments may change in the future.
|
---|
| 279 | */
|
---|
| 280 | typedef enum RTNETADDRTYPE
|
---|
| 281 | {
|
---|
| 282 | /** The invalid 0 entry. */
|
---|
| 283 | RTNETADDRTYPE_INVALID = 0,
|
---|
| 284 | /** IP version 4. */
|
---|
| 285 | RTNETADDRTYPE_IPV4,
|
---|
| 286 | /** IP version 6. */
|
---|
| 287 | RTNETADDRTYPE_IPV6,
|
---|
| 288 | /** IPX. */
|
---|
| 289 | RTNETADDRTYPE_IPX,
|
---|
| 290 | /** MAC address. */
|
---|
| 291 | RTNETADDRTYPE_MAC,
|
---|
| 292 | /** The end of the valid values. */
|
---|
| 293 | RTNETADDRTYPE_END,
|
---|
| 294 | /** The usual 32-bit hack. */
|
---|
| 295 | RTNETADDRTYPE_32_BIT_HACK = 0x7fffffff
|
---|
| 296 | } RTNETADDRTYPE;
|
---|
| 297 | /** Pointer to a network address type. */
|
---|
| 298 | typedef RTNETADDRTYPE *PRTNETADDRTYPE;
|
---|
| 299 | /** Pointer to a const network address type. */
|
---|
| 300 | typedef RTNETADDRTYPE const *PCRTNETADDRTYPE;
|
---|
[10960] | 301 |
|
---|
| 302 | /**
|
---|
[26588] | 303 | * Network address.
|
---|
| 304 | *
|
---|
| 305 | * @remarks The size and type values may change.
|
---|
| 306 | */
|
---|
| 307 | typedef struct RTNETADDR
|
---|
| 308 | {
|
---|
| 309 | /** The address union. */
|
---|
| 310 | RTNETADDRU uAddr;
|
---|
| 311 | /** Indicates which view of @a u that is valid. */
|
---|
| 312 | RTNETADDRTYPE enmType;
|
---|
| 313 | /** The port number for IPv4 and IPv6 addresses. This is set to
|
---|
| 314 | * RTNETADDR_NA_PORT if not applicable. */
|
---|
| 315 | uint32_t uPort;
|
---|
| 316 | } RTNETADDR;
|
---|
| 317 | /** Pointer to a network address. */
|
---|
| 318 | typedef RTNETADDR *PRTNETADDR;
|
---|
| 319 | /** Pointer to a const network address. */
|
---|
| 320 | typedef RTNETADDR const *PCRTNETADDR;
|
---|
| 321 |
|
---|
| 322 | /** The not applicable value of RTNETADDR::uPort value use to inid. */
|
---|
| 323 | #define RTNETADDR_PORT_NA UINT32_MAX
|
---|
| 324 |
|
---|
| 325 | /**
|
---|
[10960] | 326 | * Ethernet header.
|
---|
| 327 | */
|
---|
| 328 | #pragma pack(1)
|
---|
| 329 | typedef struct RTNETETHERHDR
|
---|
| 330 | {
|
---|
[10978] | 331 | RTMAC DstMac;
|
---|
| 332 | RTMAC SrcMac;
|
---|
[10960] | 333 | /** Ethernet frame type or frame size, depending on the kind of ethernet.
|
---|
| 334 | * This is big endian on the wire. */
|
---|
| 335 | uint16_t EtherType;
|
---|
| 336 | } RTNETETHERHDR;
|
---|
| 337 | #pragma pack()
|
---|
| 338 | AssertCompileSize(RTNETETHERHDR, 14);
|
---|
| 339 | /** Pointer to an ethernet header. */
|
---|
| 340 | typedef RTNETETHERHDR *PRTNETETHERHDR;
|
---|
| 341 | /** Pointer to a const ethernet header. */
|
---|
| 342 | typedef RTNETETHERHDR const *PCRTNETETHERHDR;
|
---|
| 343 |
|
---|
| 344 | /** @name EtherType (RTNETETHERHDR::EtherType)
|
---|
| 345 | * @{ */
|
---|
[11054] | 346 | #define RTNET_ETHERTYPE_IPV4 UINT16_C(0x0800)
|
---|
| 347 | #define RTNET_ETHERTYPE_ARP UINT16_C(0x0806)
|
---|
| 348 | #define RTNET_ETHERTYPE_IPV6 UINT16_C(0x86dd)
|
---|
[11538] | 349 | #define RTNET_ETHERTYPE_VLAN UINT16_C(0x8100)
|
---|
[11054] | 350 | #define RTNET_ETHERTYPE_IPX_1 UINT16_C(0x8037)
|
---|
| 351 | #define RTNET_ETHERTYPE_IPX_2 UINT16_C(0x8137)
|
---|
| 352 | #define RTNET_ETHERTYPE_IPX_3 UINT16_C(0x8138)
|
---|
[10960] | 353 | /** @} */
|
---|
| 354 |
|
---|
| 355 |
|
---|
| 356 | /**
|
---|
| 357 | * IPv4 header.
|
---|
| 358 | * All is bigendian on the wire.
|
---|
| 359 | */
|
---|
| 360 | #pragma pack(1)
|
---|
| 361 | typedef struct RTNETIPV4
|
---|
| 362 | {
|
---|
| 363 | #ifdef RT_BIG_ENDIAN
|
---|
| 364 | unsigned int ip_v : 4;
|
---|
| 365 | unsigned int ip_hl : 4;
|
---|
| 366 | unsigned int ip_tos : 8;
|
---|
| 367 | unsigned int ip_len : 16;
|
---|
| 368 | #else
|
---|
[10964] | 369 | /** 00:0 - Header length given as a 32-bit word count. */
|
---|
[10960] | 370 | unsigned int ip_hl : 4;
|
---|
[10964] | 371 | /** 00:4 - Header version. */
|
---|
[10960] | 372 | unsigned int ip_v : 4;
|
---|
[10964] | 373 | /** 01 - Type of service. */
|
---|
[10960] | 374 | unsigned int ip_tos : 8;
|
---|
[10964] | 375 | /** 02 - Total length (header + data). */
|
---|
[10960] | 376 | unsigned int ip_len : 16;
|
---|
| 377 | #endif
|
---|
[10964] | 378 | /** 04 - Packet idenficiation. */
|
---|
[10960] | 379 | uint16_t ip_id;
|
---|
[10964] | 380 | /** 06 - Offset if fragmented. */
|
---|
[10960] | 381 | uint16_t ip_off;
|
---|
[10964] | 382 | /** 08 - Time to live. */
|
---|
[10960] | 383 | uint8_t ip_ttl;
|
---|
[10964] | 384 | /** 09 - Protocol. */
|
---|
[10960] | 385 | uint8_t ip_p;
|
---|
[10964] | 386 | /** 0a - Header check sum. */
|
---|
[10960] | 387 | uint16_t ip_sum;
|
---|
[10964] | 388 | /** 0c - Source address. */
|
---|
| 389 | RTNETADDRIPV4 ip_src;
|
---|
| 390 | /** 10 - Destination address. */
|
---|
| 391 | RTNETADDRIPV4 ip_dst;
|
---|
| 392 | /** 14 - Options (optional). */
|
---|
[10960] | 393 | uint32_t ip_options[1];
|
---|
| 394 | } RTNETIPV4;
|
---|
[11546] | 395 | #pragma pack()
|
---|
[10960] | 396 | AssertCompileSize(RTNETIPV4, 6 * 4);
|
---|
| 397 | /** Pointer to a IPv4 header. */
|
---|
| 398 | typedef RTNETIPV4 *PRTNETIPV4;
|
---|
| 399 | /** Pointer to a const IPv4 header. */
|
---|
| 400 | typedef RTNETIPV4 const *PCRTNETIPV4;
|
---|
| 401 |
|
---|
| 402 | /** The minimum IPv4 header length (in bytes).
|
---|
| 403 | * Up to and including RTNETIPV4::ip_dst. */
|
---|
| 404 | #define RTNETIPV4_MIN_LEN (20)
|
---|
| 405 |
|
---|
| 406 |
|
---|
| 407 | /** @name IPv4 Protocol Numbers
|
---|
| 408 | * @{ */
|
---|
| 409 | /** IPv4: ICMP */
|
---|
[11445] | 410 | #define RTNETIPV4_PROT_ICMP (1)
|
---|
[10960] | 411 | /** IPv4: TCP */
|
---|
[11044] | 412 | #define RTNETIPV4_PROT_TCP (6)
|
---|
[10960] | 413 | /** IPv4: UDP */
|
---|
[11044] | 414 | #define RTNETIPV4_PROT_UDP (17)
|
---|
[10960] | 415 | /** @} */
|
---|
| 416 |
|
---|
[11044] | 417 | /** @name Common IPv4 Port Assignments
|
---|
| 418 | * @{
|
---|
| 419 | */
|
---|
| 420 | /** Boostrap Protocol / DHCP) Server. */
|
---|
| 421 | #define RTNETIPV4_PORT_BOOTPS (67)
|
---|
| 422 | /** Boostrap Protocol / DHCP) Client. */
|
---|
| 423 | #define RTNETIPV4_PORT_BOOTPC (68)
|
---|
| 424 | /** @} */
|
---|
| 425 |
|
---|
[38549] | 426 | /** @name IPv4 Flags
|
---|
| 427 | * @{ */
|
---|
| 428 | /** IPv4: Don't fragment */
|
---|
| 429 | #define RTNETIPV4_FLAGS_DF (0x4000)
|
---|
| 430 | /** IPv4: More fragments */
|
---|
| 431 | #define RTNETIPV4_FLAGS_MF (0x2000)
|
---|
| 432 | /** @} */
|
---|
| 433 |
|
---|
[10982] | 434 | RTDECL(uint16_t) RTNetIPv4HdrChecksum(PCRTNETIPV4 pIpHdr);
|
---|
[28024] | 435 | RTDECL(bool) RTNetIPv4IsHdrValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax, bool fChecksum);
|
---|
[10966] | 436 | RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr);
|
---|
| 437 | RTDECL(uint32_t) RTNetIPv4PseudoChecksumBits(RTNETADDRIPV4 SrcAddr, RTNETADDRIPV4 DstAddr, uint8_t bProtocol, uint16_t cbPkt);
|
---|
[11012] | 438 | RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t u32Sum, bool *pfOdd);
|
---|
| 439 | RTDECL(uint16_t) RTNetIPv4FinalizeChecksum(uint32_t u32Sum);
|
---|
[10960] | 440 |
|
---|
[10964] | 441 |
|
---|
| 442 | /**
|
---|
[28024] | 443 | * IPv6 header.
|
---|
| 444 | * All is bigendian on the wire.
|
---|
| 445 | */
|
---|
| 446 | #pragma pack(1)
|
---|
| 447 | typedef struct RTNETIPV6
|
---|
| 448 | {
|
---|
| 449 | /** Version (4 bits), Traffic Class (8 bits) and Flow Lable (20 bits).
|
---|
| 450 | * @todo this is probably mislabeled - ip6_flow vs. ip6_vfc, fix later. */
|
---|
| 451 | uint32_t ip6_vfc;
|
---|
| 452 | /** 04 - Payload length, including extension headers. */
|
---|
| 453 | uint16_t ip6_plen;
|
---|
| 454 | /** 06 - Next header type (RTNETIPV4_PROT_XXX). */
|
---|
| 455 | uint8_t ip6_nxt;
|
---|
| 456 | /** 07 - Hop limit. */
|
---|
| 457 | uint8_t ip6_hlim;
|
---|
| 458 | /** xx - Source address. */
|
---|
| 459 | RTNETADDRIPV6 ip6_src;
|
---|
| 460 | /** xx - Destination address. */
|
---|
| 461 | RTNETADDRIPV6 ip6_dst;
|
---|
| 462 | } RTNETIPV6;
|
---|
| 463 | #pragma pack()
|
---|
| 464 | AssertCompileSize(RTNETIPV6, 8 + 16 + 16);
|
---|
| 465 | /** Pointer to a IPv6 header. */
|
---|
| 466 | typedef RTNETIPV6 *PRTNETIPV6;
|
---|
| 467 | /** Pointer to a const IPv6 header. */
|
---|
| 468 | typedef RTNETIPV6 const *PCRTNETIPV6;
|
---|
| 469 |
|
---|
| 470 | /** The minimum IPv6 header length (in bytes).
|
---|
| 471 | * Up to and including RTNETIPV6::ip6_dst. */
|
---|
[45716] | 472 | #define RTNETIPV6_MIN_LEN (40)
|
---|
| 473 | #define RTNETIPV6_ICMPV6_ND_WITH_LLA_OPT_MIN_LEN (32)
|
---|
[28024] | 474 |
|
---|
| 475 | RTDECL(uint32_t) RTNetIPv6PseudoChecksum(PCRTNETIPV6 pIpHdr);
|
---|
| 476 | RTDECL(uint32_t) RTNetIPv6PseudoChecksumEx(PCRTNETIPV6 pIpHdr, uint8_t bProtocol, uint16_t cbPkt);
|
---|
| 477 | RTDECL(uint32_t) RTNetIPv6PseudoChecksumBits(PCRTNETADDRIPV6 pSrcAddr, PCRTNETADDRIPV6 pDstAddr,
|
---|
| 478 | uint8_t bProtocol, uint16_t cbPkt);
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 | /**
|
---|
[10960] | 482 | * UDP header.
|
---|
| 483 | */
|
---|
| 484 | #pragma pack(1)
|
---|
| 485 | typedef struct RTNETUDP
|
---|
| 486 | {
|
---|
| 487 | /** The source port. */
|
---|
| 488 | uint16_t uh_sport;
|
---|
| 489 | /** The destination port. */
|
---|
| 490 | uint16_t uh_dport;
|
---|
| 491 | /** The length of the UDP header and associated data. */
|
---|
| 492 | uint16_t uh_ulen;
|
---|
| 493 | /** The checksum of the pseudo header, the UDP header and the data. */
|
---|
| 494 | uint16_t uh_sum;
|
---|
| 495 | } RTNETUDP;
|
---|
[11546] | 496 | #pragma pack()
|
---|
[10960] | 497 | AssertCompileSize(RTNETUDP, 8);
|
---|
[10964] | 498 | /** Pointer to an UDP header. */
|
---|
[10960] | 499 | typedef RTNETUDP *PRTNETUDP;
|
---|
[10964] | 500 | /** Pointer to a const UDP header. */
|
---|
[10960] | 501 | typedef RTNETUDP const *PCRTNETUDP;
|
---|
| 502 |
|
---|
[10964] | 503 | /** The minimum UDP packet length (in bytes). (RTNETUDP::uh_ulen) */
|
---|
[10960] | 504 | #define RTNETUDP_MIN_LEN (8)
|
---|
| 505 |
|
---|
[28024] | 506 | RTDECL(uint16_t) RTNetUDPChecksum(uint32_t u32Sum, PCRTNETUDP pUdpHdr);
|
---|
[11012] | 507 | RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t u32Sum);
|
---|
[10982] | 508 | RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData);
|
---|
[11012] | 509 | RTDECL(bool) RTNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, size_t cbPktMax);
|
---|
[28024] | 510 | RTDECL(bool) RTNetIPv4IsUDPValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData, size_t cbPktMax, bool fChecksum);
|
---|
[10960] | 511 |
|
---|
[43214] | 512 |
|
---|
[11049] | 513 | /**
|
---|
| 514 | * IPv4 BOOTP / DHCP packet.
|
---|
| 515 | */
|
---|
| 516 | #pragma pack(1)
|
---|
| 517 | typedef struct RTNETBOOTP
|
---|
| 518 | {
|
---|
[17771] | 519 | /** 00 - The packet opcode (RTNETBOOTP_OP_*). */
|
---|
[11049] | 520 | uint8_t bp_op;
|
---|
| 521 | /** 01 - Hardware address type. Same as RTNETARPHDR::ar_htype. */
|
---|
| 522 | uint8_t bp_htype;
|
---|
| 523 | /** 02 - Hardware address length. */
|
---|
| 524 | uint8_t bp_hlen;
|
---|
| 525 | /** 03 - Gateway hops. */
|
---|
| 526 | uint8_t bp_hops;
|
---|
| 527 | /** 04 - Transaction ID. */
|
---|
| 528 | uint32_t bp_xid;
|
---|
| 529 | /** 08 - Seconds since boot started. */
|
---|
| 530 | uint16_t bp_secs;
|
---|
[17771] | 531 | /** 0a - Unused (BOOTP) / Flags (DHCP) (RTNET_DHCP_FLAGS_*). */
|
---|
[11049] | 532 | uint16_t bp_flags;
|
---|
| 533 | /** 0c - Client IPv4 address. */
|
---|
| 534 | RTNETADDRIPV4 bp_ciaddr;
|
---|
| 535 | /** 10 - Your IPv4 address. */
|
---|
| 536 | RTNETADDRIPV4 bp_yiaddr;
|
---|
| 537 | /** 14 - Server IPv4 address. */
|
---|
| 538 | RTNETADDRIPV4 bp_siaddr;
|
---|
| 539 | /** 18 - Gateway IPv4 address. */
|
---|
| 540 | RTNETADDRIPV4 bp_giaddr;
|
---|
| 541 | /** 1c - Client hardware address. */
|
---|
| 542 | union
|
---|
| 543 | {
|
---|
| 544 | uint8_t au8[16];
|
---|
| 545 | RTMAC Mac;
|
---|
| 546 | } bp_chaddr;
|
---|
| 547 | /** 2c - Server name. */
|
---|
| 548 | uint8_t bp_sname[64];
|
---|
| 549 | /** 6c - File name / more DHCP options. */
|
---|
| 550 | uint8_t bp_file[128];
|
---|
| 551 | /** ec - Vendor specific area (BOOTP) / Options (DHCP).
|
---|
| 552 | * @remark This is really 312 bytes in the DHCP version. */
|
---|
| 553 | union
|
---|
| 554 | {
|
---|
| 555 | uint8_t au8[128];
|
---|
| 556 | struct DHCP
|
---|
| 557 | {
|
---|
| 558 | /** ec - The DHCP cookie (RTNET_DHCP_COOKIE). */
|
---|
| 559 | uint32_t dhcp_cookie;
|
---|
| 560 | /** f0 - The DHCP options. */
|
---|
| 561 | uint8_t dhcp_opts[124];
|
---|
| 562 | } Dhcp;
|
---|
| 563 | } bp_vend;
|
---|
[10966] | 564 |
|
---|
[11049] | 565 | } RTNETBOOTP;
|
---|
[11546] | 566 | #pragma pack()
|
---|
[11049] | 567 | AssertCompileSize(RTNETBOOTP, 0xec + 128);
|
---|
| 568 | /** Pointer to a BOOTP / DHCP packet. */
|
---|
| 569 | typedef RTNETBOOTP *PRTNETBOOTP;
|
---|
| 570 | /** Pointer to a const BOOTP / DHCP packet. */
|
---|
| 571 | typedef RTNETBOOTP const *PCRTNETBOOTP;
|
---|
| 572 |
|
---|
[11052] | 573 | /** Minimum BOOTP packet length. For quick validation, no standard thing really. */
|
---|
| 574 | #define RTNETBOOTP_MIN_LEN 0xec
|
---|
| 575 | /** Minimum DHCP packet length. For quick validation, no standard thing really. */
|
---|
| 576 | #define RTNETBOOTP_DHCP_MIN_LEN 0xf1
|
---|
| 577 |
|
---|
[17771] | 578 | /** The normal size of the a DHCP packet (i.e. a RTNETBOOTP).
|
---|
| 579 | * Same as RTNET_DHCP_OPT_SIZE, just expressed differently. */
|
---|
| 580 | #define RTNET_DHCP_NORMAL_SIZE (0xec + 4 + RTNET_DHCP_OPT_SIZE)
|
---|
| 581 | /** The normal size of RTNETBOOTP::bp_vend::Dhcp::dhcp_opts. */
|
---|
| 582 | #define RTNET_DHCP_OPT_SIZE (312 - 4)
|
---|
| 583 |
|
---|
[11049] | 584 | /** @name BOOTP packet opcode values
|
---|
| 585 | * @{ */
|
---|
| 586 | #define RTNETBOOTP_OP_REQUEST 1
|
---|
| 587 | #define RTNETBOOTP_OP_REPLY 2
|
---|
| 588 | /** @} */
|
---|
| 589 |
|
---|
| 590 | /** @name DHCP flags (RTNETBOOTP::bp_flags)
|
---|
| 591 | * @{ */
|
---|
| 592 | #define RTNET_DHCP_FLAGS_NO_BROADCAST UINT16_C(0x8000) /** @todo check test!!! */
|
---|
| 593 | /** @} */
|
---|
| 594 |
|
---|
| 595 | /** The DHCP cookie (network endian). */
|
---|
| 596 | #define RTNET_DHCP_COOKIE UINT32_C(0x63825363)
|
---|
| 597 |
|
---|
[10960] | 598 | /**
|
---|
[11049] | 599 | * An IPv4 DHCP option header.
|
---|
| 600 | */
|
---|
| 601 | typedef struct RTNETDHCPOPT
|
---|
| 602 | {
|
---|
| 603 | /** 00 - The DHCP option. */
|
---|
| 604 | uint8_t dhcp_opt;
|
---|
| 605 | /** 01 - The data length (excluding this header). */
|
---|
| 606 | uint8_t dhcp_len;
|
---|
| 607 | /* 02 - The option data follows here, optional and of variable length. */
|
---|
| 608 | } RTNETDHCPOPT;
|
---|
| 609 | AssertCompileSize(RTNETDHCPOPT, 2);
|
---|
| 610 | /** Pointer to a DHCP option header. */
|
---|
| 611 | typedef RTNETDHCPOPT *PRTNETDHCPOPT;
|
---|
| 612 | /** Pointer to a const DHCP option header. */
|
---|
| 613 | typedef RTNETDHCPOPT const *PCRTNETDHCPOPT;
|
---|
| 614 |
|
---|
| 615 | /** @name DHCP options
|
---|
| 616 | * @{ */
|
---|
| 617 | /** 1 byte padding, this has no dhcp_len field. */
|
---|
[17771] | 618 | #define RTNET_DHCP_OPT_PAD 0
|
---|
| 619 |
|
---|
| 620 | /** The subnet mask. */
|
---|
| 621 | #define RTNET_DHCP_OPT_SUBNET_MASK 1
|
---|
| 622 | /** The time offset. */
|
---|
| 623 | #define RTNET_DHCP_OPT_TIME_OFFSET 2
|
---|
| 624 | /** The routers for the subnet. */
|
---|
| 625 | #define RTNET_DHCP_OPT_ROUTERS 3
|
---|
| 626 | /** Domain Name Server. */
|
---|
| 627 | #define RTNET_DHCP_OPT_DNS 6
|
---|
| 628 | /** Host name. */
|
---|
| 629 | #define RTNET_DHCP_OPT_HOST_NAME 12
|
---|
| 630 | /** Domain name. */
|
---|
| 631 | #define RTNET_DHCP_OPT_DOMAIN_NAME 15
|
---|
| 632 |
|
---|
| 633 | /** The requested address. */
|
---|
| 634 | #define RTNET_DHCP_OPT_REQ_ADDR 50
|
---|
| 635 | /** The lease time in seconds. */
|
---|
| 636 | #define RTNET_DHCP_OPT_LEASE_TIME 51
|
---|
| 637 | /** Option overload.
|
---|
| 638 | * Indicates that the bp_file and/or bp_sname holds contains DHCP options. */
|
---|
| 639 | #define RTNET_DHCP_OPT_OPTION_OVERLOAD 52
|
---|
[11049] | 640 | /** Have a 8-bit message type value as data, see RTNET_DHCP_MT_*. */
|
---|
[17771] | 641 | #define RTNET_DHCP_OPT_MSG_TYPE 53
|
---|
| 642 | /** Server ID. */
|
---|
| 643 | #define RTNET_DHCP_OPT_SERVER_ID 54
|
---|
| 644 | /** Parameter request list. */
|
---|
| 645 | #define RTNET_DHCP_OPT_PARAM_REQ_LIST 55
|
---|
| 646 | /** The maximum DHCP message size a client is willing to accept. */
|
---|
| 647 | #define RTNET_DHCP_OPT_MAX_DHCP_MSG_SIZE 57
|
---|
| 648 | /** Client ID. */
|
---|
| 649 | #define RTNET_DHCP_OPT_CLIENT_ID 61
|
---|
| 650 | /** TFTP server name. */
|
---|
| 651 | #define RTNET_DHCP_OPT_TFTP_SERVER_NAME 66
|
---|
| 652 | /** Bootfile name. */
|
---|
| 653 | #define RTNET_DHCP_OPT_BOOTFILE_NAME 67
|
---|
| 654 |
|
---|
[11049] | 655 | /** Marks the end of the DHCP options, this has no dhcp_len field. */
|
---|
[17771] | 656 | #define RTNET_DHCP_OPT_END 255
|
---|
[11049] | 657 | /** @} */
|
---|
| 658 |
|
---|
| 659 | /** @name DHCP Message Types (option 53)
|
---|
| 660 | * @{ */
|
---|
| 661 | #define RTNET_DHCP_MT_DISCOVER 1
|
---|
| 662 | #define RTNET_DHCP_MT_OFFER 2
|
---|
| 663 | #define RTNET_DHCP_MT_REQUEST 3
|
---|
| 664 | #define RTNET_DHCP_MT_DECLINE 4
|
---|
| 665 | #define RTNET_DHCP_MT_ACK 5
|
---|
| 666 | #define RTNET_DHCP_MT_NAC 6
|
---|
| 667 | #define RTNET_DHCP_MT_RELEASE 7
|
---|
| 668 | #define RTNET_DHCP_MT_INFORM 8
|
---|
| 669 | /** @} */
|
---|
| 670 |
|
---|
[14695] | 671 | /** @name DHCP Flags
|
---|
| 672 | * @{ */
|
---|
| 673 | #define RTNET_DHCP_FLAG_BROADCAST 0x8000
|
---|
| 674 | /** @} */
|
---|
| 675 |
|
---|
[11049] | 676 | RTDECL(bool) RTNetIPv4IsDHCPValid(PCRTNETUDP pUdpHdr, PCRTNETBOOTP pDhcp, size_t cbDhcp, uint8_t *pMsgType);
|
---|
| 677 |
|
---|
| 678 |
|
---|
| 679 | /**
|
---|
[10960] | 680 | * IPv4 DHCP packet.
|
---|
[25645] | 681 | * @deprecated Use RTNETBOOTP.
|
---|
[10960] | 682 | */
|
---|
| 683 | #pragma pack(1)
|
---|
| 684 | typedef struct RTNETDHCP
|
---|
| 685 | {
|
---|
[11049] | 686 | /** 00 - The packet opcode. */
|
---|
[10960] | 687 | uint8_t Op;
|
---|
| 688 | /** Hardware address type. */
|
---|
| 689 | uint8_t HType;
|
---|
| 690 | /** Hardware address length. */
|
---|
| 691 | uint8_t HLen;
|
---|
| 692 | uint8_t Hops;
|
---|
| 693 | uint32_t XID;
|
---|
| 694 | uint16_t Secs;
|
---|
| 695 | uint16_t Flags;
|
---|
| 696 | /** Client IPv4 address. */
|
---|
| 697 | RTNETADDRIPV4 CIAddr;
|
---|
| 698 | /** Your IPv4 address. */
|
---|
| 699 | RTNETADDRIPV4 YIAddr;
|
---|
| 700 | /** Server IPv4 address. */
|
---|
| 701 | RTNETADDRIPV4 SIAddr;
|
---|
| 702 | /** Gateway IPv4 address. */
|
---|
| 703 | RTNETADDRIPV4 GIAddr;
|
---|
| 704 | /** Client hardware address. */
|
---|
| 705 | uint8_t CHAddr[16];
|
---|
| 706 | /** Server name. */
|
---|
| 707 | uint8_t SName[64];
|
---|
| 708 | uint8_t File[128];
|
---|
| 709 | uint8_t abMagic[4];
|
---|
| 710 | uint8_t DhcpOpt;
|
---|
| 711 | uint8_t DhcpLen; /* 1 */
|
---|
| 712 | uint8_t DhcpReq;
|
---|
| 713 | uint8_t abOptions[57];
|
---|
| 714 | } RTNETDHCP;
|
---|
[11546] | 715 | #pragma pack()
|
---|
[10964] | 716 | /** @todo AssertCompileSize(RTNETDHCP, ); */
|
---|
[10960] | 717 | /** Pointer to a DHCP packet. */
|
---|
| 718 | typedef RTNETDHCP *PRTNETDHCP;
|
---|
| 719 | /** Pointer to a const DHCP packet. */
|
---|
| 720 | typedef RTNETDHCP const *PCRTNETDHCP;
|
---|
| 721 |
|
---|
| 722 |
|
---|
| 723 | /**
|
---|
[10964] | 724 | * TCP packet.
|
---|
| 725 | */
|
---|
| 726 | #pragma pack(1)
|
---|
| 727 | typedef struct RTNETTCP
|
---|
| 728 | {
|
---|
| 729 | /** 00 - The source port. */
|
---|
| 730 | uint16_t th_sport;
|
---|
| 731 | /** 02 - The destination port. */
|
---|
| 732 | uint16_t th_dport;
|
---|
| 733 | /** 04 - The sequence number. */
|
---|
| 734 | uint32_t th_seq;
|
---|
| 735 | /** 08 - The acknowledgement number. */
|
---|
| 736 | uint32_t th_ack;
|
---|
| 737 | #ifdef RT_BIG_ENDIAN
|
---|
| 738 | unsigned int th_win : 16;
|
---|
| 739 | unsigned int th_flags : 8;
|
---|
| 740 | unsigned int th_off : 4;
|
---|
| 741 | unsigned int th_x2 : 4;
|
---|
| 742 | #else
|
---|
| 743 | /** 0c:0 - Reserved. */
|
---|
| 744 | unsigned int th_x2 : 4;
|
---|
| 745 | /** 0c:4 - The data offset given as a dword count from the start of this header. */
|
---|
| 746 | unsigned int th_off : 4;
|
---|
| 747 | /** 0d - flags. */
|
---|
| 748 | unsigned int th_flags : 8;
|
---|
| 749 | /** 0e - The window. */
|
---|
| 750 | unsigned int th_win : 16;
|
---|
| 751 | #endif
|
---|
| 752 | /** 10 - The checksum of the pseudo header, the TCP header and the data. */
|
---|
| 753 | uint16_t th_sum;
|
---|
| 754 | /** 12 - The urgent pointer. */
|
---|
| 755 | uint16_t th_urp;
|
---|
| 756 | /* (options follows here and then the data (aka text).) */
|
---|
| 757 | } RTNETTCP;
|
---|
[11546] | 758 | #pragma pack()
|
---|
[10964] | 759 | AssertCompileSize(RTNETTCP, 20);
|
---|
| 760 | /** Pointer to a TCP packet. */
|
---|
| 761 | typedef RTNETTCP *PRTNETTCP;
|
---|
| 762 | /** Pointer to a const TCP packet. */
|
---|
| 763 | typedef RTNETTCP const *PCRTNETTCP;
|
---|
| 764 |
|
---|
| 765 | /** The minimum TCP header length (in bytes). (RTNETTCP::th_off * 4) */
|
---|
| 766 | #define RTNETTCP_MIN_LEN (20)
|
---|
| 767 |
|
---|
[28024] | 768 | /** @name TCP flags (RTNETTCP::th_flags)
|
---|
| 769 | * @{ */
|
---|
| 770 | #define RTNETTCP_F_FIN 0x01
|
---|
| 771 | #define RTNETTCP_F_SYN 0x02
|
---|
| 772 | #define RTNETTCP_F_RST 0x04
|
---|
| 773 | #define RTNETTCP_F_PSH 0x08
|
---|
| 774 | #define RTNETTCP_F_ACK 0x10
|
---|
| 775 | #define RTNETTCP_F_URG 0x20
|
---|
| 776 | #define RTNETTCP_F_ECE 0x40
|
---|
| 777 | #define RTNETTCP_F_CWR 0x80
|
---|
| 778 | /** @} */
|
---|
| 779 |
|
---|
| 780 | RTDECL(uint16_t) RTNetTCPChecksum(uint32_t u32Sum, PCRTNETTCP pTcpHdr, void const *pvData, size_t cbData);
|
---|
[11012] | 781 | RTDECL(uint32_t) RTNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr, uint32_t u32Sum);
|
---|
[11044] | 782 | RTDECL(uint16_t) RTNetIPv4TCPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, void const *pvData);
|
---|
| 783 | RTDECL(bool) RTNetIPv4IsTCPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, size_t cbHdrMax, size_t cbPktMax);
|
---|
[28024] | 784 | RTDECL(bool) RTNetIPv4IsTCPValid(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, size_t cbHdrMax, void const *pvData,
|
---|
| 785 | size_t cbPktMax, bool fChecksum);
|
---|
[10964] | 786 |
|
---|
[10966] | 787 |
|
---|
[10964] | 788 | /**
|
---|
[11025] | 789 | * IPv4 ICMP packet header.
|
---|
| 790 | */
|
---|
| 791 | #pragma pack(1)
|
---|
| 792 | typedef struct RTNETICMPV4HDR
|
---|
| 793 | {
|
---|
| 794 | /** 00 - The ICMP message type. */
|
---|
| 795 | uint8_t icmp_type;
|
---|
| 796 | /** 01 - Type specific code that further qualifies the message. */
|
---|
| 797 | uint8_t icmp_code;
|
---|
| 798 | /** 02 - Checksum of the ICMP message. */
|
---|
| 799 | uint16_t icmp_cksum;
|
---|
| 800 | } RTNETICMPV4HDR;
|
---|
[11546] | 801 | #pragma pack()
|
---|
[11025] | 802 | AssertCompileSize(RTNETICMPV4HDR, 4);
|
---|
| 803 | /** Pointer to an ICMP packet header. */
|
---|
| 804 | typedef RTNETICMPV4HDR *PRTNETICMPV4HDR;
|
---|
| 805 | /** Pointer to a const ICMP packet header. */
|
---|
| 806 | typedef RTNETICMPV4HDR const *PCRTNETICMPV4HDR;
|
---|
| 807 |
|
---|
| 808 | /** @name ICMP (v4) message types.
|
---|
| 809 | * @{ */
|
---|
| 810 | #define RTNETICMPV4_TYPE_ECHO_REPLY 0
|
---|
| 811 | #define RTNETICMPV4_TYPE_ECHO_REQUEST 8
|
---|
| 812 | #define RTNETICMPV4_TYPE_TRACEROUTE 30
|
---|
| 813 | /** @} */
|
---|
| 814 |
|
---|
| 815 | /**
|
---|
| 816 | * IPv4 ICMP ECHO Reply & Request packet.
|
---|
| 817 | */
|
---|
| 818 | #pragma pack(1)
|
---|
| 819 | typedef struct RTNETICMPV4ECHO
|
---|
| 820 | {
|
---|
| 821 | /** 00 - The ICMP header. */
|
---|
| 822 | RTNETICMPV4HDR Hdr;
|
---|
| 823 | /** 04 - The identifier to help the requestor match up the reply.
|
---|
| 824 | * Can be 0. Typically fixed value. */
|
---|
| 825 | uint16_t icmp_id;
|
---|
| 826 | /** 06 - The sequence number to help the requestor match up the reply.
|
---|
| 827 | * Can be 0. Typically incrementing between requests. */
|
---|
| 828 | uint16_t icmp_seq;
|
---|
| 829 | /** 08 - Variable length data that is to be returned unmodified in the reply. */
|
---|
| 830 | uint8_t icmp_data[1];
|
---|
| 831 | } RTNETICMPV4ECHO;
|
---|
[11546] | 832 | #pragma pack()
|
---|
[11025] | 833 | AssertCompileSize(RTNETICMPV4ECHO, 9);
|
---|
| 834 | /** Pointer to an ICMP ECHO packet. */
|
---|
| 835 | typedef RTNETICMPV4ECHO *PRTNETICMPV4ECHO;
|
---|
| 836 | /** Pointer to a const ICMP ECHO packet. */
|
---|
| 837 | typedef RTNETICMPV4ECHO const *PCRTNETICMPV4ECHO;
|
---|
| 838 |
|
---|
| 839 | /**
|
---|
| 840 | * IPv4 ICMP TRACEROUTE packet.
|
---|
| 841 | * This is an reply to an IP packet with the traceroute option set.
|
---|
| 842 | */
|
---|
| 843 | #pragma pack(1)
|
---|
| 844 | typedef struct RTNETICMPV4TRACEROUTE
|
---|
| 845 | {
|
---|
| 846 | /** 00 - The ICMP header. */
|
---|
| 847 | RTNETICMPV4HDR Hdr;
|
---|
| 848 | /** 04 - Identifier copied from the traceroute option's ID number. */
|
---|
| 849 | uint16_t icmp_id;
|
---|
| 850 | /** 06 - Unused. (Possibly an icmp_seq?) */
|
---|
| 851 | uint16_t icmp_void;
|
---|
| 852 | /** 08 - Outbound hop count. From the IP packet causing this message. */
|
---|
| 853 | uint16_t icmp_ohc;
|
---|
| 854 | /** 0a - Return hop count. From the IP packet causing this message. */
|
---|
| 855 | uint16_t icmp_rhc;
|
---|
| 856 | /** 0c - Output link speed, 0 if not known. */
|
---|
| 857 | uint32_t icmp_speed;
|
---|
| 858 | /** 10 - Output link MTU, 0 if not known. */
|
---|
| 859 | uint32_t icmp_mtu;
|
---|
| 860 | } RTNETICMPV4TRACEROUTE;
|
---|
[11546] | 861 | #pragma pack()
|
---|
[11025] | 862 | AssertCompileSize(RTNETICMPV4TRACEROUTE, 20);
|
---|
| 863 | /** Pointer to an ICMP TRACEROUTE packet. */
|
---|
| 864 | typedef RTNETICMPV4TRACEROUTE *PRTNETICMPV4TRACEROUTE;
|
---|
| 865 | /** Pointer to a const ICMP TRACEROUTE packet. */
|
---|
| 866 | typedef RTNETICMPV4TRACEROUTE const *PCRTNETICMPV4TRACEROUTE;
|
---|
| 867 |
|
---|
| 868 | /** @todo add more ICMPv4 as needed. */
|
---|
| 869 |
|
---|
| 870 | /**
|
---|
| 871 | * IPv4 ICMP union packet.
|
---|
| 872 | */
|
---|
| 873 | typedef union RTNETICMPV4
|
---|
| 874 | {
|
---|
| 875 | RTNETICMPV4HDR Hdr;
|
---|
| 876 | RTNETICMPV4ECHO Echo;
|
---|
| 877 | RTNETICMPV4TRACEROUTE Traceroute;
|
---|
| 878 | } RTNETICMPV4;
|
---|
| 879 | /** Pointer to an ICMP union packet. */
|
---|
| 880 | typedef RTNETICMPV4 *PRTNETICMPV4;
|
---|
| 881 | /** Pointer to a const ICMP union packet. */
|
---|
| 882 | typedef RTNETICMPV4 const *PCRTNETICMPV4;
|
---|
| 883 |
|
---|
| 884 |
|
---|
[52543] | 885 | /**
|
---|
| 886 | * IPv6 ICMP packet header.
|
---|
| 887 | */
|
---|
| 888 | #pragma pack(1)
|
---|
| 889 | typedef struct RTNETICMPV6HDR
|
---|
| 890 | {
|
---|
| 891 | /** 00 - The ICMPv6 message type. */
|
---|
| 892 | uint8_t icmp6_type;
|
---|
| 893 | /** 01 - Type specific code that further qualifies the message. */
|
---|
| 894 | uint8_t icmp6_code;
|
---|
| 895 | /** 02 - Checksum of the ICMPv6 message. */
|
---|
| 896 | uint16_t icmp6_cksum;
|
---|
| 897 | } RTNETICMPV6HDR;
|
---|
| 898 | #pragma pack()
|
---|
| 899 | AssertCompileSize(RTNETICMPV6HDR, 4);
|
---|
| 900 | /** Pointer to an ICMPv6 packet header. */
|
---|
| 901 | typedef RTNETICMPV6HDR *PRTNETICMPV6HDR;
|
---|
| 902 | /** Pointer to a const ICMP packet header. */
|
---|
| 903 | typedef RTNETICMPV6HDR const *PCRTNETICMPV6HDR;
|
---|
[11025] | 904 |
|
---|
[45716] | 905 | #define RTNETIPV6_PROT_ICMPV6 (58)
|
---|
[52519] | 906 |
|
---|
| 907 | /** @name Internet Control Message Protocol version 6 (ICMPv6) message types.
|
---|
| 908 | * @{ */
|
---|
| 909 | #define RTNETIPV6_ICMP_TYPE_RS 133
|
---|
| 910 | #define RTNETIPV6_ICMP_TYPE_RA 134
|
---|
| 911 | #define RTNETIPV6_ICMP_TYPE_NS 135
|
---|
| 912 | #define RTNETIPV6_ICMP_TYPE_NA 136
|
---|
| 913 | #define RTNETIPV6_ICMP_TYPE_RDR 137
|
---|
| 914 | /** @} */
|
---|
| 915 |
|
---|
[52543] | 916 | /** @name Neighbor Discovery option types
|
---|
| 917 | * @{ */
|
---|
[45716] | 918 | #define RTNETIPV6_ICMP_ND_SLLA_OPT (1)
|
---|
| 919 | #define RTNETIPV6_ICMP_ND_TLLA_OPT (2)
|
---|
[52543] | 920 | /** @} */
|
---|
[11025] | 921 |
|
---|
[52543] | 922 | /** ICMPv6 ND Source/Target Link Layer Address option */
|
---|
[45716] | 923 | #pragma pack(1)
|
---|
[52543] | 924 | typedef struct RTNETNDP_LLA_OPT
|
---|
[45716] | 925 | {
|
---|
| 926 | uint8_t type;
|
---|
| 927 | uint8_t len;
|
---|
[52543] | 928 | RTMAC lla;
|
---|
| 929 | } RTNETNDP_LLA_OPT;
|
---|
[45716] | 930 | #pragma pack()
|
---|
| 931 |
|
---|
[52543] | 932 | AssertCompileSize(RTNETNDP_LLA_OPT, 1+1+6);
|
---|
[45716] | 933 |
|
---|
[52543] | 934 | typedef RTNETNDP_LLA_OPT *PRTNETNDP_LLA_OPT;
|
---|
| 935 | typedef RTNETNDP_LLA_OPT const *PCRTNETNDP_LLA_OPT;
|
---|
[45716] | 936 |
|
---|
| 937 | /** ICMPv6 ND Neighbor Sollicitation */
|
---|
| 938 | #pragma pack(1)
|
---|
| 939 | typedef struct RTNETNDP
|
---|
| 940 | {
|
---|
[52543] | 941 | /** 00 - The ICMPv6 header. */
|
---|
| 942 | RTNETICMPV6HDR Hdr;
|
---|
| 943 | /** 04 - reserved */
|
---|
[45716] | 944 | uint32_t reserved;
|
---|
[52543] | 945 | /** 08 - target address */
|
---|
[45716] | 946 | RTNETADDRIPV6 target_address;
|
---|
| 947 | } RTNETNDP;
|
---|
| 948 | #pragma pack()
|
---|
[52543] | 949 | AssertCompileSize(RTNETNDP, 4+4+16);
|
---|
[45716] | 950 | /** Pointer to a NDP ND packet. */
|
---|
| 951 | typedef RTNETNDP *PRTNETNDP;
|
---|
| 952 | /** Pointer to a const NDP NS packet. */
|
---|
| 953 | typedef RTNETNDP const *PCRTNETNDP;
|
---|
| 954 |
|
---|
| 955 |
|
---|
[11025] | 956 | /**
|
---|
[10960] | 957 | * Ethernet ARP header.
|
---|
| 958 | */
|
---|
| 959 | #pragma pack(1)
|
---|
| 960 | typedef struct RTNETARPHDR
|
---|
| 961 | {
|
---|
| 962 | /** The hardware type. */
|
---|
| 963 | uint16_t ar_htype;
|
---|
| 964 | /** The protocol type (ethertype). */
|
---|
| 965 | uint16_t ar_ptype;
|
---|
| 966 | /** The hardware address length. */
|
---|
| 967 | uint8_t ar_hlen;
|
---|
| 968 | /** The protocol address length. */
|
---|
| 969 | uint8_t ar_plen;
|
---|
| 970 | /** The operation. */
|
---|
| 971 | uint16_t ar_oper;
|
---|
| 972 | } RTNETARPHDR;
|
---|
[11546] | 973 | #pragma pack()
|
---|
[10960] | 974 | AssertCompileSize(RTNETARPHDR, 8);
|
---|
| 975 | /** Pointer to an ethernet ARP header. */
|
---|
| 976 | typedef RTNETARPHDR *PRTNETARPHDR;
|
---|
| 977 | /** Pointer to a const ethernet ARP header. */
|
---|
| 978 | typedef RTNETARPHDR const *PCRTNETARPHDR;
|
---|
| 979 |
|
---|
| 980 | /** ARP hardware type - ethernet. */
|
---|
| 981 | #define RTNET_ARP_ETHER UINT16_C(1)
|
---|
| 982 |
|
---|
| 983 | /** @name ARP operations
|
---|
| 984 | * @{ */
|
---|
[17848] | 985 | #define RTNET_ARPOP_REQUEST UINT16_C(1) /**< Request hardware address given a protocol address (ARP). */
|
---|
[10960] | 986 | #define RTNET_ARPOP_REPLY UINT16_C(2)
|
---|
| 987 | #define RTNET_ARPOP_REVREQUEST UINT16_C(3) /**< Request protocol address given a hardware address (RARP). */
|
---|
| 988 | #define RTNET_ARPOP_REVREPLY UINT16_C(4)
|
---|
| 989 | #define RTNET_ARPOP_INVREQUEST UINT16_C(8) /**< Inverse ARP. */
|
---|
| 990 | #define RTNET_ARPOP_INVREPLY UINT16_C(9)
|
---|
| 991 | /** Check if an ARP operation is a request or not. */
|
---|
| 992 | #define RTNET_ARPOP_IS_REQUEST(Op) ((Op) & 1)
|
---|
| 993 | /** Check if an ARP operation is a reply or not. */
|
---|
| 994 | #define RTNET_ARPOP_IS_REPLY(Op) (!RTNET_ARPOP_IS_REQUEST(Op))
|
---|
| 995 | /** @} */
|
---|
| 996 |
|
---|
| 997 |
|
---|
| 998 | /**
|
---|
| 999 | * Ethernet IPv4 + 6-byte MAC ARP request packet.
|
---|
| 1000 | */
|
---|
| 1001 | #pragma pack(1)
|
---|
| 1002 | typedef struct RTNETARPIPV4
|
---|
| 1003 | {
|
---|
| 1004 | /** ARP header. */
|
---|
| 1005 | RTNETARPHDR Hdr;
|
---|
| 1006 | /** The sender hardware address. */
|
---|
[10963] | 1007 | RTMAC ar_sha;
|
---|
[10960] | 1008 | /** The sender protocol address. */
|
---|
| 1009 | RTNETADDRIPV4 ar_spa;
|
---|
| 1010 | /** The target hardware address. */
|
---|
[10963] | 1011 | RTMAC ar_tha;
|
---|
[52422] | 1012 | /** The target protocol address. */
|
---|
[10960] | 1013 | RTNETADDRIPV4 ar_tpa;
|
---|
| 1014 | } RTNETARPIPV4;
|
---|
[11546] | 1015 | #pragma pack()
|
---|
[10960] | 1016 | AssertCompileSize(RTNETARPIPV4, 8+6+4+6+4);
|
---|
| 1017 | /** Pointer to an ethernet IPv4+MAC ARP request packet. */
|
---|
| 1018 | typedef RTNETARPIPV4 *PRTNETARPIPV4;
|
---|
| 1019 | /** Pointer to a const ethernet IPv4+MAC ARP request packet. */
|
---|
| 1020 | typedef RTNETARPIPV4 const *PCRTNETARPIPV4;
|
---|
| 1021 |
|
---|
| 1022 |
|
---|
| 1023 | /** @} */
|
---|
| 1024 |
|
---|
[20374] | 1025 | RT_C_DECLS_END
|
---|
[10960] | 1026 |
|
---|
[76585] | 1027 | #endif /* !IPRT_INCLUDED_net_h */
|
---|
[10960] | 1028 |
|
---|