PDA

View Full Version : difference between sockaddr and sockaddr_in


EscapeCharacter
10-31-2002, 05:17 AM
whats the difference between the two? ive checked their size and they are both the same size, are they exactly the same just have different names for different systems?

bwkaz
10-31-2002, 09:40 AM
It's a form of inheritance.

sockaddr is the generic, protocol-independent struct (it would be an interface in Java, if you want to think that way) that all the socket functions take. sockaddr_in is the IPv4-specific struct that works for, well, IPv4 addresses (the _in is for "internet", AFAIK).

There's also sockaddr_in6, sockaddr_ipx, etc, I believe. These are for IPv6 and IPX, if I'm right and they do exist. They're all the same size, because you're passing pointers around, and the code you're calling has to be able to know how big the struct you're using is. But IPX, for example, will have a completely different internal format (addresses, for one, are set up totally differently), which the connect() (or whatever) syscall will (based on the sa_family member of the struct) have to interpret differently.

stuka
10-31-2002, 11:33 AM
Just as an additional tidbit, the sockaddr_in has a bunch of zero-padding in it to bring it up to size.

EscapeCharacter
11-01-2002, 12:10 PM
so could i think of sockaddr_in as something like this

struct sockaddr_in{
struct sockaddr;
...
extra stuff for sockaddr_in;
};

as in sockaddr_in will contain all the stuff that sockaddr has but will have some additional stuff(yeah i know stuff is a bad word but hey im from california :P)

stuka
11-01-2002, 12:31 PM
I think that's right - Beej's page has a better description IIRC.