OpenHome Forum
Device access to client's IP address - Printable Version

+- OpenHome Forum (http://forum.openhome.org)
+-- Forum: OpenHome (/forumdisplay.php?fid=1)
+--- Forum: Net (/forumdisplay.php?fid=5)
+--- Thread: Device access to client's IP address (/showthread.php?tid=1065)

Pages: 1 2


Device access to client's IP address - simoncn - 12-11-2012 10:02 PM

I'd like my Device application to be able to get the client's IP address when it receives an action request. I believe ohNet has this information as part of the TCP socket connection information, but I'm not aware of any way that application code can access it.

The scenario motivating this is a request I've had to support audio streaming to remote UPnP control points and renderers that access the media server via IP forwarding. When responding to a remote Browse request, the media server needs to customize the server address in any embedded resource URLs in the response data, because the server's local subnet address isn't valid for remote access. The media server would have a configuration setting for the customized address it should use.

This works if all control points and renderers are remote. It doesn't work if some are local and some are remote, because the server must customize these URLs for remote requests but not for local requests. To cater for this, the media server would need to know for each Browse request whether it's coming from a local or remote client, so the server can do URL customization for remote clients but not for local clients.


RE: Device access to client's IP address - simonc - 13-11-2012 05:03 PM

We could add this, but it's unfortunately not a small change. We'd need to update code in many different layers:
  • OsNetworkAccept (once per OS port)
  • Os::NetworkAccept
  • Socket::Accept
  • SocketTcpServer::Accept
  • Run for all SocketTcpSession-derived classes
  • DviSessionUpnp
  • IDviInvocation
  • DvInvocationStd (C++ bindings)
  • IDvInvocation (C# bindings)
  • IDvInvocation (Java bindings)
  • IDvInvocationC (C bindings)

I'll add this to my todo list but it might be a while before I get time for it.


RE: Device access to client's IP address - simoncn - 14-11-2012 08:02 PM

(13-11-2012 05:03 PM)simonc Wrote:  I'll add this to my todo list but it might be a while before I get time for it.

Thanks very much!

I've also been wondering about getting access to headers sent by the client, such as the User-Agent header (if present). I don't have a specific use case for this, but I can imagine needing to do some kind of customization based on what type of control point is making the request.


RE: Device access to client's IP address - simoncn - 17-12-2012 08:56 AM

(13-11-2012 05:03 PM)simonc Wrote:  I'll add this to my todo list but it might be a while before I get time for it.

I've just had another user request for this. Do you have any estimate for when it might be available? Thanks!


RE: Device access to client's IP address - simonc - 17-12-2012 09:02 AM

(17-12-2012 08:56 AM)simoncn Wrote:  
(13-11-2012 05:03 PM)simonc Wrote:  I'll add this to my todo list but it might be a while before I get time for it.

I've just had another user request for this. Do you have any estimate for when it might be available? Thanks!

Thanks for the reminder. I'll try to do this next week.


RE: Device access to client's IP address - simoncn - 17-12-2012 04:14 PM

(17-12-2012 09:02 AM)simonc Wrote:  Thanks for the reminder. I'll try to do this next week.

Thanks very much!


RE: Device access to client's IP address - simonc - 24-12-2012 02:21 PM

I've just committed a chunk of work towards this. Could you help me out with the rest please?

I've added one of two variants to IDvInvocation for each language bindings

Endpoint ClientEndpoint() const;
or
void GetClientEndpoint(out uint aAddress, out uint aPort);

I'm not sure which of these or munging address + port into a string is best for Java. Would you mind proposing a patch for the Java bindings that does whatever you deem most appropriate?

Thanks.


RE: Device access to client's IP address - simoncn - 24-12-2012 03:12 PM

(24-12-2012 02:21 PM)simonc Wrote:  I've just committed a chunk of work towards this. Could you help me out with the rest please?

I've added one of two variants to IDvInvocation for each language bindings

Endpoint ClientEndpoint() const;
or
void GetClientEndpoint(out uint aAddress, out uint aPort);

I'm not sure which of these or munging address + port into a string is best for Java. Would you mind proposing a patch for the Java bindings that does whatever you deem most appropriate?

Thanks.

Thanks very much for doing this. I'll take a look at it and propose a patch. Because of the holiday season and various family visits etc., it will probably be a week or so before I can start to look at this.

I hope you have a very happy and relaxing Christmas and New Year! Thanks very much for all your help and support in 2012.


RE: Device access to client's IP address - simonc - 24-12-2012 03:15 PM

(24-12-2012 03:12 PM)simoncn Wrote:  Thanks very much for doing this. I'll take a look at it and propose a patch. Because of the holiday season and various family visits etc., it will probably be a week or so before I can start to look at this.

Thanks, that'd be great. There's no rush for the changes, it'll be easy enough for me to integrate them at any time.

(24-12-2012 03:12 PM)simoncn Wrote:  I hope you have a very happy and relaxing Christmas and New Year! Thanks very much for all your help and support in 2012.

Thanks, and the same to you Smile.


RE: Device access to client's IP address - simoncn - 05-01-2013 08:27 PM

(24-12-2012 02:21 PM)simonc Wrote:  I've just committed a chunk of work towards this. Could you help me out with the rest please?

I've added one of two variants to IDvInvocation for each language bindings

Endpoint ClientEndpoint() const;
or
void GetClientEndpoint(out uint aAddress, out uint aPort);

I'm not sure which of these or munging address + port into a string is best for Java. Would you mind proposing a patch for the Java bindings that does whatever you deem most appropriate?

Thanks.

I'm attaching a patch with proposed support for this in the Java bindings.

I didn't think it was worth creating a new Endpoint class solely for this purpose, so I added two new methods to the DvInvocation class and the IDvInvocation interface:

public int getClientAddress();
public int getClientPort();

This change also requires adding two new native methods to DvInvocation.c and DvInvocation.h.

All the diffs are in the attached zip file.

Best regards,
Simon