#include <ctype.h>
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
Defines | |
#define | IPBITS (sizeof(unsigned long int) * 8) |
the number of bits in an IP address. | |
#define | IPBYTES (sizeof(unsigned long int)) |
the number of bytes in an IP address. | |
Functions | |
unsigned long int | prefix2mask (int prefix) |
creates a netmask from a specified number of bits. More... | |
int | mask2prefix (unsigned long int mask) |
calculates the number of bits masked off by a netmask. More... | |
unsigned long int | default_netmask (unsigned long int addr) |
returns the default (canonical) netmask associated with specified IP address. More... | |
unsigned long int | calc_broadcast (unsigned long int addr, int prefix) |
calculate broadcast address given an IP address and a prefix length. More... | |
unsigned long int | calc_network (unsigned long int addr, int prefix) |
calculates the network address for a specified address and prefix. More... | |
const char* | get_hostname (unsigned long int addr) |
returns the hostname associated with the specified IP address. More... | |
int | main (int argc, const char **argv) |
wrapper program for ipcalc functions. More... |
ipcalc provides utilities and a front-end command line interface for manipulating IP addresses, and calculating various aspects of an ip address/netmask/network address/prefix/etc.
Functionality can be accessed from other languages from the library interface, documented here. To use ipcalc from the shell, read the ipcalc(1) manual page.
When passing parameters to the various functions, take note of whether they take host byte order or network byte order. Most take host byte order, and return host byte order, but there are some exceptions.
|
calculate broadcast address given an IP address and a prefix length.
|
|
calculates the network address for a specified address and prefix.
|
|
returns the default (canonical) netmask associated with specified IP address.
When the Internet was originally set up, various ranges of IP addresses were segmented into three network classes: A, B, and C. This function will return a netmask that is associated with the IP address specified defining where it falls in the predefined classes.
|
|
returns the hostname associated with the specified IP address.
|
|
wrapper program for ipcalc functions.
This is a wrapper program for the functions that the ipcalc library provides. It can be used from shell scripts or directly from the command line. For more information, please see the ipcalc(1) man page. |
|
calculates the number of bits masked off by a netmask.
This function calculates the significant bits in an IP address as specified by a netmask. See also prefix2mask.
|
|
creates a netmask from a specified number of bits.
This function converts a prefix length to a netmask. As CIDR (classless internet domain internet domain routing) has taken off, more an more IP addresses are being specified in the format address/prefix (i.e. 192.168.2.3/24, with a corresponding netmask 255.255.255.0). If you need to see what netmask corresponds to the prefix part of the address, this is the function. See also mask2prefix.
|