summaryrefslogtreecommitdiffstats
path: root/python-ethtool
diff options
context:
space:
mode:
Diffstat (limited to 'python-ethtool')
0 files changed, 0 insertions, 0 deletions
'#n61'>61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
/*
 * ethtool.c - setting of basic ethtool options
 *
 * Copyright (C) 2003  Red Hat, Inc.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author(s): Jeremy Katz <katzj@redhat.com>
 */

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <net/if.h>

#include <linux/sockios.h>
#include "net.h"

static int set_intf_up(struct ifreq ifr, int sock) {
    if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
        return (-1);
    }
    ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
    if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
        fprintf(stderr, "failed to bring up interface %s: %s", ifr.ifr_name,
                strerror(errno));
        return -1;
    }
    return (0);
}

int setEthtoolSettings(char * dev, ethtool_speed speed, 
                       ethtool_duplex duplex) {
    int sock, err;
    struct ethtool_cmd ecmd;
    struct ifreq ifr;

    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        perror("Unable to create socket");
        return -1;
    }

    /* Setup our control structures. */
    memset(&ifr, 0, sizeof(ifr));
    strcpy(ifr.ifr_name, dev);

    if (set_intf_up(ifr, sock) == -1) {
        fprintf(stderr, "unable to bring up interface %s: %s", dev, 
                strerror(errno));
        return -1;
    }

    ecmd.cmd = ETHTOOL_GSET;
    ifr.ifr_data = (caddr_t)&ecmd;
    err = ioctl(sock, SIOCETHTOOL, &ifr);
    if (err < 0) {