Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include "csapp.h"
  2.  
  3. #define BUFFLEN 256
  4. #define SET 0
  5. #define GET 1
  6. #define DIGEST 2
  7. #define RUN 3
  8.  
  9. int set(){
  10. return 0;
  11. }
  12.  
  13. int get(){
  14. return 0;
  15. }
  16.  
  17. int digest(){
  18. return 0;
  19. }
  20.  
  21. int run(){
  22. return 0;
  23. }
  24.  
  25. int main(int argc, char** argv){
  26. int listenfd, connfd, port;
  27. socklen_t clientLen;
  28. rio_t rio;
  29. struct sockaddr_in clientaddr;
  30. char *buff, *SecretKey;
  31. struct hostent *hp;
  32. char *haddrp;
  33.  
  34.  
  35. SecretKey = (argv[2]);
  36. port = atoi(argv[1]);
  37.  
  38. //listen for connection request
  39. printf("%d %s", port, SecretKey);
  40. listenfd = Open_listenfd(port);
  41. printf("listening on port 3001");
  42. //clientlen = sizeof(clientaddr);
  43.  
  44. //establish connection
  45. while(1){
  46. clientLen = sizeof(clientaddr);
  47. connfd = Accept(listenfd, (SA*)&clientaddr, &clientLen);
  48. hp = Gethostbyaddr((const char*)&clientaddr.sin_addr.s_addr, sizeof(clientaddr.sin_addr.s_addr),AF_INET);
  49. haddrp = inet_ntoa(clientaddr.sin_addr);
  50. printf("%s %s\n", hp->h_name, haddrp);
  51. printf("here");
  52. Rio_readinitb(&rio, connfd);
  53. //unsigned char buf[4];
  54. //Rio_readlineb(&rio, buf, 4);
  55. //printf("%s",buf);
  56. //Rio_readlineb(&rio, rio.rio_buf, sizeof(rio.rio_buf));
  57. printf("they tried");
  58. if (SecretKey != (rio.rio_buf)){ //if secret key is wrong, replies -1
  59. printf("Secret key = %d\n", atoi(SecretKey));
  60. printf("---------------------\n");
  61. buff = (char*)'1';
  62. Rio_writen(connfd, buff, sizeof(buff));
  63. }
  64. else{
  65. buff = (char*)'0';
  66. printf("this did a thing");
  67. Rio_writen(connfd, buff, sizeof(buff));
  68. Rio_readlineb(&rio, rio.rio_buf, sizeof(rio.rio_buf));
  69. if(atoi(rio.rio_buf) == SET)
  70. set();
  71. if(atoi(rio.rio_buf) == GET)
  72. get();
  73. if(atoi(rio.rio_buf) == DIGEST)
  74. digest();
  75. if(atoi(rio.rio_buf) == RUN)
  76. run();
  77. }
  78. }
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement