comparison src/lwwire-packet.c @ 14:e4d98cbf95eb

packet: add get value semantics
author Brett Gordon
date Tue, 13 Dec 2016 11:26:37 -0500
parents f8226a33698d
children
comparison
equal deleted inserted replaced
13:7702bb8a8216 14:e4d98cbf95eb
153 153
154 154
155 /* set/return receive mtu */ 155 /* set/return receive mtu */
156 static int tun_proto_setrxmtu() 156 static int tun_proto_setrxmtu()
157 { 157 {
158 unsigned int val;
158 unsigned char buf[2]; 159 unsigned char buf[2];
159 if (lwwire_read(buf, 2) < 0) 160 if (lwwire_read(buf, 2) < 0)
160 return -1; 161 return -1;
161 rxmtu = (buf[0]<<8) + buf[1]; 162 val = (buf[0] << 8) + buf[1];
163 if (val)
164 {
165 rxmtu = val;
166 }
167 else
168 {
169 buf[0] = rxmtu >> 8;
170 buf[1] = rxmtu & 255;
171 }
162 lwwire_write(buf, 2); 172 lwwire_write(buf, 2);
163 return 0; 173 return 0;
164 } 174 }
165 175
166 /* set/return transmit mtu */ 176 /* set/return transmit mtu */
167 static int tun_proto_settxmtu() 177 static int tun_proto_settxmtu()
168 { 178 {
179 unsigned int val;
169 unsigned char buf[2]; 180 unsigned char buf[2];
170 if (lwwire_read(buf, 2) < 0) 181 if (lwwire_read(buf, 2) < 0)
171 return -1; 182 return -1;
172 txmtu = (buf[0]<<8) + buf[1]; 183 val = (buf[0] << 8) + buf[1];
184 if (val)
185 {
186 txmtu = val;
187 }
188 else
189 {
190 buf[0] = txmtu >> 8;
191 buf[1] = txmtu & 255;
192 }
173 lwwire_write(buf, 2); 193 lwwire_write(buf, 2);
174 return 0; 194 return 0;
175 } 195 }
176 196
177 /* set/return receive mtu */ 197 /* set/return queue length */
178 static int tun_proto_setqlen() 198 static int tun_proto_setqlen()
179 { 199 {
180 unsigned char buf[1]; 200 unsigned char buf[1];
181 if (lwwire_read(buf, 1) < 0) 201 if (lwwire_read(buf, 1) < 0)
182 return -1; 202 return -1;
183 qlen = buf[0]; 203 if (buf[0])
204 {
205 qlen = buf[0];
206 }
207 else
208 {
209 buf[0] = qlen;
210 }
184 lwwire_write(buf, 1); 211 lwwire_write(buf, 1);
185 return 0; 212 return 0;
186 } 213 }
187 214
188 215