Winsock 函数使用(急)(200分)

  • 主题发起人 主题发起人 nbwzw
  • 开始时间 开始时间
N

nbwzw

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用Winsock中的以下几个函数(最好有源程序)
WSAAsyncGetHostByName
WSAAsyncGetHostByAddr
gethostbyaddr
gethostbyname
 
leave over your email,I will send to you
 
savenight:Give me too,
Thank you!

smilboy@263.net
 
wzwboy@163.net
 
你真懒,
看帮助就可解决的问题,还来问。
 
>gethostbyname:
The Windows Sockets gethostbyname function gets host information corresponding to a hostname.

struct hostent FAR * gethostbyname (

const char FAR * name
);


Parameters

name

[out] A pointer to the null terminated name of the host.

>gethostbyaddr:
The Windows Sockets gethostbyaddr function gets host information corresponding to an address.

struct hostent FAR * gethostbyaddr (

const char FAR * addr,
int len,
int type
);


Parameters

addr

[in] A pointer to an address in network byte order.

len

[in] The length of the address.

type

[in] The type of the address.

>WSAAsyncGetHostByName:
he Windows Sockets WSAAsyncGetHostByName function gets host information corresponding to a hostname?
asynchronous version.

HANDLE WSAAsyncGetHostByName (

HWND hWnd,
unsigned int wMsg,
const char FAR * name,
char FAR * buf,
int buflen
);


Parameters

hWnd

[in] The handle of the window which should receive a message when the asynchronous request completes.

wMsg

[in] The message to be received when the asynchronous request completes.

name

[in] A pointer to the null terminated name of the host.

buf

[out] A pointer to the data area to receive the hostent data. Note that this
must be larger than the size of a hostent structure. This is because the data
area supplied is used by Windows Sockets to contain not only a hostent structure
but any and all of the data which is referenced by members of the hostent structure.
It is recommended that you supply a buffer of MAXGETHOSTSTRUCT bytes.

>WSAAsyncGetHostByAddr:
The Windows Sockets WSAAsyncGetHostByAddr function gets host information corresponding to an address?
asynchronous version.

HANDLE WSAAsyncGetHostByAddr (

HWND hWnd,
unsigned int wMsg,
const char FAR * addr,
int len,
int type,
char FAR * buf,
int buflen
);


Parameters

hWnd

[in] The handle of the window which should receive a message when the asynchronous request completes.

wMsg

[in] The message to be received when the asynchronous request completes.

addr

[in] A pointer to the network address for the host. Host addresses are stored in network byte order.

len

[in] The length of the address.

type

[in] The type of the address.

buf

[out] A pointer to the data area to receive the hostent data. Note that this
must be larger than the size of a hostent structure. This is because the data
area supplied is used by Windows Sockets to contain not only a hostent structure
but any and all of the data which is referenced by members of the hostent structure.
It is recommended that you supply a buffer of MAXGETHOSTSTRUCT bytes.

buflen

[in] The size of data area buf above.

buflen

[in] The size of data area buf above.

 
-------------------------抄来的例子:

获取计算机的身份信息

获取计算机的身份信息功能表示通过程序设计,达到自动获取机器的名字和IP地址
的目的。要实现这个功能,我们可以使用DELPHI程序提供的TCP控件来完成。下面
是一个调用了WINSOCK的独立单元的一段功能代码,我们可以把它直接嵌入到自己
的程序中去。

uses Winsock;
procedure TForm1.FormCreate(Sender: TObject);
var
wVersionRequested : WORD;
wsaData : TWSAData;
begin

{创建 WinSock}
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
end;
procedure TForm1.Button1Click(Sender: TObject);
var p : PHostEnt; s : array[0..128] of char; p2 : pchar;
begin

{得到计算机名称}
GetHostName(@s,128);
p:=GetHostByName(@s);
Memo1.Lines.Add(p^.h_Name);

{得到机器IP地址}
p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
Memo1.Lines.Add(p2);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

{释放 WinSock}
WSACleanup;
end
 
多人接受答案了。
 
后退
顶部