├── README.md ├── c ├── README.md ├── dp │ ├── lcs.c │ ├── lmis.c │ ├── matrix_chain_order.c │ ├── optimal_bst.c │ └── steel_cut.c ├── graph │ ├── asp.c │ ├── bfs.c │ ├── dfs.c │ ├── floyd_warshall.php │ ├── ford_fulkerson.php │ ├── johnson.php │ ├── mst.c │ ├── queue.c │ ├── queue.h │ ├── shortest_paths_by_matrix_multiply.php │ ├── sssp.c │ ├── strongly_connected_components.c │ └── topological_sort.c ├── greedy │ ├── huffman.c │ └── recursive_activity_selector.c ├── intelligent │ ├── ant.c │ └── simulated_annealing.c ├── other │ ├── explode.c │ ├── kmp.c │ ├── luhn.c │ ├── merge.c │ └── try_catch.c ├── php72-libevent │ ├── CREDITS │ ├── README.md │ ├── config.m4 │ ├── libevent.bak.c │ ├── libevent.c │ ├── libevent.php │ └── php_libevent.h ├── select │ ├── randomized_select.c │ └── select.c ├── sort │ ├── bucket_sort.c │ ├── counting_sort.c │ ├── merge_sort.c │ ├── quick_sort.c │ ├── radix_sort.c │ └── stooge_sort.c ├── structure │ ├── avl_tree.c │ ├── b_tree.c │ ├── binary_search_tree.c │ ├── binary_search_tree.walk.c │ ├── fib_heap.c │ ├── hash_table.c │ ├── heap.c │ ├── linear_list.c │ ├── list.c │ ├── queue.c │ ├── red_black_tree.c │ ├── stack.c │ ├── two_way_list.c │ └── veb.c ├── tipi │ ├── cgi-bin │ │ └── user.c │ ├── sapi.xlsx │ ├── test.c │ └── web_server.c ├── unix_c │ ├── 4 │ │ ├── 4.16.c │ │ ├── 4.21.c │ │ ├── 4.22.c │ │ ├── 4.23.c │ │ ├── 4.24.c │ │ └── 4.25.c │ ├── 10 │ │ ├── 10.1.c │ │ ├── 10.10.c │ │ ├── 10.11.c │ │ ├── 10.12.c │ │ ├── 10.13.c │ │ ├── 10.14.c │ │ ├── 10.15.c │ │ ├── 10.16.c │ │ ├── 10.17.c │ │ ├── 10.18.c │ │ ├── 10.19.c │ │ ├── 10.2.c │ │ ├── 10.20.c │ │ ├── 10.21.c │ │ ├── 10.3.c │ │ ├── 10.4.c │ │ ├── 10.5.c │ │ ├── 10.6.c │ │ ├── 10.7.c │ │ ├── 10.8.c │ │ └── 10.9.c │ ├── 14 │ │ └── mmap_cp.c │ ├── 16 │ │ ├── 16.1.c │ │ ├── README.md │ │ ├── print_server.c │ │ └── server.c │ ├── 17 │ │ ├── README.md │ │ ├── cli_conn.c │ │ ├── open_server_1 │ │ │ ├── buf_args.c │ │ │ ├── cli_args.c │ │ │ ├── client.c │ │ │ ├── open.c │ │ │ ├── open.h │ │ │ ├── opend.c │ │ │ ├── opend.h │ │ │ └── server.c │ │ ├── open_server_2 │ │ │ ├── buf_args.c │ │ │ ├── cli_args.c │ │ │ ├── client.c │ │ │ ├── loop.c │ │ │ ├── open.c │ │ │ ├── open.h │ │ │ ├── opend.c │ │ │ ├── opend.h │ │ │ └── server.c │ │ ├── recv_fd.c │ │ ├── send_err.c │ │ ├── send_fd.c │ │ ├── serv_accept.c │ │ └── serv_listen.c │ ├── 18 │ │ └── README.md │ ├── 20 │ │ └── README.md │ ├── README.md │ ├── apue.3e │ │ ├── DISCLAIMER │ │ ├── Make.defines.freebsd │ │ ├── Make.defines.linux │ │ ├── Make.defines.macos │ │ ├── Make.defines.solaris │ │ ├── Make.libapue.inc │ │ ├── Makefile │ │ ├── README │ │ ├── advio │ │ │ ├── Makefile │ │ │ ├── deadlock.c │ │ │ ├── fixup.awk │ │ │ ├── lockfile.c │ │ │ ├── mandatory.c │ │ │ ├── mcopy2.c │ │ │ ├── nonblockw.c │ │ │ ├── readn.c │ │ │ ├── rot13a.c │ │ │ ├── rot13c2.c.in │ │ │ └── writen.c │ │ ├── daemons │ │ │ ├── Makefile │ │ │ ├── init.c │ │ │ ├── reread.c │ │ │ ├── reread2.c │ │ │ └── single.c │ │ ├── datafiles │ │ │ ├── Makefile │ │ │ ├── getpwnam.c │ │ │ └── strftime.c │ │ ├── db │ │ │ ├── Makefile │ │ │ ├── apue_db.h │ │ │ ├── db.c │ │ │ └── t4.c │ │ ├── environ │ │ │ ├── Makefile │ │ │ ├── cmd1.c │ │ │ ├── cmd2.c │ │ │ ├── doatexit.c │ │ │ ├── echoarg.c │ │ │ ├── getrlimit.c │ │ │ ├── hello1.c │ │ │ ├── opendata.c │ │ │ ├── scope.c │ │ │ └── testjmp.c │ │ ├── exercises │ │ │ ├── Makefile │ │ │ ├── asyncsocket.c │ │ │ ├── bo.c │ │ │ ├── fifo1.c │ │ │ ├── fmemopen.c │ │ │ ├── getlogin.c │ │ │ ├── getpw44bsd.c │ │ │ ├── getpwsvr4.c │ │ │ ├── goodexit.c │ │ │ ├── longpath.c │ │ │ ├── openmax.c │ │ │ ├── pendlock.c │ │ │ ├── pollmsg2.c │ │ │ ├── prtime.c │ │ │ ├── sizepipe.c │ │ │ ├── sleep.c │ │ │ ├── sleepus_poll.c │ │ │ ├── sleepus_select.c │ │ │ ├── vfork3.c │ │ │ └── zombie.c │ │ ├── figlinks │ │ │ ├── fig1.10 │ │ │ ├── fig1.3 │ │ │ ├── fig1.4 │ │ │ ├── fig1.5 │ │ │ ├── fig1.6 │ │ │ ├── fig1.7 │ │ │ ├── fig1.8 │ │ │ ├── fig1.9 │ │ │ ├── fig10.10 │ │ │ ├── fig10.11 │ │ │ ├── fig10.12 │ │ │ ├── fig10.14 │ │ │ ├── fig10.15 │ │ │ ├── fig10.18 │ │ │ ├── fig10.19 │ │ │ ├── fig10.2 │ │ │ ├── fig10.20 │ │ │ ├── fig10.22 │ │ │ ├── fig10.23 │ │ │ ├── fig10.24 │ │ │ ├── fig10.25 │ │ │ ├── fig10.26 │ │ │ ├── fig10.28 │ │ │ ├── fig10.29 │ │ │ ├── fig10.31 │ │ │ ├── fig10.5 │ │ │ ├── fig10.6 │ │ │ ├── fig10.7 │ │ │ ├── fig10.8 │ │ │ ├── fig10.9 │ │ │ ├── fig11.10 │ │ │ ├── fig11.11 │ │ │ ├── fig11.12 │ │ │ ├── fig11.14 │ │ │ ├── fig11.15 │ │ │ ├── fig11.16 │ │ │ ├── fig11.2 │ │ │ ├── fig11.3 │ │ │ ├── fig11.4 │ │ │ ├── fig11.5 │ │ │ ├── fig12.11 │ │ │ ├── fig12.12 │ │ │ ├── fig12.13 │ │ │ ├── fig12.16 │ │ │ ├── fig12.17 │ │ │ ├── fig12.4 │ │ │ ├── fig12.8 │ │ │ ├── fig13.1 │ │ │ ├── fig13.6 │ │ │ ├── fig13.7 │ │ │ ├── fig13.8 │ │ │ ├── fig13.9 │ │ │ ├── fig14.1 │ │ │ ├── fig14.12 │ │ │ ├── fig14.20 │ │ │ ├── fig14.21 │ │ │ ├── fig14.24 │ │ │ ├── fig14.27 │ │ │ ├── fig14.5 │ │ │ ├── fig14.6 │ │ │ ├── fig14.7 │ │ │ ├── fig14.9 │ │ │ ├── fig15.11 │ │ │ ├── fig15.12 │ │ │ ├── fig15.14 │ │ │ ├── fig15.15 │ │ │ ├── fig15.17 │ │ │ ├── fig15.18 │ │ │ ├── fig15.19 │ │ │ ├── fig15.31 │ │ │ ├── fig15.33 │ │ │ ├── fig15.35 │ │ │ ├── fig15.5 │ │ │ ├── fig15.6 │ │ │ ├── fig15.7 │ │ │ ├── fig16.10 │ │ │ ├── fig16.11 │ │ │ ├── fig16.12 │ │ │ ├── fig16.16 │ │ │ ├── fig16.17 │ │ │ ├── fig16.18 │ │ │ ├── fig16.19 │ │ │ ├── fig16.20 │ │ │ ├── fig16.22 │ │ │ ├── fig16.9 │ │ │ ├── fig17.10 │ │ │ ├── fig17.12 │ │ │ ├── fig17.13 │ │ │ ├── fig17.14 │ │ │ ├── fig17.15 │ │ │ ├── fig17.16 │ │ │ ├── fig17.17 │ │ │ ├── fig17.18 │ │ │ ├── fig17.19 │ │ │ ├── fig17.2 │ │ │ ├── fig17.20 │ │ │ ├── fig17.21 │ │ │ ├── fig17.22 │ │ │ ├── fig17.23 │ │ │ ├── fig17.24 │ │ │ ├── fig17.25 │ │ │ ├── fig17.26 │ │ │ ├── fig17.27 │ │ │ ├── fig17.28 │ │ │ ├── fig17.29 │ │ │ ├── fig17.3 │ │ │ ├── fig17.30 │ │ │ ├── fig17.31 │ │ │ ├── fig17.4 │ │ │ ├── fig17.5 │ │ │ ├── fig17.8 │ │ │ ├── fig17.9 │ │ │ ├── fig18.10 │ │ │ ├── fig18.11 │ │ │ ├── fig18.12 │ │ │ ├── fig18.13 │ │ │ ├── fig18.14 │ │ │ ├── fig18.15 │ │ │ ├── fig18.16 │ │ │ ├── fig18.17 │ │ │ ├── fig18.18 │ │ │ ├── fig18.20 │ │ │ ├── fig18.21 │ │ │ ├── fig18.22 │ │ │ ├── fig19.10 │ │ │ ├── fig19.11 │ │ │ ├── fig19.12 │ │ │ ├── fig19.16 │ │ │ ├── fig19.9 │ │ │ ├── fig2.13 │ │ │ ├── fig2.14 │ │ │ ├── fig2.16 │ │ │ ├── fig2.17 │ │ │ ├── fig20.3 │ │ │ ├── fig3.1 │ │ │ ├── fig3.11 │ │ │ ├── fig3.12 │ │ │ ├── fig3.2 │ │ │ ├── fig3.5 │ │ │ ├── fig4.12 │ │ │ ├── fig4.16 │ │ │ ├── fig4.21 │ │ │ ├── fig4.22 │ │ │ ├── fig4.23 │ │ │ ├── fig4.24 │ │ │ ├── fig4.25 │ │ │ ├── fig4.3 │ │ │ ├── fig4.8 │ │ │ ├── fig4.9 │ │ │ ├── fig5.11 │ │ │ ├── fig5.12 │ │ │ ├── fig5.13 │ │ │ ├── fig5.15 │ │ │ ├── fig5.4 │ │ │ ├── fig5.5 │ │ │ ├── fig6.11 │ │ │ ├── fig6.2 │ │ │ ├── fig7.1 │ │ │ ├── fig7.11 │ │ │ ├── fig7.13 │ │ │ ├── fig7.14 │ │ │ ├── fig7.16 │ │ │ ├── fig7.3 │ │ │ ├── fig7.4 │ │ │ ├── fig7.9 │ │ │ ├── fig8.1 │ │ │ ├── fig8.12 │ │ │ ├── fig8.13 │ │ │ ├── fig8.16 │ │ │ ├── fig8.17 │ │ │ ├── fig8.20 │ │ │ ├── fig8.21 │ │ │ ├── fig8.22 │ │ │ ├── fig8.23 │ │ │ ├── fig8.24 │ │ │ ├── fig8.25 │ │ │ ├── fig8.28 │ │ │ ├── fig8.29 │ │ │ ├── fig8.3 │ │ │ ├── fig8.30 │ │ │ ├── fig8.31 │ │ │ ├── fig8.5 │ │ │ ├── fig8.6 │ │ │ ├── fig8.8 │ │ │ ├── fig9.12 │ │ │ ├── figB.1 │ │ │ ├── figB.3 │ │ │ ├── figB.4 │ │ │ ├── figC.1 │ │ │ ├── figC.10 │ │ │ ├── figC.12 │ │ │ ├── figC.13 │ │ │ ├── figC.14 │ │ │ ├── figC.15 │ │ │ ├── figC.16 │ │ │ ├── figC.17 │ │ │ ├── figC.18 │ │ │ ├── figC.20 │ │ │ ├── figC.22 │ │ │ ├── figC.23 │ │ │ ├── figC.24 │ │ │ ├── figC.3 │ │ │ ├── figC.4 │ │ │ ├── figC.5 │ │ │ ├── figC.6 │ │ │ ├── figC.7 │ │ │ └── figC.8 │ │ ├── filedir │ │ │ ├── Makefile │ │ │ ├── access.c │ │ │ ├── cdpwd.c │ │ │ ├── changemod.c │ │ │ ├── devrdev.c │ │ │ ├── filetype.c │ │ │ ├── ftw8.c │ │ │ ├── mycd.c │ │ │ ├── umask.c │ │ │ ├── unlink.c │ │ │ └── zap.c │ │ ├── fileio │ │ │ ├── Makefile │ │ │ ├── fileflags.c │ │ │ ├── hole.c │ │ │ ├── mycat.c │ │ │ ├── seek.c │ │ │ └── setfl.c │ │ ├── include │ │ │ └── apue.h │ │ ├── intro │ │ │ ├── Makefile │ │ │ ├── getcputc.c │ │ │ ├── hello.c │ │ │ ├── ls1.c │ │ │ ├── mycat.c │ │ │ ├── shell1.c │ │ │ ├── shell2.c │ │ │ ├── testerror.c │ │ │ └── uidgid.c │ │ ├── ipc1 │ │ │ ├── Makefile │ │ │ ├── add2.c │ │ │ ├── add2stdio.c │ │ │ ├── devzero.c │ │ │ ├── myuclc.c │ │ │ ├── pipe1.c │ │ │ ├── pipe2.c │ │ │ ├── pipe4.c │ │ │ ├── popen.c │ │ │ ├── popen1.c │ │ │ ├── popen2.c │ │ │ ├── slock.c │ │ │ ├── slock.h │ │ │ ├── tellwait.c │ │ │ └── tshm.c │ │ ├── ipc2 │ │ │ ├── Makefile │ │ │ ├── bindunix.c │ │ │ ├── open.fe │ │ │ │ ├── Makefile │ │ │ │ ├── main.c │ │ │ │ ├── open.c │ │ │ │ └── open.h │ │ │ ├── open │ │ │ │ ├── Makefile │ │ │ │ ├── main.c │ │ │ │ ├── open.c │ │ │ │ └── open.h │ │ │ ├── opend.fe │ │ │ │ ├── Makefile │ │ │ │ ├── cliargs.c │ │ │ │ ├── main.c │ │ │ │ ├── opend.h │ │ │ │ └── request.c │ │ │ ├── opend │ │ │ │ ├── Makefile │ │ │ │ ├── cliargs.c │ │ │ │ ├── client.c │ │ │ │ ├── loop.poll.c │ │ │ │ ├── loop.select.c │ │ │ │ ├── main.c │ │ │ │ ├── opend.h │ │ │ │ └── request.c │ │ │ ├── pollmsg.c │ │ │ ├── recvfd2.c │ │ │ ├── sendfd2.c │ │ │ └── sendmsg.c │ │ ├── lib │ │ │ ├── Makefile │ │ │ ├── Orecvfd.c │ │ │ ├── bufargs.c │ │ │ ├── cliconn.c │ │ │ ├── clrfl.c │ │ │ ├── daemonize.c │ │ │ ├── error.c │ │ │ ├── errorlog.c │ │ │ ├── lockreg.c │ │ │ ├── locktest.c │ │ │ ├── nspipe.c │ │ │ ├── openmax.c │ │ │ ├── pathalloc.c │ │ │ ├── popen.c │ │ │ ├── prexit.c │ │ │ ├── prmask.c │ │ │ ├── ptyfork.c │ │ │ ├── ptyopen.c │ │ │ ├── readn.c │ │ │ ├── recvfd.c │ │ │ ├── semaph.c │ │ │ ├── senderr.c │ │ │ ├── sendfd.c │ │ │ ├── servaccept.c │ │ │ ├── servlisten.c │ │ │ ├── setfd.c │ │ │ ├── setfl.c │ │ │ ├── signal.c │ │ │ ├── signalintr.c │ │ │ ├── sleep.c │ │ │ ├── sleepus.c │ │ │ ├── spipe.c │ │ │ ├── strerror.c │ │ │ ├── tellwait.c │ │ │ ├── ttymodes.c │ │ │ └── writen.c │ │ ├── printer │ │ │ ├── Makefile │ │ │ ├── ipp.h │ │ │ ├── print.c │ │ │ ├── print.h │ │ │ ├── printd.c │ │ │ └── util.c │ │ ├── proc │ │ │ ├── Makefile │ │ │ ├── awkexample │ │ │ ├── echoall.c │ │ │ ├── exec1.c │ │ │ ├── exec2.c │ │ │ ├── fork1.c │ │ │ ├── fork2.c │ │ │ ├── nice.c │ │ │ ├── pracct.c │ │ │ ├── pruids.c │ │ │ ├── system.c │ │ │ ├── systest1.c │ │ │ ├── systest3.c │ │ │ ├── tellwait1.c │ │ │ ├── tellwait2.c │ │ │ ├── test1.c │ │ │ ├── times1.c │ │ │ ├── vfork1.c │ │ │ └── wait1.c │ │ ├── pty │ │ │ ├── Makefile │ │ │ ├── driver.c │ │ │ ├── loop.c │ │ │ └── main.c │ │ ├── relation │ │ │ ├── Makefile │ │ │ └── orphan3.c │ │ ├── signals │ │ │ ├── Makefile │ │ │ ├── abort.c │ │ │ ├── child.c │ │ │ ├── critical.c │ │ │ ├── mask.c │ │ │ ├── read1.c │ │ │ ├── read2.c │ │ │ ├── reenter.c │ │ │ ├── setops.c │ │ │ ├── sigtstp.c │ │ │ ├── sigusr.c │ │ │ ├── sleep1.c │ │ │ ├── sleep2.c │ │ │ ├── suspend1.c │ │ │ ├── suspend2.c │ │ │ ├── system.c │ │ │ ├── systest2.c │ │ │ └── tsleep2.c │ │ ├── sockets │ │ │ ├── clconn.c │ │ │ ├── clconn2.c │ │ │ ├── findsvc.c │ │ │ ├── initsrv1.c │ │ │ ├── initsrv2.c │ │ │ ├── makefile │ │ │ ├── ruptime-dg.c │ │ │ ├── ruptime.c │ │ │ ├── ruptimed-dg.c │ │ │ ├── ruptimed-fd.c │ │ │ └── ruptimed.c │ │ ├── standards │ │ │ ├── Makefile │ │ │ ├── conf.c.modified │ │ │ ├── makeconf.awk │ │ │ ├── makeopt.awk │ │ │ ├── pathconf-lim.sym │ │ │ ├── pathconf-opt.sym │ │ │ ├── sysconf-lim.sym │ │ │ └── sysconf-opt.sym │ │ ├── stdio │ │ │ ├── Makefile │ │ │ ├── buf.c │ │ │ ├── fgetsfputs.c │ │ │ ├── getcharbug.c │ │ │ ├── getcputc.c │ │ │ ├── memstr.c │ │ │ ├── mkstemp.c │ │ │ └── tempfiles.c │ │ ├── systype.sh │ │ ├── termios │ │ │ ├── Makefile │ │ │ ├── csize.c │ │ │ ├── ctermid.c │ │ │ ├── getpass.c │ │ │ ├── isatty.c │ │ │ ├── settty.c │ │ │ ├── t_getpass.c │ │ │ ├── t_isatty.c │ │ │ ├── t_raw.c │ │ │ ├── t_ttyname.c │ │ │ ├── ttyname.c │ │ │ └── winch.c │ │ ├── threadctl │ │ │ ├── Makefile │ │ │ ├── atfork.c │ │ │ ├── detach.c │ │ │ ├── getenv1.c │ │ │ ├── getenv2.c │ │ │ ├── getenv3.c │ │ │ ├── suspend.c │ │ │ └── timeout.c │ │ └── threads │ │ │ ├── Makefile │ │ │ ├── badexit2.c │ │ │ ├── barrier.c │ │ │ ├── cleanup.c │ │ │ ├── condvar.c │ │ │ ├── exitstatus.c │ │ │ ├── maketimeout.c │ │ │ ├── mutex1.c │ │ │ ├── mutex2.c │ │ │ ├── mutex3.c │ │ │ ├── rwlock.c │ │ │ ├── threadid.c │ │ │ └── timedlock.c │ └── lib │ │ ├── apue.h │ │ ├── book.c │ │ └── error.c └── unix_socket │ ├── tcp │ ├── tcpcli01.c │ ├── tcpserv01.c │ ├── tcpservpoll01.c │ └── tcpservselect01.c │ ├── udp │ ├── udpcli01.c │ └── udpserv01.c │ └── unpv13e │ ├── DISCLAIMER │ ├── Make.defines.in │ ├── Makefile.in │ ├── README │ ├── VERSION │ ├── aclocal.m4 │ ├── advio │ ├── Makefile │ ├── daytimetcpcli.c │ ├── daytimeudpcli3.c │ ├── daytimeudpcli4.c │ ├── dgclitimeo.c │ ├── dgclitimeo1.c │ ├── dgclitimeo2.c │ ├── dgclitimeo2.lc │ ├── dgclitimeo3.c │ ├── dgclitimeo3.lc │ ├── dgechoaddr.c │ ├── dgechoaddr.lc │ ├── old │ │ ├── dgechoaddr.c │ │ ├── recvfromflags.c │ │ └── test01.c │ ├── recvfromflags.c │ ├── recvfromflags.lc │ ├── script.1 │ ├── sig_chld_waitpid.c │ ├── str_cli_kqueue04.c │ ├── str_cli_poll03.c │ ├── str_cli_select02.c │ ├── str_echo_stdio02.c │ ├── str_echo_stdio02.lc │ ├── tcpcli01.c │ ├── tcpcli02.c │ ├── tcpcli03.c │ ├── tcpcli04.c │ ├── tcpserv02.c │ ├── udpcli01.c │ ├── udpcli02.c │ ├── udpcli03.c │ ├── udpserv01.c │ ├── udpserv03.c │ ├── udpserv03.lc │ ├── udpserv04.c │ └── udpserv04.lc │ ├── bcast │ ├── Makefile │ ├── dgclibcast1.c │ ├── dgclibcast1.lc │ ├── dgclibcast2.c │ ├── dgclibcast3.c │ ├── dgclibcast3.lc │ ├── dgclibcast4.c │ ├── dgclibcast4.lc │ ├── dgclibcast5.c │ ├── dgclibcast5.lc │ ├── dgclibcast6.c │ ├── dgclibcast6.lc │ ├── udpcli01.c │ ├── udpcli02.c │ ├── udpcli03.c │ ├── udpcli04.c │ ├── udpcli05.c │ └── udpcli06.c │ ├── config.guess │ ├── config.h.in │ ├── config.sub │ ├── configure │ ├── configure.in │ ├── debug │ ├── Makefile │ ├── backlog.c │ ├── backlog.lc │ ├── qlen.c │ ├── qlen.lc │ ├── test01.c │ ├── test01.lc │ ├── test02.c │ ├── test03.c │ ├── test04.c │ ├── test05.c │ ├── test06.c │ └── unpxti.h │ ├── icmpd │ ├── Makefile │ ├── dgcli01.c │ ├── dgcli01.lc │ ├── icmpd.c │ ├── icmpd.h │ ├── icmpd.lc │ ├── readable_conn.c │ ├── readable_conn.lc │ ├── readable_listen.c │ ├── readable_listen.lc │ ├── readable_v4.c │ ├── readable_v4.lc │ ├── readable_v6.c │ ├── readable_v6.lc │ ├── script.1 │ ├── script.2 │ ├── script.3 │ ├── script.4 │ ├── udpcli01.c │ └── unpicmpd.h │ ├── inetd │ ├── Makefile │ ├── daytimetcpsrv2.c │ ├── daytimetcpsrv3.c │ └── daytimetcpsrv3.lc │ ├── install-sh │ ├── intro │ ├── Makefile │ ├── byteorder.c │ ├── daytimetcpcli.c │ ├── daytimetcpcli1.c │ ├── daytimetcpcli2.c │ ├── daytimetcpcli3.c │ ├── daytimetcpcliv6.c │ ├── daytimetcpsrv.c │ ├── daytimetcpsrv.lc │ ├── daytimetcpsrv1.c │ ├── daytimetcpsrv2.c │ ├── daytimetcpsrv3.c │ ├── daytimetcpsrvv6.c │ ├── truss.solaris.2.6 │ └── truss.unixware.2.1 │ ├── ioctl │ ├── Makefile │ ├── Progs.siocgifconf │ ├── Script.solaris │ ├── lsif01.c │ ├── lsif02.c │ ├── prifinfo.c │ ├── prifinfo.lc │ ├── prmac.c │ └── test1.c │ ├── ipopts │ ├── Makefile │ ├── dgechoprintroute.c │ ├── sigchldwaitpid.c │ ├── sourceroute.c │ ├── sourceroute.lc │ ├── sourceroute6.c │ ├── tcpcli01.c │ ├── tcpserv01.c │ ├── udpcli01.c │ └── udpserv01.c │ ├── key │ ├── Makefile │ ├── add.c │ ├── dump.c │ ├── name.c │ ├── printsadbmsg.c │ ├── register.c │ └── unp.h │ ├── lib │ ├── Makefile │ ├── addrinfo.h │ ├── connect_nonb.c │ ├── connect_nonb.lc │ ├── connect_timeo.c │ ├── connect_timeo.lc │ ├── daemon_inetd.c │ ├── daemon_inetd.lc │ ├── daemon_init.c │ ├── dg_cli.c │ ├── dg_echo.c │ ├── error.c │ ├── family_to_level.c │ ├── get_ifi_info.c │ ├── get_ifi_info.lc │ ├── gf_time.c │ ├── host_serv.c │ ├── host_serv.lc │ ├── hstrerror.c │ ├── if_indextoname.c │ ├── if_nameindex.c │ ├── if_nametoindex.c │ ├── in6addr_any.c │ ├── mcast_get_if.c │ ├── mcast_get_loop.c │ ├── mcast_get_ttl.c │ ├── mcast_join.c │ ├── mcast_join.lc │ ├── mcast_leave.c │ ├── mcast_set_if.c │ ├── mcast_set_loop.c │ ├── mcast_set_loop.lc │ ├── mcast_set_ttl.c │ ├── my_addrs.c │ ├── my_addrs.lc │ ├── pselect.c │ ├── pselect.lc │ ├── read_fd.c │ ├── read_fd.lc │ ├── readable_timeo.c │ ├── readable_timeo.lc │ ├── readline.c │ ├── readline.lc │ ├── readn.c │ ├── readn.lc │ ├── rtt.c │ ├── rtt.lc │ ├── signal.c │ ├── signal.lc │ ├── signal_intr.c │ ├── snprintf.c │ ├── sock_bind_wild.c │ ├── sock_cmp_addr.c │ ├── sock_cmp_port.c │ ├── sock_get_port.c │ ├── sock_ntop.c │ ├── sock_ntop.lc │ ├── sock_ntop_host.c │ ├── sock_set_addr.c │ ├── sock_set_port.c │ ├── sock_set_wild.c │ ├── sockatmark.c │ ├── sockfd_to_family.c │ ├── sockfd_to_family.lc │ ├── str_cli.c │ ├── str_cli.lc │ ├── str_echo.c │ ├── str_echo.lc │ ├── tcp_connect.c │ ├── tcp_connect.lc │ ├── tcp_listen.c │ ├── tcp_listen.lc │ ├── tv_sub.c │ ├── udp_client.c │ ├── udp_client.lc │ ├── udp_connect.c │ ├── udp_connect.lc │ ├── udp_server.c │ ├── udp_server.lc │ ├── unp.h │ ├── unp.lh │ ├── unpifi.h │ ├── unprtt.h │ ├── unprtt.lh │ ├── unpthread.h │ ├── wraplib.c │ ├── wrappthread.c │ ├── wrappthread.lc │ ├── wrapsock.c │ ├── wrapsock.lc │ ├── wrapstdio.c │ ├── wrapunix.c │ ├── writable_timeo.c │ ├── write_fd.c │ ├── write_fd.lc │ ├── writen.c │ └── writen.lc │ ├── libfree │ ├── Make.tar │ ├── Makefile │ ├── README │ ├── README.getaddrinfo │ ├── addrinfo.h │ ├── getaddrinfo.c │ ├── getnameinfo.c │ ├── in_cksum.c │ ├── inet_aton.c │ ├── inet_ntop.c │ ├── inet_ntop_ipv4.c │ ├── inet_ntop_ipv4.lc │ ├── inet_pton.c │ ├── inet_pton_ipv4.c │ ├── inet_pton_ipv4.lc │ ├── test_ascii2addr.c │ ├── test_getservbyname_r.c │ └── test_inet_pton.c │ ├── libgai │ ├── Makefile │ ├── addrinfo.h │ ├── freeaddrinfo.c │ ├── ga_aistruct.c │ ├── ga_aistruct.lc │ ├── ga_clone.c │ ├── ga_clone.lc │ ├── ga_echeck.c │ ├── ga_echeck.lc │ ├── ga_nsearch.c │ ├── ga_nsearch.lc │ ├── ga_port.c │ ├── ga_port.lc │ ├── ga_serv.c │ ├── ga_serv.lc │ ├── ga_unix.c │ ├── ga_unix.lc │ ├── gai_hdr.h │ ├── gai_hdr.lh │ ├── gai_strerror.c │ ├── getaddrinfo.c │ ├── getaddrinfo.lc │ ├── getnameinfo.c │ ├── getnameinfo.lc │ ├── gn_ipv46.c │ ├── gn_ipv46.lc │ ├── old │ │ ├── ga_unixstruct.c │ │ └── savecopy.c │ ├── test1.c │ └── testga.c │ ├── libroute │ ├── Makefile │ ├── get_rtaddrs.c │ ├── get_rtaddrs.lc │ ├── if_indextoname.c │ ├── if_indextoname.lc │ ├── if_nameindex.c │ ├── if_nameindex.lc │ ├── if_nametoindex.c │ ├── if_nametoindex.lc │ ├── net_rt_dump.c │ ├── net_rt_iflist.c │ ├── net_rt_iflist.lc │ ├── sock_masktop.c │ └── unproute.h │ ├── mcast │ ├── Makefile │ ├── dgclibcast1.c │ ├── dgclimcast5.c │ ├── dgclimcast6.c │ ├── main.c │ ├── recv.c │ ├── send.c │ ├── udpcli01.c │ ├── udpcli05.c │ ├── udpcli06.c │ └── udpserv01.c │ ├── mysdr │ ├── Makefile │ ├── loop.c │ ├── loop.lc │ ├── main.c │ ├── main.lc │ ├── mysdr.h │ ├── script.1 │ └── script.2 │ ├── names │ ├── Makefile │ ├── daytimetcpcli.c │ ├── daytimetcpcli1.c │ ├── daytimetcpcli1.lc │ ├── daytimetcpcli2.c │ ├── daytimetcpcli2.lc │ ├── daytimetcpcli3.c │ ├── daytimetcpcli3.lc │ ├── daytimetcpsrv1.c │ ├── daytimetcpsrv2.c │ ├── daytimetcpsrv3.c │ ├── daytimetcpsrv4.c │ ├── daytimeudpcli1.c │ ├── daytimeudpcli1.lc │ ├── daytimeudpcli2.c │ ├── daytimeudpsrv2.c │ ├── daytimeudpsrv3.c │ ├── hostent.c │ ├── hostent.lc │ ├── hostent2.c │ ├── hostent2.lc │ ├── hostent3.c │ ├── myaddrs1.c │ ├── myaddrs1.lc │ ├── netent.c │ ├── prmyaddrs.c │ ├── prmyaddrs1.c │ ├── prmyaddrs1.lc │ ├── test1.c │ ├── test2.c │ └── udp_server_reuseaddr.c │ ├── nonblock │ ├── Makefile │ ├── daytimetcpcli.c │ ├── doit.1 │ ├── home_page.c │ ├── script.1.sh │ ├── script.1.tcpd │ ├── start_connect.c │ ├── strclifork.c │ ├── strclinonb.c │ ├── strclinonb.lc │ ├── tcpcli01.c │ ├── tcpcli02.c │ ├── tcpcli03.c │ ├── tcpcli03.lc │ ├── tcpcli04.c │ ├── tcpservselect03.c │ ├── web.c │ ├── web.h │ ├── web.lc │ └── write_get_cmd.c │ ├── oob │ ├── Makefile │ ├── heartbeatcli.c │ ├── heartbeatserv.c │ ├── sigchldwaitpid.c │ ├── strcliselect02.c │ ├── strecho02.c │ ├── tcpcli02.c │ ├── tcprecv01.c │ ├── tcprecv01.lc │ ├── tcprecv02.c │ ├── tcprecv02.lc │ ├── tcprecv03.c │ ├── tcprecv03p.c │ ├── tcprecv03p.lc │ ├── tcprecv04.c │ ├── tcprecv04.lc │ ├── tcprecv05.c │ ├── tcprecv06.c │ ├── tcpsend01.c │ ├── tcpsend01.lc │ ├── tcpsend02.c │ ├── tcpsend03.c │ ├── tcpsend04.c │ ├── tcpsend04.lc │ ├── tcpsend05.c │ ├── tcpsend05.lc │ ├── tcpsend06.c │ ├── tcpsend06.lc │ └── tcpserv02.c │ ├── ping │ ├── Makefile │ ├── bsdping.c │ ├── init_v6.c │ ├── main.c │ ├── main.lc │ ├── old │ │ ├── icmp6.h │ │ └── ip6.h │ ├── ping.h │ ├── ping_v4.c │ ├── proc_v4.c │ ├── proc_v4.lc │ ├── proc_v6.c │ ├── proc_v6.lc │ ├── readloop.c │ ├── send_v4.c │ ├── send_v6.c │ ├── sig_alrm.c │ ├── sig_alrm.lc │ └── tv_sub.c │ ├── route │ ├── Makefile │ ├── checkudpsum.c │ ├── get_ifi_info.c │ ├── get_ifi_info.lc │ ├── getrt.c │ ├── getrt.lc │ ├── mynetstat.c │ ├── prifindex.c │ ├── prifinfo.c │ ├── prifname.c │ ├── prifnameindex.c │ └── unproute.h │ ├── rtt │ ├── Makefile │ ├── dg_cli.c │ ├── dg_cli.lc │ ├── dg_echo.c │ ├── dg_send_recv.c │ ├── dg_send_recv.lc │ ├── rtt.out.kumba.1 │ ├── rtt.out.kumba.2 │ ├── rtt.out.vangogh.1 │ ├── rtt.out.vangogh.2 │ ├── rtt.vals.kumba.1 │ ├── rtt.vals.vangogh.1 │ ├── udpcli01.c │ └── unprtt.h │ ├── sctp │ ├── Makefile │ ├── sctp_addr_to_associd.c │ ├── sctp_addr_to_associd.lc │ ├── sctp_bindargs.c │ ├── sctp_bindargs.lc │ ├── sctp_check_notify.c │ ├── sctp_check_notify.lc │ ├── sctp_displayevents.c │ ├── sctp_displayevents.lc │ ├── sctp_getnostrm.c │ ├── sctp_modify_hb.c │ ├── sctp_modify_hb.lc │ ├── sctp_pdapircv.c │ ├── sctp_pdapircv.lc │ ├── sctp_print_addrs.c │ ├── sctp_print_addrs.lc │ ├── sctp_strcli.c │ ├── sctp_strcli.lc │ ├── sctp_strcli1.c │ ├── sctp_strcli1.lc │ ├── sctp_strcli_un.c │ ├── sctp_strcli_un.lc │ ├── sctp_strcliecho.c │ ├── sctp_strcliecho.lc │ ├── sctp_strcliecho2.c │ ├── sctp_strcliecho2.lc │ ├── sctp_wrapper.c │ ├── sctpclient01.c │ ├── sctpclient01.lc │ ├── sctpclient02.c │ ├── sctpclient02.lc │ ├── sctpclient04.c │ ├── sctpclient04.lc │ ├── sctpserv01.c │ ├── sctpserv01.lc │ ├── sctpserv02.c │ ├── sctpserv02.lc │ ├── sctpserv03.c │ ├── sctpserv03.lc │ ├── sctpserv04.c │ ├── sctpserv04.lc │ ├── sctpserv05.c │ ├── sctpserv05.lc │ ├── sctpserv06.c │ ├── sctpserv06.lc │ ├── sctpserv07.c │ ├── sctpserv07.lc │ ├── sctpserv_fork.c │ ├── sctpserv_fork.lc │ └── unp.h │ ├── select │ ├── Makefile │ ├── strcliselect01.c │ ├── strcliselect02.c │ ├── strcliselect02.lc │ ├── tcpcli01.c │ ├── tcpcli02.c │ └── tcpcli03.c │ ├── server │ ├── Makefile │ ├── child.h │ ├── child.lh │ ├── child02.c │ ├── child02.lc │ ├── child02l.c │ ├── child02m.c │ ├── child03.c │ ├── child03m.c │ ├── child04.c │ ├── child05.c │ ├── child05.lc │ ├── client.c │ ├── clientrst.c │ ├── lock_fcntl.c │ ├── lock_fcntl.lc │ ├── lock_pthread.c │ ├── lock_pthread.lc │ ├── meter.c │ ├── pr_cpu_time.c │ ├── pthread07.c │ ├── pthread07.h │ ├── pthread07.lc │ ├── pthread08.c │ ├── pthread08.h │ ├── pthread08.lc │ ├── pthread09.c │ ├── pthread09.h │ ├── readline.c │ ├── readline_r.c │ ├── readline_r.h │ ├── serv00.c │ ├── serv01.c │ ├── serv01.lc │ ├── serv02.c │ ├── serv02.lc │ ├── serv02m.c │ ├── serv03.c │ ├── serv03m.c │ ├── serv04.c │ ├── serv05.c │ ├── serv05.lc │ ├── serv06.c │ ├── serv06.lc │ ├── serv07.c │ ├── serv07.lc │ ├── serv08.c │ ├── serv08.lc │ ├── serv09.c │ ├── sig_chld_waitpid.c │ ├── unpthread.h │ ├── web_child.c │ └── web_child_r.c │ ├── sigio │ ├── Makefile │ ├── dgcli01.c │ ├── dgecho01.c │ ├── dgecho01.lc │ ├── script.1 │ ├── script.2 │ ├── udpcli01.c │ └── udpserv01.c │ ├── sock │ ├── Makefile │ ├── README │ ├── TODO │ ├── buffers.c │ ├── cliopen.c │ ├── crlf.c │ ├── error.c │ ├── loop.c │ ├── looptcp.c │ ├── loopudp.c │ ├── main.c │ ├── multicast.c │ ├── ourhdr.h │ ├── pattern.c │ ├── servopen.c │ ├── sinktcp.c │ ├── sinkudp.c │ ├── sleepus.c │ ├── sock.h │ ├── sock.in │ ├── sockopts.c │ ├── sourceroute.c │ ├── sourcesink.c │ ├── sourcetcp.c │ ├── sourceudp.c │ ├── strerror.c │ ├── tellwait.c │ ├── write.c │ └── writen.c │ ├── sockopt │ ├── Makefile │ ├── checkopts.c │ ├── checkopts.lc │ ├── prdefaults.c │ ├── rcvbuf.c │ ├── rcvbufset.c │ └── sockopt.c │ ├── sparc64-unknown-freebsd5.1 │ └── config.h │ ├── ssntp │ ├── Makefile │ ├── main.c │ ├── main.lc │ ├── ntp.h │ ├── sntp.h │ └── sntp_proc.c │ ├── streams │ ├── Makefile │ ├── stream_dg │ │ ├── Makefile │ │ ├── client.c │ │ ├── net_stream.c │ │ └── server.c │ ├── strlist_sock.c │ ├── strlist_xti.c │ ├── tpi_bind.c │ ├── tpi_close.c │ ├── tpi_close.lc │ ├── tpi_connect.c │ ├── tpi_connect.lc │ ├── tpi_daytime.c │ ├── tpi_daytime.h │ ├── tpi_read.c │ ├── tpi_read.lc │ └── unpxti.h │ ├── tcpcliserv │ ├── Makefile │ ├── sigchldwait.c │ ├── sigchldwait.lc │ ├── sigchldwaitpid.c │ ├── sigchldwaitpid.lc │ ├── str_cli08.c │ ├── str_cli09.c │ ├── str_cli11.c │ ├── str_cli11.lc │ ├── str_echo08.c │ ├── str_echo08.lc │ ├── str_echo09.c │ ├── sum.h │ ├── tcpcli01.c │ ├── tcpcli01.lc │ ├── tcpcli04.c │ ├── tcpcli05.c │ ├── tcpcli06.c │ ├── tcpcli07.c │ ├── tcpcli08.c │ ├── tcpcli09.c │ ├── tcpcli10.c │ ├── tcpcli11.c │ ├── tcpserv01.c │ ├── tcpserv01.lc │ ├── tcpserv02.c │ ├── tcpserv03.c │ ├── tcpserv04.c │ ├── tcpserv04.lc │ ├── tcpserv08.c │ ├── tcpserv09.c │ ├── tcpservpoll01.c │ ├── tcpservpoll01.lc │ ├── tcpservselect01.c │ ├── tcpservselect01.lc │ └── tsigpipe.c │ ├── test │ ├── Makefile │ ├── accept_eintr.c │ ├── funcs.c │ ├── readline.h │ ├── readline1.c │ ├── readline1.lc │ ├── readline2.c │ ├── readline3.c │ ├── test.h │ ├── test1.c │ ├── test2.c │ ├── tisfdtype.c │ ├── treadline1.c │ ├── treadline2.c │ ├── treadline3.c │ ├── tshutdown.c │ └── tsnprintf.c │ ├── threads │ ├── Makefile │ ├── doit.1 │ ├── doit.2 │ ├── example01.c │ ├── example01.lc │ ├── example02.c │ ├── example02.lc │ ├── example03.c │ ├── readline.c │ ├── readline.lc │ ├── script.example01 │ ├── script.example02 │ ├── strclithread.c │ ├── strclithread.lc │ ├── strclithread2.c │ ├── tcpcli01.c │ ├── tcpcli02.c │ ├── tcpserv01.c │ ├── tcpserv02.c │ ├── test01.c │ ├── test02.c │ ├── test03.c │ ├── test04.c │ ├── test05.c │ ├── unpthread.h │ ├── web01.c │ ├── web01.lc │ ├── web02.c │ ├── web03.c │ └── web03.lc │ ├── traceroute │ ├── Makefile │ ├── icmpcode_v4.c │ ├── icmpcode_v6.c │ ├── main.c │ ├── main.lc │ ├── recv_v4.c │ ├── recv_v4.lc │ ├── recv_v6.c │ ├── recv_v6.lc │ ├── sig_alrm.c │ ├── trace.h │ ├── trace.lh │ ├── traceloop.c │ ├── traceloop.lc │ └── tv_sub.c │ ├── udpcksum │ ├── Makefile │ ├── cleanup.c │ ├── cleanup.lc │ ├── main.c │ ├── main.lc │ ├── pcap.c │ ├── pcap.lc │ ├── senddnsquery-libnet.c │ ├── senddnsquery-libnet.lc │ ├── senddnsquery-raw.c │ ├── senddnsquery-raw.lc │ ├── udpcksum.c │ ├── udpcksum.h │ ├── udpcksum.lc │ ├── udpread.c │ ├── udpread.c.bad │ ├── udpread.lc │ ├── udpwrite.c │ └── udpwrite.lc │ ├── udpcliserv │ ├── Makefile │ ├── dgcliaddr.c │ ├── dgclibig.c │ ├── dgclibig.lc │ ├── dgcliconnect.c │ ├── dgcliconnect.lc │ ├── dgcliinetaddr.c │ ├── dgcliloop1.c │ ├── dgcliloop3.c │ ├── dgecholoop1.c │ ├── dgecholoop2.c │ ├── dgecholoop2.lc │ ├── sigchldwaitpid.c │ ├── udpcli01.c │ ├── udpcli02.c │ ├── udpcli03.c │ ├── udpcli04.c │ ├── udpcli05.c │ ├── udpcli06.c │ ├── udpcli08.c │ ├── udpcli09.c │ ├── udpcli10.c │ ├── udpserv01.c │ ├── udpserv06.c │ ├── udpserv07.c │ ├── udpservselect01.c │ └── udpservselect01.lc │ └── unixdomain │ ├── Makefile │ ├── daytimetcpcli.c │ ├── daytimetcpsrv2.c │ ├── mycat.c │ ├── mycat.lc │ ├── myopen.c │ ├── openfile.c │ ├── readcred.c │ ├── sigchldwaitpid.c │ ├── strecho.c │ ├── testfcred.c │ ├── tfcred01.c │ ├── unixbind.c │ ├── unixbind.lc │ ├── unixdgcli01.c │ ├── unixdgcli01.lc │ ├── unixdgserv01.c │ ├── unixstrcli01.c │ ├── unixstrserv01.c │ ├── unixstrserv01.lc │ └── unixstrserv02.c ├── go ├── http │ └── http.go ├── ipconv │ └── ipconv.go ├── mcrypt │ └── mcrypt.go ├── run.sh ├── tool │ └── tool.go └── trans │ └── trans.go ├── php ├── LICENSE ├── README.md ├── daemon │ ├── Autoload.php │ ├── Daemon.php │ ├── Database.php │ ├── README.md │ ├── Register.php │ ├── Worker.php │ └── test.php ├── design_pattern │ ├── README.MD │ ├── abstract_factory.php │ ├── adapter.php │ ├── bridge.php │ ├── builder.php │ ├── chain_of_responsibility.php │ ├── command.php │ ├── composite.php │ ├── decorator.php │ ├── facade.php │ ├── factory.php │ ├── filter.php │ ├── flyweight.php │ ├── interpreter.php │ ├── iterator.php │ ├── mediator.php │ ├── memento.php │ ├── prototype.php │ ├── proxy.php │ └── singleton.php ├── distributed_task_server │ ├── README.md │ ├── TimerWheel.php │ ├── client.php │ ├── epoll.php │ ├── event.php │ ├── logger.php │ ├── lx_clip1562223966808_lx.jpg │ ├── maxcpuid.php │ ├── member.php │ ├── protocol.php │ ├── server.php │ ├── spiderman.php │ ├── start.php │ ├── tasker.php │ └── timer.php ├── library │ ├── Counter.php │ ├── Counter2.php │ ├── Counter3.php │ ├── README.MD │ ├── Redis.php │ └── StreamHttpClient.php ├── pcntl │ ├── README.MD │ ├── libevent │ │ ├── client.php │ │ ├── polling.php │ │ ├── polling_use_buffered.php │ │ └── server.php │ ├── msg_queue.php │ ├── pipe.php │ ├── select │ │ ├── client.php │ │ └── server.php │ ├── shmop.php │ ├── signal.php │ ├── simple.php │ ├── socket_unix_client.php │ └── socket_unix_server.php ├── php-http-server │ ├── Http.php │ ├── SelectServer.php │ ├── Server.php │ ├── index.php │ └── test.php ├── sort │ ├── bucket.php │ ├── build_heap.php │ ├── counting.php │ ├── heap.php │ ├── merge.php │ └── radix.php ├── test │ ├── ClassLoader.php │ ├── ClassLoaderTest.php │ ├── Container.php │ ├── Curl.php │ ├── CurlTRJ.php │ ├── Shmop2.php │ ├── StreamHttpClient.php │ ├── TimeWheel.php │ ├── Tool.php │ ├── check_card.php │ ├── class.php │ ├── date2int.php │ ├── faceid.php │ ├── fwrite.php │ ├── load_class.php │ ├── mbsplit.php │ ├── mcrypt.php │ ├── mysqli.php │ ├── pcntl_simple.php │ ├── recursion.php │ ├── select │ │ ├── client.php │ │ └── server.php │ ├── shm.php │ ├── shmop.php │ ├── skiplist.php │ ├── stdout.php │ ├── stream.php │ ├── test.php │ ├── test2.php │ ├── yac.php │ └── 新建文本文档.txt ├── ygtoo │ ├── README.md │ ├── SwooleProcess.php │ ├── array_hash_collision.php │ ├── consistent_hashing.php │ ├── ques_push │ │ ├── README.md │ │ ├── ques_push.php │ │ ├── start_ques_push.sh │ │ ├── start_work.sh │ │ └── worker.php │ └── redis_server.php └── yield │ ├── test1.php │ ├── test2.php │ ├── test3.php │ └── test4.php └── tensorflow ├── BasicClassification.py ├── BoostedTrees.py ├── BoostedTreesModel.py ├── CNNMnist.py ├── CustomLayers.py ├── CustomTrainingBasics.py ├── CustomTrainingWalkthrough.py ├── EagerExecution.py ├── LinearModelWithEstimators.py ├── RabbishSMSIdentification ├── ConversionToInt.py ├── TFtest.py └── readme.md ├── Recommedation ├── CreateGenre.py ├── CreateRatings.py ├── CreateTest.py ├── README.md ├── Recommedation.py ├── Recommedation2.py ├── RecommendationSoftmax.py ├── content.csv ├── content1000.csv ├── data.csv └── users.csv ├── Recommend ├── ExportArticle.py ├── ExportArticleInc.py ├── InvalidArticlel.py ├── KeywordsExtract.py ├── KeywordsExtractInc.py ├── RecommedationInc.py ├── RecommedationYule.py ├── SaveGenreList.py ├── SaveGenreListInc.py ├── config │ ├── config.json │ └── config_bjyt.json ├── lib │ ├── __init__.py │ ├── bootstrap.py │ ├── mysql.py │ └── pinyin.py ├── model │ ├── CFModel.py │ ├── IncCFModel.py │ └── __init__.py ├── run_inc.sh └── run_loop.sh ├── RecommendationSystems.py ├── RecommendationSystemsColab.py ├── RecommendationSystemsSoftmax.py ├── Regression.py ├── SaveRestore.py ├── TextClassification.py ├── TextClassificationNgram.py ├── TextClassificationSequence.py └── TextGenerationRNN.py /README.md: -------------------------------------------------------------------------------- 1 | # study 2 | 3 | 这里是我的学习笔记 -------------------------------------------------------------------------------- /c/README.md: -------------------------------------------------------------------------------- 1 | # c 2 | c语言学习代码 3 | -------------------------------------------------------------------------------- /c/graph/queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TRUE 1 5 | #define FALSE 0 6 | 7 | typedef struct _queue 8 | { 9 | int head;//头 10 | int tail;//尾 11 | void *A[17];//指针数组 12 | int length; 13 | int cnt; 14 | } queue; 15 | 16 | void enqueue(queue *Q, void *x); 17 | 18 | void * dequeue(queue *Q); 19 | 20 | void init_queue(queue *Q, int l); -------------------------------------------------------------------------------- /c/graph/strongly_connected_components.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | strongly_connected_components(graph *G) 4 | { 5 | dfs(G); 6 | GT = compute(G); 7 | dfs(GT); 8 | dfs_tree(GT); 9 | } 10 | -------------------------------------------------------------------------------- /c/other/merge.c: -------------------------------------------------------------------------------- 1 | /* 算法导论2.3.1 合并算法 */ 2 | #include 3 | 4 | int main() 5 | { 6 | int a[5] = {1,3,5,8,9}; 7 | int b[3] = {2,4,7}; 8 | int c[10]; 9 | int i = 0,j = 0; 10 | 11 | while( i < 5 || j < 3 ){ 12 | if( (a[i] <= b[j] && i < 5) || j == 3 ){ 13 | c[i+j] = a[i]; 14 | i++; 15 | }else{ 16 | c[i+j] = b[j]; 17 | j++; 18 | } 19 | } 20 | 21 | int k; 22 | for(k = 0; k < i+j; k++){ 23 | printf("index:%d c:%d\n", k, c[k]); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /c/php72-libevent/CREDITS: -------------------------------------------------------------------------------- 1 | Antony Dovgal, Arnaud Le Blanc 2 | -------------------------------------------------------------------------------- /c/php72-libevent/README.md: -------------------------------------------------------------------------------- 1 | libevent扩展升级php7.2版本,还没升级完成,切勿用于生产环境,只限学习交流 2 | 3 | 目前已更新的function: 4 | * event_base_new 5 | * event_new 6 | * event_set 7 | * event_base_set 8 | * event_add 9 | * event_base_loop 10 | * event_buffer_new 11 | * event_buffer_base_set 12 | * event_buffer_timeout_set 13 | * event_buffer_watermark_set 14 | * event_buffer_priority_set 15 | * event_buffer_enable 16 | * event_buffer_read 17 | * event_buffer_write 18 | * event_buffer_disable 19 | * event_buffer_free 20 | -------------------------------------------------------------------------------- /c/tipi/sapi.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inferne/notes/bbe2875e155c14a8d8a229aa3142d263cb537e78/c/tipi/sapi.xlsx -------------------------------------------------------------------------------- /c/tipi/test.c: -------------------------------------------------------------------------------- 1 | 2 | PHP_MINIT_FUNCTION(myphpextension) 3 | { 4 | //注册常量或者类初始化操作 5 | return SUCCESS; 6 | } 7 | 8 | PHP_RINIT_FUNCTION(myphpextension) 9 | { 10 | //例如记录请求开始时间 11 | //随后在请求结束的时候记录请求结束时间。这样我们就能记录下处理请求所花费的时间了 12 | return SUCCESS; 13 | } 14 | 15 | PHP_RSHUTDOWN_FUNCTION(myphpextension) 16 | { 17 | //例如记录请求结束时间,并把相应的信息写入到日志文件中。 18 | return SUCCESS; 19 | } 20 | 21 | PHP_MSHUTDOWN_FUNCTION(myphpextension) 22 | { 23 | return SUCCESS; 24 | } -------------------------------------------------------------------------------- /c/unix_c/10/10.12.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | 3 | /* Reliable version of signal(), using POSIX sigaction(). */ 4 | Sigfunc * 5 | signal(int signo, Sigfunc *func) 6 | { 7 | struct sigaction act, oact; 8 | act.sa_handle = func; 9 | sigemptyset(&act.sa_mask); 10 | act.sa_flags = 0; 11 | if(signo == SIGALRM){ 12 | #ifdef SA_INTERRUPT 13 | act.sa_flags |= SA_INTERRUPT; 14 | #endif 15 | }else{ 16 | #ifdef SA_RESTART 17 | act.sa_flags |= SA_RESTART; 18 | #endif 19 | } 20 | if(sigaction(signo, &act, &oact) < 0){ 21 | return SIG_ERR; 22 | } 23 | return oact.sa_handle; 24 | } -------------------------------------------------------------------------------- /c/unix_c/10/10.13.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | 3 | /* Reliable version of signal(), using POSIX sigaction(). */ 4 | Sigfunc * 5 | signal_intr(int signo, Sigfunc *func) 6 | { 7 | struct sigaction act, oact; 8 | 9 | act.sa_handle = func; 10 | sigemptyset(&act.sa_mask); 11 | act.sa_flags = 0; 12 | #ifdef SA_INTERRUPT 13 | act.sa_flags |= SA_INTERRUPT; 14 | #endif 15 | if(sigaction(signo, &act, &oact) < 0){ 16 | return SIG_ERR; 17 | } 18 | return oact.sa_handle; 19 | } -------------------------------------------------------------------------------- /c/unix_c/10/10.19.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | 3 | static void 4 | sig_int(int signo) 5 | { 6 | printf("caught SIGINT\n"); 7 | } 8 | 9 | static void 10 | sig_chld(int signo) 11 | { 12 | printf("caught SIGCHLD\n"); 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | if(signal(SIGINT, sig_int) == SIG_ERR) 19 | err_sys("signal(SIGINT) error"); 20 | if(signal(SIGCHLD, sig_chld) == SIG_ERR) 21 | err_sys("signal(SIGCHLD) error"); 22 | if(system("/bin/ed") < 0) 23 | err_sys("system() error"); 24 | exit(0); 25 | } -------------------------------------------------------------------------------- /c/unix_c/10/10.5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static jmp_buf env_alrm; 6 | 7 | static void 8 | sig_alrm(int signo) 9 | { 10 | longjmp(env_alrm, 1); 11 | } 12 | 13 | unsigned int 14 | sleep2(unsigned int nsecs) 15 | { 16 | if(signal(SIGALRM, sig_alrm) == SIG_ERR){ 17 | return nsecs; 18 | } 19 | if(setjmp(env_alrm) == 0){ 20 | alarm(nsecs); /* start the timer */ 21 | pause(); /* next caught signal wakes us up */ 22 | } 23 | return alarm(0); /* turn off timer, return unslept time */ 24 | } -------------------------------------------------------------------------------- /c/unix_c/16/16.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 0x12345678; 6 | 7 | printf("[0]:0x%x\n", *((char *)&x + 0)); 8 | printf("[1]:0x%x\n", *((char *)&x + 1)); 9 | printf("[2]:0x%x\n", *((char *)&x + 2)); 10 | printf("[3]:0x%x\n", *((char *)&x + 3)); 11 | 12 | return 0; 13 | } 14 | 15 | // [0]:0x78 16 | // [1]:0x56 17 | // [2]:0x34 18 | // [3]:0x12 19 | -------------------------------------------------------------------------------- /c/unix_c/17/open_server_1/cli_args.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called bu buf_args(), which is called by 5 | * request(). buf_args() has broken up the client's buffer 6 | * into an argv[]-style array, which we now process. 7 | */ 8 | int cli_args(int argc, char **argv) 9 | { 10 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 11 | strcpy(errmsg, "usage: \n"); 12 | return -1; 13 | } 14 | pathname = argv[1]; /* save ptr to pathname to open */ 15 | oflag = atoi(argv[2]); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /c/unix_c/17/open_server_1/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | int csopen(char *, int); -------------------------------------------------------------------------------- /c/unix_c/17/open_server_1/opend.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | extern char errmsg[]; /* error message string to return to client */ 7 | extern int oflag; /* open() flag: O_xxx ... */ 8 | extern char *pathname; /* of file to open() for client */ 9 | 10 | int cli_args(int, char **); 11 | void request(char *, int, int); -------------------------------------------------------------------------------- /c/unix_c/17/open_server_1/server.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | char errmsg[MAXLINE]; 4 | int oflag; 5 | char *pathname; 6 | 7 | int main(void) 8 | { 9 | int nread; 10 | char buf[MAXLINE]; 11 | 12 | for ( ; ; ) { /* read arg buffer from client, process request */ 13 | if ((nread = read(STDIN_FILENO, buf, MAXLINE)) < 0) 14 | err_sys("read error on stream pipe"); 15 | else if (nread == 0) 16 | break; /* client has closed the stream pipe */ 17 | request(buf, nread, STDOUT_FILENO); 18 | } 19 | exit(0); 20 | } -------------------------------------------------------------------------------- /c/unix_c/17/open_server_2/cli_args.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called bu buf_args(), which is called by 5 | * request(). buf_args() has broken up the client's buffer 6 | * into an argv[]-style array, which we now process. 7 | */ 8 | int cli_args(int argc, char **argv) 9 | { 10 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 11 | strcpy(errmsg, "usage: \n"); 12 | return -1; 13 | } 14 | pathname = argv[1]; /* save ptr to pathname to open */ 15 | oflag = atoi(argv[2]); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /c/unix_c/17/open_server_2/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | #define CS_OPEN "/home/sar/opend" /* server's well-known name */ 6 | 7 | int csopen(char *, int); -------------------------------------------------------------------------------- /c/unix_c/17/send_err.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | /* 4 | * Used when we had planned to send an fd using using send_fd(), 5 | * but encountered an error instead. We send the error back 6 | * using the send_fd()/recv_fd() protocol. 7 | */ 8 | int 9 | send_err(int fd, int errcode, const char *msg) 10 | { 11 | int n; 12 | if((n = strlen(msg)) > 0) 13 | if(writen(fd, msg, n) != n) /* send the error message */ 14 | return -1; 15 | if(errcode >= 0) 16 | errcode = -1; /* must be negative */ 17 | if(send_fd(fd, errcode) < 0) 18 | return -1; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /c/unix_c/18/README.md: -------------------------------------------------------------------------------- 1 | # 第18章 终端I/O 2 | 3 | ## 18.1 引言 4 | 所有操作系统的终端I/O处理都是非常繁琐的,UNIX也不例外。在大多数版本的UNIX手册中,终端I/O手册常常是最长的部分。 5 | 6 | ## 18.2 综述 7 | 终端I/O有两种不同的工作模式: 8 | 1. 规范模式输入处理(Canonical mode input prosessing)。在这种模式中,终端输入以行为单位进行处理。对于每个读要求,终端驱动程序最多返回一行。 9 | 2. 非规范模式处理(Noncanonical mode input processing)。输入字符并不组成行。 10 | -------------------------------------------------------------------------------- /c/unix_c/20/README.md: -------------------------------------------------------------------------------- 1 | # 第20章 数据库函数库 2 | -------------------------------------------------------------------------------- /c/unix_c/4/4.16.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | if (open("tempfile", O_RDWR) < 0) 8 | err_sys("open_error"); 9 | if (unlink("tempfile") < 0) 10 | err_sys("unlink error"); 11 | printf("file unlinked\n"); 12 | sleep(15); 13 | printf("done\n"); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_c/4/4.23.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | 3 | int main(void) 4 | { 5 | if (chdir("/tmp") < 0) 6 | err_sys("chdir failed"); 7 | printf("chdir to /tmp succeeded\n"); 8 | exit(0); 9 | } 10 | -------------------------------------------------------------------------------- /c/unix_c/4/4.24.c: -------------------------------------------------------------------------------- 1 | #include "../lib/apue.h" 2 | 3 | int main(void) 4 | { 5 | char *ptr; 6 | size_t size; 7 | if (chdir("/usr/spool/uucppublic") < 0) 8 | err_sys("chdir failed"); 9 | ptr = path_alloc(&size); /* our own function */ 10 | if (getcwd(ptr, size) == NULL) 11 | err_sys("getcwd failed"); 12 | printf("cwd = %s\n", ptr); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/README.md: -------------------------------------------------------------------------------- 1 | # unix_c 2 | 项目存放《unix环境高级编程》的学习代码 3 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/Make.libapue.inc: -------------------------------------------------------------------------------- 1 | $(LIBAPUE): 2 | (cd $(ROOT)/lib && $(MAKE)) 3 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/Makefile: -------------------------------------------------------------------------------- 1 | DIRS = lib intro sockets advio daemons datafiles db environ \ 2 | fileio filedir ipc1 ipc2 proc pty relation signals standards \ 3 | stdio termios threadctl threads printer exercises 4 | 5 | all: 6 | for i in $(DIRS); do \ 7 | (cd $$i && echo "making $$i" && $(MAKE) ) || exit 1; \ 8 | done 9 | 10 | clean: 11 | for i in $(DIRS); do \ 12 | (cd $$i && echo "cleaning $$i" && $(MAKE) clean) || exit 1; \ 13 | done 14 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/README: -------------------------------------------------------------------------------- 1 | Read the file called DISCLAIMER. 2 | 3 | On Freebsd, type "gmake". 4 | On other platforms, type "make" (as long as this is gnu make). 5 | 6 | For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com. 7 | Please direct questions, suggestions, and bug reports to sar@apuebook.com. 8 | 9 | Steve Rago 10 | January 2013 11 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/advio/fixup.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | BEGIN { 3 | ready = 0 4 | } 5 | /^translate/ { 6 | ready = 1 7 | next 8 | } 9 | /^{/ { 10 | next 11 | } 12 | /^}/ { 13 | ready = 0 14 | next 15 | } 16 | { 17 | if (ready) 18 | print $0 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/advio/lockfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | lockfile(int fd) 6 | { 7 | struct flock fl; 8 | 9 | fl.l_type = F_WRLCK; 10 | fl.l_start = 0; 11 | fl.l_whence = SEEK_SET; 12 | fl.l_len = 0; 13 | return(fcntl(fd, F_SETLK, &fl)); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/advio/readn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Read "n" bytes from a descriptor */ 4 | readn(int fd, void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nread; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nread = read(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount read so far */ 16 | } else if (nread == 0) { 17 | break; /* EOF */ 18 | } 19 | nleft -= nread; 20 | ptr += nread; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/advio/writen.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Write "n" bytes to a descriptor */ 4 | writen(int fd, const void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nwritten; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nwritten = write(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount written so far */ 16 | } else if (nwritten == 0) { 17 | break; 18 | } 19 | nleft -= nwritten; 20 | ptr += nwritten; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/daemons/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | all: init.o reread.o reread2.o single.o 6 | 7 | clean: 8 | rm -f $(TEMPFILES) *.o 9 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/datafiles/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = strftime 6 | 7 | all: $(PROGS) getpwnam.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/datafiles/getpwnam.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct passwd * 6 | getpwnam(const char *name) 7 | { 8 | struct passwd *ptr; 9 | 10 | setpwent(); 11 | while ((ptr = getpwent()) != NULL) 12 | if (strcmp(name, ptr->pw_name) == 0) 13 | break; /* found a match */ 14 | endpwent(); 15 | return(ptr); /* ptr is NULL if no match found */ 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/datafiles/strftime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | time_t t; 9 | struct tm *tmp; 10 | char buf1[16]; 11 | char buf2[64]; 12 | 13 | time(&t); 14 | tmp = localtime(&t); 15 | if (strftime(buf1, 16, "time and date: %r, %a %b %d, %Y", tmp) == 0) 16 | printf("buffer length 16 is too small\n"); 17 | else 18 | printf("%s\n", buf1); 19 | if (strftime(buf2, 64, "time and date: %r, %a %b %d, %Y", tmp) == 0) 20 | printf("buffer length 64 is too small\n"); 21 | else 22 | printf("%s\n", buf2); 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/db/t4.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include "apue_db.h" 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | DBHANDLE db; 9 | 10 | if ((db = db_open("db4", O_RDWR | O_CREAT | O_TRUNC, 11 | FILE_MODE)) == NULL) 12 | err_sys("db_open error"); 13 | 14 | if (db_store(db, "Alpha", "data1", DB_INSERT) != 0) 15 | err_quit("db_store error for alpha"); 16 | if (db_store(db, "beta", "Data for beta", DB_INSERT) != 0) 17 | err_quit("db_store error for beta"); 18 | if (db_store(db, "gamma", "record3", DB_INSERT) != 0) 19 | err_quit("db_store error for gamma"); 20 | 21 | db_close(db); 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = doatexit echoarg getrlimit hello1 testjmp 6 | 7 | all: $(PROGS) opendata.o scope.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/cmd2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define TOK_ADD 5 5 | 6 | jmp_buf jmpbuffer; 7 | 8 | int 9 | main(void) 10 | { 11 | char line[MAXLINE]; 12 | 13 | if (setjmp(jmpbuffer) != 0) 14 | printf("error"); 15 | while (fgets(line, MAXLINE, stdin) != NULL) 16 | do_line(line); 17 | exit(0); 18 | } 19 | 20 | . . . 21 | 22 | void 23 | cmd_add(void) 24 | { 25 | int token; 26 | 27 | token = get_token(); 28 | if (token < 0) /* an error has occurred */ 29 | longjmp(jmpbuffer, 1); 30 | /* rest of processing for this command */ 31 | } 32 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/echoarg.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int i; 7 | 8 | for (i = 0; i < argc; i++) /* echo all command-line args */ 9 | printf("argv[%d]: %s\n", i, argv[i]); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/hello1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | printf("hello, world\n"); 6 | } 7 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/opendata.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | FILE * 4 | open_data(void) 5 | { 6 | FILE *fp; 7 | char databuf[BUFSIZ]; /* setvbuf makes this the stdio buffer */ 8 | 9 | if ((fp = fopen("datafile", "r")) == NULL) 10 | return(NULL); 11 | if (setvbuf(fp, databuf, _IOLBF, BUFSIZ) != 0) 12 | return(NULL); 13 | return(fp); /* error */ 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/environ/scope.c: -------------------------------------------------------------------------------- 1 | int 2 | f1(int val) 3 | { 4 | int num = 0; 5 | int *ptr = # 6 | 7 | if (val == 0) { 8 | int val; 9 | 10 | val = 5; 11 | ptr = &val; 12 | } 13 | return(*ptr + 1); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/bo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | uint32_t i = 0x04030201; 9 | unsigned char *cp = (unsigned char *)&i; 10 | 11 | if (*cp == 1) 12 | printf("little-endian\n"); 13 | else if (*cp == 4) 14 | printf("big-endian\n"); 15 | else 16 | printf("who knows?\n"); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/fifo1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define FIFO "temp.fifo" 5 | 6 | int 7 | main(void) 8 | { 9 | int fdread, fdwrite; 10 | 11 | unlink(FIFO); 12 | if (mkfifo(FIFO, FILE_MODE) < 0) 13 | err_sys("mkfifo error"); 14 | if ((fdread = open(FIFO, O_RDONLY | O_NONBLOCK)) < 0) 15 | err_sys("open error for reading"); 16 | if ((fdwrite = open(FIFO, O_WRONLY)) < 0) 17 | err_sys("open error for writing"); 18 | clr_fl(fdread, O_NONBLOCK); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/getlogin.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | FILE *fp; 7 | char *p; 8 | 9 | daemonize("getlog"); 10 | p = getlogin(); 11 | fp = fopen("/tmp/getlog.out", "w"); 12 | if (fp != NULL) { 13 | if (p == NULL) 14 | fprintf(fp, "no login name\n"); 15 | else 16 | fprintf(fp, "login name: %s\n", p); 17 | } 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/getpw44bsd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) /* FreeBSD/Mac OS X version */ 6 | { 7 | struct passwd *ptr; 8 | 9 | if ((ptr = getpwnam("sar")) == NULL) 10 | err_sys("getpwnam error"); 11 | printf("pw_passwd = %s\n", ptr->pw_passwd == NULL || 12 | ptr->pw_passwd[0] == 0 ? "(null)" : ptr->pw_passwd); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/getpwsvr4.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) /* Linux/Solaris version */ 6 | { 7 | struct spwd *ptr; 8 | 9 | if ((ptr = getspnam("sar")) == NULL) 10 | err_sys("getspnam error"); 11 | printf("sp_pwdp = %s\n", ptr->sp_pwdp == NULL || 12 | ptr->sp_pwdp[0] == 0 ? "(null)" : ptr->sp_pwdp); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/openmax.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | #define OPEN_MAX_GUESS 256 6 | 7 | long 8 | open_max(void) 9 | { 10 | long openmax; 11 | struct rlimit rl; 12 | 13 | if ((openmax = sysconf(_SC_OPEN_MAX)) < 0 || 14 | openmax == LONG_MAX) { 15 | if (getrlimit(RLIMIT_NOFILE, &rl) < 0) 16 | err_sys("can't get file limit"); 17 | if (rl.rlim_max == RLIM_INFINITY) 18 | openmax = OPEN_MAX_GUESS; 19 | else 20 | openmax = rl.rlim_max; 21 | } 22 | return(openmax); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/prtime.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | time_t caltime; 8 | struct tm *tm; 9 | char line[MAXLINE]; 10 | 11 | if ((caltime = time(NULL)) == -1) 12 | err_sys("time error"); 13 | if ((tm = localtime(&caltime)) == NULL) 14 | err_sys("localtime error"); 15 | if (strftime(line, MAXLINE, "%a %b %d %X %Z %Y\n", tm) == 0) 16 | err_sys("strftime error"); 17 | fputs(line, stdout); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/sizepipe.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int i, n; 8 | int fd[2]; 9 | 10 | if (pipe(fd) < 0) 11 | err_sys("pipe error"); 12 | set_fl(fd[1], O_NONBLOCK); 13 | 14 | /* write 1 byte at a time until pipe is full */ 15 | for (n = 0; ; n++) { 16 | if ((i = write(fd[1], "a", 1)) != 1) { 17 | printf("write ret %d, ", i); 18 | break; 19 | } 20 | } 21 | printf("pipe capacity = %d\n", n); 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/sleep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | unsigned 6 | sleep(unsigned seconds) 7 | { 8 | int n; 9 | unsigned slept; 10 | time_t start, end; 11 | struct timeval tv; 12 | 13 | tv.tv_sec = seconds; 14 | tv.tv_usec = 0; 15 | time(&start); 16 | n = select(0, NULL, NULL, NULL, &tv); 17 | if (n == 0) 18 | return(0); 19 | time(&end); 20 | slept = end - start; 21 | if (slept >= seconds) 22 | return(0); 23 | return(seconds - slept); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/sleepus_poll.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | sleep_us(unsigned int nusecs) 5 | { 6 | struct pollfd dummy; 7 | int timeout; 8 | 9 | if ((timeout = nusecs / 1000) <= 0) 10 | timeout = 1; 11 | poll(&dummy, 0, timeout); 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/sleepus_select.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | sleep_us(unsigned int nusecs) 6 | { 7 | struct timeval tval; 8 | 9 | tval.tv_sec = nusecs / 1000000; 10 | tval.tv_usec = nusecs % 1000000; 11 | select(0, NULL, NULL, NULL, &tval); 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/vfork3.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void f1(void), f2(void); 4 | 5 | int 6 | main(void) 7 | { 8 | f1(); 9 | f2(); 10 | _exit(0); 11 | } 12 | 13 | static void 14 | f1(void) 15 | { 16 | pid_t pid; 17 | 18 | if ((pid = vfork()) < 0) 19 | err_sys("vfork error"); 20 | /* child and parent both return */ 21 | } 22 | 23 | static void 24 | f2(void) 25 | { 26 | char buf[1000]; /* automatic variables */ 27 | int i; 28 | 29 | for (i = 0; i < sizeof(buf); i++) 30 | buf[i] = 0; 31 | } 32 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/exercises/zombie.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #ifdef SOLARIS 4 | #define PSCMD "ps -a -o pid,ppid,s,tty,comm" 5 | #else 6 | #define PSCMD "ps -o pid,ppid,state,tty,command" 7 | #endif 8 | 9 | int 10 | main(void) 11 | { 12 | pid_t pid; 13 | 14 | if ((pid = fork()) < 0) 15 | err_sys("fork error"); 16 | else if (pid == 0) /* child */ 17 | exit(0); 18 | 19 | /* parent */ 20 | sleep(4); 21 | system(PSCMD); 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.10: -------------------------------------------------------------------------------- 1 | ../intro/shell2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.3: -------------------------------------------------------------------------------- 1 | ../intro/ls1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.4: -------------------------------------------------------------------------------- 1 | ../intro/mycat.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.5: -------------------------------------------------------------------------------- 1 | ../intro/getcputc.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.6: -------------------------------------------------------------------------------- 1 | ../intro/hello.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.7: -------------------------------------------------------------------------------- 1 | ../intro/shell1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.8: -------------------------------------------------------------------------------- 1 | ../intro/testerror.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig1.9: -------------------------------------------------------------------------------- 1 | ../intro/uidgid.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.10: -------------------------------------------------------------------------------- 1 | ../signals/read1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.11: -------------------------------------------------------------------------------- 1 | ../signals/read2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.12: -------------------------------------------------------------------------------- 1 | ../signals/setops.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.14: -------------------------------------------------------------------------------- 1 | ../lib/prmask.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.15: -------------------------------------------------------------------------------- 1 | ../signals/critical.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.18: -------------------------------------------------------------------------------- 1 | ../lib/signal.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.19: -------------------------------------------------------------------------------- 1 | ../lib/signalintr.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.2: -------------------------------------------------------------------------------- 1 | ../signals/sigusr.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.20: -------------------------------------------------------------------------------- 1 | ../signals/mask.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.22: -------------------------------------------------------------------------------- 1 | ../signals/suspend1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.23: -------------------------------------------------------------------------------- 1 | ../signals/suspend2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.24: -------------------------------------------------------------------------------- 1 | ../lib/tellwait.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.25: -------------------------------------------------------------------------------- 1 | ../signals/abort.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.26: -------------------------------------------------------------------------------- 1 | ../signals/systest2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.28: -------------------------------------------------------------------------------- 1 | ../signals/system.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.29: -------------------------------------------------------------------------------- 1 | ../lib/sleep.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.31: -------------------------------------------------------------------------------- 1 | ../signals/sigtstp.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.5: -------------------------------------------------------------------------------- 1 | ../signals/reenter.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.6: -------------------------------------------------------------------------------- 1 | ../signals/child.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.7: -------------------------------------------------------------------------------- 1 | ../signals/sleep1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.8: -------------------------------------------------------------------------------- 1 | ../signals/sleep2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig10.9: -------------------------------------------------------------------------------- 1 | ../signals/tsleep2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.10: -------------------------------------------------------------------------------- 1 | ../threads/mutex1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.11: -------------------------------------------------------------------------------- 1 | ../threads/mutex2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.12: -------------------------------------------------------------------------------- 1 | ../threads/mutex3.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.14: -------------------------------------------------------------------------------- 1 | ../threads/rwlock.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.15: -------------------------------------------------------------------------------- 1 | ../threads/condvar.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.16: -------------------------------------------------------------------------------- 1 | ../threads/barrier.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.2: -------------------------------------------------------------------------------- 1 | ../threads/threadid.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.3: -------------------------------------------------------------------------------- 1 | ../threads/exitstatus.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.4: -------------------------------------------------------------------------------- 1 | ../threads/badexit2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig11.5: -------------------------------------------------------------------------------- 1 | ../threads/cleanup.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.11: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.12: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.13: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv3.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.16: -------------------------------------------------------------------------------- 1 | ../threadctl/suspend.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.17: -------------------------------------------------------------------------------- 1 | ../threadctl/atfork.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.4: -------------------------------------------------------------------------------- 1 | ../threadctl/detach.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig12.8: -------------------------------------------------------------------------------- 1 | ../threadctl/timeout.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig13.1: -------------------------------------------------------------------------------- 1 | ../daemons/init.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig13.6: -------------------------------------------------------------------------------- 1 | ../daemons/single.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig13.7: -------------------------------------------------------------------------------- 1 | ../daemons/reread.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig13.8: -------------------------------------------------------------------------------- 1 | ../daemons/reread2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig13.9: -------------------------------------------------------------------------------- 1 | ../lib/setfd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.1: -------------------------------------------------------------------------------- 1 | ../advio/nonblockw.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.12: -------------------------------------------------------------------------------- 1 | ../advio/mandatory.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.20: -------------------------------------------------------------------------------- 1 | ../advio/rot13a.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.21: -------------------------------------------------------------------------------- 1 | ../advio/rot13c2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.24: -------------------------------------------------------------------------------- 1 | ../advio/writen.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.27: -------------------------------------------------------------------------------- 1 | ../advio/mcopy2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.5: -------------------------------------------------------------------------------- 1 | ../lib/lockreg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.6: -------------------------------------------------------------------------------- 1 | ../lib/locktest.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.7: -------------------------------------------------------------------------------- 1 | ../advio/deadlock.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig14.9: -------------------------------------------------------------------------------- 1 | ../advio/lockfile.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.11: -------------------------------------------------------------------------------- 1 | ../ipc1/popen2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.12: -------------------------------------------------------------------------------- 1 | ../ipc1/popen.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.14: -------------------------------------------------------------------------------- 1 | ../ipc1/myuclc.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.15: -------------------------------------------------------------------------------- 1 | ../ipc1/popen1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.17: -------------------------------------------------------------------------------- 1 | ../ipc1/add2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.18: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe4.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.19: -------------------------------------------------------------------------------- 1 | ../ipc1/add2stdio.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.31: -------------------------------------------------------------------------------- 1 | ../ipc1/tshm.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.33: -------------------------------------------------------------------------------- 1 | ../ipc1/devzero.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.35: -------------------------------------------------------------------------------- 1 | ../ipc1/slock.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.5: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.6: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig15.7: -------------------------------------------------------------------------------- 1 | ../ipc1/tellwait.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.10: -------------------------------------------------------------------------------- 1 | ../sockets/clconn.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.11: -------------------------------------------------------------------------------- 1 | ../sockets/clconn2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.12: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.16: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.17: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.18: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-fd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.19: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime-dg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.20: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-dg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.22: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig16.9: -------------------------------------------------------------------------------- 1 | ../sockets/findsvc.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.10: -------------------------------------------------------------------------------- 1 | ../lib/cliconn.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.12: -------------------------------------------------------------------------------- 1 | ../lib/senderr.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.13: -------------------------------------------------------------------------------- 1 | ../lib/sendfd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.14: -------------------------------------------------------------------------------- 1 | ../lib/recvfd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.15: -------------------------------------------------------------------------------- 1 | ../ipc2/sendfd2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.16: -------------------------------------------------------------------------------- 1 | ../ipc2/recvfd2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.17: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.h -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.18: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/main.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.19: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.2: -------------------------------------------------------------------------------- 1 | ../lib/spipe.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.20: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/opend.h -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.21: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/main.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.22: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/request.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.23: -------------------------------------------------------------------------------- 1 | ../lib/bufargs.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.24: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/cliargs.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.25: -------------------------------------------------------------------------------- 1 | ../ipc2/open/open.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.26: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/opend.h -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.27: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/client.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.28: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/main.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.29: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.select.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.3: -------------------------------------------------------------------------------- 1 | ../ipc2/pollmsg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.30: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.poll.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.31: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/request.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.4: -------------------------------------------------------------------------------- 1 | ../ipc2/sendmsg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.5: -------------------------------------------------------------------------------- 1 | ../ipc2/bindunix.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.8: -------------------------------------------------------------------------------- 1 | ../lib/servlisten.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig17.9: -------------------------------------------------------------------------------- 1 | ../lib/servaccept.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.10: -------------------------------------------------------------------------------- 1 | ../termios/settty.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.11: -------------------------------------------------------------------------------- 1 | ../termios/csize.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.12: -------------------------------------------------------------------------------- 1 | ../termios/ctermid.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.13: -------------------------------------------------------------------------------- 1 | ../termios/isatty.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.14: -------------------------------------------------------------------------------- 1 | ../termios/t_isatty.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.15: -------------------------------------------------------------------------------- 1 | ../termios/ttyname.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.16: -------------------------------------------------------------------------------- 1 | ../termios/t_ttyname.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.17: -------------------------------------------------------------------------------- 1 | ../termios/getpass.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.18: -------------------------------------------------------------------------------- 1 | ../termios/t_getpass.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.20: -------------------------------------------------------------------------------- 1 | ../lib/ttymodes.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.21: -------------------------------------------------------------------------------- 1 | ../termios/t_raw.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig18.22: -------------------------------------------------------------------------------- 1 | ../termios/winch.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig19.10: -------------------------------------------------------------------------------- 1 | ../lib/ptyfork.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig19.11: -------------------------------------------------------------------------------- 1 | ../pty/main.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig19.12: -------------------------------------------------------------------------------- 1 | ../pty/loop.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig19.16: -------------------------------------------------------------------------------- 1 | ../pty/driver.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig19.9: -------------------------------------------------------------------------------- 1 | ../lib/ptyopen.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig2.13: -------------------------------------------------------------------------------- 1 | ../standards/makeconf.awk -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig2.14: -------------------------------------------------------------------------------- 1 | ../standards/conf.c.modified -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig2.16: -------------------------------------------------------------------------------- 1 | ../lib/pathalloc.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig2.17: -------------------------------------------------------------------------------- 1 | ../lib/openmax.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig20.3: -------------------------------------------------------------------------------- 1 | ../db/t4.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig3.1: -------------------------------------------------------------------------------- 1 | ../fileio/seek.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig3.11: -------------------------------------------------------------------------------- 1 | ../fileio/fileflags.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig3.12: -------------------------------------------------------------------------------- 1 | ../fileio/setfl.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig3.2: -------------------------------------------------------------------------------- 1 | ../fileio/hole.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig3.5: -------------------------------------------------------------------------------- 1 | ../fileio/mycat.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.12: -------------------------------------------------------------------------------- 1 | ../filedir/changemod.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.16: -------------------------------------------------------------------------------- 1 | ../filedir/unlink.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.21: -------------------------------------------------------------------------------- 1 | ../filedir/zap.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.22: -------------------------------------------------------------------------------- 1 | ../filedir/ftw8.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.23: -------------------------------------------------------------------------------- 1 | ../filedir/mycd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.24: -------------------------------------------------------------------------------- 1 | ../filedir/cdpwd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.25: -------------------------------------------------------------------------------- 1 | ../filedir/devrdev.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.3: -------------------------------------------------------------------------------- 1 | ../filedir/filetype.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.8: -------------------------------------------------------------------------------- 1 | ../filedir/access.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig4.9: -------------------------------------------------------------------------------- 1 | ../filedir/umask.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.11: -------------------------------------------------------------------------------- 1 | ../stdio/buf.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.12: -------------------------------------------------------------------------------- 1 | ../stdio/tempfiles.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.13: -------------------------------------------------------------------------------- 1 | ../stdio/mkstemp.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.15: -------------------------------------------------------------------------------- 1 | ../stdio/memstr.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.4: -------------------------------------------------------------------------------- 1 | ../stdio/getcputc.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig5.5: -------------------------------------------------------------------------------- 1 | ../stdio/fgetsfputs.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig6.11: -------------------------------------------------------------------------------- 1 | ../datafiles/strftime.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig6.2: -------------------------------------------------------------------------------- 1 | ../datafiles/getpwnam.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.1: -------------------------------------------------------------------------------- 1 | ../environ/hello1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.11: -------------------------------------------------------------------------------- 1 | ../environ/cmd2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.13: -------------------------------------------------------------------------------- 1 | ../environ/testjmp.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.14: -------------------------------------------------------------------------------- 1 | ../environ/opendata.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.16: -------------------------------------------------------------------------------- 1 | ../environ/getrlimit.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.3: -------------------------------------------------------------------------------- 1 | ../environ/doatexit.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.4: -------------------------------------------------------------------------------- 1 | ../environ/echoarg.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig7.9: -------------------------------------------------------------------------------- 1 | ../environ/cmd1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.1: -------------------------------------------------------------------------------- 1 | ../proc/fork1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.12: -------------------------------------------------------------------------------- 1 | ../proc/tellwait1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.13: -------------------------------------------------------------------------------- 1 | ../proc/tellwait2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.16: -------------------------------------------------------------------------------- 1 | ../proc/exec1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.17: -------------------------------------------------------------------------------- 1 | ../proc/echoall.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.20: -------------------------------------------------------------------------------- 1 | ../proc/exec2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.21: -------------------------------------------------------------------------------- 1 | ../proc/awkexample -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.22: -------------------------------------------------------------------------------- 1 | ../proc/system.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.23: -------------------------------------------------------------------------------- 1 | ../proc/systest1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.24: -------------------------------------------------------------------------------- 1 | ../proc/systest3.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.25: -------------------------------------------------------------------------------- 1 | ../proc/pruids.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.28: -------------------------------------------------------------------------------- 1 | ../proc/test1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.29: -------------------------------------------------------------------------------- 1 | ../proc/pracct.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.3: -------------------------------------------------------------------------------- 1 | ../proc/vfork1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.30: -------------------------------------------------------------------------------- 1 | ../proc/nice.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.31: -------------------------------------------------------------------------------- 1 | ../proc/times1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.5: -------------------------------------------------------------------------------- 1 | ../lib/prexit.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.6: -------------------------------------------------------------------------------- 1 | ../proc/wait1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig8.8: -------------------------------------------------------------------------------- 1 | ../proc/fork2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/fig9.12: -------------------------------------------------------------------------------- 1 | ../relation/orphan3.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figB.1: -------------------------------------------------------------------------------- 1 | ../include/apue.h -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figB.3: -------------------------------------------------------------------------------- 1 | ../lib/error.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figB.4: -------------------------------------------------------------------------------- 1 | ../lib/errorlog.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.1: -------------------------------------------------------------------------------- 1 | ../exercises/openmax.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.10: -------------------------------------------------------------------------------- 1 | ../exercises/zombie.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.12: -------------------------------------------------------------------------------- 1 | ../exercises/goodexit.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.13: -------------------------------------------------------------------------------- 1 | ../exercises/sleep.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.14: -------------------------------------------------------------------------------- 1 | ../exercises/getlogin.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.15: -------------------------------------------------------------------------------- 1 | ../exercises/pendlock.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.16: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_select.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.17: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_poll.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.18: -------------------------------------------------------------------------------- 1 | ../exercises/sizepipe.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.20: -------------------------------------------------------------------------------- 1 | ../exercises/fifo1.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.22: -------------------------------------------------------------------------------- 1 | ../exercises/bo.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.23: -------------------------------------------------------------------------------- 1 | ../exercises/asyncsocket.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.24: -------------------------------------------------------------------------------- 1 | ../exercises/pollmsg2.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.3: -------------------------------------------------------------------------------- 1 | ../exercises/longpath.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.4: -------------------------------------------------------------------------------- 1 | ../exercises/fmemopen.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.5: -------------------------------------------------------------------------------- 1 | ../exercises/getpwsvr4.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.6: -------------------------------------------------------------------------------- 1 | ../exercises/getpw44bsd.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.7: -------------------------------------------------------------------------------- 1 | ../exercises/prtime.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/figlinks/figC.8: -------------------------------------------------------------------------------- 1 | ../exercises/vfork3.c -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/access.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | if (argc != 2) 8 | err_quit("usage: a.out "); 9 | if (access(argv[1], R_OK) < 0) 10 | err_ret("access error for %s", argv[1]); 11 | else 12 | printf("read access OK\n"); 13 | if (open(argv[1], O_RDONLY) < 0) 14 | err_ret("open error for %s", argv[1]); 15 | else 16 | printf("open for reading OK\n"); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/cdpwd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | char *ptr; 7 | size_t size; 8 | 9 | if (chdir("/usr/spool/uucppublic") < 0) 10 | err_sys("chdir failed"); 11 | 12 | ptr = path_alloc(&size); /* our own function */ 13 | if (getcwd(ptr, size) == NULL) 14 | err_sys("getcwd failed"); 15 | 16 | printf("cwd = %s\n", ptr); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/changemod.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | struct stat statbuf; 7 | 8 | /* turn on set-group-ID and turn off group-execute */ 9 | 10 | if (stat("foo", &statbuf) < 0) 11 | err_sys("stat error for foo"); 12 | if (chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0) 13 | err_sys("chmod error for foo"); 14 | 15 | /* set absolute mode to "rw-r--r--" */ 16 | 17 | if (chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) 18 | err_sys("chmod error for bar"); 19 | 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/mycd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | if (chdir("/tmp") < 0) 7 | err_sys("chdir failed"); 8 | printf("chdir to /tmp succeeded\n"); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/umask.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 5 | 6 | int 7 | main(void) 8 | { 9 | umask(0); 10 | if (creat("foo", RWRWRW) < 0) 11 | err_sys("creat error for foo"); 12 | umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 13 | if (creat("bar", RWRWRW) < 0) 14 | err_sys("creat error for bar"); 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/filedir/unlink.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | if (open("tempfile", O_RDWR) < 0) 8 | err_sys("open error"); 9 | if (unlink("tempfile") < 0) 10 | err_sys("unlink error"); 11 | printf("file unlinked\n"); 12 | sleep(15); 13 | printf("done\n"); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/fileio/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = fileflags hole mycat seek 6 | 7 | all: $(PROGS) setfl.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o file.hole 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/fileio/hole.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | char buf1[] = "abcdefghij"; 5 | char buf2[] = "ABCDEFGHIJ"; 6 | 7 | int 8 | main(void) 9 | { 10 | int fd; 11 | 12 | if ((fd = creat("file.hole", FILE_MODE)) < 0) 13 | err_sys("creat error"); 14 | 15 | if (write(fd, buf1, 10) != 10) 16 | err_sys("buf1 write error"); 17 | /* offset now = 10 */ 18 | 19 | if (lseek(fd, 16384, SEEK_SET) == -1) 20 | err_sys("lseek error"); 21 | /* offset now = 16384 */ 22 | 23 | if (write(fd, buf2, 10) != 10) 24 | err_sys("buf2 write error"); 25 | /* offset now = 16394 */ 26 | 27 | exit(0); 28 | } 29 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/fileio/mycat.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #define BUFFSIZE 4096 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char buf[BUFFSIZE]; 10 | 11 | while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) 12 | if (write(STDOUT_FILENO, buf, n) != n) 13 | err_sys("write error"); 14 | 15 | if (n < 0) 16 | err_sys("read error"); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/fileio/seek.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1) 7 | printf("cannot seek\n"); 8 | else 9 | printf("seek OK\n"); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/fileio/setfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | set_fl(int fd, int flags) /* flags are file status flags to turn on */ 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 10 | err_sys("fcntl F_GETFL error"); 11 | 12 | val |= flags; /* turn on flags */ 13 | 14 | if (fcntl(fd, F_SETFL, val) < 0) 15 | err_sys("fcntl F_SETFL error"); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = getcputc hello ls1 mycat shell1 shell2 testerror uidgid 6 | 7 | all: $(PROGS) 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/getcputc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int c; 7 | 8 | while ((c = getc(stdin)) != EOF) 9 | if (putc(c, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/hello.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("hello world from process ID %ld\n", (long)getpid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/ls1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | DIR *dp; 8 | struct dirent *dirp; 9 | 10 | if (argc != 2) 11 | err_quit("usage: ls directory_name"); 12 | 13 | if ((dp = opendir(argv[1])) == NULL) 14 | err_sys("can't open %s", argv[1]); 15 | while ((dirp = readdir(dp)) != NULL) 16 | printf("%s\n", dirp->d_name); 17 | 18 | closedir(dp); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/mycat.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #define BUFFSIZE 4096 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char buf[BUFFSIZE]; 10 | 11 | while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) 12 | if (write(STDOUT_FILENO, buf, n) != n) 13 | err_sys("write error"); 14 | 15 | if (n < 0) 16 | err_sys("read error"); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/testerror.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | fprintf(stderr, "EACCES: %s\n", strerror(EACCES)); 8 | errno = ENOENT; 9 | perror(argv[0]); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/intro/uidgid.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("uid = %d, gid = %d\n", getuid(), getgid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = add2 add2stdio devzero myuclc pipe1 pipe2 pipe4 popen1 popen2 tshm 6 | 7 | all: $(PROGS) popen.o slock.o tellwait.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | slock.o: slock.c slock.h 13 | 14 | clean: 15 | rm -f $(PROGS) $(TEMPFILES) *.o 16 | 17 | include $(ROOT)/Make.libapue.inc 18 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/add2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int n, int1, int2; 7 | char line[MAXLINE]; 8 | 9 | while ((n = read(STDIN_FILENO, line, MAXLINE)) > 0) { 10 | line[n] = 0; /* null terminate */ 11 | if (sscanf(line, "%d%d", &int1, &int2) == 2) { 12 | sprintf(line, "%d\n", int1 + int2); 13 | n = strlen(line); 14 | if (write(STDOUT_FILENO, line, n) != n) 15 | err_sys("write error"); 16 | } else { 17 | if (write(STDOUT_FILENO, "invalid args\n", 13) != 13) 18 | err_sys("write error"); 19 | } 20 | } 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/add2stdio.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int int1, int2; 7 | char line[MAXLINE]; 8 | 9 | while (fgets(line, MAXLINE, stdin) != NULL) { 10 | if (sscanf(line, "%d%d", &int1, &int2) == 2) { 11 | if (printf("%d\n", int1 + int2) == EOF) 12 | err_sys("printf error"); 13 | } else { 14 | if (printf("invalid args\n") == EOF) 15 | err_sys("printf error"); 16 | } 17 | } 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/myuclc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int c; 8 | 9 | while ((c = getchar()) != EOF) { 10 | if (isupper(c)) 11 | c = tolower(c); 12 | if (putchar(c) == EOF) 13 | err_sys("output error"); 14 | if (c == '\n') 15 | fflush(stdout); 16 | } 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/pipe1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int n; 7 | int fd[2]; 8 | pid_t pid; 9 | char line[MAXLINE]; 10 | 11 | if (pipe(fd) < 0) 12 | err_sys("pipe error"); 13 | if ((pid = fork()) < 0) { 14 | err_sys("fork error"); 15 | } else if (pid > 0) { /* parent */ 16 | close(fd[0]); 17 | write(fd[1], "hello world\n", 12); 18 | } else { /* child */ 19 | close(fd[1]); 20 | n = read(fd[0], line, MAXLINE); 21 | write(STDOUT_FILENO, line, n); 22 | } 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/popen1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | char line[MAXLINE]; 8 | FILE *fpin; 9 | 10 | if ((fpin = popen("myuclc", "r")) == NULL) 11 | err_sys("popen error"); 12 | for ( ; ; ) { 13 | fputs("prompt> ", stdout); 14 | fflush(stdout); 15 | if (fgets(line, MAXLINE, fpin) == NULL) /* read from pipe */ 16 | break; 17 | if (fputs(line, stdout) == EOF) 18 | err_sys("fputs error to pipe"); 19 | } 20 | if (pclose(fpin) == -1) 21 | err_sys("pclose error"); 22 | putchar('\n'); 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc1/slock.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct slock { 7 | sem_t *semp; 8 | char name[_POSIX_NAME_MAX]; 9 | }; 10 | 11 | struct slock * s_alloc(); 12 | void s_free(struct slock *); 13 | int s_lock(struct slock *); 14 | int s_trylock(struct slock *); 15 | int s_unlock(struct slock *); 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/bindunix.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | int fd, size; 9 | struct sockaddr_un un; 10 | 11 | un.sun_family = AF_UNIX; 12 | strcpy(un.sun_path, "foo.socket"); 13 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 14 | err_sys("socket failed"); 15 | size = offsetof(struct sockaddr_un, sun_path) + strlen(un.sun_path); 16 | if (bind(fd, (struct sockaddr *)&un, size) < 0) 17 | err_sys("bind failed"); 18 | printf("UNIX domain socket bound\n"); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/open.fe/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = openclient 10 | 11 | all: $(PROGS) 12 | 13 | openclient: main.o open.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o openclient main.o open.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/open.fe/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | int csopen(char *, int); 7 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/open/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = openclient 10 | 11 | all: $(PROGS) 12 | 13 | openclient: main.o open.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o openclient main.o open.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/open/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | #define CS_OPEN "/tmp/opend.socket" /* server's well-known name */ 6 | 7 | int csopen(char *, int); 8 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/opend.fe/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = opend 10 | 11 | all: $(PROGS) 12 | 13 | opend: main.o request.o cliargs.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o opend main.o cliargs.o request.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/opend.fe/cliargs.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called by buf_args(), which is called by 5 | * handle_request(). buf_args() has broken up the client's 6 | * buffer into an argv[]-style array, which we now process. 7 | */ 8 | int 9 | cli_args(int argc, char **argv) 10 | { 11 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 12 | strcpy(errmsg, "usage: \n"); 13 | return(-1); 14 | } 15 | pathname = argv[1]; /* save ptr to pathname to open */ 16 | oflag = atoi(argv[2]); 17 | return(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/opend.fe/main.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | char errmsg[MAXLINE]; 4 | int oflag; 5 | char *pathname; 6 | 7 | int 8 | main(void) 9 | { 10 | int nread; 11 | char buf[MAXLINE]; 12 | 13 | for ( ; ; ) { /* read arg buffer from client, process request */ 14 | if ((nread = read(STDIN_FILENO, buf, MAXLINE)) < 0) 15 | err_sys("read error on stream pipe"); 16 | else if (nread == 0) 17 | break; /* client has closed the stream pipe */ 18 | handle_request(buf, nread, STDOUT_FILENO); 19 | } 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/opend.fe/opend.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | extern char errmsg[]; /* error message string to return to client */ 7 | extern int oflag; /* open() flag: O_xxx ... */ 8 | extern char *pathname; /* of file to open() for client */ 9 | 10 | int cli_args(int, char **); 11 | void handle_request(char *, int, int); 12 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/ipc2/opend/cliargs.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called by buf_args(), which is called by 5 | * handle_request(). buf_args() has broken up the client's 6 | * buffer into an argv[] style array, which we now process. 7 | */ 8 | int 9 | cli_args(int argc, char **argv) 10 | { 11 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 12 | strcpy(errmsg, "usage: \n"); 13 | return(-1); 14 | } 15 | pathname = argv[1]; /* save ptr to pathname to open */ 16 | oflag = atoi(argv[2]); 17 | return(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/clrfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | clr_fl(int fd, int flags) 6 | /* flags are the file status flags to turn off */ 7 | { 8 | int val; 9 | 10 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 11 | err_sys("fcntl F_GETFL error"); 12 | 13 | val &= ~flags; /* turn flags off */ 14 | 15 | if (fcntl(fd, F_SETFL, val) < 0) 16 | err_sys("fcntl F_SETFL error"); 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/lockreg.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len) 6 | { 7 | struct flock lock; 8 | 9 | lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ 10 | lock.l_start = offset; /* byte offset, relative to l_whence */ 11 | lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ 12 | lock.l_len = len; /* #bytes (0 means to EOF) */ 13 | 14 | return(fcntl(fd, cmd, &lock)); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/prexit.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | pr_exit(int status) 6 | { 7 | if (WIFEXITED(status)) 8 | printf("normal termination, exit status = %d\n", 9 | WEXITSTATUS(status)); 10 | else if (WIFSIGNALED(status)) 11 | printf("abnormal termination, signal number = %d%s\n", 12 | WTERMSIG(status), 13 | #ifdef WCOREDUMP 14 | WCOREDUMP(status) ? " (core file generated)" : ""); 15 | #else 16 | ""); 17 | #endif 18 | else if (WIFSTOPPED(status)) 19 | printf("child stopped, signal number = %d\n", 20 | WSTOPSIG(status)); 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/readn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Read "n" bytes from a descriptor */ 4 | readn(int fd, void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nread; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nread = read(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount read so far */ 16 | } else if (nread == 0) { 17 | break; /* EOF */ 18 | } 19 | nleft -= nread; 20 | ptr += nread; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/senderr.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | /* 4 | * Used when we had planned to send an fd using send_fd(), 5 | * but encountered an error instead. We send the error back 6 | * using the send_fd()/recv_fd() protocol. 7 | */ 8 | int 9 | send_err(int fd, int errcode, const char *msg) 10 | { 11 | int n; 12 | 13 | if ((n = strlen(msg)) > 0) 14 | if (writen(fd, msg, n) != n) /* send the error message */ 15 | return(-1); 16 | 17 | if (errcode >= 0) 18 | errcode = -1; /* must be negative */ 19 | 20 | if (send_fd(fd, errcode) < 0) 21 | return(-1); 22 | 23 | return(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/setfd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | set_cloexec(int fd) 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFD, 0)) < 0) 10 | return(-1); 11 | 12 | val |= FD_CLOEXEC; /* enable close-on-exec */ 13 | 14 | return(fcntl(fd, F_SETFD, val)); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/setfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | set_fl(int fd, int flags) /* flags are file status flags to turn on */ 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 10 | err_sys("fcntl F_GETFL error"); 11 | 12 | val |= flags; /* turn on flags */ 13 | 14 | if (fcntl(fd, F_SETFL, val) < 0) 15 | err_sys("fcntl F_SETFL error"); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/signal.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | /* Reliable version of signal(), using POSIX sigaction(). */ 4 | Sigfunc * 5 | signal(int signo, Sigfunc *func) 6 | { 7 | struct sigaction act, oact; 8 | 9 | act.sa_handler = func; 10 | sigemptyset(&act.sa_mask); 11 | act.sa_flags = 0; 12 | if (signo == SIGALRM) { 13 | #ifdef SA_INTERRUPT 14 | act.sa_flags |= SA_INTERRUPT; 15 | #endif 16 | } else { 17 | act.sa_flags |= SA_RESTART; 18 | } 19 | if (sigaction(signo, &act, &oact) < 0) 20 | return(SIG_ERR); 21 | return(oact.sa_handler); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/signalintr.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | Sigfunc * 4 | signal_intr(int signo, Sigfunc *func) 5 | { 6 | struct sigaction act, oact; 7 | 8 | act.sa_handler = func; 9 | sigemptyset(&act.sa_mask); 10 | act.sa_flags = 0; 11 | #ifdef SA_INTERRUPT 12 | act.sa_flags |= SA_INTERRUPT; 13 | #endif 14 | if (sigaction(signo, &act, &oact) < 0) 15 | return(SIG_ERR); 16 | return(oact.sa_handler); 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/sleepus.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | sleep_us(unsigned int nusecs) 6 | { 7 | struct timeval tval; 8 | 9 | tval.tv_sec = nusecs / 1000000; 10 | tval.tv_usec = nusecs % 1000000; 11 | select(0, NULL, NULL, NULL, &tval); 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/spipe.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | /* 5 | * Returns a full-duplex pipe (a UNIX domain socket) with 6 | * the two file descriptors returned in fd[0] and fd[1]. 7 | */ 8 | int 9 | fd_pipe(int fd[2]) 10 | { 11 | return(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)); 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/strerror.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef LINUX 4 | extern char *sys_errlist[]; 5 | extern int sys_nerr; 6 | #endif 7 | 8 | char * 9 | strerror(int error) 10 | { 11 | static char mesg[30]; 12 | 13 | if (error >= 0 && error <= sys_nerr) 14 | return((char *)sys_errlist[error]); 15 | 16 | sprintf(mesg, "Unknown error (%d)", error); 17 | return(mesg); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/lib/writen.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Write "n" bytes to a descriptor */ 4 | writen(int fd, const void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nwritten; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nwritten = write(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount written so far */ 16 | } else if (nwritten == 0) { 17 | break; 18 | } 19 | nleft -= nwritten; 20 | ptr += nwritten; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/awkexample: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | # Note: on Solaris, use nawk instead 3 | BEGIN { 4 | for (i = 0; i < ARGC; i++) 5 | printf "ARGV[%d] = %s\n", i, ARGV[i] 6 | exit 7 | } 8 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/echoall.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int i; 7 | char **ptr; 8 | extern char **environ; 9 | 10 | for (i = 0; i < argc; i++) /* echo all command-line args */ 11 | printf("argv[%d]: %s\n", i, argv[i]); 12 | 13 | for (ptr = environ; *ptr != 0; ptr++) /* and all env strings */ 14 | printf("%s\n", *ptr); 15 | 16 | exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/exec2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | pid_t pid; 8 | 9 | if ((pid = fork()) < 0) { 10 | err_sys("fork error"); 11 | } else if (pid == 0) { /* child */ 12 | if (execl("/home/sar/bin/testinterp", 13 | "testinterp", "myarg1", "MY ARG2", (char *)0) < 0) 14 | err_sys("execl error"); 15 | } 16 | if (waitpid(pid, NULL, 0) < 0) /* parent */ 17 | err_sys("waitpid error"); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/pruids.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("real uid = %d, effective uid = %d\n", getuid(), geteuid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/systest1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int status; 8 | 9 | if ((status = system("date")) < 0) 10 | err_sys("system() error"); 11 | 12 | pr_exit(status); 13 | 14 | if ((status = system("nosuchcommand")) < 0) 15 | err_sys("system() error"); 16 | 17 | pr_exit(status); 18 | 19 | if ((status = system("who; exit 44")) < 0) 20 | err_sys("system() error"); 21 | 22 | pr_exit(status); 23 | 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/systest3.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int status; 7 | 8 | if (argc < 2) 9 | err_quit("command-line argument required"); 10 | 11 | if ((status = system(argv[1])) < 0) 12 | err_sys("system() error"); 13 | 14 | pr_exit(status); 15 | 16 | exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/proc/tellwait1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void charatatime(char *); 4 | 5 | int 6 | main(void) 7 | { 8 | pid_t pid; 9 | 10 | if ((pid = fork()) < 0) { 11 | err_sys("fork error"); 12 | } else if (pid == 0) { 13 | charatatime("output from child\n"); 14 | } else { 15 | charatatime("output from parent\n"); 16 | } 17 | exit(0); 18 | } 19 | 20 | static void 21 | charatatime(char *str) 22 | { 23 | char *ptr; 24 | int c; 25 | 26 | setbuf(stdout, NULL); /* set unbuffered */ 27 | for (ptr = str; (c = *ptr++) != 0; ) 28 | putc(c, stdout); 29 | } 30 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/pty/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = pty 10 | 11 | all: $(PROGS) 12 | 13 | pty: main.o loop.o driver.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o pty main.o loop.o driver.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/relation/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = orphan3 6 | 7 | all: $(PROGS) 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/signals/read1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void sig_alrm(int); 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char line[MAXLINE]; 10 | 11 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 12 | err_sys("signal(SIGALRM) error"); 13 | 14 | alarm(10); 15 | if ((n = read(STDIN_FILENO, line, MAXLINE)) < 0) 16 | err_sys("read error"); 17 | alarm(0); 18 | 19 | write(STDOUT_FILENO, line, n); 20 | exit(0); 21 | } 22 | 23 | static void 24 | sig_alrm(int signo) 25 | { 26 | /* nothing to do, just return to interrupt the read */ 27 | } 28 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/signals/sleep1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void 5 | sig_alrm(int signo) 6 | { 7 | /* nothing to do, just return to wake up the pause */ 8 | } 9 | 10 | unsigned int 11 | sleep1(unsigned int seconds) 12 | { 13 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 14 | return(seconds); 15 | alarm(seconds); /* start the timer */ 16 | pause(); /* next caught signal wakes us up */ 17 | return(alarm(0)); /* turn off timer, return unslept time */ 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/signals/sleep2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static jmp_buf env_alrm; 6 | 7 | static void 8 | sig_alrm(int signo) 9 | { 10 | longjmp(env_alrm, 1); 11 | } 12 | 13 | unsigned int 14 | sleep2(unsigned int seconds) 15 | { 16 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 17 | return(seconds); 18 | if (setjmp(env_alrm) == 0) { 19 | alarm(seconds); /* start the timer */ 20 | pause(); /* next caught signal wakes us up */ 21 | } 22 | return(alarm(0)); /* turn off timer, return unslept time */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/signals/systest2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void 4 | sig_int(int signo) 5 | { 6 | printf("caught SIGINT\n"); 7 | } 8 | 9 | static void 10 | sig_chld(int signo) 11 | { 12 | printf("caught SIGCHLD\n"); 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | if (signal(SIGINT, sig_int) == SIG_ERR) 19 | err_sys("signal(SIGINT) error"); 20 | if (signal(SIGCHLD, sig_chld) == SIG_ERR) 21 | err_sys("signal(SIGCHLD) error"); 22 | if (system("/bin/ed") < 0) 23 | err_sys("system() error"); 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/sockets/clconn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define MAXSLEEP 128 5 | 6 | int 7 | connect_retry(int sockfd, const struct sockaddr *addr, socklen_t alen) 8 | { 9 | int numsec; 10 | 11 | /* 12 | * Try to connect with exponential backoff. 13 | */ 14 | for (numsec = 1; numsec <= MAXSLEEP; numsec <<= 1) { 15 | if (connect(sockfd, addr, alen) == 0) { 16 | /* 17 | * Connection accepted. 18 | */ 19 | return(0); 20 | } 21 | 22 | /* 23 | * Delay before trying again. 24 | */ 25 | if (numsec <= MAXSLEEP/2) 26 | sleep(numsec); 27 | } 28 | return(-1); 29 | } 30 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/sockets/initsrv1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | int 6 | initserver(int type, const struct sockaddr *addr, socklen_t alen, 7 | int qlen) 8 | { 9 | int fd; 10 | int err = 0; 11 | 12 | if ((fd = socket(addr->sa_family, type, 0)) < 0) 13 | return(-1); 14 | if (bind(fd, addr, alen) < 0) 15 | goto errout; 16 | if (type == SOCK_STREAM || type == SOCK_SEQPACKET) { 17 | if (listen(fd, qlen) < 0) 18 | goto errout; 19 | } 20 | return(fd); 21 | 22 | errout: 23 | err = errno; 24 | close(fd); 25 | errno = err; 26 | return(-1); 27 | } 28 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/standards/pathconf-lim.sym: -------------------------------------------------------------------------------- 1 | FILESIZEBITS _PC_FILESIZEBITS 2 | LINK_MAX _PC_LINK_MAX 3 | MAX_CANON _PC_MAX_CANON 4 | MAX_INPUT _PC_MAX_INPUT 5 | NAME_MAX _PC_NAME_MAX 6 | PATH_MAX _PC_PATH_MAX 7 | PIPE_BUF _PC_PIPE_BUF 8 | SYMLINK_MAX _PC_SYMLINK_MAX 9 | _POSIX_TIMESTAMP_RESOLUTION _PC_TIMESTAMP_RESOLUTION 10 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/standards/pathconf-opt.sym: -------------------------------------------------------------------------------- 1 | _POSIX_CHOWN_RESTRICTED _PC_CHOWN_RESTRICTED 2 | _POSIX_NO_TRUNC _PC_NO_TRUNC 3 | _POSIX_VDISABLE _PC_VDISABLE 4 | _POSIX_ASYNC_IO _PC_ASYNC_IO 5 | _POSIX_PRIO_IO _PC_PRIO_IO 6 | _POSIX_SYNC_IO _PC_SYNC_IO 7 | _POSIX2_SYMLINKS _PC_2_SYMLINKS 8 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/stdio/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "linux" 6 | MEMSTR = memstr 7 | else 8 | MEMSTR = 9 | endif 10 | 11 | PROGS = buf fgetsfputs getcharbug getcputc mkstemp tempfiles 12 | 13 | all: $(PROGS) $(MEMSTR) 14 | 15 | %: %.c $(LIBAPUE) 16 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 17 | 18 | clean: 19 | rm -f $(PROGS) $(TEMPFILES) *.o $(MEMSTR) 20 | 21 | include $(ROOT)/Make.libapue.inc 22 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/stdio/fgetsfputs.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | char buf[MAXLINE]; 7 | 8 | while (fgets(buf, MAXLINE, stdin) != NULL) 9 | if (fputs(buf, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/stdio/getcharbug.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | char c; 7 | 8 | while ((c = getchar()) != EOF) 9 | putchar(c); 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/stdio/getcputc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int c; 7 | 8 | while ((c = getc(stdin)) != EOF) 9 | if (putc(c, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/systype.sh: -------------------------------------------------------------------------------- 1 | # (leading space required for Xenix /bin/sh) 2 | 3 | # 4 | # Determine the type of *ix operating system that we're 5 | # running on, and echo an appropriate value. 6 | # This script is intended to be used in Makefiles. 7 | # (This is a kludge. Gotta be a better way.) 8 | # 9 | 10 | case `uname -s` in 11 | "FreeBSD") 12 | PLATFORM="freebsd" 13 | ;; 14 | "Linux") 15 | PLATFORM="linux" 16 | ;; 17 | "Darwin") 18 | PLATFORM="macos" 19 | ;; 20 | "SunOS") 21 | PLATFORM="solaris" 22 | ;; 23 | *) 24 | echo "Unknown platform" >&2 25 | exit 1 26 | esac 27 | echo $PLATFORM 28 | exit 0 29 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/termios/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = csize settty t_getpass t_isatty t_raw t_ttyname winch 6 | 7 | all: $(PROGS) ctermid.o getpass.o isatty.o ttyname.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/termios/ctermid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static char ctermid_name[L_ctermid]; 5 | 6 | char * 7 | ctermid(char *str) 8 | { 9 | if (str == NULL) 10 | str = ctermid_name; 11 | return(strcpy(str, "/dev/tty")); /* strcpy() returns str */ 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/termios/isatty.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | isatty(int fd) 5 | { 6 | struct termios ts; 7 | 8 | return(tcgetattr(fd, &ts) != -1); /* true if no error (is a tty) */ 9 | } 10 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/termios/t_getpass.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | char *getpass(const char *); 4 | 5 | int 6 | main(void) 7 | { 8 | char *ptr; 9 | 10 | if ((ptr = getpass("Enter password:")) == NULL) 11 | err_sys("getpass error"); 12 | printf("password: %s\n", ptr); 13 | 14 | /* now use password (probably encrypt it) ... */ 15 | 16 | while (*ptr != 0) 17 | *ptr++ = 0; /* zero it out when we're done with it */ 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/termios/t_isatty.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("fd 0: %s\n", isatty(0) ? "tty" : "not a tty"); 7 | printf("fd 1: %s\n", isatty(1) ? "tty" : "not a tty"); 8 | printf("fd 2: %s\n", isatty(2) ? "tty" : "not a tty"); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/threadctl/detach.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | makethread(void *(*fn)(void *), void *arg) 6 | { 7 | int err; 8 | pthread_t tid; 9 | pthread_attr_t attr; 10 | 11 | err = pthread_attr_init(&attr); 12 | if (err != 0) 13 | return(err); 14 | err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 15 | if (err == 0) 16 | err = pthread_create(&tid, &attr, fn, arg); 17 | pthread_attr_destroy(&attr); 18 | return(err); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/threadctl/getenv1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAXSTRINGSZ 4096 5 | 6 | static char envbuf[MAXSTRINGSZ]; 7 | 8 | extern char **environ; 9 | 10 | char * 11 | getenv(const char *name) 12 | { 13 | int i, len; 14 | 15 | len = strlen(name); 16 | for (i = 0; environ[i] != NULL; i++) { 17 | if ((strncmp(name, environ[i], len) == 0) && 18 | (environ[i][len] == '=')) { 19 | strncpy(envbuf, &environ[i][len+1], MAXSTRINGSZ-1); 20 | return(envbuf); 21 | } 22 | } 23 | return(NULL); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_c/apue.3e/threads/maketimeout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | maketimeout(struct timespec *tsp, long minutes) 6 | { 7 | struct timeval now; 8 | 9 | /* get the current time */ 10 | gettimeofday(&now, NULL); 11 | tsp->tv_sec = now.tv_sec; 12 | tsp->tv_nsec = now.tv_usec * 1000; /* usec to nsec */ 13 | /* add the offset to get timeout value */ 14 | tsp->tv_sec += minutes * 60; 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/tcp/tcpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char const *argv[]) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) { 10 | err_quit("usage: tcpcli "); 11 | } 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | str_cli(stdin, sockfd); /* do it all */ 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/Makefile.in: -------------------------------------------------------------------------------- 1 | include ./Make.defines 2 | 3 | all: 4 | @echo "Nothing to make in this directory" 5 | @echo "Please read the README file" 6 | 7 | clean: 8 | rm -f $(CLEANFILES) 9 | 10 | distclean: 11 | rm -f $(CLEANFILES) config.cache config.log config.status config.h Make.defines Makefile 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/VERSION: -------------------------------------------------------------------------------- 1 | 2004/12/12 2 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/dgclitimeo.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 5 | { 6 | int n; 7 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 8 | 9 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 10 | 11 | Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); 12 | 13 | if (Readable_timeo(sockfd, 5) == 0) { 14 | fprintf(stderr, "socket timeout\n"); 15 | continue; 16 | } 17 | n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); 18 | 19 | recvline[n] = 0; /* null terminate */ 20 | Fputs(recvline, stdout); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/dgclitimeo1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 5 | { 6 | int n; 7 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 8 | 9 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 10 | 11 | Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); 12 | 13 | if (Readable_timeo(sockfd, 5) == 0) { 14 | fprintf(stderr, "socket timeout\n"); 15 | } else { 16 | n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); 17 | recvline[n] = 0; /* null terminate */ 18 | Fputs(recvline, stdout); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/script.1: -------------------------------------------------------------------------------- 1 | kalae % ./udpserv01 2 | 9-byte datagram from 206.62.226.33.41164, to 206.62.226.35, recv i/f = ef0 3 | 13-byte datagram from 206.62.226.65.1057, to 206.62.226.95, recv i/f = we0 (broadcast) 4 | 4-byte datagram from 206.62.226.33.41176, to 224.0.0.1, recv i/f = ef0 (multicast) 5 | 20-byte datagram from 127.0.0.1.4632, to 127.0.0.1, recv i/f = lo0 (datagram truncated) 6 | 9-byte datagram from 206.62.226.33.41178, to 206.62.226.66, recv i/f = ef0 7 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/sig_chld_waitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { 10 | printf("child %d terminated\n", pid); 11 | } 12 | return; 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/str_echo_stdio02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_echo(int sockfd) 5 | { 6 | char line[MAXLINE]; 7 | FILE *fpin, *fpout; 8 | 9 | fpin = Fdopen(sockfd, "r"); 10 | fpout = Fdopen(sockfd, "w"); 11 | 12 | while (Fgets(line, MAXLINE, fpin) != NULL) 13 | Fputs(line, fpout); 14 | } 15 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/tcpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/tcpcli03.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/tcpcli04.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(7); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/udpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(7); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/udpcli03.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(7); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/advio/udpserv01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin_family = AF_INET; 13 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 14 | servaddr.sin_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli01 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli02 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli03.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli03 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli04.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli04 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli05.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli05 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/bcast/udpcli06.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli02 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/debug/test01.c: -------------------------------------------------------------------------------- 1 | #include "unpxti.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int tfd; 7 | 8 | if (argc != 3) 9 | err_quit("usage: test01 "); 10 | 11 | tfd = Tcp_connect(argv[1], argv[2]); 12 | 13 | t_snd(tfd, "", 1, T_EXPEDITED); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/debug/test02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int fd; 7 | fd_set exset; 8 | 9 | if (argc != 3) 10 | err_quit("usage: test01 "); 11 | 12 | fd = Tcp_connect(argv[1], argv[2]); 13 | 14 | FD_ZERO(&exset); 15 | FD_SET(fd, &exset); 16 | select(fd+1, NULL, NULL, &exset, NULL); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/debug/test06.c: -------------------------------------------------------------------------------- 1 | #include "unpxti.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int fd; 7 | struct t_call *tcall; 8 | 9 | fd = T_open(XTI_TCP, O_RDWR, NULL); 10 | 11 | tcall = T_alloc(fd, T_CALL, T_ALL); 12 | printf("first t_alloc OK\n"); 13 | 14 | tcall = T_alloc(fd, T_CALL, T_ADDR | T_OPT | T_UDATA); 15 | printf("second t_alloc OK\n"); 16 | 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | OBJS = icmpd.o readable_listen.o readable_conn.o readable_v4.o readable_v6.o 4 | 5 | PROGS = icmpd udpcli01 6 | 7 | all: ${PROGS} 8 | 9 | icmpd: ${OBJS} 10 | ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} 11 | 12 | udpcli01: udpcli01.o dgcli01.o 13 | ${CC} ${CFLAGS} -o $@ udpcli01.o dgcli01.o ${LIBS} 14 | 15 | clean: 16 | rm -f ${PROGS} ${CLEANFILES} 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/icmpd.h: -------------------------------------------------------------------------------- 1 | #include "unpicmpd.h" 2 | 3 | struct client { 4 | int connfd; /* Unix domain stream socket to client */ 5 | int family; /* AF_INET or AF_INET6 */ 6 | int lport; /* local port bound to client's UDP socket */ 7 | /* network byte ordered */ 8 | } client[FD_SETSIZE]; 9 | 10 | /* 4globals */ 11 | int fd4, fd6, listenfd, maxi, maxfd, nready; 12 | fd_set rset, allset; 13 | struct sockaddr_un cliaddr; 14 | 15 | /* 4function prototypes */ 16 | int readable_conn(int); 17 | int readable_listen(void); 18 | int readable_v4(void); 19 | int readable_v6(void); 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/script.1: -------------------------------------------------------------------------------- 1 | kalae % ./udpcli01 198.82.204.99 echo 2 | hello, world 3 | ICMP error: type = 11, code = 0 4 | testing 5 | ICMP error: type = 11, code = 0 6 | 7 | kalae % ./udpcli01 gemini.tuc.noao.edu echo 8 | hi there 9 | ICMP error: type = 3, code = 3 10 | hello 11 | socket timeout 12 | testing 13 | ICMP error: type = 3, code = 3 14 | 15 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/script.2: -------------------------------------------------------------------------------- 1 | kalae % ./udpcli01 gemini.tuc.noao.edu echo 2 | hi there 3 | ICMPv4 error: dest = 140.252.8.54.1792, type = 3, code = 3 4 | 5 | 6 | kalae % ./udpcli01 198.82.204.99 echo 7 | hello, world 8 | ICMPv4 error: dest = 198.82.204.99.1792, type = 11, code = 0 9 | testing 10 | ICMPv4 error: dest = 198.82.204.99.1792, type = 11, code = 0 11 | 12 | 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/script.3: -------------------------------------------------------------------------------- 1 | kohala % ./udpcli01 gemini.tuc.noao.edu echo 2 | hello, world 3 | ICMP error: dest = 140.252.1.11.7, type = 3, code = 3 4 | kohala % 5 | kohala % ./udpcli 198.82.204.99 echo 6 | ksh: ./udpcli: not found 7 | kohala % ./udpcli01 198.82.204.99 echo 8 | hello, world 9 | ICMP error: dest = 198.82.204.99.7, type = 3, code = 3 10 | kohala % ./udpcli01 192.3.4.5.82.204.99 echo 11 | udp_client error for 192.3.4.5.82.204.99, echo: host nor service provided, or not known 12 | kohala % ./udpcli01 192.3.4.5 echo 13 | hello 14 | ICMP error: dest = 192.3.4.5.7, type = 3, code = 1 15 | 16 | 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/script.4: -------------------------------------------------------------------------------- 1 | kohala % ./udpcli01 192.3.4.5 echo 2 | hi there 3 | socket timeout 4 | and hello 5 | socket timeout 6 | kohala % ./udpcli01 gemini.tuc.noao.edu echo 7 | hello, world 8 | ICMP error: dest = 140.252.4.54.7, Connection refused, type = 3, code = 3 9 | kohala % ./udpcli01 192.3.4.5 echo 10 | hello 11 | ICMP error: dest = 192.3.4.5.7, No route to host, type = 3, code = 1 12 | 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | socklen_t salen; 8 | struct sockaddr *sa; 9 | 10 | if (argc != 3) 11 | err_quit("usage: udpcli01 "); 12 | 13 | sockfd = Udp_client(argv[1], argv[2], &sa, &salen); 14 | 15 | dg_cli(stdin, sockfd, sa, salen); 16 | 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/icmpd/unpicmpd.h: -------------------------------------------------------------------------------- 1 | #ifndef __unpicmp_h 2 | #define __unpicmp_h 3 | 4 | #include "unp.h" 5 | 6 | #define ICMPD_PATH "/tmp/icmpd" /* server's well-known pathname */ 7 | 8 | struct icmpd_err { 9 | int icmpd_errno;/* EHOSTUNREACH, EMSGSIZE, ECONNREFUSED */ 10 | char icmpd_type; /* actual ICMPv[46] type */ 11 | char icmpd_code; /* actual ICMPv[46] code */ 12 | socklen_t icmpd_len; /* length of sockaddr{} that follows */ 13 | struct sockaddr_storage icmpd_dest; /* sockaddr_storage handles any size */ 14 | }; 15 | 16 | #endif /* __unpicmp_h */ 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/inetd/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = daytimetcpsrv2 daytimetcpsrv3 4 | 5 | all: ${PROGS} 6 | 7 | daytimetcpsrv2: daytimetcpsrv2.o 8 | ${CC} ${CFLAGS} -o $@ daytimetcpsrv2.o ${LIBS} 9 | 10 | daytimetcpsrv3: daytimetcpsrv3.o 11 | ${CC} ${CFLAGS} -o $@ daytimetcpsrv3.o ${LIBS} 12 | 13 | clean: 14 | rm -f ${PROGS} ${CLEANFILES} 15 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/intro/byteorder.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | union { 7 | short s; 8 | char c[sizeof(short)]; 9 | } un; 10 | 11 | un.s = 0x0102; 12 | printf("%s: ", CPU_VENDOR_OS); 13 | if (sizeof(short) == 2) { 14 | if (un.c[0] == 1 && un.c[1] == 2) 15 | printf("big-endian\n"); 16 | else if (un.c[0] == 2 && un.c[1] == 1) 17 | printf("little-endian\n"); 18 | else 19 | printf("unknown\n"); 20 | } else 21 | printf("sizeof(short) = %d\n", sizeof(short)); 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/intro/truss.solaris.2.6: -------------------------------------------------------------------------------- 1 | so_socket(2, 2, 0, "", 1) = 3 2 | connect(3, 0xEFFFE8C8, 16) = 0 3 | read(3, " F r i A p r 4 1".., 4096) = 26 4 | ioctl(1, TCGETA, 0xEFFFE69C) = 0 5 | write(1, " F r i A p r 4 1".., 26) = 26 6 | read(3, 0xEFFFE8D8, 4096) = 0 7 | llseek(0, 0, SEEK_CUR) = 179866 8 | _exit(0) 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ioctl/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = lsif01 lsif02 prifinfo prmac 4 | 5 | all: ${PROGS} 6 | 7 | lsif01: lsif01.o 8 | ${CC} ${CFLAGS} -o $@ lsif01.o ${LIBS} 9 | 10 | lsif02: lsif02.o 11 | ${CC} ${CFLAGS} -o $@ lsif02.o ${LIBS} 12 | 13 | prifinfo: prifinfo.o 14 | ${CC} ${CFLAGS} -o $@ prifinfo.o ${LIBS} 15 | 16 | prmac: prmac.o 17 | ${CC} ${CFLAGS} -o $@ prmac.o ${LIBS} 18 | 19 | test1: test1.o 20 | ${CC} ${CFLAGS} -o $@ test1.o ${LIBS} 21 | 22 | clean: 23 | rm -f ${PROGS} ${CLEANFILES} 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ioctl/test1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | 4 | int 5 | main(int argc, char **argv) 6 | { 7 | int i, sockfd, numif; 8 | char buf[1024]; 9 | 10 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 11 | 12 | numif = 999; 13 | Ioctl(sockfd, SIOCGIFNUM, &numif); 14 | printf("numif = %d\n", numif); 15 | 16 | i = ioctl(sockfd, SIOCGHIWAT, &buf); 17 | printf("i = %d, errno = %d\n", i, errno); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ipopts/sigchldwaitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { 10 | printf("child %d terminated\n", pid); 11 | } 12 | return; 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ipopts/sourceroute6.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | inet6_srcrt_print(void *ptr) 5 | { 6 | int i, segments; 7 | char str[INET6_ADDRSTRLEN]; 8 | 9 | segments = Inet6_rth_segments(ptr); 10 | printf("received source route: "); 11 | for (i = 0; i < segments; i++) 12 | printf("%s ", Inet_ntop(AF_INET6, Inet6_rth_getaddr(ptr, i), 13 | str, sizeof(str))); 14 | printf("\n"); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ipopts/udpserv01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in6 servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET6, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin6_family = AF_INET6; 13 | servaddr.sin6_addr = in6addr_any; 14 | servaddr.sin6_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/key/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = dump register add 4 | OBJS = printsadbmsg.o name.o 5 | 6 | all: ${PROGS} 7 | 8 | dump: dump.o ${OBJS} 9 | ${CC} ${CFLAGS} -o $@ $@.o ${OBJS} ${LIBS} 10 | 11 | register: register.o ${OBJS} 12 | ${CC} ${CFLAGS} -o $@ $@.o ${OBJS} ${LIBS} 13 | 14 | add: add.o ${OBJS} 15 | ${CC} ${CFLAGS} -o $@ $@.o ${OBJS} ${LIBS} 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | all: ${LIB_OBJS} 4 | ar rv ${LIBUNP_NAME} $? 5 | ${RANLIB} ${LIBUNP_NAME} 6 | 7 | clean: 8 | rm -f ${PROGS} ${CLEANFILES} 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/daemon_inetd.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | 4 | extern int daemon_proc; /* defined in error.c */ 5 | 6 | void 7 | daemon_inetd(const char *pname, int facility) 8 | { 9 | daemon_proc = 1; /* for our err_XXX() functions */ 10 | openlog(pname, LOG_PID, facility); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/daemon_inetd.lc: -------------------------------------------------------------------------------- 1 | #include "unp.h"## 1 ##src/lib/daemon_inetd.c## 2 | #include ## 2 ##src/lib/daemon_inetd.c## 3 | 4 | extern int daemon_proc; /* defined in error.c */## 3 ##src/lib/daemon_inetd.c## 5 | 6 | void## 4 ##src/lib/daemon_inetd.c## 7 | daemon_inetd(const char *pname, int facility)## 5 ##src/lib/daemon_inetd.c## 8 | {## 6 ##src/lib/daemon_inetd.c## 9 | daemon_proc = 1; /* for our err_XXX() functions */## 7 ##src/lib/daemon_inetd.c## 10 | openlog(pname, LOG_PID, facility);## 8 ##src/lib/daemon_inetd.c## 11 | }## 9 ##src/lib/daemon_inetd.c## 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/dg_cli.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 5 | { 6 | int n; 7 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 8 | 9 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 10 | 11 | Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); 12 | 13 | n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); 14 | 15 | recvline[n] = 0; /* null terminate */ 16 | Fputs(recvline, stdout); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/dg_echo.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen) 5 | { 6 | int n; 7 | socklen_t len; 8 | char mesg[MAXLINE]; 9 | 10 | for ( ; ; ) { 11 | len = clilen; 12 | n = Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len); 13 | 14 | Sendto(sockfd, mesg, n, 0, pcliaddr, len); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/family_to_level.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | family_to_level(int family) 5 | { 6 | switch (family) { 7 | case AF_INET: 8 | return IPPROTO_IP; 9 | #ifdef IPV6 10 | case AF_INET6: 11 | return IPPROTO_IPV6; 12 | #endif 13 | default: 14 | return -1; 15 | } 16 | } 17 | 18 | int 19 | Family_to_level(int family) 20 | { 21 | int rc; 22 | 23 | if ( (rc = family_to_level(family)) < 0) 24 | err_sys("family_to_level error"); 25 | 26 | return(rc); 27 | } 28 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/gf_time.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | 4 | char * 5 | gf_time(void) 6 | { 7 | struct timeval tv; 8 | time_t t; 9 | static char str[30]; 10 | char *ptr; 11 | 12 | if (gettimeofday(&tv, NULL) < 0) 13 | err_sys("gettimeofday error"); 14 | 15 | t = tv.tv_sec; /* POSIX says tv.tv_sec is time_t; some BSDs don't agree. */ 16 | ptr = ctime(&t); 17 | strcpy(str, &ptr[11]); 18 | /* Fri Sep 13 00:00:00 1986\n\0 */ 19 | /* 0123456789012345678901234 5 */ 20 | snprintf(str+8, sizeof(str)-8, ".%06ld", tv.tv_usec); 21 | 22 | return(str); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/if_indextoname.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | /* 4 | * This is a placeholder if the system does not provide this RFC 2133 5 | * function. If routing sockets with sysctl() are provided, then the 6 | * if_XXX() functions in the libroute/ directory will replace these. 7 | */ 8 | 9 | char * 10 | if_indextoname(unsigned int index, char *name) 11 | { 12 | return(NULL); 13 | } 14 | 15 | char * 16 | If_indextoname(unsigned int index, char *name) 17 | { 18 | char *ptr; 19 | 20 | if ( (ptr = if_indextoname(index, name)) == NULL) 21 | err_quit("if_indextoname error for %d", index); 22 | return(ptr); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/if_nametoindex.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | /* 4 | * This is a placeholder if the system does not provide this RFC 2133 5 | * function. If routing sockets with sysctl() are provided, then the 6 | * if_XXX() functions in the libroute/ directory will replace these. 7 | */ 8 | 9 | unsigned int 10 | if_nametoindex(const char *name) 11 | { 12 | return(0); 13 | } 14 | 15 | unsigned int 16 | If_nametoindex(const char *name) 17 | { 18 | int index; 19 | 20 | if ( (index = if_nametoindex(name)) == 0) 21 | err_quit("if_nametoindex error for %s", name); 22 | return(index); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/in6addr_any.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | #ifdef IPV6 4 | const struct in6_addr in6addr_any; 5 | #endif 6 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/readable_timeo.c: -------------------------------------------------------------------------------- 1 | /* include readable_timeo */ 2 | #include "unp.h" 3 | 4 | int 5 | readable_timeo(int fd, int sec) 6 | { 7 | fd_set rset; 8 | struct timeval tv; 9 | 10 | FD_ZERO(&rset); 11 | FD_SET(fd, &rset); 12 | 13 | tv.tv_sec = sec; 14 | tv.tv_usec = 0; 15 | 16 | return(select(fd+1, &rset, NULL, NULL, &tv)); 17 | /* 4> 0 if descriptor is readable */ 18 | } 19 | /* end readable_timeo */ 20 | 21 | int 22 | Readable_timeo(int fd, int sec) 23 | { 24 | int n; 25 | 26 | if ( (n = readable_timeo(fd, sec)) < 0) 27 | err_sys("readable_timeo error"); 28 | return(n); 29 | } 30 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sock_get_port.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | sock_get_port(const struct sockaddr *sa, socklen_t salen) 5 | { 6 | switch (sa->sa_family) { 7 | case AF_INET: { 8 | struct sockaddr_in *sin = (struct sockaddr_in *) sa; 9 | 10 | return(sin->sin_port); 11 | } 12 | 13 | #ifdef IPV6 14 | case AF_INET6: { 15 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; 16 | 17 | return(sin6->sin6_port); 18 | } 19 | #endif 20 | } 21 | 22 | return(-1); /* ??? */ 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sock_set_addr.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sock_set_addr(struct sockaddr *sa, socklen_t salen, const void *addr) 5 | { 6 | switch (sa->sa_family) { 7 | case AF_INET: { 8 | struct sockaddr_in *sin = (struct sockaddr_in *) sa; 9 | 10 | memcpy(&sin->sin_addr, addr, sizeof(struct in_addr)); 11 | return; 12 | } 13 | 14 | #ifdef IPV6 15 | case AF_INET6: { 16 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; 17 | 18 | memcpy(&sin6->sin6_addr, addr, sizeof(struct in6_addr)); 19 | return; 20 | } 21 | #endif 22 | } 23 | 24 | return; 25 | } 26 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sock_set_port.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sock_set_port(struct sockaddr *sa, socklen_t salen, int port) 5 | { 6 | switch (sa->sa_family) { 7 | case AF_INET: { 8 | struct sockaddr_in *sin = (struct sockaddr_in *) sa; 9 | 10 | sin->sin_port = port; 11 | return; 12 | } 13 | 14 | #ifdef IPV6 15 | case AF_INET6: { 16 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; 17 | 18 | sin6->sin6_port = port; 19 | return; 20 | } 21 | #endif 22 | } 23 | 24 | return; 25 | } 26 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sock_set_wild.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sock_set_wild(struct sockaddr *sa, socklen_t salen) 5 | { 6 | const void *wildptr; 7 | 8 | switch (sa->sa_family) { 9 | case AF_INET: { 10 | static struct in_addr in4addr_any; 11 | 12 | in4addr_any.s_addr = htonl(INADDR_ANY); 13 | wildptr = &in4addr_any; 14 | break; 15 | } 16 | 17 | #ifdef IPV6 18 | case AF_INET6: { 19 | wildptr = &in6addr_any; 20 | break; 21 | } 22 | #endif 23 | 24 | default: 25 | return; 26 | } 27 | sock_set_addr(sa, salen, wildptr); 28 | return; 29 | } 30 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sockatmark.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | sockatmark(int fd) 5 | { 6 | int flag; 7 | 8 | if (ioctl(fd, SIOCATMARK, &flag) < 0) 9 | return(-1); 10 | return(flag != 0); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/sockfd_to_family.c: -------------------------------------------------------------------------------- 1 | /* include sockfd_to_family */ 2 | #include "unp.h" 3 | 4 | int 5 | sockfd_to_family(int sockfd) 6 | { 7 | struct sockaddr_storage ss; 8 | socklen_t len; 9 | 10 | len = sizeof(ss); 11 | if (getsockname(sockfd, (SA *) &ss, &len) < 0) 12 | return(-1); 13 | return(ss.ss_family); 14 | } 15 | /* end sockfd_to_family */ 16 | 17 | int 18 | Sockfd_to_family(int sockfd) 19 | { 20 | int rc; 21 | 22 | if ( (rc = sockfd_to_family(sockfd)) < 0) 23 | err_sys("sockfd_to_family error"); 24 | 25 | return(rc); 26 | } 27 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/str_cli.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_cli(FILE *fp, int sockfd) 5 | { 6 | char sendline[MAXLINE], recvline[MAXLINE]; 7 | 8 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 9 | 10 | Writen(sockfd, sendline, strlen(sendline)); 11 | 12 | if (Readline(sockfd, recvline, MAXLINE) == 0) 13 | err_quit("str_cli: server terminated prematurely"); 14 | 15 | Fputs(recvline, stdout); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/str_echo.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_echo(int sockfd) 5 | { 6 | ssize_t n; 7 | char buf[MAXLINE]; 8 | 9 | again: 10 | while ( (n = read(sockfd, buf, MAXLINE)) > 0) 11 | Writen(sockfd, buf, n); 12 | 13 | if (n < 0 && errno == EINTR) 14 | goto again; 15 | else if (n < 0) 16 | err_sys("str_echo: read error"); 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/tv_sub.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | tv_sub(struct timeval *out, struct timeval *in) 5 | { 6 | if ( (out->tv_usec -= in->tv_usec) < 0) { /* out -= in */ 7 | --out->tv_sec; 8 | out->tv_usec += 1000000; 9 | } 10 | out->tv_sec -= in->tv_sec; 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/lib/writable_timeo.c: -------------------------------------------------------------------------------- 1 | /* include writable_timeo */ 2 | #include "unp.h" 3 | 4 | int 5 | writable_timeo(int fd, int sec) 6 | { 7 | fd_set wset; 8 | struct timeval tv; 9 | 10 | FD_ZERO(&wset); 11 | FD_SET(fd, &wset); 12 | 13 | tv.tv_sec = sec; 14 | tv.tv_usec = 0; 15 | 16 | return(select(fd+1, NULL, &wset, NULL, &tv)); 17 | /* > 0 if descriptor is writable */ 18 | } 19 | /* end writable_timeo */ 20 | 21 | int 22 | Writable_timeo(int fd, int sec) 23 | { 24 | int n; 25 | 26 | if ( (n = writable_timeo(fd, sec)) < 0) 27 | err_sys("writable_timeo error"); 28 | return(n); 29 | } 30 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libfree/Make.tar: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | tar -cvf addrinfo.tar README.getaddrinfo addrinfo.h getaddrinfo.c \ 4 | getnameinfo.c test_addrinfo.c inet_ntop.c inet_pton.c 5 | 6 | compress addrinfo.tar 7 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libfree/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | all: ${LIBFREE_OBJS} 4 | ar rv ${LIBUNP_NAME} $? 5 | ${RANLIB} ${LIBUNP_NAME} 6 | 7 | test_inet_pton: test_inet_pton.o 8 | ${CC} ${CFLAGS} -o $@ test_inet_pton.o ${LIBS} 9 | 10 | clean: 11 | rm -f ${PROGS} ${CLEANFILES} 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libfree/README: -------------------------------------------------------------------------------- 1 | This directory contains the library files that do *not* #include unp.h. 2 | The intent is that these functions can stand alone, without the rest 3 | of the code from the book. 4 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libfree/test_ascii2addr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | main() 8 | { 9 | struct in6_addr foo; 10 | 11 | printf("ascii2addr returned %d\n", 12 | ascii2addr(AF_INET6, "::140.252.13.36", &foo)); 13 | 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libgai/freeaddrinfo.c: -------------------------------------------------------------------------------- 1 | #include "gai_hdr.h" 2 | 3 | /* include freeaddrinfo */ 4 | void 5 | freeaddrinfo(struct addrinfo *aihead) 6 | { 7 | struct addrinfo *ai, *ainext; 8 | 9 | for (ai = aihead; ai != NULL; ai = ainext) { 10 | if (ai->ai_addr != NULL) 11 | free(ai->ai_addr); /* socket address structure */ 12 | 13 | if (ai->ai_canonname != NULL) 14 | free(ai->ai_canonname); 15 | 16 | ainext = ai->ai_next; /* can't fetch ai_next after free() */ 17 | free(ai); /* the addrinfo{} itself */ 18 | } 19 | } 20 | /* end freeaddrinfo */ 21 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/libroute/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | all: ${LIBROUTE_OBJS} 4 | ar rv ${LIBUNP_NAME} $? 5 | ${RANLIB} ${LIBUNP_NAME} 6 | 7 | clean: 8 | rm -f ${PROGS} ${CLEANFILES} 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mcast/recv.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | recv_all(int recvfd, socklen_t salen) 5 | { 6 | int n; 7 | char line[MAXLINE+1]; 8 | socklen_t len; 9 | struct sockaddr *safrom; 10 | 11 | safrom = Malloc(salen); 12 | 13 | for ( ; ; ) { 14 | len = salen; 15 | n = Recvfrom(recvfd, line, MAXLINE, 0, safrom, &len); 16 | 17 | line[n] = 0; /* null terminate */ 18 | printf("from %s: %s", Sock_ntop(safrom, len), line); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mcast/send.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | 4 | #define SENDRATE 5 /* send one datagram every five seconds */ 5 | 6 | void 7 | send_all(int sendfd, SA *sadest, socklen_t salen) 8 | { 9 | char line[MAXLINE]; /* hostname and process ID */ 10 | struct utsname myname; 11 | 12 | if (uname(&myname) < 0) 13 | err_sys("uname error");; 14 | snprintf(line, sizeof(line), "%s, %d\n", myname.nodename, getpid()); 15 | 16 | for ( ; ; ) { 17 | Sendto(sendfd, line, strlen(line), 0, sadest, salen); 18 | 19 | sleep(SENDRATE); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mcast/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli01 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(SERV_PORT); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mcast/udpcli05.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli05 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(13); /* standard daytime server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mcast/udpcli06.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | socklen_t salen; 8 | struct sockaddr *cli, *serv; 9 | 10 | if (argc != 2) 11 | err_quit("usage: udpcli06 "); 12 | 13 | sockfd = Udp_client(argv[1], "daytime", (void **) &serv, &salen); 14 | 15 | cli = Malloc(salen); 16 | memcpy(cli, serv, salen); /* copy socket address struct */ 17 | sock_set_port(cli, salen, 0); /* and set port to 0 */ 18 | Bind(sockfd, cli, salen); 19 | 20 | dg_cli(stdin, sockfd, serv, salen); 21 | 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mysdr/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = mysdr 4 | 5 | all: ${PROGS} 6 | 7 | mysdr: main.o loop.o 8 | ${CC} ${CFLAGS} -o $@ main.o loop.o ${LIBS} 9 | 10 | clean: 11 | rm -f ${PROGS} ${CLEANFILES} 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/mysdr/mysdr.h: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | #define SAP_VERSION 1 4 | #define SAP_VERSION_MASK 0xe0000000 5 | #define SAP_VERSION_SHIFT 29 6 | #define SAP_IPV6 0x10000000 7 | #define SAP_DELETE 0x04000000 8 | #define SAP_ENCRYPTED 0x02000000 9 | #define SAP_COMPRESSED 0x01000000 10 | #define SAP_AUTHLEN_MASK 0x00ff0000 11 | #define SAP_AUTHLEN_SHIFT 16 12 | #define SAP_HASH_MASK 0x0000ffff 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/names/daytimeudpcli2.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd, n; 7 | char recvline[MAXLINE + 1]; 8 | 9 | if (argc != 3) 10 | err_quit("usage: daytimeudpcli2 "); 11 | 12 | sockfd = Udp_connect(argv[1], argv[2]); 13 | 14 | Write(sockfd, "", 1); /* send 1-byte datagram */ 15 | 16 | n = Read(sockfd, recvline, MAXLINE); 17 | recvline[n] = '\0'; /* null terminate */ 18 | Fputs(recvline, stdout); 19 | 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/names/myaddrs1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | 4 | char ** 5 | my_addrs(int *addrtype) 6 | { 7 | struct hostent *hptr; 8 | char myname[MAXHOSTNAMELEN]; 9 | 10 | if (gethostname(myname, sizeof(myname)) < 0) 11 | return(NULL); 12 | 13 | if ( (hptr = gethostbyname(myname)) == NULL) 14 | return(NULL); 15 | 16 | *addrtype = hptr->h_addrtype; 17 | return(hptr->h_addr_list); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/names/prmyaddrs.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | char **my_addrs(int *); 4 | 5 | int 6 | main(int argc, char **argv) 7 | { 8 | int addrtype; 9 | char **pptr, buf[INET6_ADDRSTRLEN]; 10 | 11 | if ( (pptr = my_addrs(&addrtype)) == NULL) 12 | err_quit("my_addrs error"); 13 | 14 | for ( ; *pptr != NULL; pptr++) 15 | printf("\taddress: %s\n", 16 | Inet_ntop(addrtype, *pptr, buf, sizeof(buf))); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/names/prmyaddrs1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | char **my_addrs(int *); 4 | 5 | int 6 | main(int argc, char **argv) 7 | { 8 | int addrtype; 9 | char **pptr, buf[INET6_ADDRSTRLEN]; 10 | 11 | if ( (pptr = my_addrs(&addrtype)) == NULL) 12 | err_quit("my_addrs error"); 13 | 14 | for ( ; *pptr != NULL; pptr++) 15 | printf("\taddress: %s\n", 16 | Inet_ntop(addrtype, *pptr, buf, sizeof(buf))); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/nonblock/doit.1: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case $# in 4 | 1) break ;; 5 | *) echo "one argument (#simultaneous connections) required" 1>&2 6 | exit 1 ;; 7 | esac 8 | 9 | time ./web $1 192.207.117.2 / \ 10 | /img/logo/awl_logo_blue_50x40.gif \ 11 | /img/a_world_of_learning.gif \ 12 | /img/toolbar_soptions.gif \ 13 | /img/toolbar_purchase.gif \ 14 | /img/toolbar_feedback.gif \ 15 | /img/toolbar_top_hilite.gif \ 16 | /img/toolbar_qsearch.gif \ 17 | /img/blue_dot.gif \ 18 | /img/logo/pearson_logo_50.gif 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/nonblock/home_page.c: -------------------------------------------------------------------------------- 1 | #include "web.h" 2 | 3 | void 4 | home_page(const char *host, const char *fname) 5 | { 6 | int fd, n; 7 | char line[MAXLINE]; 8 | 9 | fd = Tcp_connect(host, SERV); /* blocking connect() */ 10 | 11 | n = snprintf(line, sizeof(line), GET_CMD, fname); 12 | Writen(fd, line, n); 13 | 14 | for ( ; ; ) { 15 | if ( (n = Read(fd, line, MAXLINE)) == 0) 16 | break; /* server closed connection */ 17 | 18 | printf("read %d bytes of home page\n", n); 19 | /* do whatever with data */ 20 | } 21 | printf("end-of-file on home page\n"); 22 | Close(fd); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/nonblock/tcpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(7); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/nonblock/tcpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(7); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/nonblock/write_get_cmd.c: -------------------------------------------------------------------------------- 1 | #include "web.h" 2 | 3 | void 4 | write_get_cmd(struct file *fptr) 5 | { 6 | int n; 7 | char line[MAXLINE]; 8 | 9 | n = snprintf(line, sizeof(line), GET_CMD, fptr->f_name); 10 | Writen(fptr->f_fd, line, n); 11 | printf("wrote %d bytes for %s\n", n, fptr->f_name); 12 | 13 | fptr->f_flags = F_READING; /* clears F_CONNECTING */ 14 | 15 | FD_SET(fptr->f_fd, &rset); /* will read server's reply */ 16 | if (fptr->f_fd > maxfd) 17 | maxfd = fptr->f_fd; 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/oob/sigchldwaitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { 10 | printf("child %d terminated\n", pid); 11 | } 12 | return; 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/oob/strecho02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_echo(int sockfd) 5 | { 6 | ssize_t n; 7 | char line[MAXLINE]; 8 | 9 | heartbeat_serv(sockfd, 1, 5); 10 | 11 | for ( ; ; ) { 12 | if ( (n = Readline(sockfd, line, MAXLINE)) == 0) 13 | return; /* connection closed by other end */ 14 | 15 | Writen(sockfd, line, n); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/oob/tcpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/oob/tcpsend04.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | 8 | if (argc != 3) 9 | err_quit("usage: tcpsend04 "); 10 | 11 | sockfd = Tcp_connect(argv[1], argv[2]); 12 | 13 | Write(sockfd, "123", 3); 14 | printf("wrote 3 bytes of normal data\n"); 15 | 16 | Send(sockfd, "4", 1, MSG_OOB); 17 | printf("wrote 1 byte of OOB data\n"); 18 | 19 | Write(sockfd, "5", 1); 20 | printf("wrote 1 byte of normal data\n"); 21 | 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ping/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | OBJS = init_v6.o main.o proc_v4.o proc_v6.o readloop.o \ 4 | send_v4.o send_v6.o sig_alrm.o tv_sub.o 5 | PROGS = ping 6 | 7 | all: ${PROGS} 8 | 9 | ping: ${OBJS} 10 | ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} 11 | 12 | clean: 13 | rm -f ${PROGS} ${CLEANFILES} 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ping/sig_alrm.c: -------------------------------------------------------------------------------- 1 | #include "ping.h" 2 | 3 | void 4 | sig_alrm(int signo) 5 | { 6 | (*pr->fsend)(); 7 | 8 | alarm(1); 9 | return; 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ping/sig_alrm.lc: -------------------------------------------------------------------------------- 1 | #include "ping.h"## 1 ##src/ping/sig_alrm.c## 2 | 3 | void## 2 ##src/ping/sig_alrm.c## 4 | sig_alrm(int signo)## 3 ##src/ping/sig_alrm.c## 5 | {## 4 ##src/ping/sig_alrm.c## 6 | (*pr->fsend) ();## 5 ##src/ping/sig_alrm.c## 7 | 8 | alarm(1);## 6 ##src/ping/sig_alrm.c## 9 | return; /* probably interrupts recvfrom() */## 7 ##src/ping/sig_alrm.c## 10 | }## 8 ##src/ping/sig_alrm.c## 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ping/tv_sub.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | tv_sub(struct timeval *out, struct timeval *in) 5 | { 6 | if ( (out->tv_usec -= in->tv_usec) < 0) { /* out -= in */ 7 | --out->tv_sec; 8 | out->tv_usec += 1000000; 9 | } 10 | out->tv_sec -= in->tv_sec; 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/route/checkudpsum.c: -------------------------------------------------------------------------------- 1 | #include "unproute.h" 2 | #include 3 | #include 4 | #include /* for UDPCTL_xxx constants */ 5 | 6 | int 7 | main(int argc, char **argv) 8 | { 9 | int mib[4], val; 10 | size_t len; 11 | 12 | mib[0] = CTL_NET; 13 | mib[1] = AF_INET; 14 | mib[2] = IPPROTO_UDP; 15 | mib[3] = UDPCTL_CHECKSUM; 16 | 17 | len = sizeof(val); 18 | Sysctl(mib, 4, &val, &len, NULL, 0); 19 | printf("udp checksum flag: %d\n", val); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/route/prifindex.c: -------------------------------------------------------------------------------- 1 | #include "unpifi.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | if (argc != 2) 7 | err_quit("usage: prifname "); 8 | 9 | printf("interface index = %d\n", If_nametoindex(argv[1])); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/route/prifname.c: -------------------------------------------------------------------------------- 1 | #include "unpifi.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | char name[16]; 7 | 8 | if (argc != 2) 9 | err_quit("usage: prifname "); 10 | 11 | printf("interface name = %s\n", If_indextoname(atoi(argv[1]), name)); 12 | exit(0); 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/rtt/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = udpcli01 4 | 5 | all: ${PROGS} 6 | 7 | udpcli01: udpcli01.o dg_cli.o dg_send_recv.o 8 | ${CC} ${CFLAGS} -o $@ udpcli01.o dg_cli.o dg_send_recv.o ${LIBS} 9 | 10 | clean: 11 | rm -f ${PROGS} ${CLEANFILES} 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/rtt/dg_cli.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | ssize_t Dg_send_recv(int, const void *, size_t, void *, size_t, 4 | const SA *, socklen_t); 5 | 6 | void 7 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 8 | { 9 | ssize_t n; 10 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 11 | 12 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 13 | 14 | n = Dg_send_recv(sockfd, sendline, strlen(sendline), 15 | recvline, MAXLINE, pservaddr, servlen); 16 | 17 | recvline[n] = 0; /* null terminate */ 18 | Fputs(recvline, stdout); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/rtt/dg_echo.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen) 5 | { 6 | int n; 7 | socklen_t len; 8 | char mesg[MAXLINE]; 9 | 10 | for ( ; ; ) { 11 | len = clilen; 12 | n = Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len); 13 | 14 | Sendto(sockfd, mesg, n, 0, pcliaddr, clilen); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/rtt/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(7); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sctp/sctp_addr_to_associd.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | sctp_assoc_t 4 | sctp_address_to_associd(int sock_fd, struct sockaddr *sa, socklen_t salen) 5 | { 6 | struct sctp_paddrparams sp; 7 | int siz; 8 | 9 | siz = sizeof(struct sctp_paddrparams); 10 | bzero(&sp,siz); 11 | memcpy(&sp.spp_address,sa,salen); 12 | sctp_opt_info(sock_fd,0, 13 | SCTP_PEER_ADDR_PARAMS, &sp, &siz); 14 | return(sp.spp_assoc_id); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sctp/sctp_getnostrm.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | sctp_get_no_strms(int sock_fd,struct sockaddr *to, socklen_t tolen) 5 | { 6 | int retsz; 7 | struct sctp_status status; 8 | retsz = sizeof(status); 9 | bzero(&status,sizeof(status)); 10 | 11 | status.sstat_assoc_id = sctp_address_to_associd(sock_fd,to,tolen); 12 | Getsockopt(sock_fd,IPPROTO_SCTP, SCTP_STATUS, 13 | &status, &retsz); 14 | return(status.sstat_outstrms); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sctp/sctp_modify_hb.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int heartbeat_action(int sock_fd, struct sockaddr *sa, socklen_t salen, 4 | u_int value) 5 | { 6 | struct sctp_paddrparams sp; 7 | int siz; 8 | 9 | bzero(&sp,sizeof(sp)); 10 | sp.spp_hbinterval = value; 11 | memcpy((caddr_t)&sp.spp_address,sa,salen); 12 | Setsockopt(sock_fd,IPPROTO_SCTP, 13 | SCTP_PEER_ADDR_PARAMS, &sp, sizeof(sp)); 14 | return(0); 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/select/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = tcpcli01 tcpcli02 tcpcli03 4 | 5 | all: ${PROGS} 6 | 7 | tcpcli01: tcpcli01.o strcliselect01.o 8 | ${CC} ${CFLAGS} -o $@ tcpcli01.o strcliselect01.o ${LIBS} 9 | 10 | tcpcli02: tcpcli02.o strcliselect02.o 11 | ${CC} ${CFLAGS} -o $@ tcpcli02.o strcliselect02.o ${LIBS} 12 | 13 | tcpcli03: tcpcli03.o 14 | ${CC} ${CFLAGS} -o $@ tcpcli03.o ${LIBS} 15 | 16 | clean: 17 | rm -f ${PROGS} ${CLEANFILES} 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/child.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | pid_t child_pid; /* process ID */ 3 | int child_pipefd; /* parent's stream pipe to/from child */ 4 | int child_status; /* 0 = ready */ 5 | long child_count; /* # connections handled */ 6 | } Child; 7 | 8 | Child *cptr; /* array of Child structures; calloc'ed */ 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/child.lh: -------------------------------------------------------------------------------- 1 | typedef struct {## 1 ##src/server/child.h## 2 | pid_t child_pid; /* process ID */## 2 ##src/server/child.h## 3 | int child_pipefd; /* parent's stream pipe to/from child */## 3 ##src/server/child.h## 4 | int child_status; /* 0 = ready */## 4 ##src/server/child.h## 5 | long child_count; /* #connections handled */## 5 ##src/server/child.h## 6 | } Child;## 6 ##src/server/child.h## 7 | 8 | Child *cptr; /* array of Child structures; calloc'ed */## 7 ##src/server/child.h## 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/pthread07.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | pthread_t thread_tid; /* thread ID */ 3 | long thread_count; /* # connections handled */ 4 | } Thread; 5 | Thread *tptr; /* array of Thread structures; calloc'ed */ 6 | 7 | int listenfd, nthreads; 8 | socklen_t addrlen; 9 | pthread_mutex_t mlock; 10 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/pthread08.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | pthread_t thread_tid; /* thread ID */ 3 | long thread_count; /* # connections handled */ 4 | } Thread; 5 | Thread *tptr; /* array of Thread structures; calloc'ed */ 6 | 7 | #define MAXNCLI 32 8 | int clifd[MAXNCLI], iget, iput; 9 | pthread_mutex_t clifd_mutex; 10 | pthread_cond_t clifd_cond; 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/pthread09.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | pthread_t thread_tid; /* thread ID */ 3 | long thread_count; /* #connections handled */ 4 | } Thread; 5 | Thread *tptr; /* array of Thread structures; calloc'ed */ 6 | 7 | int listenfd, nthreads; 8 | socklen_t addrlen; 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/readline_r.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int read_fd; /* caller's descriptor to read from */ 3 | char *read_ptr; /* caller's buffer to read into */ 4 | size_t read_maxlen; /* max #bytes to read */ 5 | /* next three are used internally by the function */ 6 | int rl_cnt; /* initialize to 0 */ 7 | char *rl_bufptr; /* initialize to rl_buf */ 8 | char rl_buf[MAXLINE]; 9 | } Rline; 10 | 11 | void readline_rinit(int, void *, size_t, Rline *); 12 | ssize_t readline_r(Rline *); 13 | ssize_t Readline_r(Rline *); 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/server/sig_chld_waitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { 10 | /* printf("child %d terminated\n", pid); */ 11 | } 12 | return; 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = udpcli01 udpserv01 4 | 5 | all: ${PROGS} 6 | 7 | udpcli01: udpcli01.o dgcli01.o 8 | ${CC} ${CFLAGS} -o $@ udpcli01.o dgcli01.o ${LIBS} 9 | 10 | udpserv01: udpserv01.o dgecho01.o 11 | ${CC} ${CFLAGS} -o $@ udpserv01.o dgecho01.o ${LIBS} 12 | 13 | clean: 14 | rm -f ${PROGS} ${CLEANFILES} 15 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/dgcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 5 | { 6 | int n; 7 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 8 | 9 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 10 | 11 | Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); 12 | 13 | n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); 14 | 15 | recvline[n] = 0; /* null terminate */ 16 | Fputs(recvline, stdout); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/script.1: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.1 & 4 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.2 & 5 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.3 & 6 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.4 & 7 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.5 & 8 | ./udpcli01 140.252.13.35 < /usr/share/misc/termcap > /home/rstevens/temp.6 & 9 | 10 | wait 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/script.2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.1 & 4 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.2 & 5 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.3 & 6 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.4 & 7 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.5 & 8 | ./udpcli01 140.252.13.37 < /usr/share/lib/termcap > /home/rstevens/temp.6 & 9 | 10 | wait 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli01 "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(SERV_PORT); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sigio/udpserv01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin_family = AF_INET; 13 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 14 | servaddr.sin_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sock/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = sock 4 | OBJS = buffers.o cliopen.o crlf.o error.o looptcp.o loopudp.o \ 5 | main.o multicast.o pattern.o servopen.o sleepus.o sockopts.o \ 6 | sourceroute.o sourcetcp.o sourceudp.o sinktcp.o sinkudp.o \ 7 | tellwait.o write.o 8 | 9 | all: ${PROGS} 10 | 11 | ${OBJS}: sock.h 12 | 13 | sock: ${OBJS} 14 | ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} 15 | 16 | clean: 17 | rm -f ${PROGS} core core.* *.o temp.* *.out typescript* 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sock/TODO: -------------------------------------------------------------------------------- 1 | - With -v print IP address after gethostbyname returns. 2 | 3 | - First, option to write() in small chunks. Then option to use writev() 4 | instead of write(). See what happens, with and without TCO_NODELAY. 5 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sock/sock.in: -------------------------------------------------------------------------------- 1 | 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 2 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sock/strerror.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern const char *const sys_errlist[]; 4 | extern int sys_nerr; 5 | 6 | char * 7 | strerror(int error) 8 | { 9 | static char mesg[30]; 10 | 11 | if (error >= 0 && error <= sys_nerr) 12 | return(sys_errlist[error]); 13 | 14 | snprintf(mesg, sizeof(mesg), "Unknown error (%d)", error); 15 | return(mesg); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sock/writen.c: -------------------------------------------------------------------------------- 1 | #include "ourhdr.h" 2 | 3 | ssize_t /* Write "n" bytes to a descriptor. */ 4 | writen(int fd, const void *vptr, size_t n) 5 | { 6 | size_t nleft, nwritten; 7 | const char *ptr; 8 | 9 | ptr = vptr; /* can't do pointer arithmetic on void* */ 10 | nleft = n; 11 | while (nleft > 0) { 12 | if ( (nwritten = write(fd, ptr, nleft)) <= 0) 13 | return(nwritten); /* error */ 14 | 15 | nleft -= nwritten; 16 | ptr += nwritten; 17 | } 18 | return(n); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/sockopt/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = checkopts prdefaults rcvbuf rcvbufset sockopt 4 | 5 | all: ${PROGS} 6 | 7 | sockopt: sockopt.o 8 | ${CC} ${CFLAGS} -o $@ sockopt.o ${LIBS} 9 | 10 | checkopts: checkopts.o 11 | ${CC} ${CFLAGS} -o $@ checkopts.o ${LIBS} 12 | 13 | prdefaults: prdefaults.o 14 | ${CC} ${CFLAGS} -o $@ prdefaults.o ${LIBS} 15 | 16 | rcvbuf: rcvbuf.o 17 | ${CC} ${CFLAGS} -o $@ rcvbuf.o ${LIBS} 18 | 19 | rcvbufset: rcvbufset.o 20 | ${CC} ${CFLAGS} -o $@ rcvbufset.o ${LIBS} 21 | 22 | clean: 23 | rm -f ${PROGS} ${CLEANFILES} 24 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ssntp/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = ssntp 4 | 5 | all: ${PROGS} 6 | 7 | ssntp: main.o sntp_proc.o 8 | ${CC} ${CFLAGS} -o $@ main.o sntp_proc.o ${LIBS} 9 | 10 | clean: 11 | rm -f ${PROGS} ${CLEANFILES} 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/ssntp/sntp.h: -------------------------------------------------------------------------------- 1 | #include "unpifi.h" 2 | #include "ntp.h" 3 | 4 | void sntp_proc(char *, ssize_t, struct timeval *); 5 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/streams/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | PROGS = strlist_sock strlist_xti tpi_daytime 4 | 5 | all: ${PROGS} 6 | 7 | strlist_sock: strlist_sock.o 8 | ${CC} ${CFLAGS} -o $@ strlist_sock.o ${LIBS_XTI} 9 | 10 | strlist_xti: strlist_xti.o 11 | ${CC} ${CFLAGS} -o $@ strlist_xti.o ${LIBS_XTI} 12 | 13 | tpi_daytime: tpi_daytime.o tpi_bind.o tpi_connect.o tpi_read.o tpi_close.o 14 | ${CC} ${CFLAGS} -o $@ tpi_daytime.o tpi_bind.o tpi_connect.o \ 15 | tpi_read.o tpi_close.o ${LIBS_XTI} 16 | 17 | clean: 18 | rm -f ${PROGS} ${CLEANFILES} 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/streams/stream_dg/Makefile: -------------------------------------------------------------------------------- 1 | all: client server 2 | 3 | client: client.o net_stream.o 4 | cc client.o net_stream.o -o client -lnsl 5 | 6 | server: server.o net_stream.o 7 | cc server.o net_stream.o -o server -lnsl 8 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/streams/tpi_close.c: -------------------------------------------------------------------------------- 1 | #include "tpi_daytime.h" 2 | 3 | void 4 | tpi_close(int fd) 5 | { 6 | struct T_ordrel_req ordrel_req; 7 | struct strbuf ctlbuf; 8 | 9 | ordrel_req.PRIM_type = T_ORDREL_REQ; 10 | 11 | ctlbuf.len = sizeof(struct T_ordrel_req); 12 | ctlbuf.buf = (char *) &ordrel_req; 13 | Putmsg(fd, &ctlbuf, NULL, 0); 14 | 15 | Close(fd); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/streams/tpi_daytime.h: -------------------------------------------------------------------------------- 1 | #include "unpxti.h" 2 | #include 3 | #include 4 | 5 | void tpi_bind(int, const void *, size_t); 6 | void tpi_connect(int, const void *, size_t); 7 | ssize_t tpi_read(int, void *, size_t); 8 | void tpi_close(int); 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/sigchldwait.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | pid = wait(&stat); 10 | printf("child %d terminated\n", pid); 11 | return; 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/sigchldwaitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) 10 | printf("child %d terminated\n", pid); 11 | return; 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/str_cli08.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_cli(FILE *fp, int sockfd) 5 | { 6 | char sendline[MAXLINE], recvline[MAXLINE]; 7 | 8 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 9 | 10 | Writen(sockfd, sendline, strlen(sendline)); 11 | 12 | if (Readline(sockfd, recvline, MAXLINE) == 0) 13 | err_quit("str_cli: server terminated prematurely"); 14 | 15 | Fputs(recvline, stdout); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/str_cli11.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_cli(FILE *fp, int sockfd) 5 | { 6 | char sendline[MAXLINE], recvline[MAXLINE]; 7 | 8 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 9 | 10 | Writen(sockfd, sendline, 1); 11 | sleep(1); 12 | Writen(sockfd, sendline+1, strlen(sendline)-1); 13 | 14 | if (Readline(sockfd, recvline, MAXLINE) == 0) 15 | err_quit("str_cli: server terminated prematurely"); 16 | 17 | Fputs(recvline, stdout); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/str_echo08.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | str_echo(int sockfd) 5 | { 6 | long arg1, arg2; 7 | ssize_t n; 8 | char line[MAXLINE]; 9 | 10 | for ( ; ; ) { 11 | if ( (n = Readline(sockfd, line, MAXLINE)) == 0) 12 | return; /* connection closed by other end */ 13 | 14 | if (sscanf(line, "%ld%ld", &arg1, &arg2) == 2) 15 | snprintf(line, sizeof(line), "%ld\n", arg1 + arg2); 16 | else 17 | snprintf(line, sizeof(line), "input error\n"); 18 | 19 | n = strlen(line); 20 | Writen(sockfd, line, n); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/str_echo09.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include "sum.h" 3 | 4 | void 5 | str_echo(int sockfd) 6 | { 7 | ssize_t n; 8 | struct args args; 9 | struct result result; 10 | 11 | for ( ; ; ) { 12 | if ( (n = Readn(sockfd, &args, sizeof(args))) == 0) 13 | return; /* connection closed by other end */ 14 | 15 | result.sum = args.arg1 + args.arg2; 16 | Writen(sockfd, &result, sizeof(result)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/sum.h: -------------------------------------------------------------------------------- 1 | struct args { 2 | long arg1; 3 | long arg2; 4 | }; 5 | 6 | struct result { 7 | long sum; 8 | }; 9 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/tcpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/tcpcli08.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/tcpcliserv/tcpcli09.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: tcpcli "); 11 | 12 | sockfd = Socket(AF_INET, SOCK_STREAM, 0); 13 | 14 | bzero(&servaddr, sizeof(servaddr)); 15 | servaddr.sin_family = AF_INET; 16 | servaddr.sin_port = htons(SERV_PORT); 17 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 18 | 19 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | str_cli(stdin, sockfd); /* do it all */ 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/readline.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int read_fd; /* caller's descriptor to read from */ 3 | char *read_ptr; /* caller's buffer to read into */ 4 | size_t read_maxlen; /* max #bytes to read */ 5 | /* next three are used internally by the function */ 6 | int rl_cnt; /* initialize to 0 */ 7 | char *rl_bufptr; /* initialize to rl_buf */ 8 | char rl_buf[MAXLINE]; 9 | } Rline; 10 | 11 | void readline_rinit(int, void *, size_t, Rline *); 12 | ssize_t readline_r(Rline *); 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/test.h: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | /* globals */ 4 | extern struct sockaddr_in servaddr, cliaddr; 5 | extern char buff[8192]; 6 | extern int verbose; 7 | 8 | int TcpSockByAddr(char *, int); 9 | int UdpSockByAddr(char *, int); 10 | int UdpConnSockByAddr(char *, int); 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/tisfdtype.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | main() 4 | { 5 | int tcpsock, udpsock; 6 | 7 | printf("stdin: %d\n", Isfdtype(STDIN_FILENO, S_IFSOCK)); 8 | printf("stdout: %d\n", Isfdtype(STDOUT_FILENO, S_IFSOCK)); 9 | printf("stderr: %d\n", Isfdtype(STDERR_FILENO, S_IFSOCK)); 10 | 11 | tcpsock = Socket(AF_INET, SOCK_STREAM, 0); 12 | printf("TCP socket: %d\n", Isfdtype(tcpsock, S_IFSOCK)); 13 | 14 | udpsock = Socket(AF_INET, SOCK_DGRAM, 0); 15 | printf("UDP socket: %d\n", Isfdtype(udpsock, S_IFSOCK)); 16 | 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/treadline1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int count = 0; 7 | ssize_t n; 8 | char recvline[MAXLINE]; 9 | 10 | while ( ( n = readline(STDIN_FILENO, recvline, MAXLINE)) > 0) 11 | count++; 12 | printf("%d lines\n", count); 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/treadline2.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int count = 0; 7 | ssize_t n; 8 | char recvline[MAXLINE]; 9 | 10 | while ( ( n = readline(STDIN_FILENO, recvline, MAXLINE)) > 0) 11 | count++; 12 | printf("%d lines\n", count); 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/test/treadline3.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include "readline.h" 3 | 4 | int 5 | main(int argc, char **argv) 6 | { 7 | int count = 0; 8 | ssize_t n; 9 | char recvline[MAXLINE]; 10 | Rline rline; 11 | 12 | readline_rinit(STDIN_FILENO, recvline, MAXLINE, &rline); 13 | while ( (n = readline_r(&rline)) > 0) 14 | count++; 15 | printf("%d lines\n", count); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/threads/doit.1: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case $# in 4 | 1) break ;; 5 | *) echo "one argument (#simultaneous connections) required" 1>&2 6 | exit 1 ;; 7 | esac 8 | 9 | time ./web03 $1 192.207.117.2 / \ 10 | /img/logo/awl_logo_blue_50x40.gif \ 11 | /img/a_world_of_learning.gif \ 12 | /img/toolbar_soptions.gif \ 13 | /img/toolbar_purchase.gif \ 14 | /img/toolbar_feedback.gif \ 15 | /img/toolbar_top_hilite.gif \ 16 | /img/toolbar_qsearch.gif \ 17 | /img/blue_dot.gif \ 18 | /img/logo/pearson_logo_50.gif 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/threads/tcpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | 8 | if (argc != 3) 9 | err_quit("usage: tcpcli "); 10 | 11 | sockfd = Tcp_connect(argv[1], argv[2]); 12 | 13 | str_cli(stdin, sockfd); /* do it all */ 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/threads/tcpcli02.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | 8 | if (argc != 3) 9 | err_quit("usage: tcpcli "); 10 | 11 | sockfd = Tcp_connect(argv[1], argv[2]); 12 | 13 | str_cli(stdin, sockfd); /* do it all */ 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/traceroute/Makefile: -------------------------------------------------------------------------------- 1 | include ../Make.defines 2 | 3 | OBJS = main.o icmpcode_v4.o icmpcode_v6.o recv_v4.o recv_v6.o \ 4 | sig_alrm.o traceloop.o tv_sub.o 5 | PROGS = traceroute 6 | 7 | all: ${PROGS} 8 | 9 | traceroute: ${OBJS} 10 | ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} 11 | 12 | clean: 13 | rm -f ${PROGS} ${CLEANFILES} 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/traceroute/sig_alrm.c: -------------------------------------------------------------------------------- 1 | #include "trace.h" 2 | 3 | int gotalarm; 4 | 5 | void 6 | sig_alrm(int signo) 7 | { 8 | gotalarm = 1; /* set flag to note that alarm occurred */ 9 | return; /* and interrupt the recvfrom() */ 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/traceroute/tv_sub.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | tv_sub(struct timeval *out, struct timeval *in) 5 | { 6 | if ( (out->tv_usec -= in->tv_usec) < 0) { /* out -= in */ 7 | --out->tv_sec; 8 | out->tv_usec += 1000000; 9 | } 10 | out->tv_sec -= in->tv_sec; 11 | } 12 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcksum/cleanup.c: -------------------------------------------------------------------------------- 1 | #include "udpcksum.h" 2 | 3 | /* include cleanup */ 4 | void 5 | cleanup(int signo) 6 | { 7 | struct pcap_stat stat; 8 | 9 | putc('\n', stdout); 10 | 11 | if (verbose) { 12 | if (pcap_stats(pd, &stat) < 0) 13 | err_quit("pcap_stats: %s\n", pcap_geterr(pd)); 14 | printf("%d packets received by filter\n", stat.ps_recv); 15 | printf("%d packets dropped by kernel\n", stat.ps_drop); 16 | } 17 | 18 | exit(0); 19 | } 20 | /* end cleanup */ 21 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/dgcliconnect.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 5 | { 6 | int n; 7 | char sendline[MAXLINE], recvline[MAXLINE + 1]; 8 | 9 | Connect(sockfd, (SA *) pservaddr, servlen); 10 | 11 | while (Fgets(sendline, MAXLINE, fp) != NULL) { 12 | 13 | Write(sockfd, sendline, strlen(sendline)); 14 | 15 | n = Read(sockfd, recvline, MAXLINE); 16 | 17 | recvline[n] = 0; /* null terminate */ 18 | Fputs(recvline, stdout); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/dgcliloop1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | #define NDG 2000 /* datagrams to send */ 4 | #define DGLEN 1400 /* length of each datagram */ 5 | 6 | void 7 | dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) 8 | { 9 | int i; 10 | char sendline[DGLEN]; 11 | 12 | for (i = 0; i < NDG; i++) { 13 | Sendto(sockfd, sendline, DGLEN, 0, pservaddr, servlen); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/dgecholoop1.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | static void recvfrom_int(int); 4 | static int count; 5 | 6 | void 7 | dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen) 8 | { 9 | socklen_t len; 10 | char mesg[MAXLINE]; 11 | 12 | Signal(SIGINT, recvfrom_int); 13 | 14 | for ( ; ; ) { 15 | len = clilen; 16 | Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len); 17 | 18 | count++; 19 | } 20 | } 21 | 22 | static void 23 | recvfrom_int(int signo) 24 | { 25 | printf("\nreceived %d datagrams\n", count); 26 | exit(0); 27 | } 28 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/sigchldwaitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) 10 | printf("child %d terminated\n", pid); 11 | return; 12 | } 13 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(SERV_PORT); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli03.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(7); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli04.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(SERV_PORT); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli06.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(SERV_PORT); 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli08.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr; 8 | 9 | if (argc != 2) 10 | err_quit("usage: udpcli "); 11 | 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sin_family = AF_INET; 14 | servaddr.sin_port = htons(9); /* discard server */ 15 | Inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 16 | 17 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 18 | 19 | dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); 20 | 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpcli10.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | socklen_t salen; 8 | struct sockaddr *sa; 9 | 10 | if (argc != 3) 11 | err_quit("usage: udpcli02 "); 12 | 13 | sockfd = Udp_client(argv[1], argv[2], (void **) &sa, &salen); 14 | 15 | dg_cli(stdin, sockfd, sa, salen); 16 | 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpserv01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin_family = AF_INET; 13 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 14 | servaddr.sin_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpserv06.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin_family = AF_INET; 13 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 14 | servaddr.sin_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/udpcliserv/udpserv07.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_in servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sin_family = AF_INET; 13 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 14 | servaddr.sin_port = htons(SERV_PORT); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/mycat.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int my_open(const char *, int); 4 | 5 | int 6 | main(int argc, char **argv) 7 | { 8 | int fd, n; 9 | char buff[BUFFSIZE]; 10 | 11 | if (argc != 2) 12 | err_quit("usage: mycat "); 13 | 14 | if ( (fd = my_open(argv[1], O_RDONLY)) < 0) 15 | err_sys("cannot open %s", argv[1]); 16 | 17 | while ( (n = Read(fd, buff, BUFFSIZE)) > 0) 18 | Write(STDOUT_FILENO, buff, n); 19 | 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/openfile.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int fd; 7 | 8 | if (argc != 4) 9 | err_quit("openfile "); 10 | 11 | if ( (fd = open(argv[2], atoi(argv[3]))) < 0) 12 | exit( (errno > 0) ? errno : 255 ); 13 | 14 | if (write_fd(atoi(argv[1]), "", 1, fd) < 0) 15 | exit( (errno > 0) ? errno : 255 ); 16 | 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/sigchldwaitpid.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | void 4 | sig_chld(int signo) 5 | { 6 | pid_t pid; 7 | int stat; 8 | 9 | while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { 10 | printf("child %d terminated\n", pid); 11 | } 12 | return; 13 | } 14 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/testfcred.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | printf("sizeof(struct fcred) = %d\n", sizeof(struct fcred)); 8 | printf("sizeof(struct cmsghdr) = %d\n", sizeof(struct cmsghdr)); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/unixdgserv01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_un servaddr, cliaddr; 8 | 9 | sockfd = Socket(AF_LOCAL, SOCK_DGRAM, 0); 10 | 11 | unlink(UNIXDG_PATH); 12 | bzero(&servaddr, sizeof(servaddr)); 13 | servaddr.sun_family = AF_LOCAL; 14 | strcpy(servaddr.sun_path, UNIXDG_PATH); 15 | 16 | Bind(sockfd, (SA *) &servaddr, sizeof(servaddr)); 17 | 18 | dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); 19 | } 20 | -------------------------------------------------------------------------------- /c/unix_socket/unpv13e/unixdomain/unixstrcli01.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | int 4 | main(int argc, char **argv) 5 | { 6 | int sockfd; 7 | struct sockaddr_un servaddr; 8 | 9 | sockfd = Socket(AF_LOCAL, SOCK_STREAM, 0); 10 | 11 | bzero(&servaddr, sizeof(servaddr)); 12 | servaddr.sun_family = AF_LOCAL; 13 | strcpy(servaddr.sun_path, UNIXSTR_PATH); 14 | 15 | Connect(sockfd, (SA *) &servaddr, sizeof(servaddr)); 16 | 17 | str_cli(stdin, sockfd); /* do it all */ 18 | 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | # php -------------------------------------------------------------------------------- /php/daemon/Autoload.php: -------------------------------------------------------------------------------- 1 | onReceive = function(Worker $fd, $message){ 8 | //处理业务逻辑 9 | $fd->log("recive $message"); 10 | //更新数据库 11 | }; 12 | 13 | $worker->run(); 14 | 15 | $start_time = time(); 16 | 17 | for($i =0; $i < 100000; $i++){ 18 | $worker->send(time().rand(10000, 99999)); 19 | } 20 | 21 | $worker->stop(); 22 | 23 | $end_time = time(); 24 | 25 | echo "100000 use ".($start_time - $end_time)."s"; 26 | -------------------------------------------------------------------------------- /php/distributed_task_server/README.md: -------------------------------------------------------------------------------- 1 | ### 分布式任务管理服务 2 | 假设有这么个场景:有很多任务要定时执行,单机器crontab已经无法满足,多机器crontab眼花缭乱,很难管理,需要更强大的系统,因此,本项目由此而生! 3 | 4 | #### 集群管理 5 | 每个机器都会启动一个server进程进行服务之间通信 6 | #### 定时器 7 | 在没有配置文件的情况下启动服务,会生成配置文件,然后指定该服务的角色为timer,timer即为执行定时器的服务 8 | #### 任务执行 9 | 可以在配置文件指定一个服务器为timer角色,然后启动服务,这种情况启动的服务角色是tasker,即为执行任务的服务 10 | 11 | #### 服务相关进程及通信模型 12 | ![image](https://github.com/inferne/notes/blob/master/php/dist_task_server/lx_clip1562223966808_lx.jpg) 13 | -------------------------------------------------------------------------------- /php/distributed_task_server/lx_clip1562223966808_lx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inferne/notes/bbe2875e155c14a8d8a229aa3142d263cb537e78/php/distributed_task_server/lx_clip1562223966808_lx.jpg -------------------------------------------------------------------------------- /php/library/README.MD: -------------------------------------------------------------------------------- 1 | 基于stream_socket_client的http client
2 | 支持http长连接
3 | 自动根据服务端连接类型选择合适的连接类型
4 | 5 | ## StreamHttpClient.php 6 | 1. 支持的方法 7 | * get() 8 | * send a get request 9 | * post() 10 | * send a post request 11 | 12 | ## demo 13 | ```php 14 | $url = "http://http://xiaoyblog.sinaapp.com/"; 15 | 16 | $http_client = new StreamHttpClient($url); 17 | $result = $http_client->get($params); 18 | echo $result; 19 | 20 | $result = $http_client->post($params); 21 | echo $result; 22 | ``` 23 | -------------------------------------------------------------------------------- /php/pcntl/README.MD: -------------------------------------------------------------------------------- 1 | 所有进程通信代码均为父进程和子进程通信 2 | -------------------------------------------------------------------------------- /php/pcntl/simple.php: -------------------------------------------------------------------------------- 1 | i; 8 | echo self::$j; 9 | echo static::$j; 10 | } 11 | } 12 | 13 | class B extends A{ 14 | protected $i = 'aaa'; 15 | protected static $j = 1; 16 | public function test2(){ 17 | $this->test(); 18 | } 19 | } 20 | 21 | $b = new B(); 22 | $b->test(); -------------------------------------------------------------------------------- /php/test/date2int.php: -------------------------------------------------------------------------------- 1 | "; 14 | $result = 0; 15 | while ($n){ 16 | $result += $n--; 17 | } 18 | $time3 = microtime(true); 19 | echo "while $n:".($time3-$time2)." result:$result
"; 20 | -------------------------------------------------------------------------------- /php/test/stdout.php: -------------------------------------------------------------------------------- 1 | set('test', 'test'); 6 | 7 | echo $yac->get('test'); 8 | 9 | $yac->set(array('ta'=>'ta','tb'=>'tb')); 10 | 11 | print_r($yac->get(array('ta','tb'))); 12 | 13 | echo $yac->get('ta'); 14 | echo $yac->get('tb'); -------------------------------------------------------------------------------- /php/test/新建文本文档.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inferne/notes/bbe2875e155c14a8d8a229aa3142d263cb537e78/php/test/新建文本文档.txt -------------------------------------------------------------------------------- /php/ygtoo/ques_push/README.md: -------------------------------------------------------------------------------- 1 | pthreads多线程推送程序 2 | -------------------------------------------------------------------------------- /php/ygtoo/ques_push/start_work.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ~/.bash_profile 4 | 5 | PATH=/opt/service/php/bin:$PATH 6 | 7 | cd `dirname $0` 8 | 9 | PH=`pwd` 10 | 11 | #check allocation start_ask_qsa 12 | PN=`ps -ef|grep start_ques_push.sh|grep -v "#"|grep -v "vi"|grep -v "grep"|awk "BEGIN {a=0} {a++} END {print a}"` 13 | if [ "$PN" -eq "0" ] 14 | then 15 | chmod +x start_ques_push.sh 16 | nohup ./start_ques_push.sh &>/dev/null & 17 | fi 18 | -------------------------------------------------------------------------------- /tensorflow/RabbishSMSIdentification/readme.md: -------------------------------------------------------------------------------- 1 | 数据来源:https://github.com/hrwhisper/SpamMessage 2 | 3 | 1、下载数据 4 | git clone https://github.com/hrwhisper/SpamMessage 5 | 6 | 2、按照SpamMessage的readme.md文件提示初始化系统环境 7 | 8 | 3、拷贝ConversionToInt.py和TFtest.py文件到SpamMessage目录下 9 | 10 | 4、执行ConversionToInt.py把短信转换成数字向量 11 | 12 | 5、执行TFtest.py训练模型 13 | -------------------------------------------------------------------------------- /tensorflow/Recommedation/README.md: -------------------------------------------------------------------------------- 1 | 文件说明: 2 | 3 | content.csv--内容数据 4 | 5 | content1000.csv--内容数据的前1000条 6 | 7 | data.csv--用户访问数据(可通过CreateTest.py脚本生成) 8 | 9 | users.csv--用户 10 | 11 | CreateTest.py--创建测试数据脚本,包括users.csv、data.csv 12 | 13 | Recommedation.py--训练推荐模型、测试模型 14 | -------------------------------------------------------------------------------- /tensorflow/Recommend/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mysql":{ 3 | "host": "", 4 | "user": "root", 5 | "pass": "123", 6 | "port": 3306, 7 | "name": "recommend_dev" 8 | }, 9 | "expire":3, 10 | "topk":100, 11 | "embedding_dim":35 12 | } -------------------------------------------------------------------------------- /tensorflow/Recommend/config/config_bjyt.json: -------------------------------------------------------------------------------- 1 | { 2 | "mysql":{ 3 | "host": "", 4 | "user": "", 5 | "pass": "", 6 | "port": , 7 | "name": "recommend" 8 | }, 9 | "expire":90, 10 | "topk":300, 11 | "embedding_dim":100 12 | } -------------------------------------------------------------------------------- /tensorflow/Recommend/lib/__init__.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | print("作为主程序运行") 3 | else: 4 | print("init package!") -------------------------------------------------------------------------------- /tensorflow/Recommend/model/__init__.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | print("作为主程序运行") 3 | else: 4 | print("init package!") -------------------------------------------------------------------------------- /tensorflow/Recommend/run_inc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | pid=$1 4 | pname=$2 5 | echo "$pid $pname" 6 | if [[ $# -lt 2 ]]; then 7 | echo "you cmd mabe like run.sh 1 yule" 8 | exit 9 | fi 10 | python ExportArticleInc.py -p $pid -d $pname 11 | if [[ $? -eq 0 ]]; then 12 | python KeywordsExtractInc.py -d $pname 13 | fi 14 | if [[ $? -eq 0 ]]; then 15 | python RecommedationInc.py -d $pname 16 | fi 17 | if [[ $? -eq 0 ]]; then 18 | python SaveGenreListInc.py -p $pid -d $pname 19 | fi 20 | --------------------------------------------------------------------------------