亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
26uuu亚洲综合色| 日韩三级视频在线观看| 日韩av网站免费在线| 亚洲欧美韩国综合色| 中文字幕日本乱码精品影院| 久久久综合精品| 久久久国产一区二区三区四区小说| 欧美精品九九99久久| 欧美日韩国产高清一区二区| 欧美亚日韩国产aⅴ精品中极品| av在线免费不卡| 91亚洲永久精品| 在线亚洲人成电影网站色www| 一本色道久久综合亚洲91| 国产suv精品一区二区三区| 国产成人高清在线| 亚洲日本青草视频在线怡红院| 欧美激情在线观看视频免费| 中文字幕不卡在线| 国产精品白丝在线| 亚洲柠檬福利资源导航| 亚洲综合免费观看高清完整版在线 | 亚洲少妇屁股交4| 亚洲婷婷国产精品电影人久久| 日韩美女视频一区| 亚洲午夜在线视频| 激情五月婷婷综合网| 国产91精品一区二区麻豆网站| 99精品在线观看视频| 在线观看免费成人| 日韩久久精品一区| 国产精品妹子av| 亚洲成人av免费| 韩国精品主播一区二区在线观看| 懂色av一区二区三区免费看| 色综合久久九月婷婷色综合| 91精品欧美久久久久久动漫| 久久美女艺术照精彩视频福利播放| 国产精品成人一区二区三区夜夜夜 | 欧美xfplay| 日韩一区欧美小说| 美女免费视频一区二区| 99re亚洲国产精品| 日韩精品一区二区三区在线| 中文字幕一区在线| 老鸭窝一区二区久久精品| 成人在线综合网| 91精品国产综合久久小美女| 国产欧美精品一区二区色综合朱莉| 亚洲欧美视频在线观看| 激情欧美日韩一区二区| 欧美主播一区二区三区| 中文字幕欧美区| 捆绑调教一区二区三区| 欧美性一二三区| 国产女人18水真多18精品一级做| 丝袜美腿一区二区三区| 91麻豆国产自产在线观看| 2023国产精品视频| 亚洲在线观看免费视频| av一区二区三区| 久久久久久久av麻豆果冻| 水蜜桃久久夜色精品一区的特点| av中文字幕在线不卡| 久久免费视频色| 捆绑变态av一区二区三区| 欧美肥妇毛茸茸| 亚洲成av人影院| 成人一级黄色片| 久久久影视传媒| 国产一区二区伦理| 欧美va在线播放| 久久99日本精品| 日韩无一区二区| 美腿丝袜在线亚洲一区| 在线不卡的av| 日韩电影在线一区二区三区| 欧美日韩亚洲综合一区二区三区| 亚洲天堂成人网| 97久久超碰精品国产| 国产精品久久久久久久第一福利| 国产1区2区3区精品美女| 精品国产一区二区国模嫣然| 日韩国产欧美三级| 日韩一级完整毛片| 久久精品国产成人一区二区三区 | 亚洲成人久久影院| 欧美揉bbbbb揉bbbbb| 亚洲成人激情av| 欧美电影在线免费观看| 奇米888四色在线精品| 精品国产乱码久久久久久浪潮 | 精品成人佐山爱一区二区| 奇米一区二区三区av| 欧美一卡在线观看| 国内精品国产成人国产三级粉色| 久久麻豆一区二区| 成人小视频免费观看| 中文字幕一区二区三区不卡在线| 色94色欧美sute亚洲线路一ni| 亚洲靠逼com| 欧美精品xxxxbbbb| 国产老肥熟一区二区三区| 久久久不卡影院| 91麻豆国产香蕉久久精品| 亚洲国产va精品久久久不卡综合| 欧美私模裸体表演在线观看| 免费观看在线综合| 国产精品久久久久久久久免费樱桃| 91丨porny丨中文| 午夜精品久久久久| 久久久久亚洲综合| 欧美性猛片aaaaaaa做受| 男人的天堂久久精品| 日本一区二区高清| 欧美人体做爰大胆视频| 成人性视频免费网站| 亚洲免费资源在线播放| 精品国产亚洲一区二区三区在线观看| 国产成人免费视频一区| 午夜精品一区二区三区免费视频| 精品电影一区二区| 欧美视频你懂的| 国产精品77777| 天堂久久一区二区三区| 亚洲国产成人私人影院tom | 五月开心婷婷久久| 国产精品网友自拍| 日韩午夜在线影院| 日本电影亚洲天堂一区| 国产一区二区三区| 亚洲mv大片欧洲mv大片精品| 中文字幕av不卡| 精品久久久久久最新网址| 色婷婷av久久久久久久| 国产激情视频一区二区三区欧美 | 精品一区二区久久| 亚洲午夜三级在线| 1024成人网色www| 国产日韩三级在线| 欧美电影免费观看高清完整版在| 91黄色激情网站| 97精品超碰一区二区三区| 国产一区二区网址| 久久成人av少妇免费| 激情综合五月婷婷| 蜜臀国产一区二区三区在线播放 | 亚洲影院免费观看| 中文字幕色av一区二区三区| 精品国产欧美一区二区| 日韩一区二区三区四区五区六区| 欧美亚洲综合网| 欧美亚洲精品一区| 日本国产一区二区| 97精品国产露脸对白| av中文字幕在线不卡| 成人毛片视频在线观看| 国产大片一区二区| 国产激情一区二区三区桃花岛亚洲| 久久成人免费网站| 精品一区二区三区久久| 激情六月婷婷综合| 成人一二三区视频| 91看片淫黄大片一级| 91麻豆国产福利精品| 91久久精品一区二区| 日本黄色一区二区| 欧美色区777第一页| 欧美日韩国产首页| 7777精品伊人久久久大香线蕉超级流畅 | 石原莉奈一区二区三区在线观看| 亚洲网友自拍偷拍| 日韩成人一区二区| 久草在线在线精品观看| 福利91精品一区二区三区| 高清不卡一区二区| 91福利在线导航| 欧美一区二区成人6969| 亚洲精品一线二线三线| 中文字幕av在线一区二区三区| 亚洲天堂免费在线观看视频| 伊人婷婷欧美激情| 奇米综合一区二区三区精品视频| 久草这里只有精品视频| 国产成人免费视| 欧美亚洲免费在线一区| 日韩一区二区三区四区五区六区| 26uuu亚洲综合色| 亚洲精品国产a久久久久久| 亚洲一区二区三区四区五区中文| 日韩电影在线免费看| 国产精品一卡二| 色综合久久66| 精品对白一区国产伦| 亚洲三级小视频| 久久激情综合网| 在线视频一区二区三区| 久久综合一区二区| 亚洲自拍欧美精品| 国产一二精品视频|