下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。) C8 {* _0 d* b/ z' ^9 F' j& R+ U- a# p
想编一个程序,实现类似于网通拨号器的功能
( ?& |5 E, y' L  T( ~# ]" m
- z* @- N7 V, l% g+ M) U# w" V& `10:51:59 Message: 正在打开端口,请稍候...
$ S% Z. e2 c& _( R6 g10:51:59 Message: 端口已经打开5 w) f0 r9 H$ ]2 `, f7 |, L
10:51:59 Message: 正在连接网络设备,请稍候...
0 \% A: h/ S" j. q10:51:59 Message: 网络设备连接成功
3 P( t9 y" O, m. j7 b' ^  E10:51:59 Message: 网络设备已经准备就绪
  s+ T: a3 I) R9 g; e! m10:51:59 Message: 正在验证用户帐号和口令,请稍候...
; U! K8 [: D  X0 n, J0 M! L10:52:00 Message: 正在接收验证/授权过程通知消息! u3 X$ h' d; `7 g. U4 Z; J
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
1 }) s- h0 X$ ~% ^5 \2 A4 E10:52:00 Message: 正在接收验证/授权过程通知消息' J# [) E0 `/ s  {
10:52:00 Message: 交互过程结束/ |$ v' a2 p/ I' x
10:52:00 Message: 正在接收验证/授权过程通知消息/ f5 Q" M; v1 R7 ]
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
# C( l) D- N9 ?- q- V9 N  [) b) e10:52:02 Message: PPPoE连接建立成功
7 p& |; k* j! p4 G( _10:52:02 Message: IP -> 192.168.0.25 w+ `" }0 |+ }/ ~( y5 j: }
10:52:02 Message: IP -> 218.109.100.70
( |; d5 n2 @# I) U+ D9 C* H10:52:02 Message: IP -> 218.109.98.169
' C- F3 u% m; s% @
8 D$ {% a, ~6 f4 p+ O给一个实例的代码好吗?
7 H+ h: c2 O# E( v3 @2 |' p我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。* K. X+ d- H- Y' {. `, o: G8 z+ w' f
我没有编写过ppp之类的软件,没法给你一个实例。0 C5 O) ?! M( K8 N. `
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
, M. {) I9 I1 v* R: _( p$ S标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API+ G; t+ W' z5 z# @

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:$ e* v  K* v7 J
我没有编写过ppp之类的软件,没法给你一个实例。0 M) d* E0 {- T( I$ v: h; u7 }
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。9 c8 a6 R2 y: h( Y
标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
5 [& D8 A7 H( t- @

# l- A+ a9 O* Y/ H# A1 V& ?: s0 T9 X& j6 h
! |5 w/ a- y- S很可惜,真的太可惜了。! b: _: P( S5 W5 m
标准的拨号只要调用几个简单的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) connections4 M, J" t1 R+ i( _- U- r0 v; B
. e, U& q3 d$ K4 t$ S3 V* E
是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息6 c$ T. `: [- \, |9 o

* z! {  a" K- n  O9 F. Vhttp://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
: V1 `- |4 x- U$ N有一个RasDial拨号函数的定义如下:
: |% X/ f+ F* R6 JDWORD RasDial(8 S; }& p# P* U7 j2 U. ^
LPRASDIALEXTENSIONS dialExtensions,
. M, d6 m' t& P2 x* c. t: ULPTSTR phoneBookPath , % h! N' i6 u, x6 K6 j3 d3 H0 T
LPRASDIALPARAMS rasDialParam ,
7 @, Q8 F' X8 G+ J. }( p' MDWORD NotifierType,
6 O4 S! P2 N/ R4 U$ lLPVOID notifier, 2 h& R, {9 r. }. }
LPHRASCONN pRasConn );* P5 g* r/ Z& S; x- b* F
9 Y- }: Y" Z' s8 G* O3 `
我的MSDN的解说如下:
  R* ]# S, r; F# W  TParameters; m2 j0 ~$ m7 S. k; I$ [
dialExtensions
+ n, b0 d7 m# zThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
0 J  b! s4 H3 Q2 [& x1 ]$ `phoneBookPath $ k- X8 c  m. I3 q/ h& {8 @: ]  D
This 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.
5 Q) k# {/ Z; TrasDialParam 6 [' g2 C2 b+ g; }
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. 0 Z" d! `/ `* N2 \1 H
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
; C% \: r+ C4 q& B' V% n' E6 Y, J; G4 x3 o
NotifierType
. `) ]. {) v% m3 U  OSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: & a9 ^3 m$ r: ^! ?! j6 T9 ^" R
Value Description , K; X* h, n% }* D2 _, F( c
0xFFFFFFFF$ j$ |$ K/ L& d; Q
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.  
/ E5 f% _0 w0 |$ U3 Z: [5 L The progress notification message uses the WM_RASDIALEVENT message code. 6 q  r' ^4 O0 R. k+ S8 c: @' Y0 n

) h/ M8 Y6 n0 R# \2 T6 _
' E; p* E1 U( h5 n% n( B  X) p& L3 D/ R

, ~" R  d( c3 c/ G, h# {4 rnotifier ) }5 R  G$ h# h2 M& V$ F# v* j
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.   ]+ l- L( z! D  T
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. 1 P# b. J* x8 {: V
, [& X3 N7 Z( }0 w+ \# \, _6 j
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: # \! Q0 G/ N7 G* d* G7 q* s) S9 V

7 Y5 e  _2 Z7 {" s1 e5 T2 ^" HThe connection is established. In other words, the RAS connection state is RASCS_Connected. % \3 `/ C9 ]9 K$ `" g
The connection fails. In other words, dwError is nonzero. ! ^/ W: k& @1 T$ V2 J! x
RasHangUp is called on the connection.
4 ^4 U: a# `* ?* tThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
! a5 q% l! s" ]- n  l# R, x! J
0 A+ t! `1 D" k9 gpRasConn . W# e+ M6 R$ y, x) d, V
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.
  F5 I4 l+ w6 w* ^! {Return Values$ ^. e* @" z* f
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.
' H8 Y3 g5 m% ~, a
* O: v9 G( N- c9 C" YInclude Raserror.h for definitions of the RAS error codes.) w( ^/ k5 d% V* ~, c- Q* y7 S- k

. x, [' H% g) v5 O; `+ i* @Remarks) e* z! B% V& S! L
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.( i, s" ?; C; ^

/ p9 O! n5 f5 e. ~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.
  Q* E3 K2 ^  E1 W5 e$ c6 Q  N6 @
; N/ O9 m2 x/ }+ Q$ cErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection. & ~* [1 o2 _6 k9 o* [: `8 l. b

- o) a' c' ^3 V' m- |' h, }5 c8 cAn 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.
9 D3 m* W4 i" E7 q5 Z, \3 p. o1 r* }
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. * v( C2 m/ L6 g

4 k, J; G% V4 \% zThe 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/ q4 z# B3 T" x4 f
7 g7 E3 J7 j. N' P' \3 M看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号' _) B6 }8 Q. b3 U$ l
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
" G$ l2 X, I; p. @! ^4 Z第五个参数是个回调函数,一般都定义如下:6 s; P$ g6 X) g
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)2 Y8 y, v3 \3 h5 w* E' d4 ?9 U
{8 [( n1 f/ D( K3 I
        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;5 B3 q6 D0 V* }( {$ [; W
       
2 a1 `0 x! x6 S' r. }* v# ]1 A        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);0 r' }' F! }9 E" r
}. N* N( c2 h3 a5 |
这个回调函数将会把拨号的状态POST到各个窗口句柄。
  N7 s' {3 l) O9 _2 n6 y' f! _- r6 @9 ]

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃
, |7 O4 D- |4 z! ?7 w. M8 c4 v# r! @$ O
/ x2 {" d& m( a2 k% {5 D
在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出! {2 K" i' w& w+ k& h
10:51:59 Message: 正在打开端口,请稍候...( u# f+ P! {; h, E$ ?0 C
10:51:59 Message: 端口已经打开
5 S* R  G- l1 }& `10:51:59 Message: 正在连接网络设备,请稍候...
) Z" V, b0 d4 S10:51:59 Message: 网络设备连接成功
7 Q6 Q8 d( D% t: P; b5 g; v10:51:59 Message: 网络设备已经准备就绪( D4 I( w0 Y/ I% W; Q
10:51:59 Message: 正在验证用户帐号和口令,请稍候..." C. Y$ r9 Q$ P+ A, s7 ?
10:52:00 Message: 正在接收验证/授权过程通知消息0 [* O" Z3 p" ^3 H& z+ q% V6 d
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
8 T9 Z! W9 r* p, J: }10:52:00 Message: 正在接收验证/授权过程通知消息3 |# a( {$ w% o& w/ @0 N  B# F
10:52:00 Message: 交互过程结束, f7 F; X! W: L5 E, F% p* s
10:52:00 Message: 正在接收验证/授权过程通知消息
& S+ m: `6 O9 S4 ~- {' @" h0 w10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
  X) K: S( k1 M# x: [- R( }  z$ D0 |10:52:02 Message: PPPoE连接建立成功
) m% ]" H9 K' ?+ |% f0 Q7 u10:52:02 Message: IP -> 192.168.0.2
+ n+ L' L7 O4 ^# A+ i( J10:52:02 Message: IP -> 218.109.100.70
/ H: @& R% F- m: i# m5 s10:52:02 Message: IP -> 218.109.98.169& @* g, ?8 D" V0 C6 p

+ |& H! f9 t+ g9 m0 [; T: X9 |

该用户从未签到

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

该用户从未签到

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

本版积分规则

关闭

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

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