下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。
9 h2 t, I) z, z) N  P想编一个程序,实现类似于网通拨号器的功能
6 h! ~9 H' W2 q) V+ d
) x5 w  {! z. a* T  x10:51:59 Message: 正在打开端口,请稍候...
8 }2 x3 d3 w6 u, k' m# S( d, [& a10:51:59 Message: 端口已经打开
- Z: B0 F% b% P7 t$ Q' v10:51:59 Message: 正在连接网络设备,请稍候...) t% T) m3 N/ A! B, t2 n0 m1 e
10:51:59 Message: 网络设备连接成功
3 Q) j4 y) J& T! t7 S6 m" E$ M# E2 _10:51:59 Message: 网络设备已经准备就绪
9 t! v* F. U: w  R0 K10:51:59 Message: 正在验证用户帐号和口令,请稍候...
, i. g8 T! n# J10:52:00 Message: 正在接收验证/授权过程通知消息9 C: S( P/ C- f) O# x6 }+ n
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
& Q. o1 N# ?# Q" o10:52:00 Message: 正在接收验证/授权过程通知消息
* c  N1 y# k: K, O2 `; e10:52:00 Message: 交互过程结束2 D* P3 P; I' e  Z% L- W' |7 m
10:52:00 Message: 正在接收验证/授权过程通知消息
( o" l! p( ]! V  H( j10:52:00 Message: 用户帐号/口令验证通过,正在建立连接$ z  u- x9 e* u- i
10:52:02 Message: PPPoE连接建立成功
( ~: `6 r' d. V10:52:02 Message: IP -> 192.168.0.2  D8 {6 B: b& A8 H- a
10:52:02 Message: IP -> 218.109.100.70
, r3 B0 s4 w, _( H10:52:02 Message: IP -> 218.109.98.169
7 H2 l4 \8 x: g9 b
- v. m6 O& t$ I8 [9 c  h3 u# m给一个实例的代码好吗?! |; _1 n& V+ l" D
我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

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

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃
" k) T0 _% l! F: B4 t5 G& V
# u2 `  @* H0 p. L# {4 }
3 {% L8 _/ L& k/ d在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出
! o, y9 a. P4 v10:51:59 Message: 正在打开端口,请稍候...
8 [3 k1 h0 T' l- A10:51:59 Message: 端口已经打开/ L( o  y, R3 R' n& Y
10:51:59 Message: 正在连接网络设备,请稍候...; ~, s. p) U5 [! v6 {8 f' A0 N
10:51:59 Message: 网络设备连接成功
9 M4 i8 Z1 R' n7 _6 L3 ?10:51:59 Message: 网络设备已经准备就绪
5 V* g$ ?- f2 o2 e$ h7 c10:51:59 Message: 正在验证用户帐号和口令,请稍候.... E' @# P( B  e4 f$ H  `( h8 v0 k# a
10:52:00 Message: 正在接收验证/授权过程通知消息
  N: y1 o$ o# m3 G1 ^10:52:00 Message: 正在与服务器进行数据交互,请稍候...; P7 Z" ^+ |' b9 s! \5 A1 w4 n- k) v1 u
10:52:00 Message: 正在接收验证/授权过程通知消息; e% h* ]0 A5 o& A4 m' }- o
10:52:00 Message: 交互过程结束; Z/ v2 i2 i8 A% @& r9 L
10:52:00 Message: 正在接收验证/授权过程通知消息
" x8 o# B/ u  q/ K6 ^* H10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
+ @5 T$ c; B  C2 n6 x, Z9 k7 m10:52:02 Message: PPPoE连接建立成功
- j5 y' q4 Q+ b8 U6 l10:52:02 Message: IP -> 192.168.0.2
, a6 Q3 }4 }, B/ h2 \1 _9 S  X10:52:02 Message: IP -> 218.109.100.709 z* {9 \9 _( B; k
10:52:02 Message: IP -> 218.109.98.169
' D  x4 R( s4 C0 S
8 z7 p: ]5 S2 a

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
4 a7 b/ o+ O, i6 z5 c有一个RasDial拨号函数的定义如下:
' {* Q  e4 H" W! V$ Y0 SDWORD RasDial(3 a7 D0 Q) p4 ^3 A8 G! L) `
LPRASDIALEXTENSIONS dialExtensions,
" Q" g  H  `7 E' P' P% @; `LPTSTR phoneBookPath ,
+ G* l! G$ w0 ]" wLPRASDIALPARAMS rasDialParam , . C% e. Q  |- o  A  l9 H
DWORD NotifierType, & s( o8 A( s! ^. x
LPVOID notifier,
: U% b# i( X9 h' |+ i' h8 QLPHRASCONN pRasConn );9 t5 f( w' h# F( e9 M
+ N6 ^- Z& A) X6 f* ~
我的MSDN的解说如下:! }) E- o4 a' k) j6 v$ C& ?4 s3 [$ S
Parameters; W0 C- g. p; L. e3 k, o
dialExtensions
3 U: ?/ B  `- c+ ~This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. / {% F/ [2 c# `; C
phoneBookPath
# c/ E/ D! _, k" C1 _8 P7 gThis 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.
0 ^* m7 {0 J$ w4 d" crasDialParam
. D+ {* ]5 a( S/ T+ zPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
3 }# v+ ~( X9 l0 {4 C& ^The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
% x2 }, Y3 m' l- z; X1 `
: `( s8 z! T( a# iNotifierType
, I2 P& P: I  H, e1 E7 S* F7 ZSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
: T3 s. V  ]9 W2 f. d! ~Value Description " }; _* [, b3 o9 M$ |( t
0xFFFFFFFF
  X1 c' x+ F& X2 {0xFFFFFFFF 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.  1 Z, u8 Z2 U. n7 o
The progress notification message uses the WM_RASDIALEVENT message code. ! W& ~. y- ^/ h4 }+ x
" I; P  a8 A  _) O' S  L
5 Y* y" S8 a$ f7 V) _- Y) d$ H
3 V# \7 z1 G! @1 s( M
- Q% ^# U( n$ k0 U1 P+ u' Q0 O2 t0 N
notifier 8 I5 D3 m# E  c2 m: I
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.
- F) b4 P' n) @If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.   \- F' R1 k: V9 m$ J0 R9 u" H

/ E) [1 J' B9 }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:
5 ^% ]' d1 \  n2 n/ j6 O3 x
( G$ c  N5 a! u2 m& H2 vThe connection is established. In other words, the RAS connection state is RASCS_Connected. 6 A  A, F0 k8 `& M) p1 x3 k- v
The connection fails. In other words, dwError is nonzero.
3 E+ r" \0 H6 p% t- Y2 |' kRasHangUp is called on the connection.
$ t( C* A& j2 T3 g1 T0 R# L8 bThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
: a7 ?& m  A$ n0 K7 z; Y, v
2 z4 H3 l" z" J6 dpRasConn , ?) T) j6 j* |6 _
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.
" l# B# T$ g3 l8 K0 |3 ~. [" yReturn Values  y8 ]2 I+ {8 S% d' s
Zero 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.
& W0 L# {. n2 L
( [; ^3 H" T1 VInclude Raserror.h for definitions of the RAS error codes.
4 r7 T; F9 w5 i9 u1 O2 Y, e( M7 V
% Q( t& k4 h' E) `. MRemarks# _/ d9 k( Q. G
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL., ?( U, O0 a3 K3 h

5 W- k6 |3 ]+ H2 I1 F  }. Q+ U3 kRasDial 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) T* m) w. G# |, ~* E
' ]* n$ {% M4 }; n' hErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection.
' X; l9 u3 }: J# w: ?9 C* G
1 ]7 S! s3 u5 ]4 ^6 w9 V" EAn 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.
6 T8 t. ?, o  x8 a& H
, M' w! o: z8 f# n0 q& k0 Q/ f# a& BAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns.
" N6 C9 w9 I+ M! E8 ~/ h. C8 l+ e+ `6 W: h% @
The 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. + s+ W* Z, Q. I+ j- v
( @  [0 u5 F4 R. G( O/ V
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号7 [3 j2 Z% W1 ]3 _
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
$ w8 O+ r# a/ ~. ^6 K第五个参数是个回调函数,一般都定义如下:5 l, }7 X! C2 K, a) i+ n4 d( @
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
/ k7 y* A5 Z  y{
1 Z" l( d; l, k- z1 A4 w" \        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;* _0 i- J* d1 L: j' c% c& O
        4 R& N  U: y/ S  [, a
        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
4 E2 E6 c4 d$ `( \" V$ L: j}3 H6 ^. f( o4 t9 P- J
这个回调函数将会把拨号的状态POST到各个窗口句柄。
) q8 g# K. t# n
: H' s+ ~- D5 K0 s6 X5 Y

该用户从未签到

5
发表于 2003-9-22 18:51:00 | 只看该作者
试试这个,CRasMonitor v1.2, A freeware MFC class to monitor RAS (aka Dial-Up Networking) connections2 a% N* L9 ]5 N% P1 N, J

) m. E5 s7 m- N. S; Q是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息" Y" a9 l) y7 Y. i! N
- C! @9 B/ J1 V
http://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:- V8 x$ s  J+ X. }9 C$ x
我没有编写过ppp之类的软件,没法给你一个实例。# y9 O( M5 L# ~0 P+ v
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
9 ^8 K* y) [5 n$ M& }- z, f+ }. G 标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API* k0 W7 f( N3 J3 Y( K% y
9 R9 y! N7 P6 G. I
3 v: ~7 D" B: x' i8 T6 I
很可惜,真的太可惜了。$ `! C/ {  h3 Z* Y' r" o3 h
标准的拨号只要调用几个简单的API就可以做到了,但就像系统自带的RASPHONE那个程序一样,只是简单地提供拨号过程前后的状态。我想要的是介入拨号过程,唉,我自己再找找资料吧。只是网上这方面的中文资料太冷门了。我找了一个上午也没有找到。

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。7 R9 w$ a0 m" V5 h4 u7 i
我没有编写过ppp之类的软件,没法给你一个实例。
& P( i% s; d+ y我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
7 s6 D' u) z1 x6 T, \2 ]标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
7 h# g: w5 }' L0 y0 H
关闭

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

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