~ubuntu-branches/ubuntu/hardy/apache2/hardy-proposed

« back to all changes in this revision

Viewing changes to srclib/apr/test/testsockets.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Fritsch
  • Date: 2008-01-17 20:27:56 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080117202756-hv38rjknhwa2ilwi
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
/* On recent Linux systems, whilst IPv6 is always supported by glibc,
60
60
 * socket(AF_INET6, ...) calls will fail with EAFNOSUPPORT if the
61
61
 * "ipv6" kernel module is not loaded.  */
62
 
#ifdef EAFNOSUPPORT
 
62
#if defined(WSAEAFNOSUPPORT)
 
63
#define V6_NOT_ENABLED(e) ((e) == APR_OS_START_SYSERR + WSAEAFNOSUPPORT)
 
64
#elif defined(SOCEAFNOSUPPORT)
 
65
#define V6_NOT_ENABLED(e) ((e) == APR_OS_START_SYSERR + SOCEAFNOSUPPORT)
 
66
#elif defined(EAFNOSUPPORT)
63
67
#define V6_NOT_ENABLED(e) ((e) == EAFNOSUPPORT)
 
68
#elif !APR_HAVE_IPV6
 
69
#define V6_NOT_ENABLED(e) (1)
64
70
#else
65
 
#define V6_NOT_ENABLED(e) (0)
 
71
#error MUST have an EAFNOSUPPORT class of error code to enable IPv6!
66
72
#endif
67
73
 
 
74
#if APR_HAVE_IPV6
68
75
static void tcp6_socket(abts_case *tc, void *data)
69
76
{
70
 
#if APR_HAVE_IPV6
71
77
    apr_status_t rv;
72
78
    apr_socket_t *sock = NULL;
73
79
 
79
85
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
80
86
    ABTS_PTR_NOTNULL(tc, sock);
81
87
    apr_socket_close(sock);
82
 
#else
83
 
    ABTS_NOT_IMPL(tc, "IPv6");
84
 
#endif
85
88
}
86
89
 
87
90
static void udp6_socket(abts_case *tc, void *data)
88
91
{
89
 
#if APR_HAVE_IPV6
90
92
    apr_status_t rv;
91
93
    apr_socket_t *sock = NULL;
92
94
 
98
100
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
99
101
    ABTS_PTR_NOTNULL(tc, sock);
100
102
    apr_socket_close(sock);
101
 
#else
102
 
    ABTS_NOT_IMPL(tc, "IPv6");
 
103
}
103
104
#endif
104
 
}
105
105
 
106
 
static void sendto_receivefrom_helper(abts_case *tc, const char *addr, int family)
 
106
static void sendto_receivefrom_helper(abts_case *tc, const char *addr,
 
107
                                      int family)
107
108
{
108
109
    apr_status_t rv;
109
110
    apr_socket_t *sock = NULL;
117
118
    apr_size_t len = 30;
118
119
 
119
120
    rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p);
 
121
#if APR_HAVE_IPV6
 
122
    if ((family == APR_INET6) && V6_NOT_ENABLED(rv)) {
 
123
        ABTS_NOT_IMPL(tc, "IPv6 not enabled");
 
124
        return;
 
125
    }
 
126
#endif
120
127
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
121
128
    if (rv != APR_SUCCESS)
122
129
        return;
148
155
    len = STRLEN;
149
156
    rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len);
150
157
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
151
 
    ABTS_INT_EQUAL(tc, STRLEN, len);
 
158
    ABTS_SIZE_EQUAL(tc, STRLEN, len);
 
159
 
 
160
    /* fill the "from" sockaddr with a random address from another
 
161
     * family to ensure that recvfrom sets it up properly. */
 
162
#if APR_HAVE_IPV6
 
163
    if (family == APR_INET)
 
164
        rv = apr_sockaddr_info_get(&from, "3ffE:816e:abcd:1234::1",
 
165
                                   APR_INET6, 4242, 0, p);
 
166
    else
 
167
#else
 
168
        rv = apr_sockaddr_info_get(&from, "127.1.2.3", APR_INET, 4242, 0, p);
 
169
#endif
 
170
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
152
171
 
153
172
    len = 80;
154
173
    rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len);
155
174
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
156
 
    ABTS_INT_EQUAL(tc, STRLEN, len);
 
175
    ABTS_SIZE_EQUAL(tc, STRLEN, len);
157
176
    ABTS_STR_EQUAL(tc, "APR_INET, SOCK_DGRAM", recvbuf);
158
177
 
159
178
    apr_sockaddr_ip_get(&ip_addr, from);
167
186
 
168
187
static void sendto_receivefrom(abts_case *tc, void *data)
169
188
{
 
189
    int failed;
 
190
    sendto_receivefrom_helper(tc, "127.0.0.1", APR_INET);
 
191
    failed = tc->failed; tc->failed = 0;
 
192
    ABTS_TRUE(tc, !failed);
 
193
}
 
194
 
170
195
#if APR_HAVE_IPV6
 
196
static void sendto_receivefrom6(abts_case *tc, void *data)
 
197
{
 
198
    int failed;
171
199
    sendto_receivefrom_helper(tc, "::1", APR_INET6);
 
200
    failed = tc->failed; tc->failed = 0;
 
201
    ABTS_TRUE(tc, !failed);
 
202
}
172
203
#endif
173
 
    sendto_receivefrom_helper(tc, "127.0.0.1", APR_INET);
174
 
}
175
204
 
176
205
static void socket_userdata(abts_case *tc, void *data)
177
206
{
205
234
    abts_run_test(suite, tcp_socket, NULL);
206
235
    abts_run_test(suite, udp_socket, NULL);
207
236
 
 
237
    abts_run_test(suite, sendto_receivefrom, NULL);
 
238
 
 
239
#if APR_HAVE_IPV6
208
240
    abts_run_test(suite, tcp6_socket, NULL);
209
241
    abts_run_test(suite, udp6_socket, NULL);
210
242
 
211
 
    abts_run_test(suite, sendto_receivefrom, NULL);
 
243
    abts_run_test(suite, sendto_receivefrom6, NULL);
 
244
#endif
212
245
 
213
246
    abts_run_test(suite, socket_userdata, NULL);
214
247