Thread: Simple Socket Question

  1. #1
    .........
    Join Date
    Nov 2002
    Posts
    303

    Simple Socket Question

    Hi I'm reading a tutorial on sockets, the Beej one I'm sure alot of you have read it. Anyways
    it says that before I call bind() I can use INADDR_ANY as my ip and 0 as my port and then bind() will "fill in" the ip that the current process is running on and pick a port for me.
    Ok the call to bind() works, so I'm assuming it somehow used my ip because if I try using an invalid IP bind() fails. When I try to print out my ip and port after the call to bind, all I get are zero's. When I specify a port and ip myself It prints them out correctly. Am I write in assuming that bind does not fill in the sockaddr_in structure for you but does find your ip and use a port for the call to bind()? I know there are other ways to get ip's but this is bugging me, especially cause bind() works so it must have my ip. Any help would be great.

  2. #2
    .........
    Join Date
    Nov 2002
    Posts
    303
    Sweet thank you! I kept thinking there was an error somewhere in the code it was driving me nuts lol.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    88

    Re: Simple Socket Question

    Originally posted by SourceCode
    the Beej one I'm sure alot of you have read it.
    yeah it is super cool.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  2. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  3. Socket question
    By ~Kyo~ in forum Game Programming
    Replies: 4
    Last Post: 11-04-2004, 06:25 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM