Autor Beitrag
stefanl
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Di 02.12.03 22:07 
Hallo,

wie kann ich einen ping programmieren OHNE ein zusätzliches Package zu
installieren?

Die packages sind schon sehr praktisch. Aber in diesem Fall muss ich ABSOLUT sicherstellen das das ganze funktioniert wenn einfach nur
Quelltextdateien auf einen anderen Rechner KOPIERT werden.

1.) Frisch installiertes Delphi 4 OHNE irgendwelche extras
2.) Quelltexte kopieren

und dann muß die Sache laufen wenn man einfach nur auf die Projektdatei
doppelklickt.

OHNE noch irgendwelche packages zu installieren oder sonst was machen
zu müssen.

Es gibt ja Komponenten und packages zu ping (z.B. TPing)
kann man das nicht irgendwie auch so aufbauen das es wie oben
beschrieben funktioniert?

Sonst fällt mir nur noch

"von hinten zum Mond und zurück 5 loopings und dann durch die Brust ins Auge ein":

shellexecute ping.bat > ping.txt

dat wär doch furchtbar unelegant nich war ??
Da muss es was besseres geben !

Vielen Dank schon im Voraus

Stefan
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Mi 03.12.03 10:11 
schau dir doch den sourcecode von indy an dann siehst du doch wie man nen "ping" macht.

_________________
hans bist du das ?
stefanl Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 03.12.03 11:15 
Titel: wer möchte mir helfen? Soucecode für Ping
Hallo Delphi-Community,

das Anliegen des vorigen Beitrags mir den Source anzuschauen in Ehren.

Bis ich es - als relativ unerfahrener Programmierer - auseinanderdividiert
habe was ich von den Indy-Componenten für ein schlichtes ping brauche und was nicht - dauert ziemlich lange.

Wer ist so nett und hilft mir da ein Stück weiter?

Ich darf ja gerade NICHT das package installieren !!
D.h. ich muß alles was ich für das Ping brauche so in units extrahieren,
das das ganze OHNE package-installation lauffähig wird.

manche Leser scheinen das zu überlesen also nochmal

ping OHNE Packageinstallation
ping OHNE Packageinstallation

das Pingdemo:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
uses
IdIcmpClient, IdBaseComponent, IdComponent, IdRawBase, IdRawClient;

unit IdIcmpClient;

uses
  IdGlobal,
  IdRawBase,
  IdRawClient,
  IdStack,
  IdStackConsts,

könnte der Weg dahin so aussehen?

ping demo compilieren
Compiler meckert an

"TIdIcmpClient" unbekannter Bezeichner

also die Unit suchen in der das definiert ist
diese mit ins Projekt aufnehmen

wieder compilieren
compiler meckert wieder ...
usw. usw. usf.

Scheint mir nicht besonders elegant zu sein.

Ich weiß aber noch nix besseres. :?

Wer wäre denn so nett mir Tips zu geben wie ich das
OHNE Indy-Package-Installation auf die Reihe kriege?

Vielen Dank schon im Voraus

Stefan

Moderiert von user profile iconUGrohne: Delphi-Tags hinzugefügt.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mi 03.12.03 11:20 
Darf man fragen wofür du das brauchst? Würde mich mal interessieren..

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
stefanl Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 03.12.03 11:41 
Titel: alle 5 Sekunden Prüfen ob Netzwerkverbindung zwischen 2 PCs
Hallo,

man darf Fragen,

und Du hast Recht wenn ich das eigentliche Ziel beschreibe gibt es
vielleicht noch andere Möglichkeiten dieses zu erreichen.

Es geht darum alle 5 Sekunden zu Prüfen ob eine Netzwerkverbindung
zu einem Netzlaufwerk (freigegebenes Verzeichnis auf dem anderen PC) noch besteht oder nicht.

Wenn ja schauen die PCs gegenseitig in ein Freigegebenes Verzeichnis
auf dem jeweils anderen Rechner ob dort bestimmte Dateien vorhanden sind.

Wenn die Netzwerkverbindung unterbrochen ist
nimmt sich Windoof 2000 für dieses "kuck nach den Dateien"
30 Sekunden Zeit und der Rest des Programms steht solange.

Da es sich um eine Steuerungsanwendung handelt ist das völlig
unakzeptabel.

Mit UDP bekomme ich in folgender Konstellationen einen WriteStream-Error.

Betriebssystem: Win2000 (un)Professional
Netzwerkverbindung steht
auf PC2 läuft jedoch kein UDP-Programm

UDP-Programm auf PC1 sendet einen String und dann gibt es einen
WriteStream-Error der das Programm abschießt.

Mit TCP/IP vermute ich ähnliche Probleme.

Es geht lediglich darum ALLE 5 Sekunden SCHNELL = 0,1 Sekunden zu detektieren kann auf das Netzlaufwerk zugegriffen werden oder nicht.

viele Grüße

Stefan
stefanl Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 03.12.03 20:44 
Titel: umschreiben das es ohne package installieren läuft
Hallo package-Kenner,

jetzt habe ich im Internet ein kleines package aufgetrieben das die ping-funktion enthält.

wie weiter oben schon mehrfach erwähnt MUSS ich den ping ZWINGEND
OHNE die Installation von packages unter Delphi4 zum laufen bringen

wie man an meiner Vorgehendsweise unschwer erkennen kann bin
ich noch nicht allzu vertraut mit packages.

Ich habe den Sourcecode der units
IC_MISC.PAS
ICMP.PAS mit in die Unit U_PING.PAS gepackt

ohne den Abschnitt initialisation aus der unit ICMP.PAS läßt sich das
ganze sogar kompilieren. Jedoch nur mit der Fehlermeldung

"Komponente frm_ping.ping besitzt keine entsprechende Komponente
soll die Deklaration entfernt werden ?"

Liegt vermutlich daran daß ich das package nicht installiert habe
Ich will es ja auch so umstricken das es OHNE package-installation geht.

Es läßt sich auch starten bricht aber bei klick auf die Schaltfläche die
pingen soll mit der Fehlermeldung EAccessViolation ab

die U_PING.FRM enthält das Objekt

object Ping : TPIng
...
OnPing = PingPing

das

das ist die Komponente die da wohl angemeckert wird

wie kriege ich die jetzt über LUPENREINES "dem Projekt hinzufügen"
OHNE package-installation ins Programm rein?

Eine alternative wäre unter Umständen wenn man das installieren des
packages VOLLKOMMEN automatisieren könnte.

D.h. man kopiert - was für dateien auch immer - startet die *.DPR-Datei
durch doppelklick und der Rest läuft automatisch ab

so jetzt bin ich mal gespannt ob das genug Futter und konkrete Frage ist
damit jemand mal zeigt was er an erklären so drauf hat

vielen Dank schon im Voraus

viele Grüße

Stefan

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
723:
724:
725:
726:
727:
728:
729:
730:
731:
732:
733:
734:
735:
736:
737:
738:
739:
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820:
821:
822:
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834:
835:
836:
837:
838:
839:
840:
841:
842:
843:
844:
845:
846:
847:
848:
849:
850:
851:
852:
853:
854:
855:
856:
857:
858:
859:
860:
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883:
884:
885:
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925:
926:
927:
928:
929:
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940:
941:
942:
943:
944:
945:
946:
947:
948:
949:
950:
951:
952:
953:
954:
955:
956:
957:
958:
959:
960:
961:
962:
963:
964:
965:
966:
967:
968:
969:
970:
971:
972:
973:
974:
975:
976:
977:
978:
979:
980:
981:
982:
983:
984:
985:
986:
987:
988:
989:
990:
991:
992:
993:
994:
995:
996:
997:
998:
999:
1000:
1001:
1002:
1003:
1004:
1005:
1006:
1007:
1008:
1009:
1010:
1011:
1012:
1013:
1014:
1015:
1016:
1017:
1018:
1019:
1020:
1021:
1022:
1023:
1024:
1025:
1026:
1027:
1028:
1029:
1030:
1031:
1032:
1033:
1034:
1035:
1036:
1037:
1038:
1039:
1040:
1041:
1042:
1043:
1044:
1045:
1046:
1047:
1048:
1049:
1050:
1051:
1052:
1053:
1054:
1055:
1056:
1057:
1058:
1059:
1060:
1061:
1062:
1063:
1064:
1065:
1066:
1067:
1068:
1069:
1070:
1071:
1072:
1073:
1074:
1075:
1076:
1077:
1078:
1079:
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087:
1088:
1089:
1090:
1091:
1092:
1093:
1094:
1095:
1096:
1097:
1098:
1099:
1100:
1101:
1102:
1103:
1104:
1105:
1106:
1107:
1108:
1109:
1110:
1111:
1112:
1113:
1114:
1115:
1116:
1117:
1118:
1119:
1120:
1121:
1122:
1123:
1124:
1125:
1126:
1127:
1128:
1129:
1130:
1131:
1132:
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151:
1152:
1153:
1154:
1155:
1156:
1157:
1158:
1159:
1160:
1161:
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:
1183:
1184:
1185:
1186:
1187:
1188:
1189:
1190:
1191:
1192:
1193:
1194:
1195:
1196:
1197:
1198:
1199:
1200:
1201:
1202:
1203:
1204:
1205:
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213:
1214:
1215:
1216:
1217:
1218:
1219:
1220:
1221:
1222:
1223:
1224:
1225:
1226:
1227:
1228:
1229:
1230:
1231:
1232:
1233:
1234:
1235:
1236:
1237:
1238:
1239:
1240:
1241:
1242:
1243:
1244:
1245:
1246:
1247:
1248:
1249:
1250:
1251:
1252:
1253:
1254:
1255:
1256:
1257:
1258:
1259:
1260:
1261:
1262:
1263:
1264:
1265:
1266:
1267:
1268:
1269:
1270:
1271:
1272:
1273:
1274:
1275:
1276:
1277:
1278:
1279:
1280:
1281:
1282:
1283:
1284:
1285:
1286:
1287:
1288:
1289:
1290:
1291:
1292:
1293:
1294:
1295:
1296:
1297:
1298:
1299:
1300:
1301:
1302:
1303:
1304:
1305:
1306:
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318:
1319:
1320:
1321:
1322:
1323:
1324:
1325:
1326:
1327:
1328:
1329:
1330:
1331:
1332:
1333:
1334:
1335:
1336:
1337:
1338:
1339:
1340:
1341:
1342:
1343:
1344:
1345:
1346:
1347:
1348:
1349:
1350:
1351:
1352:
1353:
1354:
1355:
1356:
1357:
1358:
1359:
1360:
1361:
1362:
1363:
1364:
1365:
1366:
1367:
1368:
1369:
1370:
1371:
1372:
1373:
1374:
1375:
1376:
1377:
1378:
1379:
1380:
1381:
1382:
1383:
1384:
1385:
1386:
1387:
1388:
1389:
1390:
1391:
1392:
1393:
1394:
1395:
1396:
1397:
1398:
1399:
1400:
1401:
1402:
1403:
1404:
1405:
1406:
1407:
1408:
1409:
1410:
1411:
1412:
1413:
1414:
1415:
1416:
1417:
1418:
1419:
1420:
1421:
1422:
1423:
1424:
1425:
1426:
1427:
1428:
1429:
1430:
1431:
1432:
1433:
1434:
1435:
1436:
1437:
1438:
1439:
1440:
1441:
1442:
1443:
1444:
1445:
1446:
1447:
1448:
1449:
1450:
1451:
1452:
1453:
1454:
1455:
1456:
1457:
1458:
1459:
1460:
1461:
1462:
1463:
1464:
1465:
1466:
1467:
1468:
1469:
1470:
1471:
1472:
1473:
1474:
1475:
1476:
1477:
1478:
1479:
1480:
1481:
1482:
1483:
1484:
1485:
1486:
1487:
1488:
1489:
1490:
1491:
1492:
1493:
1494:
1495:
1496:
1497:
1498:
1499:
1500:
1501:
1502:
1503:
1504:
1505:
1506:
1507:
1508:
1509:
1510:
1511:
1512:
1513:
1514:
1515:
1516:
1517:
1518:
1519:
1520:
1521:
1522:
1523:
1524:
1525:
1526:
1527:
1528:
1529:
1530:
1531:
1532:
1533:
1534:
1535:
1536:
1537:
1538:
1539:
1540:
1541:
1542:
1543:
1544:
1545:
1546:
1547:
1548:
1549:
1550:
1551:
1552:
1553:
1554:
1555:
1556:
1557:
1558:
1559:
1560:
1561:
1562:
1563:
1564:
1565:
1566:
1567:
1568:
1569:
1570:
1571:
1572:
1573:
1574:
1575:
1576:
1577:
1578:
1579:
1580:
1581:
1582:
1583:
1584:
1585:
1586:
1587:
1588:
1589:
1590:
1591:
1592:
1593:
1594:
1595:
1596:
1597:
1598:
1599:
1600:
1601:
1602:
1603:
1604:
1605:
1606:
1607:
1608:
1609:
1610:
1611:
1612:
1613:
1614:
1615:
1616:
1617:
1618:
1619:
1620:
1621:
1622:
1623:
1624:
1625:
1626:
1627:
1628:
1629:
1630:
1631:
1632:
1633:
1634:
1635:
1636:
1637:
1638:
1639:
1640:
1641:
1642:
1643:
1644:
1645:
1646:
1647:
1648:
1649:
1650:
1651:
1652:
1653:
1654:
1655:
1656:
1657:
1658:
1659:
1660:
1661:
1662:
1663:
1664:
1665:
1666:
1667:
1668:
1669:
1670:
1671:
1672:
1673:
1674:
1675:
1676:
1677:
1678:
1679:
1680:
1681:
1682:
1683:
1684:
1685:
1686:
1687:
1688:
1689:
1690:
1691:
1692:
1693:
1694:
1695:
1696:
1697:
1698:
1699:
1700:
1701:
1702:
1703:
1704:
1705:
1706:
1707:
1708:
1709:
1710:
1711:
1712:
1713:
1714:
1715:
1716:
1717:
1718:
1719:
1720:
1721:
1722:
1723:
1724:
1725:
1726:
1727:
1728:
1729:
1730:
1731:
1732:
1733:
1734:
1735:
1736:
1737:
1738:
1739:
1740:
1741:
1742:
1743:
1744:
1745:
1746:
1747:
1748:
1749:
1750:
1751:
1752:
1753:
1754:
1755:
1756:
1757:
1758:
1759:
1760:
1761:
1762:
1763:
1764:
1765:
1766:
1767:
1768:
1769:
1770:
1771:
1772:
1773:
1774:
1775:
1776:
1777:
1778:
1779:
1780:
1781:
1782:
1783:
1784:
1785:
1786:
1787:
1788:
1789:
1790:
1791:
1792:
1793:
1794:
1795:
1796:
1797:
1798:
1799:
1800:
1801:
1802:
1803:
1804:
1805:
1806:
1807:
1808:
1809:
1810:
1811:
1812:
1813:
1814:
1815:
1816:
1817:
1818:
1819:
1820:
1821:
1822:
1823:
1824:
1825:
1826:
1827:
1828:
unit icmp;

{ this component is public domain - please check the file readme.txt for     }
{ more detailed info on usage and distributing                               }

(*@/// interface *)
interface

(*@/// uses *)
uses
  sysutils,
  classes,
  winsock,
(*$ifdef ver80 *)
  winprocs,
  wintypes,
(*$else *)
  windows,
(*$endif *)
  messages,
  forms,
  ip_misc;
(*@\\\*)

(*@/// The API stuff for the ICMP.DLL *)
(* Documentation taken from http://www.sockets.com/ms_icmp.htm *)

{ Microsoft doesn't support the standard way ICMP is implemented using
  sockets, that means by the SOCK_RAW socket type - they only work as
  user administrator! And there's no way to set the TTL for the packets, so
  there's no way to build a TraceRoute using winsock. So this unit uses their
  ICMP.DLL, although MS discourages it's use - once they have a better solution
  this properitary implementation will vanish. So be careful where you
  use this unit!
}


const
(*@///   ip status values *)
ip_status_base           = 11000;
ip_success               = 0;
ip_buf_too_small         = ip_status_base +  1;
ip_dest_net_unreachable  = ip_status_base +  2;
ip_dest_host_unreachable = ip_status_base +  3;
ip_dest_prot_unreachable = ip_status_base +  4;
ip_dest_port_unreachable = ip_status_base +  5;
ip_no_resources          = ip_status_base +  6;
ip_bad_options           = ip_status_base +  7;
ip_hw_error              = ip_status_base +  8;
ip_packet_too_big        = ip_status_base +  9;
ip_req_timed_out         = ip_status_base + 10;
ip_bad_req               = ip_status_base + 11;
ip_bad_route             = ip_status_base + 12;
ip_ttl_expired_transmit  = ip_status_base + 13;
ip_ttl_expired_reassem   = ip_status_base + 14;
ip_param_problem         = ip_status_base + 15;
ip_source_quench         = ip_status_base + 16;
ip_option_too_big        = ip_status_base + 17;
ip_bad_destination       = ip_status_base + 18;
ip_addr_deleted          = ip_status_base + 19;
ip_sepc_mtu_change       = ip_status_base + 20;
ip_mtu_change            = ip_status_base + 21;
ip_unload                = ip_status_base + 22;
ip_general_failure       = ip_status_base + 50;
max_ip_status            = ip_general_failure;
ip_pending               = ip_status_base +255;
(*@\\\0000000C01*)

type
(*@///   t_ip_options=packed record *)
p_ip_options=^t_ip_options;
t_ip_options=packed record
  Ttl: byte;             (* time to live *)
  Tos: byte;             (* type of service (usually 0) *)
  flags: byte;           (* IP header flags (usually 0) *)
  optionssize: byte;     (* size of options data (usually 0, max 40) *)
  optionsdata: pointer;  (* options data buffer *)
end;
(*@\\\0000000201*)
(*@///   t_icmp_echo_reply=packed record *)
p_icmp_echo_reply=^t_icmp_echo_reply;
t_icmp_echo_reply=packed record
  address: u_long;           (* source address *)
  status: u_long;            (* IP status *)
  rttime: u_long;            (* rount trip time in milliseconds *)
  datasize: word;            (* reply data size *)
  reserved: word;            (* who knows *)
  data: pointer;             (* reply data buffer *)
  ip_options:t_ip_options;   (* reply options *)
end;
(*@\\\*)

var
  ICMPCreateFile:function:THandle; stdcall;
  ICMPCloseHandle:function(ICMPHandle:THandle):Boolean; stdcall;
  ICMPSendEcho:function(ICMPHandle: THandle;      (* handle returned from ICMPCreateFile *)
                        DestAddress:longint;      (* destination IP address (network order) *)
                        Requestdata:pointer;      (* pointer to buffer to send *)
                        requestsize:word;         (* length of data in buffer *)
                        RequestOptns: p_ip_options;
                        ReplyBuffer:pointer;      (* see note *)
                        Replysize:dword;          (* length of reply, minimum 1 reply *)
                        Timeout: DWord            (* time in milliseconds to wait for reply *)
                        ):dword; stdcall;


(* The reply buffer will have an array of ICMP_ECHO_REPLY structures, followed
   by options and the data in ICMP echo reply datagram received. You must
   have root for at least one ICMP echo reply structure, plus 8 bytes for
   an ICMP header *)

(*@\\\0000000D14*)
(*@/// The ICMP constants for winsock like calls *)
type
(*@///   t_ip_header=packed record *)
t_ip_header=packed record
  ip_hl_v: byte;   (* low nibble: header length; high nibble: version *)
  ip_tos: byte;    (* type of service *)
  ip_len: word;    (* total length *)
  ip_id: word;     (* identification *)
  ip_off: word;    (* fragment offset field *)
  ip_ttl: byte;    (* time to live *)
  ip_p: byte;      (* protocol *)
  ip_sum: word;    (* checksum *)
  ip_src,
  ip_dst:longint;  (* source and dest address *)
  end;
(*@\\\*)
(*@///   t_icmp_echo_request=packed record *)
t_icmp_echo_request=packed record
  icmp_type: byte;            (* ICMP type *)
  icmp_code: byte;            (* ICMP code *)
  icmp_cksum: word;           (* ICMP checksum *)
  icmp_id: word;              (* ICMP identification *)
  icmp_seq: word;             (* ICMP sequence number *)
  end;
(*@\\\000000050A*)
(*@///   t_icmp_reply=packed record *)
t_icmp_reply=packed record
  icmp_type: byte;            (* ICMP type *)
  icmp_code: byte;            (* ICMP code *)
  icmp_cksum: word;           (* ICMP checksum *)
  icmp_unused: longint;       (* unused area *)
  icmp_ip: t_ip_header;       (* original IP header which cause the reply *)
  icmp_dgram:array[0..63] of byte;   (* first 64 bits of datagram *)
  end;
(*@\\\000000010D*)
const
(*@///   ICMP types *)
  ICMP_ECHOREPLY           = 0  ;  (* echo reply *)
  ICMP_UNREACH             = 3  ;  (* dest unreachable, codes: *)
    ICMP_UNREACH_NET       = 0  ;  (* bad net *)
    ICMP_UNREACH_HOST      = 1  ;  (* bad host *)
    ICMP_UNREACH_PROTOCOL  = 2  ;  (* bad protocol *)
    ICMP_UNREACH_PORT      = 3  ;  (* bad port *)
    ICMP_UNREACH_NEEDFRAG  = 4  ;  (* IP_DF caused drop *)
    ICMP_UNREACH_SRCFAIL   = 5  ;  (* src route failed *)
  ICMP_SOURCEQUENCH        = 4  ;  (* packet lost, slow down *)
  ICMP_REDIRECT            = 5  ;  (* shorter route, codes: *)
    ICMP_REDIRECT_NET      = 0  ;  (* for network *)
    ICMP_REDIRECT_HOST     = 1  ;  (* for host *)
    ICMP_REDIRECT_TOSNET   = 2  ;  (* for tos and net *)
    ICMP_REDIRECT_TOSHOST  = 3  ;  (* for tos and host *)
  ICMP_ECHO                = 8  ;  (* echo service *)
  ICMP_TIMXCEED            = 11 ;  (* time exceeded, code: *)
    ICMP_TIMXCEED_INTRANS  = 0  ;  (* ttl==0 in transit *)
    ICMP_TIMXCEED_REASS    = 1  ;  (* ttl==0 in reass *)
  ICMP_PARAMPROB           = 12 ;  (* ip header bad *)
  ICMP_TSTAMP              = 13 ;  (* timestamp request *)
  ICMP_TSTAMPREPLY         = 14 ;  (* timestamp reply *)
  ICMP_IREQ                = 15 ;  (* information request *)
  ICMP_IREQREPLY           = 16 ;  (* information reply *)
  ICMP_MASKREQ             = 17 ;  (* address mask request *)
  ICMP_MASKREPLY           = 18 ;  (* address mask reply *)
(*@\\\*)
(*@///   Options for use with [gs]etsockopt at the IP level. (corrected from winsock) *)
(*  IP_OPTIONS          = 1;  *)

  IP_TTL              =  4;           { Time to live of IP packet }
  IP_MULTICAST_IF     =  9;           { set/get IP multicast interface   }
  IP_MULTICAST_TTL    = 10;           { set/get IP multicast timetolive  }
  IP_MULTICAST_LOOP   = 11;           { set/get IP multicast loopback    }
  IP_ADD_MEMBERSHIP   = 12;           { add  an IP group membership      }
  IP_DROP_MEMBERSHIP  = 13;           { drop an IP group membership      }

(*  IP_DEFAULT_MULTICAST_TTL   = 1;    { normally limit m'casts to 1 hop  }  *)
(*  IP_DEFAULT_MULTICAST_LOOP  = 1;    { normally hear sends if a member  }  *)
(*  IP_MAX_MEMBERSHIPS         = 20;   { per socket; must fit in one mbuf }  *)
(*@\\\0000000301*)

function ICMP_checksum(var buf; length:integer):word;
(*@\\\0000000701*)

type
  t_icmp_call=(  icmp_dll,         (* only ICMP.DLL calls *)
                 icmp_winsock_ttl, (* Winsock including setting TTL *)
                 icmp_winsock_dll, (* Winsock, but ICMP.DLL for TTL *)
                 icmp_winsock,     (* Winsock, but no TTL *)
                 no_icmp           (* no at all *)
               );
var
  icmp_state:t_icmp_call;

type
  TPingEvent = procedure (sender:TObject; status: integer; ip:longint; roundtime:longint) of object;
  TRouteEvent = procedure (sender:TObject; hop: byte; ip:longint; roundtime:longint) of object;
  EICMPError=class(Exception);
(*@///   TICMP=class(TComponent) *)
TICMP=class(TComponent)
protected
  icmp_handle: THandle;  (* for ICMP.DLL mode *)
  f_socket: TSocket;     (* for winsock RAW mode *)
protected
  f_blocksize: byte;
  f_replysize: dword;
  f_timeout: cardinal;
  f_ttl: byte;
  f_address: longint;
  f_hostname: string;
  f_terminated: boolean;
  f_handle: THandle;
  procedure WndProc(var Msg : TMessage); virtual;
  procedure OpenDll;
  procedure OpenSocket;
public
  constructor Create(Aowner:TComponent); override;
  procedure Terminate;
  procedure action; virtual;
  destructor Destroy; override;
end;
(*@\\\*)
(*@///   TPing=class(TICMP) *)
TPing=class(TICMP)
protected
  f_no_of_packets_rec: integer;
  f_no_of_packets_snd: integer;
  f_roundtime_max: longint;
  f_roundtime_min: longint;
  f_roundtime_med: extended;
  f_on_ping: TPingEvent;
  function GetRoundtimeMin:longint;
  function GetRoundtimeMed:extended;
  procedure UpdateStatistics(roundtime:longint);
public
  property MinimumRoundttime: longint read GetRoundtimeMin;
  property MaximumRoundttime: longint read f_roundtime_max;
  property MeanRoundttime: extended read GetRoundTimeMed;
  property ReceivedPackets: integer read f_no_of_packets_rec;
  property SentPackets: integer read f_no_of_packets_snd;
  constructor Create(Aowner:TComponent); override;
  procedure action; override;
  procedure ReceiveSock;
  procedure SendSock;
  procedure WndProc(var Msg : TMessage); override;
  procedure ResetStatistics;
published
  property Timeout:cardinal read f_timeout write f_timeout;
  property Blocksize: byte read f_blocksize write f_blocksize default 64;
  property TimeToLive: byte read f_ttl write f_ttl default 255;
  property Hostname:string read f_hostname write f_hostname;
  property OnPing: TPingEvent read f_on_ping write f_on_ping;
end;
(*@\\\0000001C01*)
(*@///   TTraceRoute=class(TICMP) *)
TTraceRoute=class(TICMP)
protected
  f_on_route: TRouteEvent;
  f_route: TStringlist;
  f_resolve: boolean;
public
  constructor Create(Aowner:TComponent); override;
  procedure action; override;
  destructor Destroy; override;
  property Route: TStringList read f_route;
published
  property ResolveHostname:boolean read f_resolve write f_resolve default false;
  property Timeout:cardinal read f_timeout write f_timeout;
  property Blocksize: byte read f_blocksize write f_blocksize default 64;
  property TimeToLive: byte read f_ttl write f_ttl default 255;
  property Hostname:string read f_hostname write f_hostname;
  property OnRoute: TRouteEvent read f_on_route write f_on_route;
end;
(*@\\\*)

const
  uwm_socketevent = wm_user+$102; (* my magic message number *)

procedure Register;
(*@\\\0000001B01*)
(*@/// implementation *)
implementation

const
  f_packet_no: word = 0;

var
  hDll: THandle;
(*@/// function ICMP_checksum(var buf; length:integer):word; *)
function ICMP_checksum(var buf; length:integer):word;
var
  p: pointer;
  sum: longint;
  i: integer;
begin
  p:=@buf;
  sum:=0;
  for i:=1 to length div 2 do begin
    sum:=sum+word(p^);
    p:=pointer(longint(p)+2);
    end;
  if length mod 1<>0 then
    sum:=sum+byte(p^);

  sum:=(sum shr 16) + (sum and $ffff);
  sum:=sum+(sum shr 16);
  result:=word(NOT sum);
  end;
(*@\\\000000080A*)
(*@/// function now_ms:longint; *)
function now_ms:longint;
var
  systime : TSystemTime;
begin
  GetLocalTime(systime);  (* to leave the date unchanged *)
  result:=systime.wmilliseconds+1000*systime.wsecond+60000*systime.wminute;
  end;
(*@\\\0000000110*)

(*@/// class ticmp(TComponent) *)
(*@/// constructor TICMP.Create(Aowner:TComponent); *)
constructor TICMP.Create(Aowner:TComponent);
begin
  inherited create(AOwner);
  f_timeout:=5000;  (* 5 second *)
  f_blocksize:=64;
  f_ttl:=255;
  f_socket:=INVALID_SOCKET;
  icmp_handle:=invalid_handle_value;
  f_handle:=AllocateHwnd(self.WndProc);
  end;
(*@\\\0000000901*)
(*@/// destructor TICMP.Destroy; *)
destructor TICMP.Destroy;
begin
  if icmp_handle<>invalid_handle_value then
    ICMPCloseHandle(icmp_handle);
  if f_socket<>INVALID_SOCKET then
    Winsock.CloseSocket(f_socket);
  inherited destroy;
  end;
(*@\\\0000000508*)
(*@/// procedure TICMP.action; *)
procedure TICMP.action;
begin
  f_terminated:=false;
  f_replysize:=16+sizeof(t_icmp_echo_reply)+f_blocksize;
  f_address:=lookup_hostname(f_hostname);
  end;
(*@\\\0000000401*)
(*@/// procedure TICMP.Terminate; *)
procedure TICMP.Terminate;
begin
  f_terminated:=true;
  end;
(*@\\\*)
(*@/// procedure TICMP.OpenDll; *)
procedure TICMP.OpenDll;
begin
  if icmp_handle=invalid_handle_value then
    icmp_handle:=ICMPCreateFile;
  end;
(*@\\\0000000501*)
(*@/// procedure TICMP.OpenSocket; *)
procedure TICMP.OpenSocket;
begin
  if f_socket=INVALID_SOCKET then begin
    f_socket:=Winsock.Socket(PF_INET,SOCK_RAW,IPPROTO_ICMP);
    winsock.WSAAsyncSelect(f_socket,f_handle,uwm_socketevent,fd_read);
    end;
  end;
(*@\\\0000000401*)

(*@/// procedure TICMP.WndProc(var Msg : TMessage); *)
procedure TICMP.WndProc(var Msg : TMessage);
begin
  if msg.msg=wm_queryendsession then
    msg.result:=1
  end;
(*@\\\000C000301000301000301*)
(*@\\\000000081C*)
(*@/// class tping(TICMP) *)
(*@/// constructor TPing.Create(Aowner:TComponent); *)
constructor TPing.Create(Aowner:TComponent);
begin
  inherited create(AOwner);
  f_blocksize:=64;
  end;
(*@\\\0000000401*)
(*@/// procedure TPing.action; *)
procedure TPing.action;
var
  requestdata,replybuffer: pointer;
  p_reply: p_icmp_echo_reply;
  requestoptions: t_ip_options;
begin
  inherited action;
  case icmp_state of
(*@///     icmp_dll:       send and receive the ping packets via ICMP.DLL *)
icmp_dll: begin
  OpenDll;
  requestdata:=NIL;
  replybuffer:=NIL;
  f_replysize:=16+sizeof(t_icmp_echo_reply)+f_blocksize;
  try
    GetMem(requestdata,f_blocksize);
    fillchar(requestdata^,f_blocksize,#$a7);
    GetMem(replybuffer,f_replysize);

    requestoptions.ttl:=f_ttl;    (* a ping should live near infinity *)
    requestoptions.tos:=0;
    requestoptions.flags:=0;
    requestoptions.optionssize:=0;
    requestoptions.optionsdata:=NIL;

    if f_terminated then EXIT;
    inc(f_no_of_packets_snd);
    if ICMPSendEcho(icmp_handle,f_address,
                    requestdata,f_blocksize,
                    @requestoptions,
                    replybuffer,f_replysize,
                    f_timeout) = 1 then begin
      p_reply:=p_icmp_echo_reply(replybuffer);
      if assigned(f_on_ping) then
        f_on_ping(self,p_reply^.status,p_reply^.address,p_reply^.rttime);
      if (p_reply^.status=ip_success) and
         (p_reply^.address=f_address) then begin
        inc(f_no_of_packets_rec);
        UpdateStatistics(p_reply^.rttime);
        end;
      end
    else
      if assigned(f_on_ping) then
        f_on_ping(self,ip_req_timed_out,f_address,0);
  finally
    if requestdata<>NIL then
      FreeMem(requestdata,f_blocksize);
    if replybuffer<>NIL then
      FreeMem(replybuffer,f_replysize);
    end;
  end;
(*@\\\*)
(*@///     icmp_winsock*:  send the ping packets via winsock, receive is asynchron *)
icmp_winsock_ttl, icmp_winsock_dll, icmp_winsock: begin
  OpenSocket;
  if f_terminated then EXIT;
  inc(f_no_of_packets_snd);
  SendSock;
  end;
(*@\\\*)
    no_icmp: raise EICMPError.Create('No ICMP available');
    end;
  end;
(*@\\\0000000A01*)
(*@/// procedure TPing.ReceiveSock;             // receive a ICMP packet *)
procedure TPing.ReceiveSock;
type
(*@///   treply_buf=record *)
treply_buf=record
  ip_header  : t_ip_header;
  icmp_header: t_icmp_echo_request;
  time       : longint;
  end;
(*@\\\*)
var
  replybuffer: pointer;
  from: TSockAddrIn;
  whereto_len: integer;
begin
  replybuffer:=NIL;
  f_replysize:=sizeof(t_icmp_echo_request)+
               sizeof(t_ip_header)+
               sizeof(longint)+
               f_blocksize;
  try
    GetMem(replybuffer,f_replysize);
    from.sin_family:=AF_INET;
    from.sin_port:=0;
    from.sin_addr.S_addr:=f_address;
    recvfrom(f_socket,replybuffer^,f_replysize,0,from,whereto_len);
    if t_ip_header(replybuffer^).ip_hl_v=$45 then begin
        if (treply_buf(replybuffer^).icmp_header.icmp_id=word(self)) and
           assigned(f_on_ping) then
          f_on_ping(self,0,treply_buf(replybuffer^).ip_header.ip_src,
            now_ms-treply_buf(replybuffer^).time);
      end;
  finally
    if replybuffer<>NIL then
      FreeMem(replybuffer,f_replysize);
    end;
  end;
(*@\\\*)
(*@/// procedure TPing.SendSock;                // send a ICMP packet *)
procedure TPing.SendSock;
type
(*@///   ticmp_sendblock=record *)
ticmp_sendblock=record
  icmp_header: t_icmp_echo_request;
  time       : longint;
  data       : char;               (* to be extended dynamically *)
  end;
(*@\\\*)
(*@///   treply_buf=record *)
treply_buf=record
  ip_header  : t_ip_header;
  icmp_header: t_icmp_echo_request;
  time       : longint;
  end;
(*@\\\*)
var
  requestdata: pointer;
  whereto: TSockAddr;
  whereto_len: integer;
  rq_size: integer;
begin
  requestdata:=NIL;
  rq_size:=sizeof(t_icmp_echo_request)+f_blocksize+sizeof(longint);
  try
    GetMem(requestdata,rq_size);
    ticmp_sendblock(requestdata^).icmp_header.icmp_type := ICMP_ECHO;
    ticmp_sendblock(requestdata^).icmp_header.icmp_code := 0;
    ticmp_sendblock(requestdata^).icmp_header.icmp_cksum := 0;
    ticmp_sendblock(requestdata^).icmp_header.icmp_seq := f_packet_no;
    inc(f_packet_no);
    ticmp_sendblock(requestdata^).icmp_header.icmp_id := word(self);
    fillchar(ticmp_sendblock(requestdata^).data,f_blocksize,#$a7);
    ticmp_sendblock(requestdata^).time:=now_ms;
    ticmp_sendblock(requestdata^).icmp_header.icmp_cksum := ICMP_checksum(requestdata^,rq_size);
    whereto_len:=sizeof(whereto);
    whereto.sin_family:=AF_INET;
    whereto.sin_port:=0;
    whereto.sin_addr.S_addr:=f_address;
    if sendto(f_socket,requestdata^,rq_size,
      0,whereto,whereto_len)=SOCKET_ERROR then
        WSAGetLastError;
  finally
    if requestdata<>NIL then
      FreeMem(requestdata,sizeof(t_icmp_echo_request)+f_blocksize);
    end;
  end;
(*@\\\0000001501*)
(*@/// function TPing.GetRoundtimeMin:longint; *)
function TPing.GetRoundtimeMin:longint;
begin
  if f_roundtime_min=maxint then
    result:=-1
  else
    result:=f_roundtime_min;
  end;
(*@\\\0000000315*)
(*@/// function TPing.GetRoundtimeMed:extended; *)
function TPing.GetRoundtimeMed:extended;
begin
  if f_no_of_packets_rec>0 then
    result:=f_roundtime_med/f_no_of_packets_rec
  else
    result:=0;
  end;
(*@\\\000000060F*)
(*@/// procedure TPing.ResetStatistics; *)
procedure TPing.ResetStatistics;
begin
  f_no_of_packets_rec:=0;
  f_no_of_packets_snd:=0;
  f_roundtime_max:=-1;
  f_roundtime_min:=maxint;
  f_roundtime_med:=0;
  end;
(*@\\\0000000716*)
(*@/// procedure TPing.UpdateStatistics(roundtime:longint); *)
procedure TPing.UpdateStatistics(roundtime:longint);
begin
  if f_roundtime_min>roundtime then
    f_roundtime_min:=roundtime;
  if f_roundtime_max<roundtime then
    f_roundtime_max:=roundtime;
  f_roundtime_med:=f_roundtime_med+roundtime;
  end;
(*@\\\0000000701*)

(*@/// procedure TPing.WndProc(var Msg : TMessage); *)
procedure TPing.WndProc(var Msg : TMessage);
begin
  if msg.msg<>uwm_socketevent then
    inherited wndproc(msg)
  else begin
    if msg.lparamhi=socket_error then
    else begin
      case msg.lparamlo of
          fd_read: ReceiveSock;
        end;
      end;
    end;
  end;
(*@\\\0030000C01000C01000401*)
(*@\\\0000000A01*)
(*@/// class TTraceRoute(TICMP) *)
(*@/// constructor TTraceRoute.Create(Aowner:TComponent); *)
constructor TTraceRoute.Create(Aowner:TComponent);
begin
  inherited create(AOwner);
  f_blocksize:=64;
  f_route:=TStringlist.Create;
  f_resolve:=false;
  end;
(*@\\\0000000601*)
(*@/// procedure TTraceRoute.action; *)
procedure TTraceRoute.action;
var
  requestdata,replybuffer: pointer;
  p_reply: p_icmp_echo_reply;
  requestoptions: t_ip_options;
  i: integer;
begin
  inherited action;
  f_route.Clear;
  case icmp_state of
    icmp_dll,
    icmp_winsock_dll:  OpenDll;
    icmp_winsock_ttl:  raise EICMPError.Create('Not yet implemented');
    icmp_winsock,
    no_icmp:           raise EICMPError.Create('No ICMP.DLL found');
    end;

  requestdata:=NIL;
  replybuffer:=NIL;
  try
    GetMem(requestdata,f_blocksize);
    fillchar(requestdata^,f_blocksize,#$a7);
    f_replysize:=16+sizeof(t_icmp_echo_reply)+f_blocksize;
    GetMem(replybuffer,f_replysize);

    i:=0;
    while (i<f_ttl) do begin
      if f_terminated then BREAK;
      requestoptions.ttl:=i+1;
      requestoptions.tos:=0;
      requestoptions.flags:=0;
      requestoptions.optionssize:=0;
      requestoptions.optionsdata:=NIL;

      if ICMPSendEcho(icmp_handle,f_address,
                      requestdata,f_blocksize,
                      @requestoptions,
                      replybuffer,f_replysize,
                      f_timeout) = 1 then begin
        p_reply:=p_icmp_echo_reply(replybuffer);
        if (p_reply^.status=ip_success) and
           (p_reply^.address=f_address) then begin
           f_terminated:=true;
           inc(i);
          end
        else if (p_reply^.status=ip_ttl_expired_transmit) then
          inc(i)
        else
          {};
        if ((p_reply^.status=ip_success) or
           (p_reply^.status=ip_ttl_expired_transmit)) then begin
          if f_resolve then
            f_route.add(resolve_hostname(p_reply^.address))
          else
            f_route.add(ip2string(p_reply^.address));
          if assigned(f_on_route) then
            f_on_route(self,i,p_reply^.address,p_reply^.rttime);
          end;
        end;
      end;
  finally
    if requestdata<>NIL then
      FreeMem(requestdata,f_blocksize);
    if replybuffer<>NIL then
      FreeMem(replybuffer,f_replysize);
    end;
  end;
(*@\\\*)
(*@/// destructor TTraceRoute.Destroy; *)
destructor TTraceRoute.Destroy;
begin
  f_route.Free;
  inherited destroy;
  end;
(*@\\\0000000310*)
(*@\\\0000000301*)

(*@/// procedure shutdown; FAR; *)
procedure shutdown; FAR;
begin
  if hDll<>0 then  FreeLibrary(hDll);
  end;
(*@\\\0000000301*)

(*@/// procedure Register; *)
procedure Register;
begin
  RegisterComponents('Internet', [TPing]);
  RegisterComponents('Internet', [TTraceRoute]);
  end;
(*@\\\000000042E*)
(*@\\\0000000B14*)
(*@/// initialization *)
var
  f_socket: TSocket;
  h: integer;
(*@/// function check_dll:boolean; *)
function check_dll:boolean;
begin
  SetErrorMode(sem_NoOpenFileErrorBox);   (* keep it silent *)
  hDll:=LoadLibrary('ICMP.DLL');
  if hdll<>0 then begin
    @ICMPCreateFile:=GetProcAddress(hdll,'IcmpCreateFile');
    @ICMPCloseHandle:=GetProcAddress(hdll,'IcmpCloseHandle');
    @ICMPSendEcho:=GetProcAddress(hdll,'IcmpSendEcho');
    result:=true;
    end
  else
    result:=false;        (* no ICMP possible *)
  end;
(*@\\\*)
(*$ifdef ver80 *)
begin
(*$else *)
initialization
begin
(*$endif *)
  f_socket:=Winsock.Socket(PF_INET,SOCK_RAW,IPPROTO_ICMP);  (* check for raw socket *)
  if f_socket=INVALID_SOCKET then begin
    if check_dll then
      icmp_state:=icmp_dll
    else
      icmp_state:=no_icmp;
    end
  else begin
    h:=64;   (* just an arbitrary number *)
    if Winsock.SetSockOpt(f_socket,IPPROTO_IP, IP_TTL, pchar(@h), sizeof(h))<>0 then begin
      winsock.WSAGetLastError;
      if check_dll then
        icmp_state:=icmp_winsock_dll
      else
        icmp_state:=icmp_winsock;
      end
    else
      icmp_state:=icmp_winsock_ttl;
    closesocket(f_socket);
    end;
(*@\\\0000000401*)
(*@/// finalization *)
(*$ifdef ver80 *)
  AddExitProc(Shutdown);
(*$else *)
  end;
finalization
  Shutdown;
(*$endif *)
(*@\\\*)
end.
(*@\\\0003000301000011000301*)

// Ende der Unit ICMP.PAS







unit ip_misc;
(*@/// interface *)
interface
  (*$x+ *)

(*@/// uses *)
uses
  sysutils,
(*$ifdef ver80 *)
  winprocs,
  wintypes,
(*$else *)
  windows,
(*$endif *)
  winsock,
  classes;
(*@\\\*)

var
  tcpip_ready: boolean;
const
  INVALID_IP_ADDRESS= $ffffffff;  (* only invalid as a host ip, maybe OK for broadcast *)

type
  ta_8u=packed array [0..65530] of byte;
  t_encoding=(uuencode,base64,mime);

(* The date in RFC 822 conform string format *)
function internet_date(date: TDateTime):string;

(* Hostname (or IP-String) -> ip-address (in network order) *)
function lookup_hostname(const hostname:string):longint;

(* Name of the local computer *)
function my_hostname:string;

(* (Main) IP address of the local computer (network order *)
function my_ip_address:longint;

(* IP-Address (network order) -> ###.###.###.### *)
function ip2string(ip_address:longint):string;

(* IP-Address (network order) -> (Main) hostname *)
function resolve_hostname(ip: longint):string;

(* Parse the n'th email address out of a string *)
function address_from(const s:string; count: integer):string;

(* Binary stream -> Base64 (MIME) encoded strings and back *)
function encode_base64(data: TStream):TStringList;
function decode_base64(source:TStringList):TMemoryStream;

(* Find n'th occurence of a substring, from left or from right *)
function posn(const s,t:string; count:integer):integer;

(* Find the n'th char unequal from left or from right *)
function poscn(c:char; const s:string; n: integer):integer;

(* Parse the filename out of a DOS/UNC file and path name *)
function filename_of(const s:string):string;

(* Delphi 1 didn't know these, but they are useful/necessary for D2/D3 *)
(*$ifdef ver80 *)
function trim(const s:string):string;
procedure setlength(var s:string; l: byte);
(*$endif *)

(* The offset to UTC/GMT in minutes of the local time zone *)
function TimeZoneBias:longint;

(* Convert 8bit to 7bit and back *)
function eight2seven_quoteprint(const s:string):string;
function eight2seven_german(const s:string):string;
function seven2eight_quoteprint(const s:string):string;
(*@\\\0000000401*)
(*@/// implementation *)
implementation

(*@/// Some string utility functions *)
(*@/// function posn(const s,t:string; count:integer):integer; *)
function posn(const s,t:string; count:integer):integer;

{ find the count'th occurence of the substring,
  if count<0 then look from the back }


var
  i,h,last: integer;
  u: string;
begin
  u:=t;
  if count>0 then begin
    result:=length(t);
    for i:=1 to count do begin
      h:=pos(s,u);
      if h>0 then
        u:=copy(u,pos(s,u)+1,length(u))
      else begin
        u:='';
        inc(result);
        end;
      end;
    result:=result-length(u);
    end
  else if count<0 then begin
    last:=0;
    for i:=length(t) downto 1 do begin
      u:=copy(t,i,length(t));
      h:=pos(s,u);
      if (h<>0) and (h+i<>last) then begin
        last:=h+i-1;
        inc(count);
        if count=0 then BREAK;
        end;
      end;
    if count=0 then result:=last
               else result:=0;
    end
  else
    result:=0;
  end;
(*@\\\*)
(*@/// function poscn(c:char; const s:string; n: integer):integer; *)
function poscn(c:char; const s:string; n: integer):integer;

{ Find the n'th occurence of a character different to c,
  if n<0 look from the back }


var
  i: integer;
begin
  if n=0 then  n:=1;
  if n>0 then begin
    for i:=1 to length(s) do begin
      if s[i]<>c then begin
        dec(n);
        result:=i;
        if n=0 then begin
          EXIT;
          end;
        end;
      end;
    end
  else begin
    for i:=length(s) downto 1 do begin
      if s[i]<>c then begin
        inc(n);
        result:=i;
        if n=0 then begin
          EXIT;
          end;
        end;
      end;
    end;
  poscn:=0;
  end;
(*@\\\0000000C10*)
(*@/// function filename_of(const s:string):string; *)
function filename_of(const s:string):string;
var
  t:integer;
begin
  t:=posn('\',s,-1);
  if t>0 then
    result:=copy(s,t+1,length(s))
  else begin
    t:=posn(':',s,-1);
    if t>0 then
      result:=copy(s,t+1,length(s))
    else
      result:=s;
    end;
  end;
(*@\\\000000012D*)
(*$ifdef ver80 *)
(*@/// function trim(const s:string):string; *)
function trim(const s:string):string;
var
  h: integer;
begin
  (* trim from left *)
  h:=poscn(' ',s,1);
  if h>0 then
    result:=copy(s,h,length(s))
  else
    result:=s;
  (* trim from right *)
  h:=poscn(' ',result,-1);
  if h>0 then
    result:=copy(result,1,h);
  end;
(*@\\\0000000C0B*)
(*@/// procedure setlength(var s:string; l: byte); *)
procedure setlength(var s:string; l: byte);
begin
  s[0]:=char(l);
  end;
(*@\\\000000012C*)
(*$endif *)
(*@\\\0000000201*)

(*@/// function TimeZoneBias:longint;          // in minutes ! *)
function TimeZoneBias:longint;
(*@/// 16 bit way: try a 32bit API call via thunking layer, if that fails try the TZ *)
(*$ifdef ver80 *)
(*@/// function GetEnvVar(const s:string):string; *)
function GetEnvVar(const s:string):string;
var
  L: Word;
  P: PChar;
begin
  L := length(s);
  P := GetDosEnvironment;
  while P^ <> #0 do begin
    if (StrLIComp(P, PChar(@s[1]), L) = 0) and (P[L] = '=') then begin
      GetEnvVar := StrPas(P + L + 1);
      EXIT;
      end;
    Inc(P, StrLen(P) + 1);
    end;
  GetEnvVar := '';
  end;
(*@\\\0000000922*)

(*@/// function day_in_month(month,year,weekday: word; count: integer):TDateTime; *)
function day_in_month(month,year,weekday: word; count: integer):TDateTime;
var
  h: integer;
begin
  if count>0 then begin
    h:=dayofweek(encodedate(year,month,1));
    h:=((weekday-h+7) mod 7) +1 + (count-1)*7;
    result:=encodedate(year,month,h);
    end
  else begin
    h:=dayofweek(encodedate(year,month,1));
    h:=((weekday-h+7) mod 7) +1 + 6*7;
    while count<0 do begin
      h:=h-7;
      try
        result:=encodedate(year,month,h);
        inc(count);
        if count=0 then EXIT;
      except
        end;
      end;
    end;
  end;
(*@\\\*)
(*@/// function DayLight_Start:TDateTime;     // american way ! *)
function DayLight_Start:TDateTime;
var
  y,m,d: word;
begin
  DecodeDate(now,y,m,d);
  result:=day_in_month(4,y,1,1);
  (* for european one: day_in_month(3,y,1,-1) *)
  end;
(*@\\\0000000701*)
(*@/// function DayLight_End:TDateTime;       // american way ! *)
function DayLight_End:TDateTime;
var
  y,m,d: word;
begin
  DecodeDate(now,y,m,d);
  result:=day_in_month(10,y,1,-1);
  end;
(*@\\\000000060B*)
type    (* stolen from windows.pas *)
(*@///   TSystemTime = record ... end; *)
PSystemTime = ^TSystemTime;
TSystemTime = record
  wYear: Word;
  wMonth: Word;
  wDayOfWeek: Word;
  wDay: Word;
  wHour: Word;
  wMinute: Word;
  wSecond: Word;
  wMilliseconds: Word;
end;
(*@\\\0000000201*)
(*@///   TTimeZoneInformation = record ... end; *)
TTimeZoneInformation = record
  Bias: Longint;
  StandardName: array[0..31] of word;  (* wchar *)
  StandardDate: TSystemTime;
  StandardBias: Longint;
  DaylightName: array[0..31] of word;  (* wchar *)
  DaylightDate: TSystemTime;
  DaylightBias: Longint;
  end;
(*@\\\*)
var
  tz_info: TTimeZoneInformation;
  LL32:function (LibFileName: PChar; handle: longint; special: longint):Longint;
  FL32:function (hDll: Longint):boolean;
  GA32:function (hDll: Longint; functionname: PChar):longint;
  CP32:function (buffer:TTimeZoneInformation; prochandle,adressconvert,dwParams:Longint):longint;
  hdll32,dummy,farproc: longint;
  hdll:THandle;
  sign: integer;
  s: string;
begin
  hDll:=GetModuleHandle('kernel');                  { get the 16bit handle of kernel }
  @LL32:=GetProcAddress(hdll,'LoadLibraryEx32W');   { get the thunking layer functions }
  @FL32:=GetProcAddress(hdll,'FreeLibrary32W');
  @GA32:=GetProcAddress(hdll,'GetProcAddress32W');
  @CP32:=GetProcAddress(hdll,'CallProc32W');
(*@///   if possible then   call GetTimeZoneInformation via Thunking *)
if (@LL32<>NIL) and
   (@FL32<>NIL) and
   (@GA32<>NIL) and
   (@CP32<>NIL) then begin
  hDll32:=LL32('kernel32.dll',dummy,1);            { get the 32bit handle of kernel32 }
  farproc:=GA32(hDll32,'GetTimeZoneInformation');  { get the 32bit adress of the function }
  case CP32(tz_info,farproc,1,1) of                { and call it }
    1: result:=tz_info.StandardBias+tz_info.Bias;
    2: result:=tz_info.DaylightBias+tz_info.Bias;
    else result:=0;
    end;
  FL32(hDll32);                                    { and free the 32bit dll }
  end
(*@\\\0000000501*)
(*@///   else  calculate the bias out of the TZ environment variable *)
else begin
  s:=GetEnvVar('TZ');
  while (length(s)>0) and (not(s[1] in ['+','-','0'..'9'])) do
    s:=copy(s,2,length(s));
  case s[1] of
(*@///     '+': *)
'+': begin
  sign:=1;
  s:=copy(s,2,length(s));
  end;
(*@\\\*)
(*@///     '-': *)
'-': begin
  sign:=-1;
  s:=copy(s,2,length(s));
  end;
(*@\\\000000030A*)
    else sign:=1;
    end;
  try
    result:=strtoint(copy(s,1,2))*60;
    s:=copy(s,3,length(s));
  except
    try
      result:=strtoint(s[1])*60;
      s:=copy(s,2,length(s));
    except
      result:=0;
      end;
    end;
(*@///   if s[1]=':' then    minutes offset *)
if s[1]=':' then begin
  try
    result:=result+strtoint(copy(s,2,2));
    s:=copy(s,4,length(s));
  except
    try
      result:=result+strtoint(s[2]);
      s:=copy(s,3,length(s));
    except
      end;
    end;
  end;
(*@\\\0000000A01*)
(*@///   if s[1]=':' then    seconds offset - ignored *)
if s[1]=':' then begin
  try
    strtoint(copy(s,2,2));
    s:=copy(s,4,length(s));
  except
    try
      strtoint(s[2]);
      s:=copy(s,3,length(s));
    except
      end;
    end;
  end;
(*@\\\0000000A01*)
  result:=result*sign;
(*@///   if length(s)>0 then daylight saving activated, calculate it *)
if length(s)>0 then begin
  (* forget about the few hours on the start/end day *)
  if (now>daylight_start) and (now<DayLight_End+1) then
    result:=result-60;
  end;
(*@\\\0000000401*)
  end;
(*@\\\*)
  end;
(*@\\\0000000201*)
(*@/// 32 bit way: API call GetTimeZoneInformation *)
(*$else *)
var
  tz_info: TTimeZoneInformation;
begin
  case GetTimeZoneInformation(tz_info) of
    1: result:=tz_info.StandardBias+tz_info.Bias;
    2: result:=tz_info.DaylightBias+tz_info.Bias;
    else result:=0;
    end;
  end;
(*$endif *)
(*@\\\*)
(*@\\\0000000301*)

const
  bin2uue:string='`!"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';
  bin2b64:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  uue2bin:string=' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ ';
  b642bin:string='~~~~~~~~~~~^~~~_TUVWXYZ[\]~~~|~~~ !"#$%&''()*+,-./0123456789~~~~~~:;<=>?@ABCDEFGHIJKLMNOPQRS';
  linesize = 45;

(*@/// function decode_line(mode:t_encoding; const inp:string):string; *)
function decode_line(mode:t_encoding; const inp:string):string;
var
  count,pos1,pos2: integer;
  offset: shortint;
  s: string;
  out: string;
begin
  s:=inp;
  setlength(out,length(s)*3 div 4 +3);
  fillchar(out[1],length(s)*3 div 4 +3,#0);   (* worst case *)
  if (mode=uuencode) and not (s[1] in [' '..'M','`']) then
    count:=0   (* ignored line *)
  else begin
    count:=0; pos1:=0;  (* Delphi 2 Shut up! *)
    case mode of  (* !!! No check for invalid data yet *)
(*@///       uuencode:    set count,pos1, string -> Data into $00..$3F *)
uuencode: begin
  count:=(ord(s[1]) - $20) and $3f;
  for pos1:=2 to length(s) do
    s[pos1]:=char(ord(uue2bin[ord(s[pos1])-$20+1])-$20);
  pos1:=2;
  end;
(*@\\\000000031B*)
(*@///       base64,mime: set count,pos1, string -> Data into $00..$3F *)
base64,mime: begin
{   count:=length(s)*3 div 4; }
  count:=poscn('=',s,-1)*3 div 4;
  for pos1:=1 to length(s) do
    s[pos1]:=char(ord(b642bin[ord(s[pos1])-$20+1])-$20);
  pos1:=1;
  end;
(*@\\\000000041F*)
      end;
    pos2:=1;
    offset:=2;
    while pos2<=count do begin
      if (pos1>length(s)) or ((mode<>uuencode) and (s[pos1]='\'))  then begin
        if offset<>2 then inc(pos2);
        count:=pos2-1;
        end
      else if ((mode<>uuencode) and (s[pos1]='^')) then   (* illegal char in source *)
        inc(pos1)  (* skip char, prevent endless loop jane :*)
      else if offset>0 then begin
        out[pos2]:=char(ord(out[pos2]) or (ord(s[pos1]) shl offset));
        inc(pos1);
        offset:=offset-6;
        end
      else if offset<0 then begin
        offset:=abs(offset);
        out[pos2]:=char(ord(out[pos2]) or (ord(s[pos1]) shr offset));
        inc(pos2);
        offset:=8-offset;
        end
      else begin
        out[pos2]:=char(ord(out[pos2]) or ord(s[pos1]));
        inc(pos1);
        inc(pos2);
        offset:=2;
        end;
      end;
    end;
  decode_line:=copy(out,1,count);
  end;
(*@\\\0000001101*)
(*@/// function encode_line(mode:t_encoding; const buf; size:integer):string; *)
function encode_line(mode:t_encoding; const buf; size:integer):string;
var
  buff: ta_8u absolute buf;
  offset: shortint;
  pos1,pos2: byte;
  i: byte;
  out: string;
begin
  setlength(out,size*4 div 3 + 4);
  fillchar(out[1],size*4 div 3 +2,#0);   (* worst case *)
  if mode=uuencode then begin
    out[1]:=char(((size-1) and $3f)+$21);
    size:=((size+2) div 3)*3;
    end;
  offset:=2;
  pos1:=0;
  pos2:=0;   (* Delphi 2 Shut up! *)
  case mode of
    uuencode:     pos2:=2;
    base64, mime: pos2:=1;
  end;
  out[pos2]:=#0;
(*@///   while pos1<size do begin ... end;     Das eigentliche Encoding *)
while pos1<size do begin
  if offset > 0 then begin
    out[pos2]:=char(ord(out[pos2]) or ((buff[pos1] and ($3f shl offset)) shr offset));
    offset:=offset-6;
    inc(pos2);
    out[pos2]:=#0;
    end
  else if offset < 0 then begin
    offset:=abs(offset);
    out[pos2]:=char(ord(out[pos2]) or ((buff[pos1] and ($3f shr offset)) shl offset));
    offset:=8-offset;
    inc(pos1);
    end
  else begin
    out[pos2]:=char(ord(out[pos2]) or ((buff[pos1] and $3f)));
    inc(pos2);
    inc(pos1);
    out[pos2]:=#0;
    offset:=2;
    end;
  end;
(*@\\\0000000D01*)
  case mode of
(*@///     uuencode: *)
uuencode: begin
  if offset=2 then dec(pos2);
  for i:=2 to pos2 do
    out[i]:=bin2uue[ord(out[i])+1];
  end;
(*@\\\0000000401*)
(*@///     base64, mime: *)
base64, mime: begin
  if offset=2 then dec(pos2);
  for i:=1 to pos2 do
    out[i]:=bin2b64[ord(out[i])+1];
  while (pos2 and 3)<>0  do begin
    inc(pos2);
    out[pos2]:='=';
    end;
  end;
(*@\\\0000000301*)
    end;
  encode_line:=copy(out,1,pos2);
  end;
(*@\\\0000001A0E*)

(*@/// function encode_base64(data: TStream):TStringList; *)
function encode_base64(data: TStream):TStringList;
var
  buf: pointer;
  size: integer;
begin
  buf:=NIL;
{   result:=NIL; }
  try
    result:=TStringList.Create;
    getmem(buf,linesize);
    data.seek(0,0);
    size:=linesize;
    while size>0 do begin
      size:=data.read(buf^,linesize);
      if size>0 then
        result.add(encode_line(base64,buf^,size));
      end;
  finally
    if buf<>NIL then
      freemem(buf,linesize);
    end;
  end;
(*@\\\0000000201*)
(*@/// function decode_base64(source:TStringList):TMemoryStream; *)
function decode_base64(source:TStringList):TMemoryStream;
var
  i: integer;
  s: string;
begin
  result:=TMemoryStream.Create;
  for i:=0 to source.count-1 do begin
    s:=decode_line(base64,source[i]);
    result.write(s[1],length(s));
    end;
  end;
(*@\\\0000000701*)

(*@/// function eight2seven_quoteprint(const s:string):string; *)
function eight2seven_quoteprint(const s:string):string;
var
  i: integer;
begin
  result:='';
  for i:=1 to length(s) do
    case s[i] of
      '=',#$80..#$FF: result:=result+'='+uppercase(inttohex(ord(s[i]),2));
      else            result:=result+s[i];
      end;
  end;
(*@\\\0000000201*)
(*@/// function eight2seven_german(const s:string):string; *)
function eight2seven_german(const s:string):string;
var
  i: integer;
begin
  result:='';
  for i:=1 to length(s) do
    case s[i] of
      #192..#195,#197: result:=result+'A';
      #196,#198:       result:=result+'Ae';
      #199:            result:=result+'C';
      #200..#203:      result:=result+'E';
      #204..#207:      result:=result+'I';
      #209:            result:=result+'N';
      #210..#213,#216: result:=result+'O';
      #214:            result:=result+'Oe';
      #217..#219:      result:=result+'U';
      #220:            result:=result+'Ue';
      #221:            result:=result+'Y';
      #223:            result:=result+'ss';
      #224..#227,#229: result:=result+'a';
      #228,#230:       result:=result+'ae';
      #231:            result:=result+'c';
      #232..#235:      result:=result+'e';
      #236..#239:      result:=result+'i';
      #241:            result:=result+'n';
      #242..#245,#248: result:=result+'o';
      #246:            result:=result+'oe';
      #249..#251:      result:=result+'u';
      #252:            result:=result+'ue';
      #255:            result:=result+'y';
      #0..#60,#62..#127: result:=result+s[i];
      else result:=result+'='+uppercase(inttohex(ord(s[i]),2));
      end;
  end;
(*@\\\*)
(*@/// function seven2eight_quoteprint(const s:string):string; *)
function seven2eight_quoteprint(const s:string):string;
var
  i: integer;
begin
  result:='';
  i:=0;
  while i<length(s) do begin
    inc(i);
    case s[i] of
      '=': try
          result:=result+char(strtoint('$'+s[i+1]+s[i+2]));
          i:=i+2;
        except
          result:=result+'=';
        end;
      else    result:=result+s[i];
      end;
    end;
  end;
(*@\\\0000001209*)


(*@/// function my_hostname:string; *)
function my_hostname:string;
const
  bufsize=255;
var
  buf: pointer;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  my_hostname:='';
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    if char(buf^)<>#0 then begin
      RemoteHost:=Winsock.GetHostByName(buf);
      if RemoteHost<>NIL then
(*$ifdef ver80 *)
        my_hostname:=strpas(pchar(RemoteHost^.h_name))
(*$else *)
        my_hostname:=pchar(RemoteHost^.h_name)
(*$endif *)
      else my_hostname:='127.0.0.1';    (* no Hostname received *)
      end
    else my_hostname:='127.0.0.1';      (* no Hostname received *)
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  end;
(*@\\\*)
(*@/// function my_ip_address:longint; *)
function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    RemoteHost:=Winsock.GetHostByName(buf);
    if RemoteHost=NIL then
      my_ip_address:=winsock.htonl($7F000001)  (* 127.0.0.1 *)
    else
      my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  end;
(*@\\\0030000E01000E01000E01*)
(*@/// function internet_date(date: TDateTime):string; *)
function internet_date(date: TDateTime):string;
(*@/// function myinttostr(value:integer; len:byte):string; *)
function myinttostr(value:integer; len:byte):string;
begin
  myinttostr:=inttostr(value);
  while length(result)<len do
    result:='0'+result;
  end;
(*@\\\*)
(*@/// function timezone:string; *)
function timezone:string;
var
  bias: longint;
begin
  bias:=TimeZoneBias;
  if bias=0 then
    timezone:='GMT'
  else if bias<0 then
    timezone:='+' + myinttostr(abs(bias) div 60,2)
                  + myinttostr(abs(bias) mod 60,2)
  else if bias>0 then
    timezone:='-' + myinttostr(bias div 60,2)
                  + myinttostr(bias mod 60,2);
  end;
(*@\\\*)
var
  d,m,y,w,h,mm,s,ms: word;
const
  weekdays:array[1..7] of string[3]=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  months:array[1..12] of string[3]=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
begin
  decodedate(date,y,m,d);
  decodetime(date,h,mm,s,ms);
  w:=dayofweek(date);
  internet_date:=weekdays[w]+', '+inttostr(d)+' '+months[m]+' '+inttostr(y)+' '+
     myinttostr(h,2)+':'+myinttostr(mm,2)+':'+myinttostr(s,2)+' '+timezone;
  end;
(*@\\\0000000201*)
(*@/// function ip2string(ip_address:longint):string; *)
function ip2string(ip_address:longint):string;
begin
  ip_address:=winsock.ntohl(ip_address);
  result:= inttostr(ip_address shr 24)+'.'+
           inttostr((ip_address shr 16) and $ff)+'.'+
           inttostr((ip_address shr 8) and $ff)+'.'+
           inttostr(ip_address and $ff);
  end;
(*@\\\0000000401*)

(*@/// function address_from(const s:string; count: integer):string; *)
function address_from(const s:string; count: integer):string;
var
  p, ca, sp, co, se: integer;
begin
  (* search the count'th @ *)
  ca:=posn('@',s,count);
  if (ca=0) or (ca>length(s)) then
    result:=''
  else begin
    (* search for delimiting char before the @ *)
    sp:=posn(' ',copy(s,1,ca),-1);
    co:=posn(',',copy(s,1,ca),-1);
    se:=posn(';',copy(s,1,ca),-1);
    p:=0;
    if (sp<ca) and (sp>p) then  p:=sp;
    if (co<ca) and (co>p) then  p:=co;
    if (se<ca) and (se>p) then  p:=se;
    result:=copy(s,p+1,length(s));
    (* search for delimiting char after the @ *)
    sp:=posn(' ',result,1)-1;
    co:=posn(',',result,1)-1;
    se:=posn(';',result,1)-1;
    ca:=length(result);
    p:=ca+1;
    if (sp<p) and (sp>0) and (sp<ca) then  p:=sp;
    if (co<p) and (co>0) and (co<ca) then  p:=co;
    if (se<p) and (se>0) and (se<ca) then  p:=se;
    result:=copy(result,1,p-1);
    while result[1] in ['"','(','<'] do
      result:=copy(result,2,length(result));
    while result[length(result)] in ['"',')','>'] do
      result:=copy(result,1,length(result)-1);
    end;
  end;
(*@\\\0000001F35*)

(*@/// function lookup_hostname(const hostname:string):longint; *)
function lookup_hostname(const hostname:string):longint;
var
  RemoteHost : PHostEnt;  (* no, don't free it! *)
  ip_address: longint;
(*$ifdef ver80 *)
  s: string;
(*$else *)
(*$ifopt h- *)
  s: string;
(*$endif *)
(*$endif *)
begin
  ip_address:=INVALID_IP_ADDRESS;
  try
    if hostname='' then begin  (* no host given! *)
      lookup_hostname:=ip_address;
      EXIT;
      end
    else begin
(*@///       ip_address:=Winsock.Inet_Addr(PChar(hostname));  { try a xxx.xxx.xxx.xx first } *)
(*$ifdef ver80 *)
  s:=hostname+#0;
  ip_address:=Winsock.Inet_Addr(PChar(@s[1]));  (* try a xxx.xxx.xxx.xx first *)
(*$else *)
 (*$ifopt h- *)
  s:=hostname+#0;
  ip_address:=Winsock.Inet_Addr(PChar(@s[1]));  (* try a xxx.xxx.xxx.xx first *)
 (*$else *)
  ip_address:=Winsock.Inet_Addr(PChar(hostname));  (* try a xxx.xxx.xxx.xx first *)
 (*$endif *)
(*$endif *)
(*@\\\*)
      if ip_address=SOCKET_ERROR then begin
(*@///         RemoteHost:=Winsock.GetHostByName(PChar(hostname)); *)
(*$ifdef ver80 *)
  RemoteHost:=Winsock.GetHostByName(PChar(@s[1]));
(*$else *)
 (*$ifopt h- *)
  RemoteHost:=Winsock.GetHostByName(PChar(@s[1]));
 (*$else *)
  RemoteHost:=Winsock.GetHostByName(PChar(hostname));
 (*$endif *)
(*$endif *)
(*@\\\000000090C*)
        if (RemoteHost=NIL) or (RemoteHost^.h_length<=0) then begin
          lookup_hostname:=ip_address;
          EXIT;  (* host not found *)
          end
        else
          ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
            (* use the first address given *)
        end;
      end;
  except
    ip_address:=INVALID_IP_ADDRESS;
    end;
  lookup_hostname:=ip_address;
  end;
(*@\\\0000001601*)
(*@/// function resolve_hostname(ip: longint):string; *)
function resolve_hostname(ip: longint):string;
var
  RemoteHost : PHostEnt; (* No, don't free it! *)
  ip_address: longint;
begin
  ip_address:=ip;
  RemoteHost:=Winsock.GetHostByAddr(@ip_address,4,pf_inet);
  if RemoteHost<>NIL then
(*$ifdef ver80 *)
    resolve_hostname:=strpas(pchar(RemoteHost^.h_name))
(*$else *)
    resolve_hostname:=pchar(RemoteHost^.h_name)
(*$endif *)
  else
    resolve_hostname:=ip2string(ip_address);
  end;
(*@\\\0000001007*)

{ Initialize and clean up the winsock DLL }
(*@/// procedure init; *)
procedure init;
var
  point: TWSAData;
begin
  tcpip_ready:=false;
  if @Winsock.WSAStartup<>NIL then
    case Winsock.WSAStartup($0101,point) of
      WSAEINVAL, WSASYSNOTREADY, WSAVERNOTSUPPORTED: ;
      else tcpip_ready:=true;
      end;
  end;
(*@\\\0000000503*)
(*@/// procedure shutdown; FAR; *)
procedure shutdown; FAR;
begin
  if tcpip_ready then begin
    Winsock.WSACancelBlockingCall;
    Winsock.WSACleanup;
    end;
  end;
(*@\\\0000000601*)
(*@\\\0000000501*)
(*@/// initialization *)
(*$ifdef ver80 *)
begin
(*$else *)
initialization
begin
(*$endif *)
  init;
(*@\\\*)
(*@/// finalization *)
(*$ifdef ver80 *)
  AddExitProc(Shutdown);
(*$else *)
  end;
finalization
  Shutdown;
(*$endif *)
(*@\\\000000070C*)
end.
(*@\\\0000000305*)

// Ende der Unit IC_MISC.PAS



unit u_ping;
(*@/// interface *)
interface

(*@/// uses *)
uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  icmp,
  ExtCtrls;
(*@\\\0000000C01*)

type
(*@///   Tfrm_ping = class(TForm) *)
Tfrm_ping = class(TForm)
  Ping: TPing;
  lbl_host: TLabel;
  edt_hostname: TEdit;
  mem_out: TMemo;
  btn_start: TButton;
  btn_break: TButton;
  Timer: TTimer;
  procedure btn_startClick(Sender: TObject);
  procedure PingPing(sender:TObject; status:Integer; ip,roundtime:Longint);
  procedure btn_breakClick(Sender: TObject);
  procedure TimerTimer(Sender: TObject);
end;
(*@\\\0000000A1D*)

var
  frm_ping: Tfrm_ping;
(*@\\\0000000301*)
(*@/// implementation *)
implementation

{$R *.DFM}

uses
  ip_misc;

var
  nr: integer;

(*@/// procedure Tfrm_ping.btn_startClick(Sender: TObject); *)
procedure Tfrm_ping.btn_startClick(Sender: TObject);
begin
  ping.hostname:=edt_hostname.text;
  mem_out.lines.clear;
  nr:=0;
  timer.enabled:=true;
  end;
(*@\\\*)
(*@/// procedure Tfrm_ping.PingPing(sender:TObject; status:Integer; ip,roundtime:Longint); *)
procedure Tfrm_ping.PingPing(sender:TObject; status:Integer; ip,roundtime:Longint);
begin
  inc(nr);
  case status of
    ip_success:
      mem_out.lines.add(inttostr(nr)+'. '+inttostr(roundtime)+'ms');
    else
      mem_out.lines.add(inttostr(nr)+'. Failed')
    end;
end;
(*@\\\003E000601000601000801000A01000709000709*)
(*@/// procedure Tfrm_ping.btn_breakClick(Sender: TObject); *)
procedure Tfrm_ping.btn_breakClick(Sender: TObject);
begin
  ping.terminate;
  timer.enabled:=false;
  end;
(*@\\\*)
(*@/// procedure Tfrm_ping.TimerTimer(Sender: TObject); *)
procedure Tfrm_ping.TimerTimer(Sender: TObject);
begin
  ping.action;
  end;
(*@\\\*)
(*@\\\0000000C31*)
end.
(*@\\\0001000011000301*)
// Ende der Unit U_PING.PAS



Inhalt der Datei AH_COMP.DPK

package ah_comp;

{$R *.RES}
{$R 'icmp.dcr'}
{$ALIGN ON}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO OFF}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST ON}
{$MINENUMSIZE 1}
{$IMAGEBASE $00400000}
{$DESCRIPTION 'Andreas Hörstemeier''s components'}
{$DESIGNONLY}
{$IMPLICITBUILD ON}

requires
  Vcl30;

contains
  Icmp;

end.




Moderiert von user profile iconUGrohne: Delphi-Tags hinzugefügt.