csocketsunixnetwork-programmingsctp

How to close only one connection in SCTP one-to-many style c programming


C programming I have been able to create One-To-many style of SCTP connection, using

clientsockfd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

Able to send connect and send message to multiple servers using same single socket(binded to single local ip and port)

while sending message I am using destination ip:port in each message,

int res = sctp_sendmsg(clientsockfd, message, strlen(message), (struct sockaddr*)&server_addr1, sizeof(server_addr1), 0, SCTP_ADDR_OVER, 0, 0, 0);
   

Now I want to close only one connection out of these two, I checked the sctp manual/api reference doc. It suggests to use, SCTP_EOF or SCTP_ABORT flag with specific connection/association id, I tried many combinations, but it caused both connections to ABORT. Any suggestions?

    sctp_sendmsg(clientsockfd, NULL, 0,NULL, 0, 0, SCTP_ABORT,asso_id,0,0);

and

sctp_sendmsg(clientsockfd, NULL, 0,(struct sockaddr*)&server_addr1, 0, 0, SCTP_ABORT,(uint16_t)sp.spinfo_assoc_id,0,0);

I read this message being deprecated.

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0


Solution

  • The mistake was, I was not passing length of server_addr1, as 5th parameter in sctp_send() call

    sctp_sendmsg(clientsockfd, NULL, 0,(struct sockaddr*)&server_addr1, 0, 0, SCTP_ABORT,(uint16_t)sp.spinfo_assoc_id,0,0);
    

    Working api call

    sctp_sendmsg(clientsockfd, NULL, 0,(struct sockaddr*)&server_addr1,sizeof(server_addr1) , 0, SCTP_ABORT,(uint16_t)sp.spinfo_assoc_id,0,0);
      
    

    And

    sctp_sendmsg(clientsockfd, NULL, 0,(struct sockaddr*)&server_addr1,sizeof(server_addr1) , 0, SCTP_EOF,(uint16_t)sp.spinfo_assoc_id,0,0);