User-agent: Mozilla Thunderbird 0.7.2 (Windows/20040707)
Folks,
There is a long standing issue with the WSAIoctl call on PocketPC
2003 which affects rendezvous. I sent this in via the tech support
page, but got no responce. I hope this is a better forum to get thi out
to the community. The following code works (at least on my iPAQ 5455,
which has both WiFi and bluetooth, and therefore failed to work with the
stock code.
----------------------------------------------------------------------------------------
int getifaddrs( struct ifaddrs **outAddrs )
{
int err;
SocketRef sock;
DWORD size;
void * buffer;
SOCKET_ADDRESS_LIST * addressList;
struct ifaddrs * head;
struct ifaddrs ** next;
struct ifaddrs * ifa;
int n;
int i;
sock = kInvalidSocketRef;
buffer = NULL;
head = NULL;
next = &head;
// Open a temporary socket because one is needed to use WSAIoctl
(we'll close it before exiting this function).
sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
require_action( IsValidSocket( sock ), exit, err =
mStatus_NoMemoryErr );
// Call WSAIoctl with SIO_ADDRESS_LIST_QUERY and pass a null buffer.
This call will fail, but the size needed to
// for the request will be filled in. Once we know the size,
allocate a buffer to hold the entire list.
//
// NOTE: Due to a bug in Windows CE, the size returned by WSAIoctl
is not enough so double it as a workaround.
size = 0;
WSAIoctl( sock, SIO_ADDRESS_LIST_QUERY, NULL, 0, NULL, 0, &size,
NULL, NULL );
require_action( size > 0, exit, err = -1 );
/* For some stupid reason PPC2003 allocates 3 times the amount of space
needed for the socket address list...
* There are apparently 3 bugs in WSAIoctl which affect us here.
* First, the iAddressCount field always returns 0
* Second, the size of the address array is 3 time what it should be.
* Third, setting the buffer size to the actual amount returned
generates an error.
*
* The stock rendezvous code "fixes" this in several ways.
* First, they double the size returned and allocate twice as much
storage as the already inflated size.
* Second, they always declare 1 and only one interface so that:
* If there are no interfaces the app crashes with an address
violation. (I think this is fixed in 58.8)
* If there is more than one interface and the IP if is not first,
the browse will fail to find any services.
*
* This version of the code currently works.
*/
buffer = malloc( size );
require_action( buffer, exit, err = -1 );
// We now know the size of the list and have a buffer to hold so
call WSAIoctl again to get it.
size += sizeof(int); //The next address list query will return an
error unless we do this.
err = WSAIoctl( sock, SIO_ADDRESS_LIST_QUERY, NULL, 0, buffer, size,
&size, NULL, NULL );
require_noerr( err, exit );
addressList = (SOCKET_ADDRESS_LIST *) buffer;
// Process the raw interface list and build a linked list of interfaces.
//
// NOTE: Due to a bug in Windows CE, the iAddressCount field is
always 0 so use 1 in that case.
n = addressList->iAddressCount;
if( n == 0 && (((size-sizeof(int))>0)))
{
n = (size - sizeof(int))/(3*sizeof(SOCKET_ADDRESS));
} else if (n != 0) {
// MessageBox(NULL, TEXT("CE bug apparently fixed, modify
mDNSWin32"), TEXT("Attention"), MB_OK);
}
for( i = 0; i < n; ++i )
{
ifa = (struct ifaddrs *) calloc( 1, sizeof( struct ifaddrs ) );
require_action( ifa, exit, err = WSAENOBUFS );
*next = ifa;
next = &ifa->ifa_next;
// Fetch the name. $$$ TO DO: Get the real name of the interface.
ifa->ifa_name = (char *) malloc( 16 );
require_action( ifa->ifa_name, exit, err = WSAENOBUFS );
sprintf( ifa->ifa_name, "%d", i + 1 );
// Fetch flags. Note: SIO_ADDRESS_LIST_QUERY does not report
flags so just fake IFF_UP and IFF_MULTICAST.
ifa->ifa_flags = IFF_UP | IFF_MULTICAST;
// Fetch addresses.
switch( addressList->Address[ i ].lpSockaddr->sa_family )
{
case AF_INET:
{
struct sockaddr_in * sinptr4;
sinptr4 = (struct sockaddr_in *) addressList->Address[ i
].lpSockaddr;
ifa->ifa_addr = (struct sockaddr *) calloc( 1, sizeof(
*sinptr4 ) );
require_action( ifa->ifa_addr, exit, err = WSAENOBUFS );
memcpy( ifa->ifa_addr, sinptr4, sizeof( *sinptr4 ) );
break;
}
default:
break;
}
}
// Success!
if( outAddrs )
{
*outAddrs = head;
head = NULL;
}
err = 0;
exit:
if( head )
{
freeifaddrs( head );
}
if( buffer )
{
free( buffer );
}
if( sock != INVALID_SOCKET )
{
closesocket( sock );
}
return( err );
}
#endif // defined( _WIN32_WCE ) )
If I should be sending this kind of info elsewhere, please let me know.
Bruce Bernstein
_______________________________________________
rendezvous mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/rendezvous
Do not post admin requests to the list. They will be ignored.