static BOOLEAN IsWinsockInitialized(VOID) { struct hostent *Hostent; Hostent = gethostbyname("localhost"); if (!Hostent) ok_dec(WSAGetLastError(), WSANOTINITIALISED); return Hostent != NULL; }
static void Test_Data(PTEST_IMAGE TestImage) { LDR_RESOURCE_INFO ResourceInfo; LDR_ENUM_RESOURCE_INFO EnumRes[8]; ULONG ResourceCount; NTSTATUS Status; InitializeTestImage(TestImage); memset(EnumRes, 0xcc, sizeof(EnumRes)); ResourceInfo.Type = 1; ResourceInfo.Name = 1; ResourceInfo.Language = 0x408; ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, EnumRes); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 8); ok_ptr((PVOID)EnumRes[0].Data, TestImage->Resources.StringBuffer); ok_dec(EnumRes[0].Size, 2); ok_enumres(&EnumRes[0], 1, L"TEST", 0x409, TestImage->Resources.StringBuffer, 2) ok_enumres(&EnumRes[1], 1, L"TEST", 0x407, TestImage->Resources.StringBuffer + 2, 4) ok_enumres(&EnumRes[2], 1, 7, 0x408, TestImage->Resources.StringBuffer + 4, 6) ok_enumres(&EnumRes[3], 1, 7, 0x406, TestImage->Resources.StringBuffer + 6, 8) ok_enumres(&EnumRes[4], 2, L"LOL", 0x405, TestImage->Resources.StringBuffer + 8, 10) ok_enumres(&EnumRes[5], 2, L"LOL", 0x403, TestImage->Resources.StringBuffer + 10, 12) ok_enumres(&EnumRes[6], 2, L"xD", 0x402, TestImage->Resources.StringBuffer + 12, 14) ok_enumres(&EnumRes[7], 2, L"xD", 0x404, TestImage->Resources.StringBuffer + 14, 16) Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, EnumRes); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 4); }
void Test_WSAIoctl_GetInterfaceList() { WSADATA wdata; INT iResult; SOCKET sck; ULONG buflen, BytesReturned, BCastAddr; ULONG infoCount, i1, j1, iiFlagsExpected; BYTE* buf = NULL; LPINTERFACE_INFO ifInfo; PMIB_IPADDRTABLE pTable = NULL; PMIB_IPADDRROW pRow; /* Get PMIB_IPADDRTABE - these results we should get from wshtcpip.dll too. */ /* pTable is allocated by Test_WSAIoctl_InitTest! */ if (!Test_WSAIoctl_InitTest(&pTable)) goto cleanup; /* Start up Winsock */ iResult = WSAStartup(MAKEWORD(2, 2), &wdata); ok(iResult == 0, "WSAStartup failed. iResult = %d\n", iResult); /* Create the socket */ sck = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0, 0, 0); ok(sck != INVALID_SOCKET, "WSASocket failed. sck = %d\n", (INT)sck); if (sck == INVALID_SOCKET) { skip("Failed to create socket!\n"); goto cleanup; } /* Do the Ioctl (buffer to small) */ buflen = sizeof(INTERFACE_INFO)-1; buf = (BYTE*)HeapAlloc(GetProcessHeap(), 0, buflen); if (buf == NULL) { skip("Failed to allocate memory!\n"); goto cleanup; } BytesReturned = 0; iResult = WSAIoctl(sck, SIO_GET_INTERFACE_LIST, 0, 0, buf, buflen, &BytesReturned, 0, 0); ok(iResult == -1, "WSAIoctl/SIO_GET_INTERFACE_LIST did not fail! iResult = %d.\n", iResult); ok_hex(WSAGetLastError(), WSAEFAULT); ok(BytesReturned == 0, "WSAIoctl/SIO_GET_INTERFACE_LIST: BytesReturned should be 0, not %ld.\n", BytesReturned); HeapFree(GetProcessHeap(), 0, buf); buf = NULL; /* Do the Ioctl In most cases no loop is done. Only if WSAIoctl fails with WSAEFAULT (buffer to small) we need to retry with a larger buffer */ i1 = 0; while (TRUE) { if (buf != NULL) { HeapFree(GetProcessHeap(), 0, buf); buf = NULL; } buflen = sizeof(INTERFACE_INFO) * (i1+1) * 32; buf = (BYTE*)HeapAlloc(GetProcessHeap(), 0, buflen); if (buf == NULL) { skip("Failed to allocate memory!\n"); goto cleanup; } BytesReturned = 0; iResult = WSAIoctl(sck, SIO_GET_INTERFACE_LIST, 0, 0, buf, buflen, &BytesReturned, 0, 0); /* we have what we want ... leave loop */ if (iResult == NO_ERROR) break; /* only retry if buffer was to small */ /* to avoid infinite loop we maximum retry count is 4 */ if ((i1 >= 4) || (WSAGetLastError() != WSAEFAULT)) { ok_hex(iResult, NO_ERROR); skip("WSAIoctl / SIO_GET_INTERFACE_LIST\n"); goto cleanup; } /* buffer to small -> retry */ i1++; } ok_dec(BytesReturned % sizeof(INTERFACE_INFO), 0); /* Calculate how many INTERFACE_INFO we got */ infoCount = BytesReturned / sizeof(INTERFACE_INFO); ok(infoCount == pTable->dwNumEntries, "Wrong count of entries! Got %ld, expected %ld.\n", pTable->dwNumEntries, infoCount); if (winetest_debug >= 2) { trace("WSAIoctl\n"); trace(" BytesReturned %ld - InfoCount %ld\n ", BytesReturned, infoCount); ifInfo = (LPINTERFACE_INFO)buf; for (i1 = 0; i1 < infoCount; i1++) { trace("entry-index %ld\n", i1); trace(" iiFlags %ld\n", ifInfo->iiFlags); traceaddr("ifInfo^.iiAddress", ifInfo->iiAddress); traceaddr("ifInfo^.iiBroadcastAddress", ifInfo->iiBroadcastAddress); traceaddr("ifInfo^.iiNetmask", ifInfo->iiNetmask); ifInfo++; } } /* compare entries */ ifInfo = (LPINTERFACE_INFO)buf; for (i1 = 0; i1 < infoCount; i1++) { if (winetest_debug >= 2) trace("Entry %ld\n", i1); for (j1 = 0; j1 < pTable->dwNumEntries; j1++) { if (ifInfo[i1].iiAddress.AddressIn.sin_addr.s_addr == pTable->table[j1].dwAddr) { pRow = &pTable->table[j1]; break; } } if (j1 == pTable->dwNumEntries) { skip("Skipping interface\n"); continue; } /* iiFlags * Don't know if this value is fix for SIO_GET_INTERFACE_LIST! */ iiFlagsExpected = IFF_BROADCAST | IFF_MULTICAST; if ((pRow->wType & MIB_IPADDR_DISCONNECTED) == 0) iiFlagsExpected |= IFF_UP; if (pRow->dwAddr == ntohl(INADDR_LOOPBACK)) { iiFlagsExpected |= IFF_LOOPBACK; /* on Windows 7 loopback has broadcast flag cleared */ //iiFlagsExpected &= ~IFF_BROADCAST; } ok_hex(ifInfo[i1].iiFlags, iiFlagsExpected); ok_hex(ifInfo[i1].iiAddress.AddressIn.sin_addr.s_addr, pRow->dwAddr); // dwBCastAddr is not the "real" Broadcast-Address. BCastAddr = (pRow->dwBCastAddr == 1 && (iiFlagsExpected & IFF_BROADCAST) != 0) ? 0xFFFFFFFF : 0x0; ok_hex(ifInfo[i1].iiBroadcastAddress.AddressIn.sin_addr.s_addr, BCastAddr); ok_hex(ifInfo[i1].iiNetmask.AddressIn.sin_addr.s_addr, pRow->dwMask); } cleanup: if (sck != 0) closesocket(sck); if (pTable != NULL) free(pTable); if (buf != NULL) HeapFree(GetProcessHeap(), 0, buf); WSACleanup(); }
static void Test_Parameters(PTEST_IMAGE TestImage) { LDR_RESOURCE_INFO ResourceInfo; LDR_ENUM_RESOURCE_INFO Resources[8]; ULONG ResourceCount; NTSTATUS Status; InitializeTestImage(TestImage); ResourceInfo.Type = 6; ResourceInfo.Name = 1; ResourceInfo.Language = 0x409; ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 0); ResourceInfo.Type = 1; ResourceInfo.Name = 7; ResourceInfo.Language = 0x406; ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 8); ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 4); ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 2, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 2); ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 1); ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 99, &ResourceCount, Resources); ok_hex(Status, STATUS_SUCCESS); ok_dec(ResourceCount, 1); ResourceCount = 0; Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(ResourceCount, 8); ResourceCount = 7; Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(ResourceCount, 8); ResourceCount = 8; Status = LdrEnumResources(NULL, &ResourceInfo, 1, &ResourceCount, Resources); ok_hex(Status, STATUS_RESOURCE_DATA_NOT_FOUND); ok_dec(ResourceCount, 0); ResourceCount = 8; Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(ResourceCount, 4); ResourceCount = 8; _SEH2_TRY { Status = LdrEnumResources(NULL, NULL, 0, NULL, NULL); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = 0xDeadC0de; } _SEH2_END ok_hex(Status, 0xDeadC0de); ResourceCount = 42; _SEH2_TRY { Status = LdrEnumResources(TestImage, &ResourceInfo, 1, NULL, Resources); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = 0xDeadC0de; } _SEH2_END ok_hex(Status, 0xDeadC0de); ok_dec(ResourceCount, 42); ResourceCount = 8; Status = LdrEnumResources(TestImage + 2, &ResourceInfo, 1, &ResourceCount, NULL); ok_hex(Status, STATUS_RESOURCE_DATA_NOT_FOUND); ok_dec(ResourceCount, 0); TestImage->Resources.TypeEntries[0].DataIsDirectory = 0; Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL); ok_hex(Status, STATUS_INVALID_IMAGE_FORMAT); ok_dec(ResourceCount, 0); }
static VOID TestNodeName(VOID) { int Error; PADDRINFOA AddrInfo; ADDRINFOA Hints; struct { PCSTR NodeName; PCSTR ExpectedAddress; INT Flags; } Tests[] = { { "", LocalAddress }, { " ", NULL }, { "doesntexist.reactos.org", NULL }, { "localhost", "127.0.0.1" }, { "localhost:80", NULL }, { "7.8.9.10", "7.8.9.10", AI_NUMERICHOST }, { "0.0.0.0", "0.0.0.0", AI_NUMERICHOST }, { "255.255.255.255", "255.255.255.255", AI_NUMERICHOST }, { "0.0.0.0 ", "0.0.0.0", /* no AI_NUMERICHOST */ }, { "0.0.0.0:80", NULL }, { "0.0.0.0.0", NULL }, { "1.1.1.256", NULL }, { "1.2.3", NULL }, { "1.2.3.0x4", "1.2.3.4", AI_NUMERICHOST }, { "1.2.3.010", "1.2.3.8", AI_NUMERICHOST }, /* let's just assume this one doesn't change any time soon ;) */ { "google-public-dns-a.google.com", "8.8.8.8" }, }; const INT TestCount = sizeof(Tests) / sizeof(Tests[0]); INT i; /* make sure we don't get IPv6 responses */ ZeroMemory(&Hints, sizeof(Hints)); Hints.ai_family = AF_INET; trace("Nodes\n"); for (i = 0; i < TestCount; i++) { trace("%d: '%s'\n", i, Tests[i].NodeName); StartSeh() AddrInfo = InvalidPointer; Error = getaddrinfo(Tests[i].NodeName, NULL, &Hints, &AddrInfo); if (Tests[i].ExpectedAddress) { ok_dec(Error, 0); ok_dec(WSAGetLastError(), 0); ok(AddrInfo != NULL && AddrInfo != InvalidPointer, "AddrInfo = %p\n", AddrInfo); } else { ok_dec(Error, WSAHOST_NOT_FOUND); ok_dec(WSAGetLastError(), WSAHOST_NOT_FOUND); ok_ptr(AddrInfo, NULL); } if (!Error && AddrInfo && AddrInfo != InvalidPointer) { ok_addrinfo(AddrInfo, Tests[i].Flags, AF_INET, 0, 0, sizeof(SOCKADDR_IN)); ok_ptr(AddrInfo->ai_canonname, NULL); ok_sockaddr_in(AddrInfo->ai_addr, AF_INET, 0, Tests[i].ExpectedAddress); ok_ptr(AddrInfo->ai_next, NULL); freeaddrinfo(AddrInfo); } EndSeh(STATUS_SUCCESS); } }
static VOID TestServiceName(VOID) { int Error; PADDRINFOA AddrInfo; ADDRINFOA Hints; struct { PCSTR ServiceName; INT ExpectedPort; INT SockType; } Tests[] = { { "", 0 }, { "0", 0 }, { "1", 1 }, { "a", -1 }, { "010", 10 }, { "0x1a", -1 }, { "http", 80, SOCK_STREAM }, { "smtp", 25, SOCK_STREAM }, { "mail", 25, SOCK_STREAM }, /* alias for smtp */ { "router", 520, SOCK_DGRAM }, { "domain", 53, 0 /* DNS supports both UDP and TCP */ }, { ":0", -1 }, { "123", 123 }, { " 123", 123 }, { " 123", 123 }, { "32767", 32767 }, { "32768", 32768 }, { "65535", 65535 }, { "65536", 0 }, { "65537", 1 }, { "65540", 4 }, { "65536", 0 }, { "4294967295", 65535 }, { "4294967296", 65535 }, { "9999999999", 65535 }, { "999999999999999999999999999999999999", 65535 }, { "+5", 5 }, { "-1", 65535 }, { "-4", 65532 }, { "-65534", 2 }, { "-65535", 1 }, { "-65536", 0 }, { "-65537", 65535 }, { "28a", -1 }, { "28 ", -1 }, { "a28", -1 }, }; const INT TestCount = sizeof(Tests) / sizeof(Tests[0]); INT i; /* make sure we don't get IPv6 responses */ ZeroMemory(&Hints, sizeof(Hints)); Hints.ai_family = AF_INET; trace("Services\n"); for (i = 0; i < TestCount; i++) { trace("%d: '%s'\n", i, Tests[i].ServiceName); StartSeh() AddrInfo = InvalidPointer; Error = getaddrinfo(NULL, Tests[i].ServiceName, &Hints, &AddrInfo); if (Tests[i].ExpectedPort != -1) { ok_dec(Error, 0); ok_dec(WSAGetLastError(), 0); ok(AddrInfo != NULL && AddrInfo != InvalidPointer, "AddrInfo = %p\n", AddrInfo); } else { ok_dec(Error, WSATYPE_NOT_FOUND); ok_dec(WSAGetLastError(), WSATYPE_NOT_FOUND); ok_ptr(AddrInfo, NULL); } if (!Error && AddrInfo && AddrInfo != InvalidPointer) { ok_addrinfo(AddrInfo, 0, AF_INET, Tests[i].SockType, 0, sizeof(SOCKADDR_IN)); ok_ptr(AddrInfo->ai_canonname, NULL); ok_sockaddr_in(AddrInfo->ai_addr, AF_INET, Tests[i].ExpectedPort, "127.0.0.1"); ok_ptr(AddrInfo->ai_next, NULL); freeaddrinfo(AddrInfo); } EndSeh(STATUS_SUCCESS); } }