-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_reg.c
34 lines (26 loc) · 968 Bytes
/
data_reg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
static int nft_data_reg_value_snprintf_json(char *buf, size_t size,
union nft_data_reg *reg,
uint32_t flags)
{
int len = size, offset = 0, ret, i, j;
uint8_t *tmp;
int data_len = reg->len/sizeof(uint32_t);
ret = snprintf(buf, len, "{ \"data_reg\": { \"type\" : \"value\",");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
ret = snprintf(buf+offset, len, "\"len\" : %d,", data_len);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
for (i=0; i<data_len; i++) {
ret = snprintf(buf+offset, len, "\"data%d\" : \"0x", i);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
tmp = (uint8_t *)®->val[i];
for (j=0; j<sizeof(int); j++) {
ret = snprintf(buf+offset, len, "%.02x", tmp[j]);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
ret = snprintf(buf+offset, len, "\"", i);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
ret = snprintf(buf+offset, len, "}}");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
return offset;
}