From f9974afcc6f2428b52d9940bc60010e4fba0a38d Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Wed, 17 Jul 2024 09:24:31 +0800 Subject: [PATCH] sonmp: convert deprecated inet_ntoa to inet_ntop inet_ntoa has been marked as deprecated. Let's convert it to inet_ntop. Signed-off-by: Hangbin Liu --- src/daemon/protocols/sonmp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/daemon/protocols/sonmp.c b/src/daemon/protocols/sonmp.c index 34ebcd7e..ddc2771d 100644 --- a/src/daemon/protocols/sonmp.c +++ b/src/daemon/protocols/sonmp.c @@ -286,6 +286,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardw u_int8_t *pos; u_int8_t seg[3], rchassis; struct in_addr address; + char ip_addr[INET_ADDRSTRLEN]; log_debug("sonmp", "decode SONMP PDU from %s", hardware->h_ifname); @@ -334,7 +335,12 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardw chassis->c_id[0] = 1; PEEK_BYTES(&address, sizeof(struct in_addr)); memcpy(chassis->c_id + 1, &address, sizeof(struct in_addr)); - if (asprintf(&chassis->c_name, "%s", inet_ntoa(address)) == -1) { + if (inet_ntop(AF_INET, &address, ip_addr, sizeof(ip_addr)) == NULL) { + log_warnx("sonmp", "unable to convert chassis address for %s", + hardware->h_ifname); + goto malformed; + } + if (asprintf(&chassis->c_name, "%s", ip_addr) == -1) { log_warnx("sonmp", "unable to write chassis name for %s", hardware->h_ifname); goto malformed; -- 2.39.5