summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-28 18:42:40 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-28 18:42:40 +0000
commitf90bdf34ce94392fbf705c1ab23fb986bfdec16f (patch)
tree1dfcc9e65c786e9b59010f66170115ad4fcd16c0
parentadded cipher (net tested yet) (diff)
added forgotten set functions to packets
-rw-r--r--src/encrypted_packet.c6
-rw-r--r--src/plain_packet.c10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/encrypted_packet.c b/src/encrypted_packet.c
index 0f76589..176241b 100644
--- a/src/encrypted_packet.c
+++ b/src/encrypted_packet.c
@@ -96,7 +96,13 @@ u_int32_t encrypted_packet_get_payload_length(encrypted_packet_t* packet)
void encrypted_packet_set_payload_length(encrypted_packet_t* packet, u_int32_t len)
{
+ if(!packet)
+ return;
+ if(len > ENCRYPTED_PACKET_SIZE_MAX || (len + sizeof(encrypted_packet_header_t)) > ENCRYPTED_PACKET_SIZE_MAX)
+ len = ENCRYPTED_PACKET_SIZE_MAX - sizeof(encrypted_packet_header_t);
+
+ packet->payload_length_ = len;
}
seq_nr_t encrypted_packet_get_seq_nr(encrypted_packet_t* packet)
diff --git a/src/plain_packet.c b/src/plain_packet.c
index 9d31467..69338c1 100644
--- a/src/plain_packet.c
+++ b/src/plain_packet.c
@@ -65,7 +65,17 @@ u_int32_t plain_packet_get_length(plain_packet_t* packet)
void plain_packet_set_length(plain_packet_t* packet, u_int32_t len)
{
+ if(!packet)
+ return;
+ if(len > PLAIN_PACKET_SIZE_MAX)
+ len = PLAIN_PACKET_SIZE_MAX - sizeof(payload_type_t);
+ else if(len < sizeof(payload_type_t))
+ len = 0;
+ else
+ len -= sizeof(payload_type_t);
+
+ packet->payload_length_ = len;
}
u_int8_t* plain_packet_get_payload(plain_packet_t* packet)