下沙论坛

 找回密码
 注册论坛(EC通行证)

用新浪微博连接

一步搞定

QQ登录

QQ登录

下沙大学生网QQ群8(千人群)
群号:6490324 ,验证:下沙大学生网。
用手机发布本地信息严禁群发,各种宣传贴请发表在下沙信息版块有问必答,欢迎提问 提升会员等级,助你宣传
新会员必读 大学生的论坛下沙新生必读下沙币获得方法及使用
查看: 2588|回复: 8
打印 上一主题 下一主题

[求助]HZZH进,有关于网络低层控制的问题请教

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。! E# h+ ?: y, b
想编一个程序,实现类似于网通拨号器的功能5 i  e! T) M5 z6 L$ |

& c- j) n+ h1 `10:51:59 Message: 正在打开端口,请稍候...# }, D& K6 t/ o+ `/ ]* }
10:51:59 Message: 端口已经打开
1 l: u& O8 k# d& N4 d6 W+ {10:51:59 Message: 正在连接网络设备,请稍候...
- n7 [- s+ R3 I2 n10:51:59 Message: 网络设备连接成功
. R  I7 Z& U0 S8 v10:51:59 Message: 网络设备已经准备就绪
$ i5 B& \& w. H' |1 C  n10:51:59 Message: 正在验证用户帐号和口令,请稍候...
- O$ d0 w5 T9 B$ u* O: f10:52:00 Message: 正在接收验证/授权过程通知消息' x& A6 {  S. m6 y
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
. Q" ^; w7 O5 s  s- M# t# M3 [! [10:52:00 Message: 正在接收验证/授权过程通知消息. P/ q* S7 \% ~6 Z
10:52:00 Message: 交互过程结束
8 b  v! T+ Z) o! e( v2 [9 X10:52:00 Message: 正在接收验证/授权过程通知消息. E/ h+ U& A& b, `7 m& l
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接3 B5 ^* T4 B, F* L- l' e$ W+ i6 z( E! l
10:52:02 Message: PPPoE连接建立成功
8 x1 G2 l. f! }/ t1 x10:52:02 Message: IP -> 192.168.0.2; ]1 C5 W( o9 ?: M: k- s* L& _
10:52:02 Message: IP -> 218.109.100.70
5 e# U* g( ^5 q- B( E# _10:52:02 Message: IP -> 218.109.98.169
9 u- p. d$ W( m5 |" l* q0 {" n0 i3 m8 R# I
给一个实例的代码好吗?' z$ L! v. B3 ]5 O
我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。* f8 B# v$ ^4 h5 a0 P
我没有编写过ppp之类的软件,没法给你一个实例。. ~0 L7 d1 A+ ^1 l
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
- G0 S% z4 r+ q标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
* X: q3 }/ z. L; z4 y

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:3 g' i/ Z! W+ l' ]. I
我没有编写过ppp之类的软件,没法给你一个实例。) Y- ]" @1 g. u  \9 ~
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
0 v9 _/ p( Y9 @: L 标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
# i; g* l+ t: B
/ e- {/ {- S/ _$ x1 T

: Y$ M3 p& x  A$ }很可惜,真的太可惜了。
  m, M4 b& V7 y, Z标准的拨号只要调用几个简单的API就可以做到了,但就像系统自带的RASPHONE那个程序一样,只是简单地提供拨号过程前后的状态。我想要的是介入拨号过程,唉,我自己再找找资料吧。只是网上这方面的中文资料太冷门了。我找了一个上午也没有找到。

该用户从未签到

4
 楼主| 发表于 2003-9-21 21:51:00 | 只看该作者
Thank you all the same!

该用户从未签到

5
发表于 2003-9-22 18:51:00 | 只看该作者
试试这个,CRasMonitor v1.2, A freeware MFC class to monitor RAS (aka Dial-Up Networking) connections
5 M/ W# }* L) q: U. D9 ~( ^, C+ A9 O5 g
是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息
" `- m. G( P: r4 f4 T- h( o" Z! F/ ^# [- |
http://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。- k/ y$ ^, S- ^9 ^* V* \2 e
有一个RasDial拨号函数的定义如下:
8 q+ J' F+ C$ dDWORD RasDial(" ]5 m) T" P" ]$ B2 u- ]. B0 N2 u, S
LPRASDIALEXTENSIONS dialExtensions, * C0 |/ w! ~0 B
LPTSTR phoneBookPath , ) Z9 t/ O3 n1 |5 g! w9 p; a7 n
LPRASDIALPARAMS rasDialParam , ' N* h8 ~; g/ C7 ]& W& V0 e4 b
DWORD NotifierType,
0 q( u- v. [$ p7 ~9 rLPVOID notifier, ! I0 f) Y4 j9 }# B$ C9 o, d( U- h
LPHRASCONN pRasConn );. U. P, g( t3 `0 K
3 e9 _4 o! z& f
我的MSDN的解说如下:
* x- C: [! C* p; S8 E% n3 b9 jParameters8 T; Q; {' Q, _# X1 Z6 Y+ A
dialExtensions
$ @3 V' W: j, x. BThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
0 A6 v. ~0 I0 L! q5 MphoneBookPath
, n& Y; u% }5 d2 O2 C0 Q0 rThis parameter is ignored and should be set to NULL. Dial-up networking stores phone-book entries in the registry rather than in a phone-book file. + o( {9 [7 N9 ]4 ?9 z( z3 `& @% g
rasDialParam " b8 T$ L% V3 ~' E7 ]
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
) B) Q6 P% }! I- s& N+ }% QThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
2 Q! y: P, e$ ~' c3 |  G6 ^4 w
# ~7 A2 J/ B- L/ x# K& Z# I' BNotifierType & _: e! {: a" I- y  A# G
Specifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
6 m; ?& M! G- B1 yValue Description
- A4 g, _, ^% @0xFFFFFFFF
- X* R* |! t' C9 B1 w0xFFFFFFFF The notifier parameter is a handle to a window to receive progress notification messages. In a progress notification message, wParam indicates the connection state  (rasconnstate) which the RAS connection is about to enter, while  lParam indicates whether or not an error occurred.  " o7 {" n+ p/ k- N; A1 _
The progress notification message uses the WM_RASDIALEVENT message code. # K& z, K8 B" x! @
3 x/ v2 @& e- S' g
) D6 {, M$ h+ o0 _6 _* |

9 m8 o2 \% ^( {0 u, N5 j6 U% q8 |( K1 Z2 T$ y8 ]( F. r6 {
notifier & e& S+ G" t2 N2 j9 l
Pointer to a window handle to receive RasDial event notifications. If this parameter is not NULL, RasDial sends the window a message for each RasDial event. Additionally, the RasDial call operates asynchronously: RasDial returns immediately, before the connection is established, and uses the window to communicate its progress.
. G* l- W9 N1 S5 [) |! d) \If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. $ E$ C4 w( k, x8 i' [" j  u7 }( M
* O0 a. W! j% u! R6 U
If notifier is not NULL, notifications to the window can occur at any time after the initial call to RasDial. Notifications end when one of the following events occurs: % M8 l- z) v/ Q; x
/ k9 c! a- @& ^5 ], L
The connection is established. In other words, the RAS connection state is RASCS_Connected. 0 ?9 Z8 ]4 w$ D; h) j% P; ~6 `% W7 g
The connection fails. In other words, dwError is nonzero. ) n; f; o! Y9 E3 C' I
RasHangUp is called on the connection. ( M# I: m1 n4 _4 L9 V6 w
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
7 r. {# A% \& \: u, z' g% U
0 S* t% u2 g* ~pRasConn ( s& _' n2 Q0 z7 C7 m2 R4 p' N
Pointer to a variable of type HRASCONN. You must set the HRASCONN variable to NULL before calling RasDial. If RasDial succeeds, it stores a handle to the RAS connection into pRasConn. 4 W* S: w5 v3 }$ \
Return Values
* Q+ C" j- {9 E( K; J# OZero indicates success. In addition, the function stores a handle to the RAS connection into the variable pointed to by pRasConn. A nonzero error value, either from the set listed in the RAS header file or ERROR_NOT_ENOUGH_MEMORY, indicates failure.
7 u' a; }! @4 u5 M9 E2 L
( }1 O: J' p/ {* C! KInclude Raserror.h for definitions of the RAS error codes.
% c. ?& x3 v9 D% a+ C# m- ^) `2 Z" m- P8 a# N4 x' N
Remarks5 |! g7 I* M7 z$ t- W4 F9 I% @! \
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.# T/ j+ o  I/ E: l! _
) S: F# U# I  V
RasDial will not automatically display the logon dialog box. This is currently done through the Remote Networking application. Applications are responsible for getting the information from the user.% N/ q, j0 j% i  a
# f* P7 }/ z& M" F: k" D  ^
Errors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection. 2 B7 l/ g( ]4 U4 s2 k" u

6 ?- ^6 Y0 P. i9 q) KAn application must eventually call RasHangUp whenever a non-NULL connection handle is stored into pRasConn. This applies even if RasDial returns a nonzero (error) value. 4 [5 s* Y5 `" f+ ~7 |. ]8 a1 {

2 g, ~8 ?; n9 i8 }& h- @An application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns. 9 I3 K9 d5 Q! c/ Q) L: g) [7 e

; a% {5 W! Q3 u9 |. T5 ?( ^; _# kThe window handle-based notification only works if the underlying configuration supports the PostMessage function. PostMessage is exposed through the msgque component, which is a part of the GWES module. Event notification through a window handle can only work if GWES is part of the underlying configuration.
( F8 G$ O0 C& {* o0 s5 W3 [
# }  Z. Z/ q* ^7 n看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号1 P9 h% S' h) C3 s7 Y
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);6 }, W  e( {' Q1 k9 R
第五个参数是个回调函数,一般都定义如下:
# x/ g( i' M5 Y9 k7 q' m; W: B1 |void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)9 @$ f# y( n# E! i
{
5 K. z  ~+ v% O1 ~) C4 r: R        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
" \* X' Z! p( V% ~. J/ t        3 K3 F* P; C1 [
        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
% O* `7 l0 \$ q/ G( ^8 r}6 I" M- M# N6 h
这个回调函数将会把拨号的状态POST到各个窗口句柄。8 q) x0 E1 }" P  L

9 M) ?$ R+ n! K- h

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃% W; `' X! }1 R) D- A7 O0 ]: ~, B
( K: H) `( {7 ~- n0 t
. W( ]1 c  j/ g
在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出
8 K; O) d1 h9 Q, o: W' u10:51:59 Message: 正在打开端口,请稍候...$ N7 g0 ]! ^) q+ j; k- ^
10:51:59 Message: 端口已经打开
9 \4 R2 E5 ?( l) @  @  K, t' ^. W7 F- o4 e10:51:59 Message: 正在连接网络设备,请稍候...
) k$ \. Z' C6 e/ z7 i9 S' b( C10:51:59 Message: 网络设备连接成功% m8 Z( T/ b' Q( {% h7 N
10:51:59 Message: 网络设备已经准备就绪4 U; j+ q6 |% l; `
10:51:59 Message: 正在验证用户帐号和口令,请稍候.../ H# a% W" U7 X7 l# Q
10:52:00 Message: 正在接收验证/授权过程通知消息- ~% `* ]9 e& O( e5 A
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
' E' s& E% x# S, \10:52:00 Message: 正在接收验证/授权过程通知消息( N+ L7 h$ u* I5 I
10:52:00 Message: 交互过程结束9 T1 U& s3 G: G  ^  l/ P
10:52:00 Message: 正在接收验证/授权过程通知消息
8 M) A6 o- V- R: W10:52:00 Message: 用户帐号/口令验证通过,正在建立连接& k- D& L1 z. Q% d
10:52:02 Message: PPPoE连接建立成功
, _% r  Y; ~& m- C10:52:02 Message: IP -> 192.168.0.2
  n( k3 {: }$ z9 [) u* b2 d10:52:02 Message: IP -> 218.109.100.70
: ^  |5 [; W9 I6 m% X10:52:02 Message: IP -> 218.109.98.169
1 v* P* P  w6 ?% B0 p, N2 l: g5 [- A, Q" r) [

该用户从未签到

8
 楼主| 发表于 2003-11-13 14:55:00 | 只看该作者
很少接触回调函数。好像回调函数要求使用static型的,可是static型的函数用着很麻烦,还不如把消息post到主窗口再进行分流处理。

该用户从未签到

9
发表于 2003-11-22 09:11:00 | 只看该作者
ok

本版积分规则

关闭

下沙大学生网推荐上一条 /1 下一条

快速回复 返回顶部 返回列表