Index: projects/clang390-import/contrib/libcxxrt/unwind-arm.h =================================================================== --- projects/clang390-import/contrib/libcxxrt/unwind-arm.h (revision 305396) +++ projects/clang390-import/contrib/libcxxrt/unwind-arm.h (revision 305397) @@ -1,225 +1,227 @@ /* * Copyright 2012 David Chisnall. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * ARM-specific unwind definitions. These are taken from the ARM EHABI * specification. */ typedef enum { _URC_OK = 0, /* operation completed successfully */ _URC_FOREIGN_EXCEPTION_CAUGHT = 1, - _URC_END_OF_STACK = 5, + _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8, _URC_FAILURE = 9, /* unspecified failure of some kind */ _URC_FATAL_PHASE1_ERROR = _URC_FAILURE } _Unwind_Reason_Code; typedef int _Unwind_Action; typedef uint32_t _Unwind_State; #ifdef __clang__ static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0; static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1; static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2; +static const _Unwind_State _US_ACTION_MASK = 3; #else // GCC fails at knowing what a constant expression is # define _US_VIRTUAL_UNWIND_FRAME 0 # define _US_UNWIND_FRAME_STARTING 1 -# define _US_UNWIND_FRAME_RESUME 2 +# define _US_UNWIND_FRAME_RESUME 2 +# define _US_ACTION_MASK 3 #endif typedef struct _Unwind_Context _Unwind_Context; typedef uint32_t _Unwind_EHT_Header; struct _Unwind_Exception { uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code, struct _Unwind_Exception *); /* Unwinder cache, private fields for the unwinder's use */ struct { uint32_t reserved1; uint32_t reserved2; uint32_t reserved3; uint32_t reserved4; uint32_t reserved5; /* init reserved1 to 0, then don't touch */ } unwinder_cache; /* Propagation barrier cache (valid after phase 1): */ struct { uint32_t sp; uint32_t bitpattern[5]; } barrier_cache; /* Cleanup cache (preserved over cleanup): */ struct { uint32_t bitpattern[4]; } cleanup_cache; /* Pr cache (for pr's benefit): */ struct { /** function start address */ uint32_t fnstart; /** pointer to EHT entry header word */ _Unwind_EHT_Header *ehtp; /** additional data */ uint32_t additional; uint32_t reserved1; } pr_cache; /** Force alignment of next item to 8-byte boundary */ long long int :0; }; /* Unwinding functions */ _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *ucbp); void _Unwind_Resume(struct _Unwind_Exception *ucbp); void _Unwind_Complete(struct _Unwind_Exception *ucbp); void _Unwind_DeleteException(struct _Unwind_Exception *ucbp); void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context*); typedef enum { _UVRSR_OK = 0, _UVRSR_NOT_IMPLEMENTED = 1, _UVRSR_FAILED = 2 } _Unwind_VRS_Result; typedef enum { _UVRSC_CORE = 0, _UVRSC_VFP = 1, _UVRSC_WMMXD = 3, _UVRSC_WMMXC = 4 } _Unwind_VRS_RegClass; typedef enum { _UVRSD_UINT32 = 0, _UVRSD_VFPX = 1, _UVRSD_UINT64 = 3, _UVRSD_FLOAT = 4, _UVRSD_DOUBLE = 5 } _Unwind_VRS_DataRepresentation; _Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, uint32_t regno, _Unwind_VRS_DataRepresentation representation, void *valuep); _Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, uint32_t regno, _Unwind_VRS_DataRepresentation representation, void *valuep); /* Return the base-address for data references. */ extern unsigned long _Unwind_GetDataRelBase(struct _Unwind_Context *); /* Return the base-address for text references. */ extern unsigned long _Unwind_GetTextRelBase(struct _Unwind_Context *); extern unsigned long _Unwind_GetRegionStart(struct _Unwind_Context *); typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, void *); extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); /** * The next set of functions are compatibility extensions, implementing Itanium * ABI functions on top of ARM ones. */ #define _UA_SEARCH_PHASE 1 #define _UA_CLEANUP_PHASE 2 #define _UA_HANDLER_FRAME 4 #define _UA_FORCE_UNWIND 8 static inline unsigned long _Unwind_GetGR(struct _Unwind_Context *context, int reg) { unsigned long val; _Unwind_VRS_Get(context, _UVRSC_CORE, reg, _UVRSD_UINT32, &val); return val; } static inline void _Unwind_SetGR(struct _Unwind_Context *context, int reg, unsigned long val) { _Unwind_VRS_Set(context, _UVRSC_CORE, reg, _UVRSD_UINT32, &val); } static inline unsigned long _Unwind_GetIP(_Unwind_Context *context) { // Low bit store the thumb state - discard it return _Unwind_GetGR(context, 15) & ~1; } static inline void _Unwind_SetIP(_Unwind_Context *context, unsigned long val) { // The lowest bit of the instruction pointer indicates whether we're in // thumb or ARM mode. This is assumed to be fixed throughout a function, // so must be propagated when setting the program counter. unsigned long thumbState = _Unwind_GetGR(context, 15) & 1; _Unwind_SetGR(context, 15, (val | thumbState)); } /** GNU API function that unwinds the frame */ _Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception*, struct _Unwind_Context*); #define DECLARE_PERSONALITY_FUNCTION(name) \ _Unwind_Reason_Code name(_Unwind_State state,\ struct _Unwind_Exception *exceptionObject,\ struct _Unwind_Context *context); #define BEGIN_PERSONALITY_FUNCTION(name) \ _Unwind_Reason_Code name(_Unwind_State state,\ struct _Unwind_Exception *exceptionObject,\ struct _Unwind_Context *context)\ {\ int version = 1;\ uint64_t exceptionClass = exceptionObject->exception_class;\ int actions;\ switch (state)\ {\ default: return _URC_FAILURE;\ case _US_VIRTUAL_UNWIND_FRAME:\ {\ actions = _UA_SEARCH_PHASE;\ break;\ }\ case _US_UNWIND_FRAME_STARTING:\ {\ actions = _UA_CLEANUP_PHASE;\ if (exceptionObject->barrier_cache.sp == _Unwind_GetGR(context, 13))\ {\ actions |= _UA_HANDLER_FRAME;\ }\ break;\ }\ case _US_UNWIND_FRAME_RESUME:\ {\ return continueUnwinding(exceptionObject, context);\ break;\ }\ }\ _Unwind_SetGR (context, 12, reinterpret_cast(exceptionObject));\ #define CALL_PERSONALITY_FUNCTION(name) name(state,exceptionObject,context) Index: projects/clang390-import/contrib/libcxxrt =================================================================== --- projects/clang390-import/contrib/libcxxrt (revision 305396) +++ projects/clang390-import/contrib/libcxxrt (revision 305397) Property changes on: projects/clang390-import/contrib/libcxxrt ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/contrib/libcxxrt:r304236-305396 Index: projects/clang390-import/lib/libifconfig/libifconfig.c =================================================================== --- projects/clang390-import/lib/libifconfig/libifconfig.c (revision 305396) +++ projects/clang390-import/lib/libifconfig/libifconfig.c (revision 305397) @@ -1,397 +1,421 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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$ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 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 #include #include #include #include #include #include #include #include #include "libifconfig.h" #include "libifconfig_internal.h" ifconfig_handle_t * ifconfig_open(void) { struct ifconfig_handle *h; - h = calloc(1, sizeof(struct ifconfig_handle)); - + h = calloc(1, sizeof(*h)); for (int i = 0; i <= AF_MAX; i++) { h->sockets[i] = -1; } - return (h); } - void ifconfig_close(ifconfig_handle_t *h) { + for (int i = 0; i <= AF_MAX; i++) { if (h->sockets[i] != -1) { (void)close(h->sockets[i]); } } free(h); } - ifconfig_errtype ifconfig_err_errtype(ifconfig_handle_t *h) { + return (h->error.errtype); } - int ifconfig_err_errno(ifconfig_handle_t *h) { + return (h->error.errcode); } - unsigned long ifconfig_err_ioctlreq(ifconfig_handle_t *h) { + return (h->error.ioctl_request); } - int -ifconfig_get_description(ifconfig_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; - size_t descrlen = 64; + char *descr; + size_t descrlen; - memset(&ifr, 0, sizeof(struct ifreq)); + descr = NULL; + descrlen = 64; + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + for (;;) { if ((descr = reallocf(descr, descrlen)) == NULL) { h->error.errtype = OTHER; h->error.errcode = ENOMEM; return (-1); } ifr.ifr_buffer.buffer = descr; ifr.ifr_buffer.length = descrlen; - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFDESCR, - &ifr) != 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFDESCR, &ifr) != 0) { return (-1); } if (ifr.ifr_buffer.buffer == descr) { if (strlen(descr) > 0) { *description = strdup(descr); free(descr); return (0); } } else if (ifr.ifr_buffer.length > descrlen) { descrlen = ifr.ifr_buffer.length; continue; } break; } free(descr); h->error.errtype = OTHER; h->error.errcode = 0; return (-1); } - int ifconfig_set_description(ifconfig_handle_t *h, const char *name, const char *newdescription) { struct ifreq ifr; int desclen; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); desclen = strlen(newdescription); /* * Unset description if the new description is 0 characters long. * TODO: Decide whether this should be an error condition instead. */ if (desclen == 0) { return (ifconfig_unset_description(h, name)); } (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - ifr.ifr_buffer.length = desclen + 1; ifr.ifr_buffer.buffer = strdup(newdescription); + if (ifr.ifr_buffer.buffer == NULL) { h->error.errtype = OTHER; h->error.errcode = ENOMEM; return (-1); } - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) != 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, + &ifr) != 0) { free(ifr.ifr_buffer.buffer); return (-1); } + free(ifr.ifr_buffer.buffer); return (0); } - -int ifconfig_unset_description(ifconfig_handle_t *h, const char *name) +int +ifconfig_unset_description(ifconfig_handle_t *h, const char *name) { struct ifreq ifr; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_buffer.length = 0; ifr.ifr_buffer.buffer = NULL; - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, &ifr) < 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFDESCR, + &ifr) < 0) { return (-1); } return (0); } - -int ifconfig_set_name(ifconfig_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; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); tmpname = strdup(newname); if (tmpname == NULL) { h->error.errtype = OTHER; h->error.errcode = ENOMEM; return (-1); } (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_data = tmpname; - - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, &ifr) != 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFNAME, + &ifr) != 0) { free(tmpname); return (-1); } + free(tmpname); return (0); } - -int ifconfig_set_mtu(ifconfig_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)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_mtu = mtu; - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMTU, &ifr) < 0) { + + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMTU, + &ifr) < 0) { return (-1); } + return (0); } - -int ifconfig_get_mtu(ifconfig_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)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMTU, &ifr) == -1) { + + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMTU, + &ifr) == -1) { return (-1); } + *mtu = ifr.ifr_mtu; return (0); } - -int ifconfig_set_metric(ifconfig_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)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_mtu = mtu; - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMETRIC, &ifr) < 0) { + + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFMETRIC, + &ifr) < 0) { return (-1); } + return (0); } - -int ifconfig_get_metric(ifconfig_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)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMETRIC, &ifr) == -1) { + + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFMETRIC, + &ifr) == -1) { return (-1); } + *metric = ifr.ifr_metric; return (0); } - -int ifconfig_set_capability(ifconfig_handle_t *h, const char *name, +int +ifconfig_set_capability(ifconfig_handle_t *h, const char *name, const int capability) { struct ifreq ifr; struct ifconfig_capabilities ifcap; - int flags; - int value; + int flags, value; - memset(&ifr, 0, sizeof(struct ifreq)); - if (ifconfig_get_capability(h, name, &ifcap) != 0) { + memset(&ifr, 0, sizeof(ifr)); + + if (ifconfig_get_capability(h, name, + &ifcap) != 0) { return (-1); } value = capability; flags = ifcap.curcap; if (value < 0) { value = -value; flags &= ~value; } else { flags |= value; } flags &= ifcap.reqcap; (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); /* * TODO: Verify that it's safe to not have ifr.ifr_curcap * set for this request. */ ifr.ifr_reqcap = flags; - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFCAP, &ifr) < 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCSIFCAP, + &ifr) < 0) { return (-1); } return (0); } - -int ifconfig_get_capability(ifconfig_handle_t *h, const char *name, +int +ifconfig_get_capability(ifconfig_handle_t *h, const char *name, struct ifconfig_capabilities *capability) { struct ifreq ifr; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFCAP, &ifr) < 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGIFCAP, + &ifr) < 0) { return (-1); } capability->curcap = ifr.ifr_curcap; capability->reqcap = ifr.ifr_reqcap; return (0); } - -int ifconfig_destroy_interface(ifconfig_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)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFDESTROY, &ifr) < 0) { + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFDESTROY, + &ifr) < 0) { return (-1); } return (0); } - -int ifconfig_create_interface(ifconfig_handle_t *h, const char *name, char **ifname) +int +ifconfig_create_interface(ifconfig_handle_t *h, const char *name, char **ifname) { struct ifreq ifr; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); /* * TODO: * Insert special snowflake handling here. See GitHub issue #12 for details. * In the meantime, hard-nosupport interfaces that need special handling. */ - if ((strncmp(name, "wlan", strlen("wlan")) == 0) || - (strncmp(name, "vlan", strlen("vlan")) == 0) || - (strncmp(name, "vxlan", strlen("vxlan")) == 0)) { + if ((strncmp(name, "wlan", + strlen("wlan")) == 0) || + (strncmp(name, "vlan", + strlen("vlan")) == 0) || + (strncmp(name, "vxlan", + strlen("vxlan")) == 0)) { h->error.errtype = OTHER; h->error.errcode = ENOSYS; return (-1); } /* No special handling for this interface type. */ - if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFCREATE2, &ifr) < 0) { return (-1); } + *ifname = strdup(ifr.ifr_name); return (0); } Index: projects/clang390-import/lib/libifconfig/libifconfig.h =================================================================== --- projects/clang390-import/lib/libifconfig/libifconfig.h (revision 305396) +++ projects/clang390-import/lib/libifconfig/libifconfig.h (revision 305397) @@ -1,111 +1,105 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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$ */ #pragma once typedef enum { OTHER, IOCTL, SOCKET } ifconfig_errtype; /* * Opaque definition so calling application can just pass a * pointer to it for library use. */ struct ifconfig_handle; typedef struct ifconfig_handle ifconfig_handle_t; struct ifconfig_capabilities { /** Current capabilities (ifconfig prints this as 'options')*/ int curcap; /** Requested capabilities (ifconfig prints this as 'capabilities')*/ int reqcap; }; - /** Retrieves a new state object for use in other API calls. * Example usage: *{@code * // Create state object * ifconfig_handle_t *lifh = ifconfig_open(); * * // Do stuff with it * * // Dispose of the state object * ifconfig_close(lifh); * lifh = NULL; *} */ ifconfig_handle_t *ifconfig_open(void); /** Frees resources held in the provided state object. * @param h The state object to close. * @see #ifconfig_open(void) */ void ifconfig_close(ifconfig_handle_t *h); /** Identifies what kind of error occured. */ ifconfig_errtype ifconfig_err_errtype(ifconfig_handle_t *h); /** Retrieves the errno associated with the error, if any. */ int ifconfig_err_errno(ifconfig_handle_t *h); /** If error type was IOCTL, this identifies which request failed. */ unsigned long ifconfig_err_ioctlreq(ifconfig_handle_t *h); - int ifconfig_get_description(ifconfig_handle_t *h, const char *name, char **description); int ifconfig_set_description(ifconfig_handle_t *h, const char *name, const char *newdescription); 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_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 ifconfig_set_metric(ifconfig_handle_t *h, const char *name, const 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 ifconfig_set_capability(ifconfig_handle_t *h, const char *name, const int 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 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 ifconfig_create_interface(ifconfig_handle_t *h, const char *name, char **ifname); Index: projects/clang390-import/lib/libifconfig/libifconfig_internal.c =================================================================== --- projects/clang390-import/lib/libifconfig/libifconfig_internal.c (revision 305396) +++ projects/clang390-import/lib/libifconfig/libifconfig_internal.c (revision 305397) @@ -1,100 +1,98 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include -#include #include - #include "libifconfig.h" // Needed for ifconfig_errstate #include "libifconfig_internal.h" + int ifconfig_ioctlwrap_ret(ifconfig_handle_t *h, unsigned long request, int rcode) { + if (rcode != 0) { h->error.errtype = IOCTL; h->error.ioctl_request = request; h->error.errcode = errno; } + return (rcode); } - int ifconfig_ioctlwrap(ifconfig_handle_t *h, const int addressfamily, unsigned long request, struct ifreq *ifr) { int s; if (ifconfig_socket(h, addressfamily, &s) != 0) { return (-1); } int rcode = ioctl(s, request, ifr); return (ifconfig_ioctlwrap_ret(h, request, rcode)); } - /* * Function to get socket for the specified address family. * If the socket doesn't already exist, attempt to create it. */ -int ifconfig_socket(ifconfig_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; h->error.errcode = EINVAL; return (-1); } if (h->sockets[addressfamily] != -1) { *s = h->sockets[addressfamily]; return (0); } /* We don't have a socket of that type available. Create one. */ h->sockets[addressfamily] = socket(addressfamily, SOCK_DGRAM, 0); if (h->sockets[addressfamily] == -1) { h->error.errtype = SOCKET; h->error.errcode = errno; return (-1); } *s = h->sockets[addressfamily]; return (0); } Index: projects/clang390-import/lib/libifconfig/libifconfig_internal.h =================================================================== --- projects/clang390-import/lib/libifconfig/libifconfig_internal.h (revision 305396) +++ projects/clang390-import/lib/libifconfig/libifconfig_internal.h (revision 305397) @@ -1,87 +1,84 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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$ */ #pragma once #include "libifconfig.h" struct errstate { /** * Type of error. */ ifconfig_errtype errtype; /** * The error occured in this ioctl() request. * Populated if errtype = IOCTL */ unsigned long ioctl_request; /** * The value of the global errno variable when the error occured. */ int errcode; }; struct ifconfig_handle { struct errstate error; int sockets[AF_MAX + 1]; }; /** * Retrieves socket for address family from * cache, or creates it if it doesn't already exist. * @param addressfamily The address family of the socket to retrieve * @param s The retrieved socket. * @return 0 on success, -1 on failure. * {@example * This example shows how to retrieve a socket from the cache. * {@code * static void myfunc() \{ * int s; * if (ifconfig_socket(AF_LOCAL, &s) != 0) \{ * // Handle error state here * \} * // user code here * \} * } * } */ int ifconfig_socket(ifconfig_handle_t *h, const int addressfamily, int *s); /** Function used by other wrapper functions to populate _errstate when appropriate.*/ -int ifconfig_ioctlwrap_ret(ifconfig_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 ifconfig_errstate when appropriate.*/ int ifconfig_ioctlwrap(ifconfig_handle_t *h, const int addressfamily, unsigned long request, struct ifreq *ifr); Index: projects/clang390-import/share/examples/libifconfig/ifcreate.c =================================================================== --- projects/clang390-import/share/examples/libifconfig/ifcreate.c (revision 305396) +++ projects/clang390-import/share/examples/libifconfig/ifcreate.c (revision 305397) @@ -1,93 +1,90 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include #include #include #include -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { + char *ifname, *ifactualname; + if (argc != 2) { errx(EINVAL, "Invalid number of arguments." " Only one argument is accepted, and it should be the name" " of the interface to be created."); } - char *ifname, *ifactualname; - /* We have a static number of arguments. Therefore we can do it simple. */ ifname = strdup(argv[1]); printf("Requested interface name: %s\n", ifname); ifconfig_handle_t *lifh = ifconfig_open(); if (ifconfig_create_interface(lifh, ifname, &ifactualname) == 0) { printf("Successfully created interface '%s'\n", ifactualname); ifconfig_close(lifh); lifh = NULL; free(ifname); free(ifactualname); return (0); - } else { - switch (ifconfig_err_errtype(lifh)) { - case SOCKET: - warnx("couldn't create socket. This shouldn't happen.\n"); - break; - case IOCTL: - if (ifconfig_err_ioctlreq(lifh) == SIOCIFCREATE2) { - warnx( - "Failed to create interface (SIOCIFCREATE2)\n"); - } - break; - default: + } + + switch (ifconfig_err_errtype(lifh)) { + case SOCKET: + warnx("couldn't create socket. This shouldn't happen.\n"); + break; + case IOCTL: + if (ifconfig_err_ioctlreq(lifh) == SIOCIFCREATE2) { warnx( - "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", ifconfig_err_errno( - lifh)); - break; + "Failed to create interface (SIOCIFCREATE2)\n"); } - - ifconfig_close(lifh); - lifh = NULL; - free(ifname); - free(ifactualname); - return (-1); + break; + default: + warnx( + "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", ifconfig_err_errno( + lifh)); + break; } + + ifconfig_close(lifh); + lifh = NULL; + free(ifname); + free(ifactualname); + return (-1); } Index: projects/clang390-import/share/examples/libifconfig/ifdestroy.c =================================================================== --- projects/clang390-import/share/examples/libifconfig/ifdestroy.c (revision 305396) +++ projects/clang390-import/share/examples/libifconfig/ifdestroy.c (revision 305397) @@ -1,87 +1,84 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include #include #include #include -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { + char *ifname; + if (argc != 2) { errx(EINVAL, "Invalid number of arguments." " Only one argument is accepted, and it should be the name" " of the interface to be destroyed."); } - char *ifname; - /* We have a static number of arguments. Therefore we can do it simple. */ ifname = strdup(argv[1]); printf("Interface name: %s\n", ifname); ifconfig_handle_t *lifh = ifconfig_open(); if (ifconfig_destroy_interface(lifh, ifname) == 0) { printf("Successfully destroyed interface '%s'.", ifname); ifconfig_close(lifh); lifh = NULL; free(ifname); return (0); - } else { - switch (ifconfig_err_errtype(lifh)) { - case SOCKET: - warnx("couldn't create socket. This shouldn't happen.\n"); - break; - case IOCTL: - if (ifconfig_err_ioctlreq(lifh) == SIOCIFDESTROY) { - warnx( - "Failed to destroy interface (SIOCIFDESTROY)\n"); - } - break; - default: + } + + switch (ifconfig_err_errtype(lifh)) { + case SOCKET: + warnx("couldn't create socket. This shouldn't happen.\n"); + break; + case IOCTL: + if (ifconfig_err_ioctlreq(lifh) == SIOCIFDESTROY) { warnx( - "Should basically never end up here in this example.\n"); - break; + "Failed to destroy interface (SIOCIFDESTROY)\n"); } - - ifconfig_close(lifh); - lifh = NULL; - free(ifname); - return (-1); + break; + default: + warnx( + "Should basically never end up here in this example.\n"); + break; } + + ifconfig_close(lifh); + lifh = NULL; + free(ifname); + return (-1); } Index: projects/clang390-import/share/examples/libifconfig/setdescription.c =================================================================== --- projects/clang390-import/share/examples/libifconfig/setdescription.c (revision 305396) +++ projects/clang390-import/share/examples/libifconfig/setdescription.c (revision 305397) @@ -1,91 +1,89 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include #include -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { + char *ifname, *ifdescr, *curdescr; + if (argc != 3) { errx(EINVAL, "Invalid number of arguments." " First argument should be interface name, second argument" " should be the description to set."); } - char *ifname, *ifdescr, *curdescr; /* We have a static number of arguments. Therefore we can do it simple. */ ifname = strdup(argv[1]); ifdescr = strdup(argv[2]); curdescr = NULL; printf("Interface name: %s\n", ifname); 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 (ifconfig_set_description(lifh, ifname, ifdescr) == 0) { printf("New description successfully set.\n"); } else { switch (ifconfig_err_errtype(lifh)) { case SOCKET: err(ifconfig_err_errno(lifh), "Socket error"); break; case IOCTL: err(ifconfig_err_errno( lifh), "IOCTL(%lu) error", ifconfig_err_ioctlreq(lifh)); break; case OTHER: err(ifconfig_err_errno(lifh), "Other error"); break; } } free(ifname); free(ifdescr); free(curdescr); ifname = NULL; ifdescr = NULL; curdescr = NULL; ifconfig_close(lifh); return (0); } Index: projects/clang390-import/share/examples/libifconfig/setmtu.c =================================================================== --- projects/clang390-import/share/examples/libifconfig/setmtu.c (revision 305396) +++ projects/clang390-import/share/examples/libifconfig/setmtu.c (revision 305397) @@ -1,94 +1,92 @@ /* * Copyright (c) 2016, Marie Helene Kvello-Aune * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * thislist of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include #include #include #include -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { + char *ifname, *ptr; + int mtu; + if (argc != 3) { errx(EINVAL, "Invalid number of arguments." " First argument should be interface name, second argument" " should be the MTU to set."); } - char *ifname, *ptr; - int mtu; - /* We have a static number of arguments. Therefore we can do it simple. */ ifname = strdup(argv[1]); mtu = (int)strtol(argv[2], &ptr, 10); printf("Interface name: %s\n", ifname); printf("New MTU: %d", mtu); 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); ifconfig_close(lifh); lifh = NULL; free(ifname); return (0); - } else { - switch (ifconfig_err_errtype(lifh)) { - case SOCKET: - warnx("couldn't create socket. This shouldn't happen.\n"); - break; - case IOCTL: - 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", - ifconfig_err_ioctlreq(lifh), - ifconfig_err_errno(lifh)); - } - break; - default: + } + + switch (ifconfig_err_errtype(lifh)) { + case SOCKET: + warnx("couldn't create socket. This shouldn't happen.\n"); + break; + case IOCTL: + if (ifconfig_err_ioctlreq(lifh) == SIOCSIFMTU) { + warnx("Failed to set MTU (SIOCSIFMTU)\n"); + } else { warnx( - "Should basically never end up here in this example.\n"); - break; + "Failed to set MTU due to error in unexpected ioctl() call %lu. Error code: %i.\n", + ifconfig_err_ioctlreq(lifh), + ifconfig_err_errno(lifh)); } - - ifconfig_close(lifh); - lifh = NULL; - free(ifname); - return (-1); + break; + default: + warnx( + "Should basically never end up here in this example.\n"); + break; } + + ifconfig_close(lifh); + lifh = NULL; + free(ifname); + return (-1); } Index: projects/clang390-import =================================================================== --- projects/clang390-import (revision 305396) +++ projects/clang390-import (revision 305397) Property changes on: projects/clang390-import ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r305394-305396