ntohs()

ntohs()

Post by Mari » Sat, 15 Mar 2003 05:26:34



Hello,          

I write kernel module and as a source of new ideas i use other drivers :)
I've found there a very nice function "? ntohs(probably u_int32_t)" which is
quite often used. I looked for the prototype in the kernel include
directory but I couln't find it.

So my question is: what is that function for? What should I include to use
it?

I've used it and the module compiled without warnings... but when insmod:

bash-2.05a# insmod my_try.o
my_try.o: unresolved symbol ntohs

                           ^^^^^^^

so... what to do now?

regards,

        Mariusz

 
 
 

ntohs()

Post by Markus Csern » Sat, 15 Mar 2003 06:35:34



> Hello,

> I write kernel module and as a source of new ideas i use other drivers
> :) I've found there a very nice function "? ntohs(probably u_int32_t)"
> which is quite often used. I looked for the prototype in the kernel
> include directory but I couln't find it.

> So my question is: what is that function for? What should I include to
> use it?

> I've used it and the module compiled without warnings... but when
> insmod:

> bash-2.05a# insmod my_try.o
> my_try.o: unresolved symbol ntohs

>                            ^^^^^^^

> so... what to do now?

> regards,

>         Mariusz

ntohs() and friends are used to convert values between host and network
byteorder. On x86 machines the host byte order is Least Significant
Byte first, whereas the network byte order is Most Significant Byte
first.
Other architectures have different host byte orders so its important to
have a standard that is used for communication over a network so each
machine see values as they are meant to be.

Regards,
Markus

 
 
 

ntohs()

Post by Mari » Sat, 15 Mar 2003 08:49:18



> ntohs() and friends are used to convert values between host and network
> byteorder. On x86 machines the host byte order is Least Significant
> Byte first, whereas the network byte order is Most Significant Byte
> first.
> Other architectures have different host byte orders so its important to
> have a standard that is used for communication over a network so each
> machine see values as they are meant to be.

> Regards,
> Markus

Ok, now I know what's going on but I still get the message

my_try.o: unresolved symbol ntohs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

when I try to insmod my module. It compiles without warnings.
Should I link it with some libraries? Or maybe there is some other way to
deal with it?

System  : slackware 8.1
gcc     : 2.95.3
kernel  : 2.4.20

gcc flags : -o my_try.o -ansi-pedantic -Wall -D__KERNEL__ -DMODULE
-I/usr/src/linux/include/ -c my_try.c

I tried to #inlude many different files that have something to do with
"ntohs" but always compilation is ok and during insmod it complains.
http://groups.google.com also have rather nothing to say... Any ideas?

regards,

        Mariusz

 
 
 

ntohs()

Post by Grant Edwar » Sat, 15 Mar 2003 09:39:42



> Ok, now I know what's going on but I still get the message

> my_try.o: unresolved symbol ntohs
> gcc flags : -o my_try.o -ansi-pedantic -Wall -D__KERNEL__ -DMODULE
> -I/usr/src/linux/include/ -c my_try.c

> I tried to #inlude many different files that have something to do with
> "ntohs" but always compilation is ok and during insmod it complains.
> http://groups.google.com also have rather nothing to say... Any ideas?

I don't think the kernel exports an ntohs function for use by
modules.  ntohs() is a macro for user-apps to use.

You should probably be using __be16_to_cpus(x) instead of ntohs(x)

There are a whole slew of byte-order related macros available.
Take a look in /usr/src/linux/include/linux/byteorder/little_endian.h

--
Grant Edwards                   grante             Yow!  OVER the
                                  at               underpass! UNDER the
                               visi.com            overpass! Around the FUTURE
                                                   and BEYOND REPAIR!!

 
 
 

ntohs()

Post by Steven Rosted » Sat, 15 Mar 2003 11:47:50



> I don't think the kernel exports an ntohs function for use by
> modules.  ntohs() is a macro for user-apps to use.

> You should probably be using __be16_to_cpus(x) instead of ntohs(x)

> There are a whole slew of byte-order related macros available.
> Take a look in /usr/src/linux/include/linux/byteorder/little_endian.h

ntohs is a macro, and can be used in the kernel, you just need
to include <asm/byteorder.h> even for modules.

-- Steve

 
 
 

ntohs()

Post by Grant Edward » Sat, 15 Mar 2003 13:11:48




>> I don't think the kernel exports an ntohs function for use by
>> modules.  ntohs() is a macro for user-apps to use.

>> You should probably be using __be16_to_cpus(x) instead of ntohs(x)

>> There are a whole slew of byte-order related macros available.
>> Take a look in /usr/src/linux/include/linux/byteorder/little_endian.h

> ntohs is a macro, and can be used in the kernel, you just need to include
> <asm/byteorder.h> even for modules.

I stand corrected.  Interestingly, in user-land they're in <netinet/in.h>,
and ntohs is only a macro there if __OPTIMIZE__ is defined.  Otherwise it's
just another function linked in from glibc...

--
Grant Edwards                   grante             Yow!  I've read SEVEN
                                  at               MILLION books!!
                               visi.com            

 
 
 

ntohs()

Post by David Schwart » Sat, 15 Mar 2003 14:22:50



> Ok, now I know what's going on but I still get the message

> my_try.o: unresolved symbol ntohs
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> when I try to insmod my module. It compiles without warnings.
> Should I link it with some libraries? Or maybe there is some other way to
> deal with it?

        Either 'ntohs' is not in the kernel or it's not exported. You can't use
standard library functions in kernel code.

Quote:> gcc flags : -o my_try.o -ansi-pedantic -Wall -D__KERNEL__ -DMODULE
> -I/usr/src/linux/include/ -c my_try.c

        DS
 
 
 

ntohs()

Post by Mari » Sat, 15 Mar 2003 19:26:02




>> Ok, now I know what's going on but I still get the message

>> my_try.o: unresolved symbol ntohs

>> gcc flags : -o my_try.o -ansi-pedantic -Wall -D__KERNEL__ -DMODULE
>> -I/usr/src/linux/include/ -c my_try.c

>> I tried to #inlude many different files that have something to do with
>> "ntohs" but always compilation is ok and during insmod it complains.
>> http://groups.google.com also have rather nothing to say... Any ideas?

> I don't think the kernel exports an ntohs function for use by
> modules.  ntohs() is a macro for user-apps to use.

> You should probably be using __be16_to_cpus(x) instead of ntohs(x)

> There are a whole slew of byte-order related macros available.
> Take a look in /usr/src/linux/include/linux/byteorder/little_endian.h

Ok. I used be16_to_cpu(x) and it works fine. Thanks.

regards,

        Mariusz

 
 
 

ntohs()

Post by Mari » Sat, 15 Mar 2003 19:28:09


Thanks to all of you for your very good help. It makes my work faster and
knowledge biger :)

regards,

        Mariusz Kozlowski

 
 
 

1. Which library for ntoh* routines

I seem to have missed an evolutionary step somewhere such that I do not
have a library containing the ntoh* family of routines.

I am told that such a library does exist but have not been able to find it.

Can someone please point me in the right direction.

Cheers and thanks,
Stephen.

========================================================================

Adelaide, South Australia.                           Voice: 61-8-2728863
Computing & Network solutions.                       Fax  : 61-8-2741015

2. unix kernels?

3. ntohs()

4. Looking for Netzero Dialup Script for Linux