You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  1. //
  2. // "$Id: connect.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
  3. //
  4. // PPP example program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Program to make a button to turn a ppp connection on/off.
  7. // You must chmod +s /usr/sbin/pppd, and put all the options
  8. // into /etc/ppp/options.
  9. //
  10. // Copyright 1998-2010 by Bill Spitzak and others.
  11. //
  12. // This library is free software; you can redistribute it and/or
  13. // modify it under the terms of the GNU Library General Public
  14. // License as published by the Free Software Foundation; either
  15. // version 2 of the License, or (at your option) any later version.
  16. //
  17. // This library is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. // Library General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Library General Public
  23. // License along with this library; if not, write to the Free Software
  24. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  25. // USA.
  26. //
  27. // Please report all bugs and problems on the following page:
  28. //
  29. // http://www.fltk.org/str.php
  30. //
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <unistd.h>
  34. #include <signal.h>
  35. #include <sys/wait.h>
  36. #include <FL/Fl.H>
  37. #include <FL/Fl_Window.H>
  38. #include <FL/Fl_Toggle_Button.H>
  39. int running; // actually the pid
  40. Fl_Toggle_Button *Button;
  41. void sigchld(int) {
  42. waitpid(running, 0, 0);
  43. running = 0;
  44. Button->value(0);
  45. }
  46. void cb(Fl_Widget *o, void *) {
  47. if (((Fl_Toggle_Button*)o)->value()) {
  48. if (running) return;
  49. running = fork();
  50. if (!running) execl("/usr/sbin/pppd","pppd","-detach",0);
  51. else signal(SIGCHLD, sigchld);
  52. } else {
  53. if (!running) return;
  54. kill(running, SIGINT);
  55. waitpid(running, 0, 0);
  56. running = 0;
  57. }
  58. }
  59. int main(int argc, char ** argv) {
  60. Fl_Window window(100,50);
  61. Fl_Toggle_Button button(0,0,100,50,"Connect");
  62. Button = &button;
  63. button.color(1,2);
  64. button.callback(cb,0);
  65. window.show(argc,argv);
  66. return Fl::run();
  67. }
  68. //
  69. // End of "$Id: connect.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $".
  70. //