Ejemplo n.º 1
0
struct Dict *decode_dict_aux(struct Buffer *nbuf, char **bi) {
    
    // Make sure you haven't hit the end of the buffer
    if (*bi > nbuf->cnt + nbuf->size - 1) {
        fprintf(stderr, "error: decode_dict - ptr beyound end of buffer\n");
        exit(1);
    }
    
    // if this is the end return NULL
    if (**bi == 'e') {
        (*bi)++;
        return NULL;
    }
    
    // Allocate memory for dict
    struct Dict *bdict = (struct Dict *)malloc_eoe(sizeof(struct Dict));
    
    // Set the key
    bdict->key = decode_next(nbuf, bi, &(bdict->key_type));
        
    // if this is the end assign NULL to value, otherwise decode value
    if (**bi == 'e') {
        bdict->value = NULL;
    } else {
        bdict->value = decode_next(nbuf, bi, &(bdict->value_type));
    }
    
    bdict->next = decode_dict_aux(nbuf, bi);
    
    return bdict;
}
Ejemplo n.º 2
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	unsigned int offset=0;
	int value;
	int more = 0;
	LE(value,20); 	printf(" MPLS: Label: %d\n",value);
	LE(value,3); 	printf(" MPLS: Class of service: %d\n",value);
	LE(value,1);	printf(" MPLS: Stack: %s\n",value?"Last" :"More");
	if (value == 0) more = 1;
	LE(value,8);	printf(" MPLS: TTL: %d\n",value);
	
	/* MPLS doesn't say what it's encapsulating, so we make an educated
	 * guess and pray.
	 */
	if (more)
		decode_next(packet+offset/8,len-4,"eth",0x8847);
	else if ((*(packet+4)&0xF0) == 0x40)
		decode_next(packet+offset/8,len-4,"eth",0x0800);
	else if ((*(packet+4)&0xF0) == 0x60)
		decode_next(packet+offset/8,len-4,"eth",0x86DD);
	else
		decode_next(packet+offset/8,len-4,"link",1);

	return;
}
Ejemplo n.º 3
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	unsigned int i=0;
	printf(" Ubiquity:");
	for(i=0;i<132; /* Nothing */ ) {
		unsigned int j;
		printf("\n ");
		for(j=0;j<WIDTH;j++) {
			if (i+j<len)
				printf(" %02x",(unsigned char)packet[i+j]);
			else
				printf("   ");
		}
		printf("    ");
		for(j=0;j<WIDTH;j++) {
			if (i+j<len)
				if (isprint((unsigned char)packet[i+j]))
					printf("%c",(unsigned char)packet[i+j]);
				else
					printf(".");
			else
				printf("   ");
		}
		if (i+WIDTH>len)
			break;
		else
			i+=WIDTH;
	}
	printf("\n");
	if (len>132)
		decode_next(packet+132,len-132,"link",4);
	return;
}
Ejemplo n.º 4
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_chdlc_t *frame = (libtrace_chdlc_t *)packet;

	printf(" CHDLC:");
	if (len >= 1)
		printf(" Address: 0x%02x", frame->address);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 2)
		printf(" Control: 0x%02x", frame->control);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 4) {
		printf(" Ethertype: 0x%04x\n", ntohs(frame->ethertype));
		decode_next(packet + 4, len - 4, "eth", 
				ntohs(frame->ethertype));
	}
	else {
		printf("[|Truncated]\n");
		return;
	}
	

	return;
}
Ejemplo n.º 5
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	// Ethernet - just raw ethernet frames
	printf(" Legacy: ");
	if (len>=10) {
		decode_next(packet,len,"link",2);
	}
	else {
		printf("[|Truncated]\n");
		return;
	}
	return;
}
Ejemplo n.º 6
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	struct libtrace_udp *udp = (struct libtrace_udp*)packet;
	printf(" UDP:");
	if (SAFE(udp, source)) {
		struct servent *ent=getservbyport(udp->source,"udp");
		if(ent) {
			printf(" Source %i (%s)",htons(udp->source),ent->s_name);
		} else {
			printf(" Source %i",htons(udp->source));
		}
	}
	else {
		printf("\n");
		return;
	}
	if (SAFE(udp, dest)) {
		struct servent *ent=getservbyport(udp->dest,"udp");
		if(ent) {
			printf(" Dest %i (%s)",htons(udp->dest),ent->s_name);
		} else {
			printf(" Dest %i",htons(udp->dest));
		}
	}
	else {
		printf("\n");
		return;
	}
	printf("\n UDP:");
	DISPLAYS(udp, len," Len %u");
	DISPLAYS(udp, check," Checksum %u");
	printf("\n");
	if (htons(udp->source) < htons(udp->dest)) 
		decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->source));
	else
		decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->dest));
	return;
}
Ejemplo n.º 7
0
DLLEXPORT void decode(int link_type UNUSED, const char *packet, unsigned len) {

	uint16_t hbh_len = 0;
	libtrace_ip6_ext_t* hdr = (libtrace_ip6_ext_t*)packet;

	hbh_len = (hdr->len + 1) * 8;

	printf(" IPv6 Hop-by-Hop: Next Header %u Header Ext Len %u",
			hdr->nxt, hdr->len);

	printf("\n");

	decode_next(packet + hbh_len, len - hbh_len, "ip", hdr->nxt);


}
Ejemplo n.º 8
0
struct Bcont *b_decode_aux(struct Buffer *buf, char **bi) {
    if (*bi >= buf->cnt + (buf->size - 2)) {
        return NULL;
    }
    
    // Allocated memory for a struct Bcont
    struct Bcont *bval = (struct Bcont *)malloc_eoe(sizeof(struct Bcont));
    
    // Set the content and the content type
    bval->cnt = decode_next(buf, bi, &(bval->type));
    
    // Set the next bval pointer
    bval->next = b_decode_aux(buf, bi);
    
    return bval;
}
Ejemplo n.º 9
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	// ATM
	printf(" Legacy Framing:");
	if (len>=12) {
		uint16_t type = htons(*(uint16_t*)(packet+sizeof(libtrace_atm_cell_t)+4));
		printf(" %04x\n",type);
		decode_next(packet+sizeof(libtrace_atm_cell_t) + 4,
				len-sizeof(libtrace_atm_cell_t) -4, 
				"eth",type);
	}
	else {
		printf("[|Truncated]\n");
		return;
	}
	return;
}
Ejemplo n.º 10
0
DLLEXPORT void decode(int link_type UNUSED, const char *packet, unsigned len) {

	uint16_t hbh_len = 0;
	libtrace_ip6_ext_t* hdr = (libtrace_ip6_ext_t*)packet;

	hbh_len = (hdr->len + 1) * 8;

	printf(" IPv6 Routing Header: Next Header %u Header Ext Len %u",
			hdr->nxt, hdr->len);
	printf("\n IPv6 Routing Header: Routing Type %u Segments Left %u",
			*packet, *(packet + 1));		
	printf("\n");

	decode_next(packet + hbh_len, len - hbh_len, "ip", hdr->nxt);


}
Ejemplo n.º 11
0
struct List *decode_list_aux(struct Buffer *nbuf, char **bi) {
    // Make sure you haven't hit the end of the buffer
    if (*bi > nbuf->cnt + nbuf->size - 1) {
        fprintf(stderr, "error: decode_list - ptr beyound end of buffer\n");
        exit(1);
    }
    
    // if this is the end return NULL
    if (**bi == 'e') {
        (*bi)++;
        return NULL;
    }
    
    struct List *blist = (struct List *)malloc_eoe(sizeof(struct List));
    
    blist->cnt = decode_next(nbuf, bi, &(blist->type));
    
    blist->next = decode_list_aux(nbuf, bi);
    
    return blist;
}
Ejemplo n.º 12
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_hdlc_t *frame = (libtrace_hdlc_t *)packet;

	printf(" PPP:");
	if (len >= 1)
		printf(" Address: 0x%02x", frame->address);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 2)
		printf(" Control: 0x%02x", frame->control);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 4) {
		printf(" Protocol: 0x%04x\n", ntohs(frame->protocol));
		
		/* PPP protocols do not match ethertypes, so we have to
		 * convert
		 *
		 * XXX develop decoders for PPP protocols so this can be
		 * done generically 
		 */
		if (ntohs(frame->protocol) == 0x0021) {
			decode_next(packet + 4, len - 4, "eth", 0x0800);
		} 
	}
	else {
		printf("[|Truncated]\n");
		return;
	}
	

	return;
}
Ejemplo n.º 13
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_ip_t *ip = (libtrace_ip_t*)packet;
	if (len>=1) {
		printf(" IP: Header Len %i",ip->ip_hl*4);
		printf(" Ver %i",ip->ip_v);
	}
	//DISPLAY(ip_tos," TOS %02x")
	DISPLAY_EXP(ip_tos," DSCP %02x",ip->ip_tos >> 2)
	DISPLAY_EXP(ip_tos," ECN %x",ip->ip_tos & 0x2)
	DISPLAYS(ip_len," Total Length %i")
	printf("\n IP:");
	DISPLAYS(ip_id," Id %u");
	
	if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
		printf(" Fragoff %i", ntohs(ip->ip_off) & 0x1FFF);
		if (ntohs(ip->ip_off) & 0x2000) printf(" MORE_FRAG");
		if (ntohs(ip->ip_off) & 0x4000) printf(" DONT_FRAG");
		if (ntohs(ip->ip_off) & 0x8000) printf(" RESV_FRAG");
	}
	//printf("\n IP:");
	DISPLAY(ip_ttl,"\n IP: TTL %i");
	if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
		struct protoent *ent=getprotobynumber(ip->ip_p);
		if (ent) {
			printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
		}
		else {
			printf(" Proto %i",ip->ip_p);
		}
	} else {
		printf("\n");
		return;
	}
	DISPLAYS(ip_sum," Checksum %i\n");
	DISPLAYIP(ip_src," IP: Source %s ");
	DISPLAYIP(ip_dst,"Destination %s\n");
	decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p);
	return;
}
Ejemplo n.º 14
0
Archivo: stream.c Proyecto: EQ4/musicd
static int encode_next(stream_t *stream)
{
  int result, got_packet;
  AVFrame *frame = stream->encode_frame;
  AVPacket *packet = &stream->encode_packet;

  while (av_audio_fifo_size(stream->src_buf) < stream->encoder->frame_size) {
    result = decode_next(stream);
    if (result <= 0) {
      return result;
    }
  }

  av_audio_fifo_read(stream->src_buf,
                     (void **)frame->extended_data,
                     stream->encoder->frame_size);

  av_free_packet(packet);

  result = avcodec_encode_audio2(stream->encoder, packet, frame, &got_packet);

  if (result < 0) {
    musicd_log(LOG_ERROR, "stream", "can't encode: %s",
               strerror(AVUNERROR(result)));
    return -1;
  }

  if (!got_packet) {
    return 1;
  }

  stream->dst_data = packet->data;
  stream->dst_size = packet->size;

  return 1;
}
Ejemplo n.º 15
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_ip6_t *ip = (libtrace_ip6_t*)packet;
	
	uint32_t tmp = ntohl(*(uint32_t*)ip);

	printf(" IPv6: Version %u\n", (tmp >> 28) & 0x000000f);
	printf(" IPv6: Class %u\n", (tmp >> 20) & 0x000000ff);
	printf(" IPv6: Flow Label %u\n", tmp & 0x000fffff);
	printf(" IPv6: Payload Length %u\n", ntohs(ip->plen));
	printf(" IPv6: Next Header %u\n", ip->nxt);
	printf(" IPv6: Hop Limit %u\n", ip->hlim);


	char ipstr[INET6_ADDRSTRLEN];                             
	inet_ntop(AF_INET6, &(ip->ip_src), ipstr, INET6_ADDRSTRLEN);

	printf(" IPv6: Source IP %s\n", ipstr);
	inet_ntop(AF_INET6, &(ip->ip_dst), ipstr, INET6_ADDRSTRLEN);
	printf(" IPv6: Destination IP %s\n", ipstr);

	decode_next(packet+sizeof(libtrace_ip6_t),len-sizeof(libtrace_ip6_t),"ip",ip->nxt);
	return;
}
Ejemplo n.º 16
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	uint32_t *ptr; 
	uint8_t *p; /* Our current field "cursor" */
	uint8_t *s; /* Start of data fields, for alignment */
	struct libtrace_radiotap_t *rtap;
	uint16_t rtap_len;
	uint32_t rtap_pres;
	uint16_t rtap_real_len; /* to make sure length in header matches fields present */
	rtap = (libtrace_radiotap_t *)packet;
	
	printf(" Radiotap:");

	if (len < 8) {
		printf(" [|Truncated (%u bytes)]\n", len);
		return;
	}
	
	rtap_real_len = sizeof(struct libtrace_radiotap_t);
	rtap_len = bswap_le_to_host16(rtap->it_len);
	rtap_pres = bswap_le_to_host32(rtap->it_present);

	printf(" version: %u, length: %u, fields: %#08x\n", rtap->it_version,
			rtap_len, rtap_pres);
	
	/* Check for extended bitmasks */
	ptr = (uint32_t *) &(rtap->it_present);
	
	if ( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) ) 
		printf("  extended fields:");
	
	while( (bswap_le_to_host32(*ptr)) & (1 << TRACE_RADIOTAP_EXT) ) {
		rtap_real_len += sizeof (uint32_t);
		ptr++;
		printf(" %#08x", bswap_le_to_host32(*ptr));	
	}

        if ( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) )
                printf("\n");

	/* make p point to the first data field */
	s = (uint8_t *) rtap;
        p = (uint8_t *) ++ptr;

	if (rtap_pres & (1 << TRACE_RADIOTAP_TSFT)) {
		ALIGN_NATURAL_64(p,s,rtap_real_len);
		printf(" Radiotap: TSFT = %" PRIu64 " microseconds\n", bswap_le_to_host64(*((uint64_t *)p)));
		p += sizeof (uint64_t);
		rtap_real_len += sizeof (uint64_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_FLAGS)) {
		printf(" Radiotap: Flags = 0x%02x\n", *p);
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	
	if (rtap_pres & (1 << TRACE_RADIOTAP_RATE)) {
		printf(" Radiotap: Rate = %u kbps\n", (*p) * 500);
		p +=  sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}
	
	if (rtap_pres & (1 << TRACE_RADIOTAP_CHANNEL)) {
		ALIGN_NATURAL_16(p,s,rtap_real_len);
		printf(" Radiotap: Freq = %u MHz, ChanFlags: 0x%04x\n", bswap_le_to_host16(*((uint16_t *)p)), 
				*(((uint16_t *)p) + 1));
		p += sizeof (uint32_t);
		rtap_real_len += sizeof(uint32_t);
	}
											
	if (rtap_pres & (1 << TRACE_RADIOTAP_FHSS)) {
		ALIGN_NATURAL_16(p,s, rtap_real_len);
		printf(" Radiotap: FHSS HopSet = %u , HopPattern: %u\n", *p, *(p+1)); 
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}


	if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL)) {
		printf(" Radiotap: Signal = %i dBm\n", (int8_t) *p) ;
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}


	if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTNOISE)) {
		printf(" Radiotap: Noise = %i dBm\n", (int8_t) *p); 
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}


	if (rtap_pres & (1 << TRACE_RADIOTAP_LOCK_QUALITY)) {
		ALIGN_NATURAL_16(p,s, rtap_real_len);
		printf(" Radiotap: Barker Code Lock Quality = %u\n", bswap_le_to_host16(*((uint16_t *)p))); 
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}


	if (rtap_pres & (1 << TRACE_RADIOTAP_TX_ATTENUATION)) {
		ALIGN_NATURAL_16(p,s, rtap_real_len);
		printf(" Radiotap: TX Attenuation = %u\n", bswap_le_to_host16(*((uint16_t *)p))); 
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION)) {
		ALIGN_NATURAL_16(p,s,rtap_real_len);
		printf(" Radiotap: TX Attenuation = %u dB\n", bswap_le_to_host16(*((uint16_t *)p))); 
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_TX_POWER)) {
		printf(" Radiotap: TX Power = %i dBm\n", *p); 
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_ANTENNA)) {
		printf(" Radiotap: Antenna = %u\n", *p); 
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTSIGNAL)) {
		printf(" Radiotap: Signal = %u dB\n", *p); 
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTNOISE)) {
		printf(" Radiotap: Noise = %u dB\n", *p); 
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_RX_FLAGS)) {
		ALIGN_NATURAL_16(p,s,rtap_real_len);
		printf(" Radiotap: RX Flags = 0x%04x\n", *((uint16_t *)p));
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_TX_FLAGS)) {
		ALIGN_NATURAL_16(p,s,rtap_real_len);
		printf(" Radiotap: TX Flags = 0x%04x\n", *((uint16_t *)p));
		p += sizeof (uint16_t);
		rtap_real_len += sizeof(uint16_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_RTS_RETRIES)) {
		printf(" Radiotap: RTS Retries = %u\n", *p);
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_pres & (1 << TRACE_RADIOTAP_DATA_RETRIES)) {
		printf(" Radiotap: Data Retries = %u\n", *p);
		p += sizeof (uint8_t);
		rtap_real_len += sizeof(uint8_t);
	}

	if (rtap_real_len != rtap_len) 
		printf(" Radiotap: WARNING: Header contains un-decoded fields.\n");

	if (len > rtap_len) 
		decode_next(packet + rtap_len, len - rtap_len, "link", TRACE_TYPE_80211);
		
	return;

}