Category Archives: Socket Programming

Socket programming tutorials in C, Python, Perl, Php, Java and Winsock

C code to perform IP whois

By | February 16, 2012

Theory The whois information of an ip address provides various details like its network, range, isp etc. This information is maintained by various regional registry servers. Read the wikipedia article on regional internet registries for more information. There are a total of 5 regional registries spanning various geographical regions of the world. For example if… Read More »

Winsock tutorial – Socket programming in C on windows

By | December 26, 2011

Socket programming with winsock This is a quick guide/tutorial to learning socket programming in C language on Windows. “Windows” because the code snippets shown over here will work only on Windows. The windows api to socket programming is called winsock. Sockets are the fundamental “things” behind any kind of network communications done by your computer…. Read More »

Handle multiple socket connections with fd_set and select on Linux

By | December 25, 2011

Handle multiple socket connections When writing server programs using sockets , it becomes necessary to handle multiple connections at a time , since a server needs to serve multiple clients. There are many ways to do so. On linux this can be done in various ways like forking , threading , select method etc. In… Read More »

C program to get a domain’s whois information using sockets on Linux

By | December 23, 2011

Whois A whois client is a program that will simply fetch the whois information for a domain/ip address from the whois servers. The code over here works according to the algorithm discussed here. Code hostname_to_ip – This is a simple function to get an IP of a domain. str_replace – This is a generic string… Read More »

Get local ip in C on linux

By | December 20, 2011

Local Ip address The local ip is the source ip in IP packets send out from a system. When the system is a part of a local area network then the local ip in most cases is something like 192.168.*.* . The network interface (eth0) is assigned an ip address of that range. However when… Read More »

Code a packet sniffer in C with winpcap

By | December 18, 2011

Winpcap Winpcap is a packet capture library for Windows used for packet sniffing and sending raw packets. Wireshark is a popular sniffer tool that uses winpcap to sniff packets. Here is a sample code which shows how winpcap can be used to sniff incoming packets on a particular interface. Code Compile The code can be… Read More »