"compile" problem

  • Thread starter Alexander Bartzas
  • Start date
A

Alexander Bartzas

I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...:
g++ packet.cpp radix.cpp route.cpp -o route

There is no problem in the compilation of the code but when I try to run
it...

Segmentation fault (core dumped)

I've located where the problem is... It is part of the following function's
code:

int rtrequest(int req, class Sockaddr *Dst, class Sockaddr *Gateway, class
Sockaddr *Netmask, int flags, class rtentry **ret_nrt)
{
register class rtentry *rt;
register class radix_node *rn;
register class radix_node_head *rnh;
struct ifaddr *ifa;
class Sockaddr *Ndst;
....

rt->rt_ifp = (struct ifnet *) ifa->ifa_ifp;

....}

rt_ifp is of type struct ifnet *

I don't what to do to overcome the problem.
Any help is welcomed.
Thanks in advance

Alexander Bartzas
 
J

John Harrison

Alexander Bartzas said:
I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...:


There is no problem in the compilation of the code but when I try to run
it...

Segmentation fault (core dumped)

I've located where the problem is... It is part of the following function's
code:

int rtrequest(int req, class Sockaddr *Dst, class Sockaddr *Gateway, class
Sockaddr *Netmask, int flags, class rtentry **ret_nrt)
{
register class rtentry *rt;
register class radix_node *rn;
register class radix_node_head *rnh;
struct ifaddr *ifa;
class Sockaddr *Ndst;
...

rt->rt_ifp = (struct ifnet *) ifa->ifa_ifp;

...}

rt_ifp is of type struct ifnet *

I don't what to do to overcome the problem.
Any help is welcomed.
Thanks in advance

Alexander Bartzas

The normal way to solve this kind of problem is to use a debugger. Since you
are using g++ you should look at the gdb debugger. Most likely reason for
your crash is that ifa or rt are a NULL or otherwise invalid pointers. As
for why that should be, well the debugger will help you work it out.

john
 
V

Victor Bazarov

Alexander Bartzas said:
I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...:


There is no problem in the compilation of the code but when I try to run
it...

Segmentation fault (core dumped)

I've located where the problem is... It is part of the following function's
code:

int rtrequest(int req, class Sockaddr *Dst, class Sockaddr *Gateway, class
Sockaddr *Netmask, int flags, class rtentry **ret_nrt)
{
register class rtentry *rt;

'rt' here is a pointer to an object of type 'rtentry'. Which
object does it point to? Unknown. You didn't make it point
anywhere. It's uninitialised. Its value is random garbage.
register class radix_node *rn;
register class radix_node_head *rnh;
struct ifaddr *ifa;

'ifa' here is a pointer to some object of type 'ifaddr'. What
object does it point to? Unknown. Because it doesn't have
any value.
class Sockaddr *Ndst;
...

What's here? I presume there is nothing here that changes
the values of 'rt' or 'ifa'.
rt->rt_ifp = (struct ifnet *) ifa->ifa_ifp;

Here you dereference both 'rt' and 'ifa'. An attempt to
dereference a pointer whose value is garbage leads to what
you get, a segmentation fault. In terms of C++ you witness
"undefined behaviour".
...}

rt_ifp is of type struct ifnet *

I don't what to do to overcome the problem.

You need to make those pointers point somewhere real. Perhaps
you could find an example of what you're trying to accomplish.
Try looking on the Web. Neither 'rtentry', nor 'ifaddr' is
a standard type, so we cannot really help you give them correct
values.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top