Linux下几例抓包程序代码
抓包程序1 grub_allpacket.c
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int sock, n,i;
char buffer[2048];
unsigned char *iphead, *ethhead;
struct ifreq ethreq;
if ( (sock=socket(PF_PACKET, SOCK_RAW,
htons(ETH_P_IP)))<0) {
perror("socket");
exit(1);
}
/* Set the network card in promiscuos mode */
strncpy(ethreq.ifr_name,"eth0",IFNAMSIZ);
if (ioctl(sock,SIOCGIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
ethreq.ifr_flags|=IFF_PROMISC;
if (ioctl(sock,SIOCSIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
while (1) {
printf("----------\n");
n = recvfrom(sock,buffer,2048,0,NULL,NULL);
printf("%d bytes read\n",n);
printf("the frame content is :\n");
for(i=0;i<n;)
{
printf("%02x",(unsigned char)buffer[i]);
fflush(stdout);
i=i+1;
if(i%8==0)
printf("\n");
else
printf(":");
}
printf("\n");
/* Check to see if the packet contains at least
&nbs
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
记录常用操作:
文件及文件夹相关
=======================================================================
文件操作(rm);
文件夹操作(rmdir 删除空文件,rm -rf 目录名删除非空文件夹);
文件移动:mv cp都可以;
解压缩:tar
格式: tar 选项 文件目录列表
功能: 对文件目 ......
在Linux 中,动态库的搜索路径除了默认的搜索路径外,还可通过三种方法来指定:方法一:在配置文件/etc/ld.so.conf中指定动态库搜索路径;方法二:通过环境变量LD_LIBRARY_PATH指定动态库搜索路径;方法三:在编译目标代码时指定该程序的动态库搜索路径。
众所周知,Linux动态库的默认搜索路径是/lib和/usr/lib。动态库被 ......
级
别: 中级
M.
Tim Jones
, 自由作家
2009 年 11 月 19 日
处理器已经演变
为针对虚拟环境提高性能,但 I/O 方面发生了什么变化呢?了解一种名为设备(或 PCI)透传(passthrough)的 I/O
性能增强技术,这种创新技术通过使用来自 Intel® (VT-d) 或 AMD (IOMMU) 的硬件支持改进 PCI 设 ......