Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How can I force bind() to a port?

How can I force bind() to a port?
Thread Tools
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Jul 15, 2001, 03:58 PM
 
It seems that the classic environment does not release bindings to ports used by classic applications. They are released only if classic is quit.
While classic is active, bind() gives an "Address already in use" error (errno 48).

Question: How can I override the binding or how can I unbind that port before I bind to it?

code looks like:

sok = socket(AF_INET, SOCK_STREAM, 0);
setsockopt(sok, SOL_SOCKET, SO_REUSEADDR, &len, sizeof(len));
memset(&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(thePortNumber);
seteuid(0);
res = bind(sok, (struct sockaddr *) &addr, sizeof (addr));
setuid(pw->pw_uid);

// now res is -1 and errno is 48 if thePortNumber has been used by
// any classic application and classic is still active

-
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2