site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com I guess this was intended for the list. Begin forwarded message: From: Ryan Lum <cow@launchpc.com> Date: 17 mei 2005 00:52:20 GMT+02:00 To: Jonas Maebe <jonas@zeus.ugent.be> Subject: Re: Bsd sockets and GCC 4.0 On 5/16/05 4:47 PM, "Jonas Maebe" <jonas@zeus.ugent.be> wrote: I did try a different ver though int co1800_init_socket(int port) { int s, opt; struct sockaddr_in sa; struct linger ld; char buf[MAX_STRING_LENGTH]; #if defined (DIKU_WINDOWS) WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 0); if (WSAStartup(wVersionRequested, &wsaData) != 0) { main_log("SYSERR: WinSock not available!"); exit(1); } #endif GVLOCATION(3130); memset(&sa, 0, sizeof(struct sockaddr_in)); #if defined (DIKU_WINDOWS) sa.sin_family = PF_INET; sa.sin_port = htons((unsigned short)port); #else sa.sin_family = AF_INET; sa.sin_port = htons(port); #endif if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { bzero(buf, sizeof(buf)); sprintf(buf, "ERROR: opening socket.\r\n"); perror(buf); ABORT_PROGRAM(); } if (ct > time(0)) ct = time(0); } sprintf (buf, "%d", tempI); printf("error %d on socketpair\n", errno); main_log(buf); main_log ("ERROR: Damn socket errors (comm.c)"); spec_log("ERROR: Damn socket errors (comm.c)", ERROR_LOG); exit(1); } if (listen(s, 5) < 0) { main_log ("ERROR: sigh (comm.c) bug #: 3174517521297519275"); spec_log("ERROR: sigh (comm.c) bug #: 3174517521297519275", ERROR_LOG); exit(1); } return(s); } Output: error 48 on socketpair (errno) Mon May 16 17:46:04 2005 :: -1 (tempI) Mon May 16 17:46:04 2005 :: ERROR: Damn socket errors (comm.c) dmdevel has exited with status 1. On 16 May 2005, at 23:39, Ryan Lum wrote: if(bind(s, (struct sockaddr *)&sa, sizeof(sa) < 0)) { With gcc 3.3 no problems, but it is returning -1 with 4.0. I am no socket expert, and any debugging advice would help. Your code has been wrong for 10 years, it should be if(bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { You were passing 0 as namelen parameter (since sizeof(sa) > 0). Not sure why this would work with gcc 3 and not with 4 though. Jonas _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/cow%40launchpc.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Thanks for all your help, I actually just typoed the code I posted. Sorry. Here is the whole function. I am not interested in the DIKU_WINDOWS code. if ((s = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { sprintf (buf, "SYSERR: Error opening network connection: Winsock error #%d", WSAGetLastError()); main_log(buf); exit(1); } opt = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)) < 0) { main_log ("ERROR: Socket error (comm.c)"); spec_log("ERROR: Socket error (comm.c)", ERROR_LOG); exit(1); } ld.l_onoff = 0; /* make sure this is on */ ld.l_linger = 1000; /* who cares about this */ if (setsockopt(s, SOL_SOCKET, SO_LINGER, (char *)&ld, sizeof(ld)) <0) { main_log ("ERROR: ANother socker error (comm.c)"); spec_log("ERROR: ANother Socket error (comm.c)", ERROR_LOG); exit(1); } GVLOCATION(3135); int tempI; tempI= bind(s, (struct sockaddr *)&sa, sizeof(sa)); if ( tempI < 0) { long ct; #if defined (DIKU_WINDOWS) if (closesocket(s)) #else if(close(s)) #endif fprintf(stderr, "co1800_init_socket: error closing socket: %d", errno); ct = time(0); /* since script loops wait around a bit */ while (time(0)-45 < ct) { I don't have time right now to read the man bind text or google for the socketpair error, but I imagine it will probably help fix the error. Can anyone recommend a good book that covers bsd sockets. I imagine I will have to actually read about sockets before I figure this out. This email sent to cow@launchpc.com This email sent to site_archiver@lists.apple.com