plan9port/src/libventi/srvhello.c

53 lines
877 B
C
Raw Normal View History

2003-11-23 18:19:58 +00:00
#include <u.h>
#include <libc.h>
#include <venti.h>
int
vtsrvhello(VtConn *z)
{
VtFcall tx, rx;
Packet *p;
2004-05-05 04:22:16 +00:00
if((p = vtrecv(z)) == nil){
werrstr("unexpected eof on venti connection");
return -1;
}
2003-11-23 18:19:58 +00:00
if(vtfcallunpack(&tx, p) < 0){
packetfree(p);
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
}
packetfree(p);
if(tx.type != VtThello){
vtfcallclear(&tx);
werrstr("bad packet type %d; want Thello %d", tx.type, VtThello);
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
}
if(tx.tag != 0){
vtfcallclear(&tx);
werrstr("bad tag in hello");
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
}
if(strcmp(tx.version, z->version) != 0){
vtfcallclear(&tx);
werrstr("bad version in hello");
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
}
vtfree(z->uid);
z->uid = tx.uid;
tx.uid = nil;
vtfcallclear(&tx);
memset(&rx, 0, sizeof rx);
rx.type = VtRhello;
rx.tag = tx.tag;
rx.sid = "anonymous";
if((p = vtfcallpack(&rx)) == nil)
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
if(vtsend(z, p) < 0)
2004-05-05 04:22:16 +00:00
return -1;
2003-11-23 18:19:58 +00:00
2004-05-05 04:22:16 +00:00
return 0;
2003-11-23 18:19:58 +00:00
}