I second
janoszen's suggestion. Also, have you looked for already existing applications that do this sort of thing? Depending on your project constraints, using such a solution might be a better option than reinventing the wheel.
An example of using iptables to do the redirection
janoszen mentioned is:
Code:
iptables -t nat -A PREROUTING -p TCP -i $LAN_IFACE --dport 80 -j REDIRECT
Here, HTTP requests would get redirected to the HTTP daemon on the firewall itself. You'd need to handle filtering in the FORWARD chain too, though. The way to do that would depend on what the overall approach would be. For example, you might choose to have a FORWARD/ACCEPT rule be implemented with the client's MAC/IP addresses when they log in, and have the rule removed when they log out (or time out). In other words, the kinda stuff which hotspot software does for you.