Category Archives: C

Socket Programming in C

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 »

Get ip address from hostname in C using Linux sockets

By | December 10, 2011

Socket applications often need to convert hostnames like to their corresponding ip address. This is done through dns requests. The socket api in linux provides functions like gethostbyname and getaddrinfo that can be used to perform the dns requests and get the ip address. gethostbyname The first method uses the traditional gethostbyname function to… Read More »

DNS Query Code in C with linux sockets

By | October 21, 2011

This article is an extension of the article : The Linux version has some changes. On Linux the dns server ips are stored in a file called /etc/resolv.conf. So the get_dns_servers function will open this file and pickup the dns server ip addresses. A typical /etc/resolv.conf file can look like this : # Generated… Read More »

SYN Flood DOS Attack with C Source Code (Linux)

By | May 3, 2009

TCP/IP 3-way handshake is done to establish a connection between a client and a server. The process is : 1. Client –SYN Packet–> Server 2. Server –SYN/ACK Packet –> Client 3. Client –ACK Packet –> Server The above 3 steps are followed to establish a connection between source and destination. SYN Flood DOS attacks involves… Read More »