From: blackh <gra...@li...> - 2003-03-12 10:09:06
|
blackh Wed Mar 12 02:09:06 2003 EDT Modified files: /grapevine/cpp IOLoop.cpp Log: Try this on Windows 98. Index: grapevine/cpp/IOLoop.cpp diff -u grapevine/cpp/IOLoop.cpp:1.42 grapevine/cpp/IOLoop.cpp:1.43 --- grapevine/cpp/IOLoop.cpp:1.42 Tue Mar 11 16:31:26 2003 +++ grapevine/cpp/IOLoop.cpp Wed Mar 12 02:09:05 2003 @@ -1,4 +1,4 @@ -// $Id: IOLoop.cpp,v 1.42 2003/03/12 00:31:26 blackh Exp $ +// $Id: IOLoop.cpp,v 1.43 2003/03/12 10:09:05 blackh Exp $ #include "config.h" @@ -225,6 +225,8 @@ We can then look at 'getsockname' and hey presto, we can find out what local interface would be used to send packets to that remote address without actually sending any. + + Except it's not that simple on Windows 98. */ String IOLoop::localInterfaceFor(String remoteHost) { @@ -250,40 +252,32 @@ if (ret < 0) return String(); + closeSocket(sock); + #ifdef __WIN32__ if (addr.sin_addr.S_un.S_addr == 0UL) { /* Windows 98 will return 0.0.0.0 per MSDN: - The getsockname function does not always return information about the host address + The getsockname function does not always return information about the host address when the socket has been bound to an unspecified address, unless the socket has been connected with connect or accept (for example, using ADDR_ANY). - A Windows Sockets application must not assume that the address will be specified unless - the socket is connected. The address that will be used for the socket is unknown unless - the socket is connected when used in a multihomed host. If the socket is using a - connectionless protocol, the address may not be available until I/O occurs on the socket. - - So, let's send 1 byte, to see if it wakes up. + We tried sending a single byte out the socket, but that didn't work, and it is + also not what we want to do. - Is this reasonable to do? - - ** This doesn't work, but I'll fix it shortly. - SB + So, on Windows 98 we will assume the box is not multi-homed, and look up its IP + address from its name. The question is, will this work on a simple Windows 98 box + that's dialled up to the net???? */ - cout << "found 0.0.0.0 " << std::flush; - - ret = ::send(sock, "1", 1, 0); - if (ret <= 0) - return String(); - - len = sizeof(addr); - ret = ::getsockname(sock, (sockaddr*) &addr, &len); + ret = gethostname(name, sizeof(name)-1); if (ret < 0) return String(); + + if (!resolve(name, addr.sin_addr)) + return String(); } #endif - - closeSocket(sock); return String(inet_ntoa(addr.sin_addr)); } |