0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

Various inet* -> rb_inet_*

This commit is contained in:
Valery Yatsko 2008-04-20 08:55:41 +04:00
parent 79c70bbb9c
commit caa4d9d273
12 changed files with 21 additions and 423 deletions

View file

@ -126,7 +126,7 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
del_unknown_ip(source_p);
inetpton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip);
rb_inet_pton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip);
/* Check dlines now, klines will be checked on registration */
if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip,

View file

@ -76,20 +76,6 @@ extern int ircncmp(const char *s1, const char *s2, int n);
#ifdef NO_DUPE_MULTI_MESSAGES
extern char *canonize(char *);
#endif
/*
* inetntoa - optimized inet_ntoa
*/
const char *inetntoa(const char *in_addr);
/*
* inetntop()
* inetpton()
* portable interfaces for inet_ntop() and inet_pton()
*/
const char *inetntop(int af, const void *src, char *dst, unsigned int size);
int inetpton(int af, const char *src, void *dst);
const char *inetntop_sock(struct sockaddr *src, char *dst, unsigned int size);
int inetpton_sock(const char *src, struct sockaddr *dst);
/*
* clean_string - cleanup control and high ascii characters

View file

@ -337,7 +337,7 @@ report_this_status(struct Client *source_p, struct Client *target_p,
if(!MyConnect(target_p))
return 0;
inetntop_sock((struct sockaddr *)&target_p->localClient->ip, ip, sizeof(ip));
rb_inet_ntop_sock((struct sockaddr *)&target_p->localClient->ip, ip, sizeof(ip));
class_name = get_client_class(target_p);
if(IsAnyServer(target_p))

View file

@ -75,7 +75,7 @@ parse_netmask(const char *text, struct sockaddr *naddr, int *nb)
*b = 128;
} else
*b = 128;
if(inetpton_sock(ip, (struct sockaddr *)addr) > 0)
if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
return HM_IPV6;
else
return HM_HOST;
@ -92,7 +92,7 @@ parse_netmask(const char *text, struct sockaddr *naddr, int *nb)
*b = 32;
} else
*b = 32;
if(inetpton_sock(ip, (struct sockaddr *)addr) > 0)
if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
return HM_IPV4;
else
return HM_HOST;

View file

@ -178,105 +178,6 @@ strtoken(char **save, char *str, const char *fs)
return tmp;
}
static const char base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
static const char base64_pad = '=';
static const short base64_reverse_table[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
/*
* From: Thomas Helvey <tomh@inxpress.net>
*/
static const char *IpQuadTab[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
"100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
"110", "111", "112", "113", "114", "115", "116", "117", "118", "119",
"120", "121", "122", "123", "124", "125", "126", "127", "128", "129",
"130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
"140", "141", "142", "143", "144", "145", "146", "147", "148", "149",
"150", "151", "152", "153", "154", "155", "156", "157", "158", "159",
"160", "161", "162", "163", "164", "165", "166", "167", "168", "169",
"170", "171", "172", "173", "174", "175", "176", "177", "178", "179",
"180", "181", "182", "183", "184", "185", "186", "187", "188", "189",
"190", "191", "192", "193", "194", "195", "196", "197", "198", "199",
"200", "201", "202", "203", "204", "205", "206", "207", "208", "209",
"210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
"220", "221", "222", "223", "224", "225", "226", "227", "228", "229",
"230", "231", "232", "233", "234", "235", "236", "237", "238", "239",
"240", "241", "242", "243", "244", "245", "246", "247", "248", "249",
"250", "251", "252", "253", "254", "255"
};
/*
* inetntoa - in_addr to string
* changed name to remove collision possibility and
* so behaviour is guaranteed to take a pointer arg.
* -avalon 23/11/92
* inet_ntoa -- returned the dotted notation of a given
* internet number
* argv 11/90).
* inet_ntoa -- its broken on some Ultrix/Dynix too. -avalon
*/
const char *
inetntoa(const char *in)
{
static char buf[16];
char *bufptr = buf;
const unsigned char *a = (const unsigned char *) in;
const char *n;
n = IpQuadTab[*a++];
while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a++];
while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a++];
while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a];
while(*n)
*bufptr++ = *n++;
*bufptr = '\0';
return buf;
}
/*
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
@ -436,295 +337,6 @@ inet_ntop6(const unsigned char *src, char *dst, unsigned int size)
}
#endif
int
inetpton_sock(const char *src, struct sockaddr *dst)
{
if(inetpton(AF_INET, src, &((struct sockaddr_in *) dst)->sin_addr))
{
((struct sockaddr_in *) dst)->sin_port = 0;
((struct sockaddr_in *) dst)->sin_family = AF_INET;
SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in));
return 1;
}
#ifdef RB_IPV6
else if(inetpton(AF_INET6, src, &((struct sockaddr_in6 *) dst)->sin6_addr))
{
((struct sockaddr_in6 *) dst)->sin6_port = 0;
((struct sockaddr_in6 *) dst)->sin6_family = AF_INET6;
SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in6));
return 1;
}
#endif
return 0;
}
const char *
inetntop_sock(struct sockaddr *src, char *dst, unsigned int size)
{
switch (src->sa_family)
{
case AF_INET:
return (inetntop(AF_INET, &((struct sockaddr_in *) src)->sin_addr, dst, size));
break;
#ifdef RB_IPV6
case AF_INET6:
return (inetntop(AF_INET6, &((struct sockaddr_in6 *) src)->sin6_addr, dst, size));
break;
#endif
default:
return NULL;
break;
}
}
/* char *
* inetntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
* pointer to presentation format address (`dst'), or NULL (see errno).
* author:
* Paul Vixie, 1996.
*/
const char *
inetntop(int af, const void *src, char *dst, unsigned int size)
{
switch (af)
{
case AF_INET:
return (inet_ntop4(src, dst, size));
#ifdef RB_IPV6
case AF_INET6:
if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *) src) ||
IN6_IS_ADDR_V4COMPAT((const struct in6_addr *) src))
return (inet_ntop4
((const unsigned char *)
&((const struct in6_addr *) src)->s6_addr[12], dst, size));
else
return (inet_ntop6(src, dst, size));
#endif
default:
return (NULL);
}
/* NOTREACHED */
}
/*
* WARNING: Don't even consider trying to compile this on a system where
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
/* int
* inetpton(af, src, dst)
* convert from presentation format (which usually means ASCII printable)
* to network format (which is usually some kind of binary format).
* return:
* 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case)
* -1 if some other error occurred (`dst' is untouched in this case, too)
* author:
* Paul Vixie, 1996.
*/
/* int
* inet_pton4(src, dst)
* like inet_aton() but without all the hexadecimal and shorthand.
* return:
* 1 if `src' is a valid dotted quad, else 0.
* notice:
* does not touch `dst' unless it's returning 1.
* author:
* Paul Vixie, 1996.
*/
static int
inet_pton4(src, dst)
const char *src;
u_char *dst;
{
int saw_digit, octets, ch;
u_char tmp[INADDRSZ], *tp;
saw_digit = 0;
octets = 0;
*(tp = tmp) = 0;
while((ch = *src++) != '\0')
{
if(ch >= '0' && ch <= '9')
{
u_int new = *tp * 10 + (ch - '0');
if(new > 255)
return (0);
*tp = new;
if(!saw_digit)
{
if(++octets > 4)
return (0);
saw_digit = 1;
}
}
else if(ch == '.' && saw_digit)
{
if(octets == 4)
return (0);
*++tp = 0;
saw_digit = 0;
}
else
return (0);
}
if(octets < 4)
return (0);
memcpy(dst, tmp, INADDRSZ);
return (1);
}
#ifdef RB_IPV6
/* int
* inet_pton6(src, dst)
* convert presentation level address to network order binary form.
* return:
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* notice:
* (1) does not touch `dst' unless it's returning 1.
* (2) :: in a full address is silently ignored.
* credit:
* inspired by Mark Andrews.
* author:
* Paul Vixie, 1996.
*/
static int
inet_pton6(src, dst)
const char *src;
u_char *dst;
{
static const char xdigits[] = "0123456789abcdef";
u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *curtok;
int ch, saw_xdigit;
u_int val;
tp = memset(tmp, '\0', IN6ADDRSZ);
endp = tp + IN6ADDRSZ;
colonp = NULL;
/* Leading :: requires some special handling. */
if(*src == ':')
if(*++src != ':')
return (0);
curtok = src;
saw_xdigit = 0;
val = 0;
while((ch = tolower(*src++)) != '\0')
{
const char *pch;
pch = strchr(xdigits, ch);
if(pch != NULL)
{
val <<= 4;
val |= (pch - xdigits);
if(val > 0xffff)
return (0);
saw_xdigit = 1;
continue;
}
if(ch == ':')
{
curtok = src;
if(!saw_xdigit)
{
if(colonp)
return (0);
colonp = tp;
continue;
}
else if(*src == '\0')
{
return (0);
}
if(tp + INT16SZ > endp)
return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if(*src != '\0' && ch == '.')
{
if(((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0)
{
tp += INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
}
else
continue;
return (0);
}
if(saw_xdigit)
{
if(tp + INT16SZ > endp)
return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
}
if(colonp != NULL)
{
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;
if(tp == endp)
return (0);
for(i = 1; i <= n; i++)
{
endp[-i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if(tp != endp)
return (0);
memcpy(dst, tmp, IN6ADDRSZ);
return (1);
}
#endif
int
inetpton(af, src, dst)
int af;
const char *src;
void *dst;
{
switch (af)
{
case AF_INET:
return (inet_pton4(src, dst));
#ifdef RB_IPV6
case AF_INET6:
/* Somebody might have passed as an IPv4 address this is sick but it works */
if(inet_pton4(src, dst))
{
char tmp[HOSTIPLEN];
rb_sprintf(tmp, "::ffff:%s", src);
return (inet_pton6(tmp, dst));
}
else
return (inet_pton6(src, dst));
#endif
default:
return (-1);
}
/* NOTREACHED */
}
char *
strip_colour(char *string)
{

View file

@ -184,7 +184,7 @@ inetport(listener_t *listener)
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&listener->addr;
if(!IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &in6addr_any))
{
inetntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost));
rb_inet_ntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost));
listener->name = listener->vhost;
}
} else
@ -193,7 +193,7 @@ inetport(listener_t *listener)
struct sockaddr_in *in = (struct sockaddr_in *)&listener->addr;
if(in->sin_addr.s_addr != INADDR_ANY)
{
inetntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost));
rb_inet_ntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost));
listener->name = listener->vhost;
}
}
@ -323,13 +323,13 @@ add_listener(int port, const char *vhost_ip, int family, int ssl)
{
if(family == AF_INET)
{
if(inetpton(family, vhost_ip, &((struct sockaddr_in *)&vaddr)->sin_addr) <= 0)
if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in *)&vaddr)->sin_addr) <= 0)
return;
}
#ifdef RB_IPV6
else
{
if(inetpton(family, vhost_ip, &((struct sockaddr_in6 *)&vaddr)->sin6_addr) <= 0)
if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in6 *)&vaddr)->sin6_addr) <= 0)
return;
}
@ -453,7 +453,7 @@ add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, voi
* copy address to 'sockhost' as a string, copy it to host too
* so we have something valid to put into error messages...
*/
inetntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost,
rb_inet_ntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost,
sizeof(new_client->sockhost));

View file

@ -364,8 +364,8 @@ int match_ips(const char *s1, const char *s2)
else
return 0;
inetpton(aftype, address, ipptr);
inetpton(aftype, mask, maskptr);
rb_inet_pton(aftype, address, ipptr);
rb_inet_pton(aftype, mask, maskptr);
if (comp_with_mask(ipptr, maskptr, cidrlen))
return 1;
else
@ -432,8 +432,8 @@ int match_cidr(const char *s1, const char *s2)
else
return 0;
inetpton(aftype, ip, ipptr);
inetpton(aftype, ipmask, maskptr);
rb_inet_pton(aftype, ip, ipptr);
rb_inet_pton(aftype, ipmask, maskptr);
if (comp_with_mask(ipptr, maskptr, cidrlen) && match(mask, address))
return 1;
else

View file

@ -230,7 +230,7 @@ conf_set_serverinfo_network_name(void *data)
static void
conf_set_serverinfo_vhost(void *data)
{
if(inetpton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0)
if(rb_inet_pton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0)
{
conf_report_error("Invalid netmask for server IPv4 vhost (%s)", (char *) data);
return;
@ -243,7 +243,7 @@ static void
conf_set_serverinfo_vhost6(void *data)
{
#ifdef RB_IPV6
if(inetpton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0)
if(rb_inet_pton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0)
{
conf_report_error("Invalid netmask for server IPv6 vhost (%s)", (char *) data);
return;
@ -1191,7 +1191,7 @@ conf_set_connect_host(void *data)
static void
conf_set_connect_vhost(void *data)
{
if(inetpton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0)
if(rb_inet_pton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0)
{
conf_report_error("Invalid netmask for server vhost (%s)",
(char *) data);

View file

@ -864,7 +864,7 @@ void report_dns_servers(struct Client *source_p)
for (i = 0; i < irc_nscount; i++)
{
if (!inetntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]),
if (!rb_inet_ntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]),
ipaddr, sizeof ipaddr))
rb_strlcpy(ipaddr, "?", sizeof ipaddr);
sendto_one_numeric(source_p, RPL_STATSDEBUG,

View file

@ -258,7 +258,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern
/* why ipaddr, and not just source_p->sockhost? --fl */
#if 0
static char ipaddr[HOSTIPLEN];
inetntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
#endif
sendto_realops_snomask(SNO_UNAUTH, L_ALL,
"Unauthorised client connection from "

View file

@ -1177,7 +1177,7 @@ serv_connect_resolved(struct Client *client_p)
}
/* log */
inetntop_sock((struct sockaddr *)&myipnum, vhoststr, sizeof vhoststr);
rb_inet_ntop_sock((struct sockaddr *)&myipnum, vhoststr, sizeof vhoststr);
ilog(L_SERVER, "Connecting to %s[%s] port %d (%s) (vhost %s)", client_p->name, client_p->sockhost, port,
#ifdef RB_IPV6
server_p->aftype == AF_INET6 ? "IPv6" :
@ -1231,7 +1231,7 @@ serv_connect_dns_callback(void *vptr, struct DNSReply *reply)
#endif
((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = port;
/* Set sockhost properly now -- jilles */
inetntop_sock((struct sockaddr *)&client_p->localClient->ip,
rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip,
client_p->sockhost, sizeof client_p->sockhost);
serv_connect_resolved(client_p);
}

View file

@ -494,7 +494,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char
/* To avoid inconsistencies, do not abort the registration
* starting from this point -- jilles
*/
inetntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
sendto_realops_snomask(SNO_CCONN, L_ALL,
"Client connecting: %s (%s@%s) [%s] {%s} [%s]",