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

Function extractAddressParts

engine/source/platform/platformNet.cpp:272–359  ·  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

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

Callers 2

openConnectToMethod · 0.85
stringToAddressMethod · 0.85

Calls 4

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

Tested by

no test coverage detected