下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。
: N& `( I( [: U! U想编一个程序,实现类似于网通拨号器的功能
$ l9 q  E- R) v( h( X/ G! |6 ]0 ~8 X, A# E& V- ~
10:51:59 Message: 正在打开端口,请稍候..." y9 |& i9 e, O: F8 W- o( L" F- @
10:51:59 Message: 端口已经打开
. y" U# F+ V, |7 U10:51:59 Message: 正在连接网络设备,请稍候...
3 J# L1 S& z  s9 O: `. o' ^0 O10:51:59 Message: 网络设备连接成功- P0 h( ~  o( p& C- Z9 D6 G" B. C
10:51:59 Message: 网络设备已经准备就绪6 Q5 V+ F2 D% ]: @
10:51:59 Message: 正在验证用户帐号和口令,请稍候...
5 [: u% g$ ^" z5 Y* W8 V' t10:52:00 Message: 正在接收验证/授权过程通知消息
" B# ]0 Z* Z: i, Q: s: k- _1 s" O8 k0 E10:52:00 Message: 正在与服务器进行数据交互,请稍候...5 ?* ^+ d5 h0 `' B
10:52:00 Message: 正在接收验证/授权过程通知消息  @% z: K4 \, X3 k
10:52:00 Message: 交互过程结束* z( Z! F1 |: p# \
10:52:00 Message: 正在接收验证/授权过程通知消息
$ w6 ?+ U' W$ M- h! k10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
- B$ K5 L/ y* P( {10:52:02 Message: PPPoE连接建立成功
9 q4 q, E/ q& F3 Q0 T10:52:02 Message: IP -> 192.168.0.2, S* T/ f' h8 [! i$ f0 u
10:52:02 Message: IP -> 218.109.100.70
& n3 u" u4 ~0 L6 x- h; H10:52:02 Message: IP -> 218.109.98.169
0 g' o; P( w' T5 y1 {; A# p4 `: b' y8 R9 n3 B
给一个实例的代码好吗?9 a0 @! A- o" ~) J; i" w' C; Y
我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。
/ D4 q: R' H" D' Y6 U0 ~2 [* d, [我没有编写过ppp之类的软件,没法给你一个实例。$ S" v4 t% }. P' H
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。, d; `, C- g: N# ~4 G6 Y
标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
, L( l: k3 l6 m' {, K! i

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:) E0 r7 b, A% t; e' d2 a
我没有编写过ppp之类的软件,没法给你一个实例。
* b+ ]% A' \! r! e 我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
; s" ^; N3 e4 j+ A! F; K 标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API& D3 |) ]& ^4 c( Q
3 l' T1 S5 V) s: a
% n2 V% ~. F" R- \( `0 w+ o# r
很可惜,真的太可惜了。5 U# r  V6 d* U, F3 I! M% s5 S" N
标准的拨号只要调用几个简单的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 s2 d. H" n% ]( x

% I$ m$ X4 |  i" W是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息5 T4 k7 a) F$ F, d. F
0 i8 |# U9 p  X( d' [9 X3 W0 x
http://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
5 O' P& d, i' F有一个RasDial拨号函数的定义如下:6 `1 @% H1 J' m6 c' a2 {
DWORD RasDial(
  k( p' w+ h8 ^: T3 @. s, n. gLPRASDIALEXTENSIONS dialExtensions,
* v& x# y# h& Z' FLPTSTR phoneBookPath , 3 m! T6 h6 V: \& p4 Q  N
LPRASDIALPARAMS rasDialParam ,
9 [# ?. B0 x0 A" L$ WDWORD NotifierType,
$ T% v; c! ^# d: w; y* {9 o) oLPVOID notifier,
) d0 `  d8 Z; J  W9 FLPHRASCONN pRasConn );) h; q) q" y. s& j: q$ L  c2 l3 `  Y
' t: l1 T8 M  V" r
我的MSDN的解说如下:
; g/ J, o9 K6 `% T( q$ T1 W  u, u5 V1 JParameters6 T; L' `. [8 q$ u8 P8 y5 x/ a
dialExtensions
7 ]6 ~3 g+ l) a# P' nThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. ' F/ `0 q# t4 L
phoneBookPath
6 J) Q' T' X# u, xThis 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 t4 s- f5 t$ _( j
rasDialParam 3 J8 q" Y" Q# i! s6 ~% F; p0 B& e
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
9 p- v  G+ M9 G6 q4 L# ^. cThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
+ x9 i; v$ ~6 _8 p- V
5 ?. a  G, P* s7 B' V3 bNotifierType
. a# v' d* p5 q! B# w7 a" @( wSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
* M/ R" k; J( Y3 B3 ^Value Description
) b* E' V9 }7 }" \- ?+ g- @6 @$ c0xFFFFFFFF* p5 U' M% z4 s9 J1 F
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.  4 ^2 v! H! k3 `( B8 g6 u5 G# v
The progress notification message uses the WM_RASDIALEVENT message code. * I  Z/ ~+ y) F8 K: h7 V
, r3 g% B1 k& ]' |1 W! N- Q

+ P9 O. W4 O' p9 ?! y2 F$ E3 _: t2 m9 y. v, u2 Q4 i& k, v

7 k( o% O, B0 m. B/ [notifier - a4 ~3 J* i3 V* C
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. $ N6 x9 b' \8 o" m, y; {7 ^
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
& h/ s! _" S! Z7 V3 L) q  c) W7 x3 H4 S
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:
6 R7 s# R! Y5 \' b) I( g
; p! K6 x) g, o2 s: GThe connection is established. In other words, the RAS connection state is RASCS_Connected. : E' U- b, g0 _0 _/ Q% ~
The connection fails. In other words, dwError is nonzero.
! B1 V  g6 v( L! p4 ^+ z0 PRasHangUp is called on the connection.
8 t9 c& A9 v8 {9 U, I; T+ g9 rThe callback notifications are made in the context of a thread captured during the initial call to RasDial. ' W8 l8 k% I7 R2 \( z" j
, f) s. X4 w% c& d* j
pRasConn : w$ x; ]: D4 u6 P: [
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 x/ S5 j# e& _/ E1 S4 Z' r! ?* {& ?/ n
Return Values+ l9 z+ {, ^2 W
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. , G# s- j2 O  z7 l3 S

% Y( Q/ {- E* W- k2 NInclude Raserror.h for definitions of the RAS error codes.
+ X: e. u# s/ [" P. `5 n4 G) g. d2 ]/ M+ \
Remarks6 F. w$ R0 i( L* j/ O+ }
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
) A+ j' t6 ?9 p( M8 X4 U, A' {5 R, u. U7 e6 I* I
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.
6 u8 F6 s- G% ~, G5 J5 _' `: S  O" J( A
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.
% W9 m7 }) @; r& n* d% G4 `3 y' E8 ?% S
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. ! v, t9 R! \1 m
9 S$ S- K0 N1 O) X) {7 j
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. ( l# i# Q+ p1 c* C

3 K5 m9 h+ l( S$ t( H: @% D2 bThe 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.
0 H7 b5 Y/ M+ S$ A# j5 N7 ?+ [6 k
. A% C9 \7 c+ W看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号- @' K  W' T; p3 {, D- t5 L
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);$ S) A  q/ h5 a) T9 u& C
第五个参数是个回调函数,一般都定义如下:
( _! C0 C0 {& Kvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
" ?! p$ }8 n& y! P  `{
% n0 D4 S2 Z! U* H0 |        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;& F! ?: k4 j* p/ |+ P# b* N
        5 s* _8 U( A3 x8 I) Z
        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);1 T! `& ^& M: ]& m6 f% Z* T! x( m" g
}
( f) a# L. |, j6 R: i' m这个回调函数将会把拨号的状态POST到各个窗口句柄。  J* \- J6 c: {& ?6 R: b$ d

5 V: A2 |' J, C

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃/ T1 `- o1 A1 U/ j- `0 s
/ A3 B5 X+ d$ r) o) P3 i

- B1 C/ p( i: T# b在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出
- O$ n$ R9 {8 z3 v10:51:59 Message: 正在打开端口,请稍候...3 T* _% l7 l5 S- m& G# E
10:51:59 Message: 端口已经打开
/ i2 e6 R) o7 _10:51:59 Message: 正在连接网络设备,请稍候...
6 X/ Q+ t" e3 q) r* d8 n6 x4 r10:51:59 Message: 网络设备连接成功
2 A8 J& j( U# l  P& _1 j9 e/ U10:51:59 Message: 网络设备已经准备就绪
0 s! G6 B7 r4 ?' r10:51:59 Message: 正在验证用户帐号和口令,请稍候...2 t* m2 G+ }# e' R2 w- g
10:52:00 Message: 正在接收验证/授权过程通知消息
) q: d1 z2 b$ T+ e; N. [8 F10:52:00 Message: 正在与服务器进行数据交互,请稍候...
# s! m7 i9 ?1 @5 D+ }  N10:52:00 Message: 正在接收验证/授权过程通知消息
6 I$ A4 \: X$ A, o10:52:00 Message: 交互过程结束9 k) X, h! z* m
10:52:00 Message: 正在接收验证/授权过程通知消息( K: S1 r: V9 B) F% C; U
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
! A: E2 A+ e: _. s10:52:02 Message: PPPoE连接建立成功
: e  H( x1 b1 D2 z10:52:02 Message: IP -> 192.168.0.2
1 k- e$ F  L2 G2 R) `+ q8 E10:52:02 Message: IP -> 218.109.100.70
- W' A& M$ e  p" t10:52:02 Message: IP -> 218.109.98.169
9 w3 s8 g7 z+ x" w5 ^/ D1 F0 L# O3 }/ t, _) u7 i* x- j

该用户从未签到

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

该用户从未签到

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

本版积分规则

关闭

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

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