Exemplo n.º 1
0
void GetNetConfig::PrintDHCP(void)
{
	struct tm newtime;
    char buffer[32];
	errno_t error;

	if ((m_nOptions & pt_other) != pt_other) {
		return;
	}
    if (m_bTitle == TRUE) {
		printf("\tDHCP Enabled: \t");
	}
	if (!m_pAdapter->DhcpEnabled) {
        printf("No\n");
		return;
	}

    printf("Yes\n");
    if (m_bTitle == FALSE) {
		return;
	}
    printf("\t  DHCP Server: \t%s\n",
            m_pAdapter->DhcpServer.IpAddress.String);

    printf("\t  Lease Obtained: ");
    /* Display local time */
    error = _localtime32_s(&newtime, (__time32_t*) &m_pAdapter->LeaseObtained);
    if (error) {
        printf("Invalid Argument to _localtime32_s\n");
	}
    else {
        // Convert to an ASCII representation 
        error = asctime_s(buffer, 32, &newtime);
        if (error) {
            printf("Invalid Argument to asctime_s\n");
		}
        else {
            /* asctime_s returns the string terminated by \n\0 */
            printf("%s", buffer);
		}
    }

    printf("\t  Lease Expires:  ");
    error = _localtime32_s(&newtime, (__time32_t*) &m_pAdapter->LeaseExpires);
    if (error) {
        printf("Invalid Argument to _localtime32_s\n");
	}
    else {
        // Convert to an ASCII representation 
        error = asctime_s(buffer, 32, &newtime);
        if (error) {
            printf("Invalid Argument to asctime_s\n");
		}
		else {
            /* asctime_s returns the string terminated by \n\0 */
            printf("%s", buffer);
		}
    }
}
Exemplo n.º 2
0
fz_error*
setPageInfo(
    soPdfFile*  inFile,
    soPdfFile*  outFile)
{
    fz_error    *error = NULL;
    fz_obj      *outObj;
    char        creator[] = "soPdf ver " SO_PDF_VER;
    char        szTime[128] = "";
	struct tm   tmTemp;
    __time32_t  time;

    _time32(&time);
    _localtime32_s(&tmTemp, &time);
    strftime(szTime, sizeof(szTime), "%Y/%m/%d %H:%M", &tmTemp);

    PUT_INFO("Title", outFile->title);
    PUT_INFO("Author", outFile->author);
    PUT_INFO("Category", outFile->category);
    PUT_INFO("Publisher", outFile->publisher);
    PUT_INFO("Subject", outFile->subject);
    PUT_INFO("Creator", creator);
    PUT_INFO("Producer", creator);
    PUT_INFO("CreationDate", szTime);
    PUT_INFO("ModDate", szTime);

    return error;
}
Exemplo n.º 3
0
void DDS_Security_log (unsigned   log_level,
		       const char *message,
		       const char *category)
{
	struct timeval	tv;
	FILE		*f;
	struct tm	tm_data, *tm;
	char		tmbuf [40];
	DDS_LogInfo	log_info;

	if (!log_options_set || log_level < log_options.log_level)
		return;

	if (!log_options.log_file && !log_options.distribute) {
		log_printf (SEC_ID, log_level, "%s: %s\r\n", category, message);
		return;
	}
	if (log_options.log_file) {
		if (openf (f, logname, "a")) {
			gettimeofday (&tv, NULL);
#ifdef _WIN32
			_localtime32_s (&tm_data, &tv.tv_sec);
			tm = &tm_data;
#else
			tm = localtime_r (&tv.tv_sec, &tm_data);
			if (!tm) {
#ifdef LOG_DATE
				fprintf (f, "\?\?\?\?-\?\?\?-\?\? ");
#endif
				fprintf (f, "\?\?:\?\?:\?\?.\?\?\? ");
			}
			else
#endif
			{
				tmbuf [0] = '\0';
#ifdef LOG_DATE
				strftime (tmbuf, sizeof (tmbuf), "%Y-%m-%d ", tm);
#endif
				strftime (&tmbuf [strlen (tmbuf)],
						sizeof (tmbuf) - strlen (tmbuf),
						"%H:%M:%S.", tm);
				snprintf (&tmbuf [strlen (tmbuf)],
					  sizeof (tmbuf) - strlen (tmbuf),
					  "%03lu ", (unsigned long) tv.tv_usec / 1000);
				fprintf (f, "%s", tmbuf);
			}
			fprintf (f, "%s: %s\r\n", category, message);
			fclose (f);
		}
	}
	if (log_options.distribute && log_writer) {
		log_info.log_level = log_level;
		log_info.message = (char *) message;
		log_info.category = (char *) category;
		DDS_DataWriter_write (log_writer, &log_info, 0);
	}
}
Exemplo n.º 4
0
void Language::GetDateTimeString(TCHAR *buf, int cchLen, int time, int usec)
{
    const TCHAR szEnglishMonths[12][16] = 
    {
        TEXT("January"),
        TEXT("February"),
        TEXT("March"),
        TEXT("April"),
        TEXT("May"),
        TEXT("June"),
        TEXT("July"),
        TEXT("August"),
        TEXT("September"),
        TEXT("October"),
        TEXT("November"),
        TEXT("December")
    };
    const TCHAR *szEnglishName = _tables[_curLang].Get(IDS_LANG_NAME_ENG);

    struct tm tmTime;
    _localtime32_s(&tmTime, (__time32_t *)&time);

    if (_tcscmp(szEnglishName, TEXT("English")) == 0 ) // English
    {
        _stprintf_s(buf, cchLen, TEXT("%s %d, %d - %02d:%02d:%02d.%04d"), 
            szEnglishMonths[tmTime.tm_mon], 
            (int)tmTime.tm_mday, 
            (int)tmTime.tm_year + 1900,
            (int)tmTime.tm_hour, 
            (int)tmTime.tm_min, 
            (int)tmTime.tm_sec, 
            usec / 100);
    }
    else if (_tcscmp(szEnglishName, TEXT("Chinese Simplified")) == 0 ) // Chinese Simplified
    {
        _stprintf_s(buf, cchLen, TEXT("%d年%d月%d日 - %02d:%02d:%02d.%04d"), 
            (int)tmTime.tm_year + 1900,
            (int)tmTime.tm_mon, 
            (int)tmTime.tm_mday, 
            (int)tmTime.tm_hour, 
            (int)tmTime.tm_min, 
            (int)tmTime.tm_sec, 
            usec / 100);
    }
    else // Default: English
    {
        _stprintf_s(buf, cchLen, TEXT("%s %d, %d - %02d:%02d:%02d.%04d"), 
            szEnglishMonths[tmTime.tm_mon], 
            tmTime.tm_mday, 
            tmTime.tm_year + 1900,
            tmTime.tm_hour, 
            tmTime.tm_min, 
            tmTime.tm_sec, 
            usec / 100);
    }
}
Exemplo n.º 5
0
Arquivo: misc.cpp Projeto: xrmb/nxtv
__time64_t NXtimet32to64(__time32_t t32)
{
  tm t;
  _localtime32_s(&t, &t32); // ERR
  __time64_t r = _mktime64(&t);
  if(r == -1) 
  {
    R(-1, "mktime error");
    return _time64(NULL);
  }
  return r;
}
Exemplo n.º 6
0
int gameplay_ctrl_db_proc::logic_valid(const record* rec)
{
#ifdef GAME_SERVER
	//日常任务:提交时间与当前时间 不在1天,原有记录作废
	//每周x任务:提交时间与当前时间 不在1天,原有记录作废
	//指定日期任务:在time_valid处,已经被否定
#ifdef YN_LINUX
	Game_Logic::map_mutex m(&ctrl_db_mutex_);
#endif
  struct tm cur_tm_, commit_tm;	


#ifdef YN_LINUX
	time_t curt;
 	curt = time(NULL);
	localtime_r(&curt, &cur_tm_); 
	localtime_r(&rec->commit_time_, &commit_tm );
#endif
#ifdef YN_WINDOWS
	__time32_t curt;
 	curt = (__time32_t)time(NULL);
	 _localtime32_s(&cur_tm_, &curt ); 
	_localtime32_s( &commit_tm , &rec->commit_time_);
#endif

  if (cur_tm_.tm_year == commit_tm.tm_year &&
      cur_tm_.tm_yday == commit_tm.tm_yday)
  {
  	//同一天,有效
  	return 0;
  }	 
	return -1;
#else
    return 0;
#endif
}
Exemplo n.º 7
0
static errno_t __cdecl
_int_ctime32_s (char *d, size_t dn, const __time32_t *pt)
{
  struct tm ltm;
  errno_t e;

  if (!d || !dn)
     {
        errno = EINVAL;
	return EINVAL;
     }
  d[0] = 0;
  if (!pt)
     {
	errno = EINVAL;
	return EINVAL;
     }

  if ((e = _localtime32_s (&ltm, pt)) != 0)
    return e;  
  return asctime_s (d, dn, &ltm);
}
Exemplo n.º 8
0
//-------------------------------------------------------------------------------------
// Name: TimeLimitGetTimeRemaining()
//-------------------------------------------------------------------------------------
HRESULT TimeLimitGetTimeRemaining( TimeRemaining* pTime )
{
    if( 0 == pTime )
        return E_INVALIDARG;

    // zero out the structure
    ZeroMemory( pTime, sizeof( TimeRemaining ) );

    // Initialize the com subsystem
    HRESULT hr = Init();
    if( SUCCEEDED( hr ) )
    {
        tm tmStruct = { 0 };
        time_t ltTime;
        time( &ltTime );

#ifdef __STDC_SECURE_LIB__
        // Make use of the secure CRT functions
#if defined(_AMD64_)
        if( 0 != _localtime64_s( &tmStruct, &ltTime ) )
#else
		__time32_t t32;
		if( 0 != _localtime32_s( &tmStruct, &t32 ) )
#endif
        {
            hr = E_FAIL;
        }
#else
        // Secure CRT functions are not available.
        const tm* pTM = localtime( &ltTime );
        if( 0 == pTM )
        {
            tmStruct = *pTM;
        }
        else
        {
            hr = E_FAIL;
        }
#endif
        if( SUCCEEDED( hr ) )
        {
            HourlyRestrictions restrictions;
            hr = TimeLimitGetHourlyRestrictions( &restrictions );
            if( SUCCEEDED( hr ) )
            {
                BOOL logout = FALSE;
                int hours = 0;
                int d = tmStruct.tm_wday;
                int h = tmStruct.tm_hour;
                while( FALSE == logout && hours < ( 7 * 24 ) )
                {
                    if( restrictions.days[d] & ( 1 << h ) )
                    {
                        // this hour is allowed
                        ++hours;
                        ++h;
                        if( h == 24 )   // next day, reset hour index and increment day index
                        {
                            h = 0;
                            ++d;
                            if( d == 7 )    // end of week, reset day index to Sunday
                            {
                                d = 0;
                            }
                        }
                    }
                    else
                    {
                        // this hour is not allowed, we're done
                        logout = TRUE;
                    }
                }

                // assuming we didn't scan the whole week (if we did, there are no
                // blocked hours), calculate the exact hours, minutes, and seconds
                // left before logout.
                if( hours < ( 7 * 24 ) )
                {
                    int minutes = tmStruct.tm_min;
                    int seconds = tmStruct.tm_sec;
                    if( seconds > 0 )
                    {
                        // if seconds are greater than zero, then we need to account
                        // the partial minute represented by the seconds component
                        ++minutes;
                    }
                    if( minutes > 0 )
                    {
                        // if minutes are greater than zero, then we need to account
                        // for the partial hour represented by the minutes, since
                        // we've counted the hours (rather than subtracting the
                        // current hour from some fixed amount) we subtract rather
                        // than add, as we did for minutes.
                        --hours;
                    }
                    // we're subtracting the current minutes and seconds from 60 to
                    // get the time left until the beginning of the next whole hour
                    // if minutes or seconds are zero, we make them 60 so that
                    // subtraction turns up 00, as it should.
                    if( 0 == minutes )
                    {
                        minutes = 60;
                    }
                    if( 0 == seconds )
                    {
                        seconds = 60;
                    }
                    if( hours >= 0 )
                    {
                        pTime->days = static_cast<unsigned char>( hours / 24 );
                        pTime->hours = static_cast<unsigned char>( hours % 24 );
                        pTime->minutes = static_cast<unsigned char>( 60 - minutes );
                        pTime->seconds = static_cast<unsigned char>( 60 - seconds );
                    }
                    else
                    {
                        // at this point, if the hour count is negative, then
                        // the user has no time remaining.
                        pTime->days = 0;
                        pTime->hours = 0;
                        pTime->minutes = 0;
                        pTime->seconds = 0;
                    }
                }
                else
                {
                    // scanned the whole week and no blocked hours wer found
                    hr = S_FALSE;
                }
            }
        }
    }
    return hr;
}
Exemplo n.º 9
0
struct tm * localtime_r_win32(long *clock,struct tm * res)
{
    _localtime32_s(res,clock);
    return(res);
}
Exemplo n.º 10
0
//Testversion with new[] and delete[] for trying to allocate memory, rest like above
int getInterfacenames2()
{

    /* Declare and initialize variables */

    // It is possible for an adapter to have multiple
    // IPv4 addresses, gateways, and secondary WINS servers
    // assigned to the adapter.
    //
    // Note that this sample code only prints out the
    // first entry for the IP address/mask, and gateway, and
    // the primary and secondary WINS server for each adapter.

    IP_ADAPTER_INFO* pAdapterInfo;
    IP_ADAPTER_INFO* pAdapter = NULL;
    //needed to calculate the amount of Adapters to store
    ULONG memoryneeded = 0;
    DWORD dwRetVal = 0;
    UINT i;

    /* variables used to print DHCP time info */
    struct tm newtime;
    char buffer[32];
    errno_t error;

    if (GetAdaptersInfo(pAdapterInfo, &memoryneeded) == ERROR_BUFFER_OVERFLOW) {
        //creates an array of IP_ADAPTER_INFO with hopefully as many entries as needed (replaced the MALLOC function)
        pAdapterInfo = new IP_ADAPTER_INFO[memoryneeded / sizeof (IP_ADAPTER_INFO)];
        if (pAdapterInfo == NULL) {
            printf("Error allocating memory needed to call GetAdaptersinfo\n");
            return 1;
        }
    }

    if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &memoryneeded)) == NO_ERROR) {
        pAdapter = pAdapterInfo;
        while (pAdapter) {
            printf("\tComboIndex: \t%d\n", pAdapter->ComboIndex);
            printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
            printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
            printf("\tAdapter Addr: \t");
            for (i = 0; i < pAdapter->AddressLength; i++) {
                if (i == (pAdapter->AddressLength - 1))
                    printf("%.2X\n", (int) pAdapter->Address[i]);
                else
                    printf("%.2X-", (int) pAdapter->Address[i]);
            }
            printf("\tIndex: \t%d\n", pAdapter->Index);
            printf("\tType: \t");
            switch (pAdapter->Type) {
            case MIB_IF_TYPE_OTHER:
                printf("Other\n");
                break;
            case MIB_IF_TYPE_ETHERNET:
                printf("Ethernet\n");
                break;
            case MIB_IF_TYPE_TOKENRING:
                printf("Token Ring\n");
                break;
            case MIB_IF_TYPE_FDDI:
                printf("FDDI\n");
                break;
            case MIB_IF_TYPE_PPP:
                printf("PPP\n");
                break;
            case MIB_IF_TYPE_LOOPBACK:
                printf("Lookback\n");
                break;
            case MIB_IF_TYPE_SLIP:
                printf("Slip\n");
                break;
            default:
                printf("Unknown type %ld\n", pAdapter->Type);
                break;
            }

            printf("\tIP Address: \t%s\n",
                   pAdapter->IpAddressList.IpAddress.String);
            printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);

            printf("\tGateway: \t%s\n", pAdapter->GatewayList.IpAddress.String);
            printf("\t***\n");

            if (pAdapter->DhcpEnabled) {
                printf("\tDHCP Enabled: Yes\n");
                printf("\t  DHCP Server: \t%s\n",
                       pAdapter->DhcpServer.IpAddress.String);

                printf("\t  Lease Obtained: ");
                /* Display local time */
                error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseObtained);
                if (error)
                    printf("Invalid Argument to _localtime32_s\n");
                else {
                    // Convert to an ASCII representation
                    error = asctime_s(buffer, 32, &newtime);
                    if (error)
                        printf("Invalid Argument to asctime_s\n");
                    else
                        /* asctime_s returns the string terminated by \n\0 */
                        printf("%s", buffer);
                }

                printf("\t  Lease Expires:  ");
                error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseExpires);
                if (error)
                    printf("Invalid Argument to _localtime32_s\n");
                else {
                    // Convert to an ASCII representation
                    error = asctime_s(buffer, 32, &newtime);
                    if (error)
                        printf("Invalid Argument to asctime_s\n");
                    else
                        /* asctime_s returns the string terminated by \n\0 */
                        printf("%s", buffer);
                }
            } else
                printf("\tDHCP Enabled: No\n");

            if (pAdapter->HaveWins) {
                printf("\tHave Wins: Yes\n");
                printf("\t  Primary Wins Server:    %s\n",
                       pAdapter->PrimaryWinsServer.IpAddress.String);
                printf("\t  Secondary Wins Server:  %s\n",
                       pAdapter->SecondaryWinsServer.IpAddress.String);
            } else
                printf("\tHave Wins: No\n");
            pAdapter = pAdapter->Next;
            printf("\n");
        }
    } else {
        printf("GetAdaptersInfo failed with error: %d\n", dwRetVal);

    }
    if (pAdapterInfo)
        //replacement for the FREE function
        delete[] pAdapterInfo;

    return 0;
}
Exemplo n.º 11
0
int exec_iphelp_api_sample()
{
    /* Some general variables */
    ULONG ulOutBufLen;
    DWORD dwRetVal;
    unsigned int i;
  
    /* variables used for GetNetworkParams */
    FIXED_INFO *pFixedInfo;
    IP_ADDR_STRING *pIPAddr;

    /* variables used for GetAdapterInfo */
    IP_ADAPTER_INFO *pAdapterInfo;
    IP_ADAPTER_INFO *pAdapter;

    /* variables used to print DHCP time info */
    struct tm newtime;
    char buffer[32];
    errno_t error;

    /* variables used for GetInterfaceInfo */
    IP_INTERFACE_INFO *pInterfaceInfo;

    /* variables used for GetIpAddrTable */
    MIB_IPADDRTABLE *pIPAddrTable;
    DWORD dwSize;
    IN_ADDR IPAddr;
    //char *strIPAddr;
	char addr[16] = { 0 };
	std::string ip_str;

    /* variables used for AddIpAddress */
//    UINT iaIPAddress;
//    UINT imIPMask;
//    ULONG NTEContext;
//    ULONG NTEInstance;

    /* variables used for GetIpStatistics */
    MIB_IPSTATS *pStats;

    /* variables used for GetTcpStatistics */
    MIB_TCPSTATS *pTCPStats;

    printf("------------------------\n");
    printf("This is GetNetworkParams\n");
    printf("------------------------\n");

    pFixedInfo = (FIXED_INFO *) MALLOC(sizeof (FIXED_INFO));
    if (pFixedInfo == NULL) {
        printf("Error allocating memory needed to call GetNetworkParams\n");
        return 1;
    }
    ulOutBufLen = sizeof (FIXED_INFO);

    if (GetNetworkParams(pFixedInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
        FREE(pFixedInfo);
        pFixedInfo = (FIXED_INFO *) MALLOC(ulOutBufLen);
        if (pFixedInfo == NULL) {
            printf("Error allocating memory needed to call GetNetworkParams\n");
            return 1;
        }
    }

	dwRetVal = GetNetworkParams(pFixedInfo, &ulOutBufLen);
    if (dwRetVal != NO_ERROR) 
	{
        printf("GetNetworkParams failed with error %d\n", dwRetVal);
        if (pFixedInfo)
            FREE(pFixedInfo);
        return 1;
    } else {
        printf("\tHost Name: %s\n", pFixedInfo->HostName);
        printf("\tDomain Name: %s\n", pFixedInfo->DomainName);
        printf("\tDNS Servers:\n");
        printf("\t\t%s\n", pFixedInfo->DnsServerList.IpAddress.String);

        pIPAddr = pFixedInfo->DnsServerList.Next;
        while (pIPAddr) {
            printf("\t\t%s\n", pIPAddr->IpAddress.String);
            pIPAddr = pIPAddr->Next;
        }

        printf("\tNode Type: ");
        switch (pFixedInfo->NodeType) {
        case 1:
            printf("%s\n", "Broadcast");
            break;
        case 2:
            printf("%s\n", "Peer to peer");
            break;
        case 4:
            printf("%s\n", "Mixed");
            break;
        case 8:
            printf("%s\n", "Hybrid");
            break;
        default:
            printf("\n");
        }

        printf("\tNetBIOS Scope ID: %s\n", pFixedInfo->ScopeId);

        if (pFixedInfo->EnableRouting)
            printf("\tIP Routing Enabled: Yes\n");
        else
            printf("\tIP Routing Enabled: No\n");

        if (pFixedInfo->EnableProxy)
            printf("\tWINS Proxy Enabled: Yes\n");
        else
            printf("\tWINS Proxy Enabled: No\n");

        if (pFixedInfo->EnableDns)
            printf("\tNetBIOS Resolution Uses DNS: Yes\n");
        else
            printf("\tNetBIOS Resolution Uses DNS: No\n");
    }

    /* Free allocated memory no longer needed */
    if (pFixedInfo) {
        FREE(pFixedInfo);
        pFixedInfo = NULL;
    }

    printf("------------------------\n");
    printf("This is GetAdaptersInfo\n");
    printf("------------------------\n");

    pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
    if (pAdapterInfo == NULL) {
        printf("Error allocating memory needed to call GetAdapterInfo\n");
        return 1;
    }
    ulOutBufLen = sizeof (IP_ADAPTER_INFO);

    if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
        FREE(pAdapterInfo);
        pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen);
        if (pAdapterInfo == NULL) {
            printf("Error allocating memory needed to call GetAdapterInfo\n");
            return 1;
        }
    }

    if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != NO_ERROR) {
        printf("GetAdaptersInfo failed with error %d\n", dwRetVal);
        if (pAdapterInfo)
            FREE(pAdapterInfo);
        return 1;
    }

    pAdapter = pAdapterInfo;
    while (pAdapter) {
        printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
        printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
        printf("\tAdapter Addr: \t");
        for (i = 0; i < (int) pAdapter->AddressLength; i++) {
            if (i == (pAdapter->AddressLength - 1))
                printf("%.2X\n", (int) pAdapter->Address[i]);
            else
                printf("%.2X-", (int) pAdapter->Address[i]);
        }
        printf("\tIP Address: \t%s\n",
               pAdapter->IpAddressList.IpAddress.String);
        printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);

        printf("\tGateway: \t%s\n", pAdapter->GatewayList.IpAddress.String);
        printf("\t***\n");

        if (pAdapter->DhcpEnabled) {
            printf("\tDHCP Enabled: \tYes\n");
            printf("\tDHCP Server: \t%s\n",
                   pAdapter->DhcpServer.IpAddress.String);

            printf("\tLease Obtained: ");
            /* Display local time */
            error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseObtained);
            if (error)
                printf("\tInvalid Argument to _localtime32_s\n");

            else {
                // Convert to an ASCII representation 
                error = asctime_s(buffer, 32, &newtime);
                if (error)
                    printf("Invalid Argument to asctime_s\n");
                else
                    /* asctime_s returns the string terminated by \n\0 */
                    printf("%s", buffer);
            }

            printf("\tLease Expires:  ");
            error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseExpires);
            if (error)
                printf("Invalid Argument to _localtime32_s\n");
            else {
                // Convert to an ASCII representation 
                error = asctime_s(buffer, 32, &newtime);
                if (error)
                    printf("Invalid Argument to asctime_s\n");
                else
                    /* asctime_s returns the string terminated by \n\0 */
                    printf("%s", buffer);
            }
        } else
            printf("\tDHCP Enabled: \tNo\n");

        if (pAdapter->HaveWins) {
            printf("\tHave Wins: \tYes\n");
            printf("\tPrimary Wins Server: \t%s\n",
                   pAdapter->PrimaryWinsServer.IpAddress.String);
            printf("\tSecondary Wins Server: \t%s\n",
                   pAdapter->SecondaryWinsServer.IpAddress.String);
        } else
            printf("\tHave Wins: \tNo\n");

        printf("\n");
        pAdapter = pAdapter->Next;
    }

    printf("------------------------\n");
    printf("This is GetInterfaceInfo\n");
    printf("------------------------\n");

    pInterfaceInfo = (IP_INTERFACE_INFO *) MALLOC(sizeof (IP_INTERFACE_INFO));
    if (pInterfaceInfo == NULL) {
        printf("Error allocating memory needed to call GetInterfaceInfo\n");
        return 1;
    }
    ulOutBufLen = sizeof (IP_INTERFACE_INFO);
    if (GetInterfaceInfo(pInterfaceInfo, &ulOutBufLen) ==
        ERROR_INSUFFICIENT_BUFFER) {
        FREE(pInterfaceInfo);
        pInterfaceInfo = (IP_INTERFACE_INFO *) MALLOC(ulOutBufLen);
        if (pInterfaceInfo == NULL) {
            printf("Error allocating memory needed to call GetInterfaceInfo\n");
            return 1;
        }
        printf("\t The size needed for the output buffer ulLen = %ld\n",
               ulOutBufLen);
    }

    if ((dwRetVal = GetInterfaceInfo(pInterfaceInfo, &ulOutBufLen)) == NO_ERROR) {
        printf("\tNum Adapters: %ld\n\n", pInterfaceInfo->NumAdapters);
        for (i = 0; i < (unsigned int) pInterfaceInfo->NumAdapters; i++) {
            printf("\tAdapter Index[%d]: %ld\n", i,
                   pInterfaceInfo->Adapter[i].Index);
            printf("\tAdapter Name[%d]:  %ws\n\n", i,
                   pInterfaceInfo->Adapter[i].Name);
        }
        printf("GetInterfaceInfo call succeeded.\n");
    } else {
        LPVOID lpMsgBuf = NULL;

        if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),       // Default language
                          (LPTSTR) & lpMsgBuf, 0, NULL)) {
            printf("\tError: %s", (char*)lpMsgBuf);
        }
        LocalFree(lpMsgBuf);
    }

    ///* If DHCP enabled, release and renew the IP address */
    ///* THIS WORKS BUT IT TAKES A LONG TIME AND INTERRUPTS NET CONNECTIONS */
    //if (pAdapterInfo->DhcpEnabled && pInterfaceInfo->NumAdapters) {
    //    printf("Calling IpReleaseAddress for Adapter[%d]\n", 0);
    //    if ((dwRetVal =
    //         IpReleaseAddress(&pInterfaceInfo->Adapter[0])) == NO_ERROR) {
    //        printf("Ip Release succeeded.\n");
    //    }
    //    if ((dwRetVal =
    //         IpRenewAddress(&pInterfaceInfo->Adapter[0])) == NO_ERROR) {
    //        printf("Ip Renew succeeded.\n");
    //    }
    //}

    /* Free allocated memory no longer needed */
    if (pAdapterInfo) {
        FREE(pAdapterInfo);
        pAdapterInfo = NULL;
    }
    if (pInterfaceInfo) {
        FREE(pInterfaceInfo);
        pInterfaceInfo = NULL;
    }

    printf("----------------------\n");
    printf("This is GetIpAddrTable\n");
    printf("----------------------\n");

    pIPAddrTable = (MIB_IPADDRTABLE *) MALLOC(sizeof (MIB_IPADDRTABLE));
    if (pIPAddrTable == NULL) {
        printf("Error allocating memory needed to call GetIpAddrTable\n");
        return 1;
    }
    dwSize = 0;
    IPAddr.S_un.S_addr = ntohl(pIPAddrTable->table[1].dwAddr);	
	ip_str = InetNtopA(AF_INET, (PVOID)&IPAddr, addr, 16);

    if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
        FREE(pIPAddrTable);
        pIPAddrTable = (MIB_IPADDRTABLE *) MALLOC(dwSize);
        if (pIPAddrTable == NULL) {
            printf("Error allocating memory needed to call GetIpAddrTable\n");
            return 1;
        }
    }

    if ((dwRetVal = GetIpAddrTable(pIPAddrTable, &dwSize, 0)) != NO_ERROR) {
        printf("GetIpAddrTable failed with error %d\n", dwRetVal);
        if (pIPAddrTable)
            FREE(pIPAddrTable);
        return 1;
    }

    printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
    for (i = 0; i < (unsigned int) pIPAddrTable->dwNumEntries; i++) {
        printf("\n\tInterface Index[%d]:\t%ld\n", i,
               pIPAddrTable->table[i].dwIndex);
        IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
		printf("\tIP Address[%d]:     \t%s\n", i, InetNtopA(AF_INET, (PVOID)&IPAddr, addr, 16));
        IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
		printf("\tSubnet Mask[%d]:    \t%s\n", i, InetNtopA(AF_INET, (PVOID)&IPAddr, addr, 16));
        IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
		printf("\tBroadCast[%d]:      \t%s (%ld)\n", i, InetNtopA(AF_INET, (PVOID)&IPAddr, addr, 16), pIPAddrTable->table[i].dwBCastAddr);
        printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
        printf("\tAddress Index[%d]:  \t%ld\n", i, pIPAddrTable->table[i].dwIndex);
        printf("\tType and State[%d]:", i);
        if (pIPAddrTable->table[i].wType & MIB_IPADDR_PRIMARY)
            printf("\tPrimary IP Address");
        if (pIPAddrTable->table[i].wType & MIB_IPADDR_DYNAMIC)
            printf("\tDynamic IP Address");
        if (pIPAddrTable->table[i].wType & MIB_IPADDR_DISCONNECTED)
            printf("\tAddress is on disconnected interface");
        if (pIPAddrTable->table[i].wType & MIB_IPADDR_DELETED)
            printf("\tAddress is being deleted");
        if (pIPAddrTable->table[i].wType & MIB_IPADDR_TRANSIENT)
            printf("\tTransient address");
        printf("\n");
    }

    //iaIPAddress = inet_addr("192.168.0.27");
    //imIPMask = inet_addr("255.255.255.0");

    //NTEContext = 0;
    //NTEInstance = 0;

    //if ((dwRetVal = AddIPAddress(iaIPAddress,
    //                             imIPMask,
    //                             pIPAddrTable->table[0].
    //                             dwIndex,
    //                             &NTEContext, &NTEInstance)) != NO_ERROR) {

    //    LPVOID lpMsgBuf;
    //    printf("\tError adding IP address.\n");

    //    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),       // Default language
    //                      (LPTSTR) & lpMsgBuf, 0, NULL)) {
    //        printf("\tError: %s", (char*)lpMsgBuf);
    //    }
    //    LocalFree(lpMsgBuf);
    //}

    //if ((dwRetVal = DeleteIPAddress(NTEContext)) != NO_ERROR) {
    //    printf("DeleteIPAddress failed with error %d\n", dwRetVal);
    //}

    /* Free allocated memory no longer needed */
    if (pIPAddrTable) {
        FREE(pIPAddrTable);
        pIPAddrTable = NULL;
    }

    printf("-------------------------\n");
    printf("This is GetIPStatistics()\n");
    printf("-------------------------\n");

    pStats = (MIB_IPSTATS *) MALLOC(sizeof (MIB_IPSTATS));
    if (pStats == NULL) {
        printf("Error allocating memory needed to call GetIpStatistics\n");
        return 1;
    }

    if ((dwRetVal = GetIpStatistics(pStats)) != NO_ERROR) {
        printf("GetIPStatistics failed with error %d\n", dwRetVal);
        if (pStats)
            FREE(pStats);
        return 1;
    }

    printf("\tNumber of IP addresses: %ld\n", pStats->dwNumAddr);
    printf("\tNumber of Interfaces: %ld\n", pStats->dwNumIf);
    printf("\tReceives: %ld\n", pStats->dwInReceives);
    printf("\tOut Requests: %ld\n", pStats->dwOutRequests);
    printf("\tRoutes: %ld\n", pStats->dwNumRoutes);
    printf("\tTimeout Time: %ld\n", pStats->dwReasmTimeout);
    printf("\tIn Delivers: %ld\n", pStats->dwInDelivers);
    printf("\tIn Discards: %ld\n", pStats->dwInDiscards);
    printf("\tTotal In: %ld\n", pStats->dwInDelivers + pStats->dwInDiscards);
    printf("\tIn Header Errors: %ld\n", pStats->dwInHdrErrors);

    /* Free allocated memory no longer needed */
    if (pStats) {
        FREE(pStats);
        pStats = NULL;
    }

    printf("-------------------------\n");
    printf("This is GetTCPStatistics()\n");
    printf("-------------------------\n");

    pTCPStats = (MIB_TCPSTATS *) MALLOC(sizeof (MIB_TCPSTATS));
    if (pTCPStats == NULL) {
        printf("Error allocating memory needed to call GetTcpStatistics\n");
        return 1;
    }

    if ((dwRetVal = GetTcpStatistics(pTCPStats)) != NO_ERROR) {
        printf("GetTcpStatistics failed with error %d\n", dwRetVal);
        if (pTCPStats)
            FREE(pTCPStats);
        return 1;
    }

    printf("\tActive Opens: %ld\n", pTCPStats->dwActiveOpens);
    printf("\tPassive Opens: %ld\n", pTCPStats->dwPassiveOpens);
    printf("\tSegments Recv: %ld\n", pTCPStats->dwInSegs);
    printf("\tSegments Xmit: %ld\n", pTCPStats->dwOutSegs);
    printf("\tTotal # Conxs: %ld\n", pTCPStats->dwNumConns);

    /* Free allocated memory no longer needed */
    if (pTCPStats) {
        FREE(pTCPStats);
        pTCPStats = NULL;
    }

    return 0;
}
Exemplo n.º 12
0
/** 
 * @ingroup SipPlatform
 * @brief 로그 파일에 로그를 저장한다.
 * @param	iLevel	[in] 로그 파일 레벨
 * @param	fmt		[in] 로그 파일에 저장할 포맷 문자열
 * @param	...		[in] fmt 포맷에 입력할 인자들
 * @return	입력에 성공하면 0 을 리턴한다.
 *			입력값이 잘못된 경우에는 -1을 리턴한다.
 *			mutex lock 에 실패한 경우에는 -1을 리턴한다.
 *			로그 파일 Open 에 실패하면 -1을 리턴한다.
 *			로그 레벨이 설정된 로그 레벨과 일치하지 않는 경우에는 1을 리턴한다.
 */
int CLog::Print( EnumLogLevel iLevel, const char * fmt, ... )
{
	if( ( m_iLevel & iLevel ) == 0 ) return 1;

	va_list		ap;
	char		szBuf[LOG_MAX_SIZE];
	char		szDate[9], szHeader[30];
	int			iResult = 0;
	struct tm	sttTm;

	switch( iLevel )
	{
	case LOG_ERROR:
		snprintf( szHeader, sizeof(szHeader), "[ERROR] " );
		break;
	case LOG_INFO:
		snprintf( szHeader, sizeof(szHeader), "[INFO] " );
		break;
	case LOG_DEBUG:
		snprintf( szHeader, sizeof(szHeader), "[DEBUG] " );
		break;
	case LOG_NETWORK:
		snprintf( szHeader, sizeof(szHeader), "[NETWORK] " );
		break;
	case LOG_SYSTEM:
		snprintf( szHeader, sizeof(szHeader), "[SYSTEM] " );
		break;
	case LOG_SQL:
		snprintf( szHeader, sizeof(szHeader), "[SQL] " );
		break;
	default:
		memset( szHeader, 0, sizeof(szHeader) );
		break;
	}
	
	// 현재의 시간을 구한다.
	struct timeval	sttTime;

	gettimeofday( &sttTime, NULL );
#ifdef WIN32
	_localtime32_s( &sttTm, &sttTime.tv_sec );
#else
	localtime_r( &sttTime.tv_sec, &sttTm );	
#endif

	snprintf( szDate, sizeof(szDate), "%04d%02d%02d", sttTm.tm_year + 1900, sttTm.tm_mon + 1, sttTm.tm_mday );

	if( m_pThreadMutex && m_pThreadMutex->acquire() == false ) return -1;

	if( m_pszDirName && strcmp( m_szDate, szDate ) )
	{
		// 현재의 날짜와 클래스에 저장된 날짜가 다른 경우에는 로그 파일을 새로
		// 제작하여서 Open 한다.
		char	szFileName[FULLPATH_FILENAME_MAX_SIZE];
		
		m_iIndex = 1;

OPEN_FILE:
		m_iLogSize = 0;

		snprintf( szFileName, sizeof(szFileName), "%s%c%04d%02d%02d_%d.txt", m_pszDirName, DIR_SEP, sttTm.tm_year + 1900, sttTm.tm_mon + 1, sttTm.tm_mday, m_iIndex );
		
		// 이미 Open 된 파일이 있는 경우에는 이를 닫는다.
		if( m_sttFd ) 
		{
			fclose( m_sttFd );
			m_sttFd = NULL;
		}

		DeleteOldFile();

		if( m_iMaxLogSize > 0 )
		{
			int64_t iFileSize = GetFileSize( szFileName );
			if( iFileSize >= m_iMaxLogSize )
			{
				++m_iIndex;
				goto OPEN_FILE;
			}

			m_iLogSize = (int)iFileSize;
		}
		
		m_sttFd = fopen( szFileName, "ab" );
		if( m_sttFd == NULL )
		{
			printf( "log file(%s) open error\n", szFileName );
			iResult = -1;
		}

		snprintf( m_szDate, sizeof(m_szDate), "%s", szDate );
	}
	else if( m_iMaxLogSize > 0 && m_iLogSize >= m_iMaxLogSize )
	{
		++m_iIndex;
		goto OPEN_FILE;
	}

	if( m_pThreadMutex ) m_pThreadMutex->release();

	va_start( ap, fmt );
	vsnprintf( szBuf, sizeof(szBuf)-1, fmt, ap );
	va_end( ap );

	if( m_pThreadMutex && m_pThreadMutex->acquire() == false ) return -1;

	if( m_sttFd )
	{
		int iWrite;

#ifdef WIN32
		iWrite = fprintf( m_sttFd, "[%02d:%02d:%02d.%06u] %s[%u] %s\r\n"
			, sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec, sttTime.tv_usec, szHeader, GetCurrentThreadId(), szBuf );
#else
		iWrite = fprintf( m_sttFd, "[%02d:%02d:%02d.%06u] %s[%lu] %s\n"
			, sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec, (unsigned int)sttTime.tv_usec, szHeader, (unsigned long)pthread_self(), szBuf );
#endif
		fflush( m_sttFd );

		m_iLogSize += iWrite;
		m_iFolderSize += iWrite;
	}
	else if( m_pclsCallBack )
	{
#ifdef WIN32
		m_pclsCallBack->Print( iLevel, "[%u] %s", GetCurrentThreadId(), szBuf );
#else
		m_pclsCallBack->Print( iLevel, "[%u] %s", (unsigned long)pthread_self(), szBuf );
#endif
	}
	else
	{
#ifdef WIN32
		printf( "[%02d:%02d:%02d] %s%s\r\n"
			, sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec, szHeader, szBuf );
#else
		printf( "[%02d:%02d:%02d] %s%s\n"
			, sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec, szHeader, szBuf );
#endif
	}

	if( m_pThreadMutex ) m_pThreadMutex->release();

	return iResult;
}