3 YAWMPPP - PPP dock app/helper for WindowMaker
4 Copyright (C) 2000,2001:
6 Author: Felipe Bergo (bergo@seul.org)
8 based on the wmppp application by
10 Martijn Pieterse (pieterse@xs4all.nl)
11 Antoine Nulle (warp@xs4all.nl)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 $Id: ycommon.c,v 1.1.1.1 2001/02/22 07:15:59 bergo Exp $
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/ioctl.h>
45 #include <sys/socket.h>
48 #define _LINUX_SOCKET_H
51 /* guessworks for critters beyond the realm of Linux and FreeBSD */
66 #include <asm/types.h>
68 #include <linux/ppp_defs.h>
69 #include <linux/if_ppp.h>
74 #include <net/ppp_defs.h>
75 #include <net/if_ppp.h>
82 extern struct LogStruct logconn
;
87 extern struct YAWMPPP_ISP_INFO IspData
[MAX_ISPS
];
89 extern int current_isp
;
91 extern char *active_interface
;
93 /* LOGS = ~/.yawmppp2/log */
99 char temp
[128],aux
[128];
104 strcat (temp
, "/.yawmppp2/.floatlog");
107 return; /* fine: no crash file */
108 if (!fgets(aux
,128,f
)) return;
109 if ((p
=strtok(aux
,"\n"))==NULL
) return;
110 logconn
.start
=atoi(p
);
111 if (!fgets(aux
,128,f
)) return;
112 if ((p
=strtok(aux
,"\n"))==NULL
) return;
114 if (!fgets(aux
,128,f
)) return;
115 if ((p
=strtok(aux
,"\n"))==NULL
) return;
116 logconn
.status
=atoi(p
);
117 if (!fgets(aux
,128,f
)) return;
118 if ((p
=strtok(aux
,"\n"))==NULL
) return;
119 strcpy(logconn
.longname
,p
);
120 if (!fgets(aux
,128,f
)) return;
121 if ((p
=strtok(aux
,"\n"))==NULL
) return;
122 strcpy(logconn
.shortname
,p
);
123 if (!fgets(aux
,128,f
)) return;
124 if ((p
=strtok(aux
,"\n"))==NULL
) return;
125 strcpy(logconn
.phone
,p
);
126 if (!fgets(aux
,128,f
)) return;
127 if ((p
=strtok(aux
,"\n"))==NULL
) return;
128 strcpy(logconn
.user
,p
);
130 logconn
.status
=2; /* CRASH */
143 strcat (temp
, "/.yawmppp2/.floatlog");
147 logconn
.end
=time(NULL
);
148 fprintf(f
,"%lu\n%lu\n%d\n",logconn
.start
,logconn
.end
,logconn
.status
);
149 fprintf(f
,"%s\n%s\n%s\n",logconn
.longname
,logconn
.shortname
,logconn
.phone
);
150 fprintf(f
,"%s\n",logconn
.user
);
164 strcat (temp
, "/.yawmppp2/logfile");
168 s
=strlen(logconn
.phone
);
170 if (logconn
.phone
[i
]=='\t')
171 logconn
.phone
[i
]=' ';
172 s
=strlen(logconn
.shortname
);
174 if (logconn
.shortname
[i
]=='\t')
175 logconn
.shortname
[i
]=' ';
176 s
=strlen(logconn
.longname
);
178 if (logconn
.longname
[i
]=='\t')
179 logconn
.longname
[i
]=' ';
180 s
=strlen(logconn
.user
);
182 if (logconn
.user
[i
]=='\t')
185 fprintf(f
,"%lu\t%lu\t%d\t%s\t%s\t%s\t%s\n",
199 strcat (temp
, "/.yawmppp2/.floatlog");
213 strcat (temp
, "/.yawmppp2/.delayedupdate");
217 fprintf(f
,"This file shouldn't last more than a few millisecs...\n");
226 /* Open the ppp device. */
231 if ((ppp_h
= socket (AF_INET
, SOCK_DGRAM
, 0)) >= 0)
255 strcat (temp
, "/.yawmppp2/yawmppp.pid");
259 fprintf(f
,"%d",getpid());
265 remove_pid_file(void)
272 strcat (temp
, "/.yawmppp2/yawmppp.pid");
278 make_config_dir(void)
283 sprintf(tmp
,"%s/.yawmppp2",getenv("HOME"));
291 grab_isp_info(int rof
)
298 strcat (temp
, "/.yawmppp2/yawmppprc");
300 num_isps
=GetISPInfo(temp
,&IspData
[0],MAX_ISPS
);
302 if ((!num_isps
)&&(rof
)) {
311 execlp("yawmppp.pref","yawmppp.pref",NULL
);
312 execlp("/usr/local/bin/yawmppp.pref","yawmppp.pref",NULL
);
313 execlp("/usr/bin/yawmppp.pref","yawmppp.pref",NULL
);
322 execlp("yawmppp.log","yawmppp.log",NULL
);
323 execlp("/usr/local/bin/yawmppp.log","yawmppp.log",NULL
);
324 execlp("/usr/bin/yawmppp.log","yawmppp.log",NULL
);
335 get_statistics (char *devname
, long *ip
, long *op
, long *is
, long *os
)
338 struct ifpppstatsreq req
;
339 struct ppp_stats ppp_cur
;
341 memset (&ppp_cur
, 0, sizeof (ppp_cur
));
347 memset(&req
,0,sizeof(req
));
350 req
.stats_ptr
=(caddr_t
) & req
.stats
;
351 strcpy(req
.ifr__name
, active_interface
);
355 strcpy(req
.ifr_name
, active_interface
);
358 if (ioctl(ppp_h
,SIOCGPPPSTATS
,&req
) >= 0)
361 *op
= ppp_cur
.p
.ppp_opackets
;
362 *ip
= ppp_cur
.p
.ppp_ipackets
;
363 *is
= ppp_cur
.p
.ppp_ibytes
;
364 *os
= ppp_cur
.p
.ppp_obytes
;
372 stillonline (char *ifs
)
385 fp
= fopen ("/proc/net/route", "r");
388 while (fgets (temp
, 128, fp
))
390 if (strstr (temp
, ifs
))
392 i
= 1; /* Line is alive */
400 strcpy(req
.ifr_name
,active_interface
);
404 if (ioctl(ppp_h
,SIOCGIFFLAGS
,&req
)>=0) {
405 if (req
.ifr_flags
&IFF_UP
)