7901ef9cb3af51fa9d7c4222d8a38388439ada30
[sip-router] / main.c
1 /*
2  * $Id$
3  */
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <netdb.h>
9
10 #include "config.h"
11 #include "dprint.h"
12 #include "route.h"
13 #include "udp_server.h"
14
15
16
17 /* debuging function */
18 /*
19 void receive_stdin_loop()
20 {
21         #define BSIZE 1024
22         char buf[BSIZE+1];
23         int len;
24         
25         while(1){
26                 len=fread(buf,1,BSIZE,stdin);
27                 buf[len+1]=0;
28                 receive_msg(buf, len);
29                 printf("-------------------------\n");
30         }
31 }
32 */
33
34 #define NAME "0.0.0.0"
35
36
37 int main(int argc, char** argv)
38 {
39
40         char * cfg_file;
41         FILE* cfg_stream;
42         struct hostent* he;
43
44         cfg_file=CFG_FILE;
45         
46         /* process command line (get port no, cfg. file path etc) */
47         /* ...*/
48
49         our_port=SIP_PORT;
50         our_name=NAME;
51         /* get ip */
52         he=gethostbyname(our_name);
53         if (he==0){
54                 DPrint("ERROR: could not resolve %s\n", our_name);
55                 goto error;
56         }
57         our_address=*((long*)he->h_addr_list[0]);
58         printf("Listening on %s[%x]:%d\n",our_name,
59                                 (unsigned long)our_address,
60                                 (unsigned short)our_port);
61                 
62         
63         
64
65         /* load config file or die */
66         cfg_stream=fopen (cfg_file, "r");
67         if (cfg_stream==0){
68                 DPrint("ERROR: could not load config file: %s\n", strerror(errno));
69                 goto error;
70         }
71
72         if (cfg_parse_stream(cfg_stream)!=0){
73                 DPrint("ERROR: config parser failure\n");
74                 goto error;
75         }
76         
77                 
78         print_rl();
79
80
81         /* init_daemon? */
82         if (udp_init(our_address,our_port)==-1) goto error;
83         /* start/init other processes/threads ? */
84
85         /* receive loop */
86         udp_rcv_loop();
87
88
89 error:
90         return -1;
91
92 }