博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
jerry的小窝
The best way to solve a complex problem is to break it down into component parts, learn each of the parts, and learn how the parts go together. --- R. L. Graham
jarodlau.cublog.cn
管理博客
发表文章
留言
收藏夹
· emacs相关
· hack
· kernel
· linux应用
· linux开发
· 编程
博客圈
音乐
相册
导入文章
文章
· hardware
· kernel
· program
· ubuntu
· vim
· Emacs相关
· 日记随笔
· 音乐
首页
关于作者
姓名:jerry 个性介绍:get free 信仰:free
||
<<
>>
||
我的分类
最新文章
·
Dual monitor in Ubuntu ..
·
BinaryDriverHowtoDynami..
·
Ubuntu中恢复默认的任务栏..
·
利用libnet实现linux上的..
·
Ubuntu 10.04后安装指南
最新留言
·
xiaorongmei
请问你能告诉我那里能下载..
·
xuanfei
写的很好 很专业 !学习了!
最新评论
·
网友: 本站网友 时间:2..
·
我最近正准备在MID上开发一..
·
不错
·
It's a great challenge.
·
SAP99,支持下,也欢迎访问..
最新收藏
·
ubuntu中文论坛
·
!!!emacs--tut
·
!!!emacs-教程
·
★dancefire
·
★xueruini's home page★
统计信息
·
总访问量:145071
·
文章个数:161
·
评论条数:24
·
留言条数:2
·
网友推荐:
【置顶】Visual Studio 2008 简体中文正式版下载及序列号(无使用期限限制,正式版)
查看全文
发表于:2010-04-12 ┆
阅读(47)
┆
评论(0)
【置顶】用语言控制Linux:Linux的语音识别软件
<P><STRONG><FONT face=幼圆 size=4></FONT></STRONG> </P> <OL> <LI><STRONG><FONT face=幼圆 size=4> <DIV class=intro><FONT color=#ff0000>开源语音识别软件</FONT><A href="http://sourceforge.net/pro……
查看全文
发表于:2008-06-02 ┆
阅读(487)
┆
评论(0)
Dual monitor in Ubuntu Linux
<p>Yippee!!! I got dual monitor working with Ubuntu 9.04. Check the screenshot at the bottom of the post.</p> <p>I bought <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16814133279" target="_blank">NVidia GeForce 9800 GT</a> 2 months back. <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16814133279" target="_blank">Newegg</a> had a good deal on it (I think they still have). The card is energy efficient and quiet. I don’t play lots of games, so I don’t know how high the temperature goes. For normal operation in Ubuntu, the temperature stays anywhere between 46C to 54C. Installing the card in Ubuntu was smooth and Ubuntu automatically detected the card and asked me to enable the NVidia proprietary driver. I’m not sure how to increase the fan speed of the card in Ubuntu.</p> <p>I also bought an ASUS VH236H 23″ widescreen 1080p monitor from <a href="http://www.buy.com/retail/product.asp?sku=210917291" target="_blank">Buy.com</a>. They had a good deal on that monitor. I wanted to buy a glossy monitor since my laptop, HDTV etc. are matte finish (for better reason), but this monitor is also matte. It has glossy bezel, but the screen is matte. I don’t regret buying this monitor after using it for a month. The pictures are crisp clear. It has 2ms response time, 1920*1080 resolution (1080p), 5 preset modes, It’s energy star rated. It has HDMI, DVI and VGA inputs, so I can use this as HDTV. It also has built in speakers, but I don’t use that. The only negative thing is, the stand is not height adjustable.</p> <p>I connected my old 19″ Samsung monitor and the new one to the NVidia GeForce 9800 GT video card using the VGA to DVI connector (old monitor) and DVI (new one) cables. After I started Ubuntu, I went to NVidia settings manager and saw the 2 monitors under X Server display configuration. The 2nd monitor (old one) was disabled by default. I clicked on the 2nd monitor picture and clicked on Configure button. I was then presented with 3 options (shown below).</p> <p><img style="max-width: 800px;" src="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/Screenshot-Configure-Display-Device.png" alt=""></p> <p>I first selected Seperate X screen, thinking I would use them as 2 different monitor, but that didn’t work. When I selected that, only the 2nd monitor worked. I then selected the TwinView option which then spreaded my desktop across both monitors. In Twinview, you’ll see the taskbar, menu etc in only one monitor. You can move the application across both monitors. When I enabled TwinView, I believe, due to the way I connected the monitors to the dual DVI outputs in the video card, my old 19″ monitor was taken as default with menus and taskbars and the new 23″ was used as an extended monitor. All I have to do then was to click on my primary 23″ monitor and put +0+0 under position and on my secondary monitor, added +1920+0 where 1920 is the primary 23″ monitor resolution. Doing that made my new monitor as primary and the old one as secondary.</p> <p><a href="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/Screenshot-NVIDIA-X-Server-Settings.png"><img style="max-width: 800px;" src="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/Screenshot-NVIDIA-X-Server-Settings.png" alt="" height="397" width="422"></a><br> (Primary 23# monitor)</p> <p><a href="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/Screenshot-NVIDIA-X-Server-Settings-1.png"><img style="max-width: 800px;" src="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/Screenshot-NVIDIA-X-Server-Settings-1.png" alt="" height="397" width="422"></a><br> (Secondary 19″ monitor)</p> <p>Another major problem I encountered was trying to save the configuration. I tried to save the settings by clicking Save to X Configuration File button, but it said I didn’t have permission to write to Xorg.conf file. I then tried starting the NVidia settings manager under super user (sudo) mode and tried the same. It still didn’t work. What I then did was, I made a backup of xorg.conf file, opened a terminal and opened the xorg.conf file using sudo gedit /etc/X11/xorg.conf, deleted everything in that file, then went back to NVidia control panel, set the monitors as I explained above, clicked the save to X configuration button in the NVidia control panel (under X Server display configuration) . When you click the save button, I think you will see a preview button to see the new xorg code. Click the preview button, copy the code and paste that code in xorg.conf file, save and close it. Restart Ubuntu and it should work.</p> <p><a href="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/IMG_2949.JPG"><img style="max-width: 800px;" src="http://www.blog.arun-prabha.com/wp-content/uploads/2009/10/IMG_2949.JPG" alt="" height="360" width="480"></a></p>
查看全文
发表于:2010-05-18 ┆
阅读(43)
┆
评论(0)
BinaryDriverHowtoDynamicMultiMonitor
Here's a quick little script I wrote to set the proper display when I'm at work. <span class="anchor" id="line-4"></span><span class="anchor" id="line-5"></span><p class="line867"> </p><h1 id="The Situation">The Situation</h1> <span class="anchor" id="line-6"></span><span class="anchor" id="line-7"></span><p class="line874">I work at three primary places: home, office one, and office two. <span class="anchor" id="line-8"></span><span class="anchor" id="line-9"></span></p><p class="line874">At home, I just use my laptop. At office one I have a 22" monitor and at office two I have a 24" monitor. Obviously, the resolutions are different and when I connect to them I want my displays to be set perfectly. <span class="anchor" id="line-10"></span><span class="anchor" id="line-11"></span></p><p class="line874">My laptop is always to the right of my external monitor. Here is a picture of office one's setup: <span class="anchor" id="line-12"></span><span class="anchor" id="line-13"></span></p><p class="line867"><img alt="My Desktop" class="attachment" src="https://help.ubuntu.com/community/BinaryDriverHowto/DynamicMultiMonitor?action=AttachFile&do=get&target=itm-desktop-layout.jpg" title="My Desktop" width="800"> <span class="anchor" id="line-14"></span><span class="anchor" id="line-15"></span></p><p class="line874">As you can see the laptop is to the left and lower than my external monitor. <span class="anchor" id="line-16"></span><span class="anchor" id="line-17"></span></p><p class="line867"> </p><h1 id="XRandR To The Rescue!">XRandR To The Rescue!</h1> <span class="anchor" id="line-18"></span><span class="anchor" id="line-19"></span>XRandR is a powerful little utility, and with the proper amount of psychology, and extreme violence, I was able to have it do my bidding. What follows is the small shell script I wrote to control, dynamically, the external monitor settings.<br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(255, 153, 0);">#!/bin/sh<br> </span><br> <br> <span style="color: rgb(255, 153, 0);"># Sets the secondary display to the proper resolution if attached.<br> </span><br> <br> LAPTOP<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"LVDS"</span><br> HAVE_HDMI<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"`xrandr | grep 'HDMI-0 connected' | wc -l`"</span><br> HAVE_DFP<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"`xrandr | grep 'DFP1 connected' | wc -l`"</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">[</span> <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">HAVE_HDMI</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">"1"</span> <span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">;</span> then<br> EXTERNAL_OUTPUT<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"HDMI-0"</span><br> elif <span style="color: rgb(0, 0, 204);">[</span> <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">HAVE_DFP</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">"1"</span> <span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">;</span> then<br> EXTERNAL_OUTPUT<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"DFP1"</span><br> <span style="color: rgb(0, 0, 255);">else</span><br> EXTERNAL_OUTPUT<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">""</span><br> fi<br> <br> AT_OFFICE1<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"`ifconfig eth0 | grep 'addr:192.168.15.' | wc -l`"</span><br> AT_OFFICE2<span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(255, 0, 255);">"`ifconfig eth0 | grep 'addr:10.0.1.' | wc -l`"</span><br> <br> xrandr <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>output <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">LAPTOP</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>preferred<br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">[</span> <span style="color: rgb(0, 0, 204);">!</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 255);">x</span> <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">EXTERNAL_OUTPUT</span> <span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">;</span> then<br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">[</span> <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">AT_OFFICE2</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">"1"</span> <span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">;</span> then<br> xrandr <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>output <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">EXTERNAL_OUTPUT</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>mode <span style="color: rgb(255, 0, 255);">"1680x1050"</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">pos</span> 1600x0 <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>primary <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>output <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">LAPTOP</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>mode <span style="color: rgb(255, 0, 255);">"1600x900"</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">pos</span> 0x500<br> fi<br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">[</span> <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">AT_OFFICE1</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">"1"</span> <span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">;</span> then<br> xrandr <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>output <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">EXTERNAL_OUTPUT</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>mode <span style="color: rgb(255, 0, 255);">"1920x1080"</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">pos</span> 1600x0 <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>primary <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>output <span style="color: rgb(0, 0, 255);">$</span><span style="color: rgb(0, 128, 128);">LAPTOP</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>mode <span style="color: rgb(255, 0, 255);">"1600x900"</span> <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">pos</span> 0x500<br> fi<br> fi<br> </span></code></p></td></tr></tbody></table><br><p class="line874">First a disclaimer: I am no shell script expert. <span class="anchor" id="line-55"></span><span class="anchor" id="line-56"></span></p><p class="line862">My laptop's display is called <strong>LVDS</strong>. My external monitor is <strong>DFP1</strong>. However, when using the open source ATI drivers, it is called <strong>HDMI-0</strong>. Since I've been known to switch between the proprietary and open-source drivers, this script handles both. Obviously, if your external display name is different, just change it. <span class="anchor" id="line-57"></span><span class="anchor" id="line-58"></span></p><p class="line862">The script queries XRandR for the state of both HDMI-0 and DFP1. If either are in a <strong>connected</strong> state, the associated variable is set to a value of "1". I never learned sed and awk so I use the poor man's version: <tt>grep and wc</tt>. <span class="anchor" id="line-59"></span><span class="anchor" id="line-60"></span></p><p class="line862">Since both my monitors are named the same at both offices, I rely on my ethernet connection's IP address to determine where I am. Here I query <tt>ifconfig eth0</tt> for the currently assigned IP address. Each office uses a different subnet so I'm safe. <span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span></p><p class="line874">Checking these values, I'm able to determine where I am and what display is connected. Now the fun begins. Well, it's not really fun... <span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span></p><p class="line862">If my external output is connected <tt>$EXTERNAL_OUTPUT</tt> I run an XRandR command to set it up the way I like it. <span class="anchor" id="line-65"></span><span class="anchor" id="line-66"></span></p><p class="line862">My laptop is 1600x900 at all times. Therefore my external output offset is 1600. This is set in the <tt>--pos 1600x0</tt> statement. I also tell XRandR that this is my primary monitor with the <tt>--primary</tt> command. <span class="anchor" id="line-67"></span><span class="anchor" id="line-68"></span></p><p class="line862">Next, my laptop is always below my external monitor's viewport. I like my virtual space to mimic reality. Therefore I set my laptop display to be 500 pixels <strong>below</strong> the top of my external monitor's viewport. This is done with the <tt>--pos 0x500</tt> in the second half of the XRandR call. <span class="anchor" id="line-69"></span><span class="anchor" id="line-70"></span></p><p class="line862">And that is it. I named this script <strong><tt>setDisplay.sh</tt></strong> and placed it in my <tt>~/.kde/Autostart</tt> directory. <span class="anchor" id="line-71"></span><span class="anchor" id="line-72"></span></p><p class="line862">If you have several users who need to share this script, place it in your <tt>/usr/local/bin</tt> directory. <span class="anchor" id="line-73"></span><span class="anchor" id="line-74"></span></p>The final step is to make it executable: <br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">jablan<span style="color: rgb(0, 0, 255);">@</span><span style="color: rgb(128, 128, 0);">lucifurious</span><span style="color: rgb(0, 0, 204);">:</span><span style="color: rgb(0, 0, 204);">~</span><span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">.</span>kde<span style="color: rgb(0, 0, 204);">/</span>Autostart<span style="color: rgb(0, 0, 255);">$</span> <span style="color: rgb(255, 0, 0);">chmod</span> <span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 255);">x</span> <span style="color: rgb(0, 0, 204);">.</span><span style="color: rgb(0, 0, 204);">/</span>setDisplay<span style="color: rgb(0, 0, 204);">.</span>sh<br> </span></code></p></td></tr></tbody></table><br>or, if it's in <tt>/usr/local/bin</tt>: <br><br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">jablan<span style="color: rgb(0, 0, 255);">@</span><span style="color: rgb(128, 128, 0);">lucifurious</span><span style="color: rgb(0, 0, 204);">:</span><span style="color: rgb(0, 0, 204);">~</span><span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">.</span>kde<span style="color: rgb(0, 0, 204);">/</span>Autostart<span style="color: rgb(0, 0, 255);">$</span> <span style="color: rgb(255, 0, 0);">chmod</span> <span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 255);">x</span> <span style="color: rgb(0, 0, 204);">/</span>usr<span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 255);">local</span><span style="color: rgb(0, 0, 204);">/</span>bin<span style="color: rgb(0, 0, 204);">/</span>setDisplay<span style="color: rgb(0, 0, 204);">.</span>sh<br> </span></code></p></td></tr></tbody></table><br>
查看全文
发表于:2010-05-18 ┆
阅读(38)
┆
评论(0)
Ubuntu中恢复默认的任务栏面板
<p>在Ubuntu中,桌面上默认的任务栏菜单面板是上下两栏,上面是系统菜单和通知区域<br> 下面是窗口存放切换区域,那么作为ubuntu用户来说,你总会使系统用起来更顺手更美观<br> 从而会对面板定制成自己想要的,比如说用<a href="http://www.ubuntuhome.com/ubuntu-avant-window-navigator.html">DOCK</a>来 代替?<br> 或者你不小心会把它们删除掉,那么,我们怎么使它可以恢复成默认的样子呢?下面是解决办法:</p> <p>打开终端,输入以下命令:</p> <blockquote><p>gconftool --recursive-unset /apps/panel</p></blockquote> <p><span id="more-525"></span><br> 这时你会发现所有的面板都不现了,接着再输入下列命令:</p> <blockquote><p>rm -rf ~/.gconf/apps/panel</p></blockquote> <p>最后执行:</p> <blockquote><p>pkill gnome-panel</p></blockquote> <p>你会发现,你的面板已经起死回生了 <img src="http://www.ubuntuhome.com/wp-includes/images/smilies/icon_confused.gif" alt=":???:" class="wp-smiley"> </p>
查看全文
发表于:2010-05-18 ┆
阅读(79)
┆
评论(0)
利用libnet实现linux上的"网络执法官"
以前读书<span href="http://bbs.chinaunix.net/tag.php?name=%CA%B1%B4%FA" onclick="tagshow(event)" class="t_tag">时代</span>,windows上有个<span href="http://bbs.chinaunix.net/tag.php?name=%CD%F8%C2%E7" onclick="tagshow(event)" class="t_tag">网络</span><span href="http://bbs.chinaunix.net/tag.php?name=%C8%ED%BC%FE" onclick="tagshow(event)" class="t_tag">软件</span>叫"网络执法官",相信很多朋友都用过,局域网中发 现谁在bt,自己网页都打不开,很不爽,直接去跟他说恐怕又得罪人,怎么办,打开网络执法官,简单配置一下,让他上不了网.<br> <br> 当然现在的网络执法官版本功能已经很丰富了,但其原理还是跟以前一样,利用了arp欺骗,填上想要伪造的网关地址,然后网络执法官会在lan内广播免费 arp报文,其余机器就出不了外网了.一句话:很强,很暴力! <img src="http://bbs.chinaunix.net/images/smilies/default/icon_smile.gif" smilieid="31" alt="" border="0"><br> <br> Linux上实现,需要直接构造arp帧,利用其他<span href="http://bbs.chinaunix.net/tag.php?name=%BC%BC%CA%F5" onclick="tagshow(event)" class="t_tag">技术</span>,非常复杂,而用libnet这个开源库,核心代码 只要几十行即可搞定.<br> <br> 大多数<span href="http://bbs.chinaunix.net/tag.php?name=linux" onclick="tagshow(event)" class="t_tag">linux</span>发行版和其他<span href="http://bbs.chinaunix.net/tag.php?name=unix" onclick="tagshow(event)" class="t_tag">unix</span><span href="http://bbs.chinaunix.net/tag.php?name=%CF%B5%CD%B3" onclick="tagshow(event)" class="t_tag">系统</span>都自带了libnet. 看看你的系统中有没有libnet-config这个命令即可知道.<br> 没有的可以到它的主页下载安装:<br> <a href="http://www.packetfactory.net/libnet" target="_blank">http://www.packetfactory.net/libnet</a><br> <br> 另外请确认你的系统上的是1.1还是1.0版本,两个版本API很不一样,这里用的是最新的1.1,如果你不是,请升级.<br> <br> <br> <table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">gcc garp<span style="color: rgb(0, 0, 204);">.</span>c <span style="color: rgb(0, 0, 204);">-</span>o garp <span style="color: rgb(0, 0, 204);">-</span>lnet</span></code></p></td></tr></tbody></table><br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">运行<span style="color: rgb(0, 0, 204);">:</span><br> <span style="color: rgb(0, 0, 204);">-</span>h看命令行<span style="color: rgb(0, 0, 204);">,</span><br> <span style="color: rgb(0, 0, 204);">-</span>f指定出接口<span style="color: rgb(0, 0, 204);">,</span>没指定的话会自带选择一个接口<span style="color: rgb(0, 0, 204);">,</span><br> <span style="color: rgb(0, 0, 204);">-</span>t指定免费arp包的发送间隔时间<span style="color: rgb(0, 0, 204);">,</span>默认5秒<span style="color: rgb(0, 0, 204);">,</span><br> 例<span style="color: rgb(0, 0, 204);">:</span><br> <span style="color: rgb(0, 0, 204);">.</span><span style="color: rgb(0, 0, 204);">/</span>garp <span style="color: rgb(0, 0, 204);">-</span>f eth0 192<span style="color: rgb(0, 0, 204);">.</span>168<span style="color: rgb(0, 0, 204);">.</span>1<span style="color: rgb(0, 0, 204);">.</span>1 192<span style="color: rgb(0, 0, 204);">.</span>168<span style="color: rgb(0, 0, 204);">.</span>2<span style="color: rgb(0, 0, 204);">.</span>1</span></code></p></td></tr></tbody></table><br><br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>sys<span style="color: rgb(0, 0, 204);">/</span>types<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>unistd<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>stdlib<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span><span style="color: rgb(255, 0, 0);">time</span><span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>sys<span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(255, 0, 0);">socket</span><span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>netinet<span style="color: rgb(0, 0, 204);">/</span>in<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>arpa<span style="color: rgb(0, 0, 204);">/</span>inet<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>sys<span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(255, 0, 0);">select</span><span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">include</span> <span style="color: rgb(0, 0, 204);"><</span>libnet<span style="color: rgb(0, 0, 204);">.</span>h<span style="color: rgb(0, 0, 204);">></span><br> <br> <span style="color: rgb(0, 0, 204);">#</span><span style="color: rgb(255, 0, 0);">define</span> MAX_IP_NUM 32<br> <br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span>pname <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">""</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span>ifname <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">struct</span> <span style="color: rgb(255, 0, 0);">in_addr</span> ipaddrs<span style="color: rgb(0, 0, 204);">[</span>MAX_IP_NUM<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">int</span> timer <span style="color: rgb(0, 0, 204);">=</span> 5<span style="color: rgb(0, 0, 204);">;</span><br> <br> <br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">int</span><br> get_hw_addr<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span>dev<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> macbuf<span style="color: rgb(0, 0, 204);">[</span>6<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 204);">{</span><br> libnet_t <span style="color: rgb(0, 0, 204);">*</span>l<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">char</span> errbuf<span style="color: rgb(0, 0, 204);">[</span>LIBNET_ERRBUF_SIZE<span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">""</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">struct</span> libnet_ether_addr <span style="color: rgb(0, 0, 204);">*</span>mac<span style="color: rgb(0, 0, 204);">;</span><br> <br> l <span style="color: rgb(0, 0, 204);">=</span> libnet_init<span style="color: rgb(0, 0, 204);">(</span>LIBNET_LINK<span style="color: rgb(0, 0, 204);">,</span> dev<span style="color: rgb(0, 0, 204);">,</span> errbuf<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span>l<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_init: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> errbuf<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> mac <span style="color: rgb(0, 0, 204);">=</span> libnet_get_hwaddr<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span>mac<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_get_hwaddr: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> libnet_geterror<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> libnet_destroy<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(255, 0, 0);">memcpy</span><span style="color: rgb(0, 0, 204);">(</span>macbuf<span style="color: rgb(0, 0, 204);">,</span> mac<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>ether_addr_octet<span style="color: rgb(0, 0, 204);">,</span> 6<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> libnet_destroy<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 255);">return</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">int</span><br> send_garp<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span>ifname<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(0, 0, 255);">long</span> ipaddr<span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> bcast_mac<span style="color: rgb(0, 0, 204);">[</span>6<span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">{</span>0xff<span style="color: rgb(0, 0, 204);">,</span> 0xff<span style="color: rgb(0, 0, 204);">,</span> 0xff<span style="color: rgb(0, 0, 204);">,</span> 0xff<span style="color: rgb(0, 0, 204);">,</span> 0xff<span style="color: rgb(0, 0, 204);">,</span> 0xff<span style="color: rgb(0, 0, 204);">}</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> zero_mac<span style="color: rgb(0, 0, 204);">[</span>6<span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">{</span>0x00<span style="color: rgb(0, 0, 204);">,</span> 0x00<span style="color: rgb(0, 0, 204);">,</span> 0x00<span style="color: rgb(0, 0, 204);">,</span> 0x00<span style="color: rgb(0, 0, 204);">,</span> 0x00<span style="color: rgb(0, 0, 204);">,</span> 0x00<span style="color: rgb(0, 0, 204);">}</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> mymac<span style="color: rgb(0, 0, 204);">[</span>6<span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">{</span>0x00<span style="color: rgb(0, 0, 204);">}</span><span style="color: rgb(0, 0, 204);">;</span><br> libnet_t <span style="color: rgb(0, 0, 204);">*</span>l<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">char</span> errbuf<span style="color: rgb(0, 0, 204);">[</span>LIBNET_ERRBUF_SIZE<span style="color: rgb(0, 0, 204);">]</span> <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 255);">""</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">int</span> i<span style="color: rgb(0, 0, 204);">,</span> ret <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>get_hw_addr<span style="color: rgb(0, 0, 204);">(</span>ifname<span style="color: rgb(0, 0, 204);">,</span> mymac<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">!</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> l <span style="color: rgb(0, 0, 204);">=</span> libnet_init<span style="color: rgb(0, 0, 204);">(</span>LIBNET_LINK<span style="color: rgb(0, 0, 204);">,</span> ifname<span style="color: rgb(0, 0, 204);">,</span> errbuf<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span>l<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_init: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> errbuf<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">for</span> <span style="color: rgb(0, 0, 204);">(</span>i <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span> i <span style="color: rgb(0, 0, 204);"><</span> 2<span style="color: rgb(0, 0, 204);">;</span> i<span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>libnet_build_arp<span style="color: rgb(0, 0, 204);">(</span>ARPHRD_ETHER<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* hardware address type */</span><br> ETHERTYPE_IP<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* protocol address type */</span><br> 6<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* Hardware address length */</span><br> 4<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* protocol address length */</span><br> <span style="color: rgb(0, 0, 204);">(</span>i <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">?</span> ARPOP_REQUEST <span style="color: rgb(0, 0, 204);">:</span> ARPOP_REPLY<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* ARP operation type */</span><br> mymac<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* sender Hardware address */</span><br> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">&</span>ipaddr<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* sender protocol address */</span><br> <span style="color: rgb(0, 0, 204);">(</span>i <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">?</span> zero_mac <span style="color: rgb(0, 0, 204);">:</span> mymac<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* target hardware address */</span><br> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">unsigned</span> <span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">&</span>ipaddr<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* target protocol address */</span><br> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* Payload */</span><br> 0<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* Length of payload */</span><br> l<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 153, 0);">/* libnet context pointer */</span><br> 0 <span style="color: rgb(255, 153, 0);">/* packet id */</span><br> <span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1 <span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_build_arp: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> libnet_geterror<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> ret <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>libnet_build_ethernet<span style="color: rgb(0, 0, 204);">(</span>bcast_mac<span style="color: rgb(0, 0, 204);">,</span> mymac<span style="color: rgb(0, 0, 204);">,</span> ETHERTYPE_ARP<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">,</span> 0<span style="color: rgb(0, 0, 204);">,</span><br> l<span style="color: rgb(0, 0, 204);">,</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1 <span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_build_ethernet: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> libnet_geterror<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> ret <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>libnet_write<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"libnet_write: %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> libnet_geterror<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> ret <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> libnet_clear_packet<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>i <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">struct</span> <span style="color: rgb(255, 0, 0);">timespec</span> ts<span style="color: rgb(0, 0, 204);">;</span><br> ts<span style="color: rgb(0, 0, 204);">.</span>tv_sec <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> ts<span style="color: rgb(0, 0, 204);">.</span>tv_nsec <span style="color: rgb(0, 0, 204);">=</span> 500 <span style="color: rgb(0, 0, 204);">*</span> 1000 <span style="color: rgb(0, 0, 204);">*</span> 1000<span style="color: rgb(0, 0, 204);">;</span> <span style="color: rgb(255, 153, 0);">/* sleep 500 ms between the two frame. */</span><br> <span style="color: rgb(255, 0, 0);">nanosleep</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">&</span>ts<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> libnet_destroy<span style="color: rgb(0, 0, 204);">(</span>l<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 255);">return</span> ret<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">void</span><br> usage<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stdout</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"Usage:\n"</span><br> <span style="color: rgb(255, 0, 255);">" %s [-h] [-f interface] [-t time] ipaddr1 [ipaddr2 ipaddr3 ...]\n"</span><span style="color: rgb(0, 0, 204);">,</span><br> pname<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span> <br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">int</span><br> main<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 255);">int</span> argc<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(0, 0, 255);">char</span> <span style="color: rgb(0, 0, 204);">*</span>argv<span style="color: rgb(0, 0, 204);">[</span><span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">int</span> ret<span style="color: rgb(0, 0, 204);">,</span> opt<span style="color: rgb(0, 0, 204);">,</span> i<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">struct</span> <span style="color: rgb(255, 0, 0);">timeval</span> tv<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">int</span> errnum<span style="color: rgb(0, 0, 204);">;</span><br> <br> pname <span style="color: rgb(0, 0, 204);">=</span> strrchr<span style="color: rgb(0, 0, 204);">(</span>argv<span style="color: rgb(0, 0, 204);">[</span>0<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">'/'</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>pname<span style="color: rgb(0, 0, 204);">)</span><br> pname<span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">else</span><br> pname <span style="color: rgb(0, 0, 204);">=</span> argv<span style="color: rgb(0, 0, 204);">[</span>0<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 255);">while</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">(</span>opt <span style="color: rgb(0, 0, 204);">=</span> getopt<span style="color: rgb(0, 0, 204);">(</span>argc<span style="color: rgb(0, 0, 204);">,</span> argv<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"hf:t:"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">!</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">switch</span> <span style="color: rgb(0, 0, 204);">(</span>opt<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">case</span> <span style="color: rgb(255, 0, 255);">'h'</span><span style="color: rgb(0, 0, 204);">:</span><br> usage<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">case</span> <span style="color: rgb(255, 0, 255);">'f'</span><span style="color: rgb(0, 0, 204);">:</span><br> ifname <span style="color: rgb(0, 0, 204);">=</span> strdup<span style="color: rgb(0, 0, 204);">(</span>optarg<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span>ifname<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"strdup failed.\n"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">case</span> <span style="color: rgb(255, 0, 255);">'t'</span><span style="color: rgb(0, 0, 204);">:</span><br> timer <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 0);">atoi</span><span style="color: rgb(0, 0, 204);">(</span>optarg<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>timer <span style="color: rgb(0, 0, 204);"><</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"timer value is invalid.\n"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 204);">:</span><br> usage<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>optind <span style="color: rgb(0, 0, 204);">></span><span style="color: rgb(0, 0, 204);">=</span> argc<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> usage<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> i <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span> <br> <span style="color: rgb(0, 0, 255);">while</span> <span style="color: rgb(0, 0, 204);">(</span>optind <span style="color: rgb(0, 0, 204);"><</span> argc <span style="color: rgb(0, 0, 204);">&</span><span style="color: rgb(0, 0, 204);">&</span> i <span style="color: rgb(0, 0, 204);"><</span> MAX_IP_NUM<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>inet_aton<span style="color: rgb(0, 0, 204);">(</span>argv<span style="color: rgb(0, 0, 204);">[</span>optind<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(0, 0, 204);">&</span>ipaddrs<span style="color: rgb(0, 0, 204);">[</span>i<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stderr</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"ip addr error.\n"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> optind<span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> i <span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stdout</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"ifname: %s, timer: %d\n"</span><span style="color: rgb(0, 0, 204);">,</span><br> ifname <span style="color: rgb(0, 0, 204);">?</span> ifname <span style="color: rgb(0, 0, 204);">:</span> <span style="color: rgb(255, 0, 255);">"<NULL>"</span><span style="color: rgb(0, 0, 204);">,</span><br> timer<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stdout</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">"ip:\n"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> i <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">while</span> <span style="color: rgb(0, 0, 204);">(</span>ipaddrs<span style="color: rgb(0, 0, 204);">[</span>i<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">.</span>s_addr <span style="color: rgb(0, 0, 204);">&</span><span style="color: rgb(0, 0, 204);">&</span> i <span style="color: rgb(0, 0, 204);"><</span> MAX_IP_NUM<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(255, 0, 0);">fprintf</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">stdout</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 255);">" %s\n"</span><span style="color: rgb(0, 0, 204);">,</span> inet_ntoa<span style="color: rgb(0, 0, 204);">(</span>ipaddrs<span style="color: rgb(0, 0, 204);">[</span>i<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> i<span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> errnum <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">while</span> <span style="color: rgb(0, 0, 204);">(</span>1<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> tv<span style="color: rgb(0, 0, 204);">.</span>tv_sec <span style="color: rgb(0, 0, 204);">=</span> timer<span style="color: rgb(0, 0, 204);">;</span><br> tv<span style="color: rgb(0, 0, 204);">.</span>tv_usec <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <br> ret <span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(255, 0, 0);">select</span><span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(255, 0, 0);">NULL</span><span style="color: rgb(0, 0, 204);">,</span> <span style="color: rgb(0, 0, 204);">&</span>tv<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>ret <span style="color: rgb(0, 0, 204);"><</span> 0<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 0);">errno</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> EINTR <span style="color: rgb(0, 0, 204);">|</span><span style="color: rgb(0, 0, 204);">|</span> <span style="color: rgb(255, 0, 0);">errno</span> <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> EAGAIN<span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">perror</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 255);">"select"</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">-</span>1<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> i <span style="color: rgb(0, 0, 204);">=</span> 0<span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 255);">while</span> <span style="color: rgb(0, 0, 204);">(</span>ipaddrs<span style="color: rgb(0, 0, 204);">[</span>i<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">.</span>s_addr <span style="color: rgb(0, 0, 204);">&</span><span style="color: rgb(0, 0, 204);">&</span> i <span style="color: rgb(0, 0, 204);"><</span> MAX_IP_NUM<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);">{</span><br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>send_garp<span style="color: rgb(0, 0, 204);">(</span>ifname<span style="color: rgb(0, 0, 204);">,</span> ipaddrs<span style="color: rgb(0, 0, 204);">[</span>i<span style="color: rgb(0, 0, 204);">]</span><span style="color: rgb(0, 0, 204);">.</span>s_addr<span style="color: rgb(0, 0, 204);">)</span> <span style="color: rgb(0, 0, 204);"><</span> 0<span style="color: rgb(0, 0, 204);">)</span><br> errnum<span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> i <span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">+</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(0, 0, 255);">if</span> <span style="color: rgb(0, 0, 204);">(</span>errnum <span style="color: rgb(0, 0, 204);">></span><span style="color: rgb(0, 0, 204);">=</span> 10<span style="color: rgb(0, 0, 204);">)</span><br> <span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span><br> <br> <span style="color: rgb(255, 0, 0);">exit</span><span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> <span style="color: rgb(0, 0, 204);">}</span></span></code></p></td></tr></tbody></table><br>
查看全文
发表于:2010-05-17 ┆
阅读(120)
┆
评论(0)
Ubuntu 10.04后安装指南
<p>代号为Lucid Lynx的Ubuntu 10.04已经正式发布了!Canonical和Ubuntu开发人员再次完美的完成了Ubuntu的改进工作。相对于Ubuntu 9.10 Karmic Koala,新版的启动加载速度变得更快,社会化整合变得更强大,您可以轻松的管理和编辑您的图片,视频以及文档。当然啦,还进行了很多的bug修复以及 软件更新。如果您还没有开始试用,那就赶快下载安装,或是从之前的Ubuntu 9.10升级吧,好啦,让我们开始吧。<span id="more-103"></span></p> <h3>1. 受限附加</h3> <p>Ubuntu Restricted Extras将安装Adobe Flash Player,Java Runtime Environment(JRE)(sun-java-jre)的Firefox插件(icedtea),Microsoft字库 (msttcorefonts),多媒体解码器(w32codecs或w64codecs),与mp3兼容的编码(lame),FFMpeg,附加的 Gstreamer解码器,用于DVD编码的软件包(libdvdread4,请先查看libdvdcss2的相关信息),unrar档案管理,odbc 和cabextract。它还将安装多个“被剥离”的解码器和avutils(libavcodec-unstripped-52和libavutil- unstripped-49)。通过下面的命令安装:</p> <blockquote><p>sudo apt-get install ubuntu-restricted-extras</p></blockquote> <p><strong>注意:</strong>只有通过命令行终端时,才能被正确完整的安装。使用Package Manager时,通常无法完整安装。</p> <h3>2. 多媒体</h3> <h4>音频和视频回放</h4> <p>播放视频(XVid,DivX等)或是音频(MP3)文件变得非常简单。只需要双击要播放的文件并允许Totem自动下载所需解码器。其实完全可以 自己来安装一个包含所有所需解码器的软件包,查看前面所提到的Ubuntu Restricted Extras。</p> <h4>DVD回放</h4> <p>想播放加密DVD的话,您必须安装<strong>libdvdcss2</strong>。在Ubuntu 10.04中不需要手动配置Medibuntu软件库。如果您之前安装了Ubuntu Restricted Extras的话,可跳过下面的命令。否则就打开终端并输入:</p> <blockquote><p>sudo apt-get install libdvdread4</p></blockquote> <p>接着输入:</p> <blockquote><p>sudo /usr/share/doc/libdvdread4/install-css.sh</p></blockquote> <h4>MPlayer/SMPlayer</h4> <p>我个人更喜欢使用MPlayer和SMPlayer(mplayer的GUI)用于视频回放。它几乎支持所有的视频格式,外部字幕以及DVD回放, 您只需安装之前所示的解码器。输入以下命令进行安装:</p> <blockquote><p>sudo apt-get install mplayer smplayer</p></blockquote> <p>可以在这里找到它:Applications -> Video & Sound -> SMPlayer</p> <h4>VLC</h4> <p>很多用户更喜欢Video Lan Client(VLC)作为他们的多媒体播放器。VLC不需额外的解码器即支持很多格式。输入以下命令安装:</p> <blockquote><p>sudo apt-get install vlc vlc-plugin-pulse</p></blockquote> <h4>K9copy</h4> <p>K9copy是一款免费的开源DVD备份,拷贝,压缩,验证程序,它依赖于libdvdcss。通过这个软件,您可以轻松创建MPEG- 2,MPEG-4或是DVD视频。输入以下命令安装:</p> <blockquote><p>sudo apt-get install k9copy</p></blockquote> <p>更多信息请浏览:<a href="http://www.my-guides.net/en/content/view/77/26/" target="_blank">How to backup your DVDs (in dvd, xvid, mpeg-4, x264 formats) using k9copy</a></p> <h4>DVD::Rip</h4> <p>DVD::Rip是一款DVD备份/拷贝程序,使用基于GTK的perl编写,利用transcode视频/音频处理转换工具。输入以下命令安装:</p> <blockquote><p>sudo apt-get install dvdrip</p></blockquote> <p>更多信息请浏览:<a href="http://www.my-guides.net/en/content/view/136/38/" target="_blank">How to rip a DVD to DivX/XviD/H264 using DVD::Rip</a></p> <h4>2ManDVD</h4> <p>2ManDVD是一款用于创建DVD视频的GUI工具。它是ManDVD的接班人。更多安装和使用信息请浏览:<a href="http://www.my-guides.net/en/content/view/170/26/" target="_blank">How to author a DVD using 2ManDVD in Linux</a>。</p> <h4>DeVeDe</h4> <p>DeVeDe是一款利用所有被MPlayer支持的视频源文件创建适用于家庭播放器(VCD,sVCD,VCD)的DVD和CD的软件。更多安装和 使用信息请浏览:<a href="http://www.my-guides.net/en/content/view/75/26/" target="_blank">How to create a custom DVD using DeVeDe</a></p> <h3>3. Java</h3> <h4>Sun Java Runtime Environment(JRE)和Firefox Java插件</h4> <p>关闭Firefox,打开终端并输入:</p> <blockquote><p>sudo apt-get install sun-java6-jre sun-java6-plugin</p></blockquote> <h4>Sun Java Development Kit(JDK)</h4> <p>如果您想使用Java语言开发程序,applet和组件,那就需要安装JDK。</p> <blockquote><p>sudo apt-get install sun-java6-jdk</p></blockquote> <h3>4. Google Earth</h3> <p>您可以通过Google Earth查看卫星图像,地图,地形,3D建筑,从外太空星系到海洋峡谷,可以浏览地球的各个角落。您可以探索丰富的地理内容,保存您的参观地点并分享给 其他人。输入以下命令安装:</p> <blockquote><p>sudo apt-get install googleearth-package<br> make-googleearth-package --force<br> sudo dpkg -i googleearth*.deb</p></blockquote> <p>安装后可以在这里找到Google Earth:Applications > Internet > Google Earth</p> <h3>5. Google Chromium</h3> <p>Chromium是Google的开源浏览器,速度非常快。您应该试一下。安装前需要添加GPG密钥:</p> <blockquote><p>sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 4E5E17B5</p></blockquote> <p>接下来需要添加以下chromium-daily源到第三方软件库列表。System -> Administration -> Software Sources,选择Other Software标签,点击ADD。</p> <blockquote><p>deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu lucid main</p></blockquote> <blockquote><p>sudo apt-get update<br> sudo apt-get install chromium-browser</p></blockquote> <p>接着您可以在这里找到它:Applications > Internet > Chromium Web Browser.</p> <h3>6. 视觉特效</h3> <h4>Compiz Fusion</h4> <p>Compiz Fusion允许您使用高级桌面特效,比如旋转立方体桌面。</p> <blockquote><p>sudo apt-get install compiz compizconfig-settings-manager compiz-fusion-plugins-main \<br> compiz-fusion-plugins-extra emerald librsvg2-common fusion-icon</p></blockquote> <p>您会在这里看到一个蓝色的图标:Applications -> System Tools -> Compiz Fusion Icon。通过它可以配置Compiz-Fusion。</p> <h4>Conky</h4> <p>Conky是一款轻量级的X系统监控器,它可以在桌面上显示任何信息。</p> <blockquote><p>sudo apt-get install conky</p></blockquote> <h4>Screenlets</h4> <p>Screenlets是一个桌面小程序。在很多方面都很有用。输入以下命令安装:</p> <blockquote><p>sudo apt-get install screenlets</p></blockquote> <p>在这里打开:Applications -> Accessories –> Screenlets,选择您想启动/添加的screenlet(您可以选择在登录时自动运行)</p> <p>您可以在<a href="http://www.gnome-look.org/index.php?xcontentmode=6700" target="_blank">gnnome-look.org</a>和<a href="http://screenlets.org/index.php/Category:UserScreenlets" target="_blank">screenlets.org</a>下载额外的screenlets。</p> <h4>Cairo Dock</h4> <p>Cairo Dock是一款可用于任何Linux桌面的完全主题化的动画dock。它非常像OSX dock,但是却具备更多的选项。</p> <blockquote><p>sudo apt-get install cairo-dock cairo-dock-plug-ins</p></blockquote> <p>您可以在这里找到它:Applications -> Accessories -> Cairo Dock</p> <h4>Gnome Do</h4> <p>GNOME Do(Do)是一款智能启动工具,它可以简单高效的在您的计算机上执行常见任务。不仅仅可以在您的桌面环境进行搜索(例如:程序,联系人,书签,文件,音 乐),同时还可以在搜索结果里执行指定操作(例如:运行,打开,邮件,聊天,播放)。</p> <blockquote><p>sudo apt-get install gnome-do</p></blockquote> <p>您可以在这里找到它:Applications > Accessories > Cairo Dock</p> <h4>窗口按钮顺序</h4> <p>很多用户抱怨新的最小化-最大化-关闭窗口按钮,觉得不够好。Mwbuttons是一个脚本,您可以通过它轻松的将按钮从左移到右。输入以下命令安 装:</p> <blockquote><p>wget http://launchpad.net/mwbuttons/trunk/v0.2/+download/mwbuttons<br> chmod +x mwbuttons<br> ./mwbuttons</p></blockquote> <p>选择Settings > Karmic style即可修改按钮到右侧。</p> <h3>7. 互联网</h3> <h4>IRC</h4> <p>XChat是一款既可用于Linux又可用于Windows的IRC聊天软件。通过它,您可以同时加入多个IRC频道(聊天室),进行公开发言,一 对一的单独交流等。甚至可以进行文件传输。</p> <blockquote><p>sudo apt-get install xchat</p></blockquote> <p>您可以在这里找到它:Applications -> Internet -> XChat IRC</p> <p>Ubuntu 9.10使用empathy作为默认IM(Instant Messaging)客户端。这里有一些其他的即时通讯软件:</p> <h4>Pidgin</h4> <p>Pidgin是一款开源IM程序。它之前是Ubuntu(Gnome)桌面的默认IM。</p> <blockquote><p>sudo apt-get install pidgin</p></blockquote> <h4>aMSN</h4> <p>aMSN是一款MSN Messenger工具,功能和原生客户端非常相似。 输入以下命令安装:</p> <blockquote><p>sudo apt-get install amsn</p></blockquote> <p>您可以在这里找到它:Applications -> Internet -> aMSN</p> <h4>Emesene</h4> <p>Emesene是一款MSN messenger客户端。它采用简化界面,跟原生客户端非常相近。输入以下命令安装:</p> <blockquote><p>sudo apt-get install emesene</p></blockquote> <p>您可以在这里找到它:Applications -> Internet -> Emesene</p> <h4>Skype</h4> <p>Skype是一套整合VOIP和视频会议的专用程序,类似于Ekiga。在Ubuntu 10.04下安装Skype只需点击Ubuntu 8.10+ 32bit版本或Ubuntu 8.10+ 64bit版本即可。<a href="http://www.skype.com/intl/en/download/skype/linux/choose/" target="_blank">下载Skype</a>。</p> <h3><span style="color: rgb(255, 0, 0);">8. BT客户端</span></h3> <p>Transmission是Ubuntu 9.10的默认BitTorrent客户端。这里一些其他的客户端,如果您想试试的话。</p> <h4>Deluge</h4> <p>Deluge是一款轻量级的跨平台免费BitTorrent客户端。</p> <blockquote><p>sudo apt-get install deluge</p></blockquote> <p>您可以在这里找到它:Applications -> Internet -> Deluge BitTorrent client</p> <h4>Vuze</h4> <p>Vuze是Azureus的后续版本。输入以下命令安装:</p> <blockquote><p>sudo apt-get install vuze</p></blockquote> <p>您可以在这里找到它:Applications -> Internet -> Vuze</p> <h3>9. NTFS读写支持</h3> <p>Ubuntu有一个图形化配置工具可开启NTFS分区的读写。不论是Windows/Linux多启动系统或从额外的硬盘。输入以下命令并安装:</p> <blockquote><p>sudo apt-get install ntfs-config</p></blockquote> <p>您可以在这里找到它:System -> Administration -> NTFS Configuration Tool.<br> NTFS-Config将自动检测您的NTFS分区,然后您就可以开启对它们的读写支持了。它们将被挂载在/media。<br> -------------------------</p>
查看全文
发表于:2010-05-15 ┆
阅读(244)
┆
评论(0)
High resolution Plymouth & ATI/NVIDIA cards
<p><strong>[Rant]</strong><br> Deja vu. When Ubuntu first introduced PulseAudio, it was one hell of a plight for the end-user. And now it is Plymouth turn to make life an uphill struggle for user with <em>recent</em> ATI or NVIDIA card and proprietary drivers (as well as people having examination like me >.<). <a href="http://www.netsplit.com/2010/03/30/all-about-kernel-mode-setting/">Here is an interesting article</a> by Scott James Remnant on why your expensive card doesn’t play nice with Plymouth in Lucid. I also grow tired and wary of all the copy-n-paste instructions lying on the Internet which are out-dated and untested yet considered as panacea. My most hated one is ‘set gfxpayload=keep’ originated from Arch forum and now spreading like fire. It makes your the Virtual Terminal (VT) useless, ‘keep’ is not the working option in Ubuntu, last and not least, in Lucid, there is a more graceful way to do it. And I hope my guide below will not suffer the same fate as them. It was quite comprehensive after days of manual grinding and testing during exam period.</p> <hr><strong>[Problems/Symptoms/Why-Are-You-Here]</strong><br> Plymouth splash screen… <ul><li>is in low res mode.</li><li>has corrupted graphic</li><li>is decent but can’t switch to virtual terminal or VT is horribly in low res mode</li><li>is decent but the splash screen only appears for a brief 1-2 second ( you are missing the dots moving <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif" alt=":P" class="wp-smiley"> ), before that you only see a black/blank screen</li></ul> <hr><strong>[Environment]</strong><br> Use Synaptic or ‘apt-cache policy ‘ or common-sense to find out. <ul><li>GRUB >= 1.98-1ubuntu5</li><li>Plymouth >= 0.8.2-2</li><li>ATI cards with FGLRX >= 8.723.1-0ubuntu3</li><li>NVIDIA cards with nvidia-glx-1*</li><li>A clean without other tweaks to plymouth & grub, please revert them before proceeding. Really, it will not work if you insisted on apply other tweaks. <strong>!!! IMPORTANT !!!</strong></li><li>Common-sense and google searching skill</li><li>A bit of risk taking spirit and confidence</li></ul> <hr><strong>[Caveats and Limitations]</strong><br> I will use the <strong>uvesafb </strong>to fix all the problems mentioned above but I have to warn you about certain limitations first. They don’t affected me much though (widescreen works on mine). I think problem will come when you want to use solar theme or any complex theme as uvesafb doesn’t have acceleration -> slow. Extract from<a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/fb/uvesafb.txt"> documentation for uvesafb</a> <blockquote><p>uvesafb is a _generic_ driver which supports a wide variety of video cards, but which is ultimately limited by the Video BIOS interface. The most important limitations are:<br> - Lack of any type of acceleration.<br> - A strict and limited set of supported video modes. Often the native or most optimal resolution/refresh rate for your setup will not work with uvesafb, simply because the Video BIOS doesn’t support the video mode you want to use. This can be especially painful with widescreen panels, where native video modes don’t have the 4:3 aspect ratio, which is what most BIOS-es are limited to.<br> - Adjusting the refresh rate is only possible with a VBE 3.0 compliant Video BIOS. Note that many nVidia Video BIOS-es claim to be VBE 3.0 compliant, while they simply ignore any refresh rate settings.</p></blockquote> <p>Also, <strong>uvesafb</strong> replaces <strong>vesafb</strong> in Ubuntu, in case you are wondering.</p> <hr><strong>[Fix/Workaround]</strong><br> * uvesafb required v86d package to be installed. Hwinfo package is required for the next step as well.<br> <code>sudo apt-get install v86d hwinfo</code> <p> </p> <p> </p> <p>* Find out the supported resolution by using hwinfo.<br> <code>sudo hwinfo --framebuffer</code></p> <p>Sample output :<br> <code><br> 02: None 00.0: 11001 VESA Framebuffer<br> [Created at bios.464]<br> ...<br> Hardware Class: framebuffer<br> Model: "(C) 1988-2005, ATI Technologies Inc. M92"<br> Vendor: "(C) 1988-2005, ATI Technologies Inc. "<br> Device: "M92"<br> SubVendor: "ATI ATOMBIOS"<br> ...<br> Mode 0x0321: 640x480 (+2560), 24 bits<br> Mode 0x0322: 800x600 (+3200), 24 bits<br> Mode 0x0323: 1024x768 (+4096), 24 bits<br> Mode 0x03ee: 1366x768 (+1408), 8 bits<br> Mode 0x03ef: 1366x768 (+2752), 16 bits<br> Mode 0x03f0: 1366x768 (+5504), 24 bits<br> Config Status: cfg=new, avail=yes, need=no, active=unknown<br> </code></p> <p> </p> <p> </p> <p>* Edit <em>/etc/default/grub</em> to make sure we boot with uvesafb framebuffer. For the mode_option parameter change to your native screen resolution you see from running the above comment (if not just set to 1024×768-24 which is safest. Oh, Netbook user – please exercise some common-sense here) Non relevant lines are omitted for clarity.<br> <code><br> ...<br> GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset video=uvesafb:mode_option=1366x768-24,mtrr=3,scroll=ywrap"<br> ...<br> GRUB_GFXMODE=1366x768<br> </code></p> <p> </p> <p> </p> <p>* Edit <em>/etc/initramfs-tools/modules </em> to include uvesafb by adding the following line.<br> <code><br> uvesafb mode_option=1366x768-24 mtrr=3 scroll=ywrap<br> </code></p> <p> </p> <p> </p> <p>* Force the use of framebuffer:<br> <code>echo FRAMEBUFFER=y | sudo tee /etc/initramfs-tools/conf.d/splash<br> </code></p> <p> </p> <p> </p> <p>* Update and we are done <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"><br> <code><br> sudo update-grub2<br> sudo update-initramfs -u<br> </code></p> <p> </p> <p>* Now reboot and enjoy the high resolution sensation <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> (my first reboot hangs, but 2nd time onward it works flawlessly). If it works correctly, you should be able to have moving dots with the splash screen; lesser time of blank screen and much more time with splash screen.</p> <p><span style="text-align: center; display: block;"><object height="350" width="425"><param name="movie" value="http://www.youtube.com/v/LrzoUdC78Z4&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1"> <param name="allowfullscreen" value="true"> <param name="wmode" value="opaque"> <embed src="http://www.youtube.com/v/LrzoUdC78Z4&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1" type="application/x-shockwave-flash" allowfullscreen="true" wmode="opaque" height="350" width="425"> </object></span></p> <p>* And contrary to popular belief, my laptop resume and suspend works with uvesafb! <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> </p> <p>* Thing you probably will see in dmesg if succeed:<br> <code><br> [ 0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-2.6.32-21-generic-pae root=UUID=44c7c661-1f5e-49e6-a14e-7a35f1ec3f9f ro quiet splash nomodeset video=uvesafb:mode_option=1366x768-24,mtrr=3,scroll=ywrap<br> [ 6.684235] uvesafb: (C) 1988-2005, ATI Technologies Inc. , M92, 01.00, OEM: ATI ATOMBIOS, VBE v3.0<br> [ 6.783693] uvesafb: protected mode interface info at c000:a2d4<br> [ 6.783695] uvesafb: pmi: set display start = c00ca376, set palette = c00ca434<br> [ 6.783727] uvesafb: VBIOS/hardware supports DDC2 transfers<br> [ 6.845060] uvesafb: monitor limits: vf = 61 Hz, hf = 48 kHz, clk = 69 MHz<br> [ 6.845110] uvesafb: scrolling: ywrap using protected mode interface, yres_virtual=1536<br> [ 6.847159] uvesafb: framebuffer at 0xc0000000, mapped to 0xf8380000, using 8256k, total 16384k<br> [ 6.854259] uvesafb: mode switch failed (eax=0x34f, err=0). Trying again with default timings.</code></p> <hr><strong>[Other Alternatives]</strong><br> * Rog131′s ‘Making a low resolution low color plymouth theme’ is an ingenious workaround. <a href="http://kubuntuforums.net/forums/index.php?topic=3111137.msg226258#msg226258">Here</a> <p>* No splash screen but high resolution virutal terminal using EFI framebuffer. Edit <em>/etc/default/grub</em>, remove ‘splash’ option and replace the two entries below with your native resolution. Seriously, this is way better than setting the payload to keep and in 00_header. GRUB_GFXPAYLOAD_LINUX is only available from grub 1.98 in lucid.<br> <code><br> ...<br> GRUB_CMDLINE_LINUX_DEFAULT="quiet"<br> ...<br> GRUB_GFXMODE=1366x768<br> GRUB_GFXPAYLOAD_LINUX=1366x768<br> ...<br> </code></p> <hr><strong>[Last Words]</strong><br> - Comments are welcome and appreciated.<br> - Testers are welcome.<br> - I will try to respond to you ASAP but spare me some thoughts cos the poor guy here is having his final exams at his university life
查看全文
发表于:2010-05-13 ┆
阅读(387)
┆
评论(0)
How To Get Plymouth Working With Nvidia Proprietar
<p>After <a href="http://trycatch.iblogger.org/?p=436">installing the Nvidia Proprietary Drivers</a>, Plymouth doesn’t work anymore, and the boot images looks… horrible, because it’s designed to use the nouveau driver,and since you’re using the nvidia proprietary driver, it’s kind of buggy. To make it work, it needs some small adjustments to be done.<br> Edit the grub:</p> <div class="syntaxhighlighter nogutter bash" id="highlighter_149950"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="bash functions">sudo</code> <code class="bash plain">gedit /etc/default/grub</code></td></tr></tbody></table></div></div></div> <p>and uncomment by removing the <strong>#</strong> the line </p><div class="syntaxhighlighter nogutter plain" id="highlighter_876580"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="plain plain">#GRUB_GFXMODE=640x480</code></td></tr></tbody></table></div></div></div> <p>Change the resolution to whatever you like, for me it worked perfectly with </p><div class="syntaxhighlighter nogutter plain" id="highlighter_240130"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="plain plain">GRUB_GFXMODE=1280x800</code></td></tr></tbody></table></div></div></div> <p>Then, edit the following file:</p> <div class="syntaxhighlighter nogutter bash" id="highlighter_935953"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="bash functions">sudo</code> <code class="bash plain">gedit /etc/grub.d/00_header</code></td></tr></tbody></table></div></div></div> <p>,search for the following line: </p><div class="syntaxhighlighter nogutter plain" id="highlighter_224881"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="plain plain">gfxmode=${GRUB_GFXMODE}</code></td></tr></tbody></table></div></div></div> <p> and past this line under it: </p> <div class="syntaxhighlighter nogutter plain" id="highlighter_315670"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="plain plain">set gfxpayload=keep</code></td></tr></tbody></table></div></div></div> <p>The last thing to do is update the grub by typing</p> <div class="syntaxhighlighter nogutter bash" id="highlighter_487209"><div class="lines"><div class="line alt1"><table><tbody><tr><td class="content"><code class="bash functions">sudo</code> <code class="bash plain">update-grub</code></td></tr></tbody></table></div></div></div> <p>That’s all, <b>but be careful not to make any mistake, because you Ubuntu might not start</b></p><p><br></p><p><b><br></b></p>
查看全文
发表于:2010-05-13 ┆
阅读(55)
┆
评论(0)
ubuntu grub2深入剖析个性设置
<br> <div class="postbody"><font size="1"><span style="font-size: 150%; line-height: normal;">Grub2做为新一代的多系统引导器,之所以代替旧的Grub,一方面是因为旧Grub设计上的失败及其代码的凌乱不可维护,另一方面 也是因为需要更多的功能( 见<a href="http://www.gnu.org/software/grub/grub-2-faq.en.html" class="postlink">http://www.gnu.org/software/grub/grub-2-faq.en.html</a> )。<br> Grub2较之Grub的新功能有<br> 1、模块化设计<br> 不同于Grub的单一内核结构,Grub 2 的功能分布在很多的小模块中,并且能在运行时动态装载和卸除。<br> 2、支持多体系结构<br> Grub 2可支持PC(i386), MAC(powerpc)等不同的体系机构,而且支持最新的EFI架构。<br> 3、国际化的支持<br> Grub 2 可以支持非英语的语言。<br> 4、内存管理<br> Grub 2 有真正的内存管理系统。<br> 5、脚本语言<br> Grub 2 可以支持脚本语言,例如条件,循环,变量,函数等。<br> 6,绚丽的菜单界面<br> 旧的Grub已经停止开发,而Grub2还在开发过程中,所以Grub2有些功能还没有实现。但是我们已经可能用Grub2中较稳定的版本了,而 Ubuntu9.04/9.10都已包含了Grub2.<br> 而本篇重点介绍Grub2的美化,和Grub相比较,在美化上Grub2支持更多的图片格式:PNG,TGA(默认支持,Jpeg 格式的也支持,但是稍微麻烦一点,旧的GRUB 中支持的xpm格式的不再支持);再就是支持更大的分辨率(800x600),(1024x768)原版本似乎只支持640x480,这样你就可以方便的 自定义自己的splahimage了(用高分辨率的图片来做splash image);还有就是配置文件也不是原来的menu.lst,而是<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">/boot/grub/grub.cfg和/etc/grub.d /05_debian_theme</div> <br> <br> 一:简单的改变Grub2的字体颜色和背景<br> 在你进入系统之前会有一个黑底白字的Grub菜单界面,<a onclick="return hs.expand(this)" href="http://thegabfather.files.wordpress.com/2008/09/grub4kt.jpg" class="highslide"><img style="max-height: 210px;" src="http://thegabfather.files.wordpress.com/2008/09/grub4kt.jpg" alt="图片"> </a> 让你选择进入系统,这里的黑底白字可以改变的,具体如下:<br> 这里涉及到的文件是/etc/grub.d/05_debian_theme<br> 在打开之前建议先保存,以免出错,<br> <span style="color: rgb(255, 64, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo /etc/grub.d/05_de/etc/grub.d/05_debian_themebian_theme_backup</div> <br> </span> <br> 打开/etc/grub.d/05_debian_theme<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo gedit /etc/grub.d/05_debian_theme</div> </span> <br> <br> 可以在33到43行之间看到<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> set color_normal=black/black<br> set color_highlight=magenta/black<br> set menu_color_normal=cyan/blue<br> set menu_color_highlight=white/blue</div> </span> <br> <br> 这么几句,它们就是改变字体颜色的关键,foreground/background是修改字体它们的意思<br> color_normal=foreground(前景色)/background(背景色)即“/”之前的表示前景色,之后的表示背景色。<br> 具体意思请看例图:<br> <div class="attachtitle">附件:</div> <div class="attachcontent"> <span class="gensmall"><strong>文件注释:</strong> Grub的color_normal参数图解</span> <br> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95347&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_004.png" class="highslide"><img src="http://forum.ubuntu.org.cn/download/file.php?id=95347&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_004.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_004.png [ 78.13 KiB | 被浏览 2146 次 ]</span> <br> <br> </div> <br> foreground/background可供选择的有<br> black (透明,与white是不同的), dark-gray, light-gray, white, brown, yellow, red, light-red, blue, light-blue, green, light-green, cyan, light-cyan, magenta, light-magenta.颜色情况如图:<br> <div class="attachtitle">附件:</div> <div class="attachcontent"> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95348&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_005.png" class="highslide"><img src="http://forum.ubuntu.org.cn/download/file.php?id=95348&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_005.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_005.png [ 19.52 KiB | 被浏览 2146 次 ]</span> <br> <br> </div> <br> <br> 把以上四行分别有以下四行代替:<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">set color_normal=green/yellow<br> set color_highlight=magenta/black<br> set menu_color_normal=green/yellow<br> set menu_color_highlight=yellow/red</div> </span> <br> <br> 保存<br> 记得一定要更新配置文件:<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo grub-mkconfig -o /boot/grub/grub.cfg</div> </span> <br> <br> 好了,重新启动就可以看到的效果 <div class="attachtitle">附件:</div> <div class="attachcontent"> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95350&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_008.png" class="highslide "><img src="http://forum.ubuntu.org.cn/download/file.php?id=95350&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_008.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_008.png [ 35.22 KiB | 被浏览 2145 次 ]</span> <br> <br> </div> <br> 技巧:对于颜色的设定,也许真的是要做到眼见为实,你自己设定的也许呈现在屏幕上就会和你想像的不一样,这时候就要更改设置了,如果每次替换四行之后还要 重启,那就太麻烦了,这有一个好的方法,就是可以避免重启了:在Grub的菜单界面,会提示你输入“c”或者“e”,这时你就可以进入Grub的命令提示 界面了CLI(Command Line Interface),可以用到“set”命令来试不同的颜色组合了,然后按“esc”就可以看到效果了。<br> 例子: <div class="attachtitle">附件:</div> <div class="attachcontent"> <img src="http://forum.ubuntu.org.cn/download/file.php?id=95349&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_007.png"> <br> <span class="gensmall">Selection_007.png [ 3.62 KiB | 被浏览 2146 次 ]</span> <br> </div> </span></font> <font size="1"><br><span style="font-size: 150%; line-height: normal;">提示,此时的设置只对本次有效,所以你 要记下让你满意的颜色组合,然后到05_debian_theme里更改,更新,这样你就可以每次到看到 了。</span></font> <font size="1"><br><br><br><span style="font-size: 200%; line-height: normal;"><span style="color: rgb(0, 0, 0);">二:添加Splashimage到Grub</span> </span></font> <font size="1"><br><br><span style="font-size: 150%; line-height: normal;"> 在本小节中,我们要用图片来美化Grub的菜单界面。我们要用到的图片不是任意的,它默认只能是640x480的,太大的图片不能显示,或者只会显示图片 的一部分。<br> 由于Ubuntu本身就含有grub2-grub2-splashimages包,该包内含有已经设计好的图片,我们直接下载就可以了。<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo apt-get install grub2-splashimages</div> </span> <br> <br> 执行成功后就可以在/usr/share/images/grub/ 文件夹中看到splashimage了<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">cd /usr/share/images/grub/<br> ls</div> </span> <br> 终端中会有输出,下面要用到。<br> 在资源管理器里也能看到:<br> <a onclick="return hs.expand(this)" href="http://i38.tinypic.com/2wf1c2q.jpg" class="highslide"><img style="max-height: 210px;" src="http://i38.tinypic.com/2wf1c2q.jpg" alt="图片"> </a> <br> 现在我们要告诉系统到哪里去找splashimage了,即修改 /etc/grub.d/05_debian_theme文件 <br> 还建议先备份 <br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo cp /etc/grub.d/05_debian_theme /etc/grub.d/05_debian_them_backup</div> </span> <br> 打开05_debian_theme<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo gedit /etc/grub.d/05_debian_theme</div> </span> <br> <br> 找到 <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga}; do</div> 行<br> 并且用 <span style="color: rgb(255, 0, 0);"><br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> for i in {/boot/grub,/usr/share/images/desktop-base,/usr/share/images/grub}/Lake_mapourika_NZ.{png,tga}; do</div> </span> <br> 替换,可以看出这里有文件夹,文件名,及扩展名, <div class="attachtitle">附件:</div> <div class="attachcontent"> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95351&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_012.png" class="highslide"><img src="http://forum.ubuntu.org.cn/download/file.php?id=95351&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_012.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_012.png [ 30.67 KiB | 被浏览 2142 次 ]</span> <br> <br> </div> 只要修改这几处就可以更换图片了(需要是640x480)的,“Lake_mapourika_NZ”可以用终端中其它的文件名来代替,注意 {png,tga} 前面的“." 只有一个,不要复制多了。<br> 保存,更新:<br> <span style="color: rgb(255, 0, 0);"> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo grub-mkconfig -o /boot/grub/grub.cfg</div> </span> <br> <br> 注意观察终端的输出,是否有类似”<span style="color: rgb(255, 0, 0);">Found Debian backgrand"</span> 的提示,有,就证明你成功了,可以重启,欣赏你的漂亮的Grub了,如果没有提示,你要再对照步骤执行一边,看有没有错的地方。<br> </span></font> <font size="1"><br><br><span style="font-size: 150%; line-height: normal;">[size=200]三:添加自定义高分辨 率图片作为开机splash</span></font> <font size="1"><br><br><span style="font-size: 150%; line-height: normal;">Grub2 不仅支持用自己喜欢的图片做为开机的Splash来美化Grub,还支持高分辨率的图片,比如 (800x600),(1024x768)等,这样你就可以用自己喜欢的照片来做splash了,,当然这也取决于你的电脑Bios对VESA 模式的支持,那么如何知道自己电脑支持多大的分辨率呢?这就要用到Grub的命令 vbeinfo 了。<br> vbeinfo命令用识别你的显示器的Bios所能支持的最大分辨率,这并不与你进入系统之后的相等,比如我的本本是1280x800的宽屏,但是 vbeinfo显示它的Bios只支持到1024x768,我想这是因为Bios内所含有驱动有关吧。<br> 在启动的时候可以按 ‘C'进入GRub的ClI,然后输入 vbeinfo 会显示如下:<br> <div class="attachtitle">附件:</div> <div class="attachcontent"> <span class="gensmall"><strong>文件注释:</strong> vbeinfo命令显示</span> <br> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95463&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_014.png" class="highslide"><img src="http://forum.ubuntu.org.cn/download/file.php?id=95463&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_014.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_014.png [ 42.74 KiB | 被浏览 2005 次 ]</span> <br> <br> </div> <br> 就可知道你的硬件支持的最高分辨率了。<br> 在纸上记下这些数字,以备后用。<br> 现在打开/etc/default/grub 用gedit<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo gedit /etc/default/grub</div> <br> <br> 然后在"GRUB_GFXMODE="后面用小于由vbeinfo命令得来的分辨率来代替,另外还要去掉该前面的注释符“#”,不然,是不会有效果的。改 后类似下面的 <br> <div class="attachtitle">附件:</div> <div class="attachcontent"> <a onclick="return hs.expand(this)" href="http://forum.ubuntu.org.cn/download/file.php?id=95464&sid=3ffc90ab93d7701891447c7a4ffaf8fb&mode=view/Selection_015.png" class="highslide"><img src="http://forum.ubuntu.org.cn/download/file.php?id=95464&t=1&sid=3ffc90ab93d7701891447c7a4ffaf8fb" alt="Selection_015.png" title="Click to enlarge"> </a> <br> <span class="gensmall">Selection_015.png [ 16.15 KiB | 被浏览 2005 次 ]</span> <br> <br> </div> <br> 保存并更新<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo grub-mkconfig -o /boot/grub/grub.cfg </div> <br> 注:如果你改变的分辨率大于640x480(这是系统默认的),这时你重启的话你会发现Grub的菜单的字体变小了,这是必然的,分辨率变大,更清晰了, 自然字体就变小了。所以我建议你的你的分辨率不要太大,要不然就会影响美观,适得其反了。<br> 现在你就可以用适合你自已设定的分辨率的图片来美化Grub2了,比如我设定的GRUB_GFXMODE=1024x768,那我最好就用 1024x768大小的图片来做splash了,建议用背景不要太复杂的做splash,否则效果会不好。至于图片的格式也是要注意的,如果你手头没有现 成的png;tga格式的图片,可以用ps打开图片,另存为png或tga的即可。<br> 假设我的图片的名字是myimage.png<br> 复制该文件到/boot/grub/ <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo cp myimage.png /boot/grub/</div> <br> 注意要用你自己的图片的名字来代替“myimage”<br> 修改配置文件05_debian_theme以让系统知道去哪儿找哪个图片<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> sudo gedit /etc/grub.d/05_debian_theme</div> <br> 在16或17行的地方可以看到 (如果你没有修改过该行)<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent"> for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do </div> <br> <br> 用下行来代替 (不要直接代替,图片的名字一定要用你自己的。<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">for i in {/boot/grub,/usr/share/images/desktop-base}/myimage.{png,tga} ; do </div> <br> 保存 然后更新<br> <div class="quotetitle"><strong>引用:</strong> </div> <div class="quotecontent">sudo grub-mkconfig -o /boot/grub/grub.cfg</div> <br> 现在你就可以重启来看你自己的美化效果了。<br> <span style="color: rgb(191, 0, 0);"> 我的E 文一般,所以有些地方理解有偏差,如果有错的地方,希望你能指出来,我再改正。谢谢了。</span> <br> <br> 参考于 <a href="http://members.iinet.net/%7Eherman546/p20/GRUB2%20Splashimages.html#Splashimage_Font_Colors" class="postlink">http://members.iinet.net/~herman546/p20/GRUB2%20Splashimages.html#Splashimage_Font_Colors</a> <br> <a href="http://www.howtoforge.com/how-to-install-grub-2-on-ubuntu-9.04" class="postlink">http://www.howtoforge.com/how-to-install-grub-2-on-ubuntu-9.04</a> </span></font> </div>
查看全文
发表于:2010-05-13 ┆
阅读(204)
┆
评论(0)
vim 配置文件收集(作为c/c++和脚本开发的环境) 更新ing
起因是有些初学者常常问到vim,gvim要怎么配置才可以成为一个正式的开发环境。貌似这些天很多人问道这个问题。我就把基本的配置发一下,最近比较 忙。由于本人自己只是使用c/c++,ruby,Mozilla平台,所以其他语言或……
查看全文
发表于:2010-05-13 ┆
阅读(117)
┆
评论(0)
10.04 lucid 安装dropbox
在更新源中加入dropbox源(for 10.04):<br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(255, 153, 0);">#Dropbox<br> </span><br> deb http<span style="color: rgb(0, 0, 204);">:</span><span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">/</span>linux<span style="color: rgb(0, 0, 204);">.</span>getdropbox<span style="color: rgb(0, 0, 204);">.</span>com<span style="color: rgb(0, 0, 204);">/</span>ubuntu lucid main<br> deb<span style="color: rgb(0, 0, 204);">-</span>src http<span style="color: rgb(0, 0, 204);">:</span><span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">/</span>linux<span style="color: rgb(0, 0, 204);">.</span>getdropbox<span style="color: rgb(0, 0, 204);">.</span>com<span style="color: rgb(0, 0, 204);">/</span>ubuntu lucid main</span></code></p></td></tr></tbody></table><br><br>在gpg数据库中输入rian的public key:<br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">sudo apt<span style="color: rgb(0, 0, 204);">-</span>key adv <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span>keyserver pgp<span style="color: rgb(0, 0, 204);">.</span>mit<span style="color: rgb(0, 0, 204);">.</span>edu <span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">recv</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(255, 0, 0);">keys</span> 5044912E</span></code></p></td></tr></tbody></table><br>接下来是安装:<br><br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">sudo aptitude update</span></code></p></td></tr></tbody></table><br><br><table style="border-collapse: collapse;" width="95%" bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0"><tbody><tr><td><p style="line-height: 150%; margin: 5px;"><code><span style="color: rgb(0, 0, 0);">sudo apt<span style="color: rgb(0, 0, 204);">-</span>get install nautilus<span style="color: rgb(0, 0, 204);">-</span>dropbox</span></code></p></td></tr></tbody></table><br>然后就可以使用了<br><br>
查看全文
发表于:2010-05-07 ┆
阅读(74)
┆
评论(0)
用vim編輯文本的時用查找替換去掉文本文件中的^M
這樣: <br> <br>:e ++ff=dos <-這樣那個^M就應該沒有了,如果還有,可能是mac格式的 <br>:set ff=unix <br>:w
查看全文
发表于:2010-05-07 ┆
阅读(147)
┆
评论(0)
ubuntu lucid 10.04 使用smplayer硬解看高清
过程很简单<br><br><span style="font-weight: bold;">1.添加支持vdpau硬解的smplayer源</span><br><br>sudo add-apt-repository <b>ppa:nvidia-vdpau/ppa</b><br><b><br></b><span style="font-weight: bold;">……
查看全文
发表于:2010-05-06 ┆
阅读(287)
┆
评论(0)
Visual Studio 2008 安装失败(“Web 创作组件”无法安装)的解决办法
查看全文
发表于:2010-04-12 ┆
阅读(72)
┆
评论(0)
加速ubuntu上网速度
查看全文
发表于:2008-07-08 ┆
阅读(756)
┆
评论(1)
ubuntu 8.04 的设置和优化
查看全文
发表于:2008-07-08 ┆
阅读(393)
┆
评论(0)
利用 bootchart 來分析 Linux 系统的启动过程
查看全文
发表于:2008-07-08 ┆
阅读(626)
┆
评论(0)
给博客加背景音乐最简单的解决办法方案
今天突然想到怎么cu的博客没自带背景音乐播放功能的呢?于是试着给自己这个博客添加背景音乐:发现也很简单:可以在<span style="color: rgb(0, 1, 255);">管理中心</span>的<span style="color: rgb(0, 1, 255)……
查看全文
发表于:2008-06-23 ┆
阅读(1436)
┆
评论(1)
cublog添加背景音乐
查看全文
发表于:2008-06-15 ┆
阅读(429)
┆
评论(0)