changeset 14:e4d98cbf95eb

packet: add get value semantics
author Brett Gordon
date Tue, 13 Dec 2016 11:26:37 -0500
parents 7702bb8a8216
children 7231f922b0f2
files src/lwwire-packet.c
diffstat 1 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwwire-packet.c	Tue Nov 22 17:27:59 2016 -0500
+++ b/src/lwwire-packet.c	Tue Dec 13 11:26:37 2016 -0500
@@ -155,10 +155,20 @@
 /* set/return receive mtu */
 static int tun_proto_setrxmtu()
 {
+    unsigned int val;
     unsigned char buf[2];
     if (lwwire_read(buf, 2) < 0)
 	return -1;
-    rxmtu = (buf[0]<<8) + buf[1];
+    val = (buf[0] << 8) + buf[1];
+    if (val)
+    {
+	rxmtu = val;
+    }
+    else
+    {
+	buf[0] = rxmtu >> 8;
+	buf[1] = rxmtu & 255;
+    }
     lwwire_write(buf, 2);
     return 0;
 }
@@ -166,21 +176,38 @@
 /* set/return transmit mtu */
 static int tun_proto_settxmtu()
 {
+    unsigned int val;
     unsigned char buf[2];
     if (lwwire_read(buf, 2) < 0)
 	return -1;
-    txmtu = (buf[0]<<8) + buf[1];
+    val = (buf[0] << 8) + buf[1];
+    if (val)
+    {
+	txmtu = val;
+    }
+    else
+    {
+	buf[0] = txmtu >> 8;
+	buf[1] = txmtu & 255;
+    }
     lwwire_write(buf, 2);
     return 0;
 }
 
-/* set/return receive mtu */
+/* set/return queue length */
 static int tun_proto_setqlen()
 {
     unsigned char buf[1];
     if (lwwire_read(buf, 1) < 0)
 	return -1;
-    qlen = buf[0];
+    if (buf[0])
+    {
+	qlen = buf[0];
+    }
+    else
+    {
+	buf[0] = qlen;
+    }
     lwwire_write(buf, 1);
     return 0;
 }