Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's the difference between sockaddr and sockaddr_in ?

0 views
Skip to first unread message

Kenny McCormack

unread,
Sep 13, 2000, 3:00:00 AM9/13/00
to
In article <HdNv5.49$tQ5.2140@burlma1-snr2>,
Barry Margolin <bar...@genuity.net> wrote:
...
>The socket API can be used for other things besides TCP/IP,
>e.g. Unix-domain sockets. Sockaddr_in is only for Internet-domain
>sockets. The program is supposed to fill in the address structure
>appropriate for the address family in use (sockaddr_in for TCP/IP,
>sockaddr_un for Unix-domain, etc.) and then cast it to the generic sockaddr
>structure when passing it to bind() or connect().

Thanks! The net at its best.


Kenny McCormack

unread,
Sep 13, 2000, 10:30:33 AM9/13/00
to
Short summary: In Linux they seem to be interchangeable, but Solaris complains.

Longer summary: Most of the networking calls use sockaddr_in, but connect() is
documented as wanting a sockaddr. It seems to work OK to cast the 2nd arg
to (struct sockaddr *)
(Even though the object was declared as and really is a struct sockaddr_in).

Is there any reason for all of this?

Barry Margolin

unread,
Sep 13, 2000, 11:40:24 AM9/13/00
to
In article <8po329$1f8$1...@yin.interaccess.com>,

The socket API can be used for other things besides TCP/IP,


e.g. Unix-domain sockets. Sockaddr_in is only for Internet-domain
sockets. The program is supposed to fill in the address structure
appropriate for the address family in use (sockaddr_in for TCP/IP,
sockaddr_un for Unix-domain, etc.) and then cast it to the generic sockaddr
structure when passing it to bind() or connect().

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

son...@my-deja.com

unread,
Sep 13, 2000, 11:52:16 AM9/13/00
to
BSD sockets are designed to work with different protocols, so they had
to have a generalised interface. sockaddr_in is specific to TCP. So to
pass a special structure to a generalised one, you have to type cast.
Since they had to have certain type info ( AF_INET ) in certain
offsets, they did not go for the most generalised void*.

In article <8po329$1f8$1...@yin.interaccess.com>,


Sent via Deja.com http://www.deja.com/
Before you buy.

Andrew Gierth

unread,
Sep 13, 2000, 12:23:47 PM9/13/00
to
>>>>> "sonyea" == sonyea <son...@my-deja.com> writes:

sonyea> BSD sockets are designed to work with different protocols, so
sonyea> they had to have a generalised interface. sockaddr_in is
sonyea> specific to TCP. So to pass a special structure to a
sonyea> generalised one, you have to type cast. Since they had to
sonyea> have certain type info ( AF_INET ) in certain offsets, they
sonyea> did not go for the most generalised void*.

the reason that void* was not used is more likely to be because it hadn't
been invented at the time that the socket interface was designed :-)

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>

0 new messages