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

 



We will use it for parsing disabled sockets families as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
---
 net/protocols.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/net/protocols.c b/net/protocols.c
index c4a4ae2..4331351 100644
--- a/net/protocols.c
+++ b/net/protocols.c
@@ -58,6 +58,19 @@ static const struct protocol protocols[] = {
 	{ "PF_VSOCK",        40 },
 };
 
+static const struct protocol *lookup_proto(const char *name, unsigned int proto)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(protocols); i++) {
+		if ((name && strcmp(name, protocols[i].name) == 0) ||
+		    (proto != -1u && protocols[i].proto == proto))
+			return &protocols[i];
+	}
+
+	return NULL;
+}
+
 const char * get_proto_name(unsigned int proto)
 {
 	unsigned int i;
@@ -70,33 +83,20 @@ const char * get_proto_name(unsigned int proto)
 
 void find_specific_proto(const char *protoarg)
 {
+	const struct protocol *p;
 	unsigned int i;
 
-	if (specific_proto == 0) {
-		/* we were passed a string */
-		for (i = 0; i < ARRAY_SIZE(protocols); i++) {
-			if (strcmp(protoarg, protocols[i].name) == 0) {
-				specific_proto = protocols[i].proto;
-				output(2, "Proto %s = %d\n", protoarg, specific_proto);
-				break;
-			}
-		}
-	} else {
-		/* we were passed a numeric arg. */
-		for (i = 0; i < ARRAY_SIZE(protocols); i++) {
-			if (specific_proto == protocols[i].proto)
-				break;
-		}
+	p = lookup_proto(protoarg, specific_proto ? : -1u);
+	if (p) {
+		specific_proto = p->proto;
+		output(2, "Using protocol %s (%u) for all sockets\n", p->name, p->proto);
+		return;
 	}
 
-	if (i > ARRAY_SIZE(protocols)) {
-		outputerr("Protocol unknown. Pass a numeric value [0-%d] or one of ", TRINITY_PF_MAX);
-		for (i = 0; i < ARRAY_SIZE(protocols); i++)
-			outputerr("%s ", protocols[i].name);
-		outputerr("\n");
-
-		exit(EXIT_FAILURE);
-	}
+	outputerr("Protocol unknown. Pass a numeric value [0-%d] or one of ", TRINITY_PF_MAX);
+	for (i = 0; i < ARRAY_SIZE(protocols); i++)
+		outputerr("%s ", protocols[i].name);
+	outputerr("\n");
 
-	output(2, "Using protocol %s (%u) for all sockets\n", protocols[i].name, protocols[i].proto);
+	exit(EXIT_FAILURE);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe trinity" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux