aboutsummaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-02-16 13:35:24 +0000
committerrodri <rgl@antares-labs.eu>2023-02-16 13:35:24 +0000
commitfd5dc301e4a69d7b7c1293aafe5b069b4ff400a4 (patch)
treef9d51305517fe6a5bd0167522be82a0dcc28b38c /net.c
parent62e75d8830eb56ab03bd4689d51ffd6d4150f461 (diff)
downloadmusw-fd5dc301e4a69d7b7c1293aafe5b069b4ff400a4.tar.gz
musw-fd5dc301e4a69d7b7c1293aafe5b069b4ff400a4.tar.bz2
musw-fd5dc301e4a69d7b7c1293aafe5b069b4ff400a4.zip
implemented a keep alive mechanism.
also changed the newframe fn to take a Udphdr* instead of a Frame*. the verifyframe fn now returns 1 if correct 0 otherwise.
Diffstat (limited to 'net.c')
-rw-r--r--net.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/net.c b/net.c
index 12c2c5b..58542ba 100644
--- a/net.c
+++ b/net.c
@@ -66,23 +66,18 @@ delnetconn(NetConn *nc)
/* Frame */
Frame *
-newframe(Frame *pf, u8int type, u32int seq, u32int ack, u16int len, uchar *data)
+newframe(Udphdr *hdr, u8int type, u32int seq, u32int ack, u16int len, uchar *data)
{
Frame *f;
f = emalloc(sizeof(Frame)+len);
memset(f, 0, sizeof(Frame));
+ if(hdr != nil)
+ memmove(&f->udp, hdr, Udphdrsize);
f->id = ProtocolID;
f->type = type;
- if(pf != nil){
- memmove(&f->udp, &pf->udp, Udphdrsize);
- f->seq = pf->seq+1;
- f->ack = pf->seq;
- }else{
- memset(&f->udp, 0, Udphdrsize);
- f->seq = seq;
- f->ack = ack;
- }
+ f->seq = seq;
+ f->ack = ack;
f->len = len;
if(data != nil)
memmove(f->data, data, f->len);
@@ -120,8 +115,7 @@ verifyframe(Frame *f, ulong key)
memset(f->sig, 0, MD5dlen);
n = pack(msg, sizeof msg, "f", f);
hmac_md5(msg, n, k, sizeof k, h1, nil);
- memmove(f->sig, h0, MD5dlen);
- return memcmp(h0, h1, MD5dlen);
+ return memcmp(h0, h1, MD5dlen) == 0;
}
void