- if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, interface, strlen(interface)))
- {
- close(nfd);
- syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface, strerror(errno));
- return -1;
- }
+ {
+#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_ifrn.ifrn_name, interface, IFNAMSIZ);
+ if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)))
+ {
+ close(nfd);
+ syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface, strerror(errno));
+ return -1;
+ }
+#else
+ syslog(LOG_WARNING, _("BindToDevice not supported on this platform"));