2 * Copyright 2003, 2004, 2004 Porchdog Software. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
22 * OF THE POSSIBILITY OF SUCH DAMAGE.
24 * The views and conclusions contained in the software and documentation are those
25 * of the authors and should not be interpreted as representing official policies,
26 * either expressed or implied, of Porchdog Software.
30 #include <salt/debug.h>
34 static sw_result HOWL_API
36 sw_discovery discovery,
38 sw_uint32 interface_index,
41 sw_const_string domain,
42 sw_ipv4_address address,
44 sw_octets text_record,
45 sw_uint32 text_record_len,
48 sw_text_record_iterator it;
50 sw_int8 key[SW_TEXT_RECORD_MAX_LEN];
51 sw_int8 sval[SW_TEXT_RECORD_MAX_LEN];
52 sw_uint8 oval[SW_TEXT_RECORD_MAX_LEN];
54 sw_result err = SW_OKAY;
56 sw_discovery_cancel(discovery, oid);
58 fprintf(stderr, "resolve reply: 0x%x %s %s %s %s %d\n", interface_index, name, type, domain, sw_ipv4_address_name(address, name_buf, 16), port);
60 if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
62 err = sw_text_record_iterator_init(&it, text_record, text_record_len);
63 sw_check_okay(err, exit);
65 while (sw_text_record_iterator_next(it, key, oval, &oval_len) == SW_OKAY)
67 fprintf(stderr, "Txt: [%s]=[%s] - (%d bytes)\n", key, oval, oval_len);
70 err = sw_text_record_iterator_fina(it);
71 sw_check_okay(err, exit);
80 static sw_result HOWL_API
82 sw_discovery discovery,
84 sw_discovery_browse_status status,
85 sw_uint32 interface_index,
88 sw_const_string domain,
91 sw_discovery_resolve_id rid;
95 case SW_DISCOVERY_BROWSE_INVALID:
97 fprintf(stderr, "browse reply: Invalid\n");
101 case SW_DISCOVERY_BROWSE_RELEASE:
103 fprintf(stderr, "browse reply: Release\n");
107 case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
109 fprintf(stderr, "browse reply: Add Domain\n");
113 case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
115 fprintf(stderr, "browse reply: Add Default Domain\n");
119 case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
121 fprintf(stderr, "browse reply: Remove Domain\n");
125 case SW_DISCOVERY_BROWSE_ADD_SERVICE:
127 fprintf(stderr, "browse reply: Add Service 0x%x %s %s %s\n", interface_index, name, type, domain);
128 if (sw_discovery_resolve(discovery, interface_index, name, type, domain, my_resolver, NULL, &rid) != SW_OKAY)
130 fprintf(stderr, "resolve failed\n");
135 case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
137 fprintf(stderr, "browse reply: Remove Service\n");
138 fprintf(stderr, "remove service: 0x%x %s %s %s\n", interface_index, name, type, domain);
142 case SW_DISCOVERY_BROWSE_RESOLVED:
144 fprintf(stderr, "browse reply: Resolved\n");
162 sw_discovery discovery;
163 sw_discovery_oid oid;
166 err = sw_discovery_init(&discovery);
167 sw_check_okay(err, exit);
171 fprintf(stderr, "usage: mDNSBrowse <type>\n");
175 err = sw_discovery_browse(discovery, 0, argv[1], NULL, my_browser, NULL, &oid);
176 sw_check_okay(err, exit);
178 err = sw_discovery_run(discovery);
179 sw_check_okay(err, exit);