Getsockopt "Invalid argument" for IPPROTO_SCTP, SCTP_STATUS



场景:

我创建了SCTP一对多套接字(以大写字母开头的函数调用相应的标准函数,检查错误并将errno打印到stderr(

int sock_fd,msg_flags;
char readbuf[BUFFSIZE];
struct sockaddr_in servaddr, cliaddr;
struct sctp_sndrcvinfo sri;
struct sctp_event_subscribe evnts;
int stream_increment=1;
socklen_t len;
size_t rd_sz;
sock_fd = Socket( AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
bzero( &servaddr, sizeof( servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl( INADDR_ANY);
servaddr.sin_port = htons( SERV_PORT);
Bind( sock_fd, ( SA *) &servaddr, sizeof(servaddr));
bzero( &evnts, sizeof( evnts));
evnts.sctp_data_io_event = 1;
Setsockopt( sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof( evnts));
Listen( sock_fd, LISTENQ);

然后,当消息到达时,我阻塞对sctp_recvmsg的调用以读取消息

 rd_sz = Sctp_recvmsg( sock_fd, readbuf, sizeof( readbuf),
             (SA *)&cliaddr, &len, &sri,&msg_flags);

在客户端连接之后,我调用getsockopt来检索SCTP关联的当前状态

len = sizeof(struct sockaddr_in);
socklen_t retsz;
struct sctp_status status;
retsz = sizeof(status); 
bzero(&status,sizeof(status));
status.sstat_assoc_id = sctp_address_to_associd(sock_fd, (SA *)&cliaddr, len);  
getsockopt( sock_fd, IPPROTO_SCTP, SCTP_STATUS, &status, &retsz);

函数sctp_address_to_assoid为:

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);
}

为什么getsockopt返回"无效参数"?errno=22。操作系统是Linux Ubuntu 12.10。

sctp_address_to_associd()函数中的SCTP_PEER_ADDR_PARAMS套接字选项不能用于学习关联id,至少在linux上不能。

由于您已经从sctp_recvmsg((调用中获得了关联id,因此请使用struct sctp_sndrcvinfo的关联id:

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

相关内容

  • 没有找到相关文章

最新更新