Browsing articles from "March, 2007"
Mar
19
2007

DNS Query Code in C with winsock

Introduction Its no new fact that when we type a web address in our browser a dns request is immediately send by our browser to a DNS server to get the IP address of that web address.In winsock applications we achieve this by gethostbyname() and things are pretty simple.In this article we shall do this simple thing without the help of gethostbyname().We shall be sending DNS queries and receive the reply and extract the ipv4 [...]

Mar
19
2007

Packet Sniffer Code in C using Winsock

Introduction Ever since windows 2000/XP when IP_HDRINCL became a valid option for setsockopt() , WSAIoctl() had another option called SIO_RCVALL which enabled a raw socket to sniff all incoming traffic over the selected interface to whose IP the socket was bound.Hence to make a sniffer in Winsock he simple steps are : 1. Create a raw socket. 2. Bind the socket to the local IP over which the traffic is to be sniffed. 3. WSAIoctl() [...]

Mar
18
2007

Raw Sockets Using Winsock

Introduction Raw sockets, or “Raw Packets”, give you the facility to access the entire contents of a packet or datagram, both for reading and writing purpose. In other words, you can fabricate a whole packet according to your likes and dislikes. For example, a TCP packet would contain an IP header, a TCP header, and then the actual data that needs to be transmitted. When working with normal sockets, whatever we send to a socket [...]

Mar
18
2007

C Program to print permutations of a string

If the length of a string is n and the total number of places is r then the number of possible permutations is nPr or n!/(n-r)! . That is ofcourse a very simple mathematical relation. Only loops would not be a good idea to generate the permutations when n , r are both unbounded and variable. Recursion helps. The following program does the task : An Output like this comes :