Fix handling of strict-aliasing rules
[framework/connectivity/connman.git] / scripts / pppd-plugin.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29
30 #include <pppd/pppd.h>
31 #include <pppd/fsm.h>
32 #include <pppd/ipcp.h>
33
34 static void notifier_phasechange(void *data, int arg)
35 {
36         printf("phasechange: data %p arg %d\n", data, arg);
37 }
38
39 static void notifier_exit(void *data, int arg)
40 {
41         printf("exitnotify: data %p arg %d\n", data, arg);
42 }
43
44 static void notifier_ipup(void *data, int arg)
45 {
46         ipcp_options opts = ipcp_gotoptions[0];
47         ipcp_options peer = ipcp_hisoptions[0];
48         struct in_addr ouraddr, hisaddr;
49
50         printf("ipup: data %p arg %d\n", data, arg);
51
52         memcpy(&ouraddr, &opts.ouraddr, sizeof(ouraddr));
53         memcpy(&hisaddr, &peer.hisaddr, sizeof(hisaddr));
54
55         printf("%s: %s -> %s\n",
56                         ifname, inet_ntoa(ouraddr), inet_ntoa(hisaddr));
57
58         script_unsetenv("USEPEERDNS");
59         script_unsetenv("DNS1");
60         script_unsetenv("DNS2");
61 }
62
63 static void notifier_ipdown(void *data, int arg)
64 {
65         printf("ipdown: data %p arg %d\n", data, arg);
66 }
67
68 char pppd_version[] = VERSION;
69
70 int plugin_init(void);
71
72 int plugin_init(void)
73 {
74 #if 0
75         path_ipup[0] = '\0';
76         path_ipdown[0] = '\0';
77 #endif
78
79         add_notifier(&phasechange, notifier_phasechange, NULL);
80         add_notifier(&exitnotify, notifier_exit, NULL);
81
82         add_notifier(&ip_up_notifier, notifier_ipup, NULL);
83         add_notifier(&ip_down_notifier, notifier_ipdown, NULL);
84
85         return 0;
86 }