51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <arpa/inet.h>
|
|
#include "tfe_types.h"
|
|
#include "tfe_utils.h"
|
|
#include "tfe_cmsg.h"
|
|
|
|
int main(){
|
|
//init
|
|
struct tfe_cmsg *cmsg = tfe_cmsg_init();
|
|
|
|
//set
|
|
uint32_t value = 0x12345678;
|
|
int ret = tfe_cmsg_set(cmsg, TCP_RESTORE_INFO_TLV_SEQ, (const unsigned char*)(&value), 4);
|
|
printf("tfe_cmsg_set: ret is %d\n", ret);
|
|
|
|
//get TCP_RESTORE_INFO_TLV_SEQ
|
|
uint16_t size = -1;
|
|
unsigned char *value1 = NULL;
|
|
ret = tfe_cmsg_get(cmsg, TCP_RESTORE_INFO_TLV_SEQ, &size, &value1);
|
|
printf("tfe_cmsg_get: ret is %d, type is TCP_RESTORE_INFO_TLV_SEQ, value is 0x%02x, value_size is %d\n", ret, ((uint32_t*)value1)[0], size);
|
|
|
|
//get_serialize_size
|
|
size = tfe_cmsg_serialize_size_get(cmsg);
|
|
printf("tfe_cmsg_serialize_size_get: size is %d\n", size);
|
|
|
|
//serialize
|
|
unsigned char buff[size];
|
|
uint16_t serialize_len = -1;
|
|
ret = tfe_cmsg_serialize(cmsg, buff, size, &serialize_len);
|
|
printf("tfe_cmsg_serialize: ret is %d, serialize_len is %d, serialize result is: ", ret, serialize_len);
|
|
for(int i = 0; i < serialize_len; i++){
|
|
printf("%02x ", buff[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
//deserialize
|
|
struct tfe_cmsg *cmsg1 = NULL;
|
|
ret = tfe_cmsg_deserialize(buff, serialize_len, &cmsg1);
|
|
printf("tfe_cmsg_deserialize: ret is %d\n", ret);
|
|
|
|
//get TCP_RESTORE_INFO_TLV_SEQ
|
|
size = -1;
|
|
unsigned char *value2 = NULL;
|
|
ret = tfe_cmsg_get(cmsg1, TCP_RESTORE_INFO_TLV_SEQ, &size, &value2);
|
|
printf("tfe_cmsg_get: ret is %d, type is TCP_RESTORE_INFO_TLV_SEQ, value is 0x%02x, value_size is %d\n", ret, ((uint32_t*)value2)[0], size);
|
|
}
|