Create a sentinelAddr object and return it on success. * On error NULL is returned and errno is set to: * ENOENT: Can't resolve the hostname. * EINVAL: Invalid port number. */
| 599 | * EINVAL: Invalid port number. |
| 600 | */ |
| 601 | sentinelAddr *createSentinelAddr(char *hostname, int port) { |
| 602 | char ip[NET_IP_STR_LEN]; |
| 603 | sentinelAddr *sa; |
| 604 | |
| 605 | if (port < 0 || port > 65535) { |
| 606 | errno = EINVAL; |
| 607 | return NULL; |
| 608 | } |
| 609 | if (anetResolve(NULL,hostname,ip,sizeof(ip), |
| 610 | sentinel.resolve_hostnames ? ANET_NONE : ANET_IP_ONLY) == ANET_ERR) { |
| 611 | errno = ENOENT; |
| 612 | return NULL; |
| 613 | } |
| 614 | sa = (sentinelAddr*)zmalloc(sizeof(*sa), MALLOC_LOCAL); |
| 615 | sa->hostname = sdsnew(hostname); |
| 616 | sa->ip = sdsnew(ip); |
| 617 | sa->port = port; |
| 618 | return sa; |
| 619 | } |
| 620 | |
| 621 | /* Return a duplicate of the source address. */ |
| 622 | sentinelAddr *dupSentinelAddr(sentinelAddr *src) { |
no test coverage detected