Changeset 3495654 in mainline
- Timestamp:
- 2013-04-30T19:28:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c7ba2d
- Parents:
- 9e7898e
- Location:
- uspace
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/inet/inet.c
r9e7898e r3495654 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 37 37 #include <errno.h> 38 #include <inet/addr.h> 38 39 #include <inet/inetcfg.h> 39 40 #include <loc.h> … … 54 55 } 55 56 56 static int naddr_parse(const char *text, inet_naddr_t *naddr)57 {58 unsigned long a[4], bits;59 char *cp = (char *)text;60 int i;61 62 for (i = 0; i < 3; i++) {63 a[i] = strtoul(cp, &cp, 10);64 if (*cp != '.')65 return EINVAL;66 ++cp;67 }68 69 a[3] = strtoul(cp, &cp, 10);70 if (*cp != '/')71 return EINVAL;72 ++cp;73 74 bits = strtoul(cp, &cp, 10);75 if (*cp != '\0')76 return EINVAL;77 78 naddr->ipv4 = 0;79 for (i = 0; i < 4; i++) {80 if (a[i] > 255)81 return EINVAL;82 naddr->ipv4 = (naddr->ipv4 << 8) | a[i];83 }84 85 if (bits > 31)86 return EINVAL;87 88 naddr->bits = bits;89 return EOK;90 }91 92 static int addr_parse(const char *text, inet_addr_t *addr)93 {94 unsigned long a[4];95 char *cp = (char *)text;96 int i;97 98 for (i = 0; i < 3; i++) {99 a[i] = strtoul(cp, &cp, 10);100 if (*cp != '.')101 return EINVAL;102 ++cp;103 }104 105 a[3] = strtoul(cp, &cp, 10);106 if (*cp != '\0')107 return EINVAL;108 109 addr->ipv4 = 0;110 for (i = 0; i < 4; i++) {111 if (a[i] > 255)112 return EINVAL;113 addr->ipv4 = (addr->ipv4 << 8) | a[i];114 }115 116 return EOK;117 }118 119 static int naddr_format(inet_naddr_t *naddr, char **bufp)120 {121 int rc;122 123 rc = asprintf(bufp, "%d.%d.%d.%d/%d", naddr->ipv4 >> 24,124 (naddr->ipv4 >> 16) & 0xff, (naddr->ipv4 >> 8) & 0xff,125 naddr->ipv4 & 0xff, naddr->bits);126 127 if (rc < 0)128 return ENOMEM;129 130 return EOK;131 }132 133 static int addr_format(inet_addr_t *addr, char **bufp)134 {135 int rc;136 137 rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,138 (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,139 addr->ipv4 & 0xff);140 141 if (rc < 0)142 return ENOMEM;143 144 return EOK;145 }146 147 57 static int addr_create_static(int argc, char *argv[]) 148 58 { … … 178 88 } 179 89 180 rc = naddr_parse(addr_spec, &naddr);90 rc = inet_naddr_parse(addr_spec, &naddr); 181 91 if (rc != EOK) { 182 92 printf(NAME ": Invalid network address format '%s'.\n", … … 267 177 route_name = argv[2]; 268 178 269 rc = naddr_parse(dest_str, &dest);179 rc = inet_naddr_parse(dest_str, &dest); 270 180 if (rc != EOK) { 271 181 printf(NAME ": Invalid network address format '%s'.\n", … … 274 184 } 275 185 276 rc = addr_parse(router_str, &router);186 rc = inet_addr_parse(router_str, &router); 277 187 if (rc != EOK) { 278 188 printf(NAME ": Invalid address format '%s'.\n", router_str); … … 366 276 } 367 277 368 rc = naddr_format(&ainfo.naddr, &astr);278 rc = inet_naddr_format(&ainfo.naddr, &astr); 369 279 if (rc != EOK) { 370 280 printf("Memory allocation failed.\n"); … … 430 340 } 431 341 432 rc = naddr_format(&srinfo.dest, &dest_str);342 rc = inet_naddr_format(&srinfo.dest, &dest_str); 433 343 if (rc != EOK) { 434 344 printf("Memory allocation failed.\n"); … … 437 347 } 438 348 439 rc = addr_format(&srinfo.router, &router_str);349 rc = inet_addr_format(&srinfo.router, &router_str); 440 350 if (rc != EOK) { 441 351 printf("Memory allocation failed.\n"); -
uspace/app/ping/ping.c
r9e7898e r3495654 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/addr.h> 39 40 #include <inet/inetping.h> 40 41 #include <io/console.h> … … 71 72 } 72 73 73 static int addr_parse(const char *text, inet_addr_t *addr)74 {75 unsigned long a[4];76 char *cp = (char *)text;77 int i;78 79 for (i = 0; i < 3; i++) {80 a[i] = strtoul(cp, &cp, 10);81 if (*cp != '.')82 return EINVAL;83 ++cp;84 }85 86 a[3] = strtoul(cp, &cp, 10);87 if (*cp != '\0')88 return EINVAL;89 90 addr->ipv4 = 0;91 for (i = 0; i < 4; i++) {92 if (a[i] > 255)93 return EINVAL;94 addr->ipv4 = (addr->ipv4 << 8) | a[i];95 }96 97 return EOK;98 }99 100 static int addr_format(inet_addr_t *addr, char **bufp)101 {102 int rc;103 104 rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,105 (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,106 addr->ipv4 & 0xff);107 108 if (rc < 0)109 return ENOMEM;110 111 return EOK;112 }113 114 74 static void ping_signal_done(void) 115 75 { … … 125 85 int rc; 126 86 127 rc = addr_format(&sdu->src, &asrc);87 rc = inet_addr_format(&sdu->src, &asrc); 128 88 if (rc != EOK) 129 89 return ENOMEM; 130 90 131 rc = addr_format(&sdu->dest, &adest);91 rc = inet_addr_format(&sdu->dest, &adest); 132 92 if (rc != EOK) { 133 93 free(asrc); … … 237 197 238 198 /* Parse destination address */ 239 rc = addr_parse(argv[argi], &dest_addr);199 rc = inet_addr_parse(argv[argi], &dest_addr); 240 200 if (rc != EOK) { 241 201 printf(NAME ": Invalid address format.\n"); -
uspace/lib/c/Makefile
r9e7898e r3495654 91 91 generic/task.c \ 92 92 generic/futex.c \ 93 generic/inet/addr.c \ 93 94 generic/inet.c \ 94 95 generic/inetcfg.c \ -
uspace/lib/c/include/inet/inet.h
r9e7898e r3495654 40 40 #define INET_TTL_MAX 255 41 41 42 /** Node address */ 42 43 typedef struct { 43 44 uint32_t ipv4; 44 45 } inet_addr_t; 46 47 /** Network address */ 48 typedef struct { 49 /** Address */ 50 uint32_t ipv4; 51 /** Number of valid bits in @c ipv4 */ 52 int bits; 53 } inet_naddr_t; 45 54 46 55 typedef struct { -
uspace/lib/c/include/inet/inetcfg.h
r9e7898e r3495654 38 38 #include <inet/inet.h> 39 39 #include <sys/types.h> 40 41 /** Network address */42 typedef struct {43 /** Address */44 uint32_t ipv4;45 /** Number of valid bits in @c ipv4 */46 int bits;47 } inet_naddr_t;48 40 49 41 /** Address object info */
Note:
See TracChangeset
for help on using the changeset viewer.