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