Пример #1
0
int bvlc_forwarded_npdu_encode(bvlc_forwarded_npdu_t *message, buffer_t *buf)
{
  return 1
    && buffer_write_u16(buf, 0)
    && buffer_write_raw(buf, message->original_bip_address, 6)
    && buffer_write_raw(buf, message->npdu, message->npdu_length);
}
Пример #2
0
bool unabto_buffer_test(void) {

    char * raw_test_string = "asjdhc#21?(!?(92814skzjbcasa";
    uint8_t data[7 + 2 + strlen(raw_test_string)];
    unabto_buffer buf, raw_string_buf;
    buffer_write_t w_buf;
    buffer_read_t r_buf;

    uint32_t t32;
    uint16_t t16;
    uint8_t  t8;
    uint8_t raw_string_data[strlen(raw_test_string) + 1];

    buffer_init(&raw_string_buf, (uint8_t*)raw_test_string, strlen(raw_test_string));
    
    buffer_init(&buf, data, sizeof(data));
    
    buffer_write_init(&w_buf, &buf);

    if (! (buffer_write_uint32(&w_buf, 0x12345678) &&
           buffer_write_uint16(&w_buf, 0x1234) &&
           buffer_write_uint8(&w_buf, 0x12) && 
           buffer_write_raw(&w_buf, &raw_string_buf) ) ) {
        NABTO_LOG_ERROR(("Buffer write test failed"));
        return false;
    }
    
    buffer_read_init(&r_buf, &buf);
    
    memset(raw_string_data, 0, sizeof(raw_string_data) + 1);
    buffer_init(&raw_string_buf, raw_string_data, sizeof(raw_string_data));
    bool t = false;    
    if (! ( buffer_read_uint32(&r_buf, &t32) && t32 == 0x12345678 &&
            buffer_read_uint16(&r_buf, &t16) && t16 == 0x1234 &&
            buffer_read_uint8(&r_buf, &t8)   && t8  == 0x12 && 
            (t = buffer_read_raw(&r_buf, &raw_string_buf)) && buffer_get_size(&raw_string_buf) == strlen(raw_test_string) &&
            0 == strncmp((char*)buffer_get_data(&raw_string_buf), raw_test_string, strlen(raw_test_string)) )) {
        NABTO_LOG_ERROR(("Failed read test failed"));
        return false;
    }

    if (buffer_read_uint32(&r_buf, &t32) ||
        buffer_read_uint16(&r_buf, &t16) ||
        buffer_read_uint8(&r_buf, &t8) ||
        buffer_read_raw(&w_buf, &raw_string_buf) ||
        buffer_write_uint32(&w_buf, 0x12345678) ||
        buffer_write_uint16(&w_buf, 0x1234) ||
        buffer_write_uint8(&w_buf, 0x12) || 
        buffer_write_raw(&w_buf, &raw_string_buf) ) {
        NABTO_LOG_ERROR(("Some function should have returned false but returned true"));
        return false;
    }

    return true;

}
Пример #3
0
int bvlc_write_bdt_encode(bvlc_write_bdt_t *message, buffer_t *buf)
{
  int ret = 1
    && buffer_write_u16(buf, 0);

  if(ret) {
    for(uint16_t i = 0; ret && i < message->entry_count; i++) {
      ret = 1
        && buffer_write_raw(buf, message->entries[i].bip_address, 6)
        && buffer_write_raw(buf, message->entries[i].broadcast_mask, 4);
    }
  }

  return ret;
}
Пример #4
0
int bvlc_read_fdt_ack_encode(bvlc_read_fdt_ack_t *message, buffer_t *buf)
{
  int ret = 1
    && buffer_write_u16(buf, 0);

  if(ret) {
    for(uint16_t i = 0; ret && i < message->entry_count; i++) {
      ret = 1
        && buffer_write_raw(buf, message->entries[i].bip_address, 6)
        && buffer_write_u16(buf, message->entries[i].original_ttl)
        && buffer_write_u16(buf, message->entries[i].ttl);
    }
  }

  return ret;
}
Пример #5
0
int bvlc_original_broadcast_encode(bvlc_original_broadcast_t *message, buffer_t *buf)
{
  return 1
    && buffer_write_u16(buf, 0)
    && buffer_write_raw(buf, message->npdu, message->npdu_length);
}
Пример #6
0
int bvlc_delete_fdt_entry_encode(bvlc_delete_fdt_entry_t *message, buffer_t *buf)
{
  return 1
    && buffer_write_u16(buf, 0)
    && buffer_write_raw(buf, message->bip_address, 6);
}