summaryrefslogtreecommitdiffstats
path: root/src/mdns-test.c
blob: 81c062585a3edc9fb1d1eea46c82ec10b09f5504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* $Id$ */

/***
  This file is part of nss-mdns.
 
  nss-mdns is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.
 
  nss-mdns is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with nss-mdns; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>

#include "query.h"

static void ipv4_func(const ipv4_address_t *ipv4, void *userdata) {
    fprintf(stderr, "IPV4: %s\n", inet_ntoa(*(const struct in_addr*) &ipv4->address));
}

static void ipv6_func(const ipv6_address_t *ipv6, void *userdata) {
}

static void name_func(const char *name, void *userdata) {
    fprintf(stderr, "NAME: %s\n", name);
}

int main(int argc, char *argv[]) {
    int ret = 1, fd = -1;
    ipv4_address_t ipv4;

    if ((fd = mdns_open_socket()) < 0)
        goto finish;

    if (mdns_query_name(fd, argc > 1 ? argv[1] : "cocaine.local", &ipv4_func, &ipv6_func, NULL) < 0) 
        goto finish;
    
    ipv4.address = inet_addr(argc > 1 ? argv[1] : "192.168.50.1");
    
    if (mdns_query_ipv4(fd, &ipv4, name_func, NULL) < 0) 
        goto finish; 
    
    ret = 0;

finish:

    if (fd >= 0)
        close(fd);
    
    return ret;
}