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
10f80112
Commit
10f80112
authored
Jun 03, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up code
parent
a972e493
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
102 deletions
+135
-102
packet-exchange/src/client.c
packet-exchange/src/client.c
+112
-80
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+10
-9
packet-exchange/src/recv_packet.h
packet-exchange/src/recv_packet.h
+1
-1
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+12
-12
No files found.
packet-exchange/src/client.c
View file @
10f80112
This diff is collapsed.
Click to expand it.
packet-exchange/src/recv_packet.c
View file @
10f80112
...
...
@@ -22,10 +22,11 @@
#define BUFFER_SIZE 1024
static
char
rx_buffer
[
BUFFER_SIZE
];
static
int
sock_fd
;
int
init_udp_recv
()
{
int
status
;
int
fd
=
-
1
;
int
sock_
fd
=
-
1
;
struct
addrinfo
hints
,
*
servinfo
,
*
servinfo_it
;
memset
(
&
hints
,
0
,
sizeof
hints
);
...
...
@@ -41,11 +42,11 @@ int init_udp_recv() {
for
(
servinfo_it
=
servinfo
;
servinfo_it
;
servinfo_it
=
servinfo_it
->
ai_next
)
{
fd
=
socket
(
servinfo
->
ai_family
,
servinfo
->
ai_socktype
,
sock_
fd
=
socket
(
servinfo
->
ai_family
,
servinfo
->
ai_socktype
,
servinfo
->
ai_protocol
);
if
(
bind
(
fd
,
servinfo_it
->
ai_addr
,
servinfo_it
->
ai_addrlen
)
==
-
1
)
{
close
(
fd
);
if
(
bind
(
sock_
fd
,
servinfo_it
->
ai_addr
,
servinfo_it
->
ai_addrlen
)
==
-
1
)
{
close
(
sock_
fd
);
continue
;
}
break
;
...
...
@@ -53,23 +54,23 @@ int init_udp_recv() {
freeaddrinfo
(
servinfo
);
if
(
fd
==
-
1
)
if
(
sock_
fd
==
-
1
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't create receive socket"
);
printf
(
"waiting to receive...
\n
"
);
return
fd
;
return
sock_
fd
;
}
void
recv_udp_packet
(
int
fd
)
{
void
recv_udp_packet
()
{
#ifdef DEBUG
int
bytes_received
=
0
;
bytes_received
=
recvfrom
(
fd
,
rx_buffer
,
BUFFER_SIZE
-
1
,
0
,
NULL
,
NULL
);
bytes_received
=
recvfrom
(
sock_
fd
,
rx_buffer
,
BUFFER_SIZE
-
1
,
0
,
NULL
,
NULL
);
if
(
bytes_received
==
-
1
)
error
(
EXIT_FAILURE
,
errno
,
"Error while attempting to receive packets"
);
#else
recvfrom
(
fd
,
rx_buffer
,
BUFFER_SIZE
-
1
,
0
,
NULL
,
NULL
);
recvfrom
(
sock_
fd
,
rx_buffer
,
BUFFER_SIZE
-
1
,
0
,
NULL
,
NULL
);
#endif
}
packet-exchange/src/recv_packet.h
View file @
10f80112
...
...
@@ -2,6 +2,6 @@
#define RECV_PACKET
int
init_udp_recv
();
void
recv_udp_packet
(
int
fd
);
void
recv_udp_packet
();
#endif
packet-exchange/src/send_packet.c
View file @
10f80112
...
...
@@ -48,7 +48,7 @@ static int so_priority = 3;
static
struct
sock_txtime
sk_txtime
;
static
unsigned
char
*
tx_buffer
;
static
size_t
tx_buffer_len
;
static
int
fd
;
static
int
sock_
fd
;
static
int64_t
tai_offset
;
...
...
@@ -62,7 +62,7 @@ static int set_if(char *network_if) {
memset
(
&
ifreq
,
0
,
sizeof
(
ifreq
));
strncpy
(
ifreq
.
ifr_name
,
network_if
,
sizeof
(
ifreq
.
ifr_name
)
-
1
);
if
(
ioctl
(
fd
,
SIOCGIFINDEX
,
&
ifreq
))
if
(
ioctl
(
sock_
fd
,
SIOCGIFINDEX
,
&
ifreq
))
error
(
EXIT_FAILURE
,
errno
,
"ioctl SIOCGIFINDEX failed
\n
"
);
return
ifreq
.
ifr_ifindex
;
...
...
@@ -103,17 +103,17 @@ void init_udp_send(int use_etf, int use_timestamps, int packet_priority,
so_priority
=
packet_priority
;
fd
=
socket
(
PF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
fd
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"Socket creation failed
\n
"
);
sock_
fd
=
socket
(
PF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
sock_
fd
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"Socket creation failed
\n
"
);
index
=
set_if
(
network_if
);
if
(
index
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set interface
\n
"
);
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_PRIORITY
,
&
so_priority
,
if
(
setsockopt
(
sock_
fd
,
SOL_SOCKET
,
SO_PRIORITY
,
&
so_priority
,
sizeof
(
so_priority
)))
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set socket priority
\n
"
);
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_BINDTODEVICE
,
network_if
,
if
(
setsockopt
(
sock_
fd
,
SOL_SOCKET
,
SO_BINDTODEVICE
,
network_if
,
strlen
(
network_if
)))
error
(
EXIT_FAILURE
,
errno
,
"setsockopt SO_BINDTODEVICE failed
\n
"
);
...
...
@@ -121,12 +121,12 @@ void init_udp_send(int use_etf, int use_timestamps, int packet_priority,
sk_txtime
.
clockid
=
CLOCK_TAI
;
sk_txtime
.
flags
=
0
;
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_TXTIME
,
&
sk_txtime
,
sizeof
(
sk_txtime
)))
if
(
setsockopt
(
sock_
fd
,
SOL_SOCKET
,
SO_TXTIME
,
&
sk_txtime
,
sizeof
(
sk_txtime
)))
error
(
EXIT_FAILURE
,
errno
,
"setsockopt SO_TXTIME failed
\n
"
);
}
if
(
use_timestamps
)
{
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_TIMESTAMPING
,
&
so_timestamping_flags
,
if
(
setsockopt
(
sock_
fd
,
SOL_SOCKET
,
SO_TIMESTAMPING
,
&
so_timestamping_flags
,
sizeof
(
so_timestamping_flags
)))
error
(
EXIT_FAILURE
,
errno
,
"setsockopt SO_TIMESTAMPING failed
\n
"
);
}
...
...
@@ -157,7 +157,7 @@ struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps,
struct
iovec
iov
;
int
sendmsgerr
;
int
res
;
struct
pollfd
poll_fd
=
{
fd
,
POLLPRI
,
0
};
struct
pollfd
poll_fd
=
{
sock_
fd
,
POLLPRI
,
0
};
struct
packet_timestamps
packet_ts
;
struct
timespec
ts
;
...
...
@@ -199,7 +199,7 @@ struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps,
packet_ts
.
user_call_sendmsg
=
ts_to_uint
(
ts
);
}
sendmsgerr
=
sendmsg
(
fd
,
&
msg
,
0
);
sendmsgerr
=
sendmsg
(
sock_
fd
,
&
msg
,
0
);
if
(
sendmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"sendmsg failed, ret value: %d
\n
"
,
sendmsgerr
);
...
...
@@ -255,7 +255,7 @@ static void process_timestamps(struct packet_timestamps *packet_ts, int64_t hist
msg
.
msg_control
=
&
control
;
msg
.
msg_controllen
=
sizeof
(
control
);
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
|
MSG_DONTWAIT
)
==
-
1
)
{
if
(
recvmsg
(
sock_
fd
,
&
msg
,
MSG_ERRQUEUE
|
MSG_DONTWAIT
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed
\n
"
);
return
;
}
...
...
@@ -292,7 +292,7 @@ static int process_socket_error_queue() {
.
msg_control
=
msg_control
,
.
msg_controllen
=
sizeof
(
msg_control
)};
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
)
==
-
1
)
{
if
(
recvmsg
(
sock_
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