[ofa-general] [PATCH] infiniband-diags/src/saquery.c: convert GID prints to use inet_ntop

Ira Weiny weiny2 at llnl.gov
Tue Jul 1 18:33:05 PDT 2008


>From 7a9131f07ffa29e509004fb9835a82eca93d3fac Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Tue, 1 Jul 2008 14:31:00 -0700
Subject: [PATCH] infiniband-diags/src/saquery.c: convert GID prints to use inet_ntop


Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/src/saquery.c |   97 +++++++++++++++-------------------------
 1 files changed, 36 insertions(+), 61 deletions(-)

diff --git a/infiniband-diags/src/saquery.c b/infiniband-diags/src/saquery.c
index 1594cad..922703f 100644
--- a/infiniband-diags/src/saquery.c
+++ b/infiniband-diags/src/saquery.c
@@ -237,32 +237,11 @@ static void dump_path_record(void *data)
 	       );
 }
 
-/**
- * str must be longer than 32 to hold the full gid.
- * len will be checked to ensure this.
- */
-static char *
-sprint_gid(ib_gid_t *gid, char *str, size_t len)
-{
-	int  i = 0;
-	char tmp[16];
-
-	assert(str != NULL);
-	assert(len > 32);
-
-	str[0] = '\0';
-	for (i = 0; i < 16; i++) {
-		sprintf(tmp, "%02X", gid->raw[i]);
-		strcat(str, tmp);
-	}
-
-	return (str);
-}
-
 static void dump_class_port_info(void *data)
 {
 	size_t GID_STR_LEN = 256;
 	char   gid_str[GID_STR_LEN];
+	char   gid_str2[GID_STR_LEN];
 	ib_class_port_info_t *class_port_info = data;
 
 	printf("SA ClassPortInfo:\n"
@@ -271,13 +250,13 @@ static void dump_class_port_info(void *data)
 	       "\t\tCapability mask..........0x%04X\n"
 	       "\t\tCapability mask 2........0x%08X\n"
 	       "\t\tResponse time value......0x%02X\n"
-	       "\t\tRedirect GID.............0x%s\n"
+	       "\t\tRedirect GID.............%s\n"
 	       "\t\tRedirect TC/SL/FL........0x%08X\n"
 	       "\t\tRedirect LID.............0x%04X\n"
 	       "\t\tRedirect PKey............0x%04X\n"
 	       "\t\tRedirect QP..............0x%08X\n"
 	       "\t\tRedirect QKey............0x%08X\n"
-	       "\t\tTrap GID.................0x%s\n"
+	       "\t\tTrap GID.................%s\n"
 	       "\t\tTrap TC/SL/FL............0x%08X\n"
 	       "\t\tTrap LID.................0x%04X\n"
 	       "\t\tTrap PKey................0x%04X\n"
@@ -289,13 +268,13 @@ static void dump_class_port_info(void *data)
 	       cl_ntoh16(class_port_info->cap_mask),
 	       ib_class_cap_mask2(class_port_info),
 	       ib_class_resp_time_val(class_port_info),
-	       sprint_gid(&(class_port_info->redir_gid), gid_str, GID_STR_LEN),
+	       inet_ntop(AF_INET6, &(class_port_info->redir_gid), gid_str, GID_STR_LEN),
 	       cl_ntoh32(class_port_info->redir_tc_sl_fl),
 	       cl_ntoh16(class_port_info->redir_lid),
 	       cl_ntoh16(class_port_info->redir_pkey),
 	       cl_ntoh32(class_port_info->redir_qp),
 	       cl_ntoh32(class_port_info->redir_qkey),
-	       sprint_gid(&(class_port_info->trap_gid), gid_str, GID_STR_LEN),
+	       inet_ntop(AF_INET6, &(class_port_info->trap_gid), gid_str2, GID_STR_LEN),
 	       cl_ntoh32(class_port_info->trap_tc_sl_fl),
 	       cl_ntoh16(class_port_info->trap_lid),
 	       cl_ntoh16(class_port_info->trap_pkey),
@@ -326,20 +305,20 @@ static void dump_portinfo_record(void *data)
 
 static void dump_multicast_group_record(void *data)
 {
+	size_t GID_STR_LEN = 256;
+	char   gid_str[GID_STR_LEN];
 	ib_member_rec_t *p_mcmr = data;
 	uint8_t sl;
 	ib_member_get_sl_flow_hop(p_mcmr->sl_flow_hop, &sl, NULL, NULL);
 	printf("MCMemberRecord group dump:\n"
-	       "\t\tMGID....................0x%016" PRIx64 " : "
-	       "0x%016" PRIx64 "\n"
+	       "\t\tMGID....................%s\n"
 	       "\t\tMlid....................0x%X\n"
 	       "\t\tMtu.....................0x%X\n"
 	       "\t\tpkey....................0x%X\n"
 	       "\t\tRate....................0x%X\n"
 	       "\t\tSL......................0x%X\n"
 	       "",
-	       cl_ntoh64( p_mcmr->mgid.unicast.prefix ),
-	       cl_ntoh64( p_mcmr->mgid.unicast.interface_id ),
+	       inet_ntop(AF_INET6, p_mcmr->mgid.raw, gid_str, GID_STR_LEN),
 	       cl_ntoh16( p_mcmr->mlid ),
 	       p_mcmr->mtu,
 	       cl_ntoh16( p_mcmr->pkey ),
@@ -350,8 +329,10 @@ static void dump_multicast_group_record(void *data)
 
 static void dump_multicast_member_record(void *data)
 {
+	size_t GID_STR_LEN = 256;
+	char   gid_str[GID_STR_LEN];
+	char   gid_str2[GID_STR_LEN];
 	ib_member_rec_t *p_mcmr = data;
-	uint64_t gid_prefix = cl_ntoh64( p_mcmr->port_gid.unicast.prefix );
 	uint64_t gid_interface_id = cl_ntoh64( p_mcmr->port_gid.unicast.interface_id );
 	uint16_t mlid = cl_ntoh16( p_mcmr->mlid );
 	int      i = 0;
@@ -371,29 +352,26 @@ static void dump_multicast_member_record(void *data)
 
 	if (requested_name) {
 		if (strtol(requested_name, NULL, 0) == mlid) {
-			printf("\t\tPortGid.................0x%016" PRIx64 " : "
-			       "0x%016" PRIx64 " (%s)\n",
-			       gid_prefix,
-			       gid_interface_id,
+			printf("\t\tPortGid.................%s (%s)\n",
+				inet_ntop(AF_INET6, p_mcmr->port_gid.raw,
+					gid_str, GID_STR_LEN),
 			       node_name
 			      );
 		}
 	} else {
 		printf("MCMemberRecord member dump:\n"
-		       "\t\tMGID....................0x%016" PRIx64 " : "
-		       "0x%016" PRIx64 "\n"
+		       "\t\tMGID....................%s\n"
 		       "\t\tMlid....................0x%X\n"
-		       "\t\tPortGid.................0x%016" PRIx64 " : "
-		       "0x%016" PRIx64 "\n"
+		       "\t\tPortGid.................%s\n"
 		       "\t\tScopeState..............0x%X\n"
 		       "\t\tProxyJoin...............0x%X\n"
 		       "\t\tNodeDescription.........%s\n"
 		       "",
-		       cl_ntoh64( p_mcmr->mgid.unicast.prefix ),
-		       cl_ntoh64( p_mcmr->mgid.unicast.interface_id ),
+		       inet_ntop(AF_INET6, p_mcmr->mgid.raw, gid_str,
+				GID_STR_LEN),
 		       cl_ntoh16( p_mcmr->mlid ),
-		       gid_prefix,
-		       gid_interface_id,
+		       inet_ntop(AF_INET6, p_mcmr->port_gid.raw,
+				gid_str2, GID_STR_LEN),
 		       p_mcmr->scope_state,
 		       p_mcmr->proxy_join,
 		       node_name
@@ -403,6 +381,8 @@ static void dump_multicast_member_record(void *data)
 
 static void dump_service_record(void *data)
 {
+	size_t GID_STR_LEN = 256;
+	char   gid_str[GID_STR_LEN];
 	char buf_service_key[35];
 	char buf_service_name[65];
 	ib_service_record_t *p_sr = data;
@@ -430,8 +410,7 @@ static void dump_service_record(void *data)
 
 	printf("ServiceRecord dump:\n"
 	       "\t\tServiceID...............0x%016" PRIx64 "\n"
-	       "\t\tServiceGID..............0x%016" PRIx64 " : "
-	       "0x%016" PRIx64 "\n"
+	       "\t\tServiceGID..............%s\n"
 	       "\t\tServiceP_Key............0x%X\n"
 	       "\t\tServiceLease............0x%X\n"
 	       "\t\tServiceKey..............%s\n"
@@ -468,8 +447,7 @@ static void dump_service_record(void *data)
 	       "\t\tServiceData64.2.........0x%016" PRIx64 "\n"
 	       "",
 	       cl_ntoh64( p_sr->service_id ),
-	       cl_ntoh64( p_sr->service_gid.unicast.prefix ),
-	       cl_ntoh64( p_sr->service_gid.unicast.interface_id ),
+	       inet_ntop(AF_INET6, p_sr->service_gid.raw, gid_str, GID_STR_LEN),
 	       cl_ntoh16( p_sr->service_pkey ),
 	       cl_ntoh32( p_sr->service_lease ),
 	       buf_service_key,
@@ -501,6 +479,9 @@ static void dump_service_record(void *data)
 
 static void dump_inform_info_record(void *data)
 {
+	size_t GID_STR_LEN = 256;
+	char   gid_str[GID_STR_LEN];
+	char   gid_str2[GID_STR_LEN];
 	ib_inform_info_record_t *p_iir = data;
 	uint32_t qpn;
 	uint8_t  resp_time_val;
@@ -510,11 +491,10 @@ static void dump_inform_info_record(void *data)
 	if (p_iir->inform_info.is_generic) {
 		printf("InformInfoRecord dump:\n"
 		       "\t\tRID\n"
-		       "\t\tSubscriberGID...........0x%016" PRIx64 " : "
-		       "0x%016" PRIx64 "\n"
+		       "\t\tSubscriberGID...........%s\n"
 		       "\t\tSubscriberEnum..........0x%X\n"
 		       "\t\tInformInfo dump:\n"
-		       "\t\tgid.....................0x%016" PRIx64 " : 0x%016" PRIx64 "\n"
+		       "\t\tgid.....................%s\n"
 		       "\t\tlid_range_begin.........0x%X\n"
 		       "\t\tlid_range_end...........0x%X\n"
 		       "\t\tis_generic..............0x%X\n"
@@ -525,11 +505,9 @@ static void dump_inform_info_record(void *data)
 		       "\t\tresp_time_val...........0x%X\n"
 		       "\t\tnode_type...............0x%06X\n"
 		       "",
-		       cl_ntoh64( p_iir->subscriber_gid.unicast.prefix ),
-		       cl_ntoh64( p_iir->subscriber_gid.unicast.interface_id ),
+		       inet_ntop(AF_INET6, p_iir->subscriber_gid.raw, gid_str, GID_STR_LEN),
 		       cl_ntoh16( p_iir->subscriber_enum ),
-		       cl_ntoh64( p_iir->inform_info.gid.unicast.prefix ),
-		       cl_ntoh64( p_iir->inform_info.gid.unicast.interface_id ),
+		       inet_ntop(AF_INET6, p_iir->inform_info.gid.raw, gid_str2, GID_STR_LEN),
 		       cl_ntoh16( p_iir->inform_info.lid_range_begin ),
 		       cl_ntoh16( p_iir->inform_info.lid_range_end ),
 		       p_iir->inform_info.is_generic,
@@ -543,11 +521,10 @@ static void dump_inform_info_record(void *data)
 	} else {
 		printf("InformInfoRecord dump:\n"
 		       "\t\tRID\n"
-		       "\t\tSubscriberGID...........0x%016" PRIx64 " : "
-		       "0x%016" PRIx64 "\n"
+		       "\t\tSubscriberGID...........%s\n"
 		       "\t\tSubscriberEnum..........0x%X\n"
 		       "\t\tInformInfo dump:\n"
-		       "\t\tgid.....................0x%016" PRIx64 " : 0x%016" PRIx64 "\n"
+		       "\t\tgid.....................%s\n"
 		       "\t\tlid_range_begin.........0x%X\n"
 		       "\t\tlid_range_end...........0x%X\n"
 		       "\t\tis_generic..............0x%X\n"
@@ -558,11 +535,9 @@ static void dump_inform_info_record(void *data)
 		       "\t\tresp_time_val...........0x%X\n"
 		       "\t\tvendor_id...............0x%06X\n"
 		       "",
-		       cl_ntoh64( p_iir->subscriber_gid.unicast.prefix ),
-		       cl_ntoh64( p_iir->subscriber_gid.unicast.interface_id ),
+		       inet_ntop(AF_INET6, p_iir->subscriber_gid.raw, gid_str, GID_STR_LEN),
 		       cl_ntoh16( p_iir->subscriber_enum ),
-		       cl_ntoh64( p_iir->inform_info.gid.unicast.prefix ),
-		       cl_ntoh64( p_iir->inform_info.gid.unicast.interface_id ),
+		       inet_ntop(AF_INET6, p_iir->inform_info.gid.raw, gid_str2, GID_STR_LEN),
 		       cl_ntoh16( p_iir->inform_info.lid_range_begin ),
 		       cl_ntoh16( p_iir->inform_info.lid_range_end ),
 		       p_iir->inform_info.is_generic,
-- 
1.5.4.5




More information about the general mailing list