Exemplo n.º 1
0
/** check EDNS at this IP and port */
static int
check_edns_ip(char* ip, int port, int info)
{
	struct sockaddr_storage addr;
	socklen_t len = 0;
	uint8_t* wire;
	size_t wlen;
	memset(&addr, 0, sizeof(addr));
	if(verb) printf("%s ", ip);
	if(!convert_addr(ip, port, &addr, &len))
		return 2;
	/* try to send 3 times to the IP address, test root key */
	if(!get_packet(&addr, len, ".", LDNS_RR_TYPE_DNSKEY, &wire, &wlen))
		return 2;
	if(!check_packet(wire, wlen, LDNS_RR_TYPE_DNSKEY))
		return 1;
	/* check support for caching type DS for chains of trust */
	if(!get_packet(&addr, len, "se.", LDNS_RR_TYPE_DS, &wire, &wlen))
		return 2;
	if(!check_packet(wire, wlen, LDNS_RR_TYPE_DS))
		return 1;
	if(verb) printf("OK\n");
	if(info) printf(" %s", ip);
	return 0;
}
Exemplo n.º 2
0
int main()
{
  ogg_sync_state oy;
  ogg_stream_state os;
  int init=0;
  ogg_packet op;
  kate_state k;
  kate_info ki;
  kate_comment kc;
  const kate_event *ev;

  /* for the benefit of windows, which mangles data otherwise */
  set_binary_file(stdin);

  /* we initialize ogg and kate info/comment structures */
  ogg_sync_init(&oy);
  kate_info_init(&ki);
  kate_comment_init(&kc);

  /*
    First, read the headers, which must appear first in a Kate stream. When
    kate_decode_header returns a positive number, all headers have been seen
    and we're ready to decode data.
    */
  do {
    get_packet(&oy,&os,&init,&op);
  } while (kate_ogg_decode_headerin(&ki,&kc,&op)==0);

  /*
    We now have all the information we need from the headers, so we can
    initialize kate for decoding
    */
  kate_decode_init(&k,&ki);

  /*
    We can now read data, until kate_decode_packetin returns a positive
    number, signaling the end of the stream
    */
  while (1) {
    if (get_packet(&oy,&os,&init,&op)) break;
    if (kate_ogg_decode_packetin(&k,&op)>0) break;

    /* we may have an event (eg, text) */
    if (kate_decode_eventout(&k,&ev)==0) {
      printf("Kate stream has text: %s\n",ev->text);
    }
  }

  /* That's it, we can now cleanup */
  ogg_stream_clear(&os);
  ogg_sync_clear(&oy);

  kate_clear(&k);
  kate_info_clear(&ki);
  kate_comment_clear(&kc);

  return 0;
}
Exemplo n.º 3
0
int parse_anza_SP ( 
    uchar_t *packet,
   ushort_t pkttype )
{

double ptime, ytime, sec;
ulong ysec;
int year, day, hour, min;
PktPar pack;

/* Get parameters for current datatype  */

      if( !get_packet( pkttype, &pack) ) return -1;
    
      Par.staid = packet[6]*256 + packet[7];
      Par.packet = pack;
      Par.chan = -1; 
      Par.hdrtype = ( int )decode( pack.hdrtype ); 
      
      ytime = now();
      e2h( ytime, &year, &day, &hour, &min, &sec);
      ptime = epoch( year * 1000 );
      memcpy( (char *) &ysec, (char *) &packet[10], 4);
      Par.time = ptime + ysec;
      
  return (int) pkttype; 
      
      
}
Exemplo n.º 4
0
int get_packet(ogg_sync_state *oy,ogg_stream_state *os,int *init,ogg_packet *op)
{
  char *buffer;
  size_t bytes;
  ogg_page og;

  /* try to get a packet from the stream */
  if (*init && ogg_stream_packetout(os,op)) return 0;

  /* read data and feed the pages to ogg */
  buffer=ogg_sync_buffer(oy,4096);
  bytes=fread(buffer,1,4096,stdin);
  if (bytes==0) return 1; /* we're done */
  ogg_sync_wrote(oy,bytes);
  while (ogg_sync_pageout(oy,&og)>0) {
    if (!*init && ogg_page_bos(&og)) {
      ogg_stream_init(os,ogg_page_serialno(&og));
    }
    ogg_stream_pagein(os,&og);
    if (!*init && ogg_page_bos(&og)) {
      ogg_packet op;
      ogg_stream_packetpeek(os,&op);
      if (op.bytes>=8 && !memcmp(op.packet,"\200kate\0\0\0",8)) {
        *init=1;
      }
      else {
        ogg_stream_clear(os);
      }
    }
  }

  /* try again with the new data */
  return get_packet(oy,os,init,op);
}
Exemplo n.º 5
0
/* check if there's a message from the server */
void get_server_message () {
  int nr_active_sock, reclen, startptr = 0, msglen;

try_again:
  nr_active_sock = SDLNet_CheckSockets (theset, 1);
  if (nr_active_sock == 0) return;
  if (!SDLNet_SocketReady (thesock)) return;

  reclen = get_packet ();
  if (reclen == -1) return;
  if (reclen <= 0) {
    log_error ("Disconnected by the server!\n");
    exit_connection (EXIT_ALL);
    exit (1);
  }

  msglen = *((short *) (msgbuf + startptr + 1));
  msglen += 2;
  if (process_message(msgbuf+startptr, msglen) == 0) {
    /* something went wrong when processing our message. Log out. */
    exit_connection (EXIT_ALL);
    log_error ("Unable to process message");
    exit (1);
  }

  goto try_again;
}
Exemplo n.º 6
0
void vsync(DISPMANX_UPDATE_HANDLE_T u, void* arg)
{

    int ret;
    DISPMANX_UPDATE_HANDLE_T    update;

    update = vc_dispmanx_update_start( 10 );
    assert( update );
    ret = vc_dispmanx_element_change_source( update, element, resource[next_resource]);
    assert( ret == 0 );
    ret = vc_dispmanx_update_submit_sync( update );
    assert( ret == 0 );

    if(next_resource != 2) {

        int real_next_resource = next_resource ^ 1;
        next_resource = 2; // use filler if next callback called before this one ends

        // fill image
        int n;
        for (n=0; n<HEIGHT; n+=2) {
            get_packet(ROW(n)+24); // +24 because clock never changes
            memcpy(ROW(n+1)+24, ROW(n)+24, 336); // double it up because the hardware scaler
                                                 // will introduce blurring between lines
        }

        // write to resource
        ret = vc_dispmanx_resource_write_data(  resource[real_next_resource], TYPE, PITCH, image, &image_rect );
        assert( ret == 0 );

        next_resource = real_next_resource; // queue up next real resource

    }
}
Exemplo n.º 7
0
/**
 * sniff_packet()
 * --------------
 * the function to be called to read packet, do analysis, and update
 * the internal structure.
 * reads in p802.11 hdr, as well as ip hdr.
 * highest level call used by sniffer_engine...
 **/
void sniff_packet(struct SETTINGS *mySettings)
{
  struct packet_info *packet;
  
  /**
   * read the packet, and handle the type of packet returned.
   **/
  if (DEBUG) printf("reading socket\n");

  if (NULL == (packet = get_packet(mySettings)))
    return;
  if (DEBUG) printf("socket read ok\n");

  if (mySettings->scan_mode == CHANNEL_SCAN){
    process_channel_scan(packet);
  }
  else if (mySettings->scan_mode == DETAILED_SCAN){
    if (mySettings->runtime_mode == DAEMONIZED)
      mySettings->chosen_ap = NULL;
    if (mySettings->chosen_ap != NULL)
      process_detailed_scan(packet,
	     (struct access_point *)mySettings->chosen_ap);
    else
      process_detailed_scan(packet, NULL);
  } 
}
Exemplo n.º 8
0
Error PacketPeer::get_var(Variant &r_variant) {

	const uint8_t *buffer;
	int buffer_size;
	Error err = get_packet(&buffer, buffer_size);
	if (err)
		return err;

	return decode_variant(r_variant, buffer, buffer_size, NULL, allow_object_decoding);
}
Exemplo n.º 9
0
Error PacketPeer::get_var(Variant &r_variant) const {

	const uint8_t *buffer;
	int buffer_size;
	Error err = get_packet(&buffer, buffer_size);
	if (err)
		return err;

	return decode_variant(r_variant, buffer, buffer_size);
}
Exemplo n.º 10
0
ECFG *get_ECFG(double time)
{
	static ECFG Ecfg; 
	static uchar last_ndata[ECONFIG_SIZE];
	static packet *pkn,*pkx;
	static int different=1;
	static packet_selector pks;
/* static packet_selector frmpks;  */
/* static struct frameinfo_def frame; */

	SET_PKS_BY_LASTT(pks,time,E_CFG_ID);
/*SET_PKS_BY_TIME(frmpks,time,E_CFG_ID);  */
/*get_next_frame_struct(&frmpks,&frame);*/
	Ecfg.time = time;

	Ecfg.spin_period = SPIN_PERIOD;   /* this must be made more dynamic */
/*Ecfg.spin_period = frame.spin_period; */

	Ecfg.temperature = 9.3;   /* default */
	Ecfg.el_geom = GEOM_EL;
	Ecfg.eh_geom = GEOM_EH;

	pkn = get_packet(&pks);
	if(pkn && !(pkn->quality & (~pkquality)))
		different = memcmp(last_ndata, pkn->data, ECONFIG_SIZE);
	if(different && check_econfig_pk_validity(pkn)){
		if(pkn && !(pkn->quality & (~pkquality)))
			memcpy(last_ndata,pkn->data,ECONFIG_SIZE);
		decom_econfig(pkn,&Ecfg.norm_cfg);
		initialize_eesa_high(&Ecfg);
		initialize_eesa_low(&Ecfg);
		different = 0;
		Ecfg.valid++;
	}

	SET_PKS_BY_LASTT(pks,time,E_XCFG_ID);
	pkx = get_packet(&pks);

	decom_exconfig(pkx,&Ecfg.extd_cfg);

	return(&Ecfg);
}
Exemplo n.º 11
0
void feed_packets(int *sockfds, pcap_list_t *pkt_list) {
    uint32_t list_len = get_pkt_list_length(pkt_list);
    for (uint32_t i = 0; i < list_len; i++) {
        pcap_pkt *input_pkt = get_packet(pkt_list, i);
        int sockfd = sockfds[input_pkt->ifindex];
        char *data = input_pkt->data;
        int len = input_pkt->pcap_hdr.len;
        if (sendto(sockfd, data, len, 0, 0, sizeof(struct sockaddr_ll)) < 0)
            perror("sendto failed");
    }
}
void gui_video_rotate_mode(struct GuiButton *gbtn)
{
    struct Packet *pckt;
    pckt = get_packet(my_player_number);
    if (settings.video_rotate_mode) {
        set_packet_action(pckt, PckA_SwitchView, 5, 0, 0, 0);
    } else {
        set_packet_action(pckt, PckA_SwitchView, 2, 0, 0, 0);
    }
    save_settings();
}
Exemplo n.º 13
0
void packet_handler(int sig) {
	packet_t pkt;
	fprintf(stderr, "IN PACKET HANDLER, sig=%d %s \t\t pkt counter so far %d\n",
			sig, strsignal(sig), pkt_cnt);

	pkt = get_packet(cnt_msg); // the messages are of variable length. So, the 1st message consists of 1 packet, the 2nd message consists of 2 packets and so on..
	pkt_total = pkt.how_many;

	if (pkt_cnt == 0) { // when the 1st packet arrives, the size of the whole message is allocated.
		message.num_packets = pkt_total;
		message.data = (char*) mm_get(&MM,
				message.num_packets * PACKET_DATA_SIZE + 1); // +1 for ending 0
		fprintf(stderr, "=========Message address start \t %p \n",
				message.data);
//		message.data[pkt_total * PACKET_DATA_SIZE] = 0;
		memset(message.data, 0, message.num_packets * PACKET_DATA_SIZE + 1);
	}

//	fprintf(stderr, "After get %d: \t|%s| \t\t%p\n", cnt_msg, message.data,
//			message.data);

	fprintf(stderr, "CURRENT MESSAGE %d with message total number %d, which %d and stuff %s\n",
			cnt_msg, message.num_packets, pkt.which, pkt.data);

//	fprintf(stderr, "Dest: ~%p~; \t Src: %p \t Size %d \t Offset %d (%d) \t @cnt %d\n",
//			&message.data[0] + (PACKET_DATA_SIZE * pkt.which), pkt.data,
//			PACKET_DATA_SIZE, pkt.which, PACKET_DATA_SIZE * pkt.which,pkt_cnt);

	/* insert your code here ... stick packet in memory, make sure to handle duplicates appropriately */
	if (message.data[PACKET_DATA_SIZE * pkt.which] == (char) 0) {
		memcpy(message.data + (PACKET_DATA_SIZE * pkt.which), pkt.data,
				PACKET_DATA_SIZE);
	} else { // duplicated message deleted, skip this round
		return;
	}

	++pkt_cnt;
	if (pkt_cnt == message.num_packets) {
		int i;
		fputs("--------->",stderr);
		for (i=0;i<(PACKET_DATA_SIZE*message.num_packets);++i){
//			fputs("%d ",message.data[i],stderr);
			fprintf(stderr,"%d ",(int)message.data[i]);
		}
		fputs("\n",stderr);
		/*Print the packets in the correct order.*/
		fprintf(stderr, "MSG %d: \t|%s| \t\t%p\n\n", cnt_msg, message.data,
				message.data);
		mm_put(&MM, (void*) message.data);
	}
	/*Deallocate message*/

}
Exemplo n.º 14
0
//****************************************************************************
int CPacketList::get_packet_data(u8 *rbfr)
{
   packet_list_p ptemp = get_packet();
   if (ptemp == NULL) {
      return -ERROR_NO_MORE_FILES ;  //  no packet available
   }
   // syslog("get: %u bytes\n", ptemp->bfr_len) ;
   memcpy(rbfr, ptemp->bfr, ptemp->bfr_len) ;
   int rx_bytes = ptemp->bfr_len ;
   delete ptemp ;
   return rx_bytes;
}
Exemplo n.º 15
0
int netLoop(int tunFd)
{
	char *tunPkt = NULL;

	while(1)
	{
		tunPkt = get_packet(tunFd);

		processPacket(tunPkt);
		//tunPkt = NULL;
	}
	return 0; 
}
Exemplo n.º 16
0
//==========================================================================================
	//接受处理数据包
int login_loop(pcap_t *pcap_handle)
{
	struct pcap_pkthdr *pkt_header;
	const u_char *pkt_data;//存储数据包的内容
	int pcap_rec;
	int time_cnt = 0;
	int time_max = 500;//设置超时时间
	struct packet_eap *p = get_packet();//数据包

	//start验证
	pcap_sendpacket(pcap_handle,p->start,18 + p->start[17]);
	while ((pcap_rec = pcap_next_ex(pcap_handle,&pkt_header,&pkt_data)) != -1){
		if((pcap_rec == 0) || (pkt_data[12]!=0x88) || (pkt_data[13]!=0x8e)){	
			if(time_cnt++ > time_max){//超时处理
				printf("%s time out!!! need reconnect...\n", what_time());
				time_cnt = 0;
			}
			continue;
		}

        switch(pkt_data[18]){
			case 0x01://code:request
                if ( pkt_data[22]==0x01){ 	//Type: identity[rfc3748] (1)
                    printf("%s response, identity\n", what_time());
                    p->id[19]=pkt_data[19];
                    pcap_sendpacket(pcap_handle,p->id,18 + p->id[17]);   
                }

                if ( pkt_data[22]==0x04){	//Type:  MD5-Challenge [RFC3748] (4)  
					make_passwd_pkt(p->passwd, pkt_data);
                    pcap_sendpacket(pcap_handle,p->passwd,18 + p->passwd[17]);  
					printf("%s resopnse, MD5-challenge\n", what_time());
                }
                break;
           
            case 0x03://code:sussess
                printf("%s %s login successfully\n", what_time(), username);
				printf("%s press ctrl+c to logout...\n", what_time());
                break;

            case 0x04://code:failed
                printf("%s %s login failed. unknow error\n", what_time(), username);
                break;
            }   
       
	}

	return -1;
//==========================================================================================
}
Exemplo n.º 17
0
int test_packet(unsigned short cnt) {
	int conta = 0, ind = 0, r, ipc_status;
	unsigned long irq_set, data;
	char cmd;
	message msg;
	if ((irq_set = mouse_subscribe()) == -1) {
		printf("Unable to subscribe mouse!\n");
		return 1;
	}
	if (sys_outb(STAT_REG, ENABLE_MOUSE) != OK) //rato enable
		printf("Error\n");
	if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) //MOUSE
		printf("Error-MC\n");
	if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) //Ativar o envio
		printf("Error-SEND\n");
	while (cnt > conta) {
		if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
			printf("driver_receive failed with: %d", r);
			continue;
		}
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					get_packet();
					mouse_print();

				}
				break;
			default:
				break;
			}
		} else {
		}
	}
	printf("Terminou!\n");
	if (sys_outb(STAT_REG, W_TO_MOUSE) != OK)
		printf("ERROR-MC");
	if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK)
		printf("ERROR-DISABLE_STREAM");
	if (sys_inb(OUT_BUF, &data) != OK)
		printf("OUT_BUF not full!\n");
	if (data != ACK)
		printf("Not ACK!\n");
	if (mouse_unsubscribe() == -1)
		printf("falhou unsubscribe mouse!\n");
	return 0;
}
Exemplo n.º 18
0
/*
 * dump the file into the fd
 */
static void dump_file(gzFile fd, struct log_global_header *hdr)
{
   struct log_header_packet pck;
   struct log_header_info inf;
   struct dissector_info infbuf;
   u_char *pckbuf;
   int count = 0;

   /* loop until EOF */
   LOOP {
      switch (hdr->type) {
         case LOG_INFO:
            if (get_info(&inf, &infbuf) != E_SUCCESS) {
               printf("\n");
               return;
            }
            /* write the info */
            put_info(fd, &inf, &infbuf);
	    SAFE_FREE(infbuf.user);
            SAFE_FREE(infbuf.pass);
            SAFE_FREE(infbuf.info);
            SAFE_FREE(infbuf.banner);

            break;

         case LOG_PACKET:
            if (get_packet(&pck, &pckbuf) != E_SUCCESS) {
               printf("\n");
               return;
            }
            /* write the data */
            put_packet(fd, &pck, pckbuf);
            SAFE_FREE(pckbuf);
            break;
            
         default:
            FATAL_ERROR("Unknown log type");
            break;
      }
      
      /* a dot every 10 packets */
      if (count++ % 10 == 0) {
         printf(".");
         fflush(stdout);
      }
   }

}
Exemplo n.º 19
0
void select_resurrect_creature(struct GuiButton *gbtn)
{
    struct Dungeon *dungeon;
    dungeon = get_my_dungeon();
    int i;
    i = selected_resurrect_creature(dungeon, gbtn);
    if (i != -1)
    {
        struct CreatureStorage *cstore;
        cstore = &dungeon->dead_creatures[i];
        struct Packet *pckt;
        pckt = get_packet(my_player_number);
        set_packet_action(pckt, PckA_ResurrectCrtr, dungeon_special_selected, dungeon->owner | (cstore->model << 4) | (cstore->explevel << 12));
        turn_off_menu(GMnu_RESURRECT_CREATURE);
    }
}
Exemplo n.º 20
0
/* Description: Wait for a DATA frame and store the payload.
 * Author: Albin Severinson
 * Date: 08/03/15
 */
bstring get_data_frame()
{
  int rc = 0;
  bstring packet;

  //Wait for preamble to occur
  rc = wait_for_preamble();
  check(rc == 0, "Failed to get preamble.");

  //Get packet
  packet = get_packet();
  return packet;

 error:
  return NULL;
}
Exemplo n.º 21
0
Arquivo: main.c Projeto: pzl/piwm
void *handle_client_thread(void *ptr) {

	Client *client = (Client *)ptr;
	ClientWindow gfx = { 0 };
	int running = 1;

	//for reading data into
	Buffer buf;
	char *packet=NULL;
	uint32_t packlen;
	uint8_t cmd;

	buf.buf = NULL;

	printf("<%lu> got a connection ", pthread_self());
	get_client_name(&(client->addr));


	while (running) {
		// 1. get single "packet"
		printf("asking for a packet\n");
		packlen = get_packet(client->sock, &buf, &packet);
		printf("got a packet. Length: %zu\n", packlen);
		if (packlen == 0){
			running = 0;
			break;
		}

		// 2. parse packet and perform command
		cmd = (uint8_t) *packet++;
		running = run_command(cmd, packet, packlen-1, client, &gfx);

		// 3. repeat or cleanup
	}

	// X. cleanup and leave
	printf("cleaning up client data\n");
	if (gfx.window != 0){
		destroy_window(&gfx); //graphics cleanup
	}
	close(client->sock);  //network cleanup
	free(buf.buf);
	free(client);
	//pthread_exit or return
	return NULL;
}
Exemplo n.º 22
0
void *handle_request(void *desc)
{
	int sockd = ((struct client *)desc)->sockd;
	char *addr = &(((struct client *)desc)->addr);
	u_short port = ((struct client *)desc)->port;
	
	//check ip

	printf("Serving %s:%d\n\n", addr, port);

	while(get_packet(sockd) == 0);

	raw_close(sockd);

	pthread_exit(0);
	//exit(0);
}
Exemplo n.º 23
0
void
packet_selection(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data)
{
  /* Fetch the packet from the cache */
  union olsr_message *pack;
  char *packet;
  int y, x;
  short size;
  char *content[4];
  int mem_size = 10;

  content[0] = (char *)malloc(mem_size);
  content[1] = (char *)malloc(mem_size);
  content[2] = (char *)malloc(mem_size);
  content[3] = (char *)malloc(mem_size);


  pack = get_packet(row);
  packet = (char *)pack;

  //printf("Got the packet at row %d...\n", row);

  gtk_clist_clear(GTK_CLIST(packet_content_list));

  size = ntohs(pack->v4.olsr_msgsize);
  
  for(y = 0; y < size;y += 4)
    {

      for(x = 0; x < 4; x++)
	{
	  if(display_dec)
	    sprintf(content[x], "%03i", (u_char) packet[y+x]); /* Decimal format */
	  else
	    sprintf(content[x], "%02x", (u_char) packet[y+x]); /* Hex format */	    
	}

      gtk_clist_append(GTK_CLIST(packet_content_list), content);
    }

  free(content[0]);
  free(content[1]);
  free(content[2]);
  free(content[3]);

}
Exemplo n.º 24
0
int parse_pscl_IP ( 
    uchar_t *packet,
    ushort_t pkttype )
{

int nsamp, yr, day, hr, min, sec, msec;
ushort_t newtype; 
PktPar pack;
char stime[64], key[64];
struct PsclPreHdr pkt;
int dasid;

/* Get parameters for current datatype  */

      newtype = PSCLIP;
      if( !get_packet( newtype, &pack) ) return -1;
    
      dasid = bcd2hex( &packet[4] , 4 );
      Par.staid = dasid;
      Par.chan = -1;
      Par.packet = pack;
      Par.hdrtype = ( int )decode( pack.hdrtype ); 

      memcpy( (char *) &pkt, packet, sizeof( struct PsclPreHdr ));
      yr = bcd2hex( pkt.year , 2 );
      sprintf( (char *) &stime[0], "%02x%02x%02x%02x%02x%02x\0", 
        pkt.bcdtime[0], pkt.bcdtime[1], pkt.bcdtime[2], 
        pkt.bcdtime[3], pkt.bcdtime[4], pkt.bcdtime[5]); 
      sscanf( (char *) &stime[0], "%3d%2d%2d%2d%3d", 
        &day, &hr, &min, &sec, &msec);
      if( yr < 50 ) 
          sprintf( (char *) &stime[0], "20%02d%03d:%02d:%02d:%02d.%03d\0", 
                                        yr, day, hr, min, sec, msec); 
      else
          sprintf( (char *) &stime[0], "19%02d%03d:%02d:%02d:%02d.%03d\0", 
                                        yr, day, hr, min, sec, msec); 
      Par.time = str2epoch( (char *) &stime[0] );
      
   
      sprintf( &Par.packet.pkttype[0], "PSCLIP\0");
      sprintf( (char *) &key[0], "%d", newtype );
      setarr( RawPkts, (char *) &key[0], (char *) &Par.raw);
      
      return (int) pkttype;
}
Exemplo n.º 25
0
Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {

	const uint8_t *buffer;
	int buffer_size;
	Error err = get_packet(&buffer, buffer_size);
	if (err)
		return err;

	r_buffer.resize(buffer_size);
	if (buffer_size == 0)
		return OK;

	PoolVector<uint8_t>::Write w = r_buffer.write();
	for (int i = 0; i < buffer_size; i++)
		w[i] = buffer[i];

	return OK;
}
Exemplo n.º 26
0
int main4()
{
	int cnt = 1000000;
	start_pres_server();
	struct sched_pres *sp = (struct sched_pres*)buf;
	uint8 no = 0;
		
	while(1)
	{
		INFO("\033[1;33mtcp server... main4\033[0m \n");
		if(!is_client_connected() && !have_packet())
		{
			no = 0;
			DEBUG("no client!\n");
			usleep(1000000);
		}
		if(have_packet())
		{
			int len = get_packet(buf, MAX_LEN);
			CHECK2(len >=23 && len == sp->pkt_len);
			INFO("Get a packet!\n dst_tel_code:%x\nsrc_tel_code:%x\n"
				 "pkt_len:%d\nno%d\ntime:%s\ndata_type:%x\ndata_sub_type:%x\n"
				 "test_len:%d\n",
				 sp->dst_tel_code, sp->src_tel_code, sp->pkt_len, sp->no, ctime(&sp->time),
				 sp->data_type, sp->data_sub_type, sp->text_len);
			int i;
			uint8 c = 0;
			no++;
		//	DEBUG("should no:%d  RECV_NO:%d\n", no, sp->no);
	//		CHECK2(no==sp->no);
			for(i = 0; i < sp->text_len; i++)
			{
				if(sp->data[i] != c)
				{
					DEBUG("i = %d sp->data[i]==%d  c==%d\n", i, sp->data[i], c);
					CHECK2(sp->data[i]==c);
				}
				c++;
			}
		}
			usleep(10000);
	}
	stop_pres_server();
}
Exemplo n.º 27
0
int
mm_decode_video(mm_file *mf, SDL_Overlay *ovl)
{
    int rv = 0;
    ogg_packet pkt;
    yuv_buffer yuv;

    assert(mf);

    if (!mf->video) {
        return -1;
    }

    if (mf->drop_packets & MEDIA_VIDEO) {
        WARNING1("requested decode but MEDIA_VIDEO is set to ignore");
        return -1;
    }

    for (;;) {
        rv = get_packet(mf, &pkt, MEDIA_VIDEO);

        if (rv <= 0) {
            return rv;
        }

        /* we got packet, decode */
        if (theora_decode_packetin(mf->video_ctx, &pkt) == 0) {
            break;
        } else {
            WARNING1("packet does not contain theora frame");
            /* get next packet */
        }
    }

    theora_decode_YUVout(mf->video_ctx, &yuv);

    if (yuv_to_overlay(mf, &yuv, ovl) < 0) {
        return -1;
    }

    return 1;
}
Exemplo n.º 28
0
int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush,
                        int (*get_packet)(AVFormatContext *, AVPacket *, AVPacket *, int),
                        int (*compare_ts)(AVFormatContext *, AVPacket *, AVPacket *))
{
    int i, ret;

    if (pkt) {
        AVStream *st = s->streams[pkt->stream_index];
        AudioInterleaveContext *aic = st->priv_data;
        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
            unsigned new_size = av_fifo_size(aic->fifo) + pkt->size;
            if (new_size > aic->fifo_size) {
                if (av_fifo_realloc2(aic->fifo, new_size) < 0)
                    return AVERROR(ENOMEM);
                aic->fifo_size = new_size;
            }
            av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL);
        } else {
            // rewrite pts and dts to be decoded time line position
            pkt->pts = pkt->dts = aic->dts;
            aic->dts += pkt->duration;
            if ((ret = ff_interleave_add_packet(s, pkt, compare_ts)) < 0)
                return ret;
        }
        pkt = NULL;
    }

    for (i = 0; i < s->nb_streams; i++) {
        AVStream *st = s->streams[i];
        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
            AVPacket new_pkt = { 0 };
            while ((ret = interleave_new_audio_packet(s, &new_pkt, i, flush)) > 0) {
                if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0)
                    return ret;
            }
            if (ret < 0)
                return ret;
        }
    }

    return get_packet(s, out, NULL, flush);
}
Exemplo n.º 29
0
void packet_handler(int sig)
{
	packet_t pkt;
	//  fprintf (stderr, "IN PACKET HANDLER, sig=%d\n", sig);
	
	pkt = get_packet(cnt_msg); // the messages are of variable length. So, the 1st message consists of 1 packet, the 2nd message consists of 2 packets and so on..
	pkt_total = pkt.how_many;
	if(pkt_cnt==0){ // when the 1st packet arrives, the size of the whole message is allocated.
	
	} 
  
	printf("CURRENT MESSAGE %d\n",cnt_msg);

	/* insert your code here ... stick packet in memory, make sure to handle duplicates appropriately */
 
	/*Print the packets in the correct order.*/

	/*Deallocate message*/

}
Exemplo n.º 30
0
void select_transfer_creature(struct GuiButton *gbtn)
{
    struct Dungeon *dungeon;
    dungeon = get_my_dungeon();
    struct Thing *thing;
    thing = INVALID_THING;
    int listitm_idx;
    listitm_idx = selected_transfer_creature(dungeon, gbtn);
    if (listitm_idx != -1)
    {
        thing = get_player_list_nth_creature_of_model(dungeon->creatr_list_start, 0, listitm_idx);
    }
    if (thing_exists(thing))
    {
        struct Packet *pckt;
        pckt = get_packet(my_player_number);
        set_packet_action(pckt, PckA_TransferCreatr, dungeon_special_selected, thing->index);
        turn_off_menu(GMnu_TRANSFER_CREATURE);
    }
}