Problem passing telnet socket to spawned process



We have proprietary software which accepts a telnet connection, creates a new
process and passes the telnet socket down as stdin/stdout/stderr. This
software has run successfully for years, including on Windows XP SP2.

However it fails on one particular PC running Windows XP SP2. The created
process is unable to use the socket handle, setsockopt() gives an error of
10038 - ‘An operation was attempted on something that is not a socket.’.

Test code has been added to the created process to test the socket at the
start of main(). This test code shows the handle to be invalid on entry to
main.

Test code has been added to the telnet server service to ensure that the
socket is still valid after the new process has been created.

The following code segments and comments below show the sequence of events.

Can anyone suggest what the problem might be, or what we should try next?

=============
Telnet server service
=============

EnterCriticalSection(&csSocket);

if (!SetHandleInformation(hIO, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
{
EventLog->LogException("LaunchReality",
"SetHandleInformation", GetLastError());
}

pStartInfo->dwFlags |= STARTF_USESTDHANDLES;

pStartInfo->hStdInput =
pStartInfo->hStdOutput =
pStartInfo->hStdError = hIO;

BOOL res = CreateProcessAsUser(UserToken, // User Token
NULL, // -> Name of executable module
pCmd, // -> Command line string
&sa, // -> Process security
attributes
NULL, // -> Thread security attributes
TRUE, // Handle inheritance flag
DETACHED_PROCESS, // Creation flags
Environment, // -> new environment block
StartDirectory, // -> current directory name
pStartInfo, // -> STARTINFO structure
pProcessInfo // -> PROCESS_INFORMATION structure
);

/*>>>> START TEMPORARY SOCKET TEST CODE */
{
int SysErr, FileType;
int TrueI=1; // ==> (A1) Wait here until reach B6 in new
process

FileType = GetFileType(hIO); // ==> (A2) File type 3 – FILE_TYPE_PIPE

if (setsockopt((SOCKET)hIO,SOL_SOCKET,SO_OOBINLINE,
(char*)&TrueI,sizeof TrueI))
{ // ==> (A3) Successful, hIO is HANDLE 0x69c, as in new process
SysErr = GetLastError();
}
}

/*>>>> END TEMPORARY SOCKET TEST CODE */


===============
Newly created process
===============

int main(int argc, char **argv)
{

/*>>>> START TEMPORARY SOCKET TEST CODE */

int SysErr;
int TrueI=1, FileType;
HANDLE SockH;
WSADATA WSAData;

Sleep(30000);

/* Need this compatibility in winsock */
#define WINSOCKREV MAKEWORD(1,1)

SysErr = WSAStartup(WINSOCKREV,&WSAData); // ==> (B1) Successful

if (!SysErr)
{
if ((SockH = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE)
{ // ==> (B2) Successful, HANDLE
0x69c, as in service
SockH = GetStdHandle(STD_OUTPUT_HANDLE);
}

if (SockH != INVALID_HANDLE_VALUE)
{
FileType = GetFileType(SockH); // ==> (B3) File type 3 –
FILE_TYPE_PIPE

if (setsockopt((SOCKET)SockH,SOL_SOCKET,SO_OOBINLINE,
(char*)&TrueI,sizeof TrueI))
{ // ==> (B4) Failed
SysErr = GetLastError(); // ==> (B5) 10038 - An
operation was attempted on something that is not a socket.
}
}
} // ==> (B6)

/*>>>> END TEMPORARY SOCKET TEST CODE */

-- End --

.



Relevant Pages

  • Re: BBC TV 4 - Hawkwind: Do not panic
    ... But that's how people look up which port to type in to their ... If you've got a computer with no Web server running on it ... Telnet server to listen on socket 80, surely it should all `just work' ...
    (uk.comp.sys.mac)
  • Re: TCPIP programming (sockaddr_in question)
    ... me too (Specifically Telnet); ... INET6 socket so that all the progeny get IPv6 capabilities. ... I was about to say "So you can at least get the bloody port number for the ... Why would I do 2 $QIOs when I need only one. ...
    (comp.os.vms)
  • Async Socket IO Question
    ... This app is a socket server that has remote clients connect. ... telnet to the app, watch it start a read, and then kill the telnet app. ... reports true. ...
    (microsoft.public.dotnet.framework)
  • millionth socket problem....
    ... To test it, I checked it with telnet, so ... my client *is* working. ... My server is the following, ... use Socket; ...
    (perl.beginners)
  • how fast can you pingpong pickled objects?
    ... I'm transfering small pickled object over a socket. ... localhost network). ... My test code is here: ...
    (comp.lang.python)