This should do it (it is the ReceivePacket which you can find in several examples, e.g. wifi-simple-adhoc).
void ReceivePacket (Ptr<Socket> socket)
{
Address addr;
socket->GetSockName (addr);
Ptr<Packet> pkt = socket->RecvFrom(addr);
InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
Ipv4Address sourceIp = iaddr.GetIpv4();