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

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

?? windows internet programming part 3.html

?? a collection of mega hacking tools
?? HTML
?? 第 1 頁 / 共 5 頁
字號:


5.0 BUILDING HEADERS IN CODE

=======================================



The Headers are built using normal C structures, we declare a struct

for each header we want to build and declare a variable for each field

of the Header that we will be using.



While creating the structure we must remember that there are certain

expectations and limitations on the size of Headers, an IP Header is

20 Bytes in size, so we will have to use certain types of variables

to reflect the sizes of these fields the different variable types and

there sizes are as follows:



unsigned char 		= 1 byte  (8 bits)

unsigned short int 	= 2 bytes (16 bits)

unsigned int 		= 4 bytes (32 bits)





5.1 THE IP HEADER

=======================================



The IP Header as explained above will be built using a structure

containing all of the fields in the IP Header. As you will remember

there are 14 fields in the IP Header, however we will not be using

any of the IP's Options or the padding, also in our examples we will

only be using single Datagrams so there will be no need for fragmenting

the packets so we will not be using the flags field and we will just

set the Fragment Offset to 0.



So with a total of 14 fields in the IP Header we will not be using 3

of them so that leaves us with 11 fields, also we will be storing the

Ip version and length in one variable so that means we will be using

a total of 10 variables for our code when building the Header.





Well here is the structure we will be using to build the IP Header:





typedef struct ip_hdr

{

    unsigned char  ip_verlen;        // version & IHL		 =>	  1 Bytes  (combined size of both)

    unsigned char  ip_tos;           // TOS			 =>	  1 Bytes

    unsigned short ip_totallength;   // Total length		 =>	  2 Bytes

    unsigned short ip_id;            // Identification	 	 =>	  2 Bytes

    unsigned short ip_offset;        // Fragment Offset		 =>	  2 Bytes

    unsigned char  ip_ttl;           // Time to live		 =>	  1 Bytes

    unsigned char  ip_protocol;      // Protocol		 =>	  1 Bytes

    unsigned short ip_checksum;      // Header checksum		 =>	  2 Bytes

    unsigned int   ip_srcaddr;       // Source address		 => 	  4 Bytes

    unsigned int   ip_destaddr;      // Destination address	 =>    +  4 Bytes

				     //				       = 20 Bytes

}IP_HDR; 





This structure contains all of the fields we will be using and the sizes

of the variables add up to 20 Bytes, the correct size of an IP Header,

note however that the Fragment Offset field is given a value of 2 Bytes

which is equal to 16 bits, the true size of the frag offset is 13 but we

altered it here to make up for the missing 3 bits of the flag field but

it wont make any difference to the packet this is still a perfectly formed

IP Header.





5.2 THE TCP HEADER

=======================================



With the below structure you will again notice that there are a few

of the TCP Headers fields missing, again Options and Padding are not

included as we will not be using them, that leaves us with a total of

10 fields and the reserved field has been left out because it is not

currently implemented by TCP so we are left with 9 fields to fill.



With the missing fields of the Header we have increased the sizes of

the Control Bits and Data Offset fields both to 1 Byte to make up the

20 Byte size of the TCP Header.



So here is the TCP Structure:





typedef struct tcp_hdr

{

    unsigned short sport;	     // Source Port		 =>	  2 Bytes

    unsigned short dport;	     // Destination Port	 =>	  2 Bytes

    unsigned int   seqnum;	     // Sequence Number		 =>	  4 Bytes

    unsigned int   acknum;	     // Acknowledgement Number   =>	  4 Bytes

    unsigned char  DataOffset;	     // Data Offset		 =>	  1 Bytes

    unsigned char  Flags;	     // Control Bits		 =>	  1 Bytes

    unsigned short Windows;	     // Window			 =>	  2 Bytes

    unsigned short Checksum; 	     // Checksum		 =>	  2 Bytes

    unsigned short UrgPointer;       // Urgent Pointer		 =>    +  2 Bytes

				     //				       = 20 Bytes

}TCP_HDR;





5.3 THE UDP HEADER

=======================================



The below structure is the UDP Header, unlike previous headers it is

not missing any fields and adds up to a totalsize of 8 Bytes.





typedef struct udp_hdr

{

    unsigned short sport;	     // Source Port		 =>	  2 Bytes

    unsigned short dport;	     // Destination Port	 =>	  2 Bytes

    unsigned short Length; 	     // Length			 =>	  2 Bytes

    unsigned short Checksum;	     // Checksum		 =>    +  2 Bytes

				     //				       =  8 Bytes

}UDP_HDR;





5.4 THE ICMP HEADER

=======================================



The ICMP Header is similiar to the UDP Header, it has very few fields

and it adds up to a size of 8 Bytes.





typedef struct tagICMPHDR

{ 

    unsigned char  icmp_type;	     // Type of message		 =>	  1 Bytes

    unsigned char  icmp_code;        // Type sub code		 =>	  1 Bytes

    unsigned short icmp_cksum;       // Checksum		 =>	  2 Bytes	

    unsigned short icmp_id;          // Identifer		 =>	  2 Bytes

    unsigned short icmp_seq;         // sequence number		 =>	+ 2 Bytes

				     //					= 8 Bytes

} ICMPHDR, *PICMPHDR;





5.5 THE PSUEDO HEADER

=======================================



The Psuedo Header is used to protect against misrouted segments,

its size is 12 Bytes, the following structure forms the Psuedo

Header:





typedef struct ps_hdr

{

    unsigned int   source_address;   // Source Address		 =>	  4 Bytes

    unsigned int   dest_address;     // Destination Address	 =>	  4 Bytes

    unsigned char  placeholder;	     // Place Holder		 =>	  1 Bytes

    unsigned char  protocol;	     // Protocol		 =>	  1 Bytes

    unsigned short tcp_length;	     // TCP Length		 =>    +  2 Bytes

				     //				       = 12 Bytes

    struct tcp_hdr tcp;



}PS_HDR;





5.6 THE CHECKSUM FUNCTION

=======================================



The Checksum Function is needed to calculate the size of the

packet, here is the functions code:





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); 

}







6.0 SOURCE CODE

=======================================



Well in the Source Code we are first going to look at code which is

supported by all Winsock 2 Systems including Win 9x ones so that

every-1 can av' a go as it were. So in this section we are going to

put what weve learned so far together and create a working internet

application by using the icmp protocol to send an ICMP Echo Request

message, the first part of a ping program. First tough we are going

to create a header ".h" file for the application, the file contains

the checksum function and structures for the IP and ICMP headers.



Remember you will have to make sure that the header file is included

correctly with the source file and that you linked to Ws2_32.lib.



6.1 ICMP ECHO REQUEST

=======================================





/********************* icmp.h header file ************************/



// ICMP message types

#define ICMP_ECHOREQ		13	// Echo request query





// IP Header

typedef struct ip_hdr

{

    unsigned char  ip_verlen;        // version & IHL		 =>	  1 Bytes  (combined size of both)

    unsigned char  ip_tos;           // TOS			 =>	  1 Bytes

    unsigned short ip_totallength;   // Total length		 =>	  2 Bytes

    unsigned short ip_id;            // Identification	 	 =>	  2 Bytes

    unsigned short ip_offset;        // Fragment Offset		 =>	  2 Bytes

    unsigned char  ip_ttl;           // Time to live		 =>	  1 Bytes

    unsigned char  ip_protocol;      // Protocol		 =>	  1 Bytes

    unsigned short ip_checksum;      // Header checksum		 =>	  2 Bytes

    unsigned int   ip_srcaddr;       // Source address		 => 	  4 Bytes

    unsigned int   ip_destaddr;      // Destination address	 =>    +  4 Bytes

				     //				       = 20 Bytes

}IP_HDR; 





// ICMP Header

typedef struct tagICMPHDR

{ 

    unsigned char  icmp_type;	     // Type of message		 =>	  1 Bytes

    unsigned char  icmp_code;        // Type sub code		 =>	  1 Bytes

    unsigned short icmp_cksum;       // Checksum		 =>	  2 Bytes	

    unsigned short icmp_id;          // Identifer		 =>	  2 Bytes

    unsigned short icmp_seq;         // sequence number		 =>	+ 2 Bytes

				     //					= 8 Bytes

} ICMPHDR, *PICMPHDR;





#define REQ_DATASIZE 32		// Echo Request Data size





// ICMP Echo Request

typedef struct tagECHOREQUEST

{

    ICMPHDR icmpHdr;

    char    cData[REQ_DATASIZE];



} ECHOREQUEST, *PECHOREQUEST;





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); 

}



/********************* icmp.h header file ************************/





So in the header file we first #defined some code type for ICMP

Echo Request to make things a bit more readable later on, then we

set up our IP and ICMP structures by giving variables for each field

in the Protocol headers. Notice the sizes of each field add up

correctly for the sizes of the protocol headers, we also have a

structure called ECHOREQUEST, all icmp messages have different

fields except for the common ones defined in the icmp header above,

the fields of ECHOREQUEST are the extra fields nedded for echo's.

We then have a function to calculate the checksum, all these bits

of code are just placed inside our .h file to keep things shorter

and more readable in the main program, speaking of which...



/********************* icmp.c source file ************************/



// Make sure you always include your headers and link your libraries :)



#include <winsock2.h>

#include <ws2tcpip.h>

#include <stdio.h>

#include <stdlib.h>

#include "icmp.h"





void main(int argc, char **argv)

{



    DWORD dip = inet_addr(argv[1]);



    WSADATA		wsaData;

    SOCKET		sock;



    static ECHOREQUEST	echo_req;



    struct sockaddr_in sin;



    // Startup WinSock

    if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)

    {

	printf("WSAStartup failure!");

    }



    // Create a raw socket

    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == SOCKET_ERROR)

    {

        printf("Error starting socket");

    }



    sin.sin_family	= AF_INET;

    sin.sin_port	= htons(0);

    sin.sin_addr.s_addr = dip;





    // Fill in echo request

    echo_req.icmpHdr.icmp_type	= ICMP_ECHOREQ;

    echo_req.icmpHdr.icmp_code	= 0;

    echo_req.icmpHdr.icmp_cksum	= 0;

    echo_req.icmpHdr.icmp_id	= 1;

    echo_req.icmpHdr.icmp_seq	= 1;



    // Fill in some data to send

    memset(echo_req.cData, ' ', REQ_DATASIZE);



    // Compute checksum

    echo_req.icmpHdr.icmp_cksum = checksum((unsigned short *)&echo_req, sizeof(ECHOREQUEST));

	

    // Status mesage

    printf("Sending Echo Request to <%s>.\n", argv[1]);



    // Send the echo request  								  

    if (sendto(sock, (const char *) &echo_req, sizeof(ECHOREQUEST), 0, (SOCKADDR *) dip, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)

    {

       printf("sendto() failed: %d\n", WSAGetLastError());

       return -1;

    }





    // Status mesage

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区在线播放| 曰韩精品一区二区| 亚洲亚洲人成综合网络| 韩国在线一区二区| 欧美性xxxxxxxx| 国产精品乱码人人做人人爱| 精品在线视频一区| 正在播放一区二区| 一区二区三区国产精华| 成人免费视频网站在线观看| 精品久久久久久久久久久院品网| 亚洲一区二区视频在线观看| av中文字幕不卡| 久久综合九色综合欧美亚洲| 天天色 色综合| 欧美在线免费观看亚洲| 中文字幕视频一区| 成人激情文学综合网| 精品播放一区二区| 美女视频黄免费的久久| 欧美一区永久视频免费观看| 视频一区视频二区中文字幕| 在线观看av一区二区| 亚洲精品综合在线| 色天天综合色天天久久| 亚洲人成亚洲人成在线观看图片 | 日本亚洲一区二区| 欧美在线观看一区| 久久99久久99| 欧美一级专区免费大片| 日日骚欧美日韩| 欧美精品久久99| 日韩国产精品91| 日韩精品综合一本久道在线视频| 麻豆一区二区三| 精品国产乱码久久久久久久久| 久久国产尿小便嘘嘘尿| 日韩精品在线看片z| 经典三级在线一区| 久久综合久久久久88| 国产69精品久久久久毛片| 国产精品美女www爽爽爽| 97国产精品videossex| 亚洲乱码中文字幕| 欧美日韩国产成人在线免费| 天天综合日日夜夜精品| 欧美成人欧美edvon| 麻豆成人免费电影| 国产女人水真多18毛片18精品视频| 国产精品中文字幕欧美| 亚洲人一二三区| 欧美日韩夫妻久久| 国产精品一线二线三线精华| 国产精品第一页第二页第三页| 一本到不卡免费一区二区| 日韩精品高清不卡| 国产视频一区二区三区在线观看| av日韩在线网站| 午夜欧美大尺度福利影院在线看| 日韩一区二区三区四区五区六区| 激情综合色综合久久| 椎名由奈av一区二区三区| 欧美日韩国产影片| 国产91丝袜在线播放九色| 亚洲激情中文1区| 精品国产自在久精品国产| 波波电影院一区二区三区| 日韩主播视频在线| 国产精品久久久久久户外露出 | 一区二区三区丝袜| 日韩视频免费观看高清在线视频| 丁香婷婷深情五月亚洲| 午夜精品视频一区| 国产精品美女久久久久高潮 | 欧洲亚洲精品在线| 国产在线播放一区二区三区| 一区二区三区美女视频| 久久久亚洲午夜电影| 欧美日韩视频不卡| av男人天堂一区| 久久国产麻豆精品| 亚洲 欧美综合在线网络| 国产精品天美传媒| 精品盗摄一区二区三区| 欧美日韩精品一区二区三区| 国产精品18久久久久久久久久久久| 夜夜嗨av一区二区三区网页| 久久精品一区二区三区不卡牛牛| 9191久久久久久久久久久| 99久久99精品久久久久久| 国产成人av资源| 久久精品国产免费| 天堂蜜桃一区二区三区| 一区二区三区四区不卡在线| 亚洲成人1区2区| 一区二区三区影院| 中文字幕一区二区三区视频| 国产三级精品视频| 26uuu亚洲综合色| 欧美一二区视频| 欧美第一区第二区| 欧美成人艳星乳罩| 欧美成人vr18sexvr| 91精品国产入口| 欧美精品777| 这里只有精品99re| 欧美一区二区三区人| 日韩一区二区在线看片| 欧美一区二区在线视频| 日韩一区二区中文字幕| 日韩欧美国产一区二区在线播放| 欧美精品精品一区| 欧美大片国产精品| 久久久久久久久久久久久久久99 | 国产精品一级黄| 狠狠色丁香婷综合久久| 国产成人日日夜夜| 成人涩涩免费视频| 一本大道久久精品懂色aⅴ| 日本高清不卡视频| 欧美日韩一区高清| 欧美一三区三区四区免费在线看 | 丁香六月久久综合狠狠色| 国产91露脸合集magnet| 成人免费高清在线观看| 91日韩精品一区| 91麻豆精品国产91久久久久久久久| 欧美精品丝袜中出| 日韩欧美一区二区三区在线| 精品久久久久久久一区二区蜜臀| 2020国产成人综合网| 国产精品污网站| 亚洲自拍偷拍网站| 美国一区二区三区在线播放| 国产一区二区三区免费在线观看| 国产精品18久久久久久久久| 色婷婷激情久久| 欧美大度的电影原声| 国产精品国产精品国产专区不片| 亚洲一区在线观看网站| 蜜桃久久久久久久| 成人免费电影视频| 99re热这里只有精品视频| 欧日韩精品视频| 欧美va亚洲va香蕉在线| 中文一区二区在线观看| 亚洲成人福利片| 国产精品夜夜嗨| 欧美艳星brazzers| 久久亚洲综合av| 一区二区三区四区亚洲| 裸体歌舞表演一区二区| 99久久久免费精品国产一区二区| 91精品国产入口| 亚洲人成7777| 韩国av一区二区三区在线观看| 91在线精品秘密一区二区| 91精品国产91综合久久蜜臀| 国产精品伦一区二区三级视频| 午夜激情一区二区三区| 成人免费的视频| 久久综合久久鬼色| 调教+趴+乳夹+国产+精品| 国产不卡在线播放| 欧美精品自拍偷拍| 亚洲色图视频网| 国产麻豆精品一区二区| 欧美男女性生活在线直播观看| 国产欧美日韩综合| 95精品视频在线| 日韩欧美www| 午夜在线电影亚洲一区| 成人教育av在线| 亚洲精品在线一区二区| 图片区日韩欧美亚洲| 91欧美一区二区| 国产婷婷一区二区| 久久国产精品99久久人人澡| 91国内精品野花午夜精品| 国产精品少妇自拍| 国产精品一区在线观看乱码| 日韩亚洲欧美在线| 日韩中文字幕av电影| 一本一本久久a久久精品综合麻豆| 久久久电影一区二区三区| 久久国内精品视频| 欧美一级理论片| 日韩高清在线不卡| 777午夜精品免费视频| 亚洲国产日日夜夜| 在线一区二区三区| 亚洲免费观看高清完整| 91在线一区二区| 中文字幕第一区| 成人app在线| 中文字幕一区二区三| 成人激情视频网站| 国产精品美女久久久久久久久| 成人综合婷婷国产精品久久蜜臀| 国产亚洲综合色|