Sunday, October 8, 2006, 12:46 AM - Networking
Sorry everyone, spammers got to my blog and so I've had to temporarily disable comments. Maybe I can set up a captcha or something, then I'll be able to re-enable it.[ add comment ] | permalink |




( 2.7 / 120 )Sunday, March 19, 2006, 12:00 AM - Networking
Problem:
Actiontec GT701-WG DSL Modem has a dumb DNS issue. When you try to connect to a website from a computer running Linux, you may see "Trying 1.0.0.0" in the status bar and a failure to resolve the hostname.
Cause:
The router, which runs busybox Linux, has a DNS server program called dproxy that has a bug that exhibits itself when you try to resolve hosts from a Linux machine with IPv6 turned on. Unfortunately, you cannot disable the dproxy program and the router always sends its own IP address as the nameserver to a client that obtains an IP address via DHCP.
Fix:
Well, you could hard-code the nameservers on your computer or router that connects to the DSL modem. But here is a solution that I came up with two years ago for hard-coding the nameservers into the DSL modem itself. (Unfortunately, you have to employ this technique each time your Actiontec loses power.)
The solution is also presented below in case the link ever breaks:
!!! Actiontec GT701-WG DNS problem temporary solution: !!!
Normally I don't answer my own post, but I've found a "temporary"
solution here. This solution will __bypass the dproxy__ completely. The
only drawback I can see to this method is that you lose the ability to
access your modem at http://dslmodem.home/. Well, I'm not going to lose
sleep over _that_! I guess you also lose the DNS caching on the modem,
but hey, no big deal.
1. Telnet into your modem (username admin, password admin).
2. Change the dns line in your /etc/udhcpd.conf from this:
opt dns 192.168.0.1 206.81.128.1
to something like this:
opt dns 206.81.128.1 205.171.3.65
(where the two IP addresses are the IP addresses of the DNS servers
found in the /etc/resolv.conf).
3. Do _NOT_ kill udhcpd
- If you do it will restart and overwrite udhcpd.conf, losing your
changes.
4. Do a DHCP release, renew on the router/computer connected to your
modem.
Note: You won't find vi or emacs on your busybox, so you might have to
use cat (cat > udhcpd.conf) like I did, and recreate the file line by
line (about 10 lines long).
So, as you can see, we took out 192.168.0.1 from the dns that is sent to
a DHCP request, so whatever connects to your modem will no longer use
the modem as a dns proxy/gateway. Say goodbye to "Trying 1.0.0.0..."
Note:
I can't believe it has been over two years and this problem still hasn't been fixed! Shame on you Actiontec (and QWest). If anyone knows of a firmware update that fixes this problem, please let me know.
[ 10 comments ] ( 7065 views ) | permalink |




( 3 / 213 )Tuesday, March 14, 2006, 12:00 AM
(Why you should never initialize a static const int inside the class declaration)
I recently ran into a weird bug that really confused me. The code was working in VS.Net but not in g++.
These three lines illustrate the problem:
void doit(const int &) {}
struct Foo { static const int VALUE = 100; };
int main() { doit(Foo::VALUE); return 0; }
In g++ 3.4.x, you get a linker error "undefined reference to Foo::VALUE".
If you are like me, you probably try to avoid the "enum hack", especially since recent compilers now follow the C++ standard and allow you to initialize static const members of integral type inside the class itself.
However, you should know that the code above is a declaration and an initialization, NOT a definition. You must also have a definition in a .cpp file somewhere, like this:
const int Foo::VALUE;
But why do I need to define it? Can't the compiler just figure it out?
Actually, with VS.Net you must not define it. It defines it for you automatically (it's a language extension; turn off with /Za).
But why would I need to define it anyways? Constant values don't need storage space.
If compilers were magical that would be true. Although compilers should see the value as a compile-time constant and always inline it when they can, they are not required to inline; they may insist that you have an actual object defined.
That is why g++ gives you an "undefined reference" error. It was not able to inline the constant, so it needs an actual object. There are at least three scenarios where g++ does not inline a static const int:
- If you try to take the address of it (this one is obvious).
- You pass it to a function that takes a reference.
- When used with the tertiary operator ? :
But the solution for VS.Net is to NEVER define the static member in a .cpp.
CONFLICTING SOLUTIONS, WHAT DO I DO??!!
Well, I thought about disabling language extensions, especially since I am very angry with MS for being EVIL and trying to corrupt standards. But I've come up with a simpler solution:
Define and initialize in the .cpp file. It always works.
And if I need to use the value sooner, resort to the "enum hack".
Note: The standards committee is working on a fix for this issue.
[ add comment ] | permalink |




( 2.7 / 190 )Thursday, February 23, 2006, 12:00 AM - Programming
Theorem
Given: Integers a, b, c, such that:
- a >= 0
- b > 0
- c > 0
Given: % represents modulo operator
Theorem: (a % b) × c == (a×c) % (b×c)
Proof Part A:
First I will define a new formula for modulo that uses subtraction, multiplication, and the floor() function.
Given: floor(x/y) represents the integer part of the division of x and y.
| 1. | (x % y) | Given: x Modulo y |
| 2. | [x/y - floor(x/y)] × y | Divide x and y, subtract the integer part, then multiply by the divisor to get the remainder |
| 3. | x - y × floor(x/y) | Distribute multiplication over subtraction |
I didn't really prove how to go from step 1 to step 2, but it is pretty easy to reason about.
In any case, here is another page that comes up with the same formula.
Proof Part B:
Here comes the fun proof. I will prove the theorem by simplifying the equation one step at a time.
| 1. | (a % b) × c | =?= | (a×c) % (b×c) | Given: The theorem we are trying to prove |
| 2. | (a % b) × c | =?= | ca % cb | Simplify right side and reverse order of multiplication |
| 3. | [a - b × floor(a/b)] × c | =?= | ca - cb × floor[(ca)/(cb)] | Replace modulo operator with formula in step 3 of Proof Part A |
| 4. | ca - cb × floor(a/b) | =?= | ca - cb × floor[(ca)/(cb)] | Distribute multiplication over subtraction |
| 5. | -cb × floor(a/b) | =?= | -cb × floor[(ca)/(cb)] | Subtract c×a from both sides |
| 6. | floor(a/b) | =?= | floor[(ca)/(cb)] | Divide both sides with -c×b |
| 7. | floor(a/b) | == | floor(a/b) | The c's divide out. |
[ add comment ] ( 547 views ) | permalink |




( 2.8 / 179 )Friday, October 28, 2005, 12:00 AM - Programming
Problem 1:
Visual C++ .Net 2003 Standard Edition comes with a non-optimizing compiler!
How annoying!!!
Fix to Problem 1:
See this page for instructions on how to get an optimized compiler, and integrate it with the IDE. Microsoft makes the optimizing compiler available to download for free. Now, why would they let you download a free optimizing compiler, but when you pay $100 and actually buy the product, you get a non-optimizing compiler? In the words of a friend of mine, "That's some shrewd marketing. Or something."
Problem 2:
So, everything is hunky-dory now, right? Not exactly, the optimizing options are still grayed out in the GUI, just as the xona.com article mentions. Well, that's not too annoying, since you can just specify /O2 or whatever in the "Additional Options" section.
However, it actually was still very annoying for me because I use cmake (Cross Platform Make) for small projects and it conveniently changes a /O2 into an 'Optimization="2"' in your project file (which is the correct thing to do, if you have a normal IDE that doesn't gray out optimization options and then filter them out before launching cl.exe). Try as I might, I could not get cmake to just put the "/O2" in the additional options. I could put it in there myself manually, but the next time I reload the project, cmake conveniently rebuilds my project file.
I'm not angry with cmake. It's doing exactly the right thing. It's MS fault for giving me a crippled compiler! If they are giving out a free optimizing compiler, why not actually let me use it from the IDE that I paid for!
Fix to Problem 2:
Well, I wouldn't be writing this nice blog if I didn't have a solution, now would I?
There is a function in VCProjectEngine.dll that filters the command-line. Just replace 0x74 with an 0xEB at offset 0x63D7 in the DLL and you're set! (This only applies to VCProjectEngine.dll version 7.10.3077.0. With version 7.10.3274.0 the offset you want is 0x6AB3.)
Best of luck.
[ 1 comment ] ( 2571 views ) | permalink |




( 2.9 / 145 )Back Next





