Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ldpd Use satos instead of inet_ntop



details:   https://anonhg.NetBSD.org/src/rev/36e0912495c4
branches:  trunk
changeset: 784457:36e0912495c4
user:      kefren <kefren%NetBSD.org@localhost>
date:      Mon Jan 28 21:08:14 2013 +0000

description:
Use satos instead of inet_ntop
Fix an alloc problem

diffstat:

 usr.sbin/ldpd/ldp_command.c |  20 ++++++--------------
 usr.sbin/ldpd/ldp_peer.c    |  15 ++++++++-------
 2 files changed, 14 insertions(+), 21 deletions(-)

diffs (99 lines):

diff -r aa0fa46b2b6b -r 36e0912495c4 usr.sbin/ldpd/ldp_command.c
--- a/usr.sbin/ldpd/ldp_command.c       Mon Jan 28 21:03:26 2013 +0000
+++ b/usr.sbin/ldpd/ldp_command.c       Mon Jan 28 21:08:14 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_command.c,v 1.9 2013/01/28 20:06:52 kefren Exp $ */
+/* $NetBSD: ldp_command.c,v 1.10 2013/01/28 21:08:14 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -411,21 +411,16 @@
        socklen_t sin_len = sizeof(struct sockaddr_in);
        int enc;
        socklen_t enclen = sizeof(enc);
-       char traddress[39], nhaddress[39];
 
        SLIST_FOREACH(p, &ldp_peer_head, peers) {
                snprintf(sendspace, MAXSEND, "LDP peer: %s\n",
                    inet_ntoa(p->ldp_id));
                writestr(s, sendspace);
-               inet_ntop(p->transport_address->sa_family,
-                   p->transport_address->sa_data, traddress, 39);
                snprintf(sendspace, MAXSEND, "Transport address: %s\n",
-                   traddress);
+                   satos(p->transport_address));
                writestr(s, sendspace);
-               inet_ntop(p->address->sa_family, p->address->sa_data,
-                   nhaddress, 39);
                snprintf(sendspace, MAXSEND, "Next-hop address: %s\n",
-                   nhaddress);
+                   satos(p->address));
                writestr(s, sendspace);
                snprintf(sendspace, MAXSEND, "State: %s\n",
                    ldp_state_to_name(p->state));
@@ -513,7 +508,6 @@
 show_bindings(int s, char *recvspace)
 {
        struct label *l;
-       char labelgw[39];
 
        snprintf(sendspace, MAXSEND, "Local label\tNetwork\t\t\t\tNexthop\n");
        writestr(s, sendspace);
@@ -523,12 +517,10 @@
                writestr(s, sendspace);
                snprintf(sendspace, MAXSEND, "%s", union_ntoa(&l->so_pref));
                writestr(s, sendspace);
-               if (l->p) {
-                       inet_ntop(l->p->address->sa_family,
-                           l->p->address->sa_data, labelgw, 39);
+               if (l->p)
                        snprintf(sendspace, MAXSEND, "\t%s:%d\n",
-                           labelgw, l->label);
-               } else
+                           satos(l->p->address), l->label);
+               else
                        snprintf(sendspace, MAXSEND, "\n");
                writestr(s, sendspace);
        }
diff -r aa0fa46b2b6b -r 36e0912495c4 usr.sbin/ldpd/ldp_peer.c
--- a/usr.sbin/ldpd/ldp_peer.c  Mon Jan 28 21:03:26 2013 +0000
+++ b/usr.sbin/ldpd/ldp_peer.c  Mon Jan 28 21:08:14 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_peer.c,v 1.6 2013/01/27 05:53:21 kefren Exp $ */
+/* $NetBSD: ldp_peer.c,v 1.7 2013/01/28 21:08:14 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -131,13 +131,15 @@
 
        SLIST_INSERT_HEAD(&ldp_peer_head, p, peers);
        p->address = (struct sockaddr *)malloc(padd->sa_len);
-       p->transport_address = (struct sockaddr *)malloc(padd->sa_len);
        memcpy(p->address, padd, padd->sa_len);
        memcpy(&p->ldp_id, ldp_id, sizeof(struct in_addr));
-       if (tradd != NULL)
+       if (tradd != NULL) {
+               p->transport_address = (struct sockaddr *)malloc(tradd->sa_len);
                memcpy(p->transport_address, tradd, tradd->sa_len);
-       else
+       } else {
+               p->transport_address = (struct sockaddr *)malloc(padd->sa_len);
                memcpy(p->transport_address, padd, padd->sa_len);
+       }
        p->holdtime=holdtime > ldp_holddown_time ? holdtime : ldp_holddown_time;
        p->socket = s;
        if (soc < 1) {
@@ -401,11 +403,10 @@
 print_bounded_addresses(struct ldp_peer * p)
 {
        struct ldp_peer_address *wp;
-       char abuf[512], peername[39];
+       char abuf[512];
 
-       inet_ntop(p->address->sa_family, p->address->sa_data, peername, 39);
        snprintf(abuf, sizeof(abuf), "Addresses bounded to peer %s: ",
-           peername);
+           satos(p->address));
        SLIST_FOREACH(wp, &p->ldp_peer_address_head, addresses) {
                strncat(abuf, satos(&wp->address.sa),
                        sizeof(abuf) -1);



Home | Main Index | Thread Index | Old Index