Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebkit: downloading a page using a specific network interface
Forum Updated to NodeBB v4.3 + New Features

QWebkit: downloading a page using a specific network interface

Scheduled Pinned Locked Moved Qt WebKit
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sergico
    wrote on last edited by
    #1

    Hi Everybody,

    I have a PC with two network interfaces; eth0 and eth1
    eth1 has no IP address but it is bound to a ppp connection

    eth0 Link encap:Ethernet HWaddr 00:26:18:f1:91:d1
    inet addr:192.168.23.7 Bcast:192.168.23.255 Mask:255.255.255.0

    ppp0 Link encap:Point-to-Point Protocol
    inet addr:192.168.60.7 P-t-P:192.168.60.213 Mask:255.255.255.255

    I'd like is to be able to use Qt webkit to download pages using the ppp0 and not the eth0 interface.

    What I did at code level using Qt is the following:

    • Retrieve the list of available network configurations
    • Select the network configuration associated with the ppp0 iface
    • create a QNetworkAccessManager
    • set the configuration of the QNetworkAccessManager
    • create a QWebPage
    • set the network access manager of the webpage to the above one
    • load the webpage

    Unfortunately it seems that the data always exit via the eth0 iface (I monitored both ifaces with wireshark/tcpdump) The problem is not related to the routing configuration of the PC, I configured the system so that I can send packets out via the ppp0 iface.

    ie. ping -c 3 -I 192.168.60.7 www.google.com is correctly routed out via the ppp0 iface

    Here's a snapshot of my code:

    @
    QNetworkConfigurationManager* m_netConfigMngPtr;
    QNetworkAccessManager* m_netAccessMngPtr;

    m_netConfigMngPtr = new QNetworkConfigurationManager();
    qDebug() << "network config manager capabilities" << m_netConfigMngPtr->capabilities();

    QList<QNetworkConfiguration> netConfigList = m_netConfigMngPtr->allConfigurations();

    QString ifaceId;
    qDebug() << Q_FUNC_INFO << "Available Networck configurations:" << netConfigList.size();
    foreach( QNetworkConfiguration c, netConfigList)
    {
    qDebug() << Q_FUNC_INFO << "network configuration:" << c.identifier() << c.name() << c.state() << c.isValid();
    if (c.name() == "ppp0")
    {
    ifaceId = c.identifier();
    }
    }

    QNetworkConfiguration netConf = m_netConfigMngPtr->configurationFromIdentifier(ifaceId);
    qDebug() << "Net config for " << ifaceId << "(" << netConf.name() << ")" << "is valid: " << netConf.isValid();

    m_netAccessMngPtr = new QNetworkAccessManager;
    m_netAccessMngPtr->setConfiguration( netConf );

    QWebPage* m_theWebPagePtr = new QWebPage;
    m_theWebPagePtr->setNetworkAccessManager(m_netAccessMngPtr);
    m_theWebPagePtr->currentFrame()->load( QUrl("http://www.google.com") );

    @

    I'm using Qt 4.8.1 on Linux 64bit
    Any hint or suggestion on what I'm doing wrong?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved