Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The problem with WSAIoctl (). WSAGetLastError () gives 10022. Need help!

74 views
Skip to first unread message

Матвей Игошев

unread,
May 1, 2015, 1:04:07 PM5/1/15
to
Hello everybody! Blew a simple prog to WINCE and tests it on the emulator and a device with MIPSII architecture. The problem with WSAIoctl (). WSAGetLastError () gives 10022. Need help! Connection is! It does not take place:
if (WSAIoctl(sniffer, SIO_RCVALL, &j, sizeof(j), 0, 0, (LPDWORD) &in , 0 , 0) == SOCKET_ERROR)
I do not like the option SIO_RCVALL. I tried some other options (like the internet), komentirovat this place, to no avail ... ...
Validating if you know what it should be the option to read the data, please help!
All thanks in advance.

#include "stdafx.h"
#include "stdio.h"
#include "winsock2.h"
#include "mstcpip.h"

//#pragma comment(lib,"ws2_32.lib") //For winsock
#pragma comment(lib,"ws2.lib") //For winsock

//#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1) //this removes the need of mstcpip.h

int _tmain(int argc, _TCHAR* argv[])
{
SOCKET sniffer;
struct in_addr addr;
int in;

char hostname[100];
struct hostent *local;
WSADATA wsa;

//logfile=fopen("log.txt","w");
logfile=fopen("\\DiskA3\\log_UDP.txt","w");
//logfile=fopen("\\Storage Card\\log_UDP.txt","w");
if(logfile == NULL)
{
MessageBox(0, TEXT("0"),TEXT ("0"), 0);
fprintf(logfile, "Unable to create file.");
}

//Initialise Winsock
fprintf(logfile, "\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(1,1), &wsa) != 0)
//if (WSAStartup(MAKEWORD(2,2), &wsa) != 0)
{
fprintf(logfile, "WSAStartup() failed.\n");
MessageBox(0, TEXT("1"),TEXT ("1"), 0);
fclose(logfile);
return 1;
}
fprintf(logfile, "Initialised");

//Create a RAW Socket
fprintf(logfile, "\nCreating RAW Socket...");
sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
if (sniffer == INVALID_SOCKET)
{
fprintf(logfile, "Failed to create raw socket.\n");
MessageBox(0, TEXT("2"),TEXT ("2"), 0);
fclose(logfile);
return 1;
}
fprintf(logfile, "Created.");

//Retrive the local hostname
if (gethostname(hostname, sizeof(hostname)) == SOCKET_ERROR)
{
fprintf(logfile, "Error : %d",WSAGetLastError());
MessageBox(0, TEXT("3"),TEXT ("3"), 0);
fclose(logfile);
return 1;
}
fprintf(logfile, "\nHost name : %s \n",hostname);

//Retrive the available IPs of the local host
local = gethostbyname(hostname);
fprintf(logfile, "\nAvailable Network Interfaces : \n");
if (local == NULL)
{
fprintf(logfile, "Error : %d.\n",WSAGetLastError());
MessageBox(0, TEXT("4"),TEXT ("4"), 0);
fclose(logfile);
return 1;
}

for (i = 0; local->h_addr_list[i] != 0; ++i)
{
memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));
fprintf(logfile, "Interface Number : %d Address : %s\n",i,inet_ntoa(addr));
}

//fprintf(logfile, "Enter the interface number you would like to sniff : ");
//scanf("%d",&in);
in = 0;

//memset(&dest, 0, sizeof(dest));
//memcpy(&dest.sin_addr.s_addr,local->h_addr_list[in],sizeof(dest.sin_addr.s_addr));

dest.sin_addr.s_addr = htonl(INADDR_ANY);
dest.sin_family = AF_INET;
dest.sin_port = htons(29000);

fprintf(logfile, "\nBinding socket to local system and port %d ...", dest.sin_port );
if (bind(sniffer,(struct sockaddr *)&dest,sizeof(dest)) == SOCKET_ERROR)
{
fprintf(logfile, "bind(%s) failed.\n", inet_ntoa(addr));
MessageBox(0, TEXT("5"),TEXT ("5"), 0);
fclose(logfile);
return 1;
}
fprintf(logfile, "Binding successful");

//Enable this socket with the power to sniff : SIO_RCVALL is the key Receive ALL ;)

j=1;
fprintf(logfile, "\nSetting socket to sniff...");
if (WSAIoctl(sniffer, SIO_RCVALL, &j, sizeof(j), 0, 0, (LPDWORD) &in , 0 , 0) == SOCKET_ERROR)
{
fprintf(logfile, "WSAIoctl() failed.\n");
MessageBox(0, TEXT("6"),TEXT ("6"), 0);
fclose(logfile);
return 1;
}
fprintf(logfile, "Socket set.");

//Begin
fprintf(logfile, "\nStarted Sniffing\n");
fprintf(logfile, "Packet Capture Statistics...\n");
StartSniffing(sniffer); //Happy Sniffing

//End
closesocket(sniffer);
fclose(logfile);
WSACleanup();

return 0;
}
0 new messages