Beispiel #1
0
char *bgpstream_record_elem_snprintf(char *buf, size_t len,
                                     const bgpstream_record_t *bs_record,
                                     const bgpstream_elem_t *elem)
{
  assert(bs_record);
  assert(elem);

  size_t written = 0; /* < how many bytes we wanted to write */
  ssize_t c = 0;      /* < how many chars were written */
  char *buf_p = buf;

  /* Record type */
  if ((c = bgpstream_record_dump_type_snprintf(
         buf_p, B_REMAIN, bs_record->attributes.dump_type)) < 0) {
    return NULL;
  }
  written += c;
  buf_p += c;
  ADD_PIPE;

  /* Elem type */
  if ((c = bgpstream_elem_type_snprintf(buf_p, B_REMAIN, elem->type)) < 0) {
    return NULL;
  }
  written += c;
  buf_p += c;
  ADD_PIPE;

  /* Record timestamp, project, collector */
  c = snprintf(buf_p, B_REMAIN, "%ld|%s|%s", bs_record->attributes.record_time,
               bs_record->attributes.dump_project,
               bs_record->attributes.dump_collector);
  written += c;
  buf_p += c;
  ADD_PIPE;

  if (B_FULL)
    return NULL;

  if (bgpstream_elem_custom_snprintf(buf_p, B_REMAIN, elem, 0) == NULL) {
    return NULL;
  }

  written += c;
  buf_p += c;

  if (B_FULL)
    return NULL;

  return buf;
}
Beispiel #2
0
static void print_rib_control_message(bgpstream_record_t *bs_record)
{
  assert(bs_record);

  size_t written = 0; /* < how many bytes we wanted to write */
  ssize_t c = 0; /* < how many chars were written */
  char *buf_p = record_buf;
  int len = 65536;

  /* record type */
  if((c =
      bgpstream_record_dump_type_snprintf(buf_p, len-written,
                                              bs_record->attributes.dump_type)) < 0)
    {
      return;
    }
  written += c;
  buf_p += c;

  c = snprintf(buf_p, len-written, "|");
  written += c;
  buf_p += c;

  /* record position */
  if((c = bgpstream_record_dump_pos_snprintf(buf_p, len-written,
                                             bs_record->dump_pos)) < 0)
    {
      return;
    }
  written += c;
  buf_p += c;

  /* Record timestamp, project, collector */
  c = snprintf(buf_p, len-written, "|%ld|%s|%s",
               bs_record->attributes.record_time,
               bs_record->attributes.dump_project,
               bs_record->attributes.dump_collector);
  written += c;
  buf_p += c;

  if(written >= len)
    {
      return;
    }

  printf("%s\n", record_buf);
}