Ejemplo n.º 1
0
Archivo: wol.c Proyecto: ARUNRAGA/WOL
int main( int argc, char **argv )
{
  int sock;
  mac_addr_t *( *funcp )( char **args, int length ) = nextAddrFromArg;
  wol_header_t *currentWOLHeader = (wol_header_t *) malloc( sizeof( wol_header_t ));
  char **args                    = (char **) malloc( argc * ARGS_BUF_MAX * sizeof( char ));
  int length                     = argc;
  char argument;

  strncpy( currentWOLHeader->remote_addr, REMOTE_ADDR, ADDR_LEN );

  while(( argument = getopt( argc, argv, "r:f" )) != -1 )
  {
    if( argument == 'f' )
    {
      funcp = nextAddrFromFile;
    }
    else if( argument == 'r' )
    {
      strncpy( currentWOLHeader->remote_addr, optarg, ADDR_LEN );
    }
    else if( argument == '?' )
    {
      if( isprint( optopt ))
      {
        fprintf( stderr, "Unknown option: %c ...!\n", optopt );
      }
    }
    else
    {
      fprintf( stderr, USAGE, *argv );
    }
  }

  if( argc < 2 )
  {
    fprintf( stderr, USAGE, *argv );
    exit( EXIT_FAILURE );
  }

  args   = &argv[optind];
  length = argc - optind;

  if(( sock = startupSocket( )) < 0 )
  {
    exit( EXIT_FAILURE ); // Log is done in startupSocket( )
  }

  while(( currentWOLHeader->mac_addr = funcp( args, length )) != NULL )
  {
    if( sendWOL( currentWOLHeader, sock ) < 0 )
    {
      fprintf( stderr, "Error occured during sending the WOL magic packet for mac address: %s ...!\n", currentWOLHeader->mac_addr->mac_addr_str );
    }
    free( currentWOLHeader->mac_addr );
  }

  close( sock );
  return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
// Will be called when WiFi station was connected to AP
void connectOk()
{
	Serial.println("I'm CONNECTED");
	timer.initializeMs(PACKET_INTERVAL, *[] {
			digitalWrite(LED_PIN, digitalRead(BTN_PIN));
			if(!digitalRead(BTN_PIN))
			{
				Serial.println("Sending WOL");
				sendWOL(target_mac);
			}
			}).start();
}