// // Filename: mfe.c // #define Version "000" // // Edit date: 2010-03-30 // // Facility: Asterisk // // Abstract: My First Externalivr // // Environment: Asterisk // // Author: Steven L. Edwards // // Modified by // // 000 2010-03-30 SLE Create. #include #define PORT 5000 #define IP "10.10.10.2" #include #include #include #include #include #include #include #include void die(char *s) { perror(s); exit(1); } void signal_handler(int signum) { switch (signum) { case SIGINT: printf("\nReceived interrupt signal. Exiting.\n"); close(sock); exit(0); default: printf("\nUnknown signal received. Ignoring.\n"); } } int main(int argc, char **argv) { auto char event[256]; auto int idx; // Set the syslog ident openlog("udp-extivr", LOG_PID, LOG_USER); // announce ourselves syslog(LOG_ERR, "Starting."); // show how we were executed idx = 0; syslog(LOG_ERR, "argc = %d", argc); while (idx < argc) { syslog(LOG_ERR , "arg[%d] = \"%s\"" , idx , argv[idx] ); ++idx; } // this is how to send a command to asterisk //printf("S,demo-congrats\n"); //fflush(stdout); //create socket int sock; sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (sock < 0) { printf("Unable to create a socket: %s\n", strerror(errno)); return 1; } // read events and transmit while (NULL != fgets(in, 1, stdin)) { if (in[0]>0) { syslog(LOG_ERR, in); if (sendto(fd, in, 1, 0, &si_other, slen)==-1) die("sendto()"); in[0]=0; } usleep(10000); } // Function exit return(EXIT_SUCCESS); // return function status } // end of main() // (end of mfe.c)