[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: connect() question (solaris vs obsd (vs linux))
- To: torh@bogus.net (Tor Houghton)
- Subject: Re: connect() question (solaris vs obsd (vs linux))
- From: Rob Pickering <rob@syntonet.co.uk>
- Date: Wed, 29 Sep 1999 16:29:09 +0100 (BST)
Tor Houghton Said:
>
> sa.sin_port=53;
> if(bind(sd,(struct sockaddr *)&sa,sizeof(sa)) == -1) {
> perror("Unable to bind()");
> if(sd != -1) {close(sd);}
> return;
> }
> -- end excerpt --
>
> Basically, the change is that I use bind() to change the source address. I
> know I should perhaps use raw sockets, or libnet, but I didn't want to
> change the code too much.
>
> The odd thing is this.
>
> On Solaris, this code compiles cleanly, and behaves exactly as I want to.
You got lucky, big endian sparc and the junk in the uninitialised
sa struct members meant something to Solaris.
> On OpenBSD, the code compiles cleanly, but still uses random source port.
> On Linux, the code compiles cleanly, but I get the error
> Unable to connect(): Invalid argument
You need to fill in the rest of sa, including sin_family to AF_INET
and sin_addr to a valid interface on your machine or INADDR_ANY.
Then you need to set the port number properly:
sa.sin_port=htons(53);
--
Rob.