易截截图软件、单文件、免安装、纯绿色、仅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与windows C++开发异同


1) 使用的库不同。windows下图形开发一般用微软的MFC或.net库,而Linux下则常用qt库。C/C++通用库(c库,STL库)的接口相同,但内部实现不同。
2) 编译器不同。windows下用的是微软编译器VC或.net,而Linux下则用gcc。
3) 开发环境不同。windows的编译器自动生成makefile,而Linux则需要手动编写makefil ......

Linux tty/pty/pts 概念区别

tty0-6是linux本地终端,pts/x是远程登陆需要的终端,比如某人要telnet到你的机子,就需要你的系统有pts/x。 
基本概念:
 
 1. tty(终端设备的统称):
  tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘与显示器取代 ......

4.1. Introduction to Linux Routing


4.1. Introduction to Linux Routing
The design of IP routing allows for very simple route definitions for small networks, while not hindering the flexibility of routing in complex environments. A key concept in IP routing is the ability to define what addresses are locally reachable as oppose ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号