Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
0788f5ed
Commit
0788f5ed
authored
Mar 20, 2015
by
Boaz Brickner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use _wfopen_s() instead of _wfopen() to open pcap files and give better error messages.
parent
7d72f9b8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
OfflinePacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
+19
-3
No files found.
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
View file @
0788f5ed
...
...
@@ -35,9 +35,25 @@ pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName)
pcap_t
*
pcapDescriptor
;
if
(
!
StringExtensions
::
AreAllCharactersInRange
(
fileName
,
0
,
255
))
{
std
::
wstring
unamangedFilename
=
MarshalingServices
::
ManagedToUnmanagedWideString
(
fileName
);
file
=
_wfopen
(
unamangedFilename
.
c_str
(),
L"rb"
);
if
(
file
==
NULL
)
throw
gcnew
InvalidOperationException
(
String
::
Format
(
CultureInfo
::
InvariantCulture
,
"Failed opening file {0}."
,
fileName
));
errno_t
fileOpenError
=
_wfopen_s
(
&
file
,
unamangedFilename
.
c_str
(),
L"rb"
);
if
(
fileOpenError
!=
0
||
file
==
nullptr
)
{
String
^
errorMessage
;
if
(
fileOpenError
!=
0
)
{
// TODO: Replace with constexpr when microsoft support it.
static
const
int
ERROR_MESSAGE_BUFFER_SIZE
=
1024
;
wchar_t
errorMessageBuffer
[
ERROR_MESSAGE_BUFFER_SIZE
];
errno_t
getErrorMessageError
=
_wcserror_s
(
errorMessageBuffer
,
ERROR_MESSAGE_BUFFER_SIZE
,
fileOpenError
);
errorMessage
=
getErrorMessageError
==
0
?
gcnew
String
(
errorMessageBuffer
,
0
,
wcslen
(
errorMessageBuffer
))
:
"Unknown"
;
}
else
{
errorMessage
=
"Unknown"
;
}
throw
gcnew
InvalidOperationException
(
String
::
Format
(
CultureInfo
::
InvariantCulture
,
"Failed opening file {0}. Error: {1}"
,
fileName
,
errorMessage
));
}
pcapDescriptor
=
pcap_fopen_offline
(
file
,
errorBuffer
);
}
else
{
std
::
string
unamangedFilename
=
MarshalingServices
::
ManagedToUnmanagedString
(
fileName
);
...
...
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