[fpc-pascal] Test for valid ip address

Rainer Stratmann rainerstratmann at t-online.de
Thu Jul 28 10:40:34 CEST 2016


Am Donnerstag, 28. Juli 2016, 10:26:32 schrieb Jonas Maebe:
> On 28/07/16 10:14, Koenraad Lelong wrote:
> > I need a way to test if an string containing an ipv4-address is really
> > an ipv4-address.
> > I tried
> > tmpAddress:=HostAddrToStr(StrToHostAddr(IPAddressStr));
> > writeln(tmpAddress);
> > 
> >  if (tmpAddress='0.0.0.0') then
> >  
> >   begin
> >   
> >    writeln('Error in IP-address');
> >    IPAddressStr:=tmpAddress;
> >   
> >   end;
> > 
> > When I enter 192.168.185.297 (i.e. not a valid ipv4 address) in
> > IPAddressStr I get
> > 192.168.185.41
> > not the expected error-message.
> 
> You can add a multiple of 256 to any octet of an IPv4 address in most
> programs. Try it in your browser, it will probably also work.

In Firefox 45.2.0 on Linux it does not work.
It is confusing anyway.
 
> 
> Jonas
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list