This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SO_RCVTIMEO returns ENOPROTOOPT Error Using NCS 1.5

Hi, 

    I was trying to set a receive timeout on a socket, however when I use setsockopt function, it returns ENOPROTOOPT error. Please see below the snippet of my code. I am developing an application over nRF52840  DK, and I am using nRF Connect with ncs version 1..5. I would really appreciate your help in this regard. 

Best regards,

Omer

bool init_app()
{
       bool ret = true ; 
       
       recv_timeout.tv_sec = RECEIVE_TIMEOUT_IN_SECONDS ; 
       recv_timeout.tv_usec = 0 ; 
       memset(&tx_addr, 0, sizeof(tx_addr)) ;  
       tx_addr.sin6_family = AF_INET6 ; 
       tx_addr.sin6_port = htons(TRANSMITTER_PORT) ; 
       inet_pton(AF_INET6, CONFIG_NET_CONFIG_MY_IPV6_ADDR, &(tx_addr.sin6_addr)) ; 
       tx_sock_id = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP) ; 
       if(tx_sock_id == SOCKET_ERROR_CODE)
       {
                printk("Error in creating socket for communication \n") ; 
                ret = false ; 
       }

       if(setsockopt(tx_sock_id, SOL_SOCKET, SO_RCVTIMEO, (const char *) &recv_timeout, sizeof(recv_timeout)) < 0)
       {
              printk("Error in setting socket option \n") ; 
              switch(errno)
              {
                      case EBADF:
                              printk("sock id is not a valid socket descriptor \n") ; 
                              break ; 
                      case EFAULT:
                              printk("Not a valid address is optval \n") ; 
                              break ; 
                      case EINVAL:
                              printk("oplen invalid \n") ; 
                              break ; 
                      case ENOPROTOOPT:
                              printk("Unknown option \n") ; 
                              break ; 
                      case ENOTSOCK:
                              printk("File not a socket \n") ; 
                              break ; 
                      default:
                              printk("Failure reason is unknown \n") ;  
              }
              ret = false ; 
       }
}

Related