Is this a "typedef" problem?
This is the definition in one file.
typedef BYTE SOCKET; //Socket descriptor
BYTE is defined elsewhere as type char.
(I made sure the file where SOCKET is assigned a type is included in the file the problem is in.)
This is one place it is used but my compiler is saying "BerkeleyTCPServerDemo.c:83:19: error: 'bsdServerSocket' undeclared (first use in this function)" in the following (line 83 equates to the third line in this excerpt)...
void BerkeleyTCPServerDemo(void)
{
static SOCKET bsdServerSocket;
static SOCKET ClientSock[MAX_CLIENT];
struct sockaddr_in addr;
struct sockaddr_in addRemote;
int addrlen = sizeof(struct sockaddr_in);
char bfr[15];
int length;
int i;
static enum
{
BSD_INIT = 0,
BSD_CREATE_SOCKET,
BSD_BIND,
BSD_LISTEN,
BSD_OPERATION
} BSDServerState = BSD_INIT;
switch(BSDServerState)
{
case BSD_INIT:
// Initialize all client socket handles so that we don't process
// them in the BSD_OPERATION state
for(i = 0; i < MAX_CLIENT; i++)
ClientSock[i] = INVALID_SOCKET;
BSDServerState = BSD_CREATE_SOCKET;
// No break needed
case BSD_CREATE_SOCKET:
// Create a socket for this server to listen and accept connections on
bsdServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(bsdServerSocket == INVALID_SOCKET)
return;
BSDServerState = BSD_BIND;
// No break needed
case BSD_BIND:
// Bind socket to a local port
addr.sin_port = PORTNUM;
addr.sin_addr.S_un.S_addr = IP_ADDR_ANY;
if( bind( bsdServerSocket, (struct sockaddr*)&addr, addrlen ) == SOCKET_ERROR )
return;
BSDServerState = BSD_LISTEN;
// No break needed
case BSD_LISTEN:
if(listen(bsdServerSocket, MAX_CLIENT) == 0)
BSDServerState = BSD_OPERATION;
// No break. If listen() returns SOCKET_ERROR it could be because
// MAX_CLIENT is set to too large of a backlog than can be handled
// by the underlying TCP socket count (TCP_PURPOSE_BERKELEY_SERVER
// type sockets in TCPIPConfig.h). However, in this case, it is
// possible that some of the backlog is still handleable, in which
// case we should try to accept() connections anyway and proceed
// with normal operation.
I thought this is where "bsdServerSocket" is declared.
(code is from Microchip.)