Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F16652233
main.c
ae (Andrey V. Elsukov)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
ae
Feb 9 2021, 2:23 PM
2021-02-09 14:23:28 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
main.c
View Options
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2021 Yandex LLC
* Copyright (c) 2021 Andrey V. Elsukov <ae@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include
<sys/cdefs.h>
__FBSDID
(
"$FreeBSD$"
);
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<err.h>
#include
<fcntl.h>
#include
<sysexits.h>
#include
<unistd.h>
#include
<string.h>
#include
<stdio.h>
#include
<netinet/in.h>
#include
<net/if.h>
#include
<arpa/inet.h>
#include
<ifaddrs.h>
const
unsigned
short
port
=
54321
;
const
char
*
maddr
=
"ff02::210"
;
const
char
*
ifname
=
"vlan500"
;
static
int
setup_socket
(
void
)
{
struct
sockaddr_in6
sin6
;
struct
ipv6_mreq
mreq6
;
int
ifx
,
s
;
ifx
=
if_nametoindex
(
ifname
);
if
(
ifx
==
0
)
errx
(
EX_USAGE
,
"Interface %s is not found"
,
ifname
);
s
=
socket
(
AF_INET6
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
s
==
-1
)
err
(
EX_OSERR
,
"socket()"
);
memset
(
&
sin6
,
0
,
sizeof
(
sin6
));
sin6
.
sin6_family
=
AF_INET6
;
sin6
.
sin6_len
=
sizeof
(
sin6
);
sin6
.
sin6_port
=
htons
(
port
);
if
(
bind
(
s
,
(
struct
sockaddr
*
)
&
sin6
,
sizeof
(
sin6
))
==
-1
)
err
(
EX_OSERR
,
"bind()"
);
memset
(
&
mreq6
,
0
,
sizeof
(
mreq6
));
mreq6
.
ipv6mr_interface
=
ifx
;
inet_pton
(
AF_INET6
,
maddr
,
&
mreq6
.
ipv6mr_multiaddr
);
if
(
setsockopt
(
s
,
IPPROTO_IPV6
,
IPV6_JOIN_GROUP
,
&
mreq6
,
sizeof
(
mreq6
))
==
-1
)
err
(
EX_OSERR
,
"setsockopt(IPV6_JOIN_GROUP)"
);
if
(
fcntl
(
s
,
F_SETFL
,
O_NONBLOCK
)
<
0
)
err
(
EX_OSERR
,
"fcntl(O_NONBLOCK)"
);
return
(
s
);
}
int
main
(
int
argc
__unused
,
char
**
argv
__unused
)
{
char
buf
[
2048
];
int
n
,
s
,
ret
,
b
;
b
=
n
=
0
;
s
=
setup_socket
();
while
(
42
)
{
ret
=
recv
(
s
,
buf
,
sizeof
(
buf
),
0
);
if
(
ret
>
0
)
n
++
;
else
b
++
;
if
(
n
%
1234
==
0
||
b
>
20
)
{
close
(
s
);
s
=
setup_socket
();
b
=
0
;
}
if
(
n
%
10000
==
0
)
{
n
++
;
fprintf
(
stdout
,
"."
);
fflush
(
stdout
);
}
}
return
(
0
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3456849
Default Alt Text
main.c (2 KB)
Attached To
Mode
D28232: Fix possible panic in udp6_input() due to lack of locking.
Attached
Detach File
Event Timeline
Log In to Comment