TCPGetMyAddr

Command group Flag affected Reversible Execute on client Platform(s)
External commands YES NO NO All

Syntax

TCPGetMyAddr ([socket {Default 0}, ipv6 {Default kFalse}]) Returns address

Description

Note: The flag is set according to whether Omnis was able to make a call to this external command.

This Web command is multi-threaded, allowing another thread to execute in the multi-threaded server while it runs. Note that the same socket cannot safely be used concurrently by more than one thread.

TCPGetMyAddr is a domain name service command to resolve the IP address of the local computer running Omnis: the command may return a list of IP addresses in which case it uses the first address in the list. See Additional Notes below.

You can optionally pass a Socket, which corresponds to an open connection. In this case, the command returns the local IP address bound to the local endpoint of the connection. There are two cases where this is useful.

Address is an Omnis Character field which receives the IP Address of the local host. The IP address is of the form 255.255.255.254

Possible error codes are listed in the Web Command Error Codes Appendix.

Additional Notes

When passing a socket to TCPGetMyAddr, the address returned is whatever the operating system API getsockname returns, and this can be either IP v4 or v6, which depends on how the connection was established. The ip v6 parameter to TCPGetMyAddr has no effect in this case.

When passing no socket to TCPGetMyAddr, the code uses the gethostname operating system API to obtain the name of the system, and then uses the getaddrinfo operating system API to obtain a list of addresses for the host. There can several addresses in the list returned, and TCPGetMyAddr uses the first address in the list that matches the request for ip v4 or v6.

Therefore, the information returned by this command is highly dependent on information exposed by operating system APIs, and these are only cross-platform in terms of their calling interface – the information they return depends on both the Operating System and the system configuration. In the case of getaddrinfo, the order of the returned items in the list is Operating system dependent.

Example

# Return the IP address of this machine
TCPGetMyAddr Returns lIPAddress
Quit method lIPAddress