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

Vinay K Nallamothu vinay.nallamothu at gsecone.com
Mon Mar 21 16:53:03 CET 2005


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

Thanks & Regards
Vinay

 pfkey_v2_build.c |   10 ++++++----
 pfkey_v2_parse.c |   10 ++++++----

==============================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-21 16:01:20.000000000 +0530
@@ -389,6 +389,7 @@
 	int saddr_len = 0;
 	char ipaddr_txt[ADDRTOT_BUF + 6/*extra for port number*/];
 	struct sadb_address *pfkey_address = (struct sadb_address *)*pfkey_ext;
+	unsigned int saddr;
 	
 	DEBUGGING(
 		"pfkey_address_build: "
@@ -437,11 +438,12 @@
 			"pfkey_address_build: "
 			"found address family AF_INET.\n");
 		saddr_len = sizeof(struct sockaddr_in);
+		saddr = ntohl(((struct sockaddr_in*)address)->sin_addr.s_addr); 
 		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
+			, (saddr >>  24) & 0xFF
+			, (saddr >>  16) & 0xFF
+			, (saddr >>   8) & 0xFF
+			, (saddr >>   0) & 0xFF
 			, 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-21 16:35:17.430782304 +0530
@@ -297,6 +297,7 @@
 	struct sadb_address *pfkey_address = (struct sadb_address *)pfkey_ext;
 	struct sockaddr* s = (struct sockaddr*)((char*)pfkey_address + sizeof(*pfkey_address));
 	char ipaddr_txt[ADDRTOT_BUF];
+	unsigned int saddr;
 	
 	DEBUGGING(PF_KEY_DEBUG_PARSE_FLOW,
 		"pfkey_address_parse:enter\n");
@@ -356,11 +357,12 @@
 			"found address family=%d, AF_INET.\n",
 			s->sa_family);
 		saddr_len = sizeof(struct sockaddr_in);
+		saddr = ntohl(((struct sockaddr_in*)s)->sin_addr.s_addr); 
 		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);
+			, (saddr >>  24) & 0xFF
+			, (saddr >>  16) & 0xFF
+			, (saddr >>   8) & 0xFF
+			, (saddr >>   0) & 0xFF);
 		DEBUGGING(PF_KEY_DEBUG_PARSE_STRUCT,
 			"pfkey_address_parse: "
 			"found address=%s.\n",
==============================================OPENSWAN-2.X=======================================
diff -urN openswan-2.3.1dr2/linux/net/ipsec/pfkey_v2_build.c openswan-2.3.1dr2-m/linux/net/ipsec/pfkey_v2_build.c
--- openswan-2.3.1dr2/linux/net/ipsec/pfkey_v2_build.c	2004-10-03 06:56:36.000000000 +0530
+++ openswan-2.3.1dr2-m/linux/net/ipsec/pfkey_v2_build.c	2005-03-21 16:24:14.166613784 +0530
@@ -412,6 +412,7 @@
 	int saddr_len = 0;
 	char ipaddr_txt[ADDRTOT_BUF + 6/*extra for port number*/];
 	struct sadb_address *pfkey_address = (struct sadb_address *)*pfkey_ext;
+	unsigned long saddr;
 	
 	DEBUGGING(PF_KEY_DEBUG_BUILD,
 		"pfkey_address_build: "
@@ -457,11 +458,12 @@
 			"pfkey_address_build: "
 			"found address family AF_INET.\n");
 		saddr_len = sizeof(struct sockaddr_in);
+		saddr = ntohl(((struct sockaddr_in*)address)->sin_addr.s_addr); 
 		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
+			, (saddr >>  24) & 0xFF
+			, (saddr >>  16) & 0xFF
+			, (saddr >>   8) & 0xFF
+			, (saddr >>   0) & 0xFF
 			, ntohs(((struct sockaddr_in*)address)->sin_port));
 		break;
 	case AF_INET6:
diff -urN openswan-2.3.1dr2/linux/net/ipsec/pfkey_v2_parse.c openswan-2.3.1dr2-m/linux/net/ipsec/pfkey_v2_parse.c
--- openswan-2.3.1dr2/linux/net/ipsec/pfkey_v2_parse.c	2005-01-26 06:20:35.000000000 +0530
+++ openswan-2.3.1dr2-m/linux/net/ipsec/pfkey_v2_parse.c	2005-03-21 16:23:54.326629920 +0530
@@ -342,6 +342,7 @@
 	struct sadb_address *pfkey_address = (struct sadb_address *)pfkey_ext;
 	struct sockaddr* s = (struct sockaddr*)((char*)pfkey_address + sizeof(*pfkey_address));
 	char ipaddr_txt[ADDRTOT_BUF];
+	unsigned int saddr;
 	
 	/* sanity checks... */
 	if(!pfkey_address) {
@@ -393,11 +394,12 @@
 	switch(s->sa_family) {
 	case AF_INET:
 		saddr_len = sizeof(struct sockaddr_in);
+		saddr = ntohl(((struct sockaddr_in*)s)->sin_addr.s_addr); 
 		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);
+			, (saddr >>  24) & 0xFF
+			, (saddr >>  16) & 0xFF
+			, (saddr >>   8) & 0xFF
+			, (saddr >>   0) & 0xFF);
 		DEBUGGING(PF_KEY_DEBUG_PARSE_STRUCT,
 			  "pfkey_address_parse: "
 			  "found exttype=%u(%s) family=%d(AF_INET) address=%s proto=%u port=%u.\n",




More information about the Dev mailing list