Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
106 changes: 54 additions & 52 deletions jdosbox-pcap/src/main/java/jdos/host/FowardPCapEthernet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jdos.host;

import jdos.misc.Log;
import jdos.misc.setup.Section_prop;
import jdos.util.Ptr;
import org.jnetpcap.Pcap;
Expand All @@ -23,6 +22,7 @@ public void send(byte[] buffer, int offset, int len) {
dos.writeInt(len);
dos.write(buffer, offset, len);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static byte[] buffer = new byte[4096];
Expand All @@ -42,6 +42,7 @@ public void receive(RxFrame frame) {
}
} while (len>0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

Expand All @@ -50,11 +51,11 @@ public boolean open(Section_prop section, byte[] mac) {
socket = new Socket(section.Get_string("pcaphost"), section.Get_int("pcapport"));
dos = new DataOutputStream(socket.getOutputStream());
dis = new DataInputStream(socket.getInputStream());
return true;
return false;
} catch (Exception e) {
e.printStackTrace();
}
return false;
return true;
}

public void close() {
Expand All @@ -63,6 +64,7 @@ public void close() {
dis.close();
socket.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
socket = null;
dis = null;
Expand All @@ -78,71 +80,71 @@ static public void startServer(String nic, int port) {
pcaptmp.close();
try {
ServerSocket serverSocket = new ServerSocket(port);
Log.log_msg("Listening on port "+port+" for pcap forwarding. Hit q [ENTER] to quit");
System.out.println("Listening on port "+port+" for pcap forwarding. Hit q [ENTER] to quit");
while (true) {
Thread exitThread = new Thread(new Runnable() {
public void run() {
while (true) {
try {
char c = (char)System.in.read();
if (c == 'q') {
System.exit(0);
}
} catch (Exception e) {
Thread exitThread = new Thread(() -> {
while (true) {
try {
char c = (char)System.in.read();
if (c == 'q') {
System.exit(0);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
exitThread.start();
final Socket socket = serverSocket.accept();
final String address = socket.getInetAddress().toString();
Log.log_msg(" Accepted connection from "+address);
System.out.println(" Accepted connection from "+address);
final Pcap pcap = PCapEthernet.open(nic, true);
Thread serviceIn = new Thread(new Runnable() {
public void run() {
try {
DataInputStream dis = new DataInputStream(socket.getInputStream());
byte[] buffer = new byte[4096];
while (true) {
int len = dis.readInt();
if (len<0) {
return;
}
if (len>buffer.length) {
buffer = new byte[len];
}
dis.readFully(buffer, 0, len);
synchronized (pcap) {
pcap.sendPacket(buffer, 0, len);
}
Thread serviceIn = new Thread(() -> {
try {
DataInputStream dis = new DataInputStream(socket.getInputStream());
byte[] buffer = new byte[4096];
while (true) {
int len = dis.readInt();
if (len<0) {
return;
}
} catch (Exception e) {
Log.log_msg(" Dropped connection from "+address);
} finally {
try {pcap.close();} catch (Exception e1){}
if (len>buffer.length) {
buffer = new byte[len];
}
dis.readFully(buffer, 0, len);
synchronized (pcap) {
pcap.sendPacket(buffer, 0, len);
}
}
} catch (Exception e) {
System.out.println(" Dropped connection from "+address);
} finally {
try {pcap.close();} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
});
serviceIn.start();
Thread serviceOut = new Thread(new Runnable() {
public void run() {
try {
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
while (true) {
PcapHeader header = new PcapHeader(JMemory.POINTER);
JBuffer buffer = new JBuffer(JMemory.POINTER);
synchronized (pcap) {
while (pcap.nextEx(header, buffer) == Pcap.NEXT_EX_OK) {
byte[] data = buffer.getByteArray(0, header.hdr_len());
dos.writeInt(data.length);
dos.write(data);
}
Thread serviceOut = new Thread(() -> {
try {
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
while (true) {
PcapHeader header = new PcapHeader(JMemory.POINTER);
JBuffer buffer = new JBuffer(JMemory.POINTER);
synchronized (pcap) {
while (pcap.nextEx(header, buffer) == Pcap.NEXT_EX_OK) {
byte[] data = buffer.getByteArray(0, header.hdr_len());
dos.writeInt(data.length);
dos.write(data);
}
Thread.sleep(10);
}
} catch (Exception e) {
} finally {
try {pcap.close();} catch (Exception e1){}
Thread.sleep(10);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {pcap.close();} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
});
Expand Down
33 changes: 16 additions & 17 deletions jdosbox-pcap/src/main/java/jdos/host/PCapEthernet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jdos.host;

import jdos.misc.Log;
import jdos.misc.setup.Section_prop;
import jdos.util.Ptr;
import jdos.util.StringHelper;
Expand Down Expand Up @@ -37,32 +36,32 @@ public void close() {
}
public boolean open(Section_prop section, byte[] mac) {
pcap = open(section.Get_string("realnic"), true);
return pcap!=null;
return pcap == null;
}
static public Pcap open(String realnicstring, boolean async) {
try {
ArrayList alldevs = new ArrayList(); // Will be filled with NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs

/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
/**************************************************************************
First get a list of devices on this system
*/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
Log.log_msg("Cannot enumerate network interfaces: " + errbuf.toString());
System.out.println("Cannot enumerate network interfaces: " + errbuf);
return null;
}

if (realnicstring.equalsIgnoreCase("list")) {
int i = 0;
Log.log_msg("\nNetwork Interface List \n-----------------------------------");
int i;
System.out.println("\nNetwork Interface List \n-----------------------------------");
for (i=0;i<alldevs.size();i++) {
PcapIf currentdev = (PcapIf)alldevs.get(i);
String desc = currentdev.getDescription();
if (desc == null || desc.length()==0)
if (desc == null || desc.isEmpty())
desc = "no description";
i++;
Log.log_msg(StringHelper.sprintf("%2d. %s\n (%s)\n", new Object[]{new Integer(i), currentdev.getName(), desc}));
System.out.println(StringHelper.sprintf("%2d. %s\n (%s)\n", new Object[]{i, currentdev.getName(), desc}));
}
Pcap.freeAllDevs(alldevs, errbuf);
return null;
Expand All @@ -74,29 +73,29 @@ static public Pcap open(String realnicstring, boolean async) {
dev = (PcapIf)alldevs.get(index);
}
} catch (Exception e) {
for (int i=0;i<alldevs.size();i++) {
PcapIf currentdev = (PcapIf)alldevs.get(i);
for (Object alldev : alldevs) {
PcapIf currentdev = (PcapIf) alldev;
if (currentdev.getName().contains(realnicstring)) {
dev = currentdev;
break;
} else if (currentdev.getDescription()!=null && currentdev.getDescription().contains(realnicstring)) {
} else if (currentdev.getDescription() != null && currentdev.getDescription().contains(realnicstring)) {
dev = currentdev;
break;
}
}
}
if (dev == null) {
Log.log_msg("Unable to find network interface - check realnic parameter\n");
System.out.println("Unable to find network interface - check realnic parameter\n");
Pcap.freeAllDevs(alldevs, errbuf);
return null;
}
String desc = dev.getDescription();
if (desc == null || desc.length() == 0)
if (desc == null || desc.isEmpty())
desc = "no description";
Log.log_msg("Using Network interface:\n" + dev.getName() + "\n(" + desc + ")\n");
System.out.println("Using Network interface:\n" + dev.getName() + "\n(" + desc + ")\n");
Pcap pcap = Pcap.openLive(dev.getName(), 65536, Pcap.MODE_PROMISCUOUS, -1, errbuf);
if (pcap == null) {
Log.log_msg("\\nUnable to open the interface: " + errbuf.toString());
System.out.println("\\nUnable to open the interface: " + errbuf);
Pcap.freeAllDevs(alldevs, errbuf);
return null;
}
Expand Down
7 changes: 0 additions & 7 deletions jdosbox-win/src/main/java/jdos/win/Console.java

This file was deleted.

14 changes: 8 additions & 6 deletions jdosbox-win/src/main/java/jdos/win/Win.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public static void panic(String msg) {
}

public static void exit() {
Console.out("The Windows program has finished. Rebooting in .. ");
System.out.println("The Windows program has finished. Rebooting in .. ");
for (int i=5;i>0;i--) {
System.out.println(i);
try {Thread.sleep(1000);} catch (Exception e) {}
try {Thread.sleep(1000);} catch (Exception e) {
throw new RuntimeException(e);
}
}
throw new Dos_programs.RebootException();
}
Expand All @@ -57,7 +59,7 @@ static public boolean run(Drive_fat drive, Drive_fat.fatFile fil, String path)
FilePath.disks.put("C", drive);
WinFile file = WinFile.createNoHandle(new FilePath(path), false, 0, 0);

if (!HeaderPE.fastCheckWinPE(file))
if (HeaderPE.fastCheckWinPE(file))
return false;
String name;
String winPath = path.substring(0, path.lastIndexOf("\\")+1);
Expand All @@ -78,8 +80,8 @@ static public boolean run(String path) {
/*Bit8u*/char drive=(char)(Dos_files.DOS_GetDefaultDrive()+'A');
StringRef dir = new StringRef();
Dos_files.DOS_GetCurrentDir((short)0,dir);
String p = String.valueOf(drive)+":\\";
if (dir.value.length()>0) {
String p = drive +":\\";
if (!dir.value.isEmpty()) {
p+=dir.value+"\\";
}
String winPath = p;
Expand All @@ -90,7 +92,7 @@ static public boolean run(String path) {
WinFile file = null;
try {
file = WinFile.createNoHandle(new FilePath(path), false, 0, 0);
if (!HeaderPE.fastCheckWinPE(file))
if (HeaderPE.fastCheckWinPE(file))
return false;
} catch (Exception e) {
return false;
Expand Down
Loading