Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Aug 2000 13:03:55 -0700 
From:      "Ari, Ismail" <iari@exch.hpl.hp.com>
To:        "'freebsd-hackers@freebsd.org'" <freebsd-hackers@freebsd.org>
Subject:   Problem linking/integrating Socket stuff into my driver code
Message-ID:  <140D21516EC2D3119EE700902787664401DA4DE8@hplex1.hpl.hp.com>

next in thread | raw e-mail | index | archive | help

Hi everyone,

I wrote pseudo-device driver for FreeBSD kernel. It safely comes up at boot
time. There is also a corresponding device node "/dev/mydevice" for my code,
so that whenever someone makes an: 

fd = open("/dev/mydevice", .. );
ioctl( fd, COMMAND );

the "mydevioctl()" function within my code will take care of the COMMAND
requested. 

***** NOW , My problem is !! ******

I tried to add some networking functionality to my driver. Although I
#include'd every required socket and net related header in my code
<sys/socket.h>, <netdb.h>,  <netinet/in.h> and etc. I get the errors
"Undefined reference to socket()" , same for connect(),  gethostbyname(),
accept() etc. In my previous life B.K. ( Before Kernel ) I used to link  to
socket related libraries ( -lsocket, -lnls ), but this is not a standalone
program and I  am not supposed to make explicit linking to any library. This
is KERNEL anyway, it has object code for almost every standard function you
may want to use (e.g.socket() ..) For example: kern/uipc_syscalls.o has the
socket() definition and uipc_syscalls.o is already in the list of object
files to be used in kernel make; all being compiled together.

After including the required header files and after ensuring with ( >> nm -s
uipc_syscalls.o ) that socket() is defined there, how do I get my code to
see these functions.

Some Bullets that might help
------------------------------------------------------------------

* FUNNY:: I wrote a small client/server chat program (for testing) ;compiled
both client and server code using "cc -o server server.c", "cc -o client
client.c" and DID NOT LINK any special library... IT WORKED ??!! I put
server code on another PC over network and they get to communicate with the
client. "cc" somehow knows where to link I guess (Is there a list  of the
libraries that cc links somewhere? or does it just look under  /usr/lib)..
And the second funny thing is that, when I do a symbol lookup ">> nm -s
client" on the client program the functions that I use , socket(),
gethostbyname() still look U ( Unresolved, Undefined ?)  

* Kernel Makefile first compile everything with "cc -c " , i.e. "don't link
at this time" option * After everything is compiled, kernel links them
together using linker ld 
* cc without any option does all the compiling and linking job, but I am
bound to use the KERNEL's rules "cc -c" first then link everything together.
* Other drivers in the kernel ( e.g. aha SCSI driver) don't have any compile
and linking problem and usually none of them need a special treatment for
linking. Check /usr/src/sys/compile/GENERIC -> Makefile . NORMAL_C type of
compilation is enough for them.

Please Respond to: iari@hpl.hp.com AND/OR ismailari@yahoo.com

Best Regards,

Ismail Ari
HP Labs


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?140D21516EC2D3119EE700902787664401DA4DE8>