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

Method stringToAddress

Engine/source/platform/platformNet.cpp:1732–1859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1730}
1731
1732Net::Error Net::stringToAddress(const char *addressString, NetAddress *address, bool hostLookup, int requiredFamily)
1733{
1734 char addr[256];
1735 int port = 0;
1736 int actualFamily = AF_UNSPEC;
1737 if (!PlatformNetState::extractAddressParts(addressString, addr, port, actualFamily))
1738 {
1739 return WrongProtocolType;
1740 }
1741
1742 // Make sure family matches (in cast we have IP: stuff in address)
1743 if (requiredFamily != AF_UNSPEC && actualFamily != AF_UNSPEC && (actualFamily != requiredFamily))
1744 {
1745 return WrongProtocolType;
1746 }
1747
1748 if (actualFamily == AF_UNSPEC)
1749 {
1750 actualFamily = requiredFamily;
1751 }
1752
1753 addressString = addr;
1754 dMemset(address, '\0', sizeof(NetAddress));
1755
1756 if (!dStricmp(addressString, "broadcast"))
1757 {
1758 address->type = NetAddress::IPBroadcastAddress;
1759 if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET))
1760 return WrongProtocolType;
1761
1762 if (port != 0)
1763 address->port = port;
1764 else
1765 address->port = PlatformNetState::defaultPort;
1766 }
1767 else if (!dStricmp(addressString, "multicast"))
1768 {
1769 address->type = NetAddress::IPV6MulticastAddress;
1770 if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET6))
1771 return WrongProtocolType;
1772
1773 if (port != 0)
1774 address->port = port;
1775 else
1776 address->port = PlatformNetState::defaultPort;
1777 }
1778 else
1779 {
1780 sockaddr_in ipAddr;
1781 sockaddr_in6 ipAddr6;
1782
1783 dMemset(&ipAddr, 0, sizeof(ipAddr));
1784 dMemset(&ipAddr6, 0, sizeof(ipAddr6));
1785
1786 bool hasInterface = dStrchr(addressString, '%') != NULL; // if we have an interface, best use getaddrinfo to parse
1787
1788 // Check if we've got a simple ipv4 / ipv6
1789

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected