Blob


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