rohc team mailing list archive
-
rohc team
-
Mailing list archive
-
Message #00316
Re: [Question #89639]: how to start rohc
Question #89639 on rohc changed:
https://answers.launchpad.net/rohc/+question/89639
Shaan requested more information:
I have followed some of the FAQ specially "638" for a sample program to
integrate RoHC. Snapshot of the code is given below, Now I want to hook
into some of the variable i.e
ip_packet \\ Initial IP Packet
rohc_packet \\ Compressed Packet
ip_packet_rx \\ Received Packet after decompression.
I want to capture these packets in dump them into pcap for analysis,
how and where I should change my code.
2ndly, if I replace the following IPv4 header with IPv6 header program
should work, or do I have change compression/decompression
libraries/functions?
With Kind Regards,
Shaan
---------------------------------------------------------------------------------------------------------------------------------
/* system includes */
#include <stdlib.h>
#include <stdio.h>
/* includes to create a fake IP packet */
#include <netinet/ip.h>
#include <string.h>
/* includes for using ROHC library */
#include <rohc.h>
#include <rohc_comp.h>
#include <rohc_decomp.h>
/** The size (in bytes) of the buffers used in the program */
#define BUFFER_SIZE 2048
#define MAX_SIZE 2048
/** The payload for the fake IP packet */
#define FAKE_PAYLOAD "hello, ROHC world!"
/**
* @brief The main entry point for the simple ROHC program
*
* @param argc the number of arguments given to the program
* on command line
* @param argv the table of arguments given to the program
* on command line
* @return 0 in case of success, 1 otherwise
*/
int main(int argc, char **argv)
{
struct rohc_comp *compressor; /* the ROHC compressor */
struct rohc_decomp *decompressor; /* the ROHC decompressor */
unsigned char ip_packet[BUFFER_SIZE]; /* the buffer that contains
the IPv4 packet to compress */
unsigned int ip_packet_len; /* the length (in bytes) of the
IPv4 packet */
struct iphdr *ip_header; /* the header of the IPv4 packet */
unsigned char rohc_packet[BUFFER_SIZE]; /* the buffer that contains the
resulting ROHC packet */
int rohc_packet_len; /* the length (in bytes) of the
resulting ROHC packet */
unsigned int i;
//decomp
//unsigned char packet[MAX_SIZE];
// unsigned int rohc_len;
unsigned char ip_packet_rx[MAX_SIZE];
int ip_size;
/* At program start-up, initialize the pre-computed tables for the 3-bit,
* 7-bit and 8-bit CRCs that the ROHC library will use.
*
* Note that the crc_table_3, crc_table_7 and crc_table_8 variables are
* declared inside the library, there is no need to declare them in your
* source code.
*/
crc_init_table(crc_table_3, crc_get_polynom(CRC_TYPE_3));
crc_init_table(crc_table_7, crc_get_polynom(CRC_TYPE_7));
crc_init_table(crc_table_8, crc_get_polynom(CRC_TYPE_8));
/* create a ROHC compressor with small CIDs, no jamming and no adaptation
to encapsulation frames */
compressor = rohc_alloc_compressor(15, 0, 0, 0);
if(compressor == NULL)
{
fprintf(stderr, "failed create the ROHC compressor\n");
goto error;
}
/* create a ROHC compressor with small CIDs, no jamming and no adaptation
to encapsulation frames */
decompressor = rohc_alloc_decompressor(NULL);
if(decompressor == NULL)
{
fprintf(stderr, "cannot create the ROHC decompressor\n");
goto error;
}
/* enable the compression profiles you need (comment or uncomment some lines) */
rohc_activate_profile(compressor, ROHC_PROFILE_UNCOMPRESSED);
rohc_activate_profile(compressor, ROHC_PROFILE_UDP);
rohc_activate_profile(compressor, ROHC_PROFILE_IP);
//rohc_activate_profile(compressor, ROHC_PROFILE_UDPLITE);
rohc_activate_profile(compressor, ROHC_PROFILE_RTP);
/* create a fake IP packet for the purpose of this simple program */
ip_header = (struct iphdr *) ip_packet;
ip_header->version = 4; /* we create an IPv4 header */
ip_header->ihl = 5; /* minimal IPv4 header length (in 32-bit words) */
ip_header->tos = 0;
ip_packet_len = ip_header->ihl * 4 + strlen(FAKE_PAYLOAD);
ip_header->tot_len = htons(ip_packet_len);
ip_header->id = 0;
ip_header->frag_off = 0;
ip_header->ttl = 1;
ip_header->protocol = 134; /* unassigned number according to /etc/protocols */
ip_header->check = 0; /* set to 0 for checksum computation */
ip_header->saddr = htonl(0x01020304);
ip_header->daddr = htonl(0x05060708);
/* header is now built, compute the checksum */
ip_header->check = ip_fast_csum(ip_packet, ip_header->ihl);
/* copy the payload just after the IP header */
memcpy(ip_packet + ip_header->ihl * 4, FAKE_PAYLOAD, strlen(FAKE_PAYLOAD));
/* dump the IP packet on terminal */
for(i = 0; i < ip_packet_len; i++)
{
printf("0x%02x ", ip_packet[i]);
if(i != 0 && ((i + 1) % 8) == 0)
{
printf("\n");
}
}
if(i != 0 && ((i + 1) % 8) != 0) /* be sure to go to the line */
{
printf("\n");
}
/* now, compress this fake IP packet */
rohc_packet_len = rohc_compress(compressor,
ip_packet, ip_packet_len,
rohc_packet, BUFFER_SIZE);
if(rohc_packet_len <= 0)
{
fprintf(stderr, "compression of fake IP packet failed\n");
goto release_compressor;
}
/* dump the ROHC packet on terminal */
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");
}
}
if(i != 0 && ((i + 1) % 8) != 0) /* be sure to go to the line */
{
printf("\n");
}
/* release the ROHC compressor when you do not need it anymore */
rohc_free_compressor(compressor);
printf("the program ended successfully\n");
return 0;
release_compressor:
rohc_free_compressor(compressor);
error:
fprintf(stderr, "an error occured during program execution, "
"abort program\n");
//--------------------------Decompressor----------------------------------------
/* read the ROHC packet somewhere, store it in the buffer named 'packet'
and set its length in the 'packet_len' variable */
ip_size = rohc_decompress(decompressor,rohc_packet, rohc_packet_len,ip_packet_rx, MAX_SIZE);
if(ip_size <= 0)
{
if(ip_size == ROHC_FEEDBACK_ONLY)
{
// the ROHC packet contained feedback only, so there is no
// decompressed IP data
// manage this special case here, do not treat it as an error
}
else
{
fprintf(stderr, "decompression of packet failed\n");
// manage the error here
}
}
rohc_free_decompressor(decompressor);
//------------------------------------------------------------------
return 1;
}
--
You received this question notification because you are a member of ROHC
Team, which is an answer contact for rohc.