/
client.c
1181 lines (832 loc) · 31.8 KB
/
client.c
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @akannan4_proj1.c
* @author Abhishek Kannan
* @email akannan4@buffalo.edu
*
* Client
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#define RECV_BUFSIZE 1000
#define SEND_BUFSIZE 1000
struct timeval startTime, endTime;
typedef struct fileData{
char header[256];
char data[SEND_BUFSIZE];
int size;
}fileData;
/*
* Function: printTime
* --------------------
* Returns time in HH:MM:SS format
*
*
* return: time
*
*/
char* printTime(){
time_t current_time;
struct tm * time_info;
char timeString[9];
time(¤t_time);
time_info = localtime(¤t_time);
strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info);
return timeString;
}
/*
* Function: getHostFromSock
* --------------------
* Returns the hostname of a Socket descriptor
*
*
* fd: Socket file descriptor
* list: IP List
*
* returns: Hostname
*/
char* getHostFromSock(int fd,node* list){
while(list!=NULL){
if(list->socketFd==fd){
return list->hostname;
}
list=(node*) list->next;
}
}
/*
* Function: isValid
* --------------------
* Checks if an IP Address(peer) is registered to the server
*
*
* IP: IP Address
* list: IP List
* size: Size of list
*
*/
int isValid(char* IP, peer* list,int size) {
int i;
for(i=0;i<size;i++)
{
if(strcmp(IP,list[i].IPAddress)==0){
return 1;
}
}
return 0;
}
/*
* Function: syncFiles
* --------------------
* Forwards SYNC request to server
*
* list: IP list
*
*/
void syncFiles(node* list){
node *curr=list;
char * s="SYNC";
send(curr->socketFd,s,sizeof(s),0);
printf("Initiated SYNC\n");
}
/*
* Function: endSyncFiles
* --------------------
* Notifies the server that SYNC has been completed
*
*
* list: IP list
*
*/
void endSyncFiles(node* list){
node *curr=list;
char * s="E_SYNC";
send(curr->socketFd,s,sizeof(s),0);
printf("Completed SYNC\n");
}
/*
* Function: get
* --------------------
* Forwards the GET Request to the appropriate client using connection ID
*
* list: IP List
*
* returns: 1 if forward was sucessful
* 0 if forward failed/file requested from server
*/
int get(node* list) {
int connID=atoi(parsedCommand[1]);
if(connID==1){
printf("Files cannot be downloaded from server!");
return 0;
}
char* fileName=parsedCommand[2];
char request[100];
memset(request,0,100);
int i;
for(i=1;i<connID;i++){
list=(node*) list->next;
}
// parsed command is pointer, so copy to char array before sending it.
strcpy(request,parsedCommand[0]);
strcat(request, " ");
strcat(request,parsedCommand[1]);
strcat(request, " ");
strcat(request,parsedCommand[2]);
if(send(list->socketFd,request,100,0)>0) {
return 1;
}
else {
return 0;
}
}
/*
* Function: put
* --------------------
* Sends the file 'File name' to 'connection ID'
*
*
* list: IP List
*
* returns: 1 if send was sucessful
* 0 if send failed
*/
int put(node* list)
{
int connID=atoi(parsedCommand[1]);
char* fileName=parsedCommand[2];
FILE *uploadfp=NULL;
struct stat file_stat;
char file_name_size[256];
char send_buffer[SEND_BUFSIZE];
int i;
for(i=1;i<connID;i++){
list=(node*) list->next;
}
uploadfp=fopen(fileName, "r");
if(uploadfp==NULL) {
printf("the requested file does not exist: %s\n",fileName);
return 0;
}
if (fstat(fileno(uploadfp), &file_stat) < 0) {
fprintf(stderr, "Error fstat --> %s", strerror(errno));
return 0;
}
sprintf(file_name_size, "%s %d", fileName,file_stat.st_size);
printf("Sending file %s to %s \n",fileName,list->hostname);
send(list->socketFd, file_name_size, sizeof(file_name_size),0);
memset(send_buffer,0,SEND_BUFSIZE);
int sentBytes;
gettimeofday (&startTime, NULL);
while((sentBytes = fread(send_buffer, sizeof(char), SEND_BUFSIZE, uploadfp)) > 0) {
if(send(list->socketFd, send_buffer, sentBytes, 0) < 0) {
fprintf(stderr, "ERROR: Failed to send file %s. (errno = %d)\n", fileName, errno);
break;
}
}
gettimeofday (&endTime, NULL);
printf("Sent %s to %s\n", fileName,list->hostname);
long timeTaken=((endTime.tv_sec - startTime.tv_sec)*1000000L+endTime.tv_usec) - startTime.tv_usec;
printf("Time taken to upload file: %ld microseconds\n",timeTaken);
long txRate = (((long)file_stat.st_size*8 )/ timeTaken);
printf("TX Rate is : %ld x 10^-6 Mbits/microsecs \n",txRate);
return 1;
}
/*
* Function: displayAll
* --------------------
* Displays all peers connected to the server
*
* list: List containing all peers connected to the Server
* size: size of list
*/
void displayAll(peer* list,int size)
{
int i;
printf("Client : Server has sent the updated peer list\n");
printf("Hostname\t\tIP Address\t\tPort No.\n");
for(i=0;i<size;i++)
{
printf("%s\t\t%s\t\t%d\n",list[i].hostname,list[i].IPAddress,list[i].port);
}
}
/*
* Function: reg
* --------------------
* Register to the server
*
*
* fd: File descriptor used in connect
* lPort: Listening port of client
* client_IP_list: IP List
*
* returns: 1 if register was successful
* 0 if register failed
*
*/
int reg( int fd,char* lPort,node ** client_IP_list) {
char* ip = parsedCommand[1];
int port = atoi(parsedCommand[2]);
struct in_addr ip_struct;
struct sockaddr_in address;
inet_aton(ip,&ip_struct);
address.sin_addr=ip_struct;
address.sin_family = AF_INET;
address.sin_port = htons(port);
//
struct addrinfo hints, *res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
hints.ai_socktype = SOCK_STREAM;
// getaddrinfo(ip, parsedCommand[2], &hints, &res);
// getaddrinfo causing memory corruption, try to fix
//
if(connect(fd,(struct sockaddr*)&address,sizeof(address))==0) {
printf("Registration successful! \n");
send(fd,lPort,10,0);
push(address,fd,port,client_IP_list);
if(!res)
freeaddrinfo(res);
return 1;
}
else {
perror("Client");
if(!res)
freeaddrinfo(res);
return 0;
}
}
/*
* Function: con
* --------------------
* Connect to another client
*
*
* client_IP_list: IP List
* allPeers: Peers connected to server
* size: size of allPeers
* listeningPort: Listening port of client
*
* returns: sockFD if connection was successful
* 0 if connection failed/error encountered
*
*/
int con(node* client_IP_list,peer* allPeers,int size, char* listeningPort)
{
char* peerIP = parsedCommand[1];
int peerPort = atoi(parsedCommand[2]);
node *curr=client_IP_list;
char hname[256];
if (gethostname(hname, sizeof(hname)) < 0) {
perror("gethostname");
return 0;
}
if(!client_IP_list) {
printf("Client : I am not registered to the server. I am not allowed to connect to peers.\n");
return 0;
}
else if(strcmp(peerIP,client_IP_list->IPAddress)==0) {
printf("Client : You do not connect to a server. You can only register to a server!\n");
return 0;
}
else if(strcmp(peerIP,client_IP_list->hostname)==0) {
printf("Client : You do not connect to a server. You can only register to a server!\n");
return 0;
}
else if(strcmp(peerIP,hname)==0) {
printf("Client: I cannot connect to myself!\n");
return 0;
}
//Causing memorry corruption for some reason.
else if(strcmp(peerIP,myIP)==0) {
printf("Client: I cannot connect to myself!\n");
//free(machineIP);
return 0;
}
//free(machineIP);
else if( isValid(peerIP,allPeers,size) == 0 ){
printf("Client: No such IP Address is registered to the server!\n");
return 0;
}
while(curr)
{
if(strcmp(peerIP,curr->IPAddress)==0)
{
printf("Client : I am already connected to %s \n",curr->hostname);
return 0;
}
if(strcmp(peerIP,curr->hostname)==0)
{
printf("Client : I am already connected to %s \n",curr->hostname);
return 0;
}
curr = curr->next;
}
struct in_addr peerIP_struct;
struct sockaddr_in peerDetails;
int sockFD;
inet_aton(peerIP,&peerIP_struct);
peerDetails.sin_addr = peerIP_struct;
peerDetails.sin_family = AF_INET;
peerDetails.sin_port = htons(peerPort);
sockFD=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sockFD == -1)
{
printf("Client: Not able to create socket!\n");
close(sockFD);
return 0;
}
//
struct addrinfo hints, *res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
hints.ai_socktype = SOCK_STREAM;
// getaddrinfo(peerIP, parsedCommand[2], &hints, &res);
//
if(connect(sockFD,(struct sockaddr*)&peerDetails,sizeof(peerDetails))<0)
{
perror("Client");
close(sockFD);
if(!res)
freeaddrinfo(res);
return 0;
}
printf("Client : Connected to IPAddress %s \n",peerIP);
send(sockFD,listeningPort,10,0);
push(peerDetails,sockFD,peerPort,&client_IP_list);
if(!res)
freeaddrinfo(res);
return sockFD;
}
/*
* Function: terminate
* --------------------
* Terminate connection to a client
*
* list: IP List
*
* returns: File descriptor of terminated connection if termination successful
* -1 if termination failed
*
*/
int terminate(node** list){
int connID = atoi(parsedCommand[1]);
/*
if(connID==1){
printf("Cannot terminate connection with server! \n");
return -1;
}
*/
int i;
int fd;
node* curr = *list;
i=1;
while(curr){
if(i==connID){
if(strcmp(curr->hostname,"timberlake.cse.buffalo.edu")==0){
printf("Cannot terminate connection with server! \n");
return -1;
}
fd=curr->socketFd;
shutdown(fd,SHUT_RDWR);
if(close(fd)== 0){ //Termiate successful
delete(curr->IPAddress,curr->port,list);
printf("Terminated connection to %s \n",curr->hostname);
return fd;
}
}
i++;
curr=(node*) curr->next;
}
return -1;
}
/*
* Function: client
* --------------------
* Client
* port: Port number to which client should be bound
*
* returns: 1 if client was shutdown
* 0 if some error was encountered
*
*/
int client(char* port)
{
//printf("packet size is %d\n",SEND_BUFSIZE);
int completed=0;
int noOfFilesToSync=0;
int syncMode=0;
node *client_IP_list = NULL;
char msg[10000];
int cmdNo;
char* tokens[3];
char fileName[500];
FILE *uploadfp=NULL;
FILE *downloadfp=NULL;
//sockaddr_in
struct sockaddr_in myIPAddress,peerIPAddress;
//socklen_t
socklen_t peerIPAddrLen = sizeof(peerIPAddress);
int noOfConnections = 0;
int numBytes; // Number of bytes read using recv function
//Socket file descriptors
int clientSocket;
int listenerSocket;
int newSocket;
int selectedSocket;
//FD
fd_set read_fds,read_fdsCopy,write_fds,write_fdsCopy;
int fdMax;
//Initialize FD
FD_ZERO(&read_fds);
FD_ZERO(&read_fdsCopy);
FD_ZERO(&write_fds);
FD_ZERO(&write_fdsCopy);
printf("Client is up!\n");
peer* allPeers;
node* list;
int countOfPeers;
// Listener Socket
listenerSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
printf("Client created \n");
if(listenerSocket == -1) {
printf("Client: \n");
}
int reuse=1;
setsockopt(listenerSocket,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(int));
myIPAddress.sin_addr.s_addr = INADDR_ANY;
myIPAddress.sin_family = AF_INET;
myIPAddress.sin_port = htons(atoi(port));
if(bind(listenerSocket,(struct sockaddr*)&myIPAddress,sizeof(myIPAddress))== -1)
{
printf("Listener : Binding failed\n");
close(listenerSocket);
}
printf("Listener has been bound to port %d \n",atoi(port));
listen(listenerSocket,4);
printf("Listening on port %d \n",atoi(port));
fdMax = listenerSocket;
// Client Socket
clientSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(clientSocket==-1)
{
printf("Client : Could not create socket to connect to server/n");
}
// SetFD
FD_SET(STDIN_FILENO,&read_fds);
FD_SET(listenerSocket,&read_fds);
while(1)
{
read_fdsCopy = read_fds;
write_fdsCopy = write_fds;
if (select(fdMax+1, &read_fdsCopy, &write_fdsCopy, NULL, NULL) == -1)
{
perror("Client");
continue;
}
for(selectedSocket = 0;selectedSocket<=fdMax;selectedSocket++)
{
if(FD_ISSET(selectedSocket,&read_fdsCopy))
{
if(selectedSocket == listenerSocket) // This is a connection request
{
if(noOfConnections == 4)
{
printf("Client: Connection limit exceeded!\n");
continue;
}
memset(&peerIPAddress, 0, sizeof(peerIPAddrLen));
if ((newSocket = accept(listenerSocket,(struct sockaddr*)&peerIPAddress,&peerIPAddrLen))==-1)
{
printf("Client : Accept failed.\n");
}
memset(msg,0,5000);
// Receive clients listening port number
numBytes = recv(newSocket,msg,10,0);
printf("Connection request from %s : %d \n",inet_ntoa(peerIPAddress.sin_addr),atoi(msg));
push(peerIPAddress,newSocket,atoi(msg),&client_IP_list);
noOfConnections++;
FD_SET(newSocket,&read_fds); // Add new socket to FD
printf("Connection established.Yay!\n");
fdMax = getMaxFD(client_IP_list);
}
else if(selectedSocket == clientSocket) // Data from server
{
/* What data ?
1. Server shutdown
2. Recv function error
3. Peer list
*/
numBytes = recv(selectedSocket, msg, 5000,0);
char command2[4];
memcpy(command2,msg,4); // Extract first 3 characters from incoming data
if(numBytes == 0) { // Server has shutdown
printf("Client: Server terminated my connection/shutdown\n");
noOfConnections--;
printf("Closing all connections\n"); //TODO
client_IP_list=NULL;
FD_CLR(selectedSocket,&read_fds);
close(selectedSocket); // clientSocket closed
clientSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // recreate
}
else if(numBytes<0) { // Recv function error
perror("Client");
}
else if(!(strcmp(command2,"SYNC")) || (!(strcmp(command2,"sync")))) { // Check if it is GET command
// Extract list of all peers who finished SYNC.
//Send text file named after me to all connected peers
syncMode=1;
char * file;
char * dir="/local/Fall_2015/akannan4/";
char * ext=".txt";
node *curr=client_IP_list;
int i=1;
char connID[15];
char** tokens = (char**) malloc(5*sizeof(char*));
curr=curr->next; // skip server
noOfFilesToSync=noOfConnections-1;
if(curr){
i=2;
sprintf(connID, "%d", i);
file = strtok(curr->hostname,".");
char * filename = (char *) malloc(1 + strlen(dir)+ strlen(file)+ strlen(ext) );
strcpy(filename, dir);
strcat(filename, file);
strcat(filename, ext);
printf("Start %s %s\n",filename,printTime());
tokens[0]="GET";
tokens[1]=connID;
tokens[2]=filename;
i++;
parsedCommand=tokens;
get(client_IP_list);
completed++;
}
else{
syncMode=0;
}
}
else { // Peer list
if(!allPeers) free(allPeers);
countOfPeers = numBytes/sizeof(peer);
allPeers = (peer*)malloc(sizeof(peer)*(countOfPeers));
memcpy(allPeers,msg,sizeof(msg));
displayAll(allPeers,countOfPeers);
memset(msg,0,sizeof(msg));
}
}
else if(selectedSocket == 0) // Data from STDIN
{
memset(msg,0,sizeof(msg)); // clear msg array
if ((numBytes = read(selectedSocket, msg, sizeof(msg))) <= 0)
perror("Client");
else
{
cmdNo = parse(msg);
int fd;
int error;
int retval;
peer peers[1];
switch(cmdNo)
{
case 0: //HELP
help();
break;
case 1: //CREATOR
creator();
break;
case 2: //DISPLAY
display(port,1);
// free(machineIP);
break;
case 3: //REGISTER
// clientSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(reg(clientSocket,port,&client_IP_list)){
noOfConnections++;
if(fdMax < clientSocket)
fdMax = clientSocket;
FD_SET(clientSocket,&read_fds);
}
break;
case 4: //CONNECT
if(noOfConnections >= 4) { // why 4? 3 connnections to peers + one connection to server!
printf("Client : Connection limit exceeded!\n");
}
else {
fd=con(client_IP_list,allPeers,countOfPeers,port);
if(fd>0){
fdMax=getMaxFD(client_IP_list);
FD_SET(fd,&read_fds);
noOfConnections++;
}
}
break;
case 5: // LIST
displayList(client_IP_list);
break;
case 6: // TERMINATE
fd=terminate(&client_IP_list);
if(fd!=-1){
FD_CLR(fd,&read_fds);
FD_CLR(fd,&write_fds);
fdMax = getMaxFD(client_IP_list);
noOfConnections--;
if(noOfConnections==0){
client_IP_list=NULL;
}
}
else{
printf("Invalid connection ID \n");
}
break;
case 7: // QUIT
quit(&client_IP_list);
shutdown(listenerSocket,SHUT_RDWR);
close(listenerSocket);
shutdown(clientSocket,SHUT_RDWR);
close(clientSocket);
return 1;
break;
case 8: // GET
get(client_IP_list);
break;
case 9: // PUT
put(client_IP_list);
break;
case 10: //SYNC
syncFiles(client_IP_list);
break;
default:
break;
}
}
}
else{ // Data from another peer.
/* What data ?
1. Peer connection closed.
2. GET command from peer
3. Incoming file from peer.
*/
numBytes = recv(selectedSocket, msg, sizeof(msg), 0);
if (numBytes == 0) { // Peer connection closed.
//So which peer ?
memset(&peerIPAddress,0,peerIPAddrLen);
if(getpeername(selectedSocket,(struct sockaddr*)&peerIPAddress,&peerIPAddrLen)<0) {
perror("Client\n");
return 1;
}
char* IPAdd = (char*)malloc(sizeof(char)*INET6_ADDRSTRLEN);
inet_ntop(AF_INET, &(peerIPAddress.sin_addr), IPAdd, INET6_ADDRSTRLEN);
printf("Client %s has closed the connection\n",IPAdd);
delete(IPAdd,ntohs(ntohs(peerIPAddress.sin_port)),&client_IP_list);
noOfConnections--;
FD_CLR(selectedSocket, &read_fds);
fdMax = getMaxFD(client_IP_list);
close(selectedSocket);
}
else if(numBytes<0) { // Recv function error
perror("Client");
}
else {
/*
1. Check if data is a GET command
2. Check if data is a file
*/
char command[3];
memcpy(command,msg,3); // Extract first 3 characters from incoming data
char* host=getHostFromSock(selectedSocket,client_IP_list);
if(!(strcmp(command,"GET")) || (!(strcmp(command,"get"))) ) { // Check if it is GET command
char path[1024];
getcwd(path,sizeof(path));
int tokenCount = 0;
char file_name_size[256];
struct stat file_stat;
int sent_bytes;
tokens[tokenCount] = strtok(msg," ");
while(tokens[tokenCount])
{
tokens[++tokenCount]=strtok(NULL," ");
}
strcpy(fileName, tokens[2]);
strcat(path,"/");
strcat(path,fileName);
printf("%s\n",path);