如何使ip地址的字符串变成DWORD类型的ip address(100分)

T

tanrui

Unregistered / Unconfirmed
GUEST, unregistred user!
我在华南bbs上看到一个程序,用delphi来制作实现ping这个程序的功能,它
调用了windows/system32目录下的icmp.dll,在它的程序中有这么一句:
FIPAddress := inet_addr(PChar(PingEdit.Text));
其中,FIPAddress:DWORD
PingEdit中为输入的ip地址.
但是我发现inet-addr这个函数在delphi中没有,我该怎么办?
或则,怎么能够实现了?
可到 华南网木棉站 bbs.gznet.edu.cn 上看到"Delphi编程实现Ping操作" --author 张泰立 该源程序.
 
Delphi是有这个函数的。
你需要 use Winsock这个unit
 
TCP/IP通讯程序都要用到Winsock,

如果你用的是Delphi 3.0以上,
加上
Uses

WinSock;
就可以使用inet_addr了,

该函数的help在Win32的Help里面

The Windows Sockets inet_addr function
converts a string containing a dotted address into an in_addr.

unsigned long inet_addr (

const char FAR * cp
);

Parameters

cp

A character string representing a number
expressed in the Internet standard "." notation.

Return Value

If no error occurs, inet_addr returns an unsigned long
containing a suitable binary representation of the Internet
address given. If the passed-in string does not contain
a legitimate Internet address
(for example, if a portion of an "a.b.c.d" address exceeds 255),
inet_addr returns the value INADDR_NONE.
 
TCP/IP通讯程序都要用到Winsock,

如果你用的是Delphi 3.0以上,
加上
Uses

WinSock;
就可以使用inet_addr了,

该函数的help在Win32的Help里面

The Windows Sockets inet_addr function
converts a string containing a dotted address into an in_addr.

unsigned long inet_addr (

const char FAR * cp
);

Parameters

cp

A character string representing a number
expressed in the Internet standard "." notation.

Return Value

If no error occurs, inet_addr returns an unsigned long
containing a suitable binary representation of the Internet
address given. If the passed-in string does not contain
a legitimate Internet address
(for example, if a portion of an "a.b.c.d" address exceeds 255),
inet_addr returns the value INADDR_NONE.
 
另外,总不会是把inet_addr写成inet-addr的原因吧?
 
另外,总不会是把inet_addr写成inet-addr的原因吧?
 
哇赛!我说怎么这么慢呢!
原来在我的两个帖子中间
竟然插入了这么一大段。 :)
 
多人接受答案了。
 
顶部