daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   #include <arpa/inet.h>
  2.   #include <netinet/in.h>
  3.   #include <stdio.h>
  4.   #include <sys/types.h>
  5.   #include <sys/socket.h>
  6.   #include <unistd.h>
  7.   #include <stdio.h>
  8.  
  9.   #define BUFLEN 1472
  10.   #define NPACK 100000
  11.   #define PORT 1028
  12.  
  13.  
  14.   void diep(char *s)
  15.   {
  16.     perror(s);
  17.     exit(1);
  18.   }
  19.  
  20.   int main(void){
  21.    
  22.     FILE *f = fopen("dumpc.bin", "wb");
  23.     struct sockaddr_in si_me, si_other;
  24.     int s, i, slen=sizeof(si_other);
  25.     char buf[BUFLEN];
  26.  
  27.     if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
  28.       diep("socket");
  29.  
  30.     memset((char *) &si_me, 0, sizeof(si_me));
  31.     si_me.sin_family = AF_INET;
  32.     si_me.sin_port = htons(PORT);
  33.     si_me.sin_addr.s_addr = htonl(INADDR_ANY);
  34.     if (bind(s, &si_me, sizeof(si_me))==-1)
  35.         diep("bind");
  36.  
  37.     for (i=0; i<NPACK; i++) {
  38.       if (recvfrom(s, buf, BUFLEN, 0, &si_other, &slen)==-1)
  39.         diep("recvfrom()");
  40.       fwrite(buf, 1, 1472, f);
  41.       //memset(buf, 0xff,1472);
  42.       //printf("%d\n", i);
  43.       //printf("Received packet from %s:%d\n",
  44.       //       inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
  45.     }
  46.     fclose(f);
  47.     close(s);
  48.     return 0;
  49.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top