简体   繁体   中英

Protocol specific Socket creation and socket option information

I am trying to create a socket of sctp and then retrieve the socket options information, using sctp_opt_info().

I am successfully able to create the specific socket however on socket option retrieval I am getting the value as -1 indication some error. The error is because of invalid arguments of sctp_opt_info().

Can some one please guide me what is wrong. Why am I getting -1 for this call and not 0(success indicator)

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

I am getting the val1 value as -1 indicating some problem. The perror says invalid argument for sctp_opt_info(). My guess is argument two of this function , not sure though.

Any help will be appreciated.

Thanks

len , the last parameter to sctp_opt_info() is a value-result parameter. You have to atleast initialize it to the length of the parameter you pass in,

len = sizeof rto;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM