Category : "C"

Socket Programming in C

ICMP ping flood code using sockets in C – Linux

ICMP Ping Flood Icmp ping flood is a kind of DOS attack that can be performed on remote machines connected via a network. It involves sending a large number of ping echo requests (packets) to the target system such that it is not able to tackle so fast. So the result is that the host either gets too busy into replying these echo requests that it gets no time to serve its original purpose, or [...]

Programming raw udp sockets in C on Linux

Raw udp sockets Raw udp sockets are used to send manually constructed udp packets. The udp header can be found in RFC 768 and has a very simple structure as shown below. 0 7 8 15 16 23 24 31 +——–+——–+——–+——–+ | Source | Destination | | Port | Port | +——–+——–+——–+——–+ | | | | Length | Checksum | +——–+——–+——–+——–+ | | data octets … +—————- … User Datagram Header Format The length is [...]

Code a simple socket client class in c++

Wrapper class for socket functions The standard socket library in C comes with a lot of functions for every task like connecting, sending data and receiving data etc. However knowing the syntax of all the functions and calling them again and again and in the right sequence could be a bit intimidating. Using a class can help in such a situation. It has fewer functions and a simpler syntax. The class however does call the [...]

Receive full data with recv socket function in C

recv The recv function is used to receive data on a socket. For example here is the code to fetch the home page of www.msn.com The output might be something like this $ gcc simple_client.c && ./a.out Connected Data Send Reply received HTTP/1.1 200 OK Cache-Control: no-cache, no-store Pragma: no-cache Content-Type: text/html; charset=utf-8 Vary: Accept-Encoding P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND" Set-Cookie: MC1=V=3&GUID=fd76ac7b61c9436f9a414441d186becd; domain=.msn.com; expires=Mon, 08-Sep-2014 09:58:09 GMT; [...]

Programming udp sockets in C on Linux

UDP sockets This article describes how to write a simple echo server and client using udp sockets in C on Linux/Unix platform. UDP sockets or Datagram sockets are different from the TCP sockets in a number of ways. The most important difference is that UDP sockets are not connection oriented. More technically speaking, a UDP server does not accept connections and a udp client does not connect to server. The server will bind and then [...]

Server and client example with C sockets on Linux

In a previous example we learnt about the . In this example we shall build a basic ECHO client and server. The server/client shown here use TCP sockets or SOCK_STREAM. Tcp sockets are connection oriented, means that they have a concept of independant connection on a certain port which one application can use at a time. The concept of connection makes TCP a “reliable” stream such that if errors occur, they can be detected and [...]

C program to get mac address from interface name on Linux

The mac address or the hardware address or the ethernet address of an interface is a 48 bit number that looks like this : 00:1c:c0:f8:79:ee The mac address of an interface can be found given its name. The function to use is ioctl. Code Output $ gcc interface_mac.c && ./a.out Mac : 00:10:0c:28:89:1e Last Updated On : 11th September 2012

C code to perform IP whois

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 an ip address is allocated to some isp in USA then the ARIN registry would provide its whois information. To [...]

Handle multiple socket connections with fd_set and select on Linux

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 this tutorial we shall use the select method approach. The select function allows the program to monitor multiple sockets for [...]

Socket programming in C on Linux | tutorial

TCP/IP socket programming This is a quick guide/tutorial to learning socket programming in C language on a Linux system. “Linux” because the code snippets shown over here will work only on a Linux system and not on Windows. The is called winsock and we shall go through it in another tutorial. Sockets are the fundamental “things” behind any kind of network communications done by your computer. For example when you type www.google.com in your web [...]

Pages:123»