Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <58650.193.16.155.145.1096986545.squirrel@193.16.155.145> Date: Tue, 5 Oct 2004 16:29:05 +0200 (CEST) Subject: setsockopt SO_REUSEADDR From: "Rainer Hochreiter" To: cygwin AT cygwin DOT com User-Agent: SquirrelMail/1.4.3a-0.f0.9.1.legacy MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit running the program listed below with argument 'reuse' under cygwin and linux returns different results! from my point of view, the linux result is quite what i expected, a bind() error 'Address already in use'. why doen't bind() return an error under cygwin? running under cygwin: ~$ ./tcptest.cygwin.exe reuse & using socket=4200064 setsockopt(SO_REUSEADDR) ~$ ./tcptest.cygwin.exe reuse using socket=4200064 setsockopt(SO_REUSEADDR) running under linux: ~$ ./tcptest.linux reuse & using socket=134513784 setsockopt(SO_REUSEADDR) ~$ ./tcptest.linux reuse using socket=134513784 setsockopt(SO_REUSEADDR) bind() failed: Address already in use #----------------------------------------------------------------- #include #include #include #include int main(int argc, char** argv) { const unsigned reuse = (argc == 2 && strcmp(argv[1], "reuse") == 0); int s = -1; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket() failed"); exit(1); } printf("using socket=%d\n", socket); if (reuse) { int on = 1; printf("setsockopt(SO_REUSEADDR)\n"); if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) { perror("setsockopt(SO_REUSEADDR) failed"); } } struct sockaddr_in saddr; bzero((char *) &saddr, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_port = htons(12345); if (bind(s, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) { perror("bind() failed"); exit(1); } listen(s, 5); while (1) { struct sockaddr_in caddr; int caddr_len = sizeof(caddr); int s2; if ((s2 = accept(s, (struct sockaddr *) &caddr, &caddr_len)) < 0) { perror("accept() failed"); exit(1); } close(s2); } return 0; } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/