文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>RTX信息监控工具

RTX信息监控工具

时间:2010-08-01  来源:bailiangcn

一直没有找到理想的RTX在linux下面的使用方法。
用wine有姓名前两个汉字乱码,而且稳定性欠佳;
用虚拟机容易遗漏信息;
于是计划写个小的工具,能够监测RTX服务器发来的信息,版本一代码如下:

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/in.h>
#include <linux/if_ether.h>

#define RTXSIP { 10,63,128,53 }
#define RTXPORT 8000

int main(int argc, char **argv) {
    int sock, n;
    char buffer[2048];
    unsigned char *iphead;
    int sourcePort,desPort;
    
    const int rtxip[4]=RTXSIP;

    if ( (sock=socket(PF_PACKET, SOCK_RAW,
                    htons(ETH_P_IP)))<0) {
        perror("socket");
        exit(1);
    }
    printf("----------\n");

    while (1) {
        n = recvfrom(sock,buffer,2048,0,NULL,NULL);

        /* Check to see if the packet contains at least
         * complete Ethernet (14), IP (20) and TCP/UDP
         * (8) headers.
         */
        if (n<42) {
            perror("recvfrom():");
            printf("Incomplete packet (errno is %d)\n",
                    errno);
            close(sock);
            exit(0);
        }

        iphead = buffer+14; /* Skip Ethernet header */
        if (*iphead==0x45) { /* Double check for IPv4
                              * and no options present */
            sourcePort = (iphead[20]<<8)+iphead[21];
            desPort = (iphead[22]<<8)+iphead[23];

            if (iphead[12]==rtxip[0] && iphead[13]==rtxip[1] && iphead[14]==rtxip[2] && iphead[15]==rtxip[3] && sourcePort==RTXPORT && n > 1000 ){
                printf("%d bytes read\n",n);
                printf("Source,Dest ports %d,%d\n",sourcePort,desPort);
       
            }
        }
    }

}

目前可以有效地抓到来的信息,缺少提示的功能,有时间再改
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载