Category : "C"

Socket Programming in C

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

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 /* * @brief * Whois client program * * @details * This program shall perform whois for a domain and get you the whois data of that domain ...

Get local ip in C on linux

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 the machine is connected to internet ...

Code a packet sniffer in C with winpcap

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 /* Simple Sniffer with winpcap , prints ethernet , ip , tcp , udp and ...

Get ip address from hostname in C using Linux sockets

Socket applications often need to convert hostnames like google.com 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 retrieve information about a hostname/domain name. Code #include<stdio.h> //printf #include<string.h> ...

Packet Sniffer Code in C using Linux Sockets (BSD) – Part 2

In the previous part we made a simple sniffer which created a raw socket and started receiving on it. But it had few drawbacks : 1. Could sniff only incoming data. 2. Could sniff only TCP or UDP or ICMP or any one protocol packets at a time. 3. Provided IP frames , so ethernet headers were not available. In this article we are ...

DNS Query Code in C with linux sockets

This article is an extension of the article : http://www.binarytides.com/blog/dns-query-code-in-c-with-winsock/ 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 by NetworkManager nameserver 208.67.222.222 nameserver 208.67.220.220 So the lines starting with nameserver can ...

Code raw sockets in C on Linux

Raw tcp sockets in C Raw sockets can be used to construct a packet manually inside an application. In normal sockets when any data is send over the network, the kernel of the operating system adds some headers to it like IP header and TCP header. So an application only needs to take care of what data it is sending and ...

SYN Flood DOS Attack with C Source Code (Linux)

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 sending too many SYN packets (with a bad or random ...

Code a port scanner in C | linux

Tcp connect port scanning Tcp connect port scanner works by trying to establish a connection with every port that is to be scanned. If a connection is established then the port is open otherwise closed. This technique of port scanner is the most basic form of port scanning. However it is the slowest and not very stealthy and easily caught by ...

C Packet Sniffer Code with libpcap and linux sockets

Libpcap Libpcap is a packet capture library for linux which can be used to sniff packets or network traffic over a network interface. Pcap Documentation gives a description of the methods and data structures available in the libpcap library. To install libpcap on your linux distro you can either download the source from the website and compile it and install. Or if ...

Pages:«123»


Connect with us