[ee122] Can't find the inet_addr or inet_aton functions...

Christopher Cowart ccowart at berkeley.edu
Mon Sep 17 19:59:00 PDT 2007

On Mon, Sep 17, 2007 at 04:22:11PM -0700, Richard Schmidt wrote:
> which inlude file contains them? I've included all of them from Beej but i'm
> getting a symbol reference error on the function calls (both) when I try to
> compile.
> Any ideas? I don't want to have to parse the string address myself if I
> don't have to.

All C library functions (and most structs, etc.) are documented in 
UNIX man pages.

On a BSD-style system (including Mac OS X), these are part of  c 
library and are linked by default. It looks like on Solaris, you pass 
in -l flags for socket and nsl (as others have pointed out).

The command `man inet_addr' produces:

|      cc [ flag ... ] file... -lsocket -lnsl [ library...]
|      #include <sys/types.h>
|      #include <sys/socket.h>
|      #include <netinet/in.h>
|      #include <arpa/inet.h>

Which tells you 1) the .h files you need to include; 2) any link flags
you must pass to cc; 3) the type defs for the structs; 4) the function
prototypes and behaviors.

I generally have about 5 man pages open when I'm writing in C...

Chris Cowart
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 824 bytes
Desc: not available
Url : http://mailman.ICSI.Berkeley.EDU/pipermail/ee122/attachments/20070917/c38be9ac/attachment.bin 

More information about the ee122 mailing list