Sign in to follow this  
5quirrel

Require help yet again

Recommended Posts

5quirrel    122
Good day to all, This time i got totally zero idea what this line does Server_addr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr; I mean the right hand side.

Share this post


Link to post
Share on other sites
MJP    19787
Okay...

-the variable "lphost" is cast to a pointer of type "LPIN_ADDR"
-lphost, as a pointer, is dereferenced to access the "h-addr" member
-"h-addr" is dereferenced to access teh s_addr member
-"s_addr", which is a member of "sin_addr", which is a member of Server_addr, is assigned the value of the "s_addr" member of "h_addr"

Share this post


Link to post
Share on other sites
kiwibonga    183
s_addr is the unsigned long representation of an IP address. So it basically takes lphost's IP in unsigned long form and stores it in Server_addr's unsigned long IP.

Share this post


Link to post
Share on other sites
kiwibonga    183
He doesn't cast lphost, he casts lphost->h_addr.

Originally, h_addr is a PIN_ADDR (that is, a pointer to an IN_ADDR), but they cast it to a LPIN_ADDR, because that's a "far pointer." This is just for compatibility with 16 bit apps, which needed far pointers to simulate 32 bit pointers. On a 32 bit (or 64 bit) platform, it makes no difference, you can omit the cast.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this