🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Error handling in Indy 10

#345
From: Dennis Cote
Date: Wed, 16 Apr 2008 21:00
72 lines
3660 bytes
Remy Lebeau (TeamB) wrote:
> 
> You are using the TIdICMPClient component, which uses a RAW socket 
> internally (as opposed to using a TCP or UDP socket).  Admin rights are 
> required in order to use RAW sockets on NT4 onwards (which means your code 
> should not have worked on XP, either, unless you are running as an admin). 
> Of course, Microsoft circumvents its own rules by allowing icmp.dll to use 
> RAW sockets without admin rights.
> 

Yes, I am running as an administrator under XP and Vista.

> 
> Rather than casting, you could disable range checking itself for 
> NewSocketHandle().  Indy does this in a couple of other places, for example:
> 
>     function TIdStackBSDBase.NewSocketHandle(const ASocketType: 
> TIdSocketType;
>         const AProtocol: TIdSocketProtocol;
>         const AIPVersion: TIdIPVersion = ID_DEFAULT_IP_VERSION;
>         const AOverlapped: Boolean = False): TIdStackSocketHandle;
>     begin
>         {$IFOPT R+}
>         {$DEFINE RestoreRangeCheckingON}
>         {$R-}
>         {$ENDIF}
>         Result := CheckForSocketError(WSSocket(IdIPFamily[AIPVersion], 
> ASocketType, AProtocol, AOverlapped));
>         {$IFDEF RestoreRangeCheckingON}
>         {$R+}
>         {$UNDEF RestoreRangeCheckingON}
>         {$ENDIF}
>     end;
> 

This would also disable the other range check done during the call of 
WSSocket(). I'm don't think that is needed, and it should probably be 
left until it is known to cause a problem.

> 
>> I also suspect this same error may exist in other places in the code.
> 
> Actually, it doesn't.  Everywhere else that calls CheckForSocketError() 
> passes it an Integer.
> 

Good to hear.

> 
> Since CheckForSocketError() is expecting an Integer error code, not a 
> TSocket handle, I would suggest changing TIdStackBSDBase.NewSocketHandle() 
> to the following instead:
> 
>     function TIdStackBSDBase.NewSocketHandle(const ASocketType: 
> TIdSocketType;
>         const AProtocol: TIdSocketProtocol;
>         const AIPVersion: TIdIPVersion = ID_DEFAULT_IP_VERSION;
>         const AOverlapped: Boolean = False): TIdStackSocketHandle;
>     begin
>         Result := WSSocket(IdIPFamily[AIPVersion], ASocketType, AProtocol, 
> AOverlapped);
>         if Result = Id_INVALID_SOCKET then begin
>             RaiseLastSocketError;
>         end;
>     end;
> 

Thanks Remy. I will make this change in my local source file. Will this 
also be changed in the Indy SVN source, or will I have to apply a patch 
to future downloads?

Dennis Cote
Technical Details
Message-ID: <480668fa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <480632fb$1@newsgroups.borland.com> <4806604b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9330c485b2d28336
X-Google-Attributes: gid11508e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 16 Apr 2008 15:00:44 -0600
From: Dennis Cote <denniscote@gmail.com>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Error handling in Indy 10
References: <480632fb$1@newsgroups.borland.com> <4806604b$1@newsgroups.borland.com>
In-Reply-To: <4806604b$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 142.179.167.5
Message-ID: <480668fa$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1208379642 142.179.167.5 (16 Apr 2008 14:00:42 -0700)
Lines: 72
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail