smarty template cache syncing daemon (PoC)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
851B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <sys/un.h>
  8. #include <time.h>
  9. #define FILENAME "cachesync.sock"
  10. int main(int argc, char *argv[])
  11. {
  12. if (argc != 2) {
  13. printf("$ testclient <cmd>\n");
  14. exit(0);
  15. }
  16. int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  17. if (sockfd == -1) {
  18. perror("socket()");
  19. exit(-1);
  20. }
  21. struct sockaddr_un addr;
  22. addr.sun_family = AF_UNIX;
  23. strncpy(addr.sun_path, FILENAME, sizeof(addr.sun_path));
  24. int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
  25. if (connect(sockfd, (struct sockaddr *)&addr, len) < 0) {
  26. perror("connect()");
  27. exit(-1);
  28. }
  29. srandom(time(NULL));
  30. usleep((random() % 100) * 10000);
  31. write(sockfd, argv[1], strlen(argv[1]) +1);
  32. usleep((random() % 100) * 10000);
  33. close(sockfd);
  34. return 0;
  35. }