Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include "../common/common.c"
  2.  
  3. #define NAME "net1"
  4. #define UID 998
  5. #define GID 998
  6. #define PORT 2998
  7.  
  8. void run()
  9. {
  10. char buf[12];
  11. char fub[12];
  12. char *q;
  13.  
  14. unsigned int wanted;
  15.  
  16. wanted = random();
  17.  
  18. sprintf(fub, "%d", wanted);
  19.  
  20. if(write(0, &wanted, sizeof(wanted)) != sizeof(wanted)) {
  21. errx(1, ":(\n");
  22. }
  23.  
  24. if(fgets(buf, sizeof(buf)-1, stdin) == NULL) {
  25. errx(1, ":(\n");
  26. }
  27.  
  28. q = strchr(buf, '\r'); if(q) *q = 0;
  29. q = strchr(buf, '\n'); if(q) *q = 0;
  30.  
  31. if(strcmp(fub, buf) == 0) {
  32. printf("you correctly sent the data\n");
  33. } else {
  34. printf("you didn't send the data properly\n");
  35. }
  36. }
  37.  
  38. int main(int argc, char **argv, char **envp)
  39. {
  40. int fd;
  41. char *username;
  42.  
  43. /* Run the process as a daemon */
  44. background_process(NAME, UID, GID);
  45.  
  46. /* Wait for socket activity and return */
  47. fd = serve_forever(PORT);
  48.  
  49. /* Set the client socket to STDIN, STDOUT, and STDERR */
  50. set_io(fd);
  51.  
  52. /* Don't do this :> */
  53. srandom(time(NULL));
  54.  
  55. run();
  56. }