Fix port transmission

This commit is contained in:
SeekDaSky 2017-04-14 01:43:16 +02:00
parent ecb49e1117
commit d6ddbce375
7 changed files with 7 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -156,7 +156,7 @@ int multicastTerminal(struct middleware_arg* arg){
/* 3. Si on a le port -> on le met dans la reponse */ /* 3. Si on a le port -> on le met dans la reponse */
}else{ }else{
strcpy(request.addr, SERV_HOST); strcpy(request.addr, SERV_HOST);
request.port = htons(comInfo.sin_port); request.port = comInfo.sin_port;
if( DEBUGMOD&SCK ) printf("{%s}{udp_com} socket opened on %s:%d\n", arg->entity, request.addr, request.port); if( DEBUGMOD&SCK ) printf("{%s}{udp_com} socket opened on %s:%d\n", arg->entity, request.addr, request.port);
} }

View File

@ -34,7 +34,7 @@ public class CommandTerminal {
try { try {
DatagramSocket socket = new DatagramSocket(); DatagramSocket socket = new DatagramSocket();
ByteBuffer buf = ByteBuffer.allocate(19); ByteBuffer buf = ByteBuffer.allocate(21);
buf.clear(); buf.clear();
buf.put((byte)(0x01|0x02)); buf.put((byte)(0x01|0x02));
@ -47,26 +47,23 @@ public class CommandTerminal {
if(buf.get() == 3){ if(buf.get() == 3){
System.out.println("--Connection request successful"); System.out.println("--Connection request successful");
byte address[] = new byte[9]; byte address[] = new byte[15];
buf = buf.get(address,0,9); buf = buf.get(address,0,15);
String addressString = new String(address); String addressString = new String(address);
InetAddress sgcaAddress = InetAddress.getByName(addressString); InetAddress sgcaAddress = InetAddress.getByName(addressString);
buf = buf.get(address,0,7); //emulate an unsigned short
short shortVal = buf.getShort(); char cast = buf.getChar();
int port = shortVal >= 0 ? shortVal : 0x10000 + shortVal; int port = (int) cast;
System.out.println("----Address : "+sgcaAddress.getHostAddress()); System.out.println("----Address : "+sgcaAddress.getHostAddress());
System.out.println("----Port : "+port); System.out.println("----Port : "+port);
} }
} catch ( IOException e) { } catch ( IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
} }