ilnli |
08-02-2007 06:20 PM |
undefined reference error
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
int connect_nonblocking(int sockfd, const struct sockaddr * saptr, socklen_t salen, int nsec)
{
int flags, n, error;
socklen_t len;
fd_set rset, wset;
struct timeval tval;
flags = Fcntl(sockfd, F_GETFL, 0);
Fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
error = 0;
if((n = connect(sockfd, (struct sockaddr *) saptr, salen)) < 0)
if(errno != EINPROGRESS)
return(-1);
if(n == 0)
goto done;
FD_ZERO(&rset);
FD_SET(sockfd, &rset);
wset = rset;
tval.tv_sec = nsec;
tval.tv_usec = 0;
if((n = Select(sockfd + 1, &rset, &wset, NULL, nsec ? &tval : NULL)) == 0)
{
close(sockfd);
errno = ETIMEDOUT;
return(-1);
}
if(FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset))
{
len = sizeof(error);
if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
return(-1);
}
else
err_quit("select error: sockfd not set");
done:
Fcntl(sockfd, F_SETFL, flags);
if(error)
{
close(sockfd);
errno= error;
return(-1);
}
return(0);
}
but when i try to compile it gcc say
"undefined reference to fcntl"
"undefined reference to select"
"undefined reference to err_quit"
can't figure it out please help.
regards,
Imran
|