Roger:
> Is there an easy way to get the IP address of a machine in Forth?
A machine could have more than one IP address. If your PC only has
one network card, you may try this:
LIBRARY WSOCK32.DLL
FUNCTION: gethostbyname ( name -- hostent )
FUNCTION: gethostname ( name len -- x )
FUNCTION: WSACleanup ( -- err )
FUNCTION: WSAStartup ( VersionRequired WSAData -- err )
\ typedef struct hostent {
\ char FAR* h_name;
\ char FAR FAR** h_aliases;
\ short h_addrtype;
\ short h_length;
\ char FAR FAR** h_addr_list;
\ } hostent;
: /SOCK $101 HERE WSAStartup THROW ;
: SOCK\ WSACleanup DROP ;
: @DATA ( -- hostent ) PAD 80 gethostname THROW PAD gethostbyname ;
: @IP ( hostent -- ip ) 12 + @ @ @ ;
: .IP ( ip -- ) 3 0 DO DUP $FF AND 1 .R ." ." 8 RSHIFT LOOP . ;
/SOCK @DATA @IP .IP SOCK\
Regards,
Federico de Ceballos
**************************************************************************************************
The contents of this email and any attachments are confidential.
They are intended for the named recipient(s) only.
If you have received this email in error please notify the system manager or the
sender immediately and do not disclose the contents to anyone or make copies.
** eSafe scanned this email for viruses, vandals and malicious content. **
**************************************************************************************************
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu Aug 12 2004 - 00:46:11 PDT
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.