Network Protocol/HEADER

From Custom Mario Kart
Jump to navigation Jump to search

This record is the header of a set of other records. The header itself contains a magic, a CRC32 checksum and 8 byte values about the length of the other packages. The CRC32 checksum doesn't include other records like SLOT. The length can be used to determine the type or number of records of same type:

C coding example

As C struct, it looks like:

typedef struct udp_header_t
{
  /*00*/    u32		magic;		// always 0
  /*04*/    u32		crc32;		// CRC32 checksum

  /*08*/    u8		header_size;	// size of this header, always 0x10
  /*09*/    u8		race_hd1_size;	// size of RACE_HEAD1,	0 or 0x28
  /*0a*/    u8		race_hd2_size;	// size of RACE_HEAD2,	0 or 0x28
  /*0b*/    u8		select_size;	// size of SELECT,	0 or 0x04 or 0x38
  /*0c*/    u8		race_data_size;	// size of RACE_DATA,	0 or 0x40 or 0x80
  /*0d*/    u8		user_size;	// size of USER,	0 or 0xc0
  /*0e*/    u8		item_size;	// size of ITEM,	0 or 0x08 or 0x10
  /*0f*/    u8		event_size;	// size of EVENT,	0 or 0x18 .. 0xf8

  /*10*/    u8		data[0];	// data section
}
__attribute__ ((packed)) udp_header_t;

CRC32

To calculate the checksum, do the following:

  1. Replace the actual checksum with four empty bytes (so the packet now starts with eight empty bytes)
  2. Now calculate a normal CRC32 checksum of the packet.
  3. Store the checksum at bytes 0x5 to 0x8 as big endian number.

Links

Template:MKWii Network Protocol