Implement Remote Access Control in the program

Source: Internet
Author: User

Implement Remote Access Control in the program
Author: xrbeck

Remote Access Service (Remote Access Service) is Windows NT,
A remote service provided by Win2000 Server, which allows users
Connect to a local computer network through a dial-up connection.
The connection is equivalent to a local LAN, so you can use a variety
Network functions for access, this article is to introduce this sounds
It is a very dynamic technology.
First, we need to configure the server-side RAS Service. Here we use 2 k Server
For example, first install the modem. I believe it's okay.
After modem, select "network and dial-up connections" in "Control Panel" to create a new connection,
Select "Connect accepted", and add an allowed login in the last step.
In this article, set the User name: XR password: XR, so that on the server side
Establish a "waiting for access" connection, right-click and select properties, in the network
Select TCP/IP Protocol, because the author's LAN is through proxy, static allocation
Reserved IP address 172. 18. So select "specify TCP/IP address"
Two IP addresses are allocated from '192. 18.1.27 "to" 172.18.1.28 ". This is
Because vlsm is a zookeeper, 30 machines are retained in a LAN,
Select the following unassigned IP addresses. Open the management tool in the control panel,
Select Routing and Remote Access, select the local server, and "configure and enable"
Routing and Remote Access. You can view active ports.
In this way, the RAS service is configured on the server. The key is
Part 1: remote applications for RAS connection. We also need telephone lines and modem.
After the installation, we can use the rasapi provided by the system to implement dial-up connections.
Take bcb5.0 as an example: the source code is given as follows:
1. Connect the header file RAS. H, raserror. h, and the library file rasapi. Lib.
Note that there is a version conflict in this area, so temporary settings are required.
The specific code of the variable winver is as follows:
# Define oldver winver
# UNDEF winver
# Define winver 0x400

# Include <RAS. h>
# Include <raserror. h>

# UNDEF winver
# Define winver oldver
# UNDEF oldver
After static connection to rasapi. Lib, we can use the API function to implement dialing.

2. Dial part:
Void _ fastcall tform1: button1click (tobject * sender)
{
//
Hrasconn = NULL;
Rasdialparams Params;
Char Buf [256];
Memset (BUF, 0,256 );

Params. dwsize = sizeof (rasdialparams );

Lstrcpy (Params. szentryname ,"");
Lstrcpy (Params. szphonenumber, "208 ");
Lstrcpy (Params. szusername, "XR ");
Lstrcpy (Params. szpassword, "XR ");
Lstrcpy (Params. szdomain ,"");

Int ret = rasdial (null,
Null,
& Params,
0,
& Rasdialfunc,
& Hrasconn );
If (Ret! = 0)
{
Rasgeterrorstring (Ret, Buf, 256 );
Memstatus-> lines-> Add (BUF );

}
}
Here, rasdial is an asynchronous access method, and 208 is an internal company tested by the author.
The server phone number. XR is the login user name and password, because
The 2 k server tested is a common member of the peer network, without domain,
So it is set to null.

3. callback function:
Like most window programs, Ras also provides callback functions.
Asynchronous processing of connections is often the case. For example, Winsock also provides
Window message asynchronous mode.
Void winapi rasdialfunc (uint MSG, rasconnstate, DWORD dwerror)
{
//
Char szrasstring [256]; // buffer for storing the error string
Memset (szrasstring, 0,256 );
DWORD cb = sizeof (raspppip );
DWORD ret;

If (dwerror) // error occurred
{
Rasgeterrorstring (uint) dwerror, szrasstring, 256 );
Form1-> memstatus-> lines-> Add (szrasstring );
Return;
}
Switch (rasconnstate)
{
// Running states
Case rascs_openport:
Form1-> memstatus-> lines-> Add ("opening port ...");
Break;

Case rascs_portopened:
Form1-> memstatus-> lines-> Add ("port opened .");
Break;

Case rascs_authenticated:
Form1-> memstatus-> lines-> Add ("authentication complete .");
Break;

Case rascs_connected:
Form1-> memstatus-> lines-> Add ("connection connected .");

Form1-> lpprojection = new raspppip;
Form1-> lpprojection-> dwsize = sizeof (raspppip );
If (rasgetprojectioninfo (form1-> hrasconn, rasp_pppip, form1-> lpprojection, & CB) = error_success)
{
Form1-> memstatus-> lines-> Add ("Server IP:" + (ansistring) (form1-> lpprojection-> szserveripaddress ));
Form1-> memstatus-> lines-> Add ("local IP:" + (ansistring) (form1-> lpprojection-> szipaddress ));
}
Break;

Case rascs_disconnected:
Form1-> memstatus-> lines-> Add ("disconnecting ...");
Break;

Default:
Form1-> memstatus-> lines-> Add ("unknown status ");
Break;
}
}
Processes various messages. Use rasgetprojectioninfo to connect to the connection.
The allocated IP address and server address. Because it is statically allocated
The client is in a subnet, and various resources can be used, for example
If the wnet series functions are used in the LAN, or a socket is created after the connect event,
To achieve transmission, the author tests the following: after the client network cable is unplugged, the connection can be pinged
Other machines in the LAN, and because they are in the subnet, they can also access the Internet, using the iPhone per
The subnet mask returned by the function is the same as that returned by the gateway.

This article describes what RAS is and how to program and implement the RAS service.
This is a convenient and powerful function. I hope it will help you.
Discussion. qq.33854303

Test environment: client bcb5.0 + win98. server: Win2000 Server

Reference books: Windows Network Programming
Programming with Internet and TCP/IP: C ++ Builder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.