Android firmware uses UDP socket to send magic Packet

Source: Internet
Author: User

Android firmware uses UDP socket to send magic Packet

1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <unistd.h>5#include <sys/types.h>6#include <sys/stat.h>7#include <sys/socket.h>8#include <netinet/inch.h>9#include <arpa/inet.h>Ten#include <netdb.h> One  A voidFill_magic_buf (void*magic_buf,void*mac) - {  -          inti; the          Char*ptr; -  -PTR =Magic_buf; -Memset (PTR,0xFF,6);  +PTR + =6;  -  +           for(i =0; I < -; ++i) { Amemcpy (PTR, Mac,6);  atPTR + =6;  -          }  - }  -  - voidUsagevoid)  - {  inprintf"usage...\n");  -  }  to  + intMainintargcChar**argv) - {  the          ints; *          intPacket_num =Ten;  $          CharC;Panax Notoginseng  -UnsignedCharmac[6] = {0x94,0x39,0xe5,0x02,0x5E,0xc9};  the          Chardstip[ the] ="192.168.1.103";  +          intPort =4097;  A  the          structsockaddr_in address; +          Charmagic_buf[6+6* -] = {0};  -  $Daemon0,0);/*Run in background*/  $  -           while(c = getopt (argc, argv,"d:m:p:")) != -1) {  -                  Switch(c) { the                   Case 'D':  - strcpy (Dstip, optarg);Wuyi                           Break;  the                   Case 'm':  -SSCANF (Optarg,"%x:%x:%x:%x:%x:%x",  Wu(unsignedint*) &mac[0], (unsignedint*) &mac[1],  -(unsignedint*) &mac[2], (unsignedint*) &mac[3],  About(unsignedint*) &mac[4], (unsignedint*) &mac[5]);  $                           Break;  -                   Case 'P':  -Port =atoi (optarg); -                           Break;  A                  default:  + usage (); the                          return-1;  -                  }  $          }  the  thes = socket (af_inet, SOCK_DGRAM,0);  the  the          if(s = =-1) {  -Perror ("Opening Socket");  in exit (exit_failure); the          }  the  Aboutmemset (&address,0,sizeof(structsockaddr_in));  theaddress.sin_family =af_inet; theADDRESS.SIN_ADDR.S_ADDR =inet_addr (dstip); theAddress.sin_port =htons (port); +  - fill_magic_buf (Magic_buf, Mac); the Bayi          /*Ten packets. Todo:use Ping to check whether the destination are on or else. */  the           while(packet_num-->0) {  the                  if(SendTo (S, Magic_buf,sizeof(MAGIC_BUF),0,  -(structSOCKADDR *) &address,sizeof(address)) <0) {  -printf"sendto\n");  the exit (exit_failure); the                  }  theSleep1);  the          }  -  the exit (exit_success); the}

Android firmware using a UDP socket to send magic Packet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.