Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F4517626
tap-test.c
tuexen (Michael Tuexen)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
tuexen
Apr 28 2019, 9:17 PM
2019-04-28 21:17:07 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
tap-test.c
View Options
#include
<fcntl.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
int
main
(
void
)
{
#if 1
ssize_t
n
;
#endif
int
fd
;
char
sbuf
[]
=
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xbb
,
0x08
,
0x00
,
0x45
,
0x00
,
0x00
,
0x20
,
0x00
,
0x00
,
0x00
,
0x00
,
0xff
,
0x11
,
0x62
,
0x3f
,
0xac
,
0x14
,
0x00
,
0xbb
,
0xac
,
0x14
,
0x00
,
0xaa
,
0x00
,
0xbb
,
0x00
,
0xaa
,
0x00
,
0x0c
,
0x00
,
0x00
,
0x01
,
0x02
,
0x03
,
0x04
};
char
rbuf
[
1024
];
if
((
fd
=
open
(
"/dev/tap0"
,
O_RDWR
|
O_NONBLOCK
))
<
0
)
{
perror
(
"open"
);
}
system
(
"ifconfig tap0 ether aa:aa:aa:aa:aa:aa"
);
system
(
"ifconfig tap0 inet 172.20.0.170 netmask 255.255.255.0"
);
system
(
"ifconfig tap0 inet6 fe80::aa"
);
system
(
"arp -s 172.20.0.187 aa:aa:aa:aa:aa:bb"
);
#if 1
while
((
n
=
read
(
fd
,
rbuf
,
sizeof
(
rbuf
)))
>=
0
)
{
printf
(
"Received packet of length %zd
\n
"
,
n
);
sleep
(
1
);
}
#endif
sleep
(
1
);
if
(
write
(
fd
,
sbuf
,
sizeof
(
sbuf
))
<
0
)
{
perror
(
"write"
);
}
#if 1
while
((
n
=
read
(
fd
,
rbuf
,
sizeof
(
rbuf
)))
>=
0
)
{
printf
(
"Received packet of length %zd
\n
"
,
n
);
sleep
(
1
);
}
#endif
sleep
(
1
);
if
(
close
(
fd
)
<
0
)
{
perror
(
"close"
);
}
return
(
0
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1864969
Default Alt Text
tap-test.c (1 KB)
Attached To
Mode
D20044: tun/tap: merge
Attached
Detach File
Event Timeline
Log In to Comment