Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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