Annotation of embedtools/src/dwds.c, revision 1.1.2.5
1.1.2.1 misho 1: #include "global.h"
2: #include "dwds.h"
3:
4:
1.1.2.4 misho 5: sl_config cfg;
6: int Verbose, Kill, nif;
7: char **ifs, szConfig[MAXPATHLEN] = DWDS_CONFIG;
1.1.2.2 misho 8: extern char compiled[], compiledby[], compilehost[];
9:
10:
11: static void
12: Usage()
13: {
1.1.2.3 misho 14: printf( "-= dWDS =- WiFi dynamic WDS service managment for VAP\n"
1.1.2.2 misho 15: "=== %s === %s@%s ===\n\n"
1.1.2.3 misho 16: " Syntax: dwds [options] <interface|any> [interface [...]]\n"
1.1.2.2 misho 17: "\n"
18: "\t-v\t\tVerbose ...\n"
19: "\t-f\t\tForeground, not demonize process ...\n"
20: "\t-c <config>\tConfig file [default=/etc/dwds.conf]\n"
21: "\n", compiled, compiledby, compilehost);
22: }
23:
1.1.2.4 misho 24: static void
25: sigHandler(int sig)
26: {
27: int stat;
28: const u_char *v;
29: char szStr[STRSIZ];
30:
31: switch (sig) {
32: case SIGHUP:
33: UnloadConfig(&cfg);
34: if (LoadConfig(szConfig, &cfg)) {
35: printf("Error:: can`t load config %s ...\n", szConfig);
36: Kill++;
37: } else {
38: closelog();
39:
40: cfg_LoadAttribute(&cfg, CFG("dwds"), CFG("name"), CFG(szStr), STRSIZ, DWDS_NAME);
41: openlog(szStr, LOG_PID | LOG_CONS, LOG_DAEMON);
42: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("syslog_upto"));
43: setlogmask(v ? strtol((char*) v, NULL, 0) : 0);
44: }
45: break;
46: case SIGTERM:
47: Kill++;
48: break;
49: case SIGCHLD:
50: while (waitpid(-1, &stat, WNOHANG) > 0);
51: break;
52: }
53: }
54:
55: static int
56: RtMsg(struct rt_msghdr *msg, size_t len)
57: {
1.1.2.5 ! misho 58: struct dwds_if *wds = NULL;
! 59:
1.1.2.4 misho 60: return 0;
61: }
62:
1.1.2.2 misho 63: // ---------------------------------------------------------------
64:
1.1.2.1 misho 65: int
66: main(int argc, char **argv)
67: {
1.1.2.4 misho 68: char ch, szStr[STRSIZ], fg = 0;
69: const u_char *v, msg[2048];
70: int s;
71: struct sigaction sa;
72: size_t len;
1.1.2.2 misho 73:
1.1.2.3 misho 74: while ((ch = getopt(argc, argv, "hvfc:")) != -1)
75: switch (ch) {
76: case 'v':
77: Verbose++;
78: break;
79: case 'f':
80: fg = 1;
81: break;
82: case 'c':
83: strlcpy(szConfig, optarg, MAXPATHLEN);
84: break;
85: case 'h':
86: default:
87: Usage();
88: return 1;
89: }
90: argc -= optind;
91: argv += optind;
92: if (!argc) {
93: printf("Error:: not specified interface for use ...\n");
94: Usage();
95: return 1;
1.1.2.4 misho 96: } else {
97: nif = argc;
98: ifs = argv;
99: }
100: if (LoadConfig(szConfig, &cfg)) {
101: printf("Error:: can`t load config %s ...\n", szConfig);
102: return 1;
103: }
104:
105: if (fg)
106: switch (fork()) {
107: case -1:
108: printf("Error:: when fork() #%d - %s\n", errno, strerror(errno));
109: UnloadConfig(&cfg);
110: return 2;
111: case 0 :
112: VERB(1) printf("Going to shadow land ...\n");
113:
114: setsid();
115:
116: memset(&sa, 0, sizeof sa);
117: sa.sa_handler = sigHandler;
118: sigemptyset(&sa.sa_mask);
119: sigaction(SIGHUP, &sa, NULL);
120: sigaction(SIGTERM, &sa, NULL);
121: sigaction(SIGCHLD, &sa, NULL);
122: break;
123: default:
124: goto end;
125: }
126:
127: cfg_LoadAttribute(&cfg, CFG("dwds"), CFG("name"), CFG(szStr), STRSIZ, DWDS_NAME);
128: openlog(szStr, LOG_PID | LOG_CONS, LOG_DAEMON);
129: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("syslog_upto"));
130: setlogmask(v ? strtol((char*) v, NULL, 0) : 0);
131:
132: s = socket(PF_ROUTE, SOCK_RAW, 0);
133: if (s == -1) {
134: syslog(LOG_ERR, "Error:: socket() #%d - %s\n", errno, strerror(errno));
135: goto end;
136: }
137:
138: while (!Kill) {
139: len = read(s, (void*) msg, sizeof msg);
140: if (len == -1) {
141: syslog(LOG_ERR, "Error:: read() #%d - %s\n", errno, strerror(errno));
142: Kill++;
143: } else
144: RtMsg((struct rt_msghdr*) msg, len);
1.1.2.3 misho 145: }
146:
1.1.2.4 misho 147: close(s);
148: end:
149: closelog();
150: UnloadConfig(&cfg);
1.1.2.1 misho 151: return 0;
152: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>