Date: Wed, 30 May 2001 07:31:50 -0300 From: horape@tinuviel.compendium.net.ar To: freebsd-net@freebsd.org Subject: why cannot bind to someipaddress:port when something else has *:port bound? Message-ID: <20010530073150.A15247@tinuviel.compendium.net.ar>
next in thread | raw e-mail | index | archive | help
¡Hola!
The following program binds *:1000 to a socket, and then tries to bind
200.47.36.254:1000 to another socket, the error i gets is "Address
already in use". Why?
I am not asking for a "you're not allowed to do that", I know. I don't
ask for a "why are you trying to do that?", I amn't trying. But I need
to know why that's not permited. I know vaguely but i need a more sound
explanation. A pointer to a mailing list/usenet archive where the subject
was discussed in the past would be great.
Just another time, i am asking for the theory about why that shouldn't
be allowed. Not the fact that it's not allowed.
Lots of thanks,
HoraPe
The code is:
main()
{
l4();
l4esp();
select(0,NULL,NULL,NULL,NULL);
}
int l4()
{
int listenfd;
struct sockaddr_in cliaddr, servaddr;
socklen_t clilen;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if(listenfd < 0)
die();
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(1000);
if(bind(listenfd, (struct sockaddr*) &servaddr, sizeof(servaddr)) != 0)
die();
if(listen(listenfd, 10) != 0)
die();
}
int l4esp()
{
int listenfd;
struct sockaddr_in cliaddr, servaddr;
socklen_t clilen;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if(listenfd < 0)
die();
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(1000);
if(bind(listenfd, (struct sockaddr*) &servaddr, sizeof(servaddr)) != 0)
die();
if(listen(listenfd, 10) != 0)
die();
}
int l4esp()
{
int listenfd;
struct sockaddr_in cliaddr, servaddr;
socklen_t clilen;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if(listenfd < 0)
die();
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(0xc82f24fe);
servaddr.sin_port = htons(1000);
if(bind(listenfd, (struct sockaddr*) &servaddr, sizeof(servaddr)) != 0)
die();
if(listen(listenfd, 10) != 0)
die();
}
die()
{
printf("die %s\n", strerror(errno));
}
HoraPe
---
Horacio J. Peña
horape@compendium.com.ar
horape@uninet.edu
bofh@puntoar.net.ar
horape@hcdn.gov.ar
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010530073150.A15247>
