Module Name:    src
Committed By:   kefren
Date:           Mon Jan 28 21:08:14 UTC 2013

Modified Files:
        src/usr.sbin/ldpd: ldp_command.c ldp_peer.c

Log Message:
Use satos instead of inet_ntop
Fix an alloc problem


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/ldp_command.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/ldp_peer.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/ldp_command.c
diff -u src/usr.sbin/ldpd/ldp_command.c:1.9 src/usr.sbin/ldpd/ldp_command.c:1.10
--- src/usr.sbin/ldpd/ldp_command.c:1.9	Mon Jan 28 20:06:52 2013
+++ src/usr.sbin/ldpd/ldp_command.c	Mon Jan 28 21:08:14 2013
@@ -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 @@ show_neighbours(int s, char *recvspace)
 	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 @@ static int
 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 @@ show_bindings(int s, char *recvspace)
 		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);
 	}

Index: src/usr.sbin/ldpd/ldp_peer.c
diff -u src/usr.sbin/ldpd/ldp_peer.c:1.6 src/usr.sbin/ldpd/ldp_peer.c:1.7
--- src/usr.sbin/ldpd/ldp_peer.c:1.6	Sun Jan 27 05:53:21 2013
+++ src/usr.sbin/ldpd/ldp_peer.c	Mon Jan 28 21:08:14 2013
@@ -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 @@ ldp_peer_new(const struct in_addr * ldp_
 
 	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 @@ void 
 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);

Reply via email to