Очень нужно вывести из двоичной базы данных все значения в текстовом виде на perl. Но запутался с упаковкам распаковками и смещением. Может поможете?
country_id = _seek_country(gi, 0, ipnum, 31);
short int _seek_country (GeoIP *gi, int offset, unsigned long ipnum, int depth) {
  unsigned int x[2];
  unsigned char buf[2][3];
  int i,j;
  if (depth == -1) {
    fprintf(stderr,"Error Traversing Database - Perhaps database is corrupt?\\n");
    return 0;
  }
  fseek(gi->GeoIPDatabase, (long)6 * offset, SEEK_SET);
  fread(buf,3,2,gi->GeoIPDatabase);
  for (i = 0; i < 2; ++i) {
    x
 = 0;
    for (j = 0; j < 3; ++j) {
      x += (buf[j] << (j *  );
);
    }
  }
  if (ipnum & (1 << depth)) {
    if (x[1] >= 16776960) {
      return x[1] - COUNTRY_BEGIN;
    }
    return _seek_country(gi, x[1], ipnum, depth-1);
  } else {
    if (x[0] >= 16776960) {
      return x[0] - COUNTRY_BEGIN;
    }
    return _seek_country(gi, x[0], ipnum, depth-1);
  }
}