Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
651e8810eb |
|
|
@ -1,10 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Ignored default folder with query files
|
|
||||||
/queries/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="vs.pu01" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding">
|
|
||||||
<file url="file://$PROJECT_DIR$/vs.pu01/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/vs.pu01/src/main/resources" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="KubernetesApiProvider"><![CDATA[{}]]></component>
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/vs.pu01/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="temurin-25 (2)" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/VS-Aufgabe-1.iml" filepath="$PROJECT_DIR$/.idea/VS-Aufgabe-1.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
package vs;
|
package vs;
|
||||||
|
|
||||||
|
import com.sun.jdi.InternalException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
static DatagramSocket syslogSocket;
|
static DatagramSocket syslogSocket;
|
||||||
static DatagramSocket broadcastSocket;
|
static DatagramSocket broadcastSocket;
|
||||||
|
|
||||||
static final int MAX_LEN = 2048; // max. erlaubte Nachrichtenlänge in Byte
|
|
||||||
static final int RECV_BUF = 65535; // Puffer größer als jede UDP-Nachricht, damit zu lange Nachrichten erkannt werden
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
|
|
@ -42,7 +40,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
while (true){
|
while (true){
|
||||||
|
|
||||||
byte[] buffer = new byte[RECV_BUF];
|
byte[] buffer = new byte[2048];
|
||||||
|
|
||||||
DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);
|
DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);
|
||||||
|
|
||||||
|
|
@ -72,27 +70,21 @@ public class Main {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.getLength() > MAX_LEN){
|
|
||||||
System.out.println("[verworfen] msg too long ("+packet.getLength()+" bytes > "+MAX_LEN+") from "+packet.getAddress().getHostAddress()+":"+packet.getPort()+", dropped");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SyslogMessage msg = parseSysMessage(Arrays.copyOf(packet.getData(),packet.getLength()));
|
SyslogMessage msg = parseSysMessage(packet.getData());
|
||||||
System.out.println("Log received from "+packet.getAddress().getHostAddress() +":"+ packet.getPort()+ " : "+msg.toString());
|
System.out.println("Log received from "+packet.getAddress().getHostName() +":"+ packet.getPort()+ " : "+msg.toString());
|
||||||
}catch (ArrayIndexOutOfBoundsException e){
|
|
||||||
System.out.println("[verworfen] msg truncated or malformed from "+packet.getAddress().getHostAddress()+":"+packet.getPort());
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
System.out.println("[verworfen] msg not valid from "+packet.getAddress().getHostAddress()+":"+packet.getPort()+": "+e.getMessage());
|
//System.err.println("msg couldnt be parsed, "+e.getMessage());
|
||||||
|
//e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyslogMessage parseSysMessage(byte[] buff){
|
static SyslogMessage parseSysMessage(byte[] buff) throws InternalException{
|
||||||
if (buff.length == 0 || buff[0] != 60){
|
if (buff[0] != 60){
|
||||||
throw new IllegalArgumentException("msg not well formed");
|
throw new InternalException("msg not well formed");
|
||||||
}
|
}
|
||||||
SyslogMessage.Facility fac;
|
SyslogMessage.Facility fac;
|
||||||
SyslogMessage.Severity sev;
|
SyslogMessage.Severity sev;
|
||||||
|
|
@ -104,16 +96,15 @@ public class Main {
|
||||||
if (buff[step] == 62) break;
|
if (buff[step] == 62) break;
|
||||||
prival_str += (char) buff[step];
|
prival_str += (char) buff[step];
|
||||||
}
|
}
|
||||||
if (buff[step] != 62) throw new IllegalArgumentException("PRIVAL malformed");
|
if (buff[step] != 62) throw new InternalException("PRIVAL malformed");
|
||||||
if (prival_str.isEmpty()) throw new IllegalArgumentException("PRIVAL not there");
|
if (prival_str.isEmpty()) throw new InternalException("PRIVAL not there");
|
||||||
|
|
||||||
int primval = Integer.parseInt(prival_str);
|
int primval = Integer.parseInt(prival_str);
|
||||||
if (primval > 191) throw new IllegalArgumentException("PRIVAL out of range");
|
|
||||||
fac = SyslogMessage.Facility.values()[primval/8];
|
fac = SyslogMessage.Facility.values()[primval/8];
|
||||||
sev = SyslogMessage.Severity.values()[primval%8];
|
sev = SyslogMessage.Severity.values()[primval%8];
|
||||||
|
|
||||||
//version is always 1
|
//version is always 1
|
||||||
if (buff[++step] != 49) throw new IllegalArgumentException("VERSION NOT 1");
|
if (buff[++step] != 49) throw new InternalException("VERSION NOT 1");
|
||||||
|
|
||||||
//skip whitespace and verion
|
//skip whitespace and verion
|
||||||
++step;
|
++step;
|
||||||
|
|
@ -177,33 +168,26 @@ public class Main {
|
||||||
|
|
||||||
|
|
||||||
//skip structured data
|
//skip structured data
|
||||||
while (step < buff.length && buff[step] != 32){
|
while (buff[step] != 32){
|
||||||
step++;
|
step++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//MESSAGE
|
//MESSAGE
|
||||||
|
|
||||||
|
|
||||||
SyslogMessage.Message msg = null; //MSG is optional
|
String end = new String(buff,step,buff.length-step-1);
|
||||||
int start = step + 1; //step points to the whitespace before MSG
|
SyslogMessage.Message msg;
|
||||||
|
|
||||||
if (start < buff.length){
|
if (end.startsWith("\u00EF\u00BB\u00BF")){
|
||||||
if (buff.length-start >= 3 && buff[start] == (byte) 0xEF && buff[start+1] == (byte) 0xBB && buff[start+2] == (byte) 0xBF){
|
msg = new SyslogMessage.TextMessage(end);
|
||||||
msg = new SyslogMessage.TextMessage(new String(buff,start+3,buff.length-start-3,StandardCharsets.UTF_8));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Byte[] msgBuff = new Byte[buff.length-start];
|
Byte[] msgBuff = new Byte[buff.length-step];
|
||||||
for (int i = 0;i < msgBuff.length;i++){
|
for (int i = 0;i < msgBuff.length;i++){
|
||||||
msgBuff[i] = buff[i+start];
|
msgBuff[i] = buff[i+step];
|
||||||
}
|
|
||||||
//BinaryMessage.toString() would only print the array reference, so print the content
|
|
||||||
msg = new SyslogMessage.BinaryMessage(msgBuff){
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return new String(buff,start,buff.length-start,StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
msg = new SyslogMessage.BinaryMessage(msgBuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SyslogMessage(fac,sev,hostname,appName,procID,msgID,null,msg);
|
return new SyslogMessage(fac,sev,hostname,appName,procID,msgID,null,msg);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue