Ticket #198: avahi-utils.patch

File avahi-utils.patch, 9.4 kB (added by Arthur_van_Hoff@Dell.com, 9 months ago)

Patch to add -i option to specify an interface to avahi command line tools.

  • avahi-resolve.c

    old new  
    5656    int verbose; 
    5757    Command command; 
    5858    AvahiProtocol proto; 
     59    AvahiIfIndex interface; 
    5960} Config; 
    6061 
    6162static AvahiSimplePoll *simple_poll = NULL; 
     
    163164              "    -n --name            Resolve host name\n" 
    164165              "    -a --address         Resolve address\n" 
    165166              "    -v --verbose         Enable verbose mode\n" 
     167          "    -i --interface=INTF  Interface on which to publish\n" 
    166168              "    -6                   Lookup IPv6 address\n" 
    167169              "    -4                   Lookup IPv4 address\n"), 
    168170            argv0, strstr(argv0, "host-name") ? "[-n]" : "-n", 
     
    177179        { "version",        no_argument,       NULL, 'V' }, 
    178180        { "name",           no_argument,       NULL, 'n' }, 
    179181        { "address",        no_argument,       NULL, 'a' }, 
     182        { "interface",      required_argument, NULL, 'i' }, 
    180183        { "verbose",        no_argument,       NULL, 'v' }, 
    181184        { NULL, 0, NULL, 0 } 
    182185    }; 
     
    186189    c->command = strstr(argv0, "address") ? COMMAND_RESOLVE_ADDRESS : (strstr(argv0, "host-name") ? COMMAND_RESOLVE_HOST_NAME : COMMAND_UNSPEC); 
    187190    c->proto = AVAHI_PROTO_UNSPEC; 
    188191    c->verbose = 0; 
     192    c->interface = AVAHI_IF_UNSPEC; 
    189193 
    190     while ((o = getopt_long(argc, argv, "hVnav46", long_options, NULL)) >= 0) { 
     194    while ((o = getopt_long(argc, argv, "hVnav46i:", long_options, NULL)) >= 0) { 
    191195 
    192196        switch(o) { 
    193197            case 'h': 
     
    211215            case '6': 
    212216                c->proto = AVAHI_PROTO_INET6; 
    213217                break; 
     218            case 'i': 
     219        c->interface = if_nametoindex(optarg); 
     220        if (c->interface == 0) { 
     221            c->interface = atoi(optarg); 
     222        } 
     223        if (c->interface == 0) { 
     224            fprintf(stderr, _("Invalid interface: %s\n"), optarg); 
     225            return -1; 
     226        } 
     227        break; 
    214228            default: 
    215229                return -1; 
    216230        } 
     
    297311 
    298312                if (config.command == COMMAND_RESOLVE_HOST_NAME) { 
    299313 
    300                     if (!(avahi_host_name_resolver_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, argv[i], config.proto, 0, host_name_resolver_callback, NULL))) { 
     314                    if (!(avahi_host_name_resolver_new(client, config.interface, AVAHI_PROTO_UNSPEC, argv[i], config.proto, 0, host_name_resolver_callback, NULL))) { 
    301315                        fprintf(stderr, _("Failed to create host name resolver: %s\n"), avahi_strerror(avahi_client_errno(client))); 
    302316                        goto fail; 
    303317                    } 
     
    312326                        goto fail; 
    313327                    } 
    314328 
    315                     if (!(avahi_address_resolver_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, &a, 0, address_resolver_callback, NULL))) { 
     329                    if (!(avahi_address_resolver_new(client, config.interface, AVAHI_PROTO_UNSPEC, &a, 0, address_resolver_callback, NULL))) { 
    316330                        fprintf(stderr, _("Failed to create address resolver: %s\n"), avahi_strerror(avahi_client_errno(client))); 
    317331                        goto fail; 
    318332                    } 
  • avahi-browse.c

    old new  
    7373#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    7474    int no_db_lookup; 
    7575#endif 
     76    AvahiIfIndex interface; 
    7677} Config; 
    7778 
    7879typedef struct ServiceInfo ServiceInfo; 
     
    351352 
    352353    if (!(b = avahi_service_browser_new( 
    353354              client, 
    354               AVAHI_IF_UNSPEC
     355              c->interface
    355356              AVAHI_PROTO_UNSPEC, 
    356357              stype, 
    357358              domain, 
     
    418419 
    419420    if (!(b = avahi_service_type_browser_new( 
    420421              client, 
    421               AVAHI_IF_UNSPEC
     422              c->interface
    422423              AVAHI_PROTO_UNSPEC, 
    423424              c->domain, 
    424425              0, 
     
    492493 
    493494    if (!(b = avahi_domain_browser_new( 
    494495              client, 
    495               AVAHI_IF_UNSPEC
     496              c->interface
    496497              AVAHI_PROTO_UNSPEC, 
    497498              c->domain, 
    498499              AVAHI_DOMAIN_BROWSER_BROWSE, 
     
    638639              "    -c --cache           Terminate after dumping all entries from the cache\n" 
    639640              "    -l --ignore-local    Ignore local services\n" 
    640641              "    -r --resolve         Resolve services found\n" 
     642          "    -i --interface=INTF  Interface which to browse\n" 
    641643              "    -f --no-fail         Don't fail if the daemon is not available\n" 
    642644              "    -p --parsable        Output in parsable format\n"), 
    643645#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
     
    664666        { "ignore-local",   no_argument,       NULL, 'l' }, 
    665667        { "resolve",        no_argument,       NULL, 'r' }, 
    666668        { "no-fail",        no_argument,       NULL, 'f' }, 
    667         { "parsable",      no_argument,       NULL, 'p' }, 
     669        { "interface",      required_argument, NULL, 'i' }, 
     670        { "parsable",       no_argument,       NULL, 'p' }, 
    668671#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    669672        { "no-db-lookup",   no_argument,       NULL, 'k' }, 
    670673        { "dump-db",        no_argument,       NULL, 'b' }, 
     
    683686        c->no_fail = 
    684687        c->parsable = 0; 
    685688    c->domain = c->stype = NULL; 
     689    c->interface = AVAHI_IF_UNSPEC; 
    686690 
    687691#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    688692    c->no_db_lookup = 0; 
    689693#endif 
    690694 
    691     while ((o = getopt_long(argc, argv, "hVd:avtclrDfp
     695    while ((o = getopt_long(argc, argv, "hVd:avtclrDfpi:
    692696#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    693697                            "kb" 
    694698#endif 
     
    732736            case 'p': 
    733737                c->parsable = 1; 
    734738                break; 
     739            case 'i': 
     740        c->interface = if_nametoindex(optarg); 
     741        if (c->interface == 0) { 
     742            c->interface = atoi(optarg); 
     743        } 
     744        if (c->interface == 0) { 
     745            fprintf(stderr, _("Invalid interface: %s\n"), optarg); 
     746            return -1; 
     747        } 
     748        break; 
    735749#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    736750            case 'k': 
    737751                c->no_db_lookup = 1; 
  • avahi-publish.c

    old new  
    5757    uint16_t port; 
    5858    AvahiStringList *txt, *subtypes; 
    5959    AvahiAddress address; 
     60    AvahiIfIndex interface; 
    6061} Config; 
    6162 
    6263static AvahiSimplePoll *simple_poll = NULL; 
     
    132133 
    133134        assert(config->command == COMMAND_PUBLISH_SERVICE); 
    134135 
    135         if (avahi_entry_group_add_service_strlst(entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, config->host, config->port, config->txt) < 0) { 
     136        if (avahi_entry_group_add_service_strlst(entry_group, config->interface, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, config->host, config->port, config->txt) < 0) { 
    136137            fprintf(stderr, _("Failed to add service: %s\n"), avahi_strerror(avahi_client_errno(client))); 
    137138            return -1; 
    138139        } 
    139140 
    140141        for (i = config->subtypes; i; i = i->next) 
    141             if (avahi_entry_group_add_service_subtype(entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, (char*) i->text) < 0) { 
     142            if (avahi_entry_group_add_service_subtype(entry_group, config->interface, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, (char*) i->text) < 0) { 
    142143                fprintf(stderr, _("Failed to add subtype '%s': %s\n"), i->text, avahi_strerror(avahi_client_errno(client))); 
    143144                return -1; 
    144145            } 
     
    225226              "    -d --domain=DOMAIN   Domain to publish service in\n" 
    226227              "    -H --host=DOMAIN     Host where service resides\n" 
    227228              "       --subtype=SUBTYPE An additional subtype to register this service with\n" 
     229          "    -i --interface=INTF  Interface on which to publish\n" 
    228230              "    -f --no-fail         Don't fail if the daemon is not available\n"), 
    229231              argv0, strstr(argv0, "service") ? "[-s]" : "-s", 
    230232              argv0, strstr(argv0, "address") ? "[-a]" : "-a"); 
     
    245247        { "verbose",        no_argument,       NULL, 'v' }, 
    246248        { "domain",         required_argument, NULL, 'd' }, 
    247249        { "host",           required_argument, NULL, 'H' }, 
     250        { "interface",      required_argument, NULL, 'i' }, 
    248251        { "subtype",        required_argument, NULL, ARG_SUBTYPE}, 
    249252        { "no-fail",        no_argument,       NULL, 'f' }, 
    250253        { NULL, 0, NULL, 0 } 
     
    257260    c->host = c->name = c->domain = c->stype = NULL; 
    258261    c->port = 0; 
    259262    c->txt = c->subtypes = NULL; 
     263    c->interface = AVAHI_IF_UNSPEC; 
    260264 
    261     while ((o = getopt_long(argc, argv, "hVsavd:H:f", long_options, NULL)) >= 0) { 
     265    while ((o = getopt_long(argc, argv, "hVsavd:H:i:f", long_options, NULL)) >= 0) { 
    262266 
    263267        switch(o) { 
    264268            case 'h': 
     
    287291            case 'f': 
    288292                c->no_fail = 1; 
    289293                break; 
     294            case 'i': 
     295        c->interface = if_nametoindex(optarg); 
     296        if (c->interface == 0) { 
     297            c->interface = atoi(optarg); 
     298        } 
     299        if (c->interface == 0) { 
     300            fprintf(stderr, _("Invalid interface: %s\n"), optarg); 
     301            return -1; 
     302        } 
     303        break; 
    290304            case ARG_SUBTYPE: 
    291305                c->subtypes = avahi_string_list_add(c->subtypes, optarg); 
    292306                break;