/** * Send a Capabilities Exchange Answer. * Checks whether there are common applications. * \note Must be called with a lock on the peer. * @param p - peer identification * @param cer - the CER message * @param result_code - the Result-Code to send * @param sock - socket to send through */ void Snd_CEA(peer *p,AAAMessage *cer,int result_code,int sock) { AAAMessage *cea; unsigned int ip; struct sockaddr_in addr; socklen_t addrlen; char x[6]; cea = AAANewMessage(Code_CE,0,0,cer); if (!cea) goto done; addrlen = sizeof(struct sockaddr_in); if (getsockname(sock,(struct sockaddr*) &addr, &addrlen) == -1) { LOG(L_ERR,"ERROR:Snd_CEA(): Error on finding local host address > %s\n",strerror(errno)); }else{ set_2bytes(x,1); ip = htonl(addr.sin_addr.s_addr); set_4bytes(x+2,ip); AAACreateAndAddAVPToMessage(cea,AVP_Host_IP_Address,AAA_AVP_FLAG_MANDATORY,0,x,6); } set_4bytes(x,config->vendor_id); AAACreateAndAddAVPToMessage(cea,AVP_Vendor_Id,AAA_AVP_FLAG_MANDATORY,0,x,4); AAACreateAndAddAVPToMessage(cea,AVP_Product_Name,AAA_AVP_FLAG_MANDATORY,0,config->product_name.s,config->product_name.len); set_4bytes(x,result_code); AAACreateAndAddAVPToMessage(cea,AVP_Result_Code,AAA_AVP_FLAG_MANDATORY,0,x,4); Snd_CE_add_applications(cea,p); peer_send(p,sock,cea,1); done: AAAFreeMessage(&cer); }
/** * Send a Capabilities Exchange Answer. * Checks whether there are common applications. * \note Must be called with a lock on the peer. * @param p - peer identification * @param cer - the CER message * @param result_code - the Result-Code to send * @param sock - socket to send through */ void Snd_CEA(peer *p,AAAMessage *cer,int result_code,int sock) { AAAMessage *cea; unsigned int ip; union { struct sockaddr addr; struct sockaddr_in in; struct sockaddr_in6 in6; } addr_u ; socklen_t addrlen; char x[18]; cea = AAANewMessage(Code_CE,0,0,cer); if (!cea) goto done; addrlen = sizeof(addr_u); if (getsockname(sock, &(addr_u.addr), &addrlen) == -1) { LM_ERR("Snd_CEA(): Error on finding local host address > %s\n",strerror(errno)); }else{ switch(addr_u.addr.sa_family){ case AF_INET: set_2bytes(x,1); ip = htonl(addr_u.in.sin_addr.s_addr); set_4bytes(x+2,ip); AAACreateAndAddAVPToMessage(cea,AVP_Host_IP_Address,AAA_AVP_FLAG_MANDATORY,0,x,6); break; case AF_INET6: set_2bytes(x,2); memcpy(x+2,addr_u.in6.sin6_addr.s6_addr,16); AAACreateAndAddAVPToMessage(cea,AVP_Host_IP_Address,AAA_AVP_FLAG_MANDATORY,0,x,18); break; default: LM_ERR("Snd_CEA(): unknown address type with family %d\n",addr_u.addr.sa_family); } } set_4bytes(x,config->vendor_id); AAACreateAndAddAVPToMessage(cea,AVP_Vendor_Id,AAA_AVP_FLAG_MANDATORY,0,x,4); AAACreateAndAddAVPToMessage(cea,AVP_Product_Name,AAA_AVP_FLAG_MANDATORY,0,config->product_name.s,config->product_name.len); set_4bytes(x,result_code); AAACreateAndAddAVPToMessage(cea,AVP_Result_Code,AAA_AVP_FLAG_MANDATORY,0,x,4); Snd_CE_add_applications(cea,p); peer_send(p,sock,cea,1); done: AAAFreeMessage(&cer); }