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