updates. New data types.
[silc.git] / lib / silccore / silcpacket.c
index 3112f15830a6da0c35cd1ea141de8c8145140484..9895fa25915b47b38ae7624109eb7eded3097284 100644 (file)
@@ -109,10 +109,10 @@ int silc_packet_send(SilcSocketConnection sock, int force_send)
    cannot be used. */
 
 void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, 
-                        SilcBuffer buffer, unsigned int len)
+                        SilcBuffer buffer, uint32 len)
 {
   unsigned char mac[32];
-  unsigned int mac_len;
+  uint32 mac_len;
 
   /* Compute HMAC. This assumes that HMAC is created from the entire
      data area thus this uses the length found in buffer, not the length
@@ -243,9 +243,9 @@ void silc_packet_assemble(SilcPacketContext *ctx)
    outgoing buffer in SilcSocketConnection object. */
 
 void silc_packet_send_prepare(SilcSocketConnection sock,
-                             unsigned int header_len,
-                             unsigned int padlen,
-                             unsigned int data_len)
+                             uint32 header_len,
+                             uint32 padlen,
+                             uint32 data_len)
 {
   int totlen, oldlen;
 
@@ -316,7 +316,7 @@ int silc_packet_read(int sock, SilcBuffer dest)
       SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
       return -2;
     }
-    SILC_LOG_ERROR(("Cannot read from socket: %d", strerror(errno)));
+    SILC_LOG_ERROR(("Cannot read from socket: %d:%s", sock, strerror(errno)));
     return -1;
   }
 
@@ -390,6 +390,7 @@ void silc_packet_receive_process(SilcSocketConnection sock,
 
     if (packetlen < SILC_PACKET_MIN_LEN) {
       SILC_LOG_DEBUG(("Received invalid packet, dropped"));
+      silc_buffer_clear(sock->inbuf);
       return;
     }
 
@@ -427,6 +428,7 @@ void silc_packet_receive_process(SilcSocketConnection sock,
       silc_buffer_pull(sock->inbuf, mac_len);
   }
 
+  SILC_LOG_DEBUG(("Clearing inbound buffer"));
   silc_buffer_clear(sock->inbuf);
 }
 
@@ -466,7 +468,7 @@ static int silc_packet_check_mac(SilcHmac hmac, SilcBuffer buffer)
   /* Check MAC */
   if (hmac) {
     unsigned char mac[32];
-    unsigned int mac_len;
+    uint32 mac_len;
     
     SILC_LOG_DEBUG(("Verifying MAC"));
 
@@ -535,7 +537,7 @@ static int silc_packet_decrypt_rest_special(SilcCipher cipher,
 {
   /* Decrypt rest of the header plus padding */
   if (cipher) {
-    unsigned short truelen, len1, len2, padlen;
+    uint16 truelen, len1, len2, padlen;
 
     /* Pull MAC from packet before decryption */
     if (hmac) {