2008-06-01 22:08:45 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ws2_32.dll API tests
|
|
|
|
* LICENSE: GPLv2 or any later version
|
|
|
|
* FILE: apitests/ws2_32/helpers.c
|
|
|
|
* PURPOSE: Helper functions for the socket tests
|
|
|
|
* COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
|
|
|
|
*/
|
|
|
|
|
2013-09-22 19:07:35 +00:00
|
|
|
#include <apitest.h>
|
2013-02-05 17:54:22 +00:00
|
|
|
|
2013-09-22 19:07:35 +00:00
|
|
|
#include <stdio.h>
|
2008-06-01 22:08:45 +00:00
|
|
|
#include "ws2_32.h"
|
|
|
|
|
2010-08-25 08:48:55 +00:00
|
|
|
int CreateSocket(SOCKET* psck)
|
2008-06-01 22:08:45 +00:00
|
|
|
{
|
|
|
|
/* Create the socket */
|
|
|
|
*psck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
2010-08-25 08:48:55 +00:00
|
|
|
ok(*psck != INVALID_SOCKET, "*psck = %d\n", *psck);
|
2008-06-01 22:08:45 +00:00
|
|
|
|
|
|
|
if(*psck == INVALID_SOCKET)
|
|
|
|
{
|
|
|
|
printf("Winsock error code is %u\n", WSAGetLastError());
|
|
|
|
WSACleanup();
|
2010-08-25 08:48:55 +00:00
|
|
|
return 0;
|
2008-06-01 22:08:45 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 08:48:55 +00:00
|
|
|
return 1;
|
2008-06-01 22:08:45 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 08:48:55 +00:00
|
|
|
int ConnectToReactOSWebsite(SOCKET sck)
|
2008-06-01 22:08:45 +00:00
|
|
|
{
|
|
|
|
int iResult;
|
|
|
|
struct hostent* host;
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
|
|
|
|
/* Connect to "www.reactos.org" */
|
|
|
|
host = gethostbyname("www.reactos.org");
|
|
|
|
|
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_addr.s_addr = *(u_long*)host->h_addr_list[0];
|
|
|
|
sa.sin_port = htons(80);
|
|
|
|
|
|
|
|
SCKTEST(connect(sck, (struct sockaddr *)&sa, sizeof(sa)));
|
2010-08-25 08:48:55 +00:00
|
|
|
|
|
|
|
return 1;
|
2008-06-01 22:08:45 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 08:48:55 +00:00
|
|
|
int GetRequestAndWait(SOCKET sck)
|
2008-06-01 22:08:45 +00:00
|
|
|
{
|
|
|
|
const char szGetRequest[] = "GET / HTTP/1.0\r\n\r\n";
|
|
|
|
int iResult;
|
|
|
|
struct fd_set readable;
|
|
|
|
|
|
|
|
/* Send the GET request */
|
|
|
|
SCKTEST(send(sck, szGetRequest, strlen(szGetRequest), 0));
|
2010-08-25 08:48:55 +00:00
|
|
|
ok(iResult == strlen(szGetRequest), "iResult = %d\n", iResult);
|
2016-10-10 06:48:56 +00:00
|
|
|
#if 0 /* breaks windows too */
|
2008-06-01 22:08:45 +00:00
|
|
|
/* Shutdown the SEND connection */
|
|
|
|
SCKTEST(shutdown(sck, SD_SEND));
|
2016-10-10 06:48:56 +00:00
|
|
|
#endif
|
2008-06-01 22:08:45 +00:00
|
|
|
/* Wait until we're ready to read */
|
|
|
|
FD_ZERO(&readable);
|
|
|
|
FD_SET(sck, &readable);
|
|
|
|
|
|
|
|
SCKTEST(select(0, &readable, NULL, NULL, NULL));
|
2010-08-25 08:48:55 +00:00
|
|
|
|
|
|
|
return 1;
|
2008-06-01 22:08:45 +00:00
|
|
|
}
|