MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / getLocalName

Function getLocalName

engine/Poseidon/Network/Legacy/NetPeer.cpp:128–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126 return true;
127}
128
129bool getLocalName(char* name, unsigned len)
130{
131 if (!name)
132 {
133 return false;
134 }
135 if (gethostname(name, len) == SOCKET_ERROR)
136 {
137#ifdef NET_LOG_GET_LOCAL_NAME
138#ifdef _WIN32
139 NetLog("getLocalName: gethostname() failed with error: %d", WSAGetLastError());
140#else
141 NetLog("getLocalName: gethostname() failed!");
142#endif
143#endif
144 return false;
145 }
146#ifdef NET_LOG_GET_LOCAL_NAME
147 NetLog("getLocalName: local hostname: %s", name);
148#endif
149 if (isalpha(name[0]))
150 {
151 struct hostent* h = gethostbyname(name);
152 if (!h)
153 {
154#ifdef NET_LOG_GET_LOCAL_NAME
155#ifdef _WIN32
156 NetLog("getLocalName: gethostbyname(%s) failed with error: %d", name, WSAGetLastError());
157#else
158 NetLog("getLocalName: gethostbyname(%s) failed!", name);
159#endif
160#endif
161 return false;
162 }
163 strncpy(name, h->h_name, len);
164 name[len - 1] = (char)0;
165#ifdef NET_LOG_GET_LOCAL_NAME
166 NetLog("getLocalName: resolved local hostname: %s", name);
167#endif
168 }
169 return true;
170}
171
172bool getHostAddress(struct sockaddr_in& host, const char* ip, unsigned16 port)

Callers 2

InitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected