Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libifconfig/libifconfig.c
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
/* | |||||
* Copyright 1996 Massachusetts Institute of Technology | |||||
* | |||||
* Permission to use, copy, modify, and distribute this software and | |||||
* its documentation for any purpose and without fee is hereby | |||||
* granted, provided that both the above copyright notice and this | |||||
* permission notice appear in all copies, that both the above | |||||
* copyright notice and this permission notice appear in all | |||||
* supporting documentation, and that the name of M.I.T. not be used | |||||
* in advertising or publicity pertaining to distribution of the | |||||
* software without specific, written prior permission. M.I.T. makes | |||||
* no representations about the suitability of this software for any | |||||
* purpose. It is provided "as is" without express or implied | |||||
* warranty. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS | |||||
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, | |||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT | |||||
* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* | |||||
* $FreeBSD$ | |||||
*/ | |||||
#include <sys/types.h> | |||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/sysctl.h> | |||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/if_mib.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | ifconfig_set_name(ifconfig_handle_t *h, const char *name, const char *newname) | ||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, | if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, | ||||
&ifr) != 0) { | &ifr) != 0) { | ||||
free(tmpname); | free(tmpname); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
free(tmpname); | free(tmpname); | ||||
return (0); | return (0); | ||||
} | |||||
int | |||||
ifconfig_get_orig_name(ifconfig_handle_t *h, const char *ifname, | |||||
char **orig_name) | |||||
{ | |||||
struct ifmibdata ifmd; | |||||
size_t len; | |||||
int name[6]; | |||||
int i, maxifno; | |||||
name[0] = CTL_NET; | |||||
name[1] = PF_LINK; | |||||
name[2] = NETLINK_GENERIC; | |||||
name[3] = IFMIB_SYSTEM; | |||||
name[4] = IFMIB_IFCOUNT; | |||||
len = sizeof maxifno; | |||||
if (sysctl(name, 5, &maxifno, &len, 0, 0) < 0) { | |||||
h->error.errtype = OTHER; | |||||
h->error.errcode = errno; | |||||
return (-1); | |||||
} | |||||
name[3] = IFMIB_IFDATA; | |||||
name[5] = IFDATA_GENERAL; | |||||
for (i = 1; i <= maxifno; i++) { | |||||
len = sizeof ifmd; | |||||
name[4] = i; | |||||
if (sysctl(name, 6, &ifmd, &len, 0, 0) < 0) { | |||||
if (errno == ENOENT) | |||||
continue; | |||||
goto fail; | |||||
} | |||||
if (strncmp(ifmd.ifmd_name, ifname, IFNAMSIZ) != 0) | |||||
continue; | |||||
len = 0; | |||||
name[5] = IFDATA_DRIVERNAME; | |||||
if (sysctl(name, 6, NULL, &len, 0, 0) < 0) | |||||
goto fail; | |||||
*orig_name = malloc(len); | |||||
if (*orig_name == NULL) | |||||
goto fail; | |||||
if (sysctl(name, 6, *orig_name, &len, 0, 0) < 0) { | |||||
free(*orig_name); | |||||
*orig_name = NULL; | |||||
goto fail; | |||||
} | |||||
return (0); | |||||
} | |||||
fail: | |||||
h->error.errtype = OTHER; | |||||
h->error.errcode = (i <= maxifno) ? errno : ENOENT; | |||||
return (-1); | |||||
} | } | ||||
int | int | ||||
ifconfig_set_mtu(ifconfig_handle_t *h, const char *name, const int mtu) | ifconfig_set_mtu(ifconfig_handle_t *h, const char *name, const int mtu) | ||||
{ | { | ||||
struct ifreq ifr; | struct ifreq ifr; | ||||
memset(&ifr, 0, sizeof(ifr)); | memset(&ifr, 0, sizeof(ifr)); | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |