Exemplo n.º 1
0
void sendto_udp(unsigned long long uniqueSockID, int socketCallType,
		int datalen, u_char *data, int flags, struct sockaddr_in *addr,
		socklen_t addrlen) {

	uint16_t hostport;
	uint16_t dstport;
	uint32_t host_IP;
	uint32_t dst_IP;

	int len = datalen;
	int index;
	int i;

	struct in_addr *temp;

	PRINT_DEBUG();

	/** TODO handle flags cases */
	switch (flags) {
	case MSG_CONFIRM:
	case MSG_DONTROUTE:
	case MSG_DONTWAIT:
	case MSG_EOR:
	case MSG_MORE:
	case MSG_NOSIGNAL:
	case MSG_OOB: /** case of recieving a (write call)*/
	default:
		break;

	}
	PRINT_DEBUG("");

	index = findjinniSocket(uniqueSockID);
	if (index == -1) {
		PRINT_DEBUG("CRASH !! socket descriptor not found into jinni sockets");
		return;
	}

	if (addr->sin_family != AF_INET) {
		PRINT_DEBUG("Wrong address family");
		nack_send(uniqueSockID, socketCallType);
		return;
	}

	/** copying the data passed to be able to free the old memory location
	 * the new created location is the one to be included into the newly created finsFrame*/
	PRINT_DEBUG("");

	dst_IP = ntohl(addr->sin_addr.s_addr);/** it is in network format since application used htonl */
	/** addresses are in host format given that there are by default already filled
	 * host IP and host port. Otherwise, a port and IP has to be assigned explicitly below */

	/** Keep all ports and addresses in host order until later  action taken */
	dstport = ntohs(addr->sin_port); /** reverse it since it is in network order after application used htons */

	/**
	 * the current value of host_IP is zero but to be filled later with
	 * the current IP using the IPv4 modules unless a binding has occured earlier
	 */
	host_IP = jinniSockets[index].host_IP;

	/**
	 * Default current host port to be assigned is 58088
	 * It is supposed to be randomly selected from the range found in
	 * /proc/sys/net/ipv4/ip_local_port_range
	 * default range in Ubuntu is 32768 - 61000
	 * The value has been chosen randomly when the socket firstly inserted into the jinnisockets
	 * check insertjinniSocket(processid, sockfd, fakeID, type, protocol);
	 */
	hostport = jinniSockets[index].hostport;
	if (hostport == (uint16_t)(-1)) {
		while (1) {
			hostport = randoming(MIN_port, MAX_port);
			if (checkjinniports(hostport, host_IP)) {
				break;
			}
		}
		jinniSockets[index].hostport = hostport;
	}

	PRINT_DEBUG("");

	PRINT_DEBUG("index=%d, dst=%d/%d, host=%d/%d", index, dst_IP, dstport,
			host_IP, hostport);

	temp = (struct in_addr *) malloc(sizeof(struct in_addr));
	temp->s_addr = host_IP;
	PRINT_DEBUG("index=%d, dst=%s/%d, host=%s/%d", index, inet_ntoa(
			addr->sin_addr), dstport, inet_ntoa(*temp), hostport);
	//free(data);
	//free(addr);
	PRINT_DEBUG("");

	/** the meta-data parameters are all passes by copy starting from this point
	 *
	 */
	if (jinni_UDP_to_fins(data, len, dstport, dst_IP, hostport, host_IP) == 1)

	{
		/** TODO prevent the socket interceptor from holding this semaphore before we reach this point */
		PRINT_DEBUG("");

		ack_send(uniqueSockID, socketCallType);
		PRINT_DEBUG("");

	} else {
		PRINT_DEBUG("socketjinni failed to accomplish sendto");
		nack_send(uniqueSockID, socketCallType);
	}

	return;

} //end of sendto_udp
Exemplo n.º 2
0
void sendto_udp(int senderid,int sockfd,int datalen,u_char *data,int flags,
		struct sockaddr *addr,socklen_t addrlen)
{

		uint16_t hostport;
		uint16_t dstport;
		uint32_t host_IP;
		uint32_t dst_IP;

		int len=datalen;
		int index;

		/** check if the original call is either (sendto) or (send) or (write)*/
		if ( (addr == NULL) &&  (addrlen == 0) && (flags != -1000) )
		{
			/** In case of (send) */
			PRINT_DEBUG();
	return ( send_udp(senderid,sockfd,datalen,data,flags) ) ;

		}

		if ( (addr == NULL) &&  (addrlen == 0) && (flags == -1000))
		{
			PRINT_DEBUG();

			/** In case of (write) */
			 return ( write_udp (senderid,sockfd,datalen,data) ) ;
		}
		PRINT_DEBUG();

		/** TODO handle flags cases */
			switch (flags)
			{
			case MSG_CONFIRM:
			case MSG_DONTROUTE:
			case MSG_DONTWAIT :
			case MSG_EOR:
			case MSG_MORE :
			case MSG_NOSIGNAL:
			case MSG_OOB: /** case of recieving a (write call)*/
			default:
			break;


			}
		PRINT_DEBUG("");

		struct sockaddr_in *address;
		address = (struct sockaddr_in *) addr;
		/** TODO lock access to the jinnisockets */

		index = findjinniSocket(senderid,sockfd);
		PRINT_DEBUG("");

		/** TODO unlock access to the jinnisockets */
		if (index == -1)
			{
				PRINT_DEBUG("CRASH !! socket descriptor not found into jinni sockets");
				exit(1);
			}

		if (address->sin_family != AF_INET )
		{
			PRINT_DEBUG("Wrong address family");
			PRINT_DEBUG("");

			sem_wait(jinniSockets[index].s);
				PRINT_DEBUG("");

				nack_write(jinniSockets[index].jinniside_pipe_ds,senderid,sockfd);
				sem_post(jinniSockets[index].as);

			sem_post(jinniSockets[index].s);
			PRINT_DEBUG("");

		}

/** copying the data passed to be able to free the old memory location
 * the new created location is the one to be included into the newly created finsFrame*/
		PRINT_DEBUG("");

/** Keep all ports and addresses in host order until later  action taken */
dstport =ntohs( address->sin_port); /** reverse it since it is in network order after application used htons */
if (dst_IP != INADDR_LOOPBACK)
dst_IP = ntohl(address-> sin_addr.s_addr);/** it is in network format since application used htonl */
else
	dst_IP = ntohl(address-> sin_addr.s_addr);
//hostport = jinniSockets[index].hostport;
hostport = 3000;
host_IP = jinniSockets[index].host_IP;
PRINT_DEBUG("");

PRINT_DEBUG("%d,%d,%d,%d", dst_IP, dstport, host_IP,hostport);
//free(data);
//free(addr);
PRINT_DEBUG("");

/** the meta-data paraters are all passes by copy starting from this point
 *
 */
if (jinni_UDP_to_fins(data,len,dstport,dst_IP,hostport,host_IP)== 1)

{
	PRINT_DEBUG("");
 /** TODO prevent the socket interceptor from holding this semaphore before we reach this point */
	sem_wait(jinniSockets[index].s);
		PRINT_DEBUG("");

		ack_write(jinniSockets[index].jinniside_pipe_ds,senderid,sockfd);
		sem_post(jinniSockets[index].as);

	sem_post(jinniSockets[index].s);
	PRINT_DEBUG("");

}
else
{
	PRINT_DEBUG("socketjinni failed to accomplish sendto");
	sem_wait(jinniSockets[index].s);
		nack_write(jinniSockets[index].jinniside_pipe_ds,senderid,sockfd);
		sem_post(jinniSockets[index].as);

	sem_post(jinniSockets[index].s);

}


return;

} //end of sendto_udp
Exemplo n.º 3
0
void send_udp(unsigned long long uniqueSockID, int socketCallType, int datalen,
		u_char *data, int flags) {

	uint16_t hostport;
	uint16_t dstport;
	uint32_t host_IP;
	uint32_t dst_IP;
	int len = datalen;
	int index;

	if (flags == -1000) {

		return (write_udp(uniqueSockID, socketCallType, datalen, data));

	}
	/** TODO handle flags cases */
	switch (flags) {
	case MSG_CONFIRM:
	case MSG_DONTROUTE:
	case MSG_DONTWAIT:
	case MSG_EOR:
	case MSG_MORE:
	case MSG_NOSIGNAL:
	case MSG_OOB: /** case of recieving a (write call)*/
	default:
		break;
	} // end of the switch clause

	PRINT_DEBUG("");

	index = findjinniSocket(uniqueSockID);
	if (index == -1) {
		PRINT_DEBUG("CRASH !! socket descriptor not found into jinni sockets");
		return;
	}

	/** copying the data passed to be able to free the old memory location
	 * the new created location is the one to be included into the newly created finsFrame*/
	PRINT_DEBUG("");
	/** check if this socket already connected to a destined address or not */

	if (jinniSockets[index].connection_status == 0) {
		/** socket is not connected to an address. Send call will fail */

		PRINT_DEBUG("socketjinni failed to accomplish send");
		nack_send(uniqueSockID, socketCallType);
		return;
	}

	/** Keep all ports and addresses in host order until later  action taken */
	dstport = jinniSockets[index].dstport;

	dst_IP = jinniSockets[index].dst_IP;

	//hostport = jinniSockets[index].hostport;
	//hostport = 3000;

	/** addresses are in host format given that there are by default already filled
	 * host IP and host port. Otherwise, a port and IP has to be assigned explicitly below */

	/**
	 * the current value of host_IP is zero but to be filled later with
	 * the current IP using the IPv4 modules unless a binding has occured earlier
	 */
	host_IP = jinniSockets[index].host_IP;

	/**
	 * Default current host port to be assigned is 58088
	 * It is supposed to be randomly selected from the range found in
	 * /proc/sys/net/ipv4/ip_local_port_range
	 * default range in Ubuntu is 32768 - 61000
	 * The value has been chosen randomly when the socket firstly inserted into the jinnisockets
	 * check insertjinniSocket(processid, sockfd, fakeID, type, protocol);
	 */
	hostport = jinniSockets[index].hostport;
	if (hostport == (uint16_t)(-1)) {
		while (1) {
			hostport = randoming(MIN_port, MAX_port);
			if (checkjinniports(hostport, host_IP)) {
				break;
			}
		}
		jinniSockets[index].hostport = hostport;
	}

	PRINT_DEBUG("");

	PRINT_DEBUG("addr %d,%d,%d,%d", dst_IP, dstport, host_IP, hostport);
	//free(data);
	//free(addr);
	PRINT_DEBUG("");

	/** the meta-data paraters are all passes by copy starting from this point
	 *
	 */
	if (jinni_UDP_to_fins(data, len, dstport, dst_IP, hostport, host_IP) == 1)

	{
		PRINT_DEBUG("");
		/** TODO prevent the socket interceptor from holding this semaphore before we reach this point */
		PRINT_DEBUG("");

		ack_send(uniqueSockID, socketCallType);
		PRINT_DEBUG("");

	} else {
		PRINT_DEBUG("socketjinni failed to accomplish send");
		nack_send(uniqueSockID, socketCallType);
	}
}// end of send_udp