在linux下使用C后播放获取IP地址

我在linux下用C编写了一个简单的客户端服务器程序。 我已经创build了UDP套接字。 客户端使用广播消息

sendto(clientsock, buf, 100, 0, (struct sockaddr *)&to, sizeof (to)); 

服务器使用接收广播的消息

 recvfrom(serversock, buf, 100, 0, (struct sockaddr *)&rcv,&size); 

该消息正被服务器成功接收。 在服务器端,我需要find收到消息的源IP地址。 我怎样才能做到这一点 ?

对于像 –

 recvfrom(s, buf, BUFLEN, 0, &si_other, &slen) 

使用

 printf("Received packet from %s:%d\nData: %s\n\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);