Thanks Orestes Leal RodrÃguez & Alan dekok for your help. Now I m able to receive a packet and respond back successfully. But now i want to read attribute value pairs from CoA and DM-request. What I know is whatever attribute that we get needs to be converted to VALUE_PAIR and then with attribute name we can read it. I want to know that what api's can be used to convert attribute to VALUE_PAIR and then read it. I have pasted my code. while(1) { max_fd = fd + 1; fd_set rdset; FD_ZERO(&rdset); FD_SET(fd, &rdset); retval = select(max_fd, &rdset, NULL, NULL, &tv); if (retval == -1) perror("select()"); else if (retval){ syslog(LOG_INFO,"Radius:: Data is available now.\n"); if(FD_ISSET(fd, &rdset)) { RADIUS_PACKET *packet = rad_recv(fd, 0); char src_addr[INET_ADDRSTRLEN + 1] = {'\0'}; char dst_addr[INET_ADDRSTRLEN + 1] = {'\0'}; int sport = 0; int dport = 0; inet_ntop(AF_INET, &packet->src_ipaddr.ipaddr, src_addr, INET_ADDRSTRLEN); syslog(LOG_INFO,"Radius:: src_addr : %s\n", src_addr); inet_ntop(AF_INET,&packet->dst_ipaddr.ipaddr, dst_addr, INET_ADDRSTRLEN); syslog(LOG_INFO,"Radius:: dst_addr : %s\n", dst_addr); syslog(LOG_INFO,"Radius:: src_port : %d\n", packet->src_port); syslog(LOG_INFO,"Radius:: dst_port : %d\n", packet->dst_port); sport = packet->src_port; dport = packet->dst_port; syslog(LOG_INFO,"Radius:: id: %d\n", packet->id); syslog(LOG_INFO,"Radius:: code: %d\n", packet->code); syslog(LOG_INFO,"Radius:: hash: %d\n", packet->hash); int i = 0; for(i = 0; i < AUTH_VECTOR_LEN; i++) syslog(LOG_INFO,"Radius:: vector: 0x%x\n ", packet->vector[i]); hdr = (radius_packet_t *)packet->data; ptr = hdr->data; packet_length = packet->data_len - AUTH_HDR_LEN; if(rad_verify(packet,NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_verify failed : %s \n", fr_strerror()); } else syslog(LOG_INFO,"Radius:: Rad_verify successful\n"); if(rad_decode(packet,NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_decode failed : %s\n", fr_strerror()); } else syslog(LOG_INFO,"Radius:: rad_decode successful \n"); RADIUS_PACKET *reply = rad_alloc_reply(packet); switch(packet->code) { case PW_DISCONNECT_REQUEST: syslog(LOG_INFO,"Radius:: PW_DISCONNECT_REQUEST "); syslog(LOG_INFO,"Radius:: Loggedin session user ::%s ", radiususerSessionInfo.userName); if(strstr(radiususerSessionInfo.userName,"arv")) { syslog(LOG_INFO,"Radius:: Returning 1 to django"); flag_logout = 1; kill(getpid(),SIGUSR1); reply->code = htonl(41); } else reply->code = htonl(40); memset(&radiususerSessionInfo,0,sizeof(radiususerSessionInfo)); break; case PW_COA_REQUEST: syslog(LOG_INFO,"Radius:: PW_COA_REQUEST "); break; default: syslog(LOG_INFO,"Radius:: Request recieved is other them COA and DM"); } if(rad_send(reply, NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_send failed : %s", fr_strerror()); } else syslog(LOG_INFO,"Radius:: Rad_send successful"); } else syslog(LOG_INFO,"Radius:: FD_ISSET Failed"); } } } Regards, Arvind Chauhan On Sun, Oct 6, 2019 at 10:24 PM Orestes Leal RodrÃguez < olealrd1981@gmail.com> wrote:
Arvind,
You have this code:
reply = fr_packet_list_recv(pl, &rdset); if (!reply) { printf( "radclient: received bad packet: %s\n",strerror(errno)); return -1; /* bad packet */ }
Two things about it:
On the freeradius library: packet.c:908 (fr_packet_list_recv) there are two possible reasons that the function will return NULL (your case).
1. pl OR rdset == NULL (packet.c: if (!pl || !set) return NULL;)
2. This doesn't hold (from packet.c):
start = pl->last_recv; do ... } while (start != pl->last_recv);
I would say that you have an issue with pl or rdset or pl->last_recv is different than what freeradius expect.
NOTES:
I would actually suggest replacing:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize))<0)
by this:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize)) == -1)
From bind(2) (POSIX.1)
RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
Orestes - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html