aboutsummaryrefslogtreecommitdiff
path: root/src/libventi/srvhello.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-11-23 18:19:58 +0000
committerrsc <devnull@localhost>2003-11-23 18:19:58 +0000
commit056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b (patch)
tree9ad42f31c3bc124cf6617cf9eb41dd525eccce83 /src/libventi/srvhello.c
parent9df487d720a59bf8cb0dc4ccffc30ad8eb48256a (diff)
downloadplan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.gz
plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.bz2
plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.zip
new venti library.
Diffstat (limited to 'src/libventi/srvhello.c')
-rw-r--r--src/libventi/srvhello.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libventi/srvhello.c b/src/libventi/srvhello.c
new file mode 100644
index 00000000..20aedbee
--- /dev/null
+++ b/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 0;
+
+ if(vtfcallunpack(&tx, p) < 0){
+ packetfree(p);
+ return 0;
+ }
+ packetfree(p);
+
+ if(tx.type != VtThello){
+ vtfcallclear(&tx);
+ werrstr("bad packet type %d; want Thello %d", tx.type, VtThello);
+ return 0;
+ }
+ if(tx.tag != 0){
+ vtfcallclear(&tx);
+ werrstr("bad tag in hello");
+ return 0;
+ }
+ if(strcmp(tx.version, z->version) != 0){
+ vtfcallclear(&tx);
+ werrstr("bad version in hello");
+ return 0;
+ }
+ 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)
+ return 0;
+ if(vtsend(z, p) < 0)
+ return 0;
+
+ return 1;
+}