下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。3 m3 u) `2 H5 a0 c2 T; D
想编一个程序,实现类似于网通拨号器的功能' C5 p: @' ^( ]. Y; t# K2 a
6 e4 ~" R. B) Q
10:51:59 Message: 正在打开端口,请稍候...* ^/ ]; ~1 E5 I' ~
10:51:59 Message: 端口已经打开5 s4 X* ?- d5 h5 N' i
10:51:59 Message: 正在连接网络设备,请稍候...& L3 G# o" ~+ I" s5 v! _+ A
10:51:59 Message: 网络设备连接成功
  ^1 L6 }, U( ]2 k1 d' _( C10:51:59 Message: 网络设备已经准备就绪
6 w" S* S6 Z1 C3 \' u! p10:51:59 Message: 正在验证用户帐号和口令,请稍候...9 k( S- }" z3 M) R* L, @' K6 x) W) y
10:52:00 Message: 正在接收验证/授权过程通知消息
# o' `( d( S) l1 t" r10:52:00 Message: 正在与服务器进行数据交互,请稍候...
3 d. F8 E) i  W% {6 X! y5 X10:52:00 Message: 正在接收验证/授权过程通知消息
& O; u2 r7 m2 h1 N+ R; D10:52:00 Message: 交互过程结束
7 n5 b! b3 p( S8 N  n' A5 ^4 G0 ^! Y10:52:00 Message: 正在接收验证/授权过程通知消息
; U* f% {7 k& f  S5 u$ l10:52:00 Message: 用户帐号/口令验证通过,正在建立连接3 S. W6 \! U9 H7 R& k5 b2 E
10:52:02 Message: PPPoE连接建立成功
5 z4 O- d+ }- v' f10:52:02 Message: IP -> 192.168.0.2
* v- n% P0 ]3 }, P1 i$ O10:52:02 Message: IP -> 218.109.100.70
9 \* e5 a# r3 `' q9 J. ?10:52:02 Message: IP -> 218.109.98.169
' e+ X% N9 Z$ J3 ~3 c3 S' O1 i! _9 B0 i
给一个实例的代码好吗?. Q* S+ J5 q2 J/ k, ~" I  b
我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。: ^6 K  V9 l5 m/ ~1 P
我没有编写过ppp之类的软件,没法给你一个实例。6 w8 J. J2 E/ k$ n
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
1 C5 a3 K' S+ }" \: _+ K标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API% x9 X: r3 c# e7 l8 n. v+ I

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:7 G% k4 b; W: h
我没有编写过ppp之类的软件,没法给你一个实例。+ }6 E6 c- n# Y' Z( E3 O9 a
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。8 a: |- v9 _" V
标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API# d/ q  r, m0 I: n) j
: e1 S4 j! @9 A8 q+ d

3 f0 t* g! ]% k+ a很可惜,真的太可惜了。# w0 b* J# m# H) }9 |) X% K# X. [
标准的拨号只要调用几个简单的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) P. y! K3 m4 ^. N; t

- k1 m: @5 w. I% ?( ~是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息
% H4 w, y4 ]% b$ y1 Y8 o- E$ A
  I* E: u1 K* ]3 ?! @: Y2 fhttp://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。% z, _4 w+ @* n2 V' E7 T4 X* [7 ?
有一个RasDial拨号函数的定义如下:) W% b' u; c: |+ _; p$ q0 y
DWORD RasDial(
9 \5 t  u$ u' U* {7 R3 zLPRASDIALEXTENSIONS dialExtensions,
; q0 }1 x+ B% ^# |* Z9 g' Z2 jLPTSTR phoneBookPath ,
2 S- z6 b; P" v8 y) S$ tLPRASDIALPARAMS rasDialParam , - {3 k4 c8 q3 u$ q
DWORD NotifierType, $ D7 P! j8 B1 ?5 j
LPVOID notifier, 5 @' o( Z/ b0 r% d: h0 p9 `2 B$ v
LPHRASCONN pRasConn );+ a% L1 @  C: a" u6 M0 }/ r

# Z$ W" w! q/ C. N4 z2 g4 D我的MSDN的解说如下:
4 ]9 v+ R, x- R  j0 d& FParameters" i1 U8 b  x: V. c" t
dialExtensions
. p3 }/ ^) \" B/ QThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. ; }9 s' r) _( A0 ]6 @- _4 H
phoneBookPath
7 ~9 s. p' \, }: W( o4 V1 h( DThis 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.
  M/ A7 x3 n. Q/ xrasDialParam - o1 A. Y6 ?0 K* K5 Q! ?) n8 }5 ~% q
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
- G& k2 D7 n' o, R* P4 vThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. 4 x7 g8 q' |% t

7 s/ X: R+ V4 [; l% H- p8 `9 LNotifierType
. z/ F6 T; h) O$ GSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
+ c2 ^! F9 z% C1 q+ L2 }2 pValue Description
% G7 P, w6 F' ^9 Y$ y+ z# E: I# J0xFFFFFFFF
" J' ?+ b* k( T/ r' O- U1 s3 b, j0xFFFFFFFF 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.  
5 Y. u1 ]# n, |  ^4 o9 q2 D The progress notification message uses the WM_RASDIALEVENT message code.
% ~! x0 b& }- J  M- k. t- N& x& ^
) p$ I; e) w+ m( L, n
* j3 \6 `: d6 U' e# T$ x2 k! J3 R9 h4 e3 C

' N' K, _  ]/ l& Rnotifier
0 }* X4 F2 S, I9 z" }; J, K! m+ xPointer 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. * _& k) d( v/ w8 a2 n0 |
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
+ w" H0 {2 R2 f, c  @
! F0 T! V$ M" a4 x7 Z9 T( i; u5 VIf 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: 1 Z, r& P# {/ @( u

" m3 }$ D9 f0 O2 o: j+ w* uThe connection is established. In other words, the RAS connection state is RASCS_Connected.
8 C3 ~( a. I2 H* y6 u" vThe connection fails. In other words, dwError is nonzero. . j1 E! y. N$ N0 l- |0 p
RasHangUp is called on the connection. 6 K9 D) n  m$ \7 \" |; H
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
* {' B+ n3 @+ i, @9 f( X) q: Y. v: r& h8 U, H
pRasConn
5 X: {' P/ N: w, RPointer 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.
( |" P2 y) |; p! ~  m% g3 ?  lReturn Values
: U: z$ Q8 u' j, B1 TZero 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.
0 ~; e5 s- \4 `  ?3 |, U+ O0 o2 a# U9 P6 ?
Include Raserror.h for definitions of the RAS error codes." k% `5 k! T2 X  e8 s. d
$ C' G2 ^% ]3 l' ]& T
Remarks/ M% _7 L  ?* T
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.7 {5 |9 B0 I5 W1 h5 l0 u4 B; K
  f9 g8 f# L6 s' `. [" @
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.* g6 a4 G! J4 C5 _6 s
4 H9 ?; c( x: C& \- R' @/ b
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.
/ s/ s4 W& G: ]( z1 [- n: q1 q% A% R; v2 e' J! E2 v0 u2 h
An 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. 3 B4 g: d  V+ K! ]6 K

+ G  _: o  H: [# A! R! LAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns. . a7 G1 S3 v/ q" m' ?% J+ u

2 e  c$ ]' c1 T5 b; G! e7 rThe 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.
2 x3 E0 a7 ]: P  L4 p- Z/ O9 `6 w& Z
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号8 t; e* z) Q( h+ p/ K( @
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
) r2 A# z/ a* \0 S9 _2 L第五个参数是个回调函数,一般都定义如下:
8 e6 O* v0 p, xvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
8 t# I' t+ `% @1 a( R! _" r  b* a{
6 o3 M6 T$ \( P' |        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;0 N+ r. J" J/ u1 b' Q
       
1 Q* y% d  u8 E8 S" t, Q        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);8 {( I5 s& s( V0 _+ S. D
}
# G$ w  x+ c+ s7 R这个回调函数将会把拨号的状态POST到各个窗口句柄。
7 J7 W1 s( d/ B+ ~3 G" H' _5 x3 B# C7 i

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃
- {! K, \4 Q! r  V% q
4 ?! j* [7 W: _  E- u7 z% `, R+ t" C4 Y6 T3 ]5 a; o& [
在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出- W# ?, o$ p/ U2 a' b; l
10:51:59 Message: 正在打开端口,请稍候...: L) e( h0 @7 [/ M( ]: P
10:51:59 Message: 端口已经打开
) W: ?* n; k% b2 }4 D+ G( m4 o10:51:59 Message: 正在连接网络设备,请稍候...) W9 b* r2 l  E' \# j  Z
10:51:59 Message: 网络设备连接成功
% T) b4 U* m3 f: z: T10:51:59 Message: 网络设备已经准备就绪
0 h& V! E  _1 \10:51:59 Message: 正在验证用户帐号和口令,请稍候...
, g9 S) q+ ~# ]* u# c10:52:00 Message: 正在接收验证/授权过程通知消息
8 k- d) t' x, C: c10:52:00 Message: 正在与服务器进行数据交互,请稍候...
2 b0 v3 s, ^0 J" @10:52:00 Message: 正在接收验证/授权过程通知消息
2 d7 ]% B2 u( I4 o+ |0 L10:52:00 Message: 交互过程结束
( m8 c  F2 I: ]- n+ O10:52:00 Message: 正在接收验证/授权过程通知消息
& G( k! K! e" W6 S10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
% g: t2 A; J. ~% t& b1 A# a  d1 p0 G4 t10:52:02 Message: PPPoE连接建立成功6 `. c+ j3 V! B8 h9 j  E# Q1 S; i+ v* G/ n5 h
10:52:02 Message: IP -> 192.168.0.2; g9 ~6 ^. K& b( h7 `6 j. s0 B6 {
10:52:02 Message: IP -> 218.109.100.703 [: n$ s% t( M$ v: f- H
10:52:02 Message: IP -> 218.109.98.169
- R$ z6 ^: |/ M8 V4 `  c) n
4 A) r9 q. ^1 k. t

该用户从未签到

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

该用户从未签到

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

本版积分规则

关闭

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

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