Renaming libifc to libifconfig in response to feedback on initial commit of
this library. Sticking to 'libifconfig' (and 'ifconfig_' as function prefix) should reduce chances of namespace collisions, make it more clear what the library does, and be more in line with existing libraries. Submitted by: Marie Helene Kvello-Aune <marieheleneka@gmail.com> Differential Revision: https://reviews.freebsd.org/D7742 Reviewed by: cem, kp
This commit is contained in:
parent
2279a9a428
commit
ec21434933
@ -60,7 +60,7 @@ SUBDIR= ${SUBDIR_BOOTSTRAP} \
|
||||
${_libgssapi} \
|
||||
${_librpcsec_gss} \
|
||||
${_libiconv_modules} \
|
||||
libifc \
|
||||
libifconfig \
|
||||
libipsec \
|
||||
libjail \
|
||||
libkiconv \
|
||||
|
@ -1,18 +1,18 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PACKAGE= lib${LIB}
|
||||
LIB= ifc
|
||||
LIB= ifconfig
|
||||
# Don't build shared library, for now.
|
||||
NO_PIC=
|
||||
|
||||
SHLIBDIR?= /lib
|
||||
SHLIB_MAJOR= 1
|
||||
SRCS= libifc.c libifc_internal.c
|
||||
SRCS= libifconfig.c libifconfig_internal.c
|
||||
|
||||
INCSDIR= ${INCLUDEDIR}
|
||||
INCS= libifc.h
|
||||
INCS= libifconfig.h
|
||||
|
||||
#MAN= libifco.3
|
||||
#MAN= libifconfig.3
|
||||
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
WARNS?=6
|
@ -71,16 +71,16 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libifc.h"
|
||||
#include "libifc_internal.h"
|
||||
#include "libifconfig.h"
|
||||
#include "libifconfig_internal.h"
|
||||
|
||||
|
||||
libifc_handle_t *
|
||||
libifc_open(void)
|
||||
ifconfig_handle_t *
|
||||
ifconfig_open(void)
|
||||
{
|
||||
struct libifc_handle *h;
|
||||
struct ifconfig_handle *h;
|
||||
|
||||
h = calloc(1, sizeof(struct libifc_handle));
|
||||
h = calloc(1, sizeof(struct ifconfig_handle));
|
||||
|
||||
for (int i = 0; i <= AF_MAX; i++) {
|
||||
h->sockets[i] = -1;
|
||||
@ -91,7 +91,7 @@ libifc_open(void)
|
||||
|
||||
|
||||
void
|
||||
libifc_close(libifc_handle_t *h)
|
||||
ifconfig_close(ifconfig_handle_t *h)
|
||||
{
|
||||
for (int i = 0; i <= AF_MAX; i++) {
|
||||
if (h->sockets[i] != -1) {
|
||||
@ -102,29 +102,29 @@ libifc_close(libifc_handle_t *h)
|
||||
}
|
||||
|
||||
|
||||
libifc_errtype
|
||||
libifc_err_errtype(libifc_handle_t *h)
|
||||
ifconfig_errtype
|
||||
ifconfig_err_errtype(ifconfig_handle_t *h)
|
||||
{
|
||||
return (h->error.errtype);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
libifc_err_errno(libifc_handle_t *h)
|
||||
ifconfig_err_errno(ifconfig_handle_t *h)
|
||||
{
|
||||
return (h->error.errcode);
|
||||
}
|
||||
|
||||
|
||||
unsigned long
|
||||
libifc_err_ioctlreq(libifc_handle_t *h)
|
||||
ifconfig_err_ioctlreq(ifconfig_handle_t *h)
|
||||
{
|
||||
return (h->error.ioctl_request);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
libifc_get_description(libifc_handle_t *h, const char *name, char **description)
|
||||
ifconfig_get_description(ifconfig_handle_t *h, const char *name, char **description)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
char *descr = NULL;
|
||||
@ -141,7 +141,7 @@ libifc_get_description(libifc_handle_t *h, const char *name, char **description)
|
||||
|
||||
ifr.ifr_buffer.buffer = descr;
|
||||
ifr.ifr_buffer.length = descrlen;
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCGIFDESCR,
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFDESCR,
|
||||
&ifr) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
@ -166,7 +166,7 @@ libifc_get_description(libifc_handle_t *h, const char *name, char **description)
|
||||
|
||||
|
||||
int
|
||||
libifc_set_description(libifc_handle_t *h, const char *name,
|
||||
ifconfig_set_description(ifconfig_handle_t *h, const char *name,
|
||||
const char *newdescription)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
@ -180,7 +180,7 @@ libifc_set_description(libifc_handle_t *h, const char *name,
|
||||
* TODO: Decide whether this should be an error condition instead.
|
||||
*/
|
||||
if (desclen == 0) {
|
||||
return (libifc_unset_description(h, name));
|
||||
return (ifconfig_unset_description(h, name));
|
||||
}
|
||||
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
@ -193,7 +193,7 @@ libifc_set_description(libifc_handle_t *h, const char *name,
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) != 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) != 0) {
|
||||
free(ifr.ifr_buffer.buffer);
|
||||
return (-1);
|
||||
}
|
||||
@ -202,7 +202,7 @@ libifc_set_description(libifc_handle_t *h, const char *name,
|
||||
}
|
||||
|
||||
|
||||
int libifc_unset_description(libifc_handle_t *h, const char *name)
|
||||
int ifconfig_unset_description(ifconfig_handle_t *h, const char *name)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
@ -211,14 +211,14 @@ int libifc_unset_description(libifc_handle_t *h, const char *name)
|
||||
ifr.ifr_buffer.length = 0;
|
||||
ifr.ifr_buffer.buffer = NULL;
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int libifc_set_name(libifc_handle_t *h, const char *name, const char *newname)
|
||||
int ifconfig_set_name(ifconfig_handle_t *h, const char *name, const char *newname)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
char *tmpname;
|
||||
@ -234,7 +234,7 @@ int libifc_set_name(libifc_handle_t *h, const char *name, const char *newname)
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_data = tmpname;
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, &ifr) != 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, &ifr) != 0) {
|
||||
free(tmpname);
|
||||
return (-1);
|
||||
}
|
||||
@ -243,27 +243,27 @@ int libifc_set_name(libifc_handle_t *h, const char *name, const char *newname)
|
||||
}
|
||||
|
||||
|
||||
int libifc_set_mtu(libifc_handle_t *h, const char *name, const int mtu)
|
||||
int ifconfig_set_mtu(ifconfig_handle_t *h, const char *name, const int mtu)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_mtu = mtu;
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFMTU, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMTU, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int libifc_get_mtu(libifc_handle_t *h, const char *name, int *mtu)
|
||||
int ifconfig_get_mtu(ifconfig_handle_t *h, const char *name, int *mtu)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCGIFMTU, &ifr) == -1) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMTU, &ifr) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
*mtu = ifr.ifr_mtu;
|
||||
@ -271,27 +271,27 @@ int libifc_get_mtu(libifc_handle_t *h, const char *name, int *mtu)
|
||||
}
|
||||
|
||||
|
||||
int libifc_set_metric(libifc_handle_t *h, const char *name, const int mtu)
|
||||
int ifconfig_set_metric(ifconfig_handle_t *h, const char *name, const int mtu)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_mtu = mtu;
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFMETRIC, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMETRIC, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int libifc_get_metric(libifc_handle_t *h, const char *name, int *metric)
|
||||
int ifconfig_get_metric(ifconfig_handle_t *h, const char *name, int *metric)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCGIFMETRIC, &ifr) == -1) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMETRIC, &ifr) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
*metric = ifr.ifr_metric;
|
||||
@ -299,16 +299,16 @@ int libifc_get_metric(libifc_handle_t *h, const char *name, int *metric)
|
||||
}
|
||||
|
||||
|
||||
int libifc_set_capability(libifc_handle_t *h, const char *name,
|
||||
int ifconfig_set_capability(ifconfig_handle_t *h, const char *name,
|
||||
const int capability)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
struct libifc_capabilities ifcap;
|
||||
struct ifconfig_capabilities ifcap;
|
||||
int flags;
|
||||
int value;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
if (libifc_get_capability(h, name, &ifcap) != 0) {
|
||||
if (ifconfig_get_capability(h, name, &ifcap) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -329,22 +329,22 @@ int libifc_set_capability(libifc_handle_t *h, const char *name,
|
||||
* set for this request.
|
||||
*/
|
||||
ifr.ifr_reqcap = flags;
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCSIFCAP, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFCAP, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int libifc_get_capability(libifc_handle_t *h, const char *name,
|
||||
struct libifc_capabilities *capability)
|
||||
int ifconfig_get_capability(ifconfig_handle_t *h, const char *name,
|
||||
struct ifconfig_capabilities *capability)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCGIFCAP, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFCAP, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
capability->curcap = ifr.ifr_curcap;
|
||||
@ -353,21 +353,21 @@ int libifc_get_capability(libifc_handle_t *h, const char *name,
|
||||
}
|
||||
|
||||
|
||||
int libifc_destroy_interface(libifc_handle_t *h, const char *name)
|
||||
int ifconfig_destroy_interface(ifconfig_handle_t *h, const char *name)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
(void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCIFDESTROY, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFDESTROY, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int libifc_create_interface(libifc_handle_t *h, const char *name, char **ifname)
|
||||
int ifconfig_create_interface(ifconfig_handle_t *h, const char *name, char **ifname)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
@ -389,7 +389,7 @@ int libifc_create_interface(libifc_handle_t *h, const char *name, char **ifname)
|
||||
|
||||
/* No special handling for this interface type. */
|
||||
|
||||
if (libifc_ioctlwrap(h, AF_LOCAL, SIOCIFCREATE2, &ifr) < 0) {
|
||||
if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFCREATE2, &ifr) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
*ifname = strdup(ifr.ifr_name);
|
@ -34,16 +34,16 @@
|
||||
|
||||
typedef enum {
|
||||
OTHER, IOCTL, SOCKET
|
||||
} libifc_errtype;
|
||||
} ifconfig_errtype;
|
||||
|
||||
/*
|
||||
* Opaque definition so calling application can just pass a
|
||||
* pointer to it for library use.
|
||||
*/
|
||||
struct libifc_handle;
|
||||
typedef struct libifc_handle libifc_handle_t;
|
||||
struct ifconfig_handle;
|
||||
typedef struct ifconfig_handle ifconfig_handle_t;
|
||||
|
||||
struct libifc_capabilities {
|
||||
struct ifconfig_capabilities {
|
||||
/** Current capabilities (ifconfig prints this as 'options')*/
|
||||
int curcap;
|
||||
/** Requested capabilities (ifconfig prints this as 'capabilities')*/
|
||||
@ -55,57 +55,57 @@ struct libifc_capabilities {
|
||||
* Example usage:
|
||||
*{@code
|
||||
* // Create state object
|
||||
* libifc_handle_t *lifh = libifc_open();
|
||||
* ifconfig_handle_t *lifh = ifconfig_open();
|
||||
*
|
||||
* // Do stuff with it
|
||||
*
|
||||
* // Dispose of the state object
|
||||
* libifc_close(lifh);
|
||||
* ifconfig_close(lifh);
|
||||
* lifh = NULL;
|
||||
*}
|
||||
*/
|
||||
libifc_handle_t *libifc_open(void);
|
||||
ifconfig_handle_t *ifconfig_open(void);
|
||||
|
||||
/** Frees resources held in the provided state object.
|
||||
* @param h The state object to close.
|
||||
* @see #libifc_open(void)
|
||||
* @see #ifconfig_open(void)
|
||||
*/
|
||||
void libifc_close(libifc_handle_t *h);
|
||||
void ifconfig_close(ifconfig_handle_t *h);
|
||||
|
||||
/** Identifies what kind of error occured. */
|
||||
libifc_errtype libifc_err_errtype(libifc_handle_t *h);
|
||||
ifconfig_errtype ifconfig_err_errtype(ifconfig_handle_t *h);
|
||||
|
||||
/** Retrieves the errno associated with the error, if any. */
|
||||
int libifc_err_errno(libifc_handle_t *h);
|
||||
int ifconfig_err_errno(ifconfig_handle_t *h);
|
||||
|
||||
/** If error type was IOCTL, this identifies which request failed. */
|
||||
unsigned long libifc_err_ioctlreq(libifc_handle_t *h);
|
||||
unsigned long ifconfig_err_ioctlreq(ifconfig_handle_t *h);
|
||||
|
||||
int libifc_get_description(libifc_handle_t *h, const char *name,
|
||||
int ifconfig_get_description(ifconfig_handle_t *h, const char *name,
|
||||
char **description);
|
||||
int libifc_set_description(libifc_handle_t *h, const char *name,
|
||||
int ifconfig_set_description(ifconfig_handle_t *h, const char *name,
|
||||
const char *newdescription);
|
||||
int libifc_unset_description(libifc_handle_t *h, const char *name);
|
||||
int libifc_set_name(libifc_handle_t *h, const char *name, const char *newname);
|
||||
int libifc_set_mtu(libifc_handle_t *h, const char *name, const int mtu);
|
||||
int libifc_get_mtu(libifc_handle_t *h, const char *name, int *mtu);
|
||||
int ifconfig_unset_description(ifconfig_handle_t *h, const char *name);
|
||||
int ifconfig_set_name(ifconfig_handle_t *h, const char *name, const char *newname);
|
||||
int ifconfig_set_mtu(ifconfig_handle_t *h, const char *name, const int mtu);
|
||||
int ifconfig_get_mtu(ifconfig_handle_t *h, const char *name, int *mtu);
|
||||
|
||||
int libifc_set_metric(libifc_handle_t *h, const char *name, const int metric);
|
||||
int libifc_get_metric(libifc_handle_t *h, const char *name, int *metric);
|
||||
int ifconfig_set_metric(ifconfig_handle_t *h, const char *name, const int metric);
|
||||
int ifconfig_get_metric(ifconfig_handle_t *h, const char *name, int *metric);
|
||||
|
||||
int libifc_set_capability(libifc_handle_t *h, const char *name,
|
||||
int ifconfig_set_capability(ifconfig_handle_t *h, const char *name,
|
||||
const int capability);
|
||||
int libifc_get_capability(libifc_handle_t *h, const char *name,
|
||||
struct libifc_capabilities *capability);
|
||||
int ifconfig_get_capability(ifconfig_handle_t *h, const char *name,
|
||||
struct ifconfig_capabilities *capability);
|
||||
|
||||
/** Destroy a virtual interface
|
||||
* @param name Interface to destroy
|
||||
*/
|
||||
int libifc_destroy_interface(libifc_handle_t *h, const char *name);
|
||||
int ifconfig_destroy_interface(ifconfig_handle_t *h, const char *name);
|
||||
|
||||
/** Creates a (virtual) interface
|
||||
* @param name Name of interface to create. Example: bridge or bridge42
|
||||
* @param name ifname Is set to actual name of created interface
|
||||
*/
|
||||
int libifc_create_interface(libifc_handle_t *h, const char *name,
|
||||
int ifconfig_create_interface(ifconfig_handle_t *h, const char *name,
|
||||
char **ifname);
|
@ -40,11 +40,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "libifc.h" // Needed for libifc_errstate
|
||||
#include "libifc_internal.h"
|
||||
#include "libifconfig.h" // Needed for ifconfig_errstate
|
||||
#include "libifconfig_internal.h"
|
||||
|
||||
int
|
||||
libifc_ioctlwrap_ret(libifc_handle_t *h, unsigned long request, int rcode)
|
||||
ifconfig_ioctlwrap_ret(ifconfig_handle_t *h, unsigned long request, int rcode)
|
||||
{
|
||||
if (rcode != 0) {
|
||||
h->error.errtype = IOCTL;
|
||||
@ -56,17 +56,17 @@ libifc_ioctlwrap_ret(libifc_handle_t *h, unsigned long request, int rcode)
|
||||
|
||||
|
||||
int
|
||||
libifc_ioctlwrap(libifc_handle_t *h, const int addressfamily,
|
||||
ifconfig_ioctlwrap(ifconfig_handle_t *h, const int addressfamily,
|
||||
unsigned long request, struct ifreq *ifr)
|
||||
{
|
||||
int s;
|
||||
|
||||
if (libifc_socket(h, addressfamily, &s) != 0) {
|
||||
if (ifconfig_socket(h, addressfamily, &s) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int rcode = ioctl(s, request, ifr);
|
||||
return (libifc_ioctlwrap_ret(h, request, rcode));
|
||||
return (ifconfig_ioctlwrap_ret(h, request, rcode));
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ libifc_ioctlwrap(libifc_handle_t *h, const int addressfamily,
|
||||
* Function to get socket for the specified address family.
|
||||
* If the socket doesn't already exist, attempt to create it.
|
||||
*/
|
||||
int libifc_socket(libifc_handle_t *h, const int addressfamily, int *s)
|
||||
int ifconfig_socket(ifconfig_handle_t *h, const int addressfamily, int *s)
|
||||
{
|
||||
if (addressfamily > AF_MAX) {
|
||||
h->error.errtype = SOCKET;
|
@ -32,14 +32,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "libifc.h"
|
||||
#include "libifconfig.h"
|
||||
|
||||
|
||||
struct errstate {
|
||||
/**
|
||||
* Type of error.
|
||||
*/
|
||||
libifc_errtype errtype;
|
||||
ifconfig_errtype errtype;
|
||||
|
||||
/**
|
||||
* The error occured in this ioctl() request.
|
||||
@ -53,7 +53,7 @@ struct errstate {
|
||||
int errcode;
|
||||
};
|
||||
|
||||
struct libifc_handle {
|
||||
struct ifconfig_handle {
|
||||
struct errstate error;
|
||||
int sockets[AF_MAX + 1];
|
||||
};
|
||||
@ -69,7 +69,7 @@ struct libifc_handle {
|
||||
* {@code
|
||||
* static void myfunc() \{
|
||||
* int s;
|
||||
* if (libifc_socket(AF_LOCAL, &s) != 0) \{
|
||||
* if (ifconfig_socket(AF_LOCAL, &s) != 0) \{
|
||||
* // Handle error state here
|
||||
* \}
|
||||
* // user code here
|
||||
@ -77,11 +77,11 @@ struct libifc_handle {
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
int libifc_socket(libifc_handle_t *h, const int addressfamily, int *s);
|
||||
int ifconfig_socket(ifconfig_handle_t *h, const int addressfamily, int *s);
|
||||
|
||||
/** Function used by other wrapper functions to populate _errstate when appropriate.*/
|
||||
int libifc_ioctlwrap_ret(libifc_handle_t *h, unsigned long request, int rcode);
|
||||
int ifconfig_ioctlwrap_ret(ifconfig_handle_t *h, unsigned long request, int rcode);
|
||||
|
||||
/** Function to wrap ioctl() and automatically populate libifc_errstate when appropriate.*/
|
||||
int libifc_ioctlwrap(libifc_handle_t *h, const int addressfamily,
|
||||
/** Function to wrap ioctl() and automatically populate ifconfig_errstate when appropriate.*/
|
||||
int ifconfig_ioctlwrap(ifconfig_handle_t *h, const int addressfamily,
|
||||
unsigned long request, struct ifreq *ifr);
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
default:
|
||||
$(CC) -Wall -fPIC -lifc -g -o example_setdescription setdescription.c
|
||||
$(CC) -Wall -fPIC -lifc -g -o example_setmtu setmtu.c
|
||||
$(CC) -Wall -fPIC -lifc -g -o example_ifdestroy ifdestroy.c
|
||||
$(CC) -Wall -fPIC -lifc -g -o example_ifcreate ifcreate.c
|
||||
clean:
|
||||
rm -f example_*
|
8
share/examples/libifconfig/Makefile
Normal file
8
share/examples/libifconfig/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
# $FreeBSD$
|
||||
default:
|
||||
$(CC) -Wall -fPIC -lifconfig -g -o example_setdescription setdescription.c
|
||||
$(CC) -Wall -fPIC -lifconfig -g -o example_setmtu setmtu.c
|
||||
$(CC) -Wall -fPIC -lifconfig -g -o example_ifdestroy ifdestroy.c
|
||||
$(CC) -Wall -fPIC -lifconfig -g -o example_ifcreate ifcreate.c
|
||||
clean:
|
||||
rm -f example_*
|
@ -37,7 +37,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libifc.h>
|
||||
#include <libifconfig.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -55,21 +55,21 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("Requested interface name: %s\n", ifname);
|
||||
|
||||
libifc_handle_t *lifh = libifc_open();
|
||||
if (libifc_create_interface(lifh, ifname, &ifactualname) == 0) {
|
||||
ifconfig_handle_t *lifh = ifconfig_open();
|
||||
if (ifconfig_create_interface(lifh, ifname, &ifactualname) == 0) {
|
||||
printf("Successfully created interface '%s'\n", ifactualname);
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
free(ifactualname);
|
||||
return (0);
|
||||
} else {
|
||||
switch (libifc_err_errtype(lifh)) {
|
||||
switch (ifconfig_err_errtype(lifh)) {
|
||||
case SOCKET:
|
||||
warnx("couldn't create socket. This shouldn't happen.\n");
|
||||
break;
|
||||
case IOCTL:
|
||||
if (libifc_err_ioctlreq(lifh) == SIOCIFCREATE2) {
|
||||
if (ifconfig_err_ioctlreq(lifh) == SIOCIFCREATE2) {
|
||||
warnx(
|
||||
"Failed to create interface (SIOCIFCREATE2)\n");
|
||||
}
|
||||
@ -79,12 +79,12 @@ int main(int argc, char *argv[])
|
||||
"This is a thorough example accommodating for temporary"
|
||||
" 'not implemented yet' errors. That's likely what happened"
|
||||
" now. If not, your guess is as good as mine. ;)"
|
||||
" Error code: %d\n", libifc_err_errno(
|
||||
" Error code: %d\n", ifconfig_err_errno(
|
||||
lifh));
|
||||
break;
|
||||
}
|
||||
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
free(ifactualname);
|
@ -37,7 +37,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libifc.h>
|
||||
#include <libifconfig.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -55,20 +55,20 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("Interface name: %s\n", ifname);
|
||||
|
||||
libifc_handle_t *lifh = libifc_open();
|
||||
if (libifc_destroy_interface(lifh, ifname) == 0) {
|
||||
ifconfig_handle_t *lifh = ifconfig_open();
|
||||
if (ifconfig_destroy_interface(lifh, ifname) == 0) {
|
||||
printf("Successfully destroyed interface '%s'.", ifname);
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
return (0);
|
||||
} else {
|
||||
switch (libifc_err_errtype(lifh)) {
|
||||
switch (ifconfig_err_errtype(lifh)) {
|
||||
case SOCKET:
|
||||
warnx("couldn't create socket. This shouldn't happen.\n");
|
||||
break;
|
||||
case IOCTL:
|
||||
if (libifc_err_ioctlreq(lifh) == SIOCIFDESTROY) {
|
||||
if (ifconfig_err_ioctlreq(lifh) == SIOCIFDESTROY) {
|
||||
warnx(
|
||||
"Failed to destroy interface (SIOCIFDESTROY)\n");
|
||||
}
|
||||
@ -79,7 +79,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
return (-1);
|
@ -35,7 +35,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libifc.h>
|
||||
#include <libifconfig.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -54,27 +54,27 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("Interface name: %s\n", ifname);
|
||||
|
||||
libifc_handle_t *lifh = libifc_open();
|
||||
if (libifc_get_description(lifh, ifname, &curdescr) == 0) {
|
||||
ifconfig_handle_t *lifh = ifconfig_open();
|
||||
if (ifconfig_get_description(lifh, ifname, &curdescr) == 0) {
|
||||
printf("Old description: %s\n", curdescr);
|
||||
}
|
||||
|
||||
printf("New description: %s\n\n", ifdescr);
|
||||
|
||||
if (libifc_set_description(lifh, ifname, ifdescr) == 0) {
|
||||
if (ifconfig_set_description(lifh, ifname, ifdescr) == 0) {
|
||||
printf("New description successfully set.\n");
|
||||
} else {
|
||||
switch (libifc_err_errtype(lifh)) {
|
||||
switch (ifconfig_err_errtype(lifh)) {
|
||||
case SOCKET:
|
||||
err(libifc_err_errno(lifh), "Socket error");
|
||||
err(ifconfig_err_errno(lifh), "Socket error");
|
||||
break;
|
||||
case IOCTL:
|
||||
err(libifc_err_errno(
|
||||
err(ifconfig_err_errno(
|
||||
lifh), "IOCTL(%lu) error",
|
||||
libifc_err_ioctlreq(lifh));
|
||||
ifconfig_err_ioctlreq(lifh));
|
||||
break;
|
||||
case OTHER:
|
||||
err(libifc_err_errno(lifh), "Other error");
|
||||
err(ifconfig_err_errno(lifh), "Other error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -86,6 +86,6 @@ int main(int argc, char *argv[])
|
||||
ifdescr = NULL;
|
||||
curdescr = NULL;
|
||||
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
return (0);
|
||||
}
|
@ -37,7 +37,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libifc.h>
|
||||
#include <libifconfig.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -58,26 +58,26 @@ int main(int argc, char *argv[])
|
||||
printf("Interface name: %s\n", ifname);
|
||||
printf("New MTU: %d", mtu);
|
||||
|
||||
libifc_handle_t *lifh = libifc_open();
|
||||
if (libifc_set_mtu(lifh, ifname, mtu) == 0) {
|
||||
ifconfig_handle_t *lifh = ifconfig_open();
|
||||
if (ifconfig_set_mtu(lifh, ifname, mtu) == 0) {
|
||||
printf("Successfully changed MTU of %s to %d\n", ifname, mtu);
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
return (0);
|
||||
} else {
|
||||
switch (libifc_err_errtype(lifh)) {
|
||||
switch (ifconfig_err_errtype(lifh)) {
|
||||
case SOCKET:
|
||||
warnx("couldn't create socket. This shouldn't happen.\n");
|
||||
break;
|
||||
case IOCTL:
|
||||
if (libifc_err_ioctlreq(lifh) == SIOCSIFMTU) {
|
||||
if (ifconfig_err_ioctlreq(lifh) == SIOCSIFMTU) {
|
||||
warnx("Failed to set MTU (SIOCSIFMTU)\n");
|
||||
} else {
|
||||
warnx(
|
||||
"Failed to set MTU due to error in unexpected ioctl() call %lu. Error code: %i.\n",
|
||||
libifc_err_ioctlreq(lifh),
|
||||
libifc_err_errno(lifh));
|
||||
ifconfig_err_ioctlreq(lifh),
|
||||
ifconfig_err_errno(lifh));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
libifc_close(lifh);
|
||||
ifconfig_close(lifh);
|
||||
lifh = NULL;
|
||||
free(ifname);
|
||||
return (-1);
|
@ -82,7 +82,7 @@ LIBIBMAD?= ${DESTDIR}${LIBDIR}/libibmad.a
|
||||
LIBIBSDP?= ${DESTDIR}${LIBDIR}/libibsdp.a
|
||||
LIBIBUMAD?= ${DESTDIR}${LIBDIR}/libibumad.a
|
||||
LIBIBVERBS?= ${DESTDIR}${LIBDIR}/libibverbs.a
|
||||
LIBIFC?= ${DESTDIR}${LIBDIR}/libifc.a
|
||||
LIBIFCONFIG?= ${DESTDIR}${LIBDIR}/libifconfig.a
|
||||
LIBIPSEC?= ${DESTDIR}${LIBDIR}/libipsec.a
|
||||
LIBJAIL?= ${DESTDIR}${LIBDIR}/libjail.a
|
||||
LIBKADM5CLNT?= ${DESTDIR}${LIBDIR}/libkadm5clnt.a
|
||||
|
@ -105,7 +105,7 @@ _LIBRARIES= \
|
||||
heimntlm \
|
||||
heimsqlite \
|
||||
hx509 \
|
||||
ifc \
|
||||
ifconfig \
|
||||
ipsec \
|
||||
jail \
|
||||
kadm5clnt \
|
||||
|
Loading…
Reference in New Issue
Block a user