⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snapnet.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
字号:
/* $Id: snapnet.c,v 1.2 2003/09/17 11:26:10 tmoerlan Exp $ */#include <sys/types.h>#include <netinet/in_systm.h>#include <netinet/in.h>#include <netinet/ip.h>//#include <linux/ip.h>#include <sys/socket.h>#include "io.h"#include "packet.h"#include "snap.h"#include "d_printf.h"#define MAX_MTU 3924/*#define iphdr ip#define protocol ip_p#define ihl ip_hl*/struct iphdr  {#if __BYTE_ORDER == __LITTLE_ENDIAN    unsigned int ihl:4;    unsigned int version:4;#elif __BYTE_ORDER == __BIG_ENDIAN    unsigned int version:4;    unsigned int ihl:4;#else# error	"Please fix <bits/endian.h>"#endif    u_int8_t tos;    u_int16_t tot_len;    u_int16_t id;    u_int16_t frag_off;    u_int8_t ttl;    u_int8_t protocol;    u_int16_t check;    u_int32_t saddr;    u_int32_t daddr;    /*The options start here. */  };char pbuf[3 * MAX_MTU];int snap_recv_pkt(int sock, packet_t **p) {  struct iphdr *iph;  int len;  if ((len = recvfrom(sock, pbuf, sizeof(pbuf), 0, NULL, NULL)) < 0) {    perror("recvfrom");    *p = NULL;    return -1;  }  iph = (struct iphdr *)pbuf;	/* verify it's a SNAP packet */	if ((iph->protocol != IPPROTO_SNAP) || (iph->ihl < 6)) {		return -1;	}  *p = unmarshal_packet(pbuf, len, sizeof(pbuf));  if (*p == NULL) {    return -1;  } else {    return 0;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -