• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Socket "bind" isn't working for me.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket "bind" isn't working for me.


  • Subject: Re: Socket "bind" isn't working for me.
  • From: John Draper <email@hidden>
  • Date: Sat, 23 Apr 2005 22:52:31 -0700

Cameron Kerr wrote:

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.

Well - I found SOME things, which might be really obvious to an experienced UNIX programmer,
but it certainly wasn't to me. It turns out that I had to #import errno.h


I found this by accident when I was searching all files on my Mac for references to it.
In it, I was able to get the errno, which was 22. The header file said "Invalid arguments"
and was not obvious. But the "man 2 bind" said it was...


[EINVAL]           The socket is already bound to an address

Now, I was onto something... Something was already bound to that address. But it didn't
explain why my sendto was returning -1 (with same errno).... Hmmm - strange...


I knew it was possible to shoot packets out to specific remote hosts, those that
were setup to "hear" me, but it still didn't work.


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).

Yea - I stumbled onto this eventually.... But I was really frustrated I could NOT get my
hands on "UNIX Network Programming". I visited Frys, Borders, Barns and Noble and
Amazon said they could ship it in 2 weeks... I found this totally amazing because I'm
in Burbank - I guess people here just aren't into reading....


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).

Well Duhhhhh! that was QUITE obvious to me, and thus my need to post my questions
here. But, due to my inability to obtain that book, one list member pointed out this
URL, and I wish to share it with others.. I got a LOT of info from it, and thanks
a lot for turning me onto it - it's very well written, explains a huge number of
Gotchas I was totally unaware of.


http://www.ecst.csuchico.edu/~beej/guide/net/html/

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.

I also checked for that one also - Nada - none in stock, but they say they could get it in a
week.



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)

Yes - I agree errors can lead one to solutions - I was just frustrated I couldn't get it
working, and didn't know I had to #import errno.h


John

_______________________________________________
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


References: 
 >Socket "bind" isn't working for me. (From: John Draper <email@hidden>)
 >Re: Socket "bind" isn't working for me. (From: Cameron Kerr <email@hidden>)

  • Prev by Date: Re: Socket "bind" isn't working for me
  • Next by Date: Re: Socket "bind" isn't working for me
  • Previous by thread: Re: Socket "bind" isn't working for me.
  • Next by thread: Re: Socket "bind" isn't working for me
  • Index(es):
    • Date
    • Thread