Programmation de socket sous windows
Salut à tous ce qui suit en dessous est un extrait de code, avec toutes les bibliothèques, lors de la compilation avec VS 2005, j'obtiens les messages: "write" identifier not found e "read" identifier not found.
Ces fonctions ne sont-elles pas définies dans la bibliothèque winsock2.h (j'ai essayé aussi avec winsock.h).
Qu'elqu'un a t-il une idée ?
Merci d'avance.
Code:
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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#include <windows.h>
void shell (int sock)
{
int l;
char buf[512];
struct timeval time;
unsigned long ul[2];
time.tv_sec = 1;
time.tv_usec = 0;
while(1)
{
ul[0]=1;
ul[1]=sock;
l=select(0,(fd_set*)&ul,NULL,NULL,&time);
if(l==1)
{
l=recv(sock,buf,sizeof(buf),0);
if (l<=0)
{
printf("\r\n[-] connection closed.\n");
return;
}
l=write(1,buf,l);
if (l<=0)
{
printf("\r\n[-] connection closed.\n");
return;
}
}
else
{
l=read(0,buf,sizeof(buf));
if (l<=0)
{
printf("\r\n[-] connection closed.\n");
return;
}
l=send(sock,buf,l,0);
if (l<=0)
{
printf("\r\n[-] connection closed.\n");
return;
}
}
}
} |