LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 11-22-2001, 08:26 PM   #1
concoran
Member
 
Registered: Jun 2001
Location: 28N,82W
Distribution: XP,Ubuntu 9
Posts: 468

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?

Thanks,
 
Old 11-30-2001, 09:23 PM   #2
tarballedtux
Member
 
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, 06:57 PM   #3
pinoy
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, 07:51 AM   #4
Tonneman
LQ Newbie
 
Registered: Dec 2001
Posts: 14

Rep: Reputation: 0
http://www.ecst.csuchico.edu/~beej/guide/net/html/

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.

Tonneman.
 
Old 01-14-2002, 03:23 AM   #5
kervin
Member
 
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
http://www.lcg.org/sock-faq/
 
  


Reply


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 05:50 PM
Socket programming question brianvdc Programming 2 12-30-2004 02:36 PM
Socket Programming Question? sharma_deepak83 Programming 1 06-29-2004 11:36 AM
C/ C++ socket programming question (proxy servers) juby Programming 4 09-30-2003 02:34 PM
UDP socket programming question. niac Programming 6 03-02-2003 03:23 PM


All times are GMT -5. The time now is 02:08 PM.

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