Skip to content

Commit 768a7e3

Browse files
committed
Fix linux send packet, only now I got a system I can test it, which is kinda
embarassing. We should use a bind, not SO_BINDTODEVICE.
1 parent 722162d commit 768a7e3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/rawlink_stubs.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,26 @@ af_packet_open(void)
224224
int
225225
af_packet_setif(int fd, char *ifname)
226226
{
227-
int r;
227+
int r, ifidx;
228+
struct sockaddr_ll sll;
229+
230+
ifidx = if_nametoindex(ifname);
231+
if (ifidx == 0) {
232+
uerror("af_packet_setif: if_nametoindex", Nothing);
233+
return (-1);
234+
}
235+
236+
bzero(&sll, sizeof(sll));
237+
sll.sll_family = AF_PACKET;
238+
sll.sll_ifindex = ifidx;
239+
sll.sll_protocol = htons(ETH_P_ALL);
228240

229241
enter_blocking_section();
230-
r = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname,
231-
strlen(ifname));
242+
r = bind(fd, (struct sockaddr *) &sll, sizeof(sll));
232243
leave_blocking_section();
233244

234245
if (r == -1)
235-
uerror("af_packet_setif", Nothing);
246+
uerror("af_packet_setif: bind", Nothing);
236247

237248
return (r);
238249
}

0 commit comments

Comments
 (0)