/[dynamips]/trunk/udp_recv.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/udp_recv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (11 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 809 byte(s)
make working copy

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdarg.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <assert.h>
9
10 #include "utils.h"
11 #include "net.h"
12
13 #define MAX_PKT_SIZE 2048
14
15 int main(int argc,char *argv[])
16 {
17 char pkt[MAX_PKT_SIZE];
18 ssize_t pkt_size;
19 int sck = -1;
20 FILE *fd;
21
22 /* Wait connection */
23 if (ip_listen(atoi(argv[2]),SOCK_DGRAM,1,&sck) < 1) {
24 perror("ip_listen");
25 exit(EXIT_FAILURE);
26 }
27
28 /* Receive packet and store it */
29 if ((pkt_size = recvfrom(sck,pkt,sizeof(pkt),0,NULL,NULL)) < 0) {
30 perror("recvfrom");
31 exit(EXIT_FAILURE);
32 }
33
34 if (!(fd = fopen(argv[1],"w"))) {
35 perror("fopen");
36 exit(EXIT_FAILURE);
37 }
38
39 fwrite(pkt,1,pkt_size,fd);
40 fclose(fd);
41 close(sck);
42 return(0);
43 }

  ViewVC Help
Powered by ViewVC 1.1.26