Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / apps / gdp-zcpublish.c @ master

History | View | Annotate | Download (2.78 KB)

1 728cb9ee Nicholas Sun
/* vim: set ai sw=4 sts=4 ts=4 :*/
2
3
/*
4 c341565e Nicholas Sun
**        Advertise (publish) information about the GDP router
5 728cb9ee Nicholas Sun
**
6
**                This should really be done automatically by the GDP Router
7
**                itself, but for the time being this is a stop-gap.
8
**
9 055d3009 Eric Allman
**        ----- BEGIN LICENSE BLOCK -----
10
**        Applications for the Global Data Plane
11
**        From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
12
**
13 c87dd166 Eric Allman
**        Copyright (c) 2015-2019, Regents of the University of California.
14 6bd5476b Eric Allman
**        All rights reserved.
15 055d3009 Eric Allman
**
16 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
17
**        license or royalty fees, to use, copy, modify, and distribute this
18
**        software and its documentation for any purpose, provided that the above
19
**        copyright notice and the following two paragraphs appear in all copies
20
**        of this software.
21 055d3009 Eric Allman
**
22 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
23
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
24
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
25
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 055d3009 Eric Allman
**
27 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
28 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
30
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
31
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
32
**        OR MODIFICATIONS.
33 055d3009 Eric Allman
**        ----- END LICENSE BLOCK -----
34 728cb9ee Nicholas Sun
*/
35
36
37
#define GDP_PORT_DEFAULT                        8007
38
39
#include <gdp/gdp_zc_server.h>
40
41
#include <ep/ep.h>
42
#include <ep/ep_app.h>
43
44
#include <getopt.h>
45
#include <stdio.h>
46
#include <stdlib.h>
47
#include <sysexits.h>
48
#include <unistd.h>
49
50
51
void
52
usage(void)
53
{
54
        fprintf(stderr,
55
                        "Usage: %s [-i instance] [-p port]\n",
56
                        ep_app_getprogname());
57
        exit(EX_USAGE);
58
}
59
60
61
int
62
main(int argc, char **argv)
63
{
64 8bfde4bc Eric Allman
#if GDP_OSCF_USE_ZEROCONF
65 c341565e Nicholas Sun
        uint16_t port;
66 728cb9ee Nicholas Sun
        char *instance = NULL;
67
        char instancebuf[120];
68
        int opt;
69
70
        ep_lib_init(0);
71
        ep_adm_readparams("gdp");
72 c341565e Nicholas Sun
        port = ep_adm_getintparam("swarm.gdp.router.port", GDP_PORT_DEFAULT);
73 728cb9ee Nicholas Sun
        while ((opt = getopt(argc, argv, "i:p:")) > 0)
74
        {
75
                switch (opt)
76
                {
77
                case 'i':                                // instance name
78
                        instance = optarg;
79
                        break;
80
81
                case 'p':
82
                        port = atoi(optarg);
83
                        break;
84
85
                default:
86
                        usage();
87
                }
88
        }
89
90
        if (instance == NULL)
91
        {
92
                char hostname[64];
93
94
                if (gethostname(hostname, sizeof hostname) < 0)
95
                        ep_app_abort("cannot get host name");
96
                snprintf(instancebuf, sizeof instancebuf, "GDP Router on %s", hostname);
97
                instance = instancebuf;
98
        }
99
100 c341565e Nicholas Sun
        printf("advertise gdp '%s' on %d\n", instance, port);
101
        gdp_zc_publish(instance, port);
102
        printf("do other stuff here\n");
103
        sleep(300);
104
        printf("terminating...\n");
105
        return 0;
106 8bfde4bc Eric Allman
#else // GDP_OSCF_USE_ZEROCONF
107
        fprintf(stderr, "gdp-zcpublish: no Avahi available\n");
108
        return 1;
109
#endif // GDP_OSCF_USE_ZEROCONF
110 728cb9ee Nicholas Sun
}
111 c341565e Nicholas Sun
112
/* vim: set noexpandtab : */