[Openswan dev] [PATCH] printing IPv4 address on Big Endian

Vinay K Nallamothu vinay.nallamothu at gsecone.com
Sun Mar 27 16:07:31 CEST 2005


This patch uses addrtoa.
Patches generated against openswan-1.0.9 and openswan-2.3.1dr4

Thanks
Vinay

 pfkey_v2_build.c |    9 ++++-----
 pfkey_v2_parse.c |    6 +-----

======================================OPENSWAN-1.X====================================
diff -urN openswan-1.0.9/lib/pfkey_v2_build.c openswan-1.0.9-m/lib/pfkey_v2_build.c
--- openswan-1.0.9/lib/pfkey_v2_build.c	2003-11-17 04:52:48.000000000 +0530
+++ openswan-1.0.9-m/lib/pfkey_v2_build.c	2005-03-27 14:36:31.043378928 +0530
@@ -388,6 +388,7 @@
 	int error = 0;
 	int saddr_len = 0;
 	char ipaddr_txt[ADDRTOT_BUF + 6/*extra for port number*/];
+	char saddr[ADDRTOT_BUF];
 	struct sadb_address *pfkey_address = (struct sadb_address *)*pfkey_ext;
 	
 	DEBUGGING(
@@ -437,11 +438,9 @@
 			"pfkey_address_build: "
 			"found address family AF_INET.\n");
 		saddr_len = sizeof(struct sockaddr_in);
-		sprintf(ipaddr_txt, "%d.%d.%d.%d:%d"
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >>  0) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >>  8) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >> 16) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >> 24) & 0xFF
+		addrtoa(((struct sockaddr_in*)address)->sin_addr, 0, saddr, sizeof saddr);
+		sprintf(ipaddr_txt, "%s:%d"
+			, saddr
 			, ntohs(((struct sockaddr_in*)address)->sin_port));
 		break;
 	case AF_INET6:
diff -urN openswan-1.0.9/lib/pfkey_v2_parse.c openswan-1.0.9-m/lib/pfkey_v2_parse.c
--- openswan-1.0.9/lib/pfkey_v2_parse.c	2003-11-17 04:52:48.000000000 +0530
+++ openswan-1.0.9-m/lib/pfkey_v2_parse.c	2005-03-27 14:33:40.946237624 +0530
@@ -356,11 +356,7 @@
 			"found address family=%d, AF_INET.\n",
 			s->sa_family);
 		saddr_len = sizeof(struct sockaddr_in);
-		sprintf(ipaddr_txt, "%d.%d.%d.%d"
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >>  0) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >>  8) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >> 16) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >> 24) & 0xFF);
+		addrtoa(((struct sockaddr_in*)s)->sin_addr, 0, ipaddr_txt, sizeof ipaddr_txt);
 		DEBUGGING(PF_KEY_DEBUG_PARSE_STRUCT,
 			"pfkey_address_parse: "
 			"found address=%s.\n",

======================================OPENSWAN-2.X====================================
diff -urN openswan-2.3.1dr4/linux/net/ipsec/pfkey_v2_build.c openswan-2.3.1dr4-m/linux/net/ipsec/pfkey_v2_build.c
--- openswan-2.3.1dr4/linux/net/ipsec/pfkey_v2_build.c	2005-03-27 14:38:33.760723056 +0530
+++ openswan-2.3.1dr4-m/linux/net/ipsec/pfkey_v2_build.c	2005-03-27 14:43:51.073484184 +0530
@@ -411,6 +411,7 @@
 	int error = 0;
 	int saddr_len = 0;
 	char ipaddr_txt[ADDRTOT_BUF + 6/*extra for port number*/];
+	char saddr[ADDRTOT_BUF];
 	struct sadb_address *pfkey_address = (struct sadb_address *)*pfkey_ext;
 	
 	DEBUGGING(PF_KEY_DEBUG_BUILD,
@@ -457,11 +458,9 @@
 			"pfkey_address_build: "
 			"found address family AF_INET.\n");
 		saddr_len = sizeof(struct sockaddr_in);
-		sprintf(ipaddr_txt, "%d.%d.%d.%d:%d"
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >>  0) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >>  8) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >> 16) & 0xFF
-			, (((struct sockaddr_in*)address)->sin_addr.s_addr >> 24) & 0xFF
+		addrtoa(((struct sockaddr_in*)address)->sin_addr, 0, saddr, sizeof saddr);
+		sprintf(ipaddr_txt, "%s:%d"
+			, saddr
 			, ntohs(((struct sockaddr_in*)address)->sin_port));
 		break;
 	case AF_INET6:
diff -urN openswan-2.3.1dr4/linux/net/ipsec/pfkey_v2_parse.c openswan-2.3.1dr4-m/linux/net/ipsec/pfkey_v2_parse.c
--- openswan-2.3.1dr4/linux/net/ipsec/pfkey_v2_parse.c	2005-03-27 14:38:33.744725488 +0530
+++ openswan-2.3.1dr4-m/linux/net/ipsec/pfkey_v2_parse.c	2005-03-27 14:42:09.781882848 +0530
@@ -393,11 +393,7 @@
 	switch(s->sa_family) {
 	case AF_INET:
 		saddr_len = sizeof(struct sockaddr_in);
-		sprintf(ipaddr_txt, "%d.%d.%d.%d"
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >>  0) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >>  8) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >> 16) & 0xFF
-			, (((struct sockaddr_in*)s)->sin_addr.s_addr >> 24) & 0xFF);
+		addrtoa(((struct sockaddr_in*)s)->sin_addr, 0, ipaddr_txt, sizeof ipaddr_txt);
 		DEBUGGING(PF_KEY_DEBUG_PARSE_STRUCT,
 			  "pfkey_address_parse: "
 			  "found exttype=%u(%s) family=%d(AF_INET) address=%s proto=%u port=%u.\n",

======================================================================================

On Tue, 2005-03-22 at 14:36 +0530, Vinay K Nallamothu wrote:
> On Mon, 2005-03-21 at 19:19 -0800, H. Peter Anvin wrote:
> > Vinay K Nallamothu wrote:
> > > Hi,
> > >
> > > The following patches fix correct printing of IPv4 address on big endian
> > > machines.
> > >
> > > I am attaching separate patches for openswan-1.X and openswan-2.X
> > >
> >
> > inet_ntoa()?
> >
> > 	-hpa
> AFAIK, the same code goes in to klips also where inet_ntoa/inet_ntop are
> not available.
> 
> -Vinay
> 
> _______________________________________________
> Dev mailing list
> Dev at openswan.org
> http://lists.openswan.org/mailman/listinfo/dev



More information about the Dev mailing list