1 /* PPPoE support library "libpppoe"
3 * Copyright 2000 Michal Ostrowski <mostrows@styx.uwaterloo.ca>,
4 * Jamal Hadi Salim <hadi@cyberus.ca>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
16 int build_ppp_opts(char *args[],struct session *ses)
24 if ( NULL != ses->filt->pppd){
25 args[0]=(char *)malloc(strlen(ses->filt->pppd));
26 strcpy (args[0],ses->filt->pppd);
28 args[0]=(char *)malloc(strlen(_PATH_PPPD));
29 strcpy (args[0],_PATH_PPPD);
32 /* long device name */
33 snprintf(buf, 256,"%02x:%02x:%02x:%02x:%02x:%02x/%04x/%s",
34 ses->remote.sll_addr[0],
35 ses->remote.sll_addr[1],
36 ses->remote.sll_addr[2],
37 ses->remote.sll_addr[3],
38 ses->remote.sll_addr[4],
39 ses->remote.sll_addr[5],
40 ses->sp.sa_addr.pppoe.sid,
42 args[1]=(char *)malloc(strlen(buf));
47 /* override options file */
48 if (NULL != ses->filt->fname ) {
50 if (!ses->filt->peermode) {
51 args[i]=(char *)malloc(strlen("file"));
52 strcpy (args[i],"file");
54 args[i]=(char *)malloc(strlen(ses->filt->fname)+1);
55 strcpy (args[i],ses->filt->fname);
57 } else{ /* peermode */
58 args[i]=(char *)malloc(strlen("call"));
59 strcpy (args[i],"call");
61 args[i]=(char *)malloc(strlen(ses->filt->fname)+1);
62 strcpy (args[i],ses->filt->fname);
67 /* user requested for a specific name */
68 if (NULL != ses->filt->ntag) {
69 if ( NULL != ses->filt->ntag->tag_data) {
70 args[i]=(char *)malloc(strlen("pppoe_ac_name"));
71 strcpy(args[i],"pppoe_ac_name");
73 args[i]=(char *)malloc(ntohs(ses->filt->ntag->tag_len));
74 strcpy(args[i],ses->filt->ntag->tag_data);
78 /* user requested for a specific service name */
79 if (NULL != ses->filt->stag) {
80 if ( NULL != ses->filt->stag->tag_data) {
81 args[i]=(char *)malloc(strlen("pppoe_srv_name"));
82 strcpy(args[i],"pppoe_srv_name");
84 args[i]=(char *)malloc(ntohs(ses->filt->stag->tag_len));
85 strcpy(args[i],ses->filt->stag->tag_data);
92 if (ses->opt_daemonize) {
93 args[i]=(char *)malloc(strlen("nodetach"));
94 strcpy(args[i],"nodetach");
101 poe_info(ses,"calling pppd with %d args\n",i);
103 for (i=0; i<j,NULL !=args[i]; i++) {
104 poe_info(ses," <%d: %s > \n",i,args[i]);
114 int ppp_connect (struct session *ses)
120 poe_info(ses,"calling ses_connect\n");
122 ret = session_connect(ses);
126 if (ses->np == 1 && ret == 1)
127 return ses->np; /* -G */
129 return ses->np; /* -H */
135 poe_info(ses,"DONE calling ses_connect np is %d \n",ses->np);
140 poe_error (ses,"unable to fork() for pppd: %m");
146 poe_info(ses,"calling build_ppp_opts\n");
147 if (0> build_ppp_opts(args,ses)) {
148 poe_error(ses,"ppp_connect: failed to build ppp_opts\n");
151 execvp(args[0],args);
152 poe_info (ses," child got killed");
153 } else if( ses->type == SESSION_CLIENT) {
154 if (!ses->opt_daemonize)
157 poe_info (ses," OK we got killed");