getsockopt “Invalid argument” for IPPROTO_SCTP, SCTP_STATUS

         目前在学习SCTP协议,下载了Unix Networking Programming(The socokets Networking API)相关的源代码,在运行sctp目录下sctpserver01和sctpclient01的时候,server会出现如错,我的系统是Fedora20。

          [root@dell sctp]# uname -a
           Linux dell 3.11.10-301.fc20.x86_64 #1 SMP Thu Dec 5 14:01:17 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
         
          出现的错误如下:

          getsockopt error: Invalid argument

          上面的错误是因为下面的函数调用了Getsockopt造成的

          int
          sctp_get_no_strms(int sock_fd,struct sockaddr *to, socklen_t tolen)
          {
               int retsz;
               struct sctp_status status;
               retsz = sizeof(status);
               bzero(&status,sizeof(status));

               status.sstat_assoc_id = sctp_address_to_associd(sock_fd, to, tolen);
               Getsockopt(sock_fd,IPPROTO_SCTP, SCTP_STATUS,
                       &status, &retsz);
               return(status.sstat_outstrms);
         }

         函数sctp_address_to_associd的定义如下:      

    sctp_assoc_t
    sctp_address_to_associd(int sock_fd, struct sockaddr *sa, socklen_t salen)
    {
        struct sctp_paddrparams sp;
        socklen_t siz;

        siz = sizeof(struct sctp_paddrparams);
        bzero(&sp,siz);
        memcpy(&sp.spp_address,sa,salen);
        sctp_opt_info(sock_fd,0,
               SCTP_PEER_ADDR_PARAMS, &sp, &siz);
        return(sp.spp_assoc_id);
    }
    在stackeoverflow上查到了解决方法,把在调用sctp_get_no_strms之前sri的sinfo_assoc_id赋值给status.sstat_assoc_id。
    原因stackoverlow解释如下:
    The SCTP_PEER_ADDR_PARAMS socket option in the sctp_address_to_associd() function cannot be used to learn the association id, at least not on linux.

Since you already get the association id from the sctp_recvmsg() call, use the association id of the struct sctp_sndrcvinfo instead:

status.sstat_assoc_id = sri.sinfo_assoc_id;
getsockopt( sock_fd, IPPROTO_SCTP, SCTP_STATUS, &status, &retsz);

    更多详情请参考http://stackoverflow.com/questions/23897781/getsockopt-invalid-argument-for-ipproto-sctp-sctp-status






你可能感兴趣的:(编程语言)