[Live-devel] How to get other endpoint's IP address
Ross Finlayson
finlayson at live555.com
Mon Jun 13 23:36:26 PDT 2016
> I'm creating an audio "client" using RTPSource. I have a custom MediaSink-derived class which takes the traffic and routes it to my computer's audio device. Works great.
>
> What I'd like to do, however, is retrieve the sender's IP address (the IP address of the sender which is sending traffic to the port/ip as specified by my GroupSocks). How do I do this?
Unfortunately the sender’s IP address (and port number) aren’t exposed directly by our “*RTPSource” code, but there is a hack that you can use to get this.
The trick (hack) is to define a subclass of the “Groupsock” class, and, in your subclass, reimplement the virtual function
virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize, unsigned& bytesRead, struct sockaddr_in& fromAddressAndPort);
In your subclass, you would implement this virtual function as follows:
Boolean yourGroupsockSubclass::handleRead(unsigned char* buffer, unsigned bufferMaxSize,
unsigned& bytesRead, struct sockaddr_in& fromAddressAndPort) {
Boolean result = Groupsock::handleRead(buffer, bufferMaxSize, bytesRead, fromAddressAndPort);
if (result) {
// “fromAddressAndPort” is the sender’s IP address (and port number); record it
}
return result;
}
Then, you would create your “RTPSource” object with an object of your “Groupsock" subclass, rather than with a regular “Groupsock”.
Also:
> RTCPInstance* rtcpInstance =
> RTCPInstance::createNew(*environment, &rtcpGroupSock, 5000, CNAME, NULL, rtpSource);
Before doing this, you should call
rtcpGroupSock.changeDestinationParameters()
with the sender’s IP address and port number, so that RTCP “RR” packets go back to the sender. (And if you want to use “rtpGroupSock” to send audio back to the sender (via a “RTPSink” object), then you should call “changeDestinationParameters()” on “rtpGroupSock” as well.)
Ross Finlayson
Live Networks, Inc.
http://www.live555.com/
More information about the live-devel
mailing list