91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Libpcap tutorial-01

發布時間:2020-07-06 21:27:00 來源:網絡 閱讀:453 作者:hanchengen 欄目:網絡安全
  • Download libpcap source from www.tcpdump.org here

  • Download libpcap for win32 fromwww.winpcap.org

  • Check out a better pcap tutorial here


Front matter:  This is a slightly modified and extended version of my older pcap tutorial.  Revisiting this work five years later, I am necessarily dumber (age and beer) yet hopefully somewhat more knowledgeable.  Contact information has changed, please send your hate-mail to casado at cs.stanford.edu.


Contents

  • Intro (You are already here)

  • Capturing our First Packet

  • Writing a Basic Packet Capturing Engine

  • Analyzing packets..... (in progress)


Who this is for:  This tutorial assumes a cursory knowledge in networks; what a packet is, Ethernet vs. IP vs. TCP vs. UDP etc. If these concepts are foreign I highly suggest you invest in a good (e.g. probably can't find at Best Buy) networking book.  My favorites are:

  • Computer Networking : A Top-Down Approach Featuring the Internet (3rd Edition) by James F. Kurose, Keith W. Ross

  • UNIX Network Programming by W. Richard Stevens

  • The Protocols (TCP/IP Illustrated, Volume 1) by W. Richard Stevens

This tutorial does not assume any previous knowledge in network programming, just a basic familiarity with c.  If you already are a c/c++ master, then you might as well just man 3 pcap.  You should have a working c compiler on your system and libpcap installed.  All source in this section was written and tested on linux, kernel 2.2.14, while it should be mostly portable (hehe) I can't guarantee that it will compile or run on other operating systems.  You are going to want to run as root so be careful and be sure not to break your box in the meantime. Oh, and though I have tested and run all the code presented in this tutorial with no problems, I am NOT responsible if your shit breaks and has to be quarantined by the health department...  aka play at your own risk....  



hcn# gcc ldev.c -lpcap

/* ldev.c   
   編譯指令
   >gcc ldev.c -lpcap

   查詢網卡, 展示與該網卡相關的網絡地址和子網掩碼
*/
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>      /* GIMME a libpcap plz! */
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char **argv)
{
  char *dev; /* 網卡名稱 */ 
  char *net; /* 用點標識的網絡地址  */
  char *mask;/* 用點標識的子網掩碼  */
  int ret;   /* 返回標識 */
  
  char errbuf[PCAP_ERRBUF_SIZE];    /* 錯誤信息 */
  bpf_u_int32 netp;     /* 網絡地址          */
  bpf_u_int32 maskp;    /* 子網掩碼 */
  
  struct in_addr addr;

  /* 通過pcap去發現一個可用的網卡用于嗅探 */
  dev = pcap_lookupdev(errbuf);

  /* 檢測是否找到可用網卡 */
  if(dev == NULL)
  {
   printf("%s\n",errbuf);
   exit(1);
  }

  /* 打印網卡名稱 */
  printf("DEV: %s\n",dev);

  /* 通過pcap查詢網卡的網絡地址和子網掩碼*/
  ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);

  /* 檢測上不操作是否成功 */
  if(ret == -1)
  {
   printf("%s\n",errbuf);
   exit(1);
  }

  /* 將網絡地址從網絡格式轉化為人可讀格式*/
  addr.s_addr = netp;
  net = inet_ntoa(addr);

  /* 檢測轉化是否成功 */
  if(net == NULL)
  {
    perror("inet_ntoa");
    exit(1);
  }

  /* 打印網絡地址*/
  printf("NET: %s\n",net);

  /* 將子網掩碼地址從網絡格式轉為人可讀格式*/
  addr.s_addr = maskp;
  mask = inet_ntoa(addr);
  
  if(mask == NULL)
  {
    perror("inet_ntoa");
    exit(1);
  }
  
  /* 打印子網掩碼*/
  printf("MASK: %s\n",mask);

  return 0;
}


加入編譯和執行正確,控制臺將顯示如下信息:

DEV: eth0
NET: 192.168.12.0
MASK: 255.255.255.0


The value for DEV is your default interface name (likely eth0 on linux, could be eri0 on solaris). The NET and MASK values are your primary interface's subnet and subnet mask.  Don't know what those are? Might want to read this.

"So what did we just do?", you ask.  Well, we just asked libpcap to give us some specs on an interface to listen on.
"Whats an interface?"
Just think of an interface as your computers hardware connection to whatever network your computer is connected to.  On Linux, eth0 denotes the first Ethernet card in your computer.  (btw you can list all of your interfaces using the ifconfig command).

OK at this point we can compile a pcap program that essentially does nothing.  On to grabbing our first packet ...








向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

庄河市| 安吉县| 保德县| 雷波县| 兴业县| 京山县| 镇赉县| 南陵县| 互助| 洛浦县| 民勤县| 卢氏县| 辽中县| 海南省| 楚雄市| 鄂伦春自治旗| 霍城县| 日照市| 平南县| 宁强县| 台北县| 莫力| 通海县| 哈密市| 和政县| 阳原县| 阜城县| 扶余县| 兴隆县| 南投市| 百色市| 济宁市| 南安市| 若羌县| 长岛县| 大城县| 仁布县| 武义县| 巴南区| 伊金霍洛旗| 称多县|