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