int Eth_Dev_Param::get_gateway()

in sample_app/onvif_camera_mock/artifacts/onvif_srvd/src/eth_dev_param.cpp [350:399]


int Eth_Dev_Param::get_gateway(uint32_t *gateway) const
{
    if( !is_open() || !gateway )
        return -1;


    char devname[64];
    unsigned long d, g, m;
    int flgs, ref, use, metric, mtu, win, ir;


    FILE *fp = fopen("/proc/net/route", "r");

    if( !fp )
        return -1; //can't open file


    if( fscanf(fp, "%*[^\n]\n") < 0 ) // Skip the first line
    {
        fclose(fp);
        return -1;   // Empty or missing line, or read error
    }


    while( !feof(fp) )
    {
        int r;
        r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n",
                   devname, &d, &g, &flgs, &ref, &use, &metric, &m, &mtu, &win, &ir);


        if (r != 11)
        {
            fclose(fp);
            return -1;
        }

        if( strcmp(devname, _ifr.ifr_name) != 0 )
            continue;

        fclose(fp);
        *gateway = g;

        return 0; //good job
    }


    fclose(fp);
    return -1; //can't finde
}