当前位置: 首页>>代码示例>>C++>>正文


C++ send_packet函数代码示例

本文整理汇总了C++中send_packet函数的典型用法代码示例。如果您正苦于以下问题:C++ send_packet函数的具体用法?C++ send_packet怎么用?C++ send_packet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了send_packet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_packet

// Send string
void ORCP::sendString(const char* str)
{
	if(str)
		send_packet(CP_DUINO_IR, CP_DUINO_IT, CP_DUINO_BS, CP_DUINO_SENDSTRING, (uint8_t*)str, strlen(str));
}
开发者ID:Aadi2110,项目名称:openrobovision,代码行数:6,代码来源:orcp.cpp

示例2: send_file

/*
 * This function will send a file to a remote host. Expects a socket integer
 * and a string containing the full path to the local file name. File cannot
 * exceed MAXFILE definition. Takes a server boolean for some additional
 * checks.
 *
 */
void send_file(int skt, const char *filename, int server)
{
  char errmsg[ERRMSGLEN], msg[MSGLEN];
  int fsize = 0, segments = 0, cur_segment;
  FILE *infile;
  
  memset(errmsg, '\0', ERRMSGLEN);
  memset(msg, '\0', MSGLEN);
  
  /* file must exist */
  if(!exist(filename))
  {
    if(server)
    {
      send_packet(skt, "err:That file does not exist");
    }
    error("The file does not exist!");
    return;
  }
  
  /* file must be in valid size range, do not send endpoint sizes */
  fsize = filesize(filename);
  if(fsize <= 0 || fsize >= MAXFILE)
  {
    if(server)
    {
      send_packet(skt, "err:File is too big");
    }
    error("File is too big");
    return;
  }
  segments = (int) ceil(fsize / MSGLEN);
  
  /* open file or die */
  infile = fopen(filename, "r");
  if(infile == NULL)
  {
    if(server)
    {
      send_packet(skt, "err:File could not be read");
    }
    sprintf(errmsg, "File could not be read: %s", strerror(errno));
    error(errmsg);
    return;
  }
  
  /* send cts to client */
  if(server)
  {
    send_packet(skt, "cts");
    sleep(1);
  }
  
  /* send number of segments and file size to the other size cmd:arg style */
  sprintf(msg, "%d:%d", segments, fsize);
  /* do not expect a response, only data after this */
  send_packet(skt, msg);
  
  /* now read in the file, MSGLEN at a time and send the chunk to the host */
  for(cur_segment = 0; cur_segment <= segments; cur_segment++)
  {
    memset(msg, '\0', MSGLEN);
    fread(msg, MSGLEN, 1, infile);
    printf("\rFilesystem: Sending file %d / %d", cur_segment, segments);
    send_packet(skt, msg);
  }
  printf("\n");
  fclose(infile);
}
开发者ID:penguincoder,项目名称:cftp,代码行数:76,代码来源:filesystem.c

示例3: do_server

void do_server ()
{
   struct ae_recv *packet;
   int ret;
   int pktrecv = 0;
   int acksent = 0;
   int gotstop = 0;
   int printmismatch;
   int adjust;

	/* se  up pktring and get DPF filter for proper UDP packets */
   xio_net_wrap_init (&nwinfo, malloc(32 * 4096), (32 * 4096));
printf ("getting dpf: dstportno %x (%d), srcportno %x (%d)\n", dstportno, dstportno, -1, -1);
   ret = xio_net_wrap_getdpf_udp (&nwinfo, dstportno, -1);
   assert (ret != -1);

	/* wait for start packet */
   while ((packet = xio_net_wrap_getPacket(&nwinfo)) == NULL) ;

printf ("got packet: dstportno %02x %02x, srcportno %02x %02x\n", packet->r[0].data[36], packet->r[0].data[37], packet->r[0].data[34], packet->r[0].data[35]);

	/* set up proper variables, send ack packet and start timer */
   process_start_packet ((struct start_pkt *) packet->r[0].data);
   setnetcardno (packet->r[0].data);
   xio_net_wrap_returnPacket (&nwinfo, packet);
   init_packets ();
   setup_startack_packet (outpkt);
printf ("sending packet: netcardno %d, dstportno %02x %02x, srcportno %02x %02x\n", netcardno, outpkt->r[0].data[36], outpkt->r[0].data[37], outpkt->r[0].data[34], outpkt->r[0].data[35]);
   send_packet (netcardno, outpkt);

	/* get Packets, check their size, ack when appropriate */
   printmismatch = 1;
   adjust = 0;
   while (pktrecv < pktcnt) {
      while ((packet = xio_net_wrap_getPacket(&nwinfo)) == NULL) ;
      if (is_stop_pkt (packet)) {
         gotstop = 1;
         break;
      }
#ifndef DIRECT_XMIT
      if ((printmismatch) && (((struct pkt *)packet->r[0].data)->id != (pktrecv+adjust))) {
         //printf ("out of order packet: id %d, expected %d (adjust %d)\n", ((struct pkt *)packet->r[0].data)->id, pktrecv, adjust);
         //printmismatch = 0;
         adjust = ((struct pkt *)packet->r[0].data)->id - pktrecv;
      }
#endif
      assert (packet->r[0].sz == max(64,(sizeof(struct pkt) + pktdata - 4)));
      xio_net_wrap_returnPacket (&nwinfo, packet);
      pktrecv++;
      if ((ackfreq) && ((pktrecv % ackfreq) == 0)) {
         setup_dataack_packet (outpkt);
         send_packet (netcardno, outpkt);
         acksent++;
      }
   }

   /* when stop packet received, get time */

   /* print results */
   printf ("packets received %d (acks %d)   (gotstop %d)\n", pktrecv, acksent, gotstop);
}
开发者ID:aunali1,项目名称:exopc,代码行数:61,代码来源:ether.c

示例4: main

int main(int argc, char *argv[]) {
    /* Disable driver enable for RS485 ASAP */
    //DDRC |= (1 << PC2);
    //PORTC &= ~(1 << PC2);


    /* init serial line debugging */
    UBRR0H = UBRRH_VALUE;
    UBRR0L = UBRRL_VALUE;
    UCSR0B = (1 << RXCIE1) | (1 << RXEN1) | (1 << TXEN0);

    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);

    /* Initialize UART */
    net_init();
    DBG("READY!\r\n");

    DBG("Initializing SPI...\r\n");

    spi_init();

    DBG("Initializing ENC28J60...\r\n");

    init_enc28j60();

    DBG("Initialized ENC28J60\r\n");
    char obuf[64];
    snprintf(obuf, sizeof(obuf), "enc28j60 rev 0x%x\n", read_control_register(REG_EREVID));
    DBG(obuf);

    char buf[16] = "serial:       X\n";
    int cnt = 0;
    while (1) {
        if (eth_to_rs_cnt > 0 &&
            eth_to_rs[eth_to_rs_cnt-1] == '$') {
            eth_to_rs[eth_to_rs_cnt-1] = '\0';

            int dest = 0;
            int pktlen = 0;
            char minibuf[16];
            minibuf[0] = eth_to_rs[1];
            minibuf[1] = eth_to_rs[2];
            minibuf[2] = '\0';
            if (sscanf(minibuf, "%d", &dest) != 1) {
                DBG("Could not parse dest\r\n");
                eth_to_rs_cnt = 0;
                continue;
            }
            minibuf[0] = eth_to_rs[3];
            minibuf[1] = eth_to_rs[4];
            if (sscanf(minibuf, "%d", &pktlen) != 1) {
                DBG("Could not parse len\r\n");
                eth_to_rs_cnt = 0;
                continue;
            }

            if (pktlen != (eth_to_rs_cnt - 6)) {
                DBG("lens are not the same\r\n");
                minibuf[2] = '\r';
                minibuf[3] = '\n';
                minibuf[4] = '\0';
                DBG(minibuf);
                snprintf(minibuf, sizeof(minibuf), "e: %d\r\n", eth_to_rs_cnt-6);
                DBG(minibuf);
                snprintf(minibuf, sizeof(minibuf), "p: %d\r\n", pktlen);
                DBG(minibuf);
                eth_to_rs_cnt = 0;
                continue;
            }

                fmt_packet(lbuffer, dest, 0xFF, eth_to_rs + 5, pktlen);
                struct buspkt *packet = (struct buspkt*)lbuffer;

                send_packet(packet);
                syslog_send("sent packet", strlen("sent packet"));
                _delay_ms(25);
                sendit = 0;
                eth_to_rs_cnt = 0;
        }
#if 0
        network_process();
        if (uip_recvlen > 0) {
            syslog_send("handling ethernet packet", strlen("handling ethernet packet"));
            DBG("Handling packet\r\n");
            handle_icmpv6();

            if (uip_recvbuf[20] == 0x11) {
                syslog_send("handling udp packet", strlen("handling udp packet"));
                /* UDP */
                uint8_t *udp = uip_recvbuf + 14 + 40;
                uint8_t len = udp[5] - 8;
                /* TODO: sanity check */
                uint8_t *recvpayload = udp + 8 /* udp */;

                fmt_packet(lbuffer, uip_recvbuf[53], 0xFF, recvpayload, len);
                struct buspkt *packet = (struct buspkt*)lbuffer;

                //syslog_send("sending packet", strlen("sending packet"));
                send_packet(packet);
                _delay_ms(25);
//.........这里部分代码省略.........
开发者ID:raumzeitlabor,项目名称:hausbus,代码行数:101,代码来源:main.c

示例5: main


//.........这里部分代码省略.........
                    usage();
                    exit(1);
                }
                usage();
                exit(1);
        }

    setbuf(onf, NULL);

    //Set UDP Socket
    set_dest(raddr, rport);
    set_sock();

    if ((fd = open(DEV_FSEVENTS, O_RDONLY)) < 0) {
        perror("open");
        exit(1);
    }

    fca.event_list = (int8_t *)event_list;
    fca.num_events = sizeof(event_list)/sizeof(int8_t);
    fca.event_queue_depth = EVENT_QUEUE_SIZE;
    fca.fd = &clonefd; 
    if ((ret = ioctl(fd, FSEVENTS_CLONE, (char *)&fca)) < 0) {
        perror("ioctl");
        close(fd);
        exit(1);
    }

    close(fd);

    //YAML comments lines start with '#'. Use this for debug and status statements
    snprintf(msg, MAX_DATA,"#fsevents device cloned (fd %d)\n#fslogger ready\n",clonefd);
    if (udp){
        send_packet(msg, strlen(msg));
    } else {
        fprintf(onf,"%s",msg);
        // Since we use setbuf this might not be necessary. Let's do it anyway.
        fflush(onf);
    }

    if ((ret = ioctl(clonefd, FSEVENTS_WANT_EXTENDED_INFO, NULL)) < 0) {
        perror("ioctl");
        close(clonefd);
        exit(1);
    }

    while (1) { // event processing loop

        if ((ret = read(clonefd, buffer, FSEVENT_BUFSIZ)) > 0){
            snprintf(msg, MAX_DATA, "# => received %d bytes\n", ret);
            if (udp){
                send_packet(msg, strlen(msg));
            } else {
                fprintf(onf,"%s", msg);
                fflush(onf);
            }
        }

        off = 0;

        while (off < ret) { // process one or more events received
        
            // Start message over
            mlen = 0;

            struct kfs_event *kfse = (struct kfs_event *)((char *)buffer + off);
开发者ID:cutaway,项目名称:fslogger-yaml,代码行数:67,代码来源:fslogger-yaml.c

示例6: startMyftpClient

int startMyftpClient(struct sockaddr_in *servaddr, const char *filename)
{
    int socketfd;
    if((socketfd= socket(AF_INET,SOCK_DGRAM,0))<0){
        perror("Socket Error!");
        exit(1);
	}

    /*set time out*/
    struct timeval timeout = {3,0};
    if(setsockopt(socketfd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(struct timeval)) != 0){
        perror("setsockopt for time out");
        exit(1);
    }

    struct myFtphdr *packet_FRQ;
    int f_len = strlen(filename)+1;
    int FRQ_size = f_len+4;
    packet_FRQ =(struct myFtphdr *)malloc(FRQ_size);
    bzero(packet_FRQ,FRQ_size);
    packet_FRQ->mf_opcode = htons(FRQ);
    packet_FRQ->mf_cksum=htons(0);
    strcpy(packet_FRQ->mf_filename,filename);
    packet_FRQ->mf_cksum=in_cksum((unsigned short *)packet_FRQ,FRQ_size);
    if(sendto(socketfd,packet_FRQ,FRQ_size,0,(struct sockaddr *)servaddr,sizeof(struct sockaddr_in)) == -1){
        exit(1);
    }

    FILE *fin;
    char recv_file[FNAMELEN];
    sprintf(recv_file,"client_%s",filename);
    fin=fopen(recv_file,"wb");
    //Function: Get file
    printf("file transmission start!!\n");
    printf("get file : <%s> from IP:%s\n",filename,inet_ntoa(servaddr->sin_addr));
    //data packet
    struct myFtphdr *data_packet;
    int data_packet_size = MFMAXDATA+6;
    data_packet = (struct myFtphdr *)malloc(data_packet_size);

    //ACK and ERROR packet
    struct myFtphdr *ACK_ERROR_packet;
    int ACK_ERROR_size = 6;
    ACK_ERROR_packet = (struct myFtphdr *)malloc(ACK_ERROR_size);

    int sockaddr_len = sizeof(struct sockaddr_in);
    int block = 0;
    int recv;
    while(1){
        //MSG_WAITALL
        bzero(data_packet,data_packet_size);
        if((recv = recvfrom(socketfd,data_packet,data_packet_size,0,(struct sockaddr*)servaddr,&sockaddr_len))<0){
            //check the FRQ is arrived or not
            if(block == 0){
                //if block  == 1,this means we have not received the data block 1
                //so,the server may not receive FRQ or the block 1 has lost
                //FRQ can be regard as request for block 1
                printf("time out!! send FRQ packet again\n");
                if(sendto(socketfd,packet_FRQ,FRQ_size,0,(struct sockaddr *)servaddr,sizeof(struct sockaddr_in)) == -1){
                    exit(1);
                }
                continue;
            }
            //client has received block 1
            printf("time out waiting data,request server to resend\n");
            send_packet(socketfd,ACK_ERROR_packet,servaddr,block,ERROR,ACK_ERROR_size);
        }
        else if(in_cksum((unsigned short *)data_packet,data_packet_size)!=0){
            //receive data has error bit
            printf("received data checksum error\n");
            send_packet(socketfd,ACK_ERROR_packet,servaddr,block,ERROR,ACK_ERROR_size);
        }
        else if(ntohs(data_packet->mf_opcode) == DATA && ntohs(data_packet->mf_block) == block+1){
            printf("receive data for block = %d\n",ntohs(data_packet->mf_block));
            
            int write_bytes = recv-6;
            fwrite(data_packet->mf_data,1,write_bytes,fin);
            /*printf("write_bytes = %d\n",write_bytes);*/
            if(write_bytes<MFMAXDATA){
                printf("file transmission finish!!\n");
                block = 0;
                send_packet(socketfd,ACK_ERROR_packet,servaddr,block,ACK,ACK_ERROR_size);
                fclose(fin);
                break;
            }
            else{
            //send ACK
            block = ntohs(data_packet->mf_block);
            send_packet(socketfd,ACK_ERROR_packet,servaddr,block,ACK,ACK_ERROR_size);
            printf("send ack = %d\n",block);
            if(block == 65534){
                block = 1;
            }
            }
        }else if(ntohs(data_packet->mf_opcode) == DATA && ntohs(data_packet->mf_block) != block+1){
            //server dose not receive previous ack packet,send again
            int previous = ntohs(data_packet->mf_block);
            send_packet(socketfd,ACK_ERROR_packet,servaddr,previous,ACK,ACK_ERROR_size);
            
        }
//.........这里部分代码省略.........
开发者ID:twmht,项目名称:simpleFTP,代码行数:101,代码来源:client.c

示例7: incoming_content

/**
 * Handle the incoming content messages. Extracts the data, and
 * requests the next block in sequence if the received block was
 * not the final one.
 */
enum ccn_upcall_res
incoming_content(struct ccn_closure *selfp,
                 enum ccn_upcall_kind kind,
                 struct ccn_upcall_info *info)
{
    struct ccn_charbuf *name = NULL;
    struct ccn_charbuf *templ = NULL;
    const unsigned char *ccnb = NULL;
    size_t ccnb_size = 0;
    const unsigned char *data = NULL;
    size_t data_size = 0;
    size_t written;
    const unsigned char *ib = NULL; /* info->interest_ccnb */
    struct ccn_indexbuf *ic = NULL;
    int res;
    struct mydata *md = selfp->data;

    if (kind == CCN_UPCALL_FINAL)
    {
        if (md != NULL)
        {
            selfp->data = NULL;
            free(md);
            md = NULL;
        }
        return(CCN_UPCALL_RESULT_OK);
    }
    if (kind == CCN_UPCALL_INTEREST_TIMED_OUT)
	{
		 printf("le timeout!\n");
		 return(CCN_UPCALL_RESULT_REEXPRESS);
	}
	

    if (kind == CCN_UPCALL_CONTENT_UNVERIFIED)
        return(CCN_UPCALL_RESULT_VERIFY);
    if (kind != CCN_UPCALL_CONTENT)
        return(CCN_UPCALL_RESULT_ERR);
    if (md == NULL)
        selfp->data = md = calloc(1, sizeof(*md));
    ccnb = info->content_ccnb;
    ccnb_size = info->pco->offset[CCN_PCO_E];
    ib = info->interest_ccnb;
    ic = info->interest_comps;
    res = ccn_content_get_value(ccnb, ccnb_size, info->pco, &data, &data_size);
    if (res < 0) abort();
    if (info->pco->type != CCN_CONTENT_DATA)
    {
        /* For us this is spam. For now, give up. */
        fprintf(stderr, "*** spammed at block %d\n", (int)selfp->intdata);
        exit(1);
    }

    /* OK, we will accept this block. */
    if (data_size == 0)
        *(md->done) = 1;
    else
    {
        written = fwrite(data, data_size, 1, stderr);
		

		if(data_size > 500)
		{
			printf("Pack: %lu\n size:%d\n", atoi(data), data_size);
			send_packet(data, data_size);
		}

        if (written != 1)
            exit(1);
    }
    // XXX The test below should get refactored into the library
    if (info->pco->offset[CCN_PCO_B_FinalBlockID] !=
            info->pco->offset[CCN_PCO_E_FinalBlockID])
    {
        const unsigned char *finalid = NULL;
        size_t finalid_size = 0;
        const unsigned char *nameid = NULL;
        size_t nameid_size = 0;
        struct ccn_indexbuf *cc = info->content_comps;
        ccn_ref_tagged_BLOB(CCN_DTAG_FinalBlockID, ccnb,
                            info->pco->offset[CCN_PCO_B_FinalBlockID],
                            info->pco->offset[CCN_PCO_E_FinalBlockID],
                            &finalid,
                            &finalid_size);
        if (cc->n < 2) abort();
        ccn_ref_tagged_BLOB(CCN_DTAG_Component, ccnb,
                            cc->buf[cc->n - 2],
                            cc->buf[cc->n - 1],
                            &nameid,
                            &nameid_size);
        if (finalid_size == nameid_size &&
                0 == memcmp(finalid, nameid, nameid_size))
            *(md->done) = 1;
    }

//.........这里部分代码省略.........
开发者ID:netharis,项目名称:ccnxaueb,代码行数:101,代码来源:ccn_receiver.c

示例8: handle_packet

void handle_packet(apacket *p, atransport *t)
{
    D("handle_packet() %c%c%c%c", ((char*) (&(p->msg.command)))[0],
            ((char*) (&(p->msg.command)))[1],
            ((char*) (&(p->msg.command)))[2],
            ((char*) (&(p->msg.command)))[3]);
    print_packet("recv", p);

    switch(p->msg.command){
    case A_SYNC:
        if (p->msg.arg0){
            send_packet(p, t);
#if ADB_HOST
            send_connect(t);
#endif
        } else {
            t->connection_state = kCsOffline;
            handle_offline(t);
            send_packet(p, t);
        }
        return;

    case A_CNXN:  // CONNECT(version, maxdata, "system-id-string")
        handle_new_connection(t, p);
        break;

    case A_AUTH:
        if (p->msg.arg0 == ADB_AUTH_TOKEN) {
            t->connection_state = kCsUnauthorized;
            send_auth_response(p->data, p->msg.data_length, t);
        } else if (p->msg.arg0 == ADB_AUTH_SIGNATURE) {
            if (adb_auth_verify(t->token, sizeof(t->token), p->data, p->msg.data_length)) {
                adb_auth_verified(t);
                t->failed_auth_attempts = 0;
            } else {
                if (t->failed_auth_attempts++ > 256) adb_sleep_ms(1000);
                send_auth_request(t);
            }
        } else if (p->msg.arg0 == ADB_AUTH_RSAPUBLICKEY) {
            adb_auth_confirm_key(p->data, p->msg.data_length, t);
        }
        break;

    case A_OPEN: /* OPEN(local-id, 0, "destination") */
        if (t->online && p->msg.arg0 != 0 && p->msg.arg1 == 0) {
            char *name = (char*) p->data;
            name[p->msg.data_length > 0 ? p->msg.data_length - 1 : 0] = 0;
            asocket* s = create_local_service_socket(name, t);
            if (s == nullptr) {
                send_close(0, p->msg.arg0, t);
            } else {
                s->peer = create_remote_socket(p->msg.arg0, t);
                s->peer->peer = s;
                send_ready(s->id, s->peer->id, t);
                s->ready(s);
            }
        }
        break;

    case A_OKAY: /* READY(local-id, remote-id, "") */
        if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) {
            asocket* s = find_local_socket(p->msg.arg1, 0);
            if (s) {
                if(s->peer == 0) {
                    /* On first READY message, create the connection. */
                    s->peer = create_remote_socket(p->msg.arg0, t);
                    s->peer->peer = s;
                    s->ready(s);
                } else if (s->peer->id == p->msg.arg0) {
                    /* Other READY messages must use the same local-id */
                    s->ready(s);
                } else {
                    D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s",
                      p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial);
                }
            } else {
                // When receiving A_OKAY from device for A_OPEN request, the host server may
                // have closed the local socket because of client disconnection. Then we need
                // to send A_CLSE back to device to close the service on device.
                send_close(p->msg.arg1, p->msg.arg0, t);
            }
        }
        break;

    case A_CLSE: /* CLOSE(local-id, remote-id, "") or CLOSE(0, remote-id, "") */
        if (t->online && p->msg.arg1 != 0) {
            asocket* s = find_local_socket(p->msg.arg1, p->msg.arg0);
            if (s) {
                /* According to protocol.txt, p->msg.arg0 might be 0 to indicate
                 * a failed OPEN only. However, due to a bug in previous ADB
                 * versions, CLOSE(0, remote-id, "") was also used for normal
                 * CLOSE() operations.
                 *
                 * This is bad because it means a compromised adbd could
                 * send packets to close connections between the host and
                 * other devices. To avoid this, only allow this if the local
                 * socket has a peer on the same transport.
                 */
                if (p->msg.arg0 == 0 && s->peer && s->peer->transport != t) {
                    D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s",
//.........这里部分代码省略.........
开发者ID:mnemonyc,项目名称:platform_system_core,代码行数:101,代码来源:adb.cpp

示例9: elp_start_xmit

static int elp_start_xmit(struct sk_buff *skb, struct device *dev)

{
    elp_device * adapter = (elp_device *) dev->priv;

    CHECK_NULL(dev);

    /*
     * not sure what this does, but the 3c509 driver does it, so...
     */
    if (skb == NULL) {
        dev_tint(dev);
        return 0;
    }

    /*
     * Fill in the ethernet header
     * (for kernels prior to 1.1.4 only)
     */
#if (ELP_KERNEL_TYPE < 2)
    IS_SKB(skb);
    if (!skb->arp && dev->rebuild_header(SKB_DATA, dev)) {
        skb->dev = dev;
        IS_SKB(skb);
        arp_queue (skb);
        return 0;
    }
#endif

    /*
     * if we ended up with a munged length, don't send it
     */
    if (skb->len <= 0)
        return 0;

    if (elp_debug >= 3)
        printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);

    /*
     * if the transmitter is still busy, we have a transmit timeout...
     */
    if (dev->tbusy) {
        int tickssofar = jiffies - dev->trans_start;
        if (tickssofar < 200) /* was 500, AJT */
            return 1;
        printk("%s: transmit timed out, resetting adapter\n", dev->name);
        if ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0)
            printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
        adapter_reset(adapter);
        dev->trans_start = jiffies;
        dev->tbusy = 0;
    }

    /*
     * send the packet at skb->data for skb->len
     */
    if (!send_packet(adapter, (unsigned char *)SKB_DATA, skb->len)) {
        printk("%s: send packet PCB failed\n", dev->name);
        return 1;
    }

    if (elp_debug >= 3)
        printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);


    /*
     * start the transmit timeout
     */
    dev->trans_start = jiffies;

    /*
     * the transmitter is now busy
     */
    dev->tbusy = 1;

    /*
     * if we have been asked to free the buffer, do so
     */
#if (ELP_KERNEL_TYPE < 4)
    if (skb->free)
    {
        IS_SKB(skb);
        kfree_skb(skb, FREE_WRITE);
    }
#else
    dev_kfree_skb(skb, FREE_WRITE);
#endif

    return 0;
}
开发者ID:Lakshmipathi,项目名称:Linux-historic,代码行数:90,代码来源:3c505.c

示例10: accept

static int accept(struct socket *sock, struct socket *new_sock, int flags)
{
	struct sock *sk = sock->sk;
	struct sk_buff *buf;
	int res;

	lock_sock(sk);

	if (sock->state != SS_LISTENING) {
		res = -EINVAL;
		goto exit;
	}

	while (skb_queue_empty(&sk->sk_receive_queue)) {
		if (flags & O_NONBLOCK) {
			res = -EWOULDBLOCK;
			goto exit;
		}
		release_sock(sk);
		res = wait_event_interruptible(*sk_sleep(sk),
				(!skb_queue_empty(&sk->sk_receive_queue)));
		lock_sock(sk);
		if (res)
			goto exit;
	}

	buf = skb_peek(&sk->sk_receive_queue);

	res = tipc_create(sock_net(sock->sk), new_sock, 0, 0);
	if (!res) {
		struct sock *new_sk = new_sock->sk;
		struct tipc_sock *new_tsock = tipc_sk(new_sk);
		struct tipc_port *new_tport = new_tsock->p;
		u32 new_ref = new_tport->ref;
		struct tipc_msg *msg = buf_msg(buf);

		lock_sock(new_sk);

		/*
		 * Reject any stray messages received by new socket
		 * before the socket lock was taken (very, very unlikely)
		 */

		reject_rx_queue(new_sk);

		/* Connect new socket to it's peer */

		new_tsock->peer_name.ref = msg_origport(msg);
		new_tsock->peer_name.node = msg_orignode(msg);
		tipc_connect2port(new_ref, &new_tsock->peer_name);
		new_sock->state = SS_CONNECTED;

		tipc_set_portimportance(new_ref, msg_importance(msg));
		if (msg_named(msg)) {
			new_tport->conn_type = msg_nametype(msg);
			new_tport->conn_instance = msg_nameinst(msg);
		}

		/*
		 * Respond to 'SYN-' by discarding it & returning 'ACK'-.
		 * Respond to 'SYN+' by queuing it on new socket.
		 */

		if (!msg_data_sz(msg)) {
			struct msghdr m = {NULL,};

			advance_rx_queue(sk);
			send_packet(NULL, new_sock, &m, 0);
		} else {
			__skb_dequeue(&sk->sk_receive_queue);
			__skb_queue_head(&new_sk->sk_receive_queue, buf);
		}
		release_sock(new_sk);
	}
exit:
	release_sock(sk);
	return res;
}
开发者ID:jblorenzo,项目名称:mptcp-nexus-a444,代码行数:78,代码来源:socket.c

示例11: send_stream

static int send_stream(struct kiocb *iocb, struct socket *sock,
		       struct msghdr *m, size_t total_len)
{
	struct sock *sk = sock->sk;
	struct tipc_port *tport = tipc_sk_port(sk);
	struct msghdr my_msg;
	struct iovec my_iov;
	struct iovec *curr_iov;
	int curr_iovlen;
	char __user *curr_start;
	u32 hdr_size;
	int curr_left;
	int bytes_to_send;
	int bytes_sent;
	int res;

	lock_sock(sk);

	/* Handle special cases where there is no connection */

	if (unlikely(sock->state != SS_CONNECTED)) {
		if (sock->state == SS_UNCONNECTED) {
			res = send_packet(NULL, sock, m, total_len);
			goto exit;
		} else if (sock->state == SS_DISCONNECTING) {
			res = -EPIPE;
			goto exit;
		} else {
			res = -ENOTCONN;
			goto exit;
		}
	}

	if (unlikely(m->msg_name)) {
		res = -EISCONN;
		goto exit;
	}

	if ((total_len > (unsigned)INT_MAX) ||
	    (m->msg_iovlen > (unsigned)INT_MAX)) {
		res = -EMSGSIZE;
		goto exit;
	}

	/*
	 * Send each iovec entry using one or more messages
	 *
	 * Note: This algorithm is good for the most likely case
	 * (i.e. one large iovec entry), but could be improved to pass sets
	 * of small iovec entries into send_packet().
	 */

	curr_iov = m->msg_iov;
	curr_iovlen = m->msg_iovlen;
	my_msg.msg_iov = &my_iov;
	my_msg.msg_iovlen = 1;
	my_msg.msg_flags = m->msg_flags;
	my_msg.msg_name = NULL;
	bytes_sent = 0;

	hdr_size = msg_hdr_sz(&tport->phdr);

	while (curr_iovlen--) {
		curr_start = curr_iov->iov_base;
		curr_left = curr_iov->iov_len;

		while (curr_left) {
			bytes_to_send = tport->max_pkt - hdr_size;
			if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE)
				bytes_to_send = TIPC_MAX_USER_MSG_SIZE;
			if (curr_left < bytes_to_send)
				bytes_to_send = curr_left;
			my_iov.iov_base = curr_start;
			my_iov.iov_len = bytes_to_send;
			res = send_packet(NULL, sock, &my_msg, bytes_to_send);
			if (res < 0) {
				if (bytes_sent)
					res = bytes_sent;
				goto exit;
			}
			curr_left -= bytes_to_send;
			curr_start += bytes_to_send;
			bytes_sent += bytes_to_send;
		}

		curr_iov++;
	}
	res = bytes_sent;
exit:
	release_sock(sk);
	return res;
}
开发者ID:jblorenzo,项目名称:mptcp-nexus-a444,代码行数:92,代码来源:socket.c

示例12: main

int main()
{
    struct termios boardSettings;
    struct termios oldBoardSettings;

    int board;
    int sent;

    printf("INPUT TERMINAL\n\n");

    printf("Trying to connect to the board...");

    board = open_board(&oldBoardSettings, &boardSettings);

    if( board < 0 )
    {
        printf("Error: connection to board failed.");
        return 1;
    }

    char ctty = 0;
    char cboard = 0;

    printf("Connection successful!\n\n");

    while(1)
    {
        printf("user> ");

        packet_t p;
        p.header = 0x0;
        p.command = 0x0;

        ctty = getchar_tty();

        switch(ctty)
        {
            case '1':
                printf("pc> turn on led1.\n");
                p.header = SET_LED;
                p.command = LED1;
                break;
            case '2':
                p.header = SET_LED;
                p.command = LED2;
                break;
            case '3':
                p.header = SET_LED;
                p.command = LED3;
                break;
            case '4':
                p.header = SET_LED;
                p.command = LED4;
                break;
            case 'q':
                break;
            default:
                ctty = 0;
                printf("pc> Command not recognized.\n");
        };

        if(ctty == 'q')
            break;

        if(ctty)
            send_packet(board, p);

        sleep(1); //give time to board to write output

        while( (cboard = getchar_board(board)) )
            printf("%c", cboard);
    }

    printf("\nEnd of communication.\n");

    close_board(board, &oldBoardSettings);

    return 0;
}
开发者ID:stevengos,项目名称:IN4073,代码行数:79,代码来源:tx.c

示例13: sendACK

int sendACK(struct dhcpMessage *oldpacket, u_int32_t yiaddr)
{
        struct dhcpMessage packet;
        struct option_set *curr;
        struct dhcpOfferedAddr *offerlist;
        char *lease_time, *vendorid, *userclsid;
        char length = 0;
        u_int32_t lease_time_align = cur_iface->lease;
        struct in_addr addr;
        //brcm begin
        char VIinfo[VENDOR_IDENTIFYING_INFO_LEN];
        char *req;
        int saveVIoptionNeeded = 0;
        //brcm end

        init_packet(&packet, oldpacket, DHCPACK);
        packet.yiaddr = yiaddr;
        
        if ((lease_time = (char *)get_option(oldpacket, DHCP_LEASE_TIME))) {
                memcpy(&lease_time_align, lease_time, 4);
                lease_time_align = ntohl(lease_time_align);
                if (lease_time_align > cur_iface->lease) 
                        lease_time_align = cur_iface->lease;
                else if (lease_time_align < server_config.min_lease) 
                        lease_time_align = cur_iface->lease;
        }

//<< jojopo : wifi leasetime 300 seconds , 2015/12/25
        if(isHostFromWireless(packet.chaddr))
            lease_time_align = 300;
//>> jojopo : end
        
        add_simple_option(packet.options, DHCP_LEASE_TIME, lease_time_align);
        
        curr = cur_iface->options;
        while (curr) {
                if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
                        add_option_string(packet.options, curr->data);
                curr = curr->next;
        }

        add_bootp_options(&packet);

        //brcm begin
        /* if DHCPRequest from client has device identity, send back gateway identity,
           and save the device identify */
        if ((req = (char *)get_option(oldpacket, DHCP_VENDOR_IDENTIFYING))) {
          if (createVIoption(VENDOR_IDENTIFYING_FOR_GATEWAY, VIinfo) != -1)
          {
            add_option_string(packet.options, (unsigned char *)VIinfo);
          }
          saveVIoptionNeeded = 1;
        }
        //brcm end

        addr.s_addr = packet.yiaddr;
        LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr));

        if (send_packet(&packet, 0) < 0) 
                return -1;

        add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
        offerlist = find_lease_by_chaddr(packet.chaddr);
        if (saveVIoptionNeeded)
        {
           saveVIoption(req,offerlist);
        }
        vendorid = (char *)get_option(oldpacket, DHCP_VENDOR);
        userclsid = (char *)get_option(oldpacket, DHCP_USER_CLASS_ID);
        memset(offerlist->classid, 0, sizeof(offerlist->classid));
        memset(offerlist->vendorid, 0, sizeof(offerlist->vendorid));
        if( vendorid != NULL){
 	     length = *(vendorid - 1);
	     memcpy(offerlist->vendorid, vendorid, (size_t)length);
	     offerlist->vendorid[(int)length] = '\0';
        }

        if( userclsid != NULL){
 	     length = *(userclsid - 1);
	     memcpy(offerlist->classid, userclsid, (size_t)length);
	     offerlist->classid[(int)length] = '\0';
        }

        return 0;
}
开发者ID:antonywcl,项目名称:AR-5315u_PLD,代码行数:85,代码来源:serverpacket.c

示例14: sendOffer


//.........这里部分代码省略.........
	uint32_t static_lease_ip;

        //brcm begin
        char VIinfo[VENDOR_IDENTIFYING_INFO_LEN];
        //brcm end

        init_packet(&packet, oldpacket, DHCPOFFER);
        
	//For static IP lease
	static_lease_ip = getIpByMac(cur_iface->static_leases,
		oldpacket->chaddr);

	if(!static_lease_ip) {
        	/* the client is in our lease/offered table */
        	if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
                	if (!lease_expired(lease)) 
                        	lease_time_align = lease->expires - time(0);
                	packet.yiaddr = lease->yiaddr;
        	/* Or the client has a requested ip */
        	} else if ((req = (char *)get_option(oldpacket, DHCP_REQUESTED_IP)) &&

			/* Don't look here (ugly hackish thing to do) */
			memcpy(&req_align, req, 4) && 

			/* and the ip is in the lease range */
			ntohl(req_align) >= ntohl(cur_iface->start) &&
			ntohl(req_align) <= ntohl(cur_iface->end) && 

			/* and its not already taken/offered */
			((!(lease = find_lease_by_yiaddr(req_align)) ||

			/* or its taken, but expired */
			lease_expired(lease)))) {
				packet.yiaddr = req_align; 

		/* otherwise, find a free IP */
        	} else {
                	packet.yiaddr = find_address(0);
                
                	/* try for an expired lease */
			if (!packet.yiaddr) packet.yiaddr = find_address(1);
        	}
        
        	if(!packet.yiaddr) {
                	LOG(LOG_WARNING, "no IP addresses to give -- "
				"OFFER abandoned");
                	return -1;
        	}
        
        	if (!add_lease(packet.chaddr, packet.yiaddr,
			server_config.offer_time)) {
                	LOG(LOG_WARNING, "lease pool is full -- "
				"OFFER abandoned");
                	return -1;
        	}               

        	if ((lease_time = (char *)get_option(oldpacket, DHCP_LEASE_TIME))) {
                	memcpy(&lease_time_align, lease_time, 4);
                	lease_time_align = ntohl(lease_time_align);
                	if (lease_time_align > cur_iface->lease) 
                        	lease_time_align = cur_iface->lease;
        	}

        	/* Make sure we aren't just using the lease time from the
		 * previous offer */
        	if (lease_time_align < server_config.min_lease) 
                	lease_time_align = cur_iface->lease;

//<< jojopo : wifi leasetime 300 seconds , 2015/12/25
         if(isHostFromWireless(packet.chaddr))
            lease_time_align = 300;
//>> jojopo : end
	} else {
		/* It is a static lease... use it */
		packet.yiaddr = static_lease_ip;
	}
                
        add_simple_option(packet.options, DHCP_LEASE_TIME, lease_time_align);

        curr = cur_iface->options;
        while (curr) {
                if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
                        add_option_string(packet.options, curr->data);
                curr = curr->next;
        }

        add_bootp_options(&packet);

        //brcm begin
        /* if DHCPDISCOVER from client has device identity, send back gateway identity */
        if ((req = (char *)get_option(oldpacket, DHCP_VENDOR_IDENTIFYING))) {
          if (createVIoption(VENDOR_IDENTIFYING_FOR_GATEWAY, VIinfo) != -1)
            add_option_string(packet.options, (unsigned char *)VIinfo);
        }
        //brcm end

        addr.s_addr = packet.yiaddr;
        LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
        return send_packet(&packet, 0);
}
开发者ID:antonywcl,项目名称:AR-5315u_PLD,代码行数:101,代码来源:serverpacket.c

示例15: instance

/* 	Loop for downloading file, parameters:
		int sock	- socket to be used
		int type	- type of the instance (server or client)

	Returns pointer to first filedata block, stops the loops when receiving error
*/
int download_mode_loop(clientnode *cl)
{
	int n = 0, packet_len = 0, rv = 0;
	int returnval = 1;
	struct timeval to;
	packet *pck = NULL;
	data_packet *d_pck = NULL;
	error_packet *e_pck = NULL;
	fd_set s_set;

	FD_ZERO(&s_set);

	while((cl->state == RUN) || (cl->state == WAIT))
	{
		/* Set timeout values */
		to.tv_sec = TIMEOUT_SEC;
		to.tv_usec = cl->timeout;

		FD_SET(cl->socket,&s_set);

		/* Check if there is something in socket */
		rv = select(cl->socket+1,&s_set,NULL,NULL,&to);

		if(rv < 0)
		{
			pck = encode_error_packet(ERROR_NOT_DEFINED);
			send_packet(cl->socket,pck);
			perror("Error in select()");
			cl->state = STOP;
			returnval = -1;
		}

		/* If got something */
		else if(rv > 0)
		{
			if(FD_ISSET(cl->socket,&s_set)) /* Used socket has something */
			{
				/* Read packet and backup length */
				pck = read_packet(cl->socket);
				packet_len = pck->length;
				
				/* Reset timeout */
				cl->timeout = TIMEOUT_USEC;
				
				/* If packet is less than 4 bytes or greater than 516 bytes (MAX_MSG) discard it */
				if((packet_len < 4) || (packet_len > MAX_MSG))
				{
					pck = encode_error_packet(ERROR_ILLEGAL_OPERATION);
					error_minor("Invalid packet size, discarding");
					send_packet(cl->socket,pck);
				}

				/* Otherwise check the packet */
				else
				{
					if((d_pck = decode_data_packet(pck)) == NULL)
					{
						pck = encode_error_packet(ERROR_NOT_DEFINED);
						send_packet(cl->socket,pck);
						perror("Error decoding packet");
						cl->state = STOP;
						returnval = -1;
						break;
					}

					/* If it is a DATA packet */
					if(ntohs(d_pck->opcode) == OPCODE_DATA)
					{
						//printf("GOT: %d (%d bytes)\n",ntohs(d_pck->blockno),packet_len);
						/* Check blocknumber that it is the same as waited block*/
						if(ntohs(d_pck->blockno) == cl->lastpacket)
						{
							if(packet_len == 4)
							{
								cl->state = STOP;
								returnval = 1;
								break; /* If data packet with 0 data -> last packet */
							}
							
							/* Add data packet to fileblock list */
							cl->data = add_data_packet(cl->data,d_pck,packet_len);
							
							if(write_block_to_file(cl) == -1)
							{
								pck = encode_error_packet(ERROR_ACCESS_VIOLATION);
								send_packet(cl->socket,pck);
								cl->state = STOP;
							}
							
							/* Create ack packet for this packet and send it */
							pck = encode_ack_packet(ntohs(d_pck->blockno));
							n = send_packet(cl->socket,pck);

							//printf("Sent ACK: %d\n",ntohs(d_pck->blockno));
//.........这里部分代码省略.........
开发者ID:HateBreed,项目名称:tftpserverclient,代码行数:101,代码来源:clioper.c


注:本文中的send_packet函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。