Differences From Artifact [cc5718b725]:
- File
src/resolver.m
— part of check-in
[49b1989b63]
at
2014-01-26 22:38:28
on branch trunk
— Move resolving functionality to resolver.m
This is in preparation for UDP sockets, so that they can share the
resolving functionality with TCP sockets. (user: js, size: 6919) [annotate] [blame] [check-ins using]
To Artifact [de483104d4]:
- File src/resolver.m — part of check-in [44c595058b] at 2014-01-27 12:34:10 on branch trunk — of_address_to_string: Add a way to get the port (user: js, size: 7422) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
207 208 209 210 211 212 213 | # endif #endif return ret; } OFString* | | > > > | | > > > > > > > > > > > > > > > > > | 207 208 209 210 211 212 213 214 215 216 217 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 | # endif #endif return ret; } OFString* of_address_to_string_and_port(struct sockaddr *address, socklen_t addressLength, uint16_t *port) { #ifdef HAVE_THREADSAFE_GETADDRINFO char host[NI_MAXHOST]; char portCString[NI_MAXSERV]; /* FIXME: Add NI_DGRAM for UDP? */ if (getnameinfo(address, addressLength, host, NI_MAXHOST, portCString, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV)) @throw [OFAddressTranslationFailedException exception]; if (port != NULL) { char *endptr; long tmp; if ((tmp = strtol(portCString, &endptr, 10)) > UINT16_MAX) @throw [OFOutOfRangeException exception]; if (endptr != NULL && *endptr != '\0') @throw [OFAddressTranslationFailedException exception]; *port = (uint16_t)tmp; } return [OFString stringWithUTF8String: host]; #else OFString *ret; char *host; if (address->sa_family != AF_INET) @throw [OFInvalidArgumentException exception]; # if OF_HAVE_THREADS if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; # endif host = inet_ntoa(((struct sockaddr_in*)(void*)address)->sin_addr); if (host == NULL) @throw [OFAddressTranslationFailedException exception]; ret = [OFString stringWithUTF8String: host]; if (port != NULL) *port = OF_BSWAP16_IF_LE( ((struct sockaddr_in*)(void*)address)->sin_port); # if OF_HAVE_THREADS if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; # endif return ret; #endif |
︙ | ︙ |