Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread Koenraad Lelong
Op 28-07-16 om 10:38 schreef Christo: The in_addr IP address type is a packed record of byte, so if an IP address part larger than 255 is encountered in a string it will be truncated when copied to the byte record using StrToHostAddr. This probably means you have to use some other means of dete

Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread Rainer Stratmann
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); >

Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread Christo
On Thu, 2016-07-28 at 10:14 +0200, Koenraad Lelong wrote: > 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. > > According to the rtl-manual : > > function StrToHostAddr(IP: AnsiString) : in_addr > Description

Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread Mattias Gaertner
On Thu, 28 Jul 2016 10:26:32 +0200 Jonas Maebe wrote: > 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); > > i

Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread Rainer Stratmann
The IP-Adress is a dword, but you can change, that it fits for you. function str_getval( str : shortstring ) : longint; var cod : longint; begin val( str , result , cod ); end; function ip_from_string( ipstr : shortstring ; out error : boolean ) : dword; var c : char; ipn , pointanz : longint

Re: [fpc-pascal] Test for valid ip address

2016-07-28 Thread 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'); IPAd

[fpc-pascal] Test for valid ip address

2016-07-28 Thread Koenraad Lelong
Hi, 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