source: projects/initscripts/tags/initscripts-8.90.6/src/doc/man/man3/ipcalc_c.3 @ 1108

Revision 1108, 5.6 KB checked in by daisuke, 14 years ago (diff)

import initscripts-8.90.6 from internal cvs repository

Line 
1.TH "ipcalc.c" 3 "30 Apr 2001" "initscripts" \" -*- nroff -*-
2.ad l
3.nh
4.SH NAME
5ipcalc.c \- provides utilities for manipulating IP addresses.
6.SH SYNOPSIS
7.br
8.PP
9\fC#include <ctype.h>\fR
10.br
11\fC#include <popt.h>\fR
12.br
13\fC#include <stdio.h>\fR
14.br
15\fC#include <stdlib.h>\fR
16.br
17\fC#include <string.h>\fR
18.br
19\fC#include <sys/socket.h>\fR
20.br
21\fC#include <netinet/in.h>\fR
22.br
23\fC#include <arpa/inet.h>\fR
24.br
25\fC#include <netdb.h>\fR
26.br
27
28.SS Defines
29
30.in +1c
31.ti -1c
32.RI "#define \fBIPBITS\fR  (sizeof(unsigned long int) * 8)"
33.br
34.RI "\fIthe number of bits in an IP address.\fR"
35.ti -1c
36.RI "#define \fBIPBYTES\fR  (sizeof(unsigned long int))"
37.br
38.RI "\fIthe number of bytes in an IP address.\fR"
39.in -1c
40.SS Functions
41
42.in +1c
43.ti -1c
44.RI "unsigned long int \fBprefix2mask\fR (int prefix)"
45.br
46.RI "\fIcreates a netmask from a specified number of bits.\fR"
47.ti -1c
48.RI "int \fBmask2prefix\fR (unsigned long int mask)"
49.br
50.RI "\fIcalculates the number of bits masked off by a netmask.\fR"
51.ti -1c
52.RI "unsigned long int \fBdefault_netmask\fR (unsigned long int addr)"
53.br
54.RI "\fIreturns the default (canonical) netmask associated with specified IP address.\fR"
55.ti -1c
56.RI "unsigned long int \fBcalc_broadcast\fR (unsigned long int addr, int prefix)"
57.br
58.RI "\fIcalculate broadcast address given an IP address and a prefix length.\fR"
59.ti -1c
60.RI "unsigned long int \fBcalc_network\fR (unsigned long int addr, int prefix)"
61.br
62.RI "\fIcalculates the network address for a specified address and prefix.\fR"
63.ti -1c
64.RI "const char* \fBget_hostname\fR (unsigned long int addr)"
65.br
66.RI "\fIreturns the hostname associated with the specified IP address.\fR"
67.ti -1c
68.RI "int \fBmain\fR (int argc, const char **argv)"
69.br
70.RI "\fIwrapper program for ipcalc functions.\fR"
71.in -1c
72.SH DETAILED DESCRIPTION
73.PP
74provides utilities for manipulating IP addresses.
75.PP
76.PP
77 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.
78.PP
79Functionality can be accessed from other languages from the library interface, documented here. To use ipcalc from the shell, read the ipcalc(1) manual page.
80.PP
81When 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.
82.PP
83.SH FUNCTION DOCUMENTATION
84.PP
85.SS unsigned long int calc_broadcast (unsigned long int addr, int prefix)
86.PP
87calculate broadcast address given an IP address and a prefix length.
88.PP
89.PP
90 
91.PP
92\fBParameters: \fR
93.in +1c
94.TP
95\fB\fIaddr\fR\fR
96an IP address in network byte order.
97.TP
98\fB\fIprefix\fR\fR
99a prefix length.
100.PP
101\fBReturns: \fR
102.in +1c
103the calculated broadcast address for the network, in network byte order.
104.SS unsigned long int calc_network (unsigned long int addr, int prefix)
105.PP
106calculates the network address for a specified address and prefix.
107.PP
108.PP
109 
110.PP
111\fBParameters: \fR
112.in +1c
113.TP
114\fB\fIaddr\fR\fR
115an IP address, in network byte order
116.TP
117\fB\fIprefix\fR\fR
118the network prefix
119.PP
120\fBReturns: \fR
121.in +1c
122the base address of the network that addr is associated with, in network byte order.
123.SS unsigned long int default_netmask (unsigned long int addr)
124.PP
125returns the default (canonical) netmask associated with specified IP address.
126.PP
127.PP
128 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.
129.PP
130\fBParameters: \fR
131.in +1c
132.TP
133\fB\fIaddr\fR\fR
134an IP address in network byte order.
135.PP
136\fBReturns: \fR
137.in +1c
138a netmask in network byte order.
139.SS const char * get_hostname (unsigned long int addr)
140.PP
141returns the hostname associated with the specified IP address.
142.PP
143.PP
144 
145.PP
146\fBParameters: \fR
147.in +1c
148.TP
149\fB\fIaddr\fR\fR
150an IP address to find a hostname for, in network byte order
151.PP
152\fBReturns: \fR
153.in +1c
154a hostname, or NULL if one cannot be determined. Hostname is stored in a static buffer that may disappear at any time, the caller should copy the data if it needs permanent storage.
155.SS main (int argc, const char ** argv)
156.PP
157wrapper program for ipcalc functions.
158.PP
159.PP
160 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.
161.PP
162For more information, please see the ipcalc(1) man page.
163.SS int mask2prefix (unsigned long int mask)
164.PP
165calculates the number of bits masked off by a netmask.
166.PP
167.PP
168 This function calculates the significant bits in an IP address as specified by a netmask. See also \fBprefix2mask\fR.
169.PP
170\fBParameters: \fR
171.in +1c
172.TP
173\fB\fImask\fR\fR
174is the netmask, specified as an unsigned long integer in network byte order.
175.PP
176\fBReturns: \fR
177.in +1c
178the number of significant bits.
179.SS unsigned long int prefix2mask (int bits)
180.PP
181creates a netmask from a specified number of bits.
182.PP
183.PP
184 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 \fBmask2prefix\fR.
185.PP
186\fBParameters: \fR
187.in +1c
188.TP
189\fB\fIprefix\fR\fR
190is the number of bits to create a mask for.
191.PP
192\fBReturns: \fR
193.in +1c
194a network mask, in network byte order.
195.SH AUTHOR
196.PP
197Generated automatically by Doxygen for initscripts from the source code.
Note: See TracBrowser for help on using the repository browser.