Date: Fri, 30 Apr 1999 10:09:20 -0600 From: "Greg Campbell" <greg.campbell@matrikon.com> To: <freebsd-questions@FreeBSD.org> Subject: socket communication Message-ID: <000f01be9323$ce6e5bf0$9308a8c0@matrikon.com>
next in thread | raw e-mail | index | archive | help
Hi, I would appreciate some words of wisdom from anyone who has done some socket programming on FreeBSD. The question is this: Is there anything special about connecting to a socket from FreeBSD? I am getting an error from the "connect" function call (nothing more than -1 is returned which doesn't seem to map to any error messages codes. The following code is what I reverted to. It is basically the example form the Horspool book: #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define HOSTNAME "pandora" #define PORTNUM 2000 #define oops(msg) {printf("%s\n",msg);exit(-1);} struct sockaddr_in bba; struct hostent *hp; FILE *rf; int s, rfd, ch; int main() { int x; char return_char; int retval; /* build the network address */ bzero(&bba, sizeof(bba)); bba.sin_family = AF_INET; hp=gethostbyname(HOSTNAME); if(hp==NULL) oops ("no such computer"); bcopy(hp->h_addr, &bba.sin_addr, hp->h_length); bba.sin_port = htons(PORTNUM); /* make the connection */ s = socket(AF_INET, SOCK_STREAM, 0); if(s==-1) oops("socket"); if((retval=connect(s,&bba, sizeof(bba)))!= 0) oops("connect"); rf=fdopen(s,"r"); } The connect call in this snippet always returns -1 and the program drops out with the "connect" message. Let me say that the socket is open on another FreeBSD box. A HP-UX workstation and a Windows PC can both connect to the socket. The HP-UX box is using this same code as the connection client (although that really doesn't mean much - other than I have quite a bit of computer crap in my basement and extra time on my hands). Is there anything that has to be turned on in the kernal to support sockets? I am grasping at straws here. Any help would be appreciated. thanks, Greg To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000f01be9323$ce6e5bf0$9308a8c0>