Hi all!
I have to create an application that receive some packet from an
interface and builds a file from those. In the header there are three
fields: one is the total lenght of the file, one is the offset of the
packet in the file and one is the lenght of the current packet.
I made a function that gets all the packets and reconstruct the file.
while(...)
{
FilePart part;
.......
char* fileBuffer = new char[fileLenght];
int offset = part->offset;
int lenght = part->lenght;
memmove(fileBuf fer + offset, part->buffer, lenght);
lenghtCheck += lenght;
}
I used lenghtCheck to check that the sum of all the lenghts is the
same as the original file. If this is true, I then write the file.
(I didn't post a complete code since this seems to work)
My problem is that the file isn't the same as the original opnbe, some
parts are missing. I though that maybe I overwrite some parts of the
buffer (maybe some offsets are wrong?).
I'd like a function to check that every byte of the fileBuffer array
has been overwritten. DO you know how I can do this? The file is
binary, not text.
Thank you very much for your help 5 1559
* Paolo:
>
I have to create an application that receive some packet from an
interface and builds a file from those. In the header there are three
fields: one is the total lenght of the file, one is the offset of the
packet in the file and one is the lenght of the current packet.
I made a function that gets all the packets and reconstruct the file.
while(...)
{
FilePart part;
......
char* fileBuffer = new char[fileLenght];
int offset = part->offset;
int lenght = part->lenght;
memmove(fileBuf fer + offset, part->buffer, lenght);
lenghtCheck += lenght;
}
'int' may not have the range required to represent a file size.
I used lenghtCheck to check that the sum of all the lenghts is the
same as the original file. If this is true, I then write the file.
(I didn't post a complete code since this seems to work)
My problem is that the file isn't the same as the original opnbe, some
parts are missing. I though that maybe I overwrite some parts of the
buffer (maybe some offsets are wrong?).
I'd like a function to check that every byte of the fileBuffer array
has been overwritten. DO you know how I can do this?
For example, use a std::bitset where each bit represents one byte.
Update the bitset as you write. Check it at the end.
The file is binary, not text.
Irrelevant.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Well, maybe you'll say that this is not the correct group, but I'm
using MFC, and I think they won't be happy with std stuff...
Paolo schrieb:
Well, maybe you'll say that this is not the correct group, but I'm
using MFC, and I think they won't be happy with std stuff...
1) please quote.
2) Why should "they" mind what you do in your code?
3) Who is "they"?
Finally:
4) Did you open the file as binary in both places? Maybe the
newline-converter corrupted the file.
--
Thomas
Thomas J. Gritzan ha scritto:
Paolo schrieb:
Well, maybe you'll say that this is not the correct group, but I'm
using MFC, and I think they won't be happy with std stuff...
1) please quote.
2) Why should "they" mind what you do in your code?
3) Who is "they"?
Well, I read somewhere that when you use MFC, you get problem using
standard library containers, such as list and so on. After reading
this, I also tried it, and I must say that this is true. The problem is
MFC redefine new operator, and this is a problem for the standard
library.
All this to say hat I can't use the container you seggested. Anyway I
use an array of int where I store the beginning and the end of every
buffer I write, so I can check if they overlap.
Finally:
4) Did you open the file as binary in both places? Maybe the
newline-converter corrupted the file.
Yes I opened the files as binary.
--
Thomas
"Paolo" <pa****@gmail.c omwrote in message
news:11******** *************@p 79g2000cwp.goog legroups.com...
Hi all!
I have to create an application that receive some packet from an
interface and builds a file from those. In the header there are three
fields: one is the total lenght of the file, one is the offset of the
packet in the file and one is the lenght of the current packet.
I made a function that gets all the packets and reconstruct the file.
while(...)
{
FilePart part;
......
char* fileBuffer = new char[fileLenght];
int offset = part->offset;
int lenght = part->lenght;
memmove(fileBuf fer + offset, part->buffer, lenght);
lenghtCheck += lenght;
}
I used lenghtCheck to check that the sum of all the lenghts is the
same as the original file. If this is true, I then write the file.
(I didn't post a complete code since this seems to work)
My problem is that the file isn't the same as the original opnbe, some
parts are missing. I though that maybe I overwrite some parts of the
buffer (maybe some offsets are wrong?).
I'd like a function to check that every byte of the fileBuffer array
has been overwritten. DO you know how I can do this? The file is
binary, not text.
Thank you very much for your help
Without any knowledge of how your part is built, it's hard to say. It may
be a simple off by one error. Maybe your offset is one too little or one
two many, ect...
I would suggest you create a text file that you can examine easily. Maybe
something as simple as:
Line 1
Line 2
Line 3
etc...
then run through your code, write the file, and look at the output.
Now, you want to know if every byte has been set in your buffer. You can do
this with math, but if your math is wrong creating the part it may be wrong
in the examining. Something like this though should do it.
Untested code.
static LastByteSet = 0;
while (...)
{
if ( offset != 0 && LastByteSet != offset -1 )
// Error, missing some bytes here or overwriting
else
{
memmove(fileBuf fer + offset, part->buffer, lenght);
LastByteSet = (offset + length) - 1;
// Notice -1 here. If your offset was 0 and length was 1, only byte
0 would be written
}
}
// LastByteSet should be equal to lengthCheck here This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: manders2k |
last post by:
Hi all --
I'm contemplating the idea of writing a simple emacs-like editor in
python (for fun and the experience of doing so). In reading through
Craig Finseth's "The Craft of Text Editing":
http://www.finseth.com/~fin/craft/
, I've come across the "buffer gap" representation for the text data
of the buffer. Very briefly, it keeps the unallocated memory of the
|
by: inkapyrite |
last post by:
Hi all. I'm using ifstream to read from a named pipe but
i've encountered an annoying problem. For some reason, the
program blocks on reading an ifstream's internal buffer that's
only half-filled. Only when the buffer becomes full does
it resume execution.
Here's my test code for reading from a pipe:
//(compiled with g++ -std=c++98)
//---------------------------------------------
#include <iostream>
|
by: Jon LaBadie |
last post by:
Suppose I'm using stdio calls to write to a disk file.
One possible error condition is no space on file system
or even (in unix environment) a ulimit of 0 bytes.
Which calls would be expected to return error codes for
such conditions?
Would it happen on the writes (fwrite, fprintf, fputs ...),
or as they actually write to io buffers, might the errors
not occur until the data is flushed or the file is closed?
|
by: Dan DeConinck |
last post by:
Hello,
I want to save the position of all the controls on my form. I would like to
write them out to a preference file.
I have done this in DOS BASIC like this:
TO WRITE the preference
open "c:\preferences.txt" for input as #1
input #1 ,a,b,c
|
by: rdemyan via AccessMonster.com |
last post by:
I currently have code that brings up a form where the user can see a list of
spreadsheets on my ftp site, select one and then download and import the
spreadsheet into a table.
All of this processing is initiated by the user.
I'm thinking about automating some or all of this. My questions is: how do I
best determine when there is an update to a table in my Access Application
that is available on my ftp site?
| |
by: toton |
last post by:
Hi,
I want a circular buffer or queue like container (queue with array
implementation).
Moreover I want random access over the elements. And addition at tail
and remove from head need to be low cost.
STL vector is suitable for removing form tail? or it is as costly as
removing from middle?
any other std container to serve this purpose? (note , I dont need
linked list implementation of any container, as I want random access)
|
by: arnuld |
last post by:
this is from mentioned section. i did not understand some things here:
it means "flushing the buffer" and "writing to output device" are SAME
thing, these are just 2 different names for the same thing.
?
|
by: Xah Lee |
last post by:
http://xahlee.org/emacs/modernization.html
]
The Modernization of Emacs
----------------------------------------
THE PROBLEM
Emacs is a great editor. It is perhaps the most powerful and most
versatile text editor. And, besides text editing, it also serves as a
|
by: Philip Potter |
last post by:
Hello clc,
I have a buffer in a program which I write to. The buffer has
write-only, unsigned-char-at-a-time access, and the amount of space
required isn't known a priori. Therefore I want the buffer to
dynamically grow using realloc().
A comment by Richard Heathfield in a thread here suggested that a good
algorithm for this is to use realloc() to double the size of the buffer,
but if realloc() fails request smaller size increments...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |