🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5227

Re: How can I obtain local IP ( %d . %d . % d . %d )

#5227
From: Vladimir Stefanovic
Date: Thu, 23 Sep 2004 18:32
55 lines
2171 bytes
> Look at inet_ntoa() as well.

Now I grep-searched my archive and succeded to
make one version, but I have some other questions
related to some code fragment placement. In the archives
I searched those fragments were separated.

The code is from:
{community.borland.com}

Article #19707: Getting local hostname from winsock.

Question and Answer Database

FAQ: FAQ4707C - Getting local hostname from winsock.
Category: Internet/WEB
Platform: All-32Bit
 Product: C++Builder3.x,   C++Builder4.x,


void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //
    // Should this be in constructor?
    //
    WORD wVersionRequested;
    WSADATA wsaData;
    file://Start up WinSock
    wVersionRequested = MAKEWORD(1, 1);
    WSAStartup(wVersionRequested, &wsaData);

    //
    // Body
    //
    hostent *p;
    char s[128];
    char *p2;
    file://Get the computer name
    gethostname(s, 128);
    p = gethostbyname(s);
    Memo1->Lines->Add(p->h_name);
    file://Get the IpAddress
    p2 = inet_ntoa(*((in_addr *)p->h_addr));
    Memo1->Lines->Add(p2);

    //
    // Should this be in destructor?
    //
    WSACleanup();
}

--

Best regards,
Vladimir Stefanovic
Technical Details
Message-ID: <41531659$1@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
References: <4152db44@newsgroups.borland.com> <4152dd4d@newsgroups.borland.com> <41530a8e$3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f48006f510b9e3bc
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <spam@not.needed>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4152db44@newsgroups.borland.com> <4152dd4d@newsgroups.borland.com> <41530a8e$3@newsgroups.borland.com>
Subject: Re: How can I obtain local IP ( %d . %d . % d . %d )
Date: Thu, 23 Sep 2004 20:32:25 +0200
Lines: 58
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
NNTP-Posting-Host: 213.137.116.199
Message-ID: <41531659$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1095964249 213.137.116.199 (23 Sep 2004 11:30:49 -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