• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34 static sw_result HOWL_API
my_resolver(sw_discovery discovery,sw_discovery_oid oid,sw_uint32 interface_index,sw_const_string name,sw_const_string type,sw_const_string domain,sw_ipv4_address address,sw_port port,sw_octets text_record,sw_uint32 text_record_len,sw_opaque_t extra)35 my_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, "key = %s, data is %d bytes\n", key, oval_len);
68 		}
69 
70 		err = sw_text_record_iterator_fina(it);
71 		sw_check_okay(err, exit);
72 	}
73 
74 exit:
75 
76 	return err;
77 }
78 
79 
80 #if defined(WIN32)
81 int __cdecl
82 #else
83 int
84 #endif
main(int argc,char ** argv)85 main(
86 	int		argc,
87 	char	**	argv)
88 {
89 	sw_discovery		discovery;
90 	sw_discovery_oid	oid;
91 	sw_result			err;
92 
93 	err = sw_discovery_init(&discovery);
94 	sw_check_okay(err, exit);
95 
96 	if (argc != 3)
97 	{
98 		fprintf(stderr, "usage: mDNSResolve <name> <type>\n");
99 		return -1;
100 	}
101 
102 	err = sw_discovery_resolve(discovery, 0, argv[1], argv[2], "local.", my_resolver, NULL, &oid);
103 	sw_check_okay(err, exit);
104 
105 	err = sw_discovery_run(discovery);
106 	sw_check_okay(err, exit);
107 
108 exit:
109 
110 	return err;
111 }
112