Esempio n. 1
0
void SocketAddress::_SocketAddress(NetworkStack *iface, const char *host, uint16_t port)
{
    _ip_address[0] = '\0';

    // gethostbyname must check for literals, so can call it directly
    int err = iface->gethostbyname(host, this);
    _port = port;
    if (err) {
        _addr = nsapi_addr_t();
        _port = 0;
    }
}
Esempio n. 2
0
void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
{
    nsapi_addr_t addr;

    addr = nsapi_addr_t();
    addr.version = version;
    if (version == NSAPI_IPv6) {
        memcpy(addr.bytes, bytes, NSAPI_IPv6_BYTES);
    } else if (version == NSAPI_IPv4) {
        memcpy(addr.bytes, bytes, NSAPI_IPv4_BYTES);
    }
    set_addr(addr);
}
Esempio n. 3
0
void SocketAddress::set_ip_address(const char *addr)
{
    _ip_address[0] = '\0';

    if (addr && ipv4_is_valid(addr)) {
        _addr.version = NSAPI_IPv4;
        ipv4_from_address(_addr.bytes, addr);
    } else if (addr && ipv6_is_valid(addr)) {
        _addr.version = NSAPI_IPv6;
        ipv6_from_address(_addr.bytes, addr);
    } else {
        _addr = nsapi_addr_t();
    }
}
Esempio n. 4
0
void SocketAddress::_SocketAddress(NetworkStack *iface, const char *host, uint16_t port)
{
    _ip_address[0] = '\0';

    // Check for valid IP addresses
    if (host && ipv4_is_valid(host)) {
        _addr.version = NSAPI_IPv4;
        ipv4_from_address(_addr.bytes, host);
        _port = port;
    } else if (host && ipv6_is_valid(host)) {
        _addr.version = NSAPI_IPv6;
        ipv6_from_address(_addr.bytes, host);
        _port = port;
    } else {
        // DNS lookup
        int err = iface->gethostbyname(this, host);
        _port = port;
        if (err) {
            _addr = nsapi_addr_t();
            _port = 0;
        }
    }
}