srvhello.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <venti.h>
  12. int
  13. vtsrvhello(VtConn *z)
  14. {
  15. VtFcall tx, rx;
  16. Packet *p;
  17. if((p = vtrecv(z)) == nil)
  18. return -1;
  19. if(vtfcallunpack(&tx, p) < 0){
  20. packetfree(p);
  21. return -1;
  22. }
  23. packetfree(p);
  24. if(tx.msgtype != VtThello){
  25. vtfcallclear(&tx);
  26. werrstr("bad packet type %d; want Thello %d", tx.msgtype, VtThello);
  27. return -1;
  28. }
  29. if(tx.tag != 0){
  30. vtfcallclear(&tx);
  31. werrstr("bad tag in hello");
  32. return -1;
  33. }
  34. if(strcmp(tx.version, z->version) != 0){
  35. vtfcallclear(&tx);
  36. werrstr("bad version in hello");
  37. return -1;
  38. }
  39. vtfree(z->uid);
  40. z->uid = tx.uid;
  41. tx.uid = nil;
  42. vtfcallclear(&tx);
  43. memset(&rx, 0, sizeof rx);
  44. rx.msgtype = VtRhello;
  45. rx.tag = tx.tag;
  46. rx.sid = "anonymous";
  47. if((p = vtfcallpack(&rx)) == nil)
  48. return -1;
  49. if(vtsend(z, p) < 0)
  50. return -1;
  51. return 0;
  52. }