ppp.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <ip.h>
  12. #include <bio.h>
  13. #include <ndb.h>
  14. #include "../dhcp.h"
  15. #include "ipconfig.h"
  16. void
  17. pppbinddev(void)
  18. {
  19. int ac, pid;
  20. char *av[12];
  21. Waitmsg *w;
  22. /* ppp does the binding */
  23. /* start with an empty config file */
  24. if(nip == 0)
  25. writendb("", 0, 0);
  26. switch(pid = rfork(RFPROC|RFFDG|RFMEM)){
  27. case -1:
  28. sysfatal("can't start ppp: %r");
  29. case 0:
  30. ac = 0;
  31. av[ac++] = "ppp";
  32. av[ac++] = "-uf";
  33. av[ac++] = "-p";
  34. av[ac++] = conf.dev;
  35. av[ac++] = "-x";
  36. av[ac++] = conf.mpoint;
  37. if(conf.baud != nil){
  38. av[ac++] = "-b";
  39. av[ac++] = conf.baud;
  40. }
  41. av[ac] = nil;
  42. exec("/bin/ip/ppp", av);
  43. exec("/ppp", av);
  44. sysfatal("execing /ppp: %r");
  45. }
  46. /* wait for ppp to finish connecting and configuring */
  47. while((w = wait()) != nil){
  48. if(w->pid == pid){
  49. if(w->msg[0] != 0)
  50. sysfatal("/ppp exited with status: %s", w->msg);
  51. free(w);
  52. break;
  53. }
  54. free(w);
  55. }
  56. if(w == nil)
  57. sysfatal("/ppp disappeared");
  58. /* ppp sets up the configuration itself */
  59. noconfig = 1;
  60. getndb();
  61. }