/* @id: Pointer for hub id output, may be NULL  */
int net_hub_id_for_client(NetClientState *nc, int *id)
/* @id: Pointer for hub id output, may be NULL  */
int net_hub_id_for_client(NetClientState *nc, int *id)
{
    NetHubPort *port;
    if (nc->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
        port = DO_UPCAST(NetHubPort, nc, nc);
    } else if (nc->peer != NULL && nc->peer->info->type ==
            NET_CLIENT_OPTIONS_KIND_HUBPORT) {
        port = DO_UPCAST(NetHubPort, nc, nc->peer);
    } else {
        return -ENOENT;
    }
    if (id) {
        *id = port->hub->id;
    }
    return 0;
}