WakeOnLan function of the NIC.

WakeOnLan function of the NIC.

Postby yunbg1 » Wed Apr 08, 2009 11:37 am

WakeOnLan function of the NIC.

source.....

Code: Select all  Expand view

//------------------------------------------------
FUNC Mac_On(pc_noo)
loca emac, fg, ed

emac := ""
for fg := 1 to len(aSocket[pc_noo, 5])
     ed := subs(aSocket[pc_noo, 5], fg, 1)
     if ed != "-"
        emac += ed
     endi
next
if len(emac) != 0
   wol_start(emac)  
endi
RETU NIL

//------------------------------------------------------------------------------
#pragma BEGINDUMP

#include <windows.h>
#include <vfw.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <wininet.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>

int hex(char c) {
    if ('0' <= c && c <= '9') return c - '0';
    if ('a' <= c && c <= 'f') return c - 'a' + 10;
    if ('A' <= c && c <= 'F') return c - 'A' + 10;
    return -1;
}

int hex2(char *p) {
    int i;
    unsigned char c;
    i = hex(*p++);
    if (i < 0) return i;
    c = (i << 4);
    i = hex(*p);
    if (i < 0) return i;
    return c | i;
}

HB_FUNC( WOL_START )
{
    int sd;
    int len;
    int i, j;

    BOOL optval;

    struct sockaddr_in sin;

    char unsigned buf[BUFMAX];
    unsigned char mac[MACLEN];
    unsigned char *p;

    char temp_buff[1024] = {0};

    WSADATA wsaData;

    WSAStartup( MAKEWORD(2, 2), &wsaData);
    memset((char *)&sin, '0x00', sizeof(sin));

    sin.sin_family = AF_INET;
    sin.sin_port = htons(9);
    sin.sin_addr.s_addr = INADDR_BROADCAST;

    sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    optval = TRUE;
    setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (const char *)&optval, sizeof(BOOL) );

    sprintf(temp_buff, hb_parc(1));

    p = (unsigned char *)temp_buff;
    j = hex2((char *)p);

    mac[0] = j;
    p += 2;
    for (i=1; i < MACLEN; i++) {
        j = hex2((char *)p);
        mac[i] = j;
        p += 2;
    }
    p = buf;
    for (i=0; i < 6; i++) {
        *p++ = 0xFF;
    }
    for (i=0; i < 16; i++) {
        for (j=0; j < MACLEN; j++) {
            *p++ = mac[j];
        }
    }
    len = p - buf;

    sendto(sd, (const char *)buf, len, 0, (struct sockaddr*)&sin, sizeof(sin));

    closesocket(sd);
    WSACleanup();

    hb_retni(0);
}
#pragma ENDDUMP

 
FWH User
FWPPC User
FWLinux User
yunbg1
 
Posts: 107
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests