Writing Monitors for the Event Monitoring Service (December 1999)
148 Chapter5
Writing a Target Application
Target Application Overview
/*************************************************************************/
/* Read data off of the socket */
/*************************************************************************/
msglen = recvfrom (datasock, buf, objlen + HEADER_LEN, 0,
&clientaddr_in, &addrlen);
buf[HEADER_LEN+objlen] = ’\0’;
if (msglen == -1) {
perror("recvfrom() returned -1");
exit(1);
}
/*************************************************************************/
/* Print message header info */
/*************************************************************************/
timer = time(NULL);
printf("\n\n<<<<<< %s", ctime(&timer));
printf("<<<<<< Message Received from %s",
inet_ntoa(clientaddr_in.sin_addr));
hp = gethostbyaddr((const char *)&clientaddr_in.sin_addr,
sizeof(struct in_addr), AF_INET);
if (hp) {
printf(" (%s)", hp->h_name);
}
printf("\n\n");
/*************************************************************************/
/* Uncompress the object */
/*************************************************************************/
buf_offset = buf + HEADER_LEN;
obj = rm_uncompress_object(buf_offset, &error_code);
if (!obj) {
rm_strerror(error_code, errbuf, sizeof(errbuf));
fprintf(stderr, "Could not uncompress message: %s", errbuf);
continue; /* skip this message */
}