- if (sock->inbuf->len - 2 > (paddedlen + mac_len)) {
- /* Received possibly many packets at once */
-
- if (hmac)
- mac_len = hmac->hash->hash->hash_len;
-
- while (sock->inbuf->len > 0) {
- SILC_PACKET_LENGTH(sock->inbuf, packetlen, paddedlen);
-
- if (sock->inbuf->len < paddedlen) {
- /* Two cases: either we haven't read all of the data or this
- packet is malformed. Try to read data from the connection.
- If it fails this packet is malformed. */
- silc_schedule_with_fd(sock->sock, SILC_TASK_READ, 0, 1);
- if (silc_packet_receive(sock) > 0)
- continue;
-
- SILC_LOG_DEBUG(("Received incorrect packet, dropped"));
- return FALSE;
- }
-
- paddedlen += 2;
- parse_ctx = silc_calloc(1, sizeof(*parse_ctx));
- parse_ctx->packet = silc_calloc(1, sizeof(*parse_ctx->packet));
- parse_ctx->packet->buffer = silc_buffer_alloc(paddedlen + mac_len);
- parse_ctx->sock = sock;
- parse_ctx->cipher = cipher;
- parse_ctx->hmac = hmac;
- parse_ctx->context = context;
-
- silc_buffer_pull_tail(parse_ctx->packet->buffer,
- SILC_BUFFER_END(parse_ctx->packet->buffer));
- silc_buffer_put(parse_ctx->packet->buffer, sock->inbuf->data,
- paddedlen + mac_len);
-
- SILC_LOG_HEXDUMP(("Incoming packet, len %d",
- parse_ctx->packet->buffer->len),
- parse_ctx->packet->buffer->data,
- parse_ctx->packet->buffer->len);
-
- /* Call the parser */
- if (parser)
- (*parser)(parse_ctx);
-
- /* Pull the packet from inbuf thus we'll get the next one
- in the inbuf. */
- silc_buffer_pull(sock->inbuf, paddedlen);
- if (hmac)
- silc_buffer_pull(sock->inbuf, mac_len);