static int deserialize_hello(struct hello_message *hello, const void *ser) { const unsigned char *curr, *limit; uint8_t type; uint16_t size; struct ipaddr_str buf; memset (hello, 0, sizeof(*hello)); curr = ser; pkt_get_u8(&curr, &type); if (type != HELLO_MESSAGE && type != LQ_HELLO_MESSAGE) { /* No need to do anything more */ return 1; } pkt_get_reltime(&curr, &hello->vtime); pkt_get_u16(&curr, &size); pkt_get_ipaddress(&curr, &hello->source_addr); pkt_get_u8(&curr, &hello->ttl); pkt_get_u8(&curr, &hello->hop_count); pkt_get_u16(&curr, &hello->packet_seq_number); pkt_ignore_u16(&curr); pkt_get_reltime(&curr, &hello->htime); pkt_get_u8(&curr, &hello->willingness); hello->neighbors = NULL; limit = ((const unsigned char *)ser) + size; while (curr < limit) { const unsigned char *limit2 = curr; uint8_t link_code; uint16_t size2; pkt_get_u8(&curr, &link_code); pkt_ignore_u8(&curr); pkt_get_u16(&curr, &size2); limit2 += size2; while (curr < limit2) { struct hello_neighbor *neigh = olsr_malloc_hello_neighbor("HELLO deserialization"); pkt_get_ipaddress(&curr, &neigh->address); if (type == LQ_HELLO_MESSAGE) { olsr_deserialize_hello_lq_pair(&curr, neigh); } neigh->link = EXTRACT_LINK(link_code); neigh->status = EXTRACT_STATUS(link_code); neigh->next = hello->neighbors; hello->neighbors = neigh; } } return 0; }
static void lq_etxfloat_deserialize_tc_lq(uint8_t const **curr, struct tc_edge_entry *edge) { struct lq_etxfloat_tc_edge *lq_edge = (struct lq_etxfloat_tc_edge *)edge; uint8_t lq_value, nlq_value; pkt_get_u8(curr, &lq_value); pkt_get_u8(curr, &nlq_value); pkt_ignore_u16(curr); lq_edge->lq.valueLq = (float)lq_value / 255.0; lq_edge->lq.valueNlq = (float)nlq_value / 255.0; }
static void lq_etxfloat_deserialize_hello_lq(uint8_t const **curr, struct lq_hello_neighbor *neigh) { struct lq_etxfloat_lq_hello_neighbor *lq_neigh = (struct lq_etxfloat_lq_hello_neighbor *)neigh; uint8_t lq_value, nlq_value; pkt_get_u8(curr, &lq_value); pkt_get_u8(curr, &nlq_value); pkt_ignore_u16(curr); lq_neigh->lq.valueLq = (float)lq_value / 255.0; lq_neigh->lq.valueNlq = (float)nlq_value / 255.0; }
static int receive_ack(void) { uint64 seq; if (!receive_packet(ACK1, 8+8+AUTH_LENGTH, 8+8+AUTH_LENGTH)) return 0; pkt_get_u8(&rpacket, 8, &seq); if (seq != seq_last) { debugf(DEBUG_PACKET, "{Received wrong ACK sequence #}llu{ sent #}llu", seq, seq_last); return 0; } if (!pkt_validate(&rpacket, &msg_authenticator)) { debug1(DEBUG_PACKET, "Received ACK failed validation"); return 0; } debugf(DEBUG_PACKET, "{Received ACK packet #}llu", seq); buffer->pop(); seq_last = 0; return 1; }