<?xml version="1.0"?>
<?xml-stylesheet href="http://bskahan.etria.com/rss2.css" type="text/css"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:xhtml="http://www.w3.org/1999/xhtml"
     version="2.0">

    <channel>

        <title>Co-Create Developers Portal - 水手日志</title>
        <link>http://www.opendesktop.net/Members/liyu/blog</link>
        <description>一个Linux大船上水手的梦话。</description>

        <generator>Plone 2.0</generator>
        <!-- TODO
        <lastBuildDate>Mon, 30 Sep 2002 11:00:00 GMT</lastBuildDate>
        <copyright>Copyright 1997-2002 Dave Winer</copyright>
        <docs>http://backend.userland.com/rss</docs>
        <category domain="Syndic8">1765</category>
        <managingEditor>dave@userland.com</managingEditor>
        <webMaster>dave@userland.com</webMaster>
        -->

        <!-- TODO: Should there be an individual image associatable with each
        Weblog object?  I think so... -->
        <image>
            <url>http://www.opendesktop.net/logo.jpg</url>
			<title>水手日志</title>
			<link>http://www.opendesktop.net/Members/liyu/blog</link>
        </image>

        
            
                <item>
                    <title>实现“单身”程序</title>
                    <link>http://www.opendesktop.net/Members/liyu/blog/archive/2006/05/30/weblogentry-6</link>
                    <dc:creator>liyu</dc:creator>

                    <description>                        
						<h2>就是同时只允许一个程序实例运行喽。提供可用于C和Python使用的代码片断。</h2>
						<div><p>        这种需求似乎很常见。而简单的方法往往不尽人意，比如如果我们简单地使用一个普通文件作为“锁介质”的话，如果程序因为bug（我也不喜欢它，但这东东总是层出不穷，唉）什么的异常退出的话，如果不手动删除这个文件程序就永远也启动不起来了。虽然使用普通文件的方法有一些变通的技巧：比如定时写入一些数字，然后新程序启动时检查这种变化，如果没有这个数字变化，就说明原实例已经异常退出了，但这些技巧终究是难登大雅之堂的。</p><p>       我的实现方法是基于unixdomain socket的，但第一发明都肯定不是俺了，俺最早就是发现thunderbird使用这个方式。前些天修改程序遇到了这样的需求，于是兴起实现了一个，代码如下：</p>/* oneinst.c */<br /><br /><p>#include &lt;sys/socket.h&gt;<br />#include &lt;sys/un.h&gt;<br />#include &lt;time.h&gt;<br />#include &lt;unistd.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;errno.h&gt;<br />#include &lt;sched.h&gt;<br />#include &lt;glib.h&gt;<br /><br />struct check_param {<br />    int singleton;    <br />    char *lockname;<br />};<br /><br /><br />int<br />create_instance_lock(int *singleton, char *lockname)<br />{<br />    int unsock, connfd;<br />    struct sockaddr_un addr, cliaddr;<br />    int clilen;<br /><br />    unlink(lockname);<br />    addr.sun_family = AF_LOCAL;<br />    strcpy(addr.sun_path, lockname);<br />    unsock = socket(AF_LOCAL, SOCK_STREAM, 0);<br />    if (unsock&lt;0)    return -1;<br />    if (bind(unsock, (struct sockaddr*)&amp;addr, sizeof(addr)) &lt; 0)<br />        return -2;    <br />    if (listen(unsock, 10)&lt;0)<br />        return -3;<br />    fprintf(stderr, "I am running ...\n");<br />    *singleton = 0;<br />    for ( ; ; ) {<br />        clilen = sizeof(cliaddr);<br />        if ( (connfd = accept(unsock, (struct sockaddr*) &amp;cliaddr, &amp;clilen)) &lt; 0) {<br />            continue;<br />        }<br />        close(connfd);<br />    }<br />    close(unsock);<br />    return 0;<br />}<br /><br />/*  <br />    there is other instance running, return value more than 0,<br />    elsewise I am first instance,  return 0,<br />    return value less than 0, when any error occurs.<br />*/<br />int<br />query_existing_instance(int retried, char *lockname)<br />{<br />    int unsock;<br />    struct sockaddr_un addr;<br />    const struct timespec req = {0, 500000};<br />    struct timespec res;<br />    <br />    addr.sun_family = AF_LOCAL;<br />    strcpy(addr.sun_path, lockname);<br />    unsock = socket(AF_LOCAL, SOCK_STREAM, 0);<br />    if (!unsock)    return -1;<br />    if (retried &lt;= 0)    retried = 5;<br />    while (retried--) {<br />        if (connect(unsock, (struct sockaddr*)&amp;addr, sizeof(addr))&lt;0 ) {<br />            if (errno == ECONNREFUSED) {<br />                perror("failed to connect other instance");<br />                nanosleep(&amp;req, &amp;res);<br />                continue;<br />            }<br />        } else {<br />            return 1;<br />        }<br />    }<br />    close(unsock);<br />    return 0;<br />}<br /><br />gpointer<br />detect_other_instance(struct check_param *p)<br />{<br />    int ret;<br /><br />    if (!p)    return NULL;<br />    ret = query_existing_instance(3, p-&gt;lockname);<br />    if (0 == ret) {<br />        create_instance_lock(&amp;p-&gt;singleton, p-&gt;lockname);/* it should block */<br />        fprintf(stderr, "failed to create singleton lock.\n");<br />        p-&gt;singleton = -2;<br />        g_thread_exit(NULL);<br />    } else if (ret&gt;0) {<br />        fprintf(stderr, "There is another instance running, quiting now.\n");<br />        p-&gt;singleton = 1;<br />        g_thread_exit(NULL);<br />    } else {<br />        p-&gt;singleton = -2;<br />        fprintf(stderr, "We failed  on some errors.\n");<br />    }<br />    g_thread_exit(NULL);<br />}<br /><br />int<br />other_instance_running(char *lockname)<br />{<br />    GThread *thread;<br />    GError *error=NULL;<br />    struct check_param parm;<br />        <br />    if (!g_thread_supported ()) <br />        g_thread_init(NULL);    <br />     parm.singleton = -1;<br />    parm.lockname = lockname;<br />    thread = g_thread_create_full((GThreadFunc)detect_other_instance, <br />                    &amp;parm, <br />                    0,<br />                    FALSE,<br />                    TRUE,<br />                    G_THREAD_PRIORITY_LOW,<br />                    &amp;error);<br />    if (!thread) {<br />        fprintf(stderr, "failed to create new gthread : %s\n", error-&gt;message);<br />        g_error_free(error);<br />        return -3;<br />    }<br />    while (parm.singleton == -1) sched_yield();<br />    return parm.singleton;<br />}<br /></p><br /><p><br /></p><p>嗯，难度不大，是不是？我这是使用的GLIB线程库，如果你愿意当然可以改成pthread的什么的。</p><p>下面是可以让python程序也可以使用这个功能所需的代码：</p><br /><p>/* oneinst.h */</p><br /><p>#ifndef ONEINST_H__<br />#define ONEINST_H__<br />extern other_instance_running(char *lockname);<br />#endif<br /></p><p>/* pyoneint.c */</p><br />#include &lt;Python.h&gt;<br />#include "oneinst.h"<br /><br />static PyObject*<br />mice_other_instance_running(PyObject *self, PyObject *args)<br />{<br />    char *lockname;<br />    PyObject *retobj=NULL;<br />    int ret;<br /><br />    if (!PyArg_ParseTuple(args, "s", &amp;lockname)) <br />    goto OUT;<br /><br />    ret = other_instance_running(lockname);<br />    if (ret&gt;=0)<br />        retobj = PyBool_FromLong(ret);<br />    else<br />        PyErr_SetString(PyExc_RuntimeError, "failed to check other instance");<br />OUT:<br />    return retobj;<br />}<br /><br />static PyMethodDef PyMiceMethods[] = {<br />    {"other_instance_running",  mice_other_instance_running, METH_VARARGS,<br />     ""},<br />    {NULL, NULL, 0, NULL}        /* Sentinel */<br />};<br /><br /><br /><br />PyMODINIT_FUNC<br />initpyoneinst(void)<br />{<br />    Py_InitModule("pyoneinst", PyMiceMethods);<br />}<br /><br /><br />/* setup.py */<br /><br />#! /usr/bin/python2<br /><br />from distutils.core import setup, Extension<br />import pipes<br />import string<br /> <br /><br />p1 = pipes.Template()<br />p1.prepend("pkg-config gthread-2.0 --cflags", ".-")<br />cflags = p1.open("/tmp/1", "r").read().strip()<br />p2 = pipes.Template()<br />p2.prepend("pkg-config gthread-2.0 --libs", ".-")<br />loptions = p2.open("/tmp/2", "r").read().strip()<br /><br /><br />def get_cflags_list(cflags):<br />        cflags_list = string.split(cflags, " ")<br />        ret = []<br />        for one_flag in  cflags_list:<br />                ret.append(one_flag[2:])<br />        return ret<br /><br />def get_linkflags_list(loptions):<br />    print loptions<br />        all_options = string.split(loptions, " ")<br />        libs = []<br />        lib_dirs = []<br />        for one_option in all_options:<br />                if not one_option:<br />                        continue<br />                if one_option.startswith("-L"):<br />                        lib_dirs.append(one_option[2:])<br />                elif one_option.startswith("-l"):<br />                        libs.append(one_option[2:])<br />        else:<br />                        libs.append(one_option[1:])   <br />        return libs,lib_dirs<br /><br />cflags_list = get_cflags_list(cflags)<br />cflags_list.append("../../..")<br />libs, lib_dirs = get_linkflags_list(loptions)<br />m = Extension('pyoneinst',<br />                include_dirs = cflags_list,<br />                libraries = libs,<br />                library_dirs = lib_dirs,<br />                sources = ['oneinst.c', 'pyoneinst.c'])<br /><br />setup (name='pyoneinst', version='0.1', description='oneinst module', ext_modules=[m])<br /><br /><br /><p>还有一个毛坯版的Makefile.am，如果你不知道Makefile.am是什么东西的话，就忽略它吧：</p><p>EXTRA_DIST = oneinst.c oneinst.h pyoneinst.c setup.py testoneinst.py<br /><br />all-local:<br />    python setup.py build<br />    cp  build/lib*/pyoneinst.so .<br />    rm build -fr<br />    <br />install-exec-local:<br />    install -m 644 pyoneinst.so ${pkgdatadir}/netconfpkg<br />    <br />CLEANFILES := $(notdir $(wildcard *~)) $(notdir $(wildcard *\#)) $(notdir $(wildcard \.\#*)) build<br /><br />嘿！这下程序可以单身了! 不知你的程序会唱“单身情歌”否？嘿嘿</p><br /><p>Enjoy it.<br /></p><p><br /></p><p><br /></p></div>
                    </description>


                    <pubDate>2006-05-30T14:29+00:00</pubDate>
                </item>
            
        
        
            
                <item>
                    <title>Understanding Linux Network Internals</title>
                    <link>http://www.opendesktop.net/Members/liyu/blog/archive/2006/05/15/understanding-linux-network-internals</link>
                    <dc:creator>liyu</dc:creator>

                    <description>                        
						<h2></h2>
						<div>    早就听说，有一本叫&lt;&lt;Understanding Linux Network Internals&gt;&gt;的书。我非常想了解一下Linux是如何处理网络协议栈的，故而期待己久。这不，从eMule下载了好长时间才搞到。<br /><br />    果然，这本书没有令我失望。<br /><br />    (以下超链接的目标是无效的！它们是从CHM文件中复制出来的)<br /><br />           Copyright<br />            Preface<br />                  The Audience for This Book<br />                  Background Information<br />                  Organization of the Material<br />                  Conventions Used in This Book<br />                  Using Code Examples<br />                  We'd Like to Hear from You<br />                  Safari Enabled<br />                  Acknowledgments<br />            Part I:  General Background<br />                     Chapter 1.  Introduction<br />                  Section 1.1.  Basic Terminology<br />                  Section 1.2.  Common Coding Patterns<br />                  Section 1.3.  User-Space Tools<br />                  Section 1.4.  Browsing the Source Code<br />                  Section 1.5.  When a Feature Is Offered as a Patch<br />                     Chapter 2.  Critical Data Structures<br />                  Section 2.1.  The Socket Buffer: sk_buff Structure<br />                  Section 2.2.  net_device Structure<br />                  Section 2.3.  Files Mentioned in This Chapter<br />                     Chapter 3.  User-Space-to-Kernel Interface<br />                  Section 3.1.  Overview<br />                  Section 3.2.  procfs Versus sysctl<br />                  Section 3.3.  ioctl<br />                  Section 3.4.  Netlink<br />                  Section 3.5.  Serializing Configuration Changes<br />            Part II:  System Initialization<br />                     Chapter 4.  Notification Chains<br />                  Section 4.1.  Reasons for Notification Chains<br />                  Section 4.2.  Overview<br />                  Section 4.3.  Defining a Chain<br />                  Section 4.4.  Registering with a Chain<br />                  Section 4.5.  Notifying Events on a Chain<br />                  Section 4.6.  Notification Chains for the Networking Subsystems<br />                  Section 4.7.  Tuning via /proc Filesystem<br />                  Section 4.8.  Functions and Variables Featured in This Chapter<br />                  Section 4.9.  Files and Directories Featured in This Chapter<br />                     Chapter 5.  Network Device Initialization<br />                  Section 5.1.  System Initialization Overview<br />                  Section 5.2.  Device Registration and Initialization<br />                  Section 5.3.  Basic Goals of NIC Initialization<br />                  Section 5.4.  Interaction Between Devices and Kernel<br />                  Section 5.5.  Initialization Options<br />                  Section 5.6.  Module Options<br />                  Section 5.7.  Initializing the Device Handling Layer: net_dev_init<br />                  Section 5.8.  User-Space Helpers<br />                  Section 5.9.  Virtual Devices<br />                  Section 5.10.  Tuning via /proc Filesystem<br />                  Section 5.11.  Functions and Variables Featured in This Chapter<br />                  Section 5.12.  Files and Directories Featured in This Chapter<br />                     Chapter 6.  The PCI Layer and Network Interface Cards<br />                  Section 6.1.  Data Structures Featured in This Chapter<br />                  Section 6.2.  Registering a PCI NIC Device Driver<br />                  Section 6.3.  Power Management and Wake-on-LAN<br />                  Section 6.4.  Example of PCI NIC Driver Registration<br />                  Section 6.5.  The Big Picture<br />                  Section 6.6.  Tuning via /proc Filesystem<br />                  Section 6.7.  Functions and Variables Featured in This Chapter<br />                  Section 6.8.  Files and Directories Featured in This Chapter<br />                     Chapter 7.  Kernel Infrastructure for Component Initialization<br />                  Section 7.1.  Boot-Time Kernel Options<br />                  Section 7.2.  Module Initialization Code<br />                  Section 7.3.  Optimized Macro-Based Tagging<br />                  Section 7.4.  Boot-Time Initialization Routines<br />                  Section 7.5.  Memory Optimizations<br />                  Section 7.6.  Tuning via /proc Filesystem<br />                  Section 7.7.  Functions and Variables Featured in This Chapter<br />                  Section 7.8.  Files and Directories Featured in This Chapter<br />                     Chapter 8.  Device Registration and Initialization<br />                  Section 8.1.  When a Device Is Registered<br />                  Section 8.2.  When a Device Is Unregistered<br />                  Section 8.3.  Allocating net_device Structures<br />                  Section 8.4.  Skeleton of NIC Registration and Unregistration<br />                  Section 8.5.  Device Initialization<br />                  Section 8.6.  Organization of net_device Structures<br />                  Section 8.7.  Device State<br />                  Section 8.8.  Registering and Unregistering Devices<br />                  Section 8.9.  Device Registration<br />                  Section 8.10.  Device Unregistration<br />                  Section 8.11.  Enabling and Disabling a Network Device<br />                  Section 8.12.  Updating the Device Queuing Discipline State<br />                  Section 8.13.  Configuring Device-Related Information from User Space<br />                  Section 8.14.  Virtual Devices<br />                  Section 8.15.  Locking<br />                  Section 8.16.  Tuning via /proc Filesystem<br />                  Section 8.17.  Functions and Variables Featured in This Chapter<br />                  Section 8.18.  Files and Directories Featured in This Chapter<br />            Part III:  Transmission and Reception<br />                     Chapter 9.  Interrupts and Network Drivers<br />                  Section 9.1.  Decisions and Traffic Direction<br />                  Section 9.2.  Notifying Drivers When Frames Are Received<br />                  Section 9.3.  Interrupt Handlers<br />                  Section 9.4.  softnet_data Structure<br />                     Chapter 10.  Frame Reception<br />                  Section 10.1.  Interactions with Other Features<br />                  Section 10.2.  Enabling and Disabling a Device<br />                  Section 10.3.  Queues<br />                  Section 10.4.  Notifying the Kernel of Frame Reception: NAPI and netif_rx<br />                  Section 10.5.  Old Interface Between Device Drivers and Kernel: First Part of netif_rx<br />                  Section 10.6.  Congestion Management<br />                  Section 10.7.  Processing the NET_RX_SOFTIRQ: net_rx_action<br />                     Chapter 11.  Frame Transmission<br />                  Section 11.1.  Enabling and Disabling Transmissions<br />                     Chapter 12.  General and Reference Material About Interrupts<br />                  Section 12.1.  Statistics<br />                  Section 12.2.  Tuning via /proc and sysfs Filesystems<br />                  Section 12.3.  Functions and Variables Featured in This Part of the Book<br />                  Section 12.4.  Files and Directories Featured in This Part of the Book<br />                     Chapter 13.  Protocol Handlers<br />                  Section 13.1.  Overview of Network Stack<br />                  Section 13.2.  Executing the Right Protocol Handler<br />                  Section 13.3.  Protocol Handler Organization<br />                  Section 13.4.  Protocol Handler Registration<br />                  Section 13.5.  Ethernet Versus IEEE 802.3 Frames<br />                  Section 13.6.  Tuning via /proc Filesystem<br />                  Section 13.7.  Functions and Variables Featured in This Chapter<br />                  Section 13.8.  Files and Directories Featured in This Chapter<br />            Part IV:  Bridging<br />                     Chapter 14.  Bridging: Concepts<br />                  Section 14.1.  Repeaters, Bridges, and Routers<br />                  Section 14.2.  Bridges Versus Switches<br />                  Section 14.3.  Hosts<br />                  Section 14.4.  Merging LANs with Bridges<br />                  Section 14.5.  Bridging Different LAN Technologies<br />                  Section 14.6.  Address Learning<br />                  Section 14.7.  Multiple Bridges<br />                     Chapter 15.  Bridging: The Spanning Tree Protocol<br />                  Section 15.1.  Basic Terminology<br />                  Section 15.2.  Example of Hierarchical Switched L2 Topology<br />                  Section 15.3.  Basic Elements of the Spanning Tree Protocol<br />                  Section 15.4.  Bridge and Port IDs<br />                  Section 15.5.  Bridge Protocol Data Units (BPDUs)<br />                  Section 15.6.  Defining the Active Topology<br />                  Section 15.7.  Timers<br />                  Section 15.8.  Topology Changes<br />                  Section 15.9.  BPDU Encapsulation<br />                  Section 15.10.  Transmitting Configuration BPDUs<br />                  Section 15.11.  Processing Ingress Frames<br />                  Section 15.12.  Convergence Time<br />                  Section 15.13.  Overview of Newer Spanning Tree Protocols<br />                     Chapter 16.  Bridging: Linux Implementation<br />                  Section 16.1.  Bridge Device Abstraction<br />                  Section 16.2.  Important Data Structures<br />                  Section 16.3.  Initialization of Bridging Code<br />                  Section 16.4.  Creating Bridge Devices and Bridge Ports<br />                  Section 16.5.  Creating a New Bridge Device<br />                  Section 16.6.  Bridge Device Setup Routine<br />                  Section 16.7.  Deleting a Bridge<br />                  Section 16.8.  Adding Ports to a Bridge<br />                  Section 16.9.  Enabling and Disabling a Bridge Device<br />                  Section 16.10.  Enabling and Disabling a Bridge Port<br />                  Section 16.11.  Changing State on a Bridge Port<br />                  Section 16.12.  The Big Picture<br />                  Section 16.13.  Forwarding Database<br />                  Section 16.14.  Handling Ingress Traffic<br />                  Section 16.15.  Transmitting on a Bridge Device<br />                  Section 16.16.  Spanning Tree Protocol (STP)<br />                  Section 16.17.  netdevice Notification Chain<br />                     Chapter 17.  Bridging: Miscellaneous Topics<br />                  Section 17.1.  User-Space Configuration Tools<br />                  Section 17.2.  Tuning via /proc Filesystem<br />                  Section 17.3.  Tuning via /sys Filesystem<br />                  Section 17.4.  Statistics<br />                  Section 17.5.  Data Structures Featured in This Part of the Book<br />                  Section 17.6.  Functions and Variables Featured in This Part of the Book<br />                  Section 17.7.  Files and Directories Featured in This Part of the Book<br />            Part V:  Internet Protocol Version 4 (IPv4)<br />                     Chapter 18.  Internet Protocol Version 4 (IPv4): Concepts<br />                  Section 18.1.  IP Protocol: The Big Picture<br />                  Section 18.2.  IP Header<br />                  Section 18.3.  IP Options<br />                  Section 18.4.  Packet Fragmentation/Defragmentation<br />                  Section 18.5.  Checksums<br />                     Chapter 19.  Internet Protocol Version 4 (IPv4): Linux Foundations and Features<br />                  Section 19.1.  Main IPv4 Data Structures<br />                  Section 19.2.  General Packet Handling<br />                  Section 19.3.  IP Options<br />                     Chapter 20.  Internet Protocol Version 4 (IPv4): Forwarding and Local Delivery<br />                  Section 20.1.  Forwarding<br />                  Section 20.2.  Local Delivery<br />                     Chapter 21.  Internet Protocol Version 4 (IPv4): Transmission<br />                  Section 21.1.  Key Functions That Perform Transmission<br />                  Section 21.2.  Interface to the Neighboring Subsystem<br />                     Chapter 22.  Internet Protocol Version 4 (IPv4): Handling Fragmentation<br />                  Section 22.1.  IP Fragmentation<br />                  Section 22.2.  IP Defragmentation<br />                     Chapter 23.  Internet Protocol Version 4 (IPv4): Miscellaneous Topics<br />                  Section 23.1.  Long-Living IP Peer Information<br />                  Section 23.2.  Selecting the IP Header's ID Field<br />                  Section 23.3.  IP Statistics<br />                  Section 23.4.  IP Configuration<br />                  Section 23.5.  IP-over-IP<br />                  Section 23.6.  IPv4: What's Wrong with It?<br />                  Section 23.7.  Tuning via /proc Filesystem<br />                  Section 23.8.  Data Structures Featured in This Part of the Book<br />                  Section 23.9.  Functions and Variables Featured in This Part of the Book<br />                  Section 23.10.  Files and Directories Featured in This Part of the Book<br />                     Chapter 24.  Layer Four Protocol and Raw IP Handling<br />                  Section 24.1.  Available L4 Protocols<br />                  Section 24.2.  L4 Protocol Registration<br />                  Section 24.3.  L3 to L4 Delivery: ip_local_deliver_finish<br />                  Section 24.4.  IPv4 Versus IPv6<br />                  Section 24.5.  Tuning via /proc Filesystem<br />                  Section 24.6.  Functions and Variables Featured in This Chapter<br />                  Section 24.7.  Files and Directories Featured in This Chapter<br />                     Chapter 25.  Internet Control Message Protocol (ICMPv4)<br />                  Section 25.1.  ICMP Header<br />                  Section 25.2.  ICMP Payload<br />                  Section 25.3.  ICMP Types<br />                  Section 25.4.  Applications of the ICMP Protocol<br />                  Section 25.5.  The Big Picture<br />                  Section 25.6.  Protocol Initialization<br />                  Section 25.7.  Data Structures Featured in This Chapter<br />                  Section 25.8.  Transmitting ICMP Messages<br />                  Section 25.9.  ICMP Statistics<br />                  Section 25.10.  Passing Error Notifications to the Transport Layer<br />                  Section 25.11.  Tuning via /proc Filesystem<br />                  Section 25.12.  Functions and Variables Featured in This Chapter<br />                  Section 25.13.  Files and Directories Featured in This Chapter<br />            Part VI:  Neighboring Subsystem<br />                     Chapter 26.  Neighboring Subsystem: Concepts<br />                  Section 26.1.  What Is a Neighbor?<br />                  Section 26.2.  Reasons That Neighboring Protocols Are Needed<br />                  Section 26.3.  Linux Implementation<br />                  Section 26.4.  Proxying the Neighboring Protocol<br />                  Section 26.5.  When Solicitation Requests Are Transmitted and Processed<br />                  Section 26.6.  Neighbor States and Network Unreachability Detection (NUD)<br />                     Chapter 27.  Neighboring Subsystem: Infrastructure<br />                  Section 27.1.  Main Data Structures<br />                  Section 27.2.  Common Interface Between L3 Protocols and Neighboring Protocols<br />                  Section 27.3.  General Tasks of the Neighboring Infrastructure<br />                  Section 27.4.  Reference Counts on neighbour Structures<br />                  Section 27.5.  Creating a neighbour Entry<br />                  Section 27.6.  Neighbor Deletion<br />                  Section 27.7.  Acting As a Proxy<br />                  Section 27.8.  L2 Header Caching<br />                  Section 27.9.  Protocol Initialization and Cleanup<br />                  Section 27.10.  Interaction with Other Subsystems<br />                  Section 27.11.  Interaction Between Neighboring Protocols and L3 Transmission Functions<br />                  Section 27.12.  Queuing<br />                     Chapter 28.  Neighboring Subsystem: Address Resolution Protocol (ARP)<br />                  Section 28.1.  ARP Packet Format<br />                  Section 28.2.  Example of an ARP Transaction<br />                  Section 28.3.  Gratuitous ARP<br />                  Section 28.4.  Responding from Multiple Interfaces<br />                  Section 28.5.  Tunable ARP Options<br />                  Section 28.6.  ARP Protocol Initialization<br />                  Section 28.7.  Initialization of a neighbour Structure<br />                  Section 28.8.  Transmitting and Receiving ARP Packets<br />                  Section 28.9.  Processing Ingress ARP Packets<br />                  Section 28.10.  Proxy ARP<br />                  Section 28.11.  Examples<br />                  Section 28.12.  External Events<br />                  Section 28.13.  ARPD<br />                  Section 28.14.  Reverse Address Resolution Protocol (RARP)<br />                  Section 28.15.  Improvements in ND (IPv6) over ARP (IPv4)<br />                     Chapter 29.  Neighboring Subsystem: Miscellaneous Topics<br />                  Section 29.1.  System Administration of Neighbors<br />                  Section 29.2.  Tuning via /proc Filesystem<br />                  Section 29.3.  Data Structures Featured in This Part of the Book<br />                  Section 29.4.  Files and Directories Featured in This Part of the Book<br />            Part VII:  Routing<br />                     Chapter 30.  Routing: Concepts<br />                  Section 30.1.  Routers, Routes, and Routing Tables<br />                  Section 30.2.  Essential Elements of Routing<br />                  Section 30.3.  Routing Table<br />                  Section 30.4.  Lookups<br />                  Section 30.5.  Packet Reception Versus Packet Transmission<br />                     Chapter 31.  Routing: Advanced<br />                  Section 31.1.  Concepts Behind Policy Routing<br />                  Section 31.2.  Concepts Behind Multipath Routing<br />                  Section 31.3.  Interactions with Other Kernel Subsystems<br />                  Section 31.4.  Routing Protocol Daemons<br />                  Section 31.5.  Verbose Monitoring<br />                  Section 31.6.  ICMP_REDIRECT Messages<br />                  Section 31.7.  Reverse Path Filtering<br />                     Chapter 32.  Routing: Li nux Implementation<br />                  Section 32.1.  Kernel Options<br />                  Section 32.2.  Main Data Structures<br />                  Section 32.3.  Route and Address Scopes<br />                  Section 32.4.  Primary and Secondary IP Addresses<br />                  Section 32.5.  Generic Helper Routines and Macros<br />                  Section 32.6.  Global Locks<br />                  Section 32.7.  Routing Subsystem Initialization<br />                  Section 32.8.  External Events<br />                  Section 32.9.  Interactions with Other Subsystems<br />                     Chapter 33.  Routing: The Routing Cache<br />                  Section 33.1.  Routing Cache Initialization<br />                  Section 33.2.  Hash Table Organization<br />                  Section 33.3.  Major Cache Operations<br />                  Section 33.4.  Multipath Caching<br />                  Section 33.5.  Interface Between the DST and Calling Protocols<br />                  Section 33.6.  Flushing the Routing Cache<br />                  Section 33.7.  Garbage Collection<br />                  Section 33.8.  Egress ICMP REDIRECT Rate Limiting<br />                     Chapter 34.  Routing: Routing Tables<br />                  Section 34.1.  Organization of Routing Hash Tables<br />                  Section 34.2.  Routing Table Initialization<br />                  Section 34.3.  Adding and Removing Routes<br />                  Section 34.4.  Policy Routing and Its Effects on Routing Table Definitions<br />                     Chapter 35.  Routing: Lookups<br />                  Section 35.1.  High-Level View of Lookup Functions<br />                  Section 35.2.  Helper Routines<br />                  Section 35.3.  The Table Lookup: fn_hash_lookup<br />                  Section 35.4.  fib_lookup Function<br />                  Section 35.5.  Setting Functions for Reception and Transmission<br />                  Section 35.6.  General Structure of the Input and Output Routing Routines<br />                  Section 35.7.  Input Routing<br />                  Section 35.8.  Output Routing<br />                  Section 35.9.  Effects of Multipath on Next Hop Selection<br />                  Section 35.10.  Policy Routing<br />                  Section 35.11.  Source Routing<br />                  Section 35.12.  Policy Routing and Routing Table Based Classifier<br />                     Chapter 36.  Routing: Miscellaneous Topics<br />                  Section 36.1.  User-Space Configuration Tools<br />                  Section 36.2.  Statistics<br />                  Section 36.3.  Tuning via /proc Filesystem<br />                  Section 36.4.  Enabling and Disabling Forwarding<br />                  Section 36.5.  Data Structures Featured in This Part of the Book<br />                  Section 36.6.  Functions and Variables Featured in This Part of the Book<br />                  Section 36.7.  Files and Directories Featured in This Part of the Book<br />            About the Authors<br />            Colophon<br />            Index     <br />    <br /><br /><br />    我已经看了20多个chapter，感觉这本书非常容易明白。相对于&lt;&lt;linux networking architecture&gt;&gt;，行文也易懂多了，而且内容也比较新。虽然书没讲是哪个2.6版本的内核，但从片言只语中也可以看出至少是2.6.8以后的版本，但是linux的变化如此之快，关于ingress queue的流量控制的介绍已经与最新的代码不同了。但是暇不掩玉。<br /><br />    建议看完&lt;&lt;Understanding Linux Kernel&gt;&gt;和&lt;&lt;Linux Device Driver&gt;&gt;，再看这个。因为它对一些内核的基础设施的介绍并不完整。关于驱动那一块，是我见过的讲的最详细的材料了。<br /><br /></div>
                    </description>


                    <pubDate>2006-05-15T12:53+00:00</pubDate>
                </item>
            
        
        
            
                <item>
                    <title>怎样运行Xnest</title>
                    <link>http://www.opendesktop.net/Members/liyu/blog/archive/2006/04/12/xnest</link>
                    <dc:creator>liyu</dc:creator>

                    <description>                        
						<h2></h2>
						<div><p>    Xnest是一个有意思的东东。它可以在运行中的X会话中，再启动一个X服务器。当然这个“X服务器”同时也是真实X服务器的一个客户端。除去好玩来说，单就调试一些特殊X程序和X本身而言，它的意义是非常明显的。</p><p>下面介绍一种运行Xnest的方法。</p><br />    首先需要安装xorg-x11-Xnest和xorg-x11-xauth。这个两个包，在默认共创linux 2005 SP1应该没有。需要另行安装。OK，安装好它们后。需要执行以下命令：<br /><br />    1、 xauth add :1 . `mcookie`<br /><br />    为新的X服务器的xauth配置增加配置项。<br /><br />    2、Xnest :1 &amp;<br /> <br />    在:1的DISPLAY上运行Xnest服务器。<br /><br />    3、执行其它客户端程序。例如<br /><br />    DISPLAY=:1 gnome-terminal<br />    DISPLAY=:1 nautilus<br />    DISPLAY=:1 metacity<br /><br />    等等。但gnome-session不能通过这种方式运行。<br />    <br />    可以用这样的环境试验其它窗口管理器，例如Xfce, enligntenment应该是个挺爽的事情。我运行一个E16，还不错，呵呵，以后准备再试试E17。<br /><br /><br /><br /><br />    <br />   <br /></div>
                    </description>


                    <pubDate>2006-04-12T10:23+00:00</pubDate>
                </item>
            
        
        
            
                <item>
                    <title>popen和pclose是一对呀。</title>
                    <link>http://www.opendesktop.net/Members/liyu/blog/archive/2006/04/07/popenpclose</link>
                    <dc:creator>liyu</dc:creator>

                    <description>                        
						<h2>一个使用popen的C和Python范例</h2>
						<div>    popen返回值是一个FILE*，一直以为它只是一个普通的管道描述符而已，昨天才清楚有一个pclose的C库函数，关闭它可以获得子进程的返回值！试验了一下，fclose()也可以哦：<br /><br />#include &lt;stdio.h&gt;<br /> <br />int<br />main()<br />{<br />        FILE *o;<br />        char buf[100];<br /> <br />        o = popen("../../Python/exit2.sh", "w");<br />        fread(buf, 100, 1, o);<br />        printf("%s\n", buf);<br />        printf("%d\n", fclose(o));<br />}<br /><br /><br />    如果使用python，直接使用file对象的close方法也可以达到相同效果。<br />#! /usr/bin/python<br /> <br />import popen2<br />import fcntl<br />import os<br />import errno<br /> <br />o,i = popen2.popen4('./exit1.sh; ./exit2.sh')<br />flags = fcntl.fcntl(o, fcntl.F_GETFL)<br />fcntl.fcntl(o.fileno(), fcntl.F_SETFL, flags | os.O_NONBLOCK)<br />buf=""<br />this=""<br />while True:<br />        try:<br />                 this = o.read()<br />        except IOError, msg:<br />                if errno.EAGAIN == msg[0]:<br />                        continue<br />        else:<br />                if not this:<br />                        break<br />                buf+=this<br />print buf<br />print o.close()<br /><br />其中，exit?.sh以exit 1之类的语句结束。<br /><br /><br /><br /></div>
                    </description>


                    <pubDate>2006-04-07T10:04+00:00</pubDate>
                </item>
            
        
    </channel>
</rss>
