コード例 #1
0
ファイル: tcp.c プロジェクト: DavidGarriou/RIOT
void handle_tcp_fin_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
                           socket_internal_t *tcp_socket)
{
    (void) ipv6_header;

    msg_t m_send;
    socket_t *current_tcp_socket = &tcp_socket->socket_values;
    uint8_t send_buffer[BUFFER_SIZE];
    ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
    tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));

    set_tcp_cb(&current_tcp_socket->tcp_control, tcp_header->seq_nr + 1,
               current_tcp_socket->tcp_control.send_wnd, tcp_header->ack_nr + 1,
               tcp_header->ack_nr, tcp_header->window);

#ifdef TCP_HC
    current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif

    if (current_tcp_socket->tcp_control.state == TCP_FIN_WAIT_1) {
        current_tcp_socket->tcp_control.state = TCP_CLOSING;

        send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
    }
    else {
        current_tcp_socket->tcp_control.state = TCP_LAST_ACK;

        send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
    }

    net_msg_send(&m_send, tcp_socket->recv_pid, 0, CLOSE_CONN);
}
コード例 #2
0
static void send_junk_data_super(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num, unsigned int ack_num,
        int len)
{
    struct send_tcp_vars vars;
    //log_debug("size of vars: %ld", sizeof vars);
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = 0;//TCP_ACK;
    vars.seq_num = seq_num;
    //vars.ack_num = htonl(ntohl(ack_num) + 10000);
    vars.ack_num = ack_num;
    vars.wrong_tcp_checksum = 1;

    vars.payload_len = len;
    int i;
    for (i = 0; i < len; i++) {
        vars.payload[i] = '.';
    }

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #3
0
ファイル: mixed_ms_rd.c プロジェクト: NeverMore93/INTANG
static void send_fake_SYN(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num)
{
    char pkt[MAX_PACKET_SIZE];

    struct send_tcp_vars vars;
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = TCP_SYN;
    vars.seq_num = seq_num;
    vars.ack_num = 0;
    //vars.wrong_tcp_checksum = 1;

    // mss
    u_char bytes[4] = {0x02, 0x04, 0x05, 0xb4};
    memcpy(vars.tcp_opt, bytes, 4);
    vars.tcp_opt_len = 4;

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #4
0
ファイル: do_super.c プロジェクト: NeverMore93/INTANG
static void send_junk_data_super(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num, unsigned int ack_num,
        int len, unsigned char ttl)
{
    struct send_tcp_vars vars;
    //log_debug("size of vars: %ld", sizeof vars);
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = TCP_ACK;
    vars.seq_num = seq_num;
    vars.ack_num = htonl(ntohl(ack_num) + 1000);
    vars.ack_num = ack_num;
    //vars.wrong_tcp_checksum = 1;
    vars.ttl = ttl;
    
    u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
    memcpy(vars.tcp_opt, bytes, 20);
    vars.tcp_opt_len = 20;

    vars.payload_len = len;
    int i;
    for (i = 0; i < len; i++) {
        vars.payload[i] = '.';
    }

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #5
0
ファイル: test_probing_ttl.c プロジェクト: NeverMore93/INTANG
static void send_fake_payload(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num, unsigned int ack_num)
{
    char pkt[MAX_PACKET_SIZE];

    struct send_tcp_vars vars;
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = TCP_ACK;
    //vars.seq_num = htonl(ntohl(seq_num) + (rand() % 10000000 + 1000000));
    vars.seq_num = seq_num;
    vars.ack_num = ack_num;
    //vars.wrong_tcp_checksum = 1;

    u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
    memcpy(vars.tcp_opt, bytes, 20);
    vars.tcp_opt_len = 20;

    vars.payload_len = 1;
    vars.payload[0] = 'A';

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #6
0
ファイル: k_tcp.c プロジェクト: atikbif/Relkon6
void porttcp_scan(tcp_pkt* pkt1, ip_pkt* pkt2)
{
	unsigned short tmp,res=0;

	for(tmp=0;tmp<TCP_PORT_SIZE;tmp++)
	{
		if(tcp_tab[tmp].stat){if(tcp_tab[tmp].port == pkt1->p_d) {res=1;break;}}
	}
	if(res==0) return;

	if(pkt1->buf.len==0)
	{
		if(pkt1->fl == (FL_FIN | FL_ACK))
		{
			answer_tcpack(pkt1,pkt2);
			pkt1->fl = FL_FIN | FL_ACK;
			send_tcp(pkt1,pkt2);
			return;
		}
		if(pkt1->fl == FL_SYN)
		{
			answer_syn(pkt1,pkt2);
			return;
		}
		if(pkt1->fl & FL_PSH)
		{
			answer_tcpack(pkt1,pkt2);
			return;
		}
	}
	else {tcp_tab[tmp].function(pkt1,pkt2);}

}
コード例 #7
0
ファイル: tcpsock.c プロジェクト: zidier215/tcpip
int
so_tcp_send(struct usock *up,struct mbuf **bpp,struct sockaddr *to)
{
	struct tcb *tcb;
	long cnt;

	if((tcb = up->cb.tcb) == NULL){
		free_p(bpp);
		errno = ENOTCONN;
		return -1;
	}		
	cnt = send_tcp(tcb,bpp);

	while((tcb = up->cb.tcb) != NULL &&
	 tcb->sndcnt > tcb->window){
		/* Send queue is full */
		if(up->noblock){
			errno = EWOULDBLOCK;
			return -1;
		} else if((errno = kwait(up)) != 0){
			return -1;
		}
	}
	if(tcb == NULL){
		errno = ENOTCONN;
		return -1;
	}
	return cnt;
}
コード例 #8
0
ファイル: dos_attack.c プロジェクト: 0x0mar/ettercap
/* 
 * Populate the open port list and reply to 
 * SYN-ACK packets from victim host
 */
static void parse_tcp(struct packet_object *po)
{
   struct port_list *p;
   
   /* Check if it's a reply to our SYN flooding */
   if (ip_addr_cmp(&fake_host, &po->L3.dst) ||
       ip_addr_cmp(&victim_host, &po->L3.src) || 
       po->L4.flags != (TH_SYN | TH_ACK))  
          return;
	  
   /* Complete the handshake with an ACK */
   send_tcp(&fake_host, &victim_host, po->L4.dst, po->L4.src, po->L4.ack, htonl( ntohl(po->L4.seq) + 1), TH_ACK, NULL, 0);
   
   /* Check if the port is already in the "open" list... */
   SLIST_FOREACH(p, &port_table, next) 
      if (p->port == po->L4.src)
         return;
   
   /* If not...put it in */
   SAFE_CALLOC(p, 1, sizeof(struct port_list));
   p->port = po->L4.src;
   SLIST_INSERT_HEAD(&port_table, p, next);
   
   INSTANT_USER_MSG("dos_attack: Port %d added\n", ntohs(p->port));
}
コード例 #9
0
ファイル: client.c プロジェクト: tamy83/baresip-android-mtt
static bool tcpconn_fail_handler(struct le *le, void *arg)
{
	struct dns_query *q = le->data;
	int err = *((int *)arg);

	list_unlink(&q->le_tc);
	q->tc = mem_deref(q->tc);

	if (q->ntx >= *q->srvc) {
		DEBUG_WARNING("all servers failed, giving up!!\n");
		err = err ? err : ECONNREFUSED;
		goto out;
	}

	/* try next server(s) */
	err = send_tcp(q);
	if (err) {
		DEBUG_WARNING("all servers failed, giving up\n");
		goto out;
	}

 out:
	if (err) {
		query_handler(q, err, NULL, NULL, NULL, NULL);
		mem_deref(q);
	}

	return false;
}
コード例 #10
0
static void send_data(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num, unsigned int ack_num,
        unsigned char *payload, unsigned int payload_len)
{
    struct send_tcp_vars vars;
    //log_debug("size of vars: %ld", sizeof vars);
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = TCP_ACK;
    vars.seq_num = seq_num;
    vars.ack_num = ack_num;
    //vars.wrong_tcp_checksum = 1;

    /*
    u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
    memcpy(vars.tcp_opt, bytes, 20);
    vars.tcp_opt_len = 20;
    */

    vars.payload_len = payload_len;
    memcpy(vars.payload, payload, payload_len);

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #11
0
static void send_RST_super(
        const char *src_ip, unsigned short src_port, 
        const char *dst_ip, unsigned short dst_port,
        unsigned int seq_num)
{
    char pkt[MAX_PACKET_SIZE];

    struct send_tcp_vars vars;
    //log_debug("size of vars: %ld", sizeof vars);
    memset(&vars, 0, sizeof vars);
    strncpy(vars.src_ip, src_ip, 16);
    strncpy(vars.dst_ip, dst_ip, 16);
    vars.src_port = src_port;
    vars.dst_port = dst_port;
    vars.flags = TCP_RST;// | TCP_ACK;
    vars.seq_num = htonl(ntohl(seq_num) + 10);
    vars.ack_num = 0;
    //vars.wrong_tcp_checksum = 1;
    //vars.ttl = ttl;

    //u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
    //memcpy(vars.tcp_opt, bytes, 20);
    //vars.tcp_opt_len = 20;

    //dump_send_tcp_vars(&vars);

    send_tcp(&vars);
}
コード例 #12
0
ファイル: output_tcp.c プロジェクト: AstroProfundis/tsar
void
output_tcp(int have_collect)
{
    int        fd, flags, res;
    fd_set     fdr, fdw;
    struct     timeval timeout;
    struct     sockaddr_in db_addr;

    fd = socket(AF_INET, SOCK_STREAM, 0);
    if (fd < 0) {
        do_debug(LOG_FATAL, "can't get socket");
    }

    /* set socket fd noblock */
    if ((flags = fcntl(fd, F_GETFL, 0)) < 0) {
        close(fd);
        return;
    }

    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
        close(fd);
        return;
    }

    /* get db server address */
    db_addr = *str2sa(conf.output_tcp_addr);

    if (connect(fd, (struct sockaddr*)&db_addr, sizeof(db_addr)) != 0) {
        if (errno != EINPROGRESS) { // EINPROGRESS
            close(fd);
            return;

        } else {
            goto select;
        }

    } else {
        goto send;
    }

select:
    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    FD_SET(fd, &fdr);
    FD_SET(fd, &fdw);

    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

    res = select(fd + 1, &fdr, &fdw, NULL, &timeout);
    if (res <= 0) {
        close(fd);
        return;
    }

send:
    send_tcp(fd, have_collect);
    close(fd);
}
コード例 #13
0
ファイル: ec_filter.c プロジェクト: bonsaiviking/ettercap
/*
 * kill the connection:
 *    TCP:  reset
 *    UDP:  icmp port unreachable
 */
static int func_kill(struct packet_object *po)
{
   DEBUG_MSG("filter engine: func_kill");

   if (po->L4.proto == NL_TYPE_TCP) {
      /* reset both sides */
      /* 
       * we can trust the ack number.
       * at least one side will be reset. the other is automatically reset 
       */
      send_tcp(&po->L3.src, &po->L3.dst, po->L4.src, po->L4.dst, po->L4.seq, 0, TH_RST);
      send_tcp(&po->L3.dst, &po->L3.src, po->L4.dst, po->L4.src, po->L4.ack, 0, TH_RST);
   } else if (po->L4.proto == NL_TYPE_UDP) {
      send_L3_icmp_unreach(po);
   }
   
   return ESUCCESS;
}
コード例 #14
0
ファイル: tcp.c プロジェクト: fjrk/RIOT
void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
                                socket_internal_t *tcp_socket, uint8_t *payload)
{
    uint8_t tcp_payload_len = ipv6_header->length - TCP_HDR_LEN, read_bytes = 0;
    socket_t *current_tcp_socket = &tcp_socket->socket_values;
    uint8_t send_buffer[BUFFER_SIZE];
    ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
    tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));

    if (tcp_payload_len > 0) {

        if (check_tcp_consistency(current_tcp_socket, tcp_header) == PACKET_OK) {
            read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload);

            /* Refresh TCP status values */
            current_tcp_socket->tcp_control.state = ESTABLISHED;

            set_tcp_cb(&current_tcp_socket->tcp_control,
                       tcp_header->seq_nr + read_bytes,
                       current_tcp_socket->tcp_control.rcv_wnd,
                       current_tcp_socket->tcp_control.send_nxt,
                       current_tcp_socket->tcp_control.send_una,
                       current_tcp_socket->tcp_control.send_wnd);

            /* Send packet */
            //			block_continue_thread();
#ifdef TCP_HC
            current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif
            send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
        }
        /* ACK packet probably got lost */
        else {
            //			block_continue_thread();
#ifdef TCP_HC
            current_tcp_socket->tcp_control.tcp_context.hc_type = FULL_HEADER;
#endif
            send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
        }
    }
}
コード例 #15
0
ファイル: http.c プロジェクト: tempbottle/torrentkino
void http_send(TCP_NODE * n)
{
	if (n->pipeline == NODE_SHUTDOWN) {
		return;
	}

	/* Prepare event system for sending data */
	node_status(n, NODE_SEND_INIT);

	/* Start sending */
	send_tcp(n);
}
コード例 #16
0
ファイル: ftpserv.c プロジェクト: dieterdeyke/WAMPES
/* Do printf on a tcp connection */
static void Xprintf(struct tcb *tcb,char *message,char *arg1,char *arg2,char *arg3)
{
	struct mbuf *bp;

	if(tcb == NULL)
		return;

	bp = alloc_mbuf(256);
	sprintf((char *) bp->data,message,arg1,arg2,arg3);
	bp->cnt = strlen((char *) bp->data);
	send_tcp(tcb,&bp);
}
コード例 #17
0
ファイル: tcp.c プロジェクト: torrentkino/tumbleweed
void tcp_output( ITEM *i ) {
	TCP_NODE *n = list_value( i );

	switch( n->pipeline ) {
		case NODE_SEND_INIT:
		case NODE_SEND_DATA:
		case NODE_SEND_STOP:
			/* Send file */
			send_tcp( n );
			break;
	}
}
コード例 #18
0
ファイル: discrepancy.c プロジェクト: NeverMore93/INTANG
void send_insertion_packet(struct send_tcp_vars *vars, unsigned int flags)
{
    if (flags & INS_DISC_SMALL_TTL) {
        unsigned char ttl = get_ttl(str2ip(vars->dst_ip));
        vars->ttl = ttl - 3;
    }

    if (flags & INS_DISC_BAD_TCP_CHECKSUM) {
        vars->wrong_tcp_checksum = 1;
    }

    if (flags & INS_DISC_NO_TCP_FLAG) {
        // this will override existing flags
        vars->flags = 0;
    }

    if (flags & INS_DISC_BAD_ACK_NUM) {
        // ack number in the future, is it good for all cases?
        vars->ack_num + 100000;
    }

    if (flags & INS_DISC_MD5) {
        u_char bytes[20] = {0x13,0x12,0xf9,0x89,0x5c,0xdd,0xa6,0x15,0x12,0x83,0x3e,0x93,0x11,0x22,0x33,0x44,0x55,0x66,0x01,0x01};
        memcpy(vars->tcp_opt + vars->tcp_opt_len, bytes, 20);
        vars->tcp_opt_len += 20;
    }

    if (flags & INS_DISC_OLD_TIMESTAMP) {
        // check if there's timestamp 
        int i;
        for (i = 0; i < vars->tcp_opt_len; i++) {
            unsigned char kind = vars->tcp_opt[i];
            if (kind == 1) continue;  // padding
            unsigned char len = vars->tcp_opt[i + 1];
            if (kind == 8) // Timestamp
            {
                unsigned int *tsval = (unsigned int*)(vars->tcp_opt + i + 2);
                *tsval = htonl(ntohl(*tsval) - 10000);
                break;
            }
            else 
            {
                i += len;
            }
        }
    }

    //dump_send_tcp_vars(vars);

    send_tcp(vars);
}
コード例 #19
0
ファイル: k_tcp.c プロジェクト: atikbif/Relkon6
void answer_syn(tcp_pkt* pkt1,ip_pkt* pkt2)
{
	unsigned char tmp;
	for(tmp=0;tmp<4;tmp++) pkt2->ip_d[tmp] = pkt2->ip_s[tmp];
	tmp_buf[0]=pkt1->p_s;
	pkt1->p_s = pkt1->p_d;
	pkt1->p_d = tmp_buf[0];
	tmp_buf[0]=pkt1->n_tr;
	pkt1->n_tr = tcp_tmr;
	pkt1->n_rcv = tmp_buf[0]+1;
	pkt1->fl = FL_ACK | FL_SYN;
	pkt1->buf.len=0;
	send_tcp(pkt1,pkt2);
}
コード例 #20
0
ファイル: socket.c プロジェクト: manoja328/RIOT
int destiny_socket_close(int s)
{
    socket_internal_t *current_socket = get_socket(s);

    if (current_socket != NULL) {
        if (is_tcp_socket(s)) {
            /* Variables */
            msg_t m_recv;
            uint8_t send_buffer[BUFFER_SIZE];
            ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
            tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));

            /* Check if socket exists and is TCP socket */
            if (!is_tcp_socket(s)) {
                return -1;
            }

            /* Check for ESTABLISHED STATE */
            if (current_socket->socket_values.tcp_control.state != ESTABLISHED) {
                close_socket(current_socket);
                return 0;
            }

            current_socket->send_pid = thread_getpid();

            /* Refresh local TCP socket information */
            current_socket->socket_values.tcp_control.send_una++;
            current_socket->socket_values.tcp_control.state = FIN_WAIT_1;
#ifdef TCP_HC
            current_socket->socket_values.tcp_control.tcp_context.hc_type =
                COMPRESSED_HEADER;
#endif

            send_tcp(current_socket, current_tcp_packet, temp_ipv6_header,
                     TCP_FIN, 0);
            msg_receive(&m_recv);
            close_socket(current_socket);
            return 1;
        }
        else if (isUDPSocket(s)) {
            close_socket(current_socket);
            return 0;
        }

        return -1;
    }
    else {
        return -1;
    }
}
コード例 #21
0
ファイル: smisc.c プロジェクト: dieterdeyke/WAMPES
/* TCP echo server
 * Copies only as much will fit on the transmit queue
 */
static void
echo_server(
    struct tcb *tcb,
    int32 cnt)
{
    int32 acnt;
    struct mbuf *bp;

    acnt = tcb->window - tcb->sndcnt;
    if (acnt > tcb->rcvcnt)
        acnt = tcb->rcvcnt;
    if (acnt > 0) {
        if (recv_tcp(tcb, &bp, acnt) > 0)
            send_tcp(tcb, &bp);
    }
}
コード例 #22
0
ファイル: tcp.c プロジェクト: wwttt2004/torrentkino
void tcp_output( ITEM *listItem ) {
	TCP_NODE *n = list_value( listItem );
	
	switch( n->mode ) {
		case NODE_MODE_SEND_INIT:
		case NODE_MODE_SEND_MEM:
		case NODE_MODE_SEND_FILE:
		case NODE_MODE_SEND_STOP:
			
			/* Reset timeout counter */
			node_activity( n );
			
			/* Send file */
			send_tcp( n );
			break;
	}
}
コード例 #23
0
ファイル: client.c プロジェクト: bleepster/puffpuff
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);
    }
}
コード例 #24
0
ファイル: plug.c プロジェクト: easymc/easymc
int emc_send(int plug, void * msg, int flag){
	int result=-1;
	struct easymc_plug * pg = (struct easymc_plug *)global_get_plug(plug);
	if(!pg){
		errno = ENOPLUG;
		return -1;
	}
	if(pg->ipc_){
		if(0 == send_ipc(pg->ipc_, msg, flag)){
			result = 0;
		}
	}
	if(pg->tcp_){
		if(0 == send_tcp(pg->tcp_, msg, flag)){
			result = 0;
		}
	}
	return result;
}
コード例 #25
0
ファイル: tcpgate.c プロジェクト: dieterdeyke/WAMPES
static void tcp_send(struct tcb *tcb)
{

  int cnt;
  struct mbuf *bp;

  if ((cnt = space_tcp(tcb)) <= 0) {
    off_read(tcb->user);
    return;
  }
  if (!(bp = alloc_mbuf(cnt))) return;
  cnt = read(tcb->user, bp->data, (unsigned) cnt);
  if (cnt <= 0) {
    free_p(&bp);
    off_read(tcb->user);
    close_tcp(tcb);
    return;
  }
  bp->cnt = cnt;
  send_tcp(tcb, &bp);
}
コード例 #26
0
ファイル: msgclient.c プロジェクト: taysom/tau
int send_tau (ki_t k, void *msg)
{
	msg_s		*m = msg;
	msgbuf_s	*mb;
	packet_s	*p;
	key_s		key;
	gate_s		*gate;
	process_s	*avatar;

	key = get_key(k);
	if (!key.k_id) return EBADKEY;
	if (key.k_type & ONCE) rmv_key(k);

	mb = emalloc(sizeof(msgbuf_s));

	memmove( &mb->mb_body, &m->b, sizeof(mb->mb_body));

	p = &mb->mb_packet;

	gate = find_gate(key.k_id);
	if (!gate) {
		/* Broken gate */
		free(mb);
		return 0;
	}
	p->pk_sys.q_tag = gate->gt_tag;
	p->pk_sys.q_passed_key = 0;
	avatar = gate->gt_avatar;

	if (gate->gt_type & ONCE) delete_gate(gate->gt_id);

	send_tcp(mb);
	free(mb);

	//enq_dq( &avatar->pr_msgq, mb, mb_process);
	return 0;
}
コード例 #27
0
ファイル: tcp.c プロジェクト: fjrk/RIOT
void handle_tcp_fin_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
                               socket_internal_t *tcp_socket)
{
    msg_t m_send;
    socket_t *current_tcp_socket = &tcp_socket->socket_values;
    uint8_t send_buffer[BUFFER_SIZE];
    ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
    tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));

    current_tcp_socket->tcp_control.state = CLOSED;

    set_tcp_cb(&current_tcp_socket->tcp_control, tcp_header->seq_nr + 1,
               current_tcp_socket->tcp_control.send_wnd, tcp_header->ack_nr,
               tcp_header->ack_nr, tcp_header->window);

#ifdef TCP_HC
    current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif

    send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);

    msg_send(&m_send, tcp_socket->send_pid, 0);
    msg_send(&m_send, tcp_socket->recv_pid, 0);
}
コード例 #28
0
ファイル: scan.c プロジェクト: savagejen/hping
/* -------------------------------- output ---------------------------------- */
static void sender(struct portinfo *pi)
{
	int i, retry = 0;
	time_t start_time;

	start_time = get_midnight_ut_ms();

	while(1) {
		int active = 0;
		int recvd = 0;
		retry ++;
		for (i = 0; i < MAXPORT; i++) {
			if (pi[i].active && pi[i].retry) {
				active++;
				pi[i].retry--;
				sequence = -1;
				dst_port = i;
				pi[i].sentms = get_midnight_ut_ms();
				send_tcp();
				if (opt_waitinusec) {
					if (usec_delay.it_interval.tv_usec)
						usleep(usec_delay.it_interval.tv_usec);
				} else {
					sleep(sending_wait);
				}
			}
		}
		avrgms = (float) pi[MAXPORT+1].active;
		if (retry >= 3) {
			if (opt_debug)
				printf("AVRGMS %f\n", avrgms);
			if (avrgms)
				usleep((int) (avrgms*1000));
			else
				sleep(1);
		}
		for (i = 0; i < MAXPORT; i++) {
			if (!pi[i].active && pi[i].retry)
				recvd++;
		}
		/* More to scan? */
		if (!active) {
			if (!recvd)
				sleep(1);
			fprintf(stderr, "All replies received. Done.\n");
			printf("Not responding ports: ");
			for (i = 0; i < MAXPORT; i++) {
				if (pi[i].active && !pi[i].retry)
					printf("(%d %.11s) ", i, port_to_name(i));
			}
			printf("\n");
			exit(0);
		}
		/* Are we sending too fast? */
		if ((!recvd && opt_waitinusec &&
		    usec_delay.it_interval.tv_usec == 0 &&
		    (get_midnight_ut_ms() - start_time) > 500) ||
			(opt_scan_probes-retry) <= 2)
		{
			if (opt_debug)
				printf("SLOWING DONW\n");
			usec_delay.it_interval.tv_usec *= 10;
			usec_delay.it_interval.tv_usec ++;
		}
	}
}
コード例 #29
0
ファイル: handlers.c プロジェクト: gr0206/FINS-Framework
void sendto_call_handler(unsigned long long uniqueSockID, int threads,
		unsigned char *buf, ssize_t len) {

	int index;
	int datalen;
	int flags;
	u_char *data;
	socklen_t addrlen;
	struct sockaddr_in *addr;
	u_char *pt;

	PRINT_DEBUG("");

	pt = buf;

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

	PRINT_DEBUG("passed data len = %d", datalen);
	if (datalen <= 0) {
		PRINT_DEBUG("DATA Field is empty!!");
		nack_send(uniqueSockID, sendto_call);
		return;
	}

	data = (u_char *) malloc(datalen);
	PRINT_DEBUG("");

	memcpy(data, pt, datalen);
	pt += datalen;

	PRINT_DEBUG("");

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

	PRINT_DEBUG("");

	addrlen = *(socklen_t *) pt;
	pt += sizeof(socklen_t);

	PRINT_DEBUG("");

	addr = (struct sockaddr_in *) malloc(addrlen);

	memcpy(addr, pt, addrlen);
	pt += addrlen;

	PRINT_DEBUG("");

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

	index = findjinniSocket(uniqueSockID);
	if (index == -1) {
		PRINT_DEBUG(
				"CRASH !!! socket descriptor not found into jinni sockets SO pipe descriptor to reply is notfound too ");
		nack_send(uniqueSockID, sendto_call);
		return;
	}
	PRINT_DEBUG("");

	/**
	 *
	 * In case a connected socket has been called by mistake using sendto
	 * (IGNORE THE ADDRESSES AND USET THE ADDRESS THE SOCKET IS CONNECTED TO IT)
	 */

	if (jinniSockets[index].connection_status > 0) {

		if (jinniSockets[index].type == SOCK_DGRAM)
			send_udp(uniqueSockID, sendto_call, datalen, data, flags);
		else if (jinniSockets[index].type == SOCK_STREAM)
			send_tcp(uniqueSockID, sendto_call, datalen, data, flags);
		else if (jinniSockets[index].type == SOCK_RAW) {

		} else {
			PRINT_DEBUG("unknown socket type has been read !!!");
			nack_send(uniqueSockID, sendto_call);
		}

	} else {
		/**
		 * The default case , the socket is not connected socket
		 */

		if (jinniSockets[index].type == SOCK_DGRAM)
			sendto_udp(uniqueSockID, sendto_call, datalen, data, flags, addr,
					addrlen);
		else if (jinniSockets[index].type == SOCK_STREAM)
			sendto_tcp(uniqueSockID, sendto_call, datalen, data, flags, addr,
					addrlen);
		else if (jinniSockets[index].type == SOCK_RAW) {

		} else {
			PRINT_DEBUG("unknown socket type has been read !!!");
			nack_send(uniqueSockID, sendto_call);
		}

	}
	PRINT_DEBUG();
	return;

} //end of sendto_call_handler()
コード例 #30
0
ファイル: handlers.c プロジェクト: gr0206/FINS-Framework
void sendmsg_call_handler(unsigned long long uniqueSockID, int threads,
		unsigned char *buf, ssize_t len) {

	int index;
	int datalen;
	int flags;
	int msg_flags;
	int symbol;
	int controlFlag = 0;
	u_char *data;
	socklen_t addrlen;
	void *msg_control;
	int msg_controlLength;
	struct sockaddr_in *addr;
	u_char *pt;

	PRINT_DEBUG("");

	pt = buf;

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

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

	if (symbol) {
		addrlen = *(u_int *) pt;
		pt += sizeof(u_int);

		addr = (struct sockaddr_in *) malloc(addrlen);
		memcpy(addr, pt, addrlen);
		pt += addrlen;
		PRINT_DEBUG("addr=%s/%d", inet_ntoa(addr->sin_addr), addr->sin_port);
	}

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

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

	if (controlFlag) {
		msg_controlLength = *(u_int *) pt;
		pt += sizeof(u_int);

		msg_control = malloc(msg_controlLength);
		memcpy(msg_control, pt, msg_controlLength);
		pt += msg_controlLength;
	}

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

	if (datalen <= 0) {
		PRINT_DEBUG("DATA Field is empty!!");
		nack_send(uniqueSockID, sendmsg_call);
		return;
	}

	data = (u_char *) malloc(datalen);
	PRINT_DEBUG("");

	memcpy(data, pt, datalen);
	pt += datalen;

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

	PRINT_DEBUG("");

	index = findjinniSocket(uniqueSockID);
	PRINT_DEBUG("");

	if (index == -1) {
		PRINT_DEBUG(
				"CRASH !!! socket descriptor not found into jinni sockets SO pipe descriptor to reply is notfound too ");
		nack_send(uniqueSockID, sendmsg_call);
		return;
	}
	PRINT_DEBUG("");

	/**
	 * In case of connected sockets
	 */
	if (jinniSockets[index].connection_status > 0) {

		if (jinniSockets[index].type == SOCK_DGRAM)
			send_udp(uniqueSockID, sendmsg_call, datalen, data, flags);
		else if (jinniSockets[index].type == SOCK_STREAM)
			send_tcp(uniqueSockID, sendmsg_call, datalen, data, flags);
		else if ((jinniSockets[index].type == SOCK_RAW)
				&& (jinniSockets[index].protocol == IPPROTO_ICMP)) {

		} else {
			PRINT_DEBUG("unknown socket type has been read !!!");
			nack_send(uniqueSockID, sendmsg_call);
		}

	} else {

		/**
		 * In case of NON-connected sockets, WE USE THE ADDRESS GIVEN BY the APPlication
		 * Process. Check if an address has been passed or not is required
		 */
		if (symbol) { // check that the passed address is not NULL
			if (jinniSockets[index].type == SOCK_DGRAM)
				sendto_udp(uniqueSockID, sendmsg_call, datalen, data, flags,
						addr, addrlen);
			else if (jinniSockets[index].type == SOCK_STREAM)
				sendto_tcp(uniqueSockID, sendmsg_call, datalen, data, flags,
						addr, addrlen);
			else if ((jinniSockets[index].type == SOCK_RAW)
					&& (jinniSockets[index].protocol == IPPROTO_ICMP)) {

				sendto_icmp(uniqueSockID, sendmsg_call, datalen, data, flags,
						addr, addrlen);

			} else {

				PRINT_DEBUG("unknown target address !!!");
				nack_send(uniqueSockID, sendmsg_call);
			}

		}

		else {
			PRINT_DEBUG("unknown target address !!!");
			nack_send(uniqueSockID, sendmsg_call);
		}

	}

	PRINT_DEBUG();
	return;

}