"Fossies" - the Fresh Open Source Software Archive

Member "nss-mdns-0.10/src/mdns-test.c" (5 Aug 2005, 1784 Bytes) of package /linux/misc/dns/old/nss-mdns-0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* $Id: mdns-test.c 82 2005-08-05 23:51:50Z lennart $ */
    2 
    3 /***
    4   This file is part of nss-mdns.
    5  
    6   nss-mdns is free software; you can redistribute it and/or modify it
    7   under the terms of the GNU Lesser General Public License as
    8   published by the Free Software Foundation; either version 2 of the
    9   License, or (at your option) any later version.
   10  
   11   nss-mdns is distributed in the hope that it will be useful, but
   12   WITHOUT ANY WARRANTY; without even the implied warranty of
   13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   14   General Public License for more details.
   15  
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with nss-mdns; if not, write to the Free Software
   18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   19   USA.
   20 ***/
   21 
   22 #ifdef HAVE_CONFIG_H
   23 #include <config.h>
   24 #endif
   25 
   26 #include <arpa/inet.h>
   27 #include <stdio.h>
   28 #include <unistd.h>
   29 
   30 #include "query.h"
   31 
   32 static void ipv4_func(const ipv4_address_t *ipv4, void *userdata) {
   33     fprintf(stderr, "IPV4: %s\n", inet_ntoa(*(const struct in_addr*) &ipv4->address));
   34 }
   35 
   36 static void ipv6_func(const ipv6_address_t *ipv6, void *userdata) {
   37 }
   38 
   39 static void name_func(const char *name, void *userdata) {
   40     fprintf(stderr, "NAME: %s\n", name);
   41 }
   42 
   43 int main(int argc, char *argv[]) {
   44     int ret = 1, fd = -1;
   45     ipv4_address_t ipv4;
   46 
   47     if ((fd = mdns_open_socket()) < 0)
   48         goto finish;
   49 
   50     if (mdns_query_name(fd, argc > 1 ? argv[1] : "cocaine.local", &ipv4_func, &ipv6_func, NULL) < 0) 
   51         goto finish;
   52     
   53     ipv4.address = inet_addr(argc > 1 ? argv[1] : "192.168.50.1");
   54     
   55     if (mdns_query_ipv4(fd, &ipv4, name_func, NULL) < 0) 
   56         goto finish; 
   57     
   58     ret = 0;
   59 
   60 finish:
   61 
   62     if (fd >= 0)
   63         close(fd);
   64     
   65     return ret;
   66 }