qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / crashpmcd.c
blob9f9e944222733eb73e31aa5d2d003832f9ab4f2c
1 /*
2 * Crashes pmcd on IRIX. Linux seems to be OK. PV 935490.
3 */
4 #include <pcp/pmapi.h>
5 #include <pcp/impl.h>
7 static __pmPDUHdr hdr;
8 static char *target;
10 void
11 try(int len)
13 int fd;
14 int sts;
15 static int first = 1;
16 static struct sockaddr_in myAddr;
17 static struct hostent* servInfo;
18 char buf[256];
20 if (first) {
21 first = 0;
22 if ((servInfo = gethostbyname(target)) == NULL) {
23 fprintf(stderr, "host \"%s\" unknown\n", target);
24 exit(1);
26 memset(&myAddr, 0, sizeof(myAddr));
27 myAddr.sin_family = AF_INET;
28 memcpy(&myAddr.sin_addr, servInfo->h_addr, servInfo->h_length);
29 myAddr.sin_port = htons(SERVER_PORT);
32 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
33 fprintf(stderr, "socket failed: %s\n", pmErrStr(errno));
34 return;
37 if ((sts = connect(fd, (struct sockaddr*) &myAddr, sizeof(myAddr))) < 0) {
38 fprintf(stderr, "connect failed: %s\n", pmErrStr(sts));
39 close(fd);
40 return;
43 if ((sts = write(fd, &hdr, len)) != len) {
44 fprintf(stderr, "write failed: %s\n", pmErrStr(sts));
45 close(fd);
46 return;
48 sts = read(fd, buf, sizeof(buf));
49 if (sts < 0) {
50 /* in this case don't really care about the return code from read() */
53 close(fd);
56 int
57 main(int argc, char *argv[])
59 int j;
60 int k;
62 __pmSetProgname(argv[0]);
64 target = argc == 2 ? argv[1] : "localhost";
66 hdr.from = htonl(12345);
68 for (k = -1; k <= 12; k++) {
69 hdr.len = htonl(k);
70 hdr.type = htonl(0x55aa0000);
71 for (j = 0; j <= 12; j++) {
72 try(j);
76 for (k = 0; k <= 12; k++) {
77 hdr.len = htonl(k<<24);
78 hdr.type = htonl(0x000055aa);
79 for (j = 0; j <= 12; j++) {
80 try(j);
84 return 0;