├── .github └── workflows │ ├── freebsd.yml │ ├── linux.yml │ ├── multiarch.yml │ └── packaging.yml ├── AUTHORS ├── BUGS ├── CMakeLists.txt ├── COPYING ├── ChangeLog ├── NEWS ├── README.md ├── autogen.sh ├── ci ├── build-tool ├── ci-build ├── ci-install ├── ci-setup ├── ci-test └── get-dependencies ├── cmake_uninstall.cmake.in ├── debian ├── changelog ├── compat ├── control ├── copyright ├── rules ├── source │ └── format ├── tests │ ├── control │ └── simple-test ├── upstream │ ├── metadata │ └── signing-key.asc └── watch ├── freebsd └── subnetcalc │ ├── Makefile │ ├── distinfo │ ├── pkg-descr │ └── test-packaging ├── packaging.conf ├── po ├── CMakeLists.txt ├── de │ └── subnetcalc.po ├── nb │ └── subnetcalc.po └── subnetcalc.sources ├── rpm └── subnetcalc.spec ├── src ├── CMakeLists.txt ├── package-version.h.in ├── subnetcalc.1 ├── subnetcalc.bash-completion ├── subnetcalc.cc ├── t1.cc ├── test1 ├── tools.cc └── tools.h └── website.config /.github/workflows/freebsd.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Scripts 2 | # Copyright (C) 2021-2025 by Thomas Dreibholz 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # 17 | # Contact: dreibh@simula.no 18 | 19 | name: FreeBSD CI Tests 20 | 21 | on: 22 | push: 23 | branches: 24 | - master 25 | - dreibh/github-actions 26 | - dreibh/github-actions-freebsd 27 | 28 | jobs: 29 | build_job: 30 | 31 | # ###### Build matrix ################################################### 32 | strategy: 33 | matrix: 34 | include: 35 | 36 | # ====== FreeBSD 14.1 ============================================= 37 | - label: "FreeBSD 14.1: Clang/x86_64" 38 | release: 14.1 39 | cc: clang 40 | cxx: clang++ 41 | 42 | 43 | # ###### Build commands ################################################# 44 | name: ${{ matrix.label }} 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | - name: Test in FreeBSD 49 | id: test 50 | uses: vmactions/freebsd-vm@v1 51 | with: 52 | release: ${{ matrix.release }} 53 | usesh: true 54 | run: | 55 | ASSUME_ALWAYS_YES=yes pkg install -y bash 56 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-setup compile 57 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-install compile 58 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-build compile 59 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Scripts 2 | # Copyright (C) 2021-2025 by Thomas Dreibholz 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # 17 | # Contact: dreibh@simula.no 18 | 19 | name: Linux CI Tests 20 | 21 | on: 22 | push: 23 | branches: 24 | - master 25 | - dreibh/github-actions 26 | 27 | jobs: 28 | build_job: 29 | 30 | # ###### Build matrix ################################################### 31 | strategy: 32 | matrix: 33 | include: 34 | 35 | # ====== Ubuntu Linux ============================================= 36 | - label: "Ubuntu 24.04 (Noble Numbat) with GCC" 37 | image: ubuntu:24.04 38 | cc: gcc 39 | cxx: g++ 40 | - label: "Ubuntu 22.04 (Jammy Jellyfish) with GCC" 41 | image: ubuntu:22.04 42 | cc: gcc 43 | cxx: g++ 44 | - label: "Ubuntu 20.04 (Focal Fossa) with GCC" 45 | image: ubuntu:20.04 46 | cc: gcc 47 | cxx: g++ 48 | 49 | # ====== Debian Linux ============================================= 50 | - label: "Debian 12 (Bookworm) with GCC" 51 | image: debian:bookworm 52 | cc: gcc 53 | cxx: g++ 54 | - label: "Debian 11 (Bullseye) with GCC" 55 | image: debian:bullseye 56 | cc: gcc 57 | cxx: g++ 58 | 59 | # ====== Fedora Linux ============================================= 60 | - label: "Fedora 40 with Clang" 61 | image: fedora:40 62 | cc: clang 63 | cxx: clang++ 64 | 65 | 66 | # ###### Build commands ################################################# 67 | name: ${{ matrix.label }} 68 | runs-on: ubuntu-latest 69 | container: 70 | image: ${{ matrix.image }} 71 | steps: 72 | # NOTE: actions/checkout@v4 does not work for old Ubuntu 18.04! 73 | - uses: actions/checkout@v4 74 | - name: Build 75 | shell: bash 76 | run: | 77 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ARCH= ci/ci-setup compile 78 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ARCH= ci/ci-install compile 79 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ARCH= ci/ci-build compile 80 | -------------------------------------------------------------------------------- /.github/workflows/multiarch.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Scripts 2 | # Copyright (C) 2021-2025 by Thomas Dreibholz 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # 17 | # Contact: dreibh@simula.no 18 | 19 | name: Linux Multi-Arch Tests 20 | 21 | on: 22 | push: 23 | branches: 24 | - master 25 | - dreibh/github-actions 26 | 27 | jobs: 28 | build_job: 29 | 30 | # ###### Build matrix ################################################### 31 | strategy: 32 | matrix: 33 | include: 34 | 35 | # ====== Ubuntu Linux ============================================= 36 | - label: "Ubuntu 22.04 (Noble Numbat): Clang/ARMv8" 37 | arch: aarch64 38 | distro: ubuntu22.04 39 | cc: clang 40 | cxx: clang++ 41 | - label: "Ubuntu 22.04 (Noble Numbat): GCC/S390x" 42 | arch: s390x 43 | distro: ubuntu22.04 44 | cc: gcc 45 | cxx: g++ 46 | - label: "Ubuntu 22.04 (Noble Numbat): GCC/RISC-V" 47 | arch: riscv64 48 | distro: ubuntu22.04 49 | cc: gcc 50 | cxx: g++ 51 | 52 | # ====== Debian Linux ============================================= 53 | - label: "Debian 12 (Bookworm): GCC/i386" 54 | arch: i386 55 | distro: bookworm 56 | cc: gcc 57 | cxx: g++ 58 | - label: "Debian 12 (Bookworm): Clang/ARMv7" 59 | arch: arm32v7 60 | distro: bookworm 61 | cc: clang 62 | cxx: clang++ 63 | 64 | # ====== Fedora Linux ============================================= 65 | - label: "Fedora 41: GCC/PPC64" 66 | arch: ppc64le 67 | distro: fedora41 68 | cc: gcc 69 | cxx: g++ 70 | 71 | 72 | # ###### Build commands ################################################# 73 | name: ${{ matrix.label }} 74 | runs-on: ubuntu-latest 75 | steps: 76 | - uses: actions/checkout@v4 77 | # NOTE: dreibh/run-on-arch-action provides the upstream 78 | # uraimo/run-on-arch-action action, with additional dockerfiles 79 | # needed for the builds here! 80 | - uses: dreibh/run-on-arch-action@dreibh/tests 81 | name: Build 82 | id: build 83 | with: 84 | arch: ${{ matrix.arch }} 85 | distro: ${{ matrix.distro }} 86 | run: | 87 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-setup compile 88 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-install compile 89 | CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} ci/ci-build compile 90 | -------------------------------------------------------------------------------- /.github/workflows/packaging.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Scripts 2 | # Copyright (C) 2021-2025 by Thomas Dreibholz 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # 17 | # Contact: dreibh@simula.no 18 | 19 | name: Packaging CI Tests 20 | 21 | on: 22 | push: 23 | branches: 24 | - master 25 | - dreibh/github-actions 26 | 27 | jobs: 28 | # ====== Ubuntu Linux ===================================================== 29 | ubuntu-packaging: 30 | name: Ubuntu Packaging 31 | runs-on: ubuntu-24.04 32 | steps: 33 | - uses: actions/checkout@v4 34 | - name: Packaging 35 | shell: bash 36 | run: | 37 | sudo CC=gcc CXX=g++ OS=ubuntu DIST=noble ARCH= ci/ci-setup package 38 | sudo CC=gcc CXX=g++ OS=ubuntu DIST=noble ARCH= ci/ci-install package 39 | sudo CC=gcc CXX=g++ OS=ubuntu DIST=noble ARCH= ci/ci-build package 40 | sudo ci/ci-test 41 | 42 | # ====== Debian Linux ===================================================== 43 | debian-packaging: 44 | name: Debian Packaging 45 | runs-on: ubuntu-latest 46 | container: 47 | image: debian:unstable 48 | options: --privileged 49 | steps: 50 | - uses: actions/checkout@v4 51 | - name: Packaging 52 | shell: bash 53 | run: | 54 | CC=gcc CXX=g++ OS=debian DIST=unstable ARCH= ci/ci-setup package 55 | CC=gcc CXX=g++ OS=debian DIST=unstable ARCH= ci/ci-install package 56 | CC=gcc CXX=g++ OS=debian DIST=unstable ARCH= ci/ci-build package 57 | # ci/ci-test <- Not running on Ubuntu! 58 | 59 | # ====== Fedora Linux ===================================================== 60 | fedora-packaging: 61 | name: Fedora Packaging 62 | runs-on: ubuntu-latest 63 | container: 64 | # Using Fedora 39 here, due to problems with Mock! 65 | # => https://github.com/rpm-software-management/mock/issues/1487 66 | image: fedora:39 67 | options: --privileged --cap-add=SYS_ADMIN 68 | steps: 69 | - uses: actions/checkout@v4 70 | - name: Packaging 71 | shell: bash 72 | run: | 73 | CC=clang CXX=clang++ ARCH= ci/ci-setup package 74 | CC=clang CXX=clang++ ARCH= ci/ci-install package 75 | CC=clang CXX=clang++ ARCH= ci/ci-build package 76 | ci/ci-test 77 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Thomas Dreibholz 2 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dreibh/subnetcalc/ea968434a44e6998e01b39ced3f53388e68d4b3e/BUGS -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ========================================================================== 2 | # ____ _ _ _ _ ____ _ 3 | # / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | # \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | # ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | # |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | # 8 | # --- IPv4/IPv6 Subnet Calculator --- 9 | # https://www.nntb.no/~dreibh/subnetcalc/ 10 | # ========================================================================== 11 | # 12 | # SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | # Copyright (C) 2024-2025 by Thomas Dreibholz 14 | # 15 | # This program is free software: you can redistribute it and/or modify 16 | # it under the terms of the GNU General Public License as published by 17 | # the Free Software Foundation, either version 3 of the License, or 18 | # (at your option) any later version. 19 | # 20 | # This program is distributed in the hope that it will be useful, 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | # GNU General Public License for more details. 24 | # 25 | # You should have received a copy of the GNU General Public License 26 | # along with this program. If not, see . 27 | # 28 | # Contact: thomas.dreibholz@gmail.com 29 | 30 | CMAKE_MINIMUM_REQUIRED(VERSION 3.10) 31 | PROJECT(subnetcalc LANGUAGES C CXX) 32 | 33 | SET(BUILD_MAJOR "2") 34 | SET(BUILD_MINOR "6") 35 | SET(BUILD_PATCH "4") 36 | SET(BUILD_VERSION ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_PATCH}) 37 | 38 | 39 | ############################################################################# 40 | #### INSTALLATION_DIRECTORIES #### 41 | ############################################################################# 42 | 43 | # See: https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html 44 | INCLUDE(GNUInstallDirs) 45 | 46 | 47 | ############################################################################# 48 | #### PACKAGING #### 49 | ############################################################################# 50 | 51 | SET(CPACK_SOURCE_GENERATOR "TXZ") 52 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME 53 | "${CMAKE_PROJECT_NAME}-${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_PATCH}") 54 | SET(CPACK_SOURCE_IGNORE_FILES "\\\\.git;\\\\.swp$;~$;\\\\.\\\\#;/\\\\#") 55 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "^${PROJECT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}[_-]") 56 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "\\\\.cmake$|\\\\.make$|\\\\.log$") 57 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "/CMakeCache\\\\.txt$") 58 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "/(CMakeFiles|CMakeScripts|_CPack_Packages)/") 59 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "/package-version\\\\.h$") 60 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "/packaging\\\\.conf$") 61 | LIST(APPEND CPACK_SOURCE_IGNORE_FILES "^${PROJECT_SOURCE_DIR}/(po.*/|src.*/|)Makefile$") 62 | INCLUDE(CPack) 63 | 64 | ADD_CUSTOM_TARGET(dist COMMAND ${CMAKE_MAKE_PROGRAM} clean package_source) 65 | 66 | 67 | INCLUDE(CheckIncludeFile) 68 | INCLUDE(CheckStructHasMember) 69 | 70 | 71 | ############################################################################# 72 | #### UNINSTALL #### 73 | ############################################################################# 74 | 75 | IF(NOT TARGET uninstall) 76 | CONFIGURE_FILE( 77 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 78 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 79 | IMMEDIATE @ONLY) 80 | 81 | ADD_CUSTOM_TARGET(uninstall 82 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 83 | ENDIF() 84 | 85 | 86 | ############################################################################# 87 | #### OS DEPENDENT #### 88 | ############################################################################# 89 | 90 | IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 91 | MESSAGE(STATUS ${CMAKE_SYSTEM_NAME} " supported") 92 | 93 | ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 94 | MESSAGE(STATUS ${CMAKE_SYSTEM_NAME} " supported") 95 | SET(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include") 96 | SET(CMAKE_LIBRARY_PATH "/usr/local/lib") 97 | INCLUDE_DIRECTORIES("/usr/local/include") 98 | 99 | ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 100 | MESSAGE(STATUS ${CMAKE_SYSTEM_NAME} " supported") 101 | SET(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include" "/usr/local/opt/openssl/include") 102 | SET(CMAKE_LIBRARY_PATH "/usr/local/lib") 103 | INCLUDE_DIRECTORIES("/usr/local/include" "/usr/local/opt/openssl/include") 104 | 105 | ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") 106 | MESSAGE(STATUS ${CMAKE_SYSTEM_NAME} " supported") 107 | SET(CMAKE_REQUIRED_INCLUDES "/usr/pkg/include" "/usr/include" "/usr/local/include") 108 | SET(CMAKE_LIBRARY_PATH "/usr/local/lib") 109 | INCLUDE_DIRECTORIES("/usr/pkg/include" "/usr/local/include") 110 | 111 | ELSE() 112 | MESSAGE(FATAL_ERROR ${CMAKE_SYSTEM_NAME} " not supported (yet?)") 113 | 114 | ENDIF() 115 | 116 | 117 | ############################################################################# 118 | #### CHECK STRUCT MEMBERS #### 119 | ############################################################################# 120 | 121 | CHECK_STRUCT_HAS_MEMBER("struct sockaddr" "sa_len" "sys/types.h;sys/socket.h" HAVE_SA_LEN) 122 | IF (HAVE_SA_LEN) 123 | MESSAGE(STATUS "HAVE_SA_LEN") 124 | ADD_DEFINITIONS(-DHAVE_SA_LEN) 125 | ENDIF() 126 | 127 | CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in" "sin_len" "sys/types.h;netinet/in.h" HAVE_SIN_LEN) 128 | IF (HAVE_SIN_LEN) 129 | MESSAGE(STATUS "HAVE_SIN_LEN") 130 | ADD_DEFINITIONS(-DHAVE_SIN_LEN) 131 | ENDIF() 132 | 133 | CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" "sin6_len" "sys/types.h;netinet/in.h" HAVE_SIN6_LEN) 134 | IF (HAVE_SIN6_LEN) 135 | MESSAGE(STATUS "HAVE_SIN6_LEN") 136 | ADD_DEFINITIONS(-DHAVE_SIN6_LEN) 137 | ENDIF() 138 | 139 | CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" "ss_len" "sys/types.h;sys/socket.h" HAVE_SS_LEN) 140 | IF (HAVE_SS_LEN) 141 | MESSAGE(STATUS "HAVE_SS_LEN") 142 | ADD_DEFINITIONS(-DHAVE_SS_LEN) 143 | ENDIF() 144 | 145 | 146 | ############################################################################# 147 | #### REQUIREMENTS #### 148 | ############################################################################# 149 | 150 | INCLUDE(FindPackageHandleStandardArgs) 151 | 152 | # ###### GeoIP ############################################################## 153 | FIND_LIBRARY(GeoIP_LIBRARY NAMES GeoIP) 154 | FIND_PATH(GeoIP_INCLUDE_DIR NAMES GeoIP.h GeoIPCity.h) 155 | IF (GEOIP_FOUND) 156 | INCLUDE_DIRECTORIES(${GeoIP_INCLUDE_DIR}) 157 | ADD_DEFINITIONS(-DHAVE_GEOIP -DHAVE_GEOIP_IPV6) 158 | MESSAGE(STATUS "GeoIP found.") 159 | ELSE() 160 | MESSAGE(STATUS "GeoIP not found!") 161 | ENDIF() 162 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GeoIP DEFAULT_MSG GeoIP_LIBRARY GeoIP_INCLUDE_DIR) 163 | 164 | 165 | ############################################################################# 166 | #### INTERNATIONALISATION (I18N) #### 167 | ############################################################################# 168 | 169 | FIND_PACKAGE (Intl) 170 | IF (Intl_FOUND) 171 | INCLUDE_DIRECTORIES(${Intl_INCLUDE_DIRS}) 172 | LINK_DIRECTORIES(${Intl_LIBRARY_DIRS}) 173 | ELSE() 174 | MESSAGE(STATUS "Internationalization (i18n) not found!") 175 | ENDIF() 176 | 177 | FIND_PROGRAM(XGETTEXT xgettext REQUIRED) 178 | FIND_PROGRAM(MSGMERGE msgmerge REQUIRED) 179 | FIND_PROGRAM(MSGFMT msgfmt REQUIRED) 180 | 181 | 182 | ############################################################################# 183 | #### SUBDIRECTORIES #### 184 | ############################################################################# 185 | 186 | ADD_SUBDIRECTORY(src) 187 | ADD_SUBDIRECTORY(po) 188 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dreibh/subnetcalc/ea968434a44e6998e01b39ced3f53388e68d4b3e/NEWS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SubNetCalc 2 | An IPv4/IPv6 Subnet Calculator 3 | 4 | ## Description 5 | 6 | SubNetCalc is an IPv4/IPv6 subnet address calculator. For given IPv4 or IPv6 7 | address and netmask or prefix length, it calculates network address, broadcast 8 | address, maximum number of hosts and host address range. Also, it prints the 9 | addresses in binary format for better understandability. Furthermore, it prints 10 | useful information on specific address types (e.g. type, scope, interface ID, 11 | etc.). 12 | 13 | See the manpage of subnetcalc for details! 14 | 15 | ## Usage Examples 16 | 17 | ``` 18 | subnetcalc 172.31.255.254 255.255.255.0 19 | subnetcalc 172.31.255.254 24 20 | subnetcalc fec0:2345:6789:1111:221:6aff:fe0b:2674 56 21 | subnetcalc www.iem.uni-due.de 24 22 | subnetcalc fd00:: 64 -uniquelocal 23 | subnetcalc fd00::9876:256:7bff:fe1b:3255 56 -uniquelocalhq 24 | ``` 25 | 26 | My host has IP 132.252.150.254 and netmask 255.255.255.240. What are the details of its network? 27 | 28 | ``` 29 | user@host:~$ subnetcalc 132.252.150.254 255.255.255.240 30 | Address = 132.252.150.254 31 | 10000100 . 11111100 . 10010110 . 11111110 32 | Network = 132.252.150.240 / 28 33 | Netmask = 255.255.255.240 34 | Broadcast = 132.252.150.255 35 | Wildcard Mask = 0.0.0.15 36 | Hex. Address = 84FC96FE 37 | Hosts Bits = 4 38 | Max. Hosts = 14 (2^4 - 2) 39 | Host Range = { 132.252.150.241 - 132.252.150.254 } 40 | Properties = 41 | - 132.252.150.254 is a HOST address in 132.252.150.240/28 42 | - Class B 43 | DNS Hostname = dummy.iem.uni-due.de 44 | ``` 45 | 46 | Consider host www.heise.de uses a 64-bit prefix length. What are the details of its network? 47 | 48 | ``` 49 | user@host:~$ subnetcalc www.heise.de 64 50 | Address = 2a02:2e0:3fe:1001:7777:772e:2:85 51 | 2a02 = 00101010 00000010 52 | 02e0 = 00000010 11100000 53 | 03fe = 00000011 11111110 54 | 1001 = 00010000 00000001 55 | 7777 = 01110111 01110111 56 | 772e = 01110111 00101110 57 | 0002 = 00000000 00000010 58 | 0085 = 00000000 10000101 59 | Network = 2a02:2e0:3fe:1001:: / 64 60 | Netmask = ffff:ffff:ffff:ffff:: 61 | Wildcard Mask = ::ffff:ffff:ffff:ffff 62 | Hosts Bits = 64 63 | Max. Hosts = 18446744073709551615 (2^64 - 1) 64 | Host Range = { 2a02:2e0:3fe:1001::1 - 2a02:2e0:3fe:1001:ffff:ffff:ffff:ffff } 65 | Properties = 66 | - 2a02:2e0:3fe:1001:7777:772e:2:85 is a HOST address in 2a02:2e0:3fe:1001::/64 67 | - Global Unicast Properties: 68 | + Interface ID = 7777:772e:0002:0085 69 | + Solicited Node Multicast Address = ff02::1:ff02:0085 70 | + 6-to-4 Address = 2.224.3.254 71 | DNS Hostname = www.heise.de 72 | ``` 73 | 74 | My new host should use Interface ID 0x100 and Subnet ID 0x1234. Generate a Unique Local IPv6 prefix (40-bit Global ID) for my intranet, using high-quality random numbers! 75 | 76 | ``` 77 | user@host:~$ subnetcalc 0:0:0:1234::1 56 -uniquelocalhq 78 | Generating Unique Local IPv6 address (using /dev/random) ... 79 | Address = fd97:1303:1402:1234::1 80 | fd97 = 11111101 10010111 81 | 1303 = 00010011 00000011 82 | 1402 = 00010100 00000010 83 | 1234 = 00010010 00110100 84 | 0000 = 00000000 00000000 85 | 0000 = 00000000 00000000 86 | 0000 = 00000000 00000000 87 | 0001 = 00000000 00000001 88 | Network = fd97:1303:1402:1200:: / 56 89 | Netmask = ffff:ffff:ffff:ff00:: 90 | Wildcard Mask = ::ff:ffff:ffff:ffff:ffff 91 | Hosts Bits = 72 92 | Max. Hosts = 4722366482869645213695 (2^72 - 1) 93 | Host Range = { fd97:1303:1402:1200::1 - fd97:1303:1402:12ff:ffff:ffff:ffff:ffff } 94 | Properties = 95 | - fd97:1303:1402:1234::1 is a HOST address in fd97:1303:1402:1200::/56 96 | - Unique Local Unicast Properties: 97 | + Locally chosen 98 | + Global ID = 9713031402 99 | + Subnet ID = 1234 100 | + Interface ID = 0000:0000:0000:0001 101 | + Solicited Node Multicast Address = ff02::1:ff00:0001 102 | DNS Hostname = (Name or service not known) 103 | ``` 104 | 105 | Which are DNS reverse lookup name and geo location country of IP 2402:f000:1:400::2? 106 | 107 | ``` 108 | user@host:~$ subnetcalc 2402:f000:1:400::2 109 | Address = 2402:f000:1:400::2 110 | 2402 = 00100100 00000010 111 | f000 = 11110000 00000000 112 | 0001 = 00000000 00000001 113 | 0400 = 00000100 00000000 114 | 0000 = 00000000 00000000 115 | 0000 = 00000000 00000000 116 | 0000 = 00000000 00000000 117 | 0002 = 00000000 00000010 118 | Network = 2402:f000:1:400::2 / 128 119 | Netmask = ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 120 | Wildcard Mask = :: 121 | Hosts Bits = 0 122 | Max. Hosts = 1 (2^0 - 0) 123 | Host Range = { 2402:f000:1:400::2 - 2402:f000:1:400::2 } 124 | Properties = 125 | - 2402:f000:1:400::2 is a HOST address in 2402:f000:1:400::2/128 126 | - Global Unicast Properties: 127 | + Interface ID = 0000:0000:0000:0002 128 | + Solicited Node Multicast Address = ff02::1:ff00:0002 129 | + 6-to-4 Address = 240.0.0.1 130 | GeoIP Country = China (CN) 131 | DNS Hostname = bg-in-x68.1e100.net 132 | ``` 133 | 134 | Which are the MAC address and Solicited Node Multicast address of 2001:638:501:4ef8:223:aeff:fea4:8ca9/64? 135 | 136 | ``` 137 | user@host:~$ subnetcalc 2001:638:501:4ef8:223:aeff:fea4:8ca9/64 138 | Address = 2001:638:501:4ef8:223:aeff:fea4:8ca9 139 | 2001 = 00100000 00000001 140 | 0638 = 00000110 00111000 141 | 0501 = 00000101 00000001 142 | 4ef8 = 01001110 11111000 143 | 0223 = 00000010 00100011 144 | aeff = 10101110 11111111 145 | fea4 = 11111110 10100100 146 | 8ca9 = 10001100 10101001 147 | Network = 2001:638:501:4ef8:: / 64 148 | Netmask = ffff:ffff:ffff:ffff:: 149 | Wildcard Mask = ::ffff:ffff:ffff:ffff 150 | Hosts Bits = 64 151 | Max. Hosts = 18446744073709551615 (2^64 - 1) 152 | Host Range = { 2001:638:501:4ef8::1 - 2001:638:501:4ef8:ffff:ffff:ffff:ffff } 153 | Properties = 154 | - 2001:638:501:4ef8:223:aeff:fea4:8ca9 is a HOST address in 2001:638:501:4ef8::/64 155 | - Global Unicast Properties: 156 | + Interface ID = 0223:aeff:fea4:8ca9 157 | + MAC Address = 00:23:ae:a4:8c:a9 158 | + Solicited Node Multicast Address = ff02::1:ffa4:8ca9 159 | DNS Hostname = (Name or service not known) 160 | ``` 161 | 162 | ## Binary Package Installation 163 | 164 | Please use the issue tracker at [https://github.com/dreibh/subnetcalc/issues](https://github.com/dreibh/subnetcalc/issues) to report bugs and issues! 165 | 166 | ### Ubuntu Linux 167 | 168 | For ready-to-install Ubuntu Linux packages of SubNetCalc, see [Launchpad PPA for Thomas Dreibholz](https://launchpad.net/~dreibh/+archive/ubuntu/ppa/+packages?field.name_filter=subnetcalc&field.status_filter=published&field.series_filter=)! 169 | 170 | ``` 171 | sudo apt-add-repository -sy ppa:dreibh/ppa 172 | sudo apt-get update 173 | sudo apt-get install subnetcalc 174 | ``` 175 | 176 | ### Fedora Linux 177 | 178 | For ready-to-install Fedora Linux packages of SubNetCalc, see [COPR PPA for Thomas Dreibholz](https://copr.fedorainfracloud.org/coprs/dreibh/ppa/package/subnetcalc/)! 179 | 180 | ``` 181 | sudo dnf copr enable -y dreibh/ppa 182 | sudo dnf install subnetcalc 183 | ``` 184 | 185 | ### FreeBSD 186 | 187 | For ready-to-install FreeBSD packages of SubNetCalc, it is included in the ports collection, see [FreeBSD ports tree index of net/subnetcalc/](https://cgit.freebsd.org/ports/tree/net/subnetcalc/)! 188 | 189 | ``` 190 | pkg install subnetcalc 191 | ``` 192 | 193 | Alternatively, to compile it from the ports sources: 194 | 195 | ``` 196 | cd /usr/ports/net/subnetcalc 197 | make 198 | make install 199 | ``` 200 | 201 | ## Sources Download 202 | 203 | SubNetCalc is released under the GNU General Public Licence (GPL). 204 | 205 | Please use the issue tracker at [https://github.com/dreibh/subnetcalc/issues](https://github.com/dreibh/subnetcalc/issues) to report bugs and issues! 206 | 207 | ### Development Version 208 | 209 | The Git repository of the SubNetCalc sources can be found at [https://github.com/dreibh/subnetcalc](https://github.com/dreibh/subnetcalc): 210 | 211 | ``` 212 | git clone https://github.com/dreibh/subnetcalc 213 | cd subnetcalc 214 | cmake . 215 | make 216 | ``` 217 | 218 | Contributions: 219 | 220 | - Issue tracker: [https://github.com/dreibh/subnetcalc/issues](https://github.com/dreibh/subnetcalc/issues). 221 | Please submit bug reports, issues, questions, etc. in the issue tracker! 222 | 223 | - Pull Requests for SubNetCalc: [https://github.com/dreibh/subnetcalc/pulls](https://github.com/dreibh/subnetcalc/pulls). 224 | Your contributions to SubNetCalc are always welcome! 225 | 226 | - CI build tests of SubNetCalc: [https://github.com/dreibh/subnetcalc/actions](https://github.com/dreibh/subnetcalc/actions). 227 | 228 | - Coverity Scan analysis of SubNetCalc: [https://scan.coverity.com/projects/dreibh-subnetcalc](https://scan.coverity.com/projects/dreibh-subnetcalc). 229 | 230 | ### Current Stable Release 231 | 232 | See [https://www.nntb.no/~dreibh/subnetcalc/#StableRelease](https://www.nntb.no/~dreibh/subnetcalc/#StableRelease)! 233 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Build Scripts 4 | # Copyright (C) 2002-2025 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | # Bash options: 22 | set -eu 23 | 24 | 25 | CMAKE_OPTIONS="" 26 | COMMAND="" 27 | CORES= 28 | 29 | while [ $# -gt 0 ] ; do 30 | if [[ "$1" =~ ^(-|--)use-clang$ ]] ; then 31 | # Use these settings for CLang: 32 | export CXX=clang++ 33 | export CC=clang 34 | elif [[ "$1" =~ ^(-|--)use-clang-scan-build$ ]] ; then 35 | # Use these settings for CLang: 36 | export CXX=clang++ 37 | export CC=clang 38 | # Ensure build with CLang Static Analyzer 39 | mkdir -p scan-build-reports 40 | COMMAND="scan-build -o scan-build-reports" 41 | elif [[ "$1" =~ ^(-|--)use-gcc$ ]] ; then 42 | # Use these settings for GCC: 43 | export CXX=g++ 44 | export CC=gcc 45 | elif [[ "$1" =~ ^(-|--)use-gcc-analyzer$ ]] ; then 46 | # Use these settings for GCC: 47 | export CXX=g++ 48 | export CC=gcc 49 | export CFLAGS=-fanalyzer 50 | export CXXFLAGS=-fanalyzer 51 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON" 52 | CORES=1 # The analyzer takes a *huge* amount of memory! 53 | elif [[ "$1" =~ ^(-|--)debug$ ]] ; then 54 | # Enable debugging build: 55 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" 56 | elif [[ "$1" =~ ^(-|--)release$ ]] ; then 57 | # Enable debugging build: 58 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Release" 59 | elif [[ "$1" =~ ^(-|--)release-with-debinfo$ ]] ; then 60 | # Enable debugging build: 61 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=RelWithDebInfo" 62 | elif [[ "$1" =~ ^(-|--)verbose$ ]] ; then 63 | # Enable verbose Makefile: 64 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON" 65 | elif [[ "$1" =~ ^(-|--)cores ]] ; then 66 | if [[ ! "$2" =~ ^[0-9]*$ ]] ; then 67 | echo >&2 "ERROR: Number of cores must be an integer number!" 68 | exit 1 69 | fi 70 | CORES="$2" 71 | shift 72 | elif [ "$1" == "--" ] ; then 73 | shift 74 | break 75 | else 76 | echo >&2 "Usage: autogen.sh [--use-clang|--use-clang-scan-build|--use-gcc|--use-gcc-analyzer] [--debug|--release|--release-with-debinfo] [--cores N] [--verbose] -- (further CMake/Configure options)" 77 | exit 1 78 | fi 79 | shift 80 | done 81 | 82 | if [ "$(uname)" != "FreeBSD" ] ; then 83 | installPrefix="/usr" 84 | else 85 | installPrefix="/usr/local" 86 | fi 87 | 88 | 89 | # ====== Configure with CMake =============================================== 90 | if [ -e CMakeLists.txt ] ; then 91 | rm -f CMakeCache.txt 92 | if [ "$*" != "" ] ; then 93 | CMAKE_OPTIONS="${CMAKE_OPTIONS} $*" 94 | fi 95 | echo "CMake options:${CMAKE_OPTIONS} . -DCMAKE_INSTALL_PREFIX=\"${installPrefix}\"" 96 | # shellcheck disable=SC2048,SC2086 97 | ${COMMAND} cmake ${CMAKE_OPTIONS} . -DCMAKE_INSTALL_PREFIX="${installPrefix}" 98 | 99 | # ====== Configure with AutoConf/AutoMake =================================== 100 | elif [ -e bootstrap ] ; then 101 | ./bootstrap 102 | ./configure $* 103 | 104 | else 105 | echo >&2 "ERROR: Failed to configure with CMake or AutoMake/AutoConf!" 106 | exit 1 107 | fi 108 | 109 | 110 | # ====== Obtain number of cores ============================================= 111 | # Try Linux 112 | if [ "${CORES}" == "" ] ; then 113 | CORES=$(getconf _NPROCESSORS_ONLN 2>/dev/null || true) 114 | if [ "${CORES}" == "" ] ; then 115 | # Try FreeBSD 116 | CORES=$(sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2 | tr -d ' ' || true) 117 | fi 118 | if [ "${CORES}" == "" ] ; then 119 | CORES="1" 120 | fi 121 | echo "This system has ${CORES} cores!" 122 | fi 123 | 124 | 125 | # ====== Build ============================================================== 126 | ${COMMAND} make -j"${CORES}" 127 | -------------------------------------------------------------------------------- /ci/ci-build: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # GitHub Actions Scripts 4 | # Copyright (C) 2021-2025 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | # Bash options: 22 | set -eu 23 | 24 | 25 | # ====== Check arguments ==================================================== 26 | if [ $# -lt 1 ] ; then 27 | echo >&2 "Usage: $0 compile|package|... ..." 28 | exit 1 29 | fi 30 | 31 | 32 | # ====== Check/set environment variables ==================================== 33 | DIRNAME="$(dirname "$0")" 34 | UNAME="$(uname)" 35 | if [ ! -e /etc/os-release ] ; then 36 | echo >&2 "ERROR: /etc/os-release does not exist!" 37 | exit 1 38 | fi 39 | . /etc/os-release 40 | 41 | 42 | # ###### Configure ########################################################## 43 | 44 | # ====== Configure with CMake =============================================== 45 | if [ -e CMakeLists.txt ] ; then 46 | cmake . 47 | 48 | # ====== Configure with autoconf/automake (via bootstrap script) ============ 49 | elif [ -e configure.ac ] || [ -e configure.in ] ; then 50 | if [ -e autogen.sh ] ; then 51 | ./autogen.sh 52 | elif [ -e bootstrap ] ; then 53 | ./bootstrap 54 | ./configure 55 | else 56 | ./configure 57 | fi 58 | else 59 | echo >&2 "WARNING: No build system detected. Trying to just call \"make\" ..." 60 | fi 61 | 62 | # ====== Obtain MAKEFLAGS to utilise all cores ============================== 63 | if [ "${UNAME}" == "Linux" ] ; then 64 | cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || true) 65 | MAKEFLAGS="-j${cores}" 66 | elif [ "${UNAME}" == "FreeBSD" ] ; then 67 | cores=$(sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2 | tr -d ' ') 68 | MAKEFLAGS="-j${cores}" 69 | else 70 | MAKEFLAGS="" 71 | fi 72 | 73 | 74 | # ###### Perform builds ##################################################### 75 | while [ $# -gt 0 ] ; do 76 | TOOL="$1" 77 | shift 78 | 79 | 80 | # ====== Compile ========================================================= 81 | if [ "${TOOL}" == "compile" ] ; then 82 | 83 | MAKEFLAGS=${MAKEFLAGS} make # VERBOSE=1 84 | 85 | 86 | # # ====== Coverity Scan =================================================== 87 | # elif [ "${TOOL}" == "coverity" ] ; then 88 | # # ------ Build -------------------------------------------------------- 89 | # cd coverity 90 | # export PATH="coverity/$(ls -d cov*)/bin:$PATH" 91 | # cd .. 92 | # 93 | # MAKEFLAGS=${MAKEFLAGS} cov-build --dir cov-int make 94 | # tar czf coverity-results.tar.gz cov-int 95 | # ls -l coverity-results.tar.gz 96 | # 97 | # # ------ Upload results ----------------------------------------------- 98 | # if [ "${TRAVIS_BRANCH}" == "${COVERITY_SCAN_BRANCH}" ] ; then 99 | # curl --form token=${COVERITY_SCAN_TOKEN} \ 100 | # --form email=${COVERITY_SCAN_NOTIFICATION_EMAIL} \ 101 | # --form file=@coverity-results.tar.gz \ 102 | # --form version="master branch head" \ 103 | # --form description="$(git log -1|head -1)" \ 104 | # https://scan.coverity.com/builds?project=${COVERITY_PROJECT} 105 | # CURL_RESULT=$? 106 | # echo "curl returned ${CURL_RESULT}" 107 | # if [ $CURL_RESULT -ne 0 ]; then 108 | # echo >&2 "ERROR: Upload to Coverity Scan failed; curl returned ${CURL_RESULT}!" 109 | # exit 1 110 | # fi 111 | # else 112 | # echo >&2 "###### NOTE: This branch \"${TRAVIS_BRANCH}\" is not the scan branch \"${COVERITY_SCAN_BRANCH}\"! Skipping upload! ######" 113 | # fi 114 | 115 | 116 | # ====== Package ======================================================= 117 | elif [ "${TOOL}" == "package" ] ; then 118 | 119 | if [ ! -v OS ] || [ "${OS}" == "" ] ; then 120 | OS="${ID}" 121 | fi 122 | if [ ! -v ARCH ] || [ "${ARCH}" == "" ] ; then 123 | ARCH="$(uname -m)" 124 | fi 125 | 126 | if [ "${OS}" == "ubuntu" ] || [ "${OS}" == "debian" ] ; then 127 | architecture="${ARCH//x86_64/amd64}" 128 | if [ ! -v DIST ] || [ "${DIST}" == "" ] ; then 129 | distribution="${VERSION_CODENAME}" 130 | else 131 | distribution="${DIST}" 132 | fi 133 | "${DIRNAME}"/build-tool build-deb "${distribution}" --skip-signing --architecture="${architecture}" 134 | 135 | # ====== Fedora ========================================================== 136 | elif [ "${OS}" == "fedora" ] ; then 137 | 138 | architecture="${ARCH}" 139 | if [ ! -v DIST ] || [ "${DIST}" == "" ] ; then 140 | distribution="${VERSION_ID}" 141 | else 142 | distribution="${DIST}" 143 | fi 144 | LD_PRELOAD=/usr/lib64/nosync/nosync.so \ 145 | "${DIRNAME}"/build-tool build-rpm "fedora-${distribution}" --skip-signing --architecture="${architecture}" 146 | 147 | # ====== Unknown ========================================================= 148 | else 149 | echo >&2 "ERROR: Unsupported distribution ${ID} for packaging!" 150 | exit 1 151 | fi 152 | 153 | 154 | # ====== Invalid setting ================================================= 155 | else 156 | echo >&2 "ERROR: Invalid setting of TOOL=${TOOL}!" 157 | exit 1 158 | fi 159 | 160 | done 161 | -------------------------------------------------------------------------------- /ci/ci-install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # GitHub Actions Scripts 4 | # Copyright (C) 2021-2025 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | # Bash options: 22 | set -eu 23 | 24 | 25 | DIRNAME="$(dirname "$0")" 26 | "${DIRNAME}"/get-dependencies --install 27 | -------------------------------------------------------------------------------- /ci/ci-setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # GitHub Actions Scripts 4 | # Copyright (C) 2021-2025 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | # Bash options: 22 | set -eu 23 | 24 | 25 | # ====== Check arguments ==================================================== 26 | USE_PACKAGING=0 27 | while [ $# -gt 0 ] ; do 28 | if [ "$1" == "package" ] ; then 29 | USE_PACKAGING=1 30 | fi 31 | shift 32 | done 33 | 34 | 35 | # ====== Check/set environment variables ==================================== 36 | if [ ! -e /etc/os-release ] ; then 37 | echo >&2 "ERROR: /etc/os-release does not exist!" 38 | exit 1 39 | fi 40 | . /etc/os-release 41 | 42 | 43 | # ====== Ubuntu/Deban ======================================================= 44 | if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then 45 | PACKAGES="python3 python3-distro" 46 | if [ -v CC ] ; then 47 | if [[ "${CC}" =~ .*gcc.* ]] ; then 48 | PACKAGES="${PACKAGES} gcc" 49 | elif [[ "${CC}" =~ .*clang.* ]] ; then 50 | PACKAGES="${PACKAGES} clang" 51 | fi 52 | fi 53 | if [ ${USE_PACKAGING} -eq 1 ] ; then 54 | # Need to install pbuilder as well: 55 | PACKAGES="${PACKAGES} build-essential debian-archive-keyring debian-ports-archive-keyring devscripts distro-info eatmydata fakeroot pbuilder qemu-user-static sudo" 56 | fi 57 | 58 | apt-get update -qq 59 | # DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -qy 60 | # shellcheck disable=SC2086 61 | DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends \ 62 | ${PACKAGES} 63 | 64 | if [ "${ID}" == "ubuntu" ] ; then 65 | # Add PPA dreibh/ppa for Ubuntu: 66 | DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends \ 67 | software-properties-common 68 | apt-add-repository -y ppa:dreibh/ppa || true 69 | apt-get update -q 70 | fi 71 | 72 | if [ ${USE_PACKAGING} -eq 1 ] ; then 73 | # ====== pbuilder environment ========================================= 74 | # Example for GitHub Actions: 75 | # https://github.com/jrl-umi3218/github-actions/tree/master/setup-pbuilder 76 | 77 | if [ ! -v OS ] || [ "${OS}" == "" ] ; then 78 | OS="${ID}" 79 | fi 80 | if [ ! -v DIST ] || [ "${DIST}" == "" ] ; then 81 | DIST="${VERSION_CODENAME}" 82 | fi 83 | if [ ! -v ARCH ] || [ "${ARCH}" == "" ] ; then 84 | ARCH="$(dpkg --print-architecture)" 85 | fi 86 | 87 | if [ "${OS}" == "ubuntu" ] ; then 88 | COMPONENTS="main universe" 89 | MIRRORSITE=http://dk.archive.ubuntu.com/ubuntu/ 90 | KEYRING="/usr/share/keyrings/ubuntu-archive-keyring.gpg" 91 | elif [ "${OS}" == "debian" ] ; then 92 | COMPONENTS="main" 93 | if [ "${ARCH}" == "m68k" ] || [ "${ARCH}" == "riscv64" ] ; then 94 | # Debian Ports (special architectures) 95 | MIRRORSITE="http://ftp.ports.debian.org/debian-ports/" 96 | KEYRING="/usr/share/keyrings/debian-ports-archive-keyring.gpg" 97 | else 98 | # Debian (supported architectures) 99 | MIRRORSITE="http://ftp.dk.debian.org/debian/" 100 | KEYRING="/usr/share/keyrings/debian-archive-keyring.gpg" 101 | fi 102 | else 103 | echo >&2 "ERROR: Unknown distribution ${ID}!" 104 | exit 1 105 | fi 106 | 107 | cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || true) 108 | cat >/etc/pbuilderrc < /etc/dpkg/dpkg.cfg.d/02apt-speedup" | \ 153 | OS="${OS}" DISTRIBUTION="${DIST}" ARCHITECTURE="${ARCH}" pbuilder login --save-after-exec 154 | 155 | # ====== Add ppa:dreibh/ppa, updates and backports ================= 156 | if [ "${OS}" == "ubuntu" ] ; then 157 | # Add PPA dreibh/ppa for Ubuntu: 158 | OS="${OS}" DISTRIBUTION="${DIST}" ARCHITECTURE="${ARCH}" pbuilder login --save-after-login <&2 "ERROR: Unable to inject PPA configuration into Mock configuration file /etc/mock/${OS}-${DIST}-${ARCH}.cfg!" 201 | exit 1 202 | fi 203 | fi 204 | fi 205 | 206 | 207 | # ====== FreeBSD ============================================================ 208 | elif [ "${ID}" == "freebsd" ] ; then 209 | PACKAGES="autoconf automake bash gcc libtool git python3 py311-distro" 210 | 211 | # shellcheck disable=SC2086 212 | ASSUME_ALWAYS_YES=yes pkg install -y ${PACKAGES} 213 | 214 | if [ ! -e /usr/ports/.git ] ; then 215 | rm -rf /usr/ports/* /usr/ports/.??* || true 216 | mkdir -p /usr/ports 217 | cd /usr/ports 218 | git init -b main 219 | git remote add freebsd https://git.freebsd.org/ports.git 220 | git remote set-url --push freebsd ssh://git@gitrepo.freebsd.org/ports.git 221 | git config --add remote.freebsd.fetch "+refs/notes/*:refs/notes/*" 222 | git config pull.rebase true 223 | git pull --depth=1 freebsd main 224 | git branch --set-upstream-to=freebsd/main main 225 | fi 226 | 227 | # ====== Unknown ============================================================ 228 | else 229 | 230 | echo >&2 "ERROR: Unknown distribution ${ID}!" 231 | exit 1 232 | 233 | fi 234 | -------------------------------------------------------------------------------- /ci/ci-test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # GitHub Actions Scripts 4 | # Copyright (C) 2021-2025 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | # Bash options: 22 | set -eu 23 | 24 | 25 | # ====== Check/set environment variables ==================================== 26 | ID="$(uname)" 27 | if [ ! -e /etc/os-release ] ; then 28 | echo >&2 "ERROR: /etc/os-release does not exist!" 29 | exit 1 30 | fi 31 | . /etc/os-release 32 | 33 | 34 | # ====== Ubuntu/Deban ======================================================= 35 | if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then 36 | 37 | # ====== pbuilder environment ============================================ 38 | CHANGELOG_HEADER="$(head -n1 debian/changelog)" 39 | # PACKAGE="$(echo "${CHANGELOG_HEADER}" | sed -e "s/(.*//" -e "s/ //g")" 40 | PACKAGE_VERSION="$(echo "${CHANGELOG_HEADER}" | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g" -e "s/^[0-9]://g")" 41 | # shellcheck disable=SC2001 42 | OUTPUT_VERSION="$(echo "${PACKAGE_VERSION}" | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/")" 43 | # shellcheck disable=SC2001 44 | DEBIAN_VERSION="$(echo "${OUTPUT_VERSION}" | sed -e "s/\(ubuntu\|ppa\)$//1")" 45 | 46 | packages="" 47 | if [ $# -eq 0 ] ; then 48 | echo "Looking for *${DEBIAN_VERSION}*.deb in /var/cache/pbuilder/result ..." 49 | packages="$(find /var/cache/pbuilder/result -name "*${DEBIAN_VERSION}*.deb")" 50 | fi 51 | while [ $# -gt 0 ] ; do 52 | echo "Looking for $1*${DEBIAN_VERSION}*.deb in /var/cache/pbuilder/result ..." 53 | packages="${packages} $(find /var/cache/pbuilder/result -name "$1*${DEBIAN_VERSION}*.deb")" 54 | shift 55 | done 56 | packages=$(echo "${packages}" | xargs -n1 | sort -u | xargs) 57 | if [ "${packages}" == "" ] ; then 58 | echo >&2 "ERROR: No packages have been found!" 59 | exit 1 60 | fi 61 | 62 | echo "Installing ${packages} ..." 63 | # shellcheck disable=SC2086 64 | DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -fy ${packages} || { 65 | echo "NOTE: apt-get failed -> trying dpkg instead of apt-get for local file!" 66 | # NOTE: Older "apt-get" versions do not handle local files! 67 | # shellcheck disable=SC2086 68 | if ! DEBIAN_FRONTEND=noninteractive eatmydata dpkg -i "${packages}" ; then 69 | echo "There may be some dependencies missing. Trying to install them ..." 70 | DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -fy -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" --no-install-recommends 71 | echo "Retrying to install ${packages} ..." 72 | DEBIAN_FRONTEND=noninteractive eatmydata dpkg -i ${packages} 73 | fi 74 | } 75 | echo "Done!" 76 | 77 | 78 | # ====== Fedora ============================================================= 79 | elif [ "${ID}" == "fedora" ] ; then 80 | 81 | # ====== mock environment ================================================ 82 | # PACKAGE=$(grep "^Name:" rpm/*.spec | head -n1 | sed -e "s/Name://g" -e "s/[ \t]*//g") 83 | PACKAGE_VERSION=$(grep "^Version:" rpm/*.spec | head -n1 | sed -e "s/Version://g" -e "s/[ \t]*//g") 84 | 85 | release=$(bash -c "LANG=C.UTF-8 ; cat /etc/fedora-release | sed -e \"s/^\(.*\) release \([0-9]*\) (\(.*\))$/\2/g\"" | sed -e "s/[^0-9]//g") 86 | arch=$(uname -m | sed -e "s/[^0-9a-zA-Z_+-]//g") 87 | if ! cd /var/lib/mock/fedora-"${release}"-"${arch}"/result ; then 88 | if cd /var/lib/mock/fedora-rawhide-"${arch}"/result ; then 89 | release="rawhide" 90 | else 91 | echo >&2 "ERROR: No results have been found!" 92 | exit 1 93 | fi 94 | fi 95 | 96 | packages="" 97 | if [ $# -eq 0 ] ; then 98 | echo "Looking for *${PACKAGE_VERSION}*.rpm in /var/lib/mock/fedora-${release}-${arch}/result ..." 99 | packages="$(find /var/lib/mock/fedora-"${release}"-"${arch}"/result -name "*${PACKAGE_VERSION}*.rpm" | grep -v "\.src\.rpm$")" 100 | fi 101 | while [ $# -gt 0 ] ; do 102 | echo "Looking for $1*${PACKAGE_VERSION}*.rpm in /var/lib/mock/fedora-${release}-${arch}/result ..." 103 | packages="${packages} $(find /var/lib/mock/fedora-"${release}"-"${arch}"/result -name "$1*${PACKAGE_VERSION}*.rpm" | grep -v "\.src\.rpm$")" 104 | shift 105 | done 106 | packages=$(echo "${packages}" | xargs -n1 | sort -u | xargs) 107 | if [ "${packages}" == "" ] ; then 108 | echo >&2 "ERROR: No packages have been found!" 109 | exit 1 110 | fi 111 | 112 | echo "Installing ${packages} ..." 113 | # shellcheck disable=SC2086 114 | LD_PRELOAD=/usr/lib64/nosync/nosync.so dnf install -y --allowerasing ${packages} 115 | echo "Done!" 116 | 117 | 118 | # ====== FreeBSD ============================================================ 119 | elif [ "${ID}" == "freebsd" ] ; then 120 | 121 | # TDB 122 | true 123 | 124 | 125 | # ====== Unknown ============================================================ 126 | else 127 | 128 | echo >&2 "ERROR: Unexpected system ${ID}!" 129 | exit 1 130 | 131 | fi 132 | -------------------------------------------------------------------------------- /ci/get-dependencies: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # GitHub Actions Scripts 5 | # Copyright (C) 2018-2025 by Thomas Dreibholz 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | # Contact: thomas.dreibholz@gmail.com 21 | 22 | import distro 23 | import glob 24 | import os 25 | import re 26 | import subprocess 27 | import sys 28 | 29 | 30 | # ###### Extract Deb file dependencies ###################################### 31 | debDepLine = re.compile(r'^(.*:[ \t]*)(.*)$') 32 | debDepItem = re.compile(r'^([a-zA-Z0-9-+\.]+)[\s]*(|\|.*|\(.*)[\s]*$') 33 | def extractDebDependencies(line, system): 34 | dependencies = [] 35 | distribution = distro.codename() 36 | 37 | # Remove "build-depends:", etc.: 38 | m = debDepLine.match(line) 39 | if m != None: 40 | line = m.group(2) 41 | line = line.strip() 42 | 43 | # Split into segments 44 | for l in line.split(','): 45 | l = l.strip() 46 | m = debDepItem.match(l) 47 | if m != None: 48 | dependency = l 49 | 50 | # ------ Ugly work-around for cmake -------------------------------- 51 | # We need cmake >= 3.0! 52 | if ((m.group(1) == 'cmake') or (m.group(1) == 'cmake3')): 53 | if ((system == 'debian') or (system == 'ubuntu')): 54 | try: 55 | if distribution in [ 'trusty' ]: 56 | dependency = 'cmake3' 57 | except: 58 | pass 59 | 60 | dependencies.append(dependency) 61 | 62 | return dependencies 63 | 64 | 65 | # ###### Extract RPM spec dependencies ###################################### 66 | rpmDepLine = re.compile(r'^(.*:[ \t]*)(.*)$') 67 | rpmDepItem = re.compile(r'^([a-zA-Z0-9-+\.]+)[\s]*(|or[ \t]*.*|\(.*)[\s]*$') 68 | def extractRPMDependencies(line, system): 69 | dependencies = [] 70 | distribution = distro.codename() 71 | 72 | # Remove "build-depends:", etc.: 73 | m = rpmDepLine.match(line) 74 | if m != None: 75 | dependency = m.group(2).strip() 76 | dependencies.append(dependency) 77 | 78 | return dependencies 79 | 80 | 81 | # ###### Main program ####################################################### 82 | 83 | # ====== Check arguments ==================================================== 84 | system = None 85 | runInstall = False 86 | i = 1 87 | while i < len(sys.argv): 88 | if sys.argv[i] == '-s' or sys.argv[i] == '--system': 89 | if i + 1 < len(sys.argv): 90 | system = sys.argv[i + 1] 91 | i = i + 1 92 | else: 93 | sys.stderr.write('ERROR: Invalid system setting!\n') 94 | sys.exit(1) 95 | elif sys.argv[i] == '-i' or sys.argv[i] == '--install': 96 | runInstall = True 97 | elif sys.argv[i] == '-h' or sys.argv[i] == '--help': 98 | sys.stderr.write('Usage: ' + sys.argv[0] + ' [-h|--help] [-s|--system debian|ubuntu|fedora|freebsd|auto] [-i|--install]\n') 99 | sys.exit(0) 100 | else: 101 | sys.stderr.write('ERROR: Bad parameter ' + sys.argv[i] + '!\n') 102 | sys.exit(1) 103 | i = i + 1 104 | 105 | if system == None: 106 | with open("/etc/os-release") as osReleaseFile: 107 | osRelease = { } 108 | for line in osReleaseFile: 109 | key, value = line.rstrip().split("=") 110 | osRelease[key] = value.strip('"') 111 | system = osRelease['ID'] 112 | 113 | # ====== Debian/Ubuntu ====================================================== 114 | dependencies = [ ] 115 | if ((system == 'debian') or (system == 'ubuntu')): 116 | if os.path.exists('debian/control'): 117 | with open('debian/control', 'r', encoding='utf-8') as fp: 118 | inside = False 119 | for line in fp: 120 | if not line: 121 | break 122 | line_lower = line.lower() 123 | if inside: 124 | if line.startswith((' ', "\t")): 125 | dependencies = dependencies + extractDebDependencies(line, system) 126 | continue 127 | elif line.startswith('#'): 128 | continue 129 | inside = False 130 | if line_lower.startswith(('build-depends:', 'build-depends-indep:')): 131 | dependencies = dependencies + extractDebDependencies(line, system) 132 | inside = True 133 | 134 | aptCall = [ 'apt-get', 'satisfy', '-qy' ] 135 | i=0 136 | for dependency in sorted(set(dependencies)): 137 | if i > 0: 138 | sys.stdout.write(', ') 139 | sys.stdout.write(dependency) 140 | aptCall.append(dependency) 141 | i = i + 1 142 | sys.stdout.write('\n') 143 | 144 | if runInstall == True: 145 | subprocess.call(aptCall, 146 | env = { 'DEBIAN_FRONTEND': 'noninteractive' }) 147 | 148 | else: 149 | sys.stderr.write('ERROR: Unable to locate Debian control file!\n') 150 | sys.exit(1) 151 | 152 | 153 | # ====== Fedora ============================================================= 154 | elif system == 'fedora': 155 | specFiles = glob.glob('rpm/*.spec') 156 | if len(specFiles) == 1: 157 | with open(specFiles[0], 'r', encoding='utf-8') as fp: 158 | inside = False 159 | for line in fp: 160 | if not line: 161 | break 162 | line_lower = line.lower() 163 | if inside: 164 | if line.startswith('#'): 165 | continue 166 | inside = False 167 | if line_lower.startswith('buildrequires:'): 168 | dependencies = dependencies + extractRPMDependencies(line, system) 169 | inside = True 170 | 171 | dnfCall = [ 'dnf', 'install', '-y' ] 172 | i=0 173 | for dependency in sorted(set(dependencies)): 174 | if i > 0: 175 | sys.stdout.write(', ') 176 | sys.stdout.write(dependency) 177 | dnfCall.append(dependency) 178 | i = i + 1 179 | sys.stdout.write('\n') 180 | 181 | if runInstall == True: 182 | subprocess.call(dnfCall) 183 | 184 | else: 185 | sys.stderr.write('ERROR: Unable to locate RPM spec file!\n') 186 | sys.exit(1) 187 | 188 | 189 | # ====== FreeBSD ============================================================ 190 | elif system == 'freebsd': 191 | freeBSDMakefile = glob.glob('freebsd/*/Makefile') 192 | if len(freeBSDMakefile) == 1: 193 | freeBSDDirectory = os.path.dirname(freeBSDMakefile[0]) 194 | 195 | cmd = 'make build-depends-list && make run-depends-list' 196 | try: 197 | os.chdir(freeBSDDirectory) 198 | output = subprocess.check_output(cmd, shell=True) 199 | except Exception as e: 200 | sys.stderr.write('ERROR: Getting FreeBSD dependencies failed: ' + str(e) + '\n') 201 | sys.exit(1) 202 | 203 | if output != None: 204 | ports = output.decode('utf-8').splitlines() 205 | for port in ports: 206 | if port[0:3] != '---': 207 | basename = os.path.basename(port) 208 | if basename == 'glib20': 209 | basename = 'glib' # May be there is a better solution here? 210 | dependencies.append(basename) 211 | 212 | for dependency in sorted(set(dependencies)): 213 | sys.stdout.write(dependency + ' ') 214 | sys.stdout.write('\n') 215 | 216 | if runInstall == True: 217 | subprocess.call([ 'pkg', 'install', '-y' ] + dependencies) 218 | 219 | else: 220 | sys.stderr.write('ERROR: Unable to locate FreeBSD port makefile!\n') 221 | sys.exit(1) 222 | 223 | 224 | # ====== Error ============================================================== 225 | else: 226 | sys.stderr.write('ERROR: Invalid system name "' + system + '"!\n') 227 | sys.exit(1) 228 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # Based on: 2 | # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake 3 | 4 | IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 5 | MESSAGE(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 6 | ENDIF() 7 | 8 | FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 9 | STRING(REGEX REPLACE "\n" ";" files "${files}") 10 | FOREACH(file ${files}) 11 | MESSAGE(STATUS "Uninstalling $ENV{DESTDIR}${file}") 12 | IF(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 13 | EXECUTE_PROCESS( 14 | COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}" 15 | OUTPUT_VARIABLE rm_out 16 | RESULT_VARIABLE rm_retval 17 | ) 18 | IF(NOT "${rm_retval}" STREQUAL 0) 19 | MESSAGE(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 20 | ENDIF() 21 | ELSE(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 22 | MESSAGE(STATUS "File $ENV{DESTDIR}${file} does not exist.") 23 | ENDIF() 24 | ENDFOREACH() 25 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | subnetcalc (2.6.4-1ubuntu1) trixie; urgency=medium 2 | 3 | * New upstream release. 4 | 5 | -- Thomas Dreibholz Sun, 27 Apr 2025 20:28:36 +0200 6 | 7 | subnetcalc (2.6.3-1ubuntu1) trixie; urgency=medium 8 | 9 | * New upstream release. 10 | * debian/control: Updated standards version to 4.7.2. 11 | 12 | -- Thomas Dreibholz Sat, 26 Apr 2025 15:01:49 +0200 13 | 14 | subnetcalc (2.6.2-1ubuntu1) trixie; urgency=medium 15 | 16 | * New upstream release. 17 | 18 | -- Thomas Dreibholz Mon, 06 Jan 2025 21:44:09 +1300 19 | 20 | subnetcalc (2.6.1-1ubuntu1) trixie; urgency=medium 21 | 22 | * New upstream release. 23 | 24 | -- Thomas Dreibholz Fri, 13 Dec 2024 21:33:53 +0100 25 | 26 | subnetcalc (2.6.0-1ubuntu1) noble; urgency=medium 27 | 28 | * New upstream release. 29 | * debian/control: Updated standards version to 4.7.0. 30 | 31 | -- Thomas Dreibholz Wed, 13 Nov 2024 20:33:12 +0100 32 | 33 | subnetcalc (2.5.1-1ubuntu1) jammy; urgency=medium 34 | 35 | * New upstream release. 36 | 37 | -- Thomas Dreibholz Mon, 12 Feb 2024 21:36:39 +0100 38 | 39 | subnetcalc (2.5.0-1ubuntu1) jammy; urgency=medium 40 | 41 | * New upstream release. 42 | * Fix for output to stderr instead of stdout (Closes: #1061757). 43 | 44 | -- Thomas Dreibholz Sat, 10 Feb 2024 15:42:28 +0100 45 | 46 | subnetcalc (2.4.23-1ubuntu1) jammy; urgency=medium 47 | 48 | * New upstream release. 49 | 50 | -- Thomas Dreibholz Wed, 06 Dec 2023 16:48:06 +0100 51 | 52 | subnetcalc (2.4.22-1ubuntu1) jammy; urgency=medium 53 | 54 | * New upstream release. 55 | 56 | -- Thomas Dreibholz Fri, 30 Jun 2023 22:59:24 +0200 57 | 58 | subnetcalc (2.4.21-1ubuntu1) jammy; urgency=medium 59 | 60 | * New upstream release. 61 | * debian/control: Updated standards version to 4.6.2. 62 | 63 | -- Thomas Dreibholz Sun, 22 Jan 2023 22:34:02 +1100 64 | 65 | subnetcalc (2.4.20-1ubuntu1) jammy; urgency=medium 66 | 67 | * New upstream release. 68 | * debian/control: Updated standards version to 4.6.1. 69 | 70 | -- Thomas Dreibholz Sun, 11 Sep 2022 13:04:29 +0200 71 | 72 | subnetcalc (2.4.19-1ubuntu1) jammy; urgency=medium 73 | 74 | * New upstream release. 75 | * debian/control: Updated standards version to 4.6.0.1. 76 | * debian/control: Dependency update (Closes: #737575). 77 | 78 | -- Thomas Dreibholz Mon, 08 Nov 2021 20:10:38 +0100 79 | 80 | subnetcalc (2.4.18-1ubuntu1) hirsute; urgency=medium 81 | 82 | * New upstream release. 83 | * debian/control: Updated standards version to 4.5.1.0. 84 | 85 | -- Thomas Dreibholz Sat, 06 Mar 2021 23:40:21 +0100 86 | 87 | subnetcalc (2.4.17-1ubuntu1) hirsute; urgency=medium 88 | 89 | * New upstream release. 90 | * debian/control: Updated standards version to 4.5.0.3. 91 | 92 | -- Thomas Dreibholz Fri, 13 Nov 2020 19:00:18 +0100 93 | 94 | subnetcalc (2.4.16-1ubuntu1) focal; urgency=medium 95 | 96 | * New upstream release. 97 | * debian/control: Updated standards version to 4.5.0.2. 98 | * debian/tests: added simple test (Closes: #939058). 99 | 100 | -- Thomas Dreibholz Mon, 18 May 2020 12:59:09 +0200 101 | 102 | subnetcalc (2.4.15-1ubuntu1) focal; urgency=medium 103 | 104 | * New upstream release. 105 | * debian/control: Updated standards version to 4.5.0.0. 106 | 107 | -- Thomas Dreibholz Fri, 07 Feb 2020 13:21:27 +0100 108 | 109 | subnetcalc (2.4.14-1ubuntu1) eoan; urgency=medium 110 | 111 | * New upstream release. 112 | 113 | -- Thomas Dreibholz Wed, 14 Aug 2019 15:34:32 +0200 114 | 115 | subnetcalc (2.4.13-1ubuntu1) eoan; urgency=medium 116 | 117 | * New upstream release. 118 | 119 | -- Thomas Dreibholz Wed, 07 Aug 2019 17:40:55 +0200 120 | 121 | subnetcalc (2.4.12-1ubuntu1) eoan; urgency=medium 122 | 123 | * New upstream release. 124 | 125 | -- Thomas Dreibholz Thu, 25 Jul 2019 15:09:24 +0200 126 | 127 | subnetcalc (2.4.11-1ubuntu1) disco; urgency=medium 128 | 129 | * New upstream version. 130 | * debian/control: updated standards version. 131 | 132 | -- Thomas Dreibholz Wed, 27 Feb 2019 08:08:08 +0800 133 | 134 | subnetcalc (2.4.10-1ubuntu1) cosmic; urgency=low 135 | 136 | * New upstream version. 137 | * debian/upstream/metadata: added metadata file. 138 | * debian/tests/control: added tests control file. 139 | 140 | -- Thomas Dreibholz Wed, 17 Oct 2018 08:08:08 +0800 141 | 142 | subnetcalc (2.4.9-1ubuntu1) bionic; urgency=low 143 | 144 | * New upstream version. 145 | * debian/rules: Change from autoconf/automake to cmake. 146 | * debian/control: Change from autoconf/automake to cmake. 147 | * debian/control: Updated standards version. 148 | 149 | -- Thomas Dreibholz Thu, 07 Jun 2018 08:08:08 +0800 150 | 151 | subnetcalc (2.4.8-1ubuntu1) bionic; urgency=low 152 | 153 | * New upstream version. 154 | 155 | -- Thomas Dreibholz Sun, 29 Oct 2017 08:08:08 +0800 156 | 157 | subnetcalc (2.4.7-1ubuntu1) artful; urgency=low 158 | 159 | * New upstream version. 160 | 161 | -- Thomas Dreibholz Wed, 09 Aug 2017 08:08:08 +0800 162 | 163 | subnetcalc (2.4.6-1ubuntu1) artful; urgency=low 164 | 165 | * New upstream version. 166 | * debian/watch: URL update 167 | * debian/control: URL update 168 | 169 | -- Thomas Dreibholz Wed, 09 Aug 2017 08:08:08 +0800 170 | 171 | subnetcalc (2.4.5-1ubuntu1) xenial; urgency=low 172 | 173 | * New upstream version. 174 | 175 | -- Thomas Dreibholz Thu, 04 Nov 2016 08:08:08 +0800 176 | 177 | subnetcalc (2.4.4-1ubuntu1) xenial; urgency=low 178 | 179 | * New upstream version. 180 | * debian/control: Updated standards version. 181 | * debian/control: added dependency dpkg-dev for hardening options. 182 | * debian/copyright: fix for machine-readable format. 183 | * debian/rules: using buildflags.mk for hardening options. 184 | 185 | -- Thomas Dreibholz Mon, 04 Apr 2016 08:08:08 +0800 186 | 187 | subnetcalc (2.4.3-1ubuntu1) xenial; urgency=low 188 | 189 | * New upstream version. 190 | 191 | -- Thomas Dreibholz Tue, 27 Oct 2015 08:08:08 +0800 192 | 193 | subnetcalc (2.4.2-1ubuntu1) wily; urgency=low 194 | 195 | * New upstream version. 196 | 197 | -- Thomas Dreibholz Mon, 11 May 2015 08:08:08 +0800 198 | 199 | subnetcalc (2.4.1-1ubuntu1) vivid; urgency=low 200 | 201 | * debian/copyright: changed to machine-readable format. 202 | * debian/control: updated standards version. 203 | * debian/watch: added pgpsigurlmangle option. 204 | * debian/upstream/signing-key.asc: added upstream public key. 205 | 206 | -- Thomas Dreibholz Sun, 01 Mar 2015 08:08:08 +0800 207 | 208 | subnetcalc (2.3.1-1ubuntu1) utopic; urgency=low 209 | 210 | * debian/control: updated standards version. 211 | 212 | -- Thomas Dreibholz Mon, 28 Jul 2014 08:08:08 +0800 213 | 214 | subnetcalc (2.2.1-1ubuntu1) trusty; urgency=low 215 | 216 | * debian/subnetcalc.manpages: Changed manpage category from 8 to 1. 217 | * debian/control: now compiling with colorgcc. 218 | 219 | -- Thomas Dreibholz Thu, 13 Mar 2014 08:08:08 +0800 220 | 221 | subnetcalc (2.1.3-1ubuntu1) oneiric; urgency=high 222 | 223 | * Switch to dpkg-source 3.0 (quilt) format. 224 | * Switch to debhelper 7 using tiny rules. 225 | * debian/control: 226 | Applied wrap-and-sort script to wrap lines and sort dependencies. 227 | Updated standards version to 3.9.2. 228 | * New upstream version bug closed (Closes: #625081). 229 | 230 | -- Thomas Dreibholz Wed, 04 May 2011 07:07:07 +0100 231 | 232 | subnetcalc (2.1.2-1ubuntu1) maverick; urgency=low 233 | 234 | * New upstream version with fixes for FreeBSD build scripts. 235 | * Updated standards version. 236 | * New upstream version bug closed (Closes: #591381). 237 | 238 | -- Thomas Dreibholz Thu, 05 Aug 2010 21:38:38 +0200 239 | 240 | subnetcalc (2.1.1-2ubuntu1) maverick; urgency=low 241 | 242 | * Upstream version update with support for libgeoip. 243 | * Switch to dpkg-source 3.0 (quilt) format 244 | 245 | -- Thomas Dreibholz Wed, 30 Jun 2010 17:23:11 +0200 246 | 247 | subnetcalc (2.0.4-1) unstable; urgency=low 248 | 249 | * Turned off DH_VERBOSE. 250 | * Updated Homepage to homepage of SubNetCalc. 251 | 252 | -- Thomas Dreibholz Wed, 10 Jun 2009 22:29:32 +0200 253 | 254 | subnetcalc (2.0.3-1) unstable; urgency=low 255 | 256 | * Initial Debian release (Closes: #531710). 257 | * Initial Ubuntu release (LP: #325653). 258 | 259 | -- Thomas Dreibholz Mon, 08 Jun 2009 22:59:32 +0200 260 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: subnetcalc 2 | Section: net 3 | Priority: optional 4 | Maintainer: Thomas Dreibholz 5 | Homepage: https://www.nntb.no/~dreibh/subnetcalc/ 6 | Vcs-Git: https://github.com/dreibh/subnetcalc.git 7 | Vcs-Browser: https://github.com/dreibh/subnetcalc 8 | Build-Depends: cmake, 9 | debhelper (>= 12), 10 | gettext, 11 | libgeoip-dev 12 | Standards-Version: 4.7.2 13 | Rules-Requires-Root: no 14 | 15 | Package: subnetcalc 16 | Architecture: any 17 | Depends: ${misc:Depends}, 18 | ${shlibs:Depends} 19 | Recommends: iproute2, 20 | iputils-tracepath, 21 | ping | iputils-ping, 22 | rsplib-tools, 23 | traceroute | inetutils-traceroute, 24 | whois 25 | Description: IPv4/IPv6 Subnet Calculator 26 | SubNetCalc is an IPv4/IPv6 subnet address calculator. For given IPv4 or 27 | IPv6 address and netmask or prefix length, it calculates network address, 28 | broadcast address, maximum number of hosts and host address range. The 29 | output is colourized for better readability (e.g. network part, host part). 30 | Also, it prints the addresses in binary format for better understandability. 31 | Furthermore, it can identify the address type (e.g. multicast, unique local, 32 | site local, etc.) and extract additional information from the address 33 | (e.g. type, scope, interface ID, etc.). Finally, it can generate 34 | IPv6 unique local prefixes. 35 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: SubNetCalc 3 | Upstream-Contact: Thomas Dreibholz 4 | Source: https://www.nntb.no/~dreibh/subnetcalc/ 5 | 6 | Files: * 7 | Copyright: Copyright (C) 2002-2025 Thomas Dreibholz 8 | License: GPL-3+ 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | . 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | . 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | . 22 | On Debian systems, the complete text of the GNU General 23 | Public License can be found in `/usr/share/common-licenses/GPL-3'. 24 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | # export DH_VERBOSE = 1 4 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 5 | 6 | %: 7 | dh $@ --buildsystem=cmake 8 | 9 | override_dh_auto_configure: 10 | dh_auto_configure -- 11 | 12 | # Use upstream ChangeLog for installation 13 | override_dh_installchangelogs: 14 | dh_installchangelogs -k ChangeLog 15 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/tests/control: -------------------------------------------------------------------------------- 1 | Tests: simple-test 2 | -------------------------------------------------------------------------------- /debian/tests/simple-test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ========================================================================== 3 | # ____ _ _ _ _ ____ _ 4 | # / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 5 | # \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 6 | # ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 7 | # |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 8 | # 9 | # --- IPv4/IPv6 Subnet Calculator --- 10 | # https://www.nntb.no/~dreibh/subnetcalc/ 11 | # ========================================================================== 12 | # 13 | # SubNetCalc - IPv4/IPv6 Subnet Calculator 14 | # Copyright (C) 2024-2025 by Thomas Dreibholz 15 | # 16 | # This program is free software: you can redistribute it and/or modify 17 | # it under the terms of the GNU General Public License as published by 18 | # the Free Software Foundation, either version 3 of the License, or 19 | # (at your option) any later version. 20 | # 21 | # This program is distributed in the hope that it will be useful, 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | # GNU General Public License for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program. If not, see . 28 | # 29 | # Contact: thomas.dreibholz@gmail.com 30 | 31 | # Bash options: 32 | set -e 33 | 34 | subnetcalc 172.20.0.0/16 35 | subnetcalc fd00:1:2:3::ffff/64 36 | subnetcalc fe80::2f0b:a04e:15c2:bc68 64 37 | 38 | echo "Test passed!" 39 | -------------------------------------------------------------------------------- /debian/upstream/metadata: -------------------------------------------------------------------------------- 1 | Bug-Database: https://github.com/dreibh/subnetcalc/issues 2 | Repository: https://github.com/dreibh/subnetcalc.git 3 | Repository-Browse: https://github.com/dreibh/subnetcalc 4 | Bug-Submit: https://github.com/dreibh/subnetcalc/issues 5 | Security-Contact: Thomas Dreibholz 6 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | version=4 2 | opts=pgpsigurlmangle=s/$/.asc/ \ 3 | https://www.nntb.no/~dreibh/subnetcalc/index.html download/subnetcalc-(.*)\.tar\.xz 4 | -------------------------------------------------------------------------------- /freebsd/subnetcalc/Makefile: -------------------------------------------------------------------------------- 1 | PORTNAME= subnetcalc 2 | DISTVERSION= 2.6.4 3 | CATEGORIES= net 4 | MASTER_SITES= https://www.nntb.no/~dreibh/subnetcalc/download/ 5 | 6 | MAINTAINER= thomas.dreibholz@gmail.com 7 | COMMENT= IPv4/IPv6 Subnet Calculator 8 | WWW= https://www.nntb.no/~dreibh/subnetcalc/ 9 | 10 | LICENSE= GPLv3+ 11 | LICENSE_FILE= ${WRKSRC}/COPYING 12 | 13 | USES= cmake gettext tar:xz 14 | 15 | PLIST_FILES= bin/subnetcalc \ 16 | share/bash-completion/completions/subnetcalc \ 17 | share/locale/de/LC_MESSAGES/subnetcalc.mo \ 18 | share/locale/nb/LC_MESSAGES/subnetcalc.mo \ 19 | share/man/man1/subnetcalc.1.gz 20 | 21 | .include 22 | -------------------------------------------------------------------------------- /freebsd/subnetcalc/distinfo: -------------------------------------------------------------------------------- 1 | TIMESTAMP = 1745778736 2 | SHA256 (subnetcalc-2.6.4.tar.xz) = 821401f2aa4eff12108a57679c06ba752b6dc15b40c0aba272e9f952b66174dc 3 | SIZE (subnetcalc-2.6.4.tar.xz) = 145404 4 | -------------------------------------------------------------------------------- /freebsd/subnetcalc/pkg-descr: -------------------------------------------------------------------------------- 1 | SubNetCalc is an IPv4/IPv6 subnet address calculator. For given IPv4 or IPv6 2 | address and netmask or prefix length, it calculates network address, broadcast 3 | address, maximum number of hosts and host address range. The output is 4 | colourized for better readability (e.g. network part, host part). Also, it 5 | prints the addresses in binary format for better understandability. 6 | 7 | Furthermore, it can identify the address type (e.g. multicast, unique local, 8 | site local, etc.) and extract additional information from the address 9 | (e.g. type, scope, interface ID, etc.). Finally, it can generate IPv6 unique 10 | local prefixes. 11 | -------------------------------------------------------------------------------- /freebsd/subnetcalc/test-packaging: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Free Packaging Test Script 4 | # Copyright (C) 2010-2024 by Thomas Dreibholz 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Contact: thomas.dreibholz@gmail.com 20 | 21 | PACKAGE=`cat Makefile | grep "^PORTNAME=" | sed -e "s/^PORTNAME=//g" | tr -d " \t"` 22 | UPSTREAM_VERSION=`cat Makefile | grep "^DISTVERSION=" | sed -e "s/^DISTVERSION=//g" | tr -d " \t"` 23 | PORTREVISION=`cat Makefile | grep "^PORTREVISION=" | sed -e "s/^PORTREVISION=//g" | tr -d " \t"` 24 | CATEGORY=`cat Makefile | grep "^CATEGORIES=" | sed -e "s/^CATEGORIES=//g" | tr -d " \t"` 25 | 26 | PACKAGE_VERSION="${UPSTREAM_VERSION}" 27 | if [ "${PORTREVISION}" != "" ] ; then 28 | PACKAGE_VERSION="${UPSTREAM_VERSION}_${PORTREVISION}" 29 | fi 30 | 31 | 32 | echo "######################################################################" 33 | echo "PACKAGE: ${PACKAGE}" 34 | echo "UPSTREAM_VERSION: ${UPSTREAM_VERSION}" 35 | echo "PACKAGE_VERSION: ${PACKAGE_VERSION}" 36 | echo "CATEGORY: ${CATEGORY}" 37 | echo "######################################################################" 38 | 39 | 40 | if [ -e work ] ; then 41 | rm -rf work 42 | fi 43 | rm -f ${PACKAGE}-${PACKAGE_VERSION}.txz 44 | if [ -d work/pkg ] ; then 45 | find work/pkg -name "${PACKAGE}*.txz" | xargs rm -f 46 | fi 47 | 48 | 49 | echo "1. ###### make deinstall ##############################################" && \ 50 | make deinstall && \ 51 | echo "2. ###### make install ################################################" && \ 52 | make install && \ 53 | echo "3. ###### make package ################################################" && \ 54 | make package && \ 55 | echo "4. ###### make deinstall ##############################################" && \ 56 | make deinstall && \ 57 | echo "5. ###### pkg add #####################################################" && \ 58 | if [ ! -e "work/pkg/${PACKAGE}-${PACKAGE_VERSION}.pkg" ] ; then 59 | echo >&2 "ERROR: Package work/pkg/${PACKAGE}-${PACKAGE_VERSION}.pkg not found!" 60 | exit 1 61 | fi && \ 62 | pkg add work/pkg/${PACKAGE}-${PACKAGE_VERSION}.pkg && \ 63 | echo "6. ###### make deinstall ##############################################" && \ 64 | make deinstall && \ 65 | echo "7. ###### make reinstall ##############################################" && \ 66 | make reinstall && \ 67 | echo "8. ###### make package ################################################" && \ 68 | make package && \ 69 | echo "9. ###### tar tzvf *.pkg ##############################################" && \ 70 | tar tzvf work/pkg/${PACKAGE}-${PACKAGE_VERSION}.pkg && \ 71 | echo "Running portlint ..." && \ 72 | portlint && \ 73 | echo "====== Successfully completed! ======" 74 | -------------------------------------------------------------------------------- /packaging.conf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # --------------------------------------------------------- 4 | MAKE_DIST="cmake -DCMAKE_INSTALL_PREFIX=/usr . && make dist" 5 | NOT_TARGET_DISTRIBUTIONS="lucid precise trusty xenial" # <<-- Distrubutions which are *not* supported! 6 | MAINTAINER="Thomas Dreibholz " 7 | MAINTAINER_KEY="21412672518D8B2D1862EFEF5CD5D12AA0877B49" 8 | DEBIAN_LAST_ENTRY="" 9 | UBUNTU_LAST_ENTRY="" 10 | SKIP_PACKAGE_SIGNING=0 # <<-- Must be set to 0 (=off) for PPA upload! 11 | # --------------------------------------------------------- 12 | -------------------------------------------------------------------------------- /po/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ========================================================================== 2 | # ____ _ _ _ _ ____ _ 3 | # / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | # \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | # ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | # |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | # 8 | # --- IPv4/IPv6 Subnet Calculator --- 9 | # https://www.nntb.no/~dreibh/subnetcalc/ 10 | # ========================================================================== 11 | # 12 | # SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | # Copyright (C) 2024-2025 by Thomas Dreibholz 14 | # 15 | # This program is free software: you can redistribute it and/or modify 16 | # it under the terms of the GNU General Public License as published by 17 | # the Free Software Foundation, either version 3 of the License, or 18 | # (at your option) any later version. 19 | # 20 | # This program is distributed in the hope that it will be useful, 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | # GNU General Public License for more details. 24 | # 25 | # You should have received a copy of the GNU General Public License 26 | # along with this program. If not, see . 27 | # 28 | # Contact: thomas.dreibholz@gmail.com 29 | 30 | 31 | ############################################################################# 32 | #### TRANSLATIONS #### 33 | ############################################################################# 34 | 35 | SET(copyrightHolder "Copyright (C) 2013-2025 by Thomas Dreibholz") 36 | SET(bugTrackerAddress "https://github.com/dreibh/subnetcalc/issues") 37 | 38 | FILE(GLOB sources "*.sources") 39 | 40 | # ====== Find all text domains ============================================== 41 | FOREACH(source IN LISTS sources) 42 | # The .sources file lists the source files for each text domain: 43 | GET_FILENAME_COMPONENT(potFile "${source}" NAME_WE) 44 | SET(potFile "${CMAKE_CURRENT_BINARY_DIR}/${potFile}.pot") 45 | GET_FILENAME_COMPONENT(textdomain "${source}" NAME_WE) 46 | 47 | 48 | # ====== Create POT file (translation template) ========================== 49 | FILE(READ "${source}" potInputFiles) 50 | STRING(REGEX REPLACE "[ \n]" ";" potInputFiles "${potInputFiles}") 51 | # The input (in potInputFiles) contains file names and options 52 | # (e.g. --language=C++). For the dependencies, just extract the list of 53 | # files without the options: 54 | SET(LIST potInputFilesForDependency "") 55 | FOREACH(file ${potInputFiles}) 56 | GET_FILENAME_COMPONENT(fileName ${file} NAME) 57 | IF (NOT ${fileName} MATCHES "^[-][-]") 58 | # File -> Add absolute file name 59 | LIST(APPEND potInputFilesForDependency ${potInputFilesAbsolute} "${PROJECT_SOURCE_DIR}/${file}") 60 | ENDIF() 61 | ENDFOREACH() 62 | 63 | MESSAGE("Translation template: ${textdomain} (${potInputFiles} -> ${potFile})") 64 | ADD_CUSTOM_COMMAND(OUTPUT "${potFile}" 65 | COMMAND "${XGETTEXT}" 66 | --from-code=utf-8 67 | --default-domain="${textdomain}" 68 | --package-name="${PROJECT_NAME}" 69 | --package-version="${BUILD_VERSION}" 70 | --copyright-holder="${copyrightHolder}" 71 | --msgid-bugs-address="${bugTrackerAddress}" 72 | --no-wrap 73 | -p "${CMAKE_CURRENT_SOURCE_DIR}" 74 | -o "${potFile}" 75 | ${potInputFiles} 76 | COMMAND sed -e "s/charset=CHARSET/charset=UTF-8/g" -i~ "${potFile}" 77 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" 78 | DEPENDS ${potInputFilesForDependency} "${source}" 79 | VERBATIM) 80 | SET(generate_PotFile "generate_pot_${textdomain}") 81 | ADD_CUSTOM_TARGET(${generate_PotFile} ALL DEPENDS "${potFile}") 82 | 83 | 84 | # ====== Process PO files (translations) ================================= 85 | FILE(GLOB_RECURSE poFiles "*/${textdomain}.po") 86 | FOREACH(poFile IN LISTS poFiles) 87 | 88 | # ====== Update PO file (translation) ================================= 89 | GET_FILENAME_COMPONENT(languageDirectory "${poFile}" DIRECTORY) 90 | GET_FILENAME_COMPONENT(language "${languageDirectory}" NAME "${CMAKE_CURRENT_SOURCE_DIR}") 91 | SET(poStampFile "${CMAKE_CURRENT_BINARY_DIR}/${language}/.${textdomain}.po.stamp") 92 | 93 | MESSAGE("Translation update: ${textdomain}, ${language} (${potFile} -> ${poFile})") 94 | # The .po file cannot be OUTPUT, since "make clean" would then delete it 95 | # => Using a stamp file as placeholder to ensure the dependency. 96 | ADD_CUSTOM_COMMAND(OUTPUT "${poStampFile}" 97 | COMMAND "${MSGMERGE}" 98 | --update "${poFile}" "${potFile}" 99 | --no-wrap 100 | COMMAND touch "${poStampFile}" 101 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" 102 | DEPENDS ${generate_PotFile} "${potFile}") 103 | SET(generate_PoFile "generate_po_${textdomain}_${language}") 104 | ADD_CUSTOM_TARGET(${generate_PoFile} DEPENDS "${poStampFile}") 105 | 106 | 107 | # ====== Compile PO file to MO file =================================== 108 | FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${language}/LC_MESSAGES") 109 | SET(moFile "${CMAKE_CURRENT_BINARY_DIR}/${language}/LC_MESSAGES/${textdomain}.mo") 110 | 111 | MESSAGE("Compiling translation: ${textdomain}, ${language} (${poFile} -> ${moFile})") 112 | ADD_CUSTOM_COMMAND(OUTPUT "${moFile}" 113 | COMMAND "${MSGFMT}" 114 | --statistics 115 | --check 116 | --output-file="${moFile}" 117 | ${poFile} 118 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" 119 | DEPENDS ${generate_PoFile} "${poFile}") 120 | SET(generate_MoFile "generate_mo_${textdomain}_${language}") 121 | ADD_CUSTOM_TARGET(${generate_MoFile} ALL DEPENDS "${moFile}") 122 | 123 | 124 | # ====== Install MO file ============================================== 125 | INSTALL(FILES "${moFile}" 126 | DESTINATION "${CMAKE_INSTALL_DATADIR}/locale/${language}/LC_MESSAGES") 127 | 128 | ENDFOREACH() 129 | ENDFOREACH() 130 | -------------------------------------------------------------------------------- /po/de/subnetcalc.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR "Copyright (C) 2013-2025 by Thomas Dreibholz" 3 | # This file is distributed under the same license as the "subnetcalc" package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: \"subnetcalc\" \"2.5.2~rc0\"\n" 10 | "Report-Msgid-Bugs-To: \"https://github.com/dreibh/subnetcalc/issues\"\n" 11 | "POT-Creation-Date: 2025-04-26 12:38+0200\n" 12 | "PO-Revision-Date: 2024-10-19 18:40+0200\n" 13 | "Last-Translator: Thomas Dreibholz \n" 14 | "Language-Team:\n" 15 | "Language: de\n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | "X-Language: de\n" 21 | "X-Source-Language: en_GB\n" 22 | 23 | #: src/subnetcalc.cc:162 24 | msgid "ERROR: An IPv6 address must be given to generate a unique local address!" 25 | msgstr "FEHLER: Um eine eindeutige lokale Adresse zu generieren, muß eine IPv6-Adresse angegeben werden!" 26 | 27 | #: src/subnetcalc.cc:171 28 | #, c-format 29 | msgid "Generating Unique Local IPv6 address (using %s) ..." 30 | msgstr "Unique-Local-IPv6-Adresse wird generiert (mit %s) ..." 31 | 32 | #: src/subnetcalc.cc:175 33 | #, c-format 34 | msgid "ERROR: Unable to read from %s!" 35 | msgstr "FEHLER: Lesen von %s nicht möglich!" 36 | 37 | #: src/subnetcalc.cc:181 38 | #, c-format 39 | msgid "ERROR: Unable to open %s!" 40 | msgstr "FEHLER: %s konnte nicht geöffnet werden!" 41 | 42 | #: src/subnetcalc.cc:445 src/subnetcalc.cc:453 src/subnetcalc.cc:469 43 | #: src/subnetcalc.cc:482 src/subnetcalc.cc:492 44 | #, c-format 45 | msgid "%-32s" 46 | msgstr "%-32s" 47 | 48 | #: src/subnetcalc.cc:445 49 | msgid "Global ID" 50 | msgstr "Globale ID" 51 | 52 | #: src/subnetcalc.cc:453 53 | msgid "Subnet ID" 54 | msgstr "Subnetz-ID" 55 | 56 | #: src/subnetcalc.cc:469 57 | msgid "Interface ID" 58 | msgstr "Schnittstellen-ID" 59 | 60 | #: src/subnetcalc.cc:482 61 | msgid "MAC Address" 62 | msgstr "MAC-Adresse" 63 | 64 | #: src/subnetcalc.cc:492 65 | msgid "Solicited Node Multicast Address" 66 | msgstr "Solicited Node Multicastadresse" 67 | 68 | #: src/subnetcalc.cc:509 src/subnetcalc.cc:929 src/subnetcalc.cc:932 69 | #: src/subnetcalc.cc:933 src/subnetcalc.cc:935 src/subnetcalc.cc:938 70 | #: src/subnetcalc.cc:947 src/subnetcalc.cc:952 src/subnetcalc.cc:955 71 | #: src/subnetcalc.cc:972 src/subnetcalc.cc:974 72 | #, c-format 73 | msgid "%-14s" 74 | msgstr "%-14s" 75 | 76 | #: src/subnetcalc.cc:509 77 | msgid "Properties" 78 | msgstr "Eigenschaften" 79 | 80 | #: src/subnetcalc.cc:512 81 | #, c-format 82 | msgid "%s is a MULTICAST address" 83 | msgstr "%s ist eine MULTICAST-Adresse" 84 | 85 | #: src/subnetcalc.cc:519 86 | #, c-format 87 | msgid "%s is the BROADCAST address of %s/%u" 88 | msgstr "%s ist die BROADCAST-Adresse von %s/%u" 89 | 90 | #: src/subnetcalc.cc:525 91 | #, c-format 92 | msgid "%s is a NETWORK address" 93 | msgstr "%s ist eine NETZWERK-Adresse" 94 | 95 | #: src/subnetcalc.cc:530 96 | #, c-format 97 | msgid "%s is a HOST address in %s/%u" 98 | msgstr "%s ist eine HOST-Adresse in %s/%u" 99 | 100 | #: src/subnetcalc.cc:543 101 | msgid "Class A" 102 | msgstr "Klasse A" 103 | 104 | #: src/subnetcalc.cc:545 src/subnetcalc.cc:616 105 | msgid "Loopback address" 106 | msgstr "Loopback-Adresse" 107 | 108 | #: src/subnetcalc.cc:548 109 | msgid "In loopback network" 110 | msgstr "Im Loopback-Netzwerk" 111 | 112 | #: src/subnetcalc.cc:551 src/subnetcalc.cc:557 src/subnetcalc.cc:566 113 | msgid "Private" 114 | msgstr "Privat" 115 | 116 | #: src/subnetcalc.cc:555 117 | msgid "Class B" 118 | msgstr "Klasse B" 119 | 120 | #: src/subnetcalc.cc:560 121 | msgid "Link-local address" 122 | msgstr "Link-lokale Adresse" 123 | 124 | #: src/subnetcalc.cc:564 125 | msgid "Class C" 126 | msgstr "Klasse C" 127 | 128 | #: src/subnetcalc.cc:570 129 | msgid "Class D (Multicast)" 130 | msgstr "Klasse D (Multicast)" 131 | 132 | #: src/subnetcalc.cc:572 src/subnetcalc.cc:635 133 | msgid "Scope: " 134 | msgstr "Geltungsbereich: " 135 | 136 | #: src/subnetcalc.cc:574 src/subnetcalc.cc:640 137 | msgid "link-local" 138 | msgstr "Link-lokal" 139 | 140 | #: src/subnetcalc.cc:577 src/subnetcalc.cc:646 141 | msgid "organization-local" 142 | msgstr "Organisations-lokal" 143 | 144 | #: src/subnetcalc.cc:580 src/subnetcalc.cc:643 145 | msgid "site-local" 146 | msgstr "Site-lokal" 147 | 148 | #: src/subnetcalc.cc:583 src/subnetcalc.cc:649 149 | msgid "global" 150 | msgstr "global" 151 | 152 | #: src/subnetcalc.cc:594 153 | #, c-format 154 | msgid "Corresponding multicast MAC address: %s" 155 | msgstr "Entsprechende Multicast-MAC-Adresse: %s" 156 | 157 | #: src/subnetcalc.cc:599 src/subnetcalc.cc:675 158 | msgid "Source-specific multicast" 159 | msgstr "Quellenspezifischer Multicast" 160 | 161 | #: src/subnetcalc.cc:603 162 | msgid "Invalid (not in class A, B, C or D)" 163 | msgstr "Ungültig (nicht in Klasse A, B, C oder D)" 164 | 165 | #: src/subnetcalc.cc:619 166 | msgid "Unspecified address" 167 | msgstr "Nicht spezifizierte Adresse" 168 | 169 | #: src/subnetcalc.cc:622 170 | msgid "IPv4-compatible IPv6 address" 171 | msgstr "IPv4-Compatible IPv6-Adresse" 172 | 173 | #: src/subnetcalc.cc:625 174 | msgid "IPv4-mapped IPv6 address" 175 | msgstr "IPv4-Mapped IPv6-Adresse" 176 | 177 | #: src/subnetcalc.cc:628 178 | msgid "IPv4-embedded IPv6 address" 179 | msgstr "IPv4-Embedded IPv6-Adresse" 180 | 181 | #: src/subnetcalc.cc:634 182 | msgid "Multicast Properties" 183 | msgstr "Multicast-Eigenschaften" 184 | 185 | #: src/subnetcalc.cc:637 186 | msgid "node-local" 187 | msgstr "Knoten-lokal" 188 | 189 | #: src/subnetcalc.cc:652 190 | msgid "unknown" 191 | msgstr "unbekannt" 192 | 193 | #: src/subnetcalc.cc:659 194 | msgid "Temporary-allocated address" 195 | msgstr "Temporär zugewiesene Adresse" 196 | 197 | #: src/subnetcalc.cc:670 198 | msgid "Corresponding multicast MAC address: " 199 | msgstr "Entsprechende Multicast-MAC-Adresse: " 200 | 201 | #: src/subnetcalc.cc:688 202 | msgid "Address is solicited node multicast address for" 203 | msgstr "Adresse ist die Solicited Node Multicastadresse für" 204 | 205 | #: src/subnetcalc.cc:695 206 | msgid "Link-Local Unicast Properties:" 207 | msgstr "Link-lokale Unicast-Eigenschaften:" 208 | 209 | #: src/subnetcalc.cc:701 210 | msgid "Site-Local Unicast Properties:" 211 | msgstr "Site-lokale Unicast-Eigenschaften:" 212 | 213 | #: src/subnetcalc.cc:707 214 | msgid "Unique Local Unicast Properties:" 215 | msgstr "Unique Local Unicast-Eigenschaften:" 216 | 217 | #: src/subnetcalc.cc:709 218 | msgid "Locally chosen" 219 | msgstr "Lokal ausgewählt" 220 | 221 | #: src/subnetcalc.cc:712 222 | msgid "Assigned by global instance" 223 | msgstr "Zugewiesen durch globale Instanz" 224 | 225 | #: src/subnetcalc.cc:719 226 | msgid "Global Unicast Properties:" 227 | msgstr "Globale Unicast-Eigenschaften:" 228 | 229 | #: src/subnetcalc.cc:729 230 | msgid "6-to-4 Address" 231 | msgstr "6-to-4-Adresse" 232 | 233 | #: src/subnetcalc.cc:785 234 | msgid "Usage:" 235 | msgstr "Aufruf:" 236 | 237 | #: src/subnetcalc.cc:801 src/subnetcalc.cc:816 238 | #, c-format 239 | msgid "ERROR: Invalid address %s!" 240 | msgstr "FEHLER: Ungültige Adresse %s!" 241 | 242 | #: src/subnetcalc.cc:806 src/subnetcalc.cc:825 src/subnetcalc.cc:851 243 | #, c-format 244 | msgid "ERROR: Invalid netmask %s!" 245 | msgstr "FEHLER: Ungültige Netzmaske %s!" 246 | 247 | #: src/subnetcalc.cc:857 248 | #, c-format 249 | msgid "ERROR: Incompatible netmask %s!" 250 | msgstr "FEHLER: Inkompatible Netzmaske %s!" 251 | 252 | #: src/subnetcalc.cc:882 253 | #, c-format 254 | msgid "ERROR: Invalid argument %s!" 255 | msgstr "FEHLER: Ungültiges Argument %s!" 256 | 257 | #: src/subnetcalc.cc:929 258 | msgid "Address" 259 | msgstr "Adresse" 260 | 261 | #: src/subnetcalc.cc:933 262 | msgid "Network" 263 | msgstr "Netzwerk" 264 | 265 | #: src/subnetcalc.cc:935 266 | msgid "Netmask" 267 | msgstr "Netzmaske" 268 | 269 | #: src/subnetcalc.cc:938 270 | msgid "Broadcast" 271 | msgstr "Broadcast" 272 | 273 | #: src/subnetcalc.cc:943 274 | msgid "not needed on Point-to-Point links" 275 | msgstr "Bei Punkt-zu-Punkt-Links nicht erforderlich" 276 | 277 | #: src/subnetcalc.cc:947 278 | msgid "Wildcard Mask" 279 | msgstr "Wildcardmaske" 280 | 281 | #: src/subnetcalc.cc:952 282 | msgid "Hex. Address" 283 | msgstr "Hex. Adresse" 284 | 285 | #: src/subnetcalc.cc:955 286 | msgid "Hosts Bits" 287 | msgstr "Hosts-Bits" 288 | 289 | #: src/subnetcalc.cc:972 290 | msgid "Max. Hosts" 291 | msgstr "Hosts maximal" 292 | 293 | #: src/subnetcalc.cc:974 294 | msgid "Host Range" 295 | msgstr "Hostbereich" 296 | 297 | #: src/subnetcalc.cc:998 src/subnetcalc.cc:1039 298 | msgid "GeoIP AS Info" 299 | msgstr "GeoIP AS-Info" 300 | 301 | #: src/subnetcalc.cc:1006 src/subnetcalc.cc:1047 302 | msgid "GeoIP Country" 303 | msgstr "GeoIP-Land" 304 | 305 | #: src/subnetcalc.cc:1017 src/subnetcalc.cc:1058 306 | msgid "GeoIP Region" 307 | msgstr "GeoIP-Region" 308 | 309 | #: src/subnetcalc.cc:1083 310 | msgid "Performing reverse DNS lookup ..." 311 | msgstr "Reverse-DNS-Suche wird durchgeführt ..." 312 | 313 | #: src/subnetcalc.cc:1099 314 | msgid "DNS Hostname" 315 | msgstr "DNS-Hostname" 316 | -------------------------------------------------------------------------------- /po/nb/subnetcalc.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR "Copyright (C) 2013-2025 by Thomas Dreibholz" 3 | # This file is distributed under the same license as the "subnetcalc" package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: \"subnetcalc\" \"2.5.2~rc0\"\n" 10 | "Report-Msgid-Bugs-To: \"https://github.com/dreibh/subnetcalc/issues\"\n" 11 | "POT-Creation-Date: 2025-04-26 12:38+0200\n" 12 | "PO-Revision-Date: 2024-10-19 18:40+0200\n" 13 | "Last-Translator: Thomas Dreibholz \n" 14 | "Language-Team:\n" 15 | "Language: nb\n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | "X-Language: nb\n" 21 | "X-Source-Language: en_GB\n" 22 | 23 | #: src/subnetcalc.cc:162 24 | msgid "ERROR: An IPv6 address must be given to generate a unique local address!" 25 | msgstr "FEIL: En IPv6-adresse må oppgis for å generere en unik lokal adresse!" 26 | 27 | #: src/subnetcalc.cc:171 28 | #, c-format 29 | msgid "Generating Unique Local IPv6 address (using %s) ..." 30 | msgstr "Genererer unik lokal IPv6-adresse (ved hjelp av %s) ..." 31 | 32 | #: src/subnetcalc.cc:175 33 | #, c-format 34 | msgid "ERROR: Unable to read from %s!" 35 | msgstr "FEIL: Kan ikke lese fra %s!" 36 | 37 | #: src/subnetcalc.cc:181 38 | #, c-format 39 | msgid "ERROR: Unable to open %s!" 40 | msgstr "FEIL: Kan ikke åpne %s!" 41 | 42 | #: src/subnetcalc.cc:445 src/subnetcalc.cc:453 src/subnetcalc.cc:469 43 | #: src/subnetcalc.cc:482 src/subnetcalc.cc:492 44 | #, c-format 45 | msgid "%-32s" 46 | msgstr "%-32s" 47 | 48 | #: src/subnetcalc.cc:445 49 | msgid "Global ID" 50 | msgstr "Global-ID" 51 | 52 | #: src/subnetcalc.cc:453 53 | msgid "Subnet ID" 54 | msgstr "Subnett-ID" 55 | 56 | #: src/subnetcalc.cc:469 57 | msgid "Interface ID" 58 | msgstr "Interface-ID" 59 | 60 | #: src/subnetcalc.cc:482 61 | msgid "MAC Address" 62 | msgstr "MAC-adresse" 63 | 64 | #: src/subnetcalc.cc:492 65 | msgid "Solicited Node Multicast Address" 66 | msgstr "Solicited Node Multicast-adresse" 67 | 68 | #: src/subnetcalc.cc:509 src/subnetcalc.cc:929 src/subnetcalc.cc:932 69 | #: src/subnetcalc.cc:933 src/subnetcalc.cc:935 src/subnetcalc.cc:938 70 | #: src/subnetcalc.cc:947 src/subnetcalc.cc:952 src/subnetcalc.cc:955 71 | #: src/subnetcalc.cc:972 src/subnetcalc.cc:974 72 | #, c-format 73 | msgid "%-14s" 74 | msgstr "%-14s" 75 | 76 | #: src/subnetcalc.cc:509 77 | msgid "Properties" 78 | msgstr "Egenskaper" 79 | 80 | #: src/subnetcalc.cc:512 81 | #, c-format 82 | msgid "%s is a MULTICAST address" 83 | msgstr "%s er en MULTICAST-adresse" 84 | 85 | #: src/subnetcalc.cc:519 86 | #, c-format 87 | msgid "%s is the BROADCAST address of %s/%u" 88 | msgstr "%s er BROADCAST-adressen til %s/%u" 89 | 90 | #: src/subnetcalc.cc:525 91 | #, c-format 92 | msgid "%s is a NETWORK address" 93 | msgstr "%s er en NETTVERK-adresse" 94 | 95 | #: src/subnetcalc.cc:530 96 | #, c-format 97 | msgid "%s is a HOST address in %s/%u" 98 | msgstr "%s er en HOST-adresse i %s/%u" 99 | 100 | #: src/subnetcalc.cc:543 101 | msgid "Class A" 102 | msgstr "Klasse A" 103 | 104 | #: src/subnetcalc.cc:545 src/subnetcalc.cc:616 105 | msgid "Loopback address" 106 | msgstr "Loopback-adresse" 107 | 108 | #: src/subnetcalc.cc:548 109 | msgid "In loopback network" 110 | msgstr "In loopback-nettverk" 111 | 112 | #: src/subnetcalc.cc:551 src/subnetcalc.cc:557 src/subnetcalc.cc:566 113 | msgid "Private" 114 | msgstr "Privat" 115 | 116 | #: src/subnetcalc.cc:555 117 | msgid "Class B" 118 | msgstr "Klasse B" 119 | 120 | #: src/subnetcalc.cc:560 121 | msgid "Link-local address" 122 | msgstr "Link-lokal adresse" 123 | 124 | #: src/subnetcalc.cc:564 125 | msgid "Class C" 126 | msgstr "Klasse C" 127 | 128 | #: src/subnetcalc.cc:570 129 | msgid "Class D (Multicast)" 130 | msgstr "Klasse D (Multicast)" 131 | 132 | #: src/subnetcalc.cc:572 src/subnetcalc.cc:635 133 | msgid "Scope: " 134 | msgstr "Omfang: " 135 | 136 | #: src/subnetcalc.cc:574 src/subnetcalc.cc:640 137 | msgid "link-local" 138 | msgstr "link-lokal" 139 | 140 | #: src/subnetcalc.cc:577 src/subnetcalc.cc:646 141 | msgid "organization-local" 142 | msgstr "organisasjon-lokal" 143 | 144 | #: src/subnetcalc.cc:580 src/subnetcalc.cc:643 145 | msgid "site-local" 146 | msgstr "sted-lokal" 147 | 148 | #: src/subnetcalc.cc:583 src/subnetcalc.cc:649 149 | msgid "global" 150 | msgstr "global" 151 | 152 | #: src/subnetcalc.cc:594 153 | #, c-format 154 | msgid "Corresponding multicast MAC address: %s" 155 | msgstr "Tilsvarende multicast MAC-adresse: %s" 156 | 157 | #: src/subnetcalc.cc:599 src/subnetcalc.cc:675 158 | msgid "Source-specific multicast" 159 | msgstr "Kildespesifikk multicast" 160 | 161 | #: src/subnetcalc.cc:603 162 | msgid "Invalid (not in class A, B, C or D)" 163 | msgstr "Ugyldig (ikke i klasse A, B, C eller D)" 164 | 165 | #: src/subnetcalc.cc:619 166 | msgid "Unspecified address" 167 | msgstr "Uspesifisert adresse" 168 | 169 | #: src/subnetcalc.cc:622 170 | msgid "IPv4-compatible IPv6 address" 171 | msgstr "IPv4-kompatibel IPv6-adresse" 172 | 173 | #: src/subnetcalc.cc:625 174 | msgid "IPv4-mapped IPv6 address" 175 | msgstr "IPv4-tilordnet IPv6-adresse" 176 | 177 | #: src/subnetcalc.cc:628 178 | msgid "IPv4-embedded IPv6 address" 179 | msgstr "IPv4-innebygd IPv6-adresse" 180 | 181 | #: src/subnetcalc.cc:634 182 | msgid "Multicast Properties" 183 | msgstr "Multicast-egenskaper" 184 | 185 | #: src/subnetcalc.cc:637 186 | msgid "node-local" 187 | msgstr "node-lokalt" 188 | 189 | #: src/subnetcalc.cc:652 190 | msgid "unknown" 191 | msgstr "ukjent" 192 | 193 | #: src/subnetcalc.cc:659 194 | msgid "Temporary-allocated address" 195 | msgstr "Midlertidig tildelt adresse" 196 | 197 | #: src/subnetcalc.cc:670 198 | msgid "Corresponding multicast MAC address: " 199 | msgstr "Tilsvarende multicast MAC-adresse: " 200 | 201 | #: src/subnetcalc.cc:688 202 | msgid "Address is solicited node multicast address for" 203 | msgstr "Adressen er solicited node multicast-adresse for" 204 | 205 | #: src/subnetcalc.cc:695 206 | msgid "Link-Local Unicast Properties:" 207 | msgstr "Link-Local Unicast-egenskaper:" 208 | 209 | #: src/subnetcalc.cc:701 210 | msgid "Site-Local Unicast Properties:" 211 | msgstr "Site-Local Unicast-egenskaper:" 212 | 213 | #: src/subnetcalc.cc:707 214 | msgid "Unique Local Unicast Properties:" 215 | msgstr "Unique Local Unicast-egenskaper:" 216 | 217 | #: src/subnetcalc.cc:709 218 | msgid "Locally chosen" 219 | msgstr "Lokalt valgt" 220 | 221 | #: src/subnetcalc.cc:712 222 | msgid "Assigned by global instance" 223 | msgstr "Tilordnet av global forekomst" 224 | 225 | #: src/subnetcalc.cc:719 226 | msgid "Global Unicast Properties:" 227 | msgstr "Global Unicast-egenskaper:" 228 | 229 | #: src/subnetcalc.cc:729 230 | msgid "6-to-4 Address" 231 | msgstr "6-to-4-adresse" 232 | 233 | #: src/subnetcalc.cc:785 234 | msgid "Usage:" 235 | msgstr "Bruk:" 236 | 237 | #: src/subnetcalc.cc:801 src/subnetcalc.cc:816 238 | #, c-format 239 | msgid "ERROR: Invalid address %s!" 240 | msgstr "FEIL: Ugyldig adresse %s!" 241 | 242 | #: src/subnetcalc.cc:806 src/subnetcalc.cc:825 src/subnetcalc.cc:851 243 | #, c-format 244 | msgid "ERROR: Invalid netmask %s!" 245 | msgstr "FEIL: Ugyldig nettmaske %s!" 246 | 247 | #: src/subnetcalc.cc:857 248 | #, c-format 249 | msgid "ERROR: Incompatible netmask %s!" 250 | msgstr "FEIL: Inkompatibel nettmaske %s!" 251 | 252 | #: src/subnetcalc.cc:882 253 | #, c-format 254 | msgid "ERROR: Invalid argument %s!" 255 | msgstr "FEIL: Ugyldig argument %s!" 256 | 257 | #: src/subnetcalc.cc:929 258 | msgid "Address" 259 | msgstr "Adresse" 260 | 261 | #: src/subnetcalc.cc:933 262 | msgid "Network" 263 | msgstr "Nettverk" 264 | 265 | #: src/subnetcalc.cc:935 266 | msgid "Netmask" 267 | msgstr "Nettverksmaske" 268 | 269 | #: src/subnetcalc.cc:938 270 | msgid "Broadcast" 271 | msgstr "Broadcast" 272 | 273 | #: src/subnetcalc.cc:943 274 | msgid "not needed on Point-to-Point links" 275 | msgstr "ikke nødvendig på punkt-til-punkt-lenker" 276 | 277 | #: src/subnetcalc.cc:947 278 | msgid "Wildcard Mask" 279 | msgstr "Wildcardmaske" 280 | 281 | #: src/subnetcalc.cc:952 282 | msgid "Hex. Address" 283 | msgstr "Hex. adresse" 284 | 285 | #: src/subnetcalc.cc:955 286 | msgid "Hosts Bits" 287 | msgstr "Host bits" 288 | 289 | #: src/subnetcalc.cc:972 290 | msgid "Max. Hosts" 291 | msgstr "Maks. hosts " 292 | 293 | #: src/subnetcalc.cc:974 294 | msgid "Host Range" 295 | msgstr "Host range" 296 | 297 | #: src/subnetcalc.cc:998 src/subnetcalc.cc:1039 298 | msgid "GeoIP AS Info" 299 | msgstr "GeoIP AS-info" 300 | 301 | #: src/subnetcalc.cc:1006 src/subnetcalc.cc:1047 302 | msgid "GeoIP Country" 303 | msgstr "GeoIP-land" 304 | 305 | #: src/subnetcalc.cc:1017 src/subnetcalc.cc:1058 306 | msgid "GeoIP Region" 307 | msgstr "GeoIP-regionen" 308 | 309 | #: src/subnetcalc.cc:1083 310 | msgid "Performing reverse DNS lookup ..." 311 | msgstr "Utfører omvendt DNS-oppslag ..." 312 | 313 | #: src/subnetcalc.cc:1099 314 | msgid "DNS Hostname" 315 | msgstr "DNS-vertsnavn" 316 | -------------------------------------------------------------------------------- /po/subnetcalc.sources: -------------------------------------------------------------------------------- 1 | --language=C++ src/subnetcalc.cc 2 | --language=C++ src/tools.cc 3 | --language=C++ src/tools.h 4 | -------------------------------------------------------------------------------- /rpm/subnetcalc.spec: -------------------------------------------------------------------------------- 1 | Name: subnetcalc 2 | Version: 2.6.4 3 | Release: 1 4 | Summary: IPv4/IPv6 Subnet Calculator 5 | Group: Applications/Internet 6 | License: GPL-3.0-or-later 7 | URL: https://www.nntb.no/~dreibh/subnetcalc/ 8 | Source: https://www.nntb.no/~dreibh/subnetcalc/download/%{name}-%{version}.tar.xz 9 | 10 | AutoReqProv: on 11 | BuildRequires: cmake 12 | BuildRequires: gcc 13 | BuildRequires: gcc-c++ 14 | BuildRequires: gettext 15 | BuildRequires: GeoIP-devel 16 | Requires: GeoIP 17 | Recommends: iproute 18 | BuildRoot: %{_tmppath}/%{name}-%{version}-build 19 | 20 | 21 | %description 22 | SubNetCalc is an IPv4/IPv6 subnet address calculator. For given IPv4 or IPv6 23 | address and netmask or prefix length, it calculates network address, broadcast 24 | address, maximum number of hosts and host address range. The output is 25 | colourized for better readability (e.g. network part, host part). Also, it 26 | prints the addresses in binary format for better understandability. Furthermore, 27 | it can identify the address type (e.g. multicast, unique local, site local, 28 | etc.) and extract additional information from the address (e.g. type, scope, 29 | interface ID, etc.). Finally, it can generate IPv6 unique local prefixes. 30 | 31 | %prep 32 | %setup -q 33 | 34 | %build 35 | %cmake -DCMAKE_INSTALL_PREFIX=/usr . 36 | %cmake_build 37 | 38 | %install 39 | %cmake_install 40 | 41 | %files 42 | %{_bindir}/subnetcalc 43 | %{_datadir}/bash-completion/completions/subnetcalc 44 | %{_datadir}/locale/*/LC_MESSAGES/subnetcalc.mo 45 | %{_mandir}/man1/subnetcalc.1.gz 46 | 47 | 48 | %doc 49 | 50 | %changelog 51 | * Sun Apr 27 2025 Thomas Dreibholz - 2.6.4 52 | - New upstream release. 53 | * Sat Apr 26 2025 Thomas Dreibholz - 2.6.3 54 | - New upstream release. 55 | * Mon Jan 06 2025 Thomas Dreibholz - 2.6.2 56 | - New upstream release. 57 | * Fri Dec 13 2024 Thomas Dreibholz - 2.6.1 58 | - New upstream release. 59 | * Wed Nov 13 2024 Thomas Dreibholz - 2.6.0 60 | - New upstream release. 61 | * Mon Feb 12 2024 Thomas Dreibholz - 2.5.1 62 | - New upstream release. 63 | * Sat Feb 10 2024 Thomas Dreibholz - 2.5.0 64 | - New upstream release. 65 | * Wed Dec 06 2023 Thomas Dreibholz - 2.4.23 66 | - New upstream release. 67 | * Fri Jun 30 2023 Thomas Dreibholz - 2.4.22 68 | - New upstream release. 69 | * Sun Jan 22 2023 Thomas Dreibholz - 2.4.21 70 | - New upstream release. 71 | * Sun Sep 11 2022 Thomas Dreibholz - 2.4.20 72 | - New upstream release. 73 | * Mon Nov 08 2021 Thomas Dreibholz - 2.4.19 74 | - New upstream release. 75 | * Sat Mar 06 2021 Thomas Dreibholz - 2.4.18 76 | - New upstream release. 77 | * Fri Nov 13 2020 Thomas Dreibholz - 2.4.17 78 | - New upstream release. 79 | * Mon May 18 2020 Thomas Dreibholz - 2.4.16 80 | - New upstream release. 81 | * Fri Feb 07 2020 Thomas Dreibholz - 2.4.15 82 | - New upstream release. 83 | * Wed Aug 14 2019 Thomas Dreibholz - 2.4.14 84 | - New upstream release. 85 | * Wed Aug 07 2019 Thomas Dreibholz - 2.4.13 86 | - New upstream release. 87 | * Fri Jul 26 2019 Thomas Dreibholz - 2.4.12 88 | - New upstream release. 89 | * Tue May 21 2019 Thomas Dreibholz - 2.4.11 90 | - New upstream release. 91 | * Wed Nov 22 2017 Thomas Dreibholz - 2.2.0 92 | - Created RPM package. 93 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ========================================================================== 2 | # ____ _ _ _ _ ____ _ 3 | # / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | # \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | # ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | # |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | # 8 | # --- IPv4/IPv6 Subnet Calculator --- 9 | # https://www.nntb.no/~dreibh/subnetcalc/ 10 | # ========================================================================== 11 | # 12 | # SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | # Copyright (C) 2024-2025 by Thomas Dreibholz 14 | # 15 | # This program is free software: you can redistribute it and/or modify 16 | # it under the terms of the GNU General Public License as published by 17 | # the Free Software Foundation, either version 3 of the License, or 18 | # (at your option) any later version. 19 | # 20 | # This program is distributed in the hope that it will be useful, 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | # GNU General Public License for more details. 24 | # 25 | # You should have received a copy of the GNU General Public License 26 | # along with this program. If not, see . 27 | # 28 | # Contact: thomas.dreibholz@gmail.com 29 | 30 | 31 | ############################################################################# 32 | #### VERSION FILE #### 33 | ############################################################################# 34 | 35 | CONFIGURE_FILE ( 36 | "${CMAKE_CURRENT_SOURCE_DIR}/package-version.h.in" 37 | "${CMAKE_CURRENT_BINARY_DIR}/package-version.h" 38 | ) 39 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) 40 | 41 | 42 | ############################################################################# 43 | #### PROGRAMS #### 44 | ############################################################################# 45 | 46 | ADD_EXECUTABLE(subnetcalc subnetcalc.cc tools.cc) 47 | TARGET_LINK_LIBRARIES(subnetcalc ${Intl_LIBRARIES}) 48 | IF (GEOIP_FOUND) 49 | TARGET_LINK_LIBRARIES(subnetcalc ${GeoIP_LIBRARY}) 50 | ENDIF() 51 | INSTALL(TARGETS subnetcalc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 52 | INSTALL(FILES subnetcalc.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 53 | INSTALL(FILES subnetcalc.bash-completion 54 | DESTINATION ${CMAKE_INSTALL_DATADIR}/bash-completion/completions 55 | RENAME subnetcalc) 56 | -------------------------------------------------------------------------------- /src/package-version.h.in: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // ____ _ _ _ _ ____ _ 3 | // / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | // \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | // ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | // |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | // 8 | // --- IPv4/IPv6 Subnet Calculator --- 9 | // https://www.nntb.no/~dreibh/subnetcalc/ 10 | // ========================================================================== 11 | // 12 | // SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | // Copyright (C) 2024-2025 by Thomas Dreibholz 14 | // 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // 20 | // This program is distributed in the hope that it will be useful, 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | // GNU General Public License for more details. 24 | // 25 | // You should have received a copy of the GNU General Public License 26 | // along with this program. If not, see . 27 | // 28 | // Contact: thomas.dreibholz@gmail.com 29 | 30 | #ifndef SUBNETCALC_VERSION_H 31 | #define SUBNETCALC_VERSION_H 32 | 33 | #define SUBNETCALC_VERSION_MAJOR "@BUILD_MAJOR@" 34 | #define SUBNETCALC_VERSION_MINOR "@BUILD_MINOR@" 35 | #define SUBNETCALC_VERSION_PATCH "@BUILD_PATCH@" 36 | #define SUBNETCALC_VERSION "@BUILD_MAJOR@.@BUILD_MINOR@.@BUILD_PATCH@" 37 | #define SUBNETCALC_PACKAGE "@PROJECT_NAME@-@BUILD_MAJOR@.@BUILD_MINOR@.@BUILD_PATCH@" 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/subnetcalc.1: -------------------------------------------------------------------------------- 1 | .\" ========================================================================== 2 | .\" ____ _ _ _ _ ____ _ 3 | .\" / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | .\" \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | .\" ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | .\" |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | .\" 8 | .\" --- IPv4/IPv6 Subnet Calculator --- 9 | .\" https://www.nntb.no/~dreibh/subnetcalc/ 10 | .\" ========================================================================== 11 | .\" 12 | .\" SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | .\" Copyright (C) 2024-2025 by Thomas Dreibholz 14 | .\" 15 | .\" This program is free software: you can redistribute it and/or modify 16 | .\" it under the terms of the GNU General Public License as published by 17 | .\" the Free Software Foundation, either version 3 of the License, or 18 | .\" (at your option) any later version. 19 | .\" 20 | .\" This program is distributed in the hope that it will be useful, 21 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | .\" GNU General Public License for more details. 24 | .\" 25 | .\" You should have received a copy of the GNU General Public License 26 | .\" along with this program. If not, see . 27 | .\" 28 | .\" Contact: thomas.dreibholz@gmail.com 29 | .\" 30 | .\" ###### Setup ############################################################ 31 | .Dd January 06, 2025 32 | .Dt subnetcalc 1 33 | .Os subnetcalc 34 | .\" ###### Name ############################################################# 35 | .Sh NAME 36 | .Nm subnetcalc 37 | .Nd IPv4/IPv6 Subnet Calculator 38 | .\" ###### Synopsis ######################################################### 39 | .Sh SYNOPSIS 40 | .Nm subnetcalc 41 | .Op Address | Address Prefix | Address Netmask | Address/Prefix | Address/Netmask 42 | .Op Fl n 43 | .Op Fl uniquelocal 44 | .Op Fl uniquelocalhq 45 | .Op Fl nocolour | Fl nocolor 46 | .Op Fl v | Fl version 47 | .\" ###### Description ###################################################### 48 | .Sh DESCRIPTION 49 | .Nm subnetcalc 50 | is an IPv4/IPv6 subnet address calculator. For given IPv4 or IPv6 address and netmask or prefix length, it calculates network address, broadcast address, maximum number of hosts and host address range. Also, it prints the addresses in binary format for better understandability. Furthermore, it prints useful information on specific address types (e.g. type, scope, interface ID, etc.). 51 | .Pp 52 | .\" ###### Arguments ######################################################## 53 | .Sh ARGUMENTS 54 | The following arguments have to be provided: 55 | .Bl -tag -width indent 56 | .It Address 57 | The IP address. If a hostname is provided here, it is tried to resolve the address by a DNS server and the first returned address is used. Internationalized Domain Names (IDN) are supported. 58 | .It Netmask/Prefix 59 | The netmask or prefix length (0-32 for IPv4; 0-128 for IPv6). 60 | .It Fl n 61 | Skip trying a reverse DNS lookup. 62 | .It Fl uniquelocal 63 | Given an IPv6 address, the first 48 bits of the address are replaced by a randomly chosen IPv6 Unique Local prefix in fc00::/7 (see also RFC 4193). Under Linux and FreeBSD, /dev/urandom is used for random number generation. 64 | .It Fl uniquelocalhq 65 | Like \-uniquelocal, but using /dev/random instead on Linux and FreeBSD systems for highest-quality random number generation. On other systems, this option is equal to \-uniquelocal. Note, that reading from /dev/random may take some time. You can speed up this process by delivering random input e.g. by pressing keys or moving the mouse. 66 | .It Fl nocolour | Fl nocolor 67 | Turns colourised output off. 68 | .It Fl v | Fl version 69 | Just prints program version. 70 | .El 71 | .\" ###### Examples ######################################################### 72 | .Sh EXAMPLES 73 | .Bl -tag -width indent 74 | .It subnetcalc -v 75 | .It subnetcalc 132.252.250.0 255.255.255.0 76 | .It subnetcalc 132.252.250.0/255.255.255.0 -nocolor 77 | .It subnetcalc 132.252.250.0 24 78 | .It subnetcalc 132.252.250.0/24 -nocolour 79 | .It subnetcalc fe80::2f0b:a04e:15c2:bc68 64 80 | .It subnetcalc fe80::2f0b:a04e:15c2:bc68%wlp4s0 64 81 | .It subnetcalc fec0:2345:6789:1111:221:6aff:fe0b:2674 56 82 | .It subnetcalc 2a00:1450:8007::69 64 83 | .It subnetcalc ff08::1:2:3 84 | .It subnetcalc 131.220.6.5/24 85 | .It subnetcalc 132.252.181.87 \-n 86 | .It subnetcalc www.iem.uni-due.de 24 87 | .It subnetcalc www.six.heise.de 88 | .It subnetcalc fd00:: 64 \-uniquelocal 89 | .It subnetcalc fd00::9876:256:7bff:fe1b:3255 56 \-uniquelocalhq 90 | .It subnetcalc düsseldorf.de 28 91 | .It subnetcalc www.köln.de 92 | .It subnetcalc räksmörgås.josefsson.org 24 93 | .El 94 | .\" ###### Authors ########################################################## 95 | .Sh AUTHORS 96 | Thomas Dreibholz 97 | .br 98 | https://www.nntb.no/~dreibh/subnetcalc 99 | .br 100 | mailto://thomas.dreibholz@gmail.com 101 | .br 102 | -------------------------------------------------------------------------------- /src/subnetcalc.bash-completion: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | # ========================================================================== 3 | # ____ _ _ _ _ ____ _ 4 | # / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 5 | # \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 6 | # ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 7 | # |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 8 | # 9 | # --- IPv4/IPv6 Subnet Calculator --- 10 | # https://www.nntb.no/~dreibh/subnetcalc/ 11 | # ========================================================================== 12 | # 13 | # SubNetCalc - IPv4/IPv6 Subnet Calculator 14 | # Copyright (C) 2024-2025 by Thomas Dreibholz 15 | # 16 | # This program is free software: you can redistribute it and/or modify 17 | # it under the terms of the GNU General Public License as published by 18 | # the Free Software Foundation, either version 3 of the License, or 19 | # (at your option) any later version. 20 | # 21 | # This program is distributed in the hope that it will be useful, 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | # GNU General Public License for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program. If not, see . 28 | # 29 | # Contact: thomas.dreibholz@gmail.com 30 | 31 | 32 | # ###### Bash completion for subnetcalc ##################################### 33 | _subnetcalc() 34 | { 35 | # Based on: https://www.benningtons.net/index.php/bash-completion/ 36 | local cur prev words cword 37 | if type -t _comp_initialize >/dev/null; then 38 | _comp_initialize || return 39 | elif type -t _init_completion >/dev/null; then 40 | _init_completion || return 41 | else 42 | # Manual initialization for older bash completion versions: 43 | COMPREPLY=() 44 | cur="${COMP_WORDS[COMP_CWORD]}" 45 | # shellcheck disable=SC2034 46 | prev="${COMP_WORDS[COMP_CWORD-1]}" 47 | # shellcheck disable=SC2034,SC2124 48 | words="${COMP_WORDS[@]}" 49 | # shellcheck disable=SC2034 50 | cword="${COMP_CWORD}" 51 | fi 52 | 53 | # ====== Parameters ====================================================== 54 | if [ "${cword}" -le 1 ] ; then 55 | # Suggest IP addresses of local machine: 56 | local addresses 57 | if [ -x /usr/sbin/ip ] ; then 58 | addresses="$( /usr/sbin/ip addr show | awk '/[ ]+inet/ { print $2 }')" 59 | elif [ -x /sbin/ifconfig ] ; then 60 | local addressesV4 61 | local addressesV6 62 | addressesV4="$(/sbin/ifconfig | awk '/[ \t]+inet / { a=$4 ; print $2 "/" sprintf("%d.%d.%d.%d", "0x" substr(a, 3, 2), "0x" substr(a, 5, 2), "0x" substr(a, 7, 2), "0x" substr(a, 9, 2)) }')" 63 | addressesV6="$(/sbin/ifconfig | awk '/[ \t]+inet6 / { print $2 "/" $4 }' | sed -e 's#%.*/#/#')" 64 | addresses="${addressesV4} ${addressesV6}" 65 | fi 66 | # shellcheck disable=SC2207 67 | COMPREPLY=( $(compgen -W "${addresses}" -- "${cur}") ) 68 | return 69 | fi 70 | 71 | 72 | # ====== All options ===================================================== 73 | local opts=" 74 | -n 75 | -nocolor 76 | -nocolour 77 | -uniquelocal 78 | -uniquelocalhq 79 | -v 80 | -version 81 | " 82 | # shellcheck disable=SC2207 83 | COMPREPLY=( $( compgen -W "${opts}" -- "${cur}" ) ) 84 | 85 | return 0 86 | } 87 | 88 | complete -F _subnetcalc subnetcalc 89 | -------------------------------------------------------------------------------- /src/subnetcalc.cc: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // ____ _ _ _ _ ____ _ 3 | // / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | // \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | // ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | // |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | // 8 | // --- IPv4/IPv6 Subnet Calculator --- 9 | // https://www.nntb.no/~dreibh/subnetcalc/ 10 | // ========================================================================== 11 | // 12 | // SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | // Copyright (C) 2024-2025 by Thomas Dreibholz 14 | // 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // 20 | // This program is distributed in the hope that it will be useful, 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | // GNU General Public License for more details. 24 | // 25 | // You should have received a copy of the GNU General Public License 26 | // along with this program. If not, see . 27 | // 28 | // Contact: thomas.dreibholz@gmail.com 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #ifdef HAVE_GEOIP 39 | #include 40 | #include 41 | #endif 42 | 43 | #include 44 | #include 45 | 46 | #include "tools.h" 47 | #include "package-version.h" 48 | 49 | 50 | #ifdef __FreeBSD__ // FreeBSD 51 | #define s6_addr16 __u6_addr.__u6_addr16 52 | #define s6_addr32 __u6_addr.__u6_addr32 53 | #endif 54 | #ifdef __APPLE__ // MacOS X 55 | #define s6_addr16 __u6_addr.__u6_addr16 56 | #define s6_addr32 __u6_addr.__u6_addr32 57 | #endif 58 | #ifdef __sun // SunOS and Solaris 59 | #define s6_addr16 _S6_un._S6_u16 60 | #define s6_addr32 _S6_un._S6_u32 61 | #endif 62 | 63 | 64 | // ###### Is given address an IPv4 address? ################################# 65 | inline bool isIPv4(const sockaddr_union& address) 66 | { 67 | return (address.sa.sa_family == AF_INET); 68 | } 69 | 70 | 71 | // ###### Extract IPv4 address from address ################################# 72 | inline in_addr_t getIPv4Address(const sockaddr_union& address) 73 | { 74 | assert(address.sa.sa_family == AF_INET); 75 | return address.in.sin_addr.s_addr; 76 | } 77 | 78 | 79 | // ###### Extract IPv4 address from address ################################# 80 | inline in6_addr getIPv6Address(const sockaddr_union& address) 81 | { 82 | assert(address.sa.sa_family == AF_INET6); 83 | return address.in6.sin6_addr; 84 | } 85 | 86 | 87 | // ###### Is given address a multicast address? ############################# 88 | inline bool isMulticast(const sockaddr_union& address) 89 | { 90 | if(isIPv4(address)) { 91 | return IN_CLASSD(ntohl(getIPv4Address(address))); 92 | } 93 | else { 94 | const in6_addr ipv6address = getIPv6Address(address); 95 | return IN6_IS_ADDR_MULTICAST(&ipv6address); 96 | } 97 | } 98 | 99 | 100 | // ###### Show version ###################################################### 101 | void showVersion() 102 | { 103 | std::cout << "SubNetCalc " << SUBNETCALC_VERSION << "\n"; 104 | exit(0); 105 | } 106 | 107 | 108 | // ###### Read prefix from parameter ######################################## 109 | int readPrefix(const char* parameter, 110 | const sockaddr_union& forAddress, 111 | sockaddr_union& netmask) 112 | { 113 | for(size_t i = 0;i < strlen(parameter);i++) { 114 | if(!isdigit(parameter[i])) { 115 | return -1; 116 | } 117 | } 118 | int prefix = atol(parameter); 119 | if(prefix < 0) { 120 | return -1; 121 | } 122 | netmask = forAddress; 123 | if(netmask.sa.sa_family == AF_INET) { 124 | if(prefix > 32) { 125 | return -1; 126 | } 127 | int p = prefix; 128 | netmask.in.sin_addr.s_addr = 0; 129 | for(int i = 31;i >= 0;i--) { 130 | if(p > 0) { 131 | netmask.in.sin_addr.s_addr |= (1 << i); 132 | } 133 | p--; 134 | } 135 | netmask.in.sin_addr.s_addr = ntohl(netmask.in.sin_addr.s_addr); 136 | } 137 | else { 138 | if(prefix > 128) { 139 | return -1; 140 | } 141 | int p = prefix; 142 | for(int j = 0;j < 16;j++) { 143 | netmask.in6.sin6_addr.s6_addr[j] = 0; 144 | for(int i = 7;i >= 0;i--) { 145 | if(p > 0) { 146 | netmask.in6.sin6_addr.s6_addr[j] |= (1 << i); 147 | } 148 | p--; 149 | } 150 | } 151 | } 152 | return prefix; 153 | } 154 | 155 | 156 | // ###### Generate a unique local IPv6 address ############################## 157 | void generateUniqueLocal(sockaddr_union& address, 158 | const bool highQualityRng = false) 159 | { 160 | uint8_t buffer[5]; 161 | if(address.sa.sa_family != AF_INET6) { 162 | std::cerr << gettext("ERROR: An IPv6 address must be given to generate a unique local address!") << "\n"; 163 | exit(1); 164 | } 165 | 166 | #if defined(__LINUX__) || defined(__linux__) || defined(__linux) || defined(__FreeBSD__) 167 | // ====== Read random number from random device ========================== 168 | const char* randomFile = (highQualityRng == true) ? "/dev/random" : "/dev/urandom"; 169 | FILE* fh = fopen(randomFile, "r"); 170 | if(fh != nullptr) { 171 | std::cout << format(gettext("Generating Unique Local IPv6 address (using %s) ..."), 172 | randomFile) << "\n"; 173 | 174 | if(fread((char*)&buffer, 5, 1, fh) != 1) { 175 | std::cerr << format(gettext("ERROR: Unable to read from %s!"), randomFile) << "\n"; 176 | exit(1); 177 | } 178 | fclose(fh); 179 | } 180 | else { 181 | std::cerr << format(gettext("ERROR: Unable to open %s!"), randomFile) << "\n"; 182 | exit(1); 183 | } 184 | #else 185 | // ====== Get random number using random() function ====================== 186 | #warning Using default random number generator on non-Linux system! 187 | srandom((unsigned int)getMicroTime()); 188 | for(size_t i = 0;i < sizeof(buffer);i++) { 189 | buffer[i] = (uint8_t)(random() % 0xff); 190 | } 191 | #endif 192 | 193 | // ====== Create IPv6 Unique Local address =============================== 194 | address.in6.sin6_addr.s6_addr[0] = 0xfd; 195 | memcpy((char*)&address.in6.sin6_addr.s6_addr[1], (const char*)&buffer, sizeof(buffer)); 196 | } 197 | 198 | 199 | // ###### Print IPv4 address in binary digits ############################### 200 | void printAddressBinary(std::ostream& os, 201 | const sockaddr_union& address, 202 | const unsigned int prefix, 203 | const bool colourMode = true, 204 | const char* indent = "") 205 | { 206 | if(address.sa.sa_family == AF_INET) { 207 | os << indent; 208 | uint32_t a = ntohl(getIPv4Address(address)); 209 | for(int i = 31;i >= 0;i--) { 210 | const uint32_t v = (uint32_t)1 << i; 211 | if(colourMode) { 212 | if(32 - i > (int)prefix) { // Colourize output 213 | os << "\x1b[33m"; 214 | } 215 | else { 216 | os << "\x1b[34m"; 217 | } 218 | } 219 | if(a >= v) { 220 | os << "1"; 221 | a -= v; 222 | } 223 | else { 224 | os << "0"; 225 | } 226 | if(colourMode) { 227 | os << "\x1b[0m"; // Turn off colour printing 228 | } 229 | if( ((i % 8) == 0) && (i > 0) ) { 230 | os << " . "; 231 | } 232 | } 233 | os << "\n"; 234 | } 235 | else { 236 | int p = 0; 237 | in6_addr ipv6Address = getIPv6Address(address); 238 | for(int j = 0;j < 8;j++) { 239 | uint16_t a = ntohs(ipv6Address.s6_addr16[j]); 240 | char str[16]; 241 | snprintf((char*)&str, sizeof(str), "%04x", a); 242 | os << indent << str << " = "; 243 | for(int i = 15;i >= 0;i--) { 244 | const uint32_t v = (uint32_t)1 << i; 245 | if(colourMode) { 246 | if(p < (int)prefix) { // Colourize output 247 | os << "\x1b[33m"; 248 | } 249 | else { 250 | os << "\x1b[34m"; 251 | } 252 | } 253 | if(a >= v) { 254 | os << "1"; 255 | a -= v; 256 | } 257 | else { 258 | os << "0"; 259 | } 260 | if(colourMode) { 261 | os << "\x1b[0m"; // Turn off colour printing 262 | } 263 | if( ((i % 8) == 0) && (i > 0) ) { 264 | os << " "; 265 | } 266 | p++; 267 | } 268 | os << "\n"; 269 | } 270 | } 271 | } 272 | 273 | 274 | // ###### Is given netmask valid? ########################################### 275 | int getPrefixLength(const sockaddr_union& netmask) 276 | { 277 | int prefixLength; 278 | bool belongsToNetwork = true; 279 | 280 | if(netmask.sa.sa_family == AF_INET) { 281 | prefixLength = 32; 282 | const uint32_t a = ntohl(getIPv4Address(netmask)); 283 | for(int i = 31;i >= 0;i--) { 284 | if(!(a & (1 << (uint32_t)i))) { 285 | belongsToNetwork = false; 286 | prefixLength--; 287 | } 288 | else { 289 | if(belongsToNetwork == false) { 290 | return -1; 291 | } 292 | } 293 | } 294 | } 295 | else { 296 | prefixLength = 128; 297 | for(int j = 0;j < 4;j++) { 298 | const uint32_t a = ntohl(getIPv6Address(netmask).s6_addr32[j]); 299 | for(int i = 31;i >= 0;i--) { 300 | if(!(a & (1 << (uint32_t)i))) { 301 | belongsToNetwork = false; 302 | prefixLength--; 303 | } 304 | else { 305 | if(belongsToNetwork == false) { 306 | return -1; 307 | } 308 | } 309 | } 310 | } 311 | } 312 | return prefixLength; 313 | } 314 | 315 | 316 | // ###### "&" operator for addresses ######################################## 317 | sockaddr_union operator&(const sockaddr_union& a1, const sockaddr_union& a2) 318 | { 319 | assert(a1.sa.sa_family == a2.sa.sa_family); 320 | 321 | sockaddr_union a = a1; 322 | if(a.sa.sa_family == AF_INET) { 323 | a.in.sin_addr.s_addr &= a2.in.sin_addr.s_addr; 324 | } 325 | else { 326 | for(int j = 0;j < 4;j++) { 327 | a.in6.sin6_addr.s6_addr32[j] &= a2.in6.sin6_addr.s6_addr32[j]; 328 | } 329 | } 330 | return a; 331 | } 332 | 333 | 334 | // ###### "|" operator for addresses ######################################## 335 | sockaddr_union operator|(const sockaddr_union& a1, const sockaddr_union& a2) 336 | { 337 | assert(a1.sa.sa_family == a2.sa.sa_family); 338 | 339 | sockaddr_union a = a1; 340 | if(a.sa.sa_family == AF_INET) { 341 | a.in.sin_addr.s_addr |= a2.in.sin_addr.s_addr; 342 | } 343 | else { 344 | for(int j = 0;j < 4;j++) { 345 | a.in6.sin6_addr.s6_addr32[j] |= a2.in6.sin6_addr.s6_addr32[j]; 346 | } 347 | } 348 | return a; 349 | } 350 | 351 | 352 | // ###### "~" operator for addresses ######################################## 353 | sockaddr_union operator~(const sockaddr_union& a1) 354 | { 355 | sockaddr_union a = a1; 356 | if(a.sa.sa_family == AF_INET) { 357 | a.in.sin_addr.s_addr = ~a1.in.sin_addr.s_addr; 358 | } 359 | else { 360 | for(int j = 0;j < 4;j++) { 361 | a.in6.sin6_addr.s6_addr32[j] = ~a1.in6.sin6_addr.s6_addr32[j]; 362 | } 363 | } 364 | return a; 365 | } 366 | 367 | 368 | // ###### Output operator for addresses ##################################### 369 | std::ostream& operator<<(std::ostream& os, const sockaddr_union& a) 370 | { 371 | printAddress(os, &a.sa, false, true); 372 | return os; 373 | } 374 | 375 | 376 | // ###### "+" operator for addresses ######################################## 377 | sockaddr_union operator+(const sockaddr_union& a1, uint32_t n) 378 | { 379 | sockaddr_union a = a1; 380 | if(a.sa.sa_family == AF_INET) { 381 | a.in.sin_addr.s_addr = htonl(ntohl(a.in.sin_addr.s_addr) + n); 382 | } 383 | else { 384 | for(int j = 3;j >= 0;j--) { 385 | const uint64_t sum = (uint64_t)ntohl(a.in6.sin6_addr.s6_addr32[j]) + (uint64_t)n; 386 | a.in6.sin6_addr.s6_addr32[j] = htonl((uint32_t)(sum & 0xffffffffULL)); 387 | n = (uint32_t)(sum >> 32); 388 | } 389 | } 390 | return a; 391 | } 392 | 393 | 394 | // ###### "-" operator for addresses ######################################## 395 | sockaddr_union operator-(const sockaddr_union& a1, uint32_t n) 396 | { 397 | sockaddr_union a = a1; 398 | if(a.sa.sa_family == AF_INET) { 399 | a.in.sin_addr.s_addr = htonl(ntohl(a.in.sin_addr.s_addr) - n); 400 | } 401 | else { 402 | for(int j = 3;j >= 0;j--) { 403 | const uint64_t sum = (uint64_t)ntohl(a.in6.sin6_addr.s6_addr32[j]) - (uint64_t)n; 404 | a.in6.sin6_addr.s6_addr32[j] = htonl((uint32_t)(sum & 0xffffffffULL)); 405 | n = (uint32_t)(sum >> 32); 406 | } 407 | } 408 | return a; 409 | } 410 | 411 | 412 | // ###### "==" operator for addresses ####################################### 413 | int operator==(const sockaddr_union& a1, const sockaddr_union& a2) 414 | { 415 | assert(a1.sa.sa_family == a2.sa.sa_family); 416 | 417 | if(a1.sa.sa_family == AF_INET) { 418 | return (a1.in.sin_addr.s_addr == a2.in.sin_addr.s_addr); 419 | } 420 | else { 421 | for(int j = 3;j >= 0;j--) { 422 | if(a1.in6.sin6_addr.s6_addr32[j] != a2.in6.sin6_addr.s6_addr32[j]) { 423 | return false; 424 | } 425 | } 426 | return true; 427 | } 428 | } 429 | 430 | 431 | // ###### Print IPv6 unicast properties of given address #################### 432 | void printUnicastProperties(std::ostream& os, 433 | const in6_addr& ipv6address, 434 | const bool colourMode = true, 435 | const bool hasSubnetID = true, 436 | const bool hasGlobalID = false) 437 | { 438 | // ====== Global ID ====================================================== 439 | if(hasGlobalID) { 440 | char globalIDString[16]; 441 | snprintf((char*)&globalIDString, sizeof(globalIDString), "%02x%04x%04x", 442 | ntohs(ipv6address.s6_addr16[0]) & 0xff, 443 | ntohs(ipv6address.s6_addr16[1]), 444 | ntohs(ipv6address.s6_addr16[2])); 445 | os << " + " << format(gettext("%-32s"), gettext("Global ID")) << " = " << globalIDString << "\n"; 446 | } 447 | 448 | // ====== Subnet ID ====================================================== 449 | if(hasSubnetID) { 450 | char subnetIDString[16]; 451 | const uint16_t subnetID = ntohs(ipv6address.s6_addr16[3]); 452 | snprintf((char*)&subnetIDString, sizeof(subnetIDString), "%04x", subnetID); 453 | os << " + " << format(gettext("%-32s"), gettext("Subnet ID")) << " = " << subnetIDString << "\n"; 454 | } 455 | 456 | // ====== Interface ID =================================================== 457 | char interfaceIDString[128]; 458 | const uint16_t interfaceID[4] = { ntohs(ipv6address.s6_addr16[4]), 459 | ntohs(ipv6address.s6_addr16[5]), 460 | ntohs(ipv6address.s6_addr16[6]), 461 | ntohs(ipv6address.s6_addr16[7]) }; 462 | snprintf((char*)&interfaceIDString, sizeof(interfaceIDString), 463 | ((colourMode == true) ? "\x1b[36m%04x:%02x\x1b[37m%02x:%02x\x1b[38m%02x:%04x\x1b[0m" : 464 | "%04x:%02x%02x:%02x%02x:%04x"), 465 | interfaceID[0], 466 | (interfaceID[1] & 0xff00) >> 8, (interfaceID[1] & 0x00ff), 467 | (interfaceID[2] & 0xff00) >> 8, (interfaceID[2] & 0x00ff), 468 | interfaceID[3]); 469 | os << " + " << format(gettext("%-32s"), gettext("Interface ID")) << " = " << interfaceIDString << "\n"; 470 | 471 | if( ((interfaceID[1] & 0x00ff) == 0x00ff) && 472 | ((interfaceID[2] & 0xff00) == 0xfe00) ) { 473 | snprintf((char*)&interfaceIDString, sizeof(interfaceIDString), 474 | ((colourMode == true) ? "\x1b[36m%02x:%02x:%02x\x1b[0m:\x1b[38m%02x:%02x:%02x\x1b[0m" : 475 | "%02x:%02x:%02x:%02x:%02x:%02x"), 476 | ipv6address.s6_addr[8] ^ 0x02, 477 | ipv6address.s6_addr[9], 478 | ipv6address.s6_addr[10], 479 | ipv6address.s6_addr[13], 480 | ipv6address.s6_addr[14], 481 | ipv6address.s6_addr[15]); 482 | os << " + " << format(gettext("%-32s"), gettext("MAC Address")) << " = " << interfaceIDString << "\n"; 483 | } 484 | 485 | // ====== Solicited Node Multicast Address =============================== 486 | char snmcAddressString[32]; 487 | snprintf((char*)&snmcAddressString, sizeof(snmcAddressString), 488 | ((colourMode == true) ? "\x1b[32mff02::1:ff\x1b[38m%02x:%04x\x1b[0m" : 489 | "ff02::1:ff%02x:%04x"), 490 | ntohs(ipv6address.s6_addr16[6]) & 0xff, 491 | ntohs(ipv6address.s6_addr16[7])); 492 | os << " + " << format(gettext("%-32s"), gettext("Solicited Node Multicast Address")) << " = " << snmcAddressString << "\n"; 493 | } 494 | 495 | 496 | // ###### Print address properties ########################################## 497 | void printAddressProperties(std::ostream& os, 498 | const sockaddr_union& address, 499 | const sockaddr_union& netmask, 500 | const unsigned int prefix, 501 | const sockaddr_union& network, 502 | const sockaddr_union& broadcast, 503 | const bool colourMode) 504 | { 505 | char addressString[64]; 506 | address2string(&address.sa, addressString, sizeof(addressString), false, false); 507 | 508 | // ====== Common properties ============================================== 509 | os << format(gettext("%-14s"), gettext("Properties")) << " = \n"; 510 | os << " - "; 511 | if(isMulticast(address)) { 512 | os << format(gettext("%s is a MULTICAST address"), addressString); 513 | } 514 | else if( (isIPv4(address)) && 515 | (prefix < 32) && 516 | (address == broadcast) ) { 517 | char networkString[64]; 518 | address2string(&network.sa, networkString, sizeof(networkString), false, false); 519 | os << format(gettext("%s is the BROADCAST address of %s/%u"), 520 | addressString, networkString, prefix); 521 | } 522 | else if( (address == network) && 523 | ( (isIPv4(address) && (prefix < 32)) || 524 | (!isIPv4(address) && (prefix < 128)) ) ) { 525 | os << format(gettext("%s is a NETWORK address"), addressString); 526 | } 527 | else { 528 | char networkString[64]; 529 | address2string(&network.sa, networkString, sizeof(networkString), false, false); 530 | os << format(gettext("%s is a HOST address in %s/%u"), 531 | addressString, networkString, prefix); 532 | } 533 | os << "\n"; 534 | 535 | 536 | // ====== IPv4 properties ================================================ 537 | if(isIPv4(address)) { 538 | const in_addr_t ipv4address = ntohl(getIPv4Address(address)); 539 | const unsigned int a = ipv4address >> 24; 540 | const unsigned int b = (ipv4address & 0x00ff0000) >> 16; 541 | 542 | if(IN_CLASSA(ipv4address)) { 543 | os << " - " << gettext("Class A") << "\n"; 544 | if(ipv4address == INADDR_LOOPBACK) { 545 | os << " - " << gettext("Loopback address") << "\n"; 546 | } 547 | else if(a == IN_LOOPBACKNET) { 548 | os << " - " << gettext("In loopback network") << "\n"; 549 | } 550 | else if(a == 10) { 551 | os << " - " << gettext("Private") << "\n"; 552 | } 553 | } 554 | else if(IN_CLASSB(ipv4address)) { 555 | os << " - " << gettext("Class B") << "\n"; 556 | if((a == 172) && ((b >= 16) && (b <= 31))) { 557 | os << " - " << gettext("Private") << "\n"; 558 | } 559 | else if((a == 169) && (b == 254)) { 560 | os << " - " << gettext("Link-local address") << "\n"; 561 | } 562 | } 563 | else if(IN_CLASSC(ipv4address)) { 564 | os << " - " << gettext("Class C") << "\n"; 565 | if((a == 192) && (b == 168)) { 566 | os << " - " << gettext("Private") << "\n"; 567 | } 568 | } 569 | else if(IN_CLASSD(ipv4address)) { 570 | os << " - " << gettext("Class D (Multicast)") << "\n"; 571 | // ------ Multicast scope ------------------------------------------ 572 | os << " + " << gettext("Scope: "); 573 | if(a == 224) { 574 | os << gettext("link-local"); 575 | } 576 | else if((a == 239) && (b >= 192) && (b <= 251)) { 577 | os << gettext("organization-local"); 578 | } 579 | else if((a == 239) && (b >= 252) && (b <= 255)) { 580 | os << gettext("site-local"); 581 | } 582 | else { 583 | os << gettext("global"); 584 | } 585 | os << "\n"; 586 | 587 | // ------ Corresponding MAC address -------------------------------- 588 | char macAddressString[32]; 589 | snprintf((char*)&macAddressString, sizeof(macAddressString), 590 | "01:00:5e:%02x:%02x:%02x", 591 | (ipv4address & 0x007f0000) >> 16, 592 | (ipv4address & 0x0000ff00) >> 8, 593 | (ipv4address & 0x000000ff)); 594 | os << " + " << format(gettext("Corresponding multicast MAC address: %s"), 595 | macAddressString) << "\n"; 596 | 597 | // ------ Source-specific multicast -------------------------------- 598 | if(a == 232) { 599 | os << " + " << gettext("Source-specific multicast") << "\n"; 600 | } 601 | } 602 | else { 603 | os << " - " << gettext("Invalid (not in class A, B, C or D)") << "\n"; 604 | } 605 | } 606 | 607 | 608 | // ====== IPv6 properties ================================================ 609 | else { 610 | const in6_addr ipv6address = getIPv6Address(address); 611 | const uint16_t a = ntohs(ipv6address.s6_addr16[0]); 612 | const uint16_t b = ntohs(ipv6address.s6_addr16[1]); 613 | 614 | // ------ Special addresses ------------------------------------------- 615 | if(IN6_IS_ADDR_LOOPBACK(&ipv6address)) { 616 | os << " - " << gettext("Loopback address") << "\n"; 617 | } 618 | else if(IN6_IS_ADDR_UNSPECIFIED(&ipv6address)) { 619 | os << " - " << gettext("Unspecified address") << "\n"; 620 | } 621 | else if(IN6_IS_ADDR_V4COMPAT(&ipv6address)) { 622 | os << " - " << gettext("IPv4-compatible IPv6 address") << "\n"; 623 | } 624 | else if(IN6_IS_ADDR_V4MAPPED(&ipv6address)) { 625 | os << " - " << gettext("IPv4-mapped IPv6 address") << "\n"; 626 | } 627 | else if(hasTranslationPrefix(&address.in6)) { 628 | os << " - " << gettext("IPv4-embedded IPv6 address") << "\n"; 629 | } 630 | 631 | // ------ Multicast addresses ----------------------------------------- 632 | else if(IN6_IS_ADDR_MULTICAST(&ipv6address)) { 633 | // ------ Multicast scope ------------------------------------------ 634 | os << " - " << gettext("Multicast Properties") << "\n"; 635 | os << " + " << gettext("Scope: "); 636 | if(IN6_IS_ADDR_MC_NODELOCAL(&ipv6address)) { 637 | os << gettext("node-local"); 638 | } 639 | else if(IN6_IS_ADDR_MC_LINKLOCAL(&ipv6address)) { 640 | os << gettext("link-local"); 641 | } 642 | else if(IN6_IS_ADDR_MC_SITELOCAL(&ipv6address)) { 643 | os << gettext("site-local"); 644 | } 645 | else if(IN6_IS_ADDR_MC_ORGLOCAL(&ipv6address)) { 646 | os << gettext("organization-local"); 647 | } 648 | else if(IN6_IS_ADDR_MC_GLOBAL(&ipv6address)) { 649 | os << gettext("global"); 650 | } 651 | else { 652 | os << gettext("unknown"); 653 | } 654 | os << "\n"; 655 | 656 | // ------ Multicast flags ------------------------------------------ 657 | const uint8_t flags = (((uint8_t*)&ipv6address)[1] & 0xf0) >> 4; 658 | if(flags == 0x1) { 659 | os << " + " << gettext("Temporary-allocated address") << "\n"; 660 | } 661 | 662 | // ------ Corresponding MAC address -------------------------------- 663 | char macAddressString[32]; 664 | snprintf((char*)&macAddressString, sizeof(macAddressString), 665 | "33:33:%02x:%02x:%02x:%02x", 666 | ipv6address.s6_addr[12], 667 | ipv6address.s6_addr[13], 668 | ipv6address.s6_addr[14], 669 | ipv6address.s6_addr[15]); 670 | os << " + " << gettext("Corresponding multicast MAC address: ") << macAddressString << "\n"; 671 | 672 | // ------ Source-specific multicast -------------------------------- 673 | if( ((a & 0xfff0) == 0xff30) && (b == 0x0000) ) { 674 | // FF0x:0::/32 675 | os << " + " << gettext("Source-specific multicast") << "\n"; 676 | } 677 | 678 | // ------ Solicited node multicast address ------------------------- 679 | // FF02::1:FF00:0/104 680 | if((a == 0xff02) && 681 | (ntohs(ipv6address.s6_addr16[5]) == 0x0001) && 682 | (ntohs(ipv6address.s6_addr16[6]) & 0xff00) == 0xff00) { 683 | char nodeAddressString[64]; 684 | snprintf((char*)&nodeAddressString, sizeof(nodeAddressString), 685 | "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx%02x:%04x", 686 | ntohs(ipv6address.s6_addr16[6]) & 0xff, 687 | ntohs(ipv6address.s6_addr16[7])); 688 | os << " + " << gettext("Address is solicited node multicast address for") 689 | << " " << nodeAddressString << "\n"; 690 | } 691 | } 692 | 693 | // ------ Link-local Unicast ------------------------------------------ 694 | else if(IN6_IS_ADDR_LINKLOCAL(&ipv6address)) { 695 | os << " - " << gettext("Link-Local Unicast Properties:") << "\n"; 696 | printUnicastProperties(std::cout, ipv6address, colourMode, false, false); 697 | } 698 | 699 | // ------ Site-Local Unicast ------------------------------------------ 700 | else if(IN6_IS_ADDR_SITELOCAL(&ipv6address)) { 701 | os << " - " << gettext("Site-Local Unicast Properties:") << "\n"; 702 | printUnicastProperties(std::cout, ipv6address, colourMode, true, false); 703 | } 704 | 705 | // ------ Unique Local Unicast ---------------------------------------- 706 | else if((a & 0xfc00) == 0xfc00) { 707 | os << " - " << gettext("Unique Local Unicast Properties:") << "\n"; 708 | if(a & 0x0100) { 709 | os << " + " << gettext("Locally chosen") << "\n"; 710 | } 711 | else { 712 | os << " + " << gettext("Assigned by global instance") << "\n"; 713 | } 714 | printUnicastProperties(std::cout, ipv6address, colourMode, true, true); 715 | } 716 | 717 | // ------ Global Unicast ---------------------------------------------- 718 | else if((a & 0xe000) == 0x2000) { 719 | os << " - " << gettext("Global Unicast Properties:") << "\n"; 720 | printUnicastProperties(std::cout, ipv6address, colourMode, false, false); 721 | 722 | // ------ 6to4 Address --------------------------------------------- 723 | if((a & 0x2002) == 0x2002) { 724 | sockaddr_union sixToFour; 725 | sixToFour.sa.sa_family = AF_INET; 726 | const uint32_t u = ntohs(((const uint16_t*)&ipv6address.s6_addr)[1]); 727 | const uint32_t l = ntohs(((const uint16_t*)&ipv6address.s6_addr)[2]); 728 | sixToFour.in.sin_addr.s_addr = htonl((u << 16) | l); 729 | os << " + " << format("%-32s = ", gettext("6-to-4 Address")); 730 | printAddress(std::cout, &sixToFour.sa, false); 731 | os << "\n"; 732 | } 733 | } 734 | } 735 | } 736 | 737 | 738 | #if defined(__SIZEOF_INT128__) 739 | // ###### Convert unsigned 128 bit integer to string ######################## 740 | std::string toString(unsigned __int128 num) { 741 | std::string str; 742 | do { 743 | const int digit = num % 10; 744 | str = std::to_string(digit) + str; 745 | num = (num - digit) / 10; 746 | } while(num != 0); 747 | return str; 748 | } 749 | #endif 750 | 751 | 752 | // ###### Main program ###################################################### 753 | int main(int argc, char** argv) 754 | { 755 | bool colourMode = true; 756 | bool noReverseLookup = false; 757 | int options; 758 | int prefix; 759 | unsigned int hostBits; 760 | unsigned int reservedHosts; 761 | #if defined(__SIZEOF_INT128__) 762 | unsigned __int128 maxHosts; 763 | #else 764 | // There is no 128-bit type on 32-bit systems! 765 | unsigned long long maxHosts; 766 | #endif 767 | sockaddr_union network; 768 | sockaddr_union address; 769 | sockaddr_union netmask; 770 | sockaddr_union broadcast; 771 | sockaddr_union wildcard; 772 | sockaddr_union host1; 773 | sockaddr_union host2; 774 | 775 | 776 | // ====== Initialise i18n support ======================================== 777 | if(setlocale(LC_ALL, "") == NULL) { 778 | setlocale(LC_ALL, "C.UTF-8"); // "C" should exist on all systems! 779 | } 780 | bindtextdomain("subnetcalc", NULL); 781 | textdomain("subnetcalc"); 782 | 783 | // ====== Print usage ==================================================== 784 | if(argc < 2) { 785 | std::cerr << gettext("Usage:") << " " 786 | << argv[0] 787 | << " [Address|AddressPrefix|AddressNetmask|Address/Prefix|Address/Netmask] [-n] [-uniquelocal|-uniquelocalhq] [-nocolour|-nocolor] [-v|-version]\n"; 788 | exit(1); 789 | } 790 | 791 | // ====== Show version =================================================== 792 | if((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "-version") == 0) ) { 793 | showVersion(); 794 | } 795 | 796 | // ====== Get address and netmask from one parameter ===================== 797 | char* slash = index(argv[1], '/'); 798 | if(slash) { 799 | slash[0] = 0x00; 800 | if(string2address(argv[1], &address) == false) { 801 | std::cerr << format(gettext("ERROR: Invalid address %s!"), argv[1]) << "\n"; 802 | exit(1); 803 | } 804 | if( readPrefix((const char*)&slash[1], address, netmask) < 0 ) { 805 | if(string2address((const char*)&slash[1], &netmask) == false) { 806 | std::cerr << format(gettext("ERROR: Invalid netmask %s!"), argv[1]) << "\n"; 807 | exit(1); 808 | } 809 | } 810 | options = 2; 811 | } 812 | 813 | // ====== Get address and netmask from separate parameters =============== 814 | else if(slash == nullptr) { 815 | if(string2address(argv[1], &address) == false) { 816 | std::cerr << format(gettext("ERROR: Invalid address %s!"), argv[1]) << "\n"; 817 | exit(1); 818 | } 819 | if(argc > 2) { 820 | options = 3; 821 | // ------ Get netmask or prefix ------------------------------------ 822 | if(argv[2][0] != '-') { 823 | if( readPrefix(argv[2], address, netmask) < 0 ) { 824 | if(string2address(argv[2], &netmask) == false) { 825 | std::cerr << format(gettext("ERROR: Invalid netmask %s!"), argv[2]) << "\n"; 826 | exit(1); 827 | } 828 | } 829 | } 830 | else { 831 | // ------ No netmask or prefix => use default for convenience --- 832 | options = 2; 833 | prefix = readPrefix((address.sa.sa_family == AF_INET) ? "32" : "128", address, netmask); 834 | assert(prefix >= 0); 835 | } 836 | } 837 | else { 838 | // ------ No netmask or prefix => use default for convenience ------ 839 | options = 2; 840 | prefix = readPrefix((address.sa.sa_family == AF_INET) ? "32" : "128", address, netmask); 841 | assert(prefix >= 0); 842 | } 843 | } 844 | 845 | 846 | // ====== Get prefix length ============================================== 847 | prefix = getPrefixLength(netmask); 848 | if(prefix < 0) { 849 | char addressString[64]; 850 | address2string(&netmask.sa, addressString, sizeof(addressString), false, false); 851 | std::cerr << format(gettext("ERROR: Invalid netmask %s!"), addressString) << "\n"; 852 | exit(1); 853 | } 854 | if(netmask.sa.sa_family != address.sa.sa_family) { 855 | char addressString[64]; 856 | address2string(&netmask.sa, addressString, sizeof(addressString), false, false); 857 | std::cerr << format(gettext("ERROR: Incompatible netmask %s!"), addressString) << "\n"; 858 | exit(1); 859 | } 860 | 861 | 862 | // ====== Handle optional parameters ===================================== 863 | for(int i = options;i < argc;i++) { 864 | if(strcmp(argv[i], "-uniquelocal") == 0) { 865 | generateUniqueLocal(address); 866 | } 867 | else if(strcmp(argv[i], "-uniquelocalhq") == 0) { 868 | generateUniqueLocal(address, true); 869 | } 870 | else if( (strcmp(argv[i], "-nocolour") == 0) || 871 | (strcmp(argv[i], "-nocolor") == 0) ) { 872 | colourMode = false; 873 | } 874 | else if(strcmp(argv[i], "-n") == 0) { 875 | noReverseLookup = true; 876 | } 877 | else if((strcmp(argv[i], "-v") == 0) || 878 | (strcmp(argv[i], "-version") == 0) ) { 879 | showVersion(); 880 | } 881 | else { 882 | std::cerr << format(gettext("ERROR: Invalid argument %s!"), argv[i]) << "\n"; 883 | exit(1); 884 | } 885 | } 886 | 887 | 888 | // ====== Calculate network address, hosts, etc. ========================= 889 | network = address & netmask; 890 | broadcast = network | (~netmask); 891 | wildcard = ~netmask; 892 | if(isIPv4(address)) { 893 | reservedHosts = 2; 894 | hostBits = 32 - prefix; 895 | host1 = network + 1; 896 | host2 = broadcast - 1; 897 | if(prefix >= 31) { // Special case for Point-to-Point links 898 | reservedHosts = 0; 899 | host1 = network; 900 | host2 = broadcast; 901 | } 902 | } 903 | else { 904 | reservedHosts = 1; 905 | hostBits = 128 - prefix; 906 | if(prefix < 128) { 907 | host1 = network + 1; 908 | host2 = broadcast; // There is no broadcast address for IPv6! 909 | } 910 | else { 911 | reservedHosts = 0; 912 | host1 = network; 913 | host2 = broadcast; // There is no broadcast address for IPv6! 914 | } 915 | } 916 | #if defined(__SIZEOF_INT128__) 917 | maxHosts = (unsigned __int128)pow(2.0, (double)hostBits) - reservedHosts; 918 | #else 919 | if(hostBits <= 64) { 920 | maxHosts = (unsigned long long)pow(2.0, (double)hostBits) - reservedHosts; 921 | } 922 | else { 923 | maxHosts = 0; // Not enough accuracy for such a large number! 924 | } 925 | #endif 926 | 927 | 928 | // ====== Print results ================================================== 929 | std::cout << format(gettext("%-14s"), gettext("Address")) << " = " 930 | << address << "\n"; 931 | printAddressBinary(std::cout, address, prefix, colourMode, 932 | (format(gettext("%-14s"), " ") + " ").c_str()); 933 | std::cout << format(gettext("%-14s"), gettext("Network")) << " = " 934 | << network << " / " << prefix << "\n" 935 | << format(gettext("%-14s"), gettext("Netmask")) << " = " 936 | << netmask << "\n"; 937 | if(isIPv4(address)) { 938 | std::cout << format(gettext("%-14s"), gettext("Broadcast")) << " = "; 939 | if(reservedHosts == 2) { 940 | std::cout << broadcast; 941 | } 942 | else { 943 | std::cout << gettext("not needed on Point-to-Point links"); 944 | } 945 | std::cout << "\n"; 946 | } 947 | std::cout << format(gettext("%-14s"), gettext("Wildcard Mask")) 948 | << " = " << wildcard << "\n"; 949 | if(isIPv4(address)) { 950 | char hex[16]; 951 | snprintf((char*)&hex, sizeof(hex), "%08X", ntohl(address.in.sin_addr.s_addr)); 952 | std::cout << format(gettext("%-14s"), gettext("Hex. Address")) 953 | << " = " << hex << "\n"; 954 | } 955 | std::cout << format(gettext("%-14s"), gettext("Hosts Bits")) << " = " 956 | << hostBits << "\n"; 957 | if(!isMulticast(address)) { 958 | char maxHostsString[128]; 959 | if(maxHosts > 0) { 960 | #if defined(__SIZEOF_INT128__) 961 | snprintf((char*)&maxHostsString, sizeof(maxHostsString), 962 | "%s (2^%u - %u)", toString(maxHosts).c_str(), hostBits, reservedHosts); 963 | #else 964 | snprintf((char*)&maxHostsString, sizeof(maxHostsString), 965 | "%llu (2^%u - %u)", maxHosts, hostBits, reservedHosts); 966 | #endif 967 | } 968 | else { 969 | snprintf((char*)&maxHostsString, sizeof(maxHostsString), 970 | "2^%u - %u", hostBits, reservedHosts); 971 | } 972 | std::cout << format(gettext("%-14s"), gettext("Max. Hosts")) << " = " 973 | << maxHostsString << "\n" 974 | << format(gettext("%-14s"), gettext("Host Range")) << " = { " 975 | << host1 << " - " << host2 << " }" << "\n"; 976 | } 977 | 978 | 979 | // ====== Properties ===================================================== 980 | printAddressProperties(std::cout, address, netmask, prefix, network, broadcast, colourMode); 981 | 982 | 983 | // ====== GeoIP ========================================================== 984 | #ifdef HAVE_GEOIP 985 | // libGeoIP prints an error message each time it cannot open a database. 986 | // Unfortunately, packaging of these databases is very confusing: some 987 | // distributions include some of them, etc.. Just avoid annoying the user 988 | // by printing these errors to /dev/null. The error condition of a 989 | // non-existing database is handled by subnetcalc anyway. 990 | if(freopen("/dev/null", "w", stderr) == nullptr) { } 991 | 992 | const char* country = nullptr; 993 | const char* code = nullptr; 994 | if(address.sa.sa_family == AF_INET) { 995 | GeoIP* geoIP = GeoIP_open_type(GEOIP_ASNUM_EDITION, GEOIP_STANDARD); 996 | if(geoIP) { 997 | const char* org = GeoIP_name_by_ipnum(geoIP, ntohl(address.in.sin_addr.s_addr)); 998 | std::cout << format("%-14s = ", gettext("GeoIP AS Info")) 999 | << ((org != nullptr) ? org : "Unknown") << "\n"; 1000 | GeoIP_delete(geoIP); 1001 | } 1002 | geoIP = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD); 1003 | if(geoIP) { 1004 | country = GeoIP_country_name_by_ipnum(geoIP, ntohl(address.in.sin_addr.s_addr)); 1005 | code = GeoIP_country_code_by_ipnum(geoIP, ntohl(address.in.sin_addr.s_addr)); 1006 | std::cout << format("%-14s = ", gettext("GeoIP Country")) 1007 | << ((country != nullptr) ? country: "Unknown") 1008 | << " (" << ((code != nullptr) ? code : "??") << ")" << "\n"; 1009 | GeoIP_delete(geoIP); 1010 | } 1011 | geoIP = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD); 1012 | if(geoIP) { 1013 | GeoIPRecord* gir = GeoIP_record_by_ipnum(geoIP, ntohl(address.in.sin_addr.s_addr)); 1014 | if(gir != nullptr) { 1015 | const char* timeZone = GeoIP_time_zone_by_country_and_region( 1016 | gir->country_code, gir->region); 1017 | std::cout << format("%-14s = ", gettext("GeoIP Region")) 1018 | << ((gir->postal_code != nullptr) ? gir->postal_code : "") 1019 | << ((gir->postal_code != nullptr) ? " " : "") 1020 | << ((gir->city != nullptr) ? gir->city : "Unknown") 1021 | << ", " << ((gir->region != nullptr) ? gir->region : "Unknown") 1022 | << " (" 1023 | << fabs(gir->latitude) << "°" << ((gir->latitude > 0) ? "N" : "S") << ", " 1024 | << fabs(gir->longitude) << "°" << ((gir->longitude > 0) ? "E" : "W") 1025 | << ((timeZone != nullptr) ? ", " : "") 1026 | << ((timeZone != nullptr) ? timeZone : "") 1027 | << ")" 1028 | << "\n"; 1029 | GeoIPRecord_delete(gir); 1030 | } 1031 | GeoIP_delete(geoIP); 1032 | } 1033 | } 1034 | #ifdef HAVE_GEOIP_IPV6 1035 | else if(address.sa.sa_family == AF_INET6) { 1036 | GeoIP* geoIP = GeoIP_open_type(GEOIP_ASNUM_EDITION_V6, GEOIP_STANDARD); 1037 | if(geoIP) { 1038 | const char* org = GeoIP_name_by_ipnum_v6(geoIP, address.in6.sin6_addr); 1039 | std::cout << format("%-14s = ", gettext("GeoIP AS Info")) 1040 | << ((org != nullptr) ? org : "Unknown") << "\n"; 1041 | GeoIP_delete(geoIP); 1042 | } 1043 | geoIP = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD); 1044 | if(geoIP) { 1045 | country = GeoIP_country_name_by_ipnum_v6(geoIP, address.in6.sin6_addr); 1046 | code = GeoIP_country_code_by_ipnum_v6(geoIP, address.in6.sin6_addr); 1047 | std::cout << format("%-14s = ", gettext("GeoIP Country")) 1048 | << ((country != nullptr) ? country: "Unknown") 1049 | << " (" << ((code != nullptr) ? code : "??") << ")" << "\n"; 1050 | GeoIP_delete(geoIP); 1051 | } 1052 | geoIP = GeoIP_open_type(GEOIP_CITY_EDITION_REV1_V6, GEOIP_STANDARD); 1053 | if(geoIP) { 1054 | GeoIPRecord* gir = GeoIP_record_by_ipnum_v6(geoIP, address.in6.sin6_addr); 1055 | if(gir != nullptr) { 1056 | const char* timeZone = GeoIP_time_zone_by_country_and_region( 1057 | gir->country_code, gir->region); 1058 | std::cout << format("%-14s = ", gettext("GeoIP Region")) 1059 | << ((gir->postal_code != nullptr) ? gir->postal_code : "") 1060 | << ((gir->postal_code != nullptr) ? " " : "") 1061 | << ((gir->city != nullptr) ? gir->city : "Unknown") 1062 | << ", " << ((gir->region != nullptr) ? gir->region : "Unknown") 1063 | << " (" 1064 | << fabs(gir->latitude) << "°" << ((gir->latitude > 0) ? "N" : "S") << ", " 1065 | << fabs(gir->longitude) << "°" << ((gir->longitude > 0) ? "E" : "W") 1066 | << ((timeZone != nullptr) ? ", " : "") 1067 | << ((timeZone != nullptr) ? timeZone : "") 1068 | << ")" 1069 | << "\n"; 1070 | GeoIPRecord_delete(gir); 1071 | } 1072 | GeoIP_delete(geoIP); 1073 | } 1074 | } 1075 | #else 1076 | #warning This used version of GeoIP does not yet support IPv6! 1077 | #endif 1078 | #endif 1079 | 1080 | 1081 | // ====== Reverse lookup ================================================= 1082 | if(noReverseLookup == false) { 1083 | std::cout << gettext("Performing reverse DNS lookup ..."); 1084 | std::cout.flush(); 1085 | char hostname[NI_MAXHOST]; 1086 | int error = getnameinfo(&address.sa, 1087 | (address.sa.sa_family == AF_INET6) ? 1088 | sizeof(sockaddr_in6) : sizeof(sockaddr_in), 1089 | (char*)&hostname, sizeof(hostname), 1090 | nullptr, 0, 1091 | #ifdef NI_IDN 1092 | NI_NAMEREQD|NI_IDN 1093 | #else 1094 | #warning No IDN support for getnameinfo()! 1095 | NI_NAMEREQD 1096 | #endif 1097 | ); 1098 | std::cout << "\r\x1b[K" 1099 | << format("%-14s = ", gettext("DNS Hostname")); 1100 | std::cout.flush(); 1101 | if(error == 0) { 1102 | std::cout << hostname << "\n"; 1103 | } 1104 | else { 1105 | std::cout << "(" << gai_strerror(error) << ")" << "\n"; 1106 | } 1107 | } 1108 | } 1109 | -------------------------------------------------------------------------------- /src/t1.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char** argv) 6 | { 7 | for(int i = 30;i <= 39;i++) { 8 | printf("\x1b[%dmThis is foreground colour #%d!\n", i, i); 9 | } 10 | printf("\x1b[0m"); 11 | for(int i = 40;i <= 49;i++) { 12 | printf("\x1b[%dmThis is background colour #%d!\n", i, i); 13 | } 14 | puts("\x1b[0m"); 15 | return(0); 16 | } 17 | -------------------------------------------------------------------------------- /src/test1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | 5 | 6 | TEST=valgrind 7 | 8 | make -j2 9 | 10 | $TEST ./subnetcalc 10.1.1.1 32 11 | $TEST ./subnetcalc 10.1.1.1 24 12 | $TEST ./subnetcalc 10.1.1.1 31 13 | $TEST ./subnetcalc 10.1.1.1 255.255.255.255 14 | 15 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 ffff:ffff:ffff:ffff:: 16 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 56 17 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 ffff:ffff:ffff:: 18 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 64 19 | 20 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 64 -uniquelocalhq 21 | $TEST ./subnetcalc fd01:1122:3344:affe:0102:03ff:fe04:0506 64 -uniquelocal 22 | 23 | $TEST ./subnetcalc ff02::1:ff11:2233 104 24 | $TEST ./subnetcalc ff3e:0::123:4 128 25 | 26 | $TEST ./subnetcalc 64:ff9b::1.2.3.4 96 -n 27 | $TEST ./subnetcalc 64:ff9b:1:2:3:4:5.6.7.8 96 -n 28 | 29 | $TEST ./subnetcalc www.heise.de 24 30 | -------------------------------------------------------------------------------- /src/tools.cc: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // ____ _ _ _ _ ____ _ 3 | // / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | // \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | // ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | // |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | // 8 | // --- IPv4/IPv6 Subnet Calculator --- 9 | // https://www.nntb.no/~dreibh/subnetcalc/ 10 | // ========================================================================== 11 | // 12 | // SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | // Copyright (C) 2024-2025 by Thomas Dreibholz 14 | // 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // 20 | // This program is distributed in the hope that it will be useful, 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | // GNU General Public License for more details. 24 | // 25 | // You should have received a copy of the GNU General Public License 26 | // along with this program. If not, see . 27 | // 28 | // Contact: thomas.dreibholz@gmail.com 29 | 30 | #include "tools.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | 56 | 57 | // ###### Get current time ################################################## 58 | unsigned long long getMicroTime() 59 | { 60 | struct timeval tv; 61 | gettimeofday(&tv, nullptr); 62 | return (((unsigned long long)tv.tv_sec * (unsigned long long)1000000) + 63 | (unsigned long long)tv.tv_usec); 64 | } 65 | 66 | 67 | // ###### Length-checking strcpy() ########################################## 68 | int safestrcpy(char* dest, const char* src, const size_t size) 69 | { 70 | assert(size > 0); 71 | strncpy(dest, src, size); 72 | dest[size - 1] = 0x00; 73 | return strlen(dest) < size; 74 | } 75 | 76 | 77 | // ###### Length-checking strcat() ########################################## 78 | int safestrcat(char* dest, const char* src, const size_t size) 79 | { 80 | const size_t l1 = strlen(dest); 81 | const size_t l2 = strlen(src); 82 | 83 | assert(size > 0); 84 | strncat(dest, src, size - l1 - 1); 85 | dest[size - 1] = 0x00; 86 | return (l1 + l2 < size); 87 | } 88 | 89 | 90 | // ###### Find first occurrence of character in string ####################### 91 | char* strindex(char* string, const char character) 92 | { 93 | if(string != nullptr) { 94 | while(*string != character) { 95 | if(*string == 0x00) { 96 | return nullptr; 97 | } 98 | string++; 99 | } 100 | return string; 101 | } 102 | return nullptr; 103 | } 104 | 105 | 106 | 107 | // ###### Find last occurrence of character in string ####################### 108 | char* strrindex(char* string, const char character) 109 | { 110 | const char* original = string; 111 | 112 | if(original != nullptr) { 113 | string = (char*)&string[strlen(string)]; 114 | while(*string != character) { 115 | if(string == original) { 116 | return nullptr; 117 | } 118 | string--; 119 | } 120 | return string; 121 | } 122 | return nullptr; 123 | } 124 | 125 | 126 | // ###### Check for support of IPv6 ######################################### 127 | bool checkIPv6() 128 | { 129 | int sd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 130 | if(sd >= 0) { 131 | close(sd); 132 | return true; 133 | } 134 | return false; 135 | } 136 | 137 | 138 | // ###### Does the given address have a translation prefix? ################# 139 | bool hasTranslationPrefix(const sockaddr_in6* address) 140 | { 141 | return (ntohs(address->sin6_addr.s6_addr16[0]) == 0x64 && 142 | ntohs(address->sin6_addr.s6_addr16[1]) == 0xff9b && 143 | ntohs(address->sin6_addr.s6_addr16[2]) <= 1); 144 | } 145 | 146 | 147 | // ###### Get socklen for given address ##################################### 148 | size_t getSocklen(const struct sockaddr* address) 149 | { 150 | switch(address->sa_family) { 151 | case AF_INET: 152 | return sizeof(struct sockaddr_in); 153 | break; 154 | case AF_INET6: 155 | return sizeof(struct sockaddr_in6); 156 | break; 157 | default: 158 | return sizeof(struct sockaddr); 159 | break; 160 | } 161 | } 162 | 163 | 164 | // ###### Format an IPv6-embedded IPv6 address ############################## 165 | inline bool formatEmbeddedAddress(const struct sockaddr_in6* ipv6address, 166 | char* str, 167 | const size_t maxlen) 168 | { 169 | struct in6_addr prefix = ipv6address->sin6_addr; 170 | 171 | // Set the suffix to a predictable value. 172 | prefix.s6_addr32[3] = 0xffffffff; 173 | if(inet_ntop(AF_INET6, &prefix, str, maxlen) == nullptr) { 174 | return false; 175 | } 176 | 177 | // Overwrite the predictable suffix with the IPv4 address. 178 | const size_t pl = strnlen(str, maxlen) - 9; 179 | const uint32_t upper = ntohs(ipv6address->sin6_addr.s6_addr16[6]); 180 | const uint32_t lower = ntohs(ipv6address->sin6_addr.s6_addr16[7]); 181 | 182 | const struct in_addr suffix = { .s_addr = htonl((upper << 16) | lower) }; 183 | return inet_ntop(AF_INET, &suffix, str + pl, maxlen - pl) != nullptr; 184 | } 185 | 186 | 187 | // ###### Format an IPv6 address ############################################ 188 | static inline bool formatIPv6Address(const struct sockaddr_in6* ipv6address, 189 | char* str, 190 | const size_t maxlen) 191 | { 192 | if(hasTranslationPrefix(ipv6address)) { 193 | return formatEmbeddedAddress(ipv6address, str, maxlen); 194 | } 195 | 196 | return (inet_ntop(AF_INET6, &ipv6address->sin6_addr, str, maxlen) != nullptr); 197 | } 198 | 199 | 200 | // ###### Convert address to string ######################################### 201 | bool address2string(const struct sockaddr* address, 202 | char* buffer, 203 | const size_t length, 204 | const bool port, 205 | const bool hideScope) 206 | { 207 | const struct sockaddr_in* ipv4address; 208 | const struct sockaddr_in6* ipv6address; 209 | char str[128]; 210 | char scope[IFNAMSIZ + 16]; 211 | char ifnamebuffer[IFNAMSIZ]; 212 | const char* ifname; 213 | 214 | switch(address->sa_family) { 215 | case AF_INET: 216 | ipv4address = (const struct sockaddr_in*)address; 217 | if(port) { 218 | snprintf(buffer, length, 219 | "%s:%d", inet_ntoa(ipv4address->sin_addr), ntohs(ipv4address->sin_port)); 220 | } 221 | else { 222 | snprintf(buffer, length, "%s", inet_ntoa(ipv4address->sin_addr)); 223 | } 224 | return true; 225 | break; 226 | case AF_INET6: 227 | ipv6address = (const struct sockaddr_in6*)address; 228 | if( (!hideScope) && 229 | (IN6_IS_ADDR_LINKLOCAL(&ipv6address->sin6_addr) || 230 | IN6_IS_ADDR_MC_LINKLOCAL(&ipv6address->sin6_addr)) ) { 231 | ifname = if_indextoname(ipv6address->sin6_scope_id, (char*)&ifnamebuffer); 232 | if(ifname == nullptr) { 233 | snprintf((char*)&scope, sizeof(scope), "%%%s", ifname); 234 | } 235 | else { 236 | scope[0] = 0x00; 237 | } 238 | } 239 | else { 240 | scope[0] = 0x00; 241 | } 242 | if(formatIPv6Address(ipv6address, str, sizeof(str))) { 243 | if(port) { 244 | snprintf(buffer, length, 245 | "[%s%s]:%d", str, scope, ntohs(ipv6address->sin6_port)); 246 | } 247 | else { 248 | snprintf(buffer, length, "%s%s", str, scope); 249 | } 250 | return true; 251 | } 252 | break; 253 | case AF_UNSPEC: 254 | safestrcpy(buffer, "(unspecified)", length); 255 | return true; 256 | break; 257 | } 258 | return false; 259 | } 260 | 261 | 262 | // ###### Convert string to address ######################################### 263 | bool string2address(const char* string, 264 | union sockaddr_union* address, 265 | const bool readPort) 266 | { 267 | char host[128]; 268 | char port[128]; 269 | struct sockaddr_in* ipv4address = (struct sockaddr_in*)address; 270 | struct sockaddr_in6* ipv6address = (struct sockaddr_in6*)address; 271 | int portNumber = 0; 272 | char* p1; 273 | 274 | struct addrinfo hints; 275 | struct addrinfo* res; 276 | bool isNumeric; 277 | bool isIPv6; 278 | size_t hostLength; 279 | size_t i; 280 | 281 | if(strlen(string) > sizeof(host)) { 282 | return false; 283 | } 284 | strcpy((char*)&host,string); 285 | strcpy((char*)&port, "0"); 286 | 287 | // ====== Handle RFC2732-compliant addresses ============================= 288 | if(string[0] == '[') { 289 | p1 = strindex(host,']'); 290 | if(p1 != nullptr) { 291 | if((p1[1] == ':') || (p1[1] == '!')) { 292 | strcpy((char*)&port, &p1[2]); 293 | } 294 | memmove((char*)&host, (char*)&host[1], (long)p1 - (long)host - 1); 295 | host[(long)p1 - (long)host - 1] = 0x00; 296 | } 297 | } 298 | 299 | // ====== Handle standard address:port =================================== 300 | else { 301 | if(readPort) { 302 | unsigned int colons = 0; 303 | for(size_t i = 0;i < strlen(host);i++) { 304 | if(host[i] == ':') { 305 | colons++; 306 | } 307 | } 308 | if(colons == 1) { 309 | p1 = strrindex(host,':'); 310 | if(p1 == nullptr) { 311 | p1 = strrindex(host,'!'); 312 | } 313 | if(p1 != nullptr) { 314 | p1[0] = 0x00; 315 | strcpy((char*)&port, &p1[1]); 316 | } 317 | } 318 | } 319 | } 320 | 321 | // ====== Check port number ============================================== 322 | portNumber = ~0; 323 | if((sscanf(port, "%d", &portNumber) != 1) || 324 | (portNumber < 0) || 325 | (portNumber > 65535)) { 326 | return false; 327 | } 328 | 329 | 330 | // ====== Create address structure ======================================= 331 | 332 | // ====== Get information for host ======================================= 333 | res = nullptr; 334 | isNumeric = true; 335 | isIPv6 = false; 336 | hostLength = strlen(host); 337 | 338 | memset((char*)&hints, 0, sizeof(hints)); 339 | hints.ai_socktype = SOCK_DGRAM; 340 | #ifdef AI_IDN 341 | hints.ai_flags = AI_IDN; 342 | #else 343 | #warning No IDN support for getaddrinfo()! 344 | hints.ai_flags = 0; 345 | #endif 346 | 347 | for(i = 0;i < hostLength;i++) { 348 | if(host[i] == ':') { 349 | isIPv6 = true; 350 | break; 351 | } 352 | } 353 | if(!isIPv6) { 354 | for(i = 0;i < hostLength;i++) { 355 | if(!(isdigit(host[i]) || (host[i] == '.'))) { 356 | isNumeric = false; 357 | break; 358 | } 359 | } 360 | } 361 | if(isNumeric) { 362 | hints.ai_flags |= AI_NUMERICHOST; 363 | } 364 | 365 | // First try IPv6 ... 366 | hints.ai_family = AF_INET6; 367 | if(getaddrinfo(host, nullptr, &hints, &res) != 0) { 368 | // ... then (if there is no AAAA record), try also IPv4 369 | hints.ai_family = AF_UNSPEC; 370 | if(getaddrinfo(host, nullptr, &hints, &res) != 0) { 371 | return false; 372 | } 373 | } 374 | 375 | memset((char*)address,0,sizeof(union sockaddr_union)); 376 | memcpy((char*)address,res->ai_addr,res->ai_addrlen); 377 | 378 | switch(ipv4address->sin_family) { 379 | case AF_INET: 380 | ipv4address->sin_port = htons(portNumber); 381 | #ifdef HAVE_SIN_LEN 382 | ipv4address->sin_len = sizeof(struct sockaddr_in); 383 | #endif 384 | break; 385 | case AF_INET6: 386 | ipv6address->sin6_port = htons(portNumber); 387 | #ifdef HAVE_SIN6_LEN 388 | ipv6address->sin6_len = sizeof(struct sockaddr_in6); 389 | #endif 390 | break; 391 | default: 392 | return false; 393 | break; 394 | } 395 | 396 | freeaddrinfo(res); 397 | return true; 398 | } 399 | 400 | 401 | // ###### Print address ##################################################### 402 | void printAddress(std::ostream& os, 403 | const struct sockaddr* address, 404 | const bool port, 405 | const bool hideScope) 406 | { 407 | static char str[128]; 408 | 409 | if(address2string(address, (char*)&str, sizeof(str), port, hideScope)) { 410 | os << str; 411 | } 412 | else { 413 | os << "(invalid!)"; 414 | } 415 | } 416 | 417 | 418 | // ###### Create formatted string (printf-like) ############################# 419 | std::string format(const char* fmt, ...) 420 | { 421 | char buffer[16384]; 422 | va_list va; 423 | va_start(va, fmt); 424 | vsnprintf(buffer, sizeof(buffer), fmt, va); 425 | va_end(va); 426 | return(std::string(buffer)); 427 | } 428 | -------------------------------------------------------------------------------- /src/tools.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // ____ _ _ _ _ ____ _ 3 | // / ___| _ _| |__ | \ | | ___| |_ / ___|__ _| | ___ 4 | // \___ \| | | | '_ \| \| |/ _ \ __| | / _` | |/ __| 5 | // ___) | |_| | |_) | |\ | __/ |_| |__| (_| | | (__ 6 | // |____/ \__,_|_.__/|_| \_|\___|\__|\____\__,_|_|\___| 7 | // 8 | // --- IPv4/IPv6 Subnet Calculator --- 9 | // https://www.nntb.no/~dreibh/subnetcalc/ 10 | // ========================================================================== 11 | // 12 | // SubNetCalc - IPv4/IPv6 Subnet Calculator 13 | // Copyright (C) 2024-2025 by Thomas Dreibholz 14 | // 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // 20 | // This program is distributed in the hope that it will be useful, 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | // GNU General Public License for more details. 24 | // 25 | // You should have received a copy of the GNU General Public License 26 | // along with this program. If not, see . 27 | // 28 | // Contact: thomas.dreibholz@gmail.com 29 | 30 | #ifndef TOOLS_H 31 | #define TOOLS_H 32 | 33 | #ifdef HAVE_CONFIG_H 34 | #include 35 | #endif 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include 49 | 50 | 51 | #ifdef __FreeBSD__ // FreeBSD 52 | #define s6_addr16 __u6_addr.__u6_addr16 53 | #define s6_addr32 __u6_addr.__u6_addr32 54 | #endif 55 | #ifdef __APPLE__ // MacOS X 56 | #define s6_addr16 __u6_addr.__u6_addr16 57 | #define s6_addr32 __u6_addr.__u6_addr32 58 | #endif 59 | #ifdef __sun // SunOS and Solaris 60 | #define s6_addr16 _S6_un._S6_u16 61 | #define s6_addr32 _S6_un._S6_u32 62 | #endif 63 | 64 | 65 | unsigned long long getMicroTime(); 66 | 67 | 68 | int safestrcpy(char* dest, const char* src, const size_t size); 69 | int safestrcat(char* dest, const char* src, const size_t size); 70 | char* strindex(char* string, const char character); 71 | char* strrindex(char* string, const char character); 72 | 73 | 74 | union sockaddr_union { 75 | struct sockaddr sa; 76 | struct sockaddr_in in; 77 | struct sockaddr_in6 in6; 78 | }; 79 | 80 | bool checkIPv6(); 81 | bool hasTranslationPrefix(const sockaddr_in6* address); 82 | size_t getSocklen(const struct sockaddr* address); 83 | bool address2string(const struct sockaddr* address, 84 | char* buffer, 85 | const size_t length, 86 | const bool port, 87 | const bool hideScope = false); 88 | bool string2address(const char* string, 89 | union sockaddr_union* address, 90 | const bool readPort = true); 91 | 92 | void printAddress(std::ostream& os, 93 | const struct sockaddr* address, 94 | const bool port = true, 95 | const bool hideScope = false); 96 | std::string format(const char* fmt, ...); 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /website.config: -------------------------------------------------------------------------------- 1 | WEBSITE_DIRECTORY=~/public_html/subnetcalc 2 | WEBSITE_PAGE=index.html 3 | --------------------------------------------------------------------------------