Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <unistd.h>
- #include <stdio.h>
- #define BUFLEN 1472
- #define NPACK 100000
- #define PORT 1028
- void diep(char *s)
- {
- perror(s);
- exit(1);
- }
- int main(void){
- FILE *f = fopen("dumpc.bin", "wb");
- struct sockaddr_in si_me, si_other;
- int s, i, slen=sizeof(si_other);
- char buf[BUFLEN];
- if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
- diep("socket");
- memset((char *) &si_me, 0, sizeof(si_me));
- si_me.sin_family = AF_INET;
- si_me.sin_port = htons(PORT);
- si_me.sin_addr.s_addr = htonl(INADDR_ANY);
- if (bind(s, &si_me, sizeof(si_me))==-1)
- diep("bind");
- for (i=0; i<NPACK; i++) {
- if (recvfrom(s, buf, BUFLEN, 0, &si_other, &slen)==-1)
- diep("recvfrom()");
- fwrite(buf, 1, 1472, f);
- //memset(buf, 0xff,1472);
- //printf("%d\n", i);
- //printf("Received packet from %s:%d\n",
- // inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
- }
- fclose(f);
- close(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement