为什么解析不了域名?

buddyer 2004-04-29 06:20:31
var
server:TSockaddrin;
sClient:TSocket;
hostent:PHostEnt;
WSADATA:TWSADATA;
begin
{socket}

WSAStartup(makeword(2,2),WSADATA);
sClient:=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
if sClient = INVALID_SOCKET then
begin
showmessage(inttostr(WSAGetLastError));
exit;
end;

loginip:=ip;
loginport:=port;
ZeroMemory(@server,sizeof(server));
server.sin_family:=PF_INET;
server.sin_addr.S_addr:=inet_addr(pchar(loginip));

{ TODO -o徐沙 : 4/16 登录窗口的域名解析 }
if server.sin_addr.S_addr=INADDR_NONE then
begin
hostent:=gethostbyname(pchar(ip));
if hostent=nil then
begin
application.MessageBox(pchar(inttostr(GetLastError)),
'连接失败',MB_OK+MB_ICONERROR);
closesocket(sclient);
WSACleanup;
exit;
end;
// CopyMemory(@(server.sin_addr),hostent.h_addr,hostent.h_length);
server.sin_addr:=in_addr((hostent.h_addr)^);
end;
server.sin_port:=htons(strtoint(loginport));

if connect(sClient,server,sizeof(server))=socket_error then
begin
application.MessageBox('建立连接失败!','连接错误',MB_OK+MB_ICONERROR);
closesocket(sClient);
WSACleanup;
exit;
end;
为什么解析不了域名,填写的域名解析是个错的,但是ping是可以解析域名的。
不知道哪儿出问题了 ,帮我看看吧
...全文
48 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yueshujiang 2004-04-30
  • 打赏
  • 举报
回复
www.delphi.com

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧