One problem with this solution is the timeout I expect a packet response. Currently it's set to 1 second, and I still sometimes miss an IAX ping response. Which throws false alarms to my other programs, SMS's, etc. What have others done to monitor asterisks availability?
Thanks
--
Sig Lange
http://www.signuts.net/
#include <stdio.h> #include <netdb.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h>
int udpping(char *host, int port, int timeout_sec, int timeout_usec) {
int rc = 0;
int r, s;
char msg[1024];
struct hostent *hp;
struct sockaddr_in destaddr;
fd_set rfds;
struct timeval timeout;
struct hostent *hostname;
s = socket(PF_INET, SOCK_DGRAM, 17);
memset(&destaddr, 0, sizeof(destaddr));
destaddr.sin_port = htons(port);
// destaddr.sin_addr.s_addr = inet_addr(host);
//
hostname = gethostbyname(host);
destaddr.sin_addr.s_addr = ((struct in_addr *)(hostname->h_addr))->s_addr;
// 80 00 00 00 00 00 00 00 00 00 06 1e
strcpy(msg, "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x1e");
timeout.tv_sec = timeout_sec;
timeout.tv_usec = timeout_usec;
FD_ZERO(&rfds);
FD_SET(s, &rfds);
sendto(s, msg, 12, MSG_NOSIGNAL, (struct sockaddr *) &destaddr, sizeof(destaddr) );
r = select(s + 1, &rfds, NULL, NULL, &timeout);
if (r) {
r = recv(s, msg, 1024, 0);
if (r) rc = 1;
}
return rc;
}
int main(int argc, char **argv) {
int r;
if (argc < 2) {
printf("Usage: %s <ip>\n", argv[0]);
exit(100);
}
r = udpping(argv[1], 4569, 1, 0);
r = ! r;
exit(r);
}
_______________________________________________ --Bandwidth and Colocation sponsored by Easynews.com -- Asterisk-Users mailing list [email protected] http://lists.digium.com/mailman/listinfo/asterisk-users To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
