日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

libnet TCP示例

發布時間:2023/12/13 综合教程 26 生活家
生活随笔 收集整理的這篇文章主要介紹了 libnet TCP示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
[root@TD18 tmp]#gcc -o 1 1.c -lnet
[root@TD18 tmp]#./1
please enter Host address
11.11.11.11
please enter local address:
22.22.22.22
wrote 126 byte TCP packet
[root@TD18 tmp]#cat 1.c
#include<stdio.h>
#include<string.h>
#include<pcap.h>
#include<libnet.h>

main(void)
{ int c ;
   u_char *cp;
   libnet_t *l;
   libnet_ptag_t t;
   char *payload;
   u_char HostAddr[255],MyAddr[255];
   u_short payload_s;
   u_long src_ip,dst_ip;
   u_short src_prt,dst_prt;


   char errbuf[LIBNET_ERRBUF_SIZE];
   printf("please enter Host address
");
  scanf("%s",HostAddr);
   printf("please enter local address:
");
  scanf("%s",MyAddr);
   l=libnet_init( LIBNET_LINK,NULL,errbuf);
  if(l==NULL)
    {
       printf("libnet failed: %s",errbuf);
       exit(EXIT_FAILURE);
    }
  dst_ip=inet_addr(HostAddr);
  src_ip=inet_addr(MyAddr);
  dst_prt=0;
  src_prt=0;

  payload="adafhafhasfjashfasjfasjkfhsadjkfajskfjasdhfjaksfjkaf";
  payload_s=strlen(payload);
t=libnet_build_tcp_options("0303120102040111101277777777000000000000",20,l,0);
if(t==-1)
   {printf("cant build TCP options: %s
",libnet_geterror(l));
   goto bad;}

   t=libnet_build_tcp(src_prt,dst_prt,0x01010101,0x02020202,TH_SYN,32767,0,10,
                   LIBNET_TCP_H+20+payload_s,payload,payload_s,l,0 );
if(t==-1)
          {
             printf("cant build TCP header:%s
",libnet_geterror(l));
             goto bad;
          }

    t=libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_TCP_H+20+payload_s,0,242,0,64,IPPROTO_TCP,0,src_ip,dst_ip,NULL,0,l,0);

if(t==-1)
  {
   printf("cant build IP header:%s
",libnet_geterror(l));
   goto bad;
  }
  t=libnet_build_ethernet("00:0B:6A:63:5E:11","00:0B:6A:63:5E:22",ETHERTYPE_IP,NULL,0,l,0);

if(t==-1)
{printf("cant buid ethernet header:%s
",libnet_geterror(l));
  goto bad;
}
  c=libnet_write(l);
if(c==-1)
  {printf("write error:%s
",libnet_geterror(l));
   goto bad;
  }
else { printf("wrote %d byte TCP packet
",c);
     }
libnet_destroy(l);
return(EXIT_SUCCESS);
bad:
   libnet_destroy(l);
   return(EXIT_FAILURE);

}

總結

以上是生活随笔為你收集整理的libnet TCP示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。