lwtest.c revision 9fb7cdd126d59b724977c74844ad7cd537d8b2d1
/*
* Copyright (C) 2000, 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lwtest.c,v 1.21 2001/01/22 22:12:45 bwelling Exp $ */
#include <config.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
/*
* XXX getnameinfo errors, which don't appear to be standard.
*/
#define ENI_NOSERVNAME 1
#define ENI_NOHOSTNAME 2
#define ENI_MEMORY 3
#define ENI_SYSTEM 4
#define ENI_FAMILY 5
#define ENI_SALEN 6
#define ENI_NOSOCKET 7
static int fails = 0;
static void
if (val != 0) {
exit(1);
}
}
static unsigned char TESTSTRING[] =
"This is a test. This is only a test. !!!";
static lwres_context_t *ctx;
static void
test_noop(void) {
/*
* Now, parse it into a new structure.
*/
lwres_buffer_first(&b);
nooprequest2 = NULL;
nooprequest.datalength) == 0);
b.length = 0;
/*
* Now, parse it into a new structure.
*/
lwres_buffer_first(&b);
noopresponse.datalength) == 0);
b.length = 0;
}
static void
{
unsigned char addrbuf[16];
char outbuf[64];
unsigned int len;
&res);
fails++;
return;
}
if (ret == LWRES_R_SUCCESS) {
if (af == LWRES_ADDRTYPE_V4) {
len = 4;
} else {
len = 16;
}
fails++;
return;
}
break;
}
else
printf("I:gabn(%s) returned %s, expected %s\n",
fails++;
return;
}
}
}
static void
const char *name)
{
unsigned char addrbuf[16];
unsigned int len;
if (af == LWRES_ADDRTYPE_V4) {
len = 4;
} else {
len = 16;
}
fails++;
return;
}
printf("I:gnba(%s) returned %s, expected %s\n",
fails++;
return;
}
}
static void
unsigned char addrbuf[16];
int ret;
return;
else if (h_errno != HOST_NOT_FOUND) {
printf("I:gethostbyname(%s) failed: %s\n",
fails++;
return;
} else {
printf("I:gethostbyname(%s) returned not found\n",
name);
fails++;
return;
}
} else {
char outbuf[16];
printf("I:gethostbyname(%s) returned %s, "
fails++;
return;
}
}
}
static void
unsigned char addrbuf[16];
return;
else if (h_errno != HOST_NOT_FOUND) {
printf("I:gethostbyname(%s) failed: %s\n",
fails++;
return;
} else {
printf("I:gethostbyname(%s) returned not found\n",
name);
fails++;
return;
}
} else {
len = 4;
else
len = 16;
printf("I:gethostbyname(%s) returned wrong family\n",
name);
fails++;
return;
}
{
char outbuf[16];
printf("I:gethostbyname(%s) returned %s, "
fails++;
return;
}
}
}
static void
{
unsigned char addrbuf[16];
int error_num;
int flags = 0;
if (v4map)
flags |= AI_V4MAPPED;
if (all)
return;
else if (error_num != HOST_NOT_FOUND) {
printf("I:getipnodebyname(%s) failed: %d\n",
fails++;
return;
} else {
printf("I:getipnodebyname(%s) returned not found\n",
name);
fails++;
return;
}
} else {
len = 4;
else
len = 16;
printf("I:getipnodebyname(%s) returned wrong family\n",
name);
fails++;
return;
}
{
char outbuf[16];
printf("I:getipnodebyname(%s) returned %s, "
fails++;
return;
}
}
}
static void
char addrbuf[16];
len = 4;
else
len = 16;
return;
else if (h_errno != HOST_NOT_FOUND) {
printf("I:gethostbyaddr(%s) failed: %s\n",
fails++;
return;
} else {
printf("I:gethostbyaddr(%s) returned not found\n",
address);
fails++;
return;
}
} else {
printf("I:gethostbyname(%s) returned %s, "
fails++;
return;
}
}
}
static void
char addrbuf[16];
int error_num;
len = 4;
else
len = 16;
return;
else if (error_num != HOST_NOT_FOUND) {
printf("I:gethostbyaddr(%s) failed: %d\n",
fails++;
return;
} else {
printf("I:gethostbyaddr(%s) returned not found\n",
address);
fails++;
return;
}
} else {
printf("I:gethostbyname(%s) returned %s, "
fails++;
return;
}
}
}
static void
const char *address)
{
unsigned int len;
int ret;
unsigned char addrbuf[16];
} else {
if (v4ok)
else
}
if (ret != 0) {
return;
else if (ret != EAI_NODATA) {
printf("I:getaddrinfo(%s,%d,%d) failed: %s\n",
fails++;
return;
} else {
printf("I:getaddrinfo(%s,%d,%d) returned not found\n",
fails++;
return;
}
} else {
len = sizeof(struct sockaddr_in);
else
len = sizeof(struct sockaddr_in6);
printf("I:getaddrinfo(%s) returned wrong family\n",
name);
fails++;
return;
}
char outbuf[16];
printf("I:getaddrinfo(%s) returned %db, "
fails++;
return;
struct sockaddr_in *sin;
char outbuf[16];
printf("I:getaddrinfo(%s) returned %s, "
fails++;
return;
}
} else {
struct sockaddr_in6 *sin6;
{
char outbuf[16];
printf("I:getaddrinfo(%s) returned %s, "
fails++;
return;
}
}
}
}
static void
int ret;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
int salen;
char host[1025];
#ifdef LWRES_PLATFORM_HAVESALEN
#endif
} else {
#ifdef LWRES_PLATFORM_HAVESALEN
#endif
}
if (ret != 0) {
return;
else if (ret != ENI_NOHOSTNAME) {
printf("I:getnameinfo(%s) failed: %d\n",
fails++;
return;
} else {
printf("I:getnameinfo(%s) returned not found\n",
address);
fails++;
return;
}
} else {
printf("I:getaddrinfo(%s) returned %s, "
fails++;
return;
printf("I:getaddrinfo(%s) returned %s, expected %s\n",
fails++;
return;
}
}
}
static void
int should_pass)
{
int ret;
fails++;
return;
} else if (ret == 0 && should_pass == 0) {
printf("I:getrrsetbyname(%s, %d) unexpectedly succeeded\n",
fails++;
return;
} else if (ret != 0)
return;
printf("I:getrrsetbyname(%s, %d): got %d rr, expected %d\n",
fails++;
}
printf("I:getrrsetbyname(%s, %d): got %d sig, expected %d\n",
fails++;
}
return;
}
int
main(void) {
lwres_udp_port = 9210;
test_noop();
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
"ipv4.example");
NULL);
test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cde0",
test_gnba("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
test_gnba("1123:4567:89ab:cdef:0123:4567:89ab:cde0",
test_gethostbyname2("b.example1.",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
AF_INET6);
test_getipnodebyname("b.example1.",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
AF_INET6, 0, 0);
test_getipnodebyname("a.example1.",
test_getipnodebyname("a.example1.",
test_getipnodebyname("b.example1.",
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
test_gethostbyaddr("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "nibble.example");
test_gethostbyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "bitstring.example");
test_getipnodebyaddr("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "nibble.example");
test_getipnodebyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "bitstring.example");
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff");
"eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff");
test_getnameinfo("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "nibble.example");
test_getnameinfo("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "bitstring.example");
test_getnameinfo("1122:3344:5566:7788:99aa:bbcc:ddee:ff00",
AF_INET6, "dname.example1");
if (fails == 0)
printf("I:ok\n");
return (fails);
}