Why do people always implement stuff like this in CGI (C or C++)?
Using nginx+php/perl/python would work just the same and prevent a whole slew of vulnerabilities in embedded devices, while at the same time reducing maintenance and development costs.