Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Loop through an IP address in Pascal
Is there any function that will convert an IP address to LongINT and vice versa? I know both C and PHP have a standard function for this but canot find any in Pascal.
I've found this great library that claims to do this, inetaux.pas. Though it does a good job reordering the byte order the implementation of the functions StrToAddr() and AddrToString() seem to be flawed, or at least my implementation of them:
sipLng := StrToAddr(sIp);
eipLng := StrToAddr(eIp);
j += 1;
sipLng += 1;
writeln(sipLng,' ',eipLng,' ',j);
until sipLng = eipLng;
Here is a link to the library:http://www.bastisoft.de/pascal/sources/pasinet.zip
All the writeln() calls are just for debugging. I can't really look at the library and understand it too well. As I'm a newb to Pascal.
I mostly use Free Pascal on Mac and Unix, and Delphi for Windows. I've looked through the documentation of Free Pascal and couldn't find anything.
EDIT: it looks like the function is flawed. Since they each are turned into a signed LongInt sipLng is actually a greater value than the ending IP address, in this case eipLng().
Here is an example with sipLng at 192.168.2.110 and eipLng set to 192.168.2.200
if I understand this correctly the loop is infinite because the starting ip address was converted to a higher value than the ending ip address.
How do most other developers solve this problem with FreePascal? I'm sure it comes up a lot.
0 · ·