易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux发送arp请求与接收arp响应

Linux 中获得本机网卡MAC地址很简单,ioctl()就OK。可如何获得局域网其他主机的MAC地址呢…链路层广播ARP请求,然后接收ARP响应。实现介个功能其实已有现成三方库可用,如libnet。不过想加深对协议的理解和Linux网络编程API的理解,jiayi 还是决定用Linux的PF_PACKET自己实现,改啊改,终于成功~以下是大体思路
1. 为数据报分配空间,创建相应的结构体 req,arp 数据报的帧格式如图
        
2. 创建 PF_PACKET 原始套接字,发送套接字为 reqfd,接收套接字为 recvfd
3. 填写链路层通用结构体 reqsa
3. get_ifi()获取本机网络接口数据,填写要发送的ARP数据报 req 结构体,sendto()发送
4. 循环recvfrom()接收ARP响应,滤掉经由本地接口的其他ARP数据报
发送ARP请求能做的事不仅仅获取MAC地址吧…其他“有意义”的事也可以尝试一下下……下面是代码
C code
/**
* @send_arp.c
* @This software is intended to be used as a example to show how to send and receive arp request with Linux * PF_PACKET interface
* @Author:jiayi,http://www.jiayii.com
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sys/types.h>
#include <asm/types.h>
#include <features.h> /* 需要里面的 glibc 版本号 */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
        #include <netpacket/packet.h>
        #include <net/ethernet.h> /* 链路层(L2)协议 */
#else
        #include <asm/types.h>
        #include <linux/if_packet.h>
        #include <linux/if_ether.h> /* 链路层协议 */
#endif
#include <netinet/if_ether.h>
#define INLEN 4
#define MAC_BCAST_ADDR  (uint8_t *) "\xff\xff\xff\xff\xff\xff"
void usage_quit(char *arg0);
int get_ifi(char *


相关文档:

实战Linux Bluetooth编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

Moto Linux应用开发(四):A1200官方SDK

今天终于拿到moto官方SDK,是for A1200的,包括toolchian和EZX库及头文件,该SDK也适用于moto E6. 按照安装指导文档安装好SDK并执行脚本设置好环境变量后,首先是build一个最简单的sample程序hello,以验证SDK是否安装正确。运行qmake却出现如下错误:
~/workspace/devtools/moto-sdk/sample/gui/hello$ qmake hello.pro&n ......

Linux各发行版本简介

转载自:http://bbs.dp168.com/thread-23703-1-1.html
Redhat
简介:
Red Hat Linux是商业上运作最成功的一个Linux发行套件,普及程度很高,由Red Hat公司发行。
Red Hat
Linux可算是一个“中年的”Linux发行套件,1.0版本于1994年11月3日发行。虽然其历史不及Slackware般悠久,但比起很多的
Linux发行套件 ......

袁老谈linux的10年发展

 本世纪第一个十年,即将过去。回顾以往,才能看清现在,我有几句话要说。
      记得,在十年之前,人们只能玩玩美国红帽的 Linux 桌面(特别是 6.2 版本),整天 sudo (即 Super User do ),任凭激情泛滥。到了 2001 年 1 月, Linux 2.4 正式发布,首次支持 USB 和蓝牙技术,以及 ext ......

linux c mkdir创建递归目录

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define err(msg) perror(msg)
static void mkdirs(const char *dir)
{
        char tmp[1024];
        char *p;
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号