In this tutorial about socket programming in C, I stumbled over the following line:
bzero((char *) &serv;_addr, sizeof(serv_addr));
For some reason, the variable serv_addr is written as serv;_addr when it is passed as reference. It looks like a typo (and also does not seem to compile with standard flags), however this usage is consistent throughout the whole code - whenever a variable name that contains an underscore is passed as reference, a semicolon is inserted before the underscore:
if (bind(sockfd, (struct sockaddr *) &serv;_addr,
sizeof(serv_addr)) < 0)
error("ERROR on binding");
[...]
newsockfd = accept(sockfd,
(struct sockaddr *) &cli;_addr, &clilen;);
[... and some more occurences]
This consistent usage of (to my knowledge, and gcc seems to agree) invalid syntax kept me wondering if there is some explanation for this phenomenon.
Has anyone seen code like this before? Any ideas how such code could accidentally be generated?
This doesn't appear to have anything to do with underscores (_); instead, it looks like a failed attempt at normalising ampersands (&). The ampersand-construct is used in HTML to represent special characters using (among other forms) &name;. E.g. < for <, " for " and & for & itself.
It appears that every sequence of ampersand-followed-by-letters in the original source-code has been replaced by ampersand-followed-by-letters-and-a-semicolon in the HTML (presumably in the mistaken belief that these were "unterminated" ampersand-constructs). Another example from the source-code demonstrates this:
(struct sockaddr *) &cli;_addr, &clilen;);
here both &cli_addr and &clilen have added semicolons, even though the latter does not include an underscore.
At the same time, or in a subsequent "clean-up", the ampersands themselves have been converted to &, as can be seen in the HTML source of the line shown above:
(sockfd, (struct sockaddr *) &cli;_addr, &clilen;);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With