diff options
| author | 崔一鸣 <[email protected]> | 2019-06-04 21:18:55 +0800 |
|---|---|---|
| committer | 崔一鸣 <[email protected]> | 2019-06-04 21:18:55 +0800 |
| commit | 03a5f7ec6c656a4b3c1007b2ec7b252ccddceb7f (patch) | |
| tree | 63a98f7c064119d2072ed482c519c2b45f382e5c /common | |
| parent | 8f1a4f3dbd883ae27961b98058a3d04f717c609d (diff) | |
修复cmsg解析问题
Diffstat (limited to 'common')
| -rw-r--r-- | common/include/kni_cmsg.h | 3 | ||||
| -rw-r--r-- | common/src/kni_cmsg.cpp | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/common/include/kni_cmsg.h b/common/include/kni_cmsg.h index eeab498..c4b37ba 100644 --- a/common/include/kni_cmsg.h +++ b/common/include/kni_cmsg.h @@ -8,7 +8,8 @@ struct kni_cmsg_serialize_header; enum kni_cmsg_errno{ KNI_CMSG_INVALID_FORMAT = -1, KNI_CMSG_BUFF_NOT_ENOUGH = -2, - KNI_CMSG_INVALID_TYPE = -3 + KNI_CMSG_INVALID_TYPE = -3, + KNI_CMSG_TYPE_UNSET = -4, }; enum tfe_cmsg_tlv_type diff --git a/common/src/kni_cmsg.cpp b/common/src/kni_cmsg.cpp index ea4d462..0815c1b 100644 --- a/common/src/kni_cmsg.cpp +++ b/common/src/kni_cmsg.cpp @@ -65,11 +65,15 @@ int kni_cmsg_set(struct kni_cmsg *cmsg, uint16_t type, const unsigned char *valu int kni_cmsg_get(struct kni_cmsg *cmsg, uint16_t type, uint16_t *size, unsigned char **pvalue) { struct kni_cmsg_tlv *tlv = NULL; - if(type >= KNI_CMSG_TLV_NR_MAX || (tlv = cmsg->tlvs[type]) == NULL) + if(type >= KNI_CMSG_TLV_NR_MAX) { *size = 0; return KNI_CMSG_INVALID_TYPE; } + if((tlv = cmsg->tlvs[type]) == NULL){ + *size = 0; + return KNI_CMSG_TYPE_UNSET; + } *size = tlv->length - sizeof(struct kni_cmsg_tlv); *pvalue = tlv->value_as_string; return 0; @@ -153,6 +157,7 @@ int kni_cmsg_deserialize(const unsigned char *data, uint16_t len, struct kni_cms cmsg = ALLOC(struct kni_cmsg, 1); offset = sizeof(struct kni_cmsg_serialize_header); nr_tlvs = ntohs(header->nr_tlvs); + printf("nr_tlvs is %d\n", nr_tlvs); for(int i = 0; i < nr_tlvs; i++) { struct kni_cmsg_tlv *tlv = (struct kni_cmsg_tlv*)(data + offset); @@ -161,6 +166,7 @@ int kni_cmsg_deserialize(const unsigned char *data, uint16_t len, struct kni_cms goto error_out; } uint16_t type = ntohs(tlv->type); + printf("type = %d\n", type); uint16_t length = ntohs(tlv->length); if(length < sizeof(struct kni_cmsg_tlv) || offset + length > len) { |
