blacklist: clean up some of my old code

This commit is contained in:
Elizabeth Myers 2016-03-07 19:54:25 -06:00
parent 7e6b5384b3
commit cdf5ed6cc8

View file

@ -155,6 +155,7 @@ static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *
blcptr->blacklist = blptr; blcptr->blacklist = blptr;
blcptr->client_p = client_p; blcptr->client_p = client_p;
/* IPv4 */
if ((client_p->localClient->ip.ss_family == AF_INET) && blptr->ipv4) if ((client_p->localClient->ip.ss_family == AF_INET) && blptr->ipv4)
{ {
ip = (uint8_t *)&((struct sockaddr_in *)&client_p->localClient->ip)->sin_addr.s_addr; ip = (uint8_t *)&((struct sockaddr_in *)&client_p->localClient->ip)->sin_addr.s_addr;
@ -167,34 +168,30 @@ static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *
(unsigned int) ip[0], (unsigned int) ip[0],
blptr->host); blptr->host);
} }
/* IPv6 is supported now. --Elizabeth */ /* IPv6 */
else if ((client_p->localClient->ip.ss_family == AF_INET6) && blptr->ipv6) else if ((client_p->localClient->ip.ss_family == AF_INET6) && blptr->ipv6)
{ {
/* Breaks it into ip[0] = 0x00, ip[1] = 0x00... ip[16] = 0x01 for localhost /* Split up for rDNS lookup
* I wish there was a uint4_t for C, this would make the below cleaner, but... */ * ex: ip[0] = 0x00, ip[1] = 0x00... ip[16] = 0x01 for localhost
* Giving us:
* 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.foobl.invalid
* or something like that.
*/
ip = (uint8_t *)&((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_addr.s6_addr; ip = (uint8_t *)&((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_addr.s6_addr;
char *bufptr = buf; char *bufptr = buf;
int i; int i;
/* The below will give us something like
* 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.foobl.invalid
*/
/* Going backwards */ /* Going backwards */
for (i = 15; i >= 0; i--) for (i = 15; i >= 0; i--, bufptr += 4)
{ {
/* Get upper and lower nibbles (yes this works fine on /* Get upper and lower nibbles */
* both big and little endian) */
uint8_t hi = (ip[i] >> 4) & 0x0F; uint8_t hi = (ip[i] >> 4) & 0x0F;
uint8_t lo = ip[i] & 0x0F; uint8_t lo = ip[i] & 0x0F;
/* One part... (why 5? rb_snprintf adds \0) */ /* One part... 4 chars + terminator */
snprintf(bufptr, 5, "%1x.%1x.", snprintf(bufptr, 5, "%1x.%1x.",
(unsigned int) lo, /* Remember, backwards */ (unsigned int) lo, /* Remember, backwards */
(unsigned int) hi); (unsigned int) hi);
/* Lurch forward to next position */
bufptr += 4;
} }
/* Tack host on */ /* Tack host on */