From 3fff4c49c8de500a6355e012c7246890368b2cb7 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Thu, 13 May 2010 10:31:32 -0700 Subject: ppp: implement ppp_packet_new --- gatchat/ppp_net.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'gatchat/ppp_net.c') diff --git a/gatchat/ppp_net.c b/gatchat/ppp_net.c index bd1a60ee..a74c06ce 100644 --- a/gatchat/ppp_net.c +++ b/gatchat/ppp_net.c @@ -46,6 +46,7 @@ struct ppp_net { GIOChannel *channel; gint watch; gint mtu; + struct ppp_header *ppp_packet; }; gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu) @@ -95,23 +96,21 @@ static gboolean ppp_net_callback(GIOChannel *channel, GIOCondition cond, { struct ppp_net *net = (struct ppp_net *) userdata; GIOStatus status; - gchar buf[MAX_PACKET + sizeof(struct ppp_header)]; gsize bytes_read; GError *error = NULL; - struct ppp_header *ppp = (struct ppp_header *) buf; + gchar *buf = (gchar *) net->ppp_packet->info; if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) return FALSE; if (cond & G_IO_IN) { /* leave space to add PPP protocol field */ - status = g_io_channel_read_chars(channel, - buf + sizeof(struct ppp_header), net->mtu, - &bytes_read, &error); - if (bytes_read > 0) { - ppp->proto = htons(PPP_IP_PROTO); - ppp_transmit(net->ppp, (guint8 *) buf, bytes_read); - } + status = g_io_channel_read_chars(channel, buf, net->mtu, + &bytes_read, &error); + if (bytes_read > 0) + ppp_transmit(net->ppp, (guint8 *) net->ppp_packet, + bytes_read); + if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) return FALSE; } @@ -135,6 +134,12 @@ struct ppp_net *ppp_net_new(GAtPPP *ppp) if (net == NULL) return NULL; + net->ppp_packet = ppp_packet_new(MAX_PACKET, PPP_IP_PROTO); + if (net->ppp_packet == NULL) { + g_free(net); + return NULL; + } + /* open a tun interface */ fd = open("/dev/net/tun", O_RDWR); if (fd < 0) @@ -176,6 +181,8 @@ error: if (fd >= 0) close(fd); + g_free(net->if_name); + g_free(net->ppp_packet); g_free(net); return NULL; } @@ -185,6 +192,7 @@ void ppp_net_free(struct ppp_net *net) g_source_remove(net->watch); g_io_channel_unref(net->channel); + g_free(net->ppp_packet); g_free(net->if_name); g_free(net); } -- cgit v1.2.3