- 論壇徽章:
- 0
|
回復(fù) #54 dreamice 的帖子
構(gòu)造數(shù)據(jù)包的過程是這樣的
/*此處進行阻斷*/
TCP_protocol_tag= /*向數(shù)據(jù)源server端發(fā)送阻斷包*/
libnet_build_tcp(
ntohs(tcp_pack->DstPort), /* source port */
ntohs(tcp_pack->SrcPort), /* destination port */
ntohl(tcp_pack->AckNum), /* sequence number */
ntohl(tcp_pack->SeqNum)+tcp_data_len, /* acknowledgement num */
TH_RST, /* control flags */
32000, /* window size */
0, /* checksum */
0, /* urgent pointer */
LIBNET_TCP_H+buf_size, /* TCP packet size */
(unsigned char *)sendbuf, /* payload */
buf_size, /* payload size */
l, /* libnet handle */
0); /* libnet id */
IP_protocol_tag=
libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_TCP_H+buf_size, /* length */
0, /* TOS */
242, /* IP ID*/
0, /* IP Frag */
64, /* TTL */
IPPROTO_TCP, /* protocol */
0, /* checksum */
*(u_int32_t*)&ih->daddr, /* source IP */
*(u_int32_t*)&ih->saddr, /* destination IP */
0, /* payload */
0, /* payload size */
l, /* libnet handle */
0); /* libnet id */
ETH_protocol_tag = libnet_build_ethernet(
/* 構(gòu)造一個以太網(wǎng)協(xié)議塊,返回一個指向此協(xié)議快的標(biāo)記 */
ether_header->src_hw_addr, /* 以太網(wǎng)目的地址 hardware_destination*/
ether_header->targ_hw_addr, /* 以太網(wǎng)源地址 hardware_source*/
ETHERTYPE_IP, /* 以太網(wǎng)上層協(xié)議類型,此時為IP類型 */
NULL, /* 負(fù)載,這里為空 */
0, /* 負(fù)載大小 *///LIBNET_ETH_H+LIBNET_IPV4_H + LIBNET_TCP_H
l, /* Libnet句柄 */
0); /* 協(xié)議塊標(biāo)記,此時為0 */
int c=libnet_write(l);
libnet_clear_packet(l);
/////////////////////
TCP_protocol_tag= /*向數(shù)據(jù)接收端client發(fā)送阻斷包*/
libnet_build_tcp(
ntohs(tcp_pack->SrcPort), /* source port */
ntohs(tcp_pack->DstPort), /* destination port */
ntohl(tcp_pack->SeqNum), /* sequence number */
ntohl(tcp_pack->AckNum), /* acknowledgement num */
TH_RST, /* control flags */
32000, /* window size */
0, /* checksum */
0, /* urgent pointer */
LIBNET_TCP_H+buf_size, /* TCP packet size */
(unsigned char *)sendbuf, /* payload */
buf_size , /* payload size */
l, /* libnet handle */
0); /* libnet id */
IP_protocol_tag=
libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_TCP_H+buf_size, /* length */
0, /* TOS */
242, /* IP ID*/
0, /* IP Frag */
64, /* TTL */
IPPROTO_TCP, /* protocol */
0, /* checksum */
*(u_int32_t*)&ih->saddr, /* source IP */
*(u_int32_t*)&ih->daddr, /* destination IP */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0); /* libnet id */
ETH_protocol_tag = libnet_build_ethernet(
/* 構(gòu)造一個以太網(wǎng)協(xié)議塊,返回一個指向此協(xié)議快的標(biāo)記 */
ether_header->targ_hw_addr, /* 以太網(wǎng)目的地址 hardware_source*/
ether_header->src_hw_addr, /* 以太網(wǎng)源地址 hardware_destination*/
ETHERTYPE_IP, /* 以太網(wǎng)上層協(xié)議類型,此時為IP類型 */
NULL, /* 負(fù)載,這里為空 */
0, /* 負(fù)載大小 *///LIBNET_ETH_H+LIBNET_IPV4_H + LIBNET_TCP_H
l, /* Libnet句柄 */
0); /* 協(xié)議塊標(biāo)記,此時為0 */
c=libnet_write(l);
libnet_clear_packet(l); |
|