- Timestamp:
- 10/14/06 09:31:18 (6 years ago)
- Location:
- branches/ithildin-scons
- Files:
-
- 5 edited
-
include/ithildin/socket.h (modified) (1 diff)
-
include/ithildin/util.h (modified) (1 diff)
-
lib/log.c (modified) (3 diffs)
-
lib/socket.c (modified) (1 diff)
-
lib/string.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ithildin-scons/include/ithildin/socket.h
r578 r784 144 144 #endif 145 145 146 /* Functions for handling network address type detection */ 147 int get_address_type(const char *); 148 146 149 /* if we don't have a system getaddrinfo, use the ones that will be included 147 150 * from source/contrib/gailib.c */ -
branches/ithildin-scons/include/ithildin/util.h
r576 r784 10 10 #ifndef UTIL_H 11 11 #define UTIL_H 12 13 /* $Id$ */14 12 15 13 /* map a file into memory in various ways */ -
branches/ithildin-scons/lib/log.c
r761 r784 83 83 } 84 84 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 88 static uint32_t log_recursed; 89 85 90 void log_vmsg(enum logtypes type, const char *mod, const char *msg, 86 91 va_list ap) { … … 91 96 return; /* avoid doing anything for debug messages when we don't 92 97 want to */ 98 99 log_recursed++; 100 if (log_recursed == LOG_RECURSE_MAX) { 101 log_recursed--; 102 return; 103 } 93 104 94 105 vsnprintf(logmsg, LOG_MSG_MAXLEN, msg, ap); … … 115 126 break; 116 127 } 128 129 log_recursed--; 117 130 } 118 131 -
branches/ithildin-scons/lib/socket.c
r761 r784 1008 1008 #endif 1009 1009 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. */ 1014 int 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 1010 1033 /* vi:set ts=8 sts=4 sw=4 tw=76 et: */ -
branches/ithildin-scons/lib/string.c
r783 r784 315 315 int imask = 0; 316 316 int i; 317 char * s;317 char *mask; 318 318 319 319 memset(bitmask, 0xff, IPADDR_SIZE); 320 320 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) { 332 324 /* 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); 340 340 341 341 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; 344 346 } 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; 347 351 } 348 352 memset(bitmask, 0, IPADDR_SIZE); … … 351 355 bitmask[(i - 1) / 8] = 0xff << (i % 8 ? (8 - (i % 8)) : 0); 352 356 } 353 addr[IPADDR_MAXLEN] = '\0';354 357 355 358 /* now copy our addresses into bitmasks. if either pton fails, assume no
Note: See TracChangeset
for help on using the changeset viewer.
