Sender IP/Port for UDP Socket

后端 未结 2 1712
感动是毒
感动是毒 2020-12-22 00:42

Is it possible to obtain the sender IP and (dynamically obtained) port with C sockets? I have the following:

memset(&hints, 0, sizeof hints); 
hints.ai_f         


        
2条回答
  •  無奈伤痛
    2020-12-22 01:33

    Generally you get the local address/port information with the getsockname(2), but here you don't have it yet - the socket is not connected and nothing has been sent. If this is a simple UDP client - consider using connected UDP sockets - you'd be able to see local IP/port right after the connect(2).

提交回复
热议问题