RADIUS 报文解析
#include <pcap.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <netinet/ether.h>
#include <netinet/if_ether.h>
#define FILE_PATH "/home/hadoop/dpi/"
typedef long datatype ;
typedef struct node
{
long key;
long value;
struct node *next;
}Renode;
char *NodeBuff;
#define BUFSIZE 1024
#define MAXDOMAINNODE 255
typedef struct domainnode
{
uint32_t key;
char value[50];
uint16_t durtime;
struct domainnode *next;
}Domainnode;
char *DomainNodeBuff;
Domainnode *MyDomainNode;
Domainnode *DomainNode[MAXDOMAINNODE];
char DOMAINBLACKBILL[100][50];
int DOMAINBLACKMAX;
enum
{
SIP_NULL = 0x00,
SIP_SPACE = 0x20,
SIP_CR = 0x0D,
SIP_LF = 0x0A,
SIP_HTAB = 0x09,
SIP_SLASH = 0x2F,
SIP_COLON = 0x3A
};
#define MAXNODE 99
Renode *ReNode[99];
struct pseudo_header{
int sourceip;
int destip;
u_int8_t mbz;
u_int8_t ptcl;
u_int16_t plen;
} pheader;
typedef struct RADIUSHeader_t
{
u_int8_t Code;
u_int8_t Identifier;
u_int16_t Length;
u_int32_t Authenticator;
u_int32_t Authenticator1;
u_int32_t Authenticator2;
u_int32_t Authenticator3;
}RADIUSHeader_t;
typedef struct Attributes_t
{
u_int8_t Type;
u_int8_t Length;
}Attributes_t;
void delay(int sec);
u_short checksum(u_short * buffer,u_short size )
{
u_long cksum = 0;
while (size > 1) {
cksum += *buffer++;
size -= sizeof(u_short);
}
if (size) {
cksum += *(u_char *) buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return (u_short) (~cksum);
}
void p900(int i )
{
free(NodeBuff);
free(DomainNodeBuff);
printf("End Program\r\n");
exit(0);
}
int main()
{
pcap_t *handle;
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program filter;
char filter_app[] = "";
bpf_u_int32 mask;
bpf_u_int32 net;
struct pcap_pkthdr header;
const u_char *packet;
signal(SIGPIPE,SIG_IGN);
signal(SIGINT,p900);
char buf_total[BUFSIZE];
unsigned char user_name[BUFSIZE];
unsigned char pass_word[BUFSIZE];
unsigned char CHAP_Password[BUFSIZE];
unsigned char NAS_IP_Address[BUFSIZE];
unsigned char NAS_Port[BUFSIZE];
unsigned char Service_Type[BUFSIZE];
unsigned char Framed_Protocol[BUFSIZE];
unsigned char Framed_IP_Address[BUFSIZE];
unsigned char Framed_IP_Netmask[BUFSIZE];
unsigned char Framed_Routing[BUFSIZE];
unsigned char Filter_Id[BUFSIZE];
unsigned char Framed_MTU[BUFSIZE];
unsigned char Framed_Compression[BUFSIZE];
unsigned char Login_IP_Host[BUFSIZE];
unsigned char Login_Service[BUFSIZE];
unsigned char Login_TCP_Port[BUFSIZE];
unsigned char Reply_Message[BUFSIZE];
unsigned char Callback_Number[BUFSIZE];
unsigned char Callback_Id[BUFSIZE];
unsigned char Framed_Route[BUFSIZE];
unsigned char Framed_IPX_Network[BUFSIZE];
unsigned char State[BUFSIZE];
unsigned char Class[BUFSIZE];
unsigned char Vendor_Specific[BUFSIZE];
unsigned char Session_Timeout[BUFSIZE];
unsigned char Idle_Timeout[BUFSIZE];
unsigned char Termination_Action[BUFSIZE];
unsigned char Called_Station_Id[BUFSIZE];
unsigned char Calling_Station_Id[BU