3
3
* PPP library with GLib integration
5
* Copyright (C) 2009-2010 Intel Corporation. All rights reserved.
5
* Copyright (C) 2009-2011 Intel Corporation. All rights reserved.
7
7
* This program is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License version 2 as
80
void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet)
80
void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet,
83
84
gsize bytes_written;
86
90
/* find the length of the packet to transmit */
87
91
len = get_host_short(&packet[2]);
88
92
status = g_io_channel_write_chars(net->channel, (gchar *) packet,
89
len, &bytes_written, NULL);
94
&bytes_written, NULL);
96
if (status != G_IO_STATUS_NORMAL)
123
131
return net->if_name;
126
struct ppp_net *ppp_net_new(GAtPPP *ppp)
134
struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd)
128
136
struct ppp_net *net;
129
137
GIOChannel *channel = NULL;
130
138
struct ifreq ifr;
133
141
net = g_try_new0(struct ppp_net, 1);
137
145
net->ppp_packet = ppp_packet_new(MAX_PACKET, PPP_IP_PROTO);
138
if (net->ppp_packet == NULL) {
146
if (net->ppp_packet == NULL)
150
* If the fd value is still the default one,
151
* open the tun interface and configure it.
153
memset(&ifr, 0, sizeof(ifr));
156
/* open a tun interface */
157
fd = open("/dev/net/tun", O_RDWR);
161
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
162
strcpy(ifr.ifr_name, "ppp%d");
164
err = ioctl(fd, TUNSETIFF, (void *) &ifr);
168
err = ioctl(fd, TUNGETIFF, (void *) &ifr);
143
/* open a tun interface */
144
fd = open("/dev/net/tun", O_RDWR);
148
memset(&ifr, 0, sizeof(ifr));
149
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
150
strcpy(ifr.ifr_name, "ppp%d");
152
err = ioctl(fd, TUNSETIFF, (void *) &ifr);
156
173
net->if_name = strdup(ifr.ifr_name);
158
175
/* create a channel for reading and writing to this interface */
179
196
g_io_channel_unref(channel);
198
g_free(net->if_name);
199
g_free(net->ppp_packet);
184
g_free(net->if_name);
185
g_free(net->ppp_packet);
190
209
void ppp_net_free(struct ppp_net *net)
212
g_source_remove(net->watch);
216
g_io_channel_unref(net->channel);
218
g_free(net->ppp_packet);
219
g_free(net->if_name);
223
void ppp_net_suspend_interface(struct ppp_net *net)
225
if (net == NULL || net->channel == NULL)
192
231
g_source_remove(net->watch);
193
g_io_channel_unref(net->channel);
195
g_free(net->ppp_packet);
196
g_free(net->if_name);
235
void ppp_net_resume_interface(struct ppp_net *net)
237
if (net == NULL || net->channel == NULL)
240
net->watch = g_io_add_watch(net->channel,
241
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
242
ppp_net_callback, net);