12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

168 POP3 PROXY SERVER CLASS DEFINITION ANNOYANCE-FILTER §201<br />

201. We need to obtain the IP address of the server host we’re supposed to be connecting to. This<br />

can be specified by the user either in “dotted quad” notation, for example, “192.168.82.13” or as a<br />

fully qualified domain name such as “pop3.fourmilab.ch”. If the former case, we convert the address<br />

to binary with inet addr , in the latter, we invoke the resolver with gethostbyname to obtain the IP<br />

address. We do not handle IPv6 addresses at the present time.<br />

〈 Look up address of server 201 〉 ≡<br />

if (isdigit (serverName [0]) ∧ (serverIP = inet addr (serverName .c str ( ))) ≠<br />

static cast〈u int32 t 〉(−1)) {<br />

cstat = 0;<br />

}<br />

else {<br />

h = gethostbyname (serverName .c str ( ));<br />

if (h ≠ Λ) {<br />

memcpy (&serverIP , h ⃗ h addr , sizeof serverIP );<br />

cstat = 0;<br />

}<br />

else {<br />

cerr ≪ "POP3Proxy:␣POP3␣server␣" ≪ serverName .c str ( ) ≪ "␣unknown." ≪ endl ;<br />

close (clientSocket );<br />

return false ;<br />

}<br />

}<br />

This code is used in section 200.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!