Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Raw Sockets 2

Status
Not open for further replies.

ForeverCode

Programmer
Dec 6, 2002
41
0
0
US
I'm using raw sockets and when I pull the originating and destination port out of the packet(TCP/IP layer) I'm not getting the right port. I can't find if they are integers or what. All I can find is that they are 16 bits long.


Can anyone help me figure out how to get the port data into integers I can display?

-Micah
 
Yes, you got it. You should also probably use htons or htonl every time you intend to write a 16-bit or 32-bit word, respectively, and ntohs or ntohl every time you intend to read a 16-bit or 32-bit word, respectively. That way all your data transfer is considered to be in 'network byte order'.

The great thing about it is, if you decide to port your code to an architecture that uses big-endian byte order, for example the Motorola processors, you can keep those XtoXX calls the same—and the sockets implementation will take care of the rest.

[sub]I REALLY hope that helps.[/sub]
Will
 
Cool, thanx for the info. I'll have to keep that in mind. At the moment I'm just reading the raw packets but soon I'll be creating them as well.

-Micah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top