user.h user.c \
unicode.h unicode.c \
unidata.h unidata.c \
- utf8.h utf8.c \
vacopy.h \
vector.c vector.h \
wav.h wav.c \
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
-/** @file lib/addr.c Socket address support */
+/** @file lib/addr.c
+ * @brief Socket address support */
#include <config.h>
#include "types.h"
/*
* This file is part of DisOrder.
- * Copyright (C) 2004 Richard Kettlewell
+ * Copyright (C) 2004, 2007 Richard Kettlewell
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
+/** @file lib/addr.h
+ * @brief Socket address support */
#ifndef ADDR_H
#define ADDR_H
#include <signal.h>
#include <sys/wait.h>
#include <stddef.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
-#include "utf8.h"
#include "mem.h"
#include "log.h"
#include "vector.h"
#include "printf.h"
#include "basen.h"
#include "split.h"
+#include "configuration.h"
+#include "addr.h"
static int tests, errors;
static int fail_first;
check_integer(hash_count(h), 0);
}
+static void test_addr(void) {
+ struct stringlist a;
+ const char *s[2];
+ struct addrinfo *ai;
+ char *name;
+ const struct sockaddr_in *sin;
+
+ static const struct addrinfo pref = {
+ AI_PASSIVE,
+ PF_INET,
+ SOCK_STREAM,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+ };
+
+ a.n = 1;
+ a.s = (char **)s;
+ s[0] = "smtp";
+ ai = get_address(&a, &pref, &name);
+ insist(ai != 0);
+ check_integer(ai->ai_family, PF_INET);
+ check_integer(ai->ai_socktype, SOCK_STREAM);
+ check_integer(ai->ai_protocol, IPPROTO_TCP);
+ check_integer(ai->ai_addrlen, sizeof(struct sockaddr_in));
+ sin = (const struct sockaddr_in *)ai->ai_addr;
+ check_integer(sin->sin_family, AF_INET);
+ check_integer(sin->sin_addr.s_addr, 0);
+ check_integer(ntohs(sin->sin_port), 25);
+ check_string(name, "host * service smtp");
+
+ a.n = 2;
+ s[0] = "localhost";
+ s[1] = "nntp";
+ ai = get_address(&a, &pref, &name);
+ insist(ai != 0);
+ check_integer(ai->ai_family, PF_INET);
+ check_integer(ai->ai_socktype, SOCK_STREAM);
+ check_integer(ai->ai_protocol, IPPROTO_TCP);
+ check_integer(ai->ai_addrlen, sizeof(struct sockaddr_in));
+ sin = (const struct sockaddr_in *)ai->ai_addr;
+ check_integer(sin->sin_family, AF_INET);
+ check_integer(ntohl(sin->sin_addr.s_addr), 0x7F000001);
+ check_integer(ntohs(sin->sin_port), 119);
+ check_string(name, "host localhost service nntp");
+}
+
int main(void) {
mem_init();
fail_first = !!getenv("FAIL_FIRST");
insist('a' == 0x61);
insist('z' == 0x7A);
/* addr.c */
+ test_addr();
/* asprintf.c */
/* authhash.c */
/* basen.c */
+++ /dev/null
-/*
- * This file is part of DisOrder
- * Copyright (C) 2005 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#include <config.h>
-#include "types.h"
-
-#include "utf8.h"
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-fill-column:79
-End:
-*/
+++ /dev/null
-/*
- * This file is part of DisOrder
- * Copyright (C) 2004, 2005 Richard Kettlewell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-#ifndef UTF8_H
-#define UTF8_H
-
-#define PARSE_UTF8(S,C,E) do { \
- if((unsigned char)*S < 0x80) \
- C = *S++; \
- else if((unsigned char)*S <= 0xDF) { \
- C = (*S++ & 0x1F) << 6; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F); \
- if(C < 0x80) { E; } \
- } else if((unsigned char)*S <= 0xEF) { \
- C = (*S++ & 0x0F) << 12; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F) << 6; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F); \
- if(C < 0x800 \
- || (C >= 0xD800 && C <= 0xDFFF)) { \
- E; \
- } \
- } else if((unsigned char)*S <= 0xF7) { \
- C = (*S++ & 0x07) << 18; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F) << 12; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F) << 6; \
- if((*S & 0xC0) != 0x80) { E; } \
- C |= (*S++ & 0x3F); \
- if(C < 0x10000 || C > 0x10FFFF) { E; } \
- } else { \
- E; \
- } \
-} while(0)
-
-#endif /* UTF8_h */
-
-/*
-Local Variables:
-c-basic-offset:2
-comment-column:40
-End:
-*/