|
Terry,
RTVNETA SYSNAME(&SYSNAME)
This is the SNA/APPC system name.
PING RMTSYS(&SYSNAME) RCVMSG MSGTYPE(*INFO) MSG(&MSGDTA) CHGVAR VAR(&IPADDR) VALUE(%SST(&MSGDTA 57 12))
This is the TCP/IP DNS name. Nothing requires this to match the SNA name. Granted, many people would probably use the same name for both SNA and DNS, but there's no promise that this'll always work. Heck, you could actually end up pinging a different system this way!
Also, there's nothing that forces the IP address to always be in position 57 of the message. Anyone could use CHGMSGD to change the position. IBM could re-word the text of the message in the next release of OS/400. You could install a different language on the system, and it'd be in a different position. You should be getting the address from the message data, rather than from the message itself!
Worse, you've hard-coded the length at 12. If the IP address were "207.100.123.206' your program would try to ping '207.100.123.' chopping off the last number. If the IP address were '9.3.21.4' your program would grab the whole address plus part of the wording that comes after it.
CHGVAR VAR(&PATH) VALUE('net use T: \\' *TCAT + &IPADDR *TCAT '\CMTEMP')
This is Windows Networking. Only in newer versions of Windows can you use the IP address in a UNC name, in older versions you have to use the NetBIOS name.
And, naturally, the NetBIOS name is not the same as the SNA name or DNS name. Granted, the admin might make them all the same for consistency, but he doesn't have to... just like the DNS name.
Furthermore, the whole idea of getting the IP address for a "machine" is flawed. IP addresses are assigned to network interfaces, they're not assigned to computers.
You'd be better off hard-coding the name, or putting it in a data area that's easily changed, than you would writing code like the one you posted here. That way, it's simple and won't mislead the next guy.
If you REALLY want to write program that figures it out yourself, you need to use the correct APIs. gethostname() will tell you the host name of your system. gethostbyname() will perform a DNS or host table lookup on a domain name to get it's IP address. The QZLSLSTI API can be used to get the Windows Networking name of the server.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.