Wakeup frame

Nagilum akuehn@HTWM.De
Tue Feb 8 08:44:50 2000


Hi,
I know this is a bit off topic, but only a bit. I recently tried to wake
up my box using the program below but either this program doesn't work
or my hardware setup is wrong because it did not work.
I would like to know if the following program works with a rtl8139 chip
and if not if there are any other programs for this purpose..
regards,
Alexander.


PS: The program comes from
http://www.berens-partner.de/wann/computer/wol.html but i applied the
netbsd patches to it, now it works on linux too ;) .

<----------------------snip----------------------->
/*
   WAKE ON LAN - Remote Power On

   hpwake.c: Sendet eine Broadcast Message an alle Clients des
Subnetzes,
   die eine Abfolge von Bytes enthaelt um einen Rechner zu booten.

   Unterstuetzte OS: HP-UX 10.20 und 9.05
   Kompilieren: cc -o hpwake hpwake.c
   Aufruf: hpwake xx:xx:xx:xx:xx:xx
   xx:xx:xx:xx:xx:xx ist die MAC Adresse der Ethernetkarte in
Hexadezimalwerten,
   man erhaelt sie fuer einen entsprechenden Rechner durch Eingabe von:
   Unter HP-UX: lanscan
   Unter Windoof NT: ipconfig -all
   Unter Windoof 95: winipcfg

   email: wann@server7.ik.mb.uni-siegen.de
*/

#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

u_char magicpacket[500];

int get_magicpacket(unsigned char *,char *);
int main(int,char *[]);

int get_magicpacket(packet,arg)

unsigned char *packet;
char *arg;

{
        unsigned char ether_addr[6];
        int dstaddr[6];
        int i;
        int j;
        int k;
        char *a;

        for (a = arg; *a; a++)
                if (*a != ':' && !isxdigit(*a)) {
                        fprintf(stderr, "MAC address must be given in
hex! [00:11:22:33:44:55]\n");
                        exit(2);
                }

        k = sscanf(arg, "%2x:%2x:%2x:%2x:%2x:%2x",
                &dstaddr[0], &dstaddr[1], &dstaddr[2], &dstaddr[3],
&dstaddr[4], &dstaddr[5]);

        if (k != 6) {
                fprintf(stderr, "Invalid MAC address!
[00:11:22:33:44:55]\n");
                exit(2);
        }

        for (i = 0; i < 6; i++)
                ether_addr[i] = dstaddr[i];

        memcpy(packet, ether_addr, 6);
        packet[6] = 0x00;
        packet[7] = 0x74;
        j = 8;

        memset(packet+j, 0xff, 6);
        j += 6;

        for (i = 0; i < 16; i++) {
                memcpy(packet+j, ether_addr, 6);
                j += 6;
        }

        packet[111] = 0x40;
        packet[112] = 0x00;
        packet[113] = 0x90;
        packet[114] = 0x90;
        packet[115] = 0x40;
        packet[116] = 0x00;

        j += 6;

        return j;
}




int main(argc,argv)

int argc;
char *argv[];

{

        struct sockaddr_in client, server;
        int one = 1;
        int packetsize;
        int s;
        int i;

 if (argc < 2) {
  fprintf(stderr, "Usage: %s xx:xx:xx:xx:xx:xx\n", argv[0]);
  exit(1);
 }

        packetsize = get_magicpacket(magicpacket, argv[1]);

        if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
                perror("socket");

        if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&one,
sizeof(one)) < 0)
                perror("setsockopt");

        server.sin_family = AF_INET;
        server.sin_port = 0;
        server.sin_addr.s_addr = INADDR_ANY;

        client.sin_family = AF_INET;
        client.sin_port = 32768+666;  /* invalid port */
        client.sin_addr.s_addr = INADDR_BROADCAST;

        if (bind(s, (struct sockaddr *)&server, sizeof(server)) < 0)
                perror("bind");

        if ((i = sendto(s, magicpacket, packetsize, 0, (struct sockaddr
*)&client, sizeof(client))) < 0)
                perror("sendto");

        close(s);

        return 0;

}


<----------------------snip----------------------->

--
========================================================================
#    _  __          _ __http://home.htwm.de/akuehn/MPeople/MPeople.html#
#   / |/ /__ ____ _(_) /_ ____ _        dedicated to one of the best.. #
#  /    / _ `/ _ `/ / / // /  ' \ nagilum@chillout.org or +01776461165 #
# /_/|_/\_,_/\_, /_/_/\_,_/_/_/_/ Amiga OS/NetBSD(68k)/Linux(68k/PPC)  #
#           /___/            x86:   Linux / OpenBSD / FreeBSD / Win 98 #
========================================================================



 | To unsubscribe, send mail to Majordomo@cesdis.gsfc.nasa.gov, and within the
 |  body of the mail, include only the text:
 |   unsubscribe this-list-name youraddress@wherever.org
 | You will be unsubscribed as speedily as possible.