Jump to content
  • Advertisement
Sign in to follow this  
rajend3

implicit function declaration when closing socket

This topic is 4077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've coded a simple client and server and tried to connect them to each other but I'm having some difficulty when I execute them. I get an "implicit function declaration" error with respect to my close function call. Any help would be appreciated. This is my client: #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #define SERVERPORT 3000 int main() { struct sockaddr_in serverAddr; // servers address info int clientSock; // socket file desc of client serverAddr.sin_family = AF_INET; // set family serverAddr.sin_port = htons(SERVERPORT); // set port if( (serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1")) == -1 ) { perror("inet error"); } // pad sockaddr_in struct if( (memset( serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero)) == NULL ) { perror("memset error"); } // create socket if( (clientSock = socket(PF_INET, SOCK_STREAM, 0)) == -1 ) { perror("socket error"); } if( (connect(clientSock, (struct sockaddr *)&serverAddr, sizeof (struct sockaddr))) == -1 ) { perror("connect error"); } //close(clientSock); return 0; } I compiled it on a solaris machine using cc -o client client.c -lnsl -lsocket [Edited by - rajend3 on July 24, 2007 6:01:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Most likely include error (slight possibility of compiler bug for pre-3.x versions).

Try doing man on close() to find out which header it's defined in. It could be elsewhere due to Solaris specifics.

The error simply means that:
close(clientSock);
can't be found. Therefore the compiler assumes it's a declaration of a local function "close" that returns "int" (or is void the default return value) and takes "clientSock" typed parameter.

Share this post


Link to post
Share on other sites
Thanks for the help guys I did a man on close and it did turn out that I needed to add the unistd header.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!