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>
  • Cc: discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] sendmsg() !!!!
  • Date: Fri Nov 15 13:32:01 2002
  • List-id: SCTP Discussions <discussion.sctp.de>
  • Organization: University of Essen, Institute for Experimental Mathematics

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

Am Freitag, 15. November 2002 13:17 schrieb Sumathi.Elangovan:
> Hi!
> Thanks for ur help!
> The updated program is attached below....
> The sendmsg() seems to work where the "count value is 1024" which is the
> defined "buffer length"....now I am having problems with recvmsg()...i
> notice in ur last email u said that the "msg is uninitialised" in the
> server side....I modified the recvmsg() a little and the received bytes
> returns "0" "NULL" bytes.....where is it going wrong?

"msg" is still uninitialized at the server. First, do a memset to 0 on the
msghdr structure as done at the client. Then, initialize at least the iovec
part.

struct iovec iov;
iov->iov_base = buf;
iov->iov_len = buflen;
msg->msg_iov = iov;
msg->msg_iovlen = 1;


> I am trying to sort
> out the results of the trace file out...I am not able to get any
> trace....it just comes out with the "No stack found" and "Undefined
> command" I do the following:
>
> - gdb filename bt
>
> ....I am not too sure what "Core dump file" is....do I have to create a new
> dump file.. thanks again for ur help...I will try to get the stack trace in
> the mean time.

When your program crashes, you kernel usually creates a file named "core" or
"core.<Your process ID>". The core file contains a complete copy of the
program's memory when it crashed. This may be turned off. Enter "ulimit -c
unlimited" to enable core file creation of unlimited size. After restarting
your program and crashing, you can use the debugger gdb to find out where the
problem was:
# gdb <Your program> <Name of core File>
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
...
(gdb)

At the prompt (gdb), you can now enter gdb commands like "bt" or "where full".



> 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];
>
>
> //static char server, client;
>
>
> /* SERVER */
>
> void SctpServer()
> {
> int servSock,clntSock;
> int n;
> int clntLen;
> size_t cmsglen = sizeof(struct cmsghdr) + sizeof(struct
> sctp_sndrcvinfo) +
> sizeof(echoBuffer); char cbuf[cmsglen];
> struct sockaddr_in echoServAddr;
> struct sockaddr_in echoClntAddr;
> //char buffer[BUFFER_SIZE];
>
> printf("Creating server socket......");
> 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));
> echoServAddr.sin_family = AF_INET;
> echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
> echoServAddr.sin_port = htons(9);
>
> /* 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");
>
> 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");
>
> if((recvMsgSize = ext_recvmsg(clntSock,msg, 0)) < 0)
> {
> printf("send() failed.\n\n");
> exit(1);
> }
> //echoBuffer[recvMsgSize] = '\0';
> printf(" Reading %s bytes.\n", recvMsgSize);
>
>
> /*recvMsgSize = ext_recvmsg(clntSock,msg,0);
> if(recvMsgSize < 0)
> {
> printf("recvmsg() failed.\n\n");
> } else if (recvMsgSize == 0){
> printf("connection shutdown by
> client");
> }else{
>
> echoBuffer[recvMsgSize] = '\0';
> printf("%s",servSock, echoBuffer);
> } */
>
>
> //printf("\n\nClosing connection.....");
> //ext_close(clntSock);
> //printf("Connection closed....\n\n");
>
> }
>
> /* CLIENT */
>
> void SctpClient()
> {
> int clntSock,n;
> int count = 0;
> struct sockaddr_in echoClntAddr;
> struct sockaddr_in remote_addr;
> //char buffer[BUFFER_SIZE];
>
> struct iovec iov[1];
>
> (&iov[0]) -> iov_base = echoBuffer;
> (&iov[0]) -> iov_len = sizeof(echoBuffer);
>
> msg -> msg_iov = (struct iovec*) &iov;
> msg -> msg_iovlen = 1;
>
> printf("Creating client socket............");
> 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(9);
>
> printf("remote address...127.0.0.1.....");
> bzero(&remote_addr, 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(9);
>
> 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.\n\n");
> exit(1);
> }
> printf("count = %d\n",count);
>
> /* while (recvMsgSize > 0) ;
> printf("\n\n Closing Connection.\n\n");
> ext_close(clntSock);
> printf("Connection closed.\n\n"); */
> }
>
>
> Regards
> Sumathi Elangovan
>
> Sumathi Elangovan
> Design Engineer
> Thales Research Limited
> Reading
> Tel: 0118 923 8272
> Email :
> Sumathi.Elangovan AT uk.thalesgroup.com
>
>
>
> -----Original Message-----
> From: Thomas Dreibholz
> [mailto:dreibh AT exp-math.uni-essen.de]
> Sent: 15 November 2002 09:38
> To: Sumathi.Elangovan;
> discussion AT sctp.de
> Subject: Re: [SCTP-Discussion] sendmsg() !!!!
>
>
> -----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.
>
>
>
> **********************************************************************
> 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.
> **********************************************************************


Best regards
- --
=======================================================================
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

iD8DBQE91Ojj32BbsHYPLWURAlXsAKCzZmIpNtjV1P2m/2Z78sHGjVEiaQCgmsXP
SomK5fLdFUmnl9W+vE3ME2g=
=aF72
-----END PGP SIGNATURE-----




Archive powered by MHonArc 2.6.19+.

Top of page