lwtest.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000-2002, 2004, 2007, 2008, 2012, 2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: lwtest.c,v 1.32 2008/04/02 02:37:42 marka Exp $ */
#include <config.h>
#include <assert.h>
#include <stdlib.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:getipnodebyaddr(%s) failed: %d\n",
fails++;
return;
} else {
printf("I:getipnodebyaddr(%s) returned not found\n",
address);
fails++;
return;
}
} else {
printf("I:getipnodebyaddr(%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 %lub, "
"expected %ub\n", name,
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:getnameinfo(%s) returned %s, "
fails++;
return;
printf("I:getnameinfo(%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, "ip6.int.example");
test_gethostbyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "ip6.arpa.example");
test_getipnodebyaddr("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "ip6.int.example");
test_getipnodebyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "ip6.arpa.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, "ip6.int.example");
test_getnameinfo("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
AF_INET6, "ip6.arpa.example");
test_getnameinfo("1122:3344:5566:7788:99aa:bbcc:ddee:ff00",
AF_INET6, "dname.example1");
if (fails == 0)
printf("I:ok\n");
return (fails);
}