使用udp接收数据时,如何得当对方的ip和端口用sdk

解决方案 »

  1.   

    接收时,recvfrom的第5个参数sockaddr*不就是你要的么?
      

  2.   

    recvfrom
    The recvfrom function receives a datagram and stores the source address.int recvfrom(
      SOCKET s,                   
      char FAR* buf,              
      int len,                    
      int flags,                  
      struct sockaddr FAR *from,  
      int FAR *fromlen            
    );Parameters

    [in] Descriptor identifying a bound socket. 
    buf 
    [out] Buffer for the incoming data. 
    len 
    [in] Length of buf. 
    flags 
    [in] Indicator specifying the way in which the call is made. 
    from 
    [out] Optional pointer to a buffer that will hold the source address upon return. 
    fromlen 
    [in, out] Optional pointer to the size of the from buffer. 
      

  3.   

    char szip[20];
    sprintf(szip,"%s",inet_addr(sockaddr.sin_addr));int nport = sockaddr.sin_port;