Search code examples
csocketsdhcpradius-protocol

radius request gives wrong values


if (rc_avpair_add(rh, &send, PW_USER_PASSWORD, passwd, -1, 0) == NULL)
                return ERROR_RC;

        if (rc_avpair_add(rh, &send, PW_NAS_PORT_TYPE, nas_port_type, -1, 0) == NULL)
                return ERROR_RC;

        if (rc_avpair_add(rh, &send, PW_FRAMED_IP_ADDRESS,"172.17.14.90", -1, 0) == NULL)
                return ERROR_RC;

above is my part of code "radexample.c Which used for generating a " radius request" I want to pass Framed IP with it also. my issue is here PW_USER_PASSWORD sends the correct value as it is a "string" type. but PW_FRAMED_IP_ADDRESS sends wrong value as its type is "ip" and I am sending string value.. If I pass "ip" in forth arg. rc_avpair_add gives error of type conversion !!


Solution

  • PW_FRAMED_IP_ADDRESS wants an int for the fourth argument.

    The easiest method is:

    uint32_t framed_addr = 0;
    inet_pton(AF_INET, "172.17.14.90", &framed_addr);
    framed_addr = htonl(framed_addr); //network order
    if (rc_avpair_add(rh, &send, PW_FRAMED_IP_ADDRESS,&framed_addr, -1, 0) == NULL)
                return ERROR_RC;