diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-27 09:03:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-27 09:03:30 +0000 |
commit | 3b09b6e8c19dd20f855d370503768fe48df6e0e8 (patch) | |
tree | 9f186f4b847cda2add21dc4d4a08de0a8dabd607 /src/regex | |
parent | 552b814745bc1f5380c905c21e02871416196d2a (diff) | |
download | gnunet-3b09b6e8c19dd20f855d370503768fe48df6e0e8.tar.gz gnunet-3b09b6e8c19dd20f855d370503768fe48df6e0e8.zip |
-fixes
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c index 19b55fca3..676685395 100644 --- a/src/regex/regex.c +++ b/src/regex/regex.c | |||
@@ -2953,7 +2953,7 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, | |||
2953 | static void | 2953 | static void |
2954 | iptobinstr (const int af, const void *addr, char *str) | 2954 | iptobinstr (const int af, const void *addr, char *str) |
2955 | { | 2955 | { |
2956 | unsigned int i; | 2956 | int i; |
2957 | 2957 | ||
2958 | switch (af) | 2958 | switch (af) |
2959 | { | 2959 | { |
@@ -2965,20 +2965,22 @@ iptobinstr (const int af, const void *addr, char *str) | |||
2965 | str += 31; | 2965 | str += 31; |
2966 | for (i = 31; i >= 0; i--) | 2966 | for (i = 31; i >= 0; i--) |
2967 | { | 2967 | { |
2968 | *str-- = (b & 1) + '0'; | 2968 | *str = (b & 1) + '0'; |
2969 | str--; | ||
2969 | b >>= 1; | 2970 | b >>= 1; |
2970 | } | 2971 | } |
2971 | break; | 2972 | break; |
2972 | } | 2973 | } |
2973 | case AF_INET6: | 2974 | case AF_INET6: |
2974 | { | 2975 | { |
2975 | struct in6_addr b = *(struct in6_addr *) addr; | 2976 | struct in6_addr b = *(const struct in6_addr *) addr; |
2976 | 2977 | ||
2977 | str[128] = '\0'; | 2978 | str[128] = '\0'; |
2978 | str += 127; | 2979 | str += 127; |
2979 | for (i = 127; i >= 0; i--) | 2980 | for (i = 127; i >= 0; i--) |
2980 | { | 2981 | { |
2981 | *str-- = (b.s6_addr[i / 8] & 1) + '0'; | 2982 | *str = (b.s6_addr[i / 8] & 1) + '0'; |
2983 | str--; | ||
2982 | b.s6_addr[i / 8] >>= 1; | 2984 | b.s6_addr[i / 8] >>= 1; |
2983 | } | 2985 | } |
2984 | break; | 2986 | break; |
@@ -3003,9 +3005,9 @@ ipv4netmasktoprefixlen (const char *netmask) | |||
3003 | 3005 | ||
3004 | if (1 != inet_pton (AF_INET, netmask, &a)) | 3006 | if (1 != inet_pton (AF_INET, netmask, &a)) |
3005 | return 0; | 3007 | return 0; |
3006 | 3008 | len = 32; | |
3007 | for (len = 32, t = htonl (~a.s_addr); t & 1; t >>= 1, len--) ; | 3009 | for (t = htonl (~a.s_addr); 0 != t; t >>= 1) |
3008 | 3010 | len--; | |
3009 | return len; | 3011 | return len; |
3010 | } | 3012 | } |
3011 | 3013 | ||
@@ -3027,7 +3029,8 @@ GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask, | |||
3027 | pfxlen = ipv4netmasktoprefixlen (netmask); | 3029 | pfxlen = ipv4netmasktoprefixlen (netmask); |
3028 | iptobinstr (AF_INET, ip, rxstr); | 3030 | iptobinstr (AF_INET, ip, rxstr); |
3029 | rxstr[pfxlen] = '\0'; | 3031 | rxstr[pfxlen] = '\0'; |
3030 | strcat (rxstr, "(0|1)*"); | 3032 | if (pfxlen < 32) |
3033 | strcat (rxstr, "(0|1)+"); | ||
3031 | } | 3034 | } |
3032 | 3035 | ||
3033 | 3036 | ||
@@ -3041,9 +3044,10 @@ GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask, | |||
3041 | */ | 3044 | */ |
3042 | void | 3045 | void |
3043 | GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, | 3046 | GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, |
3044 | const unsigned int prefixlen, char *rxstr) | 3047 | unsigned int prefixlen, char *rxstr) |
3045 | { | 3048 | { |
3046 | iptobinstr (AF_INET6, ipv6, rxstr); | 3049 | iptobinstr (AF_INET6, ipv6, rxstr); |
3047 | rxstr[prefixlen] = '\0'; | 3050 | rxstr[prefixlen] = '\0'; |
3048 | strcat (rxstr, "(0|1)*"); | 3051 | if (prefixlen < 128) |
3052 | strcat (rxstr, "(0|1)+"); | ||
3049 | } | 3053 | } |