Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.3. Microsoft-specific.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Socket Programming CS3320 Fall 2010.
CS 4700 / CS 5700 Network Fundamentals
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Remote Procedure Call (RPC)
Socket Programming Application Programming Interface.
Remote Procedure CallCS-4513, D-Term Remote Procedure Call CS-4513 Distributed Computing Systems (Slides include materials from Operating System.
计算机系 信息处理实验室 Lecture 16 Networking
Data Communications and Networking (Third Edition)
1 JMH Associates © 2004, All rights reserved Chapter 11 Interprocess Communication.
Socket Programming.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
ISP – 9 th Recitation Socket programming – Client side.
Introduction to Project 1 Web Client and Server Jan 2006.
Systems Architecture, Fourth Edition1 Internet and Distributed Application Services Chapter 13.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
ECE 4110 – Internetwork Programming Client-Server Model.
Assignment 3 A Client/Server Application: Chatroom.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
7.3. Windows Security Descriptors
LWIP TCP/IP Stack 김백규.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Winsock Programming Blocking and Asynchronous Sockets for Windows.
Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.4. Windows APIs for Synchronization.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.2. Windows Sockets.
Unit OS A: Windows Networking A.4. Lab Manual. 2 Copyright Notice © David A. Solomon and Mark Russinovich These materials are part of the Windows.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
Practical Sockets and Threads Derek Weitzel. Windows Threads Concurrent processing Concurrent processing Windows Create Thread Windows Create Thread HANDLE.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS2: Operating System Principles 2.4. The Windows.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.3. Advanced Windows Synchronization.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
1 Network Communications A Brief Introduction. 2 Network Communications.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Tiny http client and server
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Sockets and Beginning Network Programming
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
Unit OS7: Security 7.4. Quiz Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze.
Windows Programming Lecture 09.
Unit OS A: Windows Networking
Unit OS2: Operating System Principles
Chapter 3: Windows7 Part 4.
UNIX Sockets Outline Homework #1 posted by end of day
Socket Programming in C
28.
Interprocess Communication
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
The CreateFile Function
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.3. Microsoft-specific extensions to Sockets and other Networking APIs

2 Copyright Notice © David A. Solomon and Mark Russinovich These materials are part of the Windows Operating System Internals Curriculum Development Kit, developed by David A. Solomon and Mark E. Russinovich with Andreas Polze Microsoft has licensed these materials from David Solomon Expert Seminars, Inc. for distribution to academic organizations solely for use in academic environments (and not for commercial use)

3 Roadmap for Section A.3 Windows Sockets (winsock2) Extensions Web access APIs Named pipes and mailslots NetBIOS / Wnet API

4 Winsock 2.0 Features Windows NT 4.0 was the first operating system with native support of the Winsock 2.0 specification: Access to protocols other than TCP/IP, Overlapped I/O, Ability to query and request specific qualities of service New header file and libraries: WS2_32.LIB / WS2_32.DLL winsock2.h Microsoft extensions to Winsock have been moved out into their own separate DLL WINSOCK.DLL contains forwarders to these routines

5 Microsoft-specific Extensions to Berkeley Sockets Tailored to the message-passing environment of windows WSA – Windows Sockets Asynchronous prefix Roots in Windows 3.1 Windows Sockets Committee # include # include

6 Request event notification for a socket Request a message to the window hWnd whenever any of the network events specified by the lEvent occurs. Message which should be sent is specified by the wMsg parameter. The socket for which notification is required is identified by s int PASCAL FAR WSAAsyncSelect ( SOCKET s, HWND hWnd, unsigned int wMsg, long lEvent ); ValueMeaning FD_READ Want to receive notification of readiness for reading FD_WRITE Want to receive notification of readiness for writing FD_OOB Want to receive notification of the arrival of out-of-band data FD_ACCEPT Want to receive notification of incoming connections FD_CONNECT Want to receive notification of completed connection FD_CLOSE Want to receive notification of socket closure

7 WSAAsyncSelect (contd.) Every window must have a window procedure Arguments to window procedure for notification window: wParam contains socket number lParam contains event code and any error that may have occured Event status: WORD wError = WSAGETSELECTERROR( lParam); (wError != 0 ?) LRESULT WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); switch( msg ) { case WM_PAINT:... case WM_DESTROY:... case FD_ACCEPT:... default: return( DefWindowProc( hWnd, msg, wParam, lParam )); }

8 WSAAsynchSelect (contd.) Report the event: WORD wEvent = WSAGETSELECTEVENT( lParam ); Enabling functions reactivate WSAAsyncSelect: For FD_READ, FD_OOB events: ReadFile(), read(), recv(), recvfrom() are enabling functions For FD_WRITE events: WriteFile(), write(), send(), sendto() are enabling functions Request notification of different events: Call WSAAsyncSelect() again

9 WSAAsyncSelect (contd.) Issuing a WSAAsyncSelect() for a socket cancels any previous WSAAsyncSelect() for the same socket. For example, to receive notification for both reading and writing, the application must call WSAAsyncSelect() with both FD_READ and FD_WRITE, as follows: rc = WSAAsyncSelect(s, hWnd, wMsg, FD_READ | FD_WRITE); It is not possible to specify different messages for different events. The following code will not work; the second call will cancel the effects of the first, and only FD_WRITE events will be reported with message wMsg2: rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ); rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE); To cancel all notification - i.e., to indicate that the Windows Sockets implementation should send no further messages related to network events on the socket - lEvent should be set to zero.

10 Use of WSAAsyncSelect - Server Side 1. Create a socket and bind your address to it 2. Call WSAAsyncSelect(): Request FD_ACCEPT notification 3. Call listen() – returns immediately 4. When connection request comes in: Notification window receives FD_ACCEPT notification Respond by calling accept() 5. Call WSAAsyncSelect(): Request FD_READ | FD_OOB | FD_CLOSE notifications for socket returned by accept() 6. Receiving FD_READ, FD_OOB notifications: Call ReadFile(), read(), recv(), recvfrom() to retrieve the data 7. Respond to FD_CLOSE notification by calling closesocket()

11 Use of WSAAsyncSelect() - Client Side 1. Create a socket 2. Call WSAAsyncSelect(): Request FD_CONNECT notification 3. Call connect() – returns immediately 4. When FD_CONNECT notification comes in: Request FD_READ | FD_OOB | FD_CLOSE notification on socket (reported in wParam) 5. When data from the server arrives: Notification window receives FD_READ or FD_OOB events Respond by calling ReadFile(), read(), recv(), or recvfrom() Client should be prepared for FD_CLOSE notification

12 Get host information corresponding to an address - asynchronous version type: The type of the address, which must be PF_INET. buf: A pointer to the data area to receive the hostent data. Note that this must be larger than the size of a hostent structure. It is recommended that you supply a buffer of MAXGETHOSTSTRUCT bytes. buflen: The size of data area buf above. hWnd: –The handle of the window which should receive a message when the asynchronous request completes. wMsg: –The message to be received when the asynchronous request completes. addr: –A pointer to the network address for the host. Host addresses are stored in network byte order. len: –The length of the address, which must be 4 for PF_INET. HANDLE PASCAL FAR WSAAsyncGetHostByAddr ( HWND hWnd, unsigned int wMsg, const char FAR * addr, int len, int type, char FAR * buf, int buflen ); asynchronous version of gethostbyaddr()

13 WSAAsyncGetHostByAddr (contd.) When the asynchronous operation is complete the application's window hWnd receives message wMsg. The wParam argument contains the asynchronous task handle as returned by the original function call. The high 16 bits of lParam contain any error code. The error code may be any error as defined in winsock.h. An error code of zero indicates successful completion of the asynchronous operation. On successful completion, the buffer supplied to the original function call contains a hostent structure. To access the elements of this structure, the original buffer address should be cast to a hostent structure pointer and accessed as appropriate.

14 Get host information corresponding to a hostname - asynchronous version hWnd: The handle of the window which should receive a message when the asynchronous request completes. wMsg: The message to be received when the asynchronous request completes. Name: A pointer to the name of the host. Buf: A pointer to the data area to receive the hostent data. It is recommended that you supply a buffer of MAXGETHOSTSTRUCT bytes. Buflen: The size of data area buf above. HANDLE PASCAL FAR WSAAsyncGetHostByName ( HWND hWnd, unsigned int wMsg, const char FAR * name, char FAR * buf, int buflen ); asynchronous version of gethostbyname()

15 Get protocol information corresponding to a protocol name - asynchronous version hWnd The handle of the window which should receive a message when the asynchronous request completes. wMsg The message to be received when the asynchronous request completes. name A pointer to the protocol name to be resolved. buf A pointer to the data area to receive the protoent data. (supply a buffer of MAXGETHOSTSTRUCT bytes) buflen The size of data area buf above. HANDLE PASCAL FAR WSAAsyncGetProtoByName ( HWND hWnd, unsigned int wMsg, const char FAR * name, char FAR * buf, int buflen ); asynchronous version of getprotobyname()

16 Get protocol information corresponding to a protocol number - asynchronous version hWnd The handle of the window which should receive a message when the asynchronous request completes. wMsg The message to be received when the asynchronous request completes. number The protocol number to be resolved, in host byte order. buf A pointer to the data area to receive the protoent data (supply a buffer of MAXGETHOSTSTRUCT bytes) buflen The size of data area buf above. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber ( HWND hWnd, unsigned int wMsg, int number, char FAR * buf, int buflen ); asynchronous version of getprotobynumber()

17 Additional Asynchronous Socket Routines WSAAsyncGetServByName()WSAAsyncGetServByPort()WSACancelAsyncRequest()WSACancelBlockingCall()WSACleanup()WSAGetLastError()WSAIsBlocking() WSASetBlockingHook(), WSAUnhookBlockingHook() WSASetLastError()WSAStartup()

18 WSASetBlockingHook Application invokes a blocking Sockets operation: the Windows Sockets implementation initiates the operation and then enters a loop which is similar to the following pseudocode: for(;;) { /* flush messages for good user response */ while(BlockingHook()) ; /* check for WSACancelBlockingCall() */ if(operation_cancelled()) break; /* check to see if operation completed */ if(operation_complete()) break; /* normal completion */ } support those applications which require more complex message processing – MDI (multiple document interface) model

19 Web API: Internet Support WININET.DLL supports HTTP, FTP, Gopher protocols General-purpose WinInet Functions InternetOpenInternetConnectInternetOpenUrlInternetReadFileInternetCloseHandleInternetSetStatusCallbackInternetQueryOptionInternetSetOption InternetFindNextFile (FTP and Gopher)

20 Internet Suport (http/gopher protocols) WinInet HTTP Functions HttpOpenRequestHttpAddRequestHeadersHttpSendRequestHttpQueryInfo WinInet Gopher Functions GopherFindFirstFileGopherOpenFileGopherCreateLocatorGopherGetAttribute

21 Internet Support (ftp protocol) WinInet FTP Functions FtpFindFirstFileFtpGetFileFtpPutFileFtpDeleteFileFtpRenameFileFtpOpenFileInternetWriteFileFtpCreateDirectoryFtpRemoveDirectoryFtpSetCurrentDirectoryFtpGetCurrentDirectoryFtpCommandInternetGetLastResponseInfo Most of the WinInet functions work with or return HINTERNETs (handles to Internet). While your code sees all HINTERNETs as the same type, one HINTERNET can mean something completely different from another. The first type of HINTERNET that you obtain comes when you initialize WININET.DLL by calling InternetOpen. This is the first of 13 possible subtypes of HINTERNETs.

22 HINTERNET subtypes Query the subtype of a particular handle by calling: InternetQuery Option and sending it the HINTERNET with the INTERNET_OPTION_ HANDLE_TYPE parameter INTERNET_HANDLE_TYPE_INTERNET1 INTERNET_HANDLE_TYPE_CONNECT_FTP2 INTERNET_HANDLE_TYPE_CONNECT_GOPHER3 INTERNET_HANDLE_TYPE_CONNECT_HTTP4 INTERNET_HANDLE_TYPE_FTP_FIND5 INTERNET_HANDLE_TYPE_FTP_FIND_HTML6 INTERNET_HANDLE_TYPE_FTP_FILE7 INTERNET_HANDLE_TYPE_FTP_FILE_HTML8 INTERNET_HANDLE_TYPE_GOPHER_FIND9 INTERNET_HANDLE_TYPE_GOPHER_FIND_HTML10 INTERNET_HANDLE_TYPE_GOPHER_FILE INTERNET_HANDLE_TYPE_GOPHER_FILE_HTML12 INTERNET_HANDLE_TYPE_HTTP_REQUEST13

23 Windows HTTP Services (WinHTTP) HTTP client API to send requests through the HTTP protocol to other HTTP servers WinHTTP supports desktop client applications, Windows services, and Windows server-based applications WinHTTP offers both a C/C++ application programming interface (API) and a COM automation component use in Active Server Pages WinHTTP 5.1 is an OS component of: WinHTTP 5.1 is an OS component of: Windows Server 2003 family Windows XP SP1 Windows 2000 SP3 (except Datacenter Server)

24 Usage of the WinHTTP API Windows HTTP API exposes a set of C/C++ functions that enable applications to access HTTP resources on the Web

25 Using Internet Functions After setting up WININET.DLL, the initial HINTERNET is usually passed to InternetConnect, parameter indicates the type of connecting server (HTTP, FTP, or Gopher). InternetConnect returns another subtype of HINTERNET, which is then passed to the appropriate HTTP, FTP, or Gopher functions. Alternatively call InternetOpenUrl (parses the URL; connects to the appropriate type of server automatically) After connecting to the desired server: turn to the protocol-specific functions turn to the protocol-specific functions read data from the server via InternetReadFile (works with HINTERNETs for any of the three supported protocols) Before exiting the program: all of the HINTERNETs should be closed by calling InternetCloseHandle. all of the HINTERNETs should be closed by calling InternetCloseHandle.

26 Named Pipes Message oriented: Reading process can read varying-length messages precisely as sent by the writing process Bi-directional Two processes can exchange messages over the same pipe Multiple, independent instances of a named pipe: Several clients can communicate with a single server using the same instance Server can respond to client using the same instance Pipe can be accessed over the network location transparency Convenience and connection functions

27 Using Named Pipes lpszPipeName: \\.\pipe\[path]pipename \\.\pipe\[path]pipename Not possible to create a pipe on remote machine (. – local machine) fdwOpenMode: PIPE_ACCESS_DUPLEX, PIPE_ACCESS_INBOUND, PIPE_ACCESS_OUTBOUND fdwPipeMode: PIPE_TYPE_BYTE or PIPE_TYPE_MESSAGE PIPE_READMODE_BYTE or PIPE_READMODE_MESSAGE PIPE_WAIT or PIPE_NOWAIT (will ReadFile block?) HANDLE CreateNamedPipe (LPCTSTR lpszPipeName, DWORD fdwOpenMode, DWORD fdwPipMode DWORD nMaxInstances, DWORD cbOutBuf, DWORD cbInBuf, DWORD dwTimeOut, LPSECURITY_ATTRIBUTES lpsa ); Use same flag settings for all instances of a named pipe

28 Named Pipes (contd.) nMaxInstances: Number of instances, PIPE_UNLIMITED_INSTANCES: OS choice based on resources dwTimeOut Default time-out period (in msec) for WaitNamedPipe() First CreateNamedPipe creates named pipe Closing handle to last instance deletes named pipe Polling a pipe: Nondestructive – is there a message waiting for ReadFile BOOL PeekNamedPipe (HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage);

29 Named Pipe Client Connections CreateFile with named pipe name: \\.\pipe\[path]pipename \\servername\pipe\[path]pipename First method gives better performance (local server) Status Functions: GetNamedPipeHandleStateSetNamedPipeHandleStateGetNamedPipeInfo

30 Convenience Functions WriteFile / ReadFile sequence: BOOL TransactNamedPipe( HANDLE hNamedPipe, LPVOID lpvWriteBuf, DWORD cbWriteBuf, LPVOID lpvReadBuf, DWORD cbReadBuf, LPDOWRD lpcbRead, LPOVERLAPPED lpa); CreateFile / WriteFile / ReadFile / CloseHandle: -dwTimeOut: NMPWAIT_NOWAIT, NMPWAIT_WIAT_FOREVER, NMPWAIT_USE_DEFAULT_WAIT BOOL CallNamedPipe( LPCTSTR lpszPipeName, LPVOID lpvWriteBuf, DWORD cbWriteBuf, LPVOID lpvReadBuf, DWORD cbReadBuf, LPDWORD lpcbRead, DWORD dwTimeOut);

31 Server: eliminate the polling loop lpo == NULL: Call will return as soon as there is a client connection Returns false if client connected between CreateNamed Pipe call and ConnectNamedPipe() Use DisconnectNamedPipe to free the handle for connection from another client WaitNamedPipe(): Client may wait for server‘s ConnectNamedPipe() Security rights for named pipes: GENERIC_READ, GENERIC_WRITE, SYNCHRONIZE BOOL ConnectNamedPipe (HANDLE hNamedPipe, LPOVERLAPPED lpo );

32 Windows IPC - Mailslots Broadcast mechanism: One-directional Mutliple writers/multiple readers (frequently: one-to-many comm.) Message delivery is unreliable Can be located over a network domain Message lengths are limited (w2k: < 426 byte) Operations on the mailslot: Each reader (server) creates mailslot with Creat slot() Write-only client opens mailslot with CreateFile() and uses WriteFile() – open will fail if there are no waiting readers Client‘s message can be read by all servers (readers) Client lookup: \\*\mailslot\mailslotname Client will connect to every server in network domain Mailslots bear some nasty implementation details; they are almost never used

33 Locate a server via mailslot hMS = Creat slot( “\\.\mailslot\status“); ReadFile(hMS, &ServStat); /* connect to server */ hMS = Creat slot( “\\.\mailslot\status“); ReadFile(hMS, &ServStat); /* connect to server */ App client 0 App client n Mailslot Servers While (...) { Sleep(...); hMS = CreateFile( “\\.\mailslot\status“);... WriteFile(hMS, &StatInfo } App Server Mailslot Client Message is sent periodically

34 Creating a mailslot lpszName points to a name of the form \\.\mailslot\[path]name Name must be unique; mailslot is created locally cbMaxMsg is msg size in byte dwReadTimeout Read operation will wait for so many msec 0 – immediate return MAILSLOT_WAIT_FOREVER – infinite wait HANDLE Creat slot(LPCTSTR lpszName, DWORD cbMaxMsg, DWORD dwReadTimeout, LPSECURITY_ATTRIBUTES lpsa);

35 Opening a mailslot CreateFile with the following names: \\.\mailslot\[path]name - retrieve handle for local mailslot \\host\mailslot\[path]name - retrieve handle for mailslot on specified host \\domain\mailslot\[path]name - returns handle representing all mailslots on machines in the domain \\*\mailslot\[path]name - returns handle representing mailslots on machines in the system‘s primary domain: max mesg. len: 400 bytes Client must specifiy FILE_SHARE_READ flag GetMailslotInfo() and SetMailslotInfo() are similar to their named pipe counterparts

36 WNet API Connection Functions WNetAddConnectionWNetAddConnection2WNetAddConnection3WNetCancelConnectionWNetCancelConnection2WNetConnectionDialogWNetConnectionDialog1WNetDisconnectDialogWNetDisconnectDialog1WNetGetConnectionWNetGetUniversalName Enumeration Functions –WNetCloseEnum –WNetEnumResource –WNetOpenEnum Information Functions –WNetGetNetworkInformation –WNetGetLastError –WNetGetProviderName –WNetGetResourceInformation –WNetGetResourceParent User Functions –WNetGetUser

37 WNetAddConnection connect a local device to a network resource successful connection is persistent system automatically restores the connection during subsequent logon operations lpRemoteName Points to a null-terminated string that specifies the network resource to connect to. lpPassword Points to a null-terminated string that specifies the password to be used to make a connection. This parameter is usually the password associated with the current user. NULL: the default password is used. If the string is empty, no password is used. lpLocalName Points to a null-terminated string that specifies the name of a local device to be redirected, such as F: or LPT1. The case of the characters in the string is not important. DWORD WNetAddConnection( LPTSTR lpRemoteName, // pointer to network device name LPTSTR lpPassword, // pointer to password LPTSTR lpLocalName // pointer to local device name );

38 WNetGetConnection retrieves the name of the network resource associated with a local device. DWORD WNetGetConnection( LPCTSTR lpLocalName, // pointer to local name LPTSTR lpRemoteName, // pointer to buffer for remote name LPDWORD lpnLength // pointer to buffer size, in characters ); lpLocalName Points to a null-terminated string that specifies the name of the local device to get the network name for. lpRemoteName Points to a buffer that receives the null-terminated remote name lpnLength Points to a variable that specifies the size´of the buffer.

39 Further Reading Mark E. Russinovich and David A. Solomon, Microsoft Windows Internals, 4th Edition, Microsoft Press, Networking APIs (from pp. 791) Anthony Jones, Jim Ohmund, Jim Ohlund, James Ohlund, Network Programming for Microsoft Windows, 2nd Edition, Microsoft Press, Ralph Davis, Windows NT Network Programming, Addison-Wesley, 1996.