Networking

How to find MAC address of a linux network interface using SIOCGIFHWADDR ioctl

The following C programming example retrieves all network interfaces in a Linux system and their IP addresses and MAC addresses. The name of network interface and IP address are retrieved using SIOCGIFCONF ioctl while the hardware address of each individual interface is found using SIOCGIFHWADDR ioctl.

/* iflist.c */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>

int get_iface_list(struct ifconf *ifconf)
{
  int sock, rval;

  sock = socket(AF_INET,SOCK_DGRAM,0);
  if(sock < 0)
  {
    perror("socket");
    return (-1);
  }

  if((rval = ioctl(sock, SIOCGIFCONF , (char*) ifconf  )) < 0 )
  perror("ioctl(SIOGIFCONF)");

  close(sock);

  return rval; More >

How to configure apache virtual host in Microsoft Windows for safer development

Typically for web development, one likes to simulate the web environment by using actual domain name as is instead of using some local IP address. It is very useful in case if you want to host WordPress and would like to copy your version of database as is from development server to the the actual hosting server. The applications like WordPress store domain names in the database while storing your posts as part of permalinks etc.

Another use for having real simulated environment is to ensure your ad slots like Google AdSense, DoubleClick etc appear without any issues. Otherwise the ads More >

How to disable directory listing by Apache web server

There are two ways to disable directory browsing feature of Apache web server. However the first method is most practical way as server’s configuration file is typically not modifiable by the user as part of his hosting plan. Most of the hosting provides allow modification of .htaccess file and enable ModRewrite module in the Apache.

The ModRewrite Way

Add the following line towards the end of .htaccess file present in a directory for which you would like to disable directory listing.

Options All -Indexes

However if you have lots of such directories, it may become difficult for you to do this.

The httpd.conf way

If you More >

How to understand IPv6 address and types

IPv6 uses 16 bytes (128 bits) to represent and IP address as opposed to 4 bytes (32 bits) in IPv4. IPv6 uses colon separated hexa-decimal notation as opposed to dotted-decimal notation in IPv4.With 128-bit long IP address size, IPv6 can provide 2^128 addresses. In a simple decimal notation, it takes up to 39 digits making it harder to memorize. To make it relatively convenient, an IPv6 address is represented by a series of 16 bit hexa-decimal values separated by colons. An example IPv6 address is as follows.

2001:0da3:02f0:d413:4e39:7b9a:e2cd:08a2

The leading zeros can be omitted for simplicity. The above IPv6 address looks like More >

How to reboot a Linux system remotely using ssh or telnet

You can simply login to the remote system using SSH and execute “reboot” command to reboot it. But you must be logged in “root” user to be able to reboot the remote Linux system.

This example shows how to login using IP address.

[root@neo.techpulp.com ~]# ssh root@192.168.123.55

This example shows how to login using remote host name.

[root@neo.techpulp.com ~]# ssh root@www.techpulp.com

Typically after a successful login, you will get access to shell. You can run “reboot” command to reboot the remote system. This action will automatically terminate you current SSH session.

Otherwise, you use the following example to do the job with single command.

[root@neo.techpulp.com ~]# ssh More >