12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

§199 ANNOYANCE-FILTER POP3 PROXY SERVER CLASS DEFINITION 167<br />

199. First of all, we have to camp on the listenSocket with accept until somebody connects to it. At<br />

that point we obtain the clientSocket we’ll use to conduct the dialogue with the client.<br />

〈 Wait for next client connection and accept it 199 〉 ≡<br />

errno = 0;<br />

do {<br />

fromlen = sizeof from ;<br />

clientSocket = accept (listenSocket , (struct sockaddr ∗) &from , &fromlen );<br />

if (clientSocket ≥ 0) {<br />

break;<br />

}<br />

} while (errno ≡ EINTR);<br />

if (clientSocket < 0) {<br />

perror ("POP3Proxy␣accepting␣connection␣from␣client");<br />

return false ;<br />

}<br />

if (verbose ) {<br />

cout ≪ "Accepting␣POP3␣connection␣from␣" ≪ inet ntoa (from .sin addr ) ≪ endl ;<br />

}<br />

This code is used in section 198.<br />

200. Once a connection has been accepted, we use the clientSocket to conduct the dialogue until it’s<br />

concluded.<br />

〈 Conduct dialogue with client 200 〉 ≡<br />

int clientLength , serverLength ;<br />

char clientBuffer [POP_BUFFER], serverBuffer [POP_BUFFER];<br />

int serverSocket ;<br />

u int32 t serverIP ;<br />

struct hostent ∗h;<br />

int cstat = −1;<br />

bool ok = true ;<br />

string command , argument , reply ;<br />

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

〈 Open connection to server 202 〉;<br />

〈 Read the greeting from the server and relay to the client 203 〉;<br />

〈 Conduct client/server dialogue 204 〉;<br />

〈 Close the connection to the client and server 214 〉;<br />

This code is used in section 198.

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

Saved successfully!

Ooh no, something went wrong!