Thanks! The net at its best.
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?
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.
In article <8po329$1f8$1...@yin.interaccess.com>,
Sent via Deja.com http://www.deja.com/
Before you buy.
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/>