I have a structure I wrote that should represent the entire UDP packet, with the ethernet header and everything. There he is:
#pragma pack(1)
struct UDPPacket {
unsigned char dstmac[6];
unsigned char srcmac[6];
WORD ethtype;
struct {
unsigned ver : 4;
unsigned len : 4;
} verlen;
BYTE tos;
WORD iplen;
WORD id;
struct {
unsigned flags : 3;
unsigned fragmentation : 13;
} flagfrag;
BYTE ttl;
BYTE protocol;
WORD ipchecksum;
DWORD src;
DWORD dest;
WORD srcport;
WORD destport;
WORD udplen;
WORD udpchecksum;
unsigned char data[10000];
};
#pragma pack()
Of course, this is a representation of a real UDP packet, bytes must be of the same offset as in the packet, and pointers to this type of structure will be discarded unsigned char*for sending.
My problem is that when I try to assign something after UDPPacket.verlen, it skips forward about 5 bytes and starts there. For example, when I assign iplenfeild and not set bytes at offsets 16 and 17, it assigns them to about 23 and 24 (I can’t say for sure because I do not have my program available on my phone).
Is there an obvious reason for this that I am absent, or am I just doing something wrong?