MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / extractAddressParts

Function extractAddressParts

Engine/source/platform/platformNet.cpp:228–315  ·  view source on GitHub ↗

Extracts core address parts from an address string. Returns false if it's malformed.

Source from the content-addressed store, hash-verified

226
227 /// Extracts core address parts from an address string. Returns false if it's malformed.
228 bool extractAddressParts(const char *addressString, char outAddress[256], int &outPort, int &outFamily)
229 {
230 outPort = 0;
231 outFamily = AF_UNSPEC;
232
233 if (!dStrnicmp(addressString, "ipx:", 4))
234 // ipx support deprecated
235 return false;
236
237 if (!dStrnicmp(addressString, "ip:", 3))
238 {
239 addressString += 3; // eat off the ip:
240 outFamily = AF_INET;
241 }
242 else if (!dStrnicmp(addressString, "ip6:", 4))
243 {
244 addressString += 4; // eat off the ip6:
245 outFamily = AF_INET6;
246 }
247
248 if (strlen(addressString) > 255)
249 return false;
250
251 char *portString = NULL;
252
253 if (addressString[0] == '[')
254 {
255 // Must be ipv6 notation
256 dStrcpy(outAddress, addressString+1, 256);
257 addressString = outAddress;
258
259 portString = dStrchr(outAddress, ']');
260 if (portString)
261 {
262 // Sort out the :port after the ]
263 *portString++ = '\0';
264 if (*portString != ':')
265 {
266 portString = NULL;
267 }
268 else
269 {
270 *portString++ = '\0';
271 }
272 }
273
274 if (outFamily == AF_UNSPEC)
275 {
276 outFamily = AF_INET6;
277 }
278 }
279 else
280 {
281 dStrcpy(outAddress, addressString, 256);
282 addressString = outAddress;
283
284 // Check to see if we have multiple ":" which would indicate this is an ipv6 address
285 char* scan = outAddress;

Callers 2

openConnectToMethod · 0.85
stringToAddressMethod · 0.85

Calls 4

dStrnicmpFunction · 0.85
dStrcpyFunction · 0.85
dAtoiFunction · 0.85
dStrchrFunction · 0.50

Tested by

no test coverage detected