From d194158130c6824fa048c07783f470f83ec9d8ae Mon Sep 17 00:00:00 2001 From: haozi007 Date: Thu, 26 Nov 2020 15:11:05 +0800 Subject: [PATCH 3/3] fix invalid ipv6 format Signed-off-by: haozi007 --- README.md | 2 +- src/types/types.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bcc0368..d52e27e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # clibcni CNI (Container Network Interface), a Cloud Native Computing Foundation project. -clibcni is a library used by iSulad to configure network interfaces in containers, following +clibcni is a library used by [iSulad](https://gitee.com/openeuler/iSulad) to configure network interfaces in containers, following the specification of CNI (Container Network Interface), a Cloud Native Computing Foundation project. ## How to Contribute diff --git a/src/types/types.c b/src/types/types.c index 60a63c3..a9a04e7 100644 --- a/src/types/types.c +++ b/src/types/types.c @@ -313,10 +313,14 @@ static void generate_ip_string(const uint8_t *ip, int e0, int e1, char **result) } else if (i > 0) { (*result)[j++] = ':'; } - int nret = (ip[i] >> 4); - (*result)[j++] = g_HEX_DICT[nret]; - nret = (ip[i] & 0x0f); - (*result)[j++] = g_HEX_DICT[nret]; + uint32_t nret = (ip[i] << 8) | ip[i + 1]; + if (sprintf((*result) + j, "%x", nret) < 0) { + ERROR("sprint ip failed"); + free(*result); + *result = NULL; + return; + } + j = strlen(*result); } return; } -- 2.25.1