Game Development Reference
In-Depth Information
See also
F Downloading images from Flickr and Picasa
Detecting a network address
To communicate with a web server, we need to specify its IP address. In a limited mobile
environment, it is not convenient to ask the user for the IP address and we have to detect
the address ourselves (and not involving any non-portable code). In the forthcoming
App5 example, we use the GetAdaptersAddresses() function from the Windows API
and the getifaddrs() function from POSIX. The Android runtime library provides its
own implementation of getifaddrs() , which is included in the App5 sources in the
DetectAdapters.cpp ile.
Getting ready
Let's declare a structure to hold the information describing a network adapter:
struct sAdapterInfo
{
This is the internal system name of the network adapter:
char FName[256];
The IP address of the adapter is as follows:
char FIP[128];
The unique identiication number of the adapter:
char FID[256];
};
How to do it...
1.
We provide detailed code for the Android version of the Net_
EnumerateAdapters() function in the following code. It enumerates all of the
network adapters available in the system:
bool Net_EnumerateAdapters( std::vector<sAdapterInfo>&
Adapters )
{
struct ifaddrs* MyAddrs, *ifa;
void* in_addr;
char buf[64];
 
Search WWH ::




Custom Search