1ec214349SKristof Provost /* 2ec214349SKristof Provost * Copyright (c) 2016, Marie Helene Kvello-Aune 3ec214349SKristof Provost * All rights reserved. 4ec214349SKristof Provost * 5ec214349SKristof Provost * Redistribution and use in source and binary forms, with or without modification, 6ec214349SKristof Provost * are permitted provided that the following conditions are met: 7ec214349SKristof Provost * 8ec214349SKristof Provost * 1. Redistributions of source code must retain the above copyright notice, 9ec214349SKristof Provost * thislist of conditions and the following disclaimer. 10ec214349SKristof Provost * 11ec214349SKristof Provost * 2. Redistributions in binary form must reproduce the above copyright notice, 12ec214349SKristof Provost * this list of conditions and the following disclaimer in the documentation and/or 13ec214349SKristof Provost * other materials provided with the distribution. 14ec214349SKristof Provost * 15ec214349SKristof Provost * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16ec214349SKristof Provost * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17ec214349SKristof Provost * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18ec214349SKristof Provost * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19ec214349SKristof Provost * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20ec214349SKristof Provost * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21ec214349SKristof Provost * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22ec214349SKristof Provost * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23ec214349SKristof Provost * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24ec214349SKristof Provost * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25ec214349SKristof Provost * 26ec214349SKristof Provost * $FreeBSD$ 27ec214349SKristof Provost */ 28ec214349SKristof Provost 29ec214349SKristof Provost #pragma once 30ec214349SKristof Provost 31ec214349SKristof Provost typedef enum { 32ec214349SKristof Provost OTHER, IOCTL, SOCKET 33ec214349SKristof Provost } ifconfig_errtype; 34ec214349SKristof Provost 35ec214349SKristof Provost /* 36ec214349SKristof Provost * Opaque definition so calling application can just pass a 37ec214349SKristof Provost * pointer to it for library use. 38ec214349SKristof Provost */ 39ec214349SKristof Provost struct ifconfig_handle; 40ec214349SKristof Provost typedef struct ifconfig_handle ifconfig_handle_t; 41ec214349SKristof Provost 42ec214349SKristof Provost struct ifconfig_capabilities { 43ec214349SKristof Provost /** Current capabilities (ifconfig prints this as 'options')*/ 44ec214349SKristof Provost int curcap; 45ec214349SKristof Provost /** Requested capabilities (ifconfig prints this as 'capabilities')*/ 46ec214349SKristof Provost int reqcap; 47ec214349SKristof Provost }; 48ec214349SKristof Provost 49ec214349SKristof Provost /** Retrieves a new state object for use in other API calls. 50ec214349SKristof Provost * Example usage: 51ec214349SKristof Provost *{@code 52ec214349SKristof Provost * // Create state object 53ec214349SKristof Provost * ifconfig_handle_t *lifh = ifconfig_open(); 54ec214349SKristof Provost * 55ec214349SKristof Provost * // Do stuff with it 56ec214349SKristof Provost * 57ec214349SKristof Provost * // Dispose of the state object 58ec214349SKristof Provost * ifconfig_close(lifh); 59ec214349SKristof Provost * lifh = NULL; 60ec214349SKristof Provost *} 61ec214349SKristof Provost */ 62ec214349SKristof Provost ifconfig_handle_t *ifconfig_open(void); 63ec214349SKristof Provost 64ec214349SKristof Provost /** Frees resources held in the provided state object. 65ec214349SKristof Provost * @param h The state object to close. 66ec214349SKristof Provost * @see #ifconfig_open(void) 67ec214349SKristof Provost */ 68ec214349SKristof Provost void ifconfig_close(ifconfig_handle_t *h); 69ec214349SKristof Provost 70ec214349SKristof Provost /** Identifies what kind of error occured. */ 71ec214349SKristof Provost ifconfig_errtype ifconfig_err_errtype(ifconfig_handle_t *h); 72ec214349SKristof Provost 73ec214349SKristof Provost /** Retrieves the errno associated with the error, if any. */ 74ec214349SKristof Provost int ifconfig_err_errno(ifconfig_handle_t *h); 75ec214349SKristof Provost 76ec214349SKristof Provost /** If error type was IOCTL, this identifies which request failed. */ 77ec214349SKristof Provost unsigned long ifconfig_err_ioctlreq(ifconfig_handle_t *h); 78ec214349SKristof Provost int ifconfig_get_description(ifconfig_handle_t *h, const char *name, 79ec214349SKristof Provost char **description); 80ec214349SKristof Provost int ifconfig_set_description(ifconfig_handle_t *h, const char *name, 81ec214349SKristof Provost const char *newdescription); 82ec214349SKristof Provost int ifconfig_unset_description(ifconfig_handle_t *h, const char *name); 83*9a2ff315SKristof Provost int ifconfig_set_name(ifconfig_handle_t *h, const char *name, 84*9a2ff315SKristof Provost const char *newname); 85ec214349SKristof Provost int ifconfig_set_mtu(ifconfig_handle_t *h, const char *name, const int mtu); 86ec214349SKristof Provost int ifconfig_get_mtu(ifconfig_handle_t *h, const char *name, int *mtu); 87*9a2ff315SKristof Provost int ifconfig_set_metric(ifconfig_handle_t *h, const char *name, 88*9a2ff315SKristof Provost const int metric); 89ec214349SKristof Provost int ifconfig_get_metric(ifconfig_handle_t *h, const char *name, int *metric); 90ec214349SKristof Provost int ifconfig_set_capability(ifconfig_handle_t *h, const char *name, 91ec214349SKristof Provost const int capability); 92ec214349SKristof Provost int ifconfig_get_capability(ifconfig_handle_t *h, const char *name, 93ec214349SKristof Provost struct ifconfig_capabilities *capability); 94ec214349SKristof Provost 95ec214349SKristof Provost /** Destroy a virtual interface 96ec214349SKristof Provost * @param name Interface to destroy 97ec214349SKristof Provost */ 98ec214349SKristof Provost int ifconfig_destroy_interface(ifconfig_handle_t *h, const char *name); 99ec214349SKristof Provost 100ec214349SKristof Provost /** Creates a (virtual) interface 101ec214349SKristof Provost * @param name Name of interface to create. Example: bridge or bridge42 102ec214349SKristof Provost * @param name ifname Is set to actual name of created interface 103ec214349SKristof Provost */ 104ec214349SKristof Provost int ifconfig_create_interface(ifconfig_handle_t *h, const char *name, 105ec214349SKristof Provost char **ifname); 106