c - How to not receive UDP datagrams for the wrong subnet but still broadcasts? -


i have interface eth0 set 168.152.32.222 netmask 255.255.255.0.

my server application wants receive udp datagrams following destination addresses on eth0:

  1. 168.152.32.222
  2. 168.152.32.255
  3. 255.255.255.255

this seems rather reasonable request, yet can't socket bound properly.

  • if bind 168.152.32.222, don't receive broadcasts.
  • if bind inaddr_any, datagrams interfaces.
  • if bind inaddr_any , so_bindtodevice, packets arrive on eth0 different subnets, 168.152.47.x.

in theory, accept datagrams , filter wrong packets out on own netmask again - seriously, lower layer should this, that's somehow point of netmask.

how not receive udp datagrams wrong subnet still broadcasts?

a solution outside server application acceptable, too. i'm considering filtering packets iptables, not sure if feasible though , last resort.

on application server , if don't care other udp packets, can set iptables rules :

iptables -f # flush filter rules iptables -a input -p udp -s 168.152.32.0/24 -d 162.152.32.222/32 -j accept # accept udp packets 168.152.32.0/24 network 162.152.32.222 host iptables -a input -p udp -s 168.152.32.0/24 -d 255.255.255.255/32 -j accept # accept udp packets 168.152.32.0/24 network 255.255.255.255/32 broadcast address  iptables -a input -p udp -s 168.152.32.0/24 -d 168.152.32.255/32 -j accept # accept udp packets 168.152.32.0/24 network 168.152.32.255/32 broadcast address iptables -a input -p udp -j drop # drop other incoming udp packets 

or should consider accept broadcasted packets , filter manualy src addresses of network in code. size of network small, may filtering ip_add_source_membership setsockopt option enough you.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -