Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : Re: Help with code converstion - gethostbyname.

www.cryer.info
Managed Newsgroup Archive

Re: Help with code converstion - gethostbyname.

Subject:Re: Help with code converstion - gethostbyname.
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 26 Feb 2008 18:42:32

"mataus" <mataus@gmail.com> wrote in message
news:47c025d8@newsgroups.borland.com...

> I'm trying to impliment a DNS lookup with gethostbyname() and
> I want to access the multiple IP addresses returned.  I've tested
> this in BCB and it seems easy but in Delphi I can't get my code to
> work.

Try this:

    procedure TForm1.Button1Click(Sender: TObject);
    type
        TaPInAddr = array[0..250] of PInAddr;
        PaPInAddr = ^TaPInAddr;
    var
        WSAData: TWSAData;
        remoteHost: PHostEnt;
        addr: PaPInAddr;
        I: Integer;
    begin
        if WSAStartUp(WSVersion, WSAData) = 0 then
        try
            remoteHost := gethostbyname('www.yahoo.com');
            if remoteHost <> nil then
            begin
                i := 0;
                addr := PaPInAddr(remoteHost^.h_address_list);
                while addr^[i] <> nil do
                begin
                    ShowMessage(Format('got it: %s',
[inet_ntoa(addr^[i]^)]);
                    Inc(I);
                end;
            end;
        finally
            WSACleanUp;
        end;
    end;


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive