site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com On Sep 18, 2004, at 16:05, Adrian Bool wrote: Keep in mind that _IP_VHL *is* defined when it is used in the kernel. struct xx { unsigned int xa:4; unsigned int xb:4; char xc; }; struct xx XX; main() { XX.xa = 4; XX.xb = 5; XX.xc = 255; printf("%x\n",*(int *)&XX); } PPC: 45ff0000 x86: ff54 Cheers, Justin -- Justin C. Walker, Curmudgeon-At-Large * Institute for General Semantics | When LuteFisk is outlawed | Only outlaws will have | LuteFisk *--------------------------------------*-------------------------------* _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... On 18 Sep 2004, at 06:55, Matt Jaffa wrote: despite the fact that some of the other stuff might be wrong, why wouldn't the ip_v be the right version? The output does print out 4 like it should be. I had a look at /usr/include/netinit.h for the definition of struct ip, struct ip { #ifdef _IP_VHL u_char ip_vhl; /* version << 4 | header length >> 2 */ #else #if BYTE_ORDER == LITTLE_ENDIAN u_int ip_hl:4, /* header length */ ip_v:4; /* version */ #endif #if BYTE_ORDER == BIG_ENDIAN u_int ip_v:4, /* version */ ip_hl:4; /* header length */ #endif I am confused now, as I thought that ENDIANness was the ordering of bytes. I that were the case then there would be no need to change round the nibbles depending upon the ENDIANness of the local machine. Try something like this on big-endian (PPC) and little-endian (x86) machines: The bit-ordering is the same, but the layout of bit-fields within a "storage unit" follows the layout in the source...(it makes sense, really). That's why the endianness distinction is made when using bitfields. You want the 'first' byte to show '45' in both orientations (my code doesn't distinguish, hence one is the reverse of the other). This email sent to site_archiver@lists.apple.com
participants (1)
-
Justin Walker