• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/avahi-0.6.31/avahi-compat-howl/samples/
1/*
2 * Copyright 2003, 2004, 2004 Porchdog Software. All rights reserved.
3 *
4 *	Redistribution and use in source and binary forms, with or without modification,
5 *	are permitted provided that the following conditions are met:
6 *
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.
12 *
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.
23 *
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.
27 */
28
29#include <howl.h>
30#include <salt/debug.h>
31#include <stdio.h>
32
33
34static sw_result HOWL_API
35my_resolver(
36				sw_discovery			discovery,
37				sw_discovery_oid		oid,
38				sw_uint32				interface_index,
39				sw_const_string		name,
40				sw_const_string		type,
41				sw_const_string		domain,
42				sw_ipv4_address		address,
43				sw_port					port,
44				sw_octets				text_record,
45				sw_uint32				text_record_len,
46				sw_opaque_t				extra)
47{
48	sw_text_record_iterator				it;
49	sw_int8									name_buf[16];
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];
53	sw_uint32								oval_len;
54	sw_result								err = SW_OKAY;
55
56	sw_discovery_cancel(discovery, oid);
57
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);
59
60	if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
61	{
62		err = sw_text_record_iterator_init(&it, text_record, text_record_len);
63		sw_check_okay(err, exit);
64
65		while (sw_text_record_iterator_next(it, key, oval, &oval_len) == SW_OKAY)
66		{
67			fprintf(stderr, "Txt: [%s]=[%s] - (%d bytes)\n", key, oval, oval_len);
68		}
69
70		err = sw_text_record_iterator_fina(it);
71		sw_check_okay(err, exit);
72	}
73
74exit:
75
76	return err;
77}
78
79
80static sw_result HOWL_API
81my_browser(
82				sw_discovery						discovery,
83				sw_discovery_oid					oid,
84				sw_discovery_browse_status		status,
85				sw_uint32							interface_index,
86				sw_const_string					name,
87				sw_const_string					type,
88				sw_const_string					domain,
89				sw_opaque_t							extra)
90{
91	sw_discovery_resolve_id rid;
92
93	switch (status)
94	{
95		case SW_DISCOVERY_BROWSE_INVALID:
96		{
97			fprintf(stderr, "browse reply: Invalid\n");
98		}
99		break;
100
101		case SW_DISCOVERY_BROWSE_RELEASE:
102		{
103			fprintf(stderr, "browse reply: Release\n");
104		}
105		break;
106
107		case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
108		{
109			fprintf(stderr, "browse reply: Add Domain\n");
110		}
111		break;
112
113		case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
114		{
115			fprintf(stderr, "browse reply: Add Default Domain\n");
116		}
117		break;
118
119		case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
120		{
121			fprintf(stderr, "browse reply: Remove Domain\n");
122		}
123		break;
124
125		case SW_DISCOVERY_BROWSE_ADD_SERVICE:
126		{
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)
129			{
130				fprintf(stderr, "resolve failed\n");
131			}
132		}
133		break;
134
135		case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
136		{
137			fprintf(stderr, "browse reply: Remove Service\n");
138			fprintf(stderr, "remove service: 0x%x %s %s %s\n", interface_index, name, type, domain);
139		}
140		break;
141
142		case SW_DISCOVERY_BROWSE_RESOLVED:
143		{
144			fprintf(stderr, "browse reply: Resolved\n");
145		}
146		break;
147	}
148
149	return SW_OKAY;
150}
151
152
153#if defined(WIN32)
154int __cdecl
155#else
156int
157#endif
158main(
159	int		argc,
160	char	**	argv)
161{
162	sw_discovery		discovery;
163	sw_discovery_oid	oid;
164	sw_result			err;
165
166	err = sw_discovery_init(&discovery);
167	sw_check_okay(err, exit);
168
169	if (argc != 2)
170	{
171		fprintf(stderr, "usage: mDNSBrowse <type>\n");
172		return -1;
173	}
174
175	err = sw_discovery_browse(discovery, 0, argv[1], NULL, my_browser, NULL, &oid);
176	sw_check_okay(err, exit);
177
178	err = sw_discovery_run(discovery);
179	sw_check_okay(err, exit);
180
181exit:
182
183	return err;
184}
185