struct ist größer als in einem anderen Programm???
-
[quote ~Asdok]hi,
ich hab hier zwei programme die beide mit arp-netzpaketen arbeiten und eine struktur definiert haben
typedef struct _arphdr { USHORT ar_hrd; /* format of hardware address */ USHORT ar_pro; /* format of protocol address */ UCHAR ar_hln; /* length of hardware address */ UCHAR ar_pln; /* length of protocol address */ USHORT ar_op; /* ARP opcode (command) */ UCHAR ar_sha[ETH_ALEN]; /* sender hardware address */ ULONG ar_sip; /* sender IP address */ UCHAR ar_tha[ETH_ALEN]; /* target hardware address */ ULONG ar_tip; /* target IP address */ } ArpHdr;beide programme sind in Visual Stuio 2008 geschrieben. Wenn ich bei dem einen Programm ein
sizeof(ArpHdr);erhalte ich 28 Byte größe, bei dem anderen Programm sind es 32 Byte
Wenn ich mir das ganze zur Laufzeit auf Hex-Ebene ansehe, ist in dem größeren Header etwas "verrutscht", informationen die eigentlich in das ar_tha Feld gehören, stehen zum Teil in ar_sip drin.
Ich verstehe einfach nicht, was diese struct gegenüber dem anderen Programm vergrößert. Ist wirklich copy/pasted..... aufjedenfall verursacht mir diese größere header massive probleme, weil der ganze kram jetzt nicht mehr richtig läuft
hat jemand ne idee woran das liegen kann?[/quote]
-
Die beiden Compiler richten die Struktur-Member unterschiedlich aus. Schalte dieses Verhalten einfach aus:
#include <pshpack1.h> typedef struct _arphdr { USHORT ar_hrd; /* format of hardware address */ USHORT ar_pro; /* format of protocol address */ UCHAR ar_hln; /* length of hardware address */ UCHAR ar_pln; /* length of protocol address */ USHORT ar_op; /* ARP opcode (command) */ UCHAR ar_sha[ETH_ALEN]; /* sender hardware address */ ULONG ar_sip; /* sender IP address */ UCHAR ar_tha[ETH_ALEN]; /* target hardware address */ ULONG ar_tip; /* target IP address */ } ArpHdr; #include <poppack.h>
-
do not use a struct at all. Use an unsigned char array of the required
size and write packing and unpacking functions that takes care of size,
endianess and signeds encoding. Then the code will be portable to any
architecture hands down.