Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2007 17:35:28 GMT
From:      Fredrik Lindberg <fli@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125441 for review
Message-ID:  <200708201735.l7KHZS3P059335@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125441

Change 125441 by fli@fli_nexus on 2007/08/20 17:35:23

	- Add the ability to list names and resources.
	- Tweak the syntax a bit on database manipulation routines.

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/mdns/db.c#2 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdns/mdns.c#4 edit

Differences ...

==== //depot/projects/soc2007/fli-mdns_sd/mdns/db.c#2 (text+ko) ====

@@ -42,6 +42,7 @@
 enum {
 	DBCMD_ADD,
 	DBCMD_DEL,
+	DBCMD_LIST,
 };
 
 static int
@@ -203,6 +204,83 @@
 	return (0);
 }
 
+static void
+getres(struct mdns *m, unsigned int ifidx, char *ident)
+{
+	ssize_t rlen, i;
+	const char *class, *type;
+	struct mdns_res *mr;
+
+	rlen = mdns_db_res_list(m, ident, ifidx, &mr);
+	if (rlen < 0) {
+		printf("Failed to obtain a list of resources\n");
+		return;	
+	}
+
+	printf("Resources on identifier '%s'\n", ident);
+	for (i = 0; i < rlen; i++) {
+		class = mdns_ctoa(mr[i].mr_class);
+		type = mdns_ttoa(mr[i].mr_class, mr[i].mr_type);
+
+		printf("\t%d ", mr[i].mr_ttl);
+		if (class != NULL)
+			printf("%s ", class);
+		else
+			printf("%d ", mr[i].mr_class);
+
+		if (type != NULL)
+			printf("%s ", type);
+		else
+			printf("%d ", mr[i].mr_type);
+
+		printf("%ls", mr[i].mr_res);
+		if (mr[i].mr_ptr != NULL)
+			printf(" (pointer to '%s')", mr[i].mr_ptr);	
+
+		printf("\n");
+	}
+	mdns_db_res_freelist(mr, rlen);
+}
+
+static int
+dblist(struct mdns *m, unsigned int ifidx, char *ident)
+{
+	struct mdns_name *mn;
+	int len, i, flag;
+	char *p;
+
+	len = mdns_db_name_list(m, ident, ifidx, &mn);
+	if (len < 0) {
+		printf("Failed to obtain list of names\n");
+		return (EXIT_FAILURE);
+	}
+	else if (len == 0) {
+		printf("Identifier have no names assigned\n");
+		getres(m, ifidx, ident);
+		return (0);
+	}
+
+	p = NULL;
+	flag = 0;
+	for (i = 0; i < len; i++) {
+		if (p == NULL || strcmp(p, mn[i].mn_ident) != 0) {
+			if (i > 0)
+				getres(m, ifidx, mn[i-1].mn_ident);
+
+			p = mn[i].mn_ident;
+			flag = 1;
+			printf("Names on identifier '%s'\n", p);
+		}
+		printf("\t%ls", mn[i].mn_name);
+		if (mn[i].mn_ename != NULL)
+			printf(" (%ls)", mn[i].mn_ename);
+		printf("\n");
+
+	}
+	getres(m, ifidx, mn[i-1].mn_ident);
+	return (0);
+}
+
 int
 db(struct mdns *m, int argc, char *argv[])
 {
@@ -224,15 +302,18 @@
 
 	argc -= optind;
 	argv += optind;
-	if (argc < 4)
-		return (EXIT_FAILURE);
 
-	ident = argv[0];
+	if (argc < 2)
+		ident = NULL;
+	else
+		ident = argv[1];
 
-	if (strcasecmp(argv[1], "name") == 0)
+	if (strcasecmp(argv[0], "name") == 0 && ident != NULL)
 		error = dbname(m, ident, ifidx, argc - 2, argv + 2);
-	else if (strcasecmp(argv[1], "res") == 0)
+	else if (strcasecmp(argv[0], "res") == 0 && ident != NULL)
 		error = dbres(m, ident, ifidx, argc - 2, argv + 2);
+	else if (strcasecmp(argv[0], "list") == 0)
+		error = dblist(m, ifidx, ident);
 	else {
 		printf("No such sub-command '%s'\n", argv[1]);
 		return (EXIT_FAILURE);

==== //depot/projects/soc2007/fli-mdns_sd/mdns/mdns.c#4 (text+ko) ====

@@ -46,9 +46,10 @@
 	printf("%s query [-v] [-i ifnam] [-f family] [-w sec] "
 	    "[-c class] [-t type] name\n", exec);
 
-	printf("%s db [-i ifnam] `ident' name [-s] add|del `host'\n", exec);
-	printf("%s db [-i ifnam] `ident' res [-p] [-t ttl] add|del "
+	printf("%s db [-i ifnam] name `ident' [-s] add|del `host'\n", exec);
+	printf("%s db [-i ifnam] res `ident' [-p] [-t ttl] add|del "
 	    "`class' `type' `res'\n", exec);
+	printf("%s db -i ifnam list [ident]\n", exec);
 
 	printf("%s cache [-i ifnam] view|flush\n", exec);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708201735.l7KHZS3P059335>