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

Function extractAddressParts

Engine/source/platform/platformNet.cpp:275–362  ·  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

273
274 /// Extracts core address parts from an address string. Returns false if it's malformed.
275 bool extractAddressParts(const char *addressString, char outAddress[256], int &outPort, int &outFamily)
276 {
277 outPort = 0;
278 outFamily = AF_UNSPEC;
279
280 if (!dStrnicmp(addressString, "ipx:", 4))
281 // ipx support deprecated
282 return false;
283
284 if (!dStrnicmp(addressString, "ip:", 3))
285 {
286 addressString += 3; // eat off the ip:
287 outFamily = AF_INET;
288 }
289 else if (!dStrnicmp(addressString, "ip6:", 4))
290 {
291 addressString += 4; // eat off the ip6:
292 outFamily = AF_INET6;
293 }
294
295 if (strlen(addressString) > 255)
296 return false;
297
298 char *portString = NULL;
299
300 if (addressString[0] == '[')
301 {
302 // Must be ipv6 notation
303 dStrcpy(outAddress, addressString+1);
304 addressString = outAddress;
305
306 portString = dStrchr(outAddress, ']');
307 if (portString)
308 {
309 // Sort out the :port after the ]
310 *portString++ = '\0';
311 if (*portString != ':')
312 {
313 portString = NULL;
314 }
315 else
316 {
317 *portString++ = '\0';
318 }
319 }
320
321 if (outFamily == AF_UNSPEC)
322 {
323 outFamily = AF_INET6;
324 }
325 }
326 else
327 {
328 dStrcpy(outAddress, addressString);
329 addressString = outAddress;
330
331 // Check to see if we have multiple ":" which would indicate this is an ipv6 address
332 char* scan = outAddress;

Callers 2

openConnectToMethod · 0.85
stringToAddressMethod · 0.85

Calls 4

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

Tested by

no test coverage detected