Bau bau
parent
b7f5dbc7fb
commit
fe21ccf400
|
|
@ -0,0 +1,10 @@
|
|||
# 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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
package vs;
|
||||
|
||||
import com.sun.jdi.InternalException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
|
||||
static DatagramSocket syslogSocket;
|
||||
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){
|
||||
|
|
@ -40,7 +42,7 @@ public class Main {
|
|||
}
|
||||
while (true){
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
byte[] buffer = new byte[RECV_BUF];
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);
|
||||
|
||||
|
|
@ -70,21 +72,27 @@ public class Main {
|
|||
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 {
|
||||
SyslogMessage msg = parseSysMessage(packet.getData());
|
||||
System.out.println("Log received from "+packet.getAddress().getHostName() +":"+ packet.getPort()+ " : "+msg.toString());
|
||||
SyslogMessage msg = parseSysMessage(Arrays.copyOf(packet.getData(),packet.getLength()));
|
||||
System.out.println("Log received from "+packet.getAddress().getHostAddress() +":"+ packet.getPort()+ " : "+msg.toString());
|
||||
}catch (ArrayIndexOutOfBoundsException e){
|
||||
System.out.println("[verworfen] msg truncated or malformed from "+packet.getAddress().getHostAddress()+":"+packet.getPort());
|
||||
}catch (Exception e){
|
||||
System.err.println("msg couldnt be parsed, "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.out.println("[verworfen] msg not valid from "+packet.getAddress().getHostAddress()+":"+packet.getPort()+": "+e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static SyslogMessage parseSysMessage(byte[] buff) throws InternalException{
|
||||
if (buff[0] != 60){
|
||||
throw new InternalException("msg not well formed");
|
||||
static SyslogMessage parseSysMessage(byte[] buff){
|
||||
if (buff.length == 0 || buff[0] != 60){
|
||||
throw new IllegalArgumentException("msg not well formed");
|
||||
}
|
||||
SyslogMessage.Facility fac;
|
||||
SyslogMessage.Severity sev;
|
||||
|
|
@ -96,15 +104,16 @@ public class Main {
|
|||
if (buff[step] == 62) break;
|
||||
prival_str += (char) buff[step];
|
||||
}
|
||||
if (buff[step] != 62) throw new InternalException("PRIVAL malformed");
|
||||
if (prival_str.isEmpty()) throw new InternalException("PRIVAL not there");
|
||||
if (buff[step] != 62) throw new IllegalArgumentException("PRIVAL malformed");
|
||||
if (prival_str.isEmpty()) throw new IllegalArgumentException("PRIVAL not there");
|
||||
|
||||
int primval = Integer.parseInt(prival_str);
|
||||
if (primval > 191) throw new IllegalArgumentException("PRIVAL out of range");
|
||||
fac = SyslogMessage.Facility.values()[primval/8];
|
||||
sev = SyslogMessage.Severity.values()[primval%8];
|
||||
|
||||
//version is always 1
|
||||
if (buff[++step] != 49) throw new InternalException("VERSION NOT 1");
|
||||
if (buff[++step] != 49) throw new IllegalArgumentException("VERSION NOT 1");
|
||||
|
||||
//skip whitespace and verion
|
||||
++step;
|
||||
|
|
@ -168,26 +177,33 @@ public class Main {
|
|||
|
||||
|
||||
//skip structured data
|
||||
while (buff[step] != 32){
|
||||
while (step < buff.length && buff[step] != 32){
|
||||
step++;
|
||||
}
|
||||
|
||||
//MESSAGE
|
||||
|
||||
|
||||
String end = new String(buff,step,buff.length-step-1);
|
||||
SyslogMessage.Message msg;
|
||||
SyslogMessage.Message msg = null; //MSG is optional
|
||||
int start = step + 1; //step points to the whitespace before MSG
|
||||
|
||||
if (end.startsWith("\u00EF\u00BB\u00BF")){
|
||||
msg = new SyslogMessage.TextMessage(end);
|
||||
|
||||
}
|
||||
else {
|
||||
Byte[] msgBuff = new Byte[buff.length-step];
|
||||
for (int i = 0;i < msgBuff.length;i++){
|
||||
msgBuff[i] = buff[i+step];
|
||||
if (start < buff.length){
|
||||
if (buff.length-start >= 3 && buff[start] == (byte) 0xEF && buff[start+1] == (byte) 0xBB && buff[start+2] == (byte) 0xBF){
|
||||
msg = new SyslogMessage.TextMessage(new String(buff,start+3,buff.length-start-3,StandardCharsets.UTF_8));
|
||||
}
|
||||
else {
|
||||
Byte[] msgBuff = new Byte[buff.length-start];
|
||||
for (int i = 0;i < msgBuff.length;i++){
|
||||
msgBuff[i] = buff[i+start];
|
||||
}
|
||||
//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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue