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<stdlib.h>
#include<stdio.h>
#include<sys/socket.h>
#include<netdb.h>
#include<sys/types.h>
#include<string.h>
#include<arpa/inet.h>
#include<errno.h>
int main (int argc, char ** argv){
if (argc != 4){
printf("Nombre de paramètre incorrect : format : \n %s adresse port fichier",argv[0])
}
int Socket_envoi= socket(PF_INET,SOCK_STREAM,0);
FILE fichier = fopen(argv[3],"r");
struct sockaddr_in addresse;
printf("Fichier ouvert\n");
char buf;
if (inet_pton(AF_INET,argv[1],&(adresse.sin_addr))==-1){
perror("inet_pton()");
exit(errno);
}
adresse.sin_port = htons(atoi(argv[2]));
adresse.sin_family = AF_INET;
if(connect(Socket_envoi,(SOCKADDR *) &adresse, sizeof(adresse)) == -1)
{
perror("connect()");
exit(errno);
}
char tableau[1000];
int i =0;
if(send(Socket_envoi, argv[3], strlen(argv[3]), 0) < 0)
{
perror("send()");
exit(errno);
}
while (buf = getc(fichier)!= EOF){
tableau[i]=buf;
i++;
if ( i = 999){
if(send(Socket_envoi, tableau, strlen(tableau), 0) < 0)
{
perror("send()");
exit(errno);
}
i = 0;
}
}
return 0;
}
|