diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libventi/srvhello.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libventi/srvhello.c')
-rwxr-xr-x | sys/src/libventi/srvhello.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/src/libventi/srvhello.c b/sys/src/libventi/srvhello.c new file mode 100755 index 000000000..ca34221e6 --- /dev/null +++ b/sys/src/libventi/srvhello.c @@ -0,0 +1,50 @@ +#include <u.h> +#include <libc.h> +#include <venti.h> + +int +vtsrvhello(VtConn *z) +{ + VtFcall tx, rx; + Packet *p; + + if((p = vtrecv(z)) == nil) + return -1; + + if(vtfcallunpack(&tx, p) < 0){ + packetfree(p); + return -1; + } + packetfree(p); + + if(tx.msgtype != VtThello){ + vtfcallclear(&tx); + werrstr("bad packet type %d; want Thello %d", tx.msgtype, VtThello); + return -1; + } + if(tx.tag != 0){ + vtfcallclear(&tx); + werrstr("bad tag in hello"); + return -1; + } + if(strcmp(tx.version, z->version) != 0){ + vtfcallclear(&tx); + werrstr("bad version in hello"); + return -1; + } + vtfree(z->uid); + z->uid = tx.uid; + tx.uid = nil; + vtfcallclear(&tx); + + memset(&rx, 0, sizeof rx); + rx.msgtype = VtRhello; + rx.tag = tx.tag; + rx.sid = "anonymous"; + if((p = vtfcallpack(&rx)) == nil) + return -1; + if(vtsend(z, p) < 0) + return -1; + + return 0; +} |