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

📄 contftp.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
//--------------------------------------------------------------------------
// ConTFTP.c
//
// Basic Console Functions
//     ConCmdTFTP    - Name server lookup
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <netmain.h>
#include <_stack.h>
#include "console.h"

static void TestTFTP( IPN IPAddr, char *File );

//-------------------------------------------------------------------------
// ConCmdTFTP()
//
// Function to perform TFTP
//-------------------------------------------------------------------------
void ConCmdTFTP( int ntok, char *tok1, char *tok2 )
{
    IPN    IPAddr;

    // Check for 'stat ip'
    if( ntok == 0 )
    {
        ConPrintf("\n[TFTP Command]\n");
        ConPrintf("\nCalled to retrieve a file from a TFTP server.\n\n");
        ConPrintf("tftp x.x.x.x myfile  - Retrieve 'myfile' from IP address\n");
        ConPrintf("tftp hostname myfile - Resolve 'hostname' and retrieve 'myfile'\n\n");
    }
    else if( ntok == 2 )
    {
       if( !ConStrToIPN( tok1, &IPAddr ) )
           ConPrintf("Invalid address\n\n");
       else
           TestTFTP( IPAddr, tok2 );
    }
    else
        ConPrintf("\nIllegal argument. Type 'tftp' for help\n");
}

//-------------------------------------------------------------------------
// TestTFTP()
//
//-------------------------------------------------------------------------
static void TestTFTP( IPN IPAddr, char *File )
{
    int    rc;
    char   *buffer;
    UINT16 ErrorCode;
    UINT32 Size;

    buffer = mmAlloc(3000);
    if( !buffer )
    {
        ConPrintf("\nFailed allocating temp buffer\n");
        return;
    }

    Size = 3000;
    rc = NtTftpRecv( IPAddr, File, buffer, &Size, &ErrorCode );

    if( rc >= 0 )
    {
        UINT32 i;
        int    c;

        ConPrintf("\nFile Retrieved: Size is %d\n",Size);

        if( !rc )
            Size = 3000;

        ConPrintf("\nDisplay (%d bytes) (y/n)\n",Size);
        do { c=ConGetCh(); }
            while( c != 'y' && c !='Y' && c != 'N' && c != 'n' );
        if( c=='Y' || c=='y' )
            for( i=0; i<Size; i++ )
                ConPrintf( "%c", *(buffer+i) );

        ConPrintf("\n");
    }
    else if( rc < 0 )
    {
        ConPrintf("\nTFTP Reported Error: %d\n",rc);
        if( rc == TFTPERROR_ERRORREPLY )
            ConPrintf("TFTP Server Error: %d (%s)\n",ErrorCode,buffer);
    }

    mmFree( buffer );
}

⌨️ 快捷键说明

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