亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ping.c

?? 有關linux的tcp和udp通訊的服務器端和客服端的源程序
?? C
字號:
// Module Name: Ping.c
//
// Description:
//    This sample illustrates how an ICMP ping app can be written
//    using the SOCK_RAW socket type and IPPROTO_ICMP protocol.
//    By creating a raw socket, the underlying layer does not change
//    the protocol header so that when we submit the ICMP header
//    nothing is changed so that the receiving end will see an 
//    ICMP packet. Additionally, we use the record route IP option
//    to get a round trip path to the endpoint. Note that the size
//    of the IP option header that records the route is limited to
//    nine IP addresses.
//
// Compile:
//     cl -o Ping Ping.c ws2_32.lib /Zp1
//
// Command Line Options/Parameters:
//     Ping [host] [packet-size]
//     
//     host         String name of host to ping
//     packet-size  Integer size of packet to send 
//                      (smaller than 1024 bytes)
//
//#pragma pack(1)

#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>

#define IP_RECORD_ROUTE  0x7
// 
// IP header structure
//
typedef struct _iphdr 
{
    unsigned int   h_len:4;        // Length of the header
    unsigned int   version:4;      // Version of IP
    unsigned char  tos;            // Type of service
    unsigned short total_len;      // Total length of the packet
    unsigned short ident;          // Unique identifier
    unsigned short frag_and_flags; // Flags
    unsigned char  ttl;            // Time to live
    unsigned char  proto;          // Protocol (TCP, UDP etc)
    unsigned short checksum;       // IP checksum

    unsigned int   sourceIP;
    unsigned int   destIP;
} IpHeader;

#define ICMP_ECHO        8
#define ICMP_ECHOREPLY   0
#define ICMP_MIN         8 // Minimum 8-byte ICMP packet (header)

//
// ICMP header structure
//
typedef struct _icmphdr 
{
    BYTE   i_type;
    BYTE   i_code;                 // Type sub code
    USHORT i_cksum;
    USHORT i_id;
    USHORT i_seq;
    // This is not the standard header, but we reserve space for time
    ULONG  timestamp;
} IcmpHeader;

//
// IP option header - use with socket option IP_OPTIONS
//
typedef struct _ipoptionhdr
{
    unsigned char        code;        // Option type
    unsigned char        len;         // Length of option hdr
    unsigned char        ptr;         // Offset into options
    unsigned long        addr[9];     // List of IP addrs
} IpOptionHeader;

#define DEF_PACKET_SIZE  32        // Default packet size
#define MAX_PACKET       1024      // Max ICMP packet size
#define MAX_IP_HDR_SIZE  60        // Max IP header size w/options

BOOL  bRecordRoute;
int   datasize;
char *lpdest;

//
// Function: usage
//
// Description:
//    Print usage information
//
void usage(char *progname)
{
    printf("usage: ping -r <host> [data size]\n");
    printf("       -r           record route\n");
    printf("        host        remote machine to ping\n");
    printf("        datasize    can be up to 1KB\n");
    ExitProcess(-1);
}

// 
// Function: FillICMPData
//
// Description:
//    Helper function to fill in various fields for our ICMP request
//
void FillICMPData(char *icmp_data, int datasize)
{
    IcmpHeader *icmp_hdr = NULL;
    char       *datapart = NULL;

    icmp_hdr = (IcmpHeader*)icmp_data;
    icmp_hdr->i_type = ICMP_ECHO;        // Request an ICMP echo
    icmp_hdr->i_code = 0;
    icmp_hdr->i_id = (USHORT)GetCurrentProcessId();
    icmp_hdr->i_cksum = 0;
    icmp_hdr->i_seq = 0;
  
    datapart = icmp_data + sizeof(IcmpHeader);
    //
    // Place some junk in the buffer
    //
    memset(datapart,'E', datasize - sizeof(IcmpHeader));
}

// 
// Function: checksum
//
// Description:
//    This function calculates the 16-bit one's complement sum
//    of the supplied buffer (ICMP) header
//
USHORT checksum(USHORT *buffer, int size) 
{
    unsigned long cksum=0;

    while (size > 1) 
    {
        cksum += *buffer++;
        size -= sizeof(USHORT);
    }
    if (size) 
    {
        cksum += *(UCHAR*)buffer;
    }
    cksum = (cksum >> 16) + (cksum & 0xffff);
    cksum += (cksum >>16);
    return (USHORT)(~cksum);
}

//
// Function: DecodeIPOptions
//
// Description:
//    If the IP option header is present, find the IP options
//    within the IP header and print the record route option
//    values
//
void DecodeIPOptions(char *buf, int bytes)
{
    IpOptionHeader *ipopt = NULL;
    IN_ADDR         inaddr;
    int             i;
    HOSTENT        *host = NULL;

    ipopt = (IpOptionHeader *)(buf + 20);

    printf("RR:   ");
    for(i = 0; i < (ipopt->ptr / 4) - 1; i++)
    {
        inaddr.S_un.S_addr = ipopt->addr[i];
        if (i != 0)
            printf("      ");
        host = gethostbyaddr((char *)&inaddr.S_un.S_addr,
                    sizeof(inaddr.S_un.S_addr), AF_INET);
        if (host)
            printf("(%-15s) %s\n", inet_ntoa(inaddr), host->h_name);
        else
            printf("(%-15s)\n", inet_ntoa(inaddr));
    }
    return;
}

//
// Function: DecodeICMPHeader
//
// Description:
//    The response is an IP packet. We must decode the IP header to
//    locate the ICMP data.
//
void DecodeICMPHeader(char *buf, int bytes, 
    struct sockaddr_in *from)
{
    IpHeader       *iphdr = NULL;
    IcmpHeader     *icmphdr = NULL;
    unsigned short  iphdrlen;
    DWORD           tick;
    static   int    icmpcount = 0;

    iphdr = (IpHeader *)buf;
	// Number of 32-bit words * 4 = bytes
    iphdrlen = iphdr->h_len * 4;
    tick = GetTickCount();

    if ((iphdrlen == MAX_IP_HDR_SIZE) && (!icmpcount))
        DecodeIPOptions(buf, bytes);

    if (bytes  < iphdrlen + ICMP_MIN) 
    {
        printf("Too few bytes from %s\n", 
            inet_ntoa(from->sin_addr));
    }
    icmphdr = (IcmpHeader*)(buf + iphdrlen);

    if (icmphdr->i_type != ICMP_ECHOREPLY) 
    {
        printf("nonecho type %d recvd\n", icmphdr->i_type);
        return;
    }
    // Make sure this is an ICMP reply to something we sent!
    //
    if (icmphdr->i_id != (USHORT)GetCurrentProcessId()) 
    {
        printf("someone else's packet!\n");
        return ;
    }
    printf("%d bytes from %s:", bytes, inet_ntoa(from->sin_addr));
    printf(" icmp_seq = %d. ", icmphdr->i_seq);
    printf(" time: %d ms", tick - icmphdr->timestamp);
    printf("\n");

    icmpcount++;
    return;
}

void ValidateArgs(int argc, char **argv)
{
    int                i;

    bRecordRoute = FALSE;
    lpdest = NULL;
    datasize = DEF_PACKET_SIZE;
    
    for(i = 1; i < argc; i++)
    {
        if ((argv[i][0] == '-') || (argv[i][0] == '/'))
        {
            switch (tolower(argv[i][1]))
            {
                case 'r':        // Record route option
                    bRecordRoute = TRUE;
                    break;
                default:
                    usage(argv[0]);
                    break;
            }
        }
        else if (isdigit(argv[i][0]))
            datasize = atoi(argv[i]);
        else
            lpdest = argv[i];
    }
}
        
//
// Function: main
//
// Description:
//    Setup the ICMP raw socket, and create the ICMP header. Add
//    the appropriate IP option header, and start sending ICMP
//    echo requests to the endpoint. For each send and receive,
//    we set a timeout value so that we don't wait forever for a 
//    response in case the endpoint is not responding. When we
//    receive a packet decode it.
//
int main(int argc, char **argv)
{

    WSADATA            wsaData;
    SOCKET             sockRaw = INVALID_SOCKET;
    struct sockaddr_in dest,
                       from;
    int                bread,
                       fromlen = sizeof(from),
                       timeout = 1000,
                       ret;
    char              *icmp_data = NULL,
                      *recvbuf = NULL;
    unsigned int       addr = 0;
    USHORT             seq_no = 0;
    struct hostent    *hp = NULL;
    IpOptionHeader     ipopt;


    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
    {
        printf("WSAStartup() failed: %d\n", GetLastError());
        return -1;
    }
    ValidateArgs(argc, argv);

    //
    // WSA_FLAG_OVERLAPPED flag is required for SO_RCVTIMEO, 
    // SO_SNDTIMEO option. If NULL is used as last param for 
    // WSASocket, all I/O on the socket is synchronous, the 
    // internal user mode wait code never gets a chance to 
    // execute, and therefore kernel-mode I/O blocks forever. 
    // A socket created via the socket function has the over-
	 // lapped I/O attribute set internally. But here we need 
	 // to use WSASocket to specify a raw socket.
    //
    // If you want to use timeout with a synchronous 
    // nonoverlapped socket created by WSASocket with last 
	 // param set to NULL, you can set the timeout by using 
	 // the select function, or you can use WSAEventSelect and 
	 // set the timeout in the WSAWaitForMultipleEvents 
	 // function.
    //
    sockRaw = WSASocket (AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,
                         WSA_FLAG_OVERLAPPED);
    if (sockRaw == INVALID_SOCKET) 
    {
        printf("WSASocket() failed: %d\n", WSAGetLastError());
        return -1;
    }
    if (bRecordRoute)
    {
        // Setup the IP option header to go out on every ICMP packet
        //
        ZeroMemory(&ipopt, sizeof(ipopt));
        ipopt.code = IP_RECORD_ROUTE; // Record route option
        ipopt.ptr  = 4;               // Point to the first addr offset
        ipopt.len  = 39;              // Length of option header
  
        ret = setsockopt(sockRaw, IPPROTO_IP, IP_OPTIONS, 
            (char *)&ipopt, sizeof(ipopt));
        if (ret == SOCKET_ERROR)
        {
            printf("setsockopt(IP_OPTIONS) failed: %d\n", 
                WSAGetLastError());
        }
    }
    // Set the send/recv timeout values
    //
    bread = setsockopt(sockRaw, SOL_SOCKET, SO_RCVTIMEO, 
                (char*)&timeout, sizeof(timeout));
    if(bread == SOCKET_ERROR) 
    {
        printf("setsockopt(SO_RCVTIMEO) failed: %d\n", 
            WSAGetLastError());
        return -1;
    }
    timeout = 1000;
    bread = setsockopt(sockRaw, SOL_SOCKET, SO_SNDTIMEO, 
                (char*)&timeout, sizeof(timeout));
    if (bread == SOCKET_ERROR) 
    {
        printf("setsockopt(SO_SNDTIMEO) failed: %d\n", 
            WSAGetLastError());
        return -1;
    }
    memset(&dest, 0, sizeof(dest));
    //
    // Resolve the endpoint's name if necessary
    //
    dest.sin_family = AF_INET;
    if ((dest.sin_addr.s_addr = inet_addr(lpdest)) == INADDR_NONE)
    {
        if ((hp = gethostbyname(lpdest)) != NULL)
        {
            memcpy(&(dest.sin_addr), hp->h_addr, hp->h_length);
            dest.sin_family = hp->h_addrtype;
            printf("dest.sin_addr = %s\n", inet_ntoa(dest.sin_addr));
        }
        else
        {
            printf("gethostbyname() failed: %d\n", 
                WSAGetLastError());
            return -1;
        }
    }        

    // 
    // Create the ICMP packet
    //       
    datasize += sizeof(IcmpHeader);  

    icmp_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                  MAX_PACKET);
    recvbuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                  MAX_PACKET);
    if (!icmp_data) 
    {
        printf("HeapAlloc() failed: %d\n", GetLastError());
        return -1;
    }
    memset(icmp_data,0,MAX_PACKET);
    FillICMPData(icmp_data,datasize);
    //
    // Start sending/receiving ICMP packets
    //
    while(1) 
    {
        static int nCount = 0;
        int        bwrote;
                
        if (nCount++ == 4) 
            break;
                
        ((IcmpHeader*)icmp_data)->i_cksum = 0;
        ((IcmpHeader*)icmp_data)->timestamp = GetTickCount();
        ((IcmpHeader*)icmp_data)->i_seq = seq_no++;
        ((IcmpHeader*)icmp_data)->i_cksum = 
            checksum((USHORT*)icmp_data, datasize);

        bwrote = sendto(sockRaw, icmp_data, datasize, 0, 
                     (struct sockaddr*)&dest, sizeof(dest));
        if (bwrote == SOCKET_ERROR)
        {
            if (WSAGetLastError() == WSAETIMEDOUT) 
            {
                printf("timed out\n");
                continue;
            }
            printf("sendto() failed: %d\n", WSAGetLastError());
            return -1;
        }
        if (bwrote < datasize) 
        {
            printf("Wrote %d bytes\n", bwrote);
        }
        bread = recvfrom(sockRaw, recvbuf, MAX_PACKET, 0, 
                    (struct sockaddr*)&from, &fromlen);
        if (bread == SOCKET_ERROR)
        {
            if (WSAGetLastError() == WSAETIMEDOUT) 
            {
                printf("timed out\n");
                continue;
            }
            printf("recvfrom() failed: %d\n", WSAGetLastError());
            return -1;
        }
        DecodeICMPHeader(recvbuf, bread, &from);

        Sleep(1000);
    }
    // Cleanup
    //
    if (sockRaw != INVALID_SOCKET) 
        closesocket(sockRaw);
    HeapFree(GetProcessHeap(), 0, recvbuf);
    HeapFree(GetProcessHeap(), 0, icmp_data);

    WSACleanup();
    return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
三级精品在线观看| 日韩精品福利网| 337p日本欧洲亚洲大胆色噜噜| 色婷婷久久久综合中文字幕| eeuss鲁片一区二区三区在线观看| 丁香一区二区三区| 国产不卡一区视频| 99免费精品视频| av爱爱亚洲一区| 在线观看视频一区二区欧美日韩| 日本国产一区二区| 欧美理论片在线| 日韩片之四级片| 久久久一区二区三区| 久久久久高清精品| 国产精品激情偷乱一区二区∴| 中文字幕欧美一| 亚洲另类在线一区| 婷婷开心激情综合| 国模套图日韩精品一区二区| 国产.精品.日韩.另类.中文.在线.播放| 国产成人综合自拍| 色婷婷狠狠综合| 日韩视频在线你懂得| 亚洲制服丝袜在线| 亚洲成人福利片| 精品无人码麻豆乱码1区2区 | 国产91精品露脸国语对白| 国产精品系列在线播放| av网站免费线看精品| 欧美日产在线观看| 国产日韩欧美综合在线| 亚洲欧美日韩在线不卡| 麻豆精品视频在线| 色8久久精品久久久久久蜜| 欧美一区二区性放荡片| 国产精品日韩成人| 午夜激情一区二区三区| 夫妻av一区二区| 欧美一卡在线观看| 亚洲欧洲制服丝袜| 狠狠久久亚洲欧美| 欧美日韩国产经典色站一区二区三区| 26uuu亚洲婷婷狠狠天堂| 亚洲黄色免费电影| 高清成人免费视频| 欧美一区二区在线看| 亚洲精品国产无天堂网2021 | 国产精品视频线看| 婷婷国产v国产偷v亚洲高清| 国产成人精品一区二区三区网站观看| 欧美羞羞免费网站| 中文字幕一区在线观看视频| 裸体一区二区三区| 欧美三级资源在线| 亚洲欧美国产高清| 处破女av一区二区| www激情久久| 美女高潮久久久| 欧美日韩三级在线| 亚洲在线视频免费观看| 99在线精品一区二区三区| 久久久综合九色合综国产精品| 国产成人综合在线观看| 日韩一区二区在线观看视频播放 | 欧美日韩亚州综合| 亚洲精选免费视频| 91亚洲精品久久久蜜桃| 国产欧美一区二区精品仙草咪| 老司机免费视频一区二区三区| 91精品国产91久久久久久一区二区| 亚洲日韩欧美一区二区在线| 国产福利不卡视频| 国产欧美一区二区精品久导航 | 88在线观看91蜜桃国自产| 亚洲欧美另类小说| 91麻豆国产福利在线观看| 国产精品天美传媒| 91免费国产在线| 伊人色综合久久天天人手人婷| 色婷婷av一区二区三区大白胸| 亚洲欧美在线高清| 色妞www精品视频| 洋洋成人永久网站入口| 欧美日韩精品一区二区三区| 亚洲成人福利片| 日韩欧美中文字幕精品| 国产一区视频在线看| www日韩大片| 99久久er热在这里只有精品66| 亚洲男人天堂av| 欧美日韩亚洲综合在线| 久久精品久久综合| 久久精品亚洲精品国产欧美kt∨ | 在线亚洲一区二区| 爽好久久久欧美精品| 欧美大胆人体bbbb| 成人亚洲精品久久久久软件| 亚洲免费观看高清完整版在线观看| 在线欧美小视频| 久久99精品久久久久久| 亚洲欧洲成人自拍| 欧美日韩一级片在线观看| 精品亚洲免费视频| 亚洲三级在线观看| 日韩一区二区三区电影| 成人国产亚洲欧美成人综合网| 亚洲一区二区在线播放相泽| 欧美xxxxxxxx| 色呦呦国产精品| 精品无人区卡一卡二卡三乱码免费卡| 国产精品久久久久毛片软件| 欧美一区二区视频在线观看2022 | 色综合天天做天天爱| 日本中文一区二区三区| 中文字幕一区二区视频| 欧美一激情一区二区三区| 97超碰欧美中文字幕| 久久草av在线| 一区二区三区四区视频精品免费 | 强制捆绑调教一区二区| 亚洲国产精品ⅴa在线观看| 3751色影院一区二区三区| 国产精品免费看片| 制服丝袜中文字幕一区| 日韩avvvv在线播放| 椎名由奈av一区二区三区| 在线播放91灌醉迷j高跟美女 | 精品国产污污免费网站入口 | 日韩精品一区二区三区视频| av一区二区久久| 久久精品国产一区二区三 | 欧美成人aa大片| 欧美色图12p| av不卡免费电影| 国产精品综合一区二区| 奇米777欧美一区二区| 亚洲高清免费观看高清完整版在线观看| 久久久国产精品午夜一区ai换脸| 欧美一区二区三区白人| 欧美日韩一区二区三区视频| av在线不卡网| av电影天堂一区二区在线| 国产精品综合一区二区三区| 久久66热偷产精品| 强制捆绑调教一区二区| 婷婷国产v国产偷v亚洲高清| 午夜欧美2019年伦理 | 欧美又粗又大又爽| 成人午夜私人影院| 粉嫩一区二区三区在线看| 国产成人午夜99999| 国产iv一区二区三区| 国产大陆亚洲精品国产| 丰满少妇在线播放bd日韩电影| 国产高清不卡二三区| 国产乱色国产精品免费视频| 国产成人精品一区二区三区四区| 国产美女精品在线| 国产高清在线精品| 国产91清纯白嫩初高中在线观看| 成人伦理片在线| 91麻豆国产精品久久| 欧美视频在线不卡| 91精品国模一区二区三区| 欧美猛男男办公室激情| 日韩午夜av一区| 久久久99精品免费观看不卡| 欧美国产丝袜视频| 亚洲久草在线视频| 青草国产精品久久久久久| 精品一二三四在线| av在线综合网| 7777精品伊人久久久大香线蕉完整版 | 在线观看免费成人| 欧美日本韩国一区二区三区视频| 欧美一级淫片007| 久久亚洲精精品中文字幕早川悠里| 欧美极品xxx| 亚洲午夜视频在线| 国产一区二区三区电影在线观看| 成人精品免费视频| 欧美日韩在线播放三区四区| 日韩精品一区二区三区视频播放 | 亚洲成人第一页| 国产一区二区三区久久悠悠色av | 欧美日韩成人在线| 久久精品一区二区三区不卡牛牛| 亚洲欧美日韩中文播放| 久久精品久久99精品久久| 99久久er热在这里只有精品15| 欧美日韩aaaaa| 亚洲欧洲日韩av| 久久国产精品99久久久久久老狼| 成人18精品视频| 91精品国产综合久久小美女| 成人免费一区二区三区在线观看| 日韩电影免费一区| 91麻豆国产自产在线观看| 久久亚洲精品小早川怜子|