#include "local.h"
#include <pthread.h>
#include "util.h"
#include "debug.h"
#define BDBG dbg
/*
void *
func(void *arg){
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("pid is %u\n",(unsigned int)pid);
printf("thread id is %u\n",(unsigned int)tid);
struct mip6_args *rad_args;
rad_args = (struct mip6_args *)arg;
printf("----msg buff in args is %s\n", rad_args->buff);
return((void *)0);
}
*/
main(void)
{
//about new pthread
// pthread_t radius_thread;
// pthread_attr_t attrs;
// struct mip6_args rad_thread_args;
// int err;
//rad_thread_args.argv[1]="Password = test";
// rad_thread_args.argv[0]="User-Name = test";
int mid,n;
key_t key;
MESSAGE msg;
//thread
// pthread_attr_init(&attrs);
//pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
//Use the Same key with Client
if((key = ftok(".", SEED)) == -1){
perror("Client : key generation");
exit(1);
}
// mid = msgget(key, IPC_CREAT | 0660);
printf("server mid is %d\n", mid);
while(1){
if((n = msgrcv(65538, &msg, sizeof(msg), SERVER,0)) == -1){
perror("SERVER:msgrcv");
exit(2);
}
else if (n==0)//client have finished
break;
else{
printf("msg type is %d\n", msg.acct_msg.acct_type);
BDBG("msg hoa is= %x:%x:%x:%x:%x:%x:%x:%x\n", NIP6ADDR(&msg.acct_msg.hoa));
BDBG("msg coa is= %x:%x:%x:%x:%x:%x:%x:%x\n", NIP6ADDR(&msg.acct_msg.coa));
//child process to communication to the radius server;
if(fork() == 0){
argv[1] = "-f";
argv[2] = "/home/chl/radtest/test.conf";
argv[3] = "[3ffe:3240:8007:602::1]:1813";
argv[4] = "acct";
argv[5] = "testing123";
execlp("/home/radclient","radclient",argv[1],argv[2],argv[3],argv[4],argv[5]);
}
//parent process nothing to do
else
;
// rad_thread_args.buff = msg.buffer;
//when recv msg from HA, should send acct to server
// err = pthread_create(&radius_thread, &attrs, func,&rad_thread_args);
// if(err != 0){
// perror("thread create:");
// exit(6);
// }
/*
printf("----about main is------\n");
printf("main processid is %d\n",getpid());
printf("main threadid is %d\n",pthread_self());
*/
}
}
msgctl(mid, IPC_RMID, (struct msqid_ds *)0);
exit(0);
}