Changeset 784


Ignore:
Timestamp:
10/14/06 09:31:18 (6 years ago)
Author:
wd
Message:

Merge changes from 1.1 branch to core code.

Location:
branches/ithildin-scons
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/ithildin-scons/include/ithildin/socket.h

    r578 r784  
    144144#endif 
    145145 
     146/* Functions for handling network address type detection */ 
     147int get_address_type(const char *); 
     148 
    146149/* if we don't have a system getaddrinfo, use the ones that will be included 
    147150 * from source/contrib/gailib.c */ 
  • branches/ithildin-scons/include/ithildin/util.h

    r576 r784  
    1010#ifndef UTIL_H 
    1111#define UTIL_H 
    12  
    13 /* $Id$ */ 
    1412 
    1513/* map a file into memory in various ways */ 
  • branches/ithildin-scons/lib/log.c

    r761 r784  
    8383} 
    8484 
     85/* Recursion protection for logged messages.  If we log_*() and then hook an 
     86 * event which generates a log_*() we can end up in serious trouble. :) */ 
     87#define LOG_RECURSE_MAX 10 
     88static uint32_t log_recursed; 
     89 
    8590void log_vmsg(enum logtypes type, const char *mod, const char *msg, 
    8691        va_list ap) { 
     
    9196        return; /* avoid doing anything for debug messages when we don't 
    9297                   want to */ 
     98 
     99    log_recursed++; 
     100    if (log_recursed == LOG_RECURSE_MAX) { 
     101        log_recursed--; 
     102        return; 
     103    } 
    93104 
    94105    vsnprintf(logmsg, LOG_MSG_MAXLEN, msg, ap); 
     
    115126            break; 
    116127    } 
     128 
     129    log_recursed--; 
    117130} 
    118131 
  • branches/ithildin-scons/lib/socket.c

    r761 r784  
    10081008#endif 
    10091009 
     1010/* Function to determine the type of an address.  We do cheap best effort 
     1011 * here.  If it looks IPv6-y we try inet_pton with AF_INET6, if it looks 
     1012 * IPv4-y we try inet_pton with AF_INET, and as long as one succeeds we 
     1013 * return that type. */ 
     1014int get_address_type(const char *addr) { 
     1015    const char *s = addr; 
     1016    unsigned char buf[IPADDR_SIZE]; 
     1017 
     1018#ifdef INET6 
     1019    s = strchr(addr, ':'); 
     1020    if (s != NULL && strchr(s + 1, ':') != NULL) { 
     1021        /* either IPv6 or nothing, let's see */ 
     1022        if (inet_pton(PF_INET6, addr, buf) == 1) 
     1023            return PF_INET6; 
     1024        return PF_UNSPEC; 
     1025    } 
     1026#endif 
     1027 
     1028    if (inet_pton(PF_INET, addr, buf) == 1) 
     1029        return PF_INET; 
     1030    return PF_UNSPEC; 
     1031} 
     1032 
    10101033/* vi:set ts=8 sts=4 sw=4 tw=76 et: */ 
  • branches/ithildin-scons/lib/string.c

    r783 r784  
    315315    int imask = 0; 
    316316    int i; 
    317     char *s; 
     317    char *mask; 
    318318 
    319319    memset(bitmask, 0xff, IPADDR_SIZE); 
    320320    strlcpy(addr, wild, IPADDR_MAXLEN + 1); 
    321     /* First figure out what kind of address we've got.  We no longer support 
    322      * IPv4 mask form (ip:mask), but IPv6 addresses need at least two colons. 
    323      * If we find only one, just return 0 right away. */ 
    324     if ((s = strchr(wild, ':')) != NULL) { 
    325         if (strchr(s + 1, ':') != NULL) 
    326             family = PF_INET6; /* actually, inet6.. */ 
    327         else 
    328             return 0; /* no mask support */ 
    329     } 
    330  
    331     if ((s = strchr(wild, '/')) != NULL) { 
     321 
     322    /* strip off the mask portion if it is there */ 
     323    if ((mask = strchr(wild, '/')) != NULL) { 
    332324        /* mask form.  mask specifies significant bits from left to right. 
    333          * simple enough. */ 
    334         if (IPADDR_MAXLEN > s - wild) 
    335             addr[s - wild] = '\0'; 
    336         s++; 
    337         imask = str_conv_int(s, -1); 
    338         if (imask <= 0) 
    339             return 0; /* bad bit count specified */ 
     325         * we must make sure to truncate addr at the point where the mask 
     326         * starts as well, if it starts before IPADDR_MAXLEN. */ 
     327        if (IPADDR_MAXLEN > mask - wild) 
     328            addr[mask - wild] = '\0'; 
     329        mask++; 
     330    } 
     331 
     332    /* now determine the address family */ 
     333    family = get_address_type(addr); 
     334    if (family != PF_INET && family != PF_INET6) 
     335        return 0; 
     336 
     337    /* and handle the bitmasking if need-be */ 
     338    if (mask != NULL) { 
     339        imask = str_conv_int(mask, 0); 
    340340 
    341341        if (family == PF_INET6) { 
    342             if (imask > 128) 
    343                 return 0; /* bad bit count specified */ 
     342            if (imask <= 0) 
     343                imask = 128; 
     344            else if (imask > 128) 
     345                imask = 128; 
    344346        } else { 
    345             if (imask > 32) 
    346                 return 0; /* bad bit count specified */ 
     347            if (imask <= 0) 
     348                imask = 32; 
     349            else if (imask > 32) 
     350                imask = 32; 
    347351        } 
    348352        memset(bitmask, 0, IPADDR_SIZE); 
     
    351355            bitmask[(i - 1) / 8] = 0xff << (i % 8 ? (8 - (i % 8)) : 0); 
    352356    } 
    353     addr[IPADDR_MAXLEN] = '\0'; 
    354357 
    355358    /* now copy our addresses into bitmasks.  if either pton fails, assume no 
Note: See TracChangeset for help on using the changeset viewer.