From owner-freebsd-net Tue Jul 9 14:50:51 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DF51637B400 for ; Tue, 9 Jul 2002 14:50:48 -0700 (PDT) Received: from mx20b.rmci.net (mx20b.rmci.net [205.162.184.38]) by mx1.FreeBSD.org (Postfix) with SMTP id 57D8B43E31 for ; Tue, 9 Jul 2002 14:50:48 -0700 (PDT) (envelope-from term@velocitus.net) Received: (qmail 27003 invoked from network); 9 Jul 2002 21:50:42 -0000 Received: from exchange.rmci.net (216.222.101.3) by mx20.rmci.net with SMTP; 9 Jul 2002 21:50:42 -0000 Received: by exchange.rmci.net with Internet Mail Service (5.5.2653.19) id ; Tue, 9 Jul 2002 15:50:42 -0600 Message-ID: From: Chris Given To: "'freebsd-net@freebsd.org'" Subject: Bind to specific address on FreeBSD Date: Tue, 9 Jul 2002 15:50:41 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org I can't figure out why this code won't bind to 127.0.0.1 on FreeBSD. I get an error "Can't assign requested address". #include #include #include #include #include #include #include #include #include #include #include #include #include int main() { int sock; struct sockaddr_in dp; unsigned long bind_to_addr = inet_addr("127.0.0.1"); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock < 0) { printf("Error socket : %s\n", strerror(errno)); return -1; } dp.sin_family = AF_INET; dp.sin_addr.s_addr = htonl(bind_to_addr); dp.sin_port = htons(1234); if(bind(sock, (struct sockaddr*)&dp, sizeof(struct sockaddr_in))!=0) { printf("Bind failed : %s\n", strerror(errno)); } else { printf("Bind success\n"); } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message