Offset 1, 9 lines modified | Offset 1, 9 lines modified |
1 | <?xml·version="1.0"·encoding="utf-8"?> | 1 | <?xml·version="1.0"·encoding="utf-8"?> |
2 | <!DOCTYPE·html·PUBLIC·"-//W3C//DTD·XHTML·1.0·Transitional//EN"·"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html·xmlns="http://www.w3.org/1999/xhtml"><head><meta·http-equiv="Content-Type"·content="text/html;·charset=utf-8"·/><title>FreeBSD·Developers'·Handbook</title><link·rel="stylesheet"·type="text/css"·href="docbook.css"·/><link·rev="made"·href="mailto:doc@FreeBSD.org"·/><meta·name="generator"·content="DocBook·XSL·Stylesheets·V1.78.1"·/><meta·name="description"·content="歡迎使用·Developers'·Handbook!·這份文件是由許多人·不斷撰寫·而成的,·而且許多章節仍需更新或者內容還是一片空白,·如果你想幫忙·FreeBSD·文件計劃,·請寄信到·FreeBSD·documentation·project·郵遞論壇。·最新版的文件都在·FreeBSD·官網·上面,·也可從·FreeBSD·FTP·server·下載不同格式的資料。·當然也可以在其他的·mirror站下載。"·/><script·xmlns=""·type="text/javascript"·src="/layout/js/google.js"></script></head><body><div·xml:lang="zh_tw"·class="book"·lang="zh_tw"><div·xmlns=""·class="titlepage"><div><div><h1·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60750264"></a>FreeBSD·Developers'·Handbook</h1></div><div><div·xmlns="http:·✂ | 2 | <!DOCTYPE·html·PUBLIC·"-//W3C//DTD·XHTML·1.0·Transitional//EN"·"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html·xmlns="http://www.w3.org/1999/xhtml"><head><meta·http-equiv="Content-Type"·content="text/html;·charset=utf-8"·/><title>FreeBSD·Developers'·Handbook</title><link·rel="stylesheet"·type="text/css"·href="docbook.css"·/><link·rev="made"·href="mailto:doc@FreeBSD.org"·/><meta·name="generator"·content="DocBook·XSL·Stylesheets·V1.78.1"·/><meta·name="description"·content="歡迎使用·Developers'·Handbook!·這份文件是由許多人·不斷撰寫·而成的,·而且許多章節仍需更新或者內容還是一片空白,·如果你想幫忙·FreeBSD·文件計劃,·請寄信到·FreeBSD·documentation·project·郵遞論壇。·最新版的文件都在·FreeBSD·官網·上面,·也可從·FreeBSD·FTP·server·下載不同格式的資料。·當然也可以在其他的·mirror站下載。"·/><script·xmlns=""·type="text/javascript"·src="/layout/js/google.js"></script></head><body><div·xml:lang="zh_tw"·class="book"·lang="zh_tw"><div·xmlns=""·class="titlepage"><div><div><h1·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60811704"></a>FreeBSD·Developers'·Handbook</h1></div><div><div·xmlns="http:·✂ |
3 | ····forms·(XML,·HTML,·PDF,·PostScript,·RTF·and·so·forth)·with·or·without | 3 | ····forms·(XML,·HTML,·PDF,·PostScript,·RTF·and·so·forth)·with·or·without |
4 | ····modification,·are·permitted·provided·that·the·following·conditions·are | 4 | ····modification,·are·permitted·provided·that·the·following·conditions·are |
5 | ····met:</p><div·class="orderedlist"><ol·class="orderedlist"·type="1"><li·class="listitem"><p>Redistributions·of·source·code·(XML·DocBook)·must·retain·the | 5 | ····met:</p><div·class="orderedlist"><ol·class="orderedlist"·type="1"><li·class="listitem"><p>Redistributions·of·source·code·(XML·DocBook)·must·retain·the |
6 | ········above·copyright·notice,·this·list·of·conditions·and·the·following | 6 | ········above·copyright·notice,·this·list·of·conditions·and·the·following |
7 | ········disclaimer·as·the·first·lines·of·this·file·unmodified.</p></li><li·class="listitem"><p>Redistributions·in·compiled·form·(transformed·to·other·DTDs, | 7 | ········disclaimer·as·the·first·lines·of·this·file·unmodified.</p></li><li·class="listitem"><p>Redistributions·in·compiled·form·(transformed·to·other·DTDs, |
8 | ········converted·to·PDF,·PostScript,·RTF·and·other·formats)·must | 8 | ········converted·to·PDF,·PostScript,·RTF·and·other·formats)·must |
9 | ········reproduce·the·above·copyright·notice,·this·list·of·conditions·and | 9 | ········reproduce·the·above·copyright·notice,·this·list·of·conditions·and |
Offset 46, 15 lines modified | Offset 46, 15 lines modified |
46 | ······<a·href="index.html">章節模式</a> | 46 | ······<a·href="index.html">章節模式</a> |
47 | ······/ | 47 | ······/ |
48 | ······ | 48 | ······ |
49 | » ··完整模式 | 49 | » ··完整模式 |
50 | » | 50 | » |
51 | ······] | 51 | ······] |
52 | ····</div><hr·/></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="part"><a·href="#Basics">I.·基本概念</a></span></dt><dd><dl><dt><span·class="chapter"><a·href="#introduction">1.·簡介</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#introduction-devel">1.1.·在·FreeBSD·開發程式</a></span></dt><dt><span·class="sect1"><a·href="#introduction-bsdvision">1.2.·The·BSD·Vision</a></span></dt><dt><span·class="sect1"><a·href="#introduction-archguide">1.3.·程式架構指南</a></span></dt><dt><span·class="sect1"><a·href="#introduction-layout">1.4.·<code·class="filename">/usr/src</code>·的架構</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#tools">2.·程式開發工具</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#tools-synopsis">2.1.·概敘</a></span></dt><dt><span·class="sect1"><a·href="#tools-intro">2.2.·簡介</a></span></dt><dt><span·class="sect1"><a·href="#tools-programming">2.3.·Programming·概念</a></span></dt><dt><span·class="sect1"><a·href="#tools-compiling">2.4.·用·<code·class="command">cc<·✂ | 52 | ····</div><hr·/></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="part"><a·href="#Basics">I.·基本概念</a></span></dt><dd><dl><dt><span·class="chapter"><a·href="#introduction">1.·簡介</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#introduction-devel">1.1.·在·FreeBSD·開發程式</a></span></dt><dt><span·class="sect1"><a·href="#introduction-bsdvision">1.2.·The·BSD·Vision</a></span></dt><dt><span·class="sect1"><a·href="#introduction-archguide">1.3.·程式架構指南</a></span></dt><dt><span·class="sect1"><a·href="#introduction-layout">1.4.·<code·class="filename">/usr/src</code>·的架構</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#tools">2.·程式開發工具</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#tools-synopsis">2.1.·概敘</a></span></dt><dt><span·class="sect1"><a·href="#tools-intro">2.2.·簡介</a></span></dt><dt><span·class="sect1"><a·href="#tools-programming">2.3.·Programming·概念</a></span></dt><dt><span·class="sect1"><a·href="#tools-compiling">2.4.·用·<code·class="command">cc<·✂ |
53 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#l10n">4.·Localization·and·Internationalization·-·L10N·and·I18N</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#policies">5.·Source·Tree·Guidelines·and·Policies</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#policies-contributed">5·✂ | 53 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#l10n">4.·Localization·and·Internationalization·-·L10N·and·I18N</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#policies">5.·Source·Tree·Guidelines·and·Policies</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#policies-contributed">5·✂ |
54 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#l10n">4.·Localization·and·Internationalization·-·L10N·and·I18N</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#policies">5.·Source·Tree·Guidelines·and·Policies</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#policies-contributed">5·✂ | 54 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#l10n">4.·Localization·and·Internationalization·-·L10N·and·I18N</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></dd><dt><span·class="chapter"><a·href="#policies">5.·Source·Tree·Guidelines·and·Policies</a></span></dt><dd><dl><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#policies-contributed">5·✂ |
55 | ······但是要從哪裡開始呢?FreeBSD·有提供寫程式的程式或環境嗎? | 55 | ······但是要從哪裡開始呢?FreeBSD·有提供寫程式的程式或環境嗎? |
56 | ······身為·programer·的我可以做什麼呢?</p><p>本章試著回答你一些問題,當然,單就·programming·程度來說可分很多種層次, | 56 | ······身為·programer·的我可以做什麼呢?</p><p>本章試著回答你一些問題,當然,單就·programming·程度來說可分很多種層次, |
57 | ······有的人只是單純當興趣,有的則是他的專業, | 57 | ······有的人只是單純當興趣,有的則是他的專業, |
58 | ······本章主要內容是針對程式初學者, | 58 | ······本章主要內容是針對程式初學者, |
59 | ······當然,對於那些不熟·FreeBSD·的程式開發者而言,本文件內容也是十分實用的。</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="introduction-bsdvision"></a>1.2.·The·BSD·Vision</h2></div></div></div><p>為了讓你寫出來的程式在·<span·class="trademark">UNIX</span>®·like系統上具有良好的使用性、效能和穩定性, | 59 | ······當然,對於那些不熟·FreeBSD·的程式開發者而言,本文件內容也是十分實用的。</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="introduction-bsdvision"></a>1.2.·The·BSD·Vision</h2></div></div></div><p>為了讓你寫出來的程式在·<span·class="trademark">UNIX</span>®·like系統上具有良好的使用性、效能和穩定性, |
60 | ······我們必須跟你介紹一些程式概念(original·software·tools·ideology)。·</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="introduction-archguide"></a>1.3.·程式架構指南</h2></div></div></div><p>我們想介紹的概念如下</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>在整個程式還沒寫完前,不要增加新的功能。</p></li><li·class="listitem"><p>另外一個重點就是,讓你自己選擇你的程式將會具有何種功能, | 60 | ······我們必須跟你介紹一些程式概念(original·software·tools·ideology)。·</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="introduction-archguide"></a>1.3.·程式架構指南</h2></div></div></div><p>我們想介紹的概念如下</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>在整個程式還沒寫完前,不要增加新的功能。</p></li><li·class="listitem"><p>另外一個重點就是,讓你自己選擇你的程式將會具有何種功能, |
Offset 84, 30 lines modified | Offset 84, 30 lines modified |
84 | ······不過,我們假設你已經會·<span·class="trademark">UNIX</span>®·系統的基本操作, | 84 | ······不過,我們假設你已經會·<span·class="trademark">UNIX</span>®·系統的基本操作, |
85 | ······而且更重要的是,請保持樂於學習的心態!</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-programming"></a>2.3.·Programming·概念</h2></div></div></div><p>簡單的說,程式只是一堆指令的集合體;而這些指令是用來告訴電腦應該要作那些事情。 | 85 | ······而且更重要的是,請保持樂於學習的心態!</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-programming"></a>2.3.·Programming·概念</h2></div></div></div><p>簡單的說,程式只是一堆指令的集合體;而這些指令是用來告訴電腦應該要作那些事情。 |
86 | ······有時候,指令的執行取決於前一個指令的結果而定。 | 86 | ······有時候,指令的執行取決於前一個指令的結果而定。 |
87 | ······本章將會告訴你有·2·個主要的方法,讓你可以對電腦下達這些指示(instruction)·或·<span·class="quote">“<span·class="quote">命令(commands)</span>”</span>。 | 87 | ······本章將會告訴你有·2·個主要的方法,讓你可以對電腦下達這些指示(instruction)·或·<span·class="quote">“<span·class="quote">命令(commands)</span>”</span>。 |
88 | ······第一個方法就是·<em·class="firstterm">直譯器(interpreter)</em>, | 88 | ······第一個方法就是·<em·class="firstterm">直譯器(interpreter)</em>, |
89 | ······而第二個方法是·<em·class="firstterm">編譯器(compiler)</em>。 | 89 | ······而第二個方法是·<em·class="firstterm">編譯器(compiler)</em>。 |
90 | ······由於對於電腦而言,人類語言的語意過於模糊而太難理解, | 90 | ······由於對於電腦而言,人類語言的語意過於模糊而太難理解, |
91 | ······因此命令(commands)就常會以一種(或多種)程式語言寫成,用來指示電腦所要執行的特定動作為何。</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59412792"></a>2.3.1.·直譯器</h3></div></div></div><p>使用直譯器時,所使用的程式語言就像變成一個會和你互動的環境。 | 91 | ······因此命令(commands)就常會以一種(或多種)程式語言寫成,用來指示電腦所要執行的特定動作為何。</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59454904"></a>2.3.1.·直譯器</h3></div></div></div><p>使用直譯器時,所使用的程式語言就像變成一個會和你互動的環境。 |
92 | ········當在命令提示列上打上命令時,直譯器會即時執行該命令。 | 92 | ········當在命令提示列上打上命令時,直譯器會即時執行該命令。 |
93 | ········在比較複雜的程式中,可以把所有想下達的命令統統輸入到某檔案裡面去, | 93 | ········在比較複雜的程式中,可以把所有想下達的命令統統輸入到某檔案裡面去, |
94 | ········然後呼叫直譯器去讀取該檔案,並且執行你寫在這個檔案中的指令。 | 94 | ········然後呼叫直譯器去讀取該檔案,並且執行你寫在這個檔案中的指令。 |
95 | ········如果所下的指令有錯誤產生,大多數的直譯器會進入偵錯模式(debugger), | 95 | ········如果所下的指令有錯誤產生,大多數的直譯器會進入偵錯模式(debugger), |
96 | ········並且顯示相關錯誤訊息,以便對程式除錯。</p><p>這種方式好處在於:可以立刻看到指令的執行結果,以及錯誤也可迅速修正。 | 96 | ········並且顯示相關錯誤訊息,以便對程式除錯。</p><p>這種方式好處在於:可以立刻看到指令的執行結果,以及錯誤也可迅速修正。 |
97 | » ····相對的,最大的壞處便是當你想把你寫的程式分享給其他人時,這些人必須要有跟你一樣的直譯器。 | 97 | » ····相對的,最大的壞處便是當你想把你寫的程式分享給其他人時,這些人必須要有跟你一樣的直譯器。 |
98 | » ····而且別忘了,他們也要會使用直譯器直譯程式才行。 | 98 | » ····而且別忘了,他們也要會使用直譯器直譯程式才行。 |
99 | » ····當然使用者也不希望不小心按錯鍵,就進入偵錯模式而不知所措。 | 99 | » ····當然使用者也不希望不小心按錯鍵,就進入偵錯模式而不知所措。 |
100 | » ····就執行效率而言,直譯器會使用到很多的記憶體, | 100 | » ····就執行效率而言,直譯器會使用到很多的記憶體, |
101 | » ····而且這類直譯式程式,通常並不會比編譯器所編譯的程式的更有效率。</p><p>筆者個人認為,如果你之前沒有學過任何程式語言,最好先學學習直譯式語言(interpreted·languages), | 101 | » ····而且這類直譯式程式,通常並不會比編譯器所編譯的程式的更有效率。</p><p>筆者個人認為,如果你之前沒有學過任何程式語言,最好先學學習直譯式語言(interpreted·languages), |
102 | » ····像是·Lisp,Smalltalk,Perl·和·Basic·都是,<span·class="trademark">UNIX</span>®·的·shell·像是·<code·class="command">sh</code>·和·<code·class="command">csh</code> | 102 | » ····像是·Lisp,Smalltalk,Perl·和·Basic·都是,<span·class="trademark">UNIX</span>®·的·shell·像是·<code·class="command">sh</code>·和·<code·class="command">csh</code> |
103 | » ····它們本身就是直譯器,事實上,很多人都在它們自己機器上撰寫各式的·shell·<span·class="quote">“<span·class="quote">script</span>”</span>, | 103 | » ····它們本身就是直譯器,事實上,很多人都在它們自己機器上撰寫各式的·shell·<span·class="quote">“<span·class="quote">script</span>”</span>, |
104 | » ····來順利完成各項·<span·class="quote">“<span·class="quote">housekeeping(維護)</span>”</span>·任務。 | 104 | » ····來順利完成各項·<span·class="quote">“<span·class="quote">housekeeping(維護)</span>”</span>·任務。 |
105 | » ····<span·class="trademark">UNIX</span>®·的使用哲學之一就是提供大量的小工具, | 105 | » ····<span·class="trademark">UNIX</span>®·的使用哲學之一就是提供大量的小工具, |
106 | » ····並使用·shell·script·來組合運用這些小工具,以便工作更有效率。</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59428280"></a>2.3.2.·FreeBSD·提供的直譯器</h3></div></div></div><p>下面這邊有份·FreeBSD·Ports·Collection·所提供的直譯器清單,還有討論一些比較受歡迎的直譯式語言</p><p>至於如何使用·Ports·Collection·安裝的說明,可參閱·FreeBSD·Handbook·中的 | 106 | » ····並使用·shell·script·來組合運用這些小工具,以便工作更有效率。</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59470008"></a>2.3.2.·FreeBSD·提供的直譯器</h3></div></div></div><p>下面這邊有份·FreeBSD·Ports·Collection·所提供的直譯器清單,還有討論一些比較受歡迎的直譯式語言</p><p>至於如何使用·Ports·Collection·安裝的說明,可參閱·FreeBSD·Handbook·中的 |
107 | ········<a·class="link"·href="../../../../doc/zh_TW.UTF-8/books/handbook/ports-using.html"·target="_top">Ports章節</a>。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><acronym·class="acronym">BASIC</acronym></span></dt><dd><p>BASIC·是·Beginner's·ALL-purpose·Symbolic·Instruction·Code·的縮寫。 | 107 | ········<a·class="link"·href="../../../../doc/zh_TW.UTF-8/books/handbook/ports-using.html"·target="_top">Ports章節</a>。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><acronym·class="acronym">BASIC</acronym></span></dt><dd><p>BASIC·是·Beginner's·ALL-purpose·Symbolic·Instruction·Code·的縮寫。 |
108 | » ······BASIC·於·1950·年代開始發展,最初開發這套語言的目的是為了教導當時的大學學生如何寫程式。 | 108 | » ······BASIC·於·1950·年代開始發展,最初開發這套語言的目的是為了教導當時的大學學生如何寫程式。 |
109 | » ······到了·1980,<acronym·class="acronym">BASIC</acronym>已經是很多·programmer·第一個學習的程式語言了。 | 109 | » ······到了·1980,<acronym·class="acronym">BASIC</acronym>已經是很多·programmer·第一個學習的程式語言了。 |
110 | » ······此外,BASIC·也是·Visual·Basic·的基礎。</p><p>FreeBSD·Ports·Collection·也有收錄相關的·BASIC·直譯器。 | 110 | » ······此外,BASIC·也是·Visual·Basic·的基礎。</p><p>FreeBSD·Ports·Collection·也有收錄相關的·BASIC·直譯器。 |
111 | » ······Bywater·Basic·直譯器放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/bwbasic/pkg-descr">lang/bwbasic</a>。 | 111 | » ······Bywater·Basic·直譯器放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/bwbasic/pkg-descr">lang/bwbasic</a>。 |
112 | » ······而·Phil·Cockroft's·Basic·直譯器(早期也叫·Rabbit·Basic)放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/pbasic/pkg-descr">lang/pbasic</a>。</p></dd><dt><span·class="term">Lisp</span></dt><dd><p>LISP·是在·1950·年代開始發展的一個直譯式語言,而且·LISP·就是一種 | 112 | » ······而·Phil·Cockroft's·Basic·直譯器(早期也叫·Rabbit·Basic)放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/pbasic/pkg-descr">lang/pbasic</a>。</p></dd><dt><span·class="term">Lisp</span></dt><dd><p>LISP·是在·1950·年代開始發展的一個直譯式語言,而且·LISP·就是一種 |
113 | » ······<span·class="quote">“<span·class="quote">number-crunching</span>”</span>·languages(迅速進行大量運算的程式語言),在當時算是一個普遍的程式語言。 | 113 | » ······<span·class="quote">“<span·class="quote">number-crunching</span>”</span>·languages(迅速進行大量運算的程式語言),在當時算是一個普遍的程式語言。 |
Offset 133, 19 lines modified | Offset 133, 19 lines modified |
133 | » ······因為,即使對小朋友來說,要用·Logo·來秀出複雜多邊形圖形是相當輕鬆容易的。</p><p>Logo·在·FreeBSD·Ports·Collection·的最新版則是放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/logo/pkg-descr">lang/logo</a>。</p></dd><dt><span·class="term">Python</span></dt><dd><p>Python·是物件導向的直譯式語言, | 133 | » ······因為,即使對小朋友來說,要用·Logo·來秀出複雜多邊形圖形是相當輕鬆容易的。</p><p>Logo·在·FreeBSD·Ports·Collection·的最新版則是放在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/logo/pkg-descr">lang/logo</a>。</p></dd><dt><span·class="term">Python</span></dt><dd><p>Python·是物件導向的直譯式語言, |
134 | » ······Python·的擁護者總是宣稱·Python·是最好入門的程式語言。 | 134 | » ······Python·的擁護者總是宣稱·Python·是最好入門的程式語言。 |
135 | » ······雖然·Python·可以很簡單的開始,但是不代表它就會輸給其他直譯式語言(像是·Perl·和·Tcl), | 135 | » ······雖然·Python·可以很簡單的開始,但是不代表它就會輸給其他直譯式語言(像是·Perl·和·Tcl), |
136 | » ······事實證明·Python·也可以拿來開發大型、複雜的應用程式。</p><p>FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/python/pkg-descr">lang/python</a>。</p></dd><dt><span·class="term">Ruby</span></dt><dd><p>Ruby·是純物件導向的直譯式語言。 | 136 | » ······事實證明·Python·也可以拿來開發大型、複雜的應用程式。</p><p>FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/python/pkg-descr">lang/python</a>。</p></dd><dt><span·class="term">Ruby</span></dt><dd><p>Ruby·是純物件導向的直譯式語言。 |
137 | » ······Ruby·目前非常流行,原因在於他易懂的程式語法結構,在撰寫程式時的彈性, | 137 | » ······Ruby·目前非常流行,原因在於他易懂的程式語法結構,在撰寫程式時的彈性, |
138 | » ······以及天生具有輕易的發展維護大型專案的能力。</p><p>FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/ruby8/pkg-descr">lang/ruby8</a>。</p></dd><dt><span·class="term">Tcl·and·Tk</span></dt><dd><p>Tcl·是內嵌式的直譯式語言,讓·Tcl·可以如此廣泛運用的原因是·Tcl·的移植性。 | 138 | » ······以及天生具有輕易的發展維護大型專案的能力。</p><p>FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/ruby8/pkg-descr">lang/ruby8</a>。</p></dd><dt><span·class="term">Tcl·and·Tk</span></dt><dd><p>Tcl·是內嵌式的直譯式語言,讓·Tcl·可以如此廣泛運用的原因是·Tcl·的移植性。 |
139 | » ······Tcl·也可以快速發展一個簡單但是具有雛型的程式或者具有完整功能的程式。</p><p>Tcl·許多的版本都可在·FreeBSD·上運作,而最新的·Tcl·版本為·Tcl·8.4, | 139 | » ······Tcl·也可以快速發展一個簡單但是具有雛型的程式或者具有完整功能的程式。</p><p>Tcl·許多的版本都可在·FreeBSD·上運作,而最新的·Tcl·版本為·Tcl·8.4, |
140 | » ······FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/tcl84/pkg-descr">lang/tcl84</a>。</p></dd></dl></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59551800"></a>2.3.3.·編譯器</h3></div></div></div><p>編譯器和直譯器兩者相比的話,有些不同,首先就是必須先把程式碼統統寫入到檔案裡面, | 140 | » ······FreeBSD·Ports·Collection·收錄在·<a·xmlns=""·class="package"·href="http://www.freebsd.org/cgi/url.cgi?ports/lang/tcl84/pkg-descr">lang/tcl84</a>。</p></dd></dl></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59583544"></a>2.3.3.·編譯器</h3></div></div></div><p>編譯器和直譯器兩者相比的話,有些不同,首先就是必須先把程式碼統統寫入到檔案裡面, |
141 | ········然後必須執行編譯器來試著編譯程式,如果編譯器不接受所寫的程式,那就必須一直修改程式, | 141 | ········然後必須執行編譯器來試著編譯程式,如果編譯器不接受所寫的程式,那就必須一直修改程式, |
142 | ········直到編譯器接受且把你的程式編譯成執行檔。 | 142 | ········直到編譯器接受且把你的程式編譯成執行檔。 |
143 | ········此外,也可以在提示命令列,或在除錯器中執行你編譯好的程式看看它是否可以運作。 | 143 | ········此外,也可以在提示命令列,或在除錯器中執行你編譯好的程式看看它是否可以運作。 |
144 | » <a·href="#ftn.idp59555000"·class="footnote"·id="idp59555000"><sup·class="footnote">[1]</sup></a></p><p>很明顯的,使用編譯器並不像直譯器般可以馬上得到結果。 | 144 | » <a·href="#ftn.idp59586744"·class="footnote"·id="idp59586744"><sup·class="footnote">[1]</sup></a></p><p>很明顯的,使用編譯器並不像直譯器般可以馬上得到結果。 |
145 | ········不管如何,編譯器允許你作很多直譯器不可能或者是很難達到的事情。 | 145 | ········不管如何,編譯器允許你作很多直譯器不可能或者是很難達到的事情。 |
146 | ········例如:撰寫和作業系統密切互動的程式,甚至是你自己寫的作業系統! | 146 | ········例如:撰寫和作業系統密切互動的程式,甚至是你自己寫的作業系統! |
147 | ········當你想要寫出高效率的程式時,編譯器便派上用場了。 | 147 | ········當你想要寫出高效率的程式時,編譯器便派上用場了。 |
148 | ········編譯器可以在編譯時順便最佳化你的程式,但是直譯器卻不行。 | 148 | ········編譯器可以在編譯時順便最佳化你的程式,但是直譯器卻不行。 |
149 | ········而編譯器與直譯器最大的差別在於:當你想把你寫好的程式拿到另外一台機器上跑時, | 149 | ········而編譯器與直譯器最大的差別在於:當你想把你寫好的程式拿到另外一台機器上跑時, |
150 | ········你只要將編譯器編譯出來的可執行檔,拿到新機器上便可以執行, | 150 | ········你只要將編譯器編譯出來的可執行檔,拿到新機器上便可以執行, |
151 | ········而直譯器則必須要求新機器上,必須要有跟另一台機器上相同的直譯器, | 151 | ········而直譯器則必須要求新機器上,必須要有跟另一台機器上相同的直譯器, |
Offset 162, 40 lines modified | Offset 162, 40 lines modified |
162 | ········或使用·<span·class="application">Emacs</span>·來體驗·IDE·開發環境。 | 162 | ········或使用·<span·class="application">Emacs</span>·來體驗·IDE·開發環境。 |
163 | ········在後面的·<a·class="xref"·href="#emacs"·title="2.7.·Using·Emacs·as·a·Development·Environment">節 2.7,·“Using·Emacs·as·a·Development·Environment”</a>·專題將介紹,如何以·<span·class="application">Emacs</span>·來作為·IDE·開發環境。</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-compiling"></a>2.4.·用·<code·class="command">cc</code>·來編譯程式</h2></div></div></div><p>本章範例只有針對·GNU·C·compiler·和·GNU·C++·compiler·作說明, | 163 | ········在後面的·<a·class="xref"·href="#emacs"·title="2.7.·Using·Emacs·as·a·Development·Environment">節 2.7,·“Using·Emacs·as·a·Development·Environment”</a>·專題將介紹,如何以·<span·class="application">Emacs</span>·來作為·IDE·開發環境。</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-compiling"></a>2.4.·用·<code·class="command">cc</code>·來編譯程式</h2></div></div></div><p>本章範例只有針對·GNU·C·compiler·和·GNU·C++·compiler·作說明, |
164 | ········這兩個在·FreeBSD·base·system·中就有了, | 164 | ········這兩個在·FreeBSD·base·system·中就有了, |
165 | ········直接打·<code·class="command">cc</code>·或·<code·class="command">gcc</code>·就可以執行。 | 165 | ········直接打·<code·class="command">cc</code>·或·<code·class="command">gcc</code>·就可以執行。 |
166 | ········至於,如何用直譯器產生程式的說明,通常可在直譯器的文件或線上文件找到說明,因此不再贅述。</p><p>當你寫完你的傑作後,接下來便是讓這個程式可以在·FreeBSD·上執行, | 166 | ········至於,如何用直譯器產生程式的說明,通常可在直譯器的文件或線上文件找到說明,因此不再贅述。</p><p>當你寫完你的傑作後,接下來便是讓這個程式可以在·FreeBSD·上執行, |
167 | ········通常這些要一些步驟才能完成,有些步驟則需要不同程式來完成。</p><div·class="procedure"><ol·class="procedure"·type="1"><li·class="step"><p>預先處理(Pre-process)你的程式碼,移除程式內的註解,和其他技巧, | 167 | ········通常這些要一些步驟才能完成,有些步驟則需要不同程式來完成。</p><div·class="procedure"><ol·class="procedure"·type="1"><li·class="step"><p>預先處理(Pre-process)你的程式碼,移除程式內的註解,和其他技巧, |
168 | ··········像是·expanding(擴大)·C·的·marco。</p></li><li·class="step"><p>確認你的程式語法是否確實遵照·C/C++·的規定,如果沒有符合的話,編譯器會出現警告。</p></li><li·class="step"><p>將原始碼轉成組合語言·——·它跟機器語言(machine·code)非常相近,但仍在人類可理解的範圍內(據說應該是這樣)。 | 168 | ··········像是·expanding(擴大)·C·的·marco。</p></li><li·class="step"><p>確認你的程式語法是否確實遵照·C/C++·的規定,如果沒有符合的話,編譯器會出現警告。</p></li><li·class="step"><p>將原始碼轉成組合語言·——·它跟機器語言(machine·code)非常相近,但仍在人類可理解的範圍內(據說應該是這樣)。 |
169 | » ··<a·href="#ftn.idp59589560"·class="footnote"·id="idp59589560"><sup·class="footnote">[2]</sup></a></p></li><li·class="step"><p>把組合語言轉成機器語言·——·是的,這裡說的機器語言就是常提到的·bit·和·byte,也就是·1·和·0。</p></li><li·class="step"><p>確認程式中用到的函式呼叫、全域變數是否正確,舉例來說:如若呼叫了不存在的函式,編譯器會顯示警告。</p></li><li·class="step"><p>如果程式是由程式碼檔案來編譯,編譯器會整合起來。</p></li><li·class="step"><p>編譯器會負責產生東西,讓系統上的·run-time·loader·可以把程式載入記憶體內執行。</p></li><li·class="step"><p>最後會把編譯完的執行檔存在硬碟上。</p></li></ol></div><p>通常·<em·class="firstterm">編譯(compiling)</em>·是指第·1·到第·4·個步驟。 | 169 | » ··<a·href="#ftn.idp59627576"·class="footnote"·id="idp59627576"><sup·class="footnote">[2]</sup></a></p></li><li·class="step"><p>把組合語言轉成機器語言·——·是的,這裡說的機器語言就是常提到的·bit·和·byte,也就是·1·和·0。</p></li><li·class="step"><p>確認程式中用到的函式呼叫、全域變數是否正確,舉例來說:如若呼叫了不存在的函式,編譯器會顯示警告。</p></li><li·class="step"><p>如果程式是由程式碼檔案來編譯,編譯器會整合起來。</p></li><li·class="step"><p>編譯器會負責產生東西,讓系統上的·run-time·loader·可以把程式載入記憶體內執行。</p></li><li·class="step"><p>最後會把編譯完的執行檔存在硬碟上。</p></li></ol></div><p>通常·<em·class="firstterm">編譯(compiling)</em>·是指第·1·到第·4·個步驟。 |
170 | ······——·其他步驟則稱為·<em·class="firstterm">連結(linking)</em>, | 170 | ······——·其他步驟則稱為·<em·class="firstterm">連結(linking)</em>, |
171 | ······有時候步驟·1·也可以是指·<em·class="firstterm">預先處理(pre-processing)</em>, | 171 | ······有時候步驟·1·也可以是指·<em·class="firstterm">預先處理(pre-processing)</em>, |
172 | ······而步驟·3·到步驟·4·則是·<em·class="firstterm">組譯(assembling)</em>。</p><p>幸運的是,你可以不用理會以上細節,編譯器都會自動完成。 | 172 | ······而步驟·3·到步驟·4·則是·<em·class="firstterm">組譯(assembling)</em>。</p><p>幸運的是,你可以不用理會以上細節,編譯器都會自動完成。 |
173 | ······因為·<code·class="command">cc</code>·只是是個前端程式(front·end),它會依照正確的參數來呼叫相關程式幫你處理。 | 173 | ······因為·<code·class="command">cc</code>·只是是個前端程式(front·end),它會依照正確的參數來呼叫相關程式幫你處理。 |
174 | ······只需打:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foobar.c</code></strong></pre><p>上述指令會把·<code·class="filename">foobar.c</code>·開始編譯,並完成上述動作。 | 174 | ······只需打:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foobar.c</code></strong></pre><p>上述指令會把·<code·class="filename">foobar.c</code>·開始編譯,並完成上述動作。 |
175 | ······如果你有許多檔案需要編譯,那請打類似下列指令即可:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foo.c·bar.c</code></strong></pre><p>記住語法錯誤檢查就是·——·純粹檢查語法錯誤與否, | 175 | ······如果你有許多檔案需要編譯,那請打類似下列指令即可:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foo.c·bar.c</code></strong></pre><p>記住語法錯誤檢查就是·——·純粹檢查語法錯誤與否, |
176 | ······而不會幫你檢測任何邏輯錯誤,比如:無限迴圈,或是排序方式想用·binary·sort·卻弄成·bubble·sort。 | 176 | ······而不會幫你檢測任何邏輯錯誤,比如:無限迴圈,或是排序方式想用·binary·sort·卻弄成·bubble·sort。 |
177 | ······<a·href="#ftn.idp59619128"·class="footnote"·id="idp59619128"><sup·class="footnote">[3]</sup></a></p><p><code·class="command">cc</code>·有非常多的選項,都可透過線上手冊來查。 | 177 | ······<a·href="#ftn.idp59675448"·class="footnote"·id="idp59675448"><sup·class="footnote">[3]</sup></a></p><p><code·class="command">cc</code>·有非常多的選項,都可透過線上手冊來查。 |
178 | ······下面只提一些必要且重要的選項,以作為例子。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><code·class="option">-o·<em·class="replaceable"><code>檔名</code></em></code></span></dt><dd><p><code·class="option">-o</code>·編譯後的執行檔檔名,如果沒有使用這選項的話, | 178 | ······下面只提一些必要且重要的選項,以作為例子。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><code·class="option">-o·<em·class="replaceable"><code>檔名</code></em></code></span></dt><dd><p><code·class="option">-o</code>·編譯後的執行檔檔名,如果沒有使用這選項的話, |
179 | » ····編譯好的程式預設檔名將會是·<code·class="filename">a.out</code> | 179 | » ····編譯好的程式預設檔名將會是·<code·class="filename">a.out</code> |
| |
180 | » ····<a·href="#ftn.idp59642040"·class="footnote"·id="idp59642040"><sup·class="footnote">[4]</sup></a></p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foobar.c</code></strong>···············<em·class="lineannotation"><span·class="lineannotation">執行檔就是·a.out</span></em> | 180 | » ····<a·href="#ftn.idp59687096"·class="footnote"·id="idp59687096"><sup·class="footnote">[4]</sup></a></p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·foobar.c</code></strong>···············<em·class="lineannotation"><span·class="lineannotation">執行檔就是·a.out</span></em> |
181 | <code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c</code></strong>·····<em·class="lineannotation"><span·class="lineannotation">執行檔就是·foobar</span></em> | 181 | <code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c</code></strong>·····<em·class="lineannotation"><span·class="lineannotation">執行檔就是·foobar</span></em> |
182 | » ····</pre></div></dd><dt><span·class="term"><code·class="option">-c</code></span></dt><dd><p>使用·<code·class="option">-c</code>·時,只會編譯原始碼,而不作連結(linking)。 | 182 | » ····</pre></div></dd><dt><span·class="term"><code·class="option">-c</code></span></dt><dd><p>使用·<code·class="option">-c</code>·時,只會編譯原始碼,而不作連結(linking)。 |
183 | » ····當只想確認語法是否正確或使用·Makefile·來編譯程式時,這個選項非常有用。</p><div·class="informalexample"><pre·class="screen"> | 183 | » ····當只想確認語法是否正確或使用·Makefile·來編譯程式時,這個選項非常有用。</p><div·class="informalexample"><pre·class="screen"> |
184 | ········<code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-c·foobar.c</code></strong> | 184 | ········<code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-c·foobar.c</code></strong> |
185 | » ····</pre></div><p>這會產生叫做·<code·class="filename">foobar</code>·的·<em·class="firstterm">object·file</em>(非執行檔)。 | 185 | » ····</pre></div><p>這會產生叫做·<code·class="filename">foobar</code>·的·<em·class="firstterm">object·file</em>(非執行檔)。 |
186 | » ····這檔可以與其他的·object·file·連結在一起,而成執行檔。</p></dd><dt><span·class="term"><code·class="option">-g</code></span></dt><dd><p><code·class="option">-g</code>·將會把一些給·gdb·用的除錯訊息包進去執行檔裡面,所謂的除錯訊息例如: | 186 | » ····這檔可以與其他的·object·file·連結在一起,而成執行檔。</p></dd><dt><span·class="term"><code·class="option">-g</code></span></dt><dd><p><code·class="option">-g</code>·將會把一些給·gdb·用的除錯訊息包進去執行檔裡面,所謂的除錯訊息例如: |
187 | » ····程式在第幾行出錯、那個程式第幾行做什麼函式呼叫等等。除錯資訊<span·class="emphasis"><em>非常</em></span>好用。 | 187 | » ····程式在第幾行出錯、那個程式第幾行做什麼函式呼叫等等。除錯資訊<span·class="emphasis"><em>非常</em></span>好用。 |
188 | » ····但缺點就是:對於程式來說,額外的除錯訊息會讓編譯出來的程式比較肥些。 | 188 | » ····但缺點就是:對於程式來說,額外的除錯訊息會讓編譯出來的程式比較肥些。 |
189 | » ····<code·class="option">-g</code>·的適用時機在於:當程式還在開發時使用就好, | 189 | » ····<code·class="option">-g</code>·的適用時機在於:當程式還在開發時使用就好, |
190 | » ····而當你要釋出你的·<span·class="quote">“<span·class="quote">發行版本(release·version)</span>”</span> | 190 | » ····而當你要釋出你的·<span·class="quote">“<span·class="quote">發行版本(release·version)</span>”</span> |
191 | » ····或者確認程式可運作正常的話,就不必用·<code·class="option">-g</code>·這選項了。</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-g·foobar.c</code></strong> | 191 | » ····或者確認程式可運作正常的話,就不必用·<code·class="option">-g</code>·這選項了。</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-g·foobar.c</code></strong> |
192 | » ····</pre></div><p>這動作會產生有含除錯訊息的執行檔。 | 192 | » ····</pre></div><p>這動作會產生有含除錯訊息的執行檔。 |
193 | » ····<a·href="#ftn.idp59714488"·class="footnote"·id="idp59714488"><sup·class="footnote">[5]</sup></a></p></dd><dt><span·class="term"><code·class="option">-O</code></span></dt><dd><p><code·class="option">-O</code>·會產生最佳化的執行檔, | 193 | » ····<a·href="#ftn.idp59758136"·class="footnote"·id="idp59758136"><sup·class="footnote">[5]</sup></a></p></dd><dt><span·class="term"><code·class="option">-O</code></span></dt><dd><p><code·class="option">-O</code>·會產生最佳化的執行檔, |
194 | » ····編譯器會使用一些技巧,來讓程式可以跑的比未經最佳化的程式還快, | 194 | » ····編譯器會使用一些技巧,來讓程式可以跑的比未經最佳化的程式還快, |
195 | » ····可以在大寫·O·後面加上數字來指明想要的最佳化層級。 | 195 | » ····可以在大寫·O·後面加上數字來指明想要的最佳化層級。 |
196 | » ····但是最佳化還是會有一些錯誤,舉例來說在·FreeBSD·2.10·release·中用·<code·class="command">cc</code> | 196 | » ····但是最佳化還是會有一些錯誤,舉例來說在·FreeBSD·2.10·release·中用·<code·class="command">cc</code> |
197 | » ····且指定·<code·class="option">-O2</code>·時,在某些情形下會產生錯誤的執行檔。</p><p>只有當要釋出發行版本、或者加速程式時,才需要使用最佳化選項。</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-O·-o·foobar·foobar.c</code></strong> | 197 | » ····且指定·<code·class="option">-O2</code>·時,在某些情形下會產生錯誤的執行檔。</p><p>只有當要釋出發行版本、或者加速程式時,才需要使用最佳化選項。</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-O·-o·foobar·foobar.c</code></strong> |
198 | » ····</pre></div><p>這會產生·<code·class="filename">foobar</code>·執行檔的最佳化版本。</p></dd></dl></div><p>以下三個參數將會強迫·<code·class="command">cc</code>·確認程式碼是否符合一些國際標準的規範, | 198 | » ····</pre></div><p>這會產生·<code·class="filename">foobar</code>·執行檔的最佳化版本。</p></dd></dl></div><p>以下三個參數將會強迫·<code·class="command">cc</code>·確認程式碼是否符合一些國際標準的規範, |
199 | ······也就是通常說的·<acronym·class="acronym">ANSI</acronym>·標準, | 199 | ······也就是通常說的·<acronym·class="acronym">ANSI</acronym>·標準, |
200 | ······而·<acronym·class="acronym">ANSI</acronym>·嚴格來講屬·<acronym·class="acronym">ISO</acronym>·標準。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><code·class="option">-Wall</code></span></dt><dd><p><code·class="option">-Wall</code>·顯示·<code·class="command">cc</code>··維護者所認為值得注意的所有警告訊息。 | 200 | ······而·<acronym·class="acronym">ANSI</acronym>·嚴格來講屬·<acronym·class="acronym">ISO</acronym>·標準。</p><div·class="variablelist"><dl·class="variablelist"><dt><span·class="term"><code·class="option">-Wall</code></span></dt><dd><p><code·class="option">-Wall</code>·顯示·<code·class="command">cc</code>··維護者所認為值得注意的所有警告訊息。 |
Offset 221, 77 lines modified | Offset 221, 77 lines modified |
221 | <code·class="prompt">%</code>·<strong·class="userinput"><code>c++·-o·foobar·foobar.cc</code></strong> | 221 | <code·class="prompt">%</code>·<strong·class="userinput"><code>c++·-o·foobar·foobar.cc</code></strong> |
222 | » ····</pre></div><p>上述指令都會從原始檔·<code·class="filename">foobar.cc</code>·編譯產生名為·<code·class="filename">fooboar</code>·的執行檔。 | 222 | » ····</pre></div><p>上述指令都會從原始檔·<code·class="filename">foobar.cc</code>·編譯產生名為·<code·class="filename">fooboar</code>·的執行檔。 |
223 | » ····這邊要提醒的是在·<span·class="trademark">UNIX</span>®·系統中·C++·程式傳統都以·<code·class="filename">.C</code>、 | 223 | » ····這邊要提醒的是在·<span·class="trademark">UNIX</span>®·系統中·C++·程式傳統都以·<code·class="filename">.C</code>、 |
224 | » ····<code·class="filename">.cxx</code>·或者是·<code·class="filename">.cc</code>·作為副檔名, | 224 | » ····<code·class="filename">.cxx</code>·或者是·<code·class="filename">.cc</code>·作為副檔名, |
225 | » ····而非·<span·class="trademark">MS-DOS</span>®·那種以·<code·class="filename">.cpp</code>·作為副檔名的命名方式(不過也越來越普遍了)。 | 225 | » ····而非·<span·class="trademark">MS-DOS</span>®·那種以·<code·class="filename">.cpp</code>·作為副檔名的命名方式(不過也越來越普遍了)。 |
226 | » ····<code·class="command">gcc</code>·會依副檔名來決定用哪一種編譯器編譯, | 226 | » ····<code·class="command">gcc</code>·會依副檔名來決定用哪一種編譯器編譯, |
227 | » ····然而,現在已經不再限制副檔名了, | 227 | » ····然而,現在已經不再限制副檔名了, |
228 | » ····所以可以自由的使用·<code·class="filename">.cpp</code>·作為·C++·程式碼的副檔名!</p></dd></dl></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59844408"></a>2.4.1.·常見的·<code·class="command">cc</code>·問題</h3></div></div></div><div·class="qandaset"><a·id="idp59847096"></a><dl><dt>2.4.1.1.·<a·href="#idp59847736">我用·sin()·函示撰寫我的程式, | 228 | » ····所以可以自由的使用·<code·class="filename">.cpp</code>·作為·C++·程式碼的副檔名!</p></dd></dl></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp59889464"></a>2.4.1.·常見的·<code·class="command">cc</code>·問題</h3></div></div></div><div·class="qandaset"><a·id="idp59892152"></a><dl><dt>2.4.1.1.·<a·href="#idp59892664">我用·sin()·函示撰寫我的程式, |
229 | » ······但是有個錯誤訊息(如下),這代表著?</a></dt><dt>2.4.1.2.·<a·href="#idp59874360">好吧,我試著寫些簡單的程式,來練習使用·-lm·選項(該程式會運算·2.1·的·6·次方)</a></dt><dt>2.4.1.3.·<a·href="#idp59897784">那如何才可以修正剛所說的問題?</a></dt><dt>2.4.1.4.·<a·href="#idp59914424">已經編譯好·foobar.c, | 229 | » ······但是有個錯誤訊息(如下),這代表著?</a></dt><dt>2.4.1.2.·<a·href="#idp59904440">好吧,我試著寫些簡單的程式,來練習使用·-lm·選項(該程式會運算·2.1·的·6·次方)</a></dt><dt>2.4.1.3.·<a·href="#idp59939512">那如何才可以修正剛所說的問題?</a></dt><dt>2.4.1.4.·<a·href="#idp59969080">已經編譯好·foobar.c, |
230 | » ······但是編譯後找不到·foobar·執行檔。·該去哪邊找呢?</a></dt><dt>2.4.1.5.·<a·href="#idp59931832">好,有個編譯好的程式叫做·foobar, | 230 | » ······但是編譯後找不到·foobar·執行檔。·該去哪邊找呢?</a></dt><dt>2.4.1.5.·<a·href="#idp59999544">好,有個編譯好的程式叫做·foobar, |
231 | » ······用·ls·指令時可以看到, | 231 | » ······用·ls·指令時可以看到, |
232 | » ······但執行時,訊息卻說卻沒有這檔案。為什麼?</a></dt><dt>2.4.1.6.·<a·href="#idp59948472">試著執行·test·執行檔, | 232 | » ······但執行時,訊息卻說卻沒有這檔案。為什麼?</a></dt><dt>2.4.1.6.·<a·href="#idp60015544">試著執行·test·執行檔, |
233 | » ······但是卻沒有任何事發生,到底是哪裡出錯了?</a></dt><dt>2.4.1.7.·<a·href="#idp59983160">當執行我寫的程式時剛開始正常, | 233 | » ······但是卻沒有任何事發生,到底是哪裡出錯了?</a></dt><dt>2.4.1.7.·<a·href="#idp60037304">當執行我寫的程式時剛開始正常, |
234 | » ······接下來卻出現·core·dumped·錯誤訊息。這錯誤訊息到底代表什麼?</a></dt><dt>2.4.1.8.·<a·href="#idp59992760">真是太神奇了!程式居然發生·core·dumped·了,該怎麼辦?</a></dt><dt>2.4.1.9.·<a·href="#idp60004152">當程式已經把·core·memory·資料·dump·出來後, | 234 | » ······接下來卻出現·core·dumped·錯誤訊息。這錯誤訊息到底代表什麼?</a></dt><dt>2.4.1.8.·<a·href="#idp60060088">真是太神奇了!程式居然發生·core·dumped·了,該怎麼辦?</a></dt><dt>2.4.1.9.·<a·href="#idp60071096">當程式已經把·core·memory·資料·dump·出來後, |
235 | » ······同時也出現另一個錯誤·segmentation·fault·這意思是?</a></dt><dt>2.4.1.10.·<a·href="#idp60051640">Sometimes·when·I·get·a·core·dump·it·says | 235 | » ······同時也出現另一個錯誤·segmentation·fault·這意思是?</a></dt><dt>2.4.1.10.·<a·href="#idp60119224">Sometimes·when·I·get·a·core·dump·it·says |
236 | » ······bus·error.··It·says·in·my·UNIX® | 236 | » ······bus·error.··It·says·in·my·UNIX® |
237 | » ······book·that·this·means·a·hardware·problem,·but·the | 237 | » ······book·that·this·means·a·hardware·problem,·but·the |
238 | » ······computer·still·seems·to·be·working.··Is·this | 238 | » ······computer·still·seems·to·be·working.··Is·this |
239 | » ······true?</a></dt><dt>2.4.1.11.·<a·href="#idp60072248">This·dumping·core·business·sounds·as·though·it·could | 239 | » ······true?</a></dt><dt>2.4.1.11.·<a·href="#idp60127288">This·dumping·core·business·sounds·as·though·it·could |
240 | » ······be·quite·useful,·if·I·can·make·it·happen·when·I·want·to. | 240 | » ······be·quite·useful,·if·I·can·make·it·happen·when·I·want·to. |
241 | » ······Can·I·do·this,·or·do·I·have·to·wait·until·there·is·an | 241 | » ······Can·I·do·this,·or·do·I·have·to·wait·until·there·is·an |
242 | » ······error?</a></dt></dl><table·border="0"·style="width:·100%;"><colgroup><col·align="left"·width="1%"·/><col·/></colgroup><tbody><tr·class="question"><td·align="left"·valign="top"><a·id="idp59847736"></a><a·id="idp59848760"></a><p><strong>2.4.1.1.</strong></p></td><td·align="left"·valign="top"><p>我用·<code·class="function">sin()</code>·函示撰寫我的程式, | 242 | » ······error?</a></dt></dl><table·border="0"·style="width:·100%;"><colgroup><col·align="left"·width="1%"·/><col·/></colgroup><tbody><tr·class="question"><td·align="left"·valign="top"><a·id="idp59892664"></a><a·id="idp59893176"></a><p><strong>2.4.1.1.</strong></p></td><td·align="left"·valign="top"><p>我用·<code·class="function">sin()</code>·函示撰寫我的程式, |
243 | » ······但是有個錯誤訊息(如下),這代表著?</p><div·class="informalexample"><pre·class="screen">/var/tmp/cc0143941.o:·Undefined·symbol·`_sin'·referenced·from·text·segment | 243 | » ······但是有個錯誤訊息(如下),這代表著?</p><div·class="informalexample"><pre·class="screen">/var/tmp/cc0143941.o:·Undefined·symbol·`_sin'·referenced·from·text·segment |
244 | » ······</pre></div></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>當使用·<code·class="function">sin()</code>·這類的數學函示時, | 244 | » ······</pre></div></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>當使用·<code·class="function">sin()</code>·這類的數學函示時, |
245 | » ······你必須告訴·cc·要和數學函式庫作連結(linking),就像這樣:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c·-lm</code></strong> | 245 | » ······你必須告訴·cc·要和數學函式庫作連結(linking),就像這樣:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c·-lm</code></strong> |
246 | » ······</pre></div></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59874360"></a><a·id="idp59875000"></a><p><strong>2.4.1.2.</strong></p></td><td·align="left"·valign="top"><p>好吧,我試著寫些簡單的程式,來練習使用·-lm·選項(該程式會運算·2.1·的·6·次方)</p><div·class="informalexample"><pre·class="programlisting">#include·<stdio.h> | 246 | » ······</pre></div></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59904440"></a><a·id="idp59905080"></a><p><strong>2.4.1.2.</strong></p></td><td·align="left"·valign="top"><p>好吧,我試著寫些簡單的程式,來練習使用·-lm·選項(該程式會運算·2.1·的·6·次方)</p><div·class="informalexample"><pre·class="programlisting">#include·<stdio.h> |
| |
247 | int·main()·{ | 247 | int·main()·{ |
248 | » float·f; | 248 | » float·f; |
| |
249 | » f·=·pow(2.1,·6); | 249 | » f·=·pow(2.1,·6); |
250 | » printf("2.1·^·6·=·%f\n",·f); | 250 | » printf("2.1·^·6·=·%f\n",·f); |
251 | » return·0; | 251 | » return·0; |
252 | } | 252 | } |
253 | » ······</pre></div><p>然後進行編譯:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·temp.c·-lm</code></strong> | 253 | » ······</pre></div><p>然後進行編譯:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·temp.c·-lm</code></strong> |
254 | » ······</pre></div><p>編譯後執行程式,得到下面這結果:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./a.out</code></strong> | 254 | » ······</pre></div><p>編譯後執行程式,得到下面這結果:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./a.out</code></strong> |
255 | 2.1·^·6·=·1023.000000 | 255 | 2.1·^·6·=·1023.000000 |
256 | » ······</pre></div><p>很明顯的,程式結果<span·class="emphasis"><em>不是</em></span>正確答案,到底是哪邊出錯?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>當編譯器發現你呼叫一個函示時,它會確認該函示的回傳值類型(prototype), | 256 | » ······</pre></div><p>很明顯的,程式結果<span·class="emphasis"><em>不是</em></span>正確答案,到底是哪邊出錯?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>當編譯器發現你呼叫一個函示時,它會確認該函示的回傳值類型(prototype), |
257 | » ······如果沒有特別指明,則預設的回傳值類型為·<span·class="type">int(整數)</span>。 | 257 | » ······如果沒有特別指明,則預設的回傳值類型為·<span·class="type">int(整數)</span>。 |
258 | » ······很明顯的,你的程式所需要的並不是回傳值類別為·<span·class="type">int</span>。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59897784"></a><a·id="idp59898296"></a><p><strong>2.4.1.3.</strong></p></td><td·align="left"·valign="top"><p>那如何才可以修正剛所說的問題?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>數學函示的回傳值類型(prototype)會定義在·<code·class="filename">math.h</code>, | 258 | » ······很明顯的,你的程式所需要的並不是回傳值類別為·<span·class="type">int</span>。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59939512"></a><a·id="idp59940408"></a><p><strong>2.4.1.3.</strong></p></td><td·align="left"·valign="top"><p>那如何才可以修正剛所說的問題?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>數學函示的回傳值類型(prototype)會定義在·<code·class="filename">math.h</code>, |
259 | » ······如果你有·include·這檔,編譯器就會知道該函示的回傳值類型,如此一來該運算就會得到正確的結果!</p><div·class="informalexample"><pre·class="programlisting">#include·<math.h> | 259 | » ······如果你有·include·這檔,編譯器就會知道該函示的回傳值類型,如此一來該運算就會得到正確的結果!</p><div·class="informalexample"><pre·class="programlisting">#include·<math.h> |
260 | #include·<stdio.h> | 260 | #include·<stdio.h> |
| |
261 | int·main()·{ | 261 | int·main()·{ |
262 | ... | 262 | ... |
263 | » ······</pre></div><p>加了上述內容之後,再重新編譯,最後執行:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./a.out</code></strong> | 263 | » ······</pre></div><p>加了上述內容之後,再重新編譯,最後執行:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./a.out</code></strong> |
264 | 2.1·^·6·=·85.766121 | 264 | 2.1·^·6·=·85.766121 |
265 | » ······</pre></div><p>如果有用到數學函式,<span·class="emphasis"><em>請確定</em></span>要有·include·<code·class="filename">math.h</code>·這檔, | 265 | » ······</pre></div><p>如果有用到數學函式,<span·class="emphasis"><em>請確定</em></span>要有·include·<code·class="filename">math.h</code>·這檔, |
266 | » ······而且記得要和數學函式庫作連結。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59914424"></a><a·id="idp59915448"></a><p><strong>2.4.1.4.</strong></p></td><td·align="left"·valign="top"><p>已經編譯好·<code·class="filename">foobar.c</code>, | 266 | » ······而且記得要和數學函式庫作連結。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59969080"></a><a·id="idp59969976"></a><p><strong>2.4.1.4.</strong></p></td><td·align="left"·valign="top"><p>已經編譯好·<code·class="filename">foobar.c</code>, |
267 | » ······但是編譯後找不到·<code·class="filename">foobar</code>·執行檔。·該去哪邊找呢?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>記得,除非有指定編譯結果的執行檔檔名,否則預設的執行檔檔名是·a.out。 | 267 | » ······但是編譯後找不到·<code·class="filename">foobar</code>·執行檔。·該去哪邊找呢?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>記得,除非有指定編譯結果的執行檔檔名,否則預設的執行檔檔名是·a.out。 |
268 | » ······用·<code·class="option">-o <em·class="replaceable"><code>filename</code></em></code>·參數, | 268 | » ······用·<code·class="option">-o <em·class="replaceable"><code>filename</code></em></code>·參數, |
269 | » ······就可以達到所想要的結果,比如:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c</code></strong> | 269 | » ······就可以達到所想要的結果,比如:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·-o·foobar·foobar.c</code></strong> |
270 | » ······</pre></div></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59931832"></a><a·id="idp59932344"></a><p><strong>2.4.1.5.</strong></p></td><td·align="left"·valign="top"><p>好,有個編譯好的程式叫做·<code·class="filename">foobar</code>, | 270 | » ······</pre></div></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59999544"></a><a·id="idp60000056"></a><p><strong>2.4.1.5.</strong></p></td><td·align="left"·valign="top"><p>好,有個編譯好的程式叫做·<code·class="filename">foobar</code>, |
271 | » ······用·<code·class="command">ls</code>·指令時可以看到, | 271 | » ······用·<code·class="command">ls</code>·指令時可以看到, |
272 | » ······但執行時,訊息卻說卻沒有這檔案。為什麼?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>與·<span·class="trademark">MS-DOS</span>®·不同的是,除非有指定執行檔的路徑, | 272 | » ······但執行時,訊息卻說卻沒有這檔案。為什麼?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>與·<span·class="trademark">MS-DOS</span>®·不同的是,除非有指定執行檔的路徑, |
273 | » ······否則·<span·class="trademark">UNIX</span>®·系統並不會在目前的目錄下尋找你想執行的檔案。 | 273 | » ······否則·<span·class="trademark">UNIX</span>®·系統並不會在目前的目錄下尋找你想執行的檔案。 |
274 | » ······在指令列下打·<code·class="command">./foobar</code>·代表 | 274 | » ······在指令列下打·<code·class="command">./foobar</code>·代表 |
275 | » ······<span·class="quote">“<span·class="quote">執行在這個目錄底下名為·<code·class="filename">foobar</code>·的程式</span>”</span>, | 275 | » ······<span·class="quote">“<span·class="quote">執行在這個目錄底下名為·<code·class="filename">foobar</code>·的程式</span>”</span>, |
276 | » ······或者也可以更改·<code·class="envar">PATH</code>·環境變數設定如下,以達成類似效果:</p><div·class="informalexample"><pre·class="screen">bin:/usr/bin:/usr/local/bin:. | 276 | » ······或者也可以更改·<code·class="envar">PATH</code>·環境變數設定如下,以達成類似效果:</p><div·class="informalexample"><pre·class="screen">bin:/usr/bin:/usr/local/bin:. |
277 | » ······</pre></div><p>上一行最後的·"."·代表<span·class="quote">“<span·class="quote">如果在前面寫的其他目錄找不到,就找目前的目錄</span>”</span>。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59948472"></a><a·id="idp59949112"></a><p><strong>2.4.1.6.</strong></p></td><td·align="left"·valign="top"><p>試著執行·<code·class="filename">test</code>·執行檔, | 277 | » ······</pre></div><p>上一行最後的·"."·代表<span·class="quote">“<span·class="quote">如果在前面寫的其他目錄找不到,就找目前的目錄</span>”</span>。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60015544"></a><a·id="idp60015800"></a><p><strong>2.4.1.6.</strong></p></td><td·align="left"·valign="top"><p>試著執行·<code·class="filename">test</code>·執行檔, |
278 | » ······但是卻沒有任何事發生,到底是哪裡出錯了?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>大多數的·<span·class="trademark">UNIX</span>®·系統都會在路徑·<code·class="filename">/usr/bin</code>·擺放執行檔。 | 278 | » ······但是卻沒有任何事發生,到底是哪裡出錯了?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>大多數的·<span·class="trademark">UNIX</span>®·系統都會在路徑·<code·class="filename">/usr/bin</code>·擺放執行檔。 |
279 | » ······除非有指定使用在目前目錄內的·<code·class="filename">test</code>,否則·shell·會優先選擇位在 | 279 | » ······除非有指定使用在目前目錄內的·<code·class="filename">test</code>,否則·shell·會優先選擇位在 |
280 | » ······<code·class="filename">/usr/bin</code>·的·<code·class="filename">test</code>, | 280 | » ······<code·class="filename">/usr/bin</code>·的·<code·class="filename">test</code>, |
281 | » ······要指定檔名的話,作法類似:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./test</code></strong> | 281 | » ······要指定檔名的話,作法類似:</p><div·class="informalexample"><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>./test</code></strong> |
282 | » ······</pre></div><p>為了避免上述困擾,請為你的程式取更好的名稱吧!</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59983160"></a><a·id="idp59983800"></a><p><strong>2.4.1.7.</strong></p></td><td·align="left"·valign="top"><p>當執行我寫的程式時剛開始正常, | 282 | » ······</pre></div><p>為了避免上述困擾,請為你的程式取更好的名稱吧!</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60037304"></a><a·id="idp60051000"></a><p><strong>2.4.1.7.</strong></p></td><td·align="left"·valign="top"><p>當執行我寫的程式時剛開始正常, |
283 | » ······接下來卻出現·<span·class="errorname">core·dumped</span>·錯誤訊息。這錯誤訊息到底代表什麼?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>關於·<em·class="firstterm">core·dumped</em>·這個名稱的由來, | 283 | » ······接下來卻出現·<span·class="errorname">core·dumped</span>·錯誤訊息。這錯誤訊息到底代表什麼?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>關於·<em·class="firstterm">core·dumped</em>·這個名稱的由來, |
284 | » ······可以追溯到早期的·<span·class="trademark">UNIX</span>®·系統開始使用·core·memory·對資料排序時。 | 284 | » ······可以追溯到早期的·<span·class="trademark">UNIX</span>®·系統開始使用·core·memory·對資料排序時。 |
285 | » ······基本上當程式在很多情況下發生錯誤後, | 285 | » ······基本上當程式在很多情況下發生錯誤後, |
286 | » ······作業系統會把·core·memory·中的資訊寫入·<code·class="filename">core</code>·這檔案中, | 286 | » ······作業系統會把·core·memory·中的資訊寫入·<code·class="filename">core</code>·這檔案中, |
287 | » ······以便讓·programmer·知道程式到底是為何出錯。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp59992760"></a><a·id="idp59993784"></a><p><strong>2.4.1.8.</strong></p></td><td·align="left"·valign="top"><p>真是太神奇了!程式居然發生·<span·class="errorname">core·dumped</span>·了,該怎麼辦?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>請用·<code·class="command">gdb</code>·來分析·core·結果(詳情請參考·<a·class="xref"·href="#debugging"·title="2.6.·Debugging">節 2.6,·“Debugging”</a>)。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60004152"></a><a·id="idp60005048"></a><p><strong>2.4.1.9.</strong></p></td><td·align="left"·valign="top"><p>當程式已經把·core·memory·資料·dump·出來後, | 287 | » ······以便讓·programmer·知道程式到底是為何出錯。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60060088"></a><a·id="idp60060728"></a><p><strong>2.4.1.8.</strong></p></td><td·align="left"·valign="top"><p>真是太神奇了!程式居然發生·<span·class="errorname">core·dumped</span>·了,該怎麼辦?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>請用·<code·class="command">gdb</code>·來分析·core·結果(詳情請參考·<a·class="xref"·href="#debugging"·title="2.6.·Debugging">節 2.6,·“Debugging”</a>)。</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60071096"></a><a·id="idp60072120"></a><p><strong>2.4.1.9.</strong></p></td><td·align="left"·valign="top"><p>當程式已經把·core·memory·資料·dump·出來後, |
288 | » ······同時也出現另一個錯誤·<span·class="errorname">segmentation·fault</span>·這意思是?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>基本上,這個錯誤表示你的程式在記憶體中試著做一個嚴重的非法運作(illegal·operation), | 288 | » ······同時也出現另一個錯誤·<span·class="errorname">segmentation·fault</span>·這意思是?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>基本上,這個錯誤表示你的程式在記憶體中試著做一個嚴重的非法運作(illegal·operation), |
289 | » ······<span·class="trademark">UNIX</span>®·就是被設計來保護整個作業系統免於被惡質的程式破壞,所以才會告訴你這個訊息。</p><p>最常造成<span·class="quote">“<span·class="quote">segmentation·fault</span>”</span>的原因通常為:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>試著對一個·<span·class="symbol">NULL</span>·的指標(pointer)作寫入的動作,如</p><pre·class="programlisting">char·*foo·=·NULL; | 289 | » ······<span·class="trademark">UNIX</span>®·就是被設計來保護整個作業系統免於被惡質的程式破壞,所以才會告訴你這個訊息。</p><p>最常造成<span·class="quote">“<span·class="quote">segmentation·fault</span>”</span>的原因通常為:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>試著對一個·<span·class="symbol">NULL</span>·的指標(pointer)作寫入的動作,如</p><pre·class="programlisting">char·*foo·=·NULL; |
290 | strcpy(foo,·"bang!"); | 290 | strcpy(foo,·"bang!"); |
291 | » » </pre></li><li·class="listitem"><p>使用一個尚未初始化(initialized)的指標,如:</p><pre·class="programlisting">char·*foo; | 291 | » » </pre></li><li·class="listitem"><p>使用一個尚未初始化(initialized)的指標,如:</p><pre·class="programlisting">char·*foo; |
292 | strcpy(foo,·"bang!"); | 292 | strcpy(foo,·"bang!"); |
293 | » » </pre><p>尚未初始化的指標的初始值將會是隨機的,如果你夠幸運的話, | 293 | » » </pre><p>尚未初始化的指標的初始值將會是隨機的,如果你夠幸運的話, |
294 | » » ··這個指標的初始值會指向·kernel·已經用到的記憶體位置, | 294 | » » ··這個指標的初始值會指向·kernel·已經用到的記憶體位置, |
Offset 310, 22 lines modified | Offset 310, 22 lines modified |
310 | » » </pre><p>or</p><pre·class="programlisting">char·*foo·=·malloc(27); | 310 | » » </pre><p>or</p><pre·class="programlisting">char·*foo·=·malloc(27); |
311 | free(foo); | 311 | free(foo); |
312 | free(foo); | 312 | free(foo); |
313 | » » </pre></li></ul></div><p>Making·one·of·these·mistakes·will·not·always·lead·to | 313 | » » </pre></li></ul></div><p>Making·one·of·these·mistakes·will·not·always·lead·to |
314 | » ······an·error,·but·they·are·always·bad·practice.··Some | 314 | » ······an·error,·but·they·are·always·bad·practice.··Some |
315 | » ······systems·and·compilers·are·more·tolerant·than·others, | 315 | » ······systems·and·compilers·are·more·tolerant·than·others, |
316 | » ······which·is·why·programs·that·ran·well·on·one·system·can | 316 | » ······which·is·why·programs·that·ran·well·on·one·system·can |
317 | » ······crash·when·you·try·them·on·an·another.</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60051640"></a><a·id="idp60053048"></a><p><strong>2.4.1.10.</strong></p></td><td·align="left"·valign="top"><p>Sometimes·when·I·get·a·core·dump·it·says | 317 | » ······crash·when·you·try·them·on·an·another.</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60119224"></a><a·id="idp60119480"></a><p><strong>2.4.1.10.</strong></p></td><td·align="left"·valign="top"><p>Sometimes·when·I·get·a·core·dump·it·says |
318 | » ······<span·class="errorname">bus·error</span>.··It·says·in·my·<span·class="trademark">UNIX</span>® | 318 | » ······<span·class="errorname">bus·error</span>.··It·says·in·my·<span·class="trademark">UNIX</span>® |
319 | » ······book·that·this·means·a·hardware·problem,·but·the | 319 | » ······book·that·this·means·a·hardware·problem,·but·the |
320 | » ······computer·still·seems·to·be·working.··Is·this | 320 | » ······computer·still·seems·to·be·working.··Is·this |
321 | » ······true?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>No,·fortunately·not·(unless·of·course·you·really·do | 321 | » ······true?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>No,·fortunately·not·(unless·of·course·you·really·do |
322 | » ······have·a·hardware·problem…).··This·is·usually | 322 | » ······have·a·hardware·problem…).··This·is·usually |
323 | » ······another·way·of·saying·that·you·accessed·memory·in·a·way | 323 | » ······another·way·of·saying·that·you·accessed·memory·in·a·way |
324 | » ······you·should·not·have.</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60072248"></a><a·id="idp60072760"></a><p><strong>2.4.1.11.</strong></p></td><td·align="left"·valign="top"><p>This·dumping·core·business·sounds·as·though·it·could | 324 | » ······you·should·not·have.</p></td></tr><tr·class="question"><td·align="left"·valign="top"><a·id="idp60127288"></a><a·id="idp60128184"></a><p><strong>2.4.1.11.</strong></p></td><td·align="left"·valign="top"><p>This·dumping·core·business·sounds·as·though·it·could |
325 | » ······be·quite·useful,·if·I·can·make·it·happen·when·I·want·to. | 325 | » ······be·quite·useful,·if·I·can·make·it·happen·when·I·want·to. |
326 | » ······Can·I·do·this,·or·do·I·have·to·wait·until·there·is·an | 326 | » ······Can·I·do·this,·or·do·I·have·to·wait·until·there·is·an |
327 | » ······error?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>Yes,·just·go·to·another·console·or·xterm,·do</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>ps</code></strong> | 327 | » ······error?</p></td></tr><tr·class="answer"><td·align="left"·valign="top"></td><td·align="left"·valign="top"><p>Yes,·just·go·to·another·console·or·xterm,·do</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>ps</code></strong> |
328 | » ····</pre><p>to·find·out·the·process·ID·of·your·program,·and | 328 | » ····</pre><p>to·find·out·the·process·ID·of·your·program,·and |
329 | » ······do</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>kill·-ABRT·pid</code></strong> | 329 | » ······do</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>kill·-ABRT·pid</code></strong> |
330 | » ····</pre><p>where | 330 | » ····</pre><p>where |
331 | » ······<em·class="parameter"><code><em·class="replaceable"><code>pid</code></em></code></em>·is | 331 | » ······<em·class="parameter"><code><em·class="replaceable"><code>pid</code></em></code></em>·is |
Offset 334, 15 lines modified | Offset 334, 15 lines modified |
334 | » ······trap·<span·class="symbol">SIGABRT</span>,·there·are·several·other | 334 | » ······trap·<span·class="symbol">SIGABRT</span>,·there·are·several·other |
335 | » ······signals·which·have·a·similar·effect.</p><p>Alternatively,·you·can·create·a·core·dump·from | 335 | » ······signals·which·have·a·similar·effect.</p><p>Alternatively,·you·can·create·a·core·dump·from |
336 | » ······inside·your·program,·by·calling·the | 336 | » ······inside·your·program,·by·calling·the |
337 | » ······<code·class="function">abort()</code>·function.·See·the·manual·page | 337 | » ······<code·class="function">abort()</code>·function.·See·the·manual·page |
338 | » ······of·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=abort&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">abort</span>(3)</span></a>·to·learn·more.</p><p>If·you·want·to·create·a·core·dump·from·outside·your | 338 | » ······of·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=abort&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">abort</span>(3)</span></a>·to·learn·more.</p><p>If·you·want·to·create·a·core·dump·from·outside·your |
339 | ··············program,·but·do·not·want·the·process·to·terminate,·you | 339 | ··············program,·but·do·not·want·the·process·to·terminate,·you |
340 | ··············can·use·the·<code·class="command">gcore</code>·program.·See·the | 340 | ··············can·use·the·<code·class="command">gcore</code>·program.·See·the |
341 | ··············manual·page·of·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=gcore&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">gcore</span>(1)</span></a>·for·more·information.</p></td></tr></tbody></table></div></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-make"></a>2.5.·Make</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60117944"></a>2.5.1.·What·is·<code·class="command">make</code>?</h3></div></div></div><p>When·you·are·working·on·a·simple·program·with·only·one·or | 341 | ··············manual·page·of·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=gcore&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">gcore</span>(1)</span></a>·for·more·information.</p></td></tr></tbody></table></div></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="tools-make"></a>2.5.·Make</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60177592"></a>2.5.1.·What·is·<code·class="command">make</code>?</h3></div></div></div><p>When·you·are·working·on·a·simple·program·with·only·one·or |
342 | » two·source·files,·typing·in</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·file1.c·file2.c</code></strong></pre><p>is·not·too·bad,·but·it·quickly·becomes·very·tedious·when | 342 | » two·source·files,·typing·in</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·file1.c·file2.c</code></strong></pre><p>is·not·too·bad,·but·it·quickly·becomes·very·tedious·when |
343 | » there·are·several·files——and·it·can·take·a·while·to | 343 | » there·are·several·files——and·it·can·take·a·while·to |
344 | » compile,·too.</p><p>One·way·to·get·around·this·is·to·use·object·files·and·only | 344 | » compile,·too.</p><p>One·way·to·get·around·this·is·to·use·object·files·and·only |
345 | » recompile·the·source·file·if·the·source·code·has·changed.··So | 345 | » recompile·the·source·file·if·the·source·code·has·changed.··So |
346 | » we·could·have·something·like:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·file1.o·file2.o</code></strong>·…·<strong·class="userinput"><code>file37.c</code></strong>·…</pre><p>if·we·had·changed·<code·class="filename">file37.c</code>,·but·not·any | 346 | » we·could·have·something·like:</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>cc·file1.o·file2.o</code></strong>·…·<strong·class="userinput"><code>file37.c</code></strong>·…</pre><p>if·we·had·changed·<code·class="filename">file37.c</code>,·but·not·any |
347 | » of·the·others,·since·the·last·time·we·compiled.··This·may | 347 | » of·the·others,·since·the·last·time·we·compiled.··This·may |
348 | » speed·up·the·compilation·quite·a·bit,·but·does·not·solve·the | 348 | » speed·up·the·compilation·quite·a·bit,·but·does·not·solve·the |
Offset 369, 15 lines modified | Offset 369, 15 lines modified |
369 | » source·they·apply·to,·and·can·be·called | 369 | » source·they·apply·to,·and·can·be·called |
370 | » <code·class="filename">makefile</code>,·<code·class="filename">Makefile</code> | 370 | » <code·class="filename">makefile</code>,·<code·class="filename">Makefile</code> |
371 | » or·<code·class="filename">MAKEFILE</code>.··Most·programmers·use·the | 371 | » or·<code·class="filename">MAKEFILE</code>.··Most·programmers·use·the |
372 | » name·<code·class="filename">Makefile</code>,·as·this·puts·it·near·the | 372 | » name·<code·class="filename">Makefile</code>,·as·this·puts·it·near·the |
373 | » top·of·a·directory·listing,·where·it·can·easily·be | 373 | » top·of·a·directory·listing,·where·it·can·easily·be |
374 | » seen. | 374 | » seen. |
| |
375 | » <a·href="#ftn.idp60160696"·class="footnote"·id="idp60160696"><sup·class="footnote">[6]</sup></a></p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60170680"></a>2.5.2.·Example·of·using·<code·class="command">make</code></h3></div></div></div><p>Here·is·a·very·simple·make·file:</p><pre·class="programlisting">foo:·foo.c | 375 | » <a·href="#ftn.idp60223672"·class="footnote"·id="idp60223672"><sup·class="footnote">[6]</sup></a></p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60228536"></a>2.5.2.·Example·of·using·<code·class="command">make</code></h3></div></div></div><p>Here·is·a·very·simple·make·file:</p><pre·class="programlisting">foo:·foo.c |
376 | » cc·-o·foo·foo.c</pre><p>It·consists·of·two·lines,·a·dependency·line·and·a·creation | 376 | » cc·-o·foo·foo.c</pre><p>It·consists·of·two·lines,·a·dependency·line·and·a·creation |
377 | » line.</p><p>The·dependency·line·here·consists·of·the·name·of·the | 377 | » line.</p><p>The·dependency·line·here·consists·of·the·name·of·the |
378 | » program·(known·as·the·<em·class="firstterm">target</em>),·followed | 378 | » program·(known·as·the·<em·class="firstterm">target</em>),·followed |
379 | » by·a·colon,·then·whitespace,·then·the·name·of·the·source·file. | 379 | » by·a·colon,·then·whitespace,·then·the·name·of·the·source·file. |
380 | » When·<code·class="command">make</code>·reads·this·line,·it·looks·to·see | 380 | » When·<code·class="command">make</code>·reads·this·line,·it·looks·to·see |
381 | » if·<code·class="filename">foo</code>·exists;·if·it·exists,·it·compares | 381 | » if·<code·class="filename">foo</code>·exists;·if·it·exists,·it·compares |
382 | » the·time·<code·class="filename">foo</code>·was·last·modified·to·the | 382 | » the·time·<code·class="filename">foo</code>·was·last·modified·to·the |
Offset 427, 15 lines modified | Offset 427, 15 lines modified |
427 | » If·you·do·not·quite·understand·how·<code·class="command">make</code> | 427 | » If·you·do·not·quite·understand·how·<code·class="command">make</code> |
428 | » works,·the·best·thing·to·do·is·to·write·a·simple·program·like | 428 | » works,·the·best·thing·to·do·is·to·write·a·simple·program·like |
429 | » <span·class="quote">“<span·class="quote">hello·world</span>”</span>·and·a·make·file·like·the·one·above | 429 | » <span·class="quote">“<span·class="quote">hello·world</span>”</span>·and·a·make·file·like·the·one·above |
430 | » and·experiment.··Then·progress·to·using·more·than·one·source | 430 | » and·experiment.··Then·progress·to·using·more·than·one·source |
431 | » file,·or·having·the·source·file·include·a·header·file.··The | 431 | » file,·or·having·the·source·file·include·a·header·file.··The |
432 | » <code·class="command">touch</code>·command·is·very·useful·here——it | 432 | » <code·class="command">touch</code>·command·is·very·useful·here——it |
433 | » changes·the·date·on·a·file·without·you·having·to·edit | 433 | » changes·the·date·on·a·file·without·you·having·to·edit |
434 | » it.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60244792"></a>2.5.3.·Make·and·include-files</h3></div></div></div><p>C·code·often·starts·with·a·list·of·files·to·include,·for | 434 | » it.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60295352"></a>2.5.3.·Make·and·include-files</h3></div></div></div><p>C·code·often·starts·with·a·list·of·files·to·include,·for |
435 | » example·stdio.h.·Some·of·these·files·are·system-include | 435 | » example·stdio.h.·Some·of·these·files·are·system-include |
436 | » files,·some·of·them·are·from·the·project·you·are·now·working | 436 | » files,·some·of·them·are·from·the·project·you·are·now·working |
437 | » on: | 437 | » on: |
438 | ······</p><pre·class="programlisting">#include·<stdio.h> | 438 | ······</p><pre·class="programlisting">#include·<stdio.h> |
439 | #include·"foo.h" | 439 | #include·"foo.h" |
| |
440 | int·main(....</pre><p>To·make·sure·that·this·file·is·recompiled·the·moment | 440 | int·main(....</pre><p>To·make·sure·that·this·file·is·recompiled·the·moment |
Offset 450, 15 lines modified | Offset 450, 15 lines modified |
450 | » of·include-files·and·their·dependencies:·<code·class="option">-MM</code>. | 450 | » of·include-files·and·their·dependencies:·<code·class="option">-MM</code>. |
451 | ······</p><p>If·you·add·this·to·your·Makefile:</p><pre·class="programlisting">depend: | 451 | ······</p><p>If·you·add·this·to·your·Makefile:</p><pre·class="programlisting">depend: |
452 | » gcc·-E·-MM·*.c·>·.depend</pre><p>and·run·<strong·class="userinput"><code>make·depend</code></strong>,·the·file | 452 | » gcc·-E·-MM·*.c·>·.depend</pre><p>and·run·<strong·class="userinput"><code>make·depend</code></strong>,·the·file |
453 | » <code·class="filename">.depend</code>·will·appear·with·a·list·of | 453 | » <code·class="filename">.depend</code>·will·appear·with·a·list·of |
454 | » object-files,·C-files·and·the·include-files:</p><pre·class="programlisting">foo.o:·foo.c·foo.h</pre><p>If·you·change·<code·class="filename">foo.h</code>,·next·time | 454 | » object-files,·C-files·and·the·include-files:</p><pre·class="programlisting">foo.o:·foo.c·foo.h</pre><p>If·you·change·<code·class="filename">foo.h</code>,·next·time |
455 | » you·run·<code·class="command">make</code>·all·files·depending·on | 455 | » you·run·<code·class="command">make</code>·all·files·depending·on |
456 | » <code·class="filename">foo.h</code>·will·be·recompiled.</p><p>Do·not·forget·to·run·<code·class="command">make·depend</code>·each | 456 | » <code·class="filename">foo.h</code>·will·be·recompiled.</p><p>Do·not·forget·to·run·<code·class="command">make·depend</code>·each |
457 | ········time·you·add·an·include-file·to·one·of·your·files.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60269624"></a>2.5.4.·FreeBSD·Makefiles</h3></div></div></div><p>Makefiles·can·be·rather·complicated·to·write.··Fortunately, | 457 | ········time·you·add·an·include-file·to·one·of·your·files.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60321336"></a>2.5.4.·FreeBSD·Makefiles</h3></div></div></div><p>Makefiles·can·be·rather·complicated·to·write.··Fortunately, |
458 | » BSD-based·systems·like·FreeBSD·come·with·some·very·powerful | 458 | » BSD-based·systems·like·FreeBSD·come·with·some·very·powerful |
459 | » ones·as·part·of·the·system.··One·very·good·example·of·this·is | 459 | » ones·as·part·of·the·system.··One·very·good·example·of·this·is |
460 | » the·FreeBSD·ports·system.··Here·is·the·essential·part·of·a | 460 | » the·FreeBSD·ports·system.··Here·is·the·essential·part·of·a |
461 | » typical·ports·<code·class="filename">Makefile</code>:</p><pre·class="programlisting">MASTER_SITES=···ftp://freefall.cdrom.com/pub/FreeBSD/LOCAL_PORTS/ | 461 | » typical·ports·<code·class="filename">Makefile</code>:</p><pre·class="programlisting">MASTER_SITES=···ftp://freefall.cdrom.com/pub/FreeBSD/LOCAL_PORTS/ |
462 | DISTFILES=······scheme-microcode+dist-7.3-freebsd.tgz | 462 | DISTFILES=······scheme-microcode+dist-7.3-freebsd.tgz |
| |
463 | .include·<bsd.port.mk></pre><p>Now,·if·we·go·to·the·directory·for·this·port·and·type | 463 | .include·<bsd.port.mk></pre><p>Now,·if·we·go·to·the·directory·for·this·port·and·type |
Offset 496, 15 lines modified | Offset 496, 15 lines modified |
496 | » couple·of·other·things·I·did·not·mention,·including·handling | 496 | » couple·of·other·things·I·did·not·mention,·including·handling |
497 | » any·errors·that·may·occur)·and·anyone·can·get·access·to·that | 497 | » any·errors·that·may·occur)·and·anyone·can·get·access·to·that |
498 | » just·by·putting·a·single·line·in·their·own·make·file!</p><p>If·you·want·to·have·a·look·at·these·system·makefiles, | 498 | » just·by·putting·a·single·line·in·their·own·make·file!</p><p>If·you·want·to·have·a·look·at·these·system·makefiles, |
499 | » they·are·in·<code·class="filename">/usr/share/mk</code>,·but·it·is | 499 | » they·are·in·<code·class="filename">/usr/share/mk</code>,·but·it·is |
500 | » probably·best·to·wait·until·you·have·had·a·bit·of·practice·with | 500 | » probably·best·to·wait·until·you·have·had·a·bit·of·practice·with |
501 | » makefiles,·as·they·are·very·complicated·(and·if·you·do·look·at | 501 | » makefiles,·as·they·are·very·complicated·(and·if·you·do·look·at |
502 | » them,·make·sure·you·have·a·flask·of·strong·coffee | 502 | » them,·make·sure·you·have·a·flask·of·strong·coffee |
503 | » handy!)</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60336952"></a>2.5.5.·More·advanced·uses·of·<code·class="command">make</code></h3></div></div></div><p><code·class="command">Make</code>·is·a·very·powerful·tool,·and·can | 503 | » handy!)</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60391992"></a>2.5.5.·More·advanced·uses·of·<code·class="command">make</code></h3></div></div></div><p><code·class="command">Make</code>·is·a·very·powerful·tool,·and·can |
504 | » do·much·more·than·the·simple·example·above·shows. | 504 | » do·much·more·than·the·simple·example·above·shows. |
505 | » Unfortunately,·there·are·several·different·versions·of | 505 | » Unfortunately,·there·are·several·different·versions·of |
506 | » <code·class="command">make</code>,·and·they·all·differ·considerably. | 506 | » <code·class="command">make</code>,·and·they·all·differ·considerably. |
507 | » The·best·way·to·learn·what·they·can·do·is·probably·to·read·the | 507 | » The·best·way·to·learn·what·they·can·do·is·probably·to·read·the |
508 | » documentation——hopefully·this·introduction·will·have | 508 | » documentation——hopefully·this·introduction·will·have |
509 | » given·you·a·base·from·which·you·can·do·this.</p><p>The·version·of·make·that·comes·with·FreeBSD·is·the | 509 | » given·you·a·base·from·which·you·can·do·this.</p><p>The·version·of·make·that·comes·with·FreeBSD·is·the |
510 | » <span·class="application">Berkeley·make</span>;·there·is·a·tutorial | 510 | » <span·class="application">Berkeley·make</span>;·there·is·a·tutorial |
Offset 518, 15 lines modified | Offset 518, 15 lines modified |
518 | » make</span>,·you·will·have·to·edit·the | 518 | » make</span>,·you·will·have·to·edit·the |
519 | » <code·class="filename">dir</code>·file·in·the | 519 | » <code·class="filename">dir</code>·file·in·the |
520 | » <code·class="filename">/usr/local/info</code>·directory·to·add·an·entry | 520 | » <code·class="filename">/usr/local/info</code>·directory·to·add·an·entry |
521 | » for·it.··This·involves·adding·a·line·like</p><pre·class="programlisting">·*·Make:·(make).·················The·GNU·Make·utility.</pre><p>to·the·file.··Once·you·have·done·this,·you·can·type | 521 | » for·it.··This·involves·adding·a·line·like</p><pre·class="programlisting">·*·Make:·(make).·················The·GNU·Make·utility.</pre><p>to·the·file.··Once·you·have·done·this,·you·can·type |
522 | » <strong·class="userinput"><code>info</code></strong>·and·then·select | 522 | » <strong·class="userinput"><code>info</code></strong>·and·then·select |
523 | » <span·class="guimenuitem">make</span>·from·the·menu·(or·in | 523 | » <span·class="guimenuitem">make</span>·from·the·menu·(or·in |
524 | » <span·class="application">Emacs</span>,·do·<strong·class="userinput"><code>C-h | 524 | » <span·class="application">Emacs</span>,·do·<strong·class="userinput"><code>C-h |
525 | » ··i</code></strong>).</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="debugging"></a>2.6.·Debugging</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60365240"></a>2.6.1.·The·Debugger</h3></div></div></div><p>The·debugger·that·comes·with·FreeBSD·is·called | 525 | » ··i</code></strong>).</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="debugging"></a>2.6.·Debugging</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60477112"></a>2.6.1.·The·Debugger</h3></div></div></div><p>The·debugger·that·comes·with·FreeBSD·is·called |
526 | » <code·class="command">gdb</code>·(<span·class="application">GNU | 526 | » <code·class="command">gdb</code>·(<span·class="application">GNU |
527 | » ··debugger</span>).··You·start·it·up·by·typing</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>gdb·progname</code></strong></pre><p>although·most·people·prefer·to·run·it·inside | 527 | » ··debugger</span>).··You·start·it·up·by·typing</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>gdb·progname</code></strong></pre><p>although·most·people·prefer·to·run·it·inside |
528 | » <span·class="application">Emacs</span>.··You·can·do·this·by:</p><pre·class="screen"><strong·class="userinput"><code>M-x·gdb·RET·progname·RET</code></strong></pre><p>Using·a·debugger·allows·you·to·run·the·program·under·more | 528 | » <span·class="application">Emacs</span>.··You·can·do·this·by:</p><pre·class="screen"><strong·class="userinput"><code>M-x·gdb·RET·progname·RET</code></strong></pre><p>Using·a·debugger·allows·you·to·run·the·program·under·more |
529 | » controlled·circumstances.··Typically,·you·can·step·through·the | 529 | » controlled·circumstances.··Typically,·you·can·step·through·the |
530 | » program·a·line·at·a·time,·inspect·the·value·of·variables, | 530 | » program·a·line·at·a·time,·inspect·the·value·of·variables, |
531 | » change·them,·tell·the·debugger·to·run·up·to·a·certain·point | 531 | » change·them,·tell·the·debugger·to·run·up·to·a·certain·point |
532 | » and·then·stop,·and·so·on.··You·can·even·attach·to·a·program | 532 | » and·then·stop,·and·so·on.··You·can·even·attach·to·a·program |
Offset 535, 15 lines modified | Offset 535, 15 lines modified |
535 | » though·that·is·a·little·trickier·than·the·user·applications | 535 | » though·that·is·a·little·trickier·than·the·user·applications |
536 | » we·will·be·discussing·in·this·section.</p><p><code·class="command">gdb</code>·has·quite·good·on-line·help,·as | 536 | » we·will·be·discussing·in·this·section.</p><p><code·class="command">gdb</code>·has·quite·good·on-line·help,·as |
537 | » well·as·a·set·of·info·pages,·so·this·section·will·concentrate | 537 | » well·as·a·set·of·info·pages,·so·this·section·will·concentrate |
538 | » on·a·few·of·the·basic·commands.</p><p>Finally,·if·you·find·its·text-based·command-prompt·style | 538 | » on·a·few·of·the·basic·commands.</p><p>Finally,·if·you·find·its·text-based·command-prompt·style |
539 | » off-putting,·there·is·a·graphical·front-end·for·it·(<a·class="link"·href="../../../../ports/devel.html"·target="_top">xxgdb</a>)·in·the·ports | 539 | » off-putting,·there·is·a·graphical·front-end·for·it·(<a·class="link"·href="../../../../ports/devel.html"·target="_top">xxgdb</a>)·in·the·ports |
540 | » collection.</p><p>This·section·is·intended·to·be·an·introduction·to·using | 540 | » collection.</p><p>This·section·is·intended·to·be·an·introduction·to·using |
541 | » <code·class="command">gdb</code>·and·does·not·cover·specialized·topics | 541 | » <code·class="command">gdb</code>·and·does·not·cover·specialized·topics |
542 | » such·as·debugging·the·kernel.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60399672"></a>2.6.2.·Running·a·program·in·the·debugger</h3></div></div></div><p>You·will·need·to·have·compiled·the·program·with·the | 542 | » such·as·debugging·the·kernel.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60508728"></a>2.6.2.·Running·a·program·in·the·debugger</h3></div></div></div><p>You·will·need·to·have·compiled·the·program·with·the |
543 | » <code·class="option">-g</code>·option·to·get·the·most·out·of·using | 543 | » <code·class="option">-g</code>·option·to·get·the·most·out·of·using |
544 | » <code·class="command">gdb</code>.··It·will·work·without,·but·you·will·only | 544 | » <code·class="command">gdb</code>.··It·will·work·without,·but·you·will·only |
545 | » see·the·name·of·the·function·you·are·in,·instead·of·the·source | 545 | » see·the·name·of·the·function·you·are·in,·instead·of·the·source |
546 | » code.··If·you·see·a·line·like:</p><pre·class="screen">…·(no·debugging·symbols·found)·…</pre><p>when·<code·class="command">gdb</code>·starts·up,·you·will·know·that | 546 | » code.··If·you·see·a·line·like:</p><pre·class="screen">…·(no·debugging·symbols·found)·…</pre><p>when·<code·class="command">gdb</code>·starts·up,·you·will·know·that |
547 | » the·program·was·not·compiled·with·the·<code·class="option">-g</code> | 547 | » the·program·was·not·compiled·with·the·<code·class="option">-g</code> |
548 | » option.</p><p>At·the·<code·class="command">gdb</code>·prompt,·type | 548 | » option.</p><p>At·the·<code·class="command">gdb</code>·prompt,·type |
549 | » <strong·class="userinput"><code>break·main</code></strong>.··This·will·tell·the | 549 | » <strong·class="userinput"><code>break·main</code></strong>.··This·will·tell·the |
Offset 619, 15 lines modified | Offset 619, 15 lines modified |
619 | » ··time·we·go·into·or·out·of·a·function,·even·if·we·are·using | 619 | » ··time·we·go·into·or·out·of·a·function,·even·if·we·are·using |
620 | » ··<code·class="command">up</code>·and·<code·class="command">down</code>·to·move | 620 | » ··<code·class="command">up</code>·and·<code·class="command">down</code>·to·move |
621 | » ··around·the·call·stack.··This·shows·the·name·of·the·function | 621 | » ··around·the·call·stack.··This·shows·the·name·of·the·function |
622 | » ··and·the·values·of·its·arguments,·which·helps·us·keep·track | 622 | » ··and·the·values·of·its·arguments,·which·helps·us·keep·track |
623 | » ··of·where·we·are·and·what·is·going·on.··(The·stack·is·a | 623 | » ··of·where·we·are·and·what·is·going·on.··(The·stack·is·a |
624 | » ··storage·area·where·the·program·stores·information·about·the | 624 | » ··storage·area·where·the·program·stores·information·about·the |
625 | » ··arguments·passed·to·functions·and·where·to·go·when·it | 625 | » ··arguments·passed·to·functions·and·where·to·go·when·it |
626 | » ··returns·from·a·function·call).</p></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60554424"></a>2.6.3.·Examining·a·core·file</h3></div></div></div><p>A·core·file·is·basically·a·file·which·contains·the | 626 | » ··returns·from·a·function·call).</p></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60609336"></a>2.6.3.·Examining·a·core·file</h3></div></div></div><p>A·core·file·is·basically·a·file·which·contains·the |
627 | » complete·state·of·the·process·when·it·crashed.··In·<span·class="quote">“<span·class="quote">the | 627 | » complete·state·of·the·process·when·it·crashed.··In·<span·class="quote">“<span·class="quote">the |
628 | » ··good·old·days</span>”</span>,·programmers·had·to·print·out·hex | 628 | » ··good·old·days</span>”</span>,·programmers·had·to·print·out·hex |
629 | » listings·of·core·files·and·sweat·over·machine·code·manuals, | 629 | » listings·of·core·files·and·sweat·over·machine·code·manuals, |
630 | » but·now·life·is·a·bit·easier.··Incidentally,·under·FreeBSD·and | 630 | » but·now·life·is·a·bit·easier.··Incidentally,·under·FreeBSD·and |
631 | » other·4.4BSD·systems,·a·core·file·is·called | 631 | » other·4.4BSD·systems,·a·core·file·is·called |
632 | » <code·class="filename">progname.core</code>·instead·of·just | 632 | » <code·class="filename">progname.core</code>·instead·of·just |
633 | » <code·class="filename">core</code>,·to·make·it·clearer·which·program·a | 633 | » <code·class="filename">core</code>,·to·make·it·clearer·which·program·a |
Offset 656, 15 lines modified | Offset 656, 15 lines modified |
656 | » command·causes·<code·class="command">gdb</code>·to·print·out·a | 656 | » command·causes·<code·class="command">gdb</code>·to·print·out·a |
657 | » back-trace·of·the·call·stack:</p><pre·class="screen">(gdb)·<strong·class="userinput"><code>bt</code></strong> | 657 | » back-trace·of·the·call·stack:</p><pre·class="screen">(gdb)·<strong·class="userinput"><code>bt</code></strong> |
658 | #0··0x164a·in·bazz·(anint=0x5)·at·temp.c:17 | 658 | #0··0x164a·in·bazz·(anint=0x5)·at·temp.c:17 |
659 | #1··0xefbfd888·in·end·() | 659 | #1··0xefbfd888·in·end·() |
660 | #2··0x162c·in·main·()·at·temp.c:11 | 660 | #2··0x162c·in·main·()·at·temp.c:11 |
661 | (gdb)</pre><p>The·<code·class="function">end()</code>·function·is·called·when·a | 661 | (gdb)</pre><p>The·<code·class="function">end()</code>·function·is·called·when·a |
662 | » program·crashes;·in·this·case,·the·<code·class="function">bazz()</code> | 662 | » program·crashes;·in·this·case,·the·<code·class="function">bazz()</code> |
663 | » function·was·called·from·<code·class="function">main()</code>.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60598584"></a>2.6.4.·Attaching·to·a·running·program</h3></div></div></div><p>One·of·the·neatest·features·about·<code·class="command">gdb</code> | 663 | » function·was·called·from·<code·class="function">main()</code>.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60665912"></a>2.6.4.·Attaching·to·a·running·program</h3></div></div></div><p>One·of·the·neatest·features·about·<code·class="command">gdb</code> |
664 | » is·that·it·can·attach·to·a·program·that·is·already·running.··Of | 664 | » is·that·it·can·attach·to·a·program·that·is·already·running.··Of |
665 | » course,·that·assumes·you·have·sufficient·permissions·to·do·so. | 665 | » course,·that·assumes·you·have·sufficient·permissions·to·do·so. |
666 | » A·common·problem·is·when·you·are·stepping·through·a·program | 666 | » A·common·problem·is·when·you·are·stepping·through·a·program |
667 | » that·forks,·and·you·want·to·trace·the·child,·but·the·debugger | 667 | » that·forks,·and·you·want·to·trace·the·child,·but·the·debugger |
668 | » will·only·let·you·trace·the·parent.</p><p>What·you·do·is·start·up·another·<code·class="command">gdb</code>, | 668 | » will·only·let·you·trace·the·parent.</p><p>What·you·do·is·start·up·another·<code·class="command">gdb</code>, |
669 | » use·<code·class="command">ps</code>·to·find·the·process·ID·for·the | 669 | » use·<code·class="command">ps</code>·to·find·the·process·ID·for·the |
670 | » child,·and·do</p><pre·class="screen">(gdb)·<strong·class="userinput"><code>attach·pid</code></strong></pre><p>in·<code·class="command">gdb</code>,·and·then·debug·as·usual.</p><p><span·class="quote">“<span·class="quote">That·is·all·very·well,</span>”</span>·you·are·probably | 670 | » child,·and·do</p><pre·class="screen">(gdb)·<strong·class="userinput"><code>attach·pid</code></strong></pre><p>in·<code·class="command">gdb</code>,·and·then·debug·as·usual.</p><p><span·class="quote">“<span·class="quote">That·is·all·very·well,</span>”</span>·you·are·probably |
Offset 679, 20 lines modified | Offset 679, 20 lines modified |
| |
679 | » while·(PauseMode) | 679 | » while·(PauseMode) |
680 | » » sleep(10);» /*·Wait·until·someone·attaches·to·us·*/ | 680 | » » sleep(10);» /*·Wait·until·someone·attaches·to·us·*/ |
681 | » <em·class="lineannotation"><span·class="lineannotation">…</span></em> | 681 | » <em·class="lineannotation"><span·class="lineannotation">…</span></em> |
682 | }·else·{» » » /*·parent·*/ | 682 | }·else·{» » » /*·parent·*/ |
683 | » <em·class="lineannotation"><span·class="lineannotation">…</span></em></pre><p>Now·all·you·have·to·do·is·attach·to·the·child,·set | 683 | » <em·class="lineannotation"><span·class="lineannotation">…</span></em></pre><p>Now·all·you·have·to·do·is·attach·to·the·child,·set |
684 | » <span·class="symbol">PauseMode</span>·to·<code·class="literal">0</code>,·and·wait | 684 | » <span·class="symbol">PauseMode</span>·to·<code·class="literal">0</code>,·and·wait |
685 | » for·the·<code·class="function">sleep()</code>·call·to·return!</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="emacs"></a>2.7.·Using·Emacs·as·a·Development·Environment</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60636472"></a>2.7.1.·Emacs</h3></div></div></div><p>Unfortunately,·<span·class="trademark">UNIX</span>®·systems·do·not·come·with·the·kind·of | 685 | » for·the·<code·class="function">sleep()</code>·call·to·return!</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="emacs"></a>2.7.·Using·Emacs·as·a·Development·Environment</h2></div></div></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60704312"></a>2.7.1.·Emacs</h3></div></div></div><p>Unfortunately,·<span·class="trademark">UNIX</span>®·systems·do·not·come·with·the·kind·of |
686 | » everything-you-ever-wanted-and-lots-more-you-did-not-in-one-gigantic-package | 686 | » everything-you-ever-wanted-and-lots-more-you-did-not-in-one-gigantic-package |
687 | » integrated·development·environments·that·other·systems | 687 | » integrated·development·environments·that·other·systems |
688 | » have. | 688 | » have. |
| |
689 | » <a·href="#ftn.idp60640696"·class="footnote"·id="idp60640696"><sup·class="footnote">[7]</sup></a> | 689 | » <a·href="#ftn.idp60707896"·class="footnote"·id="idp60707896"><sup·class="footnote">[7]</sup></a> |
| |
690 | » However,·it·is·possible·to·set·up·your·own·environment.··It | 690 | » However,·it·is·possible·to·set·up·your·own·environment.··It |
691 | » may·not·be·as·pretty,·and·it·may·not·be·quite·as·integrated, | 691 | » may·not·be·as·pretty,·and·it·may·not·be·quite·as·integrated, |
692 | » but·you·can·set·it·up·the·way·you·want·it.··And·it·is·free. | 692 | » but·you·can·set·it·up·the·way·you·want·it.··And·it·is·free. |
693 | » And·you·have·the·source·to·it.</p><p>The·key·to·it·all·is·Emacs.··Now·there·are·some·people·who | 693 | » And·you·have·the·source·to·it.</p><p>The·key·to·it·all·is·Emacs.··Now·there·are·some·people·who |
694 | » loathe·it,·but·many·who·love·it.··If·you·are·one·of·the·former, | 694 | » loathe·it,·but·many·who·love·it.··If·you·are·one·of·the·former, |
695 | » I·am·afraid·this·section·will·hold·little·of·interest·to·you. | 695 | » I·am·afraid·this·section·will·hold·little·of·interest·to·you. |
Offset 763, 29 lines modified | Offset 763, 29 lines modified |
763 | » <span·class="keysym">x</span>,·press·<span·class="keysym">c</span>·and·release·the | 763 | » <span·class="keysym">x</span>,·press·<span·class="keysym">c</span>·and·release·the |
764 | » <span·class="keysym">control</span>·key).··If·you·have·any·unsaved·files | 764 | » <span·class="keysym">control</span>·key).··If·you·have·any·unsaved·files |
765 | » open,·Emacs·will·ask·you·if·you·want·to·save·them.··(Ignore | 765 | » open,·Emacs·will·ask·you·if·you·want·to·save·them.··(Ignore |
766 | » the·bit·in·the·documentation·where·it·says | 766 | » the·bit·in·the·documentation·where·it·says |
767 | » <code·class="command">C-z</code>·is·the·usual·way·to·leave | 767 | » <code·class="command">C-z</code>·is·the·usual·way·to·leave |
768 | » Emacs——that·leaves·Emacs·hanging·around·in·the | 768 | » Emacs——that·leaves·Emacs·hanging·around·in·the |
769 | » background,·and·is·only·really·useful·if·you·are·on·a·system | 769 | » background,·and·is·only·really·useful·if·you·are·on·a·system |
770 | » which·does·not·have·virtual·terminals).</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60705592"></a>2.7.2.·Configuring·Emacs</h3></div></div></div><p>Emacs·does·many·wonderful·things;·some·of·them·are·built | 770 | » which·does·not·have·virtual·terminals).</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60772152"></a>2.7.2.·Configuring·Emacs</h3></div></div></div><p>Emacs·does·many·wonderful·things;·some·of·them·are·built |
771 | » in,·some·of·them·need·to·be·configured.</p><p>Instead·of·using·a·proprietary·macro·language·for | 771 | » in,·some·of·them·need·to·be·configured.</p><p>Instead·of·using·a·proprietary·macro·language·for |
772 | » configuration,·Emacs·uses·a·version·of·Lisp·specially·adapted | 772 | » configuration,·Emacs·uses·a·version·of·Lisp·specially·adapted |
773 | » for·editors,·known·as·Emacs·Lisp.··Working·with·Emacs·Lisp·can | 773 | » for·editors,·known·as·Emacs·Lisp.··Working·with·Emacs·Lisp·can |
774 | » be·quite·helpful·if·you·want·to·go·on·and·learn·something·like | 774 | » be·quite·helpful·if·you·want·to·go·on·and·learn·something·like |
775 | » Common·Lisp.··Emacs·Lisp·has·many·features·of·Common·Lisp, | 775 | » Common·Lisp.··Emacs·Lisp·has·many·features·of·Common·Lisp, |
776 | » although·it·is·considerably·smaller·(and·thus·easier·to | 776 | » although·it·is·considerably·smaller·(and·thus·easier·to |
777 | » master).</p><p>The·best·way·to·learn·Emacs·Lisp·is·to·download·the·<a·class="link"·href="ftp://ftp.gnu.org/old-gnu/emacs/elisp-manual-19-2.4.tar.gz"·target="_top">Emacs | 777 | » master).</p><p>The·best·way·to·learn·Emacs·Lisp·is·to·download·the·<a·class="link"·href="ftp://ftp.gnu.org/old-gnu/emacs/elisp-manual-19-2.4.tar.gz"·target="_top">Emacs |
778 | » ··Tutorial</a></p><p>However,·there·is·no·need·to·actually·know·any·Lisp·to·get | 778 | » ··Tutorial</a></p><p>However,·there·is·no·need·to·actually·know·any·Lisp·to·get |
779 | » started·with·configuring·Emacs,·as·I·have·included·a·sample | 779 | » started·with·configuring·Emacs,·as·I·have·included·a·sample |
780 | » <code·class="filename">.emacs</code>·file,·which·should·be·enough·to | 780 | » <code·class="filename">.emacs</code>·file,·which·should·be·enough·to |
781 | » get·you·started.··Just·copy·it·into·your·home·directory·and | 781 | » get·you·started.··Just·copy·it·into·your·home·directory·and |
782 | » restart·Emacs·if·it·is·already·running;·it·will·read·the | 782 | » restart·Emacs·if·it·is·already·running;·it·will·read·the |
783 | » commands·from·the·file·and·(hopefully)·give·you·a·useful·basic | 783 | » commands·from·the·file·and·(hopefully)·give·you·a·useful·basic |
784 | » setup.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60713656"></a>2.7.3.·A·sample·<code·class="filename">.emacs</code>·file</h3></div></div></div><p>Unfortunately,·there·is·far·too·much·here·to·explain·it·in | 784 | » setup.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp60792632"></a>2.7.3.·A·sample·<code·class="filename">.emacs</code>·file</h3></div></div></div><p>Unfortunately,·there·is·far·too·much·here·to·explain·it·in |
785 | » detail;·however·there·are·one·or·two·points·worth | 785 | » detail;·however·there·are·one·or·two·points·worth |
786 | » mentioning.</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>Everything·beginning·with·a·<code·class="literal">;</code>·is·a·comment | 786 | » mentioning.</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>Everything·beginning·with·a·<code·class="literal">;</code>·is·a·comment |
787 | » ····and·is·ignored·by·Emacs.</p></li><li·class="listitem"><p>In·the·first·line,·the | 787 | » ····and·is·ignored·by·Emacs.</p></li><li·class="listitem"><p>In·the·first·line,·the |
788 | » ····<code·class="literal">-*- Emacs-Lisp -*-</code>·is·so·that | 788 | » ····<code·class="literal">-*- Emacs-Lisp -*-</code>·is·so·that |
789 | » ····we·can·edit·the·<code·class="filename">.emacs</code>·file·itself | 789 | » ····we·can·edit·the·<code·class="filename">.emacs</code>·file·itself |
790 | » ····within·Emacs·and·get·all·the·fancy·features·for·editing | 790 | » ····within·Emacs·and·get·all·the·fancy·features·for·editing |
791 | » ····Emacs·Lisp.··Emacs·usually·tries·to·guess·this·based·on | 791 | » ····Emacs·Lisp.··Emacs·usually·tries·to·guess·this·based·on |
Offset 808, 15 lines modified | Offset 808, 15 lines modified |
808 | » ····will·open·up·the·source·file·in·which·the·error·occurred | 808 | » ····will·open·up·the·source·file·in·which·the·error·occurred |
809 | » ····and·jump·to·the·appropriate·line.</p></li><li·class="listitem"><p>We·enable·Emacs's·ability·to·act·as·a·server,·so·that | 809 | » ····and·jump·to·the·appropriate·line.</p></li><li·class="listitem"><p>We·enable·Emacs's·ability·to·act·as·a·server,·so·that |
810 | » ····if·you·are·doing·something·outside·Emacs·and·you·want·to | 810 | » ····if·you·are·doing·something·outside·Emacs·and·you·want·to |
811 | » ····edit·a·file,·you·can·just·type·in</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>emacsclient·filename</code></strong> | 811 | » ····edit·a·file,·you·can·just·type·in</p><pre·class="screen"><code·class="prompt">%</code>·<strong·class="userinput"><code>emacsclient·filename</code></strong> |
812 | » ··</pre><p>and·then·you·can·edit·the·file·in·your | 812 | » ··</pre><p>and·then·you·can·edit·the·file·in·your |
813 | » ····Emacs! | 813 | » ····Emacs! |
| |
814 | » ····<a·href="#ftn.idp63183800"·class="footnote"·id="idp63183800"><sup·class="footnote">[8]</sup></a></p></li></ul></div><div·class="example"><a·id="idp63185592"></a><div·class="example-title">範例·2.1.·A·sample·<code·class="filename">.emacs</code>·file</div><div·class="example-contents"><pre·class="programlisting">;;·-*-Emacs-Lisp-*- | 814 | » ····<a·href="#ftn.idp63241144"·class="footnote"·id="idp63241144"><sup·class="footnote">[8]</sup></a></p></li></ul></div><div·class="example"><a·id="idp63242936"></a><div·class="example-title">範例·2.1.·A·sample·<code·class="filename">.emacs</code>·file</div><div·class="example-contents"><pre·class="programlisting">;;·-*-Emacs-Lisp-*- |
| |
815 | ;;·This·file·is·designed·to·be·re-evaled;·use·the·variable·first-time | 815 | ;;·This·file·is·designed·to·be·re-evaled;·use·the·variable·first-time |
816 | ;;·to·avoid·any·problems·with·this. | 816 | ;;·to·avoid·any·problems·with·this. |
817 | (defvar·first-time·t | 817 | (defvar·first-time·t |
818 | ··"Flag·signifying·this·is·the·first·time·that·.emacs·has·been·evaled") | 818 | ··"Flag·signifying·this·is·the·first·time·that·.emacs·has·been·evaled") |
| |
819 | ;;·Meta | 819 | ;;·Meta |
Offset 1091, 15 lines modified | Offset 1091, 15 lines modified |
| |
1091 | ;;·No·need·to·debug·anything·now | 1091 | ;;·No·need·to·debug·anything·now |
| |
1092 | (setq·debug-on-error·nil) | 1092 | (setq·debug-on-error·nil) |
| |
1093 | ;;·All·done | 1093 | ;;·All·done |
1094 | (message·"All·done,·%s%s"·(user-login-name)·".") | 1094 | (message·"All·done,·%s%s"·(user-login-name)·".") |
1095 | » </pre></div></div><br·class="example-break"·/></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63187256"></a>2.7.4.·Extending·the·Range·of·Languages·Emacs·Understands</h3></div></div></div><p>Now,·this·is·all·very·well·if·you·only·want·to·program·in | 1095 | » </pre></div></div><br·class="example-break"·/></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63244600"></a>2.7.4.·Extending·the·Range·of·Languages·Emacs·Understands</h3></div></div></div><p>Now,·this·is·all·very·well·if·you·only·want·to·program·in |
1096 | » the·languages·already·catered·for·in·the | 1096 | » the·languages·already·catered·for·in·the |
1097 | » <code·class="filename">.emacs</code>·file·(C,·C++,·Perl,·Lisp·and | 1097 | » <code·class="filename">.emacs</code>·file·(C,·C++,·Perl,·Lisp·and |
1098 | » Scheme),·but·what·happens·if·a·new·language·called | 1098 | » Scheme),·but·what·happens·if·a·new·language·called |
1099 | » <span·class="quote">“<span·class="quote">whizbang</span>”</span>·comes·out,·full·of·exciting | 1099 | » <span·class="quote">“<span·class="quote">whizbang</span>”</span>·comes·out,·full·of·exciting |
1100 | » features?</p><p>The·first·thing·to·do·is·find·out·if·whizbang·comes·with | 1100 | » features?</p><p>The·first·thing·to·do·is·find·out·if·whizbang·comes·with |
1101 | » any·files·that·tell·Emacs·about·the·language.··These·usually | 1101 | » any·files·that·tell·Emacs·about·the·language.··These·usually |
1102 | » end·in·<code·class="filename">.el</code>,·short·for·<span·class="quote">“<span·class="quote">Emacs | 1102 | » end·in·<code·class="filename">.el</code>,·short·for·<span·class="quote">“<span·class="quote">Emacs |
Offset 1154, 23 lines modified | Offset 1154, 23 lines modified |
1154 | » Addison-Wesley·1991 | 1154 | » Addison-Wesley·1991 |
1155 | » ISBN·0-201-53992-6</p></li><li·class="listitem"><p>W.·Richard·Stevens | 1155 | » ISBN·0-201-53992-6</p></li><li·class="listitem"><p>W.·Richard·Stevens |
1156 | » ··<span·class="emphasis"><em>Advanced·Programming·in·the·Unix·Environment</em></span> | 1156 | » ··<span·class="emphasis"><em>Advanced·Programming·in·the·Unix·Environment</em></span> |
1157 | » ··Addison-Wesley·1992 | 1157 | » ··Addison-Wesley·1992 |
1158 | » ··ISBN·0-201-56317-7</p></li><li·class="listitem"><p>W.·Richard·Stevens | 1158 | » ··ISBN·0-201-56317-7</p></li><li·class="listitem"><p>W.·Richard·Stevens |
1159 | » ··<span·class="emphasis"><em>Unix·Network·Programming</em></span> | 1159 | » ··<span·class="emphasis"><em>Unix·Network·Programming</em></span> |
1160 | » ··Prentice-Hall·1990 | 1160 | » ··Prentice-Hall·1990 |
1161 | » ··ISBN·0-13-949876-1</p></li></ul></div></div><div·class="footnotes"><br·/><hr·class="footnote-hr"·/><div·id="ftn.idp59555000"·class="footnote"><p><a·href="#idp59555000"·class="para"><sup·class="para">[1]·</sup></a>如果在提示命令列下執行,那麼有可能會產生·core·dump。</p></div><div·id="ftn.idp59589560"·class="footnote"><p><a·href="#idp59589560"·class="para"><sup·class="para">[2]·</sup></a>嚴格說起來,在這個階段·<code·class="command">cc</code>·並不是真的把原始程式轉成組合語言, | 1161 | » ··ISBN·0-13-949876-1</p></li></ul></div></div><div·class="footnotes"><br·/><hr·class="footnote-hr"·/><div·id="ftn.idp59586744"·class="footnote"><p><a·href="#idp59586744"·class="para"><sup·class="para">[1]·</sup></a>如果在提示命令列下執行,那麼有可能會產生·core·dump。</p></div><div·id="ftn.idp59627576"·class="footnote"><p><a·href="#idp59627576"·class="para"><sup·class="para">[2]·</sup></a>嚴格說起來,在這個階段·<code·class="command">cc</code>·並不是真的把原始程式轉成組合語言, |
1162 | ··········而是轉為·machine-independent·的·<em·class="firstterm">p-code</em>。</p></div><div·id="ftn.idp59619128"·class="footnote"><p><a·href="#idp59619128"·class="para"><sup·class="para">[3]·</sup></a>剛所說的·binary·sort·和·bubble·sort·問題, | 1162 | ··········而是轉為·machine-independent·的·<em·class="firstterm">p-code</em>。</p></div><div·id="ftn.idp59675448"·class="footnote"><p><a·href="#idp59675448"·class="para"><sup·class="para">[3]·</sup></a>剛所說的·binary·sort·和·bubble·sort·問題, |
1163 | ··········在已排序好的序列中,binary·sort·搜索效率會比·bubble·sort·好。</p></div><div·id="ftn.idp59642040"·class="footnote"><p><a·href="#idp59642040"·class="para"><sup·class="para">[4]·</sup></a>至於·<code·class="option">-o</code>·的原因,則是一團歷史迷霧了。</p></div><div·id="ftn.idp59714488"·class="footnote"><p><a·href="#idp59714488"·class="para"><sup·class="para">[5]·</sup></a>請注意,因為上例沒用·<code·class="option">-o</code>·以指定執行檔名稱, | 1163 | ··········在已排序好的序列中,binary·sort·搜索效率會比·bubble·sort·好。</p></div><div·id="ftn.idp59687096"·class="footnote"><p><a·href="#idp59687096"·class="para"><sup·class="para">[4]·</sup></a>至於·<code·class="option">-o</code>·的原因,則是一團歷史迷霧了。</p></div><div·id="ftn.idp59758136"·class="footnote"><p><a·href="#idp59758136"·class="para"><sup·class="para">[5]·</sup></a>請注意,因為上例沒用·<code·class="option">-o</code>·以指定執行檔名稱, |
1164 | » ········所以執行檔會是·<code·class="filename">a.out</code>·這檔。 | 1164 | » ········所以執行檔會是·<code·class="filename">a.out</code>·這檔。 |
1165 | » ········那麼,要如何產生·<code·class="filename">foobar</code>·的執行檔並內含除錯訊息, | 1165 | » ········那麼,要如何產生·<code·class="filename">foobar</code>·的執行檔並內含除錯訊息, |
1166 | » ········這就留待看倌們練習一下囉。</p></div><div·id="ftn.idp60160696"·class="footnote"><p><a·href="#idp60160696"·class="para"><sup·class="para">[6]·</sup></a>They·do·not·use·the·<code·class="filename">MAKEFILE</code>·form | 1166 | » ········這就留待看倌們練習一下囉。</p></div><div·id="ftn.idp60223672"·class="footnote"><p><a·href="#idp60223672"·class="para"><sup·class="para">[6]·</sup></a>They·do·not·use·the·<code·class="filename">MAKEFILE</code>·form |
1167 | » ····as·block·capitals·are·often·used·for·documentation·files | 1167 | » ····as·block·capitals·are·often·used·for·documentation·files |
1168 | » ····like·<code·class="filename">README</code>.</p></div><div·id="ftn.idp60640696"·class="footnote"><p><a·href="#idp60640696"·class="para"><sup·class="para">[7]·</sup></a>Some·powerful,·free·IDEs·now·exist,·such·as·KDevelop | 1168 | » ····like·<code·class="filename">README</code>.</p></div><div·id="ftn.idp60707896"·class="footnote"><p><a·href="#idp60707896"·class="para"><sup·class="para">[7]·</sup></a>Some·powerful,·free·IDEs·now·exist,·such·as·KDevelop |
1169 | » ····in·the·ports·collection.</p></div><div·id="ftn.idp63183800"·class="footnote"><p><a·href="#idp63183800"·class="para"><sup·class="para">[8]·</sup></a>Many·Emacs·users·set·their·<code·class="envar">EDITOR</code> | 1169 | » ····in·the·ports·collection.</p></div><div·id="ftn.idp63241144"·class="footnote"><p><a·href="#idp63241144"·class="para"><sup·class="para">[8]·</sup></a>Many·Emacs·users·set·their·<code·class="envar">EDITOR</code> |
1170 | » » environment·to | 1170 | » » environment·to |
1171 | » » <code·class="literal">emacsclient</code>·so·this·happens·every | 1171 | » » <code·class="literal">emacsclient</code>·so·this·happens·every |
1172 | » » time·they·need·to·edit·a·file.</p></div></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="secure"></a>章·3.·Secure·Programming</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Murray</span>·<span·class="surname">Stokely</span></span>.·</span></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#secure-synopsis">3.1.·Synopsis</a></span></dt><dt><span·class="sect1"><a·href="#secure-philosophy">3.2.·Secure·Design | 1172 | » » time·they·need·to·edit·a·file.</p></div></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="secure"></a>章·3.·Secure·Programming</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Murray</span>·<span·class="surname">Stokely</span></span>.·</span></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#secure-synopsis">3.1.·Synopsis</a></span></dt><dt><span·class="sect1"><a·href="#secure-philosophy">3.2.·Secure·Design |
1173 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-synopsis"></a>3.1.·Synopsis</h2></div></div></div><p>This·chapter·describes·some·of·the·security·issues·that | 1173 | ······Methodology</a></span></dt><dt><span·class="sect1"><a·href="#secure-bufferov">3.3.·Buffer·Overflows</a></span></dt><dt><span·class="sect1"><a·href="#secure-setuid">3.4.·SetUID·issues</a></span></dt><dt><span·class="sect1"><a·href="#secure-chroot">3.5.·Limiting·your·program's·environment</a></span></dt><dt><span·class="sect1"><a·href="#secure-trust">3.6.·Trust</a></span></dt><dt><span·class="sect1"><a·href="#secure-race-conditions">3.7.·Race·Conditions</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-synopsis"></a>3.1.·Synopsis</h2></div></div></div><p>This·chapter·describes·some·of·the·security·issues·that |
1174 | ······have·plagued·<span·class="trademark">UNIX</span>®·programmers·for·decades·and·some·of·the·new | 1174 | ······have·plagued·<span·class="trademark">UNIX</span>®·programmers·for·decades·and·some·of·the·new |
1175 | ······tools·available·to·help·programmers·avoid·writing·exploitable | 1175 | ······tools·available·to·help·programmers·avoid·writing·exploitable |
1176 | ······code.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-philosophy"></a>3.2.·Secure·Design | 1176 | ······code.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-philosophy"></a>3.2.·Secure·Design |
Offset 1184, 54 lines modified | Offset 1184, 54 lines modified |
1184 | ······is·to·make·assumptions·about·the·sanity·of·the·environment. | 1184 | ······is·to·make·assumptions·about·the·sanity·of·the·environment. |
1185 | ······Applications·should·never·trust·user·input·(in·all·its·forms), | 1185 | ······Applications·should·never·trust·user·input·(in·all·its·forms), |
1186 | ······system·resources,·inter-process·communication,·or·the·timing·of | 1186 | ······system·resources,·inter-process·communication,·or·the·timing·of |
1187 | ······events.··<span·class="trademark">UNIX</span>®·processes·do·not·execute·synchronously·so·logical | 1187 | ······events.··<span·class="trademark">UNIX</span>®·processes·do·not·execute·synchronously·so·logical |
1188 | ······operations·are·rarely·atomic.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-bufferov"></a>3.3.·Buffer·Overflows</h2></div></div></div><p>Buffer·Overflows·have·been·around·since·the·very | 1188 | ······operations·are·rarely·atomic.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-bufferov"></a>3.3.·Buffer·Overflows</h2></div></div></div><p>Buffer·Overflows·have·been·around·since·the·very |
1189 | ······beginnings·of·the·Von-Neuman·<a·class="xref"·href="#COD">1</a>·architecture. | 1189 | ······beginnings·of·the·Von-Neuman·<a·class="xref"·href="#COD">1</a>·architecture. |
| |
1190 | ······<a·id="idp63406904"·class="indexterm"></a> | 1190 | ······<a·id="idp63472440"·class="indexterm"></a> |
1191 | ······<a·id="idp63407416"·class="indexterm"></a> | 1191 | ······<a·id="idp63472952"·class="indexterm"></a> |
| |
1192 | ······They·first·gained·widespread·notoriety·in·1988·with·the·Morris | 1192 | ······They·first·gained·widespread·notoriety·in·1988·with·the·Morris |
1193 | ······Internet·worm.··Unfortunately,·the·same·basic·attack·remains | 1193 | ······Internet·worm.··Unfortunately,·the·same·basic·attack·remains |
| |
1194 | ······<a·id="idp63407928"·class="indexterm"></a> | 1194 | ······<a·id="idp63473464"·class="indexterm"></a> |
| |
1195 | ······effective·today.··Of·the·17·CERT·security·advisories·of·1999,·10 | 1195 | ······effective·today.··Of·the·17·CERT·security·advisories·of·1999,·10 |
| |
1196 | ······<a·id="idp63408440"·class="indexterm"></a> | 1196 | ······<a·id="idp63473976"·class="indexterm"></a> |
| |
1197 | ······of·them·were·directly·caused·by·buffer-overflow·software·bugs. | 1197 | ······of·them·were·directly·caused·by·buffer-overflow·software·bugs. |
1198 | ······By·far·the·most·common·type·of·buffer·overflow·attack·is·based | 1198 | ······By·far·the·most·common·type·of·buffer·overflow·attack·is·based |
1199 | ······on·corrupting·the·stack.</p><a·id="idp63409592"·class="indexterm"></a><a·id="idp63410104"·class="indexterm"></a><p>Most·modern·computer·systems·use·a·stack·to·pass·arguments | 1199 | ······on·corrupting·the·stack.</p><a·id="idp63479224"·class="indexterm"></a><a·id="idp63479736"·class="indexterm"></a><p>Most·modern·computer·systems·use·a·stack·to·pass·arguments |
1200 | ······to·procedures·and·to·store·local·variables.··A·stack·is·a·last | 1200 | ······to·procedures·and·to·store·local·variables.··A·stack·is·a·last |
1201 | ······in·first·out·(LIFO)·buffer·in·the·high·memory·area·of·a·process | 1201 | ······in·first·out·(LIFO)·buffer·in·the·high·memory·area·of·a·process |
1202 | ······image.··When·a·program·invokes·a·function·a·new·"stack·frame"·is | 1202 | ······image.··When·a·program·invokes·a·function·a·new·"stack·frame"·is |
| |
1203 | ······<a·id="idp63410872"·class="indexterm"></a> | 1203 | ······<a·id="idp63480504"·class="indexterm"></a> |
1204 | ······<a·id="idp63411384"·class="indexterm"></a> | 1204 | ······<a·id="idp63481016"·class="indexterm"></a> |
| |
1205 | ······created.··This·stack·frame·consists·of·the·arguments·passed·to | 1205 | ······created.··This·stack·frame·consists·of·the·arguments·passed·to |
1206 | ······the·function·as·well·as·a·dynamic·amount·of·local·variable | 1206 | ······the·function·as·well·as·a·dynamic·amount·of·local·variable |
1207 | ······space.··The·"stack·pointer"·is·a·register·that·holds·the·current | 1207 | ······space.··The·"stack·pointer"·is·a·register·that·holds·the·current |
| |
1208 | ······<a·id="idp63412536"·class="indexterm"></a> | 1208 | ······<a·id="idp63482168"·class="indexterm"></a> |
1209 | ······<a·id="idp63413048"·class="indexterm"></a> | 1209 | ······<a·id="idp63482680"·class="indexterm"></a> |
| |
1210 | ······location·of·the·top·of·the·stack.··Since·this·value·is | 1210 | ······location·of·the·top·of·the·stack.··Since·this·value·is |
1211 | ······constantly·changing·as·new·values·are·pushed·onto·the·top·of·the | 1211 | ······constantly·changing·as·new·values·are·pushed·onto·the·top·of·the |
1212 | ······stack,·many·implementations·also·provide·a·"frame·pointer"·that | 1212 | ······stack,·many·implementations·also·provide·a·"frame·pointer"·that |
1213 | ······is·located·near·the·beginning·of·a·stack·frame·so·that·local | 1213 | ······is·located·near·the·beginning·of·a·stack·frame·so·that·local |
1214 | ······variables·can·more·easily·be·addressed·relative·to·this | 1214 | ······variables·can·more·easily·be·addressed·relative·to·this |
1215 | ······value.·<a·class="xref"·href="#COD">1</a>·The·return·address·for·function | 1215 | ······value.·<a·class="xref"·href="#COD">1</a>·The·return·address·for·function |
| |
1216 | ······<a·id="idp63413944"·class="indexterm"></a> | 1216 | ······<a·id="idp63483576"·class="indexterm"></a> |
1217 | ······<a·id="idp63414456"·class="indexterm"></a> | 1217 | ······<a·id="idp63484088"·class="indexterm"></a> |
1218 | ······<a·id="idp63415608"·class="indexterm"></a> | 1218 | ······<a·id="idp63485240"·class="indexterm"></a> |
1219 | ······<a·id="idp63416120"·class="indexterm"></a> | 1219 | ······<a·id="idp63485752"·class="indexterm"></a> |
| |
1220 | ······calls·is·also·stored·on·the·stack,·and·this·is·the·cause·of | 1220 | ······calls·is·also·stored·on·the·stack,·and·this·is·the·cause·of |
1221 | ······stack-overflow·exploits·since·overflowing·a·local·variable·in·a | 1221 | ······stack-overflow·exploits·since·overflowing·a·local·variable·in·a |
1222 | ······function·can·overwrite·the·return·address·of·that·function, | 1222 | ······function·can·overwrite·the·return·address·of·that·function, |
1223 | ······potentially·allowing·a·malicious·user·to·execute·any·code·he·or | 1223 | ······potentially·allowing·a·malicious·user·to·execute·any·code·he·or |
1224 | ······she·wants.</p><p>Although·stack-based·attacks·are·by·far·the·most·common, | 1224 | ······she·wants.</p><p>Although·stack-based·attacks·are·by·far·the·most·common, |
1225 | ······it·would·also·be·possible·to·overrun·the·stack·with·a·heap-based | 1225 | ······it·would·also·be·possible·to·overrun·the·stack·with·a·heap-based |
Offset 1239, 15 lines modified | Offset 1239, 15 lines modified |
1239 | ······bounds·checking·on·arrays·or·pointers·as·many·other·languages | 1239 | ······bounds·checking·on·arrays·or·pointers·as·many·other·languages |
1240 | ······do.··In·addition,·the·standard·C·library·is·filled·with·a | 1240 | ······do.··In·addition,·the·standard·C·library·is·filled·with·a |
1241 | ······handful·of·very·dangerous·functions.</p><div·class="informaltable"><table·width="100%"·border="0"><colgroup><col·/><col·/></colgroup><tbody><tr><td><code·class="function">strcpy</code>(char·*dest,·const·char | 1241 | ······handful·of·very·dangerous·functions.</p><div·class="informaltable"><table·width="100%"·border="0"><colgroup><col·/><col·/></colgroup><tbody><tr><td><code·class="function">strcpy</code>(char·*dest,·const·char |
1242 | ··········*src)</td><td><p>May·overflow·the·dest·buffer</p></td></tr><tr><td><code·class="function">strcat</code>(char·*dest,·const·char | 1242 | ··········*src)</td><td><p>May·overflow·the·dest·buffer</p></td></tr><tr><td><code·class="function">strcat</code>(char·*dest,·const·char |
1243 | ··········*src)</td><td><p>May·overflow·the·dest·buffer</p></td></tr><tr><td><code·class="function">getwd</code>(char·*buf)</td><td><p>May·overflow·the·buf·buffer</p></td></tr><tr><td><code·class="function">gets</code>(char·*s)</td><td><p>May·overflow·the·s·buffer</p></td></tr><tr><td><code·class="function">[vf]scanf</code>(const·char·*format, | 1243 | ··········*src)</td><td><p>May·overflow·the·dest·buffer</p></td></tr><tr><td><code·class="function">getwd</code>(char·*buf)</td><td><p>May·overflow·the·buf·buffer</p></td></tr><tr><td><code·class="function">gets</code>(char·*s)</td><td><p>May·overflow·the·s·buffer</p></td></tr><tr><td><code·class="function">[vf]scanf</code>(const·char·*format, |
1244 | ··········...)</td><td><p>May·overflow·its·arguments.</p></td></tr><tr><td><code·class="function">realpath</code>(char·*path,·char | 1244 | ··········...)</td><td><p>May·overflow·its·arguments.</p></td></tr><tr><td><code·class="function">realpath</code>(char·*path,·char |
1245 | ··········resolved_path[])</td><td><p>May·overflow·the·path·buffer</p></td></tr><tr><td><code·class="function">[v]sprintf</code>(char·*str,·const·char | 1245 | ··········resolved_path[])</td><td><p>May·overflow·the·path·buffer</p></td></tr><tr><td><code·class="function">[v]sprintf</code>(char·*str,·const·char |
1246 | ··········*format,·...)</td><td><p>May·overflow·the·str·buffer.</p></td></tr></tbody></table></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63428920"></a>3.3.1.·Example·Buffer·Overflow</h3></div></div></div><p>The·following·example·code·contains·a·buffer·overflow | 1246 | ··········*format,·...)</td><td><p>May·overflow·the·str·buffer.</p></td></tr></tbody></table></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63498552"></a>3.3.1.·Example·Buffer·Overflow</h3></div></div></div><p>The·following·example·code·contains·a·buffer·overflow |
1247 | ······designed·to·overwrite·the·return·address·and·skip·the | 1247 | ······designed·to·overwrite·the·return·address·and·skip·the |
1248 | ······instruction·immediately·following·the·function·call.··(Inspired | 1248 | ······instruction·immediately·following·the·function·call.··(Inspired |
1249 | ······by·<a·class="xref"·href="#Phrack">4</a>)</p><pre·class="programlisting">#include·<code·class="sgmltag-element">stdio.h</code> | 1249 | ······by·<a·class="xref"·href="#Phrack">4</a>)</p><pre·class="programlisting">#include·<code·class="sgmltag-element">stdio.h</code> |
| |
1250 | void·manipulate(char·*buffer)·{ | 1250 | void·manipulate(char·*buffer)·{ |
1251 | ··char·newbuffer[80]; | 1251 | ··char·newbuffer[80]; |
1252 | ··strcpy(newbuffer,buffer); | 1252 | ··strcpy(newbuffer,buffer); |
Offset 1263, 53 lines modified | Offset 1263, 53 lines modified |
1263 | ··manipulate(buffer); | 1263 | ··manipulate(buffer); |
1264 | ··i=2; | 1264 | ··i=2; |
1265 | ··printf("The·value·of·i·is·:·%d\n",i); | 1265 | ··printf("The·value·of·i·is·:·%d\n",i); |
1266 | ··return·0; | 1266 | ··return·0; |
1267 | }</pre><p>Let·us·examine·what·the·memory·image·of·this·process·would | 1267 | }</pre><p>Let·us·examine·what·the·memory·image·of·this·process·would |
1268 | ······look·like·if·we·were·to·input·160·spaces·into·our·little·program | 1268 | ······look·like·if·we·were·to·input·160·spaces·into·our·little·program |
1269 | ······before·hitting·return.</p><p>[XXX·figure·here!]</p><p>Obviously·more·malicious·input·can·be·devised·to·execute | 1269 | ······before·hitting·return.</p><p>[XXX·figure·here!]</p><p>Obviously·more·malicious·input·can·be·devised·to·execute |
1270 | ······actual·compiled·instructions·(such·as·exec(/bin/sh)).</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63432376"></a>3.3.2.·Avoiding·Buffer·Overflows</h3></div></div></div><p>The·most·straightforward·solution·to·the·problem·of | 1270 | ······actual·compiled·instructions·(such·as·exec(/bin/sh)).</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63502008"></a>3.3.2.·Avoiding·Buffer·Overflows</h3></div></div></div><p>The·most·straightforward·solution·to·the·problem·of |
1271 | ······stack-overflows·is·to·always·use·length·restricted·memory·and | 1271 | ······stack-overflows·is·to·always·use·length·restricted·memory·and |
1272 | ······string·copy·functions.··<code·class="function">strncpy</code>·and | 1272 | ······string·copy·functions.··<code·class="function">strncpy</code>·and |
1273 | ······<code·class="function">strncat</code>·are·part·of·the·standard·C·library. | 1273 | ······<code·class="function">strncat</code>·are·part·of·the·standard·C·library. |
| |
1274 | ······<a·id="idp63433912"·class="indexterm"></a> | 1274 | ······<a·id="idp63503544"·class="indexterm"></a> |
1275 | ······<a·id="idp63435064"·class="indexterm"></a> | 1275 | ······<a·id="idp63504696"·class="indexterm"></a> |
| |
1276 | ······These·functions·accept·a·length·value·as·a·parameter·which | 1276 | ······These·functions·accept·a·length·value·as·a·parameter·which |
1277 | ······should·be·no·larger·than·the·size·of·the·destination·buffer. | 1277 | ······should·be·no·larger·than·the·size·of·the·destination·buffer. |
1278 | ······These·functions·will·then·copy·up·to·`length'·bytes·from·the | 1278 | ······These·functions·will·then·copy·up·to·`length'·bytes·from·the |
1279 | ······source·to·the·destination.··However·there·are·a·number·of | 1279 | ······source·to·the·destination.··However·there·are·a·number·of |
1280 | ······problems·with·these·functions.··Neither·function·guarantees·NUL | 1280 | ······problems·with·these·functions.··Neither·function·guarantees·NUL |
1281 | ······termination·if·the·size·of·the·input·buffer·is·as·large·as·the | 1281 | ······termination·if·the·size·of·the·input·buffer·is·as·large·as·the |
| |
1282 | ······<a·id="idp63436216"·class="indexterm"></a> | 1282 | ······<a·id="idp63505848"·class="indexterm"></a> |
| |
1283 | ······destination.··The·length·parameter·is·also·used·inconsistently | 1283 | ······destination.··The·length·parameter·is·also·used·inconsistently |
1284 | ······between·strncpy·and·strncat·so·it·is·easy·for·programmers·to·get | 1284 | ······between·strncpy·and·strncat·so·it·is·easy·for·programmers·to·get |
1285 | ······confused·as·to·their·proper·usage.··There·is·also·a·significant | 1285 | ······confused·as·to·their·proper·usage.··There·is·also·a·significant |
1286 | ······performance·loss·compared·to·<code·class="function">strcpy</code>·when | 1286 | ······performance·loss·compared·to·<code·class="function">strcpy</code>·when |
1287 | ······copying·a·short·string·into·a·large·buffer·since | 1287 | ······copying·a·short·string·into·a·large·buffer·since |
1288 | ······<code·class="function">strncpy</code>·NUL·fills·up·the·size | 1288 | ······<code·class="function">strncpy</code>·NUL·fills·up·the·size |
1289 | ······specified.</p><p>In·OpenBSD,·another·memory·copy·implementation·has·been | 1289 | ······specified.</p><p>In·OpenBSD,·another·memory·copy·implementation·has·been |
| |
1290 | ······<a·id="idp63437880"·class="indexterm"></a> | 1290 | ······<a·id="idp63507512"·class="indexterm"></a> |
| |
1291 | ······created·to·get·around·these·problem.··The | 1291 | ······created·to·get·around·these·problem.··The |
1292 | ······<code·class="function">strlcpy</code>·and·<code·class="function">strlcat</code> | 1292 | ······<code·class="function">strlcpy</code>·and·<code·class="function">strlcat</code> |
1293 | ······functions·guarantee·that·they·will·always·null·terminate·the | 1293 | ······functions·guarantee·that·they·will·always·null·terminate·the |
1294 | ······destination·string·when·given·a·non-zero·length·argument.··For | 1294 | ······destination·string·when·given·a·non-zero·length·argument.··For |
1295 | ······more·information·about·these·functions·see·<a·class="xref"·href="#OpenBSD">6</a>.··The·OpenBSD·<code·class="function">strlcpy</code>·and | 1295 | ······more·information·about·these·functions·see·<a·class="xref"·href="#OpenBSD">6</a>.··The·OpenBSD·<code·class="function">strlcpy</code>·and |
1296 | ······<code·class="function">strlcat</code>·instructions·have·been·in·FreeBSD | 1296 | ······<code·class="function">strlcat</code>·instructions·have·been·in·FreeBSD |
1297 | ······since·3.3.</p><a·id="idp63440440"·class="indexterm"></a><a·id="idp63441592"·class="indexterm"></a><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63446840"></a>3.3.2.1.·Compiler·based·run-time·bounds·checking</h4></div></div></div><a·id="idp63447352"·class="indexterm"></a><p>Unfortunately·there·is·still·a·very·large·assortment·of | 1297 | ······since·3.3.</p><a·id="idp63510072"·class="indexterm"></a><a·id="idp63511224"·class="indexterm"></a><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63516472"></a>3.3.2.1.·Compiler·based·run-time·bounds·checking</h4></div></div></div><a·id="idp63516984"·class="indexterm"></a><p>Unfortunately·there·is·still·a·very·large·assortment·of |
1298 | ········code·in·public·use·which·blindly·copies·memory·around·without | 1298 | ········code·in·public·use·which·blindly·copies·memory·around·without |
1299 | ········using·any·of·the·bounded·copy·routines·we·just·discussed. | 1299 | ········using·any·of·the·bounded·copy·routines·we·just·discussed. |
1300 | ········Fortunately,·there·is·another·solution.··Several·compiler | 1300 | ········Fortunately,·there·is·another·solution.··Several·compiler |
1301 | ········add-ons·and·libraries·exist·to·do·Run-time·bounds·checking·in | 1301 | ········add-ons·and·libraries·exist·to·do·Run-time·bounds·checking·in |
1302 | ········C/C++.</p><a·id="idp63448632"·class="indexterm"></a><a·id="idp63449144"·class="indexterm"></a><p>StackGuard·is·one·such·add-on·that·is·implemented·as·a | 1302 | ········C/C++.</p><a·id="idp63518264"·class="indexterm"></a><a·id="idp63518776"·class="indexterm"></a><p>StackGuard·is·one·such·add-on·that·is·implemented·as·a |
1303 | ········small·patch·to·the·gcc·code·generator.··From·the·<a·class="link"·href="http://immunix.org/stackguard.html"·target="_top">StackGuard | 1303 | ········small·patch·to·the·gcc·code·generator.··From·the·<a·class="link"·href="http://immunix.org/stackguard.html"·target="_top">StackGuard |
1304 | ··········website</a>: | 1304 | ··········website</a>: |
| |
1305 | ········</p><div·class="blockquote"><blockquote·class="blockquote"><p>"StackGuard·detects·and·defeats·stack | 1305 | ········</p><div·class="blockquote"><blockquote·class="blockquote"><p>"StackGuard·detects·and·defeats·stack |
1306 | ········smashing·attacks·by·protecting·the·return·address·on·the·stack | 1306 | ········smashing·attacks·by·protecting·the·return·address·on·the·stack |
1307 | ········from·being·altered.··StackGuard·places·a·"canary"·word·next·to | 1307 | ········from·being·altered.··StackGuard·places·a·"canary"·word·next·to |
1308 | ········the·return·address·when·a·function·is·called.··If·the·canary | 1308 | ········the·return·address·when·a·function·is·called.··If·the·canary |
Offset 1322, 41 lines modified | Offset 1322, 41 lines modified |
1322 | ········to·the·gcc·code·generator,·specifically·the·function_prolog() | 1322 | ········to·the·gcc·code·generator,·specifically·the·function_prolog() |
1323 | ········and·function_epilog()·routines.··function_prolog()·has·been | 1323 | ········and·function_epilog()·routines.··function_prolog()·has·been |
1324 | ········enhanced·to·lay·down·canaries·on·the·stack·when·functions | 1324 | ········enhanced·to·lay·down·canaries·on·the·stack·when·functions |
1325 | ········start,·and·function_epilog()·checks·canary·integrity·when·the | 1325 | ········start,·and·function_epilog()·checks·canary·integrity·when·the |
1326 | ········function·exits.··Any·attempt·at·corrupting·the·return·address | 1326 | ········function·exits.··Any·attempt·at·corrupting·the·return·address |
1327 | ········is·thus·detected·before·the·function | 1327 | ········is·thus·detected·before·the·function |
1328 | ········returns."</p></blockquote></div><p> | 1328 | ········returns."</p></blockquote></div><p> |
1329 | ········</p><a·id="idp63463992"·class="indexterm"></a><p>Recompiling·your·application·with·StackGuard·is·an | 1329 | ········</p><a·id="idp63521336"·class="indexterm"></a><p>Recompiling·your·application·with·StackGuard·is·an |
1330 | ········effective·means·of·stopping·most·buffer-overflow·attacks,·but | 1330 | ········effective·means·of·stopping·most·buffer-overflow·attacks,·but |
1331 | ········it·can·still·be·compromised.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63465016"></a>3.3.2.2.·Library·based·run-time·bounds·checking</h4></div></div></div><a·id="idp63465528"·class="indexterm"></a><p>Compiler-based·mechanisms·are·completely·useless·for | 1331 | ········it·can·still·be·compromised.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63522360"></a>3.3.2.2.·Library·based·run-time·bounds·checking</h4></div></div></div><a·id="idp63522872"·class="indexterm"></a><p>Compiler-based·mechanisms·are·completely·useless·for |
1332 | ········binary-only·software·for·which·you·cannot·recompile.··For | 1332 | ········binary-only·software·for·which·you·cannot·recompile.··For |
1333 | ········these·situations·there·are·a·number·of·libraries·which | 1333 | ········these·situations·there·are·a·number·of·libraries·which |
1334 | ········re-implement·the·unsafe·functions·of·the·C-library | 1334 | ········re-implement·the·unsafe·functions·of·the·C-library |
1335 | ········(<code·class="function">strcpy</code>,·<code·class="function">fscanf</code>, | 1335 | ········(<code·class="function">strcpy</code>,·<code·class="function">fscanf</code>, |
1336 | ········<code·class="function">getwd</code>,·etc..)·and·ensure·that·these | 1336 | ········<code·class="function">getwd</code>,·etc..)·and·ensure·that·these |
1337 | ········functions·can·never·write·past·the·stack·pointer.</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem">libsafe</li><li·class="listitem">libverify</li><li·class="listitem">libparanoia</li></ul></div><p>Unfortunately·these·library-based·defenses·have·a·number | 1337 | ········functions·can·never·write·past·the·stack·pointer.</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem">libsafe</li><li·class="listitem">libverify</li><li·class="listitem">libparanoia</li></ul></div><p>Unfortunately·these·library-based·defenses·have·a·number |
1338 | ········of·shortcomings.··These·libraries·only·protect·against·a·very | 1338 | ········of·shortcomings.··These·libraries·only·protect·against·a·very |
1339 | ········small·set·of·security·related·issues·and·they·neglect·to·fix | 1339 | ········small·set·of·security·related·issues·and·they·neglect·to·fix |
1340 | ········the·actual·problem.··These·defenses·may·fail·if·the | 1340 | ········the·actual·problem.··These·defenses·may·fail·if·the |
1341 | ········application·was·compiled·with·-fomit-frame-pointer.··Also,·the | 1341 | ········application·was·compiled·with·-fomit-frame-pointer.··Also,·the |
1342 | ········LD_PRELOAD·and·LD_LIBRARY_PATH·environment·variables·can·be | 1342 | ········LD_PRELOAD·and·LD_LIBRARY_PATH·environment·variables·can·be |
1343 | ········overwritten/unset·by·the·user.</p></div></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-setuid"></a>3.4.·SetUID·issues</h2></div></div></div><a·id="idp63479736"·class="indexterm"></a><p>There·are·at·least·6·different·IDs·associated·with·any | 1343 | ········overwritten/unset·by·the·user.</p></div></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-setuid"></a>3.4.·SetUID·issues</h2></div></div></div><a·id="idp63532984"·class="indexterm"></a><p>There·are·at·least·6·different·IDs·associated·with·any |
1344 | ······given·process.··Because·of·this·you·have·to·be·very·careful·with | 1344 | ······given·process.··Because·of·this·you·have·to·be·very·careful·with |
1345 | ······the·access·that·your·process·has·at·any·given·time.··In | 1345 | ······the·access·that·your·process·has·at·any·given·time.··In |
1346 | ······particular,·all·seteuid·applications·should·give·up·their | 1346 | ······particular,·all·seteuid·applications·should·give·up·their |
1347 | ······privileges·as·soon·as·it·is·no·longer·required.</p><a·id="idp63480632"·class="indexterm"></a><a·id="idp63481784"·class="indexterm"></a><p>The·real·user·ID·can·only·be·changed·by·a·superuser | 1347 | ······privileges·as·soon·as·it·is·no·longer·required.</p><a·id="idp63533880"·class="indexterm"></a><a·id="idp63535032"·class="indexterm"></a><p>The·real·user·ID·can·only·be·changed·by·a·superuser |
1348 | ······process.··The·<span·class="application">login</span>·program·sets·this | 1348 | ······process.··The·<span·class="application">login</span>·program·sets·this |
1349 | ······when·a·user·initially·logs·in·and·it·is·seldom·changed.</p><p>The·effective·user·ID·is·set·by·the | 1349 | ······when·a·user·initially·logs·in·and·it·is·seldom·changed.</p><p>The·effective·user·ID·is·set·by·the |
1350 | ······<code·class="function">exec()</code>·functions·if·a·program·has·its | 1350 | ······<code·class="function">exec()</code>·functions·if·a·program·has·its |
1351 | ······seteuid·bit·set.··An·application·can·call | 1351 | ······seteuid·bit·set.··An·application·can·call |
1352 | ······<code·class="function">seteuid()</code>·at·any·time·to·set·the·effective | 1352 | ······<code·class="function">seteuid()</code>·at·any·time·to·set·the·effective |
1353 | ······user·ID·to·either·the·real·user·ID·or·the·saved·set-user-ID. | 1353 | ······user·ID·to·either·the·real·user·ID·or·the·saved·set-user-ID. |
1354 | ······When·the·effective·user·ID·is·set·by·<code·class="function">exec()</code> | 1354 | ······When·the·effective·user·ID·is·set·by·<code·class="function">exec()</code> |
1355 | ······functions,·the·previous·value·is·saved·in·the·saved·set-user-ID.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-chroot"></a>3.5.·Limiting·your·program's·environment</h2></div></div></div><a·id="idp63486008"·class="indexterm"></a><p>The·traditional·method·of·restricting·a·process | 1355 | ······functions,·the·previous·value·is·saved·in·the·saved·set-user-ID.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-chroot"></a>3.5.·Limiting·your·program's·environment</h2></div></div></div><a·id="idp63539256"·class="indexterm"></a><p>The·traditional·method·of·restricting·a·process |
1356 | ······is·with·the·<code·class="function">chroot()</code>·system·call.··This | 1356 | ······is·with·the·<code·class="function">chroot()</code>·system·call.··This |
1357 | ······system·call·changes·the·root·directory·from·which·all·other | 1357 | ······system·call·changes·the·root·directory·from·which·all·other |
1358 | ······paths·are·referenced·for·a·process·and·any·child·processes.··For | 1358 | ······paths·are·referenced·for·a·process·and·any·child·processes.··For |
1359 | ······this·call·to·succeed·the·process·must·have·execute·(search) | 1359 | ······this·call·to·succeed·the·process·must·have·execute·(search) |
1360 | ······permission·on·the·directory·being·referenced.··The·new | 1360 | ······permission·on·the·directory·being·referenced.··The·new |
1361 | ······environment·does·not·actually·take·effect·until·you | 1361 | ······environment·does·not·actually·take·effect·until·you |
1362 | ······<code·class="function">chdir()</code>·into·your·new·environment.··It | 1362 | ······<code·class="function">chdir()</code>·into·your·new·environment.··It |
Offset 1369, 15 lines modified | Offset 1369, 15 lines modified |
1369 | ······kern.chroot_allow_open_directories·<code·class="command">sysctl</code> | 1369 | ······kern.chroot_allow_open_directories·<code·class="command">sysctl</code> |
1370 | ······variable.··When·this·value·is·set·to·0, | 1370 | ······variable.··When·this·value·is·set·to·0, |
1371 | ······<code·class="function">chroot()</code>·will·fail·with·EPERM·if·there·are | 1371 | ······<code·class="function">chroot()</code>·will·fail·with·EPERM·if·there·are |
1372 | ······any·directories·open.··If·set·to·the·default·value·of·1,·then | 1372 | ······any·directories·open.··If·set·to·the·default·value·of·1,·then |
1373 | ······<code·class="function">chroot()</code>·will·fail·with·EPERM·if·there·are | 1373 | ······<code·class="function">chroot()</code>·will·fail·with·EPERM·if·there·are |
1374 | ······any·directories·open·and·the·process·is·already·subject·to·a | 1374 | ······any·directories·open·and·the·process·is·already·subject·to·a |
1375 | ······<code·class="function">chroot()</code>·call.··For·any·other·value,·the | 1375 | ······<code·class="function">chroot()</code>·call.··For·any·other·value,·the |
1376 | ······check·for·open·directories·will·be·bypassed·completely.</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63489976"></a>3.5.1.·FreeBSD's·jail·functionality</h3></div></div></div><a·id="idp63490488"·class="indexterm"></a><p>The·concept·of·a·Jail·extends·upon·the | 1376 | ······check·for·open·directories·will·be·bypassed·completely.</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63543224"></a>3.5.1.·FreeBSD's·jail·functionality</h3></div></div></div><a·id="idp63543736"·class="indexterm"></a><p>The·concept·of·a·Jail·extends·upon·the |
1377 | ······<code·class="function">chroot()</code>·by·limiting·the·powers·of·the | 1377 | ······<code·class="function">chroot()</code>·by·limiting·the·powers·of·the |
1378 | ······superuser·to·create·a·true·`virtual·server'.··Once·a·prison·is | 1378 | ······superuser·to·create·a·true·`virtual·server'.··Once·a·prison·is |
1379 | ······set·up·all·network·communication·must·take·place·through·the | 1379 | ······set·up·all·network·communication·must·take·place·through·the |
1380 | ······specified·IP·address,·and·the·power·of·"root·privilege"·in·this | 1380 | ······specified·IP·address,·and·the·power·of·"root·privilege"·in·this |
1381 | ······jail·is·severely·constrained.</p><p>While·in·a·prison,·any·tests·of·superuser·power·within·the | 1381 | ······jail·is·severely·constrained.</p><p>While·in·a·prison,·any·tests·of·superuser·power·within·the |
1382 | ······kernel·using·the·<code·class="function">suser()</code>·call·will·fail. | 1382 | ······kernel·using·the·<code·class="function">suser()</code>·call·will·fail. |
1383 | ······However,·some·calls·to·<code·class="function">suser()</code>·have·been | 1383 | ······However,·some·calls·to·<code·class="function">suser()</code>·have·been |
Offset 1396, 75 lines modified | Offset 1396, 75 lines modified |
1396 | ········time.</li><li·class="listitem">Bind·to·privileged·ports·in·the·Internet | 1396 | ········time.</li><li·class="listitem">Bind·to·privileged·ports·in·the·Internet |
1397 | ········domain·(ports·<·1024)</li></ul></div><p><code·class="function">Jail</code>·is·a·very·useful·tool·for | 1397 | ········domain·(ports·<·1024)</li></ul></div><p><code·class="function">Jail</code>·is·a·very·useful·tool·for |
1398 | ······running·applications·in·a·secure·environment·but·it·does·have | 1398 | ······running·applications·in·a·secure·environment·but·it·does·have |
1399 | ······some·shortcomings.··Currently,·the·IPC·mechanisms·have·not·been | 1399 | ······some·shortcomings.··Currently,·the·IPC·mechanisms·have·not·been |
1400 | ······converted·to·the·<code·class="function">suser_xxx</code>·so·applications | 1400 | ······converted·to·the·<code·class="function">suser_xxx</code>·so·applications |
1401 | ······such·as·MySQL·cannot·be·run·within·a·jail.··Superuser·access | 1401 | ······such·as·MySQL·cannot·be·run·within·a·jail.··Superuser·access |
1402 | ······may·have·a·very·limited·meaning·within·a·jail,·but·there·is | 1402 | ······may·have·a·very·limited·meaning·within·a·jail,·but·there·is |
1403 | ······no·way·to·specify·exactly·what·"very·limited"·means.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63503032"></a>3.5.2.·<span·class="trademark">POSIX</span>®.1e·Process·Capabilities</h3></div></div></div><a·id="idp63508024"·class="indexterm"></a><a·id="idp63508536"·class="indexterm"></a><p><span·class="trademark">POSIX</span>®·has·released·a·working·draft·that·adds·event | 1403 | ······no·way·to·specify·exactly·what·"very·limited"·means.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63556280"></a>3.5.2.·<span·class="trademark">POSIX</span>®.1e·Process·Capabilities</h3></div></div></div><a·id="idp63557176"·class="indexterm"></a><a·id="idp63557688"·class="indexterm"></a><p><span·class="trademark">POSIX</span>®·has·released·a·working·draft·that·adds·event |
1404 | ······auditing,·access·control·lists,·fine·grained·privileges, | 1404 | ······auditing,·access·control·lists,·fine·grained·privileges, |
1405 | ······information·labeling,·and·mandatory·access·control.</p><p>This·is·a·work·in·progress·and·is·the·focus·of·the·<a·class="link"·href="http://www.trustedbsd.org/"·target="_top">TrustedBSD</a>·project.··Some | 1405 | ······information·labeling,·and·mandatory·access·control.</p><p>This·is·a·work·in·progress·and·is·the·focus·of·the·<a·class="link"·href="http://www.trustedbsd.org/"·target="_top">TrustedBSD</a>·project.··Some |
1406 | ······of·the·initial·work·has·been·committed·to·FreeBSD-CURRENT | 1406 | ······of·the·initial·work·has·been·committed·to·FreeBSD-CURRENT |
1407 | ······(cap_set_proc(3)).</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-trust"></a>3.6.·Trust</h2></div></div></div><p>An·application·should·never·assume·that·anything·about·the | 1407 | ······(cap_set_proc(3)).</p></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-trust"></a>3.6.·Trust</h2></div></div></div><p>An·application·should·never·assume·that·anything·about·the |
1408 | ······users·environment·is·sane.··This·includes·(but·is·certainly·not | 1408 | ······users·environment·is·sane.··This·includes·(but·is·certainly·not |
1409 | ······limited·to):·user·input,·signals,·environment·variables, | 1409 | ······limited·to):·user·input,·signals,·environment·variables, |
1410 | ······resources,·IPC,·mmaps,·the·filesystem·working·directory,·file | 1410 | ······resources,·IPC,·mmaps,·the·filesystem·working·directory,·file |
1411 | ······descriptors,·the·#·of·open·files,·etc.</p><a·id="idp63511992"·class="indexterm"></a><a·id="idp63512504"·class="indexterm"></a><p>You·should·never·assume·that·you·can·catch·all·forms·of | 1411 | ······descriptors,·the·#·of·open·files,·etc.</p><a·id="idp63577528"·class="indexterm"></a><a·id="idp63578040"·class="indexterm"></a><p>You·should·never·assume·that·you·can·catch·all·forms·of |
1412 | ······invalid·input·that·a·user·might·supply.··Instead,·your | 1412 | ······invalid·input·that·a·user·might·supply.··Instead,·your |
1413 | ······application·should·use·positive·filtering·to·only·allow·a | 1413 | ······application·should·use·positive·filtering·to·only·allow·a |
1414 | ······specific·subset·of·inputs·that·you·deem·safe.··Improper·data | 1414 | ······specific·subset·of·inputs·that·you·deem·safe.··Improper·data |
1415 | ······validation·has·been·the·cause·of·many·exploits,·especially·with | 1415 | ······validation·has·been·the·cause·of·many·exploits,·especially·with |
1416 | ······CGI·scripts·on·the·world·wide·web.··For·filenames·you·need·to·be | 1416 | ······CGI·scripts·on·the·world·wide·web.··For·filenames·you·need·to·be |
1417 | ······extra·careful·about·paths·("../",·"/"),·symbolic·links,·and | 1417 | ······extra·careful·about·paths·("../",·"/"),·symbolic·links,·and |
1418 | ······shell·escape·characters.</p><a·id="idp63513400"·class="indexterm"></a><p>Perl·has·a·really·cool·feature·called·"Taint"·mode·which | 1418 | ······shell·escape·characters.</p><a·id="idp63578936"·class="indexterm"></a><p>Perl·has·a·really·cool·feature·called·"Taint"·mode·which |
1419 | ······can·be·used·to·prevent·scripts·from·using·data·derived·outside | 1419 | ······can·be·used·to·prevent·scripts·from·using·data·derived·outside |
1420 | ······the·program·in·an·unsafe·way.··This·mode·will·check·command·line | 1420 | ······the·program·in·an·unsafe·way.··This·mode·will·check·command·line |
1421 | ······arguments,·environment·variables,·locale·information,·the | 1421 | ······arguments,·environment·variables,·locale·information,·the |
1422 | ······results·of·certain·syscalls·(<code·class="function">readdir()</code>, | 1422 | ······results·of·certain·syscalls·(<code·class="function">readdir()</code>, |
1423 | ······<code·class="function">readlink()</code>, | 1423 | ······<code·class="function">readlink()</code>, |
1424 | ······<code·class="function">getpwxxx()</code>,·and·all·file·input.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-race-conditions"></a>3.7.·Race·Conditions</h2></div></div></div><p>A·race·condition·is·anomalous·behavior·caused·by·the | 1424 | ······<code·class="function">getpwxxx()</code>,·and·all·file·input.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="secure-race-conditions"></a>3.7.·Race·Conditions</h2></div></div></div><p>A·race·condition·is·anomalous·behavior·caused·by·the |
1425 | ······unexpected·dependence·on·the·relative·timing·of·events.··In | 1425 | ······unexpected·dependence·on·the·relative·timing·of·events.··In |
1426 | ······other·words,·a·programmer·incorrectly·assumed·that·a·particular | 1426 | ······other·words,·a·programmer·incorrectly·assumed·that·a·particular |
1427 | ······event·would·always·happen·before·another.</p><a·id="idp63516728"·class="indexterm"></a><a·id="idp63517624"·class="indexterm"></a><a·id="idp63518520"·class="indexterm"></a><p>Some·of·the·common·causes·of·race·conditions·are·signals, | 1427 | ······event·would·always·happen·before·another.</p><a·id="idp63582264"·class="indexterm"></a><a·id="idp63583160"·class="indexterm"></a><a·id="idp63584056"·class="indexterm"></a><p>Some·of·the·common·causes·of·race·conditions·are·signals, |
1428 | ······access·checks,·and·file·opens.··Signals·are·asynchronous·events | 1428 | ······access·checks,·and·file·opens.··Signals·are·asynchronous·events |
1429 | ······by·nature·so·special·care·must·be·taken·in·dealing·with·them. | 1429 | ······by·nature·so·special·care·must·be·taken·in·dealing·with·them. |
1430 | ······Checking·access·with·<code·class="function">access(2)</code>·then | 1430 | ······Checking·access·with·<code·class="function">access(2)</code>·then |
1431 | ······<code·class="function">open(2)</code>·is·clearly·non-atomic.··Users·can | 1431 | ······<code·class="function">open(2)</code>·is·clearly·non-atomic.··Users·can |
1432 | ······move·files·in·between·the·two·calls.··Instead,·privileged | 1432 | ······move·files·in·between·the·two·calls.··Instead,·privileged |
1433 | ······applications·should·<code·class="function">seteuid()</code>·and·then·call | 1433 | ······applications·should·<code·class="function">seteuid()</code>·and·then·call |
1434 | ······<code·class="function">open()</code>·directly.··Along·the·same·lines,·an | 1434 | ······<code·class="function">open()</code>·directly.··Along·the·same·lines,·an |
1435 | ······application·should·always·set·a·proper·umask·before | 1435 | ······application·should·always·set·a·proper·umask·before |
1436 | ······<code·class="function">open()</code>·to·obviate·the·need·for·spurious | 1436 | ······<code·class="function">open()</code>·to·obviate·the·need·for·spurious |
1437 | ······<code·class="function">chmod()</code>·calls.</p></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="l10n"></a>章·4.·Localization·and·Internationalization·-·L10N·and·I18N</h2></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="l10n-programming"></a>4.1.·Programming·I18N·Compliant·Applications</h2></div></div></div><a·id="idp63524408"·class="indexterm"></a><a·id="idp63524920"·class="indexterm"></a><p>To·make·your·application·more·useful·for·speakers·of·other | 1437 | ······<code·class="function">chmod()</code>·calls.</p></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="l10n"></a>章·4.·Localization·and·Internationalization·-·L10N·and·I18N</h2></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#l10n-programming">4.1.·Programming·I18N·Compliant·Applications</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="l10n-programming"></a>4.1.·Programming·I18N·Compliant·Applications</h2></div></div></div><a·id="idp63589944"·class="indexterm"></a><a·id="idp63590456"·class="indexterm"></a><p>To·make·your·application·more·useful·for·speakers·of·other |
1438 | » languages,·we·hope·that·you·will·program·I18N·compliant.··The·GNU | 1438 | » languages,·we·hope·that·you·will·program·I18N·compliant.··The·GNU |
1439 | » gcc·compiler·and·GUI·libraries·like·QT·and·GTK·support·I18N·through | 1439 | » gcc·compiler·and·GUI·libraries·like·QT·and·GTK·support·I18N·through |
1440 | » special·handling·of·strings.··Making·a·program·I18N·compliant·is | 1440 | » special·handling·of·strings.··Making·a·program·I18N·compliant·is |
1441 | » very·easy.··It·allows·contributors·to·port·your·application·to | 1441 | » very·easy.··It·allows·contributors·to·port·your·application·to |
1442 | » other·languages·quickly.··Refer·to·the·library·specific·I18N | 1442 | » other·languages·quickly.··Refer·to·the·library·specific·I18N |
1443 | » documentation·for·more·details.</p><p>In·contrast·with·common·perception,·I18N·compliant·code·is | 1443 | » documentation·for·more·details.</p><p>In·contrast·with·common·perception,·I18N·compliant·code·is |
1444 | » easy·to·write.··Usually,·it·only·involves·wrapping·your·strings | 1444 | » easy·to·write.··Usually,·it·only·involves·wrapping·your·strings |
1445 | » with·library·specific·functions.··In·addition,·please·be·sure·to | 1445 | » with·library·specific·functions.··In·addition,·please·be·sure·to |
1446 | » allow·for·wide·or·multibyte·character·support.</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63526200"></a>4.1.1.·A·Call·to·Unify·the·I18N·Effort</h3></div></div></div><p>It·has·come·to·our·attention·that·the·individual·I18N/L10N | 1446 | » allow·for·wide·or·multibyte·character·support.</p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63591736"></a>4.1.1.·A·Call·to·Unify·the·I18N·Effort</h3></div></div></div><p>It·has·come·to·our·attention·that·the·individual·I18N/L10N |
1447 | » ··efforts·for·each·country·has·been·repeating·each·others' | 1447 | » ··efforts·for·each·country·has·been·repeating·each·others' |
1448 | » ··efforts.··Many·of·us·have·been·reinventing·the·wheel·repeatedly | 1448 | » ··efforts.··Many·of·us·have·been·reinventing·the·wheel·repeatedly |
1449 | » ··and·inefficiently.··We·hope·that·the·various·major·groups·in | 1449 | » ··and·inefficiently.··We·hope·that·the·various·major·groups·in |
1450 | » ··I18N·could·congregate·into·a·group·effort·similar·to·the·Core | 1450 | » ··I18N·could·congregate·into·a·group·effort·similar·to·the·Core |
1451 | » ··Team's·responsibility.</p><p>Currently,·we·hope·that,·when·you·write·or·port·I18N | 1451 | » ··Team's·responsibility.</p><p>Currently,·we·hope·that,·when·you·write·or·port·I18N |
1452 | » ··programs,·you·would·send·it·out·to·each·country's·related | 1452 | » ··programs,·you·would·send·it·out·to·each·country's·related |
1453 | » ··FreeBSD·mailing·list·for·testing.··In·the·future,·we·hope·to | 1453 | » ··FreeBSD·mailing·list·for·testing.··In·the·future,·we·hope·to |
1454 | » ··create·applications·that·work·in·all·the·languages | 1454 | » ··create·applications·that·work·in·all·the·languages |
1455 | » ··out-of-the-box·without·dirty·hacks.</p><p>The·<a·class="link"·href="http://lists.FreeBSD.org/mailman/listinfo/freebsd-i18n"·target="_top">FreeBSD·internationalization·郵遞論壇</a>·has·been·established.··If·you·are·an·I18N/L10N | 1455 | » ··out-of-the-box·without·dirty·hacks.</p><p>The·<a·class="link"·href="http://lists.FreeBSD.org/mailman/listinfo/freebsd-i18n"·target="_top">FreeBSD·internationalization·郵遞論壇</a>·has·been·established.··If·you·are·an·I18N/L10N |
1456 | » ··developer,·please·send·your·comments,·ideas,·questions,·and | 1456 | » ··developer,·please·send·your·comments,·ideas,·questions,·and |
1457 | » ··anything·you·deem·related·to·it.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63528632"></a>4.1.2.·Perl·and·Python</h3></div></div></div><a·id="idp63529272"·class="indexterm"></a><a·id="idp63530040"·class="indexterm"></a><p>Perl·and·Python·have·I18N·and·wide·character·handling | 1457 | » ··anything·you·deem·related·to·it.</p></div><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp63598264"></a>4.1.2.·Perl·and·Python</h3></div></div></div><a·id="idp63598904"·class="indexterm"></a><a·id="idp63599672"·class="indexterm"></a><p>Perl·and·Python·have·I18N·and·wide·character·handling |
1458 | » ··libraries.··Please·use·them·for·I18N·compliance.</p><p>In·older·FreeBSD·versions, | 1458 | » ··libraries.··Please·use·them·for·I18N·compliance.</p><p>In·older·FreeBSD·versions, |
1459 | » ··Perl·may·give·warnings·about·not·having·a·wide·character·locale | 1459 | » ··Perl·may·give·warnings·about·not·having·a·wide·character·locale |
1460 | » ··installed·on·your·system.··You·can·set·the | 1460 | » ··installed·on·your·system.··You·can·set·the |
1461 | » ··environment·variable·<code·class="envar">LD_PRELOAD</code>·to | 1461 | » ··environment·variable·<code·class="envar">LD_PRELOAD</code>·to |
1462 | » ··<code·class="filename">/usr/lib/libxpg4.so</code>·in·your·shell.</p><p>In·<code·class="literal">sh</code>-based·shells:</p><pre·class="programlisting"><code·class="envar">LD_PRELOAD=/usr/lib/libxpg4.so</code></pre><p>In·<code·class="literal">C</code>-based·shells:</p><pre·class="programlisting"><code·class="envar">setenv·LD_PRELOAD·/usr/lib/libxpg4.so</code></pre></div></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="policies"></a>章·5.·Source·Tree·Guidelines·and·Policies</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Poul-Henning</span>·<span·class="surname">Kamp</span></span>.·</span></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#poli·✂ | 1462 | » ··<code·class="filename">/usr/lib/libxpg4.so</code>·in·your·shell.</p><p>In·<code·class="literal">sh</code>-based·shells:</p><pre·class="programlisting"><code·class="envar">LD_PRELOAD=/usr/lib/libxpg4.so</code></pre><p>In·<code·class="literal">C</code>-based·shells:</p><pre·class="programlisting"><code·class="envar">setenv·LD_PRELOAD·/usr/lib/libxpg4.so</code></pre></div></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="policies"></a>章·5.·Source·Tree·Guidelines·and·Policies</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Poul-Henning</span>·<span·class="surname">Kamp</span></span>.·</span></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#policies-maintainer">5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</a></span></dt><dt><span·class="sect1"><a·href="#poli·✂ |
1463 | ····the·FreeBSD·source·tree.</p><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-maintainer"></a>5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</h2></div></div></div><a·id="idp63551928"·class="indexterm"></a><p>If·a·particular·portion·of·the·FreeBSD·distribution·is·being | 1463 | ····the·FreeBSD·source·tree.</p><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-maintainer"></a>5.1.·<code·class="varname">MAINTAINER</code>·on·Makefiles</h2></div></div></div><a·id="idp63609272"·class="indexterm"></a><p>If·a·particular·portion·of·the·FreeBSD·distribution·is·being |
1464 | ······maintained·by·a·person·or·group·of·persons,·they·can·communicate·this | 1464 | ······maintained·by·a·person·or·group·of·persons,·they·can·communicate·this |
1465 | ······fact·to·the·world·by·adding·a | 1465 | ······fact·to·the·world·by·adding·a |
| |
1466 | ······</p><pre·class="programlisting">MAINTAINER=·email-addresses</pre><p> | 1466 | ······</p><pre·class="programlisting">MAINTAINER=·email-addresses</pre><p> |
| |
1467 | ······line·to·the·<code·class="filename">Makefile</code>s·covering·this·portion·of·the | 1467 | ······line·to·the·<code·class="filename">Makefile</code>s·covering·this·portion·of·the |
1468 | ······source·tree.</p><p>The·semantics·of·this·are·as·follows:</p><p>The·maintainer·owns·and·is·responsible·for·that·code.··This·means | 1468 | ······source·tree.</p><p>The·semantics·of·this·are·as·follows:</p><p>The·maintainer·owns·and·is·responsible·for·that·code.··This·means |
Offset 1474, 15 lines modified | Offset 1474, 15 lines modified |
1474 | ······to·the·maintainer·for·review·before·being·committed.··Only·if·the | 1474 | ······to·the·maintainer·for·review·before·being·committed.··Only·if·the |
1475 | ······maintainer·does·not·respond·for·an·unacceptable·period·of·time,·to | 1475 | ······maintainer·does·not·respond·for·an·unacceptable·period·of·time,·to |
1476 | ······several·emails,·will·it·be·acceptable·to·commit·changes·without·review | 1476 | ······several·emails,·will·it·be·acceptable·to·commit·changes·without·review |
1477 | ······by·the·maintainer.··However,·it·is·suggested·that·you·try·to·have·the | 1477 | ······by·the·maintainer.··However,·it·is·suggested·that·you·try·to·have·the |
1478 | ······changes·reviewed··by·someone·else·if·at·all·possible.</p><p>It·is·of·course·not·acceptable·to·add·a·person·or·group·as | 1478 | ······changes·reviewed··by·someone·else·if·at·all·possible.</p><p>It·is·of·course·not·acceptable·to·add·a·person·or·group·as |
1479 | ······maintainer·unless·they·agree·to·assume·this·duty.··On·the·other·hand·it | 1479 | ······maintainer·unless·they·agree·to·assume·this·duty.··On·the·other·hand·it |
1480 | ······does·not·have·to·be·a·committer·and·it·can·easily·be·a·group·of | 1480 | ······does·not·have·to·be·a·committer·and·it·can·easily·be·a·group·of |
1481 | ······people.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-contributed"></a>5.2.·Contributed·Software</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Poul-Henning</span>·<span·class="surname">Kamp</span></span>·且·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">David</span>·<span·class="surname">O'Brien</span></span>.·</span></div></div></div><a·id="idp63562808"·class="indexterm"></a><p>Some·parts·of·the·FreeBSD·distribution·consist·of·software·that·is | 1481 | ······people.</p></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-contributed"></a>5.2.·Contributed·Software</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Poul-Henning</span>·<span·class="surname">Kamp</span></span>·且·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">David</span>·<span·class="surname">O'Brien</span></span>.·</span></div></div></div><a·id="idp63616056"·class="indexterm"></a><p>Some·parts·of·the·FreeBSD·distribution·consist·of·software·that·is |
1482 | ······actively·being·maintained·outside·the·FreeBSD·project.··For·historical | 1482 | ······actively·being·maintained·outside·the·FreeBSD·project.··For·historical |
1483 | ······reasons,·we·call·this·<span·class="emphasis"><em>contributed</em></span>·software.··Some | 1483 | ······reasons,·we·call·this·<span·class="emphasis"><em>contributed</em></span>·software.··Some |
1484 | ······examples·are·<span·class="application">sendmail</span>,·<span·class="application">gcc</span>·and·<span·class="application">patch</span>.</p><p>Over·the·last·couple·of·years,·various·methods·have·been·used·in | 1484 | ······examples·are·<span·class="application">sendmail</span>,·<span·class="application">gcc</span>·and·<span·class="application">patch</span>.</p><p>Over·the·last·couple·of·years,·various·methods·have·been·used·in |
1485 | ······dealing·with·this·type·of·software·and·all·have·some·number·of | 1485 | ······dealing·with·this·type·of·software·and·all·have·some·number·of |
1486 | ······advantages·and·drawbacks.··No·clear·winner·has·emerged.</p><p>Since·this·is·the·case,·after·some·debate·one·of·these·methods·has | 1486 | ······advantages·and·drawbacks.··No·clear·winner·has·emerged.</p><p>Since·this·is·the·case,·after·some·debate·one·of·these·methods·has |
1487 | ······been·selected·as·the·<span·class="quote">“<span·class="quote">official</span>”</span>·method·and·will·be·required | 1487 | ······been·selected·as·the·<span·class="quote">“<span·class="quote">official</span>”</span>·method·and·will·be·required |
1488 | ······for·future·imports·of·software·of·this·kind.··Furthermore,·it·is | 1488 | ······for·future·imports·of·software·of·this·kind.··Furthermore,·it·is |
Offset 1605, 16 lines modified | Offset 1605, 16 lines modified |
1605 | » ··code.</p></li><li·class="listitem"><p>Object·files·are·named | 1605 | » ··code.</p></li><li·class="listitem"><p>Object·files·are·named |
1606 | » ··<code·class="filename">arch/filename.o.uu></code>.</p></li><li·class="listitem"><p>Kernel·files:</p><div·class="orderedlist"><ol·class="orderedlist"·type="a"><li·class="listitem"><p>Should·always·be·referenced·in | 1606 | » ··<code·class="filename">arch/filename.o.uu></code>.</p></li><li·class="listitem"><p>Kernel·files:</p><div·class="orderedlist"><ol·class="orderedlist"·type="a"><li·class="listitem"><p>Should·always·be·referenced·in |
1607 | ··············<code·class="filename">conf/files.*</code>·(for·build·simplicity).</p></li><li·class="listitem"><p>Should·always·be·in·<code·class="filename">LINT</code>,·but·the | 1607 | ··············<code·class="filename">conf/files.*</code>·(for·build·simplicity).</p></li><li·class="listitem"><p>Should·always·be·in·<code·class="filename">LINT</code>,·but·the |
1608 | » ······<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·decides·per·case·if·it | 1608 | » ······<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·decides·per·case·if·it |
1609 | » ······should·be·commented·out·or·not.··The | 1609 | » ······should·be·commented·out·or·not.··The |
1610 | » ······<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·can,·of·course,·change | 1610 | » ······<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·can,·of·course,·change |
1611 | » ······their·minds·later·on.</p></li><li·class="listitem"><p>The·<em·class="firstterm">Release·Engineer</em> | 1611 | » ······their·minds·later·on.</p></li><li·class="listitem"><p>The·<em·class="firstterm">Release·Engineer</em> |
1612 | ··············decides·whether·or·not·it·goes·into·the·release.</p></li></ol></div></li><li·class="listitem"><p>User-land·files:</p><div·class="orderedlist"><ol·class="orderedlist"·type="a"><li·class="listitem"><a·id="idp63606968"·class="indexterm"></a><p>The·<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·decides·if | 1612 | ··············decides·whether·or·not·it·goes·into·the·release.</p></li></ol></div></li><li·class="listitem"><p>User-land·files:</p><div·class="orderedlist"><ol·class="orderedlist"·type="a"><li·class="listitem"><a·id="idp63676600"·class="indexterm"></a><p>The·<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-core.html"·target="_top">Core·team</a>·decides·if |
1613 | ··············the·code·should·be·part·of·<code·class="command">make·world</code>.</p></li><li·class="listitem"><a·id="idp63609144"·class="indexterm"></a><p>The·<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-who.html"·target="_top">Release·Engineer</a> | 1613 | ··············the·code·should·be·part·of·<code·class="command">make·world</code>.</p></li><li·class="listitem"><a·id="idp63678776"·class="indexterm"></a><p>The·<a·class="link"·href="../../../../doc/zh_TW.UTF-8/articles/contributors/staff-who.html"·target="_top">Release·Engineer</a> |
1614 | ··············decides·if·it·goes·into·the·release.</p></li></ol></div></li></ol></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-shlib"></a>5.4.·Shared·Libraries</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Satoshi</span>·<span·class="surname">Asami</span></span>,·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Peter</span>·<span·class="surname">Wemm</span></span>·且·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">David</span>·<span·class="surname">O'Brien</span></span>.·</span></div></div></div><p>If·you·are·adding·shared·library·support·to·a·port·or·other·piece·of | 1614 | ··············decides·if·it·goes·into·the·release.</p></li></ol></div></li></ol></div></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="policies-shlib"></a>5.4.·Shared·Libraries</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Satoshi</span>·<span·class="surname">Asami</span></span>,·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Peter</span>·<span·class="surname">Wemm</span></span>·且·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">David</span>·<span·class="surname">O'Brien</span></span>.·</span></div></div></div><p>If·you·are·adding·shared·library·support·to·a·port·or·other·piece·of |
1615 | ······software·that·does·not·have·one,·the·version·numbers·should·follow·these | 1615 | ······software·that·does·not·have·one,·the·version·numbers·should·follow·these |
1616 | ······rules.··Generally,·the·resulting·numbers·will·have·nothing·to·do·with | 1616 | ······rules.··Generally,·the·resulting·numbers·will·have·nothing·to·do·with |
1617 | ······the·release·version·of·the·software.</p><p>The·three·principles·of·shared·library·building·are:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>Start·from·<code·class="literal">1.0</code></p></li><li·class="listitem"><p>If·there·is·a·change·that·is·backwards·compatible,·bump·minor | 1617 | ······the·release·version·of·the·software.</p><p>The·three·principles·of·shared·library·building·are:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>Start·from·<code·class="literal">1.0</code></p></li><li·class="listitem"><p>If·there·is·a·change·that·is·backwards·compatible,·bump·minor |
1618 | » ··number·(note·that·ELF·systems·ignore·the·minor·number)</p></li><li·class="listitem"><p>If·there·is·an·incompatible·change,·bump·major·number</p></li></ul></div><p>For·instance,·added·functions·and·bugfixes·result·in·the·minor | 1618 | » ··number·(note·that·ELF·systems·ignore·the·minor·number)</p></li><li·class="listitem"><p>If·there·is·an·incompatible·change,·bump·major·number</p></li></ul></div><p>For·instance,·added·functions·and·bugfixes·result·in·the·minor |
1619 | ······version·number·being·bumped,·while·deleted·functions,·changed·function | 1619 | ······version·number·being·bumped,·while·deleted·functions,·changed·function |
1620 | ······call·syntax,·etc.·will·force·the·major·version·number·to·change.</p><p>Stick·to·version·numbers·of·the·form·major.minor | 1620 | ······call·syntax,·etc.·will·force·the·major·version·number·to·change.</p><p>Stick·to·version·numbers·of·the·form·major.minor |
Offset 2699, 15 lines modified | Offset 2699, 15 lines modified |
2699 | ······release·the·system·resources·they·are·taking·up.</p><p>That·is·why·our·flowchart·now·contains·a·<span·class="emphasis"><em>process | 2699 | ······release·the·system·resources·they·are·taking·up.</p><p>That·is·why·our·flowchart·now·contains·a·<span·class="emphasis"><em>process |
2700 | ······signals</em></span>·box,·which·is·not·connected·to·any·other·box. | 2700 | ······signals</em></span>·box,·which·is·not·connected·to·any·other·box. |
2701 | ······By·the·way,·many·servers·also·process·<span·class="symbol">SIGHUP</span>, | 2701 | ······By·the·way,·many·servers·also·process·<span·class="symbol">SIGHUP</span>, |
2702 | ······and·typically·interpret·as·the·signal·from·the·superuser·that | 2702 | ······and·typically·interpret·as·the·signal·from·the·superuser·that |
2703 | ······they·should·reread·their·configuration·files.·This·allows·us·to | 2703 | ······they·should·reread·their·configuration·files.·This·allows·us·to |
2704 | ······change·settings·without·having·to·kill·and·restart·these | 2704 | ······change·settings·without·having·to·kill·and·restart·these |
2705 | ······servers.</p></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6"></a>章·8.·IPv6·Internals</h2></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#ipv6-implementation">8.1.·IPv6/IPsec·Implementation</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="ipv6-implementation"></a>8.1.·IPv6/IPsec·Implementation</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Yoshinobu</span>·<span·class="surname">Inoue</span></span>.·</span></div></div></div><p>This·section·should·explain·IPv6·and·IPsec·related·implementation | 2705 | ······servers.</p></div></div><div·class="chapter"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6"></a>章·8.·IPv6·Internals</h2></div></div></div><div·class="toc"><div·class="toc-title">內容目錄</div><dl·class="toc"><dt><span·class="sect1"><a·href="#ipv6-implementation">8.1.·IPv6/IPsec·Implementation</a></span></dt></dl></div><div·class="sect1"><div·xmlns=""·class="titlepage"><div><div><h2·xmlns="http://www.w3.org/1999/xhtml"·class="title"·style="clear:·both"><a·id="ipv6-implementation"></a>8.1.·IPv6/IPsec·Implementation</h2></div><div><span·class="authorgroup">Contributed·by·<span·xmlns="http://www.w3.org/1999/xhtml"·class="author"><span·class="firstname">Yoshinobu</span>·<span·class="surname">Inoue</span></span>.·</span></div></div></div><p>This·section·should·explain·IPv6·and·IPsec·related·implementation |
2706 | ····internals.··These·functionalities·are·derived·from·<a·class="link"·href="http://www.kame.net/"·target="_top">KAME·project</a></p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6details"></a>8.1.1.·IPv6</h3></div></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64043320"></a>8.1.1.1.·Conformance</h4></div></div></div><p>The·IPv6·related·functions·conforms,·or·tries·to·conform·to | 2706 | ····internals.··These·functionalities·are·derived·from·<a·class="link"·href="http://www.kame.net/"·target="_top">KAME·project</a></p><div·class="sect2"><div·xmlns=""·class="titlepage"><div><div><h3·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6details"></a>8.1.1.·IPv6</h3></div></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64100664"></a>8.1.1.1.·Conformance</h4></div></div></div><p>The·IPv6·related·functions·conforms,·or·tries·to·conform·to |
2707 | » the·latest·set·of·IPv6·specifications.··For·future·reference·we·list | 2707 | » the·latest·set·of·IPv6·specifications.··For·future·reference·we·list |
2708 | » some·of·the·relevant·documents·below·(<span·class="emphasis"><em>NOTE</em></span>:·this | 2708 | » some·of·the·relevant·documents·below·(<span·class="emphasis"><em>NOTE</em></span>:·this |
2709 | » is·not·a·complete·list·-·this·is·too·hard·to·maintain...).</p><p>For·details·please·refer·to·specific·chapter·in·the·document, | 2709 | » is·not·a·complete·list·-·this·is·too·hard·to·maintain...).</p><p>For·details·please·refer·to·specific·chapter·in·the·document, |
2710 | » RFCs,·manual·pages,·or·comments·in·the·source·code.</p><p>Conformance·tests·have·been·performed·on·the·KAME·STABLE·kit | 2710 | » RFCs,·manual·pages,·or·comments·in·the·source·code.</p><p>Conformance·tests·have·been·performed·on·the·KAME·STABLE·kit |
2711 | ········at·TAHI·project.··Results·can·be·viewed·at | 2711 | ········at·TAHI·project.··Results·can·be·viewed·at |
2712 | » <code·class="uri"><a·class="uri"·href="http://www.tahi.org/report/KAME/"·target="_top">http://www.tahi.org/report/KAME/</a></code>. | 2712 | » <code·class="uri"><a·class="uri"·href="http://www.tahi.org/report/KAME/"·target="_top">http://www.tahi.org/report/KAME/</a></code>. |
2713 | » We·also·attended·Univ.·of·New·Hampshire·IOL·tests | 2713 | » We·also·attended·Univ.·of·New·Hampshire·IOL·tests |
Offset 2823, 15 lines modified | Offset 2823, 15 lines modified |
2823 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>,·and·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getnameinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getnameinfo</span>(3)</span></a>·with·NI_WITHSCOPEID. | 2823 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>,·and·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getnameinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getnameinfo</span>(3)</span></a>·with·NI_WITHSCOPEID. |
2824 | » The·implementation·currently·assumes·1-to-1·relationship·between·a | 2824 | » The·implementation·currently·assumes·1-to-1·relationship·between·a |
2825 | » link·and·an·interface,·which·is·stronger·than·what·specs·say.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6-pnp"></a>8.1.1.4.·Plug·and·Play</h4></div></div></div><p>Most·of·the·IPv6·stateless·address·autoconfiguration·is·implemented | 2825 | » link·and·an·interface,·which·is·stronger·than·what·specs·say.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="ipv6-pnp"></a>8.1.1.4.·Plug·and·Play</h4></div></div></div><p>Most·of·the·IPv6·stateless·address·autoconfiguration·is·implemented |
2826 | » in·the·kernel.··Neighbor·Discovery·functions·are·implemented·in·the | 2826 | » in·the·kernel.··Neighbor·Discovery·functions·are·implemented·in·the |
2827 | » kernel·as·a·whole.··Router·Advertisement·(RA)·input·for·hosts·is | 2827 | » kernel·as·a·whole.··Router·Advertisement·(RA)·input·for·hosts·is |
2828 | » implemented·in·the·kernel.··Router·Solicitation·(RS)·output·for | 2828 | » implemented·in·the·kernel.··Router·Solicitation·(RS)·output·for |
2829 | » endhosts,·RS·input·for·routers,·and·RA·output·for·routers·are | 2829 | » endhosts,·RS·input·for·routers,·and·RA·output·for·routers·are |
2830 | » implemented·in·the·userland.</p><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64167224"></a>8.1.1.4.1.·Assignment·of·link-local,·and·special·addresses</h5></div></div></div><p>IPv6·link-local·address·is·generated·from·IEEE802·address | 2830 | » implemented·in·the·userland.</p><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64236856"></a>8.1.1.4.1.·Assignment·of·link-local,·and·special·addresses</h5></div></div></div><p>IPv6·link-local·address·is·generated·from·IEEE802·address |
2831 | » ··(Ethernet·MAC·address).··Each·of·interface·is·assigned·an·IPv6 | 2831 | » ··(Ethernet·MAC·address).··Each·of·interface·is·assigned·an·IPv6 |
2832 | » ··link-local·address·automatically,·when·the·interface·becomes·up | 2832 | » ··link-local·address·automatically,·when·the·interface·becomes·up |
2833 | » ··(IFF_UP).··Also,·direct·route·for·the·link-local·address·is·added | 2833 | » ··(IFF_UP).··Also,·direct·route·for·the·link-local·address·is·added |
2834 | » ··to·routing·table.</p><p>Here·is·an·output·of·netstat·command:</p><pre·class="screen">Internet6: | 2834 | » ··to·routing·table.</p><p>Here·is·an·output·of·netstat·command:</p><pre·class="screen">Internet6: |
2835 | Destination···················Gateway···················Flags······Netif·Expire | 2835 | Destination···················Gateway···················Flags······Netif·Expire |
2836 | fe80:1::%ed0/64···············link#1····················UC··········ed0 | 2836 | fe80:1::%ed0/64···············link#1····················UC··········ed0 |
2837 | fe80:2::%ep0/64···············link#2····················UC··········ep0</pre><p>Interfaces·that·has·no·IEEE802·address·(pseudo·interfaces | 2837 | fe80:2::%ep0/64···············link#2····················UC··········ep0</pre><p>Interfaces·that·has·no·IEEE802·address·(pseudo·interfaces |
Offset 2845, 15 lines modified | Offset 2845, 15 lines modified |
2845 | » ··lack·of·multicast·support),·link-local·address·will·not·be | 2845 | » ··lack·of·multicast·support),·link-local·address·will·not·be |
2846 | » ··assigned·to·that·interface.··See·section·2·for·details.</p><p>Each·interface·joins·the·solicited·multicast·address·and·the | 2846 | » ··assigned·to·that·interface.··See·section·2·for·details.</p><p>Each·interface·joins·the·solicited·multicast·address·and·the |
2847 | » ··link-local·all-nodes·multicast·addresses·(e.g.·fe80::1:ff01:6317 | 2847 | » ··link-local·all-nodes·multicast·addresses·(e.g.·fe80::1:ff01:6317 |
2848 | » ··and·ff02::1,·respectively,·on·the·link·the·interface·is·attached). | 2848 | » ··and·ff02::1,·respectively,·on·the·link·the·interface·is·attached). |
2849 | » ··In·addition·to·a·link-local·address,·the·loopback·address·(::1) | 2849 | » ··In·addition·to·a·link-local·address,·the·loopback·address·(::1) |
2850 | » ··will·be·assigned·to·the·loopback·interface.··Also,·::1/128·and | 2850 | » ··will·be·assigned·to·the·loopback·interface.··Also,·::1/128·and |
2851 | » ··ff01::/32·are·automatically·added·to·routing·table,·and·loopback | 2851 | » ··ff01::/32·are·automatically·added·to·routing·table,·and·loopback |
2852 | » ··interface·joins·node-local·multicast·group·ff01::1.</p></div><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64170296"></a>8.1.1.4.2.·Stateless·address·autoconfiguration·on·hosts</h5></div></div></div><p>In·IPv6·specification,·nodes·are·separated·into·two·categories: | 2852 | » ··interface·joins·node-local·multicast·group·ff01::1.</p></div><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64239928"></a>8.1.1.4.2.·Stateless·address·autoconfiguration·on·hosts</h5></div></div></div><p>In·IPv6·specification,·nodes·are·separated·into·two·categories: |
2853 | » ··<span·class="emphasis"><em>routers</em></span>·and·<span·class="emphasis"><em>hosts</em></span>.··Routers | 2853 | » ··<span·class="emphasis"><em>routers</em></span>·and·<span·class="emphasis"><em>hosts</em></span>.··Routers |
2854 | » ··forward·packets·addressed·to·others,·hosts·does·not·forward·the | 2854 | » ··forward·packets·addressed·to·others,·hosts·does·not·forward·the |
2855 | » ··packets.··net.inet6.ip6.forwarding·defines·whether·this·node·is | 2855 | » ··packets.··net.inet6.ip6.forwarding·defines·whether·this·node·is |
2856 | » ··router·or·host·(router·if·it·is·1,·host·if·it·is·0).</p><p>When·a·host·hears·Router·Advertisement·from·the·router,·a·host | 2856 | » ··router·or·host·(router·if·it·is·1,·host·if·it·is·0).</p><p>When·a·host·hears·Router·Advertisement·from·the·router,·a·host |
2857 | » ··may·autoconfigure·itself·by·stateless·address·autoconfiguration. | 2857 | » ··may·autoconfigure·itself·by·stateless·address·autoconfiguration. |
2858 | » ··This·behavior·can·be·controlled·by·net.inet6.ip6.accept_rtadv·(host | 2858 | » ··This·behavior·can·be·controlled·by·net.inet6.ip6.accept_rtadv·(host |
2859 | » ··autoconfigures·itself·if·it·is·set·to·1).··By·autoconfiguration, | 2859 | » ··autoconfigures·itself·if·it·is·set·to·1).··By·autoconfiguration, |
Offset 2983, 15 lines modified | Offset 2983, 15 lines modified |
2983 | » ····places.··We·need·to·convert·them·into·larger·integral·type. | 2983 | » ····places.··We·need·to·convert·them·into·larger·integral·type. |
2984 | » ····It·needs·a·great·care,·as·we·may·experience·overflow·during | 2984 | » ····It·needs·a·great·care,·as·we·may·experience·overflow·during |
2985 | » ····packet·length·computation.</p></li><li·class="listitem"><p>We·mistakingly·check·for·ip6_plen·field·of·IPv6·header | 2985 | » ····packet·length·computation.</p></li><li·class="listitem"><p>We·mistakingly·check·for·ip6_plen·field·of·IPv6·header |
2986 | » ····for·packet·payload·length·in·various·places.··We·should·be | 2986 | » ····for·packet·payload·length·in·various·places.··We·should·be |
2987 | » ····checking·mbuf·pkthdr.len·instead.··ip6_input()·will·perform | 2987 | » ····checking·mbuf·pkthdr.len·instead.··ip6_input()·will·perform |
2988 | » ····sanity·check·on·jumbo·payload·option·on·input,·and·we·can | 2988 | » ····sanity·check·on·jumbo·payload·option·on·input,·and·we·can |
2989 | » ····safely·use·mbuf·pkthdr.len·afterwards.</p></li><li·class="listitem"><p>TCP·code·needs·a·careful·update·in·bunch·of·places,·of | 2989 | » ····safely·use·mbuf·pkthdr.len·afterwards.</p></li><li·class="listitem"><p>TCP·code·needs·a·careful·update·in·bunch·of·places,·of |
2990 | » ····course.</p></li></ul></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64242872"></a>8.1.1.8.·Loop·prevention·in·header·processing</h4></div></div></div><p>IPv6·specification·allows·arbitrary·number·of·extension·headers | 2990 | » ····course.</p></li></ul></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64300216"></a>8.1.1.8.·Loop·prevention·in·header·processing</h4></div></div></div><p>IPv6·specification·allows·arbitrary·number·of·extension·headers |
2991 | » to·be·placed·onto·packets.··If·we·implement·IPv6·packet·processing | 2991 | » to·be·placed·onto·packets.··If·we·implement·IPv6·packet·processing |
2992 | » code·in·the·way·BSD·IPv4·code·is·implemented,·kernel·stack·may | 2992 | » code·in·the·way·BSD·IPv4·code·is·implemented,·kernel·stack·may |
2993 | » overflow·due·to·long·function·call·chain.··sys/netinet6·code | 2993 | » overflow·due·to·long·function·call·chain.··sys/netinet6·code |
2994 | » is·carefully·designed·to·avoid·kernel·stack·overflow.··Because·of | 2994 | » is·carefully·designed·to·avoid·kernel·stack·overflow.··Because·of |
2995 | » this,·sys/netinet6·code·defines·its·own·protocol·switch | 2995 | » this,·sys/netinet6·code·defines·its·own·protocol·switch |
2996 | » structure,·as·"struct·ip6protosw"·(see | 2996 | » structure,·as·"struct·ip6protosw"·(see |
2997 | » <code·class="filename">netinet6/ip6protosw.h</code>).··There·is·no·such | 2997 | » <code·class="filename">netinet6/ip6protosw.h</code>).··There·is·no·such |
Offset 3001, 20 lines modified | Offset 3001, 20 lines modified |
3001 | » packet·with·massive·number·of·IPsec·headers,·kernel·stack·may·blow | 3001 | » packet·with·massive·number·of·IPsec·headers,·kernel·stack·may·blow |
3002 | » up.··IPsec-over-IPv6·is·okay.··(Off-course,·for·those·all·IPsec | 3002 | » up.··IPsec-over-IPv6·is·okay.··(Off-course,·for·those·all·IPsec |
3003 | » headers·to·be·processed,·each·such·IPsec·header·must·pass·each | 3003 | » headers·to·be·processed,·each·such·IPsec·header·must·pass·each |
3004 | » IPsec·check.·So·an·anonymous·attacker·will·not·be·able·to·do·such·an | 3004 | » IPsec·check.·So·an·anonymous·attacker·will·not·be·able·to·do·such·an |
3005 | » attack.)</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="icmpv6"></a>8.1.1.9.·ICMPv6</h4></div></div></div><p>After·RFC2463·was·published,·IETF·ipngwg·has·decided·to | 3005 | » attack.)</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="icmpv6"></a>8.1.1.9.·ICMPv6</h4></div></div></div><p>After·RFC2463·was·published,·IETF·ipngwg·has·decided·to |
3006 | » disallow·ICMPv6·error·packet·against·ICMPv6·redirect,·to·prevent | 3006 | » disallow·ICMPv6·error·packet·against·ICMPv6·redirect,·to·prevent |
3007 | » ICMPv6·storm·on·a·network·medium.··This·is·already·implemented | 3007 | » ICMPv6·storm·on·a·network·medium.··This·is·already·implemented |
3008 | » into·the·kernel.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64245688"></a>8.1.1.10.·Applications</h4></div></div></div><p>For·userland·programming,·we·support·IPv6·socket·API·as | 3008 | » into·the·kernel.</p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64303032"></a>8.1.1.10.·Applications</h4></div></div></div><p>For·userland·programming,·we·support·IPv6·socket·API·as |
3009 | » specified·in·RFC2553,·RFC2292·and·upcoming·Internet·drafts.</p><p>TCP/UDP·over·IPv6·is·available·and·quite·stable.··You·can | 3009 | » specified·in·RFC2553,·RFC2292·and·upcoming·Internet·drafts.</p><p>TCP/UDP·over·IPv6·is·available·and·quite·stable.··You·can |
3010 | » enjoy·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=telnet&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">telnet</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=ftp&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">ftp</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=rlogin&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">rlogin</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=rsh&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">rsh</span>(1)</span></a>, | 3010 | » enjoy·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=telnet&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">telnet</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=ftp&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">ftp</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=rlogin&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">rlogin</span>(1)</span></a>,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=rsh&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">rsh</span>(1)</span></a>, |
3011 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=ssh&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">ssh</span>(1)</span></a>,·etc.··These·applications·are·protocol·independent. | 3011 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=ssh&sektion=1&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">ssh</span>(1)</span></a>,·etc.··These·applications·are·protocol·independent. |
3012 | » That·is,·they·automatically·chooses·IPv4·or·IPv6·according·to·DNS. | 3012 | » That·is,·they·automatically·chooses·IPv4·or·IPv6·according·to·DNS. |
3013 | » </p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64251320"></a>8.1.1.11.·Kernel·Internals</h4></div></div></div><p>While·ip_forward()·calls·ip_output(),·ip6_forward()·directly | 3013 | » </p></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64320952"></a>8.1.1.11.·Kernel·Internals</h4></div></div></div><p>While·ip_forward()·calls·ip_output(),·ip6_forward()·directly |
3014 | » calls·if_output()·since·routers·must·not·divide·IPv6·packets·into | 3014 | » calls·if_output()·since·routers·must·not·divide·IPv6·packets·into |
3015 | » fragments.</p><p>ICMPv6·should·contain·the·original·packet·as·long·as·possible | 3015 | » fragments.</p><p>ICMPv6·should·contain·the·original·packet·as·long·as·possible |
3016 | » up·to·1280.··UDP6/IP6·port·unreach,·for·instance,·should·contain | 3016 | » up·to·1280.··UDP6/IP6·port·unreach,·for·instance,·should·contain |
3017 | » all·extension·headers·and·the·*unchanged*·UDP6·and·IP6·headers. | 3017 | » all·extension·headers·and·the·*unchanged*·UDP6·and·IP6·headers. |
3018 | » So,·all·IP6·functions·except·TCP·never·convert·network·byte | 3018 | » So,·all·IP6·functions·except·TCP·never·convert·network·byte |
3019 | » order·into·host·byte·order,·to·save·the·original·packet.</p><p>tcp_input(),·udp6_input()·and·icmp6_input()·can·not·assume·that | 3019 | » order·into·host·byte·order,·to·save·the·original·packet.</p><p>tcp_input(),·udp6_input()·and·icmp6_input()·can·not·assume·that |
3020 | » IP6·header·is·preceding·the·transport·headers·due·to·extension | 3020 | » IP6·header·is·preceding·the·transport·headers·due·to·extension |
Offset 3103, 35 lines modified | Offset 3103, 35 lines modified |
3103 | » itself·is·not·recommended·as·it·does·not·handle·scoped·IPv6·addresses | 3103 | » itself·is·not·recommended·as·it·does·not·handle·scoped·IPv6·addresses |
3104 | » at·all.··For·IPv6·name·resolution,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>·is·the | 3104 | » at·all.··For·IPv6·name·resolution,·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>·is·the |
3105 | » preferred·API.·So·you·should·rewrite·your·application·to·use | 3105 | » preferred·API.·So·you·should·rewrite·your·application·to·use |
3106 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>,·when·you·get·the·time·to·do·it.</p><p>When·writing·applications·that·make·outgoing·connections, | 3106 | » <a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">getaddrinfo</span>(3)</span></a>,·when·you·get·the·time·to·do·it.</p><p>When·writing·applications·that·make·outgoing·connections, |
3107 | » story·goes·much·simpler·if·you·treat·AF_INET·and·AF_INET6·as·totally | 3107 | » story·goes·much·simpler·if·you·treat·AF_INET·and·AF_INET6·as·totally |
3108 | » separate·address·family.··{set,get}sockopt·issue·goes·simpler, | 3108 | » separate·address·family.··{set,get}sockopt·issue·goes·simpler, |
3109 | » DNS·issue·will·be·made·simpler.··We·do·not·recommend·you·to·rely | 3109 | » DNS·issue·will·be·made·simpler.··We·do·not·recommend·you·to·rely |
3110 | » upon·IPv4·mapped·address.</p><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64300088"></a>8.1.1.12.1.·unified·tcp·and·inpcb·code</h5></div></div></div><p>FreeBSD·4.x·uses·shared·tcp·code·between·IPv4·and·IPv6 | 3110 | » upon·IPv4·mapped·address.</p><div·class="sect4"><div·xmlns=""·class="titlepage"><div><div><h5·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64357432"></a>8.1.1.12.1.·unified·tcp·and·inpcb·code</h5></div></div></div><p>FreeBSD·4.x·uses·shared·tcp·code·between·IPv4·and·IPv6 |
3111 | » ··(from·sys/netinet/tcp*)·and·separate·udp4/6·code.··It·uses | 3111 | » ··(from·sys/netinet/tcp*)·and·separate·udp4/6·code.··It·uses |
3112 | » ··unified·inpcb·structure.</p><p>The·platform·can·be·configured·to·support·IPv4·mapped·address. | 3112 | » ··unified·inpcb·structure.</p><p>The·platform·can·be·configured·to·support·IPv4·mapped·address. |
3113 | » ··Kernel·configuration·is·summarized·as·follows:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>By·default,·AF_INET6·socket·will·grab·IPv4 | 3113 | » ··Kernel·configuration·is·summarized·as·follows:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>By·default,·AF_INET6·socket·will·grab·IPv4 |
3114 | » ······connections·in·certain·condition,·and·can·initiate | 3114 | » ······connections·in·certain·condition,·and·can·initiate |
3115 | » ······connection·to·IPv4·destination·embedded·in·IPv4·mapped | 3115 | » ······connection·to·IPv4·destination·embedded·in·IPv4·mapped |
3116 | » ······IPv6·address.</p></li><li·class="listitem"><p>You·can·disable·it·on·entire·system·with·sysctl·like | 3116 | » ······IPv6·address.</p></li><li·class="listitem"><p>You·can·disable·it·on·entire·system·with·sysctl·like |
3117 | » ······below.</p><p> | 3117 | » ······below.</p><p> |
3118 | » ········<code·class="command">sysctl·net.inet6.ip6.mapped_addr=0</code> | 3118 | » ········<code·class="command">sysctl·net.inet6.ip6.mapped_addr=0</code> |
3119 | » ······</p></li></ul></div><div·class="sect5"><div·xmlns=""·class="titlepage"><div><div><h6·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64304312"></a>8.1.1.12.1.1.·listening·side</h6></div></div></div><p>Each·socket·can·be·configured·to·support·special·AF_INET6 | 3119 | » ······</p></li></ul></div><div·class="sect5"><div·xmlns=""·class="titlepage"><div><div><h6·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64361656"></a>8.1.1.12.1.1.·listening·side</h6></div></div></div><p>Each·socket·can·be·configured·to·support·special·AF_INET6 |
3120 | » ····wildcard·bind·(enabled·by·default).··You·can·disable·it·on | 3120 | » ····wildcard·bind·(enabled·by·default).··You·can·disable·it·on |
3121 | » ····each·socket·basis·with·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=setsockopt&sektion=2&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">setsockopt</span>(2)</span></a>·like·below.</p><pre·class="screen">»int·on; | 3121 | » ····each·socket·basis·with·<a·class="citerefentry"·href="http://www.FreeBSD.org/cgi/man.cgi?query=setsockopt&sektion=2&manpath=freebsd-release-ports"><span·class="citerefentry"><span·class="refentrytitle">setsockopt</span>(2)</span></a>·like·below.</p><pre·class="screen">»int·on; |
| |
3122 | » setsockopt(s,·IPPROTO_IPV6,·IPV6_BINDV6ONLY, | 3122 | » setsockopt(s,·IPPROTO_IPV6,·IPV6_BINDV6ONLY, |
3123 | » » ···(char·*)&on,·sizeof·(on))·<·0)); | 3123 | » » ···(char·*)&on,·sizeof·(on))·<·0)); |
3124 | » </pre><p>Wildcard·AF_INET6·socket·grabs·IPv4·connection·if·and·only | 3124 | » </pre><p>Wildcard·AF_INET6·socket·grabs·IPv4·connection·if·and·only |
3125 | » ····if·the·following·conditions·are·satisfied:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>there·is·no·AF_INET·socket·that·matches·the·IPv4 | 3125 | » ····if·the·following·conditions·are·satisfied:</p><div·class="itemizedlist"><ul·class="itemizedlist"·style="list-style-type:·disc;·"><li·class="listitem"><p>there·is·no·AF_INET·socket·that·matches·the·IPv4 |
3126 | » » connection</p></li><li·class="listitem"><p>the·AF_INET6·socket·is·configured·to·accept·IPv4 | 3126 | » » connection</p></li><li·class="listitem"><p>the·AF_INET6·socket·is·configured·to·accept·IPv4 |
3127 | » » traffic,·i.e.··getsockopt(IPV6_BINDV6ONLY)·returns·0.</p></li></ul></div><p>There·is·no·problem·with·open/close·ordering.</p></div><div·class="sect5"><div·xmlns=""·class="titlepage"><div><div><h6·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64309304"></a>8.1.1.12.1.2.·initiating·side</h6></div></div></div><p>FreeBSD·4.x·supports·outgoing·connection·to·IPv4·mapped | 3127 | » » traffic,·i.e.··getsockopt(IPV6_BINDV6ONLY)·returns·0.</p></li></ul></div><p>There·is·no·problem·with·open/close·ordering.</p></div><div·class="sect5"><div·xmlns=""·class="titlepage"><div><div><h6·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64366648"></a>8.1.1.12.1.2.·initiating·side</h6></div></div></div><p>FreeBSD·4.x·supports·outgoing·connection·to·IPv4·mapped |
3128 | » ····address·(::ffff:10.1.1.1),·if·the·node·is·configured·to·support | 3128 | » ····address·(::ffff:10.1.1.1),·if·the·node·is·configured·to·support |
3129 | » ····IPv4·mapped·address.</p></div></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64314808"></a>8.1.1.13.·sockaddr_storage</h4></div></div></div><p>When·RFC2553·was·about·to·be·finalized,·there·was·discussion·on | 3129 | » ····IPv4·mapped·address.</p></div></div></div><div·class="sect3"><div·xmlns=""·class="titlepage"><div><div><h4·xmlns="http://www.w3.org/1999/xhtml"·class="title"><a·id="idp64372152"></a>8.1.1.13.·sockaddr_storage</h4></div></div></div><p>When·RFC2553·was·about·to·be·finalized,·there·was·discussion·on |
3130 | » how·struct·sockaddr_storage·members·are·named.··One·proposal·is·to | 3130 | » how·struct·sockaddr_storage·members·are·named.··One·proposal·is·to |
3131 | » prepend·"__"·to·the·members·(like·"__ss_len")·as·they·should·not·be | 3131 | » prepend·"__"·to·the·members·(like·"__ss_len")·as·they·should·not·be |
3132 | » touched.··The·other·proposal·was·not·to·prepend·it·(like·"ss_len") | 3132 | » touched.··The·other·proposal·was·not·to·prepend·it·(like·"ss_len") |
3133 | » as·we·need·to·touch·those·members·directly.··There·was·no·clear | 3133 | » as·we·need·to·touch·those·members·directly.··There·was·no·clear |
3134 | » consensus·on·it.</p><p>As·a·result,·RFC2553·defines·struct·sockaddr_storage·as | 3134 | » consensus·on·it.</p><p>As·a·result,·RFC2553·defines·struct·sockaddr_storage·as |
3135 | » follows:</p><pre·class="screen">»struct·sockaddr_storage·{ | 3135 | » follows:</p><pre·class="screen">»struct·sockaddr_storage·{ |
3136 | » » u_char» __ss_len;» /*·address·length·*/ | 3136 | » » u_char» __ss_len;» /*·address·length·*/ |
Offset 3148, 64 lines modified | Offset 3148, 64 lines modified |
3148 | » RFC2553bis·discussion.</p><p>If·you·look·at·multiple·IPv6·implementations,·you·will·be·able | 3148 | » RFC2553bis·discussion.</p><p>If·you·look·at·multiple·IPv6·implementations,·you·will·be·able |