#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
int main()
{
int sock = 0;
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(9001);
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1)
printf("Error creating socket");
else
{
if (bind(sock, (struct sockaddr *)& address, sizeof(address)))
printf("error binding socket");
else
{
printf("socket bound successfully");
listen(sock,5);
struct sockaddr_in address2;
int addrlen = sizeof(struct sockaddr_in);
int newSocket = accept(sock, (struct sockaddr *)&address2, &addrlen);
if (newSocket < 0)
printf("Error accepting incoming connection\n");
else
{
char* msg = "Test message";
printf("About to send the message");
send(sock,msg,strlen(msg),0);
printf("I think i just sent the message");
}
}
}
close(sock);
return 0;
}
but when I attempt to compile I'm getting the errors below:
$ gcc servtest.c
Undefined first referenced
symbol in file
bind /var/tmp//cc3taE90.o
send /var/tmp//cc3taE90.o
accept /var/tmp//cc3taE90.o
listen /var/tmp//cc3taE90.o
socket /var/tmp//cc3taE90.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Any ideas anybody???

