资源简介
sflowtool是一个sflow流量数据收集工具
代码片段和文件信息
/* Copyright (c) 2002-2011 InMon Corp. Licensed under the terms of the InMon sFlow licence: */
/* http://www.inmon.com/technology/sflowlicense.txt */
#if defined(__cplusplus)
extern “C“ {
#endif
#ifdef WIN32
#include “config_windows.h“
#else
#include “config.h“
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef WIN32
#else
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#endif
#include “sflow.h“ /* sFlow v5 */
#include “sflowtool.h“ /* sFlow v2/4 */
/* If the platform is Linux enable the source-spoofing feature too. */
#ifdef linux
#define SPOOFSOURCE 1
#endif
/*
#ifdef DARWIN
#include
#define bswap_16(x) NXSwapShort(x)
#define bswap_32(x) NXSwapInt(x)
#else
#include
#endif
*/
/* just do it in a portable way... */
static uint32_t MyByteSwap32(uint32_t n) {
return (((n & 0x000000FF)<<24) +
((n & 0x0000FF00)<<8) +
((n & 0x00FF0000)>>8) +
((n & 0xFF000000)>>24));
}
static uint16_t MyByteSwap16(uint16_t n) {
return ((n >> 8) | (n << 8));
}
#ifndef PRIu64
# ifdef WIN32
# define PRIu64 “I64u“
# else
# define PRIu64 “llu“
# endif
#endif
#define YES 1
#define NO 0
/* define my own IP header struct - to ease portability */
struct myiphdr
{
uint8_t version_and_headerLen;
uint8_t tos;
uint16_t tot_len;
uint16_t id;
uint16_t frag_off;
uint8_t ttl;
uint8_t protocol;
uint16_t check;
uint32_t saddr;
uint32_t daddr;
};
/* ip6 header if no option headers */
struct myip6hdr {
uint8_t version_and_priority;
uint8_t label1;
uint8_t label2;
uint8_t label3;
uint16_t payloadLength;
uint8_t nextHeader;
uint8_t ttl;
struct in6_addr saddr;
struct in6_addr daddr;
};
/* same for tcp */
struct mytcphdr
{
uint16_t th_sport; /* source port */
uint16_t th_dport; /* destination port */
uint32_t th_seq; /* sequence number */
uint32_t th_ack; /* acknowledgement number */
uint8_t th_off_and_unused;
uint8_t th_flags;
uint16_t th_win; /* window */
uint16_t th_sum; /* checksum */
uint16_t th_urp; /* urgent pointer */
};
/* and UDP */
struct myudphdr {
uint16_t uh_sport; /* source port */
uint16_t uh_dport; /* destination port */
uint16_t uh_ulen; /* udp length */
uint16_t uh_sum; /* udp checksum */
};
/* and ICMP */
struct myicmphdr
{
uint8_t type; /* message type */
uint8_t code; /* type sub-code */
/* ignore the rest */
};
#ifdef SPOOFSOURCE
#define SPOOFSOURCE_SENDPACKET_SIZE 2000
struct mySendPacket {
struct myiphdr ip;
struct myudphdr udp;
uint8_t data[SPOOFSOURCE_SENDPACKET_SIZE];
};
#endif
- 上一篇:CAN总线协议英文版
- 下一篇:whereisIP破解版
评论
共有 条评论