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

Subversion Repositories openrisc_me

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      tests/addr_test.c
4
//
5
//      Test network "address" functions
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2002-03-19
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
 
32
// Networking library test code
33
 
34
#include <network.h>
35
#include <cyg/infra/testcase.h>
36
 
37
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
38
static char stack[STACK_SIZE];
39
static cyg_thread thread_data;
40
static cyg_handle_t thread_handle;
41
 
42
void
43
pexit(char *s)
44
{
45
    char msg[256];
46
 
47
    diag_sprintf(msg, "%s: %s", s, strerror(errno));
48
    CYG_TEST_FAIL_FINISH(msg);
49
}
50
 
51
static void
52
walk_addrs(struct addrinfo *ai, char *title)
53
{
54
    char addr_buf[256];
55
 
56
    diag_printf("INFO: %s\n", title);
57
    while (ai) {
58
        _inet_ntop(ai->ai_addr, addr_buf, sizeof(addr_buf));
59
        diag_printf("INFO: Family: %d, Socket: %d, Addr: %s, Port: %d\n",
60
                    ai->ai_family, ai->ai_socktype, addr_buf, _inet_port(ai->ai_addr));
61
        ai = ai->ai_next;
62
    }
63
}
64
 
65
int
66
net_test(CYG_ADDRWORD data)
67
{
68
    int err;
69
    struct addrinfo *addrs, hints;
70
 
71
    bzero(&hints, sizeof(hints));
72
    hints.ai_family = PF_UNSPEC;
73
    hints.ai_socktype = SOCK_STREAM;
74
    hints.ai_flags = AI_PASSIVE;
75
    if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) {
76
        diag_printf("<ERROR> can't getaddrinfo(): %s\n", gai_strerror(err));
77
        pexit("getaddrinfo");
78
    }
79
    walk_addrs(addrs, "all passive");
80
    bzero(&hints, sizeof(hints));
81
    hints.ai_family = PF_UNSPEC;
82
    hints.ai_socktype = SOCK_STREAM;
83
    hints.ai_flags = 0;
84
    if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) {
85
        diag_printf("<ERROR> can't getaddrinfo(): %s\n", gai_strerror(err));
86
        pexit("getaddrinfo");
87
    }
88
    walk_addrs(addrs, "all active");
89
    bzero(&hints, sizeof(hints));
90
    hints.ai_family = PF_INET;
91
    hints.ai_socktype = SOCK_STREAM;
92
    hints.ai_flags = AI_PASSIVE;
93
    if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) {
94
        diag_printf("<ERROR> can't getaddrinfo(): %s\n", gai_strerror(err));
95
        pexit("getaddrinfo");
96
    }
97
    walk_addrs(addrs, "IPv4 passive");
98
#ifdef CYGPKG_NET_INET6
99
    bzero(&hints, sizeof(hints));
100
    hints.ai_family = PF_INET6;
101
    hints.ai_socktype = SOCK_STREAM;
102
    hints.ai_flags = AI_PASSIVE;
103
    if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) {
104
        diag_printf("<ERROR> can't getaddrinfo(): %s\n", gai_strerror(err));
105
        pexit("getaddrinfo");
106
    }
107
    walk_addrs(addrs, "IPv6 passive");
108
#endif
109
    bzero(&hints, sizeof(hints));
110
    hints.ai_family = PF_UNSPEC;
111
    hints.ai_socktype = SOCK_DGRAM;
112
    hints.ai_flags = AI_PASSIVE;
113
    if ((err = getaddrinfo(NULL, "snmp", &hints, &addrs)) != EAI_NONE) {
114
        diag_printf("<ERROR> can't getaddrinfo(): %s\n", gai_strerror(err));
115
        pexit("getaddrinfo");
116
    }
117
    walk_addrs(addrs, "all snmp/udp");
118
    CYG_TEST_PASS_FINISH("Address [library] test OK");
119
}
120
void
121
cyg_start(void)
122
{
123
    // Create a main thread, so we can run the scheduler and have time 'pass'
124
    cyg_thread_create(10,                // Priority - just a number
125
                      net_test,          // entry
126
                      0,                 // entry parameter
127
                      "Network test",    // Name
128
                      &stack[0],         // Stack
129
                      STACK_SIZE,        // Size
130
                      &thread_handle,    // Handle
131
                      &thread_data       // Thread data structure
132
            );
133
    cyg_thread_resume(thread_handle);  // Start it
134
    cyg_scheduler_start();
135
}

powered by: WebSVN 2.1.0

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