How to limit all tcp traffic to the network interface the session was initiated on?

view story

http://unix.stackexchange.com – I have an embedded linux system with two network interfaces (lan0, wlan0) that are configured to the same subnet. A server on this system accepts tcp connections on both interfaces. How I can assure that that all responses for a session are send on the same interface that the request was received on? I.e. how can all traffic of a tcp session be limited to a specific network interface? The listen() socket and the accepted sockets can be bound to an interface/device with setsockopt(fd, BIND_TO_DEVICE). The server does this for both interfaces. This helps to detect on which interface the sessio (HowTos)