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
|
#include <cstdlib>
#include <iostream>
#include <winsock2.h> // Librairie que l´on se sert avec les
#pragma comment(lib, "ws2_32.lib") //socket ws2_32.lib
#include <ws2tcpip.h >
int main(void){
//Création d´un socket
WSADATA WSAData; // Init var WSAData
WSAStartup(MAKEWORD(2,0), &WSAData); // Init de WSAStartup()
SOCKET sock; //Init VAR du type SOCKET
SOCKADDR_IN sin; //Info techniques du socket (cf ci dessous)
sin.sin_addr.s_addr = inet_addr("192.168.4.33");
//sin.sin_addr.s_addr = htonl(INADDR_ANY); //Toutes les connections
sin.sin_family = AF_INET; // *famille* du socket, ici internet
sin.sin_port = htons(10000); // Port 10 000
/* Type du socket: SOCK_STREAM ouvrent une conn directe entre les 2 ordi et
pourra ensuite envoyer les paquets que vous désirez, SOCK_DGRAM envoie un paquet
directement à la destination sans faire d'accept() ou de connect().*/
sock = socket(AF_INET, SOCK_STREAM,0);
//sock = socket(AF_INET, SOCK_DGRAM, 0);
//sock = socket(AF_INET, SOCK_RAW, 0); //Mieux pour faire run un Daemon
bind(sock, (SOCKADDR *)&sin, sizeof(sin)); //Attache socket (port & ADDR)
int TOS=0x80;
/*getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
s: socket auquel la fonction doit s´appliquer
level: identifies the layer that is to handle the option
SOL_SOCKET is for the socket layer, IPPROTO_IP for the IP layer, etc...
optname:
optval:
optlen: size of the data structure optval points to
*/
while(1)
{
setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&TOS, sizeof(TOS));
if (setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&TOS,
sizeof(TOS)) == SOCKET_ERROR)
printf("\nWarning: Fail to set TOS value: error - %d",
WSAGetLastError());
}
system("PAUSE");
return EXIT_SUCCESS;
} |
Partager