PPPoE协议

这篇文章由 在 星期日, 14 三月, 2010 发表。

Option Explicit
Public hRasConn As Long ‘定义一个指向RAS调用的全局句柄
Public Const APINULL = 0&
Public Const UNLEN = 256
Public Const DNLEN = 15
Public Const PWLEN = 256
Public Const RAS95_MaxPhoneNumber = 128
Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxCallbackNumber = RAS95_MaxPhoneNumber

‘dwSize表示该结构的大小(以字节为单位)。
‘szEntryName表示一个远程访问的入口名,也就是WINDOWS下的拨号网络中的连接图标小的文字;
‘szEntryName参数可是是空串,表示仅与第一个有效的MODEM建立远程连接。
‘szPhoneNumber为表示呼叫的号码。当szEntryName是空时,
‘zPhoneNumber不能为空。szCallbackNumber表示回叫号码,一般都设为空。szUserName为建立远程访问的用户名。
‘szPassword为建立远程访问的密码。szDomain为进行远程访问用户名和密码认证的域名。
‘我们将szDomain设为空,表示远程访问的服务器也是该域名下的成员
Public Type RASDIALPARAMS95
dwSize As Long
szEntryName(RAS95_MaxEntryName) As Byte
szPhoneNumber(RAS95_MaxPhoneNumber) As Byte
szCallbackNumber(RAS95_MaxCallbackNumber) As Byte
szUserName(UNLEN) As Byte
szPassword(PWLEN) As Byte
szDomain(DNLEN) As Byte
End Type
‘**********************************
‘* RAS调用错误代号 *
‘**********************************
Public Const NOT_SUPPORTED = 120&
Public Const RASBASEERROR = 600&
Public Const SUCCESS = 0&
Public Const ERROR_PORT_ALREADY_OPEN = (RASBASEERROR + 2)
Public Const ERROR_UNKNOWN = (RASBASEERROR + 35)
Public Const ERROR_REQUEST_TIMEOUT = (RASBASEERROR + 38)
Public Const ERROR_PASSWD_EXPIRED = (RASBASEERROR + 48)
Public Const ERROR_NO_DIALIN_PERMISSION = (RASBASEERROR + 49)
Public Const ERROR_SERVER_NOT_RESPONDING = (RASBASEERROR + 50)
Public Const ERROR_UNRECOGNIZED_RESPONSE = (RASBASEERROR + 52)
Public Const ERROR_NO_RESPONSES = (RASBASEERROR + 60)
Public Const ERROR_DEVICE_NOT_READY = (RASBASEERROR + 66)
Public Const ERROR_LINE_BUSY = (RASBASEERROR + 76)
Public Const ERROR_NO_ANSWER = (RASBASEERROR + 78)
Public Const ERROR_NO_CARRIER = (RASBASEERROR + 79)
Public Const ERROR_NO_DIALTONE = (RASBASEERROR + 80)
Public Const ERROR_AUTHENTICATION_FAILURE = (RASBASEERROR + 91)
Public Const ERROR_PPP_TIMEOUT = (RASBASEERROR + 118)
‘**********************************
‘* RAS API 声明 *
‘**********************************
Public Declare Function RasDial Lib “RasApi32.DLL” Alias “RasDialA” (lpRasDialExtensions As Any, ByVal lpszPhonebook As String, lprasdialparams As Any, ByVal dwNotifierType As Long, lpvNotifier As Long, lphRasConn As Long) As Long
‘RASHANGUP函数用于断开一个RAS连接。其参数hRasConn为指向一个RAS连接的句柄
Public Declare Function RasHangUp Lib “RasApi32.DLL” Alias “RasHangUpA” (ByVal hRasConn As Long) As Long
Public Declare Function lstrcpy Lib “kernel32” Alias “lstrcpyA” (lpString1 As Any, ByVal lpString2 As String) As Long

Public Function AddConnection(strNewEntryName As String, strNewPhoneNumber As String, strNewCallbackNumber As String, strNewUsername As String, strNewPassword As String, strNewDomain As String) As Integer
Dim lngRetCode As Long
Dim lngRetLstrcpy As Long
Dim lngRetHangUp As Long
Dim lprasdialparams As RASDIALPARAMS95
lprasdialparams.dwSize = 1052
‘在WINDOWS95/98中必须将dwSize设为1052’利用lstrcpy函数将字符串拷贝到BYTE数组
lngRetLstrcpy = lstrcpy(lprasdialparams.szEntryName(0), strNewEntryName)
lngRetLstrcpy = lstrcpy(lprasdialparams.szPhoneNumber(0), strNewPhoneNumber)

lngRetLstrcpy = lstrcpy(lprasdialparams.szCallbackNumber(0), strNewCallbackNumber)
lngRetLstrcpy = lstrcpy(lprasdialparams.szUserName(0), strNewUsername)
‘MsgBox (lprasdialparams.szUserName(0))
lngRetLstrcpy = lstrcpy(lprasdialparams.szPassword(0), strNewPassword)
lngRetLstrcpy = lstrcpy(lprasdialparams.szDomain(0), strNewDomain)
‘我们使用同步通信
Screen.MousePointer = vbHourglass
hRasConn = 0
lngRetCode = RasDial(ByVal APINULL, vbNullString, lprasdialparams, APINULL, ByVal APINULL, hRasConn)
Screen.MousePointer = vbDefault
‘测试有没有错误
If lngRetCode Then
lngRetHangUp = RasHangUp(hRasConn)
End If
AddConnection = lngRetCode
End Function
Public Sub RemoveConnection(H_RasConn As Long)
Call RasHangUp(hRasConn)
End Sub


Leave a Reply