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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
//
// 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 <syslog.h>
#define PORT 5000
#define IP "10.10.10.2"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
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)
|