Kill TCP Connection源代码

原创 2006年05月23日 21:19:00
//**********************************************************************
// Version: V1.0
// Coder: WinEggDrop
// Date Release: NULL
// Purpose: Kill An Active TCP Connection
// Test PlatForm: Win 2K Pro And Server SP4
// Compiled On: LCC 3.0,May Compile On VC++ 6.0(Not Test Yet)
//**********************************************************************

#include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h>

// Function ProtoType Declaration
//---------------------------------------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort
);
BOOL IsDigits(const char *String
);
void Usage(const char *Command
);
//---------------------------------------------------------------------------------------------------------------------------
// End Of Fucntion ProtoType Declaration

// Main Function
int main(int argc,char *argv
[])
{
if (
argc!=5)     
// There Are Not 5 Arguement In Total
{
    
Usage(argv[0]);     
// Display The Usage
    
return -1;    
// Quit The Program
}

KillTCPConnection(argv[1],argv[2],argv[3],argv[4]);     
// Kill The TCP Connection
return 0;     
// Quit The Program
}
// End Of Main Function

//-------------------------------------------------------------------------
// Purpose: To Display The Usage Of The Program
// Return Type: Void
// Parameters:  Const Char *Command
//-------------------------------------------------------------------------
void Usage(const char *Command
)
{
printf("/r/nUsage: %s LocalAddress LocalPort RemoteAddress,RemotePort/r/n",Command);     
// Display The Usage
printf("Example: %s 192.168.0.1 1234 12.12.12.12 22222/r/n",Command);     
// Display A Example
}
// End Of Usage Function

//-------------------------------------------------------------------------
// Purpose: To Check Whether The String Is Really A Number
// Return Type: Boolean
// Parameters:  Const Char *String
//-------------------------------------------------------------------------
BOOL IsDigits(const char *String
)
{
int StringLength = strlen(String);    
// Get The Length Of The String

for (int i = 0;i < StringLength;i++)     
// Check Every Character Of The String
{
    if (
String[i] < 48 || String[i] > 57)    
// The Character Is Not A Digit
    
{
       return
FALSE;    
// Return False
    
}
}
return
TRUE;     
// Return True As All Characters Are Digits
}
// End Of IsDigits Function

//--------------------------------------------------------------------------------------------
// Purpose: To Kill An Active TCP Connection
// Return Type: Boolean
// Parameters:
//            1.Const Char *LocalAddress  --> The Local Address Of The TCP Connection
//            2.Const Char *LocalPort     --> The Local Port Of The TCP Connection
//            3.Const Char *RemoteAddress --> The Remote Address Of The TCP Connection
//            4.Const Char *RemotePort    --> The Remote Port Of The TCP Connection
//--------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort
)
{
MIB_TCPROW  TcpRow;    
// Declare A TCP Raw

if (!IsDigits(LocalPort))    
// The Local Port Is Not A Number
{
    
printf("Invalid Local Port/r/n");     
// Display Error Message
    
return FALSE;    
// Return False
}

if (
atoi(LocalPort) < 0 || atoi(LocalPort) > 65535)     
// The Local Port Is Out Of Bound
{
    
printf("Local Port Out Of Bound/r/n");      
// Display Error Message
    
return FALSE;    
// Return False
}

if (!
IsDigits(RemotePort))      
// The Remote Port Is Not A Number
{
    
printf("Invalid Remote Port/r/n");    
// Display Error Message
    
return FALSE;    
// Return False
}

if (
atoi(RemotePort) < 0 || atoi(RemotePort) > 65535)      
// The Remote Port Is Out Of Bound
{
    
printf("Remote Port Out Of Bound/r/n");     
// Display Error Message
    
return FALSE;    
// Return False
}

// Set The TCP Row Entry
TcpRow.dwLocalPort = htons(atoi(LocalPort
));
TcpRow.dwRemotePort = htons(atoi(RemotePort
));
TcpRow.dwLocalAddr = inet_addr(LocalAddress
);
TcpRow.dwRemoteAddr = inet_addr(RemoteAddress
);
TcpRow.dwState = MIB_TCP_STATE_DELETE_TCB;     
// Flag To Indicate The System To End That TCP Connection

if (SetTcpEntry(&TcpRow) == NO_ERROR)    
// Call The API With No Error
{
    
printf("Delete The TCP Connection %s:%s-->%s:%s Successfully/r/n",LocalAddress,LocalPort,RemoteAddress,RemotePort);    
// Display Successful Message
    
return TRUE;     
// Return True
}

// Some Error Must Be Occurred
printf("Fail To Delete The TCP Connection Error Code:%d/r/n",GetLastError());      
// Display The Error Code
return FALSE;    
// Return False
}
// End Of KillTCPConnection Function
// End Of File

X connection to localhost:10.0 host broken (explicit kill or server shutdown)

X connection to localhost:10.0 host broken (explicit kill or server shutdown) 1 现象: weblogic被管理S...

TCP_Connection_Status.zip

  • 2012年06月15日 11:35
  • 5KB
  • 下载

Nginx源代码分析-connection处理

http://hi.baidu.com/langwan   很久没有更新博客了,发现 NginxCodeReview 更新了一些新的内容。用wiki方法展现的确感觉更清晰,看到RainX他们自己写了...

[原理][源代码解析]spring中@Transactional,Propagation.SUPPORTS,以及 Hibernate Session,以及jdbc Connection关系

Spring 绑定 Hibernate.    一. 1. Spring 如何处理propagation=Propagation.SUPPORTS? 2. Spring 何时生成HibernateSe...

Nginx源代码分析-connection处理 【转】

很久没有更新博客了,发现NginxCodeReview 更新了一些新的内容,用wiki方法展现的确感觉更清晰,看到RainX他们自己写了一个ep_server的demo,突然想到除了event处理以外...

hbase 源代码解析(1) Connection

最近打算对源代码学习。作为自己学习备忘。今天开始写hbase。对hbase的接触两年多。如果不对源码分析总感觉确点什么。写的肯定比不上大牛。但是学习过程的分享,我能懂,大学能学点什么就够了。已经写了第...

windows API: 一:获得本机的Tcp list含(Pid,进程所在目录)。二:例举所有进程和pid 三:kill一个进程

获得本机本机的Tcp list 主要利用的函数和结构体: PMIB_TCPTABLE_OWNER_PID:一个结构体,含有:源地址及端口,目的地址及端口,Pid,进程所在目录 GetExtende...

ZBX_TCP_READ() failed [Connection reset by peer]

zabbix都搭建好了,进行一下测试看看能否检测到agent端的数据,结果都报错了:# /usr/local/zabbix/bin/zabbix_get -s 119.254.72.141 -k di...
  • ANLJF
  • ANLJF
  • 2011年06月30日 14:32
  • 9329

[转载]通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect

错误原因: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Serve...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Kill TCP Connection源代码
举报原因:
原因补充:

(最多只允许输入30个字)