<commit_before>/* Socket
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "NetworkStack.h"
#include "nsapi_dns.h"
#include "mbed.h"
#include "stddef.h"
#include <new>


// Default NetworkStack operations
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
    // check for simple ip addresses
    if (address->set_ip_address(name)) {
        if (address->get_ip_version() != version) {
            return NSAPI_ERROR_DNS_FAILURE;
        }

        return 0;
    }

    return nsapi_dns_query(this, name, address, version);
}

int NetworkStack::add_dns_server(const SocketAddress &address)
{
    return nsapi_dns_add_server(address);
}

int NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
{<commit_msg>nsapi - Added better heuristic for the default record of DNS queries<commit_after>/* Socket
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "NetworkStack.h"
#include "nsapi_dns.h"
#include "mbed.h"
#include "stddef.h"
#include <new>


// Default NetworkStack operations
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
    // check for simple ip addresses
    if (address->set_ip_address(name)) {
        if (address->get_ip_version() != version) {
            return NSAPI_ERROR_DNS_FAILURE;
        }

        return 0;
    }

    // if the version is unspecified, try to guess the version from the
    // ip address of the underlying stack
    if (version == NSAPI_UNSPEC) {
        SocketAddress testaddress;
        if (testaddress.set_ip_address(this->get_ip_address())) {
            version = testaddress.get_ip_version();
        }
    }

    return nsapi_dns_query(this, name, address, version);
}

int NetworkStack::add_dns_server(const SocketAddress &address)
{
    return nsapi_dns_add_server(address);
}

int NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
{
{'fraction_non_alphanumeric': 0.09028683181225554, 'fraction_numerical': 0.005867014341590613, 'mean_word_length': 3.7215384615384615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306464', 'n_tokens_mistral': 904, 'n_tokens_neox': 882, 'n_words': 319}