⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condns.c

📁 本软件是TI公司免费提供的网络开发包 现在好象很难找到,有黑心的公司把它改一改,就卖价5000元,对网络开发和网络驱动开发有参考价值
💻 C
字号:
/*
 *  Copyright 2006 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *
 *  @(#) TCP/IP_Network_Developers_Kit 1.91.00.08 08-22-2006 (ndk-a08)
 */
//--------------------------------------------------------------------------
// IP Stack Console Demonstration Program
//--------------------------------------------------------------------------
// ConDNS.c
//
// Basic Console Functions
//     ConCmdLookup  - Name server lookup
//     ConStrToIPN   - Name/IP String to IPN
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <netmain.h>
#include <_stack.h>
#include "console.h"

//-------------------------------------------------------------------------
// ConCmdLookup()
//
// Function to lookup host
//-------------------------------------------------------------------------
void ConCmdLookup( int ntok, char *tok1 )
{
    char   *buffer;
    struct in_addr in1;
    int    retcode;

    // Check for 'stat ip'
    if( ntok == 0 )
    {
        ConPrintf("\n[NsLookup Command]\n");
        ConPrintf("\nCalled to lookup an official hostname and IP address\n");
        ConPrintf("from a supplied hostname or IP address\n\n");
        ConPrintf("nslookup hostname            - Resolve 'hostname' on default domain\n");
        ConPrintf("nslookup hostname.home1.net  - Resolve 'hostname.home1.net'\n");
        ConPrintf("nslookup x.x.x.x             - Resolve IP address\n\n");
    }
    else if( ntok == 1 )
    {
        // All the DNS functions need a scrap buffer
        buffer = mmAlloc( 512 );

        if( buffer )
        {
            // We can treat buffer as a HOSTENT structure after
            // DNSGetHostByXxx calls
            HOSTENT *phe = (HOSTENT *)buffer;

            // See if tok1 is an IP address
            if( inet_aton( tok1, &in1 ) )
                retcode = DNSGetHostByAddr( in1.s_addr, buffer, 512 );
            else
                retcode = DNSGetHostByName( tok1, buffer, 512 );

            if( retcode )
            {
                ConPrintf("DNSGetHostByName returned (%d) %s\n",
                           retcode, DNSErrorStr(retcode) );
                if( retcode == SOCKETERROR )
                    ConPrintf("Socket Error %d\n",fdError());
            }
            else
            {
                if( phe->h_name )
                    ConPrintf("Hostname = %s\n",phe->h_name);
                ConPrintf("AddrCnt  = %d\n",phe->h_addrcnt);
                for( retcode = 0; retcode < phe->h_addrcnt; retcode++ )
                {
                    ConPrintf("IPAddr   = ");
                    ConPrintIPN(phe->h_addr[retcode]);
                    ConPrintf("\n");
                }
            }
            ConPrintf("\n");
            mmFree( buffer );
        }
    }
    else
        ConPrintf("\nIllegal argument. Type 'nslookup' for help\n");
}

//-------------------------------------------------------------------------
// ConStrToIPN()
//
// Function to return an IP address from a supplied string. It is very
// similar to the NSLOOKUP command.
//-------------------------------------------------------------------------
int ConStrToIPN( char *str, IPN *pIPN )
{
    char   *buffer;
    struct in_addr in1;
    int    retcode = 0;

    // If the string is an IP, we're done
    if( inet_aton( str, &in1 ) )
    {
        *pIPN = in1.s_addr;
        return(1);
    }

    // All the DNS functions need a scrap buffer
    buffer = mmAlloc( 512 );
    if( buffer )
    {
        // We can treat buffer as a HOSTENT structure after
        // DNSGetHostByXxx calls
        HOSTENT *phe = (HOSTENT *)buffer;

        retcode = DNSGetHostByName( str, buffer, 512 );
        if( !retcode && phe->h_addrcnt )
        {
            *pIPN = phe->h_addr[0];
            retcode = 1;
        }
        else
            retcode = 0;

        mmFree( buffer );
    }
    return( retcode );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -