Changes in uspace/lib/c/generic/net/inet.c [45bb1d2:e4554d4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/inet.c
r45bb1d2 re4554d4 51 51 * @param[out] address The character buffer to be filled. 52 52 * @param[in] length The buffer length. 53 * @return EOK on success.54 * @return EINVAL if the data or address parameter is NULL.55 * @return ENOMEM if the character buffer is not long enough.56 * @return ENOTSUP if the address family is not supported.53 * @returns EOK on success. 54 * @returns EINVAL if the data or address parameter is NULL. 55 * @returns ENOMEM if the character buffer is not long enough. 56 * @returns ENOTSUP if the address family is not supported. 57 57 */ 58 58 int … … 64 64 switch (family) { 65 65 case AF_INET: 66 / * Check output buffer size */66 // check the output buffer size 67 67 if (length < INET_ADDRSTRLEN) 68 68 return ENOMEM; 69 69 70 / * Fill buffer with IPv4 address */70 // fill the buffer with the IPv4 address 71 71 snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", 72 72 data[0], data[1], data[2], data[3]); … … 75 75 76 76 case AF_INET6: 77 / * Check output buffer size */77 // check the output buffer size 78 78 if (length < INET6_ADDRSTRLEN) 79 79 return ENOMEM; 80 80 81 / * Fill buffer with IPv6 address */81 // fill the buffer with the IPv6 address 82 82 snprintf(address, length, 83 83 "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:" … … 101 101 * @param[in] address The character buffer to be parsed. 102 102 * @param[out] data The address data to be filled. 103 * @return EOK on success.104 * @return EINVAL if the data parameter is NULL.105 * @return ENOENT if the address parameter is NULL.106 * @return ENOTSUP if the address family is not supported.103 * @returns EOK on success. 104 * @returns EINVAL if the data parameter is NULL. 105 * @returns ENOENT if the address parameter is NULL. 106 * @returns ENOTSUP if the address family is not supported. 107 107 */ 108 108 int inet_pton(uint16_t family, const char *address, uint8_t *data) … … 124 124 return EINVAL; 125 125 126 / * Set processing parameters */126 // set the processing parameters 127 127 switch (family) { 128 128 case AF_INET: … … 142 142 } 143 143 144 / * Erase if no address */144 // erase if no address 145 145 if (!address) { 146 146 bzero(data, count); … … 148 148 } 149 149 150 / * Process string from the beginning */150 // process the string from the beginning 151 151 next = address; 152 152 index = 0; 153 153 do { 154 / * If the actual character is set */154 // if the actual character is set 155 155 if (next && *next) { 156 156 157 / * If not on the first character */157 // if not on the first character 158 158 if (index) { 159 / * Move to the next character */159 // move to the next character 160 160 ++next; 161 161 } 162 162 163 / * Parse the actual integral value */163 // parse the actual integral value 164 164 value = strtoul(next, &last, base); 165 /* 166 * Remember the last problematic character 167 * should be either '.' or ':' but is ignored to be 168 * more generic 169 */ 165 // remember the last problematic character 166 // should be either '.' or ':' but is ignored to be more 167 // generic 170 168 next = last; 171 169 172 / * Fill the address data byte by byte */170 // fill the address data byte by byte 173 171 shift = bytes - 1; 174 172 do { 175 / * like little endian */173 // like little endian 176 174 data[index + shift] = value; 177 175 value >>= 8; … … 180 178 index += bytes; 181 179 } else { 182 / * Erase the rest of the address */180 // erase the rest of the address 183 181 bzero(data + index, count - index); 184 182 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.