🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9505

how to get the ip address that connects to the internet NOT the local one..

#9505
From: Oren Halvani
Date: Tue, 06 Jul 2004 15:32
44 lines
1958 bytes
hi dear builders,

i'm try to get the ip-address that connects to the internet:
i'm using the following code..

but it gives me 2 ip-adresses: the local address and the address
that connects to the internet...

my question now is how to get ONLY the ip-address that
connects to the internet..?

any suggestions..?


Oren

/*****************************************************/
#include <wininet.h>
#include <winsock.h>

String GetIP(void)
{
   AnsiString retVal; WSAData wsaData;

   if(!WSAStartup(MAKEWORD(1,1),&wsaData))
   {
     char ac[80];
     if(gethostname(ac,sizeof(ac)) != SOCKET_ERROR)
     {
       hostent *phe = gethostbyname(ac);
       if(phe)
       {
         in_addr addr;
         for(int i = 0; phe->h_addr_list[i] != 0; ++i)
         {
           CopyMemory(&addr, phe->h_addr_list[i], sizeof(in_addr));
           if(i > 0) AppendStr(retVal, "."); AppendStr(retVal, inet_ntoa(addr));
         }
       }
     }
   }
   WSACleanup(); return retVal;
}
/*****************************************************/
Technical Details
Message-ID: <40eac5cb@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,869e2df9c5cbdd04,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Oren Halvani" <NoSpam@fdtd.com>
From: "Oren Halvani" <NoSpam@fdtd.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: how to get the ip address that connects to the internet NOT the local one..
Date: Tue, 6 Jul 2004 17:32:18 +0200
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 217.234.95.198
Message-ID: <40eac5cb@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1089127883 217.234.95.198 (6 Jul 2004 08:31:23 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail