SCTP Discussions

Text archives Help


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


Chronological Thread 
  • From: Thomas Dreibholz <dreibh AT exp-math.uni-essen.de>
  • To: "Sumathi.Elangovan" <Sumathi.Elangovan AT uk.thalesgroup.com>, discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] sendmsg() !!!!
  • Date: Fri Nov 15 10:42:00 2002
  • List-id: SCTP Discussions <discussion.sctp.de>
  • Organization: University of Essen, Institute for Experimental Mathematics

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Donnerstag, 14. November 2002 18:53 schrieb Sumathi.Elangovan:
> 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?

Yes, there is no other possibility to return flags.


> 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?

Where is the exact location of the error? Run "gdb <program name> <name of
core file>" and enter "bt". This prints the stack trace. Then, enter "where
full"; this prints the values of variables. Please send me these two results.

You do not initialize the msghdr structure in msg; you have to specify the
buffer where the data to send is located (sendmsg()) or the data can be
stored (recvmsg()). This has to be somethink like this:
struct iovec iov;
iov->iov_base = buf;
iov->iov_len = buflen;
msg->msg_iov = iov;
msg->msg_iovlen = 1;
In the client, you make a memset to 0 for msg. Although a sendmsg() does not
make sense with this, no segmentation fault should occur here. In the server,
you seem to have "msg" uninitialized. Here, "msg" may contain random junk and
lead to a segmentation fault.



> 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.
> **********************************************************************
> _______________________________________________
> discussion mailing list
> discussion AT sctp.de
> http://www.sctp.de/mailman/listinfo/discussion

- --
=======================================================================
Dipl.-Inform. Thomas Dreibholz

University of Essen, Room ES210
Inst. for Experimental Mathematics Ellernstraße 29
Computer Networking Technology Group D-45326 Essen/Germany
- -----------------------------------------------------------------------
E-Mail:
dreibh AT exp-math.uni-essen.de
Homepage: http://www.exp-math.uni-essen.de/~dreibh
=======================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE91MBa32BbsHYPLWURAvxqAJ9I9RTE/nGaTAOycA30uqT8Im6G3gCffUnS
Y8XLcAZ5cgW7vRry82LsZAk=
=2KSo
-----END PGP SIGNATURE-----




Archive powered by MHonArc 2.6.19+.

Top of page