如题
对于udp,直接sendto就发送出去了,不管目的主机的该端口开启与否,都返回成功;所以,想要在发送前监测一下

解决方案 »

  1.   

    有一个办法,不过好像麻烦了一点……当向一个没有打开的udp端口发数据时,对方系统会返回一个icmp端口不可达报文。
    建立一个raw socket,sniffer本机收到的所有icmp报文,在一段时间内检测是否收到icmp端口不可达报文,如果收到了,分析是否来自于目标主机,如果没有收到,则可能是对方端口没有打开或者检测时间过短。
      

  2.   

    GetUdpTable
    The GetUdpTable function retrieves the User Datagram Protocol (UDP) listener table. DWORD GetUdpTable(
      PMIB_UDPTABLE pUdpTable,
      PDWORD pdwSize,
      BOOL bOrder
    );Parameters
    pUdpTable 
    [out] Pointer to a buffer that receives the UDP listener table as a MIB_UDPTABLE structure. 
    pdwSize 
    [in, out] On input, specifies the size of the buffer pointed to by the pUdpTable parameter. 
    On output, if the buffer is not large enough to hold the returned listener table, the function sets this parameter equal to the required buffer size.bOrder 
    [in] Specifies whether the returned table should be sorted. If this parameter is TRUE, the table is sorted in the order of: 
    IP address 
    Port 
    Return Values
    If the function succeeds, the return value is NO_ERROR.If the function fails, the return value is one of the following error codes.Return Code Description 
    ERROR_INSUFFICIENT_BUFFER The buffer pointed to by the pUdpTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the pdwSize parameter. 
    ERROR_INVALID_PARAMETER The pdwSize parameter is NULL, or GetUdpTable is unable to write to the memory pointed to by the pdwSize parameter. 
    ERROR_NOT_SUPPORTED This function is not supported on the operating system in use on the local system. 
    Other Use FormatMessage to obtain the message string for the returned error. 
    Requirements
    Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, and Windows 98.
    Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server 4.0 SP4 and later.
    Header: Declared in Iphlpapi.h.
    Library: Use Iphlpapi.lib.
      

  3.   

    不可能用应答方式的,这种方式有点差劲。
    如果你开发的一个网络程序,需要连接别公司开发的网络程序,难道要他们为了这个需求该程序?不可能的limin(www.haha567.com)的有道理,我看到过一点例程,好像有点麻烦的。DentistryDoctor(牙科医生)的我不清楚。还是谢谢各位。
      

  4.   

    先connect一下,据说这样能收到返回错误包。不过这是不可靠的,一般是要靠人为的ACK包才行。没有其他好办法的了。