亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網(wǎng)絡(luò),我們將竭誠為您提供優(yōu)質(zhì)的服務(wù)! 誠征網(wǎng)絡(luò)推廣 | 網(wǎng)站備案 | 幫助中心 | 軟件下載 | 購買流程 | 付款方式 | 聯(lián)系我們 [ 會員登錄/注冊 ]
促銷推廣
客服中心
業(yè)務(wù)咨詢
有事點擊這里…  531199185
有事點擊這里…  61352289
點擊這里給我發(fā)消息  81721488
有事點擊這里…  376585780
有事點擊這里…  872642803
有事點擊這里…  459248018
有事點擊這里…  61352288
有事點擊這里…  380791050
技術(shù)支持
有事點擊這里…  714236853
有事點擊這里…  719304487
有事點擊這里…  1208894568
有事點擊這里…  61352289
在線客服
有事點擊這里…  531199185
有事點擊這里…  61352288
有事點擊這里…  983054746
有事點擊這里…  893984210
當(dāng)前位置:首頁 >> 技術(shù)文章 >> 文章瀏覽
技術(shù)文章

基于Linux的網(wǎng)絡(luò)數(shù)據(jù)幀捕獲方法與思考

添加時間:2011-4-17  添加: admin 
 

目前,國內(nèi)推出了許多的Linux的發(fā)行版本,其重點集中在中文平臺上,方便了國內(nèi)用戶對Linux的使用,但是有一個不是太好的跡象就是把漢化作為Linux操作系統(tǒng)的主要功能,實際上漢字處理盡管非常重要,但是把Linux作為桌面系統(tǒng)進(jìn)行推廣,其價值不是非常大,并且在推出的發(fā)行版本中,應(yīng)用程序的源代碼包多被刪除,而選擇了一些不是太有價值的X-Windows程序包,而許多應(yīng)用程序(如PHP3)必須要源代碼的支持才可進(jìn)行功能的擴展,GNU/Linux的優(yōu)秀主要是給了我們非常豐富的軟件資源,和享受資源的充分自由,應(yīng)用程序的分析難度遠(yuǎn)小于內(nèi)核,并且能夠帶來比較明顯的效果,實際上許多的應(yīng)用程序都提供了多平臺的支持。Linux目前可能作為對抗Windows NT的工具是非常合適的。

附源程序:

 /*
  
  * This program demonstrate SOCK_PACK call.
  
  * Thanks Linux. Thanks Alan Cox
  
  * derived from/usr/src/redhat/SOURCES/dosemu-0.66.7/src/dosext/net/net/libpacket.c
  
  *  compile method: cc capturer.c -o capturer
  
  */
  
  /*
  
  * Alan Cox raw code
  
  */
  
  
  /*
  
  * SOCK_PACKET support.
  
  * Placed under the GNU LGPL.
  
  *
  
  * First cut at a library of handy support routines. Comments, additions
  
  * and bug fixes greatfully received.
  
  *
  
  * (c) 1994 Alan Cox iiitac@pyr.swan.ac.uk GW4PTS@GB7SWN
  
  */
  
  #include <stdio.h>
  
  #include <features.h>
  
  #include <unistd.h>
  
  #include <stdlib.h>
  
  #include <ctype.h>
  
  #include <getopt.h>
  
  #include <string.h>
  
  #include <fcntl.h>
  
  #include <asm/types.h>
  
  #include <sys/socket.h>
  
  #include <sys/ioctl.h>
  
  /*#if __GLIBC__ > 1*/
  
  #include <asm/sockios.h>
  
  #include <net/if.h>
  
  /*#else
  
  #include <linux/sockios.h>
  
  #include <linux/if.h>
  
  #endif*/
  
  #include <netinet/in.h>
  
  #include <asm/checksum.h>
  
  /*
  
  * Obtain a file handle on a raw ethernet type. In actual fact
  
  * you can also request the dummy types for AX.25 or 802.3 also
  
  *
  
  * -1 indicates an error
  
  * 0 or higher is a file deor which we have set non blocking
  
  *
  
  * WARNING: It is ok to listen to a service the system is using (eg arp)
  
  * but don't try and run a user mode stack on the same service or all
  
  * hell will break loose.
  
  */
  
  int
  
  OpenNetworkType(unsigned short netid)
  
  {
  
  int s = socket(AF_INET, SOCK_PACKET, htons(netid));
  
  
  if (s == -1)
  
  return -1;
  
  fcntl(s, F_SETFL, O_NDELAY);
  
  return s;
  
  }
  
  /*
  
  * Close a file handle to a raw packet type.
  
  */
  
  
  void
  
  CloseNetworkLink(int sock)
  
  {
  
  close(sock);
  
  }
  
  /*
  
  * Write a packet to the network. You have to give a device to
  
  * this function. This is a device name (eg 'eth0' for the first
  
  * ethernet card). Please don't assume eth0, make it configurable
  
  * - plip is ethernet like but not eth0, ditto for the de600's.
  
  *
  
  * Return: -1 is an error
  
  * otherwise bytes written.
  
  */
  
  int
  
  WriteToNetwork(int sock, const char *device, const char *data, int len)
  
  {
  
  struct sockaddr sa;
  
  sa.sa_family = AF_INET;
  
  strcpy(sa.sa_data, device);
  
  return (sendto(sock, data, len, 0, &sa, sizeof(sa)));
  
  }
  
  /*
  
  * Read a packet from the network. The device parameter will
  
  * be filled in by this routine (make it 32 bytes or more).
  
  * If you wish to work with one interface only you must filter
  
  * yourself. Remember to make your buffer big enough for your
  
  * data. Oversized packets will be truncated.
  
  *
  
  * Return:
  
  * -1 Error
  
  * otherwise Size of packet received.
  
  */
  
  int
  
  ReadFromNetwork(int sock, char *device, char *data, int len)
  
  {
  
  struct sockaddr sa;
  
  int sz = sizeof(sa);
  
  int error;
  
  error = recvfrom(sock, data, len, 0, &sa, &sz);
  
  if (error == -1)
  
  return -1;
  
  strcpy(device, sa.sa_data);
  
  return error; /* Actually size of received packet */
  
  }
  
  /*
  
  * Handy support routines.
  
  */
  
  /*
  
  * Obtain the hardware address of an interface.
  
  * addr should be a buffer of 8 bytes or more.
  
  *
  
  * Return:
  
  * 0 Success, buffer holds data.
  
  * -1 Error.
  
  */
  
  
  /*
  
  * NET2 or NET3 - work for both.
  
  */
  
  #if defined(OLD_SIOCGIFHWADDR) || (KERNEL_VERSION >= 1003038)
  
  #define NET3
  
  #endif
  
  
  int
  
  GetDeviceHardwareAddress(char *device, char *addr)
  
  {
  
  int s = socket(AF_INET, SOCK_DGRAM, 0);
  
  struct ifreq req;
  
  int err;
  
  strcpy(req.ifr_name, device);
  
  err = ioctl(s, SIOCGIFHWADDR, &req);
  
  close(s); /* Thanks Rob. for noticing this */
  
  if (err == -1)
  
  return err;
  
  memcpy(addr, req.ifr_hwaddr.sa_data,8);
  
  return 0;
  
  }
  
  /*
  
  * Obtain the maximum packet size on an interface.
  
  *
  
  * Return:
  
  * >0 Return is the mtu of the interface
  
  * -1 Error.
  
  */
  
  int
  
  GetDeviceMTU(char *device)
  
  {
  
  int s = socket(AF_INET, SOCK_DGRAM, 0);
  
  struct ifreq req;
  
  int err;
  
  strcpy(req.ifr_name, device);
  
  err = ioctl(s, SIOCGIFMTU, &req);
  
  close(s); /* So I'll add this one as well. Ok Alan? - Rob */
  
  if (err == -1)
  
  return err;
  
  return req.ifr_mtu;
  
  }
  
  #define data_packet_len 1514
  
  int
  
  main(int argc ,char *argv[])
  
  {
  
  char devicename_rec[32];
  
  unsigned char data[data_packet_len];
  
  int netid=0x03,sock_h=0,i=0,count_rec=0;
  
  if ((sock_h=OpenNetworkType(netid))<0)
  
  {
  
  printf("Can't open net_dectype %d \n",netid);
  
  return -1;
  
  }
  
  printf("Ready to receive 0x%x data packet...\n",netid);
  
  for(;;) {
  
  if (ReadFromNetwork(sock_h,devicename_rec,data,data_packet_len)>0) {
  
  printf("Received Packet = %d\n",++count_rec) ;
  
  for (i=0;i<100;i++)
  
  printf("%2x|",data[i]);
  
  printf("\n");
  
  }
  
  }
  
  }

以上程序在Redhat 5.1下編譯通過,運行良好。

關(guān)鍵字:網(wǎng)絡(luò)、數(shù)據(jù)幀

分享到:

頂部 】 【 關(guān)閉
版權(quán)所有:佛山思海電腦網(wǎng)絡(luò)有限公司 ©1998-2024 All Rights Reserved.
聯(lián)系電話:(0757)22630313、22633833
中華人民共和國增值電信業(yè)務(wù)經(jīng)營許可證: 粵B1.B2-20030321 備案號:粵B2-20030321-1
網(wǎng)站公安備案編號:44060602000007 交互式欄目專項備案編號:200303DD003  
察察 工商 網(wǎng)安 舉報有獎  警警  手機打開網(wǎng)站