OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [ns/] [dns/] [v2_0/] [tests/] [dns1.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      tests/dns1.c
4
//
5
//      Simple test of DNS client support
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    andrew.lunn
44
// Contributors: andrew.lunn, jskov
45
// Date:         2001-09-18
46
// Purpose:      
47
// Description:  Test DNS functions. Note that the _XXX defines below
48
//               control what addresses the test uses. These must be
49
//               changed to match the particular testing network in which
50
//               the test is to be run.
51
//              
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <network.h>
57
#include <netdb.h>
58
 
59
#include <arpa/inet.h>
60
 
61
#include <cyg/infra/testcase.h>
62
 
63
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
64
static char stack[STACK_SIZE];
65
static cyg_thread thread_data;
66
static cyg_handle_t thread_handle;
67
 
68
#define __string(_x) #_x
69
#define __xstring(_x) __string(_x)
70
 
71
// Change the following if you aren't using BOOTP! It's almost certainly not right for you.
72
#define _DNS_IP            __xstring(172.16.1.254) // test farm host addr
73
#define _LOOKUP_FQDN       __xstring(b.root-servers.net.) // should stay the same?
74
#define _LOOKUP_DOMAINNAME __xstring(root-servers.net.)
75
#define _LOOKUP_HOSTNAME   __xstring(b)
76
#define _LOOKUP_IP         __xstring(128.9.0.107) // must be same as _LOOKUP_FQDN
77
#define _LOOKUP_IP_BAD     __xstring(10.0.0.0)
78
 
79
void
80
dns_test(cyg_addrword_t p)
81
{
82
    struct in_addr addr;
83
    struct hostent *hent;
84
    char dn[256];
85
    int i;
86
 
87
    CYG_TEST_INIT();
88
 
89
    init_all_network_interfaces();
90
 
91
    CYG_TEST_INFO("Starting dns1 test");
92
 
93
    setdomainname(NULL,0);
94
 
95
    for (i=0; i<2; i++) {
96
        /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
97
        inet_aton(_LOOKUP_IP, &addr);
98
        hent = gethostbyname(_LOOKUP_FQDN);
99
        if (hent != NULL) {
100
            diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
101
            if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
102
                diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
103
            }
104
            break;
105
        } else {
106
            diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
107
            CYG_TEST_INFO("Retrying with explicit DNS server");
108
            CYG_TEST_INFO("Connecting to DNS at " _DNS_IP);
109
            inet_aton(_DNS_IP, &addr);
110
            CYG_TEST_CHECK(cyg_dns_res_init(&addr) == 0, "Failed to initialize resolver");
111
        }
112
    }
113
 
114
    /* Reverse lookup the _LOOKUP_IP addres, expect _LOOKUP_FQDN
115
       as the answer. */
116
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
117
    if (hent != NULL) {
118
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
119
        if (0 != strcmp(_LOOKUP_FQDN, hent->h_name)) {
120
          diag_printf("FAIL:<expected " _LOOKUP_IP " to be " _LOOKUP_FQDN ">\n");
121
        }
122
    } else {
123
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
124
    }
125
 
126
    /* This does not require a DNS lookup. Just turn the value into
127
       binary */
128
    hent = gethostbyname(_LOOKUP_IP);
129
    if (hent != NULL) {
130
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
131
    } else {
132
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
133
    }
134
 
135
    /* Reverse lookup an address this is not in the server. Expect a
136
       NULL back */
137
    inet_aton(_LOOKUP_IP_BAD, &addr);
138
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
139
    if (hent != NULL) {
140
        diag_printf("FAIL:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
141
    } else {
142
        diag_printf("PASS:<Asked for bad IP " _LOOKUP_IP_BAD ". No answer: %s>\n", hstrerror(h_errno));
143
    }
144
 
145
    /* Setup a domainname. We now don't have to use fully qualified
146
       domain names */
147
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
148
    getdomainname(dn, sizeof(dn));
149
    diag_printf("INFO:<Domainname is now %s>\n", dn);
150
 
151
    /* Make sure FQDN still work */
152
    hent = gethostbyname(_LOOKUP_FQDN);
153
    if (hent != NULL) {
154
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
155
    } else {
156
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
157
    }
158
 
159
    /* Now just the hostname */
160
    hent = gethostbyname(_LOOKUP_HOSTNAME);
161
    if (hent != NULL) {
162
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
163
    } else {
164
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
165
    }
166
 
167
    CYG_TEST_FINISH("dns1 test completed");
168
}
169
 
170
void
171
cyg_start(void)
172
{
173
    // Create a main thread, so we can run the scheduler and have time 'pass'
174
    cyg_thread_create(10,                // Priority - just a number
175
                      dns_test,          // entry
176
                      0,                 // entry parameter
177
                      "DNS test",        // Name
178
                      &stack[0],         // Stack
179
                      STACK_SIZE,        // Size
180
                      &thread_handle,    // Handle
181
                      &thread_data       // Thread data structure
182
            );
183
    cyg_thread_resume(thread_handle);  // Start it
184
    cyg_scheduler_start();
185
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.