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. */
| 597 | * EINVAL: Invalid port number. |
| 598 | */ |
| 599 | sentinelAddr *createSentinelAddr(char *hostname, int port) { |
| 600 | char ip[NET_IP_STR_LEN]; |
| 601 | sentinelAddr *sa; |
| 602 | |
| 603 | if (port < 0 || port > 65535) { |
| 604 | errno = EINVAL; |
| 605 | return NULL; |
| 606 | } |
| 607 | if (anetResolve(NULL,hostname,ip,sizeof(ip), |
| 608 | sentinel.resolve_hostnames ? ANET_NONE : ANET_IP_ONLY) == ANET_ERR) { |
| 609 | errno = ENOENT; |
| 610 | return NULL; |
| 611 | } |
| 612 | sa = zmalloc(sizeof(*sa)); |
| 613 | sa->hostname = sdsnew(hostname); |
| 614 | sa->ip = sdsnew(ip); |
| 615 | sa->port = port; |
| 616 | return sa; |
| 617 | } |
| 618 | |
| 619 | /* Return a duplicate of the source address. */ |
| 620 | sentinelAddr *dupSentinelAddr(sentinelAddr *src) { |
no test coverage detected