- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
- close(fd);
- return -1;
- }
- if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &n, sizeof(n)) == -1) {
- close(fd);
- return -1;
- }
-
- strncpy(interface.ifr_ifrn.ifrn_name, inf, IFNAMSIZ);
- if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,(char *)&interface, sizeof(interface)) < 0) {
- close(fd);
- return -1;
- }
-
- if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) {
- close(fd);
- return -1;
- }
-