コード例 #1
0
ファイル: na-pcap.c プロジェクト: stfacc/gnome-usage
static void
parse_udp (const struct pcap_pkthdr *header,
           const u_char             *packet,
           const IPAddress          *address)
{
  struct udphdr *udp = (struct udphdr *)packet;
  push_packet (header, address, ntohs (udp->source), ntohs (udp->dest));
}
コード例 #2
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_open(RxPacket *p)
{
    char buf[16];
    int l;
    for (l = 0; l < 16; l++) {
	buf[l] = 0;
    }
    l = p->getStr8Len();
    if (l > 15) {
	printf("too long locale name.\n");
	return;
    }
    p->getStr8(buf);

    TxPacket *t;
    C16 imid;
    XimIM *im;
    imid = unused_im_id();
    mCreatedIm.push_back(imid); // had to be deleted by the creator Connection
    im = create_im(this, imid);
    im->set_lang_region(buf);
    t = createTxPacket(XIM_OPEN_REPLY, 0);
    t->pushC16(imid);
    XIMATTRIBUTE::write_imattr_to_packet(t);
    XICATTRIBUTE::write_icattr_to_packet(t);
  
    push_packet(t);

    // EventMask selection

    t = createTxPacket(XIM_SET_EVENT_MASK, 0);
    t->pushC16(imid);
    t->pushC16(0);
    if (g_option_mask & OPT_ON_DEMAND_SYNC) {
	t->pushC32(KeyPressMask|KeyReleaseMask);
	t->pushC32((unsigned int)~(KeyPressMask|KeyReleaseMask)); // no need to send
						    // XIM_SYNC_REPLY from
						    // XIM server
    } else {
	t->pushC32(KeyPressMask);
	t->pushC32(KeyPressMask); // need to send XIM_SYNC_REPLY from XIM server
    }

    push_packet(t);
}
コード例 #3
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_disconnect()
{
    TxPacket *t;
    t = createTxPacket(XIM_DISCONNECT_REPLY, 0);
    push_packet(t);

    terminate();
    if (g_option_mask & OPT_TRACE)
	printf("disconnect xim connection.\n");
}
コード例 #4
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_query_extension(RxPacket *p)
{
    C16 imid;
    imid = p->getC16();

    TxPacket *t;
    t = createTxPacket(XIM_QUERY_EXTENSION_REPLY, 0);
    t->pushC16(imid);
    t->pushC16(0);
  
    push_packet(t);
}
コード例 #5
0
static int read_page(demuxer_priv_tt * ogg, int * stream) {
    ogg_stream_tt * os;
    int i, serial, segments;
    char tmp_header[27];
    uint8_t sizes[256];
    int len, tot = 0;

    FREAD(ogg->in, 27, tmp_header);
    if (strncmp(tmp_header, "OggS", 5)) return err_bad_oggs_magic; // including version

    serial = (tmp_header[14] << 24) |
             (tmp_header[15] << 16) |
             (tmp_header[16] <<  8) |
             (tmp_header[17]      );
    *stream = find_stream(ogg, serial);
    os = &ogg->os[*stream];

    segments = tmp_header[26];
    FREAD(ogg->in, segments, sizes);

    len = os->leftover;
    for (i = 0; i < segments; i++) {
        len += sizes[i];
        if (sizes[i] != 255) {
            packet_tt p;
            p.buf = malloc(len);
            p.p.len = len;
            p.p.stream = *stream;
            p.p.flags = p.p.pts = p.p.next_pts = 0; // Ogg sucks
            memcpy(p.buf, os->leftover_buf, os->leftover);
            FREAD(ogg->in, len - os->leftover, p.buf + os->leftover);
            push_packet(&ogg->s[*stream], &p);
            tot++;
            len = 0;
            os->leftover = 0;
        }
    }

    if (len) {
        os->leftover_buf = realloc(os->leftover_buf, len);
        FREAD(ogg->in, len - os->leftover, os->leftover_buf + os->leftover);
        os->leftover = len;
    }
    if (!tot) return read_page(ogg, stream); // this page gave nothing, move on to next page

    return 0;
}
コード例 #6
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_close(RxPacket *p)
{
    C16 imid;
    imid = p->getC16();
    TxPacket *t;
    t = createTxPacket(XIM_CLOSE_REPLY, 0);
    t->pushC16(imid);
    t->pushC16(0);
    push_packet(t);
    close_im(imid);
    std::list<C16>::iterator i;
    for (i = mCreatedIm.begin(); i != mCreatedIm.end(); ++i) {
	if (*i == imid) {
	    mCreatedIm.erase(i);
	    return;
	}
    }
}
コード例 #7
0
ファイル: hw6.c プロジェクト: lfcmpi/UIC
void rel_send(int sock, void *buf, int len)
{
	while(packets_outstanding>=window_size) {
		wait_for_ack(sock);
	}
	
 	// make the packet = header + buf	
	char packet[1400];
	struct hw6_hdr *hdr = (struct hw6_hdr*)packet;
	memset(hdr,0,sizeof(struct hw6_hdr));
	hdr->sequence_number = htonl(sequence_number);
	memcpy(hdr+1,buf,len);
	sequence_number++;

	push_packet(hdr,sizeof(struct hw6_hdr)+len,current_msec());
	sendto(sock, packet, sizeof(struct hw6_hdr)+len, 0,(struct sockaddr*)&peeraddr,sizeof(peeraddr));
	//	fprintf(stderr,"Packet %d with rtt %f dev %f wsize %d timeout %d ms     to %s      \n",sequence_number-1,rtt, deviation,window_size,timeout,inet_ntoa(peeraddr.sin_addr));
}
コード例 #8
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
//
// Packet handlers
//
void Connection::xim_connect(RxPacket *p)
{
    TxPacket *t;
    
    p->rewind();
    p->getC8();
    p->getC8(); // discard
    if (p->isOverRun()) {
	push_error_packet(0, 0, 0, "Invalid Packet");
	terminate();
	return;
    }

    t = createTxPacket(XIM_CONNECT_REPLY, 0);
    t->pushC16(1);
    t->pushC16(0);
    push_packet(t);
    if (g_option_mask & OPT_TRACE)
	printf("accept xim connection.\n");
}
コード例 #9
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::push_error_packet(C16 imid, C16 icid, C16 er, const char *str)
{
    TxPacket *t;
    t = createTxPacket(XIM_ERROR, 0);
    t->pushC16(imid);
    t->pushC16(icid);
    int m = 0;
    if (imid)
	m += 1;
    if (icid)
	m += 2;

    t->pushC16((C16)m);
    t->pushC16(er);
    int l = static_cast<int>(strlen(str));
    char tmp[4];
    t->pushC16((C16)l);
    t->pushC16(0);
    t->pushBytes(str, l);
    t->pushBytes(tmp, pad4(l));
    push_packet(t);
}
コード例 #10
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_get_im_values(RxPacket *p)
{
    int l, i;
    C16 imid;
    TxPacket *t;
    t = createTxPacket(XIM_GET_IM_VALUES_REPLY, 0);
    imid = p->getC16(); // input-method id
    l = p->getC16() / 2; // number

    int *ra = (int *)alloca(sizeof(int) * l);
    int rlen = 0;
    for (i = 0; i < l; i++) {
	ra[i] = p->getC16();
	rlen += 4;
    }

    // XIMATTRIBUTE
    C16 nr_style;
    struct input_style *is = get_im_by_id(imid)->getInputStyles();
    for (nr_style = 0; is[nr_style].style; nr_style++) {
	;
    }

    // since only one IMAttribute...
    t->pushC16(imid);
    t->pushC16((C16)(8 + nr_style * 4));

    t->pushC16(0); // attribute id
    t->pushC16((C16)(4 + nr_style * 4)); // length

    t->pushC16(nr_style); // number
    t->pushC16(0);
    for (i = 0; i < nr_style; i++) {
	t->pushC32(is[i].x_style);
    }

    push_packet(t);
}
コード例 #11
0
ファイル: ximtrans.cpp プロジェクト: NgoHuy/uim
void Connection::xim_encoding_negotiation(RxPacket *p)
{
    TxPacket *t;
    t = createTxPacket(XIM_ENCODING_NEGOTIATION_REPLY, 0);
    C16 l, index;
    int i, m, s;
    C16 imid, idx;
    char buf[32];
    XimIM *im;

    imid = p->getC16(); // m_imid
    l = p->getC16();
    im = get_im_by_id(imid);
  
    index = 0;
    for (m = 0, s = 0, idx = 0; m < l; m += (s + 1), idx++) {
	s = p->getStr8Len();

	for (i= 0; i < 32; i++) {
	    buf[i] = 0;
	}
	p->getStr8(buf);

	// use COMPOUND_TEXT
	if (!strcmp("COMPOUND_TEXT", buf))
	    index = idx;
	else {
	    if (im)
		im->set_encoding(buf);
	}
    }

    t->pushC16(imid);
    t->pushC16(0);
    t->pushC16(index);
    t->pushC16(0);
    push_packet(t);
}
コード例 #12
0
ファイル: capture.c プロジェクト: DPMI/mp
int capture_loop(struct CI* CI, struct capture_context* cap){
	int ret;

	/* initialize driver */
	if ( cap->init && (ret=cap->init(cap)) != 0 ){
		sem_post(CI->flag); /* unlock parent */
		return ret; /* return error */
	}

	/* flag that thread is ready for capture */
	sem_post(CI->flag);

	/* wait until the MP is authorized until it starts capture */
	wait_for_auth();

	CI->writepos = 0; /* Reset write-position in memory */
	while(terminateThreads==0){
		/* calculate pointers into writebuffer */
		struct write_header* whead = CI_packet(CI, CI->writepos);
		struct cap_header* head = whead->cp;
		unsigned char* packet_buffer = (unsigned char*)head->payload;

		/* fill details into capture header */
		fill_caphead(head, CI->iface, MPinfo->id);

		/* read a packet */
		ssize_t bytes = cap->read_packet(cap, packet_buffer, head);

		if ( bytes < 0 ){ /* failed to read */
			break;
		} else if ( bytes == 0 ){ /* no data */
			continue;
		}

		/* stats */
		CI->packet_count++;

		/* return -1 when no filter matches */
		if ( push_packet(CI, whead, head, packet_buffer) == -1 ){
			continue;
		}

		/* stats */
		CI->matched_count++;
	}

	/* stop capture */
	logmsg(verbose, CAPTURE, "CI[%d] stopping capture on %s.\n", CI->id, CI->iface);

	/* show stats */
	if ( cap->stats ){
		cap->stats(cap);
	}

	/* driver cleanup */
	if ( cap->destroy && (ret=cap->destroy(cap)) != 0 ){
		return ret; /* return error */
	}

	return 0;
}
コード例 #13
0
int demux_stream(int videoIdx, int audioIdx, 
       demux_read_data pReadData, void* socket ) {

  int ret;
  AVFormatContext* pFormatCtx;
  AVProbeData pd;
  AVIOContext *pb;
  AVDictionaryEntry *tag = NULL;
  RECIVER_HANDLER video_handler = NULL;
  RECIVER_HANDLER audio_handler = NULL;

  const int ioBufferSize = 32768;
  unsigned char * ioBuffer = (unsigned char *)av_malloc(ioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav

  av_register_all();
  avcodec_register_all();

  pFormatCtx = avformat_alloc_context();
  pb = avio_alloc_context(ioBuffer, ioBufferSize, 0, socket, pReadData, NULL, NULL);

  pFormatCtx->pb = pb;
  int ires = avformat_open_input(&pFormatCtx, NULL, NULL, NULL);
  if(ires < 0)
  {
    printf("Open input stream not successful %d\n",ires);
  }
  else
  {
    printf("Open input stream successfull %d\n",ires);
  }

  if(audioIdx >= pFormatCtx->nb_streams) { 
    fprintf(stderr, "Index of audio substream is bigger then number streams into container\n");
    ret = -1;
    goto fail;
  }
  if(videoIdx >= pFormatCtx->nb_streams) { 
    fprintf(stderr, "Index of video substream is bigger then number streams into container\n");
    ret = -1;
    goto fail;
  }

  DEBUG_PRINT(("create reciever \n"));
  video_handler = create_reciever(VIDEO_BIN);
  if(!video_handler) {
    fprintf(stderr, "Failed during creating video handler\n");
    ret = -1;
    goto fail;
  }
  audio_handler = create_reciever(AUDIO_BIN);
  if(!audio_handler) {
    fprintf(stderr, "Failed during creating audio handler\n");
    ret = -1;
    goto fail;
  }

  DEBUG_PRINT(("start reading file %p \n", video_handler));
  do {
      AVPacket *pkt = (AVPacket*) malloc(sizeof(AVPacket));
      av_new_packet(pkt, 0x2048);
      av_init_packet(pkt);
      ret = av_read_frame(pFormatCtx, pkt);
      if(ret < 0) {
        fprintf(stderr, "Failed read frame\n");
        av_free_packet(pkt);
        free(pkt);
        break;
      } 
    
      if( pkt->stream_index == videoIdx ) {
          ret = push_packet(video_handler, pkt);
      } else if( pkt->stream_index == audioIdx ) {
          ret = push_packet(audio_handler, pkt);
      } else {
        av_free_packet(pkt);
        free(pkt);
      }
      if( ret < 0 ) {
          fprintf(stderr, "Failed push frame\n");
          av_free_packet(pkt);
          free(pkt);
          break;
      }
 
 } while(1);


fail:

  if( video_handler ) {
     stop_reciever(video_handler);
     destroy_reciever(video_handler);
  }

  if( audio_handler ) {
     stop_reciever(audio_handler);
     destroy_reciever(audio_handler);
  }

  if(pFormatCtx) avformat_close_input(&pFormatCtx);
 // av_free(ioBuffer);

  puts("Demuxed finished work. OK");
  return ret;
}