Networking
How to find Ethernet MAC address of my PC in various operating systems
Feb 7th
This article explains how to find MAC address of the PC in Linux, Windows, FreeBSP, NetBSP, OpenBSD, Caldera/SCO, IRIX, HP-UX, NeXTStep, AIX, Tru64 UNIX etc.Typically each Ethernet adapter in the world is programmed with an unique MAC address by the manufacturer. In other words, no two Ethernet adapters will have same MAC address.
In Linux (Fedora/Ubuntu/Other flavours)
[neo@techpulp ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:A3:B2:01:5E:4B inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 ...
If you have more than one Ethernet adapters in the system, you can use “ifconfig -a” command.
In Microsoft Windows NT/2000/2003/XP Open Run Command Window by pressing R while holding Windows Start Key. Otherwise Click More >
How to configure apache virtual host in Microsoft Windows for safer development
Jan 6th
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
Dec 2nd
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 check if an IP address falls in a subnet based on subnet and subnet mask
Oct 29th
This can be achieved easily with binary AND (&) operation as shown the function below.
typedef unsigned long IPv4Addr;
/* Function returns 1 if the IP falls in the subnet. Otherwise returns 0. */
int IsIpInTheSubnet(IPv4Addr ip, IPv4Addr subnet, IPv4Addr mask)
{
if((ip & mask) == (subnet & mask)) return 1;
return 0;
}
Example:
IP Address Subnet Mask Return Value 192.168.1.10 192.168.1.0 255.255.255.0 1 192.168.2.10 192.168.1.0 255.255.255.0 0The above function can easily be converted in to a macro to make it simple and more efficient.
This is what preciselyTCP/IP networking stack does for finding a route in the system routing table before More >
How to understand IPv6 address and types
Oct 22nd
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 >
What is IPv6 and why is it needed
Oct 21st
The Internet as we use today uses IPv4 as layer 3 protocol as packet delivery mechanism. IPv4 stands for Internet Protocol version 4 which was designed back in 1980. As the Internet usage grew exponentially during the last decade, the number of free IP addresses for new allocations reduced rapidly. According to current estimates, the number of free IP addresses fallen below 5% and expected to become zero by first quarter of 2011. The IPv4 protocol uses 32 bit (4 byte) addresses limiting the possible IP address space to 2^32 (4 billion). To solve this IP address exhaustion problem. Internet More >
How to reboot a Linux system remotely using ssh or telnet
Oct 12th
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 >
How to make a BSD socket non-blocking – EWOULDBLOCK
Oct 5th
Sometimes it is needed to make a socket non-blocking so that I/O requests on the socket don’t block. For a non-blocking socket, when I/O requests like read() and write() return a negative value, the errno should be checked against -EWOULDBLOCK code to find if the I/O request would have blocked.
The following utility function sets non-blocking flag of a socket.
int socketSetNonBlocking(int sockfd)
{
unsigned int flags;
flags = fcntl(sockfd. F_GETFL, 0);
if(flags < 0) return -1;
if(fcntl(sockfd, F_SETFL, flags|O_NONBLOCK) < 0) return -1;
return 0;
}
Similarly the following function makes a non-blocking socket a blocking socket.
int socketSetBlocking(int sockfd)
{
unsigned int More > 

Recent Comments