﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-开心就好-文章分类-linux develop</title><link>http://www.cppblog.com/shaovie/category/2727.html</link><description>做最好的自己</description><language>zh-cn</language><lastBuildDate>Tue, 27 May 2008 21:01:22 GMT</lastBuildDate><pubDate>Tue, 27 May 2008 21:01:22 GMT</pubDate><ttl>60</ttl><item><title>我最编写的最成功的一个makefile</title><link>http://www.cppblog.com/shaovie/articles/15836.html</link><dc:creator>崔少伟</dc:creator><author>崔少伟</author><pubDate>Fri, 01 Dec 2006 02:49:00 GMT</pubDate><guid>http://www.cppblog.com/shaovie/articles/15836.html</guid><wfw:comment>http://www.cppblog.com/shaovie/comments/15836.html</wfw:comment><comments>http://www.cppblog.com/shaovie/articles/15836.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/shaovie/comments/commentRss/15836.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/shaovie/services/trackbacks/15836.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000"> Copyright (c) 2006 HXHT, Inc.  All rights reserved.<br />#<br />#compiler and linker</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">CXX  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> g</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">
						<br />CC   </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> gcc<br />LINKER </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> g</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">
						<br />MAKE   </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> make<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">control version save-dir</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">ifdef HXHT_RELEASE<br />BIN_DIR </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">release<br /></span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />BIN_DIR </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">debug<br />endif<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">source code dir</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">VPATH </span>
				<span style="COLOR: #000000">:=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">src<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">target</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">TARGET </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> $(BIN_DIR)</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">HikVideoSvrHC<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">compile macro</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">COMP_MACRO </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">D_REENTRANT </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">D__USE_POSIX </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">D__linux__ </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">DIP_DEBUG<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">compile flags</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">CCFLAGS </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> $(COMP_MACRO) </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">g </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">Wall<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">libs</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">LIB_DIR  </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">L</span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">hc4000_sdk </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">L</span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">g729decoder<br />SYS_LIBS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lpthread </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">ldl </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lstdc</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lm </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lcrypt<br />PROJECT_LIBS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lACE </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lds40xxsdk </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">lg729decoder<br />LIBS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> $(SYS_LIBS) $(LIB_DIR) $(PROJECT_LIBS)<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">optimization</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">CCFLAGS </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">O2<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000"> EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">CCFLAGS </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">I</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">
						<br />CCFLAGS </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">I$(ACE_ROOT)<br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">CCFLAGS += -I./src<br /># EACH DIRECTORY WITH A STATIC LIBRARY MUST BE APPENDED IN THIS MANNER TO THE LINKOPTS</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">CXXFLAGS </span>
				<span style="COLOR: #000000">:=</span>
				<span style="COLOR: #000000"> $(CCFLAGS)<br />CFLAGS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">
						<br />
						<br />CPPFILES </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">      AlarmHandler</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">cpp   </span>
				<span style="COLOR: #000000">\</span>
				<span style="COLOR: #000000">
						<br />                AlarmInGetPolicyReq</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">cpp   </span>
				<span style="COLOR: #000000">\</span>
				<span style="COLOR: #000000">
						<br />                AlarmInSetPolicyReq</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">cpp   </span>
				<span style="COLOR: #000000">\</span>
				<span style="COLOR: #000000">
						<br />                AlarmOutStatusReq</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">cpp   </span>
				<span style="COLOR: #000000">\</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: #000000">
						<br />                Writer</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">cpp<br /><br />CFILES </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">
						<br />
						<br />OBJ_DIR </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">./</span>
				<span style="COLOR: #000000">obj</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">
						<br />
						<br />OBJS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> $(addprefix $(OBJ_DIR)</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> $(notdir $(CPPFILES</span>
				<span style="COLOR: #000000">:%.</span>
				<span style="COLOR: #000000">cpp</span>
				<span style="COLOR: #000000">=%.</span>
				<span style="COLOR: #000000">o)))<br /><br />all</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> $(TARGET)<br /><br />$(TARGET)</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> $(OBJS)<br />        $(LINKER) </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">o $@ $(OBJS) $(CXXFLAGS) $(LIBS)<br /><br /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000">$(OBJS):$($(notdir $@):%.o=%.cpp)</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">$(OBJ_DIR)</span>
				<span style="COLOR: #000000">%.</span>
				<span style="COLOR: #000000">o</span>
				<span style="COLOR: #000000">:%.</span>
				<span style="COLOR: #000000">cpp<br />        $(CXX) $(CXXFLAGS) </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">c $</span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">o $@<br /><br />$(OBJ_DIR)</span>
				<span style="COLOR: #000000">%.</span>
				<span style="COLOR: #000000">o</span>
				<span style="COLOR: #000000">:%.</span>
				<span style="COLOR: #000000">c<br />        $(CC) $(CCFLAGS) </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">c $</span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">o $@<br />check</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">
						<br />        ldd </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">r $(NAME)<br />clean</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">rm </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">f $(OBJS)<br />cleanall</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000"> clean all<br />        </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">rm </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">f $(TARGET)<br /></span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">PHONY</span>
				<span style="COLOR: #000000">:</span>
				<span style="COLOR: #000000">all check clean cleanall<br /></span>
		</div>
<img src ="http://www.cppblog.com/shaovie/aggbug/15836.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/shaovie/" target="_blank">崔少伟</a> 2006-12-01 10:49 <a href="http://www.cppblog.com/shaovie/articles/15836.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GNU Make自动变量一览</title><link>http://www.cppblog.com/shaovie/articles/15829.html</link><dc:creator>崔少伟</dc:creator><author>崔少伟</author><pubDate>Fri, 01 Dec 2006 00:24:00 GMT</pubDate><guid>http://www.cppblog.com/shaovie/articles/15829.html</guid><wfw:comment>http://www.cppblog.com/shaovie/comments/15829.html</wfw:comment><comments>http://www.cppblog.com/shaovie/articles/15829.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/shaovie/comments/commentRss/15829.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/shaovie/services/trackbacks/15829.html</trackback:ping><description><![CDATA[
		<span class="Code">
				<p>
						<font size="2">GNU 自动变量一览表 </font>
				</p>
				<p>
				</p>
				<table cellspacing="1" cellpadding="1" width="90%" border="1">
						<tbody>
								<tr>
										<td width="15%">
												<font size="2">名称 </font>
										</td>
										<td>
												<font size="2">含义</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$@</font>
										</td>
										<td>
												<font size="2">规则目标的文件名.如果目标是档案文件的一个成员,"$@"就是档案文件的名称</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$%</font>
										</td>
										<td>
												<font size="2">当目标是档案文件的一个成员时,"$%"是该成员的名称.否则"$%"为空</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$&lt;</font>
										</td>
										<td>
												<font size="2">第一个依赖文件的名称</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$?</font>
										</td>
										<td>
												<font size="2">以空格隔开的比目标新的所有依赖文件名.若依赖文件是档案文件的成员,只使用成员的名称</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$^</font>
										</td>
										<td>
												<font size="2">以空格隔开的所有依赖文件名.若依赖文件是档案文件的成员,只使用成员名称.无论一个依赖文件出现过多少次,"$^"值中只包含其名称的一个拷贝</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$+</font>
										</td>
										<td>
												<font size="2">与"$^"相似,但多次列出的依赖文件按照它们在构造文件中出现的顺序复制.这对于链接命令中以特定顺序重复出现的库文件名有作用</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$*</font>
										</td>
										<td>
												<font size="2">隐含规则匹配的词干.若目标为"dir/a.foo.b"且目标模式为"a.%.b",则词干为"dir/foo".对静态模式规则,词干是文件名中与目标模式中"%"匹配的部分.应避免在隐含规则或静态模式规则之外使用"$*"</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(@D)</font>
										</td>
										<td>
												<font size="2">删除结尾斜杠的目标文件名的目录部分.若"$@"的值为"dir/foo.o",则"$(@D)"为"dir".若"$@"不包含斜杠,则"$(@D)"为"."</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(@F)</font>
										</td>
										<td>
												<font size="2">目标文件名中目录下的文件部分.如果"$@"的值为"dir/foo.o",那么"$(@F)"为"foo.o".它等同于"$(notdir $@)"</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(*D)</font>
										</td>
										<td>
												<font size="2">词干中的目录部分,例如上例中的"dir"</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(*F)</font>
										</td>
										<td>
												<font size="2">词干中的目录下文件部分,例如上例中的"foo"</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(%D)</font>
										</td>
										<td>
												<font size="2">目标档案文件成员的目录部分.仅对形为"archive(member)"的档案文件成员目标有意义,且仅在member包含目录名时有用</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(%F)</font>
										</td>
										<td>
												<font size="2">目标档案文件成员中的目录下文件部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(&lt;D)</font>
										</td>
										<td>
												<font size="2">第一个依赖文件的目录部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(&lt;F)</font>
										</td>
										<td>
												<font size="2">第一个依赖文件的目录下文件部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(^D)</font>
										</td>
										<td>
												<font size="2">所有依赖文件的目录部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(^F)</font>
										</td>
										<td>
												<font size="2">所有依赖文件的目录下文件部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(?D)</font>
										</td>
										<td>
												<font size="2">比目标新的所有依赖文件的目录部分</font>
										</td>
								</tr>
								<tr>
										<td>
												<font size="2">$(?F)</font>
										</td>
										<td>
												<font size="2">比目标新的所有依赖文件的目录部分</font>
										</td>
								</tr>
						</tbody>
				</table>
		</span>
		<p id="TBPingURL">Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=521348</p>
<img src ="http://www.cppblog.com/shaovie/aggbug/15829.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/shaovie/" target="_blank">崔少伟</a> 2006-12-01 08:24 <a href="http://www.cppblog.com/shaovie/articles/15829.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux系统ioctl使用示例(转)</title><link>http://www.cppblog.com/shaovie/articles/15171.html</link><dc:creator>崔少伟</dc:creator><author>崔少伟</author><pubDate>Wed, 15 Nov 2006 03:03:00 GMT</pubDate><guid>http://www.cppblog.com/shaovie/articles/15171.html</guid><wfw:comment>http://www.cppblog.com/shaovie/comments/15171.html</wfw:comment><comments>http://www.cppblog.com/shaovie/articles/15171.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/shaovie/comments/commentRss/15171.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/shaovie/services/trackbacks/15171.html</trackback:ping><description><![CDATA[These were writed and collected by kf701,<br />you can use and modify them but NO WARRANTY.<br />  Contact with me : kf_701@21cn.com<br /><br />程序1：检测接口的 inet_addr,netmask,broad_addr<br />程序2：检查接口的物理连接是否正常<br />程序3：更简单一点测试物理连接<br />程序4：调节音量<br /><br />***************************程序1****************************************<br />#include &lt;stdio.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;errno.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />#include &lt;sys/types.h&gt;<br />#include &lt;sys/socket.h&gt;<br />#include &lt;netinet/in.h&gt;<br />#include &lt;arpa/inet.h&gt;<br /><br />#include &lt;sys/ioctl.h&gt;<br />#include &lt;net/if.h&gt;<br /><br />static void usage(){<br />        printf("usage : ipconfig interface ");<br />        exit(0);<br />}<br /><br />int main(int argc,char **argv)<br />{<br />        struct sockaddr_in *addr;<br />        struct ifreq ifr;<br />        char *name,*address;<br />        int sockfd;<br /><br />        if(argc != 2)<br />                usage();<br />        else<br />                name = argv[1];<br /><br />        sockfd = socket(AF_INET,SOCK_DGRAM,0);<br />        strncpy(ifr.ifr_name,name,IFNAMSIZ-1);<br /><br />        if(ioctl(sockfd,SIOCGIFADDR,&amp;ifr) == -1)<br />                perror("ioctl error"),exit(1);<br />        addr = (struct sockaddr_in *)&amp;(ifr.ifr_addr);<br />        address = inet_ntoa(addr-&gt;sin_addr);<br />        printf("inet addr: %s ",address);<br /><br />        if(ioctl(sockfd,SIOCGIFBRDADDR,&amp;ifr) == -1)<br />                perror("ioctl error"),exit(1);<br />        addr = (struct sockaddr_in *)&amp;ifr.ifr_broadaddr;<br />        address = inet_ntoa(addr-&gt;sin_addr);<br />        printf("broad addr: %s ",address);<br /><br />        if(ioctl(sockfd,SIOCGIFNETMASK,&amp;ifr) == -1)<br />                perror("ioctl error"),exit(1);<br />        addr = (struct sockaddr_in *)&amp;ifr.ifr_addr;<br />        address = inet_ntoa(addr-&gt;sin_addr);<br />        printf("inet mask: %s ",address);<br /><br />        printf(" ");<br />        exit(0);<br />}<br /><br />******************************** 程序2*****************************************************<br />#include &lt;stdio.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;errno.h&gt;<br />#include &lt;fcntl.h&gt;<br />#include &lt;getopt.h&gt;<br />#include &lt;sys/socket.h&gt;<br />#include &lt;sys/ioctl.h&gt;<br />#include &lt;net/if.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />typedef unsigned short u16;<br />typedef unsigned int u32;<br />typedef unsigned char u8;<br /><br />#include &lt;linux/ethtool.h&gt;<br />#include &lt;linux/sockios.h&gt;<br /><br />int detect_mii(int skfd, char *ifname)<br />{<br />        struct ifreq ifr;<br />        u16 *data, mii_val;<br />        unsigned phy_id;<br /><br />        /* Get the vitals from the interface. */<br />        strncpy(ifr.ifr_name, ifname, IFNAMSIZ);<br />        if (ioctl(skfd, SIOCGMIIPHY, &amp;ifr) &lt; 0)<br />        {<br />                fprintf(stderr, "SIOCGMIIPHY on %s failed: %s ", ifname,<br />                strerror(errno));<br />                (void) close(skfd);<br />                return 2;<br />        }<br /><br />        data = (u16 *)(&amp;ifr.ifr_data);<br />        phy_id = data[0];<br />        data[1] = 1;<br /><br /><br />        if (ioctl(skfd, SIOCGMIIREG, &amp;ifr) &lt; 0)<br />        {<br />                fprintf(stderr, "SIOCGMIIREG on %s failed: %s ", ifr.ifr_name,<br />                strerror(errno));<br />                return 2;<br />        }<br /><br />        mii_val = data[3];<br /><br />        return(((mii_val &amp; 0x0016) == 0x0004) ? 0 : 1);<br />}<br /><br />int detect_ethtool(int skfd, char *ifname)<br />{<br />        struct ifreq ifr;<br />        struct ethtool_value edata;<br /><br />        memset(&amp;ifr, 0, sizeof(ifr));<br />        edata.cmd = ETHTOOL_GLINK;<br /><br />        strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)-1);<br />        ifr.ifr_data = (char *) &amp;edata;<br /><br />        if (ioctl(skfd, SIOCETHTOOL, &amp;ifr) == -1)<br />        {<br />                printf("ETHTOOL_GLINK failed: %s ", strerror(errno));<br />                return 2;<br />        }<br /><br />        return (edata.data ? 0 : 1);<br />}<br /><br />int main(int argc, char **argv)<br />{<br />        int skfd = -1;<br />        char *ifname;<br />        int retval;<br /><br />        if( argv[1] )<br />                ifname = argv[1];<br />        else<br />                ifname = "eth0";<br /><br />        /* Open a socket. */<br />        if (( skfd = socket( AF_INET, SOCK_DGRAM, 0 ) ) &lt; 0 )<br />        {<br />                printf("socket error ");<br />                exit(-1);<br />        }<br /><br />        retval = detect_ethtool(skfd, ifname);<br /><br />        if (retval == 2)<br />                retval = detect_mii(skfd, ifname);<br /><br /><br />        close(skfd);<br /><br />        if (retval == 2)<br />                printf("Could not determine status ");<br /><br />        if (retval == 1)<br />                printf("Link down ");<br /><br />        if (retval == 0)<br />                printf("Link up ");<br /><br />        return retval;<br />}<br /><br />*******************************程序3*****************************************************<br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;errno.h&gt;<br />#include &lt;net/if.h&gt;<br />#include &lt;linux/sockios.h&gt;<br />#include &lt;sys/ioctl.h&gt;<br />#define LINKTEST_GLINK 0x0000000a<br /><br />struct linktest_value {<br />        unsigned int    cmd;<br />        unsigned int    data;<br />};<br /><br />static<br />void<br />usage(const char * pname)<br />{<br />        fprintf(stderr, "usage: %s &lt;device&gt; ", pname);<br />        fprintf(stderr, "returns: ");<br />        fprintf(stderr, " 0: link detected ");<br />        fprintf(stderr, " %d: %s ", ENODEV, strerror(ENODEV));<br />        fprintf(stderr, " %d: %s ", ENONET, strerror(ENONET));<br />        fprintf(stderr, " %d: %s ", EOPNOTSUPP, strerror(EOPNOTSUPP));<br />        exit(EXIT_FAILURE);<br />}<br /><br />static<br />int<br />linktest(const char * devname)<br />{<br />        struct ifreq ifr;<br />        struct linktest_value edata;<br />        int fd;<br /><br />        /* setup our control structures. */<br />        memset(&amp;ifr, 0, sizeof(ifr));<br />        strcpy(ifr.ifr_name, devname);<br /><br />        /* open control socket. */<br />        fd=socket(AF_INET, SOCK_DGRAM, 0);<br />        if(fd &lt; 0 ) {<br />                return -ECOMM;<br />        }<br /><br />        errno=0;<br />        edata.cmd = LINKTEST_GLINK;<br />        ifr.ifr_data = (caddr_t)&amp;edata;<br /><br />        if(!ioctl(fd, SIOCETHTOOL, &amp;ifr)) {<br />                if(edata.data) {<br />                        fprintf(stdout, "link detected on %s ", devname);<br />                        return 0;<br />                } else {<br />                        errno=ENONET;<br />                }<br />        }<br /><br />        perror("linktest");<br />        return errno;<br />}<br /><br />int<br />main(int argc, char *argv[])<br />{<br />        if(argc != 2) {<br />                usage(argv[0]);<br />        }<br />        return linktest(argv[1]);<br />}<br /><br />*************************************程序4*********************************************************<br />#include &lt;sys/types.h&gt;<br />#include &lt;sys/stat.h&gt;<br />#include &lt;fcntl.h&gt;<br />#include &lt;sys/ioctl.h&gt;<br />#include &lt;sys/soundcard.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;unistd.h&gt;<br />#include &lt;math.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#define  BASE_VALUE 257<br /><br />int main(int argc,char *argv[])<br />{<br />        int mixer_fd=0;<br />        char *names[SOUND_MIXER_NRDEVICES]=SOUND_DEVICE_LABELS;<br />        int value,i;<br /><br />        printf(" usage:%s dev_no.[0..24] value[0..100] ",argv[0]);<br />        printf("eg. %s 0 100 ",argv[0]);<br />        printf("    will change the volume to MAX volume. ");<br />        printf("The dev_no. are as below: ");<br />        for (i=0;i&lt;SOUND_MIXER_NRDEVICES;i++){<br />                if (i%3==0) printf(" ");<br />                printf("%s:%d ",names[i],i);<br />        }<br />        printf(" ");<br /><br />        if (argc&lt;3)<br />                exit(1);<br /><br />        if ((mixer_fd = open("/dev/mixer",O_RDWR))){<br />                printf("Mixer opened successfully,working... ");<br />                value=BASE_VALUE*atoi(argv[2]);<br /><br />                if (ioctl(mixer_fd,MIXER_WRITE(atoi(argv[1])),&amp;value)==0)<br />                printf("successfully.....");<br />                else    printf("unsuccessfully.....");<br />                printf("done. ");<br />         }else<br />                printf("can't open /dev/mixer error.... ");<br /><br />        exit(0);<br />}<br /><br />**********************************************************************************************<img src ="http://www.cppblog.com/shaovie/aggbug/15171.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/shaovie/" target="_blank">崔少伟</a> 2006-11-15 11:03 <a href="http://www.cppblog.com/shaovie/articles/15171.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>文件输出流引起的小问题</title><link>http://www.cppblog.com/shaovie/articles/14428.html</link><dc:creator>崔少伟</dc:creator><author>崔少伟</author><pubDate>Tue, 31 Oct 2006 09:56:00 GMT</pubDate><guid>http://www.cppblog.com/shaovie/articles/14428.html</guid><wfw:comment>http://www.cppblog.com/shaovie/comments/14428.html</wfw:comment><comments>http://www.cppblog.com/shaovie/articles/14428.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/shaovie/comments/commentRss/14428.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/shaovie/services/trackbacks/14428.html</trackback:ping><description><![CDATA[
		<p>#include &lt;stdio.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;string&gt;<br />#include &lt;sys/types.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;unistd.h&gt;<br />#include &lt;sys/wait.h&gt;</p>
		<p>class Base<br />{<br />        public:<br />                static pid_t ppid_c;<br />                static void   setppid(pid_t j){ ppid_c = j;}<br />                static pid_t getppid_c (){ return ppid_c;}<br />};<br />pid_t Base::ppid_c = 0;<br />void test (int signo)<br />{<br />        printf ("before sleep\n");<br />        sleep (3);<br />        printf ("after sleep 3 sec\n");<br />}<br />int main ()<br />{<br />        pid_t pid = fork ();<br />        if (pid &gt; 0)<br />        {<br />                signal (SIGUSR1, test);<br />                printf ("ppid = %d", getpid ());<br />                fflush (stdout); /////////////////////////////////////////////////////////问题所在<br />                signal (SIGINT, SIG_IGN);<br />                int st;<br />                waitpid (pid, &amp;st, 0);<br />        }else<br />                if (pid == 0)<br />                {<br />                        setsid ();<br />                        sleep (10);<br />                        Base::setppid (getppid ());<br />                        printf ("chiled sleep over\n");<br />                        printf ("child ppid = %d", Base::getppid_c ());<br />                        kill (Base::getppid_c (), SIGUSR1);<br />                        printf ("child program");<br />                        exit (0);<br />                }<br />}<br />在加上注释行以前..父进程居然不打印..郁闷了半天..最后组长想到这个问题printf ("ppid = %d", getpid ());<br />里边没有加\n 所以输出流先缓存起来.没有直接输出, 得手动清理</p>
<img src ="http://www.cppblog.com/shaovie/aggbug/14428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/shaovie/" target="_blank">崔少伟</a> 2006-10-31 17:56 <a href="http://www.cppblog.com/shaovie/articles/14428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linuxGDB下动态链接库的调试</title><link>http://www.cppblog.com/shaovie/articles/13182.html</link><dc:creator>崔少伟</dc:creator><author>崔少伟</author><pubDate>Sat, 30 Sep 2006 07:25:00 GMT</pubDate><guid>http://www.cppblog.com/shaovie/articles/13182.html</guid><wfw:comment>http://www.cppblog.com/shaovie/comments/13182.html</wfw:comment><comments>http://www.cppblog.com/shaovie/articles/13182.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/shaovie/comments/commentRss/13182.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/shaovie/services/trackbacks/13182.html</trackback:ping><description><![CDATA[
		<span class="content">
				<p>gdb) file &lt;你的exe&gt;<br />(gdb) load &lt;你的so&gt;                #这条应该是可选的</p>
				<p>(gdb) dir &lt;so'dir&gt;<br />(gdb) sharedlibrary &lt;你的so&gt;<br />(gdb) breakpoint &lt;你的so中somewhere&gt;<br />(gdb) run<br />load 是将动态库加载入内存。<br />sharedlibrary是将动态库的符号读入gdb，为了你能找到变量和函数名。<br />它们本身是没有明显的动作，但后面当你直接设置断点到动态库的函数（或行号）时，你就可以成功了。在此之前要记得用dir将动态库的源码也加入搜索路径。</p>
		</span>
<img src ="http://www.cppblog.com/shaovie/aggbug/13182.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/shaovie/" target="_blank">崔少伟</a> 2006-09-30 15:25 <a href="http://www.cppblog.com/shaovie/articles/13182.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>