下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。
0 b% O0 f3 q! [; v: x0 H) e想编一个程序,实现类似于网通拨号器的功能# v  E0 N, [4 R5 G5 D) z. f

  n* |8 a1 X( E$ L9 I/ @4 _9 [7 e1 g10:51:59 Message: 正在打开端口,请稍候..." `8 R( ~. }$ \2 W' P& ^% x
10:51:59 Message: 端口已经打开9 W  o) C/ |) Z6 Q
10:51:59 Message: 正在连接网络设备,请稍候...
8 O) z4 a- ^# a8 ^9 k( u10:51:59 Message: 网络设备连接成功: \* u  H; u1 u7 Z# R& C: A9 Z
10:51:59 Message: 网络设备已经准备就绪
0 q7 ~, g. [8 k0 p! x: y10:51:59 Message: 正在验证用户帐号和口令,请稍候...
. V& ?' n0 T4 D- E) K3 U0 H( p10:52:00 Message: 正在接收验证/授权过程通知消息
! l1 }0 ]  S/ x10:52:00 Message: 正在与服务器进行数据交互,请稍候...
6 q( L5 f! @4 c6 Y! ]& i% A10:52:00 Message: 正在接收验证/授权过程通知消息  o, a) r4 p' ~* O$ l( u( q
10:52:00 Message: 交互过程结束. t4 b, _8 Q8 @
10:52:00 Message: 正在接收验证/授权过程通知消息: H6 G9 m  G% R7 Q. E+ H0 r5 ^
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接) |& k7 J* ]  K6 g2 p$ x
10:52:02 Message: PPPoE连接建立成功2 R7 n. `0 a# N  X  \$ X
10:52:02 Message: IP -> 192.168.0.2
' M! o& O8 ^0 _4 K10:52:02 Message: IP -> 218.109.100.70
! y" t: w- ^& i6 r+ r9 I, u10:52:02 Message: IP -> 218.109.98.169" \9 a! c1 H9 U  s: T

9 r6 b- A* J; k; X% I8 y6 _给一个实例的代码好吗?
9 F8 c1 C" d2 a6 R& Q2 `我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。
5 U4 N5 l, r6 U我没有编写过ppp之类的软件,没法给你一个实例。- K& _4 S. N1 n. Z7 C, C+ W
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
2 o% _8 d& E4 O) u6 ^( E. P标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
3 U; J1 N5 B! }0 |& |6 \

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:7 Z7 `0 l# Z! I) J, A
我没有编写过ppp之类的软件,没法给你一个实例。6 N; K" p+ u! H; ]
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
1 F. Z7 x( u& f% B& `; i2 s9 v 标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
) m1 u$ A9 k7 L9 @; a

& U9 q  ~) j% s+ Z/ X2 }& h
/ |+ D) D9 N" G, m( s很可惜,真的太可惜了。
* {' T# [8 `* ]# |标准的拨号只要调用几个简单的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) connections7 t, {. C5 d* O* B" {* y' u
7 Y  p& @+ q& O! }4 j, D  ^/ y/ X
是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息
. _" L6 N- [7 |; n1 c7 |$ H, \- c  r- ?& F
http://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。: t5 {' O. L; X0 _
有一个RasDial拨号函数的定义如下:
& M4 ^  {) M" U1 x, ]. _DWORD RasDial(* h8 d6 e( ^4 U& S9 L( ^
LPRASDIALEXTENSIONS dialExtensions,
/ s" q+ M; q7 H( G1 i! nLPTSTR phoneBookPath ,
6 [" g; Q7 Q# o4 S: D, z; r( wLPRASDIALPARAMS rasDialParam ,   B  ?; x6 l( Y4 q9 s
DWORD NotifierType,
* A0 P3 l0 B5 [4 |9 K1 ^LPVOID notifier,
' q; O3 z5 E/ hLPHRASCONN pRasConn );: n/ Y, X! q( _, Z  U4 c, ?' _
3 X, D  n, s4 k2 l
我的MSDN的解说如下:3 E6 C' a1 r1 e' v! P: h
Parameters
& Z1 T4 {( W7 H% N; u9 @dialExtensions * L" l4 ^8 `6 l% r7 o) B
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 6 c$ r0 ]: I% E( Z+ |% A! q% ~
phoneBookPath
" J5 G3 U  L; H& q$ E+ QThis 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. . b. E; n! ]$ s
rasDialParam
$ {; K5 R8 o; R7 V' s- B% M% L0 pPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. / V6 y# i4 V& P: l
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. : V, ]# n/ a& Z; M& q% Q9 ?' e1 j

: b3 f3 P. v' Y/ k/ n- iNotifierType
- U- O6 W# u% ?0 z$ Y% pSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: ) t; s* i4 q" P5 h# R
Value Description
( \/ e- n7 u; J! k0xFFFFFFFF6 \* W7 Q+ P! u( n2 J% L
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 V# m) h- y2 o$ C' ]3 n
The progress notification message uses the WM_RASDIALEVENT message code. ' }' S" u3 @9 n
, X5 v! b- L& B  G+ h! h- a
0 w9 F- R1 a7 S  W8 D4 V
7 j+ `' P+ e7 }  M% p

5 @# \( X* U" qnotifier
' w. x. Z% d& V7 \# V; S- m& LPointer 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.
1 H! y0 l: V1 S  e" W" F$ XIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
1 f8 J& ^+ l! v! j' n. r0 S% {8 s# t) c$ b4 |) c! z# p1 U& X* w1 e& W! F- \
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:
% S# s6 j( ]3 m' ~7 t% h1 |: Z5 j+ U
The connection is established. In other words, the RAS connection state is RASCS_Connected. ; x: P5 l2 I1 \4 L0 f! X& \
The connection fails. In other words, dwError is nonzero. 9 K3 p; Q  i0 V9 C, \% A; G
RasHangUp is called on the connection.
  _. V9 I1 D( R. H+ S3 uThe callback notifications are made in the context of a thread captured during the initial call to RasDial. , |" L' r9 C$ k4 a4 x& }! O6 U

  K" L9 t* n: \# i5 m5 Y  {pRasConn * v* Q( \3 P! h  _8 {- r2 V; d
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.
+ V, V4 n& F+ P) V, X. o# ^1 fReturn Values
) w, M$ L" a+ _+ e. t* E6 D# N. JZero 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.
) A: C1 g2 Y: P" y( Z0 Q4 }) O0 S+ Q* |4 f
Include Raserror.h for definitions of the RAS error codes.( t* H" U; S  v7 o& B

5 ?% ]$ m3 h, N# C) E. e8 l% C3 C5 ?Remarks4 v7 ?, I# S9 r" k3 s
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
5 C; J; X+ v, _4 P& ?+ g0 x, S: M
% D' M6 ^' C1 T- e; d7 g0 b1 `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.: P; U3 q0 ?( h9 F, ?. i* r
5 X1 n4 o+ \( U
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.
0 |; X' H" A8 a) G1 M
0 H+ a( i% _3 W6 f3 r& FAn 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* ]. N' X- W7 ?& j, H6 U
7 I  e- l: j6 w8 B5 o2 ^1 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. " k/ P* k0 Z  b/ \
: z( H" g7 }2 G' d2 z
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. # E9 `6 C9 D# j: c7 b
1 P5 s9 S& |5 W
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
8 W+ i( u# A+ z3 H* oDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);2 D! a* _) [/ H8 Q$ G$ V
第五个参数是个回调函数,一般都定义如下:
; c8 E2 _$ u/ N; \/ o+ Qvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)* L, o+ G  N& b+ K0 X$ ^1 Y0 @
{9 D4 ]6 h" T, n8 f: c( g/ E# E
        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;9 w7 @- h) \: I- R* N
       
/ ^: R; J; _! ^* Q1 T        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
3 q, i: X+ L. V( [. v9 R}, H! ^* J5 x8 ^; X6 {; D
这个回调函数将会把拨号的状态POST到各个窗口句柄。
$ U) M: `# [+ w8 q$ U* I2 s0 M& y. j& X$ S

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃+ W7 L) ?; a+ G* G
# p, K* m& J  j- V

# L4 P: ^- c5 }% E在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出! G  S% U; X8 O) |3 u- H
10:51:59 Message: 正在打开端口,请稍候...7 M% C- d6 i" Y2 u; \0 F! w
10:51:59 Message: 端口已经打开
, m6 }4 o" ~4 ~7 d10:51:59 Message: 正在连接网络设备,请稍候...8 r! x6 m4 j7 D% m5 m
10:51:59 Message: 网络设备连接成功
- [4 a( k: `4 |10:51:59 Message: 网络设备已经准备就绪
# z' V/ [$ w8 S10:51:59 Message: 正在验证用户帐号和口令,请稍候...
& E! B' u7 q; e10:52:00 Message: 正在接收验证/授权过程通知消息) L; ?: o% A) A% u; a# n) ]
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
+ @, ^6 }$ P8 L0 C10:52:00 Message: 正在接收验证/授权过程通知消息
- l6 [5 O  O0 _5 P. m10:52:00 Message: 交互过程结束
$ A, A6 J9 Y0 m& e& f* P' _, l: M, o10:52:00 Message: 正在接收验证/授权过程通知消息6 h) c9 K+ a/ B3 c+ n6 b, ]" Q
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接
, B# V) x$ N1 }10:52:02 Message: PPPoE连接建立成功& j9 G; I9 Z, M& _: S4 v- ]
10:52:02 Message: IP -> 192.168.0.2
- h2 b" d' e2 x- d  G2 T# d6 x  S10:52:02 Message: IP -> 218.109.100.70
: Y$ K) E+ S& ?% S6 V10:52:02 Message: IP -> 218.109.98.169) O5 Y  J, o7 q% d( M
& R: y6 L6 B& M3 Z6 E, v% e

该用户从未签到

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

该用户从未签到

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

本版积分规则

关闭

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

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