rohc team mailing list archive
-
rohc team
-
Mailing list archive
-
Message #01793
Re: [Question #255525]: crc creating error and aborting compilation
Question #255525 on rohc changed:
https://answers.launchpad.net/rohc/+question/255525
Status: Needs information => Open
Ashok Kumar gave more information on the question:
Hi,
My program code "mytest.c" is given below:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netinet/if_ether.h>
#include<net/ethernet.h>
#include<netinet/ip.h>
#include<netinet/udp.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<rohc.h>
#include<rohc_comp.h>
#include<rohc_decomp.h>
#define BUFFER_SIZE 2048
void PrintData(unsigned char* ,int);
static int gen_random_num(const struct rohc_comp *const comp, void *const user_context);
int raw_sock,i,j;
FILE *logfile;
struct sockaddr_in source,dest;
int main(int argc, char **argv)
{
int saddr_size, data_size;
struct sockaddr saddr;
struct in_addr in;
struct rohc_comp *compressor;
struct rohc_decomp *decompressor;
unsigned short iphdrlen;
unsigned int ip_packet_len, rohc_packet_len;
unsigned char BUFFER[BUFFER_SIZE], rohc_packet[BUFFER_SIZE], op_packet[BUFFER_SIZE];
int ret;
printf("\n Creating ROHC compressor......\n\n");
compressor = rohc_alloc_compressor(15,0,0,0);
if(compressor == NULL)
{
fprintf(stderr,"\n Failed creating compressor!!\n");
rohc_free_compressor(compressor);
}
if(!rohc_comp_set_random_cb(compressor, gen_random_num, NULL))
{
fprintf(stderr, "\n Failed to set the compressor callback random numbers!!\n");
rohc_free_compressor(compressor);
}
printf("\n Enabling the profile");
rohc_activate_profile(compressor, ROHC_PROFILE_UNCOMPRESSED);
rohc_activate_profile(compressor, ROHC_PROFILE_UDP);
rohc_activate_profile(compressor, ROHC_PROFILE_IP);
printf("\n Creating ROHC Decompressor.....");
decompressor=rohc_alloc_decompressor(compressor);
if(decompressor == NULL)
{
fprintf(stderr,"\n Failed creating decompressor!!\n");
rohc_free_decompressor(decompressor);
}
if(!rohc_decomp_set_traces_cb(decompressor, NULL))
{
fprintf(stderr,"\n Failed to set callback traces for decompressor!!");
rohc_free_decompressor(decompressor);
}
logfile=fopen("log.txt","w");
if(logfile == NULL) printf("\n Unable to create file");
raw_sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
if(raw_sock < 0)
{
printf("\n Socket error; try with sudo");
return 1;
}
while(1)
{
saddr_size = sizeof(saddr);
data_size = recvfrom(raw_sock, BUFFER, BUFFER_SIZE, 0, &saddr, &saddr_size);
if(data_size < 0)
{
printf("\n Error of recvfrom(), failed to get packets");
return 1;
}
struct iphdr *iph = (struct iphdr*)BUFFER;
iphdrlen = iph->ihl*4;
memset(&source, 0, sizeof(source));
source.sin_addr.s_addr = iph->saddr;
memset(&dest, 0, sizeof(dest));
dest.sin_addr.s_addr = iph->daddr;
fprintf(logfile,"\n###########################################################");
fprintf(logfile,"\n***********************IP*************************\n");
fprintf(logfile,"\nIP Header\n");
fprintf(logfile," |-IP Version : %d\n",(unsigned int)iph->version);
fprintf(logfile," |-IP Header Length : %d DWORDS or %d Bytes\n",(unsigned int)iph->ihl,((unsigned int)(iph->ihl))*4);
fprintf(logfile," |-Type Of Service : %d\n",(unsigned int)iph->tos);
fprintf(logfile," |-IP Total Length : %d Bytes(Size of Packet)\n",ntohs(iph->tot_len));
fprintf(logfile," |-Identification : %d\n",ntohs(iph->id));
fprintf(logfile," |-TTL : %d\n",(unsigned int)iph->ttl);
fprintf(logfile," |-Protocol : %d\n",(unsigned int)iph->protocol);
fprintf(logfile," |-Checksum : %d\n",ntohs(iph->check));
fprintf(logfile," |-Source IP : %s\n",inet_ntoa(source.sin_addr));
fprintf(logfile," |-Destination IP : %s\n",inet_ntoa(dest.sin_addr));
struct udphdr *udph = (struct udphdr*)(BUFFER + iphdrlen);
fprintf(logfile,"\n\n***********************UDP*************************\n");
fprintf(logfile,"\nUDP Header\n");
fprintf(logfile," |-Source Port : %d\n" , ntohs(udph->source));
fprintf(logfile," |-Destination Port : %d\n" , ntohs(udph->dest));
fprintf(logfile," |-UDP Length : %d\n" , ntohs(udph->len));
fprintf(logfile," |-UDP Checksum : %d\n" , ntohs(udph->check));
fprintf(logfile,"\n************************************************************\n");
fprintf(logfile,"\n");
fprintf(logfile,"IP Header\n");
PrintData(BUFFER , iphdrlen);
fprintf(logfile,"UDP Header\n");
PrintData(BUFFER+iphdrlen , sizeof udph);
fprintf(logfile,"Data Payload\n");
PrintData(BUFFER + iphdrlen + sizeof udph ,( data_size - sizeof udph - iph->ihl * 4 ));
fprintf(logfile,"\n###########################################################");
printf("\n Compressing the UDP/IP packet...\n\n");
ret=rohc_compress2(compressor,BUFFER,data_size,rohc_packet, BUFFER_SIZE, &rohc_packet_len);
if(ret!=ROHC_OK)
{
fprintf(stderr, "Compression of IP packet failed\n");
rohc_free_compressor(compressor);
return 1;
}
printf("\n ROHC packet after compression:\n");
for(i = 0; i < ((unsigned int) rohc_packet_len); i++)
{
printf("0x%02x ", rohc_packet[i]);
if(i != 0 && ((i + 1) % 8) == 0)
{
printf("\n");
}
}
printf("\n\n Total number of bytes:%d", i);
if(i != 0 && (i % 8) != 0)
{
printf("\n");
}
printf("\n Decompressing the UDP/IP packet....\n");
ret=rohc_decompress(decompressor,rohc_packet,rohc_packet_len,op_packet,BUFFER_SIZE);
if(ret <= 0)
{
fprintf(stderr, "Decompression failed\n");
rohc_free_decompressor(decompressor);
}
printf("\n IP packet after Decompression:\n\n");
for(i = 0; i < ((unsigned int) ret); i++)
{
printf("0x%02x ", op_packet[i]);
if(i != 0 && ((i + 1) % 8) == 0)
{
printf("\n");
}
}
printf("\n\n Total number of bytes:%d", i);
if(i != 0 && (i % 8) != 0)
{
printf("\n");
}
}
close(raw_sock);
printf("\n Finished");
printf("\n Destroy the Compressor and Decompressor");
rohc_free_compressor(compressor);
rohc_free_decompressor(decompressor);
return 0;
}
static int gen_random_num(const struct rohc_comp *const comp,void *const user_context)
{
return rand();
}
void PrintData (unsigned char* data , int Size)
{
for(i=0 ; i < Size ; i++)
{
if( i!=0 && i%16==0)
{
fprintf(logfile," ");
for(j=i-16 ; j<i ; j++)
{
if(data[j]>=32 && data[j]<=128)
fprintf(logfile,"%c",(unsigned char)data[j]);
else fprintf(logfile,".");
}
fprintf(logfile,"\n");
}
if(i%16==0) fprintf(logfile," ");
fprintf(logfile," %02X",(unsigned int)data[i]);
if( i==Size-1)
{
for(j=0;j<15-i%16;j++) fprintf(logfile," ");
fprintf(logfile," ");
for(j=i-i%16 ; j<=i ; j++)
{
if(data[j]>=32 && data[j]<=128) fprintf(logfile,"%c",(unsigned char)data[j]);
else fprintf(logfile,".");
}
fprintf(logfile,"\n");
}
}
}
--
You received this question notification because you are a member of ROHC
Team, which is an answer contact for rohc.