populate comdb2db_hosts based on hostname info of comdb2db_name * returns -1 if error or no osts wa found * returns 0 if hosts were found * this function has functionality similar to cdb2_tcpresolve() */
| 1672 | * this function has functionality similar to cdb2_tcpresolve() |
| 1673 | */ |
| 1674 | static int get_host_by_name(const char *comdb2db_name, char comdb2db_hosts[][CDB2HOSTNAME_LEN], int *num_hosts) |
| 1675 | { |
| 1676 | struct hostent *hp = NULL; |
| 1677 | char dns_name[512]; |
| 1678 | |
| 1679 | if (cdb2_default_cluster[0] == '\0') { |
| 1680 | snprintf(dns_name, sizeof(dns_name), "%s.%s", comdb2db_name, cdb2_dnssuffix); |
| 1681 | } else { |
| 1682 | snprintf(dns_name, sizeof(dns_name), "%s-%s.%s", cdb2_default_cluster, comdb2db_name, |
| 1683 | cdb2_dnssuffix); |
| 1684 | } |
| 1685 | #ifdef __APPLE__ |
| 1686 | hp = gethostbyname(dns_name); |
| 1687 | #elif _LINUX_SOURCE |
| 1688 | int herr; |
| 1689 | char tmp[8192]; |
| 1690 | int tmplen = sizeof(tmp); |
| 1691 | struct hostent hostbuf; |
| 1692 | gethostbyname_r(dns_name, &hostbuf, tmp, tmplen, &hp, &herr); |
| 1693 | #elif _SUN_SOURCE |
| 1694 | int herr; |
| 1695 | char tmp[8192]; |
| 1696 | int tmplen = sizeof(tmp); |
| 1697 | struct hostent hostbuf; |
| 1698 | hp = gethostbyname_r(dns_name, &hostbuf, tmp, tmplen, &herr); |
| 1699 | #else |
| 1700 | hp = gethostbyname(dns_name); |
| 1701 | #endif |
| 1702 | if (!hp) { |
| 1703 | fprintf(stderr, "%s:gethostbyname(%s): errno=%d err=%s\n", __func__, |
| 1704 | dns_name, errno, strerror(errno)); |
| 1705 | return -1; |
| 1706 | } |
| 1707 | |
| 1708 | int rc = -1; |
| 1709 | struct in_addr **addr_list = (struct in_addr **)hp->h_addr_list; |
| 1710 | for (int i = 0; addr_list[i] != NULL; i++) { |
| 1711 | strcpy(comdb2db_hosts[i], inet_ntoa(*addr_list[i])); |
| 1712 | (*num_hosts)++; |
| 1713 | rc = 0; |
| 1714 | } |
| 1715 | return rc; |
| 1716 | } |
| 1717 | |
| 1718 | static int get_comdb2db_hosts(cdb2_hndl_tp *hndl, char comdb2db_hosts[][CDB2HOSTNAME_LEN], int *comdb2db_ports, |
| 1719 | int *master, const char *comdb2db_name, int *num_hosts, int *comdb2db_num, |
no outgoing calls
no test coverage detected