@@ -243,7 +243,7 @@ public String getServerHost() {
243243 */
244244 public int getServerPort () {
245245 if (currentParsedUDL == null ) return 0 ;
246- return currentParsedUDL . nameServerTcpPort ;
246+ return domainServerPort ;
247247 }
248248
249249
@@ -484,17 +484,26 @@ public void run() {
484484 packet .setLength (1024 );
485485 try {
486486 udpSocket .receive (packet );
487+ if (debug >= cMsgConstants .debugInfo ) {
488+ System .out .println ("UdpReceiver.run(): Received a multicast response" );
489+ }
487490 }
488491 catch (SocketTimeoutException e ) {
489492 // Check to see if we've been asked to quit
490493 if (Thread .interrupted ()) {
494+ if (debug >= cMsgConstants .debugInfo ) {
495+ System .out .println ("UdpReceiver.run(): Thread interrupted" );
496+ }
491497 return ;
492498 }
493499 continue ;
494500 }
495501
496- // if packet is smaller than 6 ints ...
497- if (packet .getLength () < 24 ) {
502+ // if packet is smaller than 5 ints ...
503+ if (packet .getLength () < 20 ) {
504+ if (debug >= cMsgConstants .debugInfo ) {
505+ System .out .println ("UdpReceiver.run(): Packet size smaller that 5 ints" );
506+ }
498507 continue ;
499508 }
500509
@@ -507,48 +516,60 @@ public void run() {
507516 if ( (magicInt1 != cMsgNetworkConstants .magicNumbers [0 ]) ||
508517 (magicInt2 != cMsgNetworkConstants .magicNumbers [1 ]) ||
509518 (magicInt3 != cMsgNetworkConstants .magicNumbers [2 ])) {
510- //System.out.println(" Bad magic numbers for multicast response packet");
519+ if (debug >= cMsgConstants .debugInfo ) {
520+ System .out .println ("UdpReceiver.run(): Bad magic numbers for multicast response packet" );
521+ }
511522 continue ;
512523 }
513524
514- currentParsedUDL .nameServerTcpPort = cMsgUtilities .bytesToInt (buf , 12 ); // port to do a direct connection to
515- if ((currentParsedUDL .nameServerTcpPort < 1024 || currentParsedUDL .nameServerTcpPort > 65535 )) {
516- //System.out.println(" Wrong format for multicast response packet");
525+ domainServerPort = cMsgUtilities .bytesToInt (buf , 12 ); // xMsg Proxy server port
526+ if ((domainServerPort < 1024 || domainServerPort > 65535 )) {
527+ if (debug >= cMsgConstants .debugInfo ) {
528+ System .out .println ("UdpReceiver.run(): Bad port in multicast response packet" );
529+ }
517530 continue ;
518531 }
519532
520- // udpPort is next but we'll skip over it since we don't use it
521-
522533 // # of address pairs to follow
523- int listLen = cMsgUtilities .bytesToInt (buf , 20 );
534+ int listLen = cMsgUtilities .bytesToInt (buf , 16 );
524535 if (listLen < 0 || listLen > 50 ) {
525- System .out .println (" Wrong format for multicast response packet, listLen = " + listLen );
536+ if (debug >= cMsgConstants .debugInfo ) {
537+ System .out .println ("UdpReceiver.run(): Wrong format for multicast response packet, listLen = " + listLen );
538+ }
526539 continue ;
527540 }
528541
529- int pos = 24 ;
542+ int pos = 20 ;
530543 String ss ;
531544 int stringLen ;
532545 ipList .clear ();
533546 broadList .clear ();
547+
548+ if (debug >= cMsgConstants .debugInfo ) {
549+ System .out .println ("UdpReceiver.run(): listLen = " + listLen );
550+ }
534551
535552 for (int i =0 ; i < listLen ; i ++) {
536553 try {
537554 stringLen = cMsgUtilities .bytesToInt (buf , pos ); pos += 4 ;
538- //System.out.println(" ip len = " + listLen);
539555 ss = new String (buf , pos , stringLen , "US-ASCII" );
540- //System.out.println(" ip = " + ss);
556+ if (debug >= cMsgConstants .debugInfo ) {
557+ System .out .println (" ip = " + ss );
558+ }
541559 ipList .add (ss );
542560 pos += stringLen ;
543561
544562 stringLen = cMsgUtilities .bytesToInt (buf , pos ); pos += 4 ;
545- //System.out.println(" broad len = " + listLen);
546563 ss = new String (buf , pos , stringLen , "US-ASCII" );
547- //System.out.println(" broad = " + ss);
564+ if (debug >= cMsgConstants .debugInfo ) {
565+ System .out .println (" broad = " + ss );
566+ }
548567 broadList .add (ss );
549568 pos += stringLen ;
550569 }
551- catch (UnsupportedEncodingException e ) {/*never happen */ }
570+ catch (UnsupportedEncodingException e ) {
571+ System .out .println ("UdpReceiver.run(): encoding error" );
572+ }
552573 }
553574 break ;
554575 }
0 commit comments