简单的 Socket 函数调用 ( 积分: 100 )

  • 主题发起人 主题发起人 全文检索
  • 开始时间 开始时间

全文检索

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure&nbsp;TForm1.Button4Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;MySocket:integer;<br>&nbsp;&nbsp;sockaddr:sockaddr_in;<br>&nbsp;&nbsp;p:pchar;<br>begin<br>&nbsp;MySocket:=Socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);<br>&nbsp;&nbsp;&nbsp;if&nbsp;MySocket=SOCKET_ERROR&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memo1.Lines.Add('套接字创建失败')&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;&nbsp;&nbsp;&nbsp;<br>&nbsp;memo1.Lines.Add('套接字创建成功')&nbsp;;<br>&nbsp;&nbsp;sockaddr.sin_family:=AF_INET;<br>&nbsp;&nbsp;sockaddr.sin_port:=0;<br>&nbsp;&nbsp;sockaddr.sin_addr.S_addr:=inet_addr(pchar('59.36.23.22'));<br><br>&nbsp;&nbsp;p:='test';<br>&nbsp;&nbsp;if&nbsp;sendto(Mysocket,p,strlen(p),0,sockaddr,sizeof(sockaddr))=SOCKET_ERROR&nbsp;then<br>&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;memo1.Lines.Add('icmp发送失败')&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseSocket(MySocket);<br>&nbsp;&nbsp;&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;memo1.Lines.Add('icmp发送成功')&nbsp;;<br>&nbsp;&nbsp;&nbsp;CloseSocket(MySocket);<br>end;<br><br><br>运行后提示&nbsp;<br>套接字创建成功'<br>'icmp发送成功'<br><br>但是听包工具没有显示有数据包送出和返回<br><br>我不想调用&nbsp;ICMP.DLL&nbsp;里面的函数去&nbsp;Ping&nbsp;也不想用控件IdIcmpClient<br><br>请问上面的代码有那里不完整的,谢谢
 
之前调用WSAStartup了吗
 
郁闷结贴了
 
后退
顶部