I would like to thank Igor Proskuriakov, Len Holgate, and Farooque Khan. My purpose for this class is to programatically determine the IP address that is assigned to a local machine. This class will return the machine's IP address in the form of a CString, a DWORD in host byte order, and a DWORD in network byte order.
IPAddressBase Class Usage
An object of this class will contain an IP address value and perform format conversion. The IP address is stored in a CString. Member functions have been provided to converted the stored CString to a network byte order DWORD or host byte order DWORD. The default constuctor initializes the class's data member
void SetHBO(DWORD dwInValue);
takes a DWORD value(in host byte order) and coverts the value to a CString. The CString equivalent is then stored in
void SetNBO(DWORD dwInValue);
takes a DWORD value(in network byte order) and coverts the value to a CString. The CString equivalent is then stored in
void SetString(CString csInString);
takes a CString and stores the value in
to a DWORD in host byte order and returns that converted value.
to a DWORD in network byte order and returns that converted value.
LocalIPQuery Class Usage
This class performs the extraction of the machine's IP address/addresses. This class contains two different methods for extraction that are programmer selectable with conditional compilation. The container that holds the extracted IP address/addresses is a STL vector.
The LIPQ_MULTI method is derived from Farooque Khan's "Using IP Helper API’s" article. This method takes the local machine's TCP/IP table and extracts each active unique IP address on the local machine. The extracted values are stored as IPAddressBase objects in the vector.
The LIPQ_PORTABLE method is from http://tangentsoft.net/wskfaq/examples/ipaddr.html. This method extracts the local machine IP address from a socket it creates. The extracted value is stored as an IPAddressBase object in the vector. This method will only extract a single IP address, but it is portable since it uses sockets.
Selection of the methods is done in the LocalIPQuery.h file.
To use LIPQ_MULTI verify that the LocalIPQuery header file is configured as follows before compiling
#define USE_THIS LIPQ_MULTI
To use LIPQ_PORTABLE verify that the LocalIPQuery header file is configured as follows before compiling
#define USE_THIS LIPQ_PORTABLE
The Dialog App
The dialog app shows the extracted IP address/addresses and one way of using the LocalIPQuery class with an IP Address Control.