Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <arpa/inet.h>
- int main(void)
- {
- int sock = 0,n = 0;
- char recvBuff[1024];
- //TEST
- char user_input[10];
- char command[20];
- struct sockaddr_in serv_addr;
- memset(recvBuff, '\0' ,sizeof(recvBuff));
- if((sock = socket(AF_INET, SOCK_STREAM, 0))< 0)
- {
- printf("\n Error : Could not create socket \n");
- return 1;
- }
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(5000);
- //serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- if(connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
- {
- printf("\n Error : Connect Failed \n");
- return 1;
- }
- //printf("cmd (? for help)>");
- while(1)
- {
- printf("cmd (? for help)> ");
- fgets(command, 20, stdin);
- if (command[0] == '?')
- printf("! You are connected to the server\n");
- else
- {
- printf("cmd (? for help)>\n");
- printf("Press a valid key\n");
- }
- printf("! Please press a key:\n");
- printf("! [1] list content of current directory (ls)\n! [2] print name of current directory (pwd)\n! [3] change current directory (cd)\n! [4] get file information\n! [5] display file (cat)\n! [?] this menu\n! [q] quit\ncmd (? for help)> ");
- fgets(command, 20, stdin);
- if (command[0] == '3')
- {
- printf("new dir (? for help)> ");
- fgets(command, 20, stdin);
- while (command[0] != '?')
- {
- printf("new dir (? for help)> ");
- fgets(command, 20, stdin);
- }
- printf("! .. the parent directory\n! / a new absolute directory\n! a new directory relative to the current position\n! [?] this menu\n! [q] leave this menu\n");
- printf("new dir (? for help)> ");
- fgets(command, 20, stdin);
- //printf("new dir (? for help)> %c%c", command[0], command[1]);
- //printf("! OK\n");
- }
- write(sock, command, strlen(command));
- memset(recvBuff, '\0', sizeof(recvBuff));
- while ( (n = read(sock, recvBuff, sizeof(recvBuff)-1)) > 0)
- {
- printf("%s\n", recvBuff);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement