bonjour tout le monde,

j'ai un problème de compréhension. j'utilise les raw socket pour forger mes paquet ICMP et les envoyé au travers du réseau.

Quand je débeug mon programme, je constate que la création du socket, l'initialisation de WS2_32.DLL, l'initialisation de la socket avec setsockopt, et l'envoie se réalisent a la perfection ( le tout en mode débeug).

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
SOCKET socketRaw;
 
// The WSAStartup function initiates use of WS2_32.DLL by a process.
bool initWSA()
{
	bool tempo = true;
	WSAData wsaData;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	 {
		 tempo = false;
	 }
	 return tempo;
}
 
// The WSACleanup function terminates use of the WS2_32.DLL.
void clearWSA()
{
	WSACleanup();
}
 
bool creat_Socket()
{
	bool tempo = true;
 
	socketRaw = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0, 0);
	if(socketRaw == INVALID_SOCKET)
	{
		tempo = false;
	}
	return tempo;
}
 
bool init_Socket()
{
	bool tempo = true;
	int sockOpt = 1;
	int result;
 
	// IPPROTO_IP IP_HDRINCL ==> Indique que l'IP header doit etre fourni par des données externes
	if((result = setsockopt(socketRaw, IPPROTO_IP, IP_HDRINCL, (char*)&sockOpt, sizeof(sockOpt))) == SOCKET_ERROR)
	{
		tempo = false;
	}
	return tempo;
}
 
bool send_Socket(struct sockaddr_in sock_info, IP * ip, ICMP * icmp)
{
	bool tempo = false;
	int result;
 
	char paquet[sizeof(ICMP) + sizeof(IP)]; //28 = sizeof(ICMP) + sizeof(IP)
 
	createICMPpaquet(ip, icmp, paquet);
 
	int t = sizeof(paquet);
 
	result = sendto(socketRaw, paquet, sizeof(paquet), 0, (struct sockaddr *)&sock_info, sizeof(sock_info));
 
	if(result != SOCKET_ERROR)
	{
		tempo = true;
	}
 
	return tempo;
}
 
void createICMPpaquet(IP *ip, ICMP *icmp, char * paquet)
{
	int icmpT = sizeof(*icmp);
	int ipT = sizeof(*ip);
 
	ZeroMemory(paquet, icmpT + ipT); //permet de remplir un bloc de mémoire avec des 0
	memcpy(paquet, ip, ipT); 
	paquet += ipT;
	memcpy(paquet, icmp, icmpT);
}
mais rien n'est observé via un analyseur de trames

D'ou peut venir un tel problème?