예제 #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(servreg_hack_process, ev, data)
{
  static struct etimer periodic;
  static struct uip_udp_conn *outconn, *inconn;
  PROCESS_BEGIN();

  /* Create outbound UDP connection. */
  outconn = udp_broadcast_new(UIP_HTONS(UDP_PORT), NULL);
  udp_bind(outconn, UIP_HTONS(UDP_PORT));

  /* Create inbound UDP connection. */
  inconn = udp_new(NULL, UIP_HTONS(UDP_PORT), NULL);
  udp_bind(inconn, UIP_HTONS(UDP_PORT));

  etimer_set(&periodic, PERIOD_TIME);
  etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == PROCESS_EVENT_TIMER && data == &periodic) {
      etimer_reset(&periodic);
      etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
    } else if(ev == PROCESS_EVENT_TIMER && data == &sendtimer) {
      send_udp_packet(outconn);
    } else if(ev == tcpip_event) {
      parse_incoming_packet(uip_appdata, uip_datalen());
    }
  }
  PROCESS_END();
}
예제 #2
0
///Send everything in our line buffer to the PC
void sendLineBuffer()
{
	long bytesToSend = pixNum;
	long loc = 0;
	unsigned char dataSize;
	///Loop trough until we've sent everything
	while (bytesToSend > 0)
	{
		dataSize = (bytesToSend >= MAXSENDSIZE) ? MAXSENDSIZE : bytesToSend;
		send_udp_packet(&sendBuffer[0], &lineBuffer[loc], dataSize);
		bytesToSend -=dataSize;
		loc+=dataSize;
	}
}
예제 #3
0
void ipx_receive(int s) {
  ipxpacket_t buf;
  int rc;
  struct sockaddr from;
  size_t sl = sizeof(from);
  rc = recvfrom(s,&buf,sizeof buf,0,&from,&sl);
  if (rc == -1) {
    fprintf(stderr,"read(ipx): %s\n", strerror(errno));
    exit(-2);
  }
  if (rc > 0) {
    if (buf.tic == -1) {
      // Setup packet
      if (!connected++) {
        connect(s,&from,sl);
	send_udp_packet(PKT_INIT,0,NULL,0);
      }
    } else {
      if (buf.u.d.checksum & NCMD_SETUP) {
	printf("setup packet, dropped\n");
      } else if (buf.u.d.checksum & NCMD_EXIT) {
	      send_udp_packet(PKT_QUIT,buf.u.d.starttic,NULL,0);
	      exit(0);
      } else if ((buf.u.d.checksum & NCMD_CHECKSUM) == buf.u.d.checksum) {
	      // No flags, normal game packet
	      char outbuf[100];
	      int tics;
	      outbuf[0] = tics = buf.u.d.numtics;
	      outbuf[1] = buf.u.d.player;
              for (int i=0; i< tics; i++)
		TicToRaw(outbuf+2+i*sizeof(ticcmd_t),&buf.u.d.cmds[i]);
	      send_udp_packet(PKT_TICC, ExpandTics(buf.u.d.starttic, basetic), outbuf, 2+tics*sizeof(ticcmd_t));
      }
    }
  }
}
예제 #4
0
bool network_cmd_send(const char *cmd_)
{
   bool ret;
   char *command       = NULL;
   char *save          = NULL;
   const char *cmd     = NULL;
   const char *host    = NULL;
   const char *port_   = NULL;
   global_t *global    = global_get_ptr();
   bool old_verbose    = global ? global->verbosity : false;
   uint16_t port       = DEFAULT_NETWORK_CMD_PORT;

   if (!network_init())
      return false;

   if (!(command = strdup(cmd_)))
      return false;

   global->verbosity = true;

   cmd = strtok_r(command, ";", &save);
   if (cmd)
      host = strtok_r(NULL, ";", &save);
   if (host)
      port_ = strtok_r(NULL, ";", &save);

   if (!host)
   {
#ifdef _WIN32
      host = "127.0.0.1";
#else
      host = "localhost";
#endif
   }

   if (port_)
      port = strtoul(port_, NULL, 0);

   RARCH_LOG("%s: \"%s\" to %s:%hu\n",
         msg_hash_to_str(MSG_SENDING_COMMAND),
         cmd, host, (unsigned short)port);

   ret = verify_command(cmd) && send_udp_packet(host, port, cmd);
   free(command);

   global->verbosity = old_verbose;
   return ret;
}
예제 #5
0
int copied_ttl(SOCKADDR_IN *dst, unsigned int timeout, RouteInfo *rinfo)
{
	SOCKET sr;
	SOCKADDR_IN from;
	int icmp_type, delta, is_packet_recieved, copiedttl;
	unsigned short seq_sent, seq_resp;
	ULONG start_test_timestamp = GetTickCount();

	sr = init_icmp_socket();
	
	strcpy(rinfo->path, UNDEFINED_PATH);
	rinfo->resp_ttl = UNDEFINED_TTL;
	rinfo->cnt_packet_waste = 0;
	seq_sent = INITIAL_SEQ;

	while(GetTickCount()-start_test_timestamp < timeout*1000)
	{
		ULONG start_packet_timestamp = GetTickCount();
		
		send_udp_packet(dst, MAX_TTL, seq_sent);
		
		rinfo->cnt_packet_waste++;

		is_packet_recieved = wait_for_icmp(sr, &seq_resp, &icmp_type, &from, &copiedttl, timeout);
		delta = GetTickCount()-start_packet_timestamp;
		if (!is_packet_recieved)		//we got no reply
		{					
		//	fprintf(stderr, "%3d  Request timed out\t", MAX_TTL);
			break;
		}		
		if(seq_sent == seq_resp)		//check if this is our ICMP packet
		{
			if (icmp_type == ICMP_DEST_UNREACH)
			{
				rinfo->time_waste_on_test = GetTickCount() - start_test_timestamp;
				rinfo->rtt = delta;
				rinfo->hopdist = MAX_TTL+1-copiedttl;
				closesocket(sr);
				return 1;
			}
		}
		//it was not a response to our packet. send it again		
	}

	closesocket(sr);
	return 0;
}
예제 #6
0
파일: command.c 프로젝트: SuperrSonic/RA-SS
bool network_cmd_send(const char *cmd_)
{
   char *command, *save;
   bool ret;
   const char *cmd = NULL;
   const char *host = NULL;
   const char *port_ = NULL;
   bool old_verbose = g_extern.verbosity;
   uint16_t port = DEFAULT_NETWORK_CMD_PORT;

   if (!netplay_init_network())
      return false;

   if (!(command = strdup(cmd_)))
      return false;

   g_extern.verbosity = true;

   cmd = strtok_r(command, ";", &save);
   if (cmd)
      host = strtok_r(NULL, ";", &save);
   if (host)
      port_ = strtok_r(NULL, ";", &save);

   if (!host)
   {
#ifdef _WIN32
      host = "127.0.0.1";
#else
      host = "localhost";
#endif
   }

   if (port_)
      port = strtoul(port_, NULL, 0);

   RARCH_LOG("Sending command: \"%s\" to %s:%hu\n",
         cmd, host, (unsigned short)port);

   ret = verify_command(cmd) && send_udp_packet(host, port, cmd);
   free(command);

   g_extern.verbosity = old_verbose;
   return ret;
}
예제 #7
0
파일: ip.c 프로젝트: ema/libip_udp
int ip_send( ipaddr_t dst, unsigned short proto, unsigned short id, void *data,
             int len )
{
    char *buf;
    size_t header_size;
    int result;
    not_quite_ip_header_t header;

    if ( my_ipaddr == 0 ) {
        ip_init();
    }

    header.protocol = proto;
    header.source = my_ipaddr;
    header.destination = dst;
    header.flags = 0;

    if ( ( random() % 100 ) < packet_loss )
        header.flags |= DROP_PACKET;

    if ( ( random() % 100 ) < packet_corruption )
        header.flags |= CORRUPT_PACKET;

    header_size = sizeof( not_quite_ip_header_t );
    buf = malloc( header_size + len );

    memcpy( buf, &header, header_size );
    memcpy( buf + header_size, data, len );

    result = send_udp_packet( dst, buf, header_size + len );

    free( buf );

    if ( result < 0 )
        return result;
    else {
        if ( result < header_size )
            return -1;
        else
            return ( result - header_size );
    }
}
예제 #8
0
void udp_receive(int s) {
  size_t len = 1024;
  packet_header_t *p = malloc(len);
  int rc;
  
  rc = read(s,p,len);
  if (rc < 0) {
    fprintf(stderr,"read(udp): %s\n", strerror(errno));
    exit(-2);
  }
  if (rc > 0) {
    switch (p->type) {
	    case PKT_SETUP:
		    {
			    struct setup_packet_s *sinfo = (void*)(p+1);
			    consoleplayer = sinfo->yourplayer;
			    send_udp_packet(PKT_GO,0,NULL,0);
			    write(ipxs,"\xff\xff\xff\xff\x00\x00\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00",16);
		    }
		    break;
	    case PKT_GO:
		    {
			    ipxpacket_t pkt;
			    memset(&pkt,0,sizeof(pkt));
			    pkt.tic = ipxcounter++;
			    pkt.u.d.player = consoleplayer^1;
			    pkt.u.d.starttic = 0;
			    pkt.u.d.numtics = 0;
			    pkt.u.d.retransmitfrom = 0;
			    pkt.u.d.checksum = NetbufferChecksum(&pkt.u.d.retransmitfrom, 4);
			    write(ipxs,&pkt,16);
		    }
		    break;
	    case PKT_TICS:
		    {
			    ipxpacket_t pkt;
			    int tic = doom_ntohl(p->tic);
			    byte *pp = (void*)(p+1);
			    int tics = *pp++;
			    memset(&pkt,0,sizeof(pkt));
			    size_t len;

			    pkt.tic = ipxcounter++;
			    pkt.u.d.starttic = tic;
			    pkt.u.d.player = (consoleplayer == 0 ? 1 : 0);
			    pkt.u.d.numtics = tics;

			    for (int t=0; t<tics; t++) {
			      int players = *pp++;
			      for (int i=0; i<players; i++) {
				if (*pp++ == pkt.u.d.player)
				  RawToTic(&pkt.u.d.cmds[t],pp);
				pp += sizeof(ticcmd_t);
			      }
			    }
			    pkt.u.d.retransmitfrom = 0;
			    len = 12+tics*sizeof(ticcmd_t);
			    len = (len+7)&0xff8; // round up to next 16
			    pkt.u.d.checksum = NetbufferChecksum(&pkt.u.d.retransmitfrom, len-8);
			    write(ipxs,&pkt,len);
		    }
    }
  }
}
예제 #9
0
void Initialize()
{
	lineNum = 0;
	pixNum = 0;
	
	///Set PORTA as an input
	DDRA = 0x00;
	
	///Set External interrupt pins as inputs
	DDRD = DDRD | (1 << PIND2);
	DDRC = DDRC | (1 << PINC2) | (1 << PINC3);
	
	///Set Stepper output ports C[4:7], D[4:7]
	DDRD = DDRD | (0xf << PORTD4);
	DDRC = DDRC | (0xf << PORTC4);
	
	///Set up i2c communcation
	i2c_init();
	
	//Setup ethernet communication
	
	/* enable PB0, reset as output */
	ETHERNET_RESET_PORT_DD |= (1<<ETHERNET_RESET_PIN);
	
	/* set output to gnd, reset the ethernet chip */
	ETHERNET_RESET_PORT &= ~(1<<ETHERNET_RESET_PIN);
	_delay_ms(10);
	/* set output to Vcc, reset inactive */
	ETHERNET_RESET_PORT |= (1<<ETHERNET_RESET_PIN);
	_delay_ms(300);
	
	/*initialize enc28j60*/
	enc28j60Init(mymac);
	_delay_ms(20);
	
	/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
	// LEDB=yellow LEDA=green
	//
	// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
	// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
	enc28j60PhyWrite(PHLCON,0x476);
	_delay_ms(20);
	
	//init the ethernet/ip layer:
	init_ip_arp_udp(mymac,myip,mypcip,mypcmac, sendBuffer);
	_delay_ms(100);

	//send out a test packet
	char str[10] = "hello ryan";
	send_udp_packet(sendBuffer, str, 10);

	
	//Enable Internal pull up resistors
	DDRC = DDRC & ~(1<< PORTC0);
	DDRC = DDRC & ~(1<< PORTC1);
	PORTC = PORTC | (1<< PORTC0);
	PORTC = PORTC | (1<< PORTC1);

	cameraOn = 0;
	
}