Search code examples
cdbus

get bus name as set by "dbus_request_name" of a message sender


For debugging purposes I want to know the sender name of a dbus message. But dbus_message_get_sender returns the senders unique name which usually is something like this: :1.60. I'm looking for a way to get the name as set by dbus_request_name.

org.freedesktop.DBus interface provides a method to query unique name that corresponds to the set name which is calledGetNameOwner. But I can't find a method to do the opposite?


One method I figured is to get a list of all registered names with the ListNames method, then query the unique name for each name with GetNameOwner until a match happens. This should work but I still think that there should be a simpler way of doing this.


Solution

  • One method I figured is to get a list of all registered names with the ListNames method, then query the unique name for each name with GetNameOwner until a match happens. This should work but I still think that there should be a simpler way of doing this.

    That is the correct way to achieve what you want.

    There is no method on the org.freedesktop.DBus interface to map from a unique name (for example, :1.5) to a well-known name (for example, org.bluez), because each unique name may be the owner of zero or more well-known names.

    Arguably there could be an org.freedesktop.DBus.ListNamesForOwner() method which would map from a unique name to an array of well-known names, but nobody has written that yet.