299分。很短的VC to Delphi的转换 ( 积分: 299 )

  • 主题发起人 主题发起人 余远源
  • 开始时间 开始时间

余远源

Unregistered / Unconfirmed
GUEST, unregistred user!
extern BOOL PeekAndPump();
extern LPADAPTER g_lpAdapter;
extern CSnifferApp theApp;
extern unsigned char Output_srcMAC[6];
extern unsigned char Output_dstMAC[6];
extern unsigned char g_szOwnMAC[6];//本机MAC地址
extern unsigned char g_szServerSideMAC[6];
extern unsigned long ServerlocalHost;
extern unsigned long ClientlocalHost;
extern unsigned long ServerIss;
extern unsigned long ClientIss;
extern CLIENTINFO ClientInfo[MAX_CLIENT];
extern BOOL bExitThread; //退出所有程序标志
extern void GetTcpFlagDisStr(char tcpFlag,char *cTemp);
static NBuf nBufs[MAXNBUFS];
NBuf *topNBuf;
NBufStats nBufStats;
u_int curFreeBufs; // added by robert to make build
unsigned long netMask; /* IP netmask to set on interface */
unsigned long LocalHost; /* Our IP address in */
static Timer timerHead; /* Sentinal for timer queue. */
static Timer *timerFree; /* The free list pointer. */
static Timer timerHeap[MAXFREETIMERS]; /* The free timer records. */
u_short ipID; /* IP packet ctr, for ID fields. */

char InAndOutLoop; //实现内部收发,不经过网卡

/*
* TCP Control block free list.
*/
TCPCB tcbs[MAXTCP];
TCPCB *topTcpCB; /* Ptr to top TCB on free list. */
TCPCB *tcbTbl[NTCB]; /* Hash table for lookup. */
u_int16_t tcpFreePort = TCP_DEFPORT; /* Initial local port. */
u_int32_t newISNOffset; /* Offset for the next sequence number. */
static UDPCB udps[MAXUDP];
static UDP_QUEUE udpqs[MAXUDPQUEUES];
static UDP_QUEUE* udp_free_list;

ICMPSTATS icmpStats;
static struct sockaddr_in icmpsrc = { sizeof(struct sockaddr_in), AF_INET };
struct sockaddr_in icmpmask = { 8, 0 };

/* TCB state labels for debugging. */
char *tcbStates[] =
{
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RECEIVED",
"ESTABLISHED",
"FINWAIT1",
"FINWAIT2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};

/***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/
/***********************************/
/*
* Initialize the TCP subsystem.
*/
void tcpInit(void)
{
int i;
/* The TCB free list. */
memset(tcbs, 0, sizeof(tcbs));
topTcpCB = &tcbs[0];

for(i = 0; i < MAXTCP; i++)
{
tcbs.next = &tcbs[i + 1];
/* Prev referencing self indicates that it's on the free list. */
tcbs.prev = &tcbs;
memset(&tcbs.resendTimer, 0, sizeof(Timer));
memset(&tcbs.keepTimer, 0, sizeof(Timer));
tcbs.state = CLOSED;
}
tcbs[MAXTCP - 1].next = NULL;
/* The TCB hash table. */
memset(&tcbTbl, 0, sizeof(tcbTbl));
/* The new sequence number offset. */
srand((unsigned)time(NULL));
newISNOffset = rand();
}
 
extern BOOL PeekAndPump();
extern LPADAPTER g_lpAdapter;
extern CSnifferApp theApp;
extern unsigned char Output_srcMAC[6];
extern unsigned char Output_dstMAC[6];
extern unsigned char g_szOwnMAC[6];//本机MAC地址
extern unsigned char g_szServerSideMAC[6];
extern unsigned long ServerlocalHost;
extern unsigned long ClientlocalHost;
extern unsigned long ServerIss;
extern unsigned long ClientIss;
extern CLIENTINFO ClientInfo[MAX_CLIENT];
extern BOOL bExitThread; //退出所有程序标志
extern void GetTcpFlagDisStr(char tcpFlag,char *cTemp);
static NBuf nBufs[MAXNBUFS];
NBuf *topNBuf;
NBufStats nBufStats;
u_int curFreeBufs; // added by robert to make build
unsigned long netMask; /* IP netmask to set on interface */
unsigned long LocalHost; /* Our IP address in */
static Timer timerHead; /* Sentinal for timer queue. */
static Timer *timerFree; /* The free list pointer. */
static Timer timerHeap[MAXFREETIMERS]; /* The free timer records. */
u_short ipID; /* IP packet ctr, for ID fields. */

char InAndOutLoop; //实现内部收发,不经过网卡

/*
* TCP Control block free list.
*/
TCPCB tcbs[MAXTCP];
TCPCB *topTcpCB; /* Ptr to top TCB on free list. */
TCPCB *tcbTbl[NTCB]; /* Hash table for lookup. */
u_int16_t tcpFreePort = TCP_DEFPORT; /* Initial local port. */
u_int32_t newISNOffset; /* Offset for the next sequence number. */
static UDPCB udps[MAXUDP];
static UDP_QUEUE udpqs[MAXUDPQUEUES];
static UDP_QUEUE* udp_free_list;

ICMPSTATS icmpStats;
static struct sockaddr_in icmpsrc = { sizeof(struct sockaddr_in), AF_INET };
struct sockaddr_in icmpmask = { 8, 0 };

/* TCB state labels for debugging. */
char *tcbStates[] =
{
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RECEIVED",
"ESTABLISHED",
"FINWAIT1",
"FINWAIT2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};

/***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/
/***********************************/
/*
* Initialize the TCP subsystem.
*/
void tcpInit(void)
{
int i;
/* The TCB free list. */
memset(tcbs, 0, sizeof(tcbs));
topTcpCB = &tcbs[0];

for(i = 0; i < MAXTCP; i++)
{
tcbs.next = &tcbs[i + 1];
/* Prev referencing self indicates that it's on the free list. */
tcbs.prev = &tcbs;
memset(&tcbs.resendTimer, 0, sizeof(Timer));
memset(&tcbs.keepTimer, 0, sizeof(Timer));
tcbs.state = CLOSED;
}
tcbs[MAXTCP - 1].next = NULL;
/* The TCB hash table. */
memset(&tcbTbl, 0, sizeof(tcbTbl));
/* The new sequence number offset. */
srand((unsigned)time(NULL));
newISNOffset = rand();
}
 
建议贴出个完整的程序,包括用到的H文件和动态连接库
这样别人才看得懂啊,再说转完后别人也可以测试一下啊
 
主要是一些格式的转换没搞清楚。不用看得懂这个的作用。
比如 extern unsigned char Output_srcMAC[6];这个如何翻成Delphi的。没必要搞整个文件出来。
Procedure tcpInit;
Var
i:Integer;
Begin
memset(tcbs,0,sizeof((tcbs)));
topTcpCB := @tcbs[0];
begin
i := 0;
while (i < MAXTCP) do begin
Begin
tcbs.next := @tcbs[i + 1];
tcbs.prev := @tcbs;
memset(@tcbs.resendTimer,0,sizeof((Timer)));
memset(@tcbs.keepTimer,0,sizeof((Timer)));
tcbs.state := CLOSED;
end;
Inc(i);
end;
end;
tcbs[MAXTCP - 1].next := NULL;
memset(@tcbTbl,0,sizeof((tcbTbl)));
srand({UNSIGNED}(time(NULL)));
newISNOffset := rand;
end;
这里的memset,srand,rand对应的在Delphi的FUNCTION。
 
memset可以用FillMemory,这个只要把后2个参数位置改一下。
srand,rand是随机函数吧,delphi下应该可以用Random替代吧
 
多人接受答案了
 
后退
顶部