netmkaddr.c 863 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <ctype.h>
  4. /*
  5. * make an address, add the defaults
  6. */
  7. char *
  8. netmkaddr(char *linear, char *defnet, char *defsrv)
  9. {
  10. static char addr[256];
  11. char *cp;
  12. /*
  13. * dump network name
  14. */
  15. cp = strchr(linear, '!');
  16. if(cp == 0){
  17. if(defnet==0){
  18. if(defsrv)
  19. snprint(addr, sizeof(addr), "net!%s!%s",
  20. linear, defsrv);
  21. else
  22. snprint(addr, sizeof(addr), "net!%s", linear);
  23. }
  24. else {
  25. if(defsrv)
  26. snprint(addr, sizeof(addr), "%s!%s!%s", defnet,
  27. linear, defsrv);
  28. else
  29. snprint(addr, sizeof(addr), "%s!%s", defnet,
  30. linear);
  31. }
  32. return addr;
  33. }
  34. /*
  35. * if there is already a service, use it
  36. */
  37. cp = strchr(cp+1, '!');
  38. if(cp)
  39. return linear;
  40. /*
  41. * add default service
  42. */
  43. if(defsrv == 0)
  44. return linear;
  45. snprint(addr, sizeof(addr), "%s!%s", linear, defsrv);
  46. return addr;
  47. }