学习编程这东西,看代码,改代码,运行代码这样才能学到实际东西!本书说在www.unpbook.com可以获取源码,不过打不开!所以google

unpv13e.tar.gz

并在网络上找到了:源码:http://code.google.com/p/stid/downloads/detail?name=unpv13e.tar.gz&can=2&q=

现在就是使用的问题了!

关于在windows下的问题

既然是unix网络编程,直接在windows下运行当然是行不通的!(问:那还学这个干嘛!?? 你说呢,我们学的是思想和方法,window网络编程其实差异不大)

不过在windows下装个UNIX模拟器cygwin貌似是一个不错的选择!也有人用这个模拟器搭建UNIX网络编程平台,不过对初学者有一定难度!(cygwin是个好东西呀!)

关于在Linux 下的使用问题

Linux也是UNIX,当然没问题!现在说明如何使用书本源码unpv13e.tar.gz问题。

首先,解压源码,这里是解压到当前目录:acer@ubuntu:~$ tar -xvf unpv13e.tar.gz

其后,建议去阅读解压后目录unpv13e下的README文档!

README文档内容如下:(ubuntu下执行红色部分即可)

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 .4BSD style routing sockets
make # only if your system supports .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 columns, not . MORE DETAILS
============ . 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. . 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 , rerun "config" and do this step again. . 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. . Once the library is made from steps and , 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 , 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 . - 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.

注意:以后我们都用make编译源代码

最后运行:./daytimetcpcli 127.0.0.1如下

acer@ubuntu:~/jwt/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
connect error: Connection refused

发现报错:connect error: Connection refused

这种情况说明服务器没有启动daytime服务!那Ubuntu如何启动,daytime服务呢?

Ubuntu启动daytime服务

1. sudo apt-get install xinetd
2. sudo vi /etc/xinetd.d/daytime, 把 disable = yes to no
3. sudo /etc/init.d/xinetd restart

在运行 ./daytimetcpcli 127.0.0.1

出现结果!!

参考:http://blog.csdn.net/baikaishui525/article/details/7013907

根目录下生成Make.defines如下:

#
# This file is generated by autoconf from "Make.defines.in".
#
# This is the "Make.defines" file that almost every "Makefile" in the
# source directories below this directory include.
# The "../" in the pathnames actually refer to this directory, since
# "make" is executed in all the subdirectories of this directory.
#
# System = i686-pc-linux-gnu CC = gcc
CFLAGS = -I../lib -g -O2 -D_REENTRANT -Wall
LIBS = ../libunp.a -lpthread
LIBS_XTI = ../libunpxti.a ../libunp.a -lpthread
RANLIB = ranlib # Following is the main library, built from all the object files
# in the lib/ and libfree/ directories.
LIBUNP_NAME = ../libunp.a # Following is the XTI library, built from all the object files
# in the libxti/ directory.
LIBUNPXTI_NAME = ../libunpxti.a # Following are all the object files to create in the lib/ directory.
LIB_OBJS = connect_nonb.o connect_timeo.o daemon_inetd.o daemon_init.o dg_cli.o dg_echo.o error.o get_ifi_info.o gf_time.o host_serv.o family_to_level.o mcast_leave.o mcast_join.o mcast_get_if.o mcast_get_loop.o mcast_get_ttl.o mcast_set_if.o mcast_set_loop.o mcast_set_ttl.o my_addrs.o read_fd.o readline.o readn.o readable_timeo.o rtt.o signal.o signal_intr.o sock_bind_wild.o sock_cmp_addr.o sock_cmp_port.o sock_ntop.o sock_ntop_host.o sock_get_port.o sock_set_addr.o sock_set_port.o sock_set_wild.o sockfd_to_family.o str_cli.o str_echo.o tcp_connect.o tcp_listen.o tv_sub.o udp_client.o udp_connect.o udp_server.o wraplib.o wrapsock.o wrapstdio.o wrappthread.o wrapunix.o write_fd.o writen.o writable_timeo.o # Following are all the object files to create in the libfree/ directory.
LIBFREE_OBJS = in_cksum.o inet_ntop.o inet_pton.o # Following are all the object files to create in the libgai/ directory.
LIBGAI_OBJS = # Following are all the object files to create in the libroute/ directory.
LIBROUTE_OBJS = get_rtaddrs.o if_indextoname.o if_nameindex.o if_nametoindex.o net_rt_iflist.o net_rt_dump.o sock_masktop.o # Following are all the object files to create in the libxti/ directory.
LIBXTI_OBJS = wrapxti.o xti_accept.o xti_flags_str.o xti_getopt.o xti_ntop.o xti_ntop_host.o xti_rdwr.o xti_setopt.o xti_str_opts.o xti_tlook_str.o CLEANFILES = core core.* *.core *.o temp.* *.out typescript* \
*.lc *.lh *.bsdi *.sparc *.uw

lib文件夹makefie内容:

include ../Make.defines

all: ${LIB_OBJS}
ar rv ${LIBUNP_NAME} $?
${RANLIB} ${LIBUNP_NAME}

clean:
rm -f ${PROGS} ${CLEANFILES}

intro文件夹下的lib文件Makefile如下:

include ../Make.defines

PROGS =    daytimetcpcli daytimetcpcli1 daytimetcpcli2 daytimetcpcli3 \
daytimetcpsrv daytimetcpsrv1 daytimetcpsrv2 daytimetcpsrv3 \
daytimetcpcliv6 daytimetcpsrvv6 \
byteorder all: ${PROGS} daytimetcpcli: daytimetcpcli.o
${CC} ${CFLAGS} -o $@ daytimetcpcli.o ${LIBS} daytimetcpcli1: daytimetcpcli1.o
${CC} ${CFLAGS} -o $@ daytimetcpcli1.o ${LIBS} daytimetcpcli2: daytimetcpcli2.o
${CC} ${CFLAGS} -o $@ daytimetcpcli2.o ${LIBS} daytimetcpcli3: daytimetcpcli3.o
${CC} ${CFLAGS} -o $@ daytimetcpcli3.o ${LIBS} daytimetcpsrv: daytimetcpsrv.o
${CC} ${CFLAGS} -o $@ daytimetcpsrv.o ${LIBS} daytimetcpsrv1: daytimetcpsrv1.o
${CC} ${CFLAGS} -o $@ daytimetcpsrv1.o ${LIBS} daytimetcpsrv2: daytimetcpsrv2.o
${CC} ${CFLAGS} -o $@ daytimetcpsrv2.o ${LIBS} daytimetcpsrv3: daytimetcpsrv3.o
${CC} ${CFLAGS} -o $@ daytimetcpsrv3.o ${LIBS} daytimetcpcliv6: daytimetcpcliv6.o
${CC} ${CFLAGS} -o $@ daytimetcpcliv6.o ${LIBS} daytimetcpsrvv6: daytimetcpsrvv6.o
${CC} ${CFLAGS} -o $@ daytimetcpsrvv6.o ${LIBS} byteorder: byteorder.o
${CC} ${CFLAGS} -o $@ byteorder.o ${LIBS} clean:
rm -f ${PROGS} ${CLEANFILES}

在select下,编译某个包含unp.h的文件。

gcc -c strcliselect01.c  -I ../lib

ubuntu搭建:

http://lingshaohuprose.blog.163.com/blog/static/169579782201232505248560/

http://blog.csdn.net/hongkangwl/article/details/24013863

http://blog.sina.com.cn/s/blog_a43aba560101a7gf.html

《 UNIX网络编程》源码的使用的更多相关文章

  1. UNIX网络编程 卷2:进程间通信

    这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两 ...

  2. 《UNIX网络编程 卷1》之"学习环境搭建"(CentOS 7)

    <UNIX网络编程 卷1>的源码可以从www.unpbook.com下载得到.解压之后的目录为unpv13e. 详细步骤 编译 进入unpv13e目录,按如下步骤编译: ./configu ...

  3. unix网络编程源码编译问题

    ​##获得更多资料欢迎进入我的网站或者 csdn或者博客园 今天在温习计算机网络时,突然将我很久前买的<unix网络编程第三版卷一>拿出来看看了.放了两年了,哈哈.主要讲的套接字,之前编写 ...

  4. UNIX网络编程 环境搭建

    配置好动态链接库或者静态链接库 1,下载UNIX网络编程书的头文件及示例源码unpv13e 2    按照readme来编译 Execute the following from the src/ d ...

  5. UNIX网络编程---传输层:TCP、UDP、SCTP(二)

    UNIX网络编程----传输层:TCP.UDP.SCTP 一.概述 本章的焦点是传输层:包括TCP.UDP.和SCTP(流控制传输协议).SCTP是一个较新的协议,最初设计用于跨因特网传输电话信令. ...

  6. UNIX网络编程---简介

    UNIX网络编程---简介 一.           概述 a)       在编写与计算机通信的程序时,首先要确定的就是和计算机通信的协议,从高层次来确定通信由哪个程序发起以及响应在合适产生.大多数 ...

  7. UNIX网络编程——原始套接字的魔力【续】

    如何从链路层直接发送数据帧 上一篇里面提到的是从链路层"收发"数据,该篇是从链路层发送数据帧. 上一节我们主要研究了如何从链路层直接接收数据帧,可以通过bind函数来将原始套接字绑 ...

  8. UNIX网络编程——UDP 的connect函数(改进版)

    上一篇我们提到,除非套接字已连接,否则异步错误是不会返回到UDP套接字的.我们确实可以给UDP套接字调用connect,然而这样做的结果却与TCP连接大相径庭:没有三次握手.内核只是检查是否存在立即可 ...

  9. UNIX网络编程——ICMP报文分析:端口不可达

    ICMP的一个规则是,ICMP差错报文必须包括生成该差错报文的数据报IP首部(包含任何选项),还必须至少包括跟在该IP首部后面的前8个字节(包含源端口和目的端口).在我们的例子中,跟在IP首部后面的前 ...

随机推荐

  1. 基于FPGA的按键扫描程序

    最近在学习FPGA,就试着写了个按键扫描的程序.虽说有过基于单片机的按键扫描处理经验,对于按键的处理还是有一些概念.但是单片机程序的编写通常都采用C写,也有用汇编,而FPGA却是采用VHDL或者Ver ...

  2. BroadcastReceiver

    BroadcastReceiver 广播接受者 Android中, Broadcast是一种数据传递的方式/通信方式. Brodadcast 是Android 系统组件之一 广播的特性 1. 由一个发 ...

  3. get与post区别

    在Ajax原理中,HTTP请求方法:get——用于获取数据(e.g. 浏览帖子):post——用于上传数据(e.g. 用户注册,上传图片) get 是在url里传数据,但这样做的安全性很差,并且容量不 ...

  4. Android开发技巧:像QQ一样输入表情图像

     EditText和TextView一样,也可以进行图文混排.所不同的是,TextView只用于显示图文混排效果,而EditText不仅可显示, 也可混合输入文字和图像,让我们先回顾一下图5.2所示的 ...

  5. 6个好用的Web开发工具

    在过去的几年间,涌现出了很多Web开发工具,它们大多还是比较吸引人的,方便了我们的工作.我们可以学习一下这些新东西,短时间就可以拓宽思路(PHP100推荐:学习10分钟,改变你的程序员生涯).这些应用 ...

  6. 开始学习python

    刚刚离开学校,到公司实习,发现所有的技术都是崭新的,所有的工具都是熟悉中带着陌生. 就像是孤身一人到了一个曾经只闻其名的偌大城市,看什么都觉得新鲜,做什么都心有畏惧.幸好 搞软件并没有那么多人情世故, ...

  7. 《WPF程序设计指南》读书笔记——第6章 Dock与Grid

    1.DockPanel面板 using System; using System.Windows; using System.Windows.Controls; using System.Window ...

  8. PAT乙级真题1005. 继续(3n+1)猜想 (25)(解题)

    原题: 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证 ...

  9. LINQ to XML学习笔记

    一.XML基础知识 1.XML:可扩展标记语言 Extensible Markup Language ,提供了一种保存数据的格式,数据可以通过这种格式很容易地在不同的应用程序之间实现共享. 2.使用X ...

  10. 【git】借助github学习成果

    1.创建分支 git branch dev   //创建分支 git checkout dev  //切换分支 或者用一句  git checkout -b dev 删除一个分支  git check ...