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 ...

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 ...

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. ...

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 /** Simple TCP client to fetch a web page Silver Moon (m00n.silv3r@gmail.com) */ #include<stdio.h> #include<string.h> //strlen #include<sys/socket.h> #include<arpa/inet.h> //inet_addr int main(int argc , char *argv) { int socket_desc; struct sockaddr_in server; char *message , server_reply; //Create socket socket_desc = socket(AF_INET , SOCK_STREAM , 0); if (socket_desc == -1) { printf("Could not create socket"); } //ip address of www.msn.com ...

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 ...

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 ...

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 #include <stdio.h> //printf #include <string.h> //strncpy #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> //ifreq #include <unistd.h> //close int main() { int fd; struct ifreq ifr; char *iface = "eth0"; unsigned char *mac; fd = socket(AF_INET, SOCK_DGRAM, ...

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 ...

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 ...

Socket programming in C on Linux – tutorial

TCP/IP socket programming in C This is a quick tutorial on 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 "virtual" endpoints of any kind of ...

Pages:123»