Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / apps / gdp-zcbrowse.c @ master

History | View | Annotate | Download (2.24 KB)

1
/*
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
**        Copyright (c) 2015-2019, Regents of the University of California.
7
**        All rights reserved.
8
**
9
**        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
**
15
**        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
**
20
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
21
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
**        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
**        ----- END LICENSE BLOCK -----
27
*/
28

    
29
#include <gdp/gdp_zc_client.h>
30

    
31

    
32
#include <stdio.h>
33
#include <stdlib.h>
34
#include <unistd.h>
35

    
36
int main(int argc, char **argv)
37
{
38
#if GDP_OSCF_USE_ZEROCONF
39
        zcinfo_t *i, **list;
40
        char *zcstr;
41

    
42
        printf("start browse\n");
43
        if (gdp_zc_scan())
44
        {
45
                printf("getting info\n");
46
                /* always need to retrieve list */
47
                list = gdp_zc_get_infolist();
48

    
49
                /* you can access info as a linked list */
50
                for (i = *list; i; i = i->info_next)
51
                {
52
                        printf("host:%s port: %d\n", i->address, i->port);
53
                }
54

    
55
                /* or you can access info as a string */
56
                zcstr = gdp_zc_addr_str(list);
57
                if (zcstr)
58
                {
59
                        printf("list: %s\n", zcstr);
60
                        /* need to free the string after you're done */
61
                        free(zcstr);
62
                }
63
                else
64
                {
65
                        printf("list fail\n");
66
                }
67

    
68
                /* 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
        }
73
        else
74
        {
75
                return 1;
76
        }
77
#else // GDP_OSCF_USE_ZEROCONF
78
        fprintf(stderr, "gdp_zcbrowse: no Avahi available\n");
79
        return 1;
80
#endif // GDP_OSCF_USE_ZEROCONF
81
}
82

    
83
/* vim: set noexpandtab : */