Category Archives: C

Socket Programming in C

Receive full data with recv socket function in C

By | August 6, 2016

recv The recv function is used to receive data on a socket. For example here is the code to fetch the home page of /** Simple TCP client to fetch a web page */ #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… Read More »

C program to get mac address from interface name on Linux

By | September 11, 2012

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… Read More »

C code to perform IP whois

By | September 21, 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 »