SilcBuffer buffer = ctx->buffer;
SilcUInt8 tmp;
int len, ret;
+ SilcUInt8 src_id_len, src_id_type, dst_id_len, dst_id_type, padlen;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SILC_STR_UI_SHORT(&ctx->truelen),
SILC_STR_UI_CHAR(&ctx->flags),
SILC_STR_UI_CHAR(&ctx->type),
- SILC_STR_UI_CHAR(&ctx->padlen),
+ SILC_STR_UI_CHAR(&padlen),
SILC_STR_UI_CHAR(&tmp),
- SILC_STR_UI_CHAR(&ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_len),
- SILC_STR_UI_CHAR(&ctx->src_id_type),
+ SILC_STR_UI_CHAR(&src_id_len),
+ SILC_STR_UI_CHAR(&dst_id_len),
+ SILC_STR_UI_CHAR(&src_id_type),
SILC_STR_END);
if (len == -1 || tmp != 0)
return SILC_PACKET_NONE;
- if (ctx->src_id_len > SILC_PACKET_MAX_ID_LEN ||
- ctx->dst_id_len > SILC_PACKET_MAX_ID_LEN) {
+ if (src_id_len > SILC_PACKET_MAX_ID_LEN ||
+ dst_id_len > SILC_PACKET_MAX_ID_LEN) {
SILC_LOG_ERROR(("Bad ID lengths in packet (%d and %d)",
- ctx->src_id_len, ctx->dst_id_len));
+ src_id_len, dst_id_len));
return SILC_PACKET_NONE;
}
silc_buffer_pull(buffer, len);
ret = silc_buffer_unformat(buffer,
SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
- ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_type),
+ src_id_len),
+ SILC_STR_UI_CHAR(&dst_id_type),
SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
- ctx->dst_id_len),
- SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
+ dst_id_len),
+ SILC_STR_UI_XNSTRING(NULL, padlen),
SILC_STR_END);
if (ret == -1)
return SILC_PACKET_NONE;
+ if (src_id_type > SILC_ID_CHANNEL || dst_id_type > SILC_ID_CHANNEL) {
+ SILC_LOG_ERROR(("Bad ID types in packet (%d and %d",
+ src_id_type, dst_id_type));
+ return SILC_PACKET_NONE;
+ }
+
+ ctx->src_id_len = src_id_len;
+ ctx->dst_id_len = dst_id_len;
+ ctx->src_id_type = src_id_type;
+ ctx->dst_id_type = dst_id_type;
+ ctx->padlen = padlen;
+
silc_buffer_push(buffer, len);
SILC_LOG_HEXDUMP(("parsed packet, len %d", ctx->buffer->len),
SilcBuffer buffer = ctx->buffer;
SilcUInt8 tmp;
int len, ret;
+ SilcUInt8 src_id_len, src_id_type, dst_id_len, dst_id_type, padlen;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SILC_STR_UI_SHORT(&ctx->truelen),
SILC_STR_UI_CHAR(&ctx->flags),
SILC_STR_UI_CHAR(&ctx->type),
- SILC_STR_UI_CHAR(&ctx->padlen),
+ SILC_STR_UI_CHAR(&padlen),
SILC_STR_UI_CHAR(&tmp),
- SILC_STR_UI_CHAR(&ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_len),
- SILC_STR_UI_CHAR(&ctx->src_id_type),
+ SILC_STR_UI_CHAR(&src_id_len),
+ SILC_STR_UI_CHAR(&dst_id_len),
+ SILC_STR_UI_CHAR(&src_id_type),
SILC_STR_END);
if (len == -1 || tmp != 0) {
SILC_LOG_ERROR(("Malformed packet header, packet dropped"));
return SILC_PACKET_NONE;
}
- if (ctx->src_id_len > SILC_PACKET_MAX_ID_LEN ||
- ctx->dst_id_len > SILC_PACKET_MAX_ID_LEN) {
+ if (src_id_len > SILC_PACKET_MAX_ID_LEN ||
+ dst_id_len > SILC_PACKET_MAX_ID_LEN) {
SILC_LOG_ERROR(("Bad ID lengths in packet (%d and %d)",
- ctx->src_id_len, ctx->dst_id_len));
+ src_id_len, dst_id_len));
return SILC_PACKET_NONE;
}
silc_buffer_pull(buffer, len);
ret = silc_buffer_unformat(buffer,
SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
- ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_type),
+ src_id_len),
+ SILC_STR_UI_CHAR(&dst_id_type),
SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
- ctx->dst_id_len),
- SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
+ dst_id_len),
+ SILC_STR_UI_XNSTRING(NULL, padlen),
SILC_STR_END);
if (ret == -1) {
SILC_LOG_ERROR(("Malformed packet header, packet dropped"));
return SILC_PACKET_NONE;
}
+ if (src_id_type > SILC_ID_CHANNEL || dst_id_type > SILC_ID_CHANNEL) {
+ SILC_LOG_ERROR(("Bad ID types in packet (%d and %d",
+ src_id_type, dst_id_type));
+ return SILC_PACKET_NONE;
+ }
+
+ ctx->src_id_len = src_id_len;
+ ctx->dst_id_len = dst_id_len;
+ ctx->src_id_type = src_id_type;
+ ctx->dst_id_type = dst_id_type;
+ ctx->padlen = padlen;
+
silc_buffer_push(buffer, len);
SILC_LOG_HEXDUMP(("parsed packet, len %d", ctx->buffer->len),
*
* unsigned char *src_id
* SilcUInt8 src_id_len
- * unsigned char src_id_type
+ * SilcUInt8 src_id_type
*
* Source ID, its length and type. On packet reception retuned ID's
* are always the hash values of the ID's from the packet.
*
* unsigned char *dst_id;
* SilcUInt8 dst_id_len;
- * unsigned char src_id_type;
+ * SilcUInt8 src_id_type;
*
* Destination ID, its length and type. On packet reception retuned
* ID's are always the hash values of the ID's from the packet.
*
- * SilcUInt8 padlen
- *
- * The padded length of the packet. This may be set by the caller
- * before calling any of the silc_packet_* routines. If not provided
- * the library will calculate the values.
- *
- * unsigned int long_pad
+ * bool long_pad
*
* If set to TRUE the packet will include the maximum padding allowed
* in SILC packet, which is 128 bytes. If FALSE only the amount of
* padding needed will be applied.
*
- * unsigned int users;
+ * SilcUInt16 users;
*
* Reference counter for this context. The context is freed only
* after the reference counter hits zero. The counter is added
* calling silc_packet_context_dup and decreased by calling the
* silc_packet_context_free.
*
+ * SilcUInt8 padlen
+ *
+ * The padded length of the packet. This may be set by the caller
+ * before calling any of the silc_packet_* routines. If not provided
+ * the library will calculate the values.
+ *
* SilcUInt32 sequence;
*
- * Packet sequence number.
+ * Packet sequence number. Set only when this context is a parsed
+ * packet.
*
* SilcBuffer buffer
*
- * The actual packet data.
+ * The actual packet data. Set only when this context is a parsed
+ * packet.
*
***/
typedef struct {
unsigned char *src_id;
unsigned char *dst_id;
- SilcUInt8 src_id_len;
- SilcUInt8 src_id_type;
- SilcUInt8 dst_id_len;
- SilcUInt8 dst_id_type;
-
- SilcUInt8 padlen;
- unsigned int long_pad : 1; /* Set when maximum padding in packet */
- unsigned int users : 23; /* Reference counter */
+ unsigned int src_id_len : 5;
+ unsigned int src_id_type : 2;
+ unsigned int dst_id_len : 5;
+ unsigned int dst_id_type : 2;
+ unsigned int long_pad : 1; /* Set when maximum padding in packet */
+ unsigned int users : 9; /* Reference counter */
+ unsigned int padlen : 8;
SilcUInt32 sequence;
SilcBuffer buffer;