cancel
Showing results for 
Search instead for 
Did you mean: 

please give me the solution for resolving the error

sriramagowtham434
Associate
Posted on August 01, 2014 at 20:51

Hi sir/madam

               when I am compiling my code for tcp/ip echoserver and echoclient I am getting the error

error: storage size of 'echoServAddr' isn't known

.

I am compiling the code by using CooCox CoIDE Tool.

Here is my code

&sharpinclude ''stdio.h''               /* for printf() and fprintf() */

&sharpinclude ''sockets.h''         /* for socket(), bind(), and connect() */

&sharpinclude ''inet.h''         /* for sockaddr_in and inet_ntoa() */

&sharpinclude ''stdlib.h''              /* for atoi() */

&sharpinclude ''string.h''             /* for memset() */

&sharpinclude ''unistd.h''         /* for close() */

&sharpinclude <netdb.h>

&sharpinclude <sys/types.h>

&sharpdefine MAXPENDING      5      /* Maximum outstanding connection requests */

&sharpdefine AF_INET         2

&sharpdefine PF_INET         AF_INET

&sharpdefine SOCK_STREAM     1

&sharpdefine IPPROTO_TCP     6

void DieWithError(char *errorMessage);   /* Error handling function */

void HandleTCPClient(int clntSocket);   /* TCP client handling function */

void tcp_echoserver_init(void)

{

int servSock;             /* Socket descriptor for server */

int clntSock;             /* Socket descriptor for client */

struct sockaddr_in   echoServAddr;     /* Local address */

struct sockaddr_in   echoClntAddr;     /* Client address */

unsigned short echoServPort;         /* Server port */

unsigned int clntLen;                          /* Length of client address data structure */

//if (argc != 2)                          /* Test for correct number of arguments */

//{

//fprintf(stderr, ''Usage: %s <Server Port>\n'', argv[0]) ;

//exit(1);

//}

//echoServPort = atoi(argv[l]); /* First arg: local port */

/* Create socket for incoming connections */

if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)

DieWithError( ''socket () failed'') ;

/* Construct local address structure */

memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */

echoServAddr.sin_family = AF_INET; /* Internet address family */

echoServAddr.sin_addr.s_addr = inet_addr(INADDR_ANY); /* Any incoming interface */

echoServAddr.sin_port = htons(echoServPort); /* Local port */

/* Bind to the local address */

if (bind(servSock, (struct sockaddr *)&echoServAddr, sizeof(echoServAddr)) < 0)

DieWithError ( ''bind () failed'');

/* Mark the socket so it will listen for incoming connections */

if (listen(servSock, MAXPENDING) < 0)

DieWithError(''listen() failed'') ;

for (;;) /* Run forever */

{

/* Set the size of the in-out parameter */

clntLen = sizeof(echoClntAddr);

/* Wait for a client to connect */

if ((clntSock = accept(servSock, (struct sockaddr *) &echoClntAddr,

&clntLen)) < 0)

DieWithError(''accept() failed'');

/* clntSock is connected to a client! */

printf(''Handling client %s\n'', inet_ntoa(echoClntAddr.sin_addr));

HandleTCPClient (clntSock) ;

}

/* NOT REACHED */

}

Please help me to resolve the above mentioned error.

Thank u Sir/Madam.

#incomplete-type
2 REPLIES 2
Posted on August 01, 2014 at 22:38

I am compiling the code by using CooCox CoIDE Tool.

Try their support forum, looks to either be a compiler issue, or some prior line causing a problem, look at the pre-processor output.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on August 02, 2014 at 23:06

''I am getting the error

error: storage size of 'echoServAddr' isn't known

.''

Would've helped if you'd also highlighted where, exactly, in the code you get that.

Anyhow, this means that you don't have a proper definition of

'echoServAddr'

 at the point where you've tried to use it. Without a proper definition, the compiler can't tell what size it is!

Try googling ''incomplete type''

eg, 

http://msdn.microsoft.com/en-us/library/200xfxh6.aspx