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

Subversion Repositories openrisc

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      tests/dns2.c
4
//
5
//      Simple test of DNS client support. This time use DHCP
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-12-03
46
// Purpose:      
47
// Description:  Test DNS functions. Use the server and domain name the
48
//               DHCP server told us.
49
//              
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <network.h>
55
#include <netdb.h>
56
 
57
#include <arpa/inet.h>
58
 
59
#include <cyg/infra/testcase.h>
60
 
61
#ifdef CYGPKG_NET_DHCP
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
#define USE_HARDCODED_DOMAIN 1
72
 
73
// Change the following if you aren't using BOOTP! It's almost certainly not right for you.
74
#define _DNS_IP            __xstring(172.16.1.254) // test farm host addr
75
#define _LOOKUP_FQDN       __xstring(b.root-servers.net.) // should stay the same?
76
#define _LOOKUP_DOMAINNAME __xstring(root-servers.net.)
77
#define _LOOKUP_HOSTNAME   __xstring(b)
78
#define _LOOKUP_IP         __xstring(128.9.0.107) // must be same as _LOOKUP_FQDN
79
#define _LOOKUP_IP_BAD     __xstring(10.0.0.0)
80
 
81
void
82
dns_test(cyg_addrword_t p)
83
{
84
    struct in_addr addr;
85
    struct hostent *hent;
86
    char dn[256];
87
 
88
    CYG_TEST_INIT();
89
 
90
    init_all_network_interfaces();
91
 
92
    CYG_TEST_INFO("Starting dns2 test");
93
 
94
    getdomainname(dn,sizeof(dn));
95
    diag_printf("INFO:<DHCP said domain name is %s>\n",dn);
96
#ifndef USE_HARDCODED_DOMAIN
97
    // If not hard-coded we can't tell what it's _meant_ to be
98
    CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)),
99
                   "DHCP got the wrong domainname");
100
#endif //ifdef _LOOKUP_DOMAINNAME
101
 
102
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
103
    inet_aton(_LOOKUP_IP, &addr);
104
    hent = gethostbyname(_LOOKUP_FQDN);
105
    if (hent != NULL) {
106
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
107
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
108
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
109
        }
110
    } else {
111
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
112
    }
113
 
114
    /* Now just the hostname */
115
#ifdef USE_HARDCODED_DOMAIN
116
    // set the domain by hand if required.
117
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
118
#endif //ifdef _LOOKUP_DOMAINNAME
119
    hent = gethostbyname(_LOOKUP_HOSTNAME);
120
    if (hent != NULL) {
121
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
122
    } else {
123
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
124
    }
125
 
126
    CYG_TEST_FINISH("dns2 test completed");
127
}
128
 
129
void
130
cyg_start(void)
131
{
132
    // Create a main thread, so we can run the scheduler and have time 'pass'
133
    cyg_thread_create(10,                // Priority - just a number
134
                      dns_test,          // entry
135
                      0,                 // entry parameter
136
                      "DNS test",        // Name
137
                      &stack[0],         // Stack
138
                      STACK_SIZE,        // Size
139
                      &thread_handle,    // Handle
140
                      &thread_data       // Thread data structure
141
            );
142
    cyg_thread_resume(thread_handle);  // Start it
143
    cyg_scheduler_start();
144
}
145
 
146
#else // CYGPKG_NET_DHCP
147
 
148
externC void
149
cyg_start( void )
150
{
151
    CYG_TEST_INIT();
152
 
153
    CYG_TEST_NA("This test needs DHCP enabled");
154
}
155
 
156
#endif

powered by: WebSVN 2.1.0

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