Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-22-2001, 07:26 PM   #1
Registered: Jun 2001
Location: 28N,82W
Distribution: XP,Ubuntu 9
Posts: 472

Rep: Reputation: 30
Question socket programming question..

For those socket gurus, I have a question...

in the 'bind' system call, the second parameter is of type 'struct sockaddr'. However, I have seen most of samples use sockaddr_in. I haven't seen an explainations for this. Does anyone knw about it?

Old 11-30-2001, 08:23 PM   #2
Registered: Aug 2001
Location: Off the coast of Madadascar
Posts: 498

Rep: Reputation: 30
Although I am not sure which is better i typically use sockaddr_in
This struct has the neccesary memebrs that bind() is looking for so use this. You never know.
Old 12-05-2001, 05:57 PM   #3
LQ Newbie
Registered: Sep 2001
Posts: 21

Rep: Reputation: 15
This is C's way of doing object oriented. The socket interface was designed to support not only IP, but other protocols as well, eg IPX. If you look at the definition of sockaddr it will have an address family type, this determines what the structure should be. If it is AF_INET, then it expects sockaddr_in, etc.
Old 12-19-2001, 06:51 AM   #4
LQ Newbie
Registered: Dec 2001
Posts: 14

Rep: Reputation: 0

This is an excellent guide to socket programming, which happens to explain the answer to your question.

Basically the sockaddr is defined as a fairly simply block of memory, the different parts of which mean different things, while sockaddr_in has member variables with meaningful names that correspond to the same places as those bits of memory in sockaddr.

Old 01-14-2002, 02:23 AM   #5
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
Two best guides for socket programming I've found.

(i) "UNIX Network Programming" by W. Richard Stevens. Your question is actually explained in there. This is a classic and is definately worth it I think. ISBN 013490012X

(ii) UNIX socket programming FAQ


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me ... about Socket programming.. rajsun Programming 2 04-24-2005 04:50 PM
Socket programming question brianvdc Programming 2 12-30-2004 01:36 PM
Socket Programming Question? sharma_deepak83 Programming 1 06-29-2004 10:36 AM
C/ C++ socket programming question (proxy servers) juby Programming 4 09-30-2003 01:34 PM
UDP socket programming question. niac Programming 6 03-02-2003 02:23 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration