top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

TCP is working. But SCTP is not working.

+3 votes
930 views

To establish a connection b/w to systems TCP handshake is happeing successfully, BUT SCTP handshake is not happening could any help me to solve this problem.

posted Jul 5, 2016 by Manohar Venkat.ch

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
Please share the configuration detail and till what stage the handshake is happening. (ECHO, ECHO RESPONSE, COOKIE, COOKIE RESP)...
In both client and server I am running wireshark, I am able to see INIT packet sent by Client but not able to see INIT-ACK form server.

One more thing client and server both are in different series of IP's . I am able to have TCP session,ping all are working.
From the description I can guess the configuration is not correct, you may need to share necessary information...
how can I attach logs?
Just edit the question and put the information whatever you want :)
server and client socket is created using following command.
sockfd = socket(AF_INET, SOCK_STREAM,IPPROTO_SCTP)

client connect is like follows
 connect(sockfd, (sockaddr *)&srv_addr, sizeof(sockaddr));
Following is my server code :
#include <stdio.h>                                                              
#include <stdlib.h>                                                             
#include <sys/socket.h>                                                         
#include <sys/types.h>                                                          
#include <netinet/in.h>                                                         
#include <netinet/sctp.h>                                                       
#include <arpa/inet.h>                                                          
#include <strings.h>                                                            
#include <string.h>                                                             
                                                                                
                                                                                
#define MAX_BUFF    1024                                                        
#define PORT        8666                                                        
                                                                                
int main(void)                                                                  
{                                                                               
                                                                                
    int server_fd, client_fd, length, index;                                    
    struct sockaddr_in saddr, caddr;                                            
    struct sctp_initmsg initmsg;                                                
    struct sctp_sndrcvinfo sndrecvinfo;                                         
    char buff[INET_ADDRSTRLEN];                                                 
    uint32_t flags = 0;                                                         
    char buffer[MAX_BUFF + 1] = "## HEY ARASH ##";                              
                                                                                
    /**************** create socket (end point connections) ******************/
    server_fd = socket (AF_INET, SOCK_STREAM, IPPROTO_SCTP);                    
                                                                                
    bzero((void *)&saddr, sizeof(saddr));                                       
                                                                                
                                                                                
    saddr.sin_family = AF_INET;                                                 
    saddr.sin_port = htons( PORT );                                             
    saddr.sin_addr.s_addr = htonl( INADDR_ANY );                                
    sndrecvinfo.sinfo_ppid = 18;                                                
    bind(server_fd, (struct sockaddr *) &saddr, sizeof(saddr));     
 memset(&initmsg, 0, sizeof(initmsg));                                       
                                                                                
    initmsg.sinit_num_ostreams = 3;                                             
    initmsg.sinit_max_instreams = 3;                                            
    initmsg.sinit_max_attempts = 2;                                             
                                                                                
                                                                                
    setsockopt(server_fd, IPPROTO_SCTP, SCTP_INITMSG,                           
            &initmsg, sizeof(initmsg));                                         
                                                                                
    listen(server_fd, 5);                                                       
                                                                                
    while(1) {                                                                  
                                                                                
                                                                                
        printf("SERVER RUNNING...\n");                                          
                                                                                
        length = sizeof(caddr);                                                 
        client_fd = accept(server_fd, (struct sockaddr *)& caddr, &length);     
                                                                                
        printf("CONNECTED TO : %s\n", inet_ntop(AF_INET, &caddr.sin_addr.s_addr,
                    buff, sizeof(buff)));                                       
                                                                                
        for (index = 0; index <= 3; index++) {                                  
            buffer[16] = '1' + index;                                           
                                                                                
            if(sctp_send(client_fd, (void *) buffer, sizeof(buffer),            
                    &sndrecvinfo,flags)== -1){                                  
            }                                                                   
           printf("sent %s\n",buffer);                                         
        }                                                                       
      }
    return 0;                                                                   
}  


Following is client code :-

#include <stdio.h>                                                              
#include <stdlib.h>                                                             
#include <sys/socket.h>                                                         
#include <sys/types.h>                                                          
#include <netinet/in.h>                                                         
#include <netinet/sctp.h>                                                       
#include <arpa/inet.h>                                                          
#include <strings.h>                                                            
#include <string.h>                                                             
                                                                                
                                                                                
                                                                                
#define MAX_BUFF    1024                                                        
#define PORT        8666                                                        
                                                                                
int main(int argc, char **argv)                                                 
{                                                                               
        int client_fd, length, flags;                                           
        char buffer[MAX_BUFF + 1] = {0};                                        
        struct sockaddr_in c_addr;                                              
        struct sctp_sndrcvinfo sndrecvinfo;                                     
                                                                                
        struct sctp_event_subscribe events;                                     
        struct sctp_initmsg initmsg;                                            
                                                                                
        if (argc != 2) {                                                        
            printf("USAGE : ./CLIENT <SERVER_ADDR>\n");                         
            exit(-1);                                                           
        }                                                                       
                                                                                
        client_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);                 
                                                                                
        memset(&initmsg, 0, sizeof(initmsg));                                   
                                                                                
        initmsg.sinit_num_ostreams = 3;
initmsg.sinit_max_instreams = 3;                                        
        initmsg.sinit_max_attempts = 2;                                         
                                                                                
        setsockopt(client_fd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof(initmsg));
                                                                                
        bzero((void *)&c_addr, sizeof(c_addr));                                 
        c_addr.sin_family = AF_INET;                                            
        c_addr.sin_port = htons( PORT );                                        
        //      c_addr.sin_addr.s_addr = htonl( argv[1] );                      
        inet_pton(AF_INET, argv[1], &c_addr.sin_addr);                          
                                                                                
    //  connect (client_fd, (const struct sockaddr *) &c_addr, sizeof(c_addr));
                                                                                
                                                                                
        memset(&events, 0, sizeof(events));                                     
                                                                                
        events.sctp_data_io_event = 1;                                          
                                                                                
        setsockopt(client_fd, SOL_SCTP, SCTP_EVENTS, (const void *)&events,     
                sizeof(events));                                                
                                                                                
        while(1) {                                                              
                                                                                
            bzero((void *)&buffer, sizeof(buffer));                             
                                                                                
            if(sctp_recvmsg(client_fd, (void *) buffer, sizeof(buffer), (struct sockaddr *)
                    NULL, 0 ,&sndrecvinfo, &flags) <= 0 ){                      
                printf("\nexit \n");                                            
                exit(0);                                                        
            }                                                                   
            printf("recvd_data %s on stream %d\n", buffer, sndrecvinfo.sinfo_stream);
                                                                                
        }                                                                       
                                                                                
        close(client_fd);                                                       
        return 0;   }
Client IP : 172.16.20.3
Server IP : 172.16.7.139
client INIT should go via router  configured with 20 series.
Both UDP and TCP is working fine but not sctp.
please help regarding this..!!
Its very difficult to review the code offline and please try to follow the following steps -
1. Run wireshark on both ends and see if INIT reached on other end or not.
2. Once INIT is received at opposite end we are sure that it is not a network issue.

Once we identified its not a network issue we can refer the following code http://www.cs.odu.edu/~cs779/spring04/lectures/sctp.html may be you need to play with SERV_PORT and IP_ADDRESS.

Once you are able to run this code task is simple just modify as per your need.

Similar Questions
+3 votes

I want to know TCP is very useful protocol for connection establishment. In LTE why we use SCTP, not TCP.
Can anybody explain why it is so?

+2 votes

What reasoning could be behind not using the TCP/SCTP for GTPv2 protocol ?

...