← Back to team overview

rohc team mailing list archive

Re: Error using the ROHC compressor

 

Josephine,

> $ gcc packetforwardrohc.c -o packetforwardrohc -I/usr/include
> -L/usr/lib -lpcap `libnet-config --defines --cflags --libs`
> -lrohc_comp -lrohc_common -lm
> 
> In file included from headers.h:8,
>                  from packetforwardrohc.c:50:
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:197: warning: ‘struct
> ip_packet’ declared inside parameter list
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:197: warning: its scope
> is only this definition or declaration, which is probably not what
> you want /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:205: warning:
> ‘struct ip_packet’ declared inside parameter list
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:210: warning: ‘struct
> ip_packet’ declared inside parameter list
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:279: warning: ‘struct
> ip_packet’ declared inside parameter list
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:280: warning: ‘struct
> ip_packet’ declared inside parameter list
> /home/josie/rohc-1.2.0/src/comp/rohc_comp.h:290: warning: ‘struct
> ip_packet’ declared inside parameter list
> In file included from packetforwardrohc.c:50:
> headers.h:14:1: warning: "ETHER_ADDR_LEN" redefined
> In file included from /usr/include/libnet.h:57,
>                  from packetforwardrohc.c:49:
> /usr/include/net/ethernet.h:52:1: warning: this is the location of the
> previous definition
> packetforwardrohc.c: In function ‘got_packet’:
> packetforwardrohc.c:535: warning: passing argument 2 of
> ‘rohc_compress’ discards qualifiers from pointer target type
> /usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function
> `_start':
> (.text+0x18): undefined reference to `main'
> collect2: ld returned 1 exit status

GCC reports a problem in the file
"/home/josie/rohc-1.2.0/src/comp/rohc_comp.h", it means you try to
include this file in your code. You should not include this file
that way.

You should first install the ROHC library binaries and headers on
your system from the sources and then build your program with the
installed binaries and headers (and not the ones you may found in the
source directory).

The ROHC headers (rohc_comp.h among others) should be installed on your
system if you followed the steps described at
https://answers.launchpad.net/rohc/+faq/635. Check that the
file /usr/include/rohc_comp.h exist. If not, install the library first.

Then, in your program (packetforwardrohc.c), simply put the 2 following
lines at the top of the code:
  #include <rohc.h>
  #include <rohc_comp.h>

A simple program example for using the ROHC compression is attached to
this message. You may build it with the following GCC command :
 $ gcc -o simple_rohc_program -g -Wall \
   -lrohc_common -lrohc_comp -lm \
   simple_rohc_program.c

Regards,

Didier Barvaux
Viveris Technologies
/**
 * @file    simple_rohc_program.c
 * @brief   A very simple program that use the compression part of the ROHC library
 * @author  Didier Barvaux / Viveris Technologies
 * @license GPL2
 */

/* 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>


/** The size (in bytes) of the buffers used in the program */
#define BUFFER_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 */
  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;

  /* 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;
  }

  /* 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");
  return 1;
}


Follow ups

References