Communicating with the TCP and UDP object

Hello, everybody!

I've just encountered an interesting article in MSDN:
They said that a programmer can create a symbolic link to the
TCP and/or UDP object (see below code).

My question is:
What is it good for? I tried to use WriteFile in order to "bypass"
the winsock and talk directly to the transport layer, without success...
(GetLastError returned 1 -- wrong function....).

Can I use this link to (somehow) write "raw" data over the net?

thanks,

  • Barak

Code:

void main()
{
HANDLE handle = NULL;
BOOL success = FALSE;
char deviceName = "TCP";
char targetPath = "\Device\TCP";
char completeDeviceName = "\\.\TCP";
//
// First create a symbolic link.
//

success = DefineDosDevice (DDD_RAW_TARGET_PATH,
deviceName,
targetPath
);

if (!success) {
MessageBox(NULL,"DefineDosDevice failed","Notice",MB_OK);
}

//
// Then call CreateFile().
//

handle = CreateFile(completeDeviceName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);

if (handle == INVALID_HANDLE_VALUE) {
MessageBox(NULL,"CreateFile failed","Notice",MB_OK);
} else {
MessageBox(NULL,"CreateFile succeeded","Notice",MB_OK);
CloseHandle(handle);
}

}


Barak Mandelovich xxxxx@mercury.co.il
Mercury Interactive ltd.

----- Original Message -----
From: Barak Mandelovich
To: NT Developers Interest List
Sent: Sunday, August 20, 2000 5:22 AM
Subject: [ntdev] Communicating with the TCP and UDP object

> Hello, everybody!
>
> I’ve just encountered an interesting article in MSDN:
> They said that a programmer can create a symbolic link to the
> TCP and/or UDP object (see below code).
>
> My question is:
> What is it good for? I tried to use WriteFile in order to “bypass”
> the winsock and talk directly to the transport layer, without success…
> (GetLastError returned 1 – wrong function…).
>
> Can I use this link to (somehow) write “raw” data over the net?
>

See the DDK documentation for the Transport Data Interface (TDI) to the
kernel mode TCP/IP stack for more information on the interface used with
“\Device\Tcp” and “\Device\Udp”. In particular, look at the methods used by
TDI to open address, endpoint and control objects.

In kernel mode you use the ZwCreateFile function to open TDI address and
endpoint objects with the Extended Attributes field used to pass essential
information for the create. This works just fine in kernel mode.

However, I don’t believe that there is a Win32 equivalent of ZwCreateFile
that actually supports the Extended Attribute information. So, using Win32
you can’t open a TDI address or endpoint object - meaning that you can’t
access TCP/IP from Win32 this way.

You might be able to write a native NT application that accesses
“\Device\Tcp”, but that’s probably not of more than academic interest.

In addition, AFAIK Read/Write is not used on these devices. Strictly IOCTL.

Finally, when you actually do access the lowest-level kernel-mode TCP/IP
driver
using “\Device\Tcp” you do NOT have the world at your fingertips. In fact,
most of the restrictions that frustrate Winsock programmers also limit
kernel mode TCP/IP use. In addition, there is a significant lack of
documentation concerning some functions.

Regards,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - TDI Client - Windows 95 Redirector
http:</http:>