Advertisement

07.24.2008 at 02:25AM PDT, ID: 23591420 | Points: 500
[x]
Attachment Details

Making sockets not inheritable in Win32

Asked by AdriendeC in Windows Programming, Windows Networking, Miscellaneous

Tags:

when you create a socket on win NT or later (e.g. 2k, XP, etc) it creates 2 underlying handles (visible in process explorer)

device\Tcp
device\Afd\Endpoint

It's possible to mark the device\Tcp handle non-inheritable using SetHandleInformation(), however I can't find any way to access the device\Afd\Endpoint handle to mark it not-inheritable.  Therefore any child process our process spawns inherits a handle called device\Afd\Endpoint for every socket in our host application (which can be VERY many).

I've looked into WSADuplicateSocket, and that is useless (only usable to duplicate a socket into another process, and can't set inheritance flags).

MSDN docs say you can't call DuplicateHandle on a SOCKET.  Presumably because of this problem above (2 handles).  It does seem to perform the same function as SetHandleInformation.

My question - does anyone know of a way to mark the entire socket (both handles) non-inheritable?  Or a way to set the default mode of socket creation to only create non-inheritable sockets?

ThanksStart Free Trial
[+][-]07.24.2008 at 07:58AM PDT, ID: 22079878

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 02:09PM PDT, ID: 22083553

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 02:23PM PDT, ID: 22083667

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.27.2008 at 04:35PM PDT, ID: 22099925

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628