SCTP Discussions

Text archives Help


[SCTP-Discussion] sendmsg() !!!!


Chronological Thread 
  • From: "Sumathi.Elangovan" <Sumathi.Elangovan AT uk.thalesgroup.com>
  • To: discussion AT sctp.de
  • Subject: [SCTP-Discussion] sendmsg() !!!!
  • Date: Thu Nov 14 18:57:01 2002
  • List-id: SCTP Discussions <discussion.sctp.de>

Hi!
This is part of the program for the server-client association and data
transfer for my application in 'C'. At first I use read() and write() for
sending a set buffer of 1024 from the client to the server...but inorder to
see whether the complete data has reached .....I need something lkke "EOR"
flag to be set. Read() and write() doesnt enable to set flags. Is that right?
So I thought i will use sendmsg() and recvmsg() instead of read() amd
write(). When I execute the below program....the association sets up fine but
after the client connects...there seems to be a problem...in the sendmsg()
where "segmentation fault occurs"...is it due to "msg" declared within the
sendmsg()? Why does this error occur? Is my declaration of sendmsg wrong?
Your help is much appreciated. Accept my apologies in sending the whole
program....just thought it will explain you better in analysing where I am
going wrong. Thank you.

#include.........
#define.............
extern int gnu_getopt_long( int argc,char *const *argv,const char
*options,const struct option *long_options,int *opt_index );
struct msghdr msg[1];
int recvMsgSize ;
char echoBuffer[RCVMSGSIZE];
/* SERVER */
void SctpServer()
{
int servSock,clntSock; /* socket descriptors for both server and
client */
int n;
struct sockaddr_in echoServAddr; /* local address */
struct sockaddr_in echoClntAddr; /* client address */
char buffer[BUFFER_SIZE];
unsigned int clntLen;

/* create socket for incoming connections */
printf("Creating server socket......");
/* the socket defined with the parameters AF_INET which indicates that
* the type of socket is an IPv4 socket and the next two arguments
specify the use of sctp */
if((servSock = ext_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0)
{
printf("socket() failed");
exit(1);
}
printf ("ext_socket()......created.\n\n");

memset(&echoServAddr, 0 , sizeof(echoServAddr));
/* Internet address family */
echoServAddr.sin_family = AF_INET;
/* any incoming interface */
echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
/* local port - can specify the port say 7 - echo */
echoServAddr.sin_port = htons(7);

/* bind to the local address */
printf("Binding address.......");
if(ext_bind(servSock, (struct sockaddr *) &echoServAddr,
sizeof(echoServAddr)) < 0)
{
printf("bind() failed");
exit(1);
}
printf( " ext_bind()........bounded .\n\n");

/* mark the socket it will listen to the incoming connection */
printf("Waiting for incoming connection.........");
if(ext_listen(servSock, MAXPENDING) < 0)
{
printf("listen() failed");
exit(1);
}
printf( "ext_listen() .....listening........\n\n");

clntLen = sizeof(echoClntAddr);
if((clntSock = ext_accept(servSock, (struct sockaddr *)
&echoClntAddr, &clntLen )) < 0)
{
printf("accept() failed");
exit(1);
}
printf("ext_accept().....connected.\n\n");
printf("Handling client %s\n\n", inet_ntoa(echoClntAddr.sin_addr));

printf("reading buffer.\n\n");
recvMsgSize = ext_recvmsg(clntSock,msg,0);
if(recvMsgSize < 0)
{
printf("recvmsg() failed");
} else if(recvMsgSize == 0)
{
puts( "Connection shut down by client");
//break;
} else {
echoBuffer[recvMsgSize] = '\0';
printf("%s",echoBuffer);
}

//printf("\n\nClosing connection.....");
//ext_close(clntSock);
//printf("Connection closed....\n\n");

}

/* CLIENT */

void SctpClient()
{
int clntSock,n,count;
struct sockaddr_in echoClntAddr;
struct sockaddr_in remote_addr;
char buffer[BUFFER_SIZE]; /* physical block size on a peripheral
device where the buffer size is 1024 */
memset(msg,0,sizeof(*msg));
printf("Creating client socket............");
/* int ext_socket(int domain, int type, int protocol) */
if ((clntSock = ext_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0)
{
printf("socket() failed");
exit(1);
}
printf("ext_socket()........ created.\n\n");

echoClntAddr.sin_family = AF_INET;
echoClntAddr.sin_addr.s_addr = INADDR_ANY;
echoClntAddr.sin_port = htons(7);


printf("remote address...127.0.0.1.....");
bzero(&remote_addr, sizeof(remote_addr));
/* remote_addr.sin_len = sizeof(remote_addr) */
remote_addr.sin_family = AF_INET;
if(inet_aton("127.0.0.1", &remote_addr.sin_addr) != 1)
{
printf("Inet_aton failed.\n\n");
exit(1);
}
remote_addr.sin_port = htons(7);

/* int ext_connect(int sockfd, const struct sockaddr*
serv_addr,socklen_t addrlen) */
if(ext_connect(clntSock, (const struct sockaddr *) &remote_addr,
sizeof(remote_addr)) < 0)
{
printf("connect() failed");
exit(1);
}
printf("ext_connect()...\n\n");

printf("writing buffer..\n\n");

if(count = ext_sendmsg( clntSock,msg, 0) < 0)
{
printf("send() failed");
}
printf("count = %d\n",clntSock,count);

/*if(ext_close(clntSock) < 0)
{
printf("ext_close failed");
exit(1);
}
printf("ext_close by Client called..\n\n"); */

}


Regards
Sumathi Elangovan

Sumathi Elangovan
Design Engineer
Thales Research Limited
Reading
Tel: 0118 923 8272
Email :
Sumathi.Elangovan AT uk.thalesgroup.com




**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed and may
not be divulged to any third party without the express permission of
the originator. Any views expressed in this message are those of the
individual sender, except where the sender specifically states them to
be the views of Thales Research & Technology (UK) Ltd.
**********************************************************************




Archive powered by MHonArc 2.6.19+.

Top of page