Skip to content

Commit

Permalink
InetAddress.getHostName()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed May 7, 2024
1 parent 4153a48 commit 5255d41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/scion/jpan/internal/HostsFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ private void init() {
Path path = Paths.get(file);
// On Windows /etc/hosts is reported as ¨: not a file"
if (!Files.exists(path) || !Files.isRegularFile(path)) {
LOG.info(PATH_LINUX + " not found.");
LOG.info("{} not found.", path);
return;
}
try (Stream<String> lines = Files.lines(path)) {
lines.forEach(this::parseLine);
lines.forEach((line) -> parseLine(line, path));
} catch (IOException e) {
throw new ScionRuntimeException(e);
}
}
}

private void parseLine(String line) {
private void parseLine(String line, Path path) {
try {
String s = line.trim();
if (s.isEmpty() || s.startsWith("#")) {
Expand All @@ -104,6 +104,7 @@ private void parseLine(String line) {
check(!addrStr.isEmpty(), "Address is empty");

byte[] addrBytes = IPHelper.toByteArray(addrStr);
check(addrBytes != null, "Address string is not a legal address");
for (int i = 1; i < lineParts.length; i++) {
String hostName = lineParts[i];
if (hostName.startsWith("#")) {
Expand All @@ -119,7 +120,7 @@ private void parseLine(String line) {
// Use "normalized" address string as key (these may differ fo IPv6)
entries.put(inetAddr.getHostAddress(), new HostEntry(isdIa, inetAddr));
} catch (IndexOutOfBoundsException | IllegalArgumentException | UnknownHostException e) {
LOG.info("ERROR {} while parsing file {}: {}", e.getMessage(), PATH_LINUX, line);
LOG.info("ERROR parsing file {}: error=\"{}\" line=\"{}\"", path, e.getMessage(), line);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/scion/jpan/testutil/JUnitSetUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void close() {

@Override
public void beforeEach(ExtensionContext context) {
System.setProperty(Constants.PROPERTY_HOSTS_FILES, "....some-invalid-file");
Scion.closeDefault();
if (failed) {
System.exit(1);
Expand Down

0 comments on commit 5255d41

Please sign in to comment.