Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. else if(ntohs(sireq.requestType) == DIGEST){
  2. printf("Request type = digest\n");
  3. FILE *fp;
  4. char path[BUFFLEN];
  5. char command[70];
  6. int len;
  7. struct digest_request dreq;
  8. struct init_response ires;
  9. ires.three_b_pad[0] = '\0';
  10. ires.three_b_pad[1] = '\0';
  11. ires.three_b_pad[2] = '\0';
  12. ires.returnCode = 0;
  13. rio_t rio;
  14. Rio_readinitb(&rio, connfd);
  15. read(connfd, &dreq, sizeof(dreq));
  16.  
  17. printf("Detail = %s\n", dreq.val);
  18. printf("Completion: success\n");
  19.  
  20. //get the command
  21. len = snprintf(command, sizeof(command), "/bin/echo %s | /usr/bin/sha256sum",dreq.val);
  22. if (len <= sizeof(command))
  23. {
  24. fp = popen(command, "r");
  25. }
  26.  
  27. // Open the command for reading.
  28. if (fp == NULL) {
  29. printf("Completion: failure\n");
  30. }
  31.  
  32. // Read the output a line at a time to path
  33. fgets(path, sizeof(path)-1, fp);
  34.  
  35. // close
  36. pclose(fp);
  37.  
  38. path[SIXTYFIVE] = '\0';
  39.  
  40. strcpy(ires.val, path);
  41. ires.valLength = SIXTYFIVE;
  42.  
  43. write(connfd, &ires, sizeof(ires));
  44. //read(connfd, &dreq.val, ntohs(dreq.valLength));
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement