Hi
I 'am developping a new network layer in NS-2 network simulation environment in C++. I got the following error : Segmentation fault when running the program I wrote.
I have localized the line where the error ocured: - memcpy(tstr,&myDSCH_SC_IE_,sizeof(DSCH_SC_IE));
where the tstr , myDSCH_SC_IE_ , DSCH_SC_IE are defined as follows : - Packet *p = Packet::alloc(); // Network Packet memory allocation
-
unsigned char* tstr = p->accessdata(); // get a pointer on the data part the packet
-
-
typedef struct DSCH_SC_IEType { DSCH_SC_IEType():NextXmtMx(0),NextHoldoffExponent(0),NumScheds(0) {} ;
-
unsigned NextXmtMx :5;
-
unsigned NextHoldoffExponent :3; //~Range in AV
-
unsigned NumScheds :8;
-
} DSCH_SC_IE ; // struct defining with constructor and bitfields
-
DSCH_SC_IE myDSCH_SC_IE_ ;
Could someone give me some suggestions
Best regards
Ramzi
5 1547
Hi
I 'am developping a new network layer in NS-2 network simulation environment in C++. I got the following error : Segmentation fault when running the program I wrote.
I have localized the line where the error ocured: - memcpy(tstr,&myDSCH_SC_IE_,sizeof(DSCH_SC_IE));
where the tstr , myDSCH_SC_IE_ , DSCH_SC_IE are defined as follows : - Packet *p = Packet::alloc(); // Network Packet memory allocation
-
unsigned char* tstr = p->accessdata(); // get a pointer on the data part the packet
-
-
typedef struct DSCH_SC_IEType { DSCH_SC_IEType():NextXmtMx(0),NextHoldoffExponent(0),NumScheds(0) {} ;
-
unsigned NextXmtMx :5;
-
unsigned NextHoldoffExponent :3; //~Range in AV
-
unsigned NumScheds :8;
-
} DSCH_SC_IE ; // struct defining with constructor and bitfields
-
DSCH_SC_IE myDSCH_SC_IE_ ;
Could someone give me some suggestions
Best regards
Ramzi
Did you check the return value? Perhaps you don't have an object to copy.
Hope this helps.
Adrin
Hi
I 'am developping a new network layer in NS-2 network simulation environment in C++. I got the following error : Segmentation fault when running the program I wrote.
I have localized the line where the error ocured: - memcpy(tstr,&myDSCH_SC_IE_,sizeof(DSCH_SC_IE));
where the tstr , myDSCH_SC_IE_ , DSCH_SC_IE are defined as follows : - Packet *p = Packet::alloc(); // Network Packet memory allocation
-
unsigned char* tstr = p->accessdata(); // get a pointer on the data part the packet
-
-
typedef struct DSCH_SC_IEType { DSCH_SC_IEType():NextXmtMx(0),NextHoldoffExponent(0),NumScheds(0) {} ;
-
unsigned NextXmtMx :5;
-
unsigned NextHoldoffExponent :3; //~Range in AV
-
unsigned NumScheds :8;
-
} DSCH_SC_IE ; // struct defining with constructor and bitfields
-
DSCH_SC_IE myDSCH_SC_IE_ ;
Could someone give me some suggestions
Best regards
Ramzi
I'm not sure if I completely understand the problem, but I think there is a spelling mismatche: You say typedef struct DSCH_SC_IEType, but refer to the struct as DSCH_SC_IE after the definition and in other declarations and the sizeof() call.
Did you check the return value? Perhaps you don't have an object to copy.
Hope this helps.
Adrin
SI I have verified that objects Packet and myDSCH_SC_IE_ already exist just before the memory copy.
Regards,
Ramzi
I'm not sure if I completely understand the problem, but I think there is a spelling mismatche: You say typedef struct DSCH_SC_IEType, but refer to the struct as DSCH_SC_IE after the definition and in other declarations and the sizeof() call.
As you can note DSCH_SC_IE refers to the name of the type defined usong struct DSCH_SC_IEType and the key word typedef.
Regards,
Ramzi
SI I have verified that objects Packet and myDSCH_SC_IE_ already exist just before the memory copy.
Regards,
Ramzi
Hmmm, ok, are packets always the same size? Perhaps you are copying something that is not there? Your problem may be in Packet.
I tried your code with a dummy packet and it worked fine: - struct Packet
-
{
-
unsigned int value;
-
-
Packet()
-
: value(999)
-
{
-
}
-
-
static Packet * alloc()
-
{
-
return new Packet();
-
}
-
-
unsigned char * accessdata()
-
{
-
return reinterpret_cast<unsigned char*>(&value);
-
}
-
};
-
-
typedef struct DSCH_SC_IEType { DSCH_SC_IEType():NextXmtMx(0),NextHoldoffExponent( 0),NumScheds(0) {} ;
-
unsigned NextXmtMx :5;
-
unsigned NextHoldoffExponent :3; //~Range in AV
-
unsigned NumScheds :8;
-
} DSCH_SC_IE ; // struct defining with constructor and bitfields
-
DSCH_SC_IE myDSCH_SC_IE_ ;
-
-
#include <memory.h>
-
int main()
-
{
-
Packet *p = Packet::alloc(); // Network Packet memory allocation
-
unsigned char* tstr = p->accessdata(); // get a pointer on the data part the packet
-
-
memcpy(tstr,&myDSCH_SC_IE_,sizeof(DSCH_SC_IE));
-
return 0;
-
}
-
Hope this helps.
Adrian
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sivignon |
last post by:
Hi,
I'm writing a php script which deals with 3 ORACLE databases.
This script is launch by a script shell on an linux machine like this :
/../php/bin/php ./MySript.php (PHP 4.3.3)
My script...
|
by: diyanat |
last post by:
i am writing a cgi script in C using the CGIC library, the script
fails to run, i am using apache on linux
error report from apache : internal server error
Premature end of script headers:...
|
by: laberth |
last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why?
Here is what I use :
typedef struct noeud {
int val;
struct noeud *fgauche;
struct noeud *fdroit;
} *arbre; //for those...
|
by: Zheng Da |
last post by:
Program received signal SIGSEGV, Segmentation fault.
0x40093343 in _int_malloc () from /lib/tls/libc.so.6
(gdb) bt
#0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6
#1 0x40094c54 in malloc...
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I...
|
by: Digital Puer |
last post by:
Hi, I'm coming over from Java to C++, so please bear with me.
In C++, is there a way for me to use exceptions to catch
segmentation faults (e.g. when I access a location off
the end of an array)?...
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
...
|
by: pycraze |
last post by:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our...
|
by: madunix |
last post by:
My Server is suffering bad lag (High Utlization)
I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2
Web visitors retrieve data from the web by php calls through oci
cobnnection...
|
by: DanielJohnson |
last post by:
int main()
{
printf("\n Hello World");
main;
return 0;
}
This program terminate just after one loop while the second program
goes on infinitely untill segmentation fault (core dumped) on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |