ppp.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <ip.h>
  4. #include <bio.h>
  5. #include <ndb.h>
  6. #include "../dhcp.h"
  7. #include "ipconfig.h"
  8. void
  9. pppbinddev(void)
  10. {
  11. int ac, pid;
  12. char *av[12];
  13. Waitmsg *w;
  14. /* ppp does the binding */
  15. /* start with an empty config file */
  16. if(nip == 0)
  17. writendb("", 0, 0);
  18. switch(pid = rfork(RFPROC|RFFDG|RFMEM)){
  19. case -1:
  20. sysfatal("can't start ppp: %r");
  21. case 0:
  22. ac = 0;
  23. av[ac++] = "ppp";
  24. av[ac++] = "-uf";
  25. av[ac++] = "-p";
  26. av[ac++] = conf.dev;
  27. av[ac++] = "-x";
  28. av[ac++] = conf.mpoint;
  29. if(conf.baud != nil){
  30. av[ac++] = "-b";
  31. av[ac++] = conf.baud;
  32. }
  33. av[ac] = nil;
  34. exec("/bin/ip/ppp", av);
  35. exec("/ppp", av);
  36. sysfatal("execing /ppp: %r");
  37. }
  38. /* wait for ppp to finish connecting and configuring */
  39. while((w = wait()) != nil){
  40. if(w->pid == pid){
  41. if(w->msg[0] != 0)
  42. sysfatal("/ppp exited with status: %s", w->msg);
  43. free(w);
  44. break;
  45. }
  46. free(w);
  47. }
  48. if(w == nil)
  49. sysfatal("/ppp disappeared");
  50. /* ppp sets up the configuration itself */
  51. noconfig = 1;
  52. getndb();
  53. }