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
|
/*
* Crashes pmcd on IRIX. Linux seems to be OK. PV 935490.
*/
#include <pcp/pmapi.h>
#include <pcp/impl.h>
static __pmPDUHdr hdr;
static char *target;
void
try(int len)
{
int fd;
int sts;
static int first = 1;
static struct sockaddr_in myAddr;
static struct hostent* servInfo;
char buf[256];
if (first) {
first = 0;
if ((servInfo = gethostbyname(target)) == NULL) {
fprintf(stderr, "host \"%s\" unknown\n", target);
exit(1);
}
memset(&myAddr, 0, sizeof(myAddr));
myAddr.sin_family = AF_INET;
memcpy(&myAddr.sin_addr, servInfo->h_addr, servInfo->h_length);
myAddr.sin_port = htons(SERVER_PORT);
}
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "socket failed: %s\n", pmErrStr(errno));
return;
}
if ((sts = connect(fd, (struct sockaddr*) &myAddr, sizeof(myAddr))) < 0) {
fprintf(stderr, "connect failed: %s\n", pmErrStr(sts));
close(fd);
return;
}
if ((sts = write(fd, &hdr, len)) != len) {
fprintf(stderr, "write failed: %s\n", pmErrStr(sts));
close(fd);
return;
}
sts = read(fd, buf, sizeof(buf));
if (sts < 0) {
/* in this case don't really care about the return code from read() */
;
}
close(fd);
}
int
main(int argc, char *argv[])
{
int j;
int k;
__pmSetProgname(argv[0]);
target = argc == 2 ? argv[1] : "localhost";
hdr.from = htonl(12345);
for (k = -1; k <= 12; k++) {
hdr.len = htonl(k);
hdr.type = htonl(0x55aa0000);
for (j = 0; j <= 12; j++) {
try(j);
}
}
for (k = 0; k <= 12; k++) {
hdr.len = htonl(k<<24);
hdr.type = htonl(0x000055aa);
for (j = 0; j <= 12; j++) {
try(j);
}
}
return 0;
}
|