Enable WOL through a Linksys Router

This is blatent copy-paste job from: http://rotwhiler.wordpress.com/2009/03/24/enable-wake-on-lan-through-linksys-wrt54g/ put here for my own posterity.

This all works very well if the computer sending the Magic Packet is on the same LAN as the sleeping computer, but requires some additional effort to get working over the Internet. Especially if the very common Linksys WRT54G is your wireless router. The WRT54G setup page employs javascript to prevent the user from entering a broadcast address, so there is a work around. Here’s what to do to set this up:

  • Enable WOL on your computer. This is usually a setting in the BIOS. (This may not be possible if you are using a wireless card. Only the very latest cards support Wireless Wake On Lan.)
  • If you don’t already have Firefox, download and install it.
  • Download and install the DOM Inspector Firefox Add-on.
  • Using Firefox, open your Linksys WRT54G admin page (usually 192.168.1.1)
  • Click on Applications & Gaming
  • Add a new entry: Application=”WOL”, Start=”9?, End=”9?, Protocol=”UDP”, IP Address=”200?
  • In Firefox, click on Tools, then DOM Inspector.
  • Use DOM inspector to find the “WOL” entry and change IP Address from 200 to 255. (Firefox will red highlight the areas you have selected in DOM Inspector, this makes it easier to narrow down to the correct element.)
  • Click “Save Changes” on the Applications and Gaming page.
  • Download and install a Magic Packet program that can send a packet over the Internet. I like this one: http://magicpacket.free.fr/

You should now be able to wake your computer up from where ever you are. (Also, I should say that my router has firmware version 8.00.5. I don’t know if this matters, since I don’t have any other router to test it on.)

Note to self: this is probably unsafe and bad. Also, I used firebug.

No Comments

cppfontconfig – Simple C++ interface into fontconfig

Lately I’ve been trying to learn how to use (and I mean *really* use) the open source font stack. Since I tend to greatly prefer c++ over c, as part of the process of learning these libraries I figured I’d workout API wrappers. Since the font stack libraries are generally object oriented, I figured a C++ wrapper around these would be easy to accomplish.

As a start, I wrote cppfontconfig, a C++ wrapper around font config.

Documentation
git://git.cheshirekow.com/cppfontconfig.git (public git access).

I’m not sure if the design is good or if it’s even useful, I guess we’ll see.

No Comments

Exception Streams in C++

Here’s a short but handy C++ Snippet. I was looking for a way to quickly generate runtime exceptions with useful information about the current program state. My process was:

  1. Create a string stream
  2. Build the message
  3. Throw the exception using the string from the stream

I felt like this was particularly cumbersome and quite annoying, especially for doing things like string parsing or SQL because there are a lot of places in the code where error checking is required.

In any case, I came up with this simple little class tempate which sits in a single header file and is included in the cpp file where it is to be used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef _UTILITY_EXCEPTIONSTREAM_H_
#define _UTILITY_EXCEPTIONSTREAM_H_
 
#include <exception>
#include <sstream>
 
namespace utility   {
 
/// used to simplify the process of generating an exception message
/**
 *  Derives from stringstream so provides an ostream interface, but throws
 *  an exception with the contents of the string when the object is destroyed
 *
 *  \tparam Exception_t must be an exception type which accepts a
 *                      const char* in it's constructor
 *
 */
template <typename Exception_t>
class ExceptionStream :
    public std::stringstream
{
    public:
        ~ExceptionStream()
        {
            throw Exception_t( str().c_str() );
        }
 
        std::ostream& operator()()
        {
            return *this;
        }
};
 
 
typedef ExceptionStream<std::runtime_error> ex;
 
 
} /* namespace utility */
#endif /* EXCEPTIONSTREAM_H_ */

Usage is like this:

1
2
3
4
5
6
7
8
9
10
ex fExp;
 
fExp = evalf( m_expression["radius"].subs(m_x == iRadius));
if( is_a<numeric>(fExp) )
    radius= ex_to<numeric>(fExp).to_double();
else
{
    utility::ex()() << "GiNaC failed to parse radius expression: "
                    << fExp;
}

Here I’m using GiNaC to parse a string into a mathematical expression. If the process fails I want to throw a runtime exception (typedef’ed as utility::ex).

The class derives from string stream so it works just like a string stream… building a string by catting together the RHS of all the string operators. The magic is that the destructor for the class throws an exception. The message for the exception is the string that was built.

It’s a very handy time saver… though I’m not sure if it’s actually safe to use. If the destructor throws an exception, is the object memory still freed?

2 Comments