| 1710 | } |
| 1711 | |
| 1712 | Net::Error Net::stringToAddress(const char *addressString, NetAddress *address, bool hostLookup, int requiredFamily) |
| 1713 | { |
| 1714 | char addr[256]; |
| 1715 | int port = 0; |
| 1716 | int actualFamily = AF_UNSPEC; |
| 1717 | if (!PlatformNetState::extractAddressParts(addressString, addr, port, actualFamily)) |
| 1718 | { |
| 1719 | return WrongProtocolType; |
| 1720 | } |
| 1721 | |
| 1722 | // Make sure family matches (in cast we have IP: stuff in address) |
| 1723 | if (requiredFamily != AF_UNSPEC && actualFamily != AF_UNSPEC && (actualFamily != requiredFamily)) |
| 1724 | { |
| 1725 | return WrongProtocolType; |
| 1726 | } |
| 1727 | |
| 1728 | if (actualFamily == AF_UNSPEC) |
| 1729 | { |
| 1730 | actualFamily = requiredFamily; |
| 1731 | } |
| 1732 | |
| 1733 | addressString = addr; |
| 1734 | dMemset(address, '\0', sizeof(NetAddress)); |
| 1735 | |
| 1736 | if (!dStricmp(addressString, "broadcast")) |
| 1737 | { |
| 1738 | address->type = NetAddress::IPBroadcastAddress; |
| 1739 | if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET)) |
| 1740 | return WrongProtocolType; |
| 1741 | |
| 1742 | if (port != 0) |
| 1743 | address->port = port; |
| 1744 | else |
| 1745 | address->port = PlatformNetState::defaultPort; |
| 1746 | } |
| 1747 | else if (!dStricmp(addressString, "multicast")) |
| 1748 | { |
| 1749 | address->type = NetAddress::IPV6MulticastAddress; |
| 1750 | if (!(actualFamily == AF_UNSPEC || actualFamily == AF_INET6)) |
| 1751 | return WrongProtocolType; |
| 1752 | |
| 1753 | if (port != 0) |
| 1754 | address->port = port; |
| 1755 | else |
| 1756 | address->port = PlatformNetState::defaultPort; |
| 1757 | } |
| 1758 | else |
| 1759 | { |
| 1760 | sockaddr_in ipAddr; |
| 1761 | sockaddr_in6 ipAddr6; |
| 1762 | |
| 1763 | dMemset(&ipAddr, 0, sizeof(ipAddr)); |
| 1764 | dMemset(&ipAddr6, 0, sizeof(ipAddr6)); |
| 1765 | |
| 1766 | bool hasInterface = dStrchr(addressString, '%') != NULL; // if we have an interface, best use getaddrinfo to parse |
| 1767 | |
| 1768 | // Check if we've got a simple ipv4 / ipv6 |
| 1769 |
nothing calls this directly
no test coverage detected