VirtualBox

Changeset 10964 in vbox for trunk/include


Ignore:
Timestamp:
Jul 30, 2008 1:48:29 AM (17 years ago)
Author:
vboxsync
Message:

IPRT: added RTNETTCP to iprt/net.h and started on the IPv4 checksum and validation methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/net.h

    r10963 r10964  
    150150    unsigned int    ip_len : 16;
    151151#else
    152     /** Header length given as a 32-bit word count. */
     152    /** 00:0 - Header length given as a 32-bit word count. */
    153153    unsigned int    ip_hl : 4;
    154     /** Header version. */
     154    /** 00:4 - Header version. */
    155155    unsigned int    ip_v : 4;
    156     /** Type of service. */
     156    /** 01 - Type of service. */
    157157    unsigned int    ip_tos : 8;
    158     /** Total length (header + data). */
     158    /** 02 - Total length (header + data). */
    159159    unsigned int    ip_len : 16;
    160160#endif
    161     /** Packet idenficiation. */
     161    /** 04 - Packet idenficiation. */
    162162    uint16_t        ip_id;
    163     /** Offset if fragmented. */
     163    /** 06 - Offset if fragmented. */
    164164    uint16_t        ip_off;
    165     /** Time to live. */
     165    /** 08 - Time to live. */
    166166    uint8_t         ip_ttl;
    167     /** Protocol. */
     167    /** 09 - Protocol. */
    168168    uint8_t         ip_p;
    169     /** Header check sum. */
     169    /** 0a - Header check sum. */
    170170    uint16_t        ip_sum;
    171     /** Source address. */
    172     uint32_t        ip_src;
    173     /** Destination address. */
    174     uint32_t        ip_dst;
    175     /** Options (optional). */
     171    /** 0c - Source address. */
     172    RTNETADDRIPV4   ip_src;
     173    /** 10 - Destination address. */
     174    RTNETADDRIPV4   ip_dst;
     175    /** 14 - Options (optional). */
    176176    uint32_t        ip_options[1];
    177177} RTNETIPV4;
     
    198198/** @} */
    199199
     200/**
     201 * Calculates the checksum of the IPv4 header.
     202 *
     203 * @returns Checksum.
     204 * @param   pIpHdr      Pointer to the IPv4 header to checksum. Assumes
     205 *                      the caller already checked the minimum size requirement.
     206 */
     207RTDECL(uint16_t) RTNetIPv4Checksum(PCRTNETIPV4 pIpHdr);
     208
     209/**
     210 * Verifies the header version, header size, packet size, and header checksum
     211 * of the specified IPv4 header.
     212 *
     213 * @returns true if valid, false if invalid.
     214 * @param   pIpHdr      Pointer to the IPv4 header to validate.
     215 * @param   cbHdrMax    The max header size, or  the max size of what pIpHdr points
     216 *                      to if you like. Note that an IPv4 header can be up to 60 bytes.
     217 * @param   cbPktMax    The max IP packet size, IP header and payload. This doesn't have
     218 *                      to be mapped following pIpHdr.
     219 */
     220RTDECL(bool) RTNetIPv4IsValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax);
     221
    200222
    201223/**
     
    216238#pragma pack(0)
    217239AssertCompileSize(RTNETUDP, 8);
     240/** Pointer to an UDP header. */
    218241typedef RTNETUDP *PRTNETUDP;
     242/** Pointer to a const UDP header. */
    219243typedef RTNETUDP const *PCRTNETUDP;
    220244
    221 /** The minimum IPv4 packet length (in bytes). (RTNETUDP::uh_ulen) */
     245/** The minimum UDP packet length (in bytes). (RTNETUDP::uh_ulen) */
    222246#define RTNETUDP_MIN_LEN   (8)
    223247
     
    258282} RTNETDHCP;
    259283#pragma pack(0)
    260 /// @todo AssertCompileSize(RTNETDHCP, );
     284/** @todo AssertCompileSize(RTNETDHCP, ); */
    261285/** Pointer to a DHCP packet. */
    262286typedef RTNETDHCP *PRTNETDHCP;
    263287/** Pointer to a const DHCP packet. */
    264288typedef RTNETDHCP const *PCRTNETDHCP;
     289
     290
     291/**
     292 * TCP packet.
     293 */
     294#pragma pack(1)
     295typedef struct RTNETTCP
     296{
     297    /** 00 - The source port. */
     298    uint16_t        th_sport;
     299    /** 02 - The destination port. */
     300    uint16_t        th_dport;
     301    /** 04 - The sequence number. */
     302    uint32_t        th_seq;
     303    /** 08 - The acknowledgement number. */
     304    uint32_t        th_ack;
     305#ifdef RT_BIG_ENDIAN
     306    unsigned int    th_win : 16;
     307    unsigned int    th_flags : 8;
     308    unsigned int    th_off : 4;
     309    unsigned int    th_x2 : 4;
     310#else
     311    /** 0c:0 - Reserved. */
     312    unsigned int    th_x2 : 4;
     313    /** 0c:4 - The data offset given as a dword count from the start of this header. */
     314    unsigned int    th_off : 4;
     315    /** 0d - flags. */
     316    unsigned int    th_flags : 8;
     317    /** 0e - The window. */
     318    unsigned int    th_win : 16;
     319#endif
     320    /** 10 - The checksum of the pseudo header, the TCP header and the data. */
     321    uint16_t        th_sum;
     322    /** 12 - The urgent pointer. */
     323    uint16_t        th_urp;
     324    /* (options follows here and then the data (aka text).) */
     325} RTNETTCP;
     326#pragma pack(0)
     327AssertCompileSize(RTNETTCP, 20);
     328/** Pointer to a TCP packet. */
     329typedef RTNETTCP *PRTNETTCP;
     330/** Pointer to a const TCP packet. */
     331typedef RTNETTCP const *PCRTNETTCP;
     332
     333/** The minimum TCP header length (in bytes). (RTNETTCP::th_off * 4) */
     334#define RTNETTCP_MIN_LEN    (20)
    265335
    266336
Note: See TracChangeset for help on using the changeset viewer.

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