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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [ns/] [dns/] [current/] [tests/] [dns2.c] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    andrew.lunn
43
// Contributors: andrew.lunn, jskov
44
// Date:         2001-12-03
45
// Purpose:      
46
// Description:  Test DNS functions. Use the server and domain name the
47
//               DHCP server told us.
48
//              
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#include <network.h>
54
#include <netdb.h>
55
 
56
#include <arpa/inet.h>
57
 
58
#include <cyg/infra/testcase.h>
59
 
60
#ifdef CYGPKG_NET_DHCP
61
 
62
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
63
static char stack[STACK_SIZE];
64
static cyg_thread thread_data;
65
static cyg_handle_t thread_handle;
66
 
67
#define __string(_x) #_x
68
#define __xstring(_x) __string(_x)
69
 
70
#define USE_HARDCODED_DOMAIN 1
71
 
72
// Change the following if you aren't using BOOTP! It's almost certainly not right for you.
73
#define _DNS_IP            __xstring(172.16.1.254) // test farm host addr
74
#define _LOOKUP_FQDN       __xstring(b.root-servers.net.) // should stay the same?
75
#define _LOOKUP_DOMAINNAME __xstring(root-servers.net.)
76
#define _LOOKUP_HOSTNAME   __xstring(b)
77
#define _LOOKUP_IP         __xstring(128.9.0.107) // must be same as _LOOKUP_FQDN
78
#define _LOOKUP_IP_BAD     __xstring(10.0.0.0)
79
 
80
void
81
dns_test(cyg_addrword_t p)
82
{
83
    struct in_addr addr;
84
    struct hostent *hent;
85
    char dn[256];
86
 
87
    CYG_TEST_INIT();
88
 
89
    init_all_network_interfaces();
90
 
91
    CYG_TEST_INFO("Starting dns2 test");
92
 
93
    getdomainname(dn,sizeof(dn));
94
    diag_printf("INFO:<DHCP said domain name is %s>\n",dn);
95
#ifndef USE_HARDCODED_DOMAIN
96
    // If not hard-coded we can't tell what it's _meant_ to be
97
    CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)),
98
                   "DHCP got the wrong domainname");
99
#endif //ifdef _LOOKUP_DOMAINNAME
100
 
101
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
102
    inet_aton(_LOOKUP_IP, &addr);
103
    hent = gethostbyname(_LOOKUP_FQDN);
104
    if (hent != NULL) {
105
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
106
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
107
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
108
        }
109
    } else {
110
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
111
    }
112
 
113
    /* Now just the hostname */
114
#ifdef USE_HARDCODED_DOMAIN
115
    // set the domain by hand if required.
116
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
117
#endif //ifdef _LOOKUP_DOMAINNAME
118
    hent = gethostbyname(_LOOKUP_HOSTNAME);
119
    if (hent != NULL) {
120
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
121
    } else {
122
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
123
    }
124
 
125
    CYG_TEST_FINISH("dns2 test completed");
126
}
127
 
128
void
129
cyg_start(void)
130
{
131
    // Create a main thread, so we can run the scheduler and have time 'pass'
132
    cyg_thread_create(10,                // Priority - just a number
133
                      dns_test,          // entry
134
                      0,                 // entry parameter
135
                      "DNS test",        // Name
136
                      &stack[0],         // Stack
137
                      STACK_SIZE,        // Size
138
                      &thread_handle,    // Handle
139
                      &thread_data       // Thread data structure
140
            );
141
    cyg_thread_resume(thread_handle);  // Start it
142
    cyg_scheduler_start();
143
}
144
 
145
#else // CYGPKG_NET_DHCP
146
 
147
externC void
148
cyg_start( void )
149
{
150
    CYG_TEST_INIT();
151
 
152
    CYG_TEST_NA("This test needs DHCP enabled");
153
}
154
 
155
#endif

powered by: WebSVN 2.1.0

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