Annotation of embedaddon/lighttpd/src/test_configfile.c, revision 1.1
1.1 ! misho 1: #include "configfile-glue.c"
! 2:
! 3: #include <assert.h>
! 4: #include <stdlib.h>
! 5: #include <stdio.h>
! 6:
! 7: const struct {
! 8: const char *string;
! 9: const char *rmtstr;
! 10: int rmtfamily;
! 11: int expect;
! 12: } rmtmask[] = {
! 13: { "1.0.0.1/1", "1.0.0.1", AF_INET, 1 }
! 14: ,{ "254.254.254.254/1", "254.0.0.1", AF_INET, 1 }
! 15: ,{ "254.254.254.252/31", "254.254.254.253", AF_INET, 1 }
! 16: ,{ "254.254.254.253/31", "254.254.254.254", AF_INET, 0 }
! 17: ,{ "254.254.254.253/32", "254.254.254.254", AF_INET, 0 }
! 18: ,{ "254.254.254.254/32", "254.254.254.254", AF_INET, 1 }
! 19: #ifdef HAVE_IPV6
! 20: ,{ "2001::/3", "2001::1", AF_INET6, 1 }
! 21: ,{ "2f01::/5", "2701::1", AF_INET6, 0 }
! 22: ,{ "2f01::/32", "2f01::1", AF_INET6, 1 }
! 23: ,{ "2f01::/32", "2f02::1", AF_INET6, 0 }
! 24: ,{ "2001::1/127", "2001::1", AF_INET6, 1 }
! 25: ,{ "2001::1/127", "2001::2", AF_INET6, 0 }
! 26: ,{ "2001::2/128", "2001::2", AF_INET6, 1 }
! 27: ,{ "2001::2/128", "2001::3", AF_INET6, 0 }
! 28: ,{ "1.0.0.1/1", "::ffff:1.0.0.1", AF_INET6, 1 }
! 29: ,{ "254.254.254.254/1", "::ffff:254.0.0.1", AF_INET6, 1 }
! 30: ,{ "254.254.254.252/31", "::ffff:254.254.254.253", AF_INET6, 1 }
! 31: ,{ "254.254.254.253/31", "::ffff:254.254.254.254", AF_INET6, 0 }
! 32: ,{ "254.254.254.253/32", "::ffff:254.254.254.254", AF_INET6, 0 }
! 33: ,{ "254.254.254.254/32", "::ffff:254.254.254.254", AF_INET6, 1 }
! 34: ,{ "::ffff:1.0.0.1/97", "1.0.0.1", AF_INET, 1 }
! 35: ,{ "::ffff:254.254.254.254/97", "254.0.0.1", AF_INET, 1 }
! 36: ,{ "::ffff:254.254.254.252/127", "254.254.254.253", AF_INET, 1 }
! 37: ,{ "::ffff:254.254.254.253/127", "254.254.254.254", AF_INET, 0 }
! 38: ,{ "::ffff:254.254.254.253/128", "254.254.254.254", AF_INET, 0 }
! 39: ,{ "::ffff:254.254.254.254/128", "254.254.254.254", AF_INET, 1 }
! 40: #endif
! 41: };
! 42:
! 43: static void test_configfile_addrbuf_eq_remote_ip_mask (void) {
! 44: int i, m;
! 45: buffer * const s = buffer_init();
! 46: char *slash;
! 47: sock_addr rmt;
! 48:
! 49: for (i = 0; i < (int)(sizeof(rmtmask)/sizeof(rmtmask[0])); ++i) {
! 50: #ifndef HAVE_INET_PTON
! 51: rmt.ipv4.sin_family = AF_INET;
! 52: rmt.ipv4.sin_addr.s_addr = inet_addr(rmtmask[i].rmtstr);
! 53: #else
! 54: if (rmtmask[i].rmtfamily == AF_INET) {
! 55: rmt.ipv4.sin_family = AF_INET;
! 56: inet_pton(AF_INET, rmtmask[i].rmtstr, &rmt.ipv4.sin_addr);
! 57: #ifdef HAVE_IPV6
! 58: } else if (rmtmask[i].rmtfamily == AF_INET6) {
! 59: rmt.ipv6.sin6_family = AF_INET6;
! 60: inet_pton(AF_INET6, rmtmask[i].rmtstr, &rmt.ipv6.sin6_addr);
! 61: #endif
! 62: } else {
! 63: continue;
! 64: }
! 65: #endif
! 66: buffer_copy_string(s, rmtmask[i].string);
! 67: slash = strchr(s->ptr,'/'); assert(slash);
! 68: m = config_addrbuf_eq_remote_ip_mask(NULL, s, slash, &rmt);
! 69: if (m != rmtmask[i].expect) {
! 70: fprintf(stderr, "failed assertion: %s %s %s\n",
! 71: rmtmask[i].string,
! 72: rmtmask[i].expect ? "==" : "!=",
! 73: rmtmask[i].rmtstr);
! 74: exit(-1);
! 75: }
! 76: }
! 77:
! 78: buffer_free(s);
! 79: }
! 80:
! 81: int main (void) {
! 82: test_configfile_addrbuf_eq_remote_ip_mask();
! 83:
! 84: return 0;
! 85: }
! 86:
! 87: /*
! 88: * stub functions (for linking)
! 89: */
! 90: void fd_close_on_exec(int fd) { UNUSED(fd); }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>