Sep 282009

In IPv4 environment(usually) we used to call function gethostbyname() to do DNS lookups.then the information is load into a struct hostent.

#include <netdb.h>
struct hostent *gethostbyname(const char *name);

struct  hostent {
        char    *h_name;        /* official name of host */
        char    **h_aliases;    /* alias list */
        int     h_addrtype;     /* host address type */
        int     h_length;       /* length of address */
        char    **h_addr_list;  /* list of addresses from name server */
#define h_addr  h_addr_list[0]  /* address, for backward compatibility */

So, the easiest way to get information from gethostbyname() call is by extracting hostent structure.

Continue reading »

Sep 262009

Every person associated with the unix / linux would be familiar with the text editor called vi / vim. but not many people know that vi / vim can be used as a stream editor. This is one example of how to use vi / vim as a text editor. suppose we have a text file containing the following text:



we will change the “hahaha” becomes “gagaga”

here’s what we do using vim

$ vim -b -c ":%s/hahaha/gagaga/g|:wq" sample.txt
"sample.txt" 6L, 24C
"sample.txt" 6L, 24C written

Now let’s see change that we’ve made

$ more sample.txt

cool isn’t it? 🙂