nblistener.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 "headers.h"
  10. static char *hmsg = "headers";
  11. int nbudphdrsize;
  12. char *
  13. nbudpannounce(uint16_t port, int *fdp)
  14. {
  15. int data, ctl;
  16. char dir[64], datafile[64+6], addr[NETPATHLEN];
  17. snprint(addr, sizeof(addr), "udp!*!%d", port);
  18. /* get a udp port */
  19. ctl = announce(addr, dir);
  20. if(ctl < 0)
  21. return "can't announce on port";
  22. snprint(datafile, sizeof(datafile), "%s/data", dir);
  23. /* turn on header style interface */
  24. nbudphdrsize = Udphdrsize;
  25. if (write(ctl, hmsg, strlen(hmsg)) != strlen(hmsg))
  26. return "failed to turn on headers";
  27. data = open(datafile, ORDWR);
  28. if (data < 0) {
  29. close(ctl);
  30. return "failed to open data file";
  31. }
  32. close(ctl);
  33. *fdp = data;
  34. return nil;
  35. }