Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:28:21+00:00 2026-05-27T21:28:21+00:00

Example: // socket created above this int iSocketOption = 1; setsockopt(CFSocketGetNative(socket), SOL_SOCKET, SO_REUSEADDR, (void

  • 0

Example:

// socket created above this
int iSocketOption = 1; 
setsockopt(CFSocketGetNative(socket), SOL_SOCKET, SO_REUSEADDR, (void *)&iSocketOption, sizeof(iSocketOption));

I understand that when you pass a wildcard pointer to the address of an int set to 1 for the option_value arg (4th arg), you are saying, yes, use the SO_REUSEADDR option.

But what is going on with option_len, the last arg? The idea seems to be to recycle the int used for the arg before it, making it into a buffer for reporting the size of an unrelated value. What is that unrelated value? Should I be doing something with it?

Here’s the excerpt from the BSD Systems Calls Manual that’s confusing me:

For getsockopt(), option_len is a value-result parameter, initially containing the size of the buffer pointed to by option_value, and modified on return to indicate the actual size of the value returned.

What is the value whose size is to be returned using the buffer passed in via the penultimate arg of setsockopt?

(Granted, the excerpt regards getsockopt, not setsockopt, but there’s no other explanation of that last arg.)


Why I asked this question:

Apress’s More iPhone 3 Development gives this example of a socket setup, inside a method that returns a BOOL:

- (BOOL) methodInvolvingSocket {
// socket creation
int ret = 1; 
setsockopt(CFSocketGetNative(socket), SOL_SOCKET, SO_REUSEADDR, (void *)&ret,
sizeof(ret));
//...socket address set up, but no further use of “ret.”
return ret;
}

At the end of this method, the return is made using “ret” — which works, because ret is 1, the equivalent of YES, but it’s a pretty weird thing to do unless there were some expectation that the value of “ret” might change.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:28:22+00:00Added an answer on May 27, 2026 at 9:28 pm

    For setsockopt the last parameter does nothing more than tell the function how long the memory pointer to by the parameter before that is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this rpg socket tutorial we created a socket client in rpg that calls
How to write byte by byte to socket in PHP? For example how can
I learned an example of usage of sockets. In this example a client sends
Here's an example of opening and reading data from a TCP socket. Is there
I'm trying to just make a simple asyncore example where one socket is the
I'll preface this by saying I have minimal experience with both Perl and Socket
I created a SSL socket in C between a client and a host using
I created a UDP socket server self.UDPServer = SocketServer.UDPServer( ( UDP_IP, UDP_PORT ), UDPServerHandler
I know that the Socket class can be instantiated in this way (as an
Looking at examples about socket programming, we can see that some people use AF_INET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.