SCTP Discussions

Text archives Help


[SCTP-Discussion] getsockopt() returning invalid argument


Chronological Thread 
  • From: john.fitzpatrick4 AT mail.dcu.ie
  • To: discussion AT sctp.de
  • Subject: [SCTP-Discussion] getsockopt() returning invalid argument
  • Date: Wed, 5 Dec 2007 12:29:15 +0000
  • List-archive: <http://lists.franken.de/pipermail/sctp-discussion>
  • List-id: SCTP Discussions <sctp-discussion.sctp.de>

Hi all,

I am writing an application using LK-SCTP and the one-to-many style
sockets using SOCK_SEQPACKET. The problem I am having is when I am
calling getsockopt() it returns with an error saying invalid argument. I
have used the same call with the same parameters while using SOCK_STREAM
with no problems. The function call is -
getsockopt(sd, IPPROTO_SCTP, SCTP_STATUS, &addrinfo, &lenaddr)

Specifically I am going to use the getsockopt function to obtain an srtt
value, is this possible while using UPD style one-to-many sockets.

I have included sample code for both a Client/Server so that you can
recreate the problem to show the problem I am having, any help is
greatly appreciated.

Kind Regards,
John Fitzpatrick

//Client Start **************************************************
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/sctp.h>
#include <sys/uio.h>

int main(int argc, char **argv)
{
//Define Variables
int sd, port;
struct sockaddr_in sin;
struct sctp_event_subscribe event;

//Check Usage
if(argc != 3){
printf("\nUsage: <Server> <port>\n");
return -1;
}

//Create Socket
sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if(sd < 0){
perror("Socket");
exit(1);
}

sin.sin_family = PF_INET;
port = atoi(argv[2]);
sin.sin_port = htons(port);
sin.sin_addr.s_addr = inet_addr(argv[1]);

//Set Socket Options
/* Enable all events */
event.sctp_data_io_event = 1;
event.sctp_association_event = 1;
event.sctp_address_event = 1;
event.sctp_send_failure_event = 1;
event.sctp_peer_error_event = 1;
event.sctp_shutdown_event = 1;
event.sctp_partial_delivery_event = 1;
event.sctp_adaption_layer_event = 1;

if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(event)) !=
0) {
perror("setevent failed");
exit(1);
}

//Connect
if(connect(sd, (struct sockaddr *) &sin, sizeof(sin)) < 0){
perror("Connect");
exit(1);
}

struct sctp_status addrinfo;
int lenaddr = sizeof(addrinfo);
int send_packet = 1;
int sz;
while(1){
sz = sctp_sendmsg(sd, (int *) &send_packet, sizeof(int),
(struct
sockaddr *) &sin, sizeof(struct sockaddr_in), 0, 0, 0, 100, 0);
send_packet++;

if(getsockopt(sd, IPPROTO_SCTP, SCTP_STATUS, &addrinfo,
&lenaddr) < 0){
perror("getsockopt");
}
}
}
//Client End **************************************************

//Server Start ************************************************
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/sctp.h>
#include <sys/uio.h>

int main(int argc, char **argv)
{
//Define Variables
int sd, bound, port;
struct sockaddr_in cli_addr, sin;
struct sctp_event_subscribe event;

//Check Usage
if(argc != 3){
printf("\nUsage: <Server> <port>\n");
return -1;
}

//Create Socket
sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if(sd < 0){
perror("Socket");
exit(1);
}

sin.sin_family = PF_INET;
port = atoi(argv[2]);
sin.sin_port = htons(port);
sin.sin_addr.s_addr = inet_addr(argv[1]);

//Bind
bound = bind(sd, (struct sockaddr *) &sin, sizeof(sin));
printf("Bound = %d\n", bound);
if(bound < 0){
perror("Bind");
exit(1);
}

//Set Socket Options
/* Enable all events */
event.sctp_data_io_event = 1;
event.sctp_association_event = 1;
event.sctp_address_event = 1;
event.sctp_send_failure_event = 1;
event.sctp_peer_error_event = 1;
event.sctp_shutdown_event = 1;
event.sctp_partial_delivery_event = 1;
event.sctp_adaption_layer_event = 1;

if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(event)) !=
0) {
perror("setevent failed");
exit(1);
}

/* Listen to socket */
if(listen(sd, 4) < 0){
perror("Listen");
}

//Receive Message
int recv;
int recv_packet;
int lenaddress = sizeof(struct sockaddr_in);
while(1){
if(sctp_recvmsg(sd, (int*)&recv_packet,
sizeof(recv_packet),
&cli_addr, &lenaddress, NULL, 0) < 0)
perror("sctp_recvmsg");
printf("Recv: %d\n", recv_packet);
}
}
//Server End ************************************************






Archive powered by MHonArc 2.6.19+.

Top of page