From owner-p4-projects@FreeBSD.ORG Mon Aug 20 17:35:29 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 79DBE16A4A1; Mon, 20 Aug 2007 17:35:29 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D10E16A49C for ; Mon, 20 Aug 2007 17:35:29 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2C1E413C4FD for ; Mon, 20 Aug 2007 17:35:29 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7KHZTU9059340 for ; Mon, 20 Aug 2007 17:35:29 GMT (envelope-from fli@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7KHZS3P059335 for perforce@freebsd.org; Mon, 20 Aug 2007 17:35:28 GMT (envelope-from fli@FreeBSD.org) Date: Mon, 20 Aug 2007 17:35:28 GMT Message-Id: <200708201735.l7KHZS3P059335@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to fli@FreeBSD.org using -f From: Fredrik Lindberg To: Perforce Change Reviews Cc: Subject: PERFORCE change 125441 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Aug 2007 17:35:29 -0000 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); }