Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
3963d1c8
Commit
3963d1c8
authored
7 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
net/route: File read/write logic should be able to handle short reads and writes.
parent
e5c79ba1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
net/route/net_fileroute.c
+99
-15
99 additions, 15 deletions
net/route/net_fileroute.c
with
99 additions
and
15 deletions
net/route/net_fileroute.c
+
99
−
15
View file @
3963d1c8
...
...
@@ -338,6 +338,8 @@ int net_openroute_ipv6(int oflags, FAR struct file *filep)
ssize_t
net_readroute_ipv4
(
FAR
struct
file
*
filep
,
FAR
struct
net_route_ipv4_s
*
route
)
{
FAR
uint8_t
*
dest
;
ssize_t
ntotal
;
ssize_t
ret
;
/* Lock the route.. we don't want to read from it while it is subject to
...
...
@@ -348,16 +350,35 @@ ssize_t net_readroute_ipv4(FAR struct file *filep,
if
(
ret
<
0
)
{
nerr
(
"ERROR: net_lockroute_ipv4() failed: %d
\n
"
,
ret
);
return
ret
;
}
else
/* Read one record from the current position in the routing table */
dest
=
(
FAR
uint8_t
*
)
route
;
ntotal
=
0
;
do
{
/* Read one record from the current position in the routing table */
size_t
nbytes
=
sizeof
(
struct
net_route_ipv4_s
)
-
ntotal
;
ssize_t
nread
;
ret
=
file_read
(
filep
,
route
,
sizeof
(
struct
net_route_ipv4_s
));
nread
=
file_read
(
filep
,
dest
,
nbytes
);
if
(
nread
<=
0
)
{
/* Read error or end of file */
ntotal
=
nread
;
break
;
}
ntotal
+=
nread
;
dest
+=
nread
;
}
while
(
ntotal
<
sizeof
(
struct
net_route_ipv4_s
));
(
void
)
net_unlockroute_ipv4
();
return
ret
;
return
ntotal
;
}
#endif
...
...
@@ -365,6 +386,8 @@ ssize_t net_readroute_ipv4(FAR struct file *filep,
ssize_t
net_readroute_ipv6
(
FAR
struct
file
*
filep
,
FAR
struct
net_route_ipv6_s
*
route
)
{
FAR
uint8_t
*
dest
;
ssize_t
ntotal
;
ssize_t
ret
;
/* Lock the route.. we don't want to read from it while it is subject to
...
...
@@ -375,16 +398,35 @@ ssize_t net_readroute_ipv6(FAR struct file *filep,
if
(
ret
<
0
)
{
nerr
(
"ERROR: net_lockroute_ipv6() failed: %d
\n
"
,
ret
);
return
ret
;
}
else
/* Read one record from the current position in the routing table */
dest
=
(
FAR
uint8_t
*
)
route
;
ntotal
=
0
;
do
{
/* Read one record from the current position in the routing table */
size_t
nbytes
=
sizeof
(
struct
net_route_ipv6_s
)
-
ntotal
;
ssize_t
nread
;
nread
=
file_read
(
filep
,
dest
,
nbytes
);
if
(
nread
<=
0
)
{
/* Read error or end of file */
ret
=
nread
;
break
;
}
ret
=
file_read
(
filep
,
route
,
sizeof
(
struct
net_route_ipv6_s
));
ntotal
+=
nread
;
dest
+=
nread
;
}
while
(
ntotal
<
sizeof
(
struct
net_route_ipv6_s
));
(
void
)
net_unlockroute_ipv6
();
return
ret
;
return
ntotal
;
}
#endif
...
...
@@ -408,6 +450,8 @@ ssize_t net_readroute_ipv6(FAR struct file *filep,
ssize_t
net_writeroute_ipv4
(
FAR
struct
file
*
filep
,
FAR
const
struct
net_route_ipv4_s
*
route
)
{
FAR
const
uint8_t
*
src
;
ssize_t
ntotal
;
ssize_t
ret
;
/* Lock the route.. we don't want to write to it while it is subject to
...
...
@@ -418,16 +462,35 @@ ssize_t net_writeroute_ipv4(FAR struct file *filep,
if
(
ret
<
0
)
{
nerr
(
"ERROR: net_lockroute_ipv4() failed: %d
\n
"
,
ret
);
return
ret
;
}
else
/* Write one record at the current position in the routing table */
src
=
(
FAR
const
uint8_t
*
)
route
;
ntotal
=
0
;
do
{
/* Write one record at the current position in the routing table */
size_t
nbytes
=
sizeof
(
struct
net_route_ipv4_s
)
-
ntotal
;
ssize_t
nwritten
;
nwritten
=
file_write
(
filep
,
src
,
nbytes
);
if
(
nwritten
<=
0
)
{
/* Write error (zero is not a valid return value for write) */
ret
=
nwritten
;
break
;
}
ret
=
file_write
(
filep
,
route
,
sizeof
(
struct
net_route_ipv4_s
));
ntotal
+=
nwritten
;
src
+=
nwritten
;
}
while
(
ntotal
<
sizeof
(
struct
net_route_ipv4_s
));
(
void
)
net_unlockroute_ipv4
();
return
ret
;
return
ntotal
;
}
#endif
...
...
@@ -435,6 +498,8 @@ ssize_t net_writeroute_ipv4(FAR struct file *filep,
ssize_t
net_writeroute_ipv6
(
FAR
struct
file
*
filep
,
FAR
const
struct
net_route_ipv6_s
*
route
)
{
FAR
const
uint8_t
*
src
;
ssize_t
ntotal
;
ssize_t
ret
;
/* Lock the route.. we don't want to write to it while it is subject to
...
...
@@ -445,13 +510,32 @@ ssize_t net_writeroute_ipv6(FAR struct file *filep,
if
(
ret
<
0
)
{
nerr
(
"ERROR: net_lockroute_ipv6() failed: %d
\n
"
,
ret
);
return
ret
;
}
else
/* Write one record at the current position in the routing table */
src
=
(
FAR
const
uint8_t
*
)
route
;
ntotal
=
0
;
do
{
/* Write one record at the current position in the routing table */
size_t
nbytes
=
sizeof
(
struct
net_route_ipv6_s
)
-
ntotal
;
ssize_t
nwritten
;
nwritten
=
file_write
(
filep
,
src
,
nbytes
);
if
(
nwritten
<=
0
)
{
/* Write error (zero is not a valid return value for write) */
ntotal
=
nwritten
;
break
;
}
ret
=
file_write
(
filep
,
route
,
sizeof
(
struct
net_route_ipv6_s
));
ntotal
+=
nwritten
;
src
+=
nwritten
;
}
while
(
ntotal
<
sizeof
(
struct
net_route_ipv6_s
));
(
void
)
net_unlockroute_ipv6
();
return
ret
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment