User Tools

Site Tools


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"
        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 “”.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
finding_20the_20host_20ip_20address.txt · Last modified: 2018/04/17 17:10 by tbest3112