Differences From Artifact [2bd834cec4]:
- File src/socket.m — part of check-in [aa0384d1bf] at 2018-07-28 18:45:36 on branch trunk — Rename OFLocalization -> OFLocale (user: js, size: 8408) [annotate] [blame] [check-ins using]
To Artifact [9e65efeb36]:
- File
src/socket.m
— part of check-in
[8aeee6680a]
at
2018-07-28 20:21:01
on branch trunk
— Add of_socket_address_ip_string()
This replaces of_address_to_string_and_port(). (user: js, size: 9710) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
218 219 220 221 222 223 224 225 226 227 228 229 230 231 | if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; # endif return ret; } #endif bool of_socket_address_equal(of_socket_address_t *address1, of_socket_address_t *address2) { struct sockaddr_in *addrIn1, *addrIn2; #ifdef HAVE_IPV6 | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; # endif return ret; } #endif static of_socket_address_t parseIPv4(OFString *IPv4, uint16_t port) { void *pool = objc_autoreleasePoolPush(); of_socket_address_t ret; struct sockaddr_in *sin = (struct sockaddr_in *)&ret.address; memset(&ret, '\0', sizeof(ret)); ret.length = sizeof(struct sockaddr_in); sin->sin_family = AF_INET; sin->sin_port = OF_BSWAP16_IF_LE(port); if (inet_pton(AF_INET, [IPv4 cStringWithEncoding: [OFLocale encoding]], &sin->sin_addr) != 1) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return ret; } #ifdef HAVE_IPV6 static of_socket_address_t parseIPv6(OFString *IPv6, uint16_t port) { void *pool = objc_autoreleasePoolPush(); of_socket_address_t ret; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ret.address; memset(&ret, '\0', sizeof(ret)); ret.length = sizeof(struct sockaddr_in6); sin6->sin6_family = AF_INET6; sin6->sin6_port = OF_BSWAP16_IF_LE(port); if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding: [OFLocale encoding]], &sin6->sin_addr6) != 1) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return ret; } #endif of_socket_address_t of_socket_address_parse_ip(OFString *IP, uint16_t port) { #ifdef HAVE_IPV6 @try { return parseIPv6(IP, port); } @catch (OFInvalidFormatException *e) { #endif return parseIPv4(IP, port); #ifdef HAVE_IPV6 } #endif } bool of_socket_address_equal(of_socket_address_t *address1, of_socket_address_t *address2) { struct sockaddr_in *addrIn1, *addrIn2; #ifdef HAVE_IPV6 |
︙ | ︙ | |||
331 332 333 334 335 336 337 | default: @throw [OFInvalidArgumentException exception]; } return hash; } | | | < < | < < | | < < < | | | > | > | | < < | > > < < | < < | < < | | > | > > | < > > > | | < < | > < | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | default: @throw [OFInvalidArgumentException exception]; } return hash; } static OFString * IPv4String(const of_socket_address_t *address, uint16_t *port) { const struct sockaddr_in *sin = (const struct sockaddr_in *)&address->address; char buffer[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &sin->sin_addr, buffer, sizeof(buffer)) == NULL) @throw [OFInvalidArgumentException exception]; if (port != NULL) *port = OF_BSWAP16_IF_LE(sin->sin_port); return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } #ifdef HAVE_IPV6 static OFString * IPv6String(const of_socket_address_t *address, uint16_t *port) { const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)&address->address; char buffer[INET6_ADDRSTRLEN]; if (inet_ntop(AF_INET, &sin6->sin_addr6, buffer, sizeof(buffer)) == NULL) @throw [OFInvalidArgumentException exception]; if (port != NULL) *port = OF_BSWAP16_IF_LE(sin6->sin_port); return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } #endif OFString * of_socket_address_ip_string(const of_socket_address_t *address, uint16_t *port) { switch (address->address.ss_family) { case AF_INET: return IPv4String(address, port); #ifdef HAVE_IPV6 case AF_INET6: return IPv6String(address, port); #endif default: @throw [OFInvalidArgumentException exception]; } } |