srvhello.c 833 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <venti.h>
  4. int
  5. vtsrvhello(VtConn *z)
  6. {
  7. VtFcall tx, rx;
  8. Packet *p;
  9. if((p = vtrecv(z)) == nil)
  10. return -1;
  11. if(vtfcallunpack(&tx, p) < 0){
  12. packetfree(p);
  13. return -1;
  14. }
  15. packetfree(p);
  16. if(tx.msgtype != VtThello){
  17. vtfcallclear(&tx);
  18. werrstr("bad packet type %d; want Thello %d", tx.msgtype, VtThello);
  19. return -1;
  20. }
  21. if(tx.tag != 0){
  22. vtfcallclear(&tx);
  23. werrstr("bad tag in hello");
  24. return -1;
  25. }
  26. if(strcmp(tx.version, z->version) != 0){
  27. vtfcallclear(&tx);
  28. werrstr("bad version in hello");
  29. return -1;
  30. }
  31. vtfree(z->uid);
  32. z->uid = tx.uid;
  33. tx.uid = nil;
  34. vtfcallclear(&tx);
  35. memset(&rx, 0, sizeof rx);
  36. rx.msgtype = VtRhello;
  37. rx.tag = tx.tag;
  38. rx.sid = "anonymous";
  39. if((p = vtfcallpack(&rx)) == nil)
  40. return -1;
  41. if(vtsend(z, p) < 0)
  42. return -1;
  43. return 0;
  44. }