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

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

?? traceroute.c

?? 有關linux的tcp和udp通訊的服務器端和客服端的源程序
?? C
字號:
// Module: Traceroute.c
//
// Description:
//    This sample is fairly similar to the ping.c sample. It 
//    creates ICMP packets and sends them to the intended 
//    recipient. The time-to-live value for the ICMP packet 
//    is initially 1 and is incremented by one everytime
//    an ICMP response is received. This way we can look
//    at the source IP address of these replies to find
//    the route to the intended recipient. Once we receive
//    an ICMP port unreachable message we know that we have
//    reached the inteded recipient and we can stop.
//
// Compile:
//    cl -o Traceroute Traceroute.c ws_32.lib /Zp1
//
// Command Line Options/Parameters
//    traceroute.exe hostname [max-hops]
//    hostname         Hostname or IP dotted decimal address of
//                      the endpoint.
//    max-hops         Maximum number of hops (routers) to 
//                      traverse to the endpoint before quitting.
//
#pragma pack(4)

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

#include <stdio.h>
#include <stdlib.h>

//
// Defines for ICMP message types
//
#define ICMP_ECHOREPLY      0
#define ICMP_DESTUNREACH    3
#define ICMP_SRCQUENCH      4
#define ICMP_REDIRECT       5
#define ICMP_ECHO           8
#define ICMP_TIMEOUT       11
#define ICMP_PARMERR       12

#define MAX_HOPS           30

#define ICMP_MIN 8    // Minimum 8 byte icmp packet (just header)

//
// IP Header
//
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;       // Source IP
    unsigned int   destIP;         // Destination IP
} IpHeader;

//
// ICMP header
//
typedef struct _ihdr 
{
    BYTE   i_type;               // ICMP message type
    BYTE   i_code;               // Sub code
    USHORT i_cksum;              
    USHORT i_id;                 // Unique id
    USHORT i_seq;                // Sequence number
    // This is not the std header, but we reserve space for time
    ULONG timestamp;
} IcmpHeader;

#define DEF_PACKET_SIZE         32
#define MAX_PACKET            1024

//
// Function: usage
//
// Description:
//    Print usage information
//
void usage(char *progname)
{
    printf("usage: %s host-name [max-hops]\n", progname);
    ExitProcess(-1);
}

//
// Function: set_ttl
//
// Description:
//    Set the time to live parameter on the socket. This controls 
//    how far the packet will be forwared before a "timeout" 
//    response will be sent back to us. This way we can see all 
//    the hops along the way to the destination.
//
int set_ttl(SOCKET s, int nTimeToLive)
{
    int     nRet;
    
    nRet = setsockopt(s, IPPROTO_IP, IP_TTL, (LPSTR)&nTimeToLive,
                sizeof(int));
    if (nRet == SOCKET_ERROR)
    {
        printf("setsockopt(IP_TTL) failed: %d\n", 
            WSAGetLastError());
        return 0;
    }
    return 1;
}

//
// Function: decode_resp
//
// Description:
//    The response is an IP packet. We must decode the IP header 
//    to locate the ICMP data.
//
int decode_resp(char *buf, int bytes, SOCKADDR_IN *from, int ttl)
{
    IpHeader       *iphdr = NULL;
    IcmpHeader     *icmphdr = NULL;
    unsigned short  iphdrlen;
    struct hostent *lpHostent = NULL;
    struct in_addr  inaddr = from->sin_addr;

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

    if (bytes < iphdrlen + ICMP_MIN) 
        printf("Too few bytes from %s\n",
            inet_ntoa(from->sin_addr));

    icmphdr = (IcmpHeader*)(buf + iphdrlen);

    switch (icmphdr->i_type)
    {
        case ICMP_ECHOREPLY:     // Response from destination
            lpHostent = gethostbyaddr((const char *)&from->sin_addr, 
                AF_INET, sizeof(struct in_addr));
            if (lpHostent != NULL)
                printf("%2d  %s (%s)\n", ttl, lpHostent->h_name, 
                    inet_ntoa(inaddr));
            return 1;
            break;
        case ICMP_TIMEOUT:      // Response from router along the way
            printf("%2d  %s\n", ttl, inet_ntoa(inaddr));
            return 0;
            break;
        case ICMP_DESTUNREACH:  // Can't reach the destination at all
            printf("%2d  %s  reports: Host is unreachable\n", ttl, 
                inet_ntoa(inaddr));
            return 1;
            break;
        default:
            printf("non-echo type %d recvd\n", icmphdr->i_type);
            return 1;
            break;
    }
    return 0;
}

//
// Function: checksum
//
// Description:
//    This function calculates the checksum for the ICMP header 
//    which is a necessary field since we are building packets by 
//    hand. Normally, the TCP layer handles all this when you do 
//    sockets, but ICMP is at a somewhat lower level.
//
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: fill_icmp_data
//
// Description:
//    Helper function to fill in various stuff in our ICMP request.
//
void fill_icmp_data(char * icmp_data, int datasize)
{
    IcmpHeader *icmp_hdr;
    char       *datapart;

    icmp_hdr = (IcmpHeader*)icmp_data;

    icmp_hdr->i_type = 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. Don't care about the data...
    //
    memset(datapart,'E', datasize - sizeof(IcmpHeader));
}

//
// Function: main
// 
int main(int argc, char **argv)
{
    WSADATA      wsd;
    SOCKET       sockRaw;
    HOSTENT     *hp = NULL;
    SOCKADDR_IN  dest,
                 from;
    int          ret,
                 datasize,
                 fromlen = sizeof(from),
                 timeout,
                 done = 0,
                 maxhops,
                 ttl = 1;
    char        *icmp_data,
                *recvbuf;
    BOOL         bOpt;
    USHORT       seq_no = 0;

    // Initialize the Winsock2 DLL
    //
    if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
    {
        printf("WSAStartup() failed: %d\n", GetLastError());
        return -1;
    }
    if (argc < 2) 
        usage(argv[0]);
    if (argc == 3)
        maxhops = atoi(argv[2]);
    else
        maxhops = MAX_HOPS;
    //
    // Create a raw socket that will be used to send the ICMP 
    // packets to the remote host you want to ping
    //
    sockRaw = WSASocket (AF_INET, SOCK_RAW, IPPROTO_ICMP,
                         NULL, 0,WSA_FLAG_OVERLAPPED);
    if (sockRaw == INVALID_SOCKET) 
    {
        printf("WSASocket() failed: %d\n", WSAGetLastError());
        ExitProcess(-1);
    }
    //
    // Set the receive and send timeout values to a second
    //
    timeout = 1000;
    ret = setsockopt(sockRaw, SOL_SOCKET, SO_RCVTIMEO, 
            (char *)&timeout, sizeof(timeout));
    if (ret == SOCKET_ERROR)
    {
        printf("setsockopt(SO_RCVTIMEO) failed: %d\n", 
            WSAGetLastError());
        return -1;
    }
    timeout = 1000;
    ret = setsockopt(sockRaw, SOL_SOCKET, SO_SNDTIMEO, 
        (char *)&timeout, sizeof(timeout));
    if (ret == SOCKET_ERROR)
    {
        printf("setsockopt(SO_SNDTIMEO) failed: %d\n", 
            WSAGetLastError());
        return -1;
    }

    ZeroMemory(&dest, sizeof(dest));
    //
    // We need to resolve the host's ip address.  We check to see 
    // if it is an actual Internet name versus an dotted decimal 
    // IP address string.
    //
    dest.sin_family = AF_INET;
    if ((dest.sin_addr.s_addr = inet_addr(argv[1])) == INADDR_NONE)
    {
        hp = gethostbyname(argv[1]);
        if (hp)
            memcpy(&(dest.sin_addr), hp->h_addr, hp->h_length);
        else
        {
            printf("Unable to resolve %s\n",argv[1]);
            ExitProcess(-1);
        }
    }
    //
    // Set the data size to the default packet size.
    // We don't care about the data since this is just traceroute/ping
    //
    datasize = DEF_PACKET_SIZE;
        
    datasize += sizeof(IcmpHeader);  
    //
    // Allocate the sending and receiving buffers for ICMP packets
    //
    icmp_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PACKET);
    recvbuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PACKET);

    if ((!icmp_data) || (!recvbuf))
    {
        printf("HeapAlloc() failed %d\n", GetLastError());
        return -1;
    }
    // Set the socket to bypass the standard routing mechanisms 
    //  i.e. use the local protocol stack to the appropriate network
    //       interface
    //
    bOpt = TRUE;
    if (setsockopt(sockRaw, SOL_SOCKET, SO_DONTROUTE, (char *)&bOpt, 
            sizeof(BOOL)) == SOCKET_ERROR) 
        printf("setsockopt(SO_DONTROUTE) failed: %d\n", 
            WSAGetLastError());

    //  
    // Here we are creating and filling in an ICMP header that is the 
    // core of trace route.
    //
    memset(icmp_data, 0, MAX_PACKET);
    fill_icmp_data(icmp_data, datasize);

    printf("\nTracing route to %s over a maximum of %d hops:\n\n", 
        argv[1], maxhops);

    for(ttl = 1; ((ttl < maxhops) && (!done)); ttl++)
    {
        int bwrote;

        // Set the time to live option on the socket
        //
        set_ttl(sockRaw, ttl);

        //
        // Fill in some more data in the ICMP header
        //
        ((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);
        //
        // Send the ICMP packet to the destination
        //
        bwrote = sendto(sockRaw, icmp_data, datasize, 0, 
                    (SOCKADDR *)&dest, sizeof(dest));
        if (bwrote == SOCKET_ERROR)
        {
            if (WSAGetLastError() == WSAETIMEDOUT) 
            {
                printf("%2d  Send request timed out.\n", ttl);
                continue;
            }
            printf("sendto() failed: %d\n", WSAGetLastError());
            return -1;
        }
        // Read a packet back from the destination or a router along 
        // the way.
        //
        ret = recvfrom(sockRaw, recvbuf, MAX_PACKET, 0, 
            (struct sockaddr*)&from, &fromlen);
        if (ret == SOCKET_ERROR)
        {
            if (WSAGetLastError() == WSAETIMEDOUT) 
            {
                printf("%2d  Receive Request timed out.\n", ttl);
                continue;
            }
            printf("recvfrom() failed: %d\n", WSAGetLastError());
            return -1;
        }
        //
        // Decode the response to see if the ICMP response is from a 
        // router along the way or whether it has reached the destination.
        //
        done = decode_resp(recvbuf, ret, &from, ttl);
        Sleep(1000);
    }
    HeapFree(GetProcessHeap(), 0, recvbuf);
    HeapFree(GetProcessHeap(), 0, icmp_data);

    return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美欧美午夜aⅴ在线观看| 精品日韩99亚洲| 精品粉嫩aⅴ一区二区三区四区| 国产精品免费aⅴ片在线观看| 偷拍一区二区三区| 99久精品国产| 久久九九全国免费| 日韩精品亚洲一区二区三区免费| 高清日韩电视剧大全免费| 欧美狂野另类xxxxoooo| 亚洲欧洲精品一区二区三区| 国产原创一区二区| 91精品久久久久久久久99蜜臂| 亚洲视频在线一区二区| 国产精品羞羞答答xxdd| 精品福利在线导航| 奇米精品一区二区三区四区 | 自拍偷拍国产精品| 激情文学综合网| 日韩免费看网站| 天天影视涩香欲综合网 | 91精品中文字幕一区二区三区| 亚洲欧洲三级电影| 99riav久久精品riav| 国产精品日日摸夜夜摸av| 狠狠色狠狠色综合| 久久这里只精品最新地址| 久久国产视频网| 久久综合色综合88| 国产麻豆视频一区| 国产亚洲短视频| 国产成人一区二区精品非洲| 国产性天天综合网| 成人免费黄色大片| 中文字幕一区二区三区四区 | 奇米精品一区二区三区四区 | 在线观看精品一区| 亚洲在线视频免费观看| 在线精品视频一区二区三四| 亚洲一区日韩精品中文字幕| 精品视频123区在线观看| 午夜久久久久久| 日韩亚洲欧美高清| 精品一区二区三区蜜桃| 国产日韩欧美制服另类| 成人app下载| 亚洲国产综合91精品麻豆| 欧美高清视频在线高清观看mv色露露十八| 亚洲成人精品一区| 精品99一区二区三区| 粉嫩一区二区三区在线看| 亚洲精品乱码久久久久久久久| 在线看一区二区| 日本91福利区| 国产精品日韩精品欧美在线| 色综合一个色综合亚洲| 久久精品国产**网站演员| 欧美大片国产精品| 成人美女视频在线观看18| 亚洲综合在线视频| 91精品国产麻豆| 国产成人av自拍| 亚洲成人手机在线| 国产清纯白嫩初高生在线观看91| 91首页免费视频| 美女任你摸久久| 亚洲免费在线视频一区 二区| 欧美久久高跟鞋激| 成人va在线观看| 日韩av一区二| 亚洲欧洲国产专区| 91精品国产综合久久国产大片| 国产一区二区三区在线观看免费视频| 亚洲欧美综合在线精品| 91精品国产美女浴室洗澡无遮挡| 成人网页在线观看| 免费视频最近日韩| 亚洲欧美激情视频在线观看一区二区三区 | 亚洲一卡二卡三卡四卡无卡久久| 精品欧美乱码久久久久久| 91婷婷韩国欧美一区二区| 蜜桃av一区二区三区电影| 亚洲免费av高清| 久久久99精品久久| 欧美丰满少妇xxxbbb| 91最新地址在线播放| 久久综合综合久久综合| 亚洲精品日韩一| 国产清纯美女被跳蛋高潮一区二区久久w | 欧美国产日本韩| 日韩精品一区在线| 欧美精品九九99久久| 成人av综合一区| 国产盗摄女厕一区二区三区| 天堂一区二区在线免费观看| 亚洲欧美一区二区三区极速播放| 欧美mv日韩mv亚洲| 在线91免费看| 欧美日韩一级大片网址| 色婷婷国产精品久久包臀| 成人午夜免费av| 国产精品亚洲成人| 国产乱码一区二区三区| 久色婷婷小香蕉久久| 蜜桃av一区二区在线观看| 奇米影视在线99精品| 日韩中文字幕区一区有砖一区| 亚洲图片欧美综合| 亚洲午夜电影在线| 亚洲国产中文字幕在线视频综合| 一区二区三区**美女毛片| 综合激情成人伊人| 亚洲精品中文在线| 亚洲码国产岛国毛片在线| 亚洲欧美成人一区二区三区| 亚洲三级电影网站| 亚洲一区在线观看视频| 一区二区三区成人| 亚洲免费三区一区二区| 亚洲激情综合网| 亚洲福中文字幕伊人影院| 性久久久久久久久久久久| 亚洲aaa精品| 蜜桃久久久久久| 黑人精品欧美一区二区蜜桃| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美亚洲图片小说| 欧美在线高清视频| 在线播放91灌醉迷j高跟美女| 制服丝袜av成人在线看| 日韩欧美久久久| 久久久久亚洲蜜桃| 亚洲三级小视频| 日韩成人一区二区三区在线观看| 久久国内精品自在自线400部| 国产精品白丝jk黑袜喷水| 成人av电影免费在线播放| 在线免费观看日韩欧美| 欧美一级搡bbbb搡bbbb| 国产日本欧美一区二区| 亚洲欧美成人一区二区三区| 日韩影院在线观看| 国产盗摄视频一区二区三区| 91在线视频网址| 91精品国产综合久久香蕉麻豆 | 蜜桃视频第一区免费观看| 国产一本一道久久香蕉| 91在线视频免费观看| 偷拍与自拍一区| 国产女人水真多18毛片18精品视频| 美美哒免费高清在线观看视频一区二区 | 久久在线免费观看| 欧美乱熟臀69xxxxxx| 777午夜精品免费视频| 国产精品一区二区果冻传媒| 欧美激情一区二区三区蜜桃视频| 久久99国产乱子伦精品免费| 成人看片黄a免费看在线| 91成人国产精品| 欧美aaaaa成人免费观看视频| 一区二区三区欧美激情| 91精品国产一区二区三区蜜臀 | 乱一区二区av| 5566中文字幕一区二区电影| 亚洲男人的天堂在线aⅴ视频| 久久精品国产亚洲a| 成人丝袜高跟foot| 91高清视频免费看| 亚洲国产精品成人综合| 国产亚洲欧洲一区高清在线观看| 久久久噜噜噜久久中文字幕色伊伊| 免费观看一级欧美片| 色呦呦网站一区| 麻豆91免费看| 久久久久久久久久久黄色| 国产剧情一区二区三区| 亚洲人成7777| 一本大道av一区二区在线播放| 国产午夜精品久久| 日本高清不卡视频| 激情文学综合丁香| 一区二区在线免费| 91麻豆精品国产91久久久| 精品一二三四区| 一区二区三区丝袜| 久久众筹精品私拍模特| 日本欧美加勒比视频| 国产精品午夜春色av| 欧美久久婷婷综合色| 激情图片小说一区| 国产精品嫩草99a| 欧美美女视频在线观看| 日韩有码一区二区三区| 国产精品美女久久久久aⅴ国产馆| 91丨九色丨黑人外教| 偷拍日韩校园综合在线| 国产日产精品一区| 日本v片在线高清不卡在线观看| 8x福利精品第一导航| 99视频一区二区三区|