undefined reference to `inet_net_pton'

undefined reference to `inet_net_pton'

Post by Samee » Wed, 25 May 2011 20:45:48



This may seem a very trivial question  but it seems to me that
'inet_net_pton()' is not being linked properly on my system - (GNU
libc) 2.12.90, Linux  2.6.35.6-45.fc14.i686

I am trying to use 'inet_net_pton()' to read a CIDR IPV4 address and
convert it appropriately. I've included the appropriate headers :
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>

but it still gives me an undefined reference error while linking :
Interestingly pure 'inet_pton()' seems to be working well. Any ideas
on how this is possible ?

 
 
 

undefined reference to `inet_net_pton'

Post by Richard Kettlewel » Wed, 25 May 2011 21:40:43



> This may seem a very trivial question  but it seems to me that
> 'inet_net_pton()' is not being linked properly on my system - (GNU
> libc) 2.12.90, Linux  2.6.35.6-45.fc14.i686

> I am trying to use 'inet_net_pton()' to read a CIDR IPV4 address and
> convert it appropriately. I've included the appropriate headers :
> #include <sys/param.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <arpa/inet.h>
> #include <sys/socket.h>
> #include <netinet/in.h>

> but it still gives me an undefined reference error while linking :
> Interestingly pure 'inet_pton()' seems to be working well. Any ideas
> on how this is possible ?

Missing -lresolve presumably.

--
http://www.greenend.org.uk/rjk/

 
 
 

undefined reference to `inet_net_pton'

Post by Samee » Thu, 26 May 2011 14:24:40




> > This may seem a very trivial question ?but it seems to me that
> > 'inet_net_pton()' is not being linked properly on my system - (GNU
> > libc) 2.12.90, Linux ?2.6.35.6-45.fc14.i686

> > I am trying to use 'inet_net_pton()' to read a CIDR IPV4 address and
> > convert it appropriately. I've included the appropriate headers :
> > #include <sys/param.h>
> > #include <sys/types.h>
> > #include <sys/socket.h>
> > #include <arpa/inet.h>
> > #include <sys/socket.h>
> > #include <netinet/in.h>

> > but it still gives me an undefined reference error while linking :
> > Interestingly pure 'inet_pton()' seems to be working well. Any ideas
> > on how this is possible ?

> Missing -lresolve presumably.

> --http://www.greenend.org.uk/rjk/

I'm sorry didn't get it..do you mean I need to link with -lresolve
option ? I tried doing it, but doesn't seem to work...

g++ -Wall -g -std=c++0x  *.o -o oql -lresolve
/usr/bin/ld: cannot find -lresolve
collect2: ld returned 1 exit status

Hope I'm right in guessing what you mean...

 
 
 

undefined reference to `inet_net_pton'

Post by Samee » Thu, 26 May 2011 14:29:24


Quote:

> Missing -lresolve presumably.

> --http://www.greenend.org.uk/rjk/

The function using inet_net_pton() :

int IPV6Node::setNode(MINEOPERATOR op, char *constant, char
*attribute, int att_len)
{
        mOp = op;
        struct in6_addr addrv6;
        if (IPV6Node::checkValue(constant,op) == 0)
        {
                cout << constant << " is invalid." << endl;
                return 0;
        }
        if (IPV6Node::setDirection(attribute)==0)
        {
                cout << "Direction is invalid." << endl;
                return 0;
        }

        if(constant != NULL)
        {
                const char *maskp = strchr(constant,'/');
                if(maskp)
                {
                        inet_net_pton(AF_INET6, constant, &(addrv6.s6_addr),
sizeof(addrv6));
                }
                else
                {
                        inet_pton(AF_INET6, constant, &(addrv6.s6_addr));
                }
                memcpy((void *)mConstant, (const void *)addrv6.s6_addr, 16);
        }
        return 1;

Quote:}

Here the inet_pton() seems to be linked well but inet_net_pton() gives
me undefined reference error...
 
 
 

undefined reference to `inet_net_pton'

Post by Richard Kettlewel » Thu, 26 May 2011 17:15:45





>> > but it still gives me an undefined reference error while linking :
>> > Interestingly pure 'inet_pton()' seems to be working well. Any ideas
>> > on how this is possible ?

>> Missing -lresolve presumably.

> I'm sorry didn't get it..do you mean I need to link with -lresolve
> option ? I tried doing it, but doesn't seem to work...

Sorry, should be -lresolv, no final 'e'.


000000000000a860 T inet_net_pton

--
http://www.greenend.org.uk/rjk/

 
 
 

undefined reference to `inet_net_pton'

Post by Samee » Fri, 27 May 2011 15:02:01






> >> > but it still gives me an undefined reference error while linking :
> >> > Interestingly pure 'inet_pton()' seems to be working well. Any ideas
> >> > on how this is possible ?

> >> Missing -lresolve presumably.

> > I'm sorry didn't get it..do you mean I need to link with -lresolve
> > option ? I tried doing it, but doesn't seem to work...

> Sorry, should be -lresolv, no final 'e'.


> 000000000000a860 T inet_net_pton

> --http://www.greenend.org.uk/rjk/

Oh..thanks..it now works -

I now have a different question to ask : inet_net_pton() converts the
input string with /prefix into a 'struct in_addr addr' form (network
form). Now how can one use this - 'addr.s_addr' to specifically select
the masked range.

For instance - if I have a range of IPV4 addresses from
192.168.x.y-192.168.x.z and I use inet_pton() on an IP address
192.168.0.0/16 then 'addr.s_addr' will be the 32 bit int
representation of the same. The masking also represents a valid IPV4
address range - between 192.168.0.0-192.168.255.255. Now how can I use
this 32 bit value to specifically select the above specified range ?

I hope I'm clear enough to explain what I need to use inet_net_pton()
for...

thanks..
Sameer