AnsweredAssumed Answered

please give me the solution for resolving the error

Question asked by gowtham.srirama on Aug 1, 2014
Latest reply on Aug 2, 2014 by Andrew Neil
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

#include "stdio.h"               /* for printf() and fprintf() */
#include "sockets.h"         /* for socket(), bind(), and connect() */
#include "inet.h"         /* for sockaddr_in and inet_ntoa() */
#include "stdlib.h"              /* for atoi() */
#include "string.h"             /* for memset() */
#include "unistd.h"         /* for close() */
#include <netdb.h>
#include <sys/types.h>


#define MAXPENDING      5      /* Maximum outstanding connection requests */
#define AF_INET         2
#define PF_INET         AF_INET
#define SOCK_STREAM     1
#define 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.

Outcomes