User Tools

Site Tools


finding_20the_20host_20ip_20address

Finding the host IP address

by Richard Russell, May 2007

It is easy to discover the host PC's network name using the FN_gethostname function in the SOCKLIB library, but there is no equivalent function for discovering its IP (Internet Protocol) address. However that can easily be achieved using a little code:

        INSTALL @lib$+"SOCKLIB"
        PROC_initsockets
 
        hostent% = FN_sethost(FN_gethostname)
        hostip% = !!hostent%!12

The code sets hostip% to the host IP address; note the use of three exclamation marks! The INSTALL and PROC_initsockets statements are included here for completeness, but of course it is quite likely that your program has already executed them earlier in the code.

If you need the IP address as a string you can create that from hostip% as follows:

        SYS `inet_ntoa`, hostip% TO lpszip%
        hostip$ = $$lpszip%

This will set hostip$ to a string in the conventional 'dot' notation “aa.bb.cc.dd”.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
finding_20the_20host_20ip_20address.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1