Network Address Translation Traversal Interfaces
The following interfaces make it possible to manage Network Address Translation (NAT) through UPnP™.
Interface Purpose
IUPnPNAT Primary interface for UPnP management of NAT.
INATEventManager Provides methods to register application-defined callback interfaces.
IDynamicPortMappingCollection This interface is not currently supported.
IDynamicPortMapping This interface is not currently supported.
IStaticPortMappingCollection Collection interface for static port mappings.
IStaticPortMapping Provides methods for managing a specific port mapping.
The following interfaces are implemented by the client application. The NAT calls the methods in these interfaces in order to inform the client of changes in the NAT configuration.
Interface Purpose
INATExternalIPAddressCallback Provides a method that the system calls if the NAT's external IP address changes.
INATNumberOfEntriesCallback Provides a method that the system calls if the number of port mappings changes.
//////////////////
// Get host name.
//
char hostname[256];
int res = gethostname(hostname, sizeof(hostname));
if (res != 0) {
printf("Error: %u\n", WSAGetLastError());
return -1;
}
printf("hostname=%s\n", hostname);
////////////////
// Get host info for hostname.
//
hostent* pHostent = gethostbyname(hostname);
if (pHostent==NULL) {
printf("Error: %u\n", WSAGetLastError());
return -1;
}
//////////////////
// Parse the hostent information returned
//
hostent& he = *pHostent;
printf("name=%s\naliases=%s\naddrtype=%d\nlength=%d\n",
he.h_name, he.h_aliases, he.h_addrtype, he.h_length);
sockaddr_in sa;
for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++) {
memcpy ( &sa.sin_addr.s_addr, he.h_addr_list[nAdapter],he.h_length);
// Output the machines IP Address.
printf("Address: %s\n", inet_ntoa(sa.sin_addr)); // display as string
}
//////////////////
// Terminate windows sockets API
//
WSACleanup();