/*
 * spoofedRadLast.c
 *
 *  Created on: May 30, 2013
 *      Author: sharondvir
 *      license: do whatever you want.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct radutmp {
	char login[32];		/* Loginname */
	/* FIXME: extend to 48 or 64 bytes */
	unsigned int nas_port;	/* Port on the terminal server (32 bits). */
	char session_id[8];		/* Radius session ID (first 8 bytes at least)*/
	/* FIXME: extend to 16 or 32 bytes */
	unsigned int nas_address;	/* IP of portmaster. */
	unsigned int framed_address;	/* SLIP/PPP address or login-host. */
	int proto;			/* Protocol. */
	time_t time;			/* Time entry was last updated. */
	time_t delay;			/* Delay time of request */
	int type;			/* Type of entry (login/logout) */
	char porttype;		/* Porttype (I=ISDN A=Async T=Async-ISDN */
	char res1,res2,res3;		/* Fills up to one int */
	char caller_id[16];		/* Calling-Station-ID */
	char reserved[12];		/* 3 ints reserved */
};

int main()
{
	struct radutmp st;
	char path[]="/var/log/radutmp";
	FILE *fp = fopen(path, "rb");
	if (fp==NULL)
	{
		printf("cant open %s\n",path);
		return -1;
	}
	while(fread(&st,sizeof(struct radutmp),1,fp)==1)
	{
		printf("%s %s %u %u ",st.login,st.type==0?"connect":"disconnect",st.nas_address,st.nas_port);
		int i=0;
		for (i=0;i<sizeof(st.session_id);i++)
		{
			printf("%c",st.session_id[i]);
		}
		printf(" %s",ctime(&st.time));
	}
	printf("reminder - output format is:\nlogin connect/disconnect nas_addr nas_port session_id time\n");
	return 0;
}



