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

Method stringToAddress

Engine/source/platform/platformNet.cpp:1685–1812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1683}
1684
1685Net::Error Net::stringToAddress(const char *addressString, NetAddress *address, bool hostLookup, int requiredFamily)
1686{
1687 char addr[256];
1688 int port = 0;
1689 int actualFamily = AF_UNSPEC;
1690 if (!PlatformNetState::extractAddressParts(addressString, addr, port, actualFamily))
1691 {
1692 return WrongProtocolType;
1693 }
1694
1695 // Make sure family matches (in cast we have IP: stuff in address)
1696 if (requiredFamily != AF_UNSPEC && actualFamily != AF_UNSPEC && (actualFamily != requiredFamily))
1697 {
1698 return WrongProtocolType;
1699 }
1700
1701 if (actualFamily == AF_UNSPEC)
1702 {
1703 actualFamily = requiredFamily;
1704 }
1705
1706 addressString = addr;
1707 dMemset(address, '\0', sizeof(NetAddress));
1708
1709 if (!dStricmp(addressString, "broadcast"))
1710 {
1711 address->type = NetAddress::IPBroadcastAddress;
1712 if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET))
1713 return WrongProtocolType;
1714
1715 if (port != 0)
1716 address->port = port;
1717 else
1718 address->port = PlatformNetState::defaultPort;
1719 }
1720 else if (!dStricmp(addressString, "multicast"))
1721 {
1722 address->type = NetAddress::IPV6MulticastAddress;
1723 if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET6))
1724 return WrongProtocolType;
1725
1726 if (port != 0)
1727 address->port = port;
1728 else
1729 address->port = PlatformNetState::defaultPort;
1730 }
1731 else
1732 {
1733 sockaddr_in ipAddr;
1734 sockaddr_in6 ipAddr6;
1735
1736 dMemset(&ipAddr, 0, sizeof(ipAddr));
1737 dMemset(&ipAddr6, 0, sizeof(ipAddr6));
1738
1739 bool hasInterface = dStrchr(addressString, '%') != NULL; // if we have an interface, best use getaddrinfo to parse
1740
1741 // Check if we've got a simple ipv4 / ipv6
1742

Callers

nothing calls this directly

Calls 7

extractAddressPartsFunction · 0.85
dStricmpFunction · 0.85
IPSocketToNetAddressFunction · 0.85
IPSocket6ToNetAddressFunction · 0.85
pickAddressByProtocolFunction · 0.85
dMemsetFunction · 0.50
dStrchrFunction · 0.50

Tested by

no test coverage detected