Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
33329637
Commit
33329637
authored
May 26, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compare txtime to timestamp
parent
c7ca3220
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+13
-12
No files found.
packet-exchange/src/send_packet.c
View file @
33329637
...
...
@@ -14,6 +14,7 @@
#include <error.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <inttypes.h>
#include <linux/errqueue.h>
#include <linux/ethtool.h>
#include <linux/net_tstamp.h>
...
...
@@ -41,8 +42,8 @@
#define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000
static
void
print_timestamps
(
struct
msghdr
*
msg
);
static
void
process_timestamps
();
static
void
print_timestamps
(
struct
msghdr
*
msg
,
uint64_t
txtime
);
static
void
process_timestamps
(
uint64_t
txtime
);
static
int
so_priority
=
3
;
static
struct
sock_txtime
sk_txtime
;
...
...
@@ -160,17 +161,16 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
if
(
sendmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"sendmsg failed, ret value: %d
\n
"
,
sendmsgerr
);
if
(
use_timestamps
)
{
if
(
use_timestamps
)
{
res
=
poll
(
&
poll_fd
,
1
,
0
);
if
(
res
>
0
)
process_timestamps
();
process_timestamps
(
txtime
);
else
fprintf
(
stderr
,
"select failed
\n
"
);
}
}
static
void
process_timestamps
()
{
static
void
process_timestamps
(
uint64_t
txtime
)
{
char
data
[
256
];
struct
msghdr
msg
;
struct
iovec
entry
;
...
...
@@ -192,13 +192,12 @@ static void process_timestamps() {
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
|
MSG_DONTWAIT
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed
\n
"
);
}
else
{
print_timestamps
(
&
msg
);
}
else
{
print_timestamps
(
&
msg
,
txtime
);
}
}
static
void
print_timestamps
(
struct
msghdr
*
msg
)
{
static
void
print_timestamps
(
struct
msghdr
*
msg
,
uint64_t
txtime
)
{
struct
cmsghdr
*
cmsg
;
for
(
cmsg
=
CMSG_FIRSTHDR
(
msg
);
cmsg
;
cmsg
=
CMSG_NXTHDR
(
msg
,
cmsg
))
{
...
...
@@ -208,8 +207,11 @@ static void print_timestamps(struct msghdr *msg) {
switch
(
cmsg
->
cmsg_type
)
{
case
SO_TIMESTAMPING
:
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
uint64_t
timestamp_ns
=
stamp
->
tv_sec
*
NSEC_PER_SEC
+
stamp
->
tv_nsec
;
printf
(
"SO_TIMESTAMPING "
);
printf
(
"SW %ld.%09ld "
,
(
long
)
stamp
->
tv_sec
,
(
long
)
stamp
->
tv_nsec
);
printf
(
"SW %"
PRIu64
" - %"
PRIu64
" (%"
PRIi64
") "
,
timestamp_ns
,
txtime
,
((
int64_t
)
timestamp_ns
)
-
txtime
);
break
;
}
default:
...
...
@@ -246,7 +248,6 @@ static int process_socket_error_queue() {
.
msg_control
=
msg_control
,
.
msg_controllen
=
sizeof
(
msg_control
)};
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed"
);
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment