LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2009, 09:29 AM   #1
aryan1
Member
 
Registered: Jul 2009
Posts: 50

Rep: Reputation: 16
Question casting problem or "puzzle" regarding hex numbers


Hi,

Below is some hex data:

58 ff eb 06 c0 a8 02 05 39 10 23 d4 8b f8 84 a5 18 00 6e d9
49 2b 4f 4b 20 54 54 6d 61 69 6c 20 50 4f 50 33 20 53 65 72
76 65 72 0d 0a

When you cast the above data into struct msg, which is defined below, thSport and thDport appear to be 6ed9 and 492b, respectively. However, I expect them to be 006e and d949.

The rest (ipSrc, ipDst, thSeq, thAck, thFlags) appears to be fine.

struct msg
{
struct in_addr ipSrc, ipDst;
u_int32_t thSeq;
u_int32_t thAck;
u_char thFlags;
u_short thSport;
u_short thDport;
};

I use Ubuntu and gcc 4.2.4

Any ideas ?

Thanks.
 
Old 08-03-2009, 09:38 AM   #2
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
It's an alignment issue. The variable 'thFlags' gets padded by the compiler by another byte right afterwards, and that's why there's this one byte offset.

Wikipedia

Scroll down to about halfway.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Perl Script To Help Solve the "M I U" puzzle on Linux or Unix LXer Syndicated Linux News 0 06-01-2008 09:10 AM
help: puzzle about "__stack_chk_fail" shawpinlee Programming 2 09-16-2007 12:04 AM
Wierd! Difference between two "random" numbers is always the same. How? WindowBreaker Slackware 10 08-28-2007 08:48 AM
Fiber card "WWID" numbers balajipriya Linux - Hardware 2 12-15-2004 03:50 AM
That "SuSE green" -- what are the RGB numbers? J.W. General 5 08-12-2004 05:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration