10
10
import java .net .Socket ;
11
11
import java .net .SocketException ;
12
12
import java .util .ArrayList ;
13
+ import java .util .Arrays ;
13
14
import java .util .HashMap ;
14
15
import java .util .List ;
15
16
import java .util .Map ;
@@ -26,11 +27,17 @@ public Router() throws IOException {
26
27
while (i < 2 ) {
27
28
System .out .println ("Vor getpacket" );
28
29
ipp = nl .getPacket ();
29
-
30
30
System .out .println (ipp .getDestinationAddress ());
31
31
System .out .println (ipp .getSourceAddress ());
32
-
33
- if (!routtable .containsKey (String .valueOf (ipp .getDestinationAddress ()))) {
32
+ ipp .setHopLimit (ipp .getHopLimit ()-1 );
33
+ if (ipp .getHopLimit ()<1 ){
34
+ ControlPacket .Type controlType = ControlPacket .Type .valueOf ("TimeExceeded" );
35
+ ControlPacket controlPacket = new ControlPacket (controlType , new byte [0 ]);
36
+ ipp .setControlPayload (controlPacket .getBytes ());
37
+ // ipp.setDestinationAddress(ipp.getSourceAddress());
38
+ // ipp.setNextHopIp(ipp.getDestinationAddress());
39
+ nl .sendPacket (ipp );
40
+ } else if (!routtable .containsKey (String .valueOf (ipp .getDestinationAddress ()))) {
34
41
System .out .println ("HIER" );
35
42
ControlPacket .Type controlType = ControlPacket .Type .valueOf ("DestinationUnreachable" );
36
43
ControlPacket controlPacket = new ControlPacket (controlType , new byte [0 ]);
@@ -46,7 +53,7 @@ public Router() throws IOException {
46
53
.getByName ((routtable .get (String .valueOf (ipp .getDestinationAddress ()))[0 ]));
47
54
ipp .setNextHopIp (nexthopip );
48
55
System .out .println ("Nexthopip: " + nexthopip + " Nextport: " + ipp .getNextHopPort ());
49
-
56
+ System . out . println ( Arrays . toString ( nexthopip . getAddress ()));
50
57
nl .sendPacket (ipp );
51
58
// IpPacket retp;
52
59
// retp = nl.getPacket();
0 commit comments