0

I am trying to use socket options SCTP_PRIMARY_ADDR to make one of local address of SCTP association as primary and SCTP_SET_PEER_PRIMARY_ADDR to request SCTP server to make one of it's address as primary for SCTP future communication.

    struct sctp_setprim setPrimary;
    memset((void *)&setPrimary, 0, sizeof(struct sctp_setprim));
    setPrimary.ssp_assoc_id = 0;
    struct sockaddr_in *in_addr;
    in_addr = (struct sockaddr_in *)&setPrimary.ssp_addr;
    in_addr->sin_port = htons(localPort);
    in_addr->sin_family = AF_INET;
    in_addr->sin_addr.s_addr = localIps[0].Int32NetworkOrder();
    int rc = setsockopt(m_s, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &setPrimary, sizeof(struct sctp_setprim));**

For above snippet of code, I see socket error "Invalid argument". I don't know the reason behind this error. I have verified ip address.

Also for SCTP_SET_PEER_PRIMARY_ADDR, below code snippet is added.

    struct sctp_setpeerprim setPeerPrimary;
    memset((void *)&setPeerPrimary, 0, sizeof(struct sctp_setpeerprim));
    setPeerPrimary.sspp_assoc_id = 0;
    struct sockaddr_in *in_addr;
    in_addr = (struct sockaddr_in *)&setPeerPrimary.sspp_addr;
    in_addr->sin_port = htons(remotePort);
    in_addr->sin_family = AF_INET;
    in_addr->sin_addr.s_addr = remoteIps[0].Int32NetworkOrder();
    int rc = setsockopt(m_s, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &setPeerPrimary, sizeof(struct sctp_setpeerprim));

For this code block, I see error "Operation not permitted". And again, I'm clueless about this error reason.

Am I doing something really wrong or my sctp library isn't supporting above socket options?

Please help.

1 Answers1

0

The peer primary option must be on a specific association. I called setsockopt with the association id I received after calling connectx. Example:

sctp_assoc_t association;
int return_value = usrsctp_connectx(socket, reinterpret_cast<struct sockaddr *>(&socket_addr_in), m_number_servers, &association);

if(return_value >= 0)
{
     sctp_setprim primary;
     primary.ssp_assoc_id = association;
     std::memcpy(&(primary.ssp_addr), &(local_addr[0]), sizeof (local_addr[0]));
     int result = usrsctp_setsockopt(socket, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &primary, sizeof(primary));

...