<commit_before>//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////

// OS INT TYPES
#include "os/OsIntTypes.h"

// SYSTEM INCLUDES
#if defined(__pingtel_on_posix__)
#   include <sys/types.h>
#   include <sys/socket.h>
#   include <netdb.h>
#   include <netinet/in.h>
#   include <arpa/inet.h>
#endif
#include <assert.h>

// APPLICATION INCLUDES
#include "os/StunUtils.h"

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STATIC VARIABLE INITIALIZATIONS

/* //////////////////////////// PUBLIC //////////////////////////////////// */

/* ============================ CREATORS ================================== */

/* ============================ MANIPULATORS ============================== */

STUN_NAT_TYPE StunUtils::determineStunNatType(const char* szServer, const int port)
{
    OsDatagramSocket* pSocket = new OsDatagramSocket(0, NULL, 0, NULL) ;
    StunMessage msg ;
    UtlString stunIp ;
    UtlString localIp; 
    STUN_NAT_TYPE rc = STUN_NAT_ERROR_BAD_SERVER ;
    char cMappedIp[64] ;
    uint16_t usMappedPort ;
    char cChangedIp[64] ;
    uint16_t usChangedPort ;

    OsSocket::getHostIp(&localIp) ;
    if (OsSocket::getHostIpByName(szServer, &stunIp))
    {
        if (sendStunNatTest(pSocket, stunIp, port, false, false, cMappedIp, 
                &usMappedPort, cChangedIp, &usChangedPort))
        {
            if ((localIp.compareTo(cMappedIp) == 0) && 
                    usMappedPort == pSocket->getLocalHostPort())
            {
                if (sendStunNatTest(pSocket, stunIp, port, true, true, NULL, NULL,
                        NULL, NULL))
                {
                    rc = STUN_NAT_OPEN ;
                }
                else
                {
                    rc = STUN_NAT_SYMMETRIC_FIREWALL ;
                }
            }
            else
            {
                if (sendStunNatTest(pSocket, stunIp, port, true, true, cMappedIp, &usMappedPort,
                        NULL, NULL))
                {
                    rc = STUN_NAT_FULL_CONE ;
                }
                else
                {
                    char cMappedIp2[64] ;
                    unsigned short usMappedPort2 ;

                    if (sendStunNatTest(pSocket, cChangedIp, usChangedPort, false, false, cMappedIp2, &usMappedPort2,
                            NULL, NULL))
                    {
                        // Check mapped IP
                        if ((strcmp(cMappedIp, cMappedIp2) == 0) && (usMappedPort2 == usMappedPort))<commit_msg>One more build fix for VS6.<commit_after>//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////

// OS INT TYPES
#include "os/OsIntTypes.h"

// SYSTEM INCLUDES
#if defined(__pingtel_on_posix__)
#   include <sys/types.h>
#   include <sys/socket.h>
#   include <netdb.h>
#   include <netinet/in.h>
#   include <arpa/inet.h>
#endif
#include <assert.h>

// APPLICATION INCLUDES
#include "os/StunUtils.h"

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STATIC VARIABLE INITIALIZATIONS

/* //////////////////////////// PUBLIC //////////////////////////////////// */

/* ============================ CREATORS ================================== */

/* ============================ MANIPULATORS ============================== */

STUN_NAT_TYPE StunUtils::determineStunNatType(const char* szServer, const int port)
{
    OsDatagramSocket* pSocket = new OsDatagramSocket(0, NULL, 0, NULL) ;
    StunMessage msg ;
    UtlString stunIp ;
    UtlString localIp; 
    STUN_NAT_TYPE rc = STUN_NAT_ERROR_BAD_SERVER ;
    char cMappedIp[64] ;
    uint16_t usMappedPort ;
    char cChangedIp[64] ;
    uint16_t usChangedPort ;

    OsSocket::getHostIp(&localIp) ;
    if (OsSocket::getHostIpByName(szServer, &stunIp))
    {
        if (sendStunNatTest(pSocket, stunIp, port, false, false, cMappedIp, 
                &usMappedPort, cChangedIp, &usChangedPort))
        {
            if ((localIp.compareTo(cMappedIp) == 0) && 
                    usMappedPort == pSocket->getLocalHostPort())
            {
                if (sendStunNatTest(pSocket, stunIp, port, true, true, NULL, NULL,
                        NULL, NULL))
                {
                    rc = STUN_NAT_OPEN ;
                }
                else
                {
                    rc = STUN_NAT_SYMMETRIC_FIREWALL ;
                }
            }
            else
            {
                if (sendStunNatTest(pSocket, stunIp, port, true, true, cMappedIp, &usMappedPort,
                        NULL, NULL))
                {
                    rc = STUN_NAT_FULL_CONE ;
                }
                else
                {
                    char cMappedIp2[64] ;
                    uint16_t usMappedPort2 ;

                    if (sendStunNatTest(pSocket, cChangedIp, usChangedPort, false, false, cMappedIp2, &usMappedPort2,
                            NULL, NULL))
                    {
                        // Check mapped IP
                        if ((strcmp(cMappedIp, cMappedIp2) == 0) && (usMappedPort2 == usMappedPort))
{'fraction_non_alphanumeric': 0.18574007220216607, 'fraction_numerical': 0.013537906137184115, 'mean_word_length': 1.5868347338935573, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5915567', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1616, 'n_words': 339}