[ENet-discuss] little trouble with enet_address_set_host on Windows
Benoit Germain
bgermain at ubisoft.fr
Tue Feb 16 03:13:16 PST 2010
Hello,
I have a little application which contains both a client and a server. The client attempts to connect to the server using an address resolved with enet_address_set_host to which I give with my PC's name as shown by ipconfig /all. Now, it happens that I also have a video capture device plugged on the PC, which for some reason creates a virtual network :
C:\Documents and Settings\bgermain>ipconfig /all
Configuration IP de Windows
Nom de l'hôte . . . . . . . . . . : ann-bgermain
Suffixe DNS principal . . . . . . : ubisoft.org
Type de noud . . . . . . . . . . : Hybride
Routage IP activé . . . . . . . . : Non
Proxy WINS activé . . . . . . . . : Non
Liste de recherche du suffixe DNS : ubisoft.org
Carte Ethernet Connexion au réseau local 2:
Suffixe DNS propre à la connexion :
Description . . . . . . . . . . . : Broadcom NetXtreme 57xx Gigabit Controller
Adresse IP. . . . . . . . . . . . : 10.2.150.9
Carte Ethernet Connexion au réseau local 3:
Suffixe DNS propre à la connexion :
Description . . . . . . . . . . . : Connexion TV/vidéo Microsoft
Adresse physique . . . . . . . . .: 00-00-00-00-00-00
Autoconfiguration d'adresse IP. . : 0.1.0.4
Masque de sous-réseau . . . . . . : 255.255.255.255
The problem is that this address comes first in hostEntry, thus causing the client to attempt to connect to the video device (I suppose). I have come up with a very dirty trick to select the address I am interested in, but maybe someone will have a more portable solution ?
int
enet_address_set_host (ENetAddress * address, const char * name)
{
#if !defined(_XBOX)
struct hostent * hostEntry;
hostEntry = gethostbyname (name);
if (hostEntry == NULL ||
hostEntry -> h_addrtype != AF_INET)
{
unsigned long host = inet_addr (name);
if (host == INADDR_NONE)
return -1;
address -> host = host;
return 0;
}
int i = 0;
for( char *addr = hostEntry -> h_addr_list[i]; addr != NULL; ++ i, addr = hostEntry -> h_addr_list[i])
{
union UIP
{
struct { enet_uint8 a, b, c, d; };
enet_uint32 asU32;
};
UIP ip;
ip.asU32 = * (enet_uint32 *) addr;
if( ip.a != 0)
{
address -> host = ip.asU32;
break;
}
}
#else
address -> host = inet_addr(name);
#endif
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20100216/271e0cc5/attachment.htm>
More information about the ENet-discuss
mailing list