July 1, 2011

P2P NAT HOLE PUNCHING UDP

One of the best articles describing udp hole punching

http://pdos.csail.mit.edu/~baford/nat/draft-ford-natp2p-00.txt

There is another article that goes into details on how to predict port on symmetrical NAT. Here is the article/IETF DRAFT 

Internet Draft                                                   B. Ford
Document: draft-ford-natp2p-00.txt                                M.I.T.
Expires: October 2003                                         April 2003


   Network Address Translation and Peer-to-Peer Applications (NATP2P)


Status of this Memo

   This document is an Internet-Draft and is subject to all provisions
   of Section 10 of RFC2026.  Internet-Drafts are working documents of
   the Internet Engineering Task Force (IETF), its areas, and its
   working groups.  Note that other groups may also distribute working
   documents as Internet-Drafts.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time.  It is inappropriate to use Internet- Drafts as reference
   material or to cite them other than as "work in progress."

   The list of current Internet-Drafts can be accessed at
   http://www.ietf.org/1id-abstracts.html

   The list of Internet-Draft Shadow Directories can be accessed at
   http://www.ietf.org/shadow.html

   Distribution of this document is unlimited.

Copyright Notice

   Copyright (C) The Internet Society (2003).  All Rights Reserved.

Abstract

   This document describes and recommends methods by which peer-to-peer
   (P2P) applications can operate efficiently in the presence of Network
   Address Translation (NAT).  This document also provides
   recommendations for the design of network address translators, in
   order for them to support P2P applications effectively without
   compromising security or performance.  This memo focuses on the
   interaction of P2P with NAT in the absence of any special proxy,
   gateway, or relaying protocols.  While not intending to preclude the
   use of such protocols, the goal of this memo is to enable P2P
   applications to function automatically without specific knowledge of
   the type, location, or configuration of the NAT.





Ford                                                            [Page 1]
 
draft-ford-natp2p-00.txt                                      April 2003


1. Introduction

   The ubiquitous deployment of Network Address Translation (NAT) on the
   Internet has provided an effective if hopefully temporary means of
   working around the ongoing depletion of the IP address space.  At the
   same time, however, the asymmetric addressing and connectivity
   regimes established by NAT and firewall systems have created unique
   problems for peer-to-peer (P2P) applications and protocols, such as
   teleconferencing and multiplayer on-line gaming.  This document
   discusses these issues and how they can be addressed.  Familiarity is
   assumed with NAT terminology and conventions, as specified in [NAT-
   TRAD] and [NAT-TERM].  As used throughout this document, the term
   "NAT" refers to "Traditional NAT" in both of its standard variants:
   namely Basic NAT, in which only IP addresses are translated, as well
   as Network Address/Port Translation (NAPT), where both IP addresses
   and transport-level port numbers are translated.  In general, this
   document always assumes NAPT as the standard "worst-case" scenario.

   In the traditional client/server paradigm, for which current NAT and
   firewall mechanisms are primarily designed, network communication
   typically operates in terms of sessions that originate in a privately
   addressed network behind a network address translator, and are
   directed to a well-connected public server with a stable IP address
   and DNS mapping.  The client, or originator, of these connections
   often does not have its own routable IP address on the public
   Internet, but instead must share a single public IP address with a
   number of other hosts on the same private network using the NAT as a
   multiplexor.  The lack of a stable, dedicated public IP address is
   not a problem for most client software such as web browsers, because
   the client only needs to be addressable for the duration of a
   particular session.

   In the peer-to-peer paradigm, however, Internet hosts that would
   normally be considered to be "clients" need to establish
   communication sessions directly with each other.  In this case, both
   the initiator and responder in a communication session might lie
   behind a NAT/Firewall, without any permanent IP address or other form
   of public network presence.  A common on-line gaming architecture,
   for example, is for the participating application hosts to contact a
   well-known server for initialization and administration purposes, but
   then to establish direct connections with each other for fast and
   efficient propagation of updates during gameplay.  Similarly, a file
   sharing application might contact a well-known server for resource
   discovery or searching purposes, but establish direct connections
   with peer hosts for data transfer.  NAT creates a problem for peer-
   to-peer connections because unless the NAT is specially configured,
   hosts behind the NAT have no consistent, permanently usable ports to
   which incoming TCP or UDP connections from "the Internet at large"



Ford                                                            [Page 2]
 
draft-ford-natp2p-00.txt                                      April 2003


   can be directed.  Firewall functionality, which is typically but not
   always bundled with NAT, creates a similar problem because firewalls
   are generally designed as one-way filters: sessions initiated inside
   the protected network are allowed, but attempts by external hosts on
   the Internet at large to initiate communication sessions with hosts
   inside the firewall are blocked.  RFC 3235 [NAT-APPL] briefly
   addresses this issue, but does not offer any general solutions that
   do not compromise security; filling that gap is the purpose of this
   document.

2. Techniques for P2P Communication with NAT

   This section describes in detail the currently known techniques for
   implementing peer-to-peer communication in the presence of NAT, from
   the perspective of the application or protocol designer.

2.1. Relaying

   The most reliable, but least efficient, method of implementing peer-
   to-peer communication in the presence of NAT is to make the peer-to-
   peer communication look to the network like client/server
   communication.  For example, suppose two client hosts, A and B, have
   each initiated TCP or UDP connections with a well-known server S
   having a permanent IP address.  Clients A and B both reside on
   privately addressed networks behind network address translators,
   however, and neither of them have control over a public IP address or
   permanently stable TCP or UDP port to which incoming connections can
   be directed.

                                Server S
                                   |
                                   |
            +----------------------+----------------------+
            |                                             |
          NAT A                                         NAT B
            |                                             |
            |                                             |
         Client A                                      Client B

   Instead of attempting to establish a direct TCP or UDP connection
   between clients A and B, the two clients can simply use the server S
   to relay messages between them.  For example, to send a message to
   client B, client A simply sends the message to server S along its
   already-established client/server connection, and server S then sends
   the message on to client B using its existing client/server
   connection with B.  This method has the advantage that it will always
   work as long as both clients have connectivity to the server.  Its
   obvious disadvantages are that it consumes the server's processing



Ford                                                            [Page 3]
 
draft-ford-natp2p-00.txt                                      April 2003


   power and network bandwidth unnecessarily, and communication latency
   between the two clients is likely to be increased even if the server
   is well-connected.

2.2. Connection Reversal

   The second technique works if only one of the clients is behind a
   NAT.  For example, suppose client A is behind a NAT but client B is
   not, as in the following diagram:

                                Server S
                            18.181.0.31:1235
                                   |
                                   |
            +----------------------+----------------------+
            |                                             |
          NAT A                                           |
    155.99.25.11:62000                                    |
            |                                             |
            |                                             |
         Client A                                      Client B
      10.0.0.1:1234                               138.76.29.7:1234

   Client A has private IP address 10.0.0.1, and the application is
   using TCP port 1234.  This client has established a connection with
   server S at public IP address 18.181.0.31 and port 1235.  NAT A has
   assigned TCP port 62000, at its own public IP address 155.99.25.11,
   to serve as the temporary public endpoint address for A's session
   with S: therefore, server S believes that client A is at IP address
   155.99.25.11 using port 62000.  Client B, however, has its own
   permanent IP address, 138.76.29.7, and the peer-to-peer application
   on B is accepting TCP connections at port 1234.

   Now suppose client B would like to initiate a peer-to-peer
   communication session with client A.  B might first attempt to
   contact client A either at the address client A believes itself to
   have, namely 10.0.0.1:1234, or at the address of A as observed by
   server S, namely 155.99.25.11:62000.  In either case, however, the
   connection will fail.  In the first case, traffic directed to IP
   address 10.0.0.1 will simply be dropped by the network because
   10.0.0.1 is not a publicly routable IP address.  In the second case,
   the TCP SYN request from B will arrive at NAT A directed to port
   62000, but NAT A will typically reject the connection request with a
   RST packet because only outgoing connections are allowed.

   After attempting and failing to establish a direct connection to A,
   client B can use server S to relay a request to client A to initiate
   a "reversed" connection to client B.  Client A, upon receiving this



Ford                                                            [Page 4]
 
draft-ford-natp2p-00.txt                                      April 2003


   relayed request through S, opens a TCP connection to client B at B's
   public IP address and port number.  NAT A allows the connection to
   proceed because it is originating inside the firewall, and client B
   can receive the connection because it is not behind a NAT.

   A variety of current peer-to-peer systems implement this technique.
   Its main limitation, of course, is that it only works as long as only
   one of the communicating peers is behind a NAT: if both peers are
   behind NATs, then the method fails.  Because connection reversal is
   not a general solution to the problem, it is NOT recommended as a
   primary strategy.  Applications may choose to attempt connection
   reversal, but should be table to fall back automatically on another
   mechanism such as relaying if neither a "forward" nor a "reversed"
   connection can be established.

2.3. UDP Hole Punching

   The third technique, and the one of primary interest in this memo, is
   sometimes known as "UDP Hole Punching."  UDP hole punching relies on
   well-established NAT conventions to allow appropriately designed
   peer-to-peer applications to "punch holes" through NATs and firewalls
   and establish direct connectivity with each other, even when both
   communicating hosts may lie behind a NAT.  This technique was
   mentioned briefly in section 5.1 of RFC 3027 [NAT-PROT] and has been
   informally described elsewhere on the Internet [KEGEL].  As the name
   implies, unfortunately, this technique works reliably only with UDP.

   We will consider two specific scenarios, and how applications can be
   designed to handle both of them gracefully.  In the first situation,
   representing the common case, two clients desiring direct peer-to-
   peer communication reside behind different NATs.  In the second, the
   two clients actually reside behind the same NAT, but do not
   necessarily know that they do.

2.3.1. Clients Behind Different NATs

   Suppose clients A and B both have private IP addresses and lie behind
   different network address translators.  The peer-to-peer application
   running on clients A and B and on server S each use UDP port 1234.  A
   and B have each initiated UDP communication sessions with server S,
   causing NAT A to assign its own public UDP port 62000 for A's session
   with S, and causing NAT B to assign its port 31000 to B's session
   with S, respectively.








Ford                                                            [Page 5]
 
draft-ford-natp2p-00.txt                                      April 2003


                                Server S
                            18.181.0.31:1234
                                   |
                                   |
            +----------------------+----------------------+
            |                                             |
          NAT A                                         NAT B
    155.99.25.11:62000                            138.76.29.7:31000
            |                                             |
            |                                             |
         Client A                                      Client B
      10.0.0.1:1234                                 10.1.1.3:1234

   Now suppose that client A wants to establish a UDP communication
   session directly with client B.  If A simply starts sending UDP
   requests to B's public address, 138.76.29.7:31000, then NAT B will
   typically discard these incoming messages because the source address
   and port number does not match those of S, with which the original
   outgoing session was established.  Similarly, if B simply starts
   sending UDP requests to A's public address, then NAT A will discard
   these messages.

   Suppose A starts sending UDP requests to B's public address, however,
   and simultaneously relays a request through server S to B, asking B
   to start sending UDP requests to A's public address.  A's outgoing
   messages directed to B's public address (138.76.29.7:31000) will
   cause NAT A to open up a new communication session between A's
   private address and B's public address.  At the same time, B's
   messages to A's public address (155.99.25.11:62000) will cause NAT B
   to open up a new communication session between B's private address
   and A's public address.  Once the new UDP sessions have been opened
   up in each direction, client A and B can communicate with each other
   directly without further reference to or burden on the "introduction"
   server S.

   The UDP hole punching technique has several useful properties.  Once
   a direct peer-to-peer UDP connection has been established between two
   NATted clients, either party on that connection can in turn take over
   the role of "introducer" and help the other party establish peer-to-
   peer connections with additional peers, minimizing the load on the
   initial introduction server S.  The application does not need to
   attempt to detect explicitly what kind of NAT it is behind, if any
   [STUN], since the procedure above will establish peer-to-peer
   communication channels equally well if either or both clients do not
   happen to be behind a NAT.  The hole punching technique even works
   automatically under "Twice NAT", where one or both clients are
   removed from the public Internet via two or more levels of address
   translation.



Ford                                                            [Page 6]
 
draft-ford-natp2p-00.txt                                      April 2003


2.3.2. Clients Behind the Same NAT

   Now consider the scenario in which the two clients (probably
   unknowingly) happen to reside behind the same NAT, and are therefore
   located in the same private IP address space.  Client A has
   established a UDP session with server S, to which the common NAT has
   assigned public port number 62000.  Client B has similarly
   established a session with S, to which the NAT has assigned public
   port number 62001.

                                Server S
                            18.181.0.31:1234
                                   |
                                   |
                                  NAT
                         A-S 155.99.25.11:62000
                         B-S 155.99.25.11:62001
                                   |
            +----------------------+----------------------+
            |                                             |
         Client A                                      Client B
      10.0.0.1:1234                                 10.1.1.3:1234

   Suppose that A and B use the UDP hole punching technique as outlined
   above to establish a communication channel using server S as an
   introducer.  Then A and B will learn each other's public IP addresses
   and port numbers as observed by server S, and start sending each
   other messages at those public addresses.  The two clients will be
   able to communicate with each other this way as long as the NAT
   allows hosts on the internal network to open translated UDP sessions
   with other internal hosts and not just with external hosts.  For
   example, when A sends a UDP packet to B's public address, the packet
   initially has a source IP address and port number of 10.0.0.1:124 and
   a destination of 155.99.25.11:62001.  The NAT receives this packet,
   translates it to have a source of 155.99.25.11:62000 (A's public
   address) and a destination of 10.1.1.3:1234, and then forwards it on
   to B.  Even if supported by the NAT, this translation and forwarding
   step is obviously unnecessary in this situation, and is likely to add
   latency to the dialog between A and B as well as burdening the NAT.

   The solution to this problem is straightforward, however.  When A and
   B initially exchange address information through server S, they
   should include their own IP addresses and port numbers as "observed"
   by themselves, as well as their addresses as observed by S.  The
   clients then simultaneously start sending packets to each other at
   each of the alternative addresses they know about, and use the first
   address that leads to successful communication.  If the two clients
   are behind the same NAT, then the packets directed to their private



Ford                                                            [Page 7]
 
draft-ford-natp2p-00.txt                                      April 2003


   addresses are likely to arrive first, resulting in a direct
   communication channel not involving the NAT.  If the two clients are
   behind different NATs, then the packets directed to their private
   addresses will fail to reach each other at all, but the clients will
   hopefully establish connectivity using their respective public
   addresses.  It is important that these packets be authenticated in
   some way, however, since in the case of different NATs it is entirely
   possible for A's messages to B's private address to reach some other,
   unrelated node on A's private network, or vice versa.

2.3.3. Consistent Port Mappings

   The hole punching technique has one main caveat: it works only if
   each of the NATs maintains a single, consistent mapping from a given
   (private IP address, private UDP port) pair to a translated (public
   IP address, public UDP port) pair, for as long as that UDP port is in
   use.  For a given UDP port on the private network, the NAT must
   ensure that the internal port is always mapped to the same public UDP
   port on the globally addressable Internet, even if communication
   occurs between that internal UDP port and multiple distinct external
   destinations on the Internet.  In particular, the NAT must not just
   naively allocate and assign a new public UDP port for each new
   session initiated from within the firewall boundary, where a
   "session" is defined by the addresses and port numbers of both
   communicating endpoints.  Assigning a new public port for each new
   session makes it impossible for a UDP application to reuse an
   already-established (public IP address, public UDP port) mapping for
   communication with different external destinations.

   While RFC 3022 [NAT-TRAD] suggests and explicitly allows NATs to
   maintain a single mapping from a (private IP address, private port)
   pair to a (public IP address, public port) pair, it unfortunately
   does not mandate this behavior.  Therefore, while many NATs implement
   the desirable behavior and therefore allow direct UDP-based P2P
   connections using the hole punching technique, other NATs currently
   do not support the technique.  Since this is the most efficient known
   method of establishing direct peer-to-peer communication between two
   nodes that are both behind NATs, and it works with a wide variety of
   existing NATs, it is recommended that applications use this technique
   if efficient peer-to-peer communication is required, but be prepared
   to fall back on simple relaying when direct communication cannot be
   established.

2.4. UDP Port Number Prediction

   A variant of the UDP hole punching technique discussed above exists
   that allows peer-to-peer UDP sessions to be created in the presence
   of some NATs that do not maintain a consistent mapping between



Ford                                                            [Page 8]
 
draft-ford-natp2p-00.txt                                      April 2003


   private and public UDP ports.  This method, sometimes called the
   "N+1" technique [BIDIR], works if public port numbers selected by the
   NAT are not held constant across all sessions originating at a given
   private IP address and port, but are nevertheless predictable.
   Consider again the situation in which two clients, A and B, each
   behind a separate NAT, have each established UDP connections with a
   permanently addressable server S:

                                  Server S
                              18.181.0.31:1234
                                     |
                                     |
              +----------------------+----------------------+
              |                                             |
            NAT A                                         NAT B
   A-S 155.99.25.11:62000                        B-S 138.76.29.7:31000
              |                                             |
              |                                             |
           Client A                                      Client B
        10.0.0.1:1234                                 10.1.1.3:1234

   NAT A has assigned its own UDP port 62000 to the communication
   session between A and S, and NAT B has assigned its port 31000 to the
   session between B and S.  By communicating through server S, A and B
   learn each other's public IP addresses and port numbers as observed
   by S.  Client A now starts sending UDP messages to port 31001 at
   address 138.76.29.7 (note the port number increment), and client B
   simultaneously starts sending messages to port 62001 at address
   155.99.25.11.  If NATs A and B assign port numbers to new sessions
   sequentially, and if not much time has passed since the A-S and B-S
   sessions were initiated, then a working bidirectional communication
   channel between A and B should result.  A's messages to B cause NAT A
   to open up a new session, to which NAT A will (hopefully) assign
   public port number 62001, because 62001 is next in sequence after the
   port number 62000 it previously assigned to the session between A and
   S.  Similarly, B's messages to A will cause NAT B to open a new
   session, to which it will (hopefully) assign port number 31001.  If
   both clients have correctly guessed the port numbers each NAT assigns
   to the new sessions, then a bidirectional UDP communication channel
   will have been established as shown below.











Ford                                                            [Page 9]
 
draft-ford-natp2p-00.txt                                      April 2003


                                  Server S
                              18.181.0.31:1234
                                     |
                                     |
              +----------------------+----------------------+
              |                                             |
            NAT A                                         NAT B
   A-S 155.99.25.11:62000                        B-S 138.76.29.7:31000
   A-B 155.99.25.11:62001                        B-A 138.76.29.7:31001
              |                                             |
              |                                             |
           Client A                                      Client B
        10.0.0.1:1234                                 10.1.1.3:1234

   Obviously there are many things that can cause this trick to fail.
   If the predicted port number at either NAT already happens to be in
   use by an unrelated session, then the NAT will skip over that port
   number and the connection attempt will fail.  If either NAT sometimes
   or always chooses port numbers non-sequentially, then the trick will
   fail.  If a different client behind NAT A (or B respectively) opens
   up a new outgoing UDP connection to any external destination after A
   (B) establishes its connection with S but before sending its first
   message to B (A), then the unrelated client will inadvertently
   "steal" the desired port number.  This trick is therefore much less
   likely to work when either NAT involved is under load.  For all of
   these reasons, it is NOT recommended that new applications implement
   this trick; it is described here for purely for historical and
   informational purposes.

2.5. Simultaneous TCP Connection Initiation

   There is a method that can be used in some cases to establish direct
   peer-to-peer TCP connections between a pair of nodes that are both
   behind NATs.  Most TCP sessions start with one endpoint sending a SYN
   packet, to which the other party responds with a SYN-ACK packet.  It
   is possible and legal, however, for two endpoints to start a TCP
   session by simultaneously sending each other SYN packets, to which
   each party subsequently responds with a separate ACK.  This procedure
   is known as a "simultaneous open."

   If a NAT receives a TCP SYN packet from outside the private network
   attempting to initiate an incoming TCP connection, the NAT will
   normally reject the connection attempt by sending back a TCP RST
   (connection reset) packet.  If, however, the SYN packet arrives with
   source and destination addresses and port numbers that correspond to
   a TCP session that the NAT believes is already active, then the NAT
   will allow the packet to pass through.  In particular, if the NAT has
   just recently seen and transmitted an outgoing SYN packet with the



Ford                                                           [Page 10]
 
draft-ford-natp2p-00.txt                                      April 2003


   same addresses and port numbers, then it will consider the session
   active and allow the incoming SYN through.  If clients A and B can
   each correctly predict the public port number that its respective NAT
   will assign the next outgoing TCP connection, and if each client
   initiates an outgoing TCP connection with the other client timed so
   that each client's outgoing SYN passes through its local NAT before
   either SYN reaches the opposite NAT, then a working peer-to-peer TCP
   connection will result.

   Unfortunately, this trick is even more fragile and timing-sensitive
   than the UDP port number prediction trick described above.  First,
   all the same things can go wrong with each side's attempt to predict
   the public port numbers the NATs will assign to the new sessions.  In
   addition, if either client's SYN arrives at the opposite NAT too
   quickly, then the NAT will reject the SYN with a RST packet, causing
   the local NAT in turn to close the new session.  Finally, even though
   support for simultaneous open is technically a mandatory part of the
   TCP specification [TCP], it is not implemented correctly or at all in
   many common operating systems.  For this reason, this trick is
   likewise mentioned here only for historical interest; it is NOT
   recommended for use by applications.  Applications that require
   efficient, direct peer-to-peer communication should use UDP.

3. NAT Design Guidelines

   This section discusses considerations for the design of network
   address translators, as they affect peer-to-peer applications.

3.1. Maintaining Consistent Public/Private Mappings for UDP Ports

   The primary and most important recommendation of this document for
   NAT designers is that the NAT maintain a consistent and stable
   mapping between a given (internal IP address, internal UDP port) pair
   and a corresponding (public IP address, public UDP port) pair for as
   long as any active sessions exist using that mapping.  The NAT may
   filter incoming traffic on a per-session basis, by examining both the
   source and destination IP addresses and port numbers in each packet.
   When a node on the private network starts sending outgoing packets to
   a new external destination, however, while using the same source IP
   address and UDP port as an existing translated UDP session, the NAT
   should ensure that the new UDP session is given the same public IP
   address and UDP port numbers as the existing session.

   One method of implementing this behavior, meant to be only
   illustrative and not prescriptive, is outlined here.  The "critical-
   path" processing performed by a NAT on a packet flowing in either
   direction typically involves extracting the source and destination IP
   addresses from the IP header, and the source and destination TCP/UDP



Ford                                                           [Page 11]
 
draft-ford-natp2p-00.txt                                      April 2003


   port numbers from the TCP/UDP header, and using these four values to
   index into a table of active sessions.  When a packet is received for
   which no entry is found in the session table, the NAT must decide
   whether or not and how to establish a new session, and this is where
   the typical "outgoing sessions only" firewall policy comes into
   effect.

   If the unknown packet was received from the public network, then it
   is usually dropped (or perhaps rejected with a RST in the case of
   TCP).  If a UDP packet for an unknown session arrives from the
   private network, however, and the NAT is configured in the typical
   way to allow outgoing UDP sessions, the then NAT looks up the
   packet's (source IP address, source UDP port) in a second internal
   table: a "mapping table."  For a given (private IP address, private
   UDP port) on the internal network, the NAT stores in the mapping
   table the corresponding (public IP address, public UDP port) it has
   assigned to represent that private endpoint.  If a mapping already
   exists, the NAT simply uses the existing mapping when constructing
   the new session.  If no such entry is present in the mapping table,
   then the NAT allocates a new public UDP port from its pool and
   creates a new mapping table entry along with the new session.  The
   NAT also maintains with each entry in the mapping table a list or
   count of the active sessions using that mapping, so that it can
   reassign the public UDP port to other purposes once all of the
   outstanding sessions for the mapping are deemed inactive.

3.1.1. Preserving Port Numbers

   Some NATs, when establishing a new UDP session, attempt to assign the
   same public port number as the corresponding private port number, if
   that port number happens to be available.  For example, if client A
   at address 10.0.0.1 initiates an outgoing UDP session with a datagram
   from port number 1234, and the NAT's public port number 1234 happens
   to be available, then the NAT uses port number 1234 at the NAT's
   public IP address as the translated endpoint address for the session.
   This behavior might be beneficial to some legacy UDP applications
   that expect to communicate only using specific UDP port numbers, but
   it is not recommended that applications depend on this behavior since
   it is only possible for a NAT to preserve the port number if at most
   one node on the internal network is using that port number.

   In addition, a NAT should NOT try to preserve the port number in a
   new session if doing so would conflict with the goal of maintaining a
   consistent mapping between public and private endpoint addresses.
   For example, suppose client A at internal port 1234 has established a
   session with external server S, and NAT A has assigned public port
   62000 to this session because port number 1234 on the NAT was not
   available at the time.  Now suppose port number 1234 on the NAT



Ford                                                           [Page 12]
 
draft-ford-natp2p-00.txt                                      April 2003


   subsequently becomes available, and while the session between A and S
   is still active, client A initiates a new session from its same
   internal port (1234) to a different external node B.  In this case,
   because an active mapping has already been established between client
   A's port 1234 and the NAT's public port 62000, this mapping should be
   maintained and the new session should also use port 62000 as the
   public port corresponding to client A's port 1234.  The NAT should
   NOT assign public port 1234 to this new session just because port
   1234 has become available: that behavior would not be likely to
   benefit the application in any way since the application has already
   been operating with a translated port number, and it would break any
   attempts the application might make to establish peer-to-peer
   connections using the UDP hole punching technique.

3.2. Maintaining Consistent Public/Private Mappings for TCP Ports

   For consistency with the behavior of UDP translation, it is suggested
   that NATs also maintain a consistent mapping between private and
   public (IP address, TCP port number) pairs for TCP connections, in
   the same way as described above for UDP.  Maintaining consistent
   mappings for TCP ports facilitates the operation of the simultaneous
   TCP open technique, which although not recommended in general for
   peer-to-peer applications, may be useful in controlled situations
   when the two endpoints are sufficiently well synchronized.
   Maintaining TCP endpoint mappings consistently may also increase the
   NAT's compatibility with other applications that initiate multiple
   TCP connections from the same source port.

3.3. Proxy Protocols

   Besides adopting the above recommendations to make a NAT's basic
   "transparent-mode" operation as peer-to-peer friendly as possible, it
   is helpful for NATs also to support proxy protocols that allow
   applications to request an explicitly managed presence on the public
   side of the NAT.  Unfortunately, several alternative protocols have
   been proposed with varying characteristics [SOCKS, RSIP, MIDCOM,
   UPNP], and as of this writing none of them have achieved clear
   acceptance or dominance in the Internet community.  Furthermore, it
   is not clear yet how well these protocols will work in the
   increasingly common "Twice NAT" situation where clients are located
   behind multiple levels of NAT, especially if the NATs are from
   different vendors, support different features and policies, and are
   under different administrative domains.  (In the common case, one is
   owned and managed by the ISP and the other by the end user.)  For
   these reasons, this document makes no attempt to explore this issue
   in detail or to recommend specific proxy protocols for NATs to
   implement.




Ford                                                           [Page 13]
 
draft-ford-natp2p-00.txt                                      April 2003


4. Security Considerations

   Using the UDP hole punching technique in peer-to-peer applications
   and supporting it in NATs should not create any new security issues.
   In particular, the technique does not require a NAT firewall to be
   "promiscuous" in any way about acceping incoming UDP traffic.  As
   long as outgoing UDP sessions are enabled and the firewall maintains
   consistent mappings between internal and external UDP ports, the
   firewall can still filter out all incoming UDP packets except those
   with (source IP, source port, destination IP, destination port)
   tuples that exactly match those of active sessions initiated from
   within the enclave.  Filtering incoming traffic aggressively while
   maintaining consistent mappings thus allows a firewall to be "peer-
   to-peer friendly" without compromising the standard firewall security
   principle of rejecting all unsolicited incoming traffic.

   It might be argued that maintaining a consistent internal/external
   port mapping can "leak" some information to the outside about the
   applications on the internal network, particularly about the
   relationships between different UDP sessions that cross the firewall
   boundary.  If the security requirements are so critical that such a
   subtle information channel is of concern, however, then the firewall
   almost certainly should not be configured to allow unrestricted
   outgoing UDP traffic in the first place.  Controlling information
   flow to this degree generally requires that the firewall only allow
   communication only via tightly-controllable application-level
   gateways, in which case the firewall can either implement the proper
   peer-to-peer communication behavior itself or disallow it entirely.

References

[BIDIR]    Peer-to-Peer Working Group, NAT/Firewall Working Committee,
           "Bidirectional Peer-to-Peer Communication with Interposing
           Firewalls and NATs", August 2001.
           http://www.peer-to-peerwg.org/tech/nat/

[KEGEL]    Dan Kegel, "NAT and Peer-to-Peer Networking", July 1999.
           http://www.alumni.caltech.edu/~dank/peer-nat.html

[MIDCOM]   P. Srisuresh, J. Kuthan, J. Rosenberg, A. Molitor, and
           A. Rayhan, "Middlebox communication architecture and
           framework", RFC 3303, August 2002.

[NAT-APPL] D. Senie, "Network Address Translator (NAT)-Friendly
           Application Design Guidelines", RFC 3235, January 2002.

[NAT-PROT] M. Holdrege and P. Srisuresh, "Protocol Complications
           with the IP Network Address Translator", RFC 3027,



Ford                                                           [Page 14]
 
draft-ford-natp2p-00.txt                                      April 2003


           January 2001.

[NAT-TERM] P. Srisuresh and M. Holdrege, "IP Network Address
           Translator (NAT) Terminology and Considerations", RFC
           2663, August 1999.

[NAT-TRAD] P. Srisuresh and K. Egevang, "Traditional IP Network
           Address Translator (Traditional NAT)", RFC 3022,
           January 2001.

[RSIP]     M. Borella, J. Lo, D. Grabelsky, and G. Montenegro,
           "Realm Specific IP: Framework", RFC 3102, October 2001.

[SOCKS]    M. Leech, M. Ganis, Y. Lee, R. Kuris, D. Koblas, and
           L. Jones, "OCKS Protocol Version 5", RFC 1928, March 1996.

[STUN]     J. Rosenberg, J. Weinberger, C. Huitema, and R. Mahy,
           "STUN - Simple Traversal of User Datagram Protocol (UDP)
           Through Network Address Translators (NATs)", RFC 3489,
           March 2003.

[TCP]      "Transmission Control Protocol", RFC 793, September 1981.

[UPNP]     UPnP Forum, "Internet Gateway Device (IGD) Standardized
           Device Control Protocol V 1.0", November 2001.
           http://www.upnp.org/standardizeddcps/igd.asp

Author's Address

   Bryan Ford
   Laboratory for Computer Science
   Massachusetts Institute of Technology
   77 Massachusetts Ave.
   Cambridge, MA 02139

   Phone: (617) 253-5261
   E-mail: baford@mit.edu
   Web: http://www.brynosaurus.com/

Full Copyright Statement

   Copyright (C) The Internet Society (2003).  All Rights Reserved.

   This document and translations of it may be copied and furnished to
   others, and derivative works that comment on or otherwise explain it
   or assist in its implementation may be prepared, copied, published
   and distributed, in whole or in part, without restriction of any
   kind, provided that the above copyright notice and this paragraph are



Ford                                                           [Page 15]
 
draft-ford-natp2p-00.txt                                      April 2003


   included on all such copies and derivative works.  However, this
   document itself may not be modified in any way, such as by removing
   the copyright notice or references to the Internet Society or other
   Internet organizations, except as needed for the purpose of
   developing Internet standards in which case the procedures for
   copyrights defined in the Internet Standards process must be
   followed, or as required to translate it into languages other than
   English.

   The limited permissions granted above are perpetual and will not be
   revoked by the Internet Society or its successors or assigns.

   This document and the information contained herein is provided on an
   "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
   TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
   BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
   HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

































Ford                                                           [Page 16]
 

June 29, 2011

Windows CE c# .net compact framework webException "the response did not contain an end of entity mark"

This problem usually occurs on the Compact Framework of .Net.

Just setting the HTTP ProtocolVersion of the WebRequest to version 1.0 fixed my problem:

request.ProtocolVersion = System.Net.HttpVersion.Version10;



I found this solution at this blog

Windows CE c# .Net An error message cannot be displayed because an optional resource assembly containing it cannot be found.

Copy this cab file to your CE device, double-click to install it on your CE device,and now you should have the detailed debug messages now.

If anyone is still having this issue the cab file you are looking for, for CF2 is actually in
"C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics"
I am running WM5 with messaing and security pack and the cab required was System_SR_ENU.CAB and not the System_SR_ENU_wm.CAB version

There is also a stack overflow question with the same answer

June 27, 2011

popular free http proxy software

1. Privoxy, block ads
2. polipo, fast light-weight proxy
3. squid, heavy-duty enterprise proxy
4. tinyproxy

All are Free and Open Source software

I use tinyproxy most of the time, and it works great.

June 20, 2011

How to use curl to upload a file

curl -F "myfile=@testfile.exe" http://123.45.5.6/test/upload.php

June 17, 2011

A fairly new comparison of openswan and strongswan

Openswan vs strongSwan


From the beginning of my VPN project, I knew about strongSwan... but I stuck to Openswan because that’s what is covered in the Openswan book I bought and read.

After perusing the strongSwan website for a few minutes, one thing became apparent: the strongSwan project has superior documentation. The comparison isn’t even close; most of the Openswan documentation hasn’t been updated in years; it often refers to Openswan 3.0 - a branch on which development has stopped for at least 3 years, if its git repository is accurate.

Additionally, when I looked at features, a few trends emerged:
  • Openswan moved in the direction of the networking industry
    • And as a result, supports aggressive mode (which the Openswan devs ask you not to use).
    • Openswan supports the legacy KLIPS IPsec kernel stack.
  • strongSwan is interested in authentication and security:
    • No surprise, given its originator provided the x.509 patch.
      • strongSwan has better support for authentication mechanisms in general
      • Supports EAP methods, including EAP-RADIUS
      • PKCS#11 smart cards
  • strongSwan only supports KLIPS on 2.4 linux kernels; if you’re running 2.6, they use the in-kernel NETKEY IPsec stack.
  • strongSwan also supports the new IKEv2 standard (and interoperates well with other IKEv2 implementations.
    • IKEv2 allows for automatic IP address assignment, DNS assignment, and routing.
    • IKEv2 is in its infancy in Openswan.
  • strongSwan aupports Mobility and Multihomed IKEv2 (also known as MOBIKE)
  • strongSwan supports additional ciphers, such as TwoFish, and elliptic curve crypto.
  • strongSwan is modular (vs. Openswan’s monolithic nature)
  • strongSwan also has IP address pools/assignment with IKEv1, which is not offered by Openswan.

With the data available to me, strongSwan looks like the clear winner. About the only thing I’ve heard about that Openswan does that strongSwan doesn’t are:
  • KLIPS/MAST on 2.6 kernels
    • This allows (with a patched & recompiled kernel) some NAT mapping that doesn’t work well with the NETKEY stack. Cases where NAT clients have the same “internal” IP address as the server, or each other have problems with NETKEY currently.
  • IKEv1 Aggressive mode: Which is something that even the Openswan developers suggest you avoid if at all possible.

June 10, 2011

Cross compile wget on Linux for Windows

GNU wget does not release binary on Windows, and it is not very straight-forward to compile for Windows, but it works great on Windows. I just compiled wget 1.12 for Windows. Please DOWNLOAD IT HERE

I did this on Debian 5.0, and I have the following mingw package installed (not https supported, shouldn't be hard to add if you want to compile the openssl):

dpkg -l | grep -i mingw
ii  mingw32                   4.2.1.dfsg-1                       Minimalist GNU win32 (cross) compiler
ii  mingw32-binutils          2.18.50-20080109-1                 Minimalist GNU win32 (cross) binutils
ii  mingw32-runtime           3.13-1                             Minimalist GNU win32 (cross) runtime

This is how to compile wget for Windows on a Linux host using the MingW32 for Linux tool chain

1. download the gnu wget source at http://www.gnu.org/software/wget/
2. tar zxvf wget-1.12.tgz;  cd wget-1.12; 
3. ./configure CC=i586-mingw32msvc-gcc AR=i586-mingw32msvc-ar RANLIB=i586-mingw32msvc-ranlib --disable-ipv6 --host=mingw32
4. change "src/config.h" to add 
           #define WINDOWS 1
           #define INHIBIT_WRAP 1
   and comment out these two lines:
           //#define HAVE_SYMLINK 1
           //#define HAVE_USLEEP 1
4.1 comment out "src/host.c" line 67
           //extern int h_errno;
5. vi src/Makefile, add "mswindows.o" to the end of the "am_wget_OBJECTS" assignment
6. search for "LIBS =", and append "-l ws2_32 -s"
7. Make

The wget.exe file is located in src/wget.exe

Enjoy!

June 8, 2011

vsftpd config file

anonymous_enable=YES
listen_port=34567
anon_root=/tmp/ftproot
run_as_launching_user=YES
pasv_promiscuous=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
dirmessage_enable=YES
xferlog_enable=NO
connect_from_port_20=YES
listen=YES

June 7, 2011

persistent ssh tunnel

MyEnTunnel

Work really well. It retries to connect after the ssh session is disconnected.

June 2, 2011

Windows CE static IP registry setting

; Enable static IP address for VMINI1
[HKEY_LOCAL_MACHINE\Comm\VMINI1\Parms\Tcpip]
"EnableDHCP"=dword:0 ; Disable the DHCP/ enable static IP
"IPAddress"="192.168.1.3"
"SubnetMask"="255.255.255.0"
Note : VMINI1 is the correct key path to point to the registry settings used by this driver.
VMINI is the adapter name

source: http://nicolasbesson.blogspot.com/2007/11/static-ip-address-for-kitl-vmini.html

May 31, 2011

hostapd madwifi in ap mode

If you are using hostapd, and hostpad is showing the following error:

ioctl[IEEE80211_IOCTL_DELKEY]: Invalid argument
ioctl[IEEE80211_IOCTL_SETMLME]: Invalid argument


Try to add :
wme_enabled=0
in hostapd.conf

This is documented in http://madwifi-project.org/ticket/1561 and it worked for me.

May 25, 2011

udp port forward

------
Option 1: user-application based udp port forwarding

Ivan Tikhonov wrote a simple udp_redirect.c program to do just this. I like it.

The link: http://brokestream.com/udp_redirect.html

-------------

Option 2 is to use iptables.

You will need to set the middle computer (Linux) to
1. NAT
2. port forward to the local computer

iptables -t nat -A POSTROUTING -j MASQUERADE -o eth0
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 161  -j DNAT --to 192.168.1.10


Then set the local computer's default gateway to the middle computer:

route add default gw 192.168.1.100

------------
If you are looking for TCP port forwarding, I use and recommend the open source program rinetd. It works on both Windows and Linux, and supports multiple TCP connections, and is very stable. The link: http://www.boutell.com/rinetd/

php internal server error

If you just see a blank page instead of an error reporting and you have no server access so you can't edit php configuration files like php.ini try this:

- create a new file in which you include the faulty script:

<?php
 error_reporting
(E_ALL);
 
ini_set("display_errors", 1);
 include(
"file_with_errors.php");
?>

- execute this file instead of the faulty script file

now errors of your faulty script should be reported.
this works fine with me. hope it solves your problem as well!

May 20, 2011

Ubuntu Host, Windows 7 Guest, Raw disk, Virtual Box

Command in Ubuntu to create the win7 virtual machine using the raw disk Windows 7 partition that comes with the Dell computer.


This is tested on Virtual Box 4.0.4
Make sure you run everything as root
Make sure you use "IDE controller" type ICH6, otherwise the win7 will blue screen (BSOD)


This is based on the following blogs:
http://www.rajatarya.com/website/taming-windows-virtualbox-vm
http://www.researchut.com/site/virtualbox-native-partition

First install Virtualbox. I found it easier to install it using the "all platform" exectuable. Make sure you also download and install the Oracle Extension Package, which is installed using this command:
 VBoxManage extpack install Extention_file_name


Then do the following commands: make sure you are root, and you are at "/root".


----------------
VBoxManage createvm --name win7 --ostype Windows7_64 --register
 
VBoxManage modifyvm "win7" --memory 1024 --acpi on --boot1 disk --nic1 nat

 
VBoxManage storagectl "win7" --name "IDE Controller"   --add ide --controller ICH6

 
VBoxManage internalcommands createrawvmdk -filename /root/win7.vmdk -rawdisk /dev/sda -partitions 1,2,3 -mbr /root/vm.mbr -relative

 
VBoxManage storageattach win7 --storagectl "IDE Controller"  --port 0 --device 0 --type hdd --medium /root/win7.vmdk



------ Other useful commands------------

vboxmanage unregistervm win7 --delete

VBoxManage storageattach win7 --storagectl "IDE Controller"  --port 0 --device 1 --type dvddrive --medium "/root/Windows 7 64-bit Repair Disc.iso"

VBoxManage storageattach win7 --storagectl "IDE Controller"  --port 0 --device 1 --type dvddrive --medium /opt/VirtualBox/additions/VBoxGuestAdditions.iso


vboxmanage controlvm win7 reset


----If you still cannot boot your Windows 7, try to use the Windows 7 Rescue image to fix it. Use the above "vboxmanage" command to attach the repair disk ISO file and hit F12 when vbox boots to boot from CD, let it fixes it and then boot to regular Win7

May 19, 2011

boot Windows in Virtualbox

Use Xmount + Opengates, for MAC users, use openjobs

https://www.pinguin.lu/index.php

May 18, 2011

Headless Virtualbox on Ubuntu 10.04 LTS

Updated Scripts (06/07/2012):

VBoxManage createvm -name centos6 --ostype RedHat -register
VBoxManage modifyvm centos6 --memory 1024 --pae on --acpi on --boot1 dvd --nic1 nat --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm centos6 --natpf1 "www,tcp,,1888,,80"
VBoxManage storagectl centos6 --name IDE0 --add ide --controller ICH6
VBoxManage createhd -filename ~/centos6/sda.vdi -size 20000
VBoxManage storageattach centos6 --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/centos6/sda.vdi
VBoxManage storageattach centos6 --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium ~/bigfiles/CentOS-6.2-i386-minimal.iso

To enable VRDE:


VBoxManage modifyvm centos6 --vrde on --vrdeport 3392

After installation is finished, boot hdd:
VBoxManage modifyvm centos6 --boot1 disk

To add hostonly interface:
# sudo tunctl -u $USER # add tap0 device
# sudo ifconfig tap0 192.168.100.1 netmask 255.255.255.0
VBoxManage modifyvm centos6 --nic2 hostonly --hostonlyadapter2 tap0

To add the second interface as bridged interface:

VBoxManage modifyvm centos6 --nic2 bridged --bridgeadapter2 eth0

Original Post:
http://tuxnetworks.blogspot.com/2010/05/howto-virtualbox-31-headless-on-lucid.html

That's it, Virtualbox should be installed and ready to go.
Now we can move on to creating a virtual machine
Create a machine named "io"

VBoxManage createvm -name io --ostype Ubuntu -register

Configure it with a nic bridged to eth0, 256Mb RAM, enable acpi and set to boot from DVD

VBoxManage modifyvm io --memory 256 --pae on --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

Create a virtual IDE controller

VBoxManage storagectl io --name IDE0 --add ide

Create a virtual HDD

VBoxManage createvdi -filename ~/.VirtualBox/Machines/io/sda.vdi -size 48000 -register

Attach the virtual HDD

VBoxManage storageattach io --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Machines/io/sda.vdi

Create and attach a virtual DVD drive to the controller and insert the DVD image

VBoxManage storageattach io --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /store/archive/ISO/ubuntu-10.04-server-i386.iso

The default vrdp port for machines is 3389, however, if you intend to run more than one guest then each one will need to listen on a different port. I use the 3xxx range with the xxx being the last octet of the machines IP address. For example, 192.168.0.1 would be 3001.

VBoxManage modifyvm io --vrdpport 3001

And thats it, your machine has been created. Time to start it up and give it a test drive!

Using the virtual machine

Start the machine

nohup VBoxHeadless -startvm io &

On a GUI workstation, establish a remote desktop connection to the machine. In my case, the host server is called "jupiter" so I type;

rdesktop -a 8 jupiter:3001

After you have installed the OS, you need to tell the machine to boot from the hdd.

VBoxManage modifyvm io --boot1 disk

You can also deregister the dvd image if you don't intend to use it again.

VBoxManage unregisterimage dvd /store/archive/ISO/ubuntu-10.04-server-i386.iso

To Stop VM/Hibernate/Save Sate:

vboxmanage controlvm centos6 savestate

To Power Off VM:
vboxmanage controlvm centos6 poweroff


Here are some other useful commands;

VBoxManage showvminfo io
VBoxManage list hdds
VBoxManage list runningvms
VBoxManage controlvm io poweroff
VBoxManage unregistervm io --delete
VBoxManage controlvm io savestate
VBoxManage closemedium disk UUID
VBoxManage modifyhd UUID --type immutable

May 17, 2011

Linux Command Line FTP/HTTP segemented download accelartor software

  1. aria2c

  2. axel

  3. lftp (use the "pget" command of lftp)

     

    ari2c and axel supports FTP, HTTP and HTTPS, while lftp supports more protocols such as FTPS, SFTP, etc.

May 16, 2011

/etc/hosts not working?

If you have a Linux machine and your /etc/hosts is not working, make sure you have a file called

/etc/nsswitch.conf 
 
with the following content: 
 
passwd:         files
group:          files
hosts:          files dns
networks:       files dns
services:       files
protocols:      files
netmasks:       files

May 13, 2011

Windows CE 5.0 QFE download

Microsoft has moved on to Windows CE 7 (Compact 7) and revamped their download site so that all the windows CE 5.0 downloads cannot be located anymore.

To patch your platform builder 5.0 to the latest, download the "rollup" files from here:

http://www.microsoft.com/windowsembedded/en-us/downloads/download-windows-embedded-ce-5.aspx

Once you installed any QFE, you will have a application called CEQFECHECK.exe  under C:\WINDOWS\system32\ceqfecheck. This application checks which QFE you have installed and did not install. Check it out.

April 18, 2011

jQuery TableSorter "o is undefined" problem

If you use jQuery TableSorter and see the "o is undefined" problem, it is the probably the case that you are using "<td>" inside the <thead> section instead of <th>. Use <th> and you will be good.

March 17, 2011

sqlite pdo write lock problem solved

When using PHP and PDO to access an sqlite dababase, and when you do a "select *" using the $handle->query($sqlcmd), you must use "foreach" to read all the select results before you can issue the next "query" or "exec" call. Otherwise, the database will be locked.

March 4, 2011

Win32 applications GUI vs Console

This web page explains well the difference between a WIN32 GUI app vs. Console app.

March 3, 2011

php header redirect IE issue

In web development, a HTTP POST is often processed on the server ending with a header("Location:page.php") call, so that user can refresh their page without re-posting. This usually works well.

The only issue is IE. After posting or file upload, using the PHP header() call won't work with IE, although it works with Firefox. You will have to use the HTML direct instead.

February 9, 2011

Windows CE ssh server and client

Windows CE development is not as fun as Linux because of the lack of open source tools. However, once I am able to make ssh server and client running on it, it becomes better. Here is how to get ssh server and client running on windows CE 5 (ARM based):

1. Download CESSH at http://www.codeplex.com/wikipage?projectname=CESSH
    Download sshd_config at http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=CESSH&DownloadId=3561
    Download file http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=CESSH&DownloadId=3562

2. copy the files to your windows CE device, suppose "\ssh"
3. mkdir "\Hard Disk"
4. copy sshd_config "\Hard Disk"
5. mkdir "\NandFlash"
6. mkdir "\NandFlash\ssh"
7. copy ssh_host_dsa_key to "\NandFlash\ssh"
8.  run "adduser.exe root rootpass" to add the user "root" with password "rootpass"
9. copy SocketToFile.DLL to \windows
10. run "sshd.exe" 

To test it, get pocketputty
 (http://www.pocketputty.net/download.html)


If make this work over ActiveSync, use the remote port tunnel in putty.

Another great tool to have is netcat for CE: http://www.dr-bischoff.de/wince/Andreas_WINCE_stuff.html#netcat

Hope this helps.

February 4, 2011

Slick board and XML/SWF charts

SlickBoard and XML/SWF charts seem like very great products. Let me know if you have used it.

And also the google visualization tools which give you access to google finance like charts (http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html)

January 28, 2011

Free php web stat analyzer

1. TraceWatch
2. BBClone

Both GPL and Free.

January 27, 2011

git, cgit and mini_httpd

 git allows very easy local installation. We need a easy way to view the local git repository. mini_httpd is a great local web server to use, and git web app can either be "gitweb" or "cgit".

I tried "gitweb" but couldn't get it to see my projects. But I got "cgit" to work well. Here is how:

1. download and compile cgit. very simple, just follow the README file.
2. change cgit Makefile, "CGIT_CONFIG = /yourpath/cgitrc", then "touch cgit.c" and "make" again. We do this because by default cgitrc is located at /etc/ and we want it local.
3. Create your cgitrc file from the example file. I use something like this:

cache-size=0
css=/cgit.css
enable-index-links=1
enable-log-filecount=1
enable-log-linecount=1
max-stats=quarter
root-title=My git repository
root-desc=Tracking my project development
root-readme=about.html
snapshots=tar.gz
mimetype.git=image/git
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml
repo.url=linux
repo.path=/opt/gittest/.git
repo.desc=My project
repo.owner=me@me.com
repo.readme=info/web/about.html
repo.snapshots=tar.gz
repo.enable-log-linecount=0
repo.max-stats=month

4. start minihttpd and your are in business. :-)

January 26, 2011

Vim non greedy regular expression search

* (0 or more) greedy matching
\+ (1 or more) greedy matching
\{-} (0 or more) non-greedy matching
\{-n,} (at least n) non-greedy matching
 
http://blog.vinceliu.com/2008/02/non-greedy-regular-expression-matching.html 

CSS Positioning explained

http://www.barelyfitz.com/screencast/html-training/css/positioning/

Simple truth:

1. Use positon:relative in the outer box and then positoin:absolute in the inner box. This is very effective.

2. When using position:absolute with background image, make sure you explicitly specify "width" and "height", otherwise it won't work.

CSS and box shadow (blurred shadow)

All major browsers except IE (IE9 may support it) supports the CSS3 box shadow. So you need the javascript to do some tricks for IE. Here is the link. http://www.hintzmann.dk/testcenter/js/jquery/boxshadow/

January 24, 2011

Use Linux to control power outlet via USB

Much of information on this page is based the web page at here

1. buy EcoStrip , and Linksys USB2HUB4 USB 2.0 hub. This hub supports power control. Internally it uses NEC chipset.

2. Download hub-ctrl.c, OR download it at this site

3. Use lsusb utilities with -v option, you can inspect 'Hub Descriptor', such like:
Hub Descriptor:
   [...]
     wHubCharacteristic 0x0089
       Per-port power switching
       Per-port overcurrent protection
       Port indicators
   [...]

4.compile hub-ctrl.c with -lusb (you need to install libusb-dev if you don't have it)

5. run "sudo ./hub-ctrl" to list the possible hub that supports power control
Bus 002 Device 003: ID 0409:0058 NEC Corp. HighSpeed Hub
Bus 002 Device 002: ID 8087:0020
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
 
6.From above, you can see that my Linksys hub is located at Bus 2 Device 3. So I use the following command to turn the ecoStrip (which is plugged into the Linksys Hub port 1) power off:

sudo ./hub-ctrl -b 2 -d 3 -P 1 
 
And the following command to turn it on

sudo ./hub-ctrl -b 2 -d 3 -P 1 -p 1

January 21, 2011

transfer or populate sqlite table to another table

INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL1, COL4, COL7 FROM TABLE1

January 19, 2011

Use PHP to receive email

I use "sendmail". Other MTA should be similar.

1. Supposed you want php to receive emails destined to "support@example.com". Go to /etc/aliases and add a line:
     support: "|/usr/local/bin/getemail.php"

2. restart sendmail
3. go to /etc/smrsh, and create two symbolic link files:

 ln -s /usr/bin/php php
 ln -s /usr/local/bin/getemail.php getemail.php

These symbolic links basically tells sendmail you know these programs are safe for it to run

4. create your php script. A simple php script looks like this. Of course you should add your logic to it.
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
         $email .= fread($fd, 1024);
}
fclose($fd);

file_put_contents("/tmp/email.txt",$email);
die();

January 18, 2011

See which file is preventing you from mount read-only

In embedded systems, you can make your entire root file system read only (therefore preventing flash corruption) by doing:

mount -o remount,ro /

But sometimes this fails, because some files are being open as "writable". We need to find a way to identify these processes. lsof comes to rescue.
 
lsof +D / | awk $4~/w$/{print}

This commands list all open files recursively then uses an one-line awk script to find the lines that have files open for write. 

lsof is a really good friend. :-)

January 11, 2011

PHP PDF import and modification

There is a php library that allows importing a page from an existing PDF file, and then write data/graph on top of it. This essentially allows one to modify a pdf file.

The library is called FPDI (http://www.setasign.de/products/pdf-php-solutions/fpdi/about/). It uses the basic PDF library FPDF, or TCPDF (which is a fork of FPDF).

Seems useful. haven't tried it yet.

More: tried it yesterday and it works beautifully!! Use GSview32 to find the exact x/y of the place where you want to insert text/graph.

Another gem found.

January 10, 2011

https, TLS, SSL and multiple hosts

http://en.wikipedia.org/wiki/Server_Name_Indication

Unfortunately Windows XP with IE does not support this.

December 28, 2010

Use sqlite3 with codeigniter

Codeigniter is a small, fast, and well-documented web framework. However, currently (as of version 1.7.3), only sqlite2 is supported. I made codeigniter 1.7.3 work with sqlite3, including the scaffolding feature, which I really like.

Here is how to make codeigniter 1.7.3 work with sqlite3:

1. Download the php-based sqlite3 PDO driver for codeigniter. This driver is based on the driver in the codeigniter wiki, but fixed up so it works with v1.7.3 and with scaffolding.

Download the sqlite3 PDO driver (based on the wiki driver 0.2)

2. Edit system/database/DB_driver.php,  around line 831, add the 4 lines below starting with '+'.


foreach($query->result_array() as $row)
{
if (isset($row['COLUMN_NAME']))
{
$retval[] = $row['COLUMN_NAME'];
}
+ else if ($this->platform()=="pdo")
+ {
+ $retval[] = next($row);
+ }
else
{
$retval[] = current($row);
}
}


3. Create directory /pdo in /database/drivers and copy to this directory
  driver *.php files
4. Create SQLite3 database file, and put it to any directory.
  My database file is [APPPATH]/db/base.db
5. In application database config [APPPATH]/config/database.php  set next settings:
 
$db['default']['hostname'''; 
$db['default']['username''';
$db['default']['password''';
$db['default']['database''sqlite:'.APPPATH.'db/base.db';
$db['default']['dbdriver''pdo'

Enjoy.

December 27, 2010

vimdiff ignoring white space

I had been searching for a way to ignore white spaces while using vimdiff. Unfortunately, vimdiff -h yields the generic Vim help. I finally found that including the following line in vimrc solves the problem.
set diffopt+=iwhite
From the command line:
vimdiff -c 'set diffopt+=iwhite' ...
 

December 22, 2010

codeignitor removes index.php

Ok, try
<IfModule mod_rewrite.c>
    
RewriteEngine On
    RewriteBase 
/

    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d

    RewriteRule 
^(.*)$ /index.php?/$1 [L] <-- do not forget the after index.php!
</
IfModule>

<
IfModule !mod_rewrite.c>
    
# If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    
ErrorDocument 404 /index.php</IfModule
in config.php set
$config['index_page'"";$config['uri_protocol']    "AUTO"
With this htaccess index.php-hiding works for me with PHP4 and PHP5 running PHP as a CGI

Corss Compile tcpdump for linux/mips

1. download libpcap (I use version 1.1.1 at the time of post) and tcpdump (v4.1.1 as of time of post)

2. unzip both directory under the same directory, such as download/libpcap-1.1.1 and download/tcpdump-4.1.1


Build libpcap:

3. cd libpcap-1.1.1 ;

4. vi configure; search for "linux version", and remove the entire section of "case" under "linux)" until "do we have the wireless extensions". This is so that ./configure does not try to detect linux (and fail). Our linux is fine.

5. CC=/YOUR-CROSS-COMPILER-PATH/mips-openwrt-linux-gcc ./configure --host=mips-linux  --with-pcap=linux
6.  make. after make is successful, you'll have a libpcap.a

Build tcpdump:

7. cd ../tcpdump-4.1.1

8 .vi configure; earch for "linux version", and remove the entire section of "case" under "linux*)" until ";; \n *)".

9. CC=/YOUR-CROSS-COMPILER-PATH/mips-openwrt-linux-gcc ./configure --host=mips-linux  --with-pcap=linux


10. vi Makefile; search for /usr/include and remove them; the Makefile by mistake include including files in the host system. Remove them.





11. make. you can strip the final tcpdump if you like. all done.

December 17, 2010

How to cross compile tinyproxy for mips

tinyproxy version: 1.8.2

1. Change the configure file to comment the section containing "Check for asciidoc" until all the way to "ac_config_files=" (not including). Also Remove the lines that test "HAVE_A2X_TRUE".

2. CC=/home/tzhang/filter/trunk/toolchain_bin/mips-openwrt-linux-gcc ./configure --host=mips-linux --enable-filter --disable-upstream --disable-reverse --enable-transparent --disable-regexcheck

3. modify config.h: search for "rpl_", and comment the two lines that contains rpl_malloc and rpl_remalloc. Use /* */ syntax to comment out.

4. vi src/Makefile, search for "LDFLAGS", and append " -s" to it (to strip the final binary)

5. Chanage Makefile to only build src. Find SUBDIRS , comment out all other directories other than "src".

6. Make. find the binary at src/tinyproxy.

The two important articles to read to understand Windows7/Vista Arp behavior

http://blogs.technet.com/b/networking/archive/2009/03/30/tcp-ip-networking-from-the-wire-up.aspx

http://support.microsoft.com/kb/949589

December 16, 2010

bfilter

A web proxy filter that blocks ads, achieves effects like Firfox AdBlock Plus.

http://Bfilter.sourceforge.net

December 15, 2010

vim global command

http://www.networkcomputing.com/unixworld/tutorial/009/009.part3.html

syntax: g/stuff-to-search/[range]EX command

example:

global /^/ + delete
:g/blah/d  , this deletes all lines containging 'blah'
:g/blah/ ,+ delete , this deletes all lines and next lines that containing 'blah'


See more at http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Command-line

December 14, 2010

December 11, 2010

iptables SO_ORIGINAL_DST

this option in socket call can let you retrieve the original IP and port number of a redirected TCP session. Brilliant.

December 9, 2010

Git Get Started

Getting Started
Let's say you have a development project in the directory devproject. Let's start using Git to manage this project.
First off install Git. In Debian and Ubuntu we just need to do "aptitude install git"
cd devproject
git init
git add .
git commit -m "My first commit"
At this point you have all the benefits of a local version control system but no one can see your work. To make it available to other people we'll need to install a remote repository on your server. At home, I only allow people to access my code through SSH so that's the method I am going to talk about here.
ssh alex
mkdir -p /var/git/devproject.git
cd /var/git/devproject.git
git --bare init
exit
Your remote Git server is now configured so let's set up our local repository to talk to the remote repository
cd devproject
git remote add origin ssh://alex/var/git/devproject.git
We can now push our changes to that repository:
git push origin master
 
git clone: clone from a remote a new local repository
git fetch: update the local "remote" directory
git pull: = git fetch + git merge

December 8, 2010

Compile Openssl for Linux MIPS

1. Grab openssl source 1.0.c
2. Grab the Linux-MIPS patch at http://svn.cross-lfs.org/svn/repos/patches/openssl/openssl-0.9.8k-mips_support-1.patch
3. apply the patch: the patch basically just add a few lines to the Configure file. you can do that manually if you want.
4. CC=YOUR-MIPS-CC ./configure linux-mips  (add "shared" if you want to build shared library)
5. make

December 7, 2010

Increase VNC Speed (tightvnc)

  • If you select the "Low-bandwidth connection" option under "Connection profile" a lot of the default options will be changed. You will notice a drastic increase in performance from that allowance.
  • If you want to tweak the connection further, click the "Options" button to see what is under the hood. Choose the "Tight" encoding option to use TightVNC's compression. Select "Use 8-bit color" to reduce the number of colors and therefore increase speed. Below that, slide the compression bar down to its fastest point to make major changes on performance. Keep in mind that this will also affect the image quality.

December 6, 2010

rSync for Windows

1. Download the zipfile for DelteCopy (Without Installer)
2. Unzip it. It includes rsync.exe for Windows
3. copy deltecd.conf to rsyncd.conf
4. run it as a daemon: rsync --daemon --no-detach --config=\PATH\rsyncd.conf
5. if that works, it will open a port on 873 (make sure you firewall is off).
6. to make it permanent, you can use "srvany" to install it as a service.

More detailed instructions can be found at HERE.

Edit Motion Jpeg on Windows

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Background:
Digital Still Cameras for the last couple of years have been able to record video. The cameras put the video (and usually PCM aka RAW audio) in either Quicktime (MOV) or AVI containers.

The video codec is usually Motion JPEG (FourCC:MJPG) because the chip in the camera usually makes JPG and making Motion JPEG is a trivial extension since MJPEG is close to sequential JPEGs.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical hurdle on the PC:
To be able to play video or audio you need to have a de-compressor to understand the container (eg MOV, AVI) AND a de-compressor for each stream in the container.
Container examples: "MOV" –QuickTime Movie, "AVI" – Windows’ implementation of the “RIFF” format.
video examples: "M2V" -mpeg2 video, "MJPG" - Motion JPEG.
audio example: "PCM" - raw audio, "AC3" - Dolby Digital audio.

The algorithm is either built into the tool (eg MOV decode in QuickTime, Adobe & free tools like MPlayer etc) OR it has to be present as installed component on the PC.

On Windows there are TWO sorts of CODECs. The original "Video For Windows" (VfW) and DirectShow.
Editing tools (in general) ONLY work with VfW codecs.

Windows XP, Vista and Win7 all ship with DirectShow MJPEG codecs, but not VfW ….so easy to watch but you can’t EDIT.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The problem:
So you have these MOV[ MJPEG + PCM ] or AVI[ MJPEG + PCM ] files and want to edit them to do something as simple as put them on a DVD for mom to see the new baby.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The solution:
You can buy a VfW Motion JPEG decoder (eg http://www.morgan-multimedia.com/M-JPEG2000/index.htm )
OR you can get it in freeware.

FFDshow ( http://sourceforge.net/projects/ffdshow/ ) uses the libavcodec library developed in the FFmpeg Movie Player ( http://ffmpeg.org/ ) open-source effort. The libavcodec library has TONS of codecs. It is better known for its MPEG4, Xvid, DivX but it also has a lot of others. One of those “others” is MJPG.

The FFDshow project takes that decode (and in some cases encode too) capability and presents them as VfW (as well as DirectShow) codecs!

Viola, you now have the ability to understand MJPEG in video editing tools. (and tons of other codecs if you enable them).

The only thing you need to do after installation is go to the Start Menu’s “FFDShow VFW Configuration” and under the “Decoder” tab’s “Codecs” (at the top). Then on the right side scroll down to MJPEG and change it from “disabled” to “libavcodec”.



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
An Aside:
This will become more and more important in the years to come because motion films are shot and delivered to digital cinemas as “2k”, “4k” or “8k” ( http://en.wikipedia.org/wiki/Digital_cinema ) in MOTION JPEG2000 ( http://en.wikipedia.org/wiki/JPEG_2000#Motion_JPEG_2000 ) . It’s only so long before INDIE film makers and then pro-sumers want to edit in these resolutions.

‘thanks for reading.

[EDIT - LeChineur had problems with this solution. Instead of you having to read this entire thread I'm putting an edit here to summarize the problem]
In the end it came down to this. LeChineur's FFDshow install didn't work. In summary:

Originally Posted by LeChineur
This got me thinking. So I checked and I indeed did not have the ff_vfw.dll on my system. So I uninstalled the version 3.054 of FFDShow (dated 08/04/2009) which was installed on my system, downloaded and installed version 3.052 (dated 08/03/2009) and voila, I then had the ff_vfw.dll.

That solved the problem. PP now plays the video clip fine, as well as all the other "AVI" (MJPEG) clips from my Canon camera. Incredible!

So rallymax, your original post was in fact correct. Why the version of FFDShow that I first downloaded didn't install the correct dll the first time is still a mystery, but whatever...

December 4, 2010

use .htaccess to protect your web folder

Generate the password file

htpasswd -c .htpasswd fred
(where fred is the username you want to use). You'll be prompted to enter and retype your password, then the .htpasswd file will be created for you.

Next, upload this file to your website. Make sure you place it outside the Web root of your site if possible, as you don't want just anyone to be able to view the file! For example, place it above your public_html or htdocs folder. (Having said this, Apache is often set up by default to block web-based access to files beginning with .ht. Better safe than sorry though!)
If you can't place your .htpasswd file outside your Web root, name it something that's not easily guessable - for example, .htxuymwp - so that people won't be able to find it easily. (In addition, it helps to start the filename with .ht; as mentioned earlier, Apache usually blocks access to files starting with .ht.)

Creating the .htaccess file

Protecting a folder

To password protect a folder on your site, you need to put the following code in your .htaccess file:

AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user
/full/path/to/.htpasswd should be the full path to the .htpasswd file that you uploaded earlier. The full path is the path to the file from the Web server's volume root - for example, /home/username/.htpasswd or C:\wwwroot\username\.htpasswd. (If you're not sure of the full path to your site or home directory, ask your Web hosting company for this info.)
The above .htaccess file will password protect all files in the folder that it is placed in, and all sub-folders under that folder too. So if you wanted to password protect your entire site, you would place the .htaccess file in your Web root folder.

Protecting a file

To password protect just a single file in a folder, use the following .htaccess file:

AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"

<Files "mypage.html">
  Require valid-user
</Files>

This will password protect just the mypage.html file in the folder where you put the .htaccess file.

December 3, 2010

Export Audio from Windows Movie Maker

In Windows Movie Maker....
To save only the audio track of a video clip...
drag the video to the "Audio/Music" track.
Then go to...File > Publish Movie and you'll get options
for audio quality and save it to a wma audio file.

This will result in a .wma audio file. Be sure
to drag the clip all the way to the left on the
timeline or you will have dead air at the
beginning.

an IM proxy

http://www.imspector.org/

December 1, 2010

How to turn a Windows application into Windows Service

http://www.tacktech.com/display.cfm?ttid=197

The Windows NT/2000 Resource Kit provides two utilities that allow you to create a Windows user-defined service for Windows applications and some 16-bit applications (but not for batch files).

Whats needed for Windows NT/2000:
Instrsrv.exe installs and removes system services from Windows NT/2000
Srvany.exe allows any Windows application to run as a service.
You can download both files here srvany.zip

This zip includes three files. The two you need srvany.exe and instsrv.exe to install the services and also srvany.wri which documents everything you can do with the program.
Note: Make sure the Services Manager is closed while running the DOS commands.



You will need to put these files in a directory called reskit At a MS-DOS command prompt(Start | Run | "cmd.exe"), type the following command:
<path>\reskit\INSTSRV.EXE "Service Name" <path>\reskit\SRVANY.EXE
This creates the service in the Services manager and the registry keys to setup what program to run.

http:www.tacktech.com/



Next open regedit.exe Start | run | regedit.exe

http:www.tacktech.com/



Next navigate to this registry key.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name

http:www.tacktech.com/



From the Edit menu, click Add Key and name it Parameters
Next from the Edit menu, click Add Value and type this information.
Value Name: Application
Data Type : REG_SZ
String : <path>\<application.ext>

http:www.tacktech.com/



Now you can start your service from the Service Manager

http:www.tacktech.com/



With this same program you can remove the service also. Just run this command from command prompt.
<path>\reskit\INSTSRV.EXE "Service Name" REMOVE

November 30, 2010

Free online screen sharing website

http://www.mikogo.com/

If you couple this with freeconference.com, you've got a free webcast solution. :-)

To map a list of addresses

If you have a list of addresses you want to map, you can use Google Fusion Tables. Just import your EXCEL file and tell it which column is address, it will do the rest. Great product.

November 23, 2010

qq protocol analysis

the popular QQ protocol is reimplemented by open source community at eva.sourceforge.net, it is also known as libeva.


libeva is used by gaim, miranda and others for adding support to QQ.


The QQ packet is encrypted using TEA algorithm. The session key is created when login. The KEK (key encryption key) is MD5(MD5(password)), and another layer of trivial hard-coded key TEA encryption. In order to sniff QQ, one has to know the login password and therefore to derive the session key.

libyahoo2 for yahoo messenger

library to write your own yahoo messenger or understand the yahoo protocol:


http://libyahoo2.sourceforge.net/

November 21, 2010

google app email server setup

If you use a hosting company and use gmail app, in order to receive email correctly, you need to do two things:

1. set MX record of your domain to gmail app, see <creating mx records> at gmail app help. The current mx records are:

Priority Mail server
1 ASPMX.L.GOOGLE.COM
5 ALT1.ASPMX.L.GOOGLE.COM
5 ALT2.ASPMX.L.GOOGLE.COM
10 ASPMX2.GOOGLEMAIL.COM
10 ASPMX3.GOOGLEMAIL.COM

2. create SPF record, i.e.  a 'TXT' entry on your domain DNS, with value as:
"v=spf1 include:_spf.google.com ~all"

The second thing is to prevent spam. It is required by google app, otherwise you mail will be bounced.

November 14, 2010

http proxy with virus scan

http://www.server-side.de/index.htm

November 12, 2010

grep with less and color

When you simply run grep --color it implies grep --color=auto which detects whether the output is a terminal and if so enables colors. However, when it detects a pipe it disables coloring. The following command:
grep --color=always -R "search string" * | less -R
Will always enable coloring and override the automatic detection, and you will get the color highlighting in less.




You can add these to your bashrc aliases:


alias grep='grep --color=always'
alias less='less -R'


ubuntu install security updates only

just run:

sudo unattended-upgrade

config file is located at: /etc/apt/apt.conf.d/50unattended-upgrades

This command will enable the automatic security update:

sudo dpkg-reconfigure -plow unattended-upgrades

November 11, 2010

vim: list of color groups

In Vim, to see a list of color groups, use
:hi

or the complicated version:

:so $VIMRUNTIME/syntax/hitest.vim


Then you can use the group name in :match command

:help \bar to see multiple string match

For Example, the following command highlights ring or later using the color-group DiffText

:match DiffText /ring\|later/

November 4, 2010

Drop Linux kernel Cache to make your memory really free

drop_caches

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
  • echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
  • echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
  • echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.
This tunable was added in 2.6.16.

October 19, 2010

Super Cheap solid Wireless Access Point

http://www.ubnt.com/nanostationloco

only $49

October 8, 2010

Difference between typedef and define in C

here are two differences between define and typedef.

Firstly, typedef obeys scoping rules just like variables, whereas define
stays valid until the end of the file (or until a matching undef).

Secondly, some things can be done with typedef that cannot be done with define.
Examples:

Code:
typedef int* int_p1;
int_p1 a, b, c;  // a, b, and c are all int pointers.

#define int_p2 int*
int_p2 a, b, c;  // only the first is a pointer!
Code:
typedef int a10[10];
a10 a, b, c; // create three 10-int arrays
Code:
typedef int (*func_p) (int);
func_p fp // func_p is a pointer to a function that
          // takes an int and returns an int


Source: http://www.go4expert.com/forums/showthread.php?t=13405

Iphone, Android, Blackberry cross-platform app development tools

Comparing Phonegap and Titaninum at stack overflow.