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

📄 consock.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
//--------------------------------------------------------------------------
// ConSock.c
//
// Basic Console Functions
//     ConCmdSocket  - Socket Command
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <netmain.h>
#include <_stack.h>
#include "console.h"

static void DumpSockets( uint SockProt );

//-------------------------------------------------------------------------
// ConCmdSocket()
//
// Function to dump socket status
//-------------------------------------------------------------------------
void ConCmdSocket( int ntok, char *tok1 )
{
    if( ntok == 1 && !stricmp( tok1, "udp" ) )
        DumpSockets( SOCKPROT_UDP );
    else if( ntok == 1 && !stricmp( tok1, "tcp" ) )
        DumpSockets( SOCKPROT_TCP );
    else if( ntok == 1 && !stricmp( tok1, "raw" ) )
        DumpSockets( SOCKPROT_RAW );
    else if( ntok == 0 )
    {
        ConPrintf("\n[Socket Command]\n");
        ConPrintf("\nCalled to print the status of all sockets in the system\n\n");
        ConPrintf("socket tcp   - Print out TCP socket status\n");
        ConPrintf("socket udp   - Print out UDP socket status\n");
        ConPrintf("socket raw   - Print out RAW socket status\n\n");
    }
    else
        ConPrintf("\nError in command line. Type 'socket' for help\n");
}

static char *States[] = { "CLOSED","LISTEN","SYNSENT","SYNRCVD",
                          "ESTABLISHED","CLOSEWAIT","FINWAIT1","CLOSING",
                          "LASTACK","FINWAIT2","TIMEWAIT" };

//-------------------------------------------------------------------------
// DumpSockets()
//
// Function to dump the socket list
//-------------------------------------------------------------------------
static void DumpSockets( uint SockProt )
{
    UINT8   *pBuf;
    int     Entries,i;
    SOCKPCB *ppcb;
    char    str[40];

    pBuf = mmBulkAlloc(2048);
    if( !pBuf )
        return;

    // Use llEnter / llExit since we're calling into the stack
    llEnter();
    Entries = SockGetPcb( SockProt, 2048, pBuf );
    llExit();

    ConPrintf("\nLocal IP         LPort  Foreign IP       FPort  State\n");
    ConPrintf("---------------  -----  ---------------  -----  -----------\n");

    for(i=0; i<Entries; i++)
    {
        ppcb = (SOCKPCB *)(pBuf+(i*sizeof(SOCKPCB)));

        NtIPN2Str( ppcb->IPAddrLocal, str );
        ConPrintf( "%-15s  %-5u  ", str, htons(ppcb->PortLocal) );

        NtIPN2Str( ppcb->IPAddrForeign, str );
        ConPrintf( "%-15s  %-5u", str, htons(ppcb->PortForeign) );

        if( SockProt == SOCKPROT_TCP )
            ConPrintf("  %s\n",States[ppcb->State]);
        else
            ConPrintf("\n");
    }
    ConPrintf("\n");

    mmBulkFree( pBuf );
}

⌨️ 快捷键说明

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