UNIX网络编程(unp)源码下载和编译
来源:互联网 发布:安卓速读软件 编辑:程序博客网 时间:2024/06/05 06:21
源代码下载地址
http://www.unpbook.com/src.html
该连接为UNIX网络编程,卷一,第三版的源代码。
编译源代码
把下载好的代码,放到UNIX系统中。或者直接在你的UNIX系统中使用下面的命令下载:
curl http://www.unpbook.com/unpv13e.tar.gz > /dev/zero
下载完成后会看到文件unpv13e.tar.gz文件,使用下面的命令解压该文件:
tar -xvf unpv13e.tar.gz
解压后会发现多了一个名字叫做unpv13e的目录,进入到该目录中,准备开始编译。
怎么编译呢?作者已经在目录中包含了一个README文件,告诉我们如何编译和使用。
使用vi或vim打开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 # 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.1If 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 arenot "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文件已经写得很清楚了,在源码目录下,第一步运行下面的命令,该命令会去检查你的系统是否支持某些功能,并生成相应的配置头文件config.h等等。
./configure
第二步编译所有程序都会使用的基础库:
cd libmake
第三步继续编译基础库,该基础库不依赖项目中的代码,可以独立出来给其它项目使用:
cd ../libfreemake
可选的编译内容,该部分是可选的,当你的系统支持下面的功能时才能编译成功:
cd ../libroute # only if your system supports 4.4BSD style routing socketsmake # only if your system supports 4.4BSD style routing socketscd ../libxti # only if your system supports XTImake # only if your system supports XTI
最后,编译introduce章节的代码,并尝试运行:
cd ../intro # build and test a basic client programmake daytimetcpcli./daytimetcpcli 127.0.0.1
注意:在运行./daytimetcpcli 127.0.0.1
命令可能会出现connect error: Connection refused
的错误,是因为对应的服务没有启动,但是没关系,你的程序已经可以运行起来了。
阅读全文
2 0
- UNIX网络编程(unp)源码下载和编译
- 《网络编程》关于 UNIX网络编程 卷1 的 unp.h 和源码编译问题
- 《网络编程》关于 UNIX网络编程 卷1 的 unp.h 和源码编译问题
- 《网络编程》关于 UNIX网络编程 卷1 的 unp.h 和源码编译问题
- UNP Unix网络编程卷2源码编译问题
- unix网络编程(UNP),unp.h生成config.h
- UNIX网络编程(配置unp.h)
- UNIX网络编程(一)-unp.h文件的编译
- 《unix网络编程》源码编译
- 《UNIX网络编程》中的unp.h和config.h
- Unix网络编程(卷二)unpv 源码下载及编译报错解决
- unix网络编程(第三版)中的unp.h
- unix网络编程(unp)----源代码环境搭建
- unix网络编程(第三版)中的unp.h
- Xcode下配置UNIX网络编程(UNP)环境
- unix网络编程书籍源码编译和测试
- UNIX网络编程 UNP 卷2 第一章
- 《Unix 网络编程》 unp.h头文件
- HDU3966 Aragorn's Story(树链剖分+线段树)
- phandle
- ROS与Python入门教程-制作Makefile文件
- Android 判断当前系统语言
- Ubuntu 16.04中安装Sublime Text 3并安装Package Control插件
- UNIX网络编程(unp)源码下载和编译
- 洛谷 2898 [USACO08JAN]haybale猜测Haybale Guessing
- 第八周 【项目8-稀疏矩阵的三元组表示的实现及应用】
- 数据库表索引创建脚本
- 判断网络状态
- 第十周项目1-验证算法(1)
- Android Studio出现Failed to open zip file问题的解决方法
- matlab 读arff文件时的问题
- 第十周 项目2- 二叉树构造算法的验证