NP hope it works for you and it should apply to any site you can put on it's own subdomain. I'm really not very familiar with magneto, but the only thing I can think of you might have to do, depending on exactly how magneto works wrt linking is perform a string-replace to get the subdomain out of the links/canonical.
So, for code-set2.example.com: echo str_replace('code-set2.example.com','www.example.com',file_get_contents('http://code-set2.example.com'.$_SERVER['REQUEST_URI']));
Would change a link like this: http://code-set2.example.com/some-page.ext
Obviously for code-set1.example.com you just change code-set2.example.com to code-set1.example.com in the replace.