gdp / apps / gdp-zcbrowse.c @ master
History | View | Annotate | Download (2.24 KB)
1 | 055d3009 | Eric Allman | /*
|
---|---|---|---|
2 | ** ----- BEGIN LICENSE BLOCK -----
|
||
3 | ** Applications for the Global Data Plane
|
||
4 | ** From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
|
||
5 | **
|
||
6 | c87dd166 | Eric Allman | ** Copyright (c) 2015-2019, Regents of the University of California.
|
7 | 6bd5476b | Eric Allman | ** All rights reserved.
|
8 | 055d3009 | Eric Allman | **
|
9 | 6bd5476b | Eric Allman | ** Permission is hereby granted, without written agreement and without
|
10 | ** license or royalty fees, to use, copy, modify, and distribute this
|
||
11 | ** software and its documentation for any purpose, provided that the above
|
||
12 | ** copyright notice and the following two paragraphs appear in all copies
|
||
13 | ** of this software.
|
||
14 | 055d3009 | Eric Allman | **
|
15 | 6bd5476b | Eric Allman | ** IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
|
16 | ** SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
|
||
17 | ** PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
|
||
18 | ** EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
19 | 055d3009 | Eric Allman | **
|
20 | 6bd5476b | Eric Allman | ** REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
21 | 055d3009 | Eric Allman | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
22 | 6bd5476b | Eric Allman | ** FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
|
23 | ** IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
|
||
24 | ** OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||
25 | ** OR MODIFICATIONS.
|
||
26 | 055d3009 | Eric Allman | ** ----- END LICENSE BLOCK -----
|
27 | */
|
||
28 | |||
29 | 728cb9ee | Nicholas Sun | #include <gdp/gdp_zc_client.h> |
30 | |||
31 | 8bfde4bc | Eric Allman | |
32 | 728cb9ee | Nicholas Sun | #include <stdio.h> |
33 | #include <stdlib.h> |
||
34 | #include <unistd.h> |
||
35 | |||
36 | 8bfde4bc | Eric Allman | int main(int argc, char **argv) |
37 | 58af2b0f | Nicholas Sun | { |
38 | 8bfde4bc | Eric Allman | #if GDP_OSCF_USE_ZEROCONF
|
39 | 58af2b0f | Nicholas Sun | zcinfo_t *i, **list; |
40 | c341565e | Nicholas Sun | char *zcstr;
|
41 | 728cb9ee | Nicholas Sun | |
42 | c341565e | Nicholas Sun | printf("start browse\n");
|
43 | 58af2b0f | Nicholas Sun | if (gdp_zc_scan())
|
44 | { |
||
45 | c341565e | Nicholas Sun | printf("getting info\n");
|
46 | /* always need to retrieve list */
|
||
47 | list = gdp_zc_get_infolist(); |
||
48 | 728cb9ee | Nicholas Sun | |
49 | c341565e | Nicholas Sun | /* you can access info as a linked list */
|
50 | 58af2b0f | Nicholas Sun | for (i = *list; i; i = i->info_next)
|
51 | { |
||
52 | c341565e | Nicholas Sun | printf("host:%s port: %d\n", i->address, i->port);
|
53 | } |
||
54 | 728cb9ee | Nicholas Sun | |
55 | c341565e | Nicholas Sun | /* or you can access info as a string */
|
56 | zcstr = gdp_zc_addr_str(list); |
||
57 | 58af2b0f | Nicholas Sun | if (zcstr)
|
58 | { |
||
59 | c341565e | Nicholas Sun | printf("list: %s\n", zcstr);
|
60 | /* need to free the string after you're done */
|
||
61 | free(zcstr); |
||
62 | 58af2b0f | Nicholas Sun | } |
63 | else
|
||
64 | { |
||
65 | c341565e | Nicholas Sun | printf("list fail\n");
|
66 | } |
||
67 | 728cb9ee | Nicholas Sun | |
68 | c341565e | Nicholas Sun | /* you always need to free the list after you're done */
|
69 | printf("freeing info\n");
|
||
70 | gdp_zc_free_infolist(list); |
||
71 | return 0; |
||
72 | 58af2b0f | Nicholas Sun | } |
73 | else
|
||
74 | { |
||
75 | c341565e | Nicholas Sun | return 1; |
76 | } |
||
77 | 8bfde4bc | Eric Allman | #else // GDP_OSCF_USE_ZEROCONF |
78 | fprintf(stderr, "gdp_zcbrowse: no Avahi available\n");
|
||
79 | return 1; |
||
80 | #endif // GDP_OSCF_USE_ZEROCONF |
||
81 | 728cb9ee | Nicholas Sun | } |
82 | c341565e | Nicholas Sun | |
83 | /* vim: set noexpandtab : */ |