net.h revision 16ce6af7dc35406c61ca9267e0b8fed766a57fd5
/** @file
* IPRT - Network Protocols.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef ___iprt_net_h
#define ___iprt_net_h
/** @defgroup grp_rt_net RTNet - Network Protocols
* @ingroup grp_rt
* @{
*/
/**
* IPv4 address.
*/
typedef RTUINT32U RTNETADDRIPV4;
/** Pointer to a IPv4 address. */
typedef RTNETADDRIPV4 *PRTNETADDRIPV4;
/** Pointer to a const IPv4 address. */
typedef RTNETADDRIPV4 const *PCRTNETADDRIPV4;
/**
* IPv6 address.
*/
typedef RTUINT128U RTNETADDRIPV6;
/** Pointer to a IPv4 address. */
typedef RTNETADDRIPV6 *PRTNETADDRIPV6;
/** Pointer to a const IPv4 address. */
typedef RTNETADDRIPV6 const *PCRTNETADDRIPV6;
/**
* IPX address.
*/
#pragma pack(1)
typedef struct RTNETADDRIPX
{
/** The network ID. */
/** The node ID. (Defaults to the MAC address apparently.) */
} RTNETADDRIPX;
#pragma pack(0)
/** Pointer to an IPX address. */
typedef RTNETADDRIPX *PRTNETADDRIPX;
/** Pointer to a const IPX address. */
typedef RTNETADDRIPX const *PCRTNETADDRIPX;
/**
* Address union.
*/
typedef union RTNETADDRU
{
/** 64-bit view. */
/** 32-bit view. */
/** 16-bit view. */
/** 8-bit view. */
/** IPv4 view. */
/** IPv6 view. */
/** IPX view. */
/** MAC address view. */
} RTNETADDRU;
/** Pointer to an address union. */
typedef RTNETADDRU *PRTNETADDRU;
/** Pointer to a const address union. */
typedef RTNETADDRU const *PCRTNETADDRU;
/**
* Ethernet header.
*/
#pragma pack(1)
typedef struct RTNETETHERHDR
{
/** Ethernet frame type or frame size, depending on the kind of ethernet.
* This is big endian on the wire. */
#pragma pack()
/** Pointer to an ethernet header. */
typedef RTNETETHERHDR *PRTNETETHERHDR;
/** Pointer to a const ethernet header. */
typedef RTNETETHERHDR const *PCRTNETETHERHDR;
/** @name EtherType (RTNETETHERHDR::EtherType)
* @{ */
/** @} */
/**
* IPv4 header.
* All is bigendian on the wire.
*/
#pragma pack(1)
typedef struct RTNETIPV4
{
#ifdef RT_BIG_ENDIAN
unsigned int ip_v : 4;
unsigned int ip_hl : 4;
unsigned int ip_tos : 8;
unsigned int ip_len : 16;
#else
/** 00:0 - Header length given as a 32-bit word count. */
unsigned int ip_hl : 4;
/** 00:4 - Header version. */
unsigned int ip_v : 4;
/** 01 - Type of service. */
unsigned int ip_tos : 8;
/** 02 - Total length (header + data). */
unsigned int ip_len : 16;
#endif
/** 04 - Packet idenficiation. */
/** 06 - Offset if fragmented. */
/** 08 - Time to live. */
/** 09 - Protocol. */
/** 0a - Header check sum. */
/** 0c - Source address. */
/** 10 - Destination address. */
/** 14 - Options (optional). */
} RTNETIPV4;
#pragma pack(0)
/** Pointer to a IPv4 header. */
typedef RTNETIPV4 *PRTNETIPV4;
/** Pointer to a const IPv4 header. */
typedef RTNETIPV4 const *PCRTNETIPV4;
/** The minimum IPv4 header length (in bytes).
* Up to and including RTNETIPV4::ip_dst. */
#define RTNETIPV4_MIN_LEN (20)
/** @name IPv4 Protocol Numbers
* @{ */
/** IPv4: ICMP */
#define RTNETIPV4_PROT_ICMP (0)
/** IPv4: TCP */
#define RTNETIPV4_PROT_TCP (6)
/** IPv4: UDP */
#define RTNETIPV4_PROT_UDP (17)
/** @} */
RTDECL(uint32_t) RTNetIPv4PseudoChecksumBits(RTNETADDRIPV4 SrcAddr, RTNETADDRIPV4 DstAddr, uint8_t bProtocol, uint16_t cbPkt);
RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t iSum, bool *pfOdd);
/**
* UDP header.
*/
#pragma pack(1)
typedef struct RTNETUDP
{
/** The source port. */
/** The destination port. */
/** The length of the UDP header and associated data. */
/** The checksum of the pseudo header, the UDP header and the data. */
} RTNETUDP;
#pragma pack(0)
/** Pointer to an UDP header. */
/** Pointer to a const UDP header. */
typedef RTNETUDP const *PCRTNETUDP;
/** The minimum UDP packet length (in bytes). (RTNETUDP::uh_ulen) */
#define RTNETUDP_MIN_LEN (8)
/**
* IPv4 DHCP packet.
*/
#pragma pack(1)
typedef struct RTNETDHCP
{
/** Hardware address type. */
/** Hardware address length. */
/** Client IPv4 address. */
/** Your IPv4 address. */
/** Server IPv4 address. */
/** Gateway IPv4 address. */
/** Client hardware address. */
/** Server name. */
} RTNETDHCP;
#pragma pack(0)
/** @todo AssertCompileSize(RTNETDHCP, ); */
/** Pointer to a DHCP packet. */
typedef RTNETDHCP *PRTNETDHCP;
/** Pointer to a const DHCP packet. */
typedef RTNETDHCP const *PCRTNETDHCP;
/**
* TCP packet.
*/
#pragma pack(1)
typedef struct RTNETTCP
{
/** 00 - The source port. */
/** 02 - The destination port. */
/** 04 - The sequence number. */
/** 08 - The acknowledgement number. */
#ifdef RT_BIG_ENDIAN
unsigned int th_win : 16;
unsigned int th_flags : 8;
unsigned int th_off : 4;
unsigned int th_x2 : 4;
#else
/** 0c:0 - Reserved. */
unsigned int th_x2 : 4;
/** 0c:4 - The data offset given as a dword count from the start of this header. */
unsigned int th_off : 4;
/** 0d - flags. */
unsigned int th_flags : 8;
/** 0e - The window. */
unsigned int th_win : 16;
#endif
/** 10 - The checksum of the pseudo header, the TCP header and the data. */
/** 12 - The urgent pointer. */
/* (options follows here and then the data (aka text).) */
} RTNETTCP;
#pragma pack(0)
/** Pointer to a TCP packet. */
/** Pointer to a const TCP packet. */
typedef RTNETTCP const *PCRTNETTCP;
/** The minimum TCP header length (in bytes). (RTNETTCP::th_off * 4) */
#define RTNETTCP_MIN_LEN (20)
/**
* Ethernet ARP header.
*/
#pragma pack(1)
typedef struct RTNETARPHDR
{
/** The hardware type. */
/** The protocol type (ethertype). */
/** The hardware address length. */
/** The protocol address length. */
/** The operation. */
} RTNETARPHDR;
#pragma pack(0)
/** Pointer to an ethernet ARP header. */
typedef RTNETARPHDR *PRTNETARPHDR;
/** Pointer to a const ethernet ARP header. */
typedef RTNETARPHDR const *PCRTNETARPHDR;
/** ARP hardware type - ethernet. */
/** @name ARP operations
* @{ */
#define RTNET_ARPOP_REQUEST UINT16_C(1) /**< Request hardward address given a protocol address (ARP). */
#define RTNET_ARPOP_REVREQUEST UINT16_C(3) /**< Request protocol address given a hardware address (RARP). */
/** Check if an ARP operation is a request or not. */
/** Check if an ARP operation is a reply or not. */
/** @} */
/**
* Ethernet IPv4 + 6-byte MAC ARP request packet.
*/
#pragma pack(1)
typedef struct RTNETARPIPV4
{
/** ARP header. */
/** The sender hardware address. */
/** The sender protocol address. */
/** The target hardware address. */
/** The arget protocol address. */
} RTNETARPIPV4;
#pragma pack(0)
/** Pointer to an ethernet IPv4+MAC ARP request packet. */
typedef RTNETARPIPV4 *PRTNETARPIPV4;
/** Pointer to a const ethernet IPv4+MAC ARP request packet. */
typedef RTNETARPIPV4 const *PCRTNETARPIPV4;
/** @todo RTNETNDP (IPv6)*/
/** @} */
#endif