Reputation: 406
I am working with Vxworks 653 platfrom, I have created an application partition. I want to create a server on the application partition, after building it i am receiving the errors
undefined reference to "socket", undefined reference to "bind"
What should i do it is a linker error or what i am missing
The code:
# include "vxWorks.h"
# include "sockLib.h"
# include "sys/socket.h"
# include "netinet/in.h"
# include "inetLib.h"
# include "ioLib.h"
# include "string.h"
# include "stdio.h"
# include "taskLib.h"
/* typedefs */
typedef int SOCK_FD;/*
/* forward declarations */
LOCAL void error(char* str);
/******************************************************************************
*
* vxServer - processes UDP client requests
*
* This routine sits in an infinite loop handling client requests.
* When a request is received, the client's data is converted
* to the local byte-ordering and then displayed. Next,
* a reply is sent to the client. Then the server will process
* the next request or block if there is none.
*/
void vxServer(u_short port)
{
int clientAddrLength;
SOCK_FD sockFd;
struct sockaddr_in clientAddr;
struct sockaddr_in srvAddr;
char inetAddr[INET_ADDR_LEN];
u_short clientPort;
char* reply = "Here is your reply\n";
int val;
clientAddrLength = sizeof (clientAddr);
/* Create a socket */
if ((sockFd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
error("Socket failed");
/*
* Bind to a well known address. INADDR_ANY says
* any network interface will do. htonX()
* routines put things in network byte order.
*/
bzero((char*)&srvAddr, sizeof(srvAddr));
srvAddr.sin_family = AF_INET;
srvAddr.sin_port = htons(port);
srvAddr.sin_addr.s_addr = INADDR_ANY;
if (bind (sockFd, (struct sockaddr *) &srvAddr, sizeof(srvAddr)) < 0)
{
close(sockFd);
error("Bind failed");
}
FOREVER
{
if (recvfrom (sockFd, (char*) &val, sizeof(val), 0,
(struct sockaddr *) &clientAddr,
&clientAddrLength) < 0)
{
close(sockFd);
error("recvfrom failed");
}
val = ntohl(val);
inet_ntoa_b(clientAddr.sin_addr, inetAddr);
clientPort = ntohl(clientAddr.sin_port);
printf("Message received from client "
"(port = %d, inet = %s):\n",
clientPort, inetAddr);
printf("%d\n", val);
if (sendto (sockFd, reply, strlen(reply) + 1,
0,(struct sockaddr *) &clientAddr,
clientAddrLength) < 0)
{
close(sockFd);
error("sendto failed");
}
}
}
void error(char* str)
{
perror(str);
exit(1);
}
Upvotes: 0
Views: 621
Reputation: 14057
These days I'm more familiar with VxWorks Helix than the older VxWorks 653, but have you checked that the INCLUDE_SOCKLIB component has been added to your project, or the SOCKET layer added to your VSB?
Usually when there is a linker error such as the one you described, either a component is missing from your project and/or a layer is missing from your VSB.
Upvotes: 1