Thread: Obtaining your IP address

  1. #1
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    You shouldn't need to connect a socket just to find out what your IP is.

    char name[256], * ip ;
    if (gethostname(name,255) == 0)
     struct hostent * hp ;
     struct in_addr addr ;
     hp = gethostbyname (name) ;
     if (!hp) 
      // error
     memcpy (&addr, hp->h_addr_list[0], hp->h_length) ;
     ip = inet_ntoa (addr) ;
     // code with this, etc
     // error
    I don't know what the portability situation with this is, but it works fine for me.

  2. #2
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    You sure are quick to fly off the handle, sir. I figured it would be acceptable as there ARE other replies in that thread, and guess what? Oh no! They aren't yours! Oh wait, I see. They were glorifying you, so they are acceptable. Of course. It all makes sense. If someone doubts you, it goes in a thread where others won't see it in your FAQ. Now as I did not read your full topic, seeing as I do not need heaps and heaps of your advice, I did not see the message about not posting. Maybe you should edit the FIRST post to say that. Of course, don't want to be a burden.

    Chill. You seem to be on a power trip and quick to flame. My apologies for making a suggestion.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    There, problem solved, that thread is closed. vVv, just PM me or another mod when you want to update it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux raw socket programming
    By cnb in forum Networking/Device Communication
    Replies: 17
    Last Post: 11-08-2010, 08:56 AM
  2. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM