🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How can I Trace the Route to an IP Addres from within my program

#249
From: DreamChaser
Date: Wed, 25 Jun 2008 05:51
91 lines
4240 bytes
Bob Gonder wrote:
> 
> Look at the first link in Extras...RFC 1393.
> Then look back in this group to last week:
> 
> Date: Thu, 19 Jun 2008 00:49:44 -0500
> From: DreamChaser
> Newsgroups: borland.public.cppbuilder.internet.socket
> Subject: IP_OPT_RR and IcmpSendEcho() anybody how how?
> Message-ID: <4859f37d@newsgroups.borland.com>
> 
Thanks for the shout out Bob, but I haven't gotten IP_OPT_RR to work 
yet. Using the pseudo code that Gambit provided I am still getting an 
Options Bad error from IcmpSendEcho().

#pragma pack(push,1)
typedef struct {
    BYTE   cbType;
    BYTE   cbSize;
    BYTE   pointer;
    IPAddr addresses[62];
} RecordRouteOption, *PRecordRouteOption;
#pragma pack(pop)

     HANDLE icmp = IcmpCreateFile();
     IPAddr addr;
     char *SendData = "Hello";

    //This is www.google.com
    ipaddr.S_un.S_addr = inet_addr("74.125.47.147");


     BYTE options[sizeof(RecordRouteOption)+1] = {0};

     PRecordRouteOption option = (PRecordRouteOption) options;
     option->type = IP_OPT_RR;
     option->length = sizeof(RecordRouteOption);
     option->pointer = 4;

     (++option)->type = IP_OPT_EOL;

     IP_OPTION_INFORMATION info = {0};
     info.Ttl = 256;
     //info.Tos = ...;
     //info.Flags = ...;
     info.OptionsSize = sizeof(options);
     info.OptionsData = options;

     DWORD ReplySize = sizeof(ICMP_ECHO_REPLY) + strlen(SendData);
     ICMP_ECHO_REPLY *reply = (ICMP_ECHO_REPLY*) malloc(ReplySize);
     ...
     if( IcmpSendEcho(icmp, addr, SendData, strlen(SendData), &info, 
reply, ReplySize, 1000) > 0 )     {
       struct in_addr ReplyAddr;
       ReplyAddr.S_un.S_addr = reply.Address;
       switch (reply.Status) {
          case IP_SUCCESS:
             S.sprintf("%s Reply from %s: bytes=%d, time=%3dms, TTL=%3d",
                         Now().FormatString(TIME_FORMAT),
                         inet_ntoa(ReplyAddr),
                         reply.DataSize,
                         reply.RoundTripTime,
                         reply.Options.Ttl
                      );
             nMaxTime = (reply.RoundTripTime > nMaxTime) ? 
reply.RoundTripTime : nMaxTime;
             idx = 0xFF;
             break;
          case IP_TTL_EXPIRED_TRANSIT:
             hst = gethostbyaddr((char *) &ReplyAddr, 4, AF_INET);
             S.sprintf("\t[Hop:%3d] %15s: Time=%3dms, TOS=%3d, %s",
                         idx,
                         inet_ntoa(ReplyAddr),
                         reply.RoundTripTime,
                         reply.Options.Tos,
                         (hst) ? hst->h_name : ""
                      );
             break;
          default:
             S.sprintf("%s %s %s",
                         Now().FormatString(TIME_FORMAT),
                         inet_ntoa(ReplyAddr),
                         ErrorStrings[reply.Status - IP_STATUS_BASE]
                   );
             idx = 0xFF;
       } //EndIf (reply.Status != IP_SUCCESS)
       Memo1->Lines->Add(S);
     }
     ...
     free(reply);
     IcmpCloseHandle(icmp);
Technical Details
Message-ID: <4861dce2$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <MPG.22c8301ab312798c989a97@newsgroups.borland.com> <485faf40$1@newsgroups.borland.com> <MPG.22cb3a3e698457ac989a9a@newsgroups.borland.com> <rrj264107nnff1gqarmhq4p0v1c23k6801@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,7aa64e4617379849
X-Google-Attributes: gid11508e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 25 Jun 2008 00:51:30 -0500
From: DreamChaser <NO-Spam@No-Span.net>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: How can I Trace the Route to an IP Addres from within my program
References: <MPG.22c8301ab312798c989a97@newsgroups.borland.com> <485faf40$1@newsgroups.borland.com> <MPG.22cb3a3e698457ac989a9a@newsgroups.borland.com> <rrj264107nnff1gqarmhq4p0v1c23k6801@4ax.com>
In-Reply-To: <rrj264107nnff1gqarmhq4p0v1c23k6801@4ax.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 65.6.192.60
Message-ID: <4861dce2$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1214373090 65.6.192.60 (24 Jun 2008 22:51:30 -0700)
Lines: 91
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail