Merge commit '429c5b5faac669c9d054c7d70040d74a909486ae'
Merge commit '429c5b5faac669c9d054c7d70040d74a909486ae'

file:a/makefile -> file:b/makefile
--- a/makefile
+++ b/makefile
@@ -1,7 +1,7 @@
-all: bin/psk31 bin/filter_test bin/packet bin/sound_device bin/NOAA_ATP bin/mixer bin/foward
+all: bin/psk31 bin/filter_test bin/packet bin/sound_device bin/NOAA_ATP bin/mixer bin/forward
 
-bin/foward: build/obj/foward.o
-	g++ -O3 -o bin/foward build/obj/foward.o
+bin/forward: build/obj/forward.o
+	gcc -O3 -o bin/forward build/obj/forward.o
 
 bin/mixer: build/obj/mixer.o build/obj/Util.o
 	g++ -O3 -o bin/mixer build/obj/mixer.o build/obj/Util.o
@@ -21,8 +21,8 @@
 bin/NOAA_ATP: build/obj/NOAA_ATP_main.o build/obj/NOAA_ATP.o build/obj/Util.o
 	g++ -O3 -o bin/NOAA_ATP build/obj/NOAA_ATP_main.o build/obj/NOAA_ATP.o build/obj/Util.o
 
-build/obj/foward.o: src/net/foward.cpp
-	g++ -O3 -o build/obj/foward.o -c src/net/foward.cpp
+build/obj/forward.o: src/net/forward.c
+	gcc -O3 -o build/obj/forward.o -c src/net/forward.c
 
 build/obj/mixer.o: src/mixer/mixer.cpp
 	g++ -O3 -o build/obj/mixer.o -c src/mixer/mixer.cpp
@@ -70,7 +70,7 @@
 	g++ -O3 -o build/obj/Util.o -c src/util/Util.cpp
 
 clean:
-	rm bin/*
-	rm build/obj/*
+	rm -rf bin/*
+	rm -rf build/obj/*
 
 

file:b/src/net/forward.c (new)
--- /dev/null
+++ b/src/net/forward.c
@@ -1,1 +1,128 @@
+#include "forward.h"
 
+// UDP socket to forward data to and address
+int sock;
+struct addrinfo hints;
+struct addrinfo *result, *rp;
+
+int open_udp_socket(char *hostname, char *port){
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
+	hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
+	hints.ai_flags = 0;
+	hints.ai_protocol = 0;
+
+
+	//Create the socket
+	int error = getaddrinfo(hostname, port, &hints, &result);
+	if(error != 0){
+		perror("Failed to create socket");
+		return -1;
+	}
+
+	for(rp = result; rp != NULL; rp = rp->ai_next){
+		sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+		if(sock == -1)
+			continue;
+
+		if(connect(sock, rp->ai_addr, rp->ai_addrlen) == 0)
+			break;                  /* Success */
+
+		close(sock);
+
+	}
+
+	if(rp == NULL){
+		perror("Bind failed");
+		return -1;
+	}
+
+	freeaddrinfo(result);
+
+	return 0;
+
+}
+
+int close_udp_socket(){
+
+	close(sock);
+	return 0;
+
+}
+
+int send_data(int len, char* data){
+
+	//send the message to server
+	int bytesSent = write(sock, data, len);
+	if(bytesSent != len){
+		perror("Mismatch in number of bytes sent");
+		fprintf(stderr, "Send %d bytes\n", bytesSent);
+		return -1;
+	}
+
+	return 0;
+
+}
+
+int main(int argc, char **argv){
+
+	if(argc < 3){
+		printf("Usage: %s hostname port\n", argv[0]);
+		return -1;
+	}
+
+	char buffer[1000];
+
+	bool running = true;
+
+	// Hostname, Port
+	if(open_udp_socket(argv[1], argv[2]) == -1){
+		perror("Error creating socket");
+		return -1;
+	}
+
+	while(running){
+
+		char len1, len2;
+		len1 = getc(stdin);
+		len2 = getc(stdin);
+
+		if(feof(stdin)){
+			printf("stdin closed\n");
+			break;
+		}
+
+		unsigned short len;
+
+		int count;
+
+		len = (((unsigned char)len1)<<8) + ((unsigned char)len2);
+
+		if(len > 1000){
+			fprintf(stderr, "Buffer to small for packet!\n");
+			break;
+		}
+
+		int i;
+		for(i = 0; i < len; i++){
+			int byte = getc(stdin);
+			buffer[i] = (unsigned char)byte;
+		}
+
+		// Standard log
+		fprintf(stdout, "Sending Packet Length: %d\n", ((int)len));
+
+		if(send_data(len, buffer) == -1){
+			fprintf(stderr, "Failed to send data to client via udp\n");
+			break;
+		}
+
+	}
+
+	close_udp_socket();
+
+	return 0;
+
+}
+

file:b/src/net/forward.h (new)
--- /dev/null
+++ b/src/net/forward.h
@@ -1,1 +1,17 @@
+#ifndef FORWARD_H
+#define FORWARD_H
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <stdio.h>
+
+#endif
+

file:a/src/net/foward.cpp (deleted)
--- a/src/net/foward.cpp
+++ /dev/null
@@ -1,114 +1,1 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include <iomanip>
-#include <iostream>
-#include <cstring>
-
-#include "../util/Util.cpp"
-
-// UDP socket to forward data to and address
-int sock;
-struct addrinfo hints;
-struct addrinfo *result, *rp;
-
-int open_udp_socket(std::string hostname, std::string port){
-
-	memset(&hints, 0, sizeof(struct addrinfo));
-	hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
-	hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
-	hints.ai_flags = 0;
-	hints.ai_protocol = 0;
-
-
-	//Create the socket
-	int error = getaddrinfo(hostname.c_str(), port.c_str(), &hints, &result);
-	if(error != 0) {
-      std::cerr << "Failed to create socket" << std::endl;
-      return -1;
-   }
-
-	for(rp = result; rp != NULL; rp = rp->ai_next) {
-		sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
-		if(sock == -1)
-			continue;
-
-		if(connect(sock, rp->ai_addr, rp->ai_addrlen) == 0)
-			break;                  /* Success */
-
-		close(sock);
-
-	}
-
-   if(rp == NULL) {
-	  std::cerr << "bind failed" << std::endl;
-      return -1;
-   }
-
-   freeaddrinfo(result);
-
-   return 0;
-
-}
-
-int close_udp_socket(){
-
-	close(sock);
-
-	return 0;
-
-}
-
-int send_data(int len, char* data){
-
-   //send the message to server
-	int bytesSent = write(sock, data, len);
-	if(bytesSent != len) {
-	   std::cerr << "Mismatch in number of bytes sent" << std::endl;
-	   std::cerr << "Error " << errno << std::endl;
-	   std::cerr << "Sent " << bytesSent << " bytes" << std::endl;
-	   return -1;
-   }
-
-	return 0;
-
-}
-
-int main(int argc, char **argv){
-
-	std::string args;
-	for(int i = 0; i < argc; i++) args += std::string(argv[i]) + std::string(" ");
-	util::readInArguments(args);
-
-	std::string hostname = util::getArgument("--hostname");
-	std::string port = util::getArgument("--port");
-
-	char buffer[1000];
-
-	bool running = true;
-
-	if(open_udp_socket(hostname, port) == -1) return -1;
-
-	while(running){
-
-		char len;
-		if(!std::cin.get(len)) break;
-		if(!std::cin.read(buffer, len)) break;
-
-		std::cout << "Sending Packet Length: " << ((int)len) << std::endl;
-
-		if(send_data(len, buffer) == -1) break;
-
-	}
-
-	close_udp_socket();
-
-	return 0;
-
-}
-

--- a/src/packet/packet_main.cpp
+++ b/src/packet/packet_main.cpp
@@ -17,8 +17,12 @@
  */
 void print_raw_packet(packet_data pd){
 
+	unsigned short length = pd.byte_sequence.size();
 	char *bytes = pd.byte_sequence.data();
-	std::cout.put(pd.byte_sequence.size());
+
+	std::cout.put((length>>8)&0xFF);
+	std::cout.put(length&0xFF);
+
 	std::cout.write(bytes, pd.byte_sequence.size());
 	std::cout.flush();