当前位置: 技术问答>linux和unix
《UNIX网络编程》中unp.h文件的使用问题
来源: 互联网 发布时间:2016-12-14
本文导语: 这两天开始学习Stevens先生的《UNIX网络编程》这本书,讲的很好。 就是书中所有程序都用了unp.h头文件,我也在网上找到了unp.h这个文件, 把网上的代码粘到Linux里面,但是编译时出错,原来unp.h文件里也用了其他文件...
这两天开始学习Stevens先生的《UNIX网络编程》这本书,讲的很好。
就是书中所有程序都用了unp.h头文件,我也在网上找到了unp.h这个文件,
把网上的代码粘到Linux里面,但是编译时出错,原来unp.h文件里也用了其他文件,比如:config.h,addrinfo.h
我大概浏览了一下附录,好像只给了unp.h文件的内容,那其他在哪儿?
我还在网上找到了另外版本的unp.h,是两个tar.gz包,在linux里解压后是unpv22e和unp12e 文件夹
这个里面的文件很多,估计是全的。
但我怎么用它呢?
请教高手帮我解决一下,无法用unp.h,那这本书的程序自己定义头文件虽能跑,但很不好。
就是书中所有程序都用了unp.h头文件,我也在网上找到了unp.h这个文件,
把网上的代码粘到Linux里面,但是编译时出错,原来unp.h文件里也用了其他文件,比如:config.h,addrinfo.h
我大概浏览了一下附录,好像只给了unp.h文件的内容,那其他在哪儿?
我还在网上找到了另外版本的unp.h,是两个tar.gz包,在linux里解压后是unpv22e和unp12e 文件夹
这个里面的文件很多,估计是全的。
但我怎么用它呢?
请教高手帮我解决一下,无法用unp.h,那这本书的程序自己定义头文件虽能跑,但很不好。
|
我这几天也在看他的书,也遇到了和你一样的问题
首先解释下unpv12e
其中v1是指<UNIX网络编程>的第一卷(还有第二卷关于进程的)
2e表示2nd edition第二版,所以你找到那两个包都是第二版的,一个是第一卷,一个是第二卷
建议你找个unpv13e的,因为比较新,所以兼容问题比较少吧
找到的代码包unpv13e,然后按照下列步骤操作就可以了
0. To extract the source directories from the unpv12e.tar.gz tar file,
execute:
cd
gunzip -c unpv12e.tar.gz | tar -xvf -
This creates a directory named unpv12e/ containing about 40 other
directories. The names of these 40 other directories are what appears
in the horizontal rules that start and end each source code listing
in the book. For example, the file unpv12e/intro/daytimetcpcli.c
corresponds to the source code in Figure 1.5 (Page 6) of the book.
1. There is a "unp.h" header that appears in every one of the 40 directories.
If you need to make any changes to this "unp.h" header, notice that it
is a hard link in each directory, so you only need to change it once.
Hard links are also used with the other "unp*.h" headers.
2. I used the GNU autoconf package to generate a shell script named
"configure" that you must execute. This script will try and figure
out lots of characteristics of your system.
This script builds two important files "Make.defines" and "config.h".
Each "Makefile" in each of the 40 directories includes "Make.defines",
and the first #include done by "unp.h" is of "config.h".
These two files *must* be set correctly for your system, or you will
not be able to build the source code.
3. 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).
Go into the "libfree/" directory and type "make". This adds to the
"libunp.a" library. Similarly go into the "libgai", "libroute" and
"libxti" directories and "make". The "libroute" directory should only
be used if your system supports 4.4BSD-style routing sockets. The
"libxti" directory should only be used if your system supports XTI
(not TLI).
4. Once the library is made, you can then go into any of the source code
directories and make whatever program you are interested in. A good
starting poing is the "intro" directory and "make daytimetcpcli".
这是一个README文档中摘抄的
我按照上面步骤操作后也有几个错误,正在解决中
就知道这些了
首先解释下unpv12e
其中v1是指<UNIX网络编程>的第一卷(还有第二卷关于进程的)
2e表示2nd edition第二版,所以你找到那两个包都是第二版的,一个是第一卷,一个是第二卷
建议你找个unpv13e的,因为比较新,所以兼容问题比较少吧
找到的代码包unpv13e,然后按照下列步骤操作就可以了
0. To extract the source directories from the unpv12e.tar.gz tar file,
execute:
cd
gunzip -c unpv12e.tar.gz | tar -xvf -
This creates a directory named unpv12e/ containing about 40 other
directories. The names of these 40 other directories are what appears
in the horizontal rules that start and end each source code listing
in the book. For example, the file unpv12e/intro/daytimetcpcli.c
corresponds to the source code in Figure 1.5 (Page 6) of the book.
1. There is a "unp.h" header that appears in every one of the 40 directories.
If you need to make any changes to this "unp.h" header, notice that it
is a hard link in each directory, so you only need to change it once.
Hard links are also used with the other "unp*.h" headers.
2. I used the GNU autoconf package to generate a shell script named
"configure" that you must execute. This script will try and figure
out lots of characteristics of your system.
This script builds two important files "Make.defines" and "config.h".
Each "Makefile" in each of the 40 directories includes "Make.defines",
and the first #include done by "unp.h" is of "config.h".
These two files *must* be set correctly for your system, or you will
not be able to build the source code.
3. 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).
Go into the "libfree/" directory and type "make". This adds to the
"libunp.a" library. Similarly go into the "libgai", "libroute" and
"libxti" directories and "make". The "libroute" directory should only
be used if your system supports 4.4BSD-style routing sockets. The
"libxti" directory should only be used if your system supports XTI
(not TLI).
4. Once the library is made, you can then go into any of the source code
directories and make whatever program you are interested in. A good
starting poing is the "intro" directory and "make daytimetcpcli".
这是一个README文档中摘抄的
我按照上面步骤操作后也有几个错误,正在解决中
就知道这些了
|
就用比较全的那个试一试吧.
解压后放在某个目录下,编译的时候用-I把该目录包含进来。
解压后放在某个目录下,编译的时候用-I把该目录包含进来。
|
unp.h里应该有一个宏的!
|
为什么不用就不行呢?用了就好么?
为什么要照书上把代码敲一遍呢? 理解了, 然后自己做不是更好么?
为什么要照书上把代码敲一遍呢? 理解了, 然后自己做不是更好么?