Beispiel #1
0
int main(int argc, char *argv[]) {

	IP4_init(argc, argv);

	struct udp_metadata_parsed meta;
	struct finsFrame* pff;
	struct finsFrame ff;

	unsigned char str[] = "00000000ALEX";

	ff.dataFrame.pdu = &str[0];

	meta.u_IPdst = IP4_ADR_P2N(171,2,14,100);
	meta.u_IPsrc = IP4_ADR_P2N(153,18,8,105);
	meta.u_destPort = 13;
	meta.u_srcPort = 1087;

	ff.dataFrame.pduLength = 4;
	ff.dataOrCtrl = DATA;
	ff.destinationID = UDPID;
	ff.dataFrame.directionFlag = DOWN;

	memcpy(&ff.dataFrame.metaData, &meta, 16);
	udp_out_fdf(&ff);
	return EXIT_SUCCESS;
}
/* udp_out test */
int main() {
	struct udp_metadata_parsed meta;
	struct finsFrame* pff;
	struct finsFrame ff;
	unsigned short checksum = 0;

	char str[20] = "00000000TESTING";

	ff.dataFrame.pdu = &str[0];


	meta.u_IPdst = IP4_ADR_P2N(171,2,14,10);
	meta.u_IPsrc = IP4_ADR_P2N(153,18,8,105);
	meta.u_destPort = 13;
	meta.u_srcPort = 1087;



	ff.dataFrame.pduLength = 7;
	ff.dataOrCtrl = DATA;
	ff.destinationID = UDPID;
	ff.dataFrame.directionFlag = DOWN;


	memcpy(&ff.dataFrame.metaData, &meta, 16);
	pff = &ff;

//	printf("The metadata's value for the length is %d\n", pseudoheader2.u_pslen);
//	printf("The UDP packet's value for the length is %d\n", packet2.u_len);
	udp_out(pff);

	return (0);
}
struct ip4_routing_table * parse_nlmsg(struct nlmsghdr* msg)
{
	char dst_temp[IP4_ALEN];
	char gw_temp[IP4_ALEN];
	unsigned int priority;
	unsigned int interface;
	struct ip4_routing_table *table_pointer = NULL;

	switch (msg->nlmsg_type)
	{
	case NLMSG_ERROR:
	{
		struct nlmsgerr* errorMsg = (struct nlmsgerr*) NLMSG_DATA(msg);
		PRINT_DEBUG("\nrecvd NLMSG_ERROR error seq:%d code:%d...", msg->nlmsg_seq, errorMsg->error);
		break;
	}
	case RTM_NEWROUTE:
	{
		struct rtmsg* rtm = (struct rtmsg*) NLMSG_DATA(msg);
		struct rtattr* rta = RTM_RTA(rtm);
		int rtaLen = msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
		if (rtm->rtm_type == RTN_UNICAST) // don't consider local, broadcast and unreachable routes
		{
			table_pointer = (struct ip4_routing_table*) malloc(
					sizeof(struct ip4_routing_table));
			memset(table_pointer, 0, sizeof(struct ip4_routing_table)); // zero the routing table entry data
			for (; RTA_OK(rta, rtaLen); rta = RTA_NEXT(rta, rtaLen))
			{
				switch (rta->rta_type)
				{
				case RTA_DST: //destination
					table_pointer->mask = rtm->rtm_dst_len;
					memcpy(dst_temp, RTA_DATA(rta), IP4_ALEN);
					PRINT_DEBUG("received RTA_DST");
					PRINT_DEBUG("dst_str = %u.%u.%u.%u", dst_temp[0]&0xFF, dst_temp[1]&0xFF, dst_temp[2]&0xFF, dst_temp[3]&0xFF);
					table_pointer->dst
							= IP4_ADR_P2N(dst_temp[0]&0xFF, dst_temp[1]&0xFF, dst_temp[2]&0xFF, dst_temp[3]&0xFF);
					break;
				case RTA_GATEWAY: //next hop
					table_pointer->mask = rtm->rtm_dst_len;
					memcpy(gw_temp, RTA_DATA(rta), IP4_ALEN);
					PRINT_DEBUG("received RTA_GATEWAY");
					PRINT_DEBUG("gw_str = %u.%u.%u.%u",gw_temp[0]&0xFF, gw_temp[1]&0xFF, gw_temp[2]&0xFF, gw_temp[3]&0xFF);
					table_pointer->gw
							= IP4_ADR_P2N(gw_temp[0]&0xFF, gw_temp[1]&0xFF, gw_temp[2]&0xFF, gw_temp[3]&0xFF);
					break;
				case RTA_OIF: //interface
					memcpy(&table_pointer->interface, RTA_DATA(rta),
							sizeof(interface));
					PRINT_DEBUG("interface:%u",table_pointer->interface);
					break;
				case RTA_PRIORITY: //metric
					memcpy(&table_pointer->metric, RTA_DATA(rta),
							sizeof(priority));
					PRINT_DEBUG("metric:%u",table_pointer->metric);
					break;
				} //switch(rta->)
			}// for()
		} // if RTN_UNICAST
		return (table_pointer);
	}
	} //switch (msg->nlmsg_type)
	return (NULL);
}
Beispiel #4
0
/**
 * @file IP4.c
 * @brief FINS module - Internet Protocol version 4
 *
 * Main function of the module.
 */


#include "IP4.h"


//IP4addr my_ip_addr = IP4_ADR_P2N(172,31,165,252);
IP4addr my_ip_addr = IP4_ADR_P2N(127,0,0,1);
IP4addr my_mask = IP4_ADR_P2N(255, 255, 255, 0);
struct ip4_routing_table* routing_table;
struct ip4_stats stats;



int main(int argc, char *argv[])
{
	IP4_init(argc, argv);
	char a[]="test";
	IP_testharness_init(a);
	struct finsFrame ff;

	int i;
	for(i=0;i<30;i++)
	{
		IP4_receive_fdf(&ff);
	}
Beispiel #5
0
#include "IP4.h"
#include "udp.h"

IP4addr my_ip_addr = IP4_ADR_P2N(172,31,165,252);
IP4addr my_mask = IP4_ADR_P2N(255, 255, 255, 0);
struct ip4_routing_table* routing_table;
struct ip4_stats stats;
struct udp_statistics udpStat;

int main(int argc, char *argv[]) {

	IP4_init(argc, argv);

	struct udp_metadata_parsed meta;
	struct finsFrame* pff;
	struct finsFrame ff;

	unsigned char str[] = "00000000ALEX";

	ff.dataFrame.pdu = &str[0];

	meta.u_IPdst = IP4_ADR_P2N(171,2,14,100);
	meta.u_IPsrc = IP4_ADR_P2N(153,18,8,105);
	meta.u_destPort = 13;
	meta.u_srcPort = 1087;

	ff.dataFrame.pduLength = 4;
	ff.dataOrCtrl = DATA;
	ff.destinationID = UDPID;
	ff.dataFrame.directionFlag = DOWN;
/* udp_out test */
int main(int argc, char *argv[]) {
	struct udp_metadata_parsed meta;
	struct finsFrame* pff;
	struct finsFrame ff;
	unsigned short checksum = 0;

	IP4_init(argc, argv);

	char str[20] = "TESTING";

	ff.dataFrame.pdu = &str[0];


	meta.u_IPdst = IP4_ADR_P2N(192,168,1,28);
	meta.u_IPsrc = IP4_ADR_P2N(192,168,1,28);
	meta.u_destPort = 13;
	meta.u_srcPort = 1087;



	ff.dataFrame.pduLength = 7;
	ff.dataOrCtrl = DATA;
	ff.destinationID = UDPID;
	ff.dataFrame.directionFlag = DOWN;


	memcpy(&ff.dataFrame.metaData, &meta, 16);
	pff = &ff;

//	printf("The metadata's value for the length is %d\n", pseudoheader2.u_pslen);
//	printf("The UDP packet's value for the length is %d\n", packet2.u_len);

/* Time to split into two processes
 *  1) the child Process is for capturing (incoming)
 *  2) the parent process is for injecting frames (outgoing)
 */

	/* inject handler is initialized earlier to make sure that forwarding
	 * feature is able to work even if the parent process did not start injecting yet
	 */
	inject_init();
	pid_t pID = fork();
	int status;
	   if (pID == 0)                // child
	   {
	      // Code only executed by child process
	/*	   PRINT_DEBUG("child started to capture");
		   capture_init();
		   pcap_close ( capture_handle );
*/



	    }
	    else if (pID < 0)            // failed to fork
	    {
	        PRINT_DEBUG("\n Error while forking, program will exit");
	        exit(1);
	        // Throw exception
	    }
	    else                                   // parent
	    {
	      // Code only executed by parent process
	    	PRINT_DEBUG("parent started to inject");

	    	int i=0;

	    	for ( i=0; i< 20; i++ )
	    	{
	    		sleep(1);
	    		PRINT_DEBUG("#%d",i);
	    		udp_out_fdf(pff);
	    		PRINT_DEBUG("UDP done");


	    	}

	    	/* terminate the wifi module */
	    	wifi_terminate();

	    	/* wait until the child return */
			wait(&status);
				if (WIFEXITED(status))
				{
					PRINT_DEBUG("Parent: child has exited normally with status %d", WEXITSTATUS(status));
				}

				else
				{
					PRINT_DEBUG("Parent: child has not terminated normally");
				}


	    }




	return (0);
}
#include <unistd.h>
#include <sys/wait.h>

#include <pthread.h>
#include <pcap.h>

#include "finstypes.h"
#include "finsdebug.h"
#include "udp.h"
#include "IP4.h"
#include "wifimod.h"

#define DEBUG
#define ERROR

IP4addr my_ip_addr = IP4_ADR_P2N(192,168,1,28);
IP4addr my_mask = IP4_ADR_P2N(255, 255, 255, 0);
struct ip4_routing_table* routing_table;
struct ip4_stats stats;

struct udp_statistics udpStat;



/* packet inject handle */
pcap_t *inject_handle;

/* packet capture handle */
pcap_t *capture_handle;