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