使用Linux 原始套接字抓取数据链路层上IEC61850-9-2(LE) SV数据包并显示的参考程序
2014-09-15 17:54
495 查看
目标:在linux下使用C语言的原始套接字来接收以太网数据链路层上的数据,如果接收的数据是IEC61850-9-2 SV类型,则打印。。。。仅供参考!
源代码:
运行效果:
(------------------完---------------------)
源代码:
#include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include <linux/if_ether.h> #include <linux/in.h> #define BUFFER_MAX 2048 int main(int argc, char *argv[]) { int sock, n_read, eth_type; char buffer[BUFFER_MAX]; char *eth_head; if((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { fprintf(stdout, "create socket error/n"); exit(0); } while(1) { n_read = recvfrom(sock, buffer, 2048, 0, NULL, NULL); if(n_read < 42) { fprintf(stdout, "Incomplete header, packet corrupt/n"); continue; } eth_head = buffer; eth_type=((unsigned char)eth_head[16])*16*16+(unsigned char)eth_head[17]; if(eth_type==0x88ba){ //judge wether the eth_type is iec61850 sv printf("\n----------------IEC61850-9-2 SV---------------------\n"); int i=0; for(i=0;i<n_read;i++){ printf("%.2X ",(unsigned char)eth_head[i]); if(((i+1)%16)==0) printf("\n"); } printf("\n----------------------------------------------------\n"); } } }
运行效果:
(------------------完---------------------)
相关文章推荐
- 使用Linux 原始套接字抓取数据链路层上IEC61850-9-2(LE) SV数据包并显示的参考程序
- Linux下使用RAW SOCKET原始套接字构造UDP原始数据帧广播到局域网,在局域网的另一台计算机上显示UDP发送的信息
- 利用原始套接字(sock_raw)编写的抓取ip数据包的小程序
- Linux下使用RAW SOCKET原始套接字构造UDP原始数据帧广播到局域网,在局域网的另一台计算机上显示UDP发送的信息
- 【Linux网络编程】原始套接字实例:发送 UDP 数据包
- 使用原始套接字SOCK_RAW捕捉网络数据包并简单分析
- 原始套接字的使用之编程实现DoS(拒绝服务)攻击程序
- Linux下使用原始套接字实现ping 功能
- linux实现抓包 (使用原始套接字数据连路层协议)
- Linux使用tcpdump抓取网络数据包示例
- 使用原始套接字实现数据包捕获
- 原始套接字抓取所有以太网数据包与分析
- Linux使用tcpdump抓取网络数据包示例
- Linux使用tcpdump抓取网络数据包示例
- Linux使用tcpdump抓取网络数据包示例
- linux 操作系统中显示数据包到主机的路径traceroute命令的使用
- linux使用tcpdump抓包工具抓取网络数据包
- 004.UDP--拼接UDP数据包,构造ip头和udp头通信(使用原始套接字)
- Linux使用tcpdump抓取网络数据包示例
- Linux 网络编程——原始套接字实例:发送 UDP 数据包