blob: 9c23af59baa6c285ec54d8b8e569b04b416615f5
1 | #include <stdlib.h> |
2 | #include <stdio.h> |
3 | #include <stdarg.h> |
4 | #include <string.h> |
5 | |
6 | #include <sys/types.h> |
7 | #include <errno.h> |
8 | |
9 | #include <unistd.h> |
10 | |
11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> |
13 | |
14 | #include <sys/un.h> |
15 | #include <netwrapper.h> |
16 | |
17 | #include "pppoe_status.h" |
18 | |
19 | static char pppd_connect_cmd[512]; |
20 | static char pppoe_plugin_cmd[] = {"'pppoe -p " _ROOT_PATH "/etc/ppp/pppoe.pid" " -I eth0 -T 80 -U -m 1412'" }; |
21 | static char pppd_options[] = {"debug logfd 1 noipdefault noauth default-asyncmap defaultroute nodetach mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp lcp-echo-interval 20 lcp-echo-failure 3"}; |
22 | |
23 | static int usage() |
24 | { |
25 | fprintf(stderr,"ppp_cli connect <user> <pwd>\n"); |
26 | fprintf(stderr,"ppp_cli disconnect\n"); |
27 | |
28 | return -1; |
29 | } |
30 | |
31 | |
32 | int main(int argc, char *argv[]) |
33 | { |
34 | int i; |
35 | struct netwrapper_ctrl * ctrl; |
36 | |
37 | if (argc < 2 || (0 != strcmp( "connect", argv[1]) && |
38 | 0 != strcmp( "disconnect", argv[1]) )) { |
39 | usage(); |
40 | return -2; |
41 | } |
42 | |
43 | ctrl = netwrapper_ctrl_open(_ROOT_PATH "/etc/ppp/pppcli", PPPOE_WRAPPER_SERVER_PATH); |
44 | if (ctrl == NULL) { |
45 | printf("Failed to connect to pppd\n"); |
46 | return -1; |
47 | } |
48 | |
49 | if (0 == strcmp( "connect", argv[1])) { |
50 | sprintf(pppd_connect_cmd, "pppd pty %s %s user %s password %s &", |
51 | pppoe_plugin_cmd, pppd_options, argv[2], argv[3] ); |
52 | |
53 | } |
54 | else if (0 == strcmp( "disconnect", argv[1])) { |
55 | sprintf(pppd_connect_cmd, "ppp-stop"); |
56 | } |
57 | |
58 | |
59 | netwrapper_ctrl_request(ctrl, pppd_connect_cmd, strlen(pppd_connect_cmd)); |
60 | |
61 | netwrapper_ctrl_close(ctrl); |
62 | exit(0); |
63 | } |
64 |