Exemplo n.º 1
0
size_t
packerMAC::unpackMyHdr(unsigned char *buf, size_t offset, Packet *p)
{

	// Pointer to the MAC packet header
	hdr_mac *hmac = HDR_MAC(p);

	int field_idx = 0;

	memset(&(hmac->ftype_), 0, sizeof(hmac->ftype_));
	offset += get(buf, offset, &(hmac->ftype_), n_bits[field_idx++]);

	memset(&(hmac->macSA_), 0, sizeof(hmac->macSA_));
	offset += get(buf, offset, &(hmac->macSA_), n_bits[field_idx++]);
	hmac->macSA_ = restoreSignedValue(hmac->macSA_, n_bits[field_idx - 1]);

	memset(&(hmac->macDA_), 0, sizeof(hmac->macDA_));
	offset += get(buf, offset, &(hmac->macDA_), n_bits[field_idx++]);
	hmac->macDA_ = restoreSignedValue(hmac->macDA_, n_bits[field_idx - 1]);

	/* Old function to uncompresso signed value
	if (n_bits[field_idx - 1] < sizeof(hmac->macDA()) * 8) { // Compression!
		bitset<sizeof(hmac->macDA()) * 8 > my_bitset(hmac->macDA());
		if (my_bitset[n_bits[field_idx - 1] - 1] == 1) {
			for (int i = n_bits[field_idx - 1]; i < sizeof(hmac->macDA()) * 8;
	++i) {
				my_bitset.set(i,1);
			}
		}
		hmac->macDA() = static_cast<int>(my_bitset.to_ulong());
	}
	 */

	memset(&(hmac->hdr_type_), 0, sizeof(hmac->hdr_type_));
	offset += get(buf, offset, &(hmac->hdr_type_), n_bits[field_idx++]);

	memset(&(hmac->txtime_), 0, sizeof(hmac->txtime_));
	offset += get(buf, offset, &(hmac->txtime_), n_bits[field_idx++]);

	memset(&(hmac->sstime_), 0, sizeof(hmac->sstime_));
	offset += get(buf, offset, &(hmac->sstime_), n_bits[field_idx++]);

	memset(&(hmac->padding_), 0, sizeof(hmac->padding_));
	offset += get(buf, offset, &(hmac->padding_), n_bits[field_idx++]);
	hmac->padding_ = restoreSignedValue(hmac->padding_, n_bits[field_idx - 1]);

	if (debug_) {
		printf("\033[0;45;30m RX MAC packer hdr \033[0m \n");
		printMyHdrFields(p);
	}

	return offset;
}
Exemplo n.º 2
0
size_t packerCOMMON::unpackMyHdr(unsigned char* buf, size_t offset, Packet* p) {
    // Pointer to the COMMON packet header
    hdr_cmn* ch = HDR_CMN(p);

    // Common header fields useful for DESERT
    if (n_bits[PTYPE]){
        memset(&(ch->ptype_), 0, sizeof (ch->ptype_));
        offset += get(buf, offset, &(ch->ptype_), n_bits[PTYPE]);
    }

    if (n_bits[SIZE]){
	   memset(&(ch->size_), 0, sizeof (ch->size_));
	   offset += get(buf, offset, &(ch->size_), n_bits[SIZE]);
	   ch->size_ = restoreSignedValue(ch->size_, n_bits[SIZE]);
    }
	
    if(n_bits[UID]){
        memset(&(ch->uid_), 0, sizeof (ch->uid_));
        offset += get(buf, offset, &(ch->uid_), n_bits[UID]);
        ch->uid_ = restoreSignedValue(ch->uid_, n_bits[UID]);
    }
    
    if(n_bits[ERROR]){
        memset(&(ch->error_), 0, sizeof (ch->error_));
        offset += get(buf, offset, &(ch->error_), n_bits[ERROR]);
        ch->error_ = restoreSignedValue(ch->error_, n_bits[ERROR]);
    }

    if(n_bits[TIMESTAMP]){
        memset(&(ch->ts_), 0, sizeof (ch->ts_));
        offset += get(buf, offset, &(ch->ts_), n_bits[TIMESTAMP]);
    }

    if(n_bits[DIRECTION]){
        memset(&(ch->direction_), 0, sizeof (ch->direction_));
        offset += get(buf, offset, &(ch->direction_), n_bits[DIRECTION]);
        ch->direction_ = restoreSignedValue(ch->direction_, n_bits[DIRECTION]);   
    }
    
    if(n_bits[PREV_HOP]){
        memset(&(ch->prev_hop_), 0, sizeof (ch->prev_hop_));
        offset += get(buf, offset, &(ch->prev_hop_), n_bits[PREV_HOP]);
        ch->prev_hop_ = restoreSignedValue(ch->prev_hop_, n_bits[PREV_HOP]);
    }

    if(n_bits[NEXT_HOP]){
        memset(&(ch->next_hop_), 0, sizeof (ch->next_hop_));
        offset += get(buf, offset, &(ch->next_hop_), n_bits[NEXT_HOP]);
        ch->next_hop_ = restoreSignedValue(ch->next_hop_, n_bits[NEXT_HOP]);
    }

    if(n_bits[ADDR_TYPE]){
        memset(&(ch->addr_type_), 0, sizeof (ch->addr_type_));
        offset += get(buf, offset, &(ch->addr_type_), n_bits[ADDR_TYPE]);
        ch->addr_type_ = restoreSignedValue(ch->addr_type_, n_bits[ADDR_TYPE]);
    }
    
    if(n_bits[LAST_HOP]){
        memset(&(ch->last_hop_), 0, sizeof (ch->last_hop_));
        offset += get(buf, offset, &(ch->last_hop_), n_bits[LAST_HOP]);
        ch->last_hop_ = restoreSignedValue(ch->last_hop_, n_bits[LAST_HOP]);
    }
    
    if(n_bits[TXTIME]){
        memset(&(ch->txtime_), 0, sizeof (ch->txtime_));
        offset += get(buf, offset, &(ch->txtime_), n_bits[TXTIME]);
    }

    // Other common header fields (maybe useful for future usage)	
    memset(&(ch->errbitcnt_), 0, sizeof (ch->errbitcnt_));
    offset += get(buf, offset, &(ch->errbitcnt_), n_bits[errbitcnt_]);
    ch->errbitcnt_ = restoreSignedValue(ch->errbitcnt_, n_bits[errbitcnt_]);

    memset(&(ch->fecsize_), 0, sizeof (ch->fecsize_));
    offset += get(buf, offset, &(ch->fecsize_), n_bits[fecsize_]);
    ch->fecsize_ = restoreSignedValue(ch->fecsize_, n_bits[fecsize_]);

    memset(&(ch->iface_), 0, sizeof (ch->iface_));
    offset += get(buf, offset, &(ch->iface_), n_bits[iface_]);
    ch->iface_ = restoreSignedValue(ch->iface_, n_bits[iface_]);

    memset(&(ch->src_rt_valid), 0, sizeof (ch->src_rt_valid));
    offset += get(buf, offset, &(ch->src_rt_valid), n_bits[src_rt_valid]);

    memset(&(ch->ts_arr_), 0, sizeof (ch->ts_arr_));
    offset += get(buf, offset, &(ch->ts_arr_), n_bits[ts_arr_]);

    memset(&(ch->aomdv_salvage_count_), 0, sizeof (ch->aomdv_salvage_count_));
    offset += get(buf, offset, &(ch->aomdv_salvage_count_), n_bits[aomdv_salvage_count_]);
    ch->aomdv_salvage_count_ = restoreSignedValue(ch->aomdv_salvage_count_, n_bits[aomdv_salvage_count_]);

    memset(&(ch->xmit_failure_), 0, sizeof (ch->xmit_failure_));
    offset += get(buf, offset, &(ch->xmit_failure_), n_bits[xmit_failure_]);

    memset(&(ch->xmit_failure_data_), 0, sizeof (ch->xmit_failure_data_));
    offset += get(buf, offset, &(ch->xmit_failure_data_), n_bits[xmit_failure_data_]);

    memset(&(ch->xmit_reason_), 0, sizeof (ch->xmit_reason_));
    offset += get(buf, offset, &(ch->xmit_reason_), n_bits[xmit_reason_]);
    ch->xmit_reason_ = restoreSignedValue(ch->xmit_reason_, n_bits[xmit_reason_]);

    memset(&(ch->num_forwards_), 0, sizeof (ch->num_forwards_));
    offset += get(buf, offset, &(ch->num_forwards_), n_bits[num_forwards_]);

    memset(&(ch->opt_num_forwards_), 0, sizeof (ch->opt_num_forwards_));
    offset += get(buf, offset, &(ch->opt_num_forwards_), n_bits[opt_num_forwards_]);

    if (debug_) {
        printf("\033[0;43;30m RX COMMON packer hdr \033[0m \n");
        printMyHdrFields(p);
    }

    return offset;
}