-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpulsar_record.c
100 lines (93 loc) · 2.69 KB
/
pulsar_record.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#define _FILE_OFFSET_BITS 64
#include <sys/socket.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netdb.h>
#include <string.h>
#include <strings.h>
#include <netinet/in.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <sys/stat.h>
#define CLK (140000000. / 2)
#define SOCKSIZE (8388608*8)
#define MTU 8900
/*#define MAXCOUNT (unsigned long)(30 * CLK * 60. / 64. / 512.)*/
#define MAXCOUNT 1024*1024*100
unsigned char * packet_buf;
int fd,fdw;
int main(int argc, char * argv[])
{
int i,j = 0;
struct sockaddr_in server_addr, client_addr;
struct hostent *hp;
struct timeval stamp;
unsigned int packet_counter, max_packet_counter, client_len=sizeof(client_addr);
int optval, optlen;
ssize_t ps;
if(argc != 2)
{
fprintf(stderr, "%s requires one argument: output file name\n", argv[0]);
exit(10);
}
if ((fdw = open(argv[1], O_WRONLY| O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
fprintf(stderr, "Can't open %s\n", argv[1]);
exit(10);
}
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
fprintf(stderr, "no socket\n");
exit(10);
}
optval = SOCKSIZE;
optlen = sizeof(optval);
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, optlen)<0) {
fprintf(stderr, "setsockopt failed\n");
exit(10);
}
if(getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, &optlen)<0) {
fprintf(stderr, "getsockopt failed\n");
exit(10);
}
fprintf(stderr, "Getsocket SO_RCVBUF returned: %d\n",optval);
if (optval <= SOCKSIZE) {
fprintf(stderr, "SO_RCVBUF too small: increase net.core.rmem_max to %ld\n",SOCKSIZE);
exit(10);
}
bzero(&server_addr, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(22102);
server_addr.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <0) {
fprintf(stderr, "bind failed\n");
exit(10);
}
if((packet_buf = malloc(MTU)) == NULL) {
fprintf(stderr, "malloc failed\n");
exit(10);
}
while (j < MAXCOUNT) {
if((ps=recvfrom(fd, packet_buf, MTU, 0,
(struct sockaddr *)&client_addr, &client_len))<0) {
fprintf(stderr, "recvfrom() failed\n");
exit(10);
}
if(ps != 2052)
{
fprintf(stderr, "Read %ld bytes!\n", ps);
}
memcpy(packet_buf+256*4, packet_buf, 4); /* Copy the packet counter to second half */
write(fdw,packet_buf+256*4,256*4); /* Write only the second half */
j++;
if (j % (int)(70000000/512/64) == 0)
{
printf("MB: %d\n",(int)(j/1024));
fsync(fdw);
}
}
close(fd);
close(fdw);
}