Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. IP Address

IP Address

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnsGe
    wrote on last edited by
    #1

    Hai Friends, How can i get the IP addrees of the current system. Plase anyone give me a step by step procedure

    S 1 Reply Last reply
    0
    • A AnsGe

      Hai Friends, How can i get the IP addrees of the current system. Plase anyone give me a step by step procedure

      S Offline
      S Offline
      SJolly
      wrote on last edited by
      #2

      Hello, I've done this before using windows sockets. I don't know if it's the best way, but it definitely works: char szHostName[400]; struct hostent *hostinfo = NULL; IN_ADDR addr; char szIP[16]; // "xxx.xxx.xxx.xxx\0" ULONG ulIP = 0; // get the dns name as a string gethostname(szHostName, 400); // get the host info (contains ip address) hostinfo = gethostbyname(szHostName); if(hostinfo == NULL) { DWORD dwError = WSAGetLastError(); // handle the error } else { // get the ip as ULONG ulIP = *reinterpret_cast(hostinfo->h_addr_list[0]); // put the ip it into an IN_ADDR addr.S_un.S_addr = ulIP; // changes ip into string sprintf(szIP, "%s", inet_ntoa(addr)); TRACE("My IP address is %s\n", szIP); } Regards, Simon

      A 1 Reply Last reply
      0
      • S SJolly

        Hello, I've done this before using windows sockets. I don't know if it's the best way, but it definitely works: char szHostName[400]; struct hostent *hostinfo = NULL; IN_ADDR addr; char szIP[16]; // "xxx.xxx.xxx.xxx\0" ULONG ulIP = 0; // get the dns name as a string gethostname(szHostName, 400); // get the host info (contains ip address) hostinfo = gethostbyname(szHostName); if(hostinfo == NULL) { DWORD dwError = WSAGetLastError(); // handle the error } else { // get the ip as ULONG ulIP = *reinterpret_cast(hostinfo->h_addr_list[0]); // put the ip it into an IN_ADDR addr.S_un.S_addr = ulIP; // changes ip into string sprintf(szIP, "%s", inet_ntoa(addr)); TRACE("My IP address is %s\n", szIP); } Regards, Simon

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Hai, Thanks for your message. But when i copy the given code lot of errors occured. IN_ADDR undeclared identifier etc. I have not insatlled Platform SDK. For running the code may i need the Paltform SDK? regards Anish

        S 1 Reply Last reply
        0
        • A Anonymous

          Hai, Thanks for your message. But when i copy the given code lot of errors occured. IN_ADDR undeclared identifier etc. I have not insatlled Platform SDK. For running the code may i need the Paltform SDK? regards Anish

          S Offline
          S Offline
          SJolly
          wrote on last edited by
          #4

          Sorry, yes you will definitely need the platform SDK. Regards, Simon

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups