Require help yet again

Started by
5 comments, last by 5quirrel 15 years, 12 months ago
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.
Advertisement
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"
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.
why is there a need to cast the lphost?

Thank you for your help guys
Quote:Original post by 5quirrel
why is there a need to cast the lphost?

Thank you for your help guys


Well what type is lphost declared as?

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.
ok i get some bit of light. Thank you all =).

The brackets really makes things confusing =s

This topic is closed to new replies.

Advertisement