Sam Walsh / F7_Ethernet

Dependents:   Nucleo_F746ZG_Ethernet_MQTT_Ultrasound

Fork of F7_Ethernet by Dieter Graef

Committer:
EmbeddedSam
Date:
Mon Oct 24 12:59:21 2016 +0000
Revision:
2:b4727195c450
Parent:
0:d26c1b55cfca
working with 1 ultrasound sensor approx 10hz update rate on mqtt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:d26c1b55cfca 1 /**
DieterGraef 0:d26c1b55cfca 2 * @file
DieterGraef 0:d26c1b55cfca 3 * This is the IPv4 address tools implementation.
DieterGraef 0:d26c1b55cfca 4 *
DieterGraef 0:d26c1b55cfca 5 */
DieterGraef 0:d26c1b55cfca 6
DieterGraef 0:d26c1b55cfca 7 /*
DieterGraef 0:d26c1b55cfca 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
DieterGraef 0:d26c1b55cfca 9 * All rights reserved.
DieterGraef 0:d26c1b55cfca 10 *
DieterGraef 0:d26c1b55cfca 11 * Redistribution and use in source and binary forms, with or without modification,
DieterGraef 0:d26c1b55cfca 12 * are permitted provided that the following conditions are met:
DieterGraef 0:d26c1b55cfca 13 *
DieterGraef 0:d26c1b55cfca 14 * 1. Redistributions of source code must retain the above copyright notice,
DieterGraef 0:d26c1b55cfca 15 * this list of conditions and the following disclaimer.
DieterGraef 0:d26c1b55cfca 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
DieterGraef 0:d26c1b55cfca 17 * this list of conditions and the following disclaimer in the documentation
DieterGraef 0:d26c1b55cfca 18 * and/or other materials provided with the distribution.
DieterGraef 0:d26c1b55cfca 19 * 3. The name of the author may not be used to endorse or promote products
DieterGraef 0:d26c1b55cfca 20 * derived from this software without specific prior written permission.
DieterGraef 0:d26c1b55cfca 21 *
DieterGraef 0:d26c1b55cfca 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
DieterGraef 0:d26c1b55cfca 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
DieterGraef 0:d26c1b55cfca 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
DieterGraef 0:d26c1b55cfca 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
DieterGraef 0:d26c1b55cfca 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
DieterGraef 0:d26c1b55cfca 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:d26c1b55cfca 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:d26c1b55cfca 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
DieterGraef 0:d26c1b55cfca 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
DieterGraef 0:d26c1b55cfca 31 * OF SUCH DAMAGE.
DieterGraef 0:d26c1b55cfca 32 *
DieterGraef 0:d26c1b55cfca 33 * This file is part of the lwIP TCP/IP stack.
DieterGraef 0:d26c1b55cfca 34 *
DieterGraef 0:d26c1b55cfca 35 * Author: Adam Dunkels <adam@sics.se>
DieterGraef 0:d26c1b55cfca 36 *
DieterGraef 0:d26c1b55cfca 37 */
DieterGraef 0:d26c1b55cfca 38
DieterGraef 0:d26c1b55cfca 39 #include "lwip/opt.h"
DieterGraef 0:d26c1b55cfca 40 #include "lwip/ip_addr.h"
DieterGraef 0:d26c1b55cfca 41 #include "lwip/netif.h"
DieterGraef 0:d26c1b55cfca 42
DieterGraef 0:d26c1b55cfca 43 /* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
DieterGraef 0:d26c1b55cfca 44 const ip_addr_t ip_addr_any = { IPADDR_ANY };
DieterGraef 0:d26c1b55cfca 45 const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST };
DieterGraef 0:d26c1b55cfca 46
DieterGraef 0:d26c1b55cfca 47 /**
DieterGraef 0:d26c1b55cfca 48 * Determine if an address is a broadcast address on a network interface
DieterGraef 0:d26c1b55cfca 49 *
DieterGraef 0:d26c1b55cfca 50 * @param addr address to be checked
DieterGraef 0:d26c1b55cfca 51 * @param netif the network interface against which the address is checked
DieterGraef 0:d26c1b55cfca 52 * @return returns non-zero if the address is a broadcast address
DieterGraef 0:d26c1b55cfca 53 */
DieterGraef 0:d26c1b55cfca 54 u8_t
DieterGraef 0:d26c1b55cfca 55 ip4_addr_isbroadcast(u32_t addr, const struct netif *netif)
DieterGraef 0:d26c1b55cfca 56 {
DieterGraef 0:d26c1b55cfca 57 ip_addr_t ipaddr;
DieterGraef 0:d26c1b55cfca 58 ip4_addr_set_u32(&ipaddr, addr);
DieterGraef 0:d26c1b55cfca 59
DieterGraef 0:d26c1b55cfca 60 /* all ones (broadcast) or all zeroes (old skool broadcast) */
DieterGraef 0:d26c1b55cfca 61 if ((~addr == IPADDR_ANY) ||
DieterGraef 0:d26c1b55cfca 62 (addr == IPADDR_ANY)) {
DieterGraef 0:d26c1b55cfca 63 return 1;
DieterGraef 0:d26c1b55cfca 64 /* no broadcast support on this network interface? */
DieterGraef 0:d26c1b55cfca 65 } else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) {
DieterGraef 0:d26c1b55cfca 66 /* the given address cannot be a broadcast address
DieterGraef 0:d26c1b55cfca 67 * nor can we check against any broadcast addresses */
DieterGraef 0:d26c1b55cfca 68 return 0;
DieterGraef 0:d26c1b55cfca 69 /* address matches network interface address exactly? => no broadcast */
DieterGraef 0:d26c1b55cfca 70 } else if (addr == ip4_addr_get_u32(&netif->ip_addr)) {
DieterGraef 0:d26c1b55cfca 71 return 0;
DieterGraef 0:d26c1b55cfca 72 /* on the same (sub) network... */
DieterGraef 0:d26c1b55cfca 73 } else if (ip_addr_netcmp(&ipaddr, &(netif->ip_addr), &(netif->netmask))
DieterGraef 0:d26c1b55cfca 74 /* ...and host identifier bits are all ones? =>... */
DieterGraef 0:d26c1b55cfca 75 && ((addr & ~ip4_addr_get_u32(&netif->netmask)) ==
DieterGraef 0:d26c1b55cfca 76 (IPADDR_BROADCAST & ~ip4_addr_get_u32(&netif->netmask)))) {
DieterGraef 0:d26c1b55cfca 77 /* => network broadcast address */
DieterGraef 0:d26c1b55cfca 78 return 1;
DieterGraef 0:d26c1b55cfca 79 } else {
DieterGraef 0:d26c1b55cfca 80 return 0;
DieterGraef 0:d26c1b55cfca 81 }
DieterGraef 0:d26c1b55cfca 82 }
DieterGraef 0:d26c1b55cfca 83
DieterGraef 0:d26c1b55cfca 84 /** Checks if a netmask is valid (starting with ones, then only zeros)
DieterGraef 0:d26c1b55cfca 85 *
DieterGraef 0:d26c1b55cfca 86 * @param netmask the IPv4 netmask to check (in network byte order!)
DieterGraef 0:d26c1b55cfca 87 * @return 1 if the netmask is valid, 0 if it is not
DieterGraef 0:d26c1b55cfca 88 */
DieterGraef 0:d26c1b55cfca 89 u8_t
DieterGraef 0:d26c1b55cfca 90 ip4_addr_netmask_valid(u32_t netmask)
DieterGraef 0:d26c1b55cfca 91 {
DieterGraef 0:d26c1b55cfca 92 u32_t mask;
DieterGraef 0:d26c1b55cfca 93 u32_t nm_hostorder = lwip_htonl(netmask);
DieterGraef 0:d26c1b55cfca 94
DieterGraef 0:d26c1b55cfca 95 /* first, check for the first zero */
DieterGraef 0:d26c1b55cfca 96 for (mask = 1UL << 31 ; mask != 0; mask >>= 1) {
DieterGraef 0:d26c1b55cfca 97 if ((nm_hostorder & mask) == 0) {
DieterGraef 0:d26c1b55cfca 98 break;
DieterGraef 0:d26c1b55cfca 99 }
DieterGraef 0:d26c1b55cfca 100 }
DieterGraef 0:d26c1b55cfca 101 /* then check that there is no one */
DieterGraef 0:d26c1b55cfca 102 for (; mask != 0; mask >>= 1) {
DieterGraef 0:d26c1b55cfca 103 if ((nm_hostorder & mask) != 0) {
DieterGraef 0:d26c1b55cfca 104 /* there is a one after the first zero -> invalid */
DieterGraef 0:d26c1b55cfca 105 return 0;
DieterGraef 0:d26c1b55cfca 106 }
DieterGraef 0:d26c1b55cfca 107 }
DieterGraef 0:d26c1b55cfca 108 /* no one after the first zero -> valid */
DieterGraef 0:d26c1b55cfca 109 return 1;
DieterGraef 0:d26c1b55cfca 110 }
DieterGraef 0:d26c1b55cfca 111
DieterGraef 0:d26c1b55cfca 112 /* Here for now until needed in other places in lwIP */
DieterGraef 0:d26c1b55cfca 113 #ifndef isprint
DieterGraef 0:d26c1b55cfca 114 #define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
DieterGraef 0:d26c1b55cfca 115 #define isprint(c) in_range(c, 0x20, 0x7f)
DieterGraef 0:d26c1b55cfca 116 #define isdigit(c) in_range(c, '0', '9')
DieterGraef 0:d26c1b55cfca 117 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
DieterGraef 0:d26c1b55cfca 118 #define islower(c) in_range(c, 'a', 'z')
DieterGraef 0:d26c1b55cfca 119 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
DieterGraef 0:d26c1b55cfca 120 #endif
DieterGraef 0:d26c1b55cfca 121
DieterGraef 0:d26c1b55cfca 122 /**
DieterGraef 0:d26c1b55cfca 123 * Ascii internet address interpretation routine.
DieterGraef 0:d26c1b55cfca 124 * The value returned is in network order.
DieterGraef 0:d26c1b55cfca 125 *
DieterGraef 0:d26c1b55cfca 126 * @param cp IP address in ascii represenation (e.g. "127.0.0.1")
DieterGraef 0:d26c1b55cfca 127 * @return ip address in network order
DieterGraef 0:d26c1b55cfca 128 */
DieterGraef 0:d26c1b55cfca 129 u32_t
DieterGraef 0:d26c1b55cfca 130 ipaddr_addr(const char *cp)
DieterGraef 0:d26c1b55cfca 131 {
DieterGraef 0:d26c1b55cfca 132 ip_addr_t val;
DieterGraef 0:d26c1b55cfca 133
DieterGraef 0:d26c1b55cfca 134 if (ipaddr_aton(cp, &val)) {
DieterGraef 0:d26c1b55cfca 135 return ip4_addr_get_u32(&val);
DieterGraef 0:d26c1b55cfca 136 }
DieterGraef 0:d26c1b55cfca 137 return (IPADDR_NONE);
DieterGraef 0:d26c1b55cfca 138 }
DieterGraef 0:d26c1b55cfca 139
DieterGraef 0:d26c1b55cfca 140 /**
DieterGraef 0:d26c1b55cfca 141 * Check whether "cp" is a valid ascii representation
DieterGraef 0:d26c1b55cfca 142 * of an Internet address and convert to a binary address.
DieterGraef 0:d26c1b55cfca 143 * Returns 1 if the address is valid, 0 if not.
DieterGraef 0:d26c1b55cfca 144 * This replaces inet_addr, the return value from which
DieterGraef 0:d26c1b55cfca 145 * cannot distinguish between failure and a local broadcast address.
DieterGraef 0:d26c1b55cfca 146 *
DieterGraef 0:d26c1b55cfca 147 * @param cp IP address in ascii represenation (e.g. "127.0.0.1")
DieterGraef 0:d26c1b55cfca 148 * @param addr pointer to which to save the ip address in network order
DieterGraef 0:d26c1b55cfca 149 * @return 1 if cp could be converted to addr, 0 on failure
DieterGraef 0:d26c1b55cfca 150 */
DieterGraef 0:d26c1b55cfca 151 int
DieterGraef 0:d26c1b55cfca 152 ipaddr_aton(const char *cp, ip_addr_t *addr)
DieterGraef 0:d26c1b55cfca 153 {
DieterGraef 0:d26c1b55cfca 154 u32_t val;
DieterGraef 0:d26c1b55cfca 155 u8_t base;
DieterGraef 0:d26c1b55cfca 156 char c;
DieterGraef 0:d26c1b55cfca 157 u32_t parts[4];
DieterGraef 0:d26c1b55cfca 158 u32_t *pp = parts;
DieterGraef 0:d26c1b55cfca 159
DieterGraef 0:d26c1b55cfca 160 c = *cp;
DieterGraef 0:d26c1b55cfca 161 for (;;) {
DieterGraef 0:d26c1b55cfca 162 /*
DieterGraef 0:d26c1b55cfca 163 * Collect number up to ``.''.
DieterGraef 0:d26c1b55cfca 164 * Values are specified as for C:
DieterGraef 0:d26c1b55cfca 165 * 0x=hex, 0=octal, 1-9=decimal.
DieterGraef 0:d26c1b55cfca 166 */
DieterGraef 0:d26c1b55cfca 167 if (!isdigit(c))
DieterGraef 0:d26c1b55cfca 168 return (0);
DieterGraef 0:d26c1b55cfca 169 val = 0;
DieterGraef 0:d26c1b55cfca 170 base = 10;
DieterGraef 0:d26c1b55cfca 171 if (c == '0') {
DieterGraef 0:d26c1b55cfca 172 c = *++cp;
DieterGraef 0:d26c1b55cfca 173 if (c == 'x' || c == 'X') {
DieterGraef 0:d26c1b55cfca 174 base = 16;
DieterGraef 0:d26c1b55cfca 175 c = *++cp;
DieterGraef 0:d26c1b55cfca 176 } else
DieterGraef 0:d26c1b55cfca 177 base = 8;
DieterGraef 0:d26c1b55cfca 178 }
DieterGraef 0:d26c1b55cfca 179 for (;;) {
DieterGraef 0:d26c1b55cfca 180 if (isdigit(c)) {
DieterGraef 0:d26c1b55cfca 181 val = (val * base) + (int)(c - '0');
DieterGraef 0:d26c1b55cfca 182 c = *++cp;
DieterGraef 0:d26c1b55cfca 183 } else if (base == 16 && isxdigit(c)) {
DieterGraef 0:d26c1b55cfca 184 val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
DieterGraef 0:d26c1b55cfca 185 c = *++cp;
DieterGraef 0:d26c1b55cfca 186 } else
DieterGraef 0:d26c1b55cfca 187 break;
DieterGraef 0:d26c1b55cfca 188 }
DieterGraef 0:d26c1b55cfca 189 if (c == '.') {
DieterGraef 0:d26c1b55cfca 190 /*
DieterGraef 0:d26c1b55cfca 191 * Internet format:
DieterGraef 0:d26c1b55cfca 192 * a.b.c.d
DieterGraef 0:d26c1b55cfca 193 * a.b.c (with c treated as 16 bits)
DieterGraef 0:d26c1b55cfca 194 * a.b (with b treated as 24 bits)
DieterGraef 0:d26c1b55cfca 195 */
DieterGraef 0:d26c1b55cfca 196 if (pp >= parts + 3) {
DieterGraef 0:d26c1b55cfca 197 return (0);
DieterGraef 0:d26c1b55cfca 198 }
DieterGraef 0:d26c1b55cfca 199 *pp++ = val;
DieterGraef 0:d26c1b55cfca 200 c = *++cp;
DieterGraef 0:d26c1b55cfca 201 } else
DieterGraef 0:d26c1b55cfca 202 break;
DieterGraef 0:d26c1b55cfca 203 }
DieterGraef 0:d26c1b55cfca 204 /*
DieterGraef 0:d26c1b55cfca 205 * Check for trailing characters.
DieterGraef 0:d26c1b55cfca 206 */
DieterGraef 0:d26c1b55cfca 207 if (c != '\0' && !isspace(c)) {
DieterGraef 0:d26c1b55cfca 208 return (0);
DieterGraef 0:d26c1b55cfca 209 }
DieterGraef 0:d26c1b55cfca 210 /*
DieterGraef 0:d26c1b55cfca 211 * Concoct the address according to
DieterGraef 0:d26c1b55cfca 212 * the number of parts specified.
DieterGraef 0:d26c1b55cfca 213 */
DieterGraef 0:d26c1b55cfca 214 switch (pp - parts + 1) {
DieterGraef 0:d26c1b55cfca 215
DieterGraef 0:d26c1b55cfca 216 case 0:
DieterGraef 0:d26c1b55cfca 217 return (0); /* initial nondigit */
DieterGraef 0:d26c1b55cfca 218
DieterGraef 0:d26c1b55cfca 219 case 1: /* a -- 32 bits */
DieterGraef 0:d26c1b55cfca 220 break;
DieterGraef 0:d26c1b55cfca 221
DieterGraef 0:d26c1b55cfca 222 case 2: /* a.b -- 8.24 bits */
DieterGraef 0:d26c1b55cfca 223 if (val > 0xffffffUL) {
DieterGraef 0:d26c1b55cfca 224 return (0);
DieterGraef 0:d26c1b55cfca 225 }
DieterGraef 0:d26c1b55cfca 226 val |= parts[0] << 24;
DieterGraef 0:d26c1b55cfca 227 break;
DieterGraef 0:d26c1b55cfca 228
DieterGraef 0:d26c1b55cfca 229 case 3: /* a.b.c -- 8.8.16 bits */
DieterGraef 0:d26c1b55cfca 230 if (val > 0xffff) {
DieterGraef 0:d26c1b55cfca 231 return (0);
DieterGraef 0:d26c1b55cfca 232 }
DieterGraef 0:d26c1b55cfca 233 val |= (parts[0] << 24) | (parts[1] << 16);
DieterGraef 0:d26c1b55cfca 234 break;
DieterGraef 0:d26c1b55cfca 235
DieterGraef 0:d26c1b55cfca 236 case 4: /* a.b.c.d -- 8.8.8.8 bits */
DieterGraef 0:d26c1b55cfca 237 if (val > 0xff) {
DieterGraef 0:d26c1b55cfca 238 return (0);
DieterGraef 0:d26c1b55cfca 239 }
DieterGraef 0:d26c1b55cfca 240 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
DieterGraef 0:d26c1b55cfca 241 break;
DieterGraef 0:d26c1b55cfca 242 default:
DieterGraef 0:d26c1b55cfca 243 LWIP_ASSERT("unhandled", 0);
DieterGraef 0:d26c1b55cfca 244 break;
DieterGraef 0:d26c1b55cfca 245 }
DieterGraef 0:d26c1b55cfca 246 if (addr) {
DieterGraef 0:d26c1b55cfca 247 ip4_addr_set_u32(addr, htonl(val));
DieterGraef 0:d26c1b55cfca 248 }
DieterGraef 0:d26c1b55cfca 249 return (1);
DieterGraef 0:d26c1b55cfca 250 }
DieterGraef 0:d26c1b55cfca 251
DieterGraef 0:d26c1b55cfca 252 /**
DieterGraef 0:d26c1b55cfca 253 * Convert numeric IP address into decimal dotted ASCII representation.
DieterGraef 0:d26c1b55cfca 254 * returns ptr to static buffer; not reentrant!
DieterGraef 0:d26c1b55cfca 255 *
DieterGraef 0:d26c1b55cfca 256 * @param addr ip address in network order to convert
DieterGraef 0:d26c1b55cfca 257 * @return pointer to a global static (!) buffer that holds the ASCII
DieterGraef 0:d26c1b55cfca 258 * represenation of addr
DieterGraef 0:d26c1b55cfca 259 */
DieterGraef 0:d26c1b55cfca 260 char *
DieterGraef 0:d26c1b55cfca 261 ipaddr_ntoa(const ip_addr_t *addr)
DieterGraef 0:d26c1b55cfca 262 {
DieterGraef 0:d26c1b55cfca 263 static char str[16];
DieterGraef 0:d26c1b55cfca 264 return ipaddr_ntoa_r(addr, str, 16);
DieterGraef 0:d26c1b55cfca 265 }
DieterGraef 0:d26c1b55cfca 266
DieterGraef 0:d26c1b55cfca 267 /**
DieterGraef 0:d26c1b55cfca 268 * Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used.
DieterGraef 0:d26c1b55cfca 269 *
DieterGraef 0:d26c1b55cfca 270 * @param addr ip address in network order to convert
DieterGraef 0:d26c1b55cfca 271 * @param buf target buffer where the string is stored
DieterGraef 0:d26c1b55cfca 272 * @param buflen length of buf
DieterGraef 0:d26c1b55cfca 273 * @return either pointer to buf which now holds the ASCII
DieterGraef 0:d26c1b55cfca 274 * representation of addr or NULL if buf was too small
DieterGraef 0:d26c1b55cfca 275 */
DieterGraef 0:d26c1b55cfca 276 char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen)
DieterGraef 0:d26c1b55cfca 277 {
DieterGraef 0:d26c1b55cfca 278 u32_t s_addr;
DieterGraef 0:d26c1b55cfca 279 char inv[3];
DieterGraef 0:d26c1b55cfca 280 char *rp;
DieterGraef 0:d26c1b55cfca 281 u8_t *ap;
DieterGraef 0:d26c1b55cfca 282 u8_t rem;
DieterGraef 0:d26c1b55cfca 283 u8_t n;
DieterGraef 0:d26c1b55cfca 284 u8_t i;
DieterGraef 0:d26c1b55cfca 285 int len = 0;
DieterGraef 0:d26c1b55cfca 286
DieterGraef 0:d26c1b55cfca 287 s_addr = ip4_addr_get_u32(addr);
DieterGraef 0:d26c1b55cfca 288
DieterGraef 0:d26c1b55cfca 289 rp = buf;
DieterGraef 0:d26c1b55cfca 290 ap = (u8_t *)&s_addr;
DieterGraef 0:d26c1b55cfca 291 for(n = 0; n < 4; n++) {
DieterGraef 0:d26c1b55cfca 292 i = 0;
DieterGraef 0:d26c1b55cfca 293 do {
DieterGraef 0:d26c1b55cfca 294 rem = *ap % (u8_t)10;
DieterGraef 0:d26c1b55cfca 295 *ap /= (u8_t)10;
DieterGraef 0:d26c1b55cfca 296 inv[i++] = '0' + rem;
DieterGraef 0:d26c1b55cfca 297 } while(*ap);
DieterGraef 0:d26c1b55cfca 298 while(i--) {
DieterGraef 0:d26c1b55cfca 299 if (len++ >= buflen) {
DieterGraef 0:d26c1b55cfca 300 return NULL;
DieterGraef 0:d26c1b55cfca 301 }
DieterGraef 0:d26c1b55cfca 302 *rp++ = inv[i];
DieterGraef 0:d26c1b55cfca 303 }
DieterGraef 0:d26c1b55cfca 304 if (len++ >= buflen) {
DieterGraef 0:d26c1b55cfca 305 return NULL;
DieterGraef 0:d26c1b55cfca 306 }
DieterGraef 0:d26c1b55cfca 307 *rp++ = '.';
DieterGraef 0:d26c1b55cfca 308 ap++;
DieterGraef 0:d26c1b55cfca 309 }
DieterGraef 0:d26c1b55cfca 310 *--rp = 0;
DieterGraef 0:d26c1b55cfca 311 return buf;
DieterGraef 0:d26c1b55cfca 312 }