GET_ALL_FILES update

This commit is contained in:
s449273 2020-01-03 10:24:51 +01:00
parent 89c6696c67
commit 7462265f08
1 changed files with 18 additions and 12 deletions

View File

@ -7,6 +7,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <sys/time.h>
#include <dirent.h> #include <dirent.h>
int main(int argc, char **argv) int main(int argc, char **argv)
@ -48,7 +49,7 @@ int main(int argc, char **argv)
&addrlen)) >= 0) &addrlen)) >= 0)
{ {
start: start:
printf("CONNECT FROM : %s\n ", inet_ntoa(endpoint.sin_addr)); printf("CONNECT FROM : %s\n", inet_ntoa(endpoint.sin_addr));
bzero(buff, 512); bzero(buff, 512);
recv(sdconnection, buff, 512, 0); recv(sdconnection, buff, 512, 0);
@ -60,25 +61,30 @@ int main(int argc, char **argv)
bzero(names_files, 512); bzero(names_files, 512);
bzero(name_file, 512); bzero(name_file, 512);
n = scandir(".", &namelist, NULL, alphasort); DIR *d = opendir(".");
if (n == -1) struct dirent *enterDirectory;
if (d == NULL)
{ {
perror("scandir"); printf("OPEN ERROR\n");
exit(EXIT_FAILURE); return EXIT_FAILURE;
} }
while (n--) while ((enterDirectory = readdir(d)) != NULL)
{ {
sprintf(name_file, "%s\n", namelist[n]->d_name); if (enterDirectory->d_type == DT_REG)
strcat(names_files, name_file); {
free(namelist[n]); sprintf(name_file, "%s\n", enterDirectory->d_name);
strcat(names_files, name_file);
}
} }
free(namelist);
closedir(d);
if (s = send(sdconnection, names_files, 512, 0) == 512) if (s = send(sdconnection, names_files, 512, 0) == 512)
{ {
printf("SEND SUCCESS"); printf("SEND SUCCESS\n");
goto start; goto start;
} }
} }
@ -186,4 +192,4 @@ int main(int argc, char **argv)
} }
close(sdsocket); close(sdsocket);
return 0; return 0;
} }