Question #266555 on rohc changed:
https://answers.launchpad.net/rohc/+question/266555

    Status: Answered => Open

Ashok Kumar is still having a problem:
Hi,
      I installed the latest version of ROHC from Git as per the instruction 
given in the link and also enabled non-regression test. Then I used the 
following code which deliberately takes the fifth packet to de-compressor 
without being compressed and the error its created also shown


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<netdb.h>

#include<netinet/ip_icmp.h>   
#include<netinet/udp.h>   
#include<netinet/tcp.h>
#include<netinet/ip.h>
#include<netinet/if_ether.h>
#include<net/ethernet.h>
#include<netinet/in.h>

#include<sys/socket.h>
#include<arpa/inet.h>
#include<sys/ioctl.h>
#include<sys/time.h>
#include<sys/types.h>
#include<unistd.h>

#include<stdarg.h>
#include<rohc/rohc.h>
#include<rohc/rohc_comp.h>
#include<rohc/rohc_decomp.h>
#include<rohc/rohc_time.h>

#define BUFFER_SIZE 65536


//void PrintData(unsigned char* ,int);
static int gen_random_num(const struct rohc_comp *const comp, void *const 
user_context);
static void print_rohc_traces(void *const priv_ctxt,const rohc_trace_level_t 
level,const rohc_trace_entity_t entity,
                              const int profile,const char *const format,...);
int raw_sock,i,j;
FILE *logfile;
struct sockaddr_in source,dest;

int main(int argc, char **argv)
{
        int saddr_size, data_size;
        int count = 0;
        struct sockaddr saddr;
        struct in_addr in;
        struct rohc_comp *compressor;
        struct rohc_decomp *decompressor;
        struct rohc_buf *rcvd_feedback = NULL;
        struct rohc_buf *feedback_send = NULL;
        struct rohc_ts rohc_ts;
        int ret;
        unsigned char luchar_RohcDecStatus, luchar_RohcComStatus;
        unsigned int seed;
        size_t i;
        rohc_status_t status;


        unsigned short iphdrlen;
        unsigned int ip_packet_len, rohc_packet_len;
        unsigned char BUFFER[BUFFER_SIZE], rohc_packet[BUFFER_SIZE], 
op_packet[BUFFER_SIZE];
                
        
        printf("\n Creating ROHC compressor......\n\n");
        compressor = rohc_comp_new2(ROHC_SMALL_CID, ROHC_SMALL_CID_MAX, 
gen_random_num, NULL);
        if(compressor == NULL)
        { 
                printf("Failed creating compressor!!\n");
                rohc_comp_free(compressor);
        }
                
        if(!rohc_comp_set_traces_cb2(compressor, 
NULL,NULL))//if(!rohc_comp_set_traces_cb2(compressor, print_rohc_traces,NULL))
        {
                printf( "Failed to set the compressor callback random 
numbers!!\n");
                rohc_comp_free(compressor);
        }
        
        printf("Enabling compressor profiles");
        if(!rohc_comp_enable_profiles(compressor, ROHC_PROFILE_UNCOMPRESSED, 
ROHC_PROFILE_IP, ROHC_PROFILE_UDP, ROHC_PROFILE_TCP, -1))
        {
                printf("Failed to enable the Compressor profiles\n");
                rohc_comp_free(compressor);
        }

        printf("\n Creating ROHC Decompressor.....");
        decompressor=rohc_decomp_new2(ROHC_SMALL_CID, ROHC_SMALL_CID_MAX, 
ROHC_U_MODE);
        if(decompressor == NULL)
        {
                printf("Failed creating decompressor!!\n");
                rohc_decomp_free(decompressor);
        }

        
if(!rohc_decomp_set_traces_cb2(decompressor,NULL,NULL))//if(!rohc_decomp_set_traces_cb2(decompressor,print_rohc_traces,NULL))
        {
                printf("Failed to set callback traces for decompressor!!\n");
                rohc_decomp_free(decompressor);
        } 

        if(!rohc_decomp_enable_profiles(decompressor, 
ROHC_PROFILE_UNCOMPRESSED, ROHC_PROFILE_IP, ROHC_PROFILE_UDP, ROHC_PROFILE_TCP, 
-1))
        {
                printf("Failed to enable the De-compressor profiles\n");
                rohc_decomp_free(decompressor);
        }
        
        logfile=fopen("log.txt","w");
        if(logfile == NULL) 
        {
                printf("Unable to create file\n");
        }
        
        raw_sock = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_ALL));
        //setsockopt(raw_sock , SOL_SOCKET , SO_BINDTODEVICE , "eth0" , 
strlen("eth0")+ 1 );
                
        if(raw_sock < 0)
        {
                perror("\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 + sizeof(struct 
ethhdr));
                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;

                if((((unsigned int)iph->protocol)==6||((unsigned 
int)iph->protocol)==17)&&(strcmp(inet_ntoa(dest.sin_addr),"172.16.18.134")==0))
                {

                        count++;                        
                        
                        int ethhdr_size = sizeof(struct ethhdr);
                        struct rohc_buf rohcBuf_IpPacket = 
rohc_buf_init_full(&BUFFER[ethhdr_size], data_size-ethhdr_size , 0);
                unsigned char rohc_Combuffer[BUFFER_SIZE];
                struct rohc_buf rohc_Compacket = 
rohc_buf_init_empty(rohc_Combuffer, BUFFER_SIZE);
                        if(count!=5)
                        {
                                printf("\n Compressing the TCP/IP 
packet...\n\n");                              
                                luchar_RohcComStatus = 
rohc_compress4(compressor, rohcBuf_IpPacket, &rohc_Compacket);
                            if(luchar_RohcComStatus!= ROHC_STATUS_OK)
                                {
                                        printf( "Compression of TCP/IP packet 
failed\n");
                                        rohc_comp_free(compressor);
                                        return 1;
                                }
                                printf("IP packet size=%d ROHC packet size 
=%d\n", data_size-sizeof(struct ethhdr),rohc_Compacket.len);
                        }
        
                        
                        //if(count!=5)
                        //{
                                printf("\n Decompressing the TCP/IP 
packet....\n");                             
                                struct rohc_buf rohc_packet = 
rohc_buf_init_full(rohc_Combuffer,rohc_Compacket.len, 0);
                                unsigned char rohc_Decombuffer[BUFFER_SIZE];
                                struct rohc_buf rohc_Decompacket = 
rohc_buf_init_empty(rohc_Decombuffer, BUFFER_SIZE);

                                luchar_RohcDecStatus = 
rohc_decompress3(decompressor, rohc_packet, &rohc_Decompacket,
                                rcvd_feedback, feedback_send);
                                if(luchar_RohcDecStatus !=  ROHC_STATUS_OK)
                            {
                                        printf("Decompression TCP/IP packet 
failed\n");
                            rohc_decomp_free(decompressor);
                            }
                                printf("ROHC packet size=%d IP packet 
size=%d\n", rohc_Compacket.len,rohc_Decompacket.len);
                        //}
                
                }
                else
                {
                        //printf("IP packet received of protocol 
number:%d\r",(unsigned int)iph->protocol);
                }
                usleep(0);
        }
        close(raw_sock);
        printf("\n Finished");
        printf("\n Destroy the Compressor and Decompressor");
        rohc_comp_free(compressor);
        rohc_decomp_free(decompressor);
        return 0;
}

static int gen_random_num(const struct rohc_comp *const comp,void *const 
user_context)
{
        return rand();
}

static void print_rohc_traces(void *const priv_ctxt,const rohc_trace_level_t 
level,const rohc_trace_entity_t entity,const int profile,
        const char *const format,...)
{
        va_list args;
        va_start(args, format);
        vfprintf(stdout, format, args);
        va_end(args);
}

sudo ./ROHCTest

 Creating ROHC compressor......

Enabling compressor profiles
 Creating ROHC Decompressor.....
 Compressing the TCP/IP packet...

IP packet size=618 ROHC packet size =617

 Decompressing the TCP/IP packet....
ROHC packet size=617 IP packet size=618

 Compressing the TCP/IP packet...

IP packet size=52 ROHC packet size =51

 Decompressing the TCP/IP packet....
ROHC packet size=51 IP packet size=52

 Compressing the TCP/IP packet...

IP packet size=593 ROHC packet size =592

 Decompressing the TCP/IP packet....
ROHC packet size=592 IP packet size=593

 Compressing the TCP/IP packet...

IP packet size=613 ROHC packet size =613

 Decompressing the TCP/IP packet....
ROHC packet size=613 IP packet size=613

 Decompressing the TCP/IP packet....
Decompression TCP/IP packet failed
ROHC packet size=0 IP packet size=0

 Compressing the TCP/IP packet...

IP packet size=52 ROHC packet size =27

 Decompressing the TCP/IP packet....
ROHCTest: rohc_decomp.c:3616: rohc_decomp_decode_cid: Assertion `0' failed.
Aborted


But it works like a champ when a compressed packet is purposely discarded in 
de-compressor without getting aborted...

-- 
You received this question notification because you are a member of ROHC
Team, which is an answer contact for rohc.

_______________________________________________
Mailing list: https://launchpad.net/~rohc
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~rohc
More help   : https://help.launchpad.net/ListHelp

Reply via email to