记录一次配置unix网络编程环境的过程和遇到的问题

时间:2022-04-13 16:44:41

记录一次搭建unix网络编程环境过程中遇到的问题和总结

计算机环境虚拟机 linuxmint-18-xfce-64bit

1.打开unix网络编程.iso
把目录下的文件复制到某一目录,修改权限,可命令可鼠标操作。

2.

s@ss-Linux ~/unix/unpv13e $ sudo su
[sudo] s 的密码:
ss-Linux unpv13e # ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for C compiler default output... configure: error: C compiler cannot create executables
See `config.log' for more details.

很明显在检测环境时gcc无法生成可执行文件。
于是我又执行了一次configure,还是同样的结果。
我查看了一下config.log也看不大明白。
上网翻博客。。。也没查到相关内容。

3.突发奇想,编译器出现问题,不如换个编译器。

s-Linux unpv13e # apt-get install g++
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
binutils cpp-5 g++-5 gcc-5 gcc-5-base gcc-5-base:i386 libasan2 libatomic1
libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libgcc-5-dev libgfortran3
libgomp1 libitm1 liblsan0 libmpx0 libquadmath0 libstdc++-5-dev
libstdc++6:i386 libstdc++6 libtsan0 libubsan0
建议安装:
binutils-doc gcc-5-locales g++-multilib g++-5-multilib gcc-5-doc
libstdc++6-5-dbg gcc-5-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg
libatomic1-dbg libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg
libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg glibc-doc libstdc++-5-doc
下列【新】软件包将被安装:
g++ g++-5 libc-dev-bin libc6-dev libstdc++-5-dev
下列软件包将被升级:
binutils cpp-5 gcc-5 gcc-5-base gcc-5-base:i386 libasan2 libatomic1 libcc1-0
libcilkrts5 libgcc-5-dev libgfortran3 libgomp1 libitm1 liblsan0 libmpx0
libquadmath0 libstdc++6:i386 libstdc++6 libtsan0 libubsan0 。。。。。。。。(略)

上面可以看到gcc等,希望有用。

4.再次执行configure

ss-Linux unpv13e # ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for ranlib... ranlib
checking for pthread_create in -lpthread... yes
checking for t_open in -lnsl... no
checking for library containing socket... none required
checking for /usr/local/bind/lib/libbind.a... no
checking for /root/libbind.a... no
checking for /root/libresolv.a... no
checking for res_init in -lresolv... no
checking for t_open in -lxti... no
checking for /root/libunp.a... no
checking for /root/libunpxti.a... no
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/socket.h... yes
checking for sys/time.h... yes
checking for time.h... yes
checking for netinet/in.h... yes
checking for arpa/inet.h... yes
checking for errno.h... yes
checking for fcntl.h... yes
checking for netdb.h... yes
checking for signal.h... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for sys/stat.h... yes
checking for sys/uio.h... yes
checking for unistd.h... yes
checking for sys/wait.h... yes
checking for sys/un.h... yes
checking for sys/param.h... yes
checking for sys/select.h... yes
checking for sys/sysctl.h... yes
checking for poll.h... yes
checking for sys/event.h... no
checking for strings.h... yes
checking for sys/ioctl.h... yes
checking for sys/filio.h... no
checking for sys/sockio.h... no
checking for pthread.h... yes
checking for net/if_dl.h... no
checking for xti.h... no
checking for xti_inet.h... no
checking for netconfig.h... no
checking for netdir.h... no
checking for stropts.h... yes
checking whether time.h and sys/time.h may both be included... yes
checking if uint8_t defined... yes
checking if int16_t defined... yes
checking if uint16_t defined... yes
checking if int32_t defined... yes
checking if uint32_t defined... yes
checking if size_t defined... yes
checking if ssize_t defined... yes
checking if socklen_t defined... yes
checking if sa_family_t defined... yes
checking if t_scalar_t defined... yes
checking if t_uscalar_t defined... yes
checking for struct sockaddr.sa_len... no
checking for struct sockaddr_storage... yes
checking for struct sockaddr_storage.ss_family... yes
checking for struct msghdr.msg_control... yes
checking for struct ifreq.ifr_mtu... yes
checking for getaddrinfo function prototype in netdb.h... yes
checking for getnameinfo function prototype in netdb.h... yes
checking for gethostname function prototype in unistd.h... yes
checking for getrusage function prototype in sys/resource.h... yes
checking for hstrerror function prototype in netdb.h... yes
checking for if_nametoindex function prototype in net/if.h... yes
checking for inet_aton function prototype in arpa/inet.h... yes
checking for inet_pton function prototype in arpa/inet.h... yes
checking for pselect function prototype in sys/select.h... yes
checking for snprintf function prototype in stdio.h... yes
checking for sockatmark function prototype in sys/socket.h... yes
checking for struct addrinfo... yes
checking for struct if_nameindex... yes
checking for struct sockaddr_dl... no
checking for struct timespec... yes
checking for /dev/tcp... no
checking for /dev/xti/tcp... no
checking for /dev/streams/xtiso/tcp... no
checking for bzero... yes
checking for getaddrinfo... yes
checking for gethostname... yes
checking for gethostbyname2... yes
checking for gethostbyname_r... yes
checking for getnameinfo... yes
checking for hstrerror... yes
checking for if_nametoindex... yes
checking for inet_aton... yes
checking for inet_pton... yes
checking for inet6_rth_init... yes
checking for kqueue... no
checking for kevent... no
checking for mkstemp... yes
checking for poll... yes
checking for pselect... yes
checking for snprintf... yes
checking for sockatmark... yes
checking for vsnprintf... yes
checking for IPv4 support... yes
checking for IPv6 support... yes
checking for Unix domain sockets... yes
checking for multicast support... yes
checking for -I/root/doc/unp2ev1/src/include... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating Make.defines
config.status: creating config.h

5.明显通过检测生成了

Makefile
Make.defines
config.h

6.根据readme的指示,编译库文件

ss-Linux unpv13e # cd lib
ss-Linux lib # make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o connect_timeo.o connect_timeo.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daemon_inetd.o daemon_inetd.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daemon_init.o daemon_init.c
daemon_init.c: In function ‘daemon_init’:
daemon_init.c:34:2: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir("/"); /* change working directory */
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o dg_cli.o dg_cli.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o dg_echo.o dg_echo.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o error.o error.c
error.c: In function ‘err_doit’:
error.c:102:17: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(level, buf);
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o get_ifi_info.o get_ifi_info.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o gf_time.o gf_time.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o host_serv.o host_serv.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o family_to_level.o family_to_level.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_leave.o mcast_leave.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_join.o mcast_join.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_if.o mcast_get_if.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_loop.o mcast_get_loop.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_ttl.o mcast_get_ttl.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_if.o mcast_set_if.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_loop.o mcast_set_loop.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_ttl.o mcast_set_ttl.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o my_addrs.o my_addrs.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o read_fd.o read_fd.c
read_fd.c: In function ‘read_fd’:
read_fd.c:45:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*recvfd = *((int *) CMSG_DATA(cmptr));
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readline.o readline.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readn.o readn.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readable_timeo.o readable_timeo.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o rtt.o rtt.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o signal.o signal.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o signal_intr.o signal_intr.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_bind_wild.o sock_bind_wild.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_cmp_addr.o sock_cmp_addr.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_cmp_port.o sock_cmp_port.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_ntop.o sock_ntop.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_ntop_host.o sock_ntop_host.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_get_port.o sock_get_port.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_addr.o sock_set_addr.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_port.o sock_set_port.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_wild.o sock_set_wild.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sockfd_to_family.o sockfd_to_family.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o str_cli.o str_cli.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o str_echo.o str_echo.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tcp_connect.o tcp_connect.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tcp_listen.o tcp_listen.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tv_sub.o tv_sub.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_client.o udp_client.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_connect.o udp_connect.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_server.o udp_server.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wraplib.o wraplib.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapsock.o wrapsock.c
wrapsock.c: In function ‘Inet6_rth_space’:
wrapsock.c:81:8: warning: implicit declaration of function ‘inet6_rth_space’ [-Wimplicit-function-declaration]
ret = inet6_rth_space(type, segments);
^
wrapsock.c: In function ‘Inet6_rth_init’:
wrapsock.c:93:8: warning: implicit declaration of function ‘inet6_rth_init’ [-Wimplicit-function-declaration]
ret = inet6_rth_init(rthbuf, rthlen, type, segments);
^
wrapsock.c:93:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
ret = inet6_rth_init(rthbuf, rthlen, type, segments);
^
wrapsock.c: In function ‘Inet6_rth_add’:
wrapsock.c:103:6: warning: implicit declaration of function ‘inet6_rth_add’ [-Wimplicit-function-declaration]
if (inet6_rth_add(rthbuf, addr) < 0)
^
wrapsock.c: In function ‘Inet6_rth_reverse’:
wrapsock.c:110:6: warning: implicit declaration of function ‘inet6_rth_reverse’ [-Wimplicit-function-declaration]
if (inet6_rth_reverse(in, out) < 0)
^
wrapsock.c: In function ‘Inet6_rth_segments’:
wrapsock.c:119:8: warning: implicit declaration of function ‘inet6_rth_segments’ [-Wimplicit-function-declaration]
ret = inet6_rth_segments(rthbuf);
^
wrapsock.c: In function ‘Inet6_rth_getaddr’:
wrapsock.c:131:8: warning: implicit declaration of function ‘inet6_rth_getaddr’ [-Wimplicit-function-declaration]
ret = inet6_rth_getaddr(rthbuf, idx);
^
wrapsock.c:131:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
ret = inet6_rth_getaddr(rthbuf, idx);
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapstdio.o wrapstdio.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrappthread.o wrappthread.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapunix.o wrapunix.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o write_fd.o write_fd.c
write_fd.c: In function ‘write_fd’:
write_fd.c:24:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*((int *) CMSG_DATA(cmptr)) = sendfd;
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o writen.o writen.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o writable_timeo.o writable_timeo.c
ar rv ../libunp.a 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
ar: 正在创建 ../libunp.a
a - connect_nonb.o
a - connect_timeo.o
a - daemon_inetd.o
a - daemon_init.o
a - dg_cli.o
a - dg_echo.o
a - error.o
a - get_ifi_info.o
a - gf_time.o
a - host_serv.o
a - family_to_level.o
a - mcast_leave.o
a - mcast_join.o
a - mcast_get_if.o
a - mcast_get_loop.o
a - mcast_get_ttl.o
a - mcast_set_if.o
a - mcast_set_loop.o
a - mcast_set_ttl.o
a - my_addrs.o
a - read_fd.o
a - readline.o
a - readn.o
a - readable_timeo.o
a - rtt.o
a - signal.o
a - signal_intr.o
a - sock_bind_wild.o
a - sock_cmp_addr.o
a - sock_cmp_port.o
a - sock_ntop.o
a - sock_ntop_host.o
a - sock_get_port.o
a - sock_set_addr.o
a - sock_set_port.o
a - sock_set_wild.o
a - sockfd_to_family.o
a - str_cli.o
a - str_echo.o
a - tcp_connect.o
a - tcp_listen.o
a - tv_sub.o
a - udp_client.o
a - udp_connect.o
a - udp_server.o
a - wraplib.o
a - wrapsock.o
a - wrapstdio.o
a - wrappthread.o
a - wrapunix.o
a - write_fd.o
a - writen.o
a - writable_timeo.o
ranlib ../libunp.a

7.编译库文件

ss-Linux lib # cd ../libfree
ss-Linux libfree # make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o in_cksum.o in_cksum.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c
inet_ntop.c: In function ‘inet_ntop’:
inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype
size_t size;
^
In file included from inet_ntop.c:27:0:
/usr/include/arpa/inet.h:64:20: error: prototype declaration
extern const char *inet_ntop (int __af, const void *__restrict __cp,
^
<builtin>: recipe for target 'inet_ntop.o' failed
make: *** [inet_ntop.o] Error 1

错误原因可以看出是
类型不对。
通过搜索 可以知道

ANSCI创造了size_t数据类型,它用作malloc的唯一参数(待分配的字节数),或者作为read和write的第三个参数(待读写的字节数)。在32位系统中,size_t是一个32位值,但是64位系统中它必须是一个64位值,以便发挥更大寻址模型的优势。这意味着64位系统中也许含有一个把size_t定义为unsigned long的typedef指令。联网API存在如下问题:POSIX.1g的某些草案规定,存放套接字的地址结构大小的函数参数具有size_t的数据类型(如bind和connect的第三个参数)。某些XTI结构也含有数据类型为long的成员(如t_info和t_opthdr结构)。如果这些规定不加修改,当unix从ILP32模型转为LP64模型时,size_t和long都将从32位变成64位值,这两个列子实际上并不需要使用64的数据类型:套接字的地址结构的长度最多也就几百个字节,给XTI的结构成员使用long数据类型是个错误。
处理这些情况的办法是使用专门设计的数据类型。套接字API对套接字地址结构的长度使用socklen_t数据类型,XTI则使用t_scalar_t和t_uscalar_t数据类型。不把这些值由32位改为64位的理由是易于为那些已经在32位系统上编译的应用程序提供在新的64位系统中的二进制代码的兼容性

我的电脑是64位。

解决办法
找到inet_ntop.c第61行 size_t size ->改成 socklen_t size)

8.重新编译

ss-Linux libfree # make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c
/usr/include/arpa/inet.h: In function ‘inet_ntop’:
inet_ntop.c:152:23: warning: ‘best.len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (best.base == -1 || cur.len > best.len)
^
inet_ntop.c:123:28: note: ‘best.len’ was declared here
struct { int base, len; } best, cur;
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_pton.o inet_pton.c
ar rv ../libunp.a in_cksum.o inet_ntop.o inet_pton.o
a - in_cksum.o
a - inet_ntop.o
a - inet_pton.o
ranlib ../libunp.a

9.路由套接字 库

ss-Linux libfree # cd ../libroute
ss-Linux libroute # make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o get_rtaddrs.o get_rtaddrs.c
In file included from get_rtaddrs.c:1:0:
unproute.h:3:45: fatal error: net/if_dl.h: 没有那个文件或目录
compilation terminated.
<builtin>: recipe for target 'get_rtaddrs.o' failed
make: *** [get_rtaddrs.o] Error 1

又出错了,
c - What package do i need to install for using routing sockets? - Stack Overflow
http://*.com/questions/1520649/what-package-do-i-need-to-install-for-using-routing-sockets

Please note, you DO NOT need to make in that folder "libroute"

See the Document:

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
Linux is not BSD style routing, just go to ../intro and build examples~!

好吧,编译到此结束。

10.打开lib目录
修改unp.h
     #include "../config.h"
改成
     #include "config.h"

11.返回unpv13e文件夹

ss-Linux unpv13e # cp config.h /usr/local/include
ss-Linux unpv13e # cp lib/unp.h /usr/local/include
ss-Linux unpv13e # sudo cp libunp.a /usr/local/lib
ss-Linux unpv13e # cd intro

12.到此搭建完毕,测试一下

ss-Linux intro # gcc daytimetcpcli.c -o 获取时间
/tmp/cciq4Jvt.o:在函数‘main’中:
daytimetcpcli.c:(.text+0x3b):对‘err_quit’未定义的引用
daytimetcpcli.c:(.text+0x6d):对‘err_sys’未定义的引用
daytimetcpcli.c:(.text+0xe5):对‘err_quit’未定义的引用
daytimetcpcli.c:(.text+0x114):对‘err_sys’未定义的引用
daytimetcpcli.c:(.text+0x153):对‘err_sys’未定义的引用
daytimetcpcli.c:(.text+0x196):对‘err_sys’未定义的引用
collect2: error: ld returned 1 exit status

又错。。。。。
按道理头文件,库文件都弄好了啊。......

有个makefile,make,make,make编译成功。[上面的问题,第二天解决了,请翻到最后。初学者很无奈。。。。。。。

ss-Linux intro # make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli.o daytimetcpcli.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli1.o daytimetcpcli1.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli1 daytimetcpcli1.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli2.o daytimetcpcli2.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli2 daytimetcpcli2.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli3.o daytimetcpcli3.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli3 daytimetcpcli3.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv.o daytimetcpsrv.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv daytimetcpsrv.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv1.o daytimetcpsrv1.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv1 daytimetcpsrv1.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv2.o daytimetcpsrv2.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv2 daytimetcpsrv2.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv3.o daytimetcpsrv3.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv3 daytimetcpsrv3.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcliv6.o daytimetcpcliv6.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcliv6 daytimetcpcliv6.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrvv6.o daytimetcpsrvv6.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrvv6 daytimetcpsrvv6.o ../libunp.a -lpthread
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o byteorder.o byteorder.c
byteorder.c: In function ‘main’:
byteorder.c:21:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof(short) = %d\n", sizeof(short));
^
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o byteorder byteorder.o ../libunp.a -lpthread

成功!

测试一下

ss-Linux intro # ./daytimetcpcli 127.0.0.1
connect error: Connection refused

又出错。。。

继续上搜索引擎
原来是由于某些原因daytime服务并没有启动,可能系统还没有安装这个服务。

13.安装xinetd

ss-Linux intro # apt-get install xinetd

具体请百度,不作解释。

14.启用daytime服务
打开 /etc/xinetd.d/daytime 有2个文件修改
disable yes 改为 disable no
重启服务

service xinetd restart

15.再次测试

ss-Linux intro # ./daytimetcpcli 127.0.0.1
13 AUG 2016 20:39:16 CST

成功!!!

12.1.关于单独编译daytimetcpcli.c出错的原因
没有指定需要链接的库。
gcc -l参数是用来指定程序要链接的库,-l紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,容易看出,把库文件名的头lib和尾.so去掉就是库名

解决加入libunp.a库

ss-Linux intro # gcc daytimetcpcli.c -o 获取时间 -lunp
ss-Linux intro # ./获取时间 127.0.0.1
14 AUG 2016 08:20:15 CST

感想:

1.花费了两天时间终于粗略的把环境搭建好了,想深入学习,深刻感受到基础知识的重要性。没有系统学习过linux,make命令等等,非常吃力。遇到问题,都不知道如何搜索问题,只能把错误信息粘贴到搜索引擎上,盲目的搜索。

2.眼高手低

3.对于帮助文档一定要好好看,不要什么一上来就去搜索引擎上去寻找答案。

4.第二次搭建环境了,第一次乱七八糟弄好也遇到很多问题没解决,这一次基本上都解决了。以后应认真学习努力加油!

最后,写的有些仓促,肯定存在一些细节错误或者没写出来,假如你看到了请指出来,有问题一起来讨论。后续我会继续修改文章的。

转载请注明出处。谢谢。