MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / getHostAddress

Method getHostAddress

src/net/Address.cpp:123–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123Address Address::getHostAddress(const std::string hname) {
124 Address a;
125 InAddr tempAddr;
126 int j;
127
128 struct hostent* hent;
129 if (hname == "") { // local address
130 char hostname[MAXHOSTNAMELEN + 1];
131 if (gethostname(hostname, sizeof(hostname)) >= 0) {
132 hent = gethostbyname(hostname);
133 }
134 else {
135 return a;
136 }
137 }
138 else if (inet_aton(hname.c_str(), &tempAddr) != 0) {
139 a.addr.clear();
140 a.addr.push_back(tempAddr);
141 return a;
142 }
143 else { // non-local address
144 hent = gethostbyname(hname.c_str());
145 }
146
147 if (!hent) {
148 herror("Looking up host name");
149 return a;
150 }
151
152 a.addr.clear();
153 for (j = 0; hent->h_addr_list[j] != NULL; j++) {
154 ::memcpy(&tempAddr, hent->h_addr_list[j], sizeof(tempAddr));
155 a.addr.push_back(tempAddr);
156 }
157 return a;
158}
159
160std::string Address::getHostByAddress(InAddr addr) {
161 int addrLen = sizeof(addr);

Callers 2

dnsLookupDoneFunction · 0.45
stateDNSMethod · 0.45

Calls 5

inet_atonFunction · 0.85
herrorFunction · 0.85
c_strMethod · 0.80
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected