void NetServer::_RemoveInvalidInterfaces(int socket) { // get a list of all interfaces ifconf config; config.ifc_len = sizeof(config.ifc_value); if (ioctl(socket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0) return; uint32 count = (uint32)config.ifc_value; if (count == 0) { // there are no interfaces yet return; } void *buffer = malloc(count * sizeof(struct ifreq)); if (buffer == NULL) { fprintf(stderr, "%s: Out of memory.\n", Name()); return; } config.ifc_len = count * sizeof(struct ifreq); config.ifc_buf = buffer; if (ioctl(socket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0) { free(buffer); return; } ifreq *interface = (ifreq *)buffer; for (uint32 i = 0; i < count; i++) { if (!_IsValidInterface(socket, interface->ifr_name)) { // remove invalid interface ifreq request; if (!prepare_request(request, interface->ifr_name)) break; if (ioctl(socket, SIOCDIFADDR, &request, sizeof(request)) < 0) { fprintf(stderr, "%s: Could not delete interface %s: %s\n", Name(), interface->ifr_name, strerror(errno)); } } interface = (ifreq *)((addr_t)interface + IF_NAMESIZE + interface->ifr_addr.sa_len); } free(buffer); }
BOOL WiiMouse_DrvUtil_GetInterfaceHandles(WiiMouse_HandleInfo_t *handleInfo) { BOOL retval = FALSE; UCHAR interfaceIndex = 0; UCHAR pipeIndex = 0; USB_INTERFACE_DESCRIPTOR usbInterfaceDesc; WINUSB_PIPE_INFORMATION pipeInfo; while( WinUsb_QueryInterfaceSettings(handleInfo->winUsbHandle, interfaceIndex, &usbInterfaceDesc) ) { if( _IsValidInterface(&usbInterfaceDesc) ) { break; } interfaceIndex++; } if( GetLastError() == ERROR_INVALID_HANDLE ) { WiiMouse_AddMsg(DERR,"Error, WinUsb_QueryInterfaceSettings invalid handle\n"); return FALSE; } if( !WinUsb_GetAssociatedInterface(handleInfo->winUsbHandle, interfaceIndex, &handleInfo->interfaceHandle) ) { DWORD err = GetLastError(); if( err != ERROR_ALREADY_EXISTS ) { WiiMouse_AddMsg(DERR,"Error, WinUsb_GetAssociatedInterface failed: %d\n", err); return FALSE; } else { handleInfo->interfaceHandle = handleInfo->winUsbHandle; handleInfo->interfaceId = 0; } } handleInfo->interfaceId = interfaceIndex; for( pipeIndex = 0; pipeIndex < usbInterfaceDesc.bNumEndpoints; pipeIndex++ ) { if( !WinUsb_QueryPipe(handleInfo->winUsbHandle, interfaceIndex, pipeIndex, &pipeInfo) ) { WiiMouse_AddMsg(DERR,"Error, WinUsb_QueryPipe failed: %d\n", GetLastError()); retval = FALSE; break; } else { _SetEndpoint(handleInfo, &pipeInfo); } } /* if( !_ValidateEndpoints(handleInfo) ) { WiiMouse_AddMsg(DERR,"Error, endpoint validation failed\n"); retval = FALSE; }*/ if( !retval ) { WinUsb_Free(handleInfo->interfaceHandle); } return retval; }