mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
First pass at addrlength grossness cleanup. Man, this is ugly.
This commit is contained in:
@@ -27,15 +27,18 @@
|
||||
* controlled tree.
|
||||
*/
|
||||
|
||||
#ifdef NEED_AF_INET6
|
||||
#define AF_INET6 99
|
||||
#endif
|
||||
|
||||
#ifdef NEED_INET_NTOP
|
||||
char *isc_inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
const char *isc_inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
#else
|
||||
#define isc_inet_ntop inet_ntop
|
||||
#endif
|
||||
|
||||
#ifdef NEED_INET_PTON
|
||||
int
|
||||
isc_inet_pton(int af, const char *src, void *dst);
|
||||
int isc_inet_pton(int af, const char *src, void *dst);
|
||||
#else
|
||||
#define isc_inet_pton inet_pton
|
||||
#endif
|
||||
|
@@ -70,9 +70,11 @@
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
|
||||
static char rcsid[] = "$Id: inet_aton.c,v 1.2 1999/02/06 01:51:36 halley Exp $";
|
||||
static char rcsid[] = "$Id: inet_aton.c,v 1.3 1999/02/06 08:48:07 explorer Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
@@ -82,6 +84,7 @@ static char rcsid[] = "$Id: inet_aton.c,v 1.2 1999/02/06 01:51:36 halley Exp $";
|
||||
#include <ctype.h>
|
||||
|
||||
#include <isc/types.h>
|
||||
#include <isc/inet.h>
|
||||
|
||||
/*
|
||||
* Check whether "cp" is a valid ascii representation
|
||||
|
@@ -16,9 +16,11 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$Id: inet_ntop.c,v 1.2 1999/01/30 04:27:48 explorer Exp $";
|
||||
static char rcsid[] = "$Id: inet_ntop.c,v 1.3 1999/02/06 08:48:07 explorer Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -28,9 +30,12 @@ static char rcsid[] = "$Id: inet_ntop.c,v 1.2 1999/01/30 04:27:48 explorer Exp $
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <isc/inet.h>
|
||||
|
||||
#define NS_INT16SZ 2
|
||||
#define NS_IN6ADDRSZ 16
|
||||
|
||||
@@ -39,9 +44,9 @@ static char rcsid[] = "$Id: inet_ntop.c,v 1.2 1999/01/30 04:27:48 explorer Exp $
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static const char *isc_inet_ntop4(const u_char *src, char *dst, size_t size);
|
||||
static const char *isc_inet_ntop4(const unsigned char *src, char *dst, size_t size);
|
||||
#ifdef AF_INET6
|
||||
static const char *isc_inet_ntop6(const u_char *src, char *dst, size_t size);
|
||||
static const char *isc_inet_ntop6(const unsigned char *src, char *dst, size_t size);
|
||||
#endif
|
||||
|
||||
/* char *
|
||||
@@ -76,12 +81,12 @@ isc_inet_ntop(int af, const void *src, char *dst, size_t size)
|
||||
* `dst' (as a const)
|
||||
* notes:
|
||||
* (1) uses no statics
|
||||
* (2) takes a u_char* not an in_addr as input
|
||||
* (2) takes a unsigned char* not an in_addr as input
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static const char *
|
||||
isc_inet_ntop4(const u_char *src, char *dst, size_t size)
|
||||
isc_inet_ntop4(const unsigned char *src, char *dst, size_t size)
|
||||
{
|
||||
static const char *fmt = "%u.%u.%u.%u";
|
||||
char tmp[sizeof "255.255.255.255"];
|
||||
@@ -103,7 +108,7 @@ isc_inet_ntop4(const u_char *src, char *dst, size_t size)
|
||||
*/
|
||||
#ifdef AF_INET6
|
||||
static const char *
|
||||
isc_inet_ntop6(const u_char *src, char *dst, size_t size)
|
||||
isc_inet_ntop6(const unsigned char *src, char *dst, size_t size)
|
||||
{
|
||||
/*
|
||||
* Note that int32_t and int16_t need only be "at least" large enough
|
||||
@@ -114,7 +119,7 @@ isc_inet_ntop6(const u_char *src, char *dst, size_t size)
|
||||
*/
|
||||
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
|
||||
struct { int base, len; } best, cur;
|
||||
u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
|
||||
unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
|
||||
int i;
|
||||
|
||||
/*
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$Id: inet_pton.c,v 1.1 1999/02/02 00:37:09 halley Exp $";
|
||||
static char rcsid[] = "$Id: inet_pton.c,v 1.2 1999/02/06 08:48:07 explorer Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <config.h>
|
||||
@@ -25,11 +25,15 @@ static char rcsid[] = "$Id: inet_pton.c,v 1.1 1999/02/02 00:37:09 halley Exp $";
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <isc/inet.h>
|
||||
|
||||
#define NS_INT16SZ 2
|
||||
#define NS_INADDRSZ 4
|
||||
#define NS_IN6ADDRSZ 16
|
||||
@@ -39,8 +43,8 @@ static char rcsid[] = "$Id: inet_pton.c,v 1.1 1999/02/02 00:37:09 halley Exp $";
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static int inet_pton4(const char *src, u_char *dst);
|
||||
static int inet_pton6(const char *src, u_char *dst);
|
||||
static int inet_pton4(const char *src, unsigned char *dst);
|
||||
static int inet_pton6(const char *src, unsigned char *dst);
|
||||
|
||||
/* int
|
||||
* isc_inet_pton(af, src, dst)
|
||||
@@ -84,11 +88,11 @@ isc_inet_pton(af, src, dst)
|
||||
static int
|
||||
inet_pton4(src, dst)
|
||||
const char *src;
|
||||
u_char *dst;
|
||||
unsigned char *dst;
|
||||
{
|
||||
static const char digits[] = "0123456789";
|
||||
int saw_digit, octets, ch;
|
||||
u_char tmp[NS_INADDRSZ], *tp;
|
||||
unsigned char tmp[NS_INADDRSZ], *tp;
|
||||
|
||||
saw_digit = 0;
|
||||
octets = 0;
|
||||
@@ -97,7 +101,7 @@ inet_pton4(src, dst)
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr(digits, ch)) != NULL) {
|
||||
u_int new = *tp * 10 + (pch - digits);
|
||||
unsigned int new = *tp * 10 + (pch - digits);
|
||||
|
||||
if (new > 255)
|
||||
return (0);
|
||||
@@ -137,14 +141,14 @@ inet_pton4(src, dst)
|
||||
static int
|
||||
inet_pton6(src, dst)
|
||||
const char *src;
|
||||
u_char *dst;
|
||||
unsigned char *dst;
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, saw_xdigit;
|
||||
u_int val;
|
||||
unsigned int val;
|
||||
|
||||
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||
endp = tp + NS_IN6ADDRSZ;
|
||||
@@ -179,8 +183,8 @@ inet_pton6(src, dst)
|
||||
}
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
@@ -196,8 +200,8 @@ inet_pton6(src, dst)
|
||||
if (saw_xdigit) {
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
|
@@ -36,6 +36,9 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
/* temp hack! XXX */
|
||||
#define ISC_SOCKADDR_LEN_T int
|
||||
|
||||
#ifndef _WIN32
|
||||
#define WINAPI /* we're not windows */
|
||||
#endif
|
||||
@@ -718,7 +721,7 @@ internal_accept(isc_task_t *task, isc_event_t *ev)
|
||||
isc_socket_newconnev_t *dev;
|
||||
ncintev_t *iev;
|
||||
struct sockaddr addr;
|
||||
u_int addrlen;
|
||||
ISC_SOCKADDR_LEN_T addrlen;
|
||||
int fd;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
@@ -841,7 +844,7 @@ internal_recv(isc_task_t *task, isc_event_t *ev)
|
||||
int cc;
|
||||
size_t read_count;
|
||||
struct sockaddr addr;
|
||||
u_int addrlen;
|
||||
ISC_SOCKADDR_LEN_T addrlen;
|
||||
|
||||
/*
|
||||
* Find out what socket this is and lock it.
|
||||
@@ -1634,11 +1637,14 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region,
|
||||
*/
|
||||
if (EMPTY(sock->recv_list)) {
|
||||
if (sock->type == isc_socket_udp) {
|
||||
ISC_SOCKADDR_LEN_T addrlen;
|
||||
ev->addrlength = sizeof(isc_sockaddr_t);
|
||||
addrlen = (ISC_SOCKADDR_LEN_T)ev->addrlength;
|
||||
cc = recvfrom(sock->fd, ev->region.base,
|
||||
ev->region.length, 0,
|
||||
(struct sockaddr *)&ev->address,
|
||||
&ev->addrlength);
|
||||
&addrlen);
|
||||
ev->addrlength = (unsigned int)addrlen;
|
||||
} else {
|
||||
cc = recv(sock->fd, ev->region.base,
|
||||
ev->region.length, 0);
|
||||
@@ -1734,13 +1740,14 @@ isc_socket_send(isc_socket_t *sock, isc_region_t *region,
|
||||
isc_result_t
|
||||
isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
|
||||
isc_task_t *task, isc_taskaction_t action, void *arg,
|
||||
isc_sockaddr_t *address, unsigned int addrlength)
|
||||
isc_sockaddr_t *address, unsigned int addrlen)
|
||||
{
|
||||
isc_socketevent_t *ev;
|
||||
rwintev_t *iev;
|
||||
isc_socketmgr_t *manager;
|
||||
isc_task_t *ntask = NULL;
|
||||
int cc;
|
||||
ISC_SOCKADDR_LEN_T addrlength = (ISC_SOCKADDR_LEN_T)addrlen;
|
||||
|
||||
REQUIRE(VALID_SOCKET(sock));
|
||||
|
||||
@@ -2188,7 +2195,7 @@ internal_connect(isc_task_t *task, isc_event_t *ev)
|
||||
isc_socket_connev_t *dev;
|
||||
cnintev_t *iev;
|
||||
int cc;
|
||||
int optlen;
|
||||
ISC_SOCKADDR_LEN_T optlen;
|
||||
|
||||
sock = ev->sender;
|
||||
iev = (cnintev_t *)ev;
|
||||
@@ -2302,7 +2309,7 @@ isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp,
|
||||
int *lengthp)
|
||||
{
|
||||
isc_sockaddr_t addr;
|
||||
int len;
|
||||
ISC_SOCKADDR_LEN_T len;
|
||||
|
||||
REQUIRE(VALID_SOCKET(sock));
|
||||
REQUIRE(addressp != NULL);
|
||||
@@ -2318,13 +2325,13 @@ isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp,
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
if (*lengthp < sock->addrlength) {
|
||||
if ((unsigned int)*lengthp < (unsigned int)len) {
|
||||
UNLOCK(&sock->lock);
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
||||
memcpy(addressp, &sock->address, (size_t)sock->addrlength);
|
||||
*lengthp = sock->addrlength;
|
||||
memcpy(addressp, &sock->address, (size_t)len);
|
||||
*lengthp = (unsigned int)len;
|
||||
|
||||
UNLOCK(&sock->lock);
|
||||
|
||||
|
Reference in New Issue
Block a user