Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the code of LAN remote boot software

Shulou Source: shulou.com Published: 2022-06-03 07:42:31 11月15日 Update

This article mainly explains "how to write the code of LAN remote boot software". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to write LAN remote boot software production code"!

The code is as follows:

/ *

> File Name: wake_up.c

> Author: wz

> Created Time: Fri 15 Nov 2013 03:42:47 PM CST

* * /

# include

# include

# include

# include

# include

# include

# include

Void get_mac (char * argv,unsigned char * save_mac)

{

Int j = 0

Int num_x = 0mm numb first = 1

While (* argv! = 0)

{

If (* argv! =':')

{

If (isdigit (* argv) & & first)

{

Num_x = (* argv -'0') * 16

First = 0

Argv++

Continue

}

If (first & & isalpha (* argv))

{

Num_x = (10 + (* argv -'a')) * 16

First = 0

Argv++

Continue

}

If (! first & & isdigit (* argv))

{

Num_x = num_x+ (* argv -'0')

First = 1

Argv++

Continue

}

If (! first & & isalpha (* argv))

{

Num_x = num_x + (10 + (* argv -'a'))

First = 1

Argv++

Continue

}

}

Else

{

Save_ Mac [j] = num_x

Num_x = 0

Argv++

Jacks +

}

}

Save_ Mac [j] = num_x

}

Int main (int argc,char * argv [])

{

Int sockfd,i,j,on = 1BI n

Unsigned char packet [120]

Unsigned char save_mac [120]

Struct sockaddr_in to

If (argc < 2)

{

Fprintf (stderr, "usage: program name + target host physical address")

Return 1

}

Get_mac (argv [1], save_mac)

/ / build magic packet

For (I = 0; I < 6; iTunes +)

{

Packet [I] = 0xff

}

For (I = 1; I < 17; iTunes +)

{

Memcpy (packet+i*6,save_mac,6)

}

Sockfd = socket (AF_INET,SOCK_DGRAM,0)

Setsockopt (sockfd,SOL_SOCKET,SO_BROADCAST,&on,sizeof (on))

If (socket < 0)

{

Fprintf (stderr, "socket creation error\ n")

Return 1

}

Memset ((void *) & to,0,sizeof (to))

To.sin_family = AF_INET

To.sin_port = htons (30000)

To.sin_addr.s_addr = inet_addr ("125.217.40.255")

N = sendto (sockfd,packet,sizeof (packet), 0, (struct sockaddr *) & to,sizeof (to))

If (n)

Tags: Code local area local area network software production content learning practicality deeper success host interest address socket practicality practicality simple operation data method more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS NVidia Apple Huawei