]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
sonmp: convert deprecated inet_ntoa to inet_ntop
authorHangbin Liu <liuhangbin@gmail.com>
Wed, 17 Jul 2024 01:24:31 +0000 (09:24 +0800)
committerVincent Bernat <vincent@bernat.ch>
Sat, 26 Oct 2024 07:34:49 +0000 (09:34 +0200)
inet_ntoa has been marked as deprecated. Let's convert it to inet_ntop.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
src/daemon/protocols/sonmp.c

index 34ebcd7e3110b6a74ff7b254510cda3cfa9c5339..ddc2771d75c1bee1dc1fcc8fbe5374f3aa5fb89b 100644 (file)
@@ -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;