commit 369181658b5b196e3608236482fb43bcc7e78534
parent ea442478979c4becf1815b8401dad4cb221989e2
Author: cnlohr <charles@cnlohr.com>
Date: Sat, 6 Dec 2014 01:54:03 -0500
add some files to cnpingo
Diffstat:
A | DrawFunctions.c | | | 273 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | DrawFunctions.h | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | LICENSE | | | 40 | ++++++++++++++++++++-------------------- |
A | Makefile | | | 21 | +++++++++++++++++++++ |
A | WinDriver.c | | | 226 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | XDriver.c | | | 259 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | cnping.c | | | 260 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | os_generic.c | | | 335 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | os_generic.h | | | 76 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | ping.c | | | 216 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | ping.h | | | 24 | ++++++++++++++++++++++++ |
A | searchnet.c | | | 94 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 files changed, 1858 insertions(+), 20 deletions(-)
diff --git a/DrawFunctions.c b/DrawFunctions.c
@@ -0,0 +1,273 @@
+/*
+Copyright (c) 2010, 2011 Charles Lohr
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "DrawFunctions.h"
+#include <stdio.h>
+
+int CNFGPenX, CNFGPenY;
+uint32_t CNFGBGColor;
+uint32_t CNFGLastColor;
+uint32_t CNFGDialogColor; //background for boxes
+
+const unsigned short FontCharMap[256] = {
+ 65535, 0, 10, 20, 32, 44, 56, 68, 70, 65535, 65535, 80, 92, 65535, 104, 114,
+ 126, 132, 138, 148, 156, 166, 180, 188, 200, 206, 212, 218, 224, 228, 238, 244,
+ 65535, 250, 254, 258, 266, 278, 288, 302, 304, 310, 316, 324, 328, 226, 252, 330,
+ 332, 342, 348, 358, 366, 372, 382, 392, 400, 410, 420, 424, 428, 262, 432, 436,
+ 446, 460, 470, 486, 496, 508, 516, 522, 536, 542, 548, 556, 568, 572, 580, 586,
+ 598, 608, 622, 634, 644, 648, 654, 662, 670, 682, 692, 700, 706, 708, 492, 198,
+ 714, 716, 726, 734, 742, 750, 760, 768, 782, 790, 794, 802, 204, 810, 820, 384,
+ 828, 836, 844, 850, 860, 864, 872, 880, 890, 894, 902, 908, 916, 920, 928, 934,
+ 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535,
+ 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535,
+ 944, 948, 960, 970, 986, 996, 1000, 1016, 1020, 1026, 1034, 1042, 364, 1046, 1056, 1058,
+ 1066, 1072, 1080, 932, 1092, 1100, 68, 1110, 1114, 1116, 1124, 1132, 1142, 1154, 1170, 1180,
+ 1192, 1204, 1218, 1234, 1248, 1264, 1276, 1290, 1300, 1310, 1322, 1334, 1342, 1350, 1360, 1370,
+ 1384, 1396, 1406, 1416, 1428, 1442, 1454, 1458, 1472, 1480, 1488, 1498, 1508, 1520, 1530, 1544,
+ 1556, 1568, 1582, 1598, 1612, 1628, 1642, 1654, 1666, 1678, 1692, 1706, 1710, 1714, 1720, 1726,
+ 1738, 1752, 1762, 1772, 1784, 1798, 1810, 1816, 1826, 1836, 1846, 1858, 1870, 1880, 1890, 65535, };
+
+const unsigned char FontCharData[1902] = {
+ 0x00, 0x01, 0x20, 0x21, 0x03, 0x23, 0x23, 0x14, 0x14, 0x83, 0x00, 0x01, 0x20, 0x21, 0x04, 0x24,
+ 0x24, 0x13, 0x13, 0x84, 0x01, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x11, 0x92,
+ 0x11, 0x22, 0x22, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x02, 0x02, 0x91, 0x01, 0x21, 0x21, 0x23,
+ 0x23, 0x01, 0x03, 0x21, 0x03, 0x01, 0x12, 0x94, 0x03, 0x23, 0x13, 0x14, 0x23, 0x22, 0x22, 0x11,
+ 0x11, 0x02, 0x02, 0x83, 0x12, 0x92, 0x12, 0x12, 0x01, 0x21, 0x21, 0x23, 0x23, 0x03, 0x03, 0x81,
+ 0x03, 0x21, 0x21, 0x22, 0x21, 0x11, 0x03, 0x14, 0x14, 0x23, 0x23, 0x92, 0x01, 0x10, 0x10, 0x21,
+ 0x21, 0x12, 0x12, 0x01, 0x12, 0x14, 0x03, 0xa3, 0x02, 0x03, 0x03, 0x13, 0x02, 0x12, 0x13, 0x10,
+ 0x10, 0xa1, 0x01, 0x23, 0x03, 0x21, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x82, 0x00, 0x22,
+ 0x22, 0x04, 0x04, 0x80, 0x20, 0x02, 0x02, 0x24, 0x24, 0xa0, 0x01, 0x10, 0x10, 0x21, 0x10, 0x14,
+ 0x14, 0x03, 0x14, 0xa3, 0x00, 0x03, 0x04, 0x04, 0x20, 0x23, 0x24, 0xa4, 0x00, 0x20, 0x00, 0x02,
+ 0x02, 0x22, 0x10, 0x14, 0x20, 0xa4, 0x01, 0x21, 0x21, 0x23, 0x23, 0x03, 0x03, 0x01, 0x20, 0x10,
+ 0x10, 0x14, 0x14, 0x84, 0x03, 0x23, 0x23, 0x24, 0x24, 0x04, 0x04, 0x83, 0x01, 0x10, 0x10, 0x21,
+ 0x10, 0x14, 0x14, 0x03, 0x14, 0x23, 0x04, 0xa4, 0x01, 0x10, 0x21, 0x10, 0x10, 0x94, 0x03, 0x14,
+ 0x23, 0x14, 0x10, 0x94, 0x02, 0x22, 0x22, 0x11, 0x22, 0x93, 0x02, 0x22, 0x02, 0x11, 0x02, 0x93,
+ 0x01, 0x02, 0x02, 0xa2, 0x02, 0x22, 0x22, 0x11, 0x11, 0x02, 0x02, 0x13, 0x13, 0xa2, 0x11, 0x22,
+ 0x22, 0x02, 0x02, 0x91, 0x02, 0x13, 0x13, 0x22, 0x22, 0x82, 0x10, 0x13, 0x14, 0x94, 0x10, 0x01,
+ 0x20, 0x91, 0x10, 0x14, 0x20, 0x24, 0x01, 0x21, 0x03, 0xa3, 0x21, 0x10, 0x10, 0x01, 0x01, 0x23,
+ 0x23, 0x14, 0x14, 0x03, 0x10, 0x94, 0x00, 0x01, 0x23, 0x24, 0x04, 0x03, 0x03, 0x21, 0x21, 0xa0,
+ 0x21, 0x10, 0x10, 0x01, 0x01, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0x23, 0x02, 0xa4, 0x10, 0x91,
+ 0x10, 0x01, 0x01, 0x03, 0x03, 0x94, 0x10, 0x21, 0x21, 0x23, 0x23, 0x94, 0x01, 0x23, 0x11, 0x13,
+ 0x21, 0x03, 0x02, 0xa2, 0x02, 0x22, 0x11, 0x93, 0x31, 0xc0, 0x03, 0xa1, 0x00, 0x20, 0x20, 0x24,
+ 0x24, 0x04, 0x04, 0x00, 0x12, 0x92, 0x01, 0x10, 0x10, 0x14, 0x04, 0xa4, 0x01, 0x10, 0x10, 0x21,
+ 0x21, 0x22, 0x22, 0x04, 0x04, 0xa4, 0x00, 0x20, 0x20, 0x24, 0x24, 0x04, 0x12, 0xa2, 0x00, 0x02,
+ 0x02, 0x22, 0x20, 0xa4, 0x20, 0x00, 0x00, 0x02, 0x02, 0x22, 0x22, 0x24, 0x24, 0x84, 0x20, 0x02,
+ 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x82, 0x00, 0x20, 0x20, 0x21, 0x21, 0x12, 0x12, 0x94,
+ 0x00, 0x04, 0x00, 0x20, 0x20, 0x24, 0x04, 0x24, 0x02, 0xa2, 0x00, 0x02, 0x02, 0x22, 0x22, 0x20,
+ 0x20, 0x00, 0x22, 0x84, 0x11, 0x11, 0x13, 0x93, 0x11, 0x11, 0x13, 0x84, 0x20, 0x02, 0x02, 0xa4,
+ 0x00, 0x22, 0x22, 0x84, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x13, 0x14, 0x94, 0x21, 0x01,
+ 0x01, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x12, 0x12, 0x13, 0x13, 0xa3, 0x04, 0x01, 0x01, 0x10,
+ 0x10, 0x21, 0x21, 0x24, 0x02, 0xa2, 0x00, 0x04, 0x04, 0x14, 0x14, 0x23, 0x23, 0x12, 0x12, 0x02,
+ 0x12, 0x21, 0x21, 0x10, 0x10, 0x80, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x01, 0x10, 0x10, 0xa1,
+ 0x00, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x04, 0x04, 0x80, 0x00, 0x04, 0x04, 0x24,
+ 0x00, 0x20, 0x02, 0x92, 0x00, 0x04, 0x00, 0x20, 0x02, 0x92, 0x21, 0x10, 0x10, 0x01, 0x01, 0x03,
+ 0x03, 0x14, 0x14, 0x23, 0x23, 0x22, 0x22, 0x92, 0x00, 0x04, 0x20, 0x24, 0x02, 0xa2, 0x00, 0x20,
+ 0x10, 0x14, 0x04, 0xa4, 0x00, 0x20, 0x20, 0x23, 0x23, 0x14, 0x14, 0x83, 0x00, 0x04, 0x02, 0x12,
+ 0x12, 0x21, 0x21, 0x20, 0x12, 0x23, 0x23, 0xa4, 0x00, 0x04, 0x04, 0xa4, 0x04, 0x00, 0x00, 0x11,
+ 0x11, 0x20, 0x20, 0xa4, 0x04, 0x00, 0x00, 0x22, 0x20, 0xa4, 0x01, 0x10, 0x10, 0x21, 0x21, 0x23,
+ 0x23, 0x14, 0x14, 0x03, 0x03, 0x81, 0x00, 0x04, 0x00, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x82,
+ 0x01, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x04, 0x93, 0x00, 0x04,
+ 0x00, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x02, 0x02, 0xa4, 0x21, 0x10, 0x10, 0x01, 0x01, 0x23,
+ 0x23, 0x14, 0x14, 0x83, 0x00, 0x20, 0x10, 0x94, 0x00, 0x04, 0x04, 0x24, 0x24, 0xa0, 0x00, 0x03,
+ 0x03, 0x14, 0x14, 0x23, 0x23, 0xa0, 0x00, 0x04, 0x04, 0x24, 0x14, 0x13, 0x24, 0xa0, 0x00, 0x01,
+ 0x01, 0x23, 0x23, 0x24, 0x04, 0x03, 0x03, 0x21, 0x21, 0xa0, 0x00, 0x01, 0x01, 0x12, 0x12, 0x14,
+ 0x12, 0x21, 0x21, 0xa0, 0x00, 0x20, 0x20, 0x02, 0x02, 0x04, 0x04, 0xa4, 0x10, 0x00, 0x00, 0x04,
+ 0x04, 0x94, 0x01, 0xa3, 0x10, 0x20, 0x20, 0x24, 0x24, 0x94, 0x00, 0x91, 0x02, 0x04, 0x04, 0x24,
+ 0x24, 0x22, 0x23, 0x12, 0x12, 0x82, 0x00, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x82, 0x24, 0x04,
+ 0x04, 0x03, 0x03, 0x12, 0x12, 0xa2, 0x20, 0x24, 0x24, 0x04, 0x04, 0x02, 0x02, 0xa2, 0x24, 0x04,
+ 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x93, 0x04, 0x01, 0x02, 0x12, 0x01, 0x10, 0x10, 0xa1,
+ 0x23, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0x23, 0x23, 0x24, 0x24, 0x15, 0x15, 0x84, 0x00, 0x04,
+ 0x03, 0x12, 0x12, 0x23, 0x23, 0xa4, 0x11, 0x11, 0x12, 0x94, 0x22, 0x22, 0x23, 0x24, 0x24, 0x15,
+ 0x15, 0x84, 0x00, 0x04, 0x03, 0x13, 0x13, 0x22, 0x13, 0xa4, 0x02, 0x04, 0x02, 0x13, 0x12, 0x14,
+ 0x12, 0x23, 0x23, 0xa4, 0x02, 0x04, 0x03, 0x12, 0x12, 0x23, 0x23, 0xa4, 0x02, 0x05, 0x04, 0x24,
+ 0x24, 0x22, 0x22, 0x82, 0x02, 0x04, 0x04, 0x24, 0x25, 0x22, 0x22, 0x82, 0x02, 0x04, 0x03, 0x12,
+ 0x12, 0xa2, 0x22, 0x02, 0x02, 0x03, 0x03, 0x23, 0x23, 0x24, 0x24, 0x84, 0x11, 0x14, 0x02, 0xa2,
+ 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0xa2, 0x02, 0x03, 0x03, 0x14, 0x14, 0x23, 0x23, 0xa2,
+ 0x02, 0x03, 0x03, 0x14, 0x14, 0x12, 0x13, 0x24, 0x24, 0xa2, 0x02, 0x24, 0x04, 0xa2, 0x02, 0x03,
+ 0x03, 0x14, 0x22, 0x23, 0x23, 0x85, 0x02, 0x22, 0x22, 0x04, 0x04, 0xa4, 0x20, 0x10, 0x10, 0x14,
+ 0x14, 0x24, 0x12, 0x82, 0x10, 0x11, 0x13, 0x94, 0x00, 0x10, 0x10, 0x14, 0x14, 0x04, 0x12, 0xa2,
+ 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x03, 0x04, 0x04, 0x24, 0x24, 0x23, 0x23, 0x12, 0x12, 0x83,
+ 0x10, 0x10, 0x11, 0x94, 0x21, 0x10, 0x10, 0x01, 0x01, 0x02, 0x02, 0x13, 0x13, 0x22, 0x10, 0x93,
+ 0x11, 0x00, 0x00, 0x04, 0x04, 0x24, 0x24, 0x23, 0x02, 0x92, 0x01, 0x02, 0x11, 0x21, 0x22, 0x23,
+ 0x03, 0x13, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x82, 0x00, 0x11, 0x11, 0x20, 0x11, 0x14,
+ 0x02, 0x22, 0x03, 0xa3, 0x10, 0x12, 0x13, 0x95, 0x20, 0x00, 0x00, 0x02, 0x02, 0x11, 0x11, 0x22,
+ 0x02, 0x13, 0x13, 0x22, 0x22, 0x24, 0x24, 0x84, 0x00, 0x00, 0x20, 0xa0, 0x20, 0x10, 0x10, 0x11,
+ 0x11, 0xa1, 0x10, 0x21, 0x20, 0x21, 0x21, 0x11, 0x11, 0x90, 0x11, 0x02, 0x02, 0x13, 0x21, 0x12,
+ 0x12, 0xa3, 0x01, 0x21, 0x21, 0xa2, 0x10, 0x20, 0x20, 0x21, 0x21, 0x11, 0x12, 0x10, 0x11, 0xa2,
+ 0x00, 0xa0, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x81, 0x02, 0x22, 0x11, 0x13, 0x03, 0xa3,
+ 0x01, 0x10, 0x10, 0x21, 0x21, 0x03, 0x03, 0xa3, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x02,
+ 0x12, 0x23, 0x23, 0x83, 0x02, 0x05, 0x04, 0x14, 0x14, 0x23, 0x22, 0xa4, 0x14, 0x10, 0x10, 0x01,
+ 0x01, 0x12, 0x10, 0x20, 0x20, 0xa4, 0x14, 0x15, 0x15, 0x85, 0x20, 0xa1, 0x10, 0x20, 0x20, 0x21,
+ 0x21, 0x11, 0x11, 0x90, 0x01, 0x12, 0x12, 0x03, 0x11, 0x22, 0x22, 0x93, 0x00, 0x01, 0x02, 0x20,
+ 0x12, 0x13, 0x13, 0x23, 0x22, 0xa4, 0x00, 0x01, 0x02, 0x20, 0x12, 0x22, 0x22, 0x13, 0x13, 0x14,
+ 0x14, 0xa4, 0x00, 0x10, 0x10, 0x11, 0x11, 0x01, 0x11, 0x02, 0x02, 0x20, 0x12, 0x13, 0x13, 0x23,
+ 0x22, 0xa4, 0x10, 0x10, 0x11, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0xa3, 0x04, 0x02, 0x02, 0x11,
+ 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x10, 0xa1, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24,
+ 0x03, 0x23, 0x01, 0x90, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x01, 0x10,
+ 0x10, 0xa1, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x01, 0x10, 0x10, 0x11,
+ 0x11, 0xa0, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x00, 0x00, 0x20, 0xa0,
+ 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x00, 0x20, 0x20, 0x11, 0x11, 0x80,
+ 0x00, 0x04, 0x02, 0x22, 0x00, 0x11, 0x10, 0x14, 0x10, 0x20, 0x14, 0xa4, 0x23, 0x14, 0x14, 0x03,
+ 0x03, 0x01, 0x01, 0x10, 0x10, 0x21, 0x14, 0x15, 0x15, 0x85, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24,
+ 0x03, 0x13, 0x00, 0x91, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24, 0x03, 0x13, 0x11, 0xa0, 0x02, 0x22,
+ 0x02, 0x04, 0x04, 0x24, 0x03, 0x13, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24,
+ 0x03, 0x13, 0x00, 0x00, 0x20, 0xa0, 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x00, 0x91, 0x02, 0x22,
+ 0x12, 0x14, 0x04, 0x24, 0x11, 0xa0, 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x01, 0x10, 0x10, 0xa1,
+ 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x20, 0x20, 0x00, 0x80, 0x00, 0x10, 0x10, 0x21, 0x21, 0x23,
+ 0x23, 0x14, 0x14, 0x04, 0x04, 0x00, 0x02, 0x92, 0x04, 0x02, 0x02, 0x24, 0x24, 0x22, 0x01, 0x10,
+ 0x10, 0x11, 0x11, 0xa0, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x00, 0x91, 0x02, 0x22,
+ 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x11, 0xa0, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02,
+ 0x11, 0x20, 0x00, 0x91, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x01, 0x10, 0x10, 0x11,
+ 0x11, 0xa0, 0x01, 0x21, 0x21, 0x24, 0x24, 0x04, 0x04, 0x01, 0x00, 0x00, 0x20, 0xa0, 0x01, 0x23,
+ 0x03, 0xa1, 0x01, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x03, 0xa1,
+ 0x01, 0x04, 0x04, 0x24, 0x24, 0x21, 0x11, 0xa0, 0x01, 0x04, 0x04, 0x24, 0x24, 0x21, 0x00, 0x91,
+ 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x01, 0x10, 0x10, 0xa1, 0x01, 0x04, 0x04, 0x24, 0x24, 0x21,
+ 0x00, 0x00, 0x20, 0xa0, 0x01, 0x02, 0x02, 0x13, 0x13, 0x14, 0x13, 0x22, 0x22, 0x21, 0x11, 0xa0,
+ 0x00, 0x04, 0x01, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x83, 0x00, 0x05, 0x00, 0x10, 0x10, 0x21,
+ 0x21, 0x12, 0x02, 0x22, 0x22, 0x24, 0x24, 0x84, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12,
+ 0x12, 0x02, 0x00, 0x91, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x11, 0xa0,
+ 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x04,
+ 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04,
+ 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x01, 0x21, 0xa1, 0x02, 0x04, 0x04, 0x24,
+ 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0x21, 0x21, 0x81, 0x02, 0x13, 0x02, 0x04,
+ 0x04, 0x24, 0x12, 0x14, 0x12, 0x22, 0x13, 0x23, 0x22, 0xa3, 0x03, 0x04, 0x04, 0x24, 0x03, 0x12,
+ 0x12, 0x22, 0x14, 0x15, 0x15, 0x85, 0x24, 0x04, 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13,
+ 0x00, 0x91, 0x24, 0x04, 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x11, 0xa0, 0x24, 0x04,
+ 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x01, 0x10, 0x10, 0xa1, 0x24, 0x04, 0x04, 0x02,
+ 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x01, 0x01, 0x21, 0xa1, 0x12, 0x14, 0x00, 0x91, 0x12, 0x14,
+ 0x11, 0xa0, 0x12, 0x14, 0x01, 0x10, 0x10, 0xa1, 0x12, 0x14, 0x01, 0x01, 0x21, 0xa1, 0x00, 0x22,
+ 0x11, 0x20, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x82, 0x02, 0x04, 0x03, 0x12, 0x12, 0x23,
+ 0x23, 0x24, 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
+ 0x00, 0x91, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24,
+ 0x24, 0x22, 0x22, 0x02, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
+ 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02, 0x01, 0x01,
+ 0x21, 0xa1, 0x11, 0x11, 0x02, 0x22, 0x13, 0x93, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
+ 0x04, 0xa2, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x00, 0x91, 0x02, 0x04, 0x04, 0x14,
+ 0x14, 0x23, 0x24, 0x22, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x01, 0x10,
+ 0x10, 0xa1, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x01, 0x01, 0x21, 0xa1, 0x02, 0x03,
+ 0x03, 0x14, 0x22, 0x23, 0x23, 0x05, 0x11, 0xa0, 0x00, 0x04, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13,
+ 0x13, 0x82, 0x02, 0x03, 0x03, 0x14, 0x22, 0x23, 0x23, 0x05, 0x01, 0x01, 0x21, 0xa1, };
+
+
+
+void CNFGDrawText( const char * text, int scale )
+{
+ const unsigned char * lmap;
+ float iox = (float)CNFGPenX;
+ float ioy = (float)CNFGPenY;
+
+ int place = 0;
+ unsigned short index;
+ int bQuit = 0;
+ while( text[place] )
+ {
+ unsigned char c = text[place];
+
+ switch( c )
+ {
+ case 9:
+ iox += 12 * scale;
+ break;
+ case 10:
+ iox = (float)CNFGPenX;
+ ioy += 6 * scale;
+ break;
+ default:
+ index = FontCharMap[c];
+ if( index == 65535 )
+ {
+ iox += 3 * scale;
+ break;
+ }
+
+ lmap = &FontCharData[index];
+ do
+ {
+ int x1 = (int)((((*lmap) & 0x70)>>4)*scale + iox);
+ int y1 = (int)(((*lmap) & 0x0f)*scale + ioy);
+ int x2 = (int)((((*(lmap+1)) & 0x70)>>4)*scale + iox);
+ int y2 = (int)(((*(lmap+1)) & 0x0f)*scale + ioy);
+ lmap++;
+ CNFGTackSegment( x1, y1, x2, y2 );
+ bQuit = *lmap & 0x80;
+ lmap++;
+ } while( !bQuit );
+
+ iox += 3 * scale;
+ }
+ place++;
+ }
+}
+
+
+void CNFGDrawBox( int x1, int y1, int x2, int y2 )
+{
+ unsigned lc = CNFGLastColor;
+ CNFGColor( CNFGDialogColor );
+ CNFGTackRectangle( x1, y1, x2, y2 );
+ CNFGColor( lc );
+ CNFGTackSegment( x1, y1, x2, y1 );
+ CNFGTackSegment( x2, y1, x2, y2 );
+ CNFGTackSegment( x2, y2, x1, y2 );
+ CNFGTackSegment( x1, y2, x1, y1 );
+}
+
+void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize )
+{
+ int charsx = 0;
+ int charsy = 1;
+ int charsline = 0;
+ const char * s;
+
+ for( s = text; *s; s++ )
+ {
+ if( *s == '\n' )
+ {
+ charsline = 0;
+ if( *(s+1) )
+ charsy++;
+ }
+ else
+ {
+ charsline++;
+ if( charsline > charsx )
+ charsx = charsline;
+ }
+ }
+
+ *w = charsx * textsize * 3 + textsize;
+ *h = charsy * textsize * 6;
+}
+
+void CNFGDrawTextbox( int x, int y, const char * text, int textsize )
+{
+ int w;
+ int h;
+
+ CNFGGetTextExtents( text, &w, &h, textsize );
+
+ CNFGDrawBox( x, y, x + w, y + h );
+ CNFGPenX = x + textsize;
+ CNFGPenY = y + textsize;
+ CNFGDrawText( text, textsize );
+}
diff --git a/DrawFunctions.h b/DrawFunctions.h
@@ -0,0 +1,54 @@
+//Copyright (c) 2011 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
+
+#ifndef _DRAWFUCNTIONS_H
+#define _DRAWFUCNTIONS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+typedef struct {
+ short x, y;
+} RDPoint;
+
+extern int CNFGPenX, CNFGPenY;
+extern uint32_t CNFGBGColor;
+extern uint32_t CNFGLastColor;
+extern uint32_t CNFGDialogColor; //background for boxes
+
+void CNFGDrawText( const char * text, int scale );
+void CNFGDrawBox( int x1, int y1, int x2, int y2 );
+void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize );
+void CNFGDrawTextbox( int x, int y, const char * text, int textsize ); //ignores pen.
+
+//To be provided by driver.
+uint32_t CNFGColor( uint32_t RGB );
+void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h );
+void CNFGTackPixel( short x1, short y1 );
+void CNFGTackSegment( short x1, short y1, short x2, short y2 );
+void CNFGTackRectangle( short x1, short y1, short x2, short y2 );
+void CNFGTackPoly( RDPoint * points, int verts );
+void CNFGClearFrame();
+void CNFGSwapBuffers();
+
+void CNFGGetDimensions( short * x, short * y );
+void CNFGSetup( const char * WindowName, int w, int h );
+void CNFGSetupFullscreen( const char * WindowName, int screen_number );
+void CNFGHandleInput();
+
+
+//You must provide:
+void HandleKey( int keycode, int bDown );
+void HandleButton( int x, int y, int button, int bDown );
+void HandleMotion( int x, int y, int mask );
+
+
+#ifdef __cplusplus
+};
+#endif
+
+
+#endif
+
diff --git a/LICENSE b/LICENSE
@@ -1,22 +1,22 @@
-The MIT License (MIT)
+//The myping tool is licensed under the below license.
+//The rest of rawdraw and CNPing may be licensed feely under the MIT-x11
+//or NewBSD Licenses. You choose!
-Copyright (c) 2014 Charles
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+/* myping.c
+ *
+ * Copyright (c) 2000 Sean Walton and Macmillan Publishers. Use may be in
+ * whole or in part in accordance to the General Public License (GPL).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+*/
diff --git a/Makefile b/Makefile
@@ -0,0 +1,21 @@
+all : cnping searchnet
+
+CFLAGS:=$(CFLAGS) -g -Os
+CXXFLAGS:=$(CFLAGS)
+LDFLAGS:=-g
+
+MINGW32:=/usr/bin/i686-w64-mingw32-
+
+cnping.exe : cnping.c DrawFunctions.c WinDriver.c os_generic.c ping.c
+ $(MINGW32)gcc -m32 $(CFLAGS) -o $@ $^ -lgdi32
+
+# Rasterizer.o
+cnping : cnping.o DrawFunctions.o XDriver.o os_generic.o ping.o
+ gcc $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread -lXinerama -lXext $(LDFLAGS)
+
+searchnet : os_generic.o ping.o searchnet.o
+ gcc $(CFLAGS) -o $@ $^ -lpthread
+
+clean :
+ rm -rf *.o *~ cnping cnping.exe
+
diff --git a/WinDriver.c b/WinDriver.c
@@ -0,0 +1,226 @@
+//Copyright (c) 2011 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
+//Portion from: http://en.wikibooks.org/wiki/Windows_Programming/Window_Creation
+
+
+#include "DrawFunctions.h"
+#include <windows.h>
+#include <stdlib.h>
+#include <malloc.h> //for alloca
+
+static HINSTANCE lhInstance;
+static HWND lsHWND;
+static HDC lsHDC;
+static HBITMAP lsBackBitmap;
+static HDC lsWindowHDC;
+static HBRUSH lsHBR;
+static HPEN lsHPEN;
+static HBRUSH lsClearBrush;
+static unsigned int lsLastWidth;
+static unsigned int lsLastHeight;
+
+static void InternalHandleResize()
+{
+ DeleteObject( lsBackBitmap );
+ lsBackBitmap = CreateCompatibleBitmap( lsHDC, lsLastWidth, lsLastHeight );
+ SelectObject( lsHDC, lsBackBitmap );
+
+}
+
+uint32_t CNFGColor( uint32_t RGB )
+{
+ CNFGLastColor = RGB;
+
+ DeleteObject( lsHBR );
+ lsHBR = CreateSolidBrush( RGB );
+ SelectObject( lsHDC, lsHBR );
+
+ DeleteObject( lsHPEN );
+ lsHPEN = CreatePen( PS_SOLID, 0, RGB );
+ SelectObject( lsHDC, lsHPEN );
+
+ return RGB;
+}
+
+void CNFGTackSegment( short x1, short y1, short x2, short y2 )
+{
+ POINT pt[2] = { {x1, y1}, {x2, y2} };
+ Polyline( lsHDC, pt, 2 );
+ SetPixel( lsHDC, x1, y1, CNFGLastColor );
+ SetPixel( lsHDC, x2, y2, CNFGLastColor );
+}
+
+void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
+{
+ RECT r;
+ if( x1 < x2 ) { r.left = x1; r.right = x2; }
+ else { r.left = x2; r.right = x1; }
+ if( y1 < y2 ) { r.top = y1; r.bottom = y2; }
+ else { r.top = y2; r.bottom = y1; }
+ FillRect( lsHDC, &r, lsHBR );
+}
+
+void CNFGClearFrame()
+{
+ RECT r = { 0, 0, lsLastWidth, lsLastHeight };
+ DeleteObject( lsClearBrush );
+ lsClearBrush = CreateSolidBrush( CNFGBGColor );
+ SelectObject( lsHDC, lsClearBrush );
+
+ FillRect( lsHDC, &r, lsClearBrush );
+}
+
+void CNFGSwapBuffers()
+{
+ int thisw, thish;
+ RECT r;
+ BitBlt( lsWindowHDC, 0, 0, lsLastWidth, lsLastHeight, lsHDC, 0, 0, SRCCOPY );
+ UpdateWindow( lsHWND );
+
+ //Check to see if the window is closed.
+ if( !IsWindow( lsHWND ) )
+ {
+ exit( 0 );
+ }
+
+ GetClientRect( lsHWND, &r );
+ thisw = r.right - r.left;
+ thish = r.bottom - r.top;
+ if( thisw != lsLastWidth || thish != lsLastHeight )
+ {
+ lsLastWidth = thisw;
+ lsLastHeight = thish;
+ InternalHandleResize();
+ }
+}
+
+void CNFGTackPoly( RDPoint * points, int verts )
+{
+ int i;
+ POINT * t = (POINT*)alloca( sizeof( POINT ) * verts );
+ for( i = 0; i < verts; i++ )
+ {
+ t[i].x = points[i].x;
+ t[i].y = points[i].y;
+ }
+ Polygon( lsHDC, t, verts );
+}
+
+
+void CNFGTackPixel( short x1, short y1 )
+{
+ SetPixel( lsHDC, x1, y1, CNFGLastColor );
+}
+
+void CNFGGetDimensions( short * x, short * y )
+{
+ *x = lsLastWidth;
+ *y = lsLastHeight;
+}
+
+//This was from the article
+LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ return 0;
+ }
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+}
+
+//This was from the article, too... well, mostly.
+void CNFGSetup( const char * name_of_window, int width, int height )
+{
+ static LPSTR szClassName = "MyClass";
+ RECT client, window;
+ WNDCLASS wnd;
+ int w, h, wd, hd;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ lsLastWidth = width;
+ lsLastHeight = height;
+
+ wnd.style = CS_HREDRAW | CS_VREDRAW; //we will explain this later
+ wnd.lpfnWndProc = MyWndProc;
+ wnd.cbClsExtra = 0;
+ wnd.cbWndExtra = 0;
+ wnd.hInstance = hInstance;
+ wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default icon
+ wnd.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrow mouse cursor
+ wnd.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
+ wnd.lpszMenuName = NULL; //no menu
+ wnd.lpszClassName = szClassName;
+
+ if(!RegisterClass(&wnd)) //register the WNDCLASS
+ {
+ MessageBox(NULL, "This Program Requires Windows NT", "Error", MB_OK);
+ }
+
+ lsHWND = CreateWindow(szClassName,
+ name_of_window, //name_of_window,
+ WS_OVERLAPPEDWINDOW, //basic window style
+ CW_USEDEFAULT,
+ CW_USEDEFAULT, //set starting point to default value
+ lsLastWidth,
+ lsLastHeight, //set all the dimensions to default value
+ NULL, //no parent window
+ NULL, //no menu
+ hInstance,
+ NULL); //no parameters to pass
+
+
+ lsWindowHDC = GetDC( lsHWND );
+ lsHDC = CreateCompatibleDC( lsWindowHDC );
+ lsBackBitmap = CreateCompatibleBitmap( lsWindowHDC, lsLastWidth, lsLastHeight );
+ SelectObject( lsHDC, lsBackBitmap );
+
+ lsClearBrush = CreateSolidBrush( CNFGBGColor );
+ lsHBR = CreateSolidBrush( 0xFFFFFF );
+ lsHPEN = CreatePen( PS_SOLID, 0, 0xFFFFFF );
+
+ ShowWindow(lsHWND, 1); //display the window on the screen
+
+ //Once set up... we have to change the window's borders so we get the client size right.
+ GetClientRect( lsHWND, &client );
+ GetWindowRect( lsHWND, &window );
+ w = ( window.right - window.left);
+ h = ( window.bottom - window.top);
+ wd = w - client.right;
+ hd = h - client.bottom;
+ MoveWindow( lsHWND, window.left, window.top, lsLastWidth + wd, lsLastHeight + hd, 1 );
+
+ InternalHandleResize();
+}
+
+void CNFGHandleInput()
+{
+ int ldown = 0;
+
+ MSG msg;
+ while( PeekMessage( &msg, lsHWND, 0, 0xFFFF, 1 ) )
+ {
+ TranslateMessage(&msg);
+
+ switch( msg.message )
+ {
+ case WM_MOUSEMOVE:
+ HandleMotion( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, ( (msg.wParam & 0x01)?1:0) | ((msg.wParam & 0x02)?2:0) | ((msg.wParam & 0x10)?4:0) );
+ break;
+ case WM_LBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 1, 1 ); break;
+ case WM_RBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 2, 1 ); break;
+ case WM_MBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 3, 1 ); break;
+ case WM_LBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 1, 0 ); break;
+ case WM_RBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 2, 0 ); break;
+ case WM_MBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 3, 0 ); break;
+ case WM_KEYDOWN:
+ case WM_KEYUP:
+ HandleKey( tolower( msg.wParam ), (msg.message==WM_KEYDOWN) );
+ break;
+ default:
+ DispatchMessage(&msg);
+ break;
+ }
+ }
+}
+
diff --git a/XDriver.c b/XDriver.c
@@ -0,0 +1,259 @@
+//Copyright (c) 2011 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
+//portions from
+//http://www.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html
+
+#define HAS_XINERAMA
+
+#include "DrawFunctions.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+#ifdef HAS_XINERAMA
+#include <X11/extensions/shape.h>
+#include <X11/extensions/Xinerama.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+
+XWindowAttributes CNFGWinAtt;
+Display *CNFGDisplay;
+Window CNFGWindow;
+Pixmap CNFGPixmap;
+GC CNFGGC;
+GC CNFGWindowGC;
+int FullScreen = 0;
+
+void CNFGGetDimensions( short * x, short * y )
+{
+ *x = CNFGWinAtt.width;
+ *y = CNFGWinAtt.height;
+}
+
+static void InternalLinkScreenAndGo( const char * WindowName )
+{
+ XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
+
+ XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask );
+ XSetStandardProperties( CNFGDisplay, CNFGWindow, WindowName, WindowName, None, NULL, 0, NULL );
+
+ CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0);
+
+ CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
+ CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
+}
+
+void CNFGSetupFullscreen( const char * WindowName, int screen_no )
+{
+#ifdef HAS_XINERAMA
+ XineramaScreenInfo *screeninfo = NULL;
+ int screens;
+ int event_basep, error_basep, a, b;
+ CNFGDisplay = XOpenDisplay(NULL);
+ int screen = XDefaultScreen(CNFGDisplay);
+ int xpos, ypos;
+
+ if (!XShapeQueryExtension(CNFGDisplay, &event_basep, &error_basep))
+ {
+ fprintf( stderr, "X-Server does not support shape extension" );
+ exit( 1 );
+ }
+
+ Visual * visual = DefaultVisual(CNFGDisplay, screen);
+ CNFGWinAtt.depth = DefaultDepth(CNFGDisplay, screen);
+
+ if (XineramaQueryExtension(CNFGDisplay, &a, &b ) &&
+ (screeninfo = XineramaQueryScreens(CNFGDisplay, &screens)) &&
+ XineramaIsActive(CNFGDisplay) && screen_no >= 0 &&
+ screen_no < screens ) {
+
+ CNFGWinAtt.width = screeninfo[screen_no].width;
+ CNFGWinAtt.height = screeninfo[screen_no].height;
+ xpos = screeninfo[screen_no].x_org;
+ ypos = screeninfo[screen_no].y_org;
+ } else
+ {
+ CNFGWinAtt.width = XDisplayWidth(CNFGDisplay, screen);
+ CNFGWinAtt.height = XDisplayHeight(CNFGDisplay, screen);
+ xpos = 0;
+ ypos = 0;
+ }
+ if (screeninfo)
+ XFree(screeninfo);
+
+
+ XSetWindowAttributes setwinattr;
+ setwinattr.override_redirect = 1;
+ setwinattr.save_under = 1;
+ setwinattr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonPressMask | PointerMotionMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask |KeyPressMask |KeyReleaseMask | SubstructureNotifyMask | FocusChangeMask;
+ setwinattr.border_pixel = 0;
+
+ CNFGWindow = XCreateWindow(CNFGDisplay, XRootWindow(CNFGDisplay, screen),
+ xpos, ypos, CNFGWinAtt.width, CNFGWinAtt.height,
+ 0, CNFGWinAtt.depth, InputOutput, visual, CWBorderPixel | CWEventMask | CWOverrideRedirect | CWSaveUnder, &setwinattr);
+
+ XMapWindow(CNFGDisplay, CNFGWindow);
+ XSetInputFocus( CNFGDisplay, CNFGWindow, RevertToParent, CurrentTime );
+ XFlush(CNFGDisplay);
+ FullScreen = 1;
+//printf( "%d %d %d %d\n", xpos, ypos, CNFGWinAtt.width, CNFGWinAtt.height );
+ InternalLinkScreenAndGo( WindowName );
+/*
+ setwinattr.override_redirect = 1;
+ XChangeWindowAttributes(
+ CNFGDisplay, CNFGWindow,
+ CWBorderPixel | CWEventMask | CWOverrideRedirect, &setwinattr);
+*/
+#else
+ CNFGSetup( WindowName, 640, 480 );
+#endif
+}
+
+
+void CNFGSetup( const char * WindowName, int w, int h )
+{
+ CNFGDisplay = XOpenDisplay(NULL);
+ XGetWindowAttributes( CNFGDisplay, RootWindow(CNFGDisplay, 0), &CNFGWinAtt );
+
+ int depth = CNFGWinAtt.depth;
+ CNFGWindow = XCreateWindow(CNFGDisplay, RootWindow(CNFGDisplay, 0), 1, 1, w, h, 0, depth, InputOutput, CopyFromParent, 0, 0 );
+ XMapWindow(CNFGDisplay, CNFGWindow);
+ XFlush(CNFGDisplay);
+
+ InternalLinkScreenAndGo( WindowName );
+}
+
+void CNFGHandleInput()
+{
+ static int ButtonsDown;
+ XEvent report;
+
+ int bKeyDirection = 1;
+ int r;
+ while( (r=XCheckMaskEvent( CNFGDisplay, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask , &report )) )
+ {
+// XEvent nev;
+// XPeekEvent(CNFGDisplay, &nev);
+
+ //printf( "EVENT %d\n", report.type );
+ //XMaskEvent(CNFGDisplay, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask, &report);
+
+ bKeyDirection = 1;
+ switch (report.type)
+ {
+ case NoExpose:
+ break;
+ case Expose:
+ XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
+ if( CNFGPixmap ) XFreePixmap( CNFGDisplay, CNFGPixmap );
+ CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
+ if( CNFGGC ) XFreeGC( CNFGDisplay, CNFGGC );
+ CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
+ break;
+ case KeyRelease:
+ bKeyDirection = 0;
+ case KeyPress:
+ HandleKey( XLookupKeysym(&report.xkey, 0), bKeyDirection );
+ break;
+ case ButtonRelease:
+ bKeyDirection = 0;
+ case ButtonPress:
+ HandleButton( report.xbutton.x, report.xbutton.y, report.xbutton.button, bKeyDirection );
+ ButtonsDown = (ButtonsDown & (~(1<<report.xbutton.button))) | ( bKeyDirection << report.xbutton.button );
+
+ //Intentionall fall through -- we want to send a motion in event of a button as well.
+ case MotionNotify:
+ HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 );
+ break;
+ default:
+ printf( "Event: %d\n", report.type );
+ }
+ }
+}
+
+
+void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
+{
+ static XImage *xi;
+ static int depth;
+ static int lw, lh;
+ static unsigned char * lbuffer;
+ int r, ls;
+
+ if( !xi )
+ {
+ int screen = DefaultScreen(CNFGDisplay);
+ Visual * visual = DefaultVisual(CNFGDisplay, screen);
+ depth = DefaultDepth(CNFGDisplay, screen)/8;
+// xi = XCreateImage(CNFGDisplay, DefaultVisual( CNFGDisplay, DefaultScreen(CNFGDisplay) ), depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 );
+// lw = w;
+// lh = h;
+ }
+
+ if( lw != w || lh != h )
+ {
+ if( xi ) free( xi );
+ xi = XCreateImage(CNFGDisplay, DefaultVisual( CNFGDisplay, DefaultScreen(CNFGDisplay) ), depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 );
+ lw = w;
+ lh = h;
+ }
+
+ ls = lw * lh;
+
+ XPutImage(CNFGDisplay, CNFGWindow, CNFGWindowGC, xi, 0, 0, 0, 0, w, h );
+}
+
+
+#ifndef RASTERIZER
+
+
+uint32_t CNFGColor( uint32_t RGB )
+{
+ unsigned char red = RGB & 0xFF;
+ unsigned char grn = ( RGB >> 8 ) & 0xFF;
+ unsigned char blu = ( RGB >> 16 ) & 0xFF;
+ CNFGLastColor = RGB;
+ unsigned long color = (red<<16)|(grn<<8)|(blu);
+ XSetForeground(CNFGDisplay, CNFGGC, color);
+ return color;
+}
+
+void CNFGClearFrame()
+{
+ XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
+ XSetForeground(CNFGDisplay, CNFGGC, CNFGColor(CNFGBGColor) );
+ XFillRectangle(CNFGDisplay, CNFGPixmap, CNFGGC, 0, 0, CNFGWinAtt.width, CNFGWinAtt.height );
+}
+
+void CNFGSwapBuffers()
+{
+ XCopyArea(CNFGDisplay, CNFGPixmap, CNFGWindow, CNFGWindowGC, 0,0,CNFGWinAtt.width,CNFGWinAtt.height,0,0);
+ XFlush(CNFGDisplay);
+ if( FullScreen )
+ XSetInputFocus( CNFGDisplay, CNFGWindow, RevertToParent, CurrentTime );
+}
+
+void CNFGTackSegment( short x1, short y1, short x2, short y2 )
+{
+ XDrawLine( CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1, x2, y2 );
+}
+
+void CNFGTackPixel( short x1, short y1 )
+{
+ XDrawPoint( CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1 );
+}
+
+void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
+{
+ XFillRectangle(CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1, x2-x1, y2-y1 );
+}
+
+void CNFGTackPoly( RDPoint * points, int verts )
+{
+ XFillPolygon(CNFGDisplay, CNFGPixmap, CNFGGC, (XPoint *)points, 3, Convex, CoordModeOrigin );
+}
+
+#endif
+
diff --git a/cnping.c b/cnping.c
@@ -0,0 +1,260 @@
+//Copyright (c) 2011-2014 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/ip_icmp.h>
+#include <arpa/inet.h>
+#include <sys/select.h>
+#include <netdb.h>
+#include "DrawFunctions.h"
+#include "os_generic.h"
+#include "ping.h"
+
+unsigned frames = 0;
+unsigned long iframeno = 0;
+short screenx, screeny;
+const char * pinghost;
+float pingperiod;
+
+uint8_t pattern[8];
+
+
+#define PINGCYCLEWIDTH 1024
+#define TIMEOUT 4
+
+double PingSendTimes[PINGCYCLEWIDTH];
+double PingRecvTimes[PINGCYCLEWIDTH];
+int current_cycle = 0;
+
+void display(uint8_t *buf, int bytes)
+{
+ int reqid = (buf[0] << 24) | (buf[1]<<16) | (buf[2]<<8) | (buf[3]);
+ reqid &= (PINGCYCLEWIDTH-1);
+
+ double STime = PingSendTimes[reqid];
+ double LRTime = PingRecvTimes[reqid];
+
+ if( memcmp( buf+4, pattern, 8 ) != 0 ) return;
+ if( LRTime > STime ) return;
+ if( STime < 1 ) return;
+
+ //Otherwise this is a legit packet.
+
+ PingRecvTimes[reqid] = OGGetAbsoluteTime();
+}
+
+int load_ping_packet( uint8_t * buffer, int bufflen )
+{
+ buffer[0] = current_cycle >> 24;
+ buffer[1] = current_cycle >> 16;
+ buffer[2] = current_cycle >> 8;
+ buffer[3] = current_cycle >> 0;
+
+ memcpy( buffer+4, pattern, 8 );
+
+ PingSendTimes[current_cycle&(PINGCYCLEWIDTH-1)] = OGGetAbsoluteTime();
+ PingRecvTimes[current_cycle&(PINGCYCLEWIDTH-1)] = 0;
+
+ current_cycle++;
+
+ return 12;
+}
+
+void * PingListen( void * r )
+{
+ listener();
+ printf( "Fault on listen.\n" );
+ exit( -2 );
+}
+
+void * PingSend( void * r )
+{
+ do_pinger( pinghost, pingperiod );
+ printf( "Fault on ping.\n" );
+ exit( -1 );
+}
+
+
+
+
+void HandleKey( int keycode, int bDown ){}
+void HandleButton( int x, int y, int button, int bDown ){}
+void HandleMotion( int x, int y, int mask ){}
+void DrawFrame( void )
+{
+ int i, x, y;
+
+ double now = OGGetAbsoluteTime();
+
+ double totaltime = 0;
+ int totalcountok = 0;
+ double mintime = 100;
+ double maxtime = 0;
+ double stddev = 0;
+ double last;
+
+ for( i = 0; i < screenx; i++ )
+ {
+ int index = ((current_cycle - i - 1) + PINGCYCLEWIDTH) & (PINGCYCLEWIDTH-1);
+ double st = PingSendTimes[index];
+ double rt = PingRecvTimes[index];
+
+ double dt = 0;
+
+ if( rt > st )
+ {
+ CNFGColor( 0xffffff );
+ dt = rt - st;
+ dt *= 1000;
+ totaltime += dt;
+ if( dt < mintime ) mintime = dt;
+ if( dt > maxtime ) maxtime = dt;
+ totalcountok++;
+ }
+ else
+ {
+ CNFGColor( 0xff );
+ dt = now - st;
+ dt *= 1000;
+
+ }
+
+ if( i == 1 )
+ last = dt;
+ int h = dt;
+
+ CNFGTackSegment( i, screeny, i, screeny - h );
+ }
+
+ double avg = totaltime / totalcountok;
+
+ for( i = 0; i < screenx; i++ )
+ {
+ int index = ((current_cycle - i - 1) + PINGCYCLEWIDTH) & (PINGCYCLEWIDTH-1);
+ double st = PingSendTimes[index];
+ double rt = PingRecvTimes[index];
+
+ double dt = 0;
+ if( rt > st )
+ {
+ dt = rt - st;
+ dt *= 1000;
+ stddev += (dt-avg)*(dt-avg);
+ }
+ }
+
+ stddev /= totalcountok;
+
+ stddev = sqrt(stddev);
+
+ CNFGColor( 0xff00 );
+ int l = avg;
+ CNFGTackSegment( 0, screeny-l, screenx, screeny - l );
+ l = avg + stddev;
+ CNFGTackSegment( 0, screeny-l, screenx, screeny - l );
+ l = avg - stddev;
+ CNFGTackSegment( 0, screeny-l, screenx, screeny - l );
+
+ char stbuf[1024];
+ char * sptr = &stbuf[0];
+ sptr += sprintf( sptr, "Last: %5.2f ms\n", last );
+ sptr += sprintf( sptr, "Min : %5.2f ms\n", mintime );
+ sptr += sprintf( sptr, "Max : %5.2f ms\n", maxtime );
+ sptr += sprintf( sptr, "Avg : %5.2f ms\n", avg );
+ sptr += sprintf( sptr, "Std : %5.2f ms\n", stddev );
+ CNFGColor( 0x00 );
+ for( x = -1; x < 2; x++ ) for( y = -1; y < 2; y++ )
+ {
+ CNFGPenX = 10+x; CNFGPenY = 10+y;
+ CNFGDrawText( stbuf, 2 );
+ }
+ CNFGColor( 0xffffff );
+ CNFGPenX = 10; CNFGPenY = 10;
+ CNFGDrawText( stbuf, 2 );
+
+}
+
+int main( int argc, const char ** argv )
+{
+ char title[1024];
+ int i, x, y, r;
+ double ThisTime;
+ double LastFPSTime = OGGetAbsoluteTime();
+ double LastFrameTime = OGGetAbsoluteTime();
+ double SecToWait;
+ int linesegs = 0;
+// struct in_addr dst;
+ struct addrinfo *result;
+
+ srand( (int)(OGGetAbsoluteTime()*10) );
+
+ for( i = 0; i < sizeof( pattern ); i++ )
+ {
+ pattern[i] = rand();
+ }
+ CNFGBGColor = 0x800000;
+ CNFGDialogColor = 0x444444;
+
+ for( i = 0; i < PINGCYCLEWIDTH; i++ )
+ {
+ PingSendTimes[i] = 0;
+ PingRecvTimes[i] = 0;
+ }
+
+ if( argc < 2 )
+ {
+ fprintf( stderr, "Usage: cnping [host] [ping period in seconds (optional)]\n" );
+ }
+
+ sprintf( title, "%s - cnping", argv[1] );
+ CNFGSetup( title, 640, 480 );
+
+ ping_setup();
+
+ pinghost = argv[1];
+ pingperiod = (argc==3)?atof( argv[2] ):.02;
+
+ OGCreateThread( PingListen, 0 );
+ OGCreateThread( PingSend, 0 );
+
+ while(1)
+ {
+ int i, pos;
+ float f;
+ iframeno++;
+ RDPoint pto[3];
+
+ CNFGHandleInput();
+
+ CNFGClearFrame();
+ CNFGColor( 0xFFFFFF );
+ CNFGGetDimensions( &screenx, &screeny );
+
+ DrawFrame();
+
+ frames++;
+ CNFGSwapBuffers();
+
+ ThisTime = OGGetAbsoluteTime();
+ if( ThisTime > LastFPSTime + 1 )
+ {
+ frames = 0;
+ linesegs = 0;
+ LastFPSTime+=1;
+ }
+
+ SecToWait = .016 - ( ThisTime - LastFrameTime );
+ LastFrameTime += .016;
+ if( SecToWait > 0 )
+ OGUSleep( (int)( SecToWait * 1000000 ) );
+ }
+
+ return(0);
+}
+
diff --git a/os_generic.c b/os_generic.c
@@ -0,0 +1,335 @@
+#include "os_generic.h"
+
+
+#ifdef USE_WINDOWS
+
+#include <windows.h>
+
+void OGSleep( int is )
+{
+ Sleep( is*1000 );
+}
+
+void OGUSleep( int ius )
+{
+ Sleep( ius/1000 );
+}
+
+double OGGetAbsoluteTime()
+{
+ static LARGE_INTEGER lpf;
+ LARGE_INTEGER li;
+
+ if( !lpf.QuadPart )
+ {
+ QueryPerformanceFrequency( &lpf );
+ }
+
+ QueryPerformanceCounter( &li );
+ return (double)li.QuadPart / (double)lpf.QuadPart;
+}
+
+
+double OGGetFileTime( const char * file )
+{
+ FILETIME ft;
+
+ HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+
+ if( h==INVALID_HANDLE_VALUE )
+ return -1;
+
+ GetFileTime( h, 0, 0, &ft );
+
+ CloseHandle( h );
+
+ return ft.dwHighDateTime + ft.dwLowDateTime;
+}
+
+
+og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
+{
+ return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0 );
+}
+
+void * OGJoinThread( og_thread_t ot )
+{
+ WaitForSingleObject( ot, INFINITE );
+ CloseHandle( ot );
+}
+
+void OGCancelThread( og_thread_t ot )
+{
+ CloseHandle( ot );
+}
+
+og_mutex_t OGCreateMutex()
+{
+ return CreateMutex( 0, 0, 0 );
+}
+
+void OGLockMutex( og_mutex_t om )
+{
+ WaitForSingleObject(om, INFINITE);
+}
+
+void OGUnlockMutex( og_mutex_t om )
+{
+ ReleaseMutex(om);
+}
+
+void OGDeleteMutex( og_mutex_t om )
+{
+ CloseHandle( om );
+}
+
+
+
+og_sema_t OGCreateSema()
+{
+ HANDLE sem = CreateSemaphore( 0, 0, 32767, 0 );
+ return (og_sema_t)sem;
+}
+
+int OGGetSema( og_sema_t os )
+{
+ typedef LONG NTSTATUS;
+ HANDLE sem = (HANDLE)os;
+ typedef NTSTATUS (NTAPI *_NtQuerySemaphore)(
+ HANDLE SemaphoreHandle,
+ DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
+ PVOID SemaphoreInformation, /* but this is to much to dump here */
+ ULONG SemaphoreInformationLength,
+ PULONG ReturnLength OPTIONAL
+ );
+
+ typedef struct _SEMAPHORE_BASIC_INFORMATION {
+ ULONG CurrentCount;
+ ULONG MaximumCount;
+ } SEMAPHORE_BASIC_INFORMATION;
+
+
+ static _NtQuerySemaphore NtQuerySemaphore;
+ SEMAPHORE_BASIC_INFORMATION BasicInfo;
+ NTSTATUS Status;
+
+ if( !NtQuerySemaphore )
+ {
+ NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress (GetModuleHandle ("ntdll.dll"), "NtQuerySemaphore");
+ if( !NtQuerySemaphore )
+ {
+ return -1;
+ }
+ }
+
+
+ Status = NtQuerySemaphore (sem, 0 /*SemaphoreBasicInformation*/,
+ &BasicInfo, sizeof (SEMAPHORE_BASIC_INFORMATION), NULL);
+
+ if (Status == ERROR_SUCCESS)
+ {
+ return BasicInfo.CurrentCount;
+ }
+
+ return -2;
+}
+
+void OGLockSema( og_sema_t os )
+{
+ WaitForSingleObject( (HANDLE)os, INFINITE );
+}
+
+void OGUnlockSema( og_sema_t os )
+{
+ ReleaseSemaphore( (HANDLE)os, 1, 0 );
+}
+
+void OGDeleteSema( og_sema_t os )
+{
+ CloseHandle( os );
+}
+
+#else
+
+#define _GNU_SOURCE
+
+
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/time.h>
+#include <semaphore.h>
+
+pthread_mutex_t g_RawMutexStart = PTHREAD_MUTEX_INITIALIZER;
+
+void OGSleep( int is )
+{
+ sleep( is );
+}
+
+void OGUSleep( int ius )
+{
+ usleep( ius );
+}
+
+double OGGetAbsoluteTime()
+{
+ struct timeval tv;
+ gettimeofday( &tv, 0 );
+ return ((double)tv.tv_usec)/1000000. + (tv.tv_sec);
+}
+
+double OGGetFileTime( const char * file )
+{
+ struct stat buff;
+
+ int r = stat( file, &buff );
+
+ if( r < 0 )
+ {
+ return -1;
+ }
+
+ return buff.st_mtime;
+}
+
+
+
+og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
+{
+ pthread_t * ret = malloc( sizeof( pthread_t ) );
+ int r = pthread_create( ret, 0, routine, parameter );
+ if( r )
+ {
+ free( ret );
+ return 0;
+ }
+ return (og_thread_t)ret;
+}
+
+void * OGJoinThread( og_thread_t ot )
+{
+ void * retval;
+ if( !ot )
+ {
+ return 0;
+ }
+ pthread_join( *(pthread_t*)ot, &retval );
+ free( ot );
+ return retval;
+}
+
+void OGCancelThread( og_thread_t ot )
+{
+ if( !ot )
+ {
+ return;
+ }
+ pthread_cancel( *(pthread_t*)ot );
+ free( ot );
+}
+
+og_mutex_t OGCreateMutex()
+{
+ pthread_mutexattr_t mta;
+ og_mutex_t r = malloc( sizeof( pthread_mutex_t ) );
+
+ pthread_mutexattr_init(&mta);
+ pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
+
+ pthread_mutex_init( (pthread_mutex_t *)r, &mta );
+
+ return r;
+}
+
+void OGLockMutex( og_mutex_t om )
+{
+ if( !om )
+ {
+ return;
+ }
+ pthread_mutex_lock( (pthread_mutex_t*)om );
+}
+
+void OGUnlockMutex( og_mutex_t om )
+{
+ if( !om )
+ {
+ return;
+ }
+ pthread_mutex_unlock( (pthread_mutex_t*)om );
+}
+
+void OGDeleteMutex( og_mutex_t om )
+{
+ if( !om )
+ {
+ return;
+ }
+
+ pthread_mutex_destroy( (pthread_mutex_t*)om );
+ free( om );
+}
+
+
+
+
+og_sema_t OGCreateSema()
+{
+ sem_t * sem = malloc( sizeof( sem_t ) );
+ sem_init( sem, 0, 0 );
+ return (og_sema_t)sem;
+}
+
+int OGGetSema( og_sema_t os )
+{
+ int valp;
+ sem_getvalue( os, &valp );
+ return valp;
+}
+
+
+void OGLockSema( og_sema_t os )
+{
+ sem_wait( os );
+}
+
+void OGUnlockSema( og_sema_t os )
+{
+ sem_post( os );
+}
+
+void OGDeleteSema( og_sema_t os )
+{
+ sem_destroy( os );
+ free(os);
+}
+
+
+
+#endif
+
+//Date Stamp: 2012-02-15
+
+/*
+ Copyright (c) 2011-2012 <>< Charles Lohr
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of this file.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
diff --git a/os_generic.h b/os_generic.h
@@ -0,0 +1,76 @@
+#ifndef _OS_GENERIC_H
+#define _OS_GENERIC_H
+
+#ifdef WIN32
+#define USE_WINDOWS
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//Things that shouldn't be macro'd
+double OGGetAbsoluteTime();
+void OGSleep( int is );
+void OGUSleep( int ius );
+double OGGetFileTime( const char * file );
+
+//Threads and Mutices
+typedef void* og_thread_t;
+typedef void* og_mutex_t;
+typedef void* og_sema_t;
+
+og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
+void * OGJoinThread( og_thread_t ot );
+void OGCancelThread( og_thread_t ot );
+
+//Always a recrusive mutex.
+og_mutex_t OGCreateMutex();
+void OGLockMutex( og_mutex_t om );
+void OGUnlockMutex( og_mutex_t om );
+void OGDeleteMutex( og_mutex_t om );
+
+//Always a semaphore
+og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially. NOTE: Max count is 32767
+void OGLockSema( og_sema_t os );
+int OGGetSema( og_sema_t os ); //if <0 there was a failure.
+void OGUnlockSema( og_sema_t os );
+void OGDeleteSema( og_sema_t os );
+
+#ifdef __cplusplus
+};
+#endif
+
+
+
+#endif
+
+
+//Date Stamp: 2012-02-15
+
+/*
+ NOTE: Portions (namely the top section) are part of headers from other
+ sources.
+
+ Copyright (c) 2011-2012 <>< Charles Lohr
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of this file.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
diff --git a/ping.c b/ping.c
@@ -0,0 +1,216 @@
+/* myping.c
+ *
+ * Copyright (c) 2000 Sean Walton and Macmillan Publishers. Use may be in
+ * whole or in part in accordance to the General Public License (GPL).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+*/
+
+/*****************************************************************************/
+/*** myping.c ***/
+/*** ***/
+/*** Use the ICMP protocol to request "echo" from destination. ***/
+/*****************************************************************************/
+
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <resolv.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/ip_icmp.h>
+#include <stdlib.h>
+
+
+#define PACKETSIZE 1500
+struct packet
+{
+ struct icmphdr hdr;
+ char msg[PACKETSIZE-sizeof(struct icmphdr)];
+};
+
+int pid=-1;
+struct protoent *proto=NULL;
+
+/*--------------------------------------------------------------------*/
+/*--- checksum - standard 1s complement checksum ---*/
+/*--------------------------------------------------------------------*/
+unsigned short checksum(void *b, int len)
+{ unsigned short *buf = b;
+ unsigned int sum=0;
+ unsigned short result;
+
+ for ( sum = 0; len > 1; len -= 2 )
+ sum += *buf++;
+ if ( len == 1 )
+ sum += *(unsigned char*)buf;
+ sum = (sum >> 16) + (sum & 0xFFFF);
+ sum += (sum >> 16);
+ result = ~sum;
+ return result;
+}
+
+/*--------------------------------------------------------------------*/
+/*--- display - present echo info ---*/
+/*--------------------------------------------------------------------*/
+/*void display(void *buf, int bytes)
+{ int i;
+ struct iphdr *ip = buf;
+ struct icmphdr *icmp = buf+ip->ihl*4;
+
+ printf("----------------\n");
+ for ( i = 0; i < bytes; i++ )
+ {
+ if ( !(i & 15) ) printf("\nX: ", i);
+ printf("X ", ((unsigned char*)buf)[i]);
+ }
+ printf("\n");
+ printf("IPv%d: hdr-size=%d pkt-size=%d protocol=%d TTL=%d src=%s ",
+ ip->version, ip->ihl*4, ntohs(ip->tot_len), ip->protocol,
+ ip->ttl, inet_ntoa(ip->saddr));
+ printf("dst=%s\n", inet_ntoa(ip->daddr));
+ if ( icmp->un.echo.id == pid )
+ {
+ printf("ICMP: type[%d/%d] checksum[%d] id[%d] seq[%d]\n",
+ icmp->type, icmp->code, ntohs(icmp->checksum),
+ icmp->un.echo.id, icmp->un.echo.sequence);
+ }
+}
+*/
+/*--------------------------------------------------------------------*/
+/*--- listener - separate process to listen for and collect messages--*/
+/*--------------------------------------------------------------------*/
+void listener(void)
+{ int sd;
+ struct sockaddr_in addr;
+ unsigned char buf[1024];
+
+ sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
+ if ( sd < 0 )
+ {
+ perror("socket");
+ exit(0);
+ }
+ for (;;)
+ { int bytes, len=sizeof(addr);
+
+ bzero(buf, sizeof(buf));
+ bytes = recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len);
+ if ( bytes > 0 )
+ display(buf + 28, bytes - 28 );
+ else
+ perror("recvfrom");
+ }
+ printf( "Fault on listen.\n" );
+ exit(0);
+}
+
+/*--------------------------------------------------------------------*/
+/*--- ping - Create message and send it. ---*/
+/*--------------------------------------------------------------------*/
+void ping(struct sockaddr_in *addr, float pingperiod)
+{ const int val=255;
+ int i, sd, cnt=1;
+ struct packet pckt;
+ struct sockaddr_in r_addr;
+
+ sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
+ if ( sd < 0 )
+ {
+ perror("socket");
+ return;
+ }
+ if ( setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0)
+ perror("Set TTL option");
+ if ( fcntl(sd, F_SETFL, O_NONBLOCK) != 0 )
+ perror("Request nonblocking I/O");
+
+ do
+ { int len=sizeof(r_addr);
+
+// printf("Msg #%d\n", cnt);
+// if ( recvfrom(sd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&r_addr, &len) > 0 )
+ {
+ //printf("***Got message!***\n");
+ }
+ bzero(&pckt, sizeof(pckt));
+ pckt.hdr.type = ICMP_ECHO;
+ pckt.hdr.un.echo.id = pid;
+ int rsize = load_ping_packet( pckt.msg, sizeof( pckt.msg ) );
+ pckt.msg[i] = 0;
+ pckt.hdr.un.echo.sequence = cnt++;
+ pckt.hdr.checksum = checksum(&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize );
+ if ( sendto(sd, &pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr)) <= 0 )
+ perror("sendto");
+
+ if( pingperiod > 0 )
+ {
+ uint32_t dlw = 1000000.0*pingperiod;
+ usleep( dlw );
+ }
+ } while( pingperiod >= 0 );
+ close( sd );
+}
+
+void ping_setup()
+{
+ pid = getpid();
+ proto = getprotobyname("ICMP");
+}
+
+void do_pinger( const char * strhost, float _ping_period )
+{
+ struct sockaddr_in addr;
+ struct hostent *hname;
+ hname = gethostbyname(strhost);
+
+ bzero(&addr, sizeof(addr));
+ addr.sin_family = hname->h_addrtype;
+ addr.sin_port = 0;
+ addr.sin_addr.s_addr = *(long*)hname->h_addr;
+ ping(&addr, _ping_period);
+}
+
+/*--------------------------------------------------------------------*/
+/*--- main - look up host and start ping processes. ---*/
+/*--------------------------------------------------------------------*/
+int pingmain(int count, char *strings[])
+{ struct hostent *hname;
+ struct sockaddr_in addr;
+
+ if ( count != 2 )
+ {
+ printf("usage: %s <addr>\n", strings[0]);
+ exit(0);
+ }
+ if ( count > 1 )
+ {
+ pid = getpid();
+ proto = getprotobyname("ICMP");
+ hname = gethostbyname(strings[1]);
+ bzero(&addr, sizeof(addr));
+ addr.sin_family = hname->h_addrtype;
+ addr.sin_port = 0;
+ addr.sin_addr.s_addr = *(long*)hname->h_addr;
+ if ( fork() == 0 )
+ listener();
+ else
+ ping(&addr, 1);
+ wait(0);
+ }
+ else
+ printf("usage: myping <hostname>\n");
+ return 0;
+}
+
diff --git a/ping.h b/ping.h
@@ -0,0 +1,24 @@
+#ifndef _PING_H
+#define _PING_H
+
+#include <stdint.h>
+
+struct sockaddr_in;
+
+unsigned short checksum(void *b, int len);
+
+//Callback (when received)
+void display(uint8_t *buf, int bytes);
+
+//Callback (before sending)
+//return value = # of bytes to send in ping message.
+int load_ping_packet( uint8_t * buffer, int buffersize );
+
+void listener(void);
+void ping(struct sockaddr_in *addr , float pingperiod); //If pingperiod = -1, run once and exit.
+void do_pinger( const char * strhost, float _ping_period ); //If pingperiod = -1, run once and exit.
+
+void ping_setup();
+
+#endif
+
diff --git a/searchnet.c b/searchnet.c
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include "ping.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+uint32_t my_random_key;
+uint8_t send_id[4];
+
+void * PingListen( void * r )
+{
+ listener();
+ printf( "Fault on listen.\n" );
+ exit( -2 );
+}
+
+void display(uint8_t *buf, int bytes)
+{
+ int i;
+ uint32_t reqid = ((uint32_t)buf[0+1] << 24) | (buf[1+1]<<16) | (buf[2+1]<<8) | (buf[3+1]);
+
+/* for( i = 0; i < bytes; i++ )
+ {
+ printf( "%02x ", buf[i] );
+ }
+ printf( "\n" );
+ printf( "REQ: %08x %08x\n", reqid, my_random_key );
+/// printf( "%d.%d.%d.%d\n", buf[4], buf[5], buf[6], buf[7] );
+*/
+ if( reqid != my_random_key ) return;
+
+ printf( "%d.%d.%d.%d\n", buf[4+1], buf[5+1], buf[6+1], buf[7+1] );
+}
+
+int load_ping_packet( uint8_t * buffer, int bufflen )
+{
+ buffer[0+1] = my_random_key >> 24;
+ buffer[1+1] = my_random_key >> 16;
+ buffer[2+1] = my_random_key >> 8;
+ buffer[3+1] = my_random_key >> 0;
+
+ buffer[4+1] = send_id[0];
+ buffer[5+1] = send_id[1];
+ buffer[6+1] = send_id[2];
+ buffer[7+1] = send_id[3];
+
+ return 12;
+}
+
+
+int main( int argc, char ** argv )
+{
+ uint32_t offset;
+ int mask;
+ in_addr_t base;
+ char dispip[32];
+ float speed;
+
+ ping_setup();
+ OGCreateThread( PingListen, 0 );
+ srand( ((int)(OGGetAbsoluteTime()*10000)) );
+ my_random_key = rand();
+
+ if( argc != 4 )
+ {
+ fprintf( stderr, "Usage: [searchnet IP net] [mask (single #, i.e. 24)] [speed (in seconds per attempt)]\n" );
+ return -1;
+ }
+
+ base = ntohl(inet_addr( argv[1] ));
+ mask = 1<<(32-atoi(argv[2]));
+ speed = atof(argv[3]);
+
+ base &= ~(mask-1);
+ printf( "Base: %08x / Mask: %08x\n", base, mask );
+ for( offset = 0; offset < mask; offset++ )
+ {
+ uint32_t cur = base + offset;
+ sprintf( dispip, "%d.%d.%d.%d", (cur>>24)&0xff, (cur>>16)&0xff, (cur>>8)&0xff, (cur)&0xff );
+ send_id[0] = (cur>>24)&0xff;
+ send_id[1] = (cur>>16)&0xff;
+ send_id[2] = (cur>>8)&0xff;
+ send_id[3] = (cur)&0xff;
+// printf( "Pinging: %s\n", dispip );
+ do_pinger( dispip, -1 );
+
+ OGUSleep( (int)(speed * 1000000) );
+ }
+
+ return 0;
+}
+