├── .gitignore ├── C++Primer ├── OOP │ ├── quote.cpp │ └── quote.h ├── Template │ └── com.cpp └── smart_point │ ├── strblob.cpp │ └── strblob.h ├── CPP_Concurrency_In_Action ├── README.md └── hello.cpp ├── Effecttive-C++ ├── README.md ├── term02.cpp ├── term03.cpp ├── term05.cpp └── term27.cpp ├── Inside-The-CPP-Object-Model ├── 1.1-cpp-object-model.cpp ├── README.md ├── object-lessons.cpp ├── pointer2member-data.cpp ├── the-semantics-of-constructors.cpp └── virtual-inheritan.cpp ├── PPT ├── C++新标准C++11_14.pdf ├── C++课件_面向对象高级编程(上).pdf ├── C++课件_面向对象高级编程(下).pdf └── STL标准库与泛型编程.pdf ├── README.md ├── STL ├── README.md ├── array.cpp └── vector.cpp ├── apue ├── 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 │ ├── deadlock.c │ ├── fixup.awk │ ├── lockfile.c │ ├── mandatory │ ├── mandatory.c │ ├── mcopy2 │ ├── mcopy2.c │ ├── nonblockw │ ├── nonblockw.c │ ├── readn.c │ ├── rot13a │ ├── rot13a.c │ ├── rot13c2 │ ├── rot13c2.c │ ├── rot13c2.c.in │ ├── writen.c │ └── xlate │ ├── daemons │ ├── Makefile │ ├── init.c │ ├── reread.c │ ├── reread2.c │ └── single.c │ ├── datafiles │ ├── Makefile │ ├── getpwnam.c │ ├── strftime │ └── strftime.c │ ├── db │ ├── Makefile │ ├── apue_db.h │ ├── db.c │ ├── t4 │ └── t4.c │ ├── environ │ ├── Makefile │ ├── cmd1.c │ ├── cmd2.c │ ├── doatexit │ ├── doatexit.c │ ├── echoarg │ ├── echoarg.c │ ├── getrlimit │ ├── getrlimit.c │ ├── hello1 │ ├── hello1.c │ ├── opendata.c │ ├── scope.c │ ├── testjmp │ └── testjmp.c │ ├── exercises │ ├── Makefile │ ├── asyncsocket.c │ ├── bo │ ├── bo.c │ ├── fifo1 │ ├── fifo1.c │ ├── fmemopen.c │ ├── getlogin │ ├── getlogin.c │ ├── getpw44bsd │ ├── getpw44bsd.c │ ├── getpwsvr4.c │ ├── goodexit │ ├── goodexit.c │ ├── longpath │ ├── longpath.c │ ├── openmax.c │ ├── pendlock │ ├── pendlock.c │ ├── pollmsg2.c │ ├── prtime │ ├── prtime.c │ ├── sizepipe │ ├── sizepipe.c │ ├── sleep.c │ ├── sleepus_poll.c │ ├── sleepus_select.c │ ├── vfork3 │ ├── vfork3.c │ ├── zombie │ └── 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 │ ├── access.c │ ├── cdpwd │ ├── cdpwd.c │ ├── changemod │ ├── changemod.c │ ├── devrdev │ ├── devrdev.c │ ├── filetype │ ├── filetype.c │ ├── ftw8 │ ├── ftw8.c │ ├── mycd │ ├── mycd.c │ ├── umask │ ├── umask.c │ ├── unlink │ ├── unlink.c │ └── zap.c │ ├── fileio │ ├── Makefile │ ├── fileflags │ ├── fileflags.c │ ├── hole │ ├── hole.c │ ├── mycat │ ├── mycat.c │ ├── seek │ ├── seek.c │ └── setfl.c │ ├── include │ └── apue.h │ ├── intro │ ├── Makefile │ ├── getcputc │ ├── getcputc.c │ ├── hello │ ├── hello.c │ ├── ls1 │ ├── ls1.c │ ├── mycat │ ├── mycat.c │ ├── shell1 │ ├── shell1.c │ ├── shell2 │ ├── shell2.c │ ├── testerror │ ├── testerror.c │ ├── uidgid │ └── uidgid.c │ ├── ipc1 │ ├── Makefile │ ├── add2 │ ├── add2.c │ ├── add2stdio │ ├── add2stdio.c │ ├── devzero │ ├── devzero.c │ ├── myuclc │ ├── myuclc.c │ ├── pipe1 │ ├── pipe1.c │ ├── pipe2 │ ├── pipe2.c │ ├── pipe4 │ ├── pipe4.c │ ├── popen.c │ ├── popen1 │ ├── popen1.c │ ├── popen2 │ ├── popen2.c │ ├── slock.c │ ├── slock.h │ ├── tellwait.c │ ├── tshm │ └── tshm.c │ ├── ipc2 │ ├── Makefile │ ├── bindunix │ ├── bindunix.c │ ├── open.fe │ │ ├── Makefile │ │ ├── main.c │ │ ├── open.c │ │ ├── open.h │ │ └── openclient │ ├── open │ │ ├── Makefile │ │ ├── main.c │ │ ├── open.c │ │ ├── open.h │ │ └── openclient │ ├── opend.fe │ │ ├── Makefile │ │ ├── cliargs.c │ │ ├── main.c │ │ ├── opend │ │ ├── opend.h │ │ └── request.c │ ├── opend │ │ ├── Makefile │ │ ├── cliargs.c │ │ ├── client.c │ │ ├── loop.poll.c │ │ ├── loop.select.c │ │ ├── main.c │ │ ├── opend.h │ │ ├── opend.poll │ │ ├── opend.select │ │ └── request.c │ ├── pollmsg │ ├── pollmsg.c │ ├── recvfd2.c │ ├── sendfd2.c │ ├── sendmsg │ └── 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 │ ├── print.c │ ├── print.h │ ├── printd │ ├── printd.c │ └── util.c │ ├── proc │ ├── Makefile │ ├── awkexample │ ├── echoall │ ├── echoall.c │ ├── exec1 │ ├── exec1.c │ ├── exec2 │ ├── exec2.c │ ├── fork1 │ ├── fork1.c │ ├── fork2 │ ├── fork2.c │ ├── nice │ ├── nice.c │ ├── pracct │ ├── pracct.c │ ├── pruids │ ├── pruids.c │ ├── system.c │ ├── systest1 │ ├── systest1.c │ ├── systest3 │ ├── systest3.c │ ├── tellwait1 │ ├── tellwait1.c │ ├── tellwait2 │ ├── tellwait2.c │ ├── test1 │ ├── test1.c │ ├── times1 │ ├── times1.c │ ├── vfork1 │ ├── vfork1.c │ ├── wait1 │ └── wait1.c │ ├── pty │ ├── Makefile │ ├── driver.c │ ├── loop.c │ ├── main.c │ └── pty │ ├── relation │ ├── Makefile │ ├── orphan3 │ └── orphan3.c │ ├── signals │ ├── Makefile │ ├── abort.c │ ├── child.c │ ├── critical │ ├── critical.c │ ├── mask │ ├── mask.c │ ├── read1 │ ├── read1.c │ ├── read2 │ ├── read2.c │ ├── reenter │ ├── reenter.c │ ├── setops.c │ ├── sigtstp │ ├── sigtstp.c │ ├── sigusr │ ├── sigusr.c │ ├── sleep1.c │ ├── sleep2.c │ ├── suspend1 │ ├── suspend1.c │ ├── suspend2 │ ├── suspend2.c │ ├── system.c │ ├── systest2 │ ├── systest2.c │ ├── tsleep2 │ └── tsleep2.c │ ├── sockets │ ├── clconn.c │ ├── clconn2.c │ ├── findsvc │ ├── findsvc.c │ ├── initsrv1.c │ ├── initsrv2.c │ ├── makefile │ ├── ruptime │ ├── ruptime-dg │ ├── ruptime-dg.c │ ├── ruptime.c │ ├── ruptimed │ ├── ruptimed-dg │ ├── ruptimed-dg.c │ ├── ruptimed-fd │ ├── ruptimed-fd.c │ └── ruptimed.c │ ├── standards │ ├── Makefile │ ├── conf │ ├── conf.c │ ├── makeconf.awk │ ├── makeopt.awk │ ├── options │ ├── options.c │ ├── pathconf-lim.sym │ ├── pathconf-opt.sym │ ├── pathconf.sym │ ├── pathopt.sym │ ├── sysconf-lim.sym │ ├── sysconf-opt.sym │ ├── sysconf.sym │ └── sysopt.sym │ ├── stdio │ ├── Makefile │ ├── buf │ ├── buf.c │ ├── fgetsfputs │ ├── fgetsfputs.c │ ├── getcharbug │ ├── getcharbug.c │ ├── getcputc │ ├── getcputc.c │ ├── memstr.c │ ├── mkstemp │ ├── mkstemp.c │ ├── tempfiles │ └── tempfiles.c │ ├── systype.sh │ ├── termios │ ├── Makefile │ ├── csize │ ├── csize.c │ ├── ctermid.c │ ├── getpass.c │ ├── isatty.c │ ├── settty │ ├── settty.c │ ├── t_getpass │ ├── t_getpass.c │ ├── t_isatty │ ├── t_isatty.c │ ├── t_raw │ ├── t_raw.c │ ├── t_ttyname │ ├── t_ttyname.c │ ├── ttyname.c │ ├── winch │ └── winch.c │ ├── threadctl │ ├── Makefile │ ├── atfork │ ├── atfork.c │ ├── detach.c │ ├── getenv1.c │ ├── getenv2.c │ ├── getenv3.c │ ├── suspend │ ├── suspend.c │ └── timeout.c │ └── threads │ ├── Makefile │ ├── badexit2 │ ├── badexit2.c │ ├── barrier.c │ ├── cleanup │ ├── cleanup.c │ ├── condvar.c │ ├── exitstatus │ ├── exitstatus.c │ ├── maketimeout.c │ ├── mutex1.c │ ├── mutex2.c │ ├── mutex3.c │ ├── rwlock.c │ ├── threadid │ ├── threadid.c │ └── timedlock.c ├── c++11:14 ├── README.md ├── alias-template.cpp ├── equal-default-delete.cpp ├── initializer-list.cpp ├── lambda.cpp ├── override.cpp ├── rvalue-reference.cpp ├── template-template-parameter.cpp ├── template.cpp ├── tuple.cpp └── variadic-template.cpp ├── cpp-part1 ├── README.md ├── Singleton.h ├── account-test.cpp ├── account.h ├── complex.h ├── complex_test.cpp ├── oop-demo.h ├── opp-test.cpp ├── singlenton-test.cpp ├── string-test.cpp ├── string.h ├── template-com.h └── template-test.cpp ├── cpp-part2 ├── README.md ├── auto.cpp ├── class-template.cpp ├── const.cpp ├── conversion-function.cpp ├── function-like.cpp ├── function-template.cpp ├── inheritance.cpp ├── member-templete.cpp ├── namespace.cpp ├── new-delete.cpp ├── object-model.cpp ├── overload-new-delete.cpp ├── partial-specialization.cpp ├── pointer-like.cpp ├── ranged-base-for.cpp ├── reference.cpp ├── specialization.cpp ├── template-template-parament.cpp └── variadic-templates.cpp ├── imag ├── const.jpg ├── delete.jpg ├── delete[].jpg ├── deque.png ├── head-class.jpg ├── lambda-1.jpg ├── lambda-2.jpg ├── lambda.jpg ├── map.png ├── mult-map.png ├── mult-set.png ├── new.jpg ├── queue.png ├── set.png ├── stack.png ├── unordered-mult-map.png ├── unordered-mult-set.png ├── vtbl.jpg └── vtbl2.jpg └── muduo ├── unp ├── README.md ├── daytimetcp │ ├── cli.c │ └── server.c ├── poll │ └── tcpserpool01.c ├── select │ ├── strcliselect01.c │ ├── strcliselect02.c │ └── tcpservselect01.c ├── sync │ └── mutex.c ├── tcpclistener │ ├── tcpcli01.c │ ├── tcpcli04.c │ ├── tcpserv01.c │ ├── tcpserv02.c │ └── tcpserv04.c ├── threads │ ├── strclithread.c │ ├── tcpserv01.c │ └── unpthread.h └── unixdomain │ ├── unixbind.c │ └── unixstrserve01.c └── unpv13e ├── DISCLAIMER ├── Make.defines ├── Make.defines.in ├── Makefile ├── 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 ├── config.h.in ├── config.log ├── config.status ├── 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 /C++Primer/Template/com.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | int compare(const T &v1, const T &v2) { 6 | if (v1 > v2) return -1; 7 | if (v1 < v2) return 1; 8 | return 0; 9 | } 10 | 11 | int main() { 12 | cout << compare(1,2); 13 | } -------------------------------------------------------------------------------- /CPP_Concurrency_In_Action/README.md: -------------------------------------------------------------------------------- 1 | [Cpp_Concurrency_In_Action](https://github.com/xiaoweiChen/Cpp_Concurrency_In_Action) -------------------------------------------------------------------------------- /CPP_Concurrency_In_Action/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void hello() { 5 | std::cout << "Hello Concurrent World" << std::endl; 6 | } 7 | 8 | int main() { 9 | std::thread t(hello); 10 | t.join(); 11 | } -------------------------------------------------------------------------------- /Effecttive-C++/term05.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/Effecttive-C++/term05.cpp -------------------------------------------------------------------------------- /Inside-The-CPP-Object-Model/1.1-cpp-object-model.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Point { 5 | public: 6 | Point(float xval); 7 | virtual ~Point(); 8 | float x() const; 9 | static int PointCount(); 10 | protected: 11 | virtual ostream& print(ostream &os) const; 12 | float _x; 13 | static int _point_count; 14 | }; -------------------------------------------------------------------------------- /Inside-The-CPP-Object-Model/README.md: -------------------------------------------------------------------------------- 1 | ## 深度探索C++对象模型 2 | 3 | ### 第2章 构造函数语义学 4 | 5 | 1. 明确的初始化操作 6 | 7 | 2. -------------------------------------------------------------------------------- /Inside-The-CPP-Object-Model/pointer2member-data.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Point3d { 5 | public: 6 | virtual ~Point3d(){}; 7 | float m; 8 | float n; 9 | private: 10 | static Point3d origin; 11 | float x,y,z; 12 | }; 13 | 14 | int main() { 15 | 16 | } -------------------------------------------------------------------------------- /Inside-The-CPP-Object-Model/virtual-inheritan.cpp: -------------------------------------------------------------------------------- 1 | class Point2d { 2 | protected: 3 | float _x, _y; 4 | }; 5 | 6 | class Vertex:public virtual Point2d { 7 | protected: 8 | Vertex *next; 9 | }; 10 | 11 | class Point3d : public virtual Point2d { 12 | protected: 13 | float _z; 14 | }; 15 | 16 | class Vertex3d: public Vertex, public Point3d { 17 | protected: 18 | float mumble; 19 | }; -------------------------------------------------------------------------------- /PPT/C++新标准C++11_14.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/PPT/C++新标准C++11_14.pdf -------------------------------------------------------------------------------- /PPT/C++课件_面向对象高级编程(上).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/PPT/C++课件_面向对象高级编程(上).pdf -------------------------------------------------------------------------------- /PPT/C++课件_面向对象高级编程(下).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/PPT/C++课件_面向对象高级编程(下).pdf -------------------------------------------------------------------------------- /PPT/STL标准库与泛型编程.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/PPT/STL标准库与泛型编程.pdf -------------------------------------------------------------------------------- /apue/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/README.md -------------------------------------------------------------------------------- /apue/apue.3e/Make.libapue.inc: -------------------------------------------------------------------------------- 1 | $(LIBAPUE): 2 | (cd $(ROOT)/lib && $(MAKE)) 3 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/deadlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/deadlock -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/mandatory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/mandatory -------------------------------------------------------------------------------- /apue/apue.3e/advio/mcopy2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/mcopy2 -------------------------------------------------------------------------------- /apue/apue.3e/advio/nonblockw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/nonblockw -------------------------------------------------------------------------------- /apue/apue.3e/advio/rot13a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/rot13a -------------------------------------------------------------------------------- /apue/apue.3e/advio/rot13c2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/advio/rot13c2 -------------------------------------------------------------------------------- /apue/apue.3e/advio/xlate: -------------------------------------------------------------------------------- 1 | if (isalpha(c)) { 2 | if (c >= 'n') 3 | c -= 13; 4 | else if (c >= 'a') 5 | c += 13; 6 | else if (c >= 'N') 7 | c -= 13; 8 | else 9 | c += 13; 10 | } 11 | return(c); 12 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/datafiles/strftime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/datafiles/strftime -------------------------------------------------------------------------------- /apue/apue.3e/db/t4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/db/t4 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/doatexit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/environ/doatexit -------------------------------------------------------------------------------- /apue/apue.3e/environ/echoarg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/environ/echoarg -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/getrlimit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/environ/getrlimit -------------------------------------------------------------------------------- /apue/apue.3e/environ/hello1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/environ/hello1 -------------------------------------------------------------------------------- /apue/apue.3e/environ/hello1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | printf("hello, world\n"); 6 | } 7 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/testjmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/environ/testjmp -------------------------------------------------------------------------------- /apue/apue.3e/exercises/bo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/bo -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/fifo1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/fifo1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getlogin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/getlogin -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getpw44bsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/getpw44bsd -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/goodexit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/goodexit -------------------------------------------------------------------------------- /apue/apue.3e/exercises/longpath: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/longpath -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/pendlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/pendlock -------------------------------------------------------------------------------- /apue/apue.3e/exercises/prtime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/prtime -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sizepipe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/sizepipe -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/vfork3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/vfork3 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/zombie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/exercises/zombie -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.10: -------------------------------------------------------------------------------- 1 | ../intro/shell2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.3: -------------------------------------------------------------------------------- 1 | ../intro/ls1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.4: -------------------------------------------------------------------------------- 1 | ../intro/mycat.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.5: -------------------------------------------------------------------------------- 1 | ../intro/getcputc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.6: -------------------------------------------------------------------------------- 1 | ../intro/hello.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.7: -------------------------------------------------------------------------------- 1 | ../intro/shell1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.8: -------------------------------------------------------------------------------- 1 | ../intro/testerror.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.9: -------------------------------------------------------------------------------- 1 | ../intro/uidgid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.10: -------------------------------------------------------------------------------- 1 | ../signals/read1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.11: -------------------------------------------------------------------------------- 1 | ../signals/read2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.12: -------------------------------------------------------------------------------- 1 | ../signals/setops.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.14: -------------------------------------------------------------------------------- 1 | ../lib/prmask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.15: -------------------------------------------------------------------------------- 1 | ../signals/critical.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.18: -------------------------------------------------------------------------------- 1 | ../lib/signal.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.19: -------------------------------------------------------------------------------- 1 | ../lib/signalintr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.2: -------------------------------------------------------------------------------- 1 | ../signals/sigusr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.20: -------------------------------------------------------------------------------- 1 | ../signals/mask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.22: -------------------------------------------------------------------------------- 1 | ../signals/suspend1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.23: -------------------------------------------------------------------------------- 1 | ../signals/suspend2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.24: -------------------------------------------------------------------------------- 1 | ../lib/tellwait.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.25: -------------------------------------------------------------------------------- 1 | ../signals/abort.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.26: -------------------------------------------------------------------------------- 1 | ../signals/systest2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.28: -------------------------------------------------------------------------------- 1 | ../signals/system.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.29: -------------------------------------------------------------------------------- 1 | ../lib/sleep.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.31: -------------------------------------------------------------------------------- 1 | ../signals/sigtstp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.5: -------------------------------------------------------------------------------- 1 | ../signals/reenter.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.6: -------------------------------------------------------------------------------- 1 | ../signals/child.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.7: -------------------------------------------------------------------------------- 1 | ../signals/sleep1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.8: -------------------------------------------------------------------------------- 1 | ../signals/sleep2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.9: -------------------------------------------------------------------------------- 1 | ../signals/tsleep2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.10: -------------------------------------------------------------------------------- 1 | ../threads/mutex1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.11: -------------------------------------------------------------------------------- 1 | ../threads/mutex2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.12: -------------------------------------------------------------------------------- 1 | ../threads/mutex3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.14: -------------------------------------------------------------------------------- 1 | ../threads/rwlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.15: -------------------------------------------------------------------------------- 1 | ../threads/condvar.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.16: -------------------------------------------------------------------------------- 1 | ../threads/barrier.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.2: -------------------------------------------------------------------------------- 1 | ../threads/threadid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.3: -------------------------------------------------------------------------------- 1 | ../threads/exitstatus.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.4: -------------------------------------------------------------------------------- 1 | ../threads/badexit2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.5: -------------------------------------------------------------------------------- 1 | ../threads/cleanup.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.11: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.12: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.13: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.16: -------------------------------------------------------------------------------- 1 | ../threadctl/suspend.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.17: -------------------------------------------------------------------------------- 1 | ../threadctl/atfork.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.4: -------------------------------------------------------------------------------- 1 | ../threadctl/detach.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.8: -------------------------------------------------------------------------------- 1 | ../threadctl/timeout.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.1: -------------------------------------------------------------------------------- 1 | ../daemons/init.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.6: -------------------------------------------------------------------------------- 1 | ../daemons/single.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.7: -------------------------------------------------------------------------------- 1 | ../daemons/reread.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.8: -------------------------------------------------------------------------------- 1 | ../daemons/reread2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.9: -------------------------------------------------------------------------------- 1 | ../lib/setfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.1: -------------------------------------------------------------------------------- 1 | ../advio/nonblockw.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.12: -------------------------------------------------------------------------------- 1 | ../advio/mandatory.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.20: -------------------------------------------------------------------------------- 1 | ../advio/rot13a.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.21: -------------------------------------------------------------------------------- 1 | ../advio/rot13c2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.24: -------------------------------------------------------------------------------- 1 | ../advio/writen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.27: -------------------------------------------------------------------------------- 1 | ../advio/mcopy2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.5: -------------------------------------------------------------------------------- 1 | ../lib/lockreg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.6: -------------------------------------------------------------------------------- 1 | ../lib/locktest.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.7: -------------------------------------------------------------------------------- 1 | ../advio/deadlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.9: -------------------------------------------------------------------------------- 1 | ../advio/lockfile.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.11: -------------------------------------------------------------------------------- 1 | ../ipc1/popen2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.12: -------------------------------------------------------------------------------- 1 | ../ipc1/popen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.14: -------------------------------------------------------------------------------- 1 | ../ipc1/myuclc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.15: -------------------------------------------------------------------------------- 1 | ../ipc1/popen1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.17: -------------------------------------------------------------------------------- 1 | ../ipc1/add2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.18: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.19: -------------------------------------------------------------------------------- 1 | ../ipc1/add2stdio.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.31: -------------------------------------------------------------------------------- 1 | ../ipc1/tshm.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.33: -------------------------------------------------------------------------------- 1 | ../ipc1/devzero.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.35: -------------------------------------------------------------------------------- 1 | ../ipc1/slock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.5: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.6: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.7: -------------------------------------------------------------------------------- 1 | ../ipc1/tellwait.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.10: -------------------------------------------------------------------------------- 1 | ../sockets/clconn.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.11: -------------------------------------------------------------------------------- 1 | ../sockets/clconn2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.12: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.16: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.17: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.18: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-fd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.19: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime-dg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.20: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-dg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.22: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.9: -------------------------------------------------------------------------------- 1 | ../sockets/findsvc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.10: -------------------------------------------------------------------------------- 1 | ../lib/cliconn.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.12: -------------------------------------------------------------------------------- 1 | ../lib/senderr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.13: -------------------------------------------------------------------------------- 1 | ../lib/sendfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.14: -------------------------------------------------------------------------------- 1 | ../lib/recvfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.15: -------------------------------------------------------------------------------- 1 | ../ipc2/sendfd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.16: -------------------------------------------------------------------------------- 1 | ../ipc2/recvfd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.17: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.18: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.19: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.2: -------------------------------------------------------------------------------- 1 | ../lib/spipe.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.20: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/opend.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.21: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.22: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/request.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.23: -------------------------------------------------------------------------------- 1 | ../lib/bufargs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.24: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/cliargs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.25: -------------------------------------------------------------------------------- 1 | ../ipc2/open/open.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.26: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/opend.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.27: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/client.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.28: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.29: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.select.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.3: -------------------------------------------------------------------------------- 1 | ../ipc2/pollmsg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.30: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.poll.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.31: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/request.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.4: -------------------------------------------------------------------------------- 1 | ../ipc2/sendmsg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.5: -------------------------------------------------------------------------------- 1 | ../ipc2/bindunix.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.8: -------------------------------------------------------------------------------- 1 | ../lib/servlisten.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.9: -------------------------------------------------------------------------------- 1 | ../lib/servaccept.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.10: -------------------------------------------------------------------------------- 1 | ../termios/settty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.11: -------------------------------------------------------------------------------- 1 | ../termios/csize.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.12: -------------------------------------------------------------------------------- 1 | ../termios/ctermid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.13: -------------------------------------------------------------------------------- 1 | ../termios/isatty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.14: -------------------------------------------------------------------------------- 1 | ../termios/t_isatty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.15: -------------------------------------------------------------------------------- 1 | ../termios/ttyname.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.16: -------------------------------------------------------------------------------- 1 | ../termios/t_ttyname.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.17: -------------------------------------------------------------------------------- 1 | ../termios/getpass.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.18: -------------------------------------------------------------------------------- 1 | ../termios/t_getpass.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.20: -------------------------------------------------------------------------------- 1 | ../lib/ttymodes.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.21: -------------------------------------------------------------------------------- 1 | ../termios/t_raw.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.22: -------------------------------------------------------------------------------- 1 | ../termios/winch.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.10: -------------------------------------------------------------------------------- 1 | ../lib/ptyfork.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.11: -------------------------------------------------------------------------------- 1 | ../pty/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.12: -------------------------------------------------------------------------------- 1 | ../pty/loop.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.16: -------------------------------------------------------------------------------- 1 | ../pty/driver.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.9: -------------------------------------------------------------------------------- 1 | ../lib/ptyopen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.13: -------------------------------------------------------------------------------- 1 | ../standards/makeconf.awk -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.14: -------------------------------------------------------------------------------- 1 | ../standards/conf.c.modified -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.16: -------------------------------------------------------------------------------- 1 | ../lib/pathalloc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.17: -------------------------------------------------------------------------------- 1 | ../lib/openmax.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig20.3: -------------------------------------------------------------------------------- 1 | ../db/t4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.1: -------------------------------------------------------------------------------- 1 | ../fileio/seek.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.11: -------------------------------------------------------------------------------- 1 | ../fileio/fileflags.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.12: -------------------------------------------------------------------------------- 1 | ../fileio/setfl.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.2: -------------------------------------------------------------------------------- 1 | ../fileio/hole.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.5: -------------------------------------------------------------------------------- 1 | ../fileio/mycat.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.12: -------------------------------------------------------------------------------- 1 | ../filedir/changemod.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.16: -------------------------------------------------------------------------------- 1 | ../filedir/unlink.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.21: -------------------------------------------------------------------------------- 1 | ../filedir/zap.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.22: -------------------------------------------------------------------------------- 1 | ../filedir/ftw8.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.23: -------------------------------------------------------------------------------- 1 | ../filedir/mycd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.24: -------------------------------------------------------------------------------- 1 | ../filedir/cdpwd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.25: -------------------------------------------------------------------------------- 1 | ../filedir/devrdev.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.3: -------------------------------------------------------------------------------- 1 | ../filedir/filetype.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.8: -------------------------------------------------------------------------------- 1 | ../filedir/access.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.9: -------------------------------------------------------------------------------- 1 | ../filedir/umask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.11: -------------------------------------------------------------------------------- 1 | ../stdio/buf.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.12: -------------------------------------------------------------------------------- 1 | ../stdio/tempfiles.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.13: -------------------------------------------------------------------------------- 1 | ../stdio/mkstemp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.15: -------------------------------------------------------------------------------- 1 | ../stdio/memstr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.4: -------------------------------------------------------------------------------- 1 | ../stdio/getcputc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.5: -------------------------------------------------------------------------------- 1 | ../stdio/fgetsfputs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig6.11: -------------------------------------------------------------------------------- 1 | ../datafiles/strftime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig6.2: -------------------------------------------------------------------------------- 1 | ../datafiles/getpwnam.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.1: -------------------------------------------------------------------------------- 1 | ../environ/hello1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.11: -------------------------------------------------------------------------------- 1 | ../environ/cmd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.13: -------------------------------------------------------------------------------- 1 | ../environ/testjmp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.14: -------------------------------------------------------------------------------- 1 | ../environ/opendata.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.16: -------------------------------------------------------------------------------- 1 | ../environ/getrlimit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.3: -------------------------------------------------------------------------------- 1 | ../environ/doatexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.4: -------------------------------------------------------------------------------- 1 | ../environ/echoarg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.9: -------------------------------------------------------------------------------- 1 | ../environ/cmd1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.1: -------------------------------------------------------------------------------- 1 | ../proc/fork1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.12: -------------------------------------------------------------------------------- 1 | ../proc/tellwait1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.13: -------------------------------------------------------------------------------- 1 | ../proc/tellwait2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.16: -------------------------------------------------------------------------------- 1 | ../proc/exec1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.17: -------------------------------------------------------------------------------- 1 | ../proc/echoall.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.20: -------------------------------------------------------------------------------- 1 | ../proc/exec2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.21: -------------------------------------------------------------------------------- 1 | ../proc/awkexample -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.22: -------------------------------------------------------------------------------- 1 | ../proc/system.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.23: -------------------------------------------------------------------------------- 1 | ../proc/systest1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.24: -------------------------------------------------------------------------------- 1 | ../proc/systest3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.25: -------------------------------------------------------------------------------- 1 | ../proc/pruids.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.28: -------------------------------------------------------------------------------- 1 | ../proc/test1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.29: -------------------------------------------------------------------------------- 1 | ../proc/pracct.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.3: -------------------------------------------------------------------------------- 1 | ../proc/vfork1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.30: -------------------------------------------------------------------------------- 1 | ../proc/nice.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.31: -------------------------------------------------------------------------------- 1 | ../proc/times1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.5: -------------------------------------------------------------------------------- 1 | ../lib/prexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.6: -------------------------------------------------------------------------------- 1 | ../proc/wait1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.8: -------------------------------------------------------------------------------- 1 | ../proc/fork2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig9.12: -------------------------------------------------------------------------------- 1 | ../relation/orphan3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.1: -------------------------------------------------------------------------------- 1 | ../include/apue.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.3: -------------------------------------------------------------------------------- 1 | ../lib/error.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.4: -------------------------------------------------------------------------------- 1 | ../lib/errorlog.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.1: -------------------------------------------------------------------------------- 1 | ../exercises/openmax.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.10: -------------------------------------------------------------------------------- 1 | ../exercises/zombie.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.12: -------------------------------------------------------------------------------- 1 | ../exercises/goodexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.13: -------------------------------------------------------------------------------- 1 | ../exercises/sleep.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.14: -------------------------------------------------------------------------------- 1 | ../exercises/getlogin.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.15: -------------------------------------------------------------------------------- 1 | ../exercises/pendlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.16: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_select.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.17: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_poll.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.18: -------------------------------------------------------------------------------- 1 | ../exercises/sizepipe.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.20: -------------------------------------------------------------------------------- 1 | ../exercises/fifo1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.22: -------------------------------------------------------------------------------- 1 | ../exercises/bo.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.23: -------------------------------------------------------------------------------- 1 | ../exercises/asyncsocket.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.24: -------------------------------------------------------------------------------- 1 | ../exercises/pollmsg2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.3: -------------------------------------------------------------------------------- 1 | ../exercises/longpath.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.4: -------------------------------------------------------------------------------- 1 | ../exercises/fmemopen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.5: -------------------------------------------------------------------------------- 1 | ../exercises/getpwsvr4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.6: -------------------------------------------------------------------------------- 1 | ../exercises/getpw44bsd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.7: -------------------------------------------------------------------------------- 1 | ../exercises/prtime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.8: -------------------------------------------------------------------------------- 1 | ../exercises/vfork3.c -------------------------------------------------------------------------------- /apue/apue.3e/filedir/access: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/access -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/cdpwd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/cdpwd -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/changemod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/changemod -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/devrdev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/devrdev -------------------------------------------------------------------------------- /apue/apue.3e/filedir/filetype: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/filetype -------------------------------------------------------------------------------- /apue/apue.3e/filedir/ftw8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/ftw8 -------------------------------------------------------------------------------- /apue/apue.3e/filedir/mycd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/mycd -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/umask: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/umask -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/unlink: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/filedir/unlink -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/fileflags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/fileio/fileflags -------------------------------------------------------------------------------- /apue/apue.3e/fileio/hole: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/fileio/hole -------------------------------------------------------------------------------- /apue/apue.3e/fileio/mycat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/fileio/mycat -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/seek: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/fileio/seek -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/getcputc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/getcputc -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/hello -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/ls1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/ls1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/mycat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/mycat -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/shell1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/shell1 -------------------------------------------------------------------------------- /apue/apue.3e/intro/shell2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/shell2 -------------------------------------------------------------------------------- /apue/apue.3e/intro/testerror: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/testerror -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/uidgid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/intro/uidgid -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/add2 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2stdio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/add2stdio -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/devzero: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/devzero -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/myuclc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/myuclc -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/pipe1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/pipe2 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/pipe4 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/popen1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/popen1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/popen2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/popen2 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/tshm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc1/tshm -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/bindunix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/bindunix -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open.fe/openclient: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/open.fe/openclient -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open/openclient: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/open/openclient -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/opend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/opend.fe/opend -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend/opend.poll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/opend/opend.poll -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend/opend.select: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/opend/opend.select -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/pollmsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/pollmsg -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/sendmsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/ipc2/sendmsg -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/printer/print: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/printer/print -------------------------------------------------------------------------------- /apue/apue.3e/printer/printd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/printer/printd -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/echoall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/echoall -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/exec1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/exec1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/exec2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/exec2 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/fork1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/fork1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/fork2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/fork2 -------------------------------------------------------------------------------- /apue/apue.3e/proc/nice: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/nice -------------------------------------------------------------------------------- /apue/apue.3e/proc/pracct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/pracct -------------------------------------------------------------------------------- /apue/apue.3e/proc/pruids: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/pruids -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/systest1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/systest3 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/tellwait1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/tellwait2 -------------------------------------------------------------------------------- /apue/apue.3e/proc/test1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/test1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/times1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/times1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/vfork1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/vfork1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/wait1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/proc/wait1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/pty/pty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/pty/pty -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/relation/orphan3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/relation/orphan3 -------------------------------------------------------------------------------- /apue/apue.3e/signals/critical: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/critical -------------------------------------------------------------------------------- /apue/apue.3e/signals/mask: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/mask -------------------------------------------------------------------------------- /apue/apue.3e/signals/read1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/read1 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/read2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/read2 -------------------------------------------------------------------------------- /apue/apue.3e/signals/reenter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/reenter -------------------------------------------------------------------------------- /apue/apue.3e/signals/sigtstp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/sigtstp -------------------------------------------------------------------------------- /apue/apue.3e/signals/sigusr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/sigusr -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/suspend1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/suspend1 -------------------------------------------------------------------------------- /apue/apue.3e/signals/suspend2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/suspend2 -------------------------------------------------------------------------------- /apue/apue.3e/signals/systest2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/systest2 -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/tsleep2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/signals/tsleep2 -------------------------------------------------------------------------------- /apue/apue.3e/sockets/findsvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/findsvc -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/ruptime -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptime-dg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/ruptime-dg -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/ruptimed -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed-dg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/ruptimed-dg -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed-fd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/sockets/ruptimed-fd -------------------------------------------------------------------------------- /apue/apue.3e/standards/conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/standards/conf -------------------------------------------------------------------------------- /apue/apue.3e/standards/options: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/standards/options -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathconf.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 | -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathopt.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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/buf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/buf -------------------------------------------------------------------------------- /apue/apue.3e/stdio/fgetsfputs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/fgetsfputs -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcharbug: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/getcharbug -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcputc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/getcputc -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/mkstemp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/mkstemp -------------------------------------------------------------------------------- /apue/apue.3e/stdio/tempfiles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/stdio/tempfiles -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/csize: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/csize -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/settty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/settty -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_getpass: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/t_getpass -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_isatty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/t_isatty -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/t_raw -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_ttyname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/t_ttyname -------------------------------------------------------------------------------- /apue/apue.3e/termios/winch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/termios/winch -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/atfork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threadctl/atfork -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/suspend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threadctl/suspend -------------------------------------------------------------------------------- /apue/apue.3e/threads/badexit2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threads/badexit2 -------------------------------------------------------------------------------- /apue/apue.3e/threads/cleanup: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threads/cleanup -------------------------------------------------------------------------------- /apue/apue.3e/threads/exitstatus: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threads/exitstatus -------------------------------------------------------------------------------- /apue/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 | -------------------------------------------------------------------------------- /apue/apue.3e/threads/threadid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/apue/apue.3e/threads/threadid -------------------------------------------------------------------------------- /c++11:14/alias-template.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/c++11:14/alias-template.cpp -------------------------------------------------------------------------------- /c++11:14/lambda.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main () { 6 | // 函数对象 7 | auto l = []{ 8 | cout << "hello lambda" << endl; 9 | }; 10 | l(); 11 | 12 | 13 | vector v{1,2,31,4,50}; 14 | int x = 1, y = 8; 15 | // 用lambda去掉区域内的数据 16 | v.erase(remove_if( 17 | v.begin(), 18 | v.end(), 19 | [x,y](int n) {return x < n && n < y;} 20 | ), v.end()); 21 | 22 | for(auto i: v) { 23 | cout << i << ' '; 24 | } 25 | cout << endl; 26 | } -------------------------------------------------------------------------------- /c++11:14/override.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/c++11:14/override.cpp -------------------------------------------------------------------------------- /c++11:14/template-template-parameter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 6 | class Container 7 | > 8 | class XCls{ 9 | private: 10 | Container c; 11 | public: 12 | XCls() { 13 | for(long i = 0; i < 100; ++i) { 14 | c.insert(c.end(), T()); 15 | } 16 | } 17 | }; 18 | 19 | template 20 | using Vec = vector>; 21 | 22 | class MyString{}; 23 | 24 | int main() { 25 | XCls x; 26 | } -------------------------------------------------------------------------------- /c++11:14/template.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/c++11:14/template.cpp -------------------------------------------------------------------------------- /c++11:14/tuple.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/c++11:14/tuple.cpp -------------------------------------------------------------------------------- /cpp-part1/Singleton.h: -------------------------------------------------------------------------------- 1 | #ifndef __SINGLENTON__ 2 | #define __SINGLENTON__ 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Singlenton { 8 | public: 9 | static Singlenton& getInstance(); 10 | void setup() { 11 | cout << "setuping"<< endl; 12 | }; 13 | private: 14 | Singlenton(){cout<<"create"<类型+类::静态变量名 15 | // 类的静态数据必须要在外面定义一下这样才能给初值 16 | double Account::m_rate = 0.8; 17 | 18 | #endif -------------------------------------------------------------------------------- /cpp-part1/complex_test.cpp: -------------------------------------------------------------------------------- 1 | #include "complex.h" 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | complex test(1,2); 8 | complex test1(1,2); 9 | cout << test.func(test1) << endl; 10 | test += test1; 11 | cout << test << test1 <Serialize 7 | my.onOpenFile(); 8 | } -------------------------------------------------------------------------------- /cpp-part1/singlenton-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Singleton.h" 3 | 4 | int main() { 5 | Singlenton::getInstance().setup(); 6 | Singlenton::getInstance().setup(); 7 | } -------------------------------------------------------------------------------- /cpp-part1/template-com.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEMCOM__ 2 | #define __TEMCOM__ 3 | 4 | template 5 | class complex { 6 | public: 7 | complex(T r = 0, T i = 0) :re(r), im(i){}; 8 | // complex& operator += (const complex& com); 9 | T real() {return re;} 10 | T imag() {return im;} 11 | private: 12 | T re, im; 13 | }; 14 | 15 | #endif -------------------------------------------------------------------------------- /cpp-part1/template-test.cpp: -------------------------------------------------------------------------------- 1 | #include "templete-com.h" 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | complex cd(1.0, 2.0); 7 | complex ci(3,4); 8 | cout << cd.imag() << endl; 9 | } -------------------------------------------------------------------------------- /cpp-part2/auto.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | vector v; 6 | v.push_back(1); 7 | 8 | vector::iterator ite; 9 | ite = v.begin(); 10 | 11 | // #2 ite1的类型太长 使用auto可以被自动推导 12 | auto ite1 = v.end(); 13 | 14 | // # 3错误 15 | // auto ite2; 16 | // ite2 = v.end(); 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /cpp-part2/class-template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class complex { 6 | public: 7 | complex(T r = 0, T i = 0) :re(r), im(i){}; 8 | // complex& operator += (const complex& com); 9 | T real() {return re;} 10 | T imag() {return im;} 11 | private: 12 | T re, im; 13 | }; 14 | 15 | int main() { 16 | complex a(1,2); 17 | complex b(1.1, 1.2); 18 | } -------------------------------------------------------------------------------- /cpp-part2/function-like.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 仿函数 一个类重载()符号之后 表现的像函数 5 | int main() { 6 | 7 | } -------------------------------------------------------------------------------- /cpp-part2/namespace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace test1 { 4 | void echo() { 5 | std::cout << "test1 echo" << std::endl; 6 | } 7 | } 8 | 9 | namespace test2 { 10 | void echo() { 11 | std::cout << "test2 echo" << std::endl; 12 | } 13 | } 14 | void echo() { 15 | std::cout << "main echo" << std::endl; 16 | } 17 | int main() { 18 | test1::echo(); 19 | test2::echo(); 20 | ::echo(); 21 | } -------------------------------------------------------------------------------- /cpp-part2/pointer-like.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 智能指针 5 | template 6 | class my_shared_ptr { 7 | public: 8 | T& operator*() const { 9 | return *px; 10 | } 11 | 12 | T* operator->() const { 13 | return px; 14 | } 15 | 16 | my_shared_ptr(T* p): px(p) {} 17 | private: 18 | T* px; 19 | long* pn; 20 | }; -------------------------------------------------------------------------------- /cpp-part2/template-template-parament.cpp: -------------------------------------------------------------------------------- 1 | // fuck 太难懂了 以后再看吧 2 | // template 4 | // class Container 5 | // > 6 | // class XCls{ 7 | // private: 8 | // Container c; 9 | // }; 10 | -------------------------------------------------------------------------------- /cpp-part2/variadic-templates.cpp: -------------------------------------------------------------------------------- 1 | // 数量不定的模板参数 c++ 11 2 | #include 3 | 4 | void print() { 5 | std::cout< 10 | void print(const T& firstArg, const Types&... args) { 11 | // sizeof...(args) 表示还剩下 多少个参数 12 | std::cout << firstArg << " left:" << sizeof...(args) << ' '; 13 | print(args...); 14 | } 15 | 16 | int main() { 17 | print(1,2,'a',1.0); 18 | } -------------------------------------------------------------------------------- /imag/const.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/const.jpg -------------------------------------------------------------------------------- /imag/delete.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/delete.jpg -------------------------------------------------------------------------------- /imag/delete[].jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/delete[].jpg -------------------------------------------------------------------------------- /imag/deque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/deque.png -------------------------------------------------------------------------------- /imag/head-class.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/head-class.jpg -------------------------------------------------------------------------------- /imag/lambda-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/lambda-1.jpg -------------------------------------------------------------------------------- /imag/lambda-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/lambda-2.jpg -------------------------------------------------------------------------------- /imag/lambda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/lambda.jpg -------------------------------------------------------------------------------- /imag/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/map.png -------------------------------------------------------------------------------- /imag/mult-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/mult-map.png -------------------------------------------------------------------------------- /imag/mult-set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/mult-set.png -------------------------------------------------------------------------------- /imag/new.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/new.jpg -------------------------------------------------------------------------------- /imag/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/queue.png -------------------------------------------------------------------------------- /imag/set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/set.png -------------------------------------------------------------------------------- /imag/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/stack.png -------------------------------------------------------------------------------- /imag/unordered-mult-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/unordered-mult-map.png -------------------------------------------------------------------------------- /imag/unordered-mult-set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/unordered-mult-set.png -------------------------------------------------------------------------------- /imag/vtbl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/vtbl.jpg -------------------------------------------------------------------------------- /imag/vtbl2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/imag/vtbl2.jpg -------------------------------------------------------------------------------- /muduo/unp/README.md: -------------------------------------------------------------------------------- 1 | ## UNP 2 | 3 | 记录细碎的知识点 4 | 5 | ### TCP客户/服务器程序示例 6 | 网络连接的一些边界问题 7 | 8 | 1. 客户和服务器启动时候发生了什么? 9 | 2. 客户正常终止时发生了什么? 10 | 3. 若服务器进程在客户之前终止,客户会发生什么? 11 | 4. 若服务器主机崩溃,则客户发生什么? 12 | 13 | 14 | -------------------------------------------------------------------------------- /muduo/unp/sync/mutex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/muduo/unp/sync/mutex.c -------------------------------------------------------------------------------- /muduo/unp/unixdomain/unixstrserve01.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangsoon/cpptest/819a71cf53c94db213649e1d7700a33ab79317a5/muduo/unp/unixdomain/unixstrserve01.c -------------------------------------------------------------------------------- /muduo/unpv13e/Makefile: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/unpv13e/VERSION: -------------------------------------------------------------------------------- 1 | 2004/12/12 2 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/unpv13e/lib/in6addr_any.c: -------------------------------------------------------------------------------- 1 | #include "unp.h" 2 | 3 | #ifdef IPV6 4 | const struct in6_addr in6addr_any; 5 | #endif 6 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/unpv13e/sock/sock.in: -------------------------------------------------------------------------------- 1 | 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 2 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/unpv13e/ssntp/sntp.h: -------------------------------------------------------------------------------- 1 | #include "unpifi.h" 2 | #include "ntp.h" 3 | 4 | void sntp_proc(char *, ssize_t, struct timeval *); 5 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/unpv13e/tcpcliserv/sum.h: -------------------------------------------------------------------------------- 1 | struct args { 2 | long arg1; 3 | long arg2; 4 | }; 5 | 6 | struct result { 7 | long sum; 8 | }; 9 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | -------------------------------------------------------------------------------- /muduo/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 | --------------------------------------------------------------------------------