···3030 type = types.bool;
3131 default = false;
3232 description = ''
3333- Enable the stable grsecurity patch, based on Linux 3.2.
3333+ Enable the stable grsecurity patch, based on Linux 3.14.
3434 '';
3535 };
3636···3838 type = types.bool;
3939 default = false;
4040 description = ''
4141- Enable the testing grsecurity patch, based on Linux 3.13.
4141+ Enable the testing grsecurity patch, based on Linux 3.17.
4242 '';
4343 };
4444
···169169 hardware.firmware = mkOption {
170170 type = types.listOf types.path;
171171 default = [];
172172- example = [ "/root/my-firmware" ];
173172 description = ''
174173 List of directories containing firmware files. Such files
175174 will be loaded automatically if the kernel asks for them
···178177 firmware file with the same name, the first path in the list
179178 takes precedence. Note that you must rebuild your system if
180179 you add files to any of these directories. For quick testing,
181181- put firmware files in /root/test-firmware and add that
182182- directory to the list.
183183- Note that you can also add firmware packages to this
184184- list as these are directories in the nix store.
180180+ put firmware files in <filename>/root/test-firmware</filename>
181181+ and add that directory to the list. Note that you can also
182182+ add firmware packages to this list as these are directories in
183183+ the nix store.
185184 '';
186185 apply = list: pkgs.buildEnv {
187186 name = "firmware";
···244243 if [ ! -e /var/lib/udev/prev-systemd -o "$(readlink /var/lib/udev/prev-systemd)" != ${config.systemd.package} ]; then
245244 echo "regenerating udev hardware database..."
246245 ${config.systemd.package}/bin/udevadm hwdb --update && ln -sfn ${config.systemd.package} /var/lib/udev/prev-systemd
246246+ fi
247247+248248+ # Allow the kernel to find our firmware.
249249+ if [ -e /sys/module/firmware_class/parameters/path ]; then
250250+ echo -n "${config.hardware.firmware}" > /sys/module/firmware_class/parameters/path
247251 fi
248252 '';
249253
···187187 # Use ||, not &&, to avoid exiting from the if with $? = 1, which
188188 # would make configure fail if this is the last instruction.
189189 $ac_cs_success || as_fn_exit 1
190190+191191+diff --git a/src/Makefile b/src/Makefile
192192+index 1c4d104..fff2015 100644
193193+--- a/src/Makefile
194194++++ b/src/Makefile
195195+@@ -1298,7 +1298,7 @@ MACVIMGUI_SRC = gui.c gui_beval.c MacVim/gui_macvim.m MacVim/MMBackend.m \
196196+ MacVim/MacVim.m
197197+ MACVIMGUI_OBJ = objects/gui.o objects/gui_beval.o objects/pty.o \
198198+ objects/gui_macvim.o objects/MMBackend.o objects/MacVim.o
199199+-MACVIMGUI_DEFS = -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe
200200++MACVIMGUI_DEFS = -DMACOS_X_UNIX -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe
201201+ MACVIMGUI_IPATH =
202202+ MACVIMGUI_LIBS_DIR =
203203+ MACVIMGUI_LIBS1 = -framework Cocoa -framework Carbon
204204+205205+diff --git a/src/if_python.c b/src/if_python.c
206206+index b356bf7..b7bfa78 100644
207207+--- a/src/if_python.c
208208++++ b/src/if_python.c
209209+@@ -55,11 +55,7 @@
210210+211211+ #define PY_SSIZE_T_CLEAN
212212+213213+-#ifdef FEAT_GUI_MACVIM
214214+-# include <Python/Python.h>
215215+-#else
216216+-# include <Python.h>
217217+-#endif
218218++#include <Python.h>
219219+220220+ #if !defined(PY_VERSION_HEX) || PY_VERSION_HEX < 0x02050000
221221+ # undef PY_SSIZE_T_CLEAN
222222+ MACVIMGUI_LIBS1 = -framework Cocoa -framework Carbon
+9-11
pkgs/applications/editors/yi/yi-custom.nix
···99# ‘reload’ and similar functions should all work as long as the user
1010# doesn't need new libraries at which point they should add them to
1111# extraPackages and rebuild from the expression.
1212-{ cabal, yi, extraPackages, makeWrapper }:
1313-1212+{ cabal, yi, extraPackages, makeWrapper, ghcWithPackages }:
1313+let
1414+ w = ghcWithPackages (self: [ yi ] ++ extraPackages self);
1515+ wrappedGhc = w.override { ignoreCollisions = true; };
1616+in
1417cabal.mkDerivation (self: rec {
1518 pname = "yi-custom";
1619 version = "0.0.0.1";
1720 src = ./yi-custom-cabal;
1821 isLibrary = true;
1919- buildDepends = extraPackages ++ [ yi ];
2222+ buildDepends = [ yi ];
2023 buildTools = [ makeWrapper ];
2124 noHaddock = true;
2225 doCheck = false;
23262424- # Allows Yi to find the libraries it needs at runtime. We drop ‘:’
2525- # from this GHC_PACKAGE_PATH because we're wrapping over a different
2626- # wrapper that used --prefix: if we didn't, we end up with a
2727- # double-colon, confusing GHC.
2727+ # put custom GHC env in front which stops crap from being picked up
2828+ # from user database
2829 postInstall = ''
2929- makeWrapper ${yi}/bin/yi $out/bin/yi --set GHC_PACKAGE_PATH ''${GHC_PACKAGE_PATH%?}
3030+ makeWrapper ${yi}/bin/yi $out/bin/yi --prefix PATH : ${wrappedGhc}/bin
3031 '';
3131-3232 meta = {
3333 homepage = "http://haskell.org/haskellwiki/Yi";
3434 description = "Wrapper over user-specified Haskell libraries for use in Yi config";
3535 license = self.stdenv.lib.licenses.publicDomain;
3636 platforms = self.ghc.meta.platforms;
3737 maintainers = with self.stdenv.lib.maintainers; [ fuuzetsu ];
3838- # The wrapper does not yet work properly if we actually try to use it.
3939- broken = true;
4038 };
41394240})
···22index e78f231..6b6773b 100755
33--- a/src/etc/local_stage0.sh
44+++ b/src/etc/local_stage0.sh
55-@@ -53,8 +53,3 @@ if [ -z $TARG_DIR ]; then
55+@@ -53,11 +53,6 @@
66 fi
77-77+88 cp ${PREFIX}/bin/rustc${BIN_SUF} ${TARG_DIR}/stage0/bin/
99-cp ${PREFIX}/${LIB_DIR}/${RUSTLIBDIR}/${TARG_DIR}/${LIB_DIR}/* ${TARG_DIR}/stage0/${LIB_DIR}/
1010-cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}extra*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
1111-cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}rust*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
1212-cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}std*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
1313-cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}syntax*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
1414+1515+ # do not fail if one of the above fails, as all we need is a working rustc!
1616+ exit 0
···11{ stdenv, fetchurl }:
2233stdenv.mkDerivation rec {
44- name = "mtdev-1.1.2";
44+ name = "mtdev-1.1.5";
5566 src = fetchurl {
77 url = "http://bitmath.org/code/mtdev/${name}.tar.bz2";
88- sha256 = "0c2sfxxymf20ylvblgmdmybqs0cydmphg9fq6fnp6flbl0fd33b9";
88+ sha256 = "0zxs7shzgbalkvlaiibi25bd902rbmkv9n1lww6q8j3ri9qdaxv6";
99 };
10101111- meta = {
1111+ meta = with stdenv.lib; {
1212 homepage = http://bitmath.org/code/mtdev/;
1313-1413 description = "Multitouch Protocol Translation Library";
1515-1614 longDescription = ''
1715 The mtdev is a stand-alone library which transforms all variants of
1816 kernel MT events to the slotted type B protocol. The events put into
···2018 tracking, type A with contact tracking, or type B with contact tracking.
2119 See the kernel documentation for further details.
2220 '';
2323-2424- license = stdenv.lib.licenses.mit;
2121+ license = licenses.mit;
2222+ platforms = platforms.unix;
2323+ maintainers = with maintainers; [ wkennington ];
2524 };
2625}
+1-1
pkgs/development/libraries/pangomm/default.nix
···1818 meta = with stdenv.lib; {
1919 description = "C++ interface to the Pango text rendering library";
2020 homepage = http://www.pango.org/;
2121- # TODO license = with licenses; [ lgpl2 lgpl21 ];
2121+ license = with licenses; [ lgpl2 lgpl21 ];
2222 maintainers = with maintainers; [ lovek323 raskin ];
2323 platforms = platforms.unix;
2424
···11+From Ingo Hadan <ingo.hadan@sdm.de> Fri, 02 Apr 2010 21:08:50 +0200
22+From: Julien Moutinho <julm+tsocks@autogeree.net>
33+Date: Fri, 26 Apr 2013 01:57:26 +0200
44+Subject: tsocks fails if socksified application uses poll(2) (e.g. subversion-1.5)
55+66+---
77+diff --git a/tsocks.c b/tsocks.c
88+index 9cfdfff..470babd 100644
99+--- a/tsocks.c
1010++++ b/tsocks.c
1111+@@ -657,10 +657,11 @@ int poll(POLL_SIGNATURE) {
1212+ * be ready for writing), otherwise we'll just let the select loop
1313+ * come around again (since we can't flag it for read, we don't know
1414+ * if there is any data to be read and can't be bothered checking) */
1515+- if (conn->selectevents & WRITE) {
1616+- setevents |= POLLOUT;
1717++ if (conn->selectevents & POLLOUT) {
1818++ ufds[i].revents |= POLLOUT;
1919+ nevents++;
2020+ }
2121++ ufds[i].events = conn->selectevents;
2222+ }
2323+ }
2424+ } while (nevents == 0);
2525+2626+
···2020 --set GHC_PACKAGE_PATH "\$GHC_PACKAGE_PATH:" # always end with : to include base packages
2121 '';
22222323- meta = {
2424- description = ihaskell.meta.description;
2525- };
2626-}2323+ inherit (ihaskell) meta;
2424+}
···1515 homepage = http://lttng.org/;
1616 # liblttvtraceread (ltt/ directory) is distributed under the GNU LGPL v2.1.
1717 # The rest of the LTTV package is distributed under the GNU GPL v2.
1818- # TODO license = with licenses; [ gpl2 lgpl21 ];
1818+ license = with licenses; [ gpl2 lgpl21 ];
1919 platforms = platforms.linux;
2020 maintainers = [ maintainers.bjornfor ];
2121 };
···11-From f1b66ff83a0babbe99fef81b3a960d7a4ce8dbc6 Mon Sep 17 00:00:00 2001
22-From: vadimk <vadim4j@gmail.com>
33-Date: Sat, 30 Aug 2014 15:06:00 +0300
44-Subject: ip link: Remove unnecessary device checking
55-66-The real checking is performed later in iplink_modify(..) func which
77-checks device existence if NLM_F_CREATE flag is set.
88-99-Also it fixes the case when impossible to add veth link which was
1010-caused by 9a02651a87 (ip: check for missing dev arg when doing VF rate)
1111-because these devices are not exist yet.
1212-1313-Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
1414-Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
1515-Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
1616-1717-diff --git a/ip/iplink.c b/ip/iplink.c
1818-index 1a907d9..ea06871 100644
1919---- a/ip/iplink.c
2020-+++ b/ip/iplink.c
2121-@@ -593,8 +593,6 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
2222- duparg2("dev", *argv);
2323- *dev = *argv;
2424- dev_index = ll_name_to_index(*dev);
2525-- if (dev_index == 0)
2626-- invarg("Unknown device", *argv);
2727- }
2828- argc--; argv++;
2929- }
3030---
3131-cgit v0.10.1
3232-
+8-2
pkgs/os-specific/linux/kernel/common-config.nix
···332332 TRANSPARENT_HUGEPAGE_ALWAYS? n
333333 TRANSPARENT_HUGEPAGE_MADVISE? y
334334335335- # zram support (e.g for in-memory compressed swap)
335335+ # zram support (e.g for in-memory compressed swap).
336336 ${optionalString (versionAtLeast version "3.4") ''
337337 ZSMALLOC y
338338 ''}
339339 ZRAM m
340340-340340+341341 ${optionalString (versionAtLeast version "3.17") "NFC? n"}
342342+343343+ # Enable firmware loading via udev. Only needed for non-declarative
344344+ # firmware in /root/test-firmware.
345345+ ${optionalString (versionAtLeast version "3.17") ''
346346+ FW_LOADER_USER_HELPER_FALLBACK y
347347+ ''}
342348343349 ${kernelPlatform.kernelExtraConfig or ""}
344350 ${extraConfig}
···1818 CC = stdenv.cross.config + "-gcc";
1919 };
20202121+ # Too red
2222+ configureFlags = [ "--disable-modern-top" ];
2323+2124 meta = {
2225 homepage = http://sourceforge.net/projects/procps-ng/;
2326 description = "Utilities that give information about processes using the /proc filesystem";
···11-diff --git a/contrib/c/makekey.c b/contrib/c/makekey.c
22-new file mode 100644
33-index 0000000..c7184e5
44---- /dev/null
55-+++ b/contrib/c/makekey.c
66-@@ -0,0 +1,46 @@
77-+/* vim: set expandtab ts=4 sw=4: */
88-+/*
99-+ * You may redistribute this program and/or modify it under the terms of
1010-+ * the GNU General Public License as published by the Free Software Foundation,
1111-+ * either version 3 of the License, or (at your option) any later version.
1212-+ *
1313-+ * This program is distributed in the hope that it will be useful,
1414-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1515-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616-+ * GNU General Public License for more details.
1717-+ *
1818-+ * You should have received a copy of the GNU General Public License
1919-+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-+ */
2121-+#include "crypto/random/Random.h"
2222-+#include "memory/MallocAllocator.h"
2323-+#include "crypto/AddressCalc.h"
2424-+#include "util/AddrTools.h"
2525-+#include "util/Hex.h"
2626-+
2727-+#include "crypto_scalarmult_curve25519.h"
2828-+
2929-+#include <stdio.h>
3030-+
3131-+int main(int argc, char** argv)
3232-+{
3333-+ struct Allocator* alloc = MallocAllocator_new(1<<22);
3434-+ struct Random* rand = Random_new(alloc, NULL, NULL);
3535-+
3636-+ uint8_t privateKey[32];
3737-+ uint8_t publicKey[32];
3838-+ uint8_t ip[16];
3939-+ uint8_t hexPrivateKey[65];
4040-+
4141-+ for (;;) {
4242-+ Random_bytes(rand, privateKey, 32);
4343-+ crypto_scalarmult_curve25519_base(publicKey, privateKey);
4444-+ if (AddressCalc_addressForPublicKey(ip, publicKey)) {
4545-+ Hex_encode(hexPrivateKey, 65, privateKey, 32);
4646-+ printf(hexPrivateKey);
4747-+ return 0;
4848-+ }
4949-+ }
5050-+ return 0;
5151-+}
5252-+
5353-diff --git a/node_build/make.js b/node_build/make.js
5454-index 5e51645..11465e3 100644
5555---- a/node_build/make.js
5656-+++ b/node_build/make.js
5757-@@ -339,6 +339,7 @@ Builder.configure({
5858- builder.buildExecutable('contrib/c/privatetopublic.c');
5959- builder.buildExecutable('contrib/c/sybilsim.c');
6060- builder.buildExecutable('contrib/c/makekeys.c');
6161-+ builder.buildExecutable('contrib/c/makekey.c');
6262-6363- builder.buildExecutable('crypto/random/randombytes.c');
6464-
+286
pkgs/tools/networking/cjdns/rfc5952.patch
···11+diff --git a/admin/angel/cjdroute2.c b/admin/angel/cjdroute2.c
22+index dfce6c6..77954a7 100644
33+--- a/admin/angel/cjdroute2.c
44++++ b/admin/angel/cjdroute2.c
55+@@ -80,7 +80,7 @@ static int genAddress(uint8_t addressOut[40],
66+ if (AddressCalc_addressForPublicKey(address.ip6.bytes, address.key)) {
77+ Hex_encode(privateKeyHexOut, 65, privateKey, 32);
88+ Base32_encode(publicKeyBase32Out, 53, address.key, 32);
99+- Address_printIp(addressOut, &address);
1010++ Address_printShortIp(addressOut, &address);
1111+ return 0;
1212+ }
1313+ }
1414+diff --git a/contrib/c/makekeys.c b/contrib/c/makekeys.c
1515+index 3727fff..29582f1 100644
1616+--- a/contrib/c/makekeys.c
1717++++ b/contrib/c/makekeys.c
1818+@@ -41,7 +41,7 @@ int main(int argc, char** argv)
1919+ if (AddressCalc_addressForPublicKey(ip, publicKey)) {
2020+ Hex_encode(hexPrivateKey, 65, privateKey, 32);
2121+ Base32_encode(publicKeyBase32, 53, publicKey, 32);
2222+- AddrTools_printIp(printedIp, ip);
2323++ AddrTools_printShortIp(printedIp, ip);
2424+ printf("%s %s %s.k\n", hexPrivateKey, printedIp, publicKeyBase32);
2525+ }
2626+ }
2727+diff --git a/contrib/c/privatetopublic.c b/contrib/c/privatetopublic.c
2828+index 7f5f967..dc98f1c 100644
2929+--- a/contrib/c/privatetopublic.c
3030++++ b/contrib/c/privatetopublic.c
3131+@@ -73,7 +73,7 @@ int main(int argc, char** argv)
3232+ AddressCalc_addressForPublicKey(address.ip6.bytes, address.key);
3333+ if (address.ip6.bytes[0] == 0xFC) {
3434+ Base32_encode(publicKeyBase32Out, 53, address.key, 32);
3535+- Address_printIp(addressOut, &address);
3636++ Address_printShortIp(addressOut, &address);
3737+ printf( "Input privkey: %s\n"
3838+ "Matching pubkey: %s.k\n"
3939+ "Resulting address: %s\n"
4040+diff --git a/contrib/c/publictoip6.c b/contrib/c/publictoip6.c
4141+index fc92f7e..99afc4c 100644
4242+--- a/contrib/c/publictoip6.c
4343++++ b/contrib/c/publictoip6.c
4444+@@ -48,7 +48,7 @@ int main(int argc, char** argv)
4545+ }
4646+4747+ uint8_t output[40] = {0};
4848+- AddrTools_printIp(output, ip6Bytes);
4949++ AddrTools_printShortIp(output, ip6Bytes);
5050+ printf("%s\n", output);
5151+ return 0;
5252+ }
5353+diff --git a/dht/Address.c b/dht/Address.c
5454+index e4c2dba..ba77cad 100644
5555+--- a/dht/Address.c
5656++++ b/dht/Address.c
5757+@@ -102,6 +102,12 @@ void Address_printIp(uint8_t output[40], struct Address* addr)
5858+ AddrTools_printIp(output, addr->ip6.bytes);
5959+ }
6060+6161++void Address_printShortIp(uint8_t output[40], struct Address* addr)
6262++{
6363++ Address_getPrefix(addr);
6464++ AddrTools_printShortIp(output, addr->ip6.bytes);
6565++}
6666++
6767+ void Address_print(uint8_t output[60], struct Address* addr)
6868+ {
6969+ Address_printIp(output, addr);
7070+diff --git a/dht/Address.h b/dht/Address.h
7171+index 43c6f05..f200b40 100644
7272+--- a/dht/Address.h
7373++++ b/dht/Address.h
7474+@@ -94,6 +94,8 @@ void Address_forKey(struct Address* out, const uint8_t key[Address_KEY_SIZE]);
7575+7676+ void Address_printIp(uint8_t output[40], struct Address* addr);
7777+7878++void Address_printShortIp(uint8_t output[40], struct Address* addr);
7979++
8080+ void Address_print(uint8_t output[60], struct Address* addr);
8181+8282+ String* Address_toString(struct Address* addr, struct Allocator* alloc);
8383+diff --git a/net/Ducttape.c b/net/Ducttape.c
8484+index 84597d0..1813f3f 100644
8585+--- a/net/Ducttape.c
8686++++ b/net/Ducttape.c
8787+@@ -227,7 +227,7 @@ static inline bool isRouterTraffic(struct Message* message, struct Headers_IP6He
8888+ #define debugHandles(logger, session, message, ...) \
8989+ do { \
9090+ uint8_t ip[40]; \
9191+- AddrTools_printIp(ip, session->ip6); \
9292++ AddrTools_printIp(ip, session->ip6); \
9393+ Log_debug(logger, "ver[%u] send[%d] recv[%u] ip[%s] " message, \
9494+ session->version, \
9595+ Endian_hostToBigEndian32(session->sendHandle_be), \
9696+@@ -271,10 +271,10 @@ static inline uint8_t incomingForMe(struct Message* message,
9797+ if (Bits_memcmp(addr.ip6.bytes, dtHeader->ip6Header->sourceAddr, 16)) {
9898+ #ifdef Log_DEBUG
9999+ uint8_t keyAddr[40];
100100+- Address_printIp(keyAddr, &addr);
101101++ Address_printShortIp(keyAddr, &addr);
102102+ Bits_memcpyConst(addr.ip6.bytes, dtHeader->ip6Header->sourceAddr, 16);
103103+ uint8_t srcAddr[40];
104104+- Address_printIp(srcAddr, &addr);
105105++ Address_printShortIp(srcAddr, &addr);
106106+ Log_debug(context->logger,
107107+ "DROP packet because source address is not same as key.\n"
108108+ " %s source addr\n"
109109+@@ -292,7 +292,7 @@ static inline uint8_t incomingForMe(struct Message* message,
110110+ if (Checksum_udpIp6(dtHeader->ip6Header->sourceAddr, (uint8_t*)uh, message->length)) {
111111+ #ifdef Log_DEBUG
112112+ uint8_t keyAddr[40];
113113+- Address_printIp(keyAddr, &addr);
114114++ Address_printShortIp(keyAddr, &addr);
115115+ Log_debug(context->logger,
116116+ "DROP Router packet with incorrect checksum, from [%s]", keyAddr);
117117+ #endif
118118+@@ -708,7 +708,7 @@ static inline int core(struct Message* message,
119119+ struct Address destination;
120120+ Bits_memcpyConst(destination.ip6.bytes, ip6Header->destinationAddr, 16);
121121+ uint8_t ipAddr[40];
122122+- Address_printIp(ipAddr, &destination);
123123++ Address_printShortIp(ipAddr, &destination);
124124+ Log_debug(context->logger, "Forwarding data to %s via %s\n", ipAddr, nhAddr);
125125+ #endif */
126126+ } else {
127127+@@ -723,7 +723,7 @@ static inline int core(struct Message* message,
128128+ struct Address destination;
129129+ Bits_memcpyConst(destination.ip6.bytes, ip6Header->destinationAddr, 16);
130130+ uint8_t ipAddr[40];
131131+- Address_printIp(ipAddr, &destination);
132132++ Address_printShortIp(ipAddr, &destination);
133133+ Log_info(context->logger, "DROP message because this node is the closest known "
134134+ "node to the destination %s.", ipAddr);
135135+ #endif
136136+diff --git a/test/printIp_test.c b/test/printIp_test.c
137137+new file mode 100644
138138+index 0000000..75d7427
139139+--- /dev/null
140140++++ b/test/printIp_test.c
141141+@@ -0,0 +1,54 @@
142142++/* vim: set expandtab ts=4 sw=4: */
143143++/*
144144++ * You may redistribute this program and/or modify it under the terms of
145145++ * the GNU General Public License as published by the Free Software Foundation,
146146++ * either version 3 of the License, or (at your option) any later version.
147147++ *
148148++ * This program is distributed in the hope that it will be useful,
149149++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
150150++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151151++ * GNU General Public License for more details.
152152++ *
153153++ * You should have received a copy of the GNU General Public License
154154++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
155155++ */
156156++
157157++#include "crypto/random/Random.h"
158158++#include "memory/MallocAllocator.h"
159159++#include "util/AddrTools.h"
160160++#include "util/Assert.h"
161161++
162162++#include <stdio.h>
163163++
164164++int main()
165165++{
166166++ struct Allocator* alloc = MallocAllocator_new(1<<22);
167167++ struct Random* rand = Random_new(alloc, NULL, NULL);
168168++
169169++ uint8_t ip[16];
170170++ uint8_t printedIp[40];
171171++ uint8_t printedShortIp[40];
172172++ uint8_t ipFromFull[16];
173173++ uint8_t ipFromShort[16];
174174++
175175++ for (int i = 0; i < 1024; ++i) {
176176++ Random_bytes(rand, ip, 16);
177177++
178178++ for (int j = 0; j < 16; j++) {
179179++ // make the random result have lots of zeros since that's what we're looking for.
180180++ ip[j] = (ip[j] % 2) ? 0 : ip[j];
181181++ }
182182++
183183++ AddrTools_printIp(printedIp, ip);
184184++ AddrTools_printShortIp(printedShortIp, ip);
185185++ //printf("%s\n%s\n\n", printedIp, printedShortIp);
186186++
187187++ AddrTools_parseIp(ipFromFull, printedIp);
188188++ AddrTools_parseIp(ipFromShort, printedShortIp);
189189++
190190++ Assert_true(0 == Bits_memcmp(ip, ipFromFull, 16));
191191++ Assert_true(0 == Bits_memcmp(ipFromFull, ipFromShort, 16));
192192++ }
193193++
194194++ return 0;
195195++}
196196+diff --git a/util/AddrTools.h b/util/AddrTools.h
197197+index 858ced4..d59544d 100644
198198+--- a/util/AddrTools.h
199199++++ b/util/AddrTools.h
200200+@@ -143,6 +143,44 @@ static inline void AddrTools_printIp(uint8_t output[40], const uint8_t binIp[16]
201201+ output[39] = '\0';
202202+ }
203203+204204++static inline void AddrTools_printShortIp(uint8_t output[40], const uint8_t binIp[16])
205205++{
206206++ /* The chances of hitting :0:0: and breaking
207207++ * RFC5952 are 1 in (1 / (2^16))^2 * 6.
208208++ * E. Siler
209209++ */
210210++
211211++ char *p = output;
212212++ int i = 0;
213213++ for (; i < 16;) {
214214++ if ((size_t)p != (size_t)output) {
215215++ *p++= ':';
216216++ }
217217++
218218++ if (binIp[i] > 0x0F) {
219219++ Hex_encode(p, 2, &binIp[i++], 1);
220220++ p += 2;
221221++ } else if (binIp[i] > 0x00) {
222222++ *p++ = Hex_encodeLowNibble(binIp[i++]);
223223++ } else {
224224++ ++i;
225225++ if (binIp[i] > 0x0F) {
226226++ Hex_encode(p, 2, &binIp[i++], 1);
227227++ p += 2;
228228++ } else {
229229++ *p++ = Hex_encodeLowNibble(binIp[i++]);
230230++ }
231231++ continue;
232232++ }
233233++ Hex_encode(p, 2, &binIp[i++], 1);
234234++ p += 2;
235235++ }
236236++ *p = '\0';
237237++
238238++ Assert_true((size_t)p <= ((size_t)output + 40));
239239++ Assert_true(i <= 16);
240240++}
241241++
242242+ /**
243243+ * Parse out an address.
244244+ *
245245+diff --git a/util/Hex.c b/util/Hex.c
246246+index e3e3c4d..b9bce57 100644
247247+--- a/util/Hex.c
248248++++ b/util/Hex.c
249249+@@ -29,6 +29,8 @@ static const uint8_t numForAscii[] =
250250+ 99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
251251+ };
252252+253253++static const char* hexEntities = "0123456789abcdef";
254254++
255255+ int Hex_encode(uint8_t* output,
256256+ const uint32_t outputLength,
257257+ const uint8_t* in,
258258+@@ -40,8 +42,6 @@ int Hex_encode(uint8_t* output,
259259+ output[inputLength * 2] = '\0';
260260+ }
261261+262262+- static const char* hexEntities = "0123456789abcdef";
263263+-
264264+ for (uint32_t i = 0; i < inputLength; i++) {
265265+ output[i * 2] = hexEntities[in[i] >> 4];
266266+ output[i * 2 + 1] = hexEntities[in[i] & 15];
267267+@@ -88,3 +88,8 @@ int Hex_decode(uint8_t* output,
268268+269269+ return length / 2;
270270+ }
271271++
272272++uint8_t Hex_encodeLowNibble(const uint8_t nibble)
273273++{
274274++ return hexEntities[nibble & 15];
275275++}
276276+diff --git a/util/Hex.h b/util/Hex.h
277277+index 4570c3e..a12e402 100644
278278+--- a/util/Hex.h
279279++++ b/util/Hex.h
280280+@@ -41,4 +41,6 @@ bool Hex_isHexEntity(const uint8_t character);
281281+282282+ int Hex_decodeByte(const uint8_t highNibble, const uint8_t lowNibble);
283283+284284++uint8_t Hex_encodeLowNibble(const uint8_t nibble);
285285++
286286+ #endif