Close

A poll() problem...

A project log for micro HTTP server in C

Connect your browser to your smart devices, using a minimalist HTTP compliant server written in POSIX/C

Yann Guidon / YGDESYann Guidon / YGDES 01/06/2021 at 18:580 Comments

I got something unexpected while looking for easy/simple/light ways to probe if the server is up with a bash script.

> ./serv_simple
  === And now, browse to 127.0.0.1:60075 ===
Port: 60075, Keepalive: 10s
Path: files  Root page: index.html

Warning: chroot() failure (are you root ?) : No such file or directory

Server socket ready
H_BLOCKED

On the script side:

root@pi:/home/pi# echo "GET /" | telnet 127.0.0.1 60075
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

and then:

* Connected to 127.0.0.1:39298
HTTaP-Session: 2l1cvf10
H_BLOCKING
0
received 7
---------------------------
GET /

*
got root
trying to read file: index.html
Extra Header: 25 bytes
Content-Type: text/html
sending 95 bytes header + 12387 bytes payload : 12482
1

poll() problem on client socket: No such file or directory

Meanwhile I get a kernel message :

[ 2038.025046] TCP: request_sock_TCP: Possible SYN flooding on port 60075. Sending cookies.  Check SNMP counters.

OTOH when I change the URL to an invalid one, the server closes the connection itsef and it works.

root@pi:/home/pi# echo "GET /plop" | telnet 127.0.0.1 60075
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

I can thus check the server with this command:

( wget 127.0.0.1:60075/plop -O - 2>&1 | grep 404 ) && echo OK

Or better :

wget -q '127.0.0.1:60075/?' -O - | grep HTTaP

However the poll() failure behaviour is inappropriate and it is now fixed withHTTaP_src.20210106.tgz

Discussions