Pelles C forum Pelles C forum
News: Version 6.00 released!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 06, 2010, 09:03:09 PM


Login with username, password and session length


Pages: [1] 2 3 ... 10
 1 
 on: Today at 03:14:32 PM 
Started by CommonTater - Last post by CommonTater
In Win7 Microsoft has changed the wake from sleep protocals for their LAN networking.  Simply pinging a machine will no longer wake it.  You must either connect to it with TCP or send it a Magic Packet before using UDP... In fact the only guaranteed wakeup is the magic packet.

The details are here... http://technet.microsoft.com/en-us/library/ee617165(WS.10).aspx

Ok so ... what the @#$@# is a Magic Packet?

Basically it's a 128 byte packet where the first 6 bytes are set to 0xFF, followed by at least 16 repetitions of the target machine's MAC address (the physical network ID of the NIC chip).  To get the MAC address you use the Windows SendARP function.  

Below is an example of how to get the MAC address and send a Magic Packet from an open UDP port using Winsock2.... Basically you hand it a SOCKADDR structure with the target IP address, the number of retires for the ARP request and the delay between retries (in seconds).


Code:
/////////////////////////////////////////////////////////////////////////////////////////
// Send Magic Packet
//

// build and send magic packet
BOOL WakeHost(PSOCKADDR Host, BYTE Tries, BYTE Delay)
  { SOCKADDR  ha;                 // host ip and port
    BYTE      mac[6];             // host mac address
    ULONG     smac = 6;           // size of mac address
    BYTE      magic[128] = {0};   // magic packet  
    FD_SET    st;                 // socket to be tested
    TIMEVAL   tv;                 // delay time for test
    BYTE      rt = 0;              // retry counter
    // make a copy of the sockaddr
    memcpy(&ha,Host,sizeof(SOCKADDR));
    // switch port
    ((PSOCKADDR_IN) &ha)->sin_port = htons(9);
    // get mac address
    while (SendARP(((PSOCKADDR_IN)&ha)->sin_addr.S_un.S_addr,0,(PULONG)&mac,&smac))
      { if (++ rt > Tries)
          return 0;
        Sleep(Delay * 1000); }
    // build magic packet
    memset(&magic,255,6);
    for ( int x = 6; x < 102 ; x++)
      magic[x] = mac[x % 6];
    // wait then send
    st.fd_count    = 1;
    st.fd_array[0] = hSocket;
    tv.tv_sec      = 5;
    tv.tv_usec     = 0;
    if (select(1,NULL,&st,NULL,&tv) > 0)
      sendto(hSocket,(PCHAR)&magic,128,0,&ha,sizeof(SOCKADDR));
    return 1; }












 2 
 on: Yesterday at 05:58:00 PM 
Started by whatsup - Last post by CommonTater
It's simply a problem of LV_ITEM structure initialization.
Code:
void MakeListView (HWND hWnd)
{
  LV_COLUMN  lvCol;
  LV_ITEM  lvItem;
  memset(&lvItem,0,sizeof(LV_ITEM)); //Set unused members to zero

Pelles C will also "auto initialize" the struct for you...

LV_ITEM lvitem = {0};

Will cause the compiler to generate the initialization code for you.


 3 
 on: Yesterday at 05:18:49 AM 
Started by CLR - Last post by CLR
Hi. I wrote an article for beginners. It's in portuguese.

Corrections & translations welcome.  Wink

link
http://wiki.pellesc.de/doku.php?id=pt:error_messages

 4 
 on: Yesterday at 02:04:16 AM 
Started by whatsup - Last post by whatsup
thank you so much sir.
i'm shame it was my fault Sad

 5 
 on: September 04, 2010, 03:40:44 PM 
Started by Juni - Last post by Juni
Thank you very much both  Smiley

The sample really helps a lot thank you  Smiley Smiley


 6 
 on: September 04, 2010, 01:22:21 PM 
Started by Alessio - Last post by CommonTater
Good point...


 7 
 on: September 04, 2010, 12:47:39 PM 
Started by alexei - Last post by JohnF
Other compilers are OK with this (see code below). Is it because of ANSI?
Is there a way to do such things without re-declaring variables?
I mean typecasting any variable to any type.

Test.c(5): error #2088: Lvalue required.
Test.c(6): error #2088: Lvalue required.

The answer is no. You can sometimes cast the right side so that it matches the left side but you can never cast the left side or change a variable into a different type.

Code:
float f = 1.0;
 int i;
 i = (int)f;

John

 8 
 on: September 04, 2010, 11:29:49 AM 
Started by alexei - Last post by alexei
Other compilers are OK with this (see code below). Is it because of ANSI?
Is there a way to do such things without re-declaring variables?
I mean typecasting any variable to any type.

Code:
int main (int argc, char *argv[])
{
  unsigned z;
  void* p;
  (int)z = (int)z-5;
  (int)p = (int)p+2;
  return 0;
}
Test.c(5): error #2088: Lvalue required.
Test.c(6): error #2088: Lvalue required.

 9 
 on: September 04, 2010, 10:10:32 AM 
Started by Juni - Last post by JohnF
Juni,

The attached project shows how to subclass.

EDIT: Changed it so that the picture box will be redrawn if covered and uncovered by another window.

John

 10 
 on: September 04, 2010, 08:51:08 AM 
Started by Alessio - Last post by Stefan Pendl
Once you have it in your global settings, you can update it into a project's settings by clicking the "default" button on the folders tab.

This would remove any additional path added just for the project, I think.

It would be nice to have things merged, since removing unwanted paths is easier, than adding the lost ones.

Pages: [1] 2 3 ... 10
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.123 seconds with 16 queries.