Example #1
0
void recv_call_handler(unsigned long long uniqueSockID, int threads,
		unsigned char *buf, ssize_t len) {

	int index;
	int datalen;
	int flags;
	u_char *pt;

	PRINT_DEBUG();

	pt = buf;

	datalen = *(size_t *) pt;
	pt += sizeof(size_t);

	flags = *(int *) pt;
	pt += sizeof(int);

	if (pt - buf != len) {
		PRINT_DEBUG("READING ERROR! CRASH, diff=%d len=%d", pt - buf, len);
		nack_send(uniqueSockID, recv_call);
		return;
	}

	/** Notice that send is only used with tcp connections since
	 * the receiver is already known
	 */
	index = findjinniSocket(uniqueSockID);
	if (index == -1) {
		PRINT_DEBUG("CRASH !!socket descriptor not found into jinni sockets");
		nack_send(uniqueSockID, recv_call);
		return;
	}

	if (jinniSockets[index].type == SOCK_DGRAM) {
		/** Whenever we need to implement non_blocking mode using
		 * threads. We will call the function below using thread_create
		 */

		recv_udp(uniqueSockID, datalen, flags);

	} else if (jinniSockets[index].type == SOCK_STREAM) {
		recv_tcp(uniqueSockID, datalen, flags);

	} else {
		PRINT_DEBUG("This socket is of unknown type");
		nack_send(uniqueSockID, recv_call);
	}

} // end of recv_call_handler()
Example #2
0
void cb_rw(int fd, short event, void *args)
{
    connection *c = (connection *)args;

    if(event == EV_READ) {
        if(c->transport == SOCK_STREAM)
            recv_tcp(c);
        else
            recv_udp(c);
    }
   
    if(event == EV_WRITE) {
        if(c->transport == SOCK_STREAM)
            send_tcp(c);
        else
            send_udp(c);
    }
}
Example #3
0
/* Process remote command */
static void
uremote(
    struct iface *iface,
    struct udp_cb *up,
    int cnt)
{

    struct mbuf *bp;
    struct socket fsock;
    char command;
    int32 addr;

    recv_udp(up,&fsock,&bp);
    command = PULLCHAR(&bp);
    switch(command & 0xff) {
    case SYS__EXIT:
        if(chkrpass(bp) == 0) {
            logmsg(NULL,"%s - Remote exit PASSWORD FAIL",
                   pinet_udp(&fsock));
        } else {
            logmsg(NULL,"%s - Remote exit PASSWORD OK",
                   pinet_udp(&fsock));
            main_exit = 1;
        }
        break;
    case KICK__ME:
        if(len_p(bp) >= sizeof(int32))
            addr = pull32(&bp);
        else
            addr = fsock.address;
        kick(addr);
        /*** smtptick((void *)addr); ***/
        break;
    }
    free_p(&bp);
}