gpt4 book ai didi

c - 协议(protocol)特定的套接字创建和套接字选项信息

转载 作者:行者123 更新时间:2023-11-30 16:03:02 25 4
gpt4 key购买 nike

我正在尝试创建 sctp 套接字,然后使用 sctp_opt_info() 检索套接字选项信息。

我成功地创建了特定的套接字,但是在套接字选项检索时,我得到的值为 -1,表明出现了一些错误。该错误是由于 sctp_opt_info() 的参数无效所致。

有人可以指导我出了什么问题吗?为什么我在这次调用中得到 -1 而不是 0(成功指示器)

int socket_desc;
struct sockaddr_in sin[1];
unsigned int len;
int val1,val2;
char s[100];

struct sctp_rtoinfo {
sctp_assoc_t srto_assoc_id;
uint32_t srto_initial;
uint32_t srto_max;
uint32_t srto_min;
}rto;


socket_desc=socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (socket_desc==-1)
printf("Socket Fail");

val1 = sctp_opt_info(socket_desc,IPPROTO_SCTP,SCTP_RTOINFO,&rto,&len);

printf("Erro : %d, \n", errno );
perror(s);
printf("Status opt info: %d\n",val1);

我得到的 val1 值为 -1,表明存在问题。 perror 表示 sctp_opt_info() 的参数无效。我的猜测是这个函数的第二个参数,但不确定。

任何帮助将不胜感激。

谢谢

最佳答案

lensctp_opt_info() 的最后一个参数是值-结果参数。您至少必须将其初始化为您传入的参数的长度,

len = sizeof rto;

关于c - 协议(protocol)特定的套接字创建和套接字选项信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4502411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com