Tweak
This commit is contained in:
parent
16f0faf3ce
commit
8b2f04c2ea
112
testmdnsd.c
112
testmdnsd.c
@ -37,61 +37,93 @@
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mdns.h"
|
||||
#include "mdnsd.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// create host entries
|
||||
char *hostname = "some-random-host.local";
|
||||
void
|
||||
background()
|
||||
{
|
||||
int fd;
|
||||
|
||||
switch ((int)fork())
|
||||
{
|
||||
case -1:
|
||||
perror("fork");
|
||||
exit(1);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifdef TIOCNOTTY
|
||||
if (ioctl(fileno(stdin), TIOCNOTTY) == -1)
|
||||
perror("detach_console");
|
||||
#endif
|
||||
freopen("/dev/null", "r", stdin);
|
||||
|
||||
fd = open("/dev/null", O_WRONLY, 0666);
|
||||
dup2(fd, fileno(stdout));
|
||||
dup2(fd, fileno(stderr));
|
||||
close(fd);
|
||||
|
||||
setsid();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char hostname[0x100], ifname[0x100];
|
||||
struct hostent *hp;
|
||||
struct in_addr saddr;
|
||||
|
||||
if (gethostname(hostname, sizeof(hostname) - 1) == -1)
|
||||
{
|
||||
printf("Couldn't retrieve humax hostname.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(hp = gethostbyname(hostname)))
|
||||
{
|
||||
printf("Couldn't retrieve humax IP address.\n");
|
||||
return 1;
|
||||
}
|
||||
memmove((char *)&saddr.s_addr, (char *)hp->h_addr,
|
||||
sizeof(saddr.s_addr));
|
||||
printf("Hostname: %s (%s)\n", hostname, inet_ntoa(saddr));
|
||||
|
||||
struct mdnsd *svr = mdnsd_start();
|
||||
if (svr == NULL) {
|
||||
printf("mdnsd_start() error\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Started MDNS Service\n");
|
||||
|
||||
printf("mdnsd_start OK. press ENTER to add hostname & service\n");
|
||||
getchar();
|
||||
mdnsd_set_hostname(svr, hostname, saddr.s_addr);
|
||||
|
||||
mdnsd_set_hostname(svr, hostname, inet_addr("192.168.0.29"));
|
||||
|
||||
struct rr_entry *a2_e = NULL;
|
||||
a2_e = rr_create_a(create_nlabel(hostname), inet_addr("192.168.0.31"));
|
||||
mdnsd_add_rr(svr, a2_e);
|
||||
|
||||
struct rr_entry *aaaa_e = NULL;
|
||||
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET6;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
struct addrinfo* results;
|
||||
getaddrinfo(
|
||||
"fe80::e2f8:47ff:fe20:28e0",
|
||||
NULL,
|
||||
&hints,
|
||||
&results);
|
||||
struct sockaddr_in6* addr = (struct sockaddr_in6*)results->ai_addr;
|
||||
struct in6_addr v6addr = addr->sin6_addr;
|
||||
freeaddrinfo(results);
|
||||
|
||||
aaaa_e = rr_create_aaaa(create_nlabel(hostname), &v6addr);
|
||||
|
||||
mdnsd_add_rr(svr, aaaa_e);
|
||||
sprintf(ifname, "Humax Fox T2 (%s) Web Interface", hostname);
|
||||
|
||||
const char *txt[] = {
|
||||
"path=/mywebsite",
|
||||
NULL
|
||||
};
|
||||
struct mdns_service *svc = mdnsd_register_svc(svr, "My Website",
|
||||
"_http._tcp.local", 8080, NULL, txt);
|
||||
mdns_service_destroy(svc);
|
||||
"path=/",
|
||||
NULL
|
||||
};
|
||||
struct mdns_service *svc = mdnsd_register_svc(
|
||||
svr, ifname, "_http._tcp.local", 80,
|
||||
NULL, txt);
|
||||
//mdns_service_destroy(svc);
|
||||
|
||||
printf("added service and hostname. press ENTER to exit\n");
|
||||
getchar();
|
||||
printf("Registered name.\n");
|
||||
|
||||
mdnsd_stop(svr);
|
||||
for (;;)
|
||||
sleep(3600);
|
||||
|
||||
// mdnsd_stop(svr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user