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

  • SEARCH
  • Home
  • 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 8695661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:05:31+00:00 2026-06-13T01:05:31+00:00

I have code in windows that calls to getsockname as following: getsockname(*x,NULL,0) the third

  • 0

I have code in windows that calls to getsockname as following:

getsockname(*x,NULL,0)

the third parameter (namelen) is IN\Out parameter, and contains the size of the name buffer, in bytes. On return, the namelen parameter contains the actual size in bytes of the name parameter.
Now, my question is what will occure if the the name equals to null, and the namelen equals to zero?I saw taht in linux, if name is NULL, namelen is ignored, but the MSDN doesn’t mention anything about this case..
The MSDN link is here
the IBM link for linux is here

thanks in advance

  • 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-06-13T01:05:32+00:00Added an answer on June 13, 2026 at 1:05 am

    In your code, you have passed zero for the third parameter.

    The third parameter cannot be null, according to the specification, it must be a pointer to an integer giving the length of the second parameter, and on output gives the actual size of the address. Passing zero does not mean that you are saying no storage has been allocated, it means you are saying you haven’t passed the information nor anywhere to write the output value.

    According to MSDN and Linux documentation, the function should return -1 and set errno to EFAULT ( or WSAGetLastError to WSAEFAULT on in windows sockets). This is defined as “Using the name and namelen parameters as specified would result in an attempt to access storage outside of the caller’s address space.”

    However that’s not part of the Posix specification, and I don’t read that as requiring the function the check the addresses – just that it can. In other words, in Posix at least, this is undefined behaviour. That means anything can happen.

    In Linux, you say you have observed that the two parameters are ignored if null is passed. I suspect that your code isn’t checking the return value, which will probably be -1 with errno set to EFAULT.

    Posix functions don’t throw exceptions. You should be checking the return code, possibly something like this:

    int result = getsockname(*x,NULL,0); 
    if(result){
        /*Failed - handle here*/ 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which works on windows, that calls LocalAlloc as follows: LocalAlloc(LMEM_ZEROINIT, size)
We have some code that must access low level windows XP os calls which
I am in Windows and Suppose I have a main python code that calls
Conditions: Windows 98 SE WMI not available I have code that looks like this,
I read that Windows wp8 allows native code. So how then have ports such
I have a Windows Phone 7.5/Silverlight app. I have some code that I duplicate
I have some existing code that worked fine under Windows 2003, to obtain the
I have some older code that doesn't appear to work on 64bit Windows 7.
enter code here Hi All, I have a simple windows service application that connects
I have a program I wrote in Windows with this piece of code that

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.