下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-9-21 10:56:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用一般的微软公布的API只能执行一般的连接到网络之类的功能,无法实时获得网络设备以及数据传输之类的信息。" b0 n7 z! P" Z9 Y; r0 Q( b
想编一个程序,实现类似于网通拨号器的功能
& C: l) X6 z: q* L( L+ p7 b# ?+ O, k1 a
10:51:59 Message: 正在打开端口,请稍候...7 P. J7 i3 m- ~$ T2 f
10:51:59 Message: 端口已经打开& f% f( D3 d' w- X
10:51:59 Message: 正在连接网络设备,请稍候...8 Z% `. l# x" \! r6 c
10:51:59 Message: 网络设备连接成功: s- l9 a: Z+ B6 s
10:51:59 Message: 网络设备已经准备就绪% Z" h4 W- X4 y
10:51:59 Message: 正在验证用户帐号和口令,请稍候...5 W6 Q4 t7 y* ?! s
10:52:00 Message: 正在接收验证/授权过程通知消息
& H5 W/ c0 l4 O$ Q10:52:00 Message: 正在与服务器进行数据交互,请稍候...
8 B2 U' G  M6 D10:52:00 Message: 正在接收验证/授权过程通知消息
6 z3 c0 ^( z+ ^- z) o10:52:00 Message: 交互过程结束
0 |4 ~  G( g* J. B' P! a) ?10:52:00 Message: 正在接收验证/授权过程通知消息- W& n' `, A# u
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接. W9 a% p  g: ?- G3 j
10:52:02 Message: PPPoE连接建立成功% Y; l8 J: S3 C* }, U4 k; ^/ z% J. Q& y
10:52:02 Message: IP -> 192.168.0.2* {! z4 u6 e7 u# {
10:52:02 Message: IP -> 218.109.100.70
9 c. X" c. I! M" O# y5 v" K4 U8 K10:52:02 Message: IP -> 218.109.98.1694 B" H6 U0 S( V1 t

: s) a9 R, [5 t* P给一个实例的代码好吗?
. J" N: r) i& @$ Z" q* F; I我的邮箱是:eagle_twenty@163.com
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

2
发表于 2003-9-21 21:00:00 | 只看该作者
网通的拨号器实际上是一个PPPOE的拨号软件,因此你的要求是要自己编写一个PPPOE的拨号程序,这样就能够显示出所有的信息来,前提是你必须熟悉pppoe的编程。
3 Q4 k# j8 h0 g6 D$ g+ r我没有编写过ppp之类的软件,没法给你一个实例。
1 j' D4 A& Z- E5 N' u我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。
/ D" m* W+ ^/ [4 u6 e4 m8 ~- N标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API
& c( k$ u% K! Q/ c5 a$ l

该用户从未签到

3
 楼主| 发表于 2003-9-21 21:45:00 | 只看该作者
以下是引用hzzh在2003-9-21 21:00:00的发言:
/ h! z* w/ b, a1 J- M# X 我没有编写过ppp之类的软件,没法给你一个实例。3 ?# u. W" b2 z. K; x4 Z
我想,偷懒的话,可以安装一个RASPPPOE软件。RASPPPOE只是提供了一个pppoe的协议,拨号直接利用了微软的拨号器,因此只要按标准的拨号软件编程方法就可以编写出一个拨号软件来,可能得到的信息稍微少了一点。7 _" n* l% O& u8 k$ {
标准的拨号软件编程方法可以参考MSDN的Establishing a Dial-Up Connection to the Internet 中的API& T( s" }7 j! K  e9 k5 H5 d4 O
) i1 N" b$ A+ n
- w+ \' y( X0 o' s* _
很可惜,真的太可惜了。
  v1 ~/ v& b* B- j! d2 b% V标准的拨号只要调用几个简单的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
- {! g6 Y) J4 ?6 `9 C* P: E  D5 g$ ?+ f
是一个监控拨号网络连接的MFC类,或许能够得到一些拨号过程消息
3 v) f7 Z. ^; M$ t. d3 F% D" V% g3 A0 J; N
http://chulsoft.xiloo.com/code/ras.zip

该用户从未签到

6
 楼主| 发表于 2003-10-25 00:48:00 | 只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。/ e3 I+ _# K9 u/ C4 O- ^* `4 N
有一个RasDial拨号函数的定义如下:
, h. T* r8 J0 b1 x" }DWORD RasDial(
- S& i3 [; z: u' p( q3 g. i- ?LPRASDIALEXTENSIONS dialExtensions,
0 O7 {- q1 f) R  q1 dLPTSTR phoneBookPath ,
: D1 D0 [7 f" \9 m7 Y% JLPRASDIALPARAMS rasDialParam ,
9 q6 j- K( X7 YDWORD NotifierType,
! e( O  _7 O" D  BLPVOID notifier, 8 L( B4 t& q/ q* o5 T/ R! P# x
LPHRASCONN pRasConn );
5 v" W  m) X; K% Q  j# E$ t. r9 v# a6 k3 O+ |1 j7 @1 I
我的MSDN的解说如下:
9 ]  Y: T- P2 _Parameters* ~6 p' x6 z% y$ ?  |5 Z
dialExtensions
6 N/ m' W. B+ h; C: HThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
. c8 r0 Z/ _6 U  d3 N. [  k# NphoneBookPath ; |1 W' W( K/ ^" H9 n
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. + \' r/ ^+ R* f, C3 D& N! N% v
rasDialParam
% ^, o! V2 t( `Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
' C% u) Y/ p6 [  oThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
( @& W1 v& L( i/ x/ u" u! r" O+ P, P
NotifierType
. n9 h/ x! y0 u8 P2 ]3 MSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
' a1 k, v+ d: Y3 V: r8 ]" XValue Description
  {8 Y2 i  o5 A0xFFFFFFFF
* R4 j) z' w* |8 E) G0xFFFFFFFF 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.  
) V) v1 D7 P: Q8 w9 q- Z The progress notification message uses the WM_RASDIALEVENT message code.
" T; y% i# c) g0 x  H' @9 p) v$ R4 J8 t7 u

/ B$ _/ A0 P- G$ z+ `1 R. B
0 G1 n" N$ J. ~- I# c2 W
0 N. g0 y* V4 G6 l) Enotifier 5 Y' [7 \, w8 P5 y4 `
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.
+ c4 H+ V3 ^9 qIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
# B) i/ X% U5 j7 `% b2 @0 r% U6 l) K+ ~3 y/ l* L$ g& G, q
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:
+ ?* t3 M+ v& e$ K) d0 G2 D: u4 C4 ?5 G
The connection is established. In other words, the RAS connection state is RASCS_Connected. ' I( _- O! d* i8 b1 Z5 s
The connection fails. In other words, dwError is nonzero.
0 m1 S5 s* y2 ~RasHangUp is called on the connection. , V5 t# u) I7 h. W! R
The callback notifications are made in the context of a thread captured during the initial call to RasDial. 9 u/ e, x6 ]: u; Y

( f9 v  V  j) B: y+ _pRasConn $ H7 A+ @/ z0 I- m
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. 6 W& f; d( ^6 R% f
Return Values
( p: R' `$ f- \  P! b+ NZero 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.
  `$ l3 I5 b; z4 E  _  ~$ w1 m. p, b4 A
Include Raserror.h for definitions of the RAS error codes.% c3 @1 y" Z% z/ t

) ]  D& h6 ~- L7 \4 p3 |$ ~Remarks5 f  t+ @: U' `9 f& a7 E: ^
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.1 {: {6 ^4 ]0 d1 o8 K

0 B0 l5 q$ V/ a8 g- R: ZRasDial 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.
: v" Y; @5 c9 p3 J- h) t) ^, B$ F% I8 F8 ^) d
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.
9 j2 |) p1 }, y3 b  d: T& T$ w7 C- E3 F& X, R7 F
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. - X% b7 c; V! r  g
' ?! o7 E1 _% u9 ^4 t8 A& S% U
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. . R2 X/ H/ T* T! L. V; i/ i

% N0 Y& p: h) pThe 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. . D' |. ^* |8 d- \
( \4 ]  ~0 R! k7 S- X
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
! k8 |  I# w$ f, GDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);. g2 u1 J4 W( N9 @  h/ ]5 Y
第五个参数是个回调函数,一般都定义如下:
& v/ T6 ?2 R5 r4 Fvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
1 y5 [& b  o, Q; q3 |3 w! w{  h* A% l4 S: |' g2 L/ t
        CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;! H* c3 G4 t, P* A
       
  N0 M' s+ F  T3 r        RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);$ z5 ]! E" ?9 ]
}
8 v4 f, Q/ d  X: I这个回调函数将会把拨号的状态POST到各个窗口句柄。
. A4 X, O7 z# ^2 O0 B1 J4 K1 g4 X" |3 J

该用户从未签到

7
发表于 2003-10-28 12:53:00 | 只看该作者
呵呵,自己把MSDN给啃出来了,这是最高的境界了,可喜可贺。确实MSDN中什么都有,只要肯啃
% x) J! e) x; F' M
+ {  c( Z* W" Q1 W' c: c9 x& Z
6 ^$ |! H  I) @/ x' \) b在回调函数void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)中,不需要再用PostMessage把消息发到主窗口了,只要直接用switch(rasconnstate)就可以输出
; r8 \+ z. D% w1 [5 ?& c10:51:59 Message: 正在打开端口,请稍候...
( `5 v0 B5 f. p3 W& K- \3 K( N# q10:51:59 Message: 端口已经打开
$ I9 `& f! L0 Z+ _. Y6 U10:51:59 Message: 正在连接网络设备,请稍候...
7 D( _1 n' I1 Y  G* Y# Q, V7 I10:51:59 Message: 网络设备连接成功
# x4 J- F2 q$ i' E6 Z$ u" r10:51:59 Message: 网络设备已经准备就绪
4 V1 g. p4 J4 g& [- L# T10:51:59 Message: 正在验证用户帐号和口令,请稍候...
2 P/ L, d, v3 R) q% g% W10:52:00 Message: 正在接收验证/授权过程通知消息/ g7 j1 j- ^- U) |" P: p; `4 E
10:52:00 Message: 正在与服务器进行数据交互,请稍候...
0 e: I# j, b* {# x9 Y5 j10:52:00 Message: 正在接收验证/授权过程通知消息
" y; p  r, j- {( a10:52:00 Message: 交互过程结束) o7 B! z* _' A2 g" Z
10:52:00 Message: 正在接收验证/授权过程通知消息) c* {' B6 `4 ?! o
10:52:00 Message: 用户帐号/口令验证通过,正在建立连接" Y- g; \# [3 \" C
10:52:02 Message: PPPoE连接建立成功9 d5 `& @3 ^6 J$ n7 u5 k3 A( G+ B
10:52:02 Message: IP -> 192.168.0.2
0 [' j1 Z6 R  W# V: `10:52:02 Message: IP -> 218.109.100.70
, ?( d" o/ p6 w10:52:02 Message: IP -> 218.109.98.169
& h) [, S* J& M8 @" s- E+ t3 \
, u- G4 }/ Z4 L* |' B  D# |7 ?( O

该用户从未签到

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

该用户从未签到

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

本版积分规则

关闭

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

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