Collaboration diagram for Host Lookup:
Files | |
file | hostlookup.c |
Implementation of host lookup functionality. | |
file | hostlookup.h |
Interface to host lookup functions. | |
Data Structures | |
struct | INetAddr_t |
Stores an IPv4 or IPv6 network address. More... | |
struct | SocketAddr_t |
Stores an IPv4 or IPv6 socket address. More... | |
Defines | |
SocketAddr_t::EqualAddresses(sa1, sa2) | |
True if two addresses, sans port, are equal. | |
#define | EqualAddresses(sa1, sa2) |
True if two addresses, sans port, are equal. | |
#define | MAX_HOST_LEN 64 |
The maximum hostname length supported. | |
Typedefs | |
typedef INetAddr_t | INetAddr |
typedef SocketAddr_t | SocketAddr |
Functions | |
static void | DoAddrLookup (void *name) |
Performs a lookup for the address of a given hostname on the I/O Thread. | |
void | DoHostnameLookup (void *) |
An operation for the I/O Thread that attempts to discover the local system's hostname and address. | |
static void | DoNameLookup (void *address) |
Performs a lookup for the hostname of a given address on the I/O Thread. | |
int | LookupResult (char *name, INetAddr *addr) |
Provides the results of a host lookup started by a call to either StartAddrLookup() or StartNameLookup(), or a notice that the operation is in progress. | |
void | StartAddrLookup (char *name) |
Starts the process of finding the address of a host based on its name. | |
void | StartNameLookup (SocketAddr *addr, char *name) |
Starts the process of finding the full hostname of a machine based on its address. | |
Bool | StartStrNameLookup (char *addrstr, char *name) |
Starts the process of finding the full hostname of a machine based on its address. | |
Variables | |
static struct addrinfo * | addrLookup = NULL |
Stores the results from looking up an address. | |
static int | conditionCode = 0 |
The current condition code used to tell what the lookup code is doing or the result returned by the sockets function used for the lookup. | |
static INetAddr | hostaddr |
The numeric IP address who's name is sought. | |
char | localhostAddrStr [INET6_ADDRSTRLEN] |
Stores the address of the local system as a string. | |
char | localhostName [64] |
Stores the name of the local system. | |
static char * | lookupName = NULL |
A pointer to where to place the hostname when looking up from an address. | |
SocketAddr | outgoingAddr |
The socket address of the server that the client is in communication with. |
Only one lookup can be in progress at any given time, and there is no mechanism to queue lookup requests. Generally the results of a lookup can only be retrieved once. These restrictions simply the lookup implementation as well as its public interface. They should not impose problems for most networked games.
The implementation is ment to work with IPv6, but favors IPv4. IPv6 support has not been tested, so this code may fail with IPv6.
Copyright (C) 2007 Jeff Jackowski
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Or visit their website at: http://www.gnu.org/
EqualAddresses | ( | sa1, | |||
sa2 | ) | [related, inherited] |
True if two addresses, sans port, are equal.
sa1 | A pointer to a SocketAddr to compare. | |
sa2 | Another pointer to a SocketAddr to compare. |
Definition at line 154 of file hostlookup.h.
Referenced by GetSamples(), HandleConnReq(), ValidateClient(), and ValidateServer().
#define EqualAddresses | ( | sa1, | |||
sa2 | ) | [related] |
Value:
(((sa1)->addr.sa_family == (sa2)->addr.sa_family) && \ ((((sa2)->addr.sa_family == AF_INET) \ && ((sa2)->ipv4.sin_addr.s_addr == (sa1)->ipv4.sin_addr.s_addr)) \ || (((sa2)->addr.sa_family == AF_INET6) && \ IN6_ARE_ADDR_EQUAL(&((sa2)->ipv6.sin6_addr), \ &((sa1)->ipv6.sin6_addr)))))
sa1 | A pointer to a SocketAddr to compare. | |
sa2 | Another pointer to a SocketAddr to compare. |
Definition at line 154 of file hostlookup.h.
#define MAX_HOST_LEN 64 |
The maximum hostname length supported.
Definition at line 89 of file hostlookup.h.
Referenced by DiscoverConnectServer(), DoHostnameLookup(), DoNameLookup(), and LookupResult().
typedef struct INetAddr_t INetAddr |
Definition at line 111 of file hostlookup.h.
typedef struct SocketAddr_t SocketAddr |
Definition at line 138 of file hostlookup.h.
static void DoAddrLookup | ( | void * | name | ) | [static] |
Performs a lookup for the address of a given hostname on the I/O Thread.
For internal use only.
name | A pointer to a character array that holds a NULL-terminated string containing the hostname who's address is sought. |
Definition at line 87 of file hostlookup.c.
References addrLookup, and conditionCode.
Referenced by DoHostnameLookup(), and StartAddrLookup().
void DoHostnameLookup | ( | void * | ) |
An operation for the I/O Thread that attempts to discover the local system's hostname and address.
Performs an address lookup of what the system claims to be its name. If the lookup finds a name other than localhost, the new name will be stored in localhostName. Otherwise, the name stored will be the one returned by gethostname(). If the address is not for the loopback interface, a string representation of the address will be stored in localhostAddrStr. Otherwise, the string will have zero length.
On Linux (and other UNIX-like syetems?), the address found on many home LANs, and some other LANs, will be the loopback address. To avoid this requires another address listed with the system's name in /etc/hosts, or (maybe?) an entry in a nameserver used by the system.
Definition at line 276 of file hostlookup.c.
References addrLookup, conditionCode, DoAddrLookup(), localhostAddrStr, localhostName, and MAX_HOST_LEN.
Referenced by NetInit(), and NetInitSrv().
Here is the call graph for this function:
static void DoNameLookup | ( | void * | address | ) | [static] |
Performs a lookup for the hostname of a given address on the I/O Thread.
For internal use only.
address | An address to lookup, or NULL. |
Definition at line 109 of file hostlookup.c.
References conditionCode, INetAddr_t::family, hostaddr, INetAddr_t::ipv4, SocketAddr_t::ipv4, INetAddr_t::ipv6, SocketAddr_t::ipv6, SocketAddr_t::length, lookupName, and MAX_HOST_LEN.
Referenced by StartNameLookup(), and StartStrNameLookup().
int LookupResult | ( | char * | name, | |
INetAddr * | addr | |||
) |
Provides the results of a host lookup started by a call to either StartAddrLookup() or StartNameLookup(), or a notice that the operation is in progress.
After the results are retrived with this function, they will no longer be availble through this interface.
name | For name lookups, this is ignored. For address lookups, (StartAddrLookup(), lookup by name) this provides a place to store the fully qualified name. The name pointer must point to an array MAX_HOST_LEN bytes long, or be NULL. | |
addr | If non-NULL, the indicated address struct will be filled with the address in network byte order. |
Definition at line 214 of file hostlookup.c.
References addrLookup, conditionCode, INetAddr_t::family, hostaddr, INetAddr_t::ipv4, INetAddr_t::ipv6, MAX_HOST_LEN, prnfile, STRING_ERR_HOSTLOOK, and strings.
Referenced by NetStatUpdate().
void StartAddrLookup | ( | char * | name | ) |
Starts the process of finding the address of a host based on its name.
The lookup occurs on the separate I/O Thread. Obtain the result by calling LookupResult().
name | The hostname of the machine who's address is to be found. |
Definition at line 132 of file hostlookup.c.
References conditionCode, DoAddrLookup(), and QueueOperation().
Here is the call graph for this function:
void StartNameLookup | ( | SocketAddr * | addr, | |
char * | name | |||
) |
Starts the process of finding the full hostname of a machine based on its address.
The lookup occurs on the separate I/O Thread. Obtain the result by calling LookupResult().
addr | The socket address of the host who's name is sought. |
name | The string where the hostname will be placed. It must be MAX_HOST_LEN bytes long. |
Definition at line 194 of file hostlookup.c.
References conditionCode, DoNameLookup(), lookupName, and QueueOperation().
Referenced by DiscoverConnectServer().
Here is the call graph for this function:
Bool StartStrNameLookup | ( | char * | addrstr, | |
char * | name | |||
) |
Starts the process of finding the full hostname of a machine based on its address.
The lookup occurs on the separate I/O Thread. Obtain the result by calling LookupResult().
addrstr | A string containing the address in dotted decimal notation. |
name | The string where the hostname will be placed. It must be MAX_HOST_LEN bytes long. |
Definition at line 165 of file hostlookup.c.
References conditionCode, DoNameLookup(), FALSE, INetAddr_t::family, hostaddr, lookupName, QueueOperation(), and TRUE.
Here is the call graph for this function:
struct addrinfo* addrLookup = NULL [static] |
Stores the results from looking up an address.
For internal use only.
Definition at line 46 of file hostlookup.c.
Referenced by DoAddrLookup(), DoHostnameLookup(), and LookupResult().
int conditionCode = 0 [static] |
The current condition code used to tell what the lookup code is doing or the result returned by the sockets function used for the lookup.
Valid values are:
For internal use only.
Definition at line 66 of file hostlookup.c.
Referenced by DoAddrLookup(), DoHostnameLookup(), DoNameLookup(), LookupResult(), StartAddrLookup(), StartNameLookup(), and StartStrNameLookup().
The numeric IP address who's name is sought.
For internal use only.
Definition at line 73 of file hostlookup.c.
Referenced by DoNameLookup(), LookupResult(), and StartStrNameLookup().
char localhostAddrStr[INET6_ADDRSTRLEN] |
Stores the address of the local system as a string.
Definition at line 77 of file hostlookup.c.
Referenced by DoHostnameLookup(), NetStatFocus(), NetStatUpdate(), and RenderLocalAddr().
char localhostName[64] |
Stores the name of the local system.
Definition at line 75 of file hostlookup.c.
Referenced by DoHostnameLookup(), and NetStatUpdate().
char* lookupName = NULL [static] |
A pointer to where to place the hostname when looking up from an address.
For internal use only.
Definition at line 53 of file hostlookup.c.
Referenced by DoNameLookup(), StartNameLookup(), and StartStrNameLookup().
The socket address of the server that the client is in communication with.
Not marked as static because it is used in other networking related source files.
Definition at line 109 of file net.c.
Referenced by ClientSync(), ConfigIPv4Broadcast(), DiscoverConnectServer(), HandleConnAccept(), NetStatUpdate(), Send(), SendAck(), SendConnectMsg(), and ValidateServer().