Re: Socket "bind" isn't working for me.
Re: Socket "bind" isn't working for me.
- Subject: Re: Socket "bind" isn't working for me.
- From: Cameron Kerr <email@hidden>
- Date: Sun, 24 Apr 2005 08:58:15 +1200
On 23/04/2005, at 7:31 PM, John Draper wrote:
In My application, the "bind" fails and returns a -1. However,
I'm unable to read "errno" to determine just what the error is. I
looked for "errno", a standard global variable containing this
value, but I have no way to look at it, because the
"strerror(ED_ERRNO)" is also broken.
Although the manual page for strerror or perror doesn't explain it
well, it does refer the reader to intro(2), and in that manual page
(man 2 intro) it does talk about errno.h. It is unfortunate that it
doesn't point to errno.h in the synopsis though.
If you look at the man page for bind(2), then you'll see in the ERRORS
section that EINVAL will be issued when the socket is already bound to
an address (port).
A couple of pointers when programming in Sockets.
1) You can't learn how to program the Sockets API by just reading the
manual pages (although the manual pages are essential reading), hence
the UNIX Network Programming book (Volume 1). It's kind of expensive,
but WELL worth it. Accept no substitutes. The third edition should be
out now. Unfortunately the previous author (Richard W. Stevens) died
suddenly, but two of his friends have filled his shoes in the
maintenance of this great book.
2) Always check for errors. Apart from what I've shown you above, here
is another common idiom (one that doesn't require errno.h to be
included)
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
perror( "socket" );
return -1;
}
--
Cameron Kerr
Telecommunications Teaching Fellow & SysAdmin
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden