Changeset 10661 for trunk/FACT++/src
- Timestamp:
- 05/11/11 14:52:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ftmctrl.cc
r10655 r10661 1710 1710 } 1711 1711 1712 /*1713 string GetLocalIp()1714 {1715 const char *kDnsIp = getenv("DIM_DNS_NODE");1716 1717 struct addrinfo hints, *servinfo, *p;1718 1719 memset(&hints, 0, sizeof hints);1720 hints.ai_family = AF_INET; //AF_UNSPEC; // use AF_INET6 to force IPv61721 hints.ai_socktype = SOCK_STREAM;1722 1723 int rv;1724 if ((rv = getaddrinfo(kDnsIp, NULL, &hints, &servinfo)) != 0)1725 {1726 cout << "WARNING - getaddrinfo: " << gai_strerror(rv) << endl;1727 return kDnsIp;1728 }1729 1730 // loop through all the results and connect to the first we can1731 for (p=servinfo; p; p=p->ai_next)1732 {1733 const int sock = socket(AF_INET, SOCK_DGRAM, 0);1734 if (sock==-1)1735 continue;1736 1737 if (connect(sock, p->ai_addr, p->ai_addrlen)==-1)1738 {1739 cout << "WARNING - connect: " << strerror(errno) << endl;1740 close(sock);1741 continue;1742 }1743 1744 sockaddr_in name;1745 socklen_t namelen = sizeof(name);1746 if (getsockname(sock, (sockaddr*)&name, &namelen)==-1)1747 {1748 cout << "WARNING - getsockname: " << strerror(errno) << endl;1749 close(sock);1750 continue;1751 }1752 1753 char buffer[16];1754 if (!inet_ntop(AF_INET, &name.sin_addr, buffer, 16))1755 {1756 cout << "WARNING - inet_ntop: " << strerror(errno) << endl;1757 close(sock);1758 continue;1759 }1760 1761 close(sock);1762 1763 freeaddrinfo(servinfo); // all done with this structure1764 1765 cout << "DIM_HOST_NODE=" << buffer << endl;1766 return buffer;1767 }1768 1769 freeaddrinfo(servinfo); // all done with this structure1770 return kDnsIp;1771 }1772 */1773 1774 1712 int main(int argc, const char* argv[]) 1775 1713 {
Note:
See TracChangeset
for help on using the changeset viewer.