[fpc-pascal] Test for valid ip address
Jonas Maebe
jonas.maebe at elis.ugent.be
Thu Jul 28 10:26:32 CEST 2016
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.
Jonas
More information about the fpc-pascal
mailing list