蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年6月6日 10:18



菜鸟求救阿..<UNIX网络编程第三版> 设置大问题

我在www.unpbook.com把代码下了下来来调第一个程序但是不行,我的做法是:



在/root目录创一个文件夹 include  ==>> /root/include

把网上的代码文件夹:/lib/unp.h ,/sparc4-unknown-freebsd5.1/config.h ,和/lib/error ,
还试过把网上的代码文件夹的/lib目录全拷到          /root/include上

当我调:第4页 daytimetcpcli.c :


#include <unp.h>

int
main(int argc, char **argv)
{
        int                                        sockfd, n;
        struct sockaddr_in6        servaddr;
        char                                recvline[MAXLINE + 1];

        if (argc != 2)
                err_quit("usage: a.out <IPaddress>");

        if ( (sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
                err_sys("socket error");

        bzero(&servaddr, sizeof(servaddr));
        servaddr.sin6_family = AF_INET6;
        servaddr.sin6_port   = htons(13);        /* daytime server */
        if (inet_pton(AF_INET6, argv[1], &servaddr.sin6_addr) <= 0)
                err_quit("inet_pton error for %s", argv[1]);

        if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
                err_sys("connect error");

        while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
                recvline[n] = 0;        /* null terminate */
                if (fputs(recvline, stdout) == EOF)
                        err_sys("fputs error");
        }
        if (n < 0)
                err_sys("read error");

        exit(0);
}









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

当我:
[root@localhost network]# gcc daytimetcpcliv6.c  -L/root/include -I/root/include -lnew -o test



就N多个错误了:



In file included from daytimetcpcliv6.c:1:
/root/include/unp.h:7:66: ../config.h: 没有那个文件或目录
In file included from daytimetcpcliv6.c:1:
/root/include/unp.h:227: error: redefinition of `struct sockaddr_storage'
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:10: error: redefinition of `struct addrinfo'
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:22:1: warning: "AI_PASSIVE" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:569:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:23:1: warning: "AI_CANONNAME" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:570:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:29:1: warning: "NI_NOFQDN" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:615:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:30:1: warning: "NI_NUMERICHOST" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:613:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:31:1: warning: "NI_NAMEREQD" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:616:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:32:1: warning: "NI_NUMERICSERV" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:614:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:36:1: warning: "EAI_ADDRFAMILY" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:597:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:37:1: warning: "EAI_AGAIN" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:591:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:38:1: warning: "EAI_BADFLAGS" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:589:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:39:1: warning: "EAI_FAIL" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:592:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:40:1: warning: "EAI_FAMILY" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:594:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:41:1: warning: "EAI_MEMORY" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:598:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:42:1: warning: "EAI_NODATA" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:593:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:43:1: warning: "EAI_NONAME" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:590:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:44:1: warning: "EAI_SERVICE" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:596:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:45:1: warning: "EAI_SOCKTYPE" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:595:1: warning: this is the location of the previous definition
In file included from /root/include/unp.h:249,
                 from daytimetcpcliv6.c:1:
/root/include/../lib/addrinfo.h:46:1: warning: "EAI_SYSTEM" redefined
In file included from /root/include/unp.h:29,
                 from daytimetcpcliv6.c:1:
/usr/include/netdb.h:599:1: warning: this is the location of the previous definition
In file included from daytimetcpcliv6.c:1:
/root/include/unp.h:263: error: redefinition of `struct timespec'
/root/include/unp.h:363: error: conflicting types for 'gai_strerror'
/usr/include/netdb.h:640: error: previous declaration of 'gai_strerror' was here
/root/include/unp.h:363: error: conflicting types for 'gai_strerror'
/usr/include/netdb.h:640: error: previous declaration of 'gai_strerror' was here
/root/include/unp.h:367: error: conflicting types for 'getnameinfo'
/usr/include/netdb.h:649: error: previous declaration of 'getnameinfo' was here
/root/include/unp.h:367: error: conflicting types for 'getnameinfo'
/usr/include/netdb.h:649: error: previous declaration of 'getnameinfo' was here
/root/include/unp.h:371: error: conflicting types for 'gethostname'
/usr/include/unistd.h:791: error: previous declaration of 'gethostname' was here
/root/include/unp.h:371: error: conflicting types for 'gethostname'
/usr/include/unistd.h:791: error: previous declaration of 'gethostname' was here




我用的LINUX是Fedora 3




怎么办怎么办....我是菜鸟......应该怎 么设呢?清大侠们详细一点阿说的...............万分急阿我..........................

/root/include/unp.h:7:66: ../config.h: 没有那个文件或目录:D

是啊,看看unp.h里 ../config.h的路径.

请问你们怎么设的呢?

旧问题改了,新问题又来了:
之前改了unp.h:

#include        "/root/include/config.h"        /* configuration options for current OS */
                                                        /* "../config.h" is generated by configure */



但一运行:


[root@localhost network]# gcc daytimetcpcliv6.c -L/root/include -I/root/include -lnew -o test
In file included from daytimetcpcliv6.c:1:
/root/include/unp.h:56:41: sys/event.h: 没有那个文件或目录
/root/include/unp.h:70:24: sys/filio.h: 没有那个文件或目录
/root/include/unp.h:73:25: sys/sockio.h: 没有那个文件或目录
/root/include/unp.h:81:24: net/if_dl.h: 没有那个文件或目录
In file included from daytimetcpcliv6.c:1:
/root/include/unp.h:489: warning: "struct kevent" declared inside parameter list
/root/include/unp.h:489: warning: its scope is only this definition or declaration, which is probably not what you want
[root@localhost network]#









我搜了N次,怎么也找不到:

sys/event.h
sys/filio.h
sys/sockio.h
net/if_dl.h:

其实,我觉得自己往里敲一点也不错,总是有效果的。

汗阿....................急死了..............

哪里有:


我搜了N次,怎么也找不到:

sys/event.h
sys/filio.h
sys/sockio.h
net/if_dl.h:

大家请帮帮忙啊...很急啊..我已经搞了它两个小时了

代码都没下全吧, 一个完整的 tar包都不需要自己设置路径, 解包后就可以编译了. 下个全的去吧

用如下命令试试:
find / -name event.h -print

[root@localhost src]# find / -name event.h -print
/lib/modules/2.6.9-1.667/build/include/config/ipmi/panic/event.h
/usr/include/kde/libkcal/event.h
/usr/include/kde/kparts/event.h


第一个event.h是:

#undef CONFIG_IPMI_PANIC_EVENT


/usr/include/kde/libkcal/event.h
/usr/include/kde/kparts/event.h 是:

#ifndef __kparts_event_h__
#define __kparts_event_h__

#include <qevent.h>

class QWidget;

namespace KParts
{
class Part;

/**
* Base class for all KParts events.
*/
class Event : public QCustomEvent
{
public:
  Event( const char *eventName );

  virtual const char *eventName() const;

  static bool test( const QEvent *event );
  static bool test( const QEvent *event, const char *name );
};

/**
* This event is sent to a Part when its GUI has been activated or deactivated.
* This is related to PartActivateEvent, but the difference is that
* GUIActivateEvent happens later (when the GUI is actually built),
* only for parts that have GUI elements, and only if using KParts::MainWindow.
* @see KParts::Part::guiActivateEvent()
*/
class GUIActivateEvent : public Event
{
public:
  GUIActivateEvent( bool activated ) : Event( s_strGUIActivateEvent ), m_bActivated( activated ) {}

  bool activated() const { return m_bActivated; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strGUIActivateEvent ); }

private:
  static const char *s_strGUIActivateEvent;
  bool m_bActivated;
};

/**
* This event is sent by the part manager when the active part changes.
* Each time the active part changes, it will send first a PartActivateEvent
* with activated=false, part=oldActivePart, widget=oldActiveWidget
* and then another PartActivateEvent
* with activated=true, part=newPart, widget=newWidget.
* @see KParts::Part::partActivateEvent
*/
class PartActivateEvent : public Event
{
public:
  PartActivateEvent( bool activated, Part *part, QWidget *widget ) : Event( s_strPartActivateEvent ), m_bActivated( activated ), m_part( part ), m_widget( widget ) {}

  bool activated() const { return m_bActivated; }

  Part *part() const { return m_part; }
  QWidget *widget() const { return m_widget; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strPartActivateEvent ); }

private:
  static const char *s_strPartActivateEvent;
  bool m_bActivated;
  Part *m_part;
  QWidget *m_widget;
};

/**
* This event is sent when a part is selected or deselected.
* @see KParts::PartManager::setSelectionPolicy
*/
class PartSelectEvent : public Event
{
public:
  PartSelectEvent( bool selected, Part *part, QWidget *widget ) : Event( s_strPartSelectEvent ), m_bSelected( selected ), m_part( part ), m_widget( widget ) {}

  bool selected() const { return m_bSelected; }

  Part *part() const { return m_part; }
  QWidget *widget() const { return m_widget; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strPartSelectEvent ); }

private:
  static const char *s_strPartSelectEvent;
  bool m_bSelected;
  Part *m_part;
  QWidget *m_widget;
};

} // namespace

#endif



哪一个是阿?

[root@localhost src]# find / -name event.h -print
/lib/modules/2.6.9-1.667/build/include/config/ipmi/panic/event.h
/usr/include/kde/libkcal/event.h
/usr/include/kde/kparts/event.h
find: /proc/4149/task: 没有那个文件或目录
[root@localhost src]#
                        

/lib/modules/2.6.9-1.667/build/include/config/ipmi/panic/event.h  是:


#undef CONFIG_IPMI_PANIC_EVENT



/usr/include/kde/libkcal/event.h
/usr/include/kde/kparts/event.h    是:


#ifndef __kparts_event_h__
#define __kparts_event_h__

#include <qevent.h>

class QWidget;

namespace KParts
{
class Part;

/**
* Base class for all KParts events.
*/
class Event : public QCustomEvent
{
public:
  Event( const char *eventName );

  virtual const char *eventName() const;

  static bool test( const QEvent *event );
  static bool test( const QEvent *event, const char *name );
};

/**
* This event is sent to a Part when its GUI has been activated or deactivated.
* This is related to PartActivateEvent, but the difference is that
* GUIActivateEvent happens later (when the GUI is actually built),
* only for parts that have GUI elements, and only if using KParts::MainWindow.
* @see KParts::Part::guiActivateEvent()
*/
class GUIActivateEvent : public Event
{
public:
  GUIActivateEvent( bool activated ) : Event( s_strGUIActivateEvent ), m_bActivated( activated ) {}

  bool activated() const { return m_bActivated; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strGUIActivateEvent ); }

private:
  static const char *s_strGUIActivateEvent;
  bool m_bActivated;
};

/**
* This event is sent by the part manager when the active part changes.
* Each time the active part changes, it will send first a PartActivateEvent
* with activated=false, part=oldActivePart, widget=oldActiveWidget
* and then another PartActivateEvent
* with activated=true, part=newPart, widget=newWidget.
* @see KParts::Part::partActivateEvent
*/
class PartActivateEvent : public Event
{
public:
  PartActivateEvent( bool activated, Part *part, QWidget *widget ) : Event( s_strPartActivateEvent ), m_bActivated( activated ), m_part( part ), m_widget( widget ) {}

  bool activated() const { return m_bActivated; }

  Part *part() const { return m_part; }
  QWidget *widget() const { return m_widget; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strPartActivateEvent ); }

private:
  static const char *s_strPartActivateEvent;
  bool m_bActivated;
  Part *m_part;
  QWidget *m_widget;
};

/**
* This event is sent when a part is selected or deselected.
* @see KParts::PartManager::setSelectionPolicy
*/
class PartSelectEvent : public Event
{
public:
  PartSelectEvent( bool selected, Part *part, QWidget *widget ) : Event( s_strPartSelectEvent ), m_bSelected( selected ), m_part( part ), m_widget( widget ) {}

  bool selected() const { return m_bSelected; }

  Part *part() const { return m_part; }
  QWidget *widget() const { return m_widget; }

  static bool test( const QEvent *event ) { return Event::test( event, s_strPartSelectEvent ); }

private:
  static const char *s_strPartSelectEvent;
  bool m_bSelected;
  Part *m_part;
  QWidget *m_widget;
};

} // namespace

#endif





哪一个才是阿?





[root@localhost src]# find / -name sys/filio.h -print
find: /proc/4149/task: 没有那个文件或目录
[root@localhost src]#   




包是全的了...tar的.


里面有个readme:

QUICK AND DIRTY
===============

Execute the following from the src/ directory:

    ./configure    # try to figure out all implementation differences

    cd lib         # build the basic library that all programs need
    make           # use "gmake" everywhere on BSD/OS systems

    cd ../libfree  # continue building the basic library
    make

    cd ../libroute # only if your system supports 4.4BSD style routing sockets   这个我make有错
    make           # only if your system supports 4.4BSD style routing sockets

    cd ../libxti   # only if your system supports XTI            根本就没有这个目录
    make           # only if your system supports XTI

    cd ../intro    # build and test a basic client program
    make daytimetcpcli
    ./daytimetcpcli 127.0.0.1                                     但最后还是能运行了

If all that works, you're all set to start compiling individual programs.

Notice that all the source code assumes tabs every 4 columns, not 8.

MORE DETAILS
============

5.  If you need to make any changes to the "unp.h" header, notice that it
    is a hard link in each directory, so you only need to change it once.

6.  Go into the "lib/" directory and type "make".  This builds the library
    "libunp.a" that is required by almost all of the programs.  There may
    be compiler warnings (see NOTES below).  This step is where you'll find
    all of your system's dependencies, and you must just update your cf/
    files from step 1, rerun "config" and do this step again.

6.  Go into the "libfree/" directory and type "make".  This adds to the
    "libunp.a" library.  The files in this directory do not #include
    the "unp.h" header, as people may want to use these functions
    independent of the book's examples.

8.  Once the library is made from steps 5 and 6, you can then go into any
    of the source code directories and make whatever program you are
    interested in.  Note that the horizontal rules at the beginning and
    end of each program listing in the book contain the directory name and
    filename.

    BEWARE: Not all programs in each directory will compile on all systems
    (e.g., the file src/advio/recvfromflags.c will not compile unless your
    system supports the IP_RECVDSTADDR socket option).  Also, not all files
    in each directory are included in the book.  Beware of any files with
    "test" in the filename: they are probably a quick test program that I
    wrote to check something, and may or may not work.

NOTES
-----

- Many systems do not have correct function prototypes for the socket
  functions, and this can cause many warnings during compilation.
  For example, Solaris 2.5 omits the "const" from the 2nd argument
  to connect().  Lots of systems use "int" for the length of socket
  address structures, while Posix.1g specifies "size_t".  Lots of
  systems still have the pointer argument to [sg]etsockopt() as a
  "char *" instead of a "void *", and this also causes warnings.

- SunOS 4.1.x: If you are using Sun's acc compiler, you need to run
  the configure program as

        CC=acc CFLAGS=-w CPPFLAGS=-w ./configure

  Failure to do this results in numerous system headers (<sys/sockio.h>)
  not being found during configuration, causing compile errors later.

- If your system supports IPv6 and you want to run the examples in the
  book using hostnames, you must install the latest BIND release.  You
  can get it from ftp://ftp.vix.com/pub/bind/release.  All you need from
  this release is a resolver library that you should then add to the
  LDLIBS and LDLIBS_THREADS lines.

- IPv6 support is still in its infancy.  There may be differences
  between the IPv6 sockets API specifications and what the vendor
  provides.  This may require hand tweaking, but should get better
  over time.

- If your system supports an older draft of the Posix pthreads standard,
  but configure detects the support of pthreads, you will have to disable
  this by hand.  Digital Unix V3.2C has this problem, for example, as it
  supports draft 4, not the final draft.

  To fix this, remove wrappthread.o from LIB_OBJS in "Make.defines" and
  don't try to build and run any of the threads programs.

COMMON DIFFERENCES
------------------

These are the common differences that I see in various headers that are
not "yet" at the level of Posix.1g or X/Open XNS Issue 5.

- getsockopt() and setsockopt(): 5th argument is not correct type.

- t_bind(): second argument is missing "const".

- t_connect(): second argument is missing "const".

- t_open(): first argument is missing "const".

- t_optmsmg(): second argument is missing "const".

- If your <xti.h> defines the members of the t_opthdr{} as longs,
  instead of t_uscalar_t, some of the printf formats of these value
  might generate warnings from your compiler, since you are printing
  a long without a corresponding long format specifier.

看目录里的readme...

行了,问题早已解决了

帮个忙啊,跟你发的站内短信不知道你收到了没有,我系统里没有filio.h
所以请帮忙把你的tar源码包发到我的邮箱行么?
[email]closetome123@yahoo.com.cn[/email]
非常感谢!!!!




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com