-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
107 lines (83 loc) · 3.13 KB
/
Copy pathutils.c
File metadata and controls
107 lines (83 loc) · 3.13 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define BUFFERSIZE 1024
void addToLog(char * stringDescriptivo, char * hostname, char * ip, char * protocol, int port)
{
FILE *fd;
long timevar;
time (&timevar);
fd = fopen("log.txt", "a");
if(fd == NULL ) {fputs("Add to log: file error.", stderr); return;}
fprintf(fd, "%s Hostname: %s ip: %s Protocol: %s Puerto cliente: %d date: %s",stringDescriptivo, hostname, ip, protocol, port, (char *)ctime(&timevar));
fclose(fd);
}
void addFileTransferInfoToLog(int type, char * fileName, char * ip)
{
FILE *fd;
long timevar;
time (&timevar);
fd = fopen("log.txt", "a");
if(fd == NULL ) {fputs("Add to log: file error.", stderr); return;}
if(type==1) fprintf(fd, "--Recibiendo %s de %s\n", fileName, ip );
if(type==2) fprintf(fd, "--Enviando %s a %s\n", fileName, ip );
fclose(fd);
}
void addEndFileTransferInfoToLog(int type, char * fileName, char * ip, char * errmsg)
{
FILE *fd;
long timevar;
time (&timevar);
fd = fopen("log.txt", "a");
if(fd == NULL ) {fputs("Add to log: file error.", stderr); return;}
if(type==1) fprintf(fd, "Completada recepcion de %s desde %s a las %s\n", fileName, ip, (char *)ctime(&timevar) );
if(type==2) fprintf(fd, "Completado envio de %s desde %s a las %s\n", fileName, ip, (char *)ctime(&timevar) );
if(type==5) fprintf(fd, "Envío de %s desde %s fallido debido a: %s a las %s\n", fileName, ip, errmsg, (char *)ctime(&timevar) );
fclose(fd);
}
void addClientFileTransferInfo(int type, int port, char * fileName, char * ip, char * errmsg, int paquete)
{
FILE *fd;
long timevar;
time (&timevar);
char filename[15];
sprintf(filename, "%d", port);
strcat(filename,".txt");
fd = fopen(filename, "a");
if(fd == NULL ) {fputs("Add to log: file error.", stderr); return;}
if(type==0) fprintf(fd, "Inicio de transmision de %s desde %s a las %s\n",fileName, ip,(char *)ctime(&timevar));
if(type==1) fprintf(fd, "--Recepcion del paquete %d desde %s\n", paquete, ip );
if(type==2) fprintf(fd, "--Envio del paquete %d desde %s\n", paquete, ip );
if(type==3) fprintf(fd, "--Completada recepcion de %s desde %s\n", fileName, ip );
if(type==4) fprintf(fd, "Completada transmisión de %s desde %s a las %s\n",fileName, ip ,(char *)ctime(&timevar));
if(type==5) fprintf(fd, "Envio de %s desde %s fallido debido a: %s a las %s\n", fileName, ip, errmsg, (char *)ctime(&timevar));
fclose(fd);
}
//Ejemplo: sendErrorMSG(s, clientaddr_in, FICHERONOENCONTRADO, "No se ha podido encontrar");
void sendErrorMSG_UDP(int s, struct sockaddr_in clientaddr_in, int codigoError, char * errMsg){
BYTE * msg;
int addrlen;
int nc;
addrlen = sizeof(struct sockaddr_in);
msg = ErrorMsg(codigoError, errMsg);
nc = sendto (s, msg, BUFFERSIZE, 0, (struct sockaddr *)&clientaddr_in, addrlen);
if ( nc == -1) {
perror("serverUDP");
printf("%s: sendto error\n", "serverUDP");
return;
}
return;
}
void sendErrorMSG_TCP(int s, int codigoError, char * errMsg){
BYTE * msg;
int nc;
msg = ErrorMsg(codigoError, errMsg);
nc = send (s, msg, BUFFERSIZE, 0);
if ( nc == -1) {
perror("serverUDP");
printf("%s: sendto error\n", "serverUDP");
return;
}
return;
}