RADIUS 报文解析

本文详细探讨了RADIUS(Remote Authentication Dial-In User Service)协议的报文结构,包括认证和授权过程中的各种报文类型。通过解析报文头部和属性,读者将能深入了解RADIUS的工作原理及其在网络身份验证中的关键角色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 <netinet/tcp.h>
//#include <netinet/udp.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;               /*zero */
    u_int8_t ptcl;              /*protocol */
    u_int16_t plen;             /*length include tcp/udp header */
} 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[] = "port 80"; /* 过滤表达式 */
	char filter_app[] = ""; /* 过滤表达式 */
	bpf_u_int32 mask; /* 所在网络的掩码 */
	bpf_u_int32 net; /* 主机的IP地址 */
	struct pcap_pkthdr header; /* 由pcap.h定义 */
	const u_char *packet; /* 实际的包 */
	/* Define the device */
	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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ghost丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值