├── debian ├── compat ├── README.source ├── docs ├── changelog ├── rules ├── control └── copyright ├── pydhcplib ├── __init__.py ├── type_hw_addr.py ├── type_strlist.py ├── dhcp_file_io.py ├── type_hwmac.py ├── type_ipv4.py ├── interface.py ├── dhcp_basic_packet.py ├── dhcp_network.py ├── dhcp_packet.py └── dhcp_constants.py ├── man ├── man8 │ └── pydhcp.8.gz ├── man3 │ ├── pydhcplib.3.gz │ ├── pydhcplib.ipv4.3.gz │ └── pydhcplib.strlist.3.gz └── fr │ └── man3 │ ├── pydhcplib.3.gz │ ├── pydhcplib.ipv4.3.gz │ ├── pydhcplib.hwmac.3.gz │ ├── pydhcplib.strlist.3.gz │ ├── pydhcplib.DhcpPacket.3.gz │ └── pydhcplib.DhcpBasicPacket.3.gz ├── MANIFEST.in ├── examples ├── gen_packet_example.py ├── strlist_example.py ├── ipv4_example.py ├── hwaddr_example.py ├── client_example.py └── server_example.py ├── TODO ├── networking ├── rawsocket.h ├── rawsocket.c └── rawsocketmod.c ├── setup.py ├── python-pydhcplib.spec ├── README.rst ├── scripts └── pydhcp ├── docs └── dhcp_options_supported.txt └── COPYING /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/README.source: -------------------------------------------------------------------------------- 1 | ../README.rst -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.rst 2 | TODO 3 | -------------------------------------------------------------------------------- /pydhcplib/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.2' 2 | -------------------------------------------------------------------------------- /man/man8/pydhcp.8.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/man8/pydhcp.8.gz -------------------------------------------------------------------------------- /man/man3/pydhcplib.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/man3/pydhcplib.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.3.gz -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include networking/*.h 2 | include man/man8/* 3 | include man/man3/* 4 | include man/fr/man3/* 5 | -------------------------------------------------------------------------------- /man/man3/pydhcplib.ipv4.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/man3/pydhcplib.ipv4.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.ipv4.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.ipv4.3.gz -------------------------------------------------------------------------------- /man/man3/pydhcplib.strlist.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/man3/pydhcplib.strlist.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.hwmac.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.hwmac.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.strlist.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.strlist.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.DhcpPacket.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.DhcpPacket.3.gz -------------------------------------------------------------------------------- /man/fr/man3/pydhcplib.DhcpBasicPacket.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgvncsz0f/pydhcplib/HEAD/man/fr/man3/pydhcplib.DhcpBasicPacket.3.gz -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | python-dhcplib (0.0.1-1) unstable; urgency=low 2 | 3 | * Initial debian package files 4 | 5 | -- Rodrigo Sampaio Vaz Sun, 04 Mar 2012 16:28:42 +0000 6 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /examples/gen_packet_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from pydhcplib.dhcp_packet import DhcpPacket 4 | from pydhcplib.type_strlist import strlist 5 | from pydhcplib.type_ipv4 import ipv4 6 | 7 | 8 | packet = DhcpPacket() 9 | 10 | packet.SetOption("op",[1]) 11 | packet.SetOption("domain_name",strlist("anemon.org").list()) 12 | packet.SetOption("router",ipv4("192.168.0.1").list()+[6,4,2,1]) 13 | packet.SetOption("time_server",[100,100,100,7,6,4,2,1]) 14 | packet.SetOption("yiaddr",[192,168,0,18]) 15 | 16 | print packet.str() 17 | -------------------------------------------------------------------------------- /examples/strlist_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from pydhcplib.type_strlist import strlist 4 | 5 | 6 | word = strlist() 7 | print "a0 : ",word 8 | 9 | word1 = strlist("azerty") 10 | print "a1 : ",word1 11 | 12 | word2 = strlist("qwerty") 13 | print "a2 : ",word2 14 | 15 | word3 = strlist([97, 122, 101, 114, 116, 121]) 16 | print "a3 : ",word3 17 | 18 | if word1 == word2 : print "test 1 : ",word1, "==",word2 19 | else : print "test 1 : " ,word1, "!=",word2 20 | 21 | if word1 == word3 : print "test 2 : ", word1, "==",word3 22 | else : print "test 2 : ", word1, "!=",word3 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/ipv4_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | 4 | from pydhcplib.type_ipv4 import ipv4 5 | 6 | 7 | address = ipv4() 8 | print "a0 : ",address 9 | 10 | address1 = ipv4("192.168.0.1") 11 | print "a1 : ",address1 12 | 13 | address2 = ipv4("10.0.0.1") 14 | print "a2 : ",address2 15 | 16 | address3 = ipv4([192,168,0,1]) 17 | print "a3 : ",address3 18 | 19 | 20 | 21 | if address1 == address2 : print "test 1 : ",address1, "==",address2 22 | else : print "test 1 : " ,address1, "!=",address2 23 | 24 | if address1 == address3 : print "test 2 : ", address1, "==",address3 25 | else : print "test 2 : ", address1, "!=",address3 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: python-dhcplib 2 | Section: python 3 | Priority: extra 4 | Maintainer: Rodrigo Sampaio Vaz 5 | Build-Depends: debhelper (>= 7.0.50~) 6 | Standards-Version: 3.8.4 7 | Homepage: http://github.com/dsouza/pydhcplib 8 | 9 | Package: python-dhcplib 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Description: python dhcp server and client lib 13 | Pydhcplib is a python library to read/write and encode/decode dhcp packet on network. 14 | 15 | N.B. This is a fork of this project http://pydhcplib.tuxfamily.org/pmwiki/. The only change [so far] is the implementation of a missing feature as described in the end of this document 16 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * Options should be available in list or directly in string form 2 | * Server_identifier is not correctly set for selecting state 3 | * Write test scripts 4 | * Better exception handling 5 | * Docs 6 | * Package for various systems 7 | * Add directory type for dhcp_file_io (multiple file IO support) 8 | * Change interface to linux_interface and search for *BSD management 9 | * Add a packet.SetTextOption for textual data handling 10 | * Handle Maximum DHCP Message Size (option 57) 11 | * Handle Overload (option 52) 12 | * using recvmsg + IP_PKTINFO/cmsg to figure the interface of the UDP packet 13 | 14 | OK * Use recvfrom instead of recv to store source IP of the received packet. 15 | OK * Do simple SetParameter in dhcp_packet class to read human readable data (look at anemon server code) 16 | OK * Finish import class 17 | -------------------------------------------------------------------------------- /examples/hwaddr_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from pydhcplib.type_hw_addr import hwmac 4 | 5 | 6 | address = hwmac() 7 | print "a0 : ",address 8 | 9 | address1 = hwmac("ff:11:22:33:44:55") 10 | print "a1 : ",address1 11 | 12 | address2 = hwmac("f6.16.26.36.46.56") 13 | print "a2 : ",address2 14 | 15 | address3 = hwmac("ff.11-22:33-44.55") 16 | print "a3 : ",address3 17 | 18 | 19 | 20 | if address1 == address2 : print "test 1 : ",address1, "==",address2 21 | else : print "test 1 : " ,address1, "!=",address2 22 | 23 | if address1 == address3 : print "test 2 : ", address1, "==",address3 24 | else : print "test 2 : ", address1, "!=",address3 25 | 26 | 27 | 28 | address4 = hwmac([186, 45, 67, 176, 6, 11]) 29 | address5 = hwmac("ba:2d:43:b0:06:0c") 30 | 31 | print "b0 : ", address4,address4.list() 32 | print "b1 : ", address5,address5.list() 33 | -------------------------------------------------------------------------------- /pydhcplib/type_hw_addr.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | # Temporarily needed for backward compatibilities. 20 | from pydhcplib.type_hwmac import * 21 | -------------------------------------------------------------------------------- /networking/rawsocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Russ Dill September 2001 3 | * Rewritten by Vladimir Oleynik (C) 2003 4 | * 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 | */ 7 | /* 8 | * This code was stolen, pretty much, from busybox. :-) 9 | */ 10 | #ifndef PYDHCPLIB_RAWSOCKET_H 11 | #define PYDHCPLIB_RAWSOCKET_H 1 12 | 13 | #include 14 | #include 15 | 16 | #ifndef DHCP_MAX_PKGSZ 17 | #define DHCP_MAX_PKGSZ (1500 - sizeof(struct iphdr) - sizeof(struct udphdr)) 18 | #endif 19 | 20 | struct ip_udp_dhcp_packet 21 | { 22 | struct iphdr ip; 23 | struct udphdr udp; 24 | uint8_t data[DHCP_MAX_PKGSZ]; 25 | }; 26 | 27 | /* Construct a ip/udp header for a packet, send packet */ 28 | int rawsocket_udp_send_packet(const uint8_t *payload, int datalen, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, const uint8_t *dest_arp, int ifindex); 29 | 30 | #define IP_UDP_DHCP_SIZE(payloadsz) (sizeof(struct ip_udp_dhcp_packet)-DHCP_MAX_PKGSZ+payloadsz) 31 | #define UDP_DHCP_SIZE(payloadsz) (sizeof(struct udphdr)+payloadsz) 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This work was packaged for Debian by: 2 | 3 | root on Sun, 04 Mar 2012 16:28:42 +0000 4 | 5 | It was downloaded from: 6 | 7 | 8 | 9 | Upstream Author(s): 10 | 11 | 12 | 13 | 14 | Copyright: 15 | 16 | 17 | 18 | 19 | License: 20 | 21 | 22 | 23 | The Debian packaging is: 24 | 25 | Copyright (C) 2012 root 26 | 27 | # Please chose a license for your packaging work. If the program you package 28 | # uses a mainstream license, using the same license is the safest choice. 29 | # Please avoid to pick license terms that are more restrictive than the 30 | # packaged work, as it may make Debian's contributions unacceptable upstream. 31 | # If you just want it to be GPL version 3, leave the following lines in. 32 | 33 | and is licensed under the GPL version 3, 34 | see "/usr/share/common-licenses/GPL-3". 35 | 36 | # Please also look if there are files or directories which have a 37 | # different copyright/license attached and list them here. 38 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2.5 2 | 3 | from distutils.core import setup 4 | from distutils.core import Extension 5 | 6 | fr8_manpages = ['man/fr/man8/pydhcp.8.gz'] 7 | fr3_manpages = ['man/fr/man3/pydhcplib.3.gz', 8 | 'man/fr/man3/pydhcplib.DhcpBasicPacket.3.gz', 9 | 'man/fr/man3/pydhcplib.DhcpPacket.3.gz', 10 | 'man/fr/man3/pydhcplib.hwmac.3.gz', 11 | 'man/fr/man3/pydhcplib.ipv4.3.gz', 12 | 'man/fr/man3/pydhcplib.strlist.3.gz'] 13 | en3_manpages = ['man/man3/pydhcplib.strlist.3.gz', 14 | 'man/man3/pydhcplib.3.gz', 15 | 'man/man3/pydhcplib.ipv4.3.gz'] 16 | en8_manpages = ['man/man8/pydhcp.8.gz'] 17 | 18 | rawsocketmod = Extension( "pydhcplib._rawsocket", 19 | sources = ["networking/rawsocket.c", "networking/rawsocketmod.c"] 20 | ) 21 | 22 | setup(name='pydhcplib', 23 | version = "0.6.2", 24 | license = "GPL v3", 25 | description = "Dhcp client/server library", 26 | author = "Mathieu Ignacio, Diego Souza", 27 | author_email = "mignacio@april.org", 28 | url = "http://github.com/dgvncsz0f/pydhcplib", 29 | packages = ["pydhcplib"], 30 | scripts = ["scripts/pydhcp"], 31 | ext_modules = [rawsocketmod], 32 | data_files = [("share/man/man8",en8_manpages), 33 | # ("share/man/fr/man8",fr8_manpages), 34 | ("share/man/fr/man3",fr3_manpages), 35 | ("share/man/man3",en3_manpages) 36 | ]) 37 | -------------------------------------------------------------------------------- /python-pydhcplib.spec: -------------------------------------------------------------------------------- 1 | %define __python python2.6 2 | %define __pyver 2.6 3 | %define debug_package %{nil} 4 | %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print (get_python_lib())")} 5 | 6 | Name: python-pydhcplib 7 | Version: 0.6.2 8 | Release: 1%{?dist} 9 | Summary: Python dhcp library 10 | Group: Network 11 | 12 | License: ASL 2.0 13 | URL: http://code.locaweb.com.br/iaas/motoko 14 | Source0: pydhcplib-%{version}.tar.gz 15 | Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root 16 | 17 | BuildRequires: python 18 | 19 | Requires: python 20 | 21 | %description 22 | Pydhcplib is a python library to read/write and encode/decode dhcp packet on network. 23 | 24 | %prep 25 | %setup -q -n pydhcplib-%{version} 26 | 27 | %build 28 | echo -n 29 | 30 | %install 31 | rm -rf $RPM_BUILD_ROOT 32 | %{__python} setup.py install --root $RPM_BUILD_ROOT 33 | 34 | 35 | %files 36 | %defattr(-,root,root,-) 37 | %{_bindir}/pydhcp 38 | /usr/lib/python%{__pyver}/site-packages/pydhcplib-%{version}-py%{__pyver}.egg-info 39 | /usr/lib/python%{__pyver}/site-packages/pydhcplib/* 40 | %{_mandir}/fr/man3/pydhcplib.3.gz 41 | %{_mandir}/fr/man3/pydhcplib.DhcpBasicPacket.3.gz 42 | %{_mandir}/fr/man3/pydhcplib.DhcpPacket.3.gz 43 | %{_mandir}/fr/man3/pydhcplib.hwmac.3.gz 44 | %{_mandir}/fr/man3/pydhcplib.ipv4.3.gz 45 | %{_mandir}/fr/man3/pydhcplib.strlist.3.gz 46 | %{_mandir}/man3/pydhcplib.3.gz 47 | %{_mandir}/man3/pydhcplib.ipv4.3.gz 48 | %{_mandir}/man3/pydhcplib.strlist.3.gz 49 | %{_mandir}/man8/pydhcp.8.gz 50 | 51 | 52 | %changelog 53 | * Sat Mar 15 2014 Andre Ferraz - 0.6.2-1 54 | - Initial release 55 | -------------------------------------------------------------------------------- /examples/client_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # pydhcplib 4 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 5 | # 6 | # This file is part of pydhcplib. 7 | # Pydhcplib is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | from pydhcplib.dhcp_packet import * 21 | from pydhcplib.dhcp_network import * 22 | 23 | netopt = {'client_listen_port':68, 24 | 'server_listen_port':67, 25 | 'listen_address':"0.0.0.0"} 26 | 27 | class Client(DhcpClient): 28 | def __init__(self, options): 29 | DhcpClient.__init__(self,options["listen_address"], 30 | options["client_listen_port"], 31 | options["server_listen_port"]) 32 | 33 | def HandleDhcpOffer(self, packet): 34 | print packet.str() 35 | def HandleDhcpAck(self, packet): 36 | print packet.str() 37 | def HandleDhcpNack(self, packet): 38 | print packet.str() 39 | 40 | client = Client(netopt) 41 | # Use BindToAddress if you want to emit/listen to an internet address (like 192.168.1.1) 42 | # or BindToDevice if you want to emit/listen to a network device (like eth0) 43 | client.BindToAddress() 44 | 45 | while True : 46 | client.GetNextDhcpPacket() 47 | print client.str() 48 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | :: 2 | 3 | _ _ _ _ _ 4 | _ __ _ _ __| | |__ ___ _ __ | (_) |__ 5 | | '_ \| | | |/ _` | '_ \ / __| '_ \| | | '_ \ 6 | | |_) | |_| | (_| | | | | (__| |_) | | | |_) | 7 | | .__/ \__, |\__,_|_| |_|\___| .__/|_|_|_.__/ 8 | |_| |___/ |_| 9 | 10 | 11 | =========== 12 | Pydhcplib 13 | =========== 14 | 15 | Pydhcplib is a python library to read/write and encode/decode dhcp 16 | packet on network. 17 | 18 | N.B. This is a fork of this project http://pydhcplib.tuxfamily.org/pmwiki/. The only change [so far] is the implementation of a missing feature as described in the end of this document [1_]. 19 | 20 | Installation : 21 | ============== 22 | 23 | On Debian, simply run `./setup.py install`. Python modules will be 24 | installed in /usr/lib/python2.X/site-packages/pydhcplib/. 25 | 26 | If you want to install it on a different location, use the `--prefix` 27 | on the `setup.py` command line like this:: 28 | 29 | $ ./setup.py install --prefix=/rootpath/to/your/location/ 30 | 31 | How to use pydhcplib : 32 | ====================== 33 | 34 | Look in the examples directory to learn how to use the modules.:: 35 | 36 | $ man pydhcp 37 | $ man pydhcplib 38 | 39 | .. 1: 40 | 41 | Differences to the original pydhcplib 42 | ===================================== 43 | 44 | The short story is I've "stolen" the udp raw socket code from [the 45 | amazing] *busybox* project changing it to work with the udp payload 46 | [the actual dhcp packet] this library creates. 47 | 48 | This was required to make it work in the case the fields `giaddr` and 49 | `ciaddr` are zero and the broadcast bit flag is not set. This requires 50 | unicasting the udp packet to the `yiaddr` address, which does not yet 51 | exist. Using the kernel to send the packet fails as there is no ARP 52 | information available. This requires using raw sockets to inject the 53 | missing `hwaddr` information. 54 | 55 | -------------------------------------------------------------------------------- /examples/server_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # pydhcplib 4 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 5 | # 6 | # This file is part of pydhcplib. 7 | # Pydhcplib is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | from pydhcplib.dhcp_packet import * 21 | from pydhcplib.dhcp_network import * 22 | 23 | 24 | netopt = {'client_listen_port':"68", 25 | 'iface': 'eth0', 26 | 'server_listen_port':"67", 27 | 'listen_address':"0.0.0.0" 28 | } 29 | 30 | class Server(DhcpServer): 31 | def __init__(self, options): 32 | DhcpServer.__init__(self, 33 | options["iface"], 34 | options["listen_address"], 35 | options["client_listen_port"], 36 | options["server_listen_port"] 37 | ) 38 | 39 | def HandleDhcpDiscover(self, packet): 40 | print packet.str() 41 | def HandleDhcpRequest(self, packet): 42 | print packet.str() 43 | def HandleDhcpDecline(self, packet): 44 | print packet.str() 45 | def HandleDhcpRelease(self, packet): 46 | print packet.str() 47 | def HandleDhcpInform(self, packet): 48 | print packet.str() 49 | 50 | 51 | server = Server(netopt) 52 | 53 | while True : 54 | server.GetNextDhcpPacket() 55 | -------------------------------------------------------------------------------- /pydhcplib/type_strlist.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | class strlist : 19 | def __init__(self,data="") : 20 | str_type = type(data) 21 | self._str = "" 22 | self._list = [] 23 | 24 | if str_type == str : 25 | self._str = data 26 | for each in range(len(self._str)) : 27 | self._list.append(ord(self._str[each])) 28 | elif str_type == list : 29 | self._list = data 30 | self._str = "".join(map(chr,self._list)) 31 | else : raise TypeError , 'strlist init : Valid types are str and list of int' 32 | 33 | # return string 34 | def str(self) : 35 | return self._str 36 | 37 | # return list (useful for DhcpPacket class) 38 | def list(self) : 39 | return self._list 40 | 41 | # return int 42 | # FIXME 43 | def int(self) : 44 | return 0 45 | 46 | 47 | 48 | """ Useful function for native python operations """ 49 | 50 | def __hash__(self) : 51 | return self._str.__hash__() 52 | 53 | def __repr__(self) : 54 | return self._str 55 | 56 | def __nonzero__(self) : 57 | if self._str != "" : return 1 58 | return 0 59 | 60 | def __cmp__(self,other) : 61 | if self._str == other : return 0 62 | return 1 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /pydhcplib/dhcp_file_io.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import sys 19 | import dhcp_packet 20 | import IN 21 | 22 | class DhcpFileIO() : 23 | def __init__(self) : 24 | self.binary = False 25 | self.filedesc = False 26 | 27 | def EnableBinaryTransport(self) : 28 | self.binary = True 29 | 30 | def DisableBinaryTransport(self) : 31 | self.binary = False 32 | 33 | def SendDhcpPacketTo(self,packet,forgetthisparameter1=None,forgetthisparameter2=None) : 34 | if self.filedesc and self.binary : 35 | self.filedesc.write(packet.EncodePacket()) 36 | elif self.filedesc and not self.binary : 37 | self.filedesc.write(packet.str()) 38 | 39 | def GetNextDhcpPacket(self) : 40 | if self.filedesc and self.binary : 41 | packet = dhcp_packet.DhcpPacket() 42 | data = self.filedesc.read(4096) 43 | packet.DecodePacket(data) 44 | return packet 45 | 46 | elif self.filedesc and not self.binary : 47 | packet = dhcp_packet.DhcpPacket() 48 | for line in self.filedesc : packet.AddLine(line) 49 | return packet 50 | 51 | 52 | class DhcpStdIn(DhcpFileIO) : 53 | def __init__(self) : 54 | self.EnableBinaryTransport() 55 | self.filedesc = sys.stdin 56 | 57 | class DhcpStdOut(DhcpFileIO) : 58 | def __init__(self) : 59 | self.EnableBinaryTransport() 60 | self.filedesc = sys.stdout 61 | 62 | class DhcpFileOut(DhcpFileIO) : 63 | def __init__(self,filename) : 64 | self.filedesc = file(filename, 'w') 65 | self.EnableBinaryTransport() 66 | 67 | class DhcpFileIn(DhcpFileIO) : 68 | def __init__(self,filename) : 69 | self.filedesc = file(filename, 'r') 70 | self.EnableBinaryTransport() 71 | -------------------------------------------------------------------------------- /pydhcplib/type_hwmac.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | from binascii import unhexlify,hexlify 20 | 21 | # Check and convert hardware/nic/mac address type 22 | class hwmac: 23 | def __init__(self,value="00:00:00:00:00:00") : 24 | self._hw_numlist = [] 25 | self._hw_string = "" 26 | hw_type = type(value) 27 | if hw_type == str : 28 | value = value.strip() 29 | self._hw_string = value 30 | self._StringToNumlist(value) 31 | self._CheckNumList() 32 | elif hw_type == list : 33 | self._hw_numlist = value 34 | self._CheckNumList() 35 | self._NumlistToString() 36 | else : raise TypeError , 'hwmac init : Valid types are str and list' 37 | 38 | 39 | 40 | # Check if _hw_numlist is valid and raise error if not. 41 | def _CheckNumList(self) : 42 | if len(self._hw_numlist) != 6 : raise ValueError , "hwmac : wrong list length." 43 | for part in self._hw_numlist : 44 | if type (part) != int : raise TypeError , "hwmac : each element of list must be int" 45 | if part < 0 or part > 255 : raise ValueError , "hwmac : need numbers between 0 and 255." 46 | return True 47 | 48 | 49 | def _StringToNumlist(self,value): 50 | self._hw_string = self._hw_string.replace("-",":").replace(".",":") 51 | self._hw_string = self._hw_string.lower() 52 | 53 | for twochar in self._hw_string.split(":"): 54 | self._hw_numlist.append(ord(unhexlify(twochar))) 55 | 56 | # Convert NumList type ip to String type ip 57 | def _NumlistToString(self) : 58 | self._hw_string = ":".join(map(hexlify,map(chr,self._hw_numlist))) 59 | 60 | # Convert String type ip to NumList type ip 61 | # return ip string 62 | def str(self) : 63 | return self._hw_string 64 | 65 | # return ip list (useful for DhcpPacket class) 66 | def list(self) : 67 | return self._hw_numlist 68 | 69 | def __hash__(self) : 70 | return self._hw_string.__hash__() 71 | 72 | def __repr__(self) : 73 | return self._hw_string 74 | 75 | def __cmp__(self,other) : 76 | if self._hw_string == other : return 0 77 | return 1 78 | 79 | def __nonzero__(self) : 80 | if self._hw_string != "00:00:00:00:00:00" : return 1 81 | return 0 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /networking/rawsocket.c: -------------------------------------------------------------------------------- 1 | /* vi: set sw=4 ts=4: */ 2 | /* 3 | * Packet ops 4 | * 5 | * Rewrite by Russ Dill July 2001 6 | * 7 | * Licensed under GPLv2, see file LICENSE in this source tree. 8 | */ 9 | /* 10 | * This code was stolen, pretty much, from busybox. :-) 11 | */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "rawsocket.h" 20 | 21 | static 22 | uint16_t rawsocket_checksum(void *addr, int count) 23 | { 24 | /* Compute Internet Checksum for "count" bytes 25 | * beginning at location "addr". 26 | */ 27 | int32_t sum = 0; 28 | uint16_t *source = (uint16_t *) addr; 29 | 30 | while (count > 1) { 31 | /* This is the inner loop */ 32 | sum += *source++; 33 | count -= 2; 34 | } 35 | 36 | /* Add left-over byte, if any */ 37 | if (count > 0) { 38 | /* Make sure that the left-over byte is added correctly both 39 | * with little and big endian hosts */ 40 | uint16_t tmp = 0; 41 | *(uint8_t*)&tmp = *(uint8_t*)source; 42 | sum += tmp; 43 | } 44 | /* Fold 32-bit sum to 16 bits */ 45 | while (sum >> 16) 46 | sum = (sum & 0xffff) + (sum >> 16); 47 | 48 | return ~sum; 49 | } 50 | 51 | /* Construct a ip/udp header for a packet, send packet */ 52 | int rawsocket_udp_send_packet(const uint8_t *payload, int datalen, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, const uint8_t *dest_arp, int ifindex) 53 | { 54 | struct sockaddr_ll dest_sll; 55 | struct ip_udp_dhcp_packet packet; 56 | int result = -1; 57 | int fd; 58 | 59 | fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); 60 | if (fd < 0 || datalen>DHCP_MAX_PKGSZ) 61 | return(result); // failure 62 | 63 | memset(&dest_sll, 0, sizeof(dest_sll)); 64 | memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data)); 65 | memcpy(packet.data, payload, datalen); 66 | 67 | dest_sll.sll_family = AF_PACKET; 68 | dest_sll.sll_protocol = htons(ETH_P_IP); 69 | dest_sll.sll_ifindex = ifindex; 70 | dest_sll.sll_halen = 6; 71 | memcpy(dest_sll.sll_addr, dest_arp, 6); 72 | 73 | if (bind(fd, (struct sockaddr *)&dest_sll, sizeof(dest_sll)) < 0) 74 | goto ret_close; 75 | 76 | packet.ip.protocol = IPPROTO_UDP; 77 | packet.ip.saddr = source_nip; 78 | packet.ip.daddr = dest_nip; 79 | packet.udp.source = htons(source_port); 80 | packet.udp.dest = htons(dest_port); 81 | /* size, excluding IP header: */ 82 | packet.udp.len = htons(UDP_DHCP_SIZE(datalen)); 83 | /* for UDP checksumming, ip.len is set to UDP packet len */ 84 | packet.ip.tot_len = packet.udp.len; 85 | packet.udp.check = rawsocket_checksum(&packet, IP_UDP_DHCP_SIZE(datalen)); 86 | /* but for sending, it is set to IP packet len */ 87 | packet.ip.tot_len = htons(IP_UDP_DHCP_SIZE(datalen)); 88 | packet.ip.ihl = sizeof(packet.ip) >> 2; 89 | packet.ip.version = IPVERSION; 90 | packet.ip.ttl = IPDEFTTL; 91 | packet.ip.check = rawsocket_checksum(&packet.ip, sizeof(packet.ip)); 92 | 93 | result = sendto(fd, &packet, IP_UDP_DHCP_SIZE(datalen), /*flags:*/ 0, (struct sockaddr *) &dest_sll, sizeof(dest_sll)); 94 | 95 | ret_close: 96 | close(fd); 97 | return(result); 98 | } 99 | -------------------------------------------------------------------------------- /networking/rawsocketmod.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011, Diego Souza */ 2 | /* All rights reserved. */ 3 | 4 | /* Redistribution and use in source and binary forms, with or without */ 5 | /* modification, are permitted provided that the following conditions are met: */ 6 | 7 | /* * Redistributions of source code must retain the above copyright notice, */ 8 | /* this list of conditions and the following disclaimer. */ 9 | /* * Redistributions in binary form must reproduce the above copyright notice, */ 10 | /* this list of conditions and the following disclaimer in the documentation */ 11 | /* and/or other materials provided with the distribution. */ 12 | /* * Neither the name of the nor the names of its contributors */ 13 | /* may be used to endorse or promote products derived from this software */ 14 | /* without specific prior written permission. */ 15 | 16 | /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 17 | /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 18 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 19 | /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE */ 20 | /* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */ 21 | /* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR */ 22 | /* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER */ 23 | /* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */ 24 | /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ 25 | /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 26 | 27 | #include 28 | #include "rawsocket.h" 29 | 30 | static 31 | PyObject *python_rawsocket_udp_send_packet(PyObject *self, PyObject *args); 32 | 33 | static 34 | PyMethodDef rawsocket_methods[] = { 35 | {"udp_send_packet", python_rawsocket_udp_send_packet, METH_VARARGS, "Sends an udp packet using raw socket"}, 36 | {NULL, NULL, 0, NULL} 37 | }; 38 | 39 | static 40 | PyObject *python_rawsocket_udp_send_packet(PyObject *self, PyObject *args) 41 | { 42 | char *payload, *hwaddr; 43 | int payloadlen, hwaddrlen; 44 | unsigned int source_nip, source_port; 45 | unsigned int dest_nip, dest_port; 46 | int ifindex; 47 | 48 | if (! PyArg_ParseTuple(args, "z#IIIIz#i", &payload, &payloadlen, &source_nip, &source_port, &dest_nip, &dest_port, &hwaddr, &hwaddrlen, &ifindex)) 49 | return(NULL); 50 | 51 | if (hwaddrlen != 6) 52 | Py_RETURN_FALSE; 53 | 54 | int result = rawsocket_udp_send_packet( (const uint8_t*) payload, 55 | payloadlen, 56 | (uint32_t) source_nip, 57 | (uint32_t) source_port, 58 | (uint32_t) dest_nip, 59 | (uint32_t) dest_port, 60 | (const uint8_t*) hwaddr, 61 | ifindex 62 | ); 63 | if (result == 0) 64 | Py_RETURN_TRUE; 65 | else 66 | Py_RETURN_FALSE; 67 | } 68 | 69 | PyMODINIT_FUNC 70 | init_rawsocket(void) 71 | { 72 | (void) Py_InitModule("_rawsocket", rawsocket_methods); 73 | } 74 | -------------------------------------------------------------------------------- /pydhcplib/type_ipv4.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | # Check and convert ipv4 address type 20 | class ipv4: 21 | def __init__(self,value="0.0.0.0") : 22 | ip_type = type(value) 23 | if ip_type == str : 24 | if not self.CheckString(value) : raise ValueError, "ipv4 string argument is not an valid ip " 25 | self._ip_string = value 26 | self._StringToNumlist() 27 | self._StringToLong() 28 | self._NumlistToString() 29 | elif ip_type == list : 30 | if not self.CheckNumList(value) : raise ValueError, "ipv4 list argument is not an valid ip " 31 | self._ip_numlist = value 32 | self._NumlistToString() 33 | self._StringToLong() 34 | elif ip_type == int or ip_type == long: 35 | self._ip_long = value 36 | self._LongToNumlist() 37 | self._NumlistToString() 38 | elif ip_type == bool : 39 | self._ip_long = 0 40 | self._LongToNumlist() 41 | self._NumlistToString() 42 | 43 | else : raise TypeError , 'ipv4 init : Valid types are str, list, int or long' 44 | 45 | # Convert Long type ip to numlist ip 46 | def _LongToNumlist(self) : 47 | self._ip_numlist = [self._ip_long >> 24 & 0xFF] 48 | self._ip_numlist.append(self._ip_long >> 16 & 0xFF) 49 | self._ip_numlist.append(self._ip_long >> 8 & 0xFF) 50 | self._ip_numlist.append(self._ip_long & 0xFF) 51 | if not self.CheckNumList(self._ip_numlist) : raise ValueError, "ipv4 list argument is not an valid ip " 52 | # Convert String type ip to Long type ip 53 | def _StringToLong(self) : 54 | ip_numlist = map(int,self._ip_string.split('.')) 55 | self._ip_long = ip_numlist[3] + ip_numlist[2]*256 + ip_numlist[1]*256*256 + ip_numlist[0]*256*256*256 56 | if not self.CheckNumList(self._ip_numlist) : raise ValueError, "ipv4 list argument is not an valid ip " 57 | # Convert NumList type ip to String type ip 58 | def _NumlistToString(self) : 59 | self._ip_string = ".".join(map(str,self._ip_numlist)) 60 | if not self.CheckNumList(self._ip_numlist) : raise ValueError, "ipv4 list argument is not an valid ip " 61 | # Convert String type ip to NumList type ip 62 | def _StringToNumlist(self) : 63 | self._ip_numlist = map(int,self._ip_string.split('.')) 64 | if not self.CheckNumList(self._ip_numlist) : raise ValueError, "ipv4 list argument is not an valid ip " 65 | 66 | """ Public methods """ 67 | # Check if _ip_numlist is valid and raise error if not. 68 | # self._ip_numlist 69 | def CheckNumList(self,value) : 70 | if len(value) != 4 : return False 71 | for part in value : 72 | if part < 0 or part > 255 : return False 73 | return True 74 | 75 | # Check if _ip_numlist is valid and raise error if not. 76 | def CheckString(self,value) : 77 | tmp = value.strip().split('.') 78 | if len(tmp) != 4 : return False 79 | for each in tmp : 80 | if not each.isdigit() : return False 81 | return True 82 | 83 | # return ip string 84 | def str(self) : 85 | return self._ip_string 86 | 87 | # return ip list (useful for DhcpPacket class) 88 | def list(self) : 89 | return self._ip_numlist 90 | 91 | # return Long ip type (useful for SQL ip address backend) 92 | def int(self) : 93 | return self._ip_long 94 | 95 | 96 | """ Useful function for native python operations """ 97 | 98 | def __hash__(self) : 99 | return self._ip_long.__hash__() 100 | 101 | def __repr__(self) : 102 | return self._ip_string 103 | 104 | def __cmp__(self,other) : 105 | return cmp(self._ip_long, other._ip_long); 106 | 107 | def __nonzero__(self) : 108 | if self._ip_long != 0 : return 1 109 | return 0 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /pydhcplib/interface.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (C) 2005, TUBITAK/UEKAE 5 | # 6 | # This program is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU General Public License as published by the 8 | # Free Software Foundation; either version 2 of the License, or (at your 9 | # option) any later version. Please read the COPYING file. 10 | # 11 | 12 | import os 13 | import array 14 | import fcntl 15 | import struct 16 | import socket 17 | 18 | class interface: 19 | """ ioctl stuff """ 20 | 21 | IFNAMSIZ = 16 # interface name size 22 | 23 | # From 24 | 25 | SIOCGIFADDR = 0x8915 # get PA address 26 | SIOCGIFBRDADDR = 0x8919 # get broadcast PA address 27 | SIOCGIFCONF = 0x8912 # get iface list 28 | SIOCGIFFLAGS = 0x8913 # get flags 29 | SIOCGIFMTU = 0x8921 # get MTU size 30 | SIOCGIFNETMASK = 0x891b # get network PA mask 31 | SIOCSIFADDR = 0x8916 # set PA address 32 | SIOCSIFBRDADDR = 0x891a # set broadcast PA address 33 | SIOCSIFFLAGS = 0x8914 # set flags 34 | SIOCSIFMTU = 0x8922 # set MTU size 35 | SIOCSIFNETMASK = 0x891c # set network PA mask 36 | SIOCGIFINDEX = 0x8933 # if_index mapping 37 | 38 | # From 39 | 40 | IFF_UP = 0x1 # Interface is up. 41 | IFF_BROADCAST = 0x2 # Broadcast address valid. 42 | IFF_DEBUG = 0x4 # Turn on debugging. 43 | IFF_LOOPBACK = 0x8 # Is a loopback net. 44 | IFF_POINTOPOINT = 0x10 # Interface is point-to-point link. 45 | IFF_NOTRAILERS = 0x20 # Avoid use of trailers. 46 | IFF_RUNNING = 0x40 # Resources allocated. 47 | IFF_NOARP = 0x80 # No address resolution protocol. 48 | IFF_PROMISC = 0x100 # Receive all packets. 49 | IFF_ALLMULTI = 0x200 # Receive all multicast packets. 50 | IFF_MASTER = 0x400 # Master of a load balancer. 51 | IFF_SLAVE = 0x800 # Slave of a load balancer. 52 | IFF_MULTICAST = 0x1000 # Supports multicast. 53 | IFF_PORTSEL = 0x2000 # Can set media type. 54 | IFF_AUTOMEDIA = 0x4000 # Auto media select active. 55 | 56 | 57 | def __init__(self): 58 | # create a socket to communicate with system 59 | self.sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 60 | 61 | def _ioctl(self, func, args): 62 | return fcntl.ioctl(self.sockfd.fileno(), func, args) 63 | 64 | def _call(self, ifname, func, ip = None): 65 | 66 | if ip is None: 67 | data = (ifname + '\0'*32)[:32] 68 | else: 69 | ifreq = (ifname + '\0' * self.IFNAMSIZ)[:self.IFNAMSIZ] 70 | data = struct.pack("16si4s10x", ifreq, socket.AF_INET, socket.inet_aton(ip)) 71 | 72 | try: 73 | result = self._ioctl(func, data) 74 | except IOError: 75 | return None 76 | 77 | return result 78 | 79 | def getInterfaceList(self): 80 | """ Get all interface names in a list """ 81 | # get interface list 82 | buffer = array.array('c', '\0' * 1024) 83 | ifconf = struct.pack("iP", buffer.buffer_info()[1], buffer.buffer_info()[0]) 84 | result = self._ioctl(self.SIOCGIFCONF, ifconf) 85 | 86 | # loop over interface names 87 | iflist = [] 88 | size, ptr = struct.unpack("iP", result) 89 | for idx in range(0, size, 32): 90 | ifconf = buffer.tostring()[idx:idx+32] 91 | name, dummy = struct.unpack("16s16s", ifconf) 92 | name, dummy = name.split('\0', 1) 93 | iflist.append(name) 94 | 95 | return iflist 96 | 97 | def getAddr(self, ifname): 98 | """ Get the inet addr for an interface """ 99 | result = self._call(ifname, self.SIOCGIFADDR) 100 | if (result is not None): 101 | return socket.inet_ntoa(result[20:24]) 102 | 103 | def getNetmask(self, ifname): 104 | """ Get the netmask for an interface """ 105 | result = self._call(ifname, self.SIOCGIFNETMASK) 106 | if (result is not None): 107 | return socket.inet_ntoa(result[20:24]) 108 | 109 | def getIndex(self, ifname): 110 | """ Get the ifindex for an interface """ 111 | data = self._call(ifname, self.SIOCGIFINDEX) 112 | index = struct.unpack("16si12x", data)[1] 113 | return index 114 | 115 | def getBroadcast(self, ifname): 116 | """ Get the broadcast addr for an interface """ 117 | result = self._call(ifname, self.SIOCGIFBRDADDR) 118 | return socket.inet_ntoa(result[20:24]) 119 | 120 | def getStatus(self, ifname): 121 | """ Check whether interface is UP """ 122 | result = self._call(ifname, self.SIOCGIFFLAGS) 123 | flags, = struct.unpack('H', result[16:18]) 124 | return (flags & self.IFF_UP) != 0 125 | 126 | def getMTU(self, ifname): 127 | """ Get the MTU size of an interface """ 128 | data = self._call(ifname, self.SIOCGIFMTU) 129 | mtu = struct.unpack("16si12x", data)[1] 130 | return mtu 131 | 132 | def setAddr(self, ifname, ip): 133 | """ Set the inet addr for an interface """ 134 | result = self._call(ifname, self.SIOCSIFADDR, ip) 135 | 136 | if result and socket.inet_ntoa(result[20:24]) is ip: 137 | return True 138 | else: 139 | return None 140 | 141 | def setNetmask(self, ifname, ip): 142 | """ Set the netmask for an interface """ 143 | result = self._call(ifname, self.SIOCSIFNETMASK, ip) 144 | 145 | if result and socket.inet_ntoa(result[20:24]) is ip: 146 | return True 147 | else: 148 | return None 149 | 150 | def setBroadcast(self, ifname, ip): 151 | """ Set the broadcast addr for an interface """ 152 | result = self._call(ifname, self.SIOCSIFBRDADDR, ip) 153 | 154 | if socket.inet_ntoa(result[20:24]) is ip: 155 | return True 156 | else: 157 | return None 158 | 159 | def setStatusDown(self, ifname): 160 | """ Set interface status (UP/DOWN) """ 161 | ifreq = (ifname + '\0' * self.IFNAMSIZ)[:self.IFNAMSIZ] 162 | 163 | result = self._call(ifname, self.SIOCGIFFLAGS) 164 | flags, = struct.unpack('H', result[16:18]) 165 | flags &= ~self.IFF_UP 166 | 167 | data = struct.pack("16sh", ifreq, flags) 168 | result = self._ioctl(self.SIOCSIFFLAGS, data) 169 | 170 | return result 171 | 172 | def setStatusUp(self, ifname): 173 | """ Set interface status (UP/DOWN) """ 174 | ifreq = (ifname + '\0' * self.IFNAMSIZ)[:self.IFNAMSIZ] 175 | 176 | flags = self.IFF_UP 177 | flags |= self.IFF_RUNNING 178 | flags |= self.IFF_BROADCAST 179 | flags |= self.IFF_MULTICAST 180 | flags &= ~self.IFF_NOARP 181 | flags &= ~self.IFF_PROMISC 182 | 183 | data = struct.pack("16sh", ifreq, flags) 184 | result = self._ioctl(self.SIOCSIFFLAGS, data) 185 | 186 | return result 187 | 188 | def setMTU(self, ifname, mtu): 189 | """ Set the MTU size of an interface """ 190 | ifreq = (ifname + '\0' * self.IFNAMSIZ)[:self.IFNAMSIZ] 191 | 192 | data = struct.pack("16si", ifreq, mtu) 193 | result = self._ioctl(self.SIOCSIFMTU, data) 194 | 195 | if struct.unpack("16si", result)[1] is mtu: 196 | return True 197 | else: 198 | return None 199 | 200 | -------------------------------------------------------------------------------- /pydhcplib/dhcp_basic_packet.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import operator 19 | from struct import unpack 20 | from struct import pack 21 | from dhcp_constants import * 22 | import sys 23 | 24 | 25 | # DhcpPacket : base class to encode/decode dhcp packets. 26 | 27 | class DhcpBasicPacket: 28 | def __init__(self): 29 | self.packet_data = [0]*240 30 | self.options_data = {} 31 | self.packet_data[236:240] = MagicCookie 32 | self.source_address = False 33 | 34 | def IsDhcpPacket(self): 35 | if self.packet_data[236:240] != MagicCookie : return False 36 | return True 37 | 38 | # Check if variable is a list with int between 0 and 255 39 | def CheckType(self,variable): 40 | if type(variable) == list : 41 | for each in variable : 42 | if (type(each) != int) or (each < 0) or (each > 255) : 43 | return False 44 | return True 45 | else : return False 46 | 47 | 48 | def DeleteOption(self,name): 49 | # if name is a standard dhcp field 50 | # Set field to 0 51 | if DhcpFields.has_key(name) : 52 | begin = DhcpFields[name][0] 53 | end = DhcpFields[name][0]+DhcpFields[name][1] 54 | self.packet_data[begin:end] = [0]*DhcpFields[name][1] 55 | return True 56 | 57 | # if name is a dhcp option 58 | # delete option from self.option_data 59 | elif self.options_data.has_key(name) : 60 | # forget how to remove a key... try delete 61 | self.options_data.__delitem__(name) 62 | return True 63 | 64 | return False 65 | 66 | def GetOption(self,name): 67 | if DhcpFields.has_key(name) : 68 | option_info = DhcpFields[name] 69 | return self.packet_data[option_info[0]:option_info[0]+option_info[1]] 70 | 71 | elif self.options_data.has_key(name) : 72 | return self.options_data[name] 73 | 74 | return [] 75 | 76 | 77 | def SetOption(self,name,value): 78 | 79 | # Basic value checking : 80 | # has value list a correct length 81 | 82 | # if name is a standard dhcp field 83 | if DhcpFields.has_key(name) : 84 | if len(value) != DhcpFields[name][1] : 85 | sys.stderr.write( "pydhcplib.dhcp_basic_packet.setoption error, bad option length : "+name) 86 | return False 87 | begin = DhcpFields[name][0] 88 | end = DhcpFields[name][0]+DhcpFields[name][1] 89 | self.packet_data[begin:end] = value 90 | return True 91 | 92 | # if name is a dhcp option 93 | elif DhcpOptions.has_key(name) : 94 | 95 | # fields_specs : {'option_code':fixed_length,minimum_length,multiple} 96 | # if fixed_length == 0 : minimum_length and multiple apply 97 | # else : forget minimum_length and multiple 98 | # multiple : length MUST be a multiple of 'multiple' 99 | # FIXME : this definition should'nt be in dhcp_constants ? 100 | fields_specs = { "ipv4":[4,0,1], "ipv4+":[0,4,4], 101 | "string":[0,0,1], "bool":[1,0,1], 102 | "char":[1,0,1], "16-bits":[2,0,1], 103 | "32-bits":[4,0,1], "identifier":[0,2,1], 104 | "RFC3397":[0,4,1],"none":[0,0,1],"char+":[0,1,1] 105 | } 106 | 107 | specs = fields_specs[DhcpOptionsTypes[DhcpOptions[name]]] 108 | length = len(value) 109 | if (specs[0]!=0 and specs==length) or (specs[1]<=length and length%specs[2]==0): 110 | self.options_data[name] = value 111 | return True 112 | else : 113 | return False 114 | 115 | sys.stderr.write( "pydhcplib.dhcp_basic_packet.setoption error : unknown option "+name) 116 | return False 117 | 118 | 119 | 120 | def IsOption(self,name): 121 | if self.options_data.has_key(name) : return True 122 | elif DhcpFields.has_key(name) : return True 123 | else : return False 124 | 125 | # Encode Packet and return it 126 | def EncodePacket(self): 127 | 128 | # MUST set options in order to respect the RFC (see router option) 129 | order = {} 130 | 131 | for each in self.options_data.keys() : 132 | order[DhcpOptions[each]] = [] 133 | order[DhcpOptions[each]].append(DhcpOptions[each]) 134 | order[DhcpOptions[each]].append(len(self.options_data[each])) 135 | order[DhcpOptions[each]] += self.options_data[each] 136 | 137 | options = [] 138 | 139 | for each in sorted(order.keys()) : options += (order[each]) 140 | 141 | packet = self.packet_data[:240] + options 142 | packet.append(255) # add end option 143 | pack_fmt = str(len(packet))+"c" 144 | 145 | packet = map(chr,packet) 146 | 147 | return pack(pack_fmt,*packet) 148 | 149 | 150 | # Insert packet in the object 151 | def DecodePacket(self,data,debug=False): 152 | self.packet_data = [] 153 | self.options_data = {} 154 | 155 | if (not data) : return False 156 | # we transform all data to int list 157 | unpack_fmt = str(len(data)) + "c" 158 | for i in unpack(unpack_fmt,data): 159 | self.packet_data.append(ord(i)) 160 | 161 | # Some servers or clients don't place magic cookie immediately 162 | # after headers and begin options fields only after magic. 163 | # These 4 lines search magic cookie and begin iterator after. 164 | iterator = 236 165 | end_iterator = len(self.packet_data) 166 | while ( self.packet_data[iterator:iterator+4] != MagicCookie and iterator < end_iterator) : 167 | iterator += 1 168 | iterator += 4 169 | 170 | # parse extended options 171 | 172 | while iterator < end_iterator : 173 | if self.packet_data[iterator] == 0 : # pad option 174 | opt_first = iterator+1 175 | iterator += 1 176 | 177 | elif self.packet_data[iterator] == 255 : 178 | self.packet_data = self.packet_data[:240] # base packet length without magic cookie 179 | return 180 | 181 | elif DhcpOptionsTypes.has_key(self.packet_data[iterator]) and self.packet_data[iterator]!= 255: 182 | opt_len = self.packet_data[iterator+1] 183 | opt_first = iterator+1 184 | self.options_data[DhcpOptionsList[self.packet_data[iterator]]] = self.packet_data[opt_first+1:opt_len+opt_first+1] 185 | iterator += self.packet_data[opt_first] + 2 186 | else : 187 | opt_first = iterator+1 188 | iterator += self.packet_data[opt_first] + 2 189 | 190 | # cut packet_data to remove options 191 | 192 | self.packet_data = self.packet_data[:240] # base packet length with magic cookie 193 | -------------------------------------------------------------------------------- /pydhcplib/dhcp_network.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import sys 19 | import socket 20 | import select 21 | import dhcp_packet 22 | import interface 23 | import struct 24 | import _rawsocket 25 | import type_ipv4 26 | import IN 27 | 28 | class DhcpNetwork: 29 | def __init__(self, ifname, listen_address="0.0.0.0", listen_port=67, emit_port=68): 30 | netifo = interface.interface() 31 | self.ifname = ifname 32 | self.listen_port = int(listen_port) 33 | self.emit_port = int(emit_port) 34 | self.listen_address = listen_address 35 | self.so_reuseaddr = False 36 | self.so_broadcast = True 37 | self.dhcp_socket = None 38 | 39 | # Networking stuff 40 | def CreateSocket(self, so_broadcast, so_reuseaddr) : 41 | dhcp_socket = None 42 | try : 43 | dhcp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 44 | except socket.error, msg : 45 | sys.stderr.write('pydhcplib.DhcpNetwork socket creation error : '+str(msg)) 46 | 47 | try : 48 | if so_broadcast : 49 | dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1) 50 | except socket.error, msg : 51 | sys.stderr.write('pydhcplib.DhcpNetwork socket error in setsockopt SO_BROADCAST : '+str(msg)) 52 | 53 | try : 54 | if so_reuseaddr : 55 | dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) 56 | except socket.error, msg : 57 | sys.stderr.write('pydhcplib.DhcpNetwork socket error in setsockopt SO_REUSEADDR : '+str(msg)) 58 | 59 | return dhcp_socket 60 | 61 | def EnableReuseaddr(self) : 62 | self.so_reuseaddr = True 63 | 64 | def DisableReuseaddr(self) : 65 | self.so_reuseaddr = False 66 | 67 | def EnableBroadcast(self) : 68 | self.so_broadcast = True 69 | 70 | def DisableBroadcast(self) : 71 | self.so_broadcast = False 72 | 73 | def BindToDevice(self) : 74 | try : 75 | self.dhcp_socket.setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,self.ifname) 76 | except socket.error, msg : 77 | sys.stderr.write ('pydhcplib.DhcpNetwork.BindToDevice error in setsockopt SO_BINDTODEVICE : '+str(msg)) 78 | 79 | try : 80 | self.dhcp_socket.bind(('', self.listen_port)) 81 | except socket.error, msg : 82 | sys.stderr.write( 'pydhcplib.DhcpNetwork.BindToDevice error : '+str(msg)) 83 | 84 | def BindToAddress(self) : 85 | try : 86 | self.dhcp_socket.bind((self.listen_address, self.listen_port)) 87 | except socket.error,msg : 88 | sys.stderr.write( 'pydhcplib.DhcpNetwork.BindToAddress error : '+str(msg)) 89 | 90 | 91 | def GetNextDhcpPacket(self,timeout=60): 92 | data ="" 93 | 94 | 95 | while data == "" : 96 | 97 | data_input,data_output,data_except = select.select([self.dhcp_socket],[],[],timeout) 98 | 99 | if( data_input != [] ) : (data,source_address) = self.dhcp_socket.recvfrom(2048) 100 | else : return None 101 | 102 | if data != "" : 103 | packet = dhcp_packet.DhcpPacket() 104 | packet.source_address = source_address 105 | packet.DecodePacket(data) 106 | 107 | self.HandleDhcpAll(packet) 108 | 109 | if packet.IsDhcpDiscoverPacket(): 110 | self.HandleDhcpDiscover(packet) 111 | elif packet.IsDhcpRequestPacket(): 112 | self.HandleDhcpRequest(packet) 113 | elif packet.IsDhcpDeclinePacket(): 114 | self.HandleDhcpDecline(packet) 115 | elif packet.IsDhcpReleasePacket(): 116 | self.HandleDhcpRelease(packet) 117 | elif packet.IsDhcpInformPacket(): 118 | self.HandleDhcpInform(packet) 119 | elif packet.IsDhcpOfferPacket(): 120 | self.HandleDhcpOffer(packet) 121 | elif packet.IsDhcpAckPacket(): 122 | self.HandleDhcpAck(packet) 123 | elif packet.IsDhcpNackPacket(): 124 | self.HandleDhcpNack(packet) 125 | else: self.HandleDhcpUnknown(packet) 126 | 127 | return packet 128 | 129 | def SendDhcpPacket(self, request, response): 130 | giaddr = ".".join(map(str, request.GetOption("giaddr"))) 131 | ciaddr = ".".join(map(str, request.GetOption("ciaddr"))) 132 | yiaddr = ".".join(map(str, response.GetOption("yiaddr"))) 133 | chaddr = struct.pack(6*"B", *request.GetOption("chaddr")[0:6]) 134 | broadcast = request.GetOption("flags")[0] != 0 135 | 136 | if (giaddr != "0.0.0.0"): 137 | self.SendDhcpPacketTo(response, giaddr, self.listen_port) 138 | elif (response.IsDhcpNackPacket()): 139 | self.SendDhcpPacketTo(response, "255.255.255.255", self.emit_port) 140 | elif (ciaddr != "0.0.0.0"): 141 | self.SendDhcpPacketTo(response, ciaddr, self.emit_port) 142 | elif (broadcast): 143 | self.SendDhcpPacketTo(response, "255.255.255.255", self.emit_port) 144 | else: # unicast to yiaddr 145 | ifconfig = interface.interface() 146 | ifindex = ifconfig.getIndex(self.ifname) 147 | ifaddr = ifconfig.getAddr(self.ifname) 148 | if (ifaddr is None): 149 | ifaddr = "0.0.0.0" 150 | _rawsocket.udp_send_packet( response.EncodePacket(), 151 | type_ipv4.ipv4(ifaddr).int(), 152 | self.listen_port, 153 | type_ipv4.ipv4(yiaddr).int(), 154 | self.emit_port, 155 | chaddr, 156 | ifindex 157 | ) 158 | 159 | def SendDhcpPacketTo(self, packet, _ip, _port): 160 | return self.dhcp_socket.sendto(packet.EncodePacket(),(_ip,_port)) 161 | 162 | # Server side Handle methods 163 | def HandleDhcpDiscover(self, packet): 164 | pass 165 | 166 | def HandleDhcpRequest(self, packet): 167 | pass 168 | 169 | def HandleDhcpDecline(self, packet): 170 | pass 171 | 172 | def HandleDhcpRelease(self, packet): 173 | pass 174 | 175 | def HandleDhcpInform(self, packet): 176 | pass 177 | 178 | 179 | # client-side Handle methods 180 | def HandleDhcpOffer(self, packet): 181 | pass 182 | 183 | def HandleDhcpAck(self, packet): 184 | pass 185 | 186 | def HandleDhcpNack(self, packet): 187 | pass 188 | 189 | # Handle unknown options or all options 190 | def HandleDhcpUnknown(self, packet): 191 | pass 192 | 193 | def HandleDhcpAll(self, packet): 194 | pass 195 | 196 | 197 | 198 | class DhcpServer(DhcpNetwork) : 199 | def __init__(self, ifname,listen_address="0.0.0.0",client_listen_port=68,server_listen_port=67) : 200 | 201 | DhcpNetwork.__init__(self,ifname,listen_address,server_listen_port,client_listen_port) 202 | 203 | self.EnableBroadcast() 204 | self.DisableReuseaddr() 205 | 206 | self.dhcp_socket = self.CreateSocket(self.so_broadcast, self.so_reuseaddr) 207 | self.BindToAddress() 208 | 209 | class DhcpClient(DhcpNetwork) : 210 | def __init__(self, ifname=None, listen_address="0.0.0.0", client_listen_port=68,server_listen_port=67) : 211 | 212 | DhcpNetwork.__init__(self,ifname,listen_address,client_listen_port,server_listen_port) 213 | 214 | self.EnableBroadcast() 215 | self.EnableReuseaddr() 216 | 217 | self.dhcp_socket = self.CreateSocket(self.so_broadcast, self.so_reuseaddr) 218 | 219 | 220 | class DhcpClientOld(DhcpNetwork) : 221 | def __init__(self, listen_address="0.0.0.0",client_listen_port=68,server_listen_port=67) : 222 | 223 | DhcpNetwork.__init__(self,None,listen_address,client_listen_port,server_listen_port) 224 | 225 | try : 226 | self.dhcp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 227 | except socket.error, msg : 228 | sys.stderr.write( 'pydhcplib.DhcpClient socket creation error : '+str(msg)) 229 | 230 | try : 231 | self.dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1) 232 | self.dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) 233 | except socket.error, msg : 234 | sys.stderr.write( 'pydhcplib.DhcpClient socket error in setsockopt SO_BROADCAST or SO_REUSEADDR : '+str(msg)) 235 | 236 | 237 | def BindToDevice(self) : 238 | try : 239 | self.dhcp_socket.setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,self.ifname) 240 | except socket.error, msg : 241 | sys.stderr.write( 'pydhcplib.DhcpClient socket error in setsockopt SO_BINDTODEVICE : '+str(msg)) 242 | 243 | try : 244 | self.dhcp_socket.bind(('', self.listen_port)) 245 | except socket.error, msg : 246 | sys.stderr.write( 'pydhcplib.DhcpClient bind error : '+str(msg)) 247 | 248 | 249 | 250 | def BindToAddress(self) : 251 | try : 252 | self.dhcp_socket.bind((self.listen_address, self.listen_port)) 253 | except socket.error,msg : 254 | sys.stderr.write( 'pydhcplib.DhcpClient bind error : '+str(msg)) 255 | 256 | 257 | class DhcpServerOld(DhcpNetwork) : 258 | def __init__(self, ifname, listen_address="0.0.0.0", client_listen_port=68,server_listen_port=67) : 259 | 260 | DhcpNetwork.__init__(self,ifname,listen_address,server_listen_port,client_listen_port) 261 | 262 | try : 263 | self.dhcp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 264 | except socket.error, msg : 265 | sys.stderr.write( 'pydhcplib.DhcpServer socket creation error : '+str(msg)) 266 | 267 | try: 268 | self.dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1) 269 | except socket.error, msg : 270 | sys.stderr.write( 'pydhcplib.DhcpServer socket error in setsockopt SO_BROADCAST : '+str(msg)) 271 | 272 | try : 273 | self.dhcp_socket.bind((self.listen_address, self.listen_port)) 274 | except socket.error, msg : 275 | sys.stderr.write( 'pydhcplib.DhcpServer bind error : '+str(msg)) 276 | 277 | 278 | -------------------------------------------------------------------------------- /scripts/pydhcp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # pydhcplib 3 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 4 | # 5 | # This file is part of pydhcplib. 6 | # Pydhcplib is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | from pydhcplib import dhcp_constants 20 | from pydhcplib import dhcp_packet 21 | from pydhcplib import dhcp_network 22 | from pydhcplib import dhcp_file_io 23 | from pydhcplib import type_hwmac 24 | from pydhcplib import type_ipv4 25 | from pydhcplib import type_strlist 26 | from pydhcplib import interface 27 | 28 | import sys 29 | 30 | from optparse import OptionParser 31 | 32 | 33 | parser = OptionParser() 34 | 35 | """ Action options """ 36 | parser.add_option("-c", "--count", action="store",dest="count", help="Exact count of dhcp packets to be processed.", default="0", type="int") 37 | parser.add_option("-v", "--version", action="store_true",dest="version", help="Get pydhcplib and pydhcp version.", default=False) 38 | parser.add_option("-o", "--output", action="store",dest="output", help="\";;\"", default=False) 39 | parser.add_option("-i", "--input", action="store",dest="input", help="\";;\"", default=False) 40 | 41 | 42 | 43 | (options, args) = parser.parse_args() 44 | 45 | def print_error(_msg) : 46 | return sys.stderr.write(_msg+"\n") 47 | 48 | def main() : 49 | listener = False 50 | emitter = False 51 | 52 | port_destination = False 53 | ip_destination = False 54 | 55 | 56 | if options.version == True : 57 | print "PyDhcpLib version : ",dhcp_constants.PyDhcpLibVersion 58 | sys.exit(0) 59 | 60 | # process input command line 61 | if options.input != False : 62 | options.input = process_inline_options(options.input) 63 | listener = process_input(options.input,options.count) 64 | else : 65 | print_error ("Warning : no input option defined. Default is *stdin* with option *binary*.") 66 | listener = dhcp_file_io.DhcpStdIn() 67 | 68 | # process output command line 69 | if options.output != False : 70 | options.output = process_inline_options(options.output) 71 | emitter = process_output(options.output,options.count) 72 | ip_destination = options.output[2] 73 | port_destination = options.output[3] 74 | else : 75 | print_error ("Warning : no output option defined. Default is *stdout* with option *binary*.") 76 | emitter = dhcp_file_io.DhcpStdOut() 77 | 78 | # Last check before processing 79 | if ( not emitter ) : return False 80 | if ( not listener ) : return False 81 | 82 | # Go ! Process dhcp packet 83 | count = options.count 84 | 85 | if not options.input or options.input[0] == 'file' or options.input[0] == 'stdin' : 86 | count = 1 87 | if not options.output or options.output[0] == 'file' or options.output[0] == 'stdout' : 88 | count = 1 89 | 90 | gap = 0 91 | if count != 0 : gap = 1 92 | else : count = 1 93 | 94 | while count > 0 : 95 | packet = listener.GetNextDhcpPacket() 96 | emitter.SendDhcpPacketTo(packet,ip_destination,port_destination) 97 | count -= gap 98 | 99 | return True 100 | 101 | def process_input(_input,_count) : 102 | if not _input : 103 | print_error( "process_input_error" ) 104 | return false 105 | 106 | option_up = False 107 | option_binary = False 108 | listener = False 109 | file_in = False 110 | if not _count : _count = 0 111 | 112 | for option in _input[1] : 113 | if (option == 'binary') : 114 | option_binary = True 115 | if (option == 'up') : 116 | option_up = True 117 | 118 | _type = _input[0] 119 | _location = _input[2] 120 | _port = _input[3] 121 | 122 | if (_type == 'device') : 123 | if not option_binary : print_error ("Warning : option *readable* has no effect for types *device* and *address*") 124 | if option_up : 125 | print_error ("Setting interface "+_location+" up.)") 126 | check_device(_location,options.no_up) 127 | listener = dhcp_network.DhcpClient(_location,_port,_port) 128 | listener.BindToDevice() 129 | return listener 130 | 131 | elif (_type == 'address') : 132 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 133 | if not option_binary : print_error ("Warning : option *readable* has no effect for types *device* and *address*") 134 | listener = dhcp_network.DhcpClient(_location,_port,_port) 135 | listener.BindToAddress() 136 | return listener 137 | 138 | elif (_type == 'file') : 139 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 140 | if option_binary and _count !=1 : print_error ("Warning : option *count* is always 1 for type *file*") 141 | listener = dhcp_file_io.DhcpFileIn(_location) 142 | if not option_binary : listener.DisableBinaryTransport() 143 | return listener 144 | 145 | elif(_type == 'stdin') : 146 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 147 | listener = dhcp_file_io.DhcpStdIn() 148 | listener.DisableBinaryTransport() 149 | return listener 150 | 151 | 152 | def process_output(_output,_count) : 153 | if not _output : 154 | print_error( "process_output_error" ) 155 | return false 156 | 157 | option_up = False 158 | option_binary = False 159 | listener = False 160 | file_in = False 161 | if not _count : _count = 0 162 | 163 | for option in _output[1] : 164 | if (option == 'binary') : 165 | option_binary = True 166 | if (option == 'up') : 167 | option_up = True 168 | 169 | _type = _output[0] 170 | _location = _output[2] 171 | _port = _output[3] 172 | _iface = _output[4] 173 | 174 | if (_type == 'device') : 175 | print_error('Warning : type *device* not available for output. Send data to stdout with option *binary*') 176 | emitter = dhcp_file_io.DhcpStdOut() 177 | emitter.EnableBinaryTransport() 178 | return emitter 179 | 180 | elif (_type == 'address') : 181 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 182 | if not option_binary : print_error ("Warning : option *readable* has no effect for types *device* and *address*") 183 | check_device(_iface,False) 184 | emitter = dhcp_network.DhcpNetwork(_iface,_location,_port,_port) 185 | return emitter 186 | 187 | elif (_type == 'file') : 188 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 189 | if option_binary and _count !=1 : print_error ("Warning : option *count* is always 1 for type *file*") 190 | emitter = dhcp_file_io.DhcpFileOut(_location) 191 | 192 | if not option_binary : emitter.DisableBinaryTransport() 193 | else : emitter.EnableBinaryTransport() 194 | 195 | return emitter 196 | 197 | elif(_type == 'stdout') : 198 | if option_up : print_error ("Warning : option *up* has effect only for type *device* ") 199 | emitter = dhcp_file_io.DhcpStdOut() 200 | emitter.DisableBinaryTransport() 201 | return emitter 202 | 203 | def check_device(device_name,_up) : 204 | device = interface.interface() 205 | 206 | # Set UP interface if no_up option not present 207 | if _up : device.setStatusUp(device_name) 208 | 209 | # test if interface exists 210 | all_devices = device.getInterfaceList() 211 | valid = 0 212 | 213 | for each in all_devices : 214 | if each == device_name : valid += 1 215 | if valid == 0 : print_error( "Warning : no configured device - "+device_name+" - found." ) 216 | 217 | 218 | def process_inline_options(definition) : 219 | type_list = ['device','address','file','stdin','stdout'] 220 | options_list = ['readable','binary','up','noup'] 221 | input_split = definition.split(';') 222 | 223 | # Test the number of field in device definition 224 | if (len(input_split) > 3) : 225 | print_error( "Error : too many fields in device definition" ) 226 | return False 227 | elif (len(input_split) < 3) : 228 | print_error( "Error : not enough fields in device description" ) 229 | return False 230 | 231 | 232 | # Get and test _type_ field 233 | input_type = input_split[0] 234 | try: type_list.index(input_type) 235 | except ValueError: 236 | print_error( "Error : unknown type <"+input_type+"> (device, address, file, input, or output)") 237 | return False 238 | 239 | 240 | # Get an test options field 241 | input_options = input_split[1].split('|') 242 | 243 | if (len(input_options[0]) == 0) : input_options = [] 244 | mutual_up = 0 245 | readable_up = 0 246 | for each in input_options : 247 | try: options_list.index(each) 248 | except ValueError: 249 | print_error( "Error : unknown option <"+each+"> (readable, binary, up, or noup)") 250 | return False 251 | if each == 'up' : mutual_up += 1 252 | if each == 'noup' : mutual_up += 1 253 | if each == 'readable' : readable_up += 1 254 | if each == 'binary' : readable_up += 1 255 | if ( mutual_up > 1) : 256 | print_error( "Error : and are mutualy exclusive.") 257 | return False 258 | if ( readable_up > 1) : 259 | print_error( "Error : and are mutualy exclusive." ) 260 | return False 261 | 262 | # Get name and port 263 | if input_type=='device' or input_type=='address' : 264 | try : 265 | input_name = input_split[2] 266 | input_tmp = input_name.split(':') 267 | input_name = input_tmp[0] 268 | input_port = input_tmp[1] 269 | if input_type=="address": 270 | input_iface = input_tmp[2] 271 | else: 272 | input_iface = input_name 273 | except : 274 | if input_type=='device' : print_error( "Error : wrong name field. Example : eth0:68" ) 275 | if input_type=='address' : print_error( "Error : wrong name field. Example : 192.168.8.5:68:eth0" ) 276 | return False 277 | elif input_type=='file' : 278 | input_name = input_split[2] 279 | input_port = '' 280 | input_iface = "" 281 | else : 282 | input_name = '' 283 | input_port = '' 284 | input_iface = "" 285 | 286 | return [input_type,input_options,input_name,input_port,input_iface] 287 | 288 | try : 289 | if main() : sys.exit(0) 290 | sys.exit(1) 291 | except KeyboardInterrupt : 292 | print_error("Exiting pydhcp"); 293 | sys.exit(1) 294 | -------------------------------------------------------------------------------- /pydhcplib/dhcp_packet.py: -------------------------------------------------------------------------------- 1 | # pydhcplib 2 | # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org 3 | # 4 | # This file is part of pydhcplib. 5 | # Pydhcplib is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import operator 19 | from struct import unpack 20 | from struct import pack 21 | from dhcp_basic_packet import * 22 | from dhcp_constants import * 23 | from type_ipv4 import ipv4 24 | from type_strlist import strlist 25 | from type_hwmac import hwmac 26 | import sys 27 | 28 | class DhcpPacket(DhcpBasicPacket): 29 | def str(self): 30 | # Process headers : 31 | printable_data = "# Header fields\n" 32 | 33 | op = self.packet_data[DhcpFields['op'][0]:DhcpFields['op'][0]+DhcpFields['op'][1]] 34 | printable_data += "op : " + DhcpFieldsName['op'][str(op[0])] + "\n" 35 | 36 | 37 | for opt in ['htype','hlen','hops','xid','secs','flags', 38 | 'ciaddr','yiaddr','siaddr','giaddr','chaddr','sname','file'] : 39 | begin = DhcpFields[opt][0] 40 | end = DhcpFields[opt][0]+DhcpFields[opt][1] 41 | data = self.packet_data[begin:end] 42 | result = '' 43 | if DhcpFieldsTypes[opt] == "int" : result = str(data[0]) 44 | elif DhcpFieldsTypes[opt] == "int2" : result = str(data[0]*256+data[1]) 45 | elif DhcpFieldsTypes[opt] == "int4" : result = str(ipv4(data).int()) 46 | elif DhcpFieldsTypes[opt] == "str" : 47 | for each in data : 48 | if each != 0 : result += chr(each) 49 | else : break 50 | 51 | elif DhcpFieldsTypes[opt] == "ipv4" : result = ipv4(data).str() 52 | elif DhcpFieldsTypes[opt] == "hwmac" : 53 | result = [] 54 | hexsym = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'] 55 | for iterator in range(6) : 56 | result += [str(hexsym[data[iterator]/16]+hexsym[data[iterator]%16])] 57 | 58 | result = ':'.join(result) 59 | 60 | printable_data += opt+" : "+result + "\n" 61 | 62 | # Process options : 63 | printable_data += "# Options fields\n" 64 | 65 | for opt in self.options_data.keys(): 66 | data = self.options_data[opt] 67 | result = "" 68 | optnum = DhcpOptions[opt] 69 | if opt=='dhcp_message_type' : result = DhcpFieldsName['dhcp_message_type'][str(data[0])] 70 | elif DhcpOptionsTypes[optnum] == "char" : result = str(data[0]) 71 | elif DhcpOptionsTypes[optnum] == "16-bits" : result = str(data[0]*256+data[0]) 72 | elif DhcpOptionsTypes[optnum] == "32-bits" : result = str(ipv4(data).int()) 73 | elif DhcpOptionsTypes[optnum] == "string" : 74 | for each in data : 75 | if each != 0 : result += chr(each) 76 | else : break 77 | 78 | elif DhcpOptionsTypes[optnum] == "ipv4" : result = ipv4(data).str() 79 | elif DhcpOptionsTypes[optnum] == "ipv4+" : 80 | for i in range(0,len(data),4) : 81 | if len(data[i:i+4]) == 4 : 82 | result += ipv4(data[i:i+4]).str() + " - " 83 | elif DhcpOptionsTypes[optnum] == "char+" : 84 | if optnum == 55 : # parameter_request_list 85 | result = ','.join([DhcpOptionsList[each] for each in data]) 86 | else : result += str(data) 87 | 88 | printable_data += opt + " : " + result + "\n" 89 | 90 | return printable_data 91 | 92 | def AddLine(self,_string) : 93 | (parameter,junk,value) = _string.partition(':') 94 | parameter = parameter.strip() 95 | # If value begin with a whitespace, remove it, leave others 96 | if len(value)>0 and value[0] == ' ' : value = value[1:] 97 | value = self._OptionsToBinary(parameter,value) 98 | if value : self.SetOption(parameter,value) 99 | 100 | def _OptionsToBinary(self,parameter,value) : 101 | # Transform textual data into dhcp binary data 102 | 103 | p = parameter.strip() 104 | # 1- Search for header informations or specific parameter 105 | if p == 'op' or p == 'htype' : 106 | value = value.strip() 107 | if value.isdigit() : return [int(value)] 108 | try : 109 | value = DhcpNames[value.strip()] 110 | return [value] 111 | except KeyError : 112 | return [0] 113 | 114 | elif p == 'hlen' or p == 'hops' : 115 | try : 116 | value = int(value) 117 | return [value] 118 | except ValueError : 119 | return [0] 120 | 121 | elif p == 'secs' or p == 'flags' : 122 | try : 123 | value = ipv4(int(value)).list() 124 | except ValueError : 125 | value = [0,0,0,0] 126 | 127 | return value[2:] 128 | 129 | elif p == 'xid' : 130 | try : 131 | value = ipv4(int(value)).list() 132 | except ValueError : 133 | value = [0,0,0,0] 134 | return value 135 | 136 | elif p == 'ciaddr' or p == 'yiaddr' or p == 'siaddr' or p == 'giaddr' : 137 | try : 138 | ip = ipv4(value).list() 139 | except ValueError : 140 | ip = [0,0,0,0] 141 | return ip 142 | 143 | elif p == 'chaddr' : 144 | try: 145 | value = hwmac(value).list()+[0]*10 146 | except ValueError,TypeError : 147 | value = [0]*16 148 | return value 149 | 150 | elif p == 'sname' : 151 | return 152 | elif p == 'file' : 153 | return 154 | elif p == 'parameter_request_list' : 155 | value = value.strip().split(',') 156 | tmp = [] 157 | for each in value: 158 | if DhcpOptions.has_key(each) : tmp.append(DhcpOptions[each]) 159 | return tmp 160 | elif p=='dhcp_message_type' : 161 | try : 162 | return [DhcpNames[value]] 163 | except KeyError: 164 | return 165 | 166 | # 2- Search for options 167 | try : option_type = DhcpOptionsTypes[DhcpOptions[parameter]] 168 | except KeyError : return False 169 | 170 | if option_type == "ipv4" : 171 | # this is a single ip address 172 | try : 173 | binary_value = map(int,value.split(".")) 174 | except ValueError : return False 175 | 176 | elif option_type == "ipv4+" : 177 | # this is multiple ip address 178 | iplist = value.split(",") 179 | opt = [] 180 | for single in iplist : 181 | opt += (ipv4(single).list()) 182 | binary_value = opt 183 | 184 | elif option_type == "32-bits" : 185 | # This is probably a number... 186 | try : 187 | digit = int(value) 188 | binary_value = [digit>>24&0xFF,(digit>>16)&0xFF,(digit>>8)&0xFF,digit&0xFF] 189 | except ValueError : 190 | return False 191 | 192 | elif option_type == "16-bits" : 193 | try : 194 | digit = int(value) 195 | binary_value = [(digit>>8)&0xFF,digit&0xFF] 196 | except ValueError : return False 197 | 198 | 199 | elif option_type == "char" : 200 | try : 201 | digit = int(value) 202 | binary_value = [digit&0xFF] 203 | except ValueError : return False 204 | 205 | elif option_type == "bool" : 206 | if value=="False" or value=="false" or value==0 : 207 | binary_value = [0] 208 | else : binary_value = [1] 209 | 210 | elif option_type == "string" : 211 | binary_value = strlist(value).list() 212 | 213 | else : 214 | binary_value = strlist(value).list() 215 | 216 | return binary_value 217 | 218 | # FIXME: This is called from IsDhcpSomethingPacket, but is this really 219 | # needed? Or maybe this testing should be done in 220 | # DhcpBasicPacket.DecodePacket(). 221 | 222 | # Test Packet Type 223 | def IsDhcpSomethingPacket(self,type): 224 | if self.IsDhcpPacket() == False : return False 225 | if self.IsOption("dhcp_message_type") == False : return False 226 | if self.GetOption("dhcp_message_type") != type : return False 227 | return True 228 | 229 | def IsDhcpDiscoverPacket(self): 230 | return self.IsDhcpSomethingPacket([1]) 231 | 232 | def IsDhcpOfferPacket(self): 233 | return self.IsDhcpSomethingPacket([2]) 234 | 235 | def IsDhcpRequestPacket(self): 236 | return self.IsDhcpSomethingPacket([3]) 237 | 238 | def IsDhcpDeclinePacket(self): 239 | return self.IsDhcpSomethingPacket([4]) 240 | 241 | def IsDhcpAckPacket(self): 242 | return self.IsDhcpSomethingPacket([5]) 243 | 244 | def IsDhcpNackPacket(self): 245 | return self.IsDhcpSomethingPacket([6]) 246 | 247 | def IsDhcpReleasePacket(self): 248 | return self.IsDhcpSomethingPacket([7]) 249 | 250 | def IsDhcpInformPacket(self): 251 | return self.IsDhcpSomethingPacket([8]) 252 | 253 | 254 | def GetMultipleOptions(self,options=()): 255 | result = {} 256 | for each in options: 257 | result[each] = self.GetOption(each) 258 | return result 259 | 260 | def SetMultipleOptions(self,options={}): 261 | for each in options.keys(): 262 | self.SetOption(each,options[each]) 263 | 264 | 265 | 266 | 267 | 268 | 269 | # Creating Response Packet 270 | 271 | # Server-side functions 272 | # From RFC 2132 page 28/29 273 | def CreateDhcpOfferPacketFrom(self,src): # src = discover packet 274 | self.SetOption("htype",src.GetOption("htype")) 275 | self.SetOption("xid",src.GetOption("xid")) 276 | self.SetOption("flags",src.GetOption("flags")) 277 | self.SetOption("giaddr",src.GetOption("giaddr")) 278 | self.SetOption("chaddr",src.GetOption("chaddr")) 279 | self.SetOption("ip_address_lease_time",src.GetOption("ip_address_lease_time")) 280 | self.TransformToDhcpOfferPacket() 281 | 282 | def TransformToDhcpOfferPacket(self): 283 | self.SetOption("dhcp_message_type",[2]) 284 | self.SetOption("op",[2]) 285 | self.SetOption("hlen",[6]) 286 | 287 | self.DeleteOption("secs") 288 | self.DeleteOption("ciaddr") 289 | self.DeleteOption("request_ip_address") 290 | self.DeleteOption("parameter_request_list") 291 | self.DeleteOption("client_identifier") 292 | self.DeleteOption("maximum_message_size") 293 | 294 | 295 | 296 | 297 | 298 | """ Dhcp ACK packet creation """ 299 | def CreateDhcpAckPacketFrom(self,src): # src = request or inform packet 300 | self.SetOption("htype",src.GetOption("htype")) 301 | self.SetOption("xid",src.GetOption("xid")) 302 | self.SetOption("ciaddr",src.GetOption("ciaddr")) 303 | self.SetOption("flags",src.GetOption("flags")) 304 | self.SetOption("giaddr",src.GetOption("giaddr")) 305 | self.SetOption("chaddr",src.GetOption("chaddr")) 306 | self.SetOption("ip_address_lease_time",src.GetOption("ip_address_lease_time")) 307 | self.TransformToDhcpAckPacket() 308 | 309 | def TransformToDhcpAckPacket(self): # src = request or inform packet 310 | self.SetOption("op",[2]) 311 | self.SetOption("hlen",[6]) 312 | self.SetOption("dhcp_message_type",[5]) 313 | 314 | self.DeleteOption("secs") 315 | self.DeleteOption("request_ip_address") 316 | self.DeleteOption("parameter_request_list") 317 | self.DeleteOption("client_identifier") 318 | self.DeleteOption("maximum_message_size") 319 | 320 | 321 | """ Dhcp NACK packet creation """ 322 | def CreateDhcpNackPacketFrom(self,src): # src = request or inform packet 323 | 324 | self.SetOption("htype",src.GetOption("htype")) 325 | self.SetOption("xid",src.GetOption("xid")) 326 | self.SetOption("flags",src.GetOption("flags")) 327 | self.SetOption("giaddr",src.GetOption("giaddr")) 328 | self.SetOption("chaddr",src.GetOption("chaddr")) 329 | self.TransformToDhcpNackPacket() 330 | 331 | def TransformToDhcpNackPacket(self): 332 | self.SetOption("op",[2]) 333 | self.SetOption("hlen",[6]) 334 | self.DeleteOption("secs") 335 | self.DeleteOption("ciaddr") 336 | self.DeleteOption("yiaddr") 337 | self.DeleteOption("siaddr") 338 | self.DeleteOption("sname") 339 | self.DeleteOption("file") 340 | self.DeleteOption("request_ip_address") 341 | self.DeleteOption("ip_address_lease_time") 342 | self.DeleteOption("parameter_request_list") 343 | self.DeleteOption("client_identifier") 344 | self.DeleteOption("maximum_message_size") 345 | self.SetOption("dhcp_message_type",[6]) 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | """ GetClientIdentifier """ 354 | 355 | def GetClientIdentifier(self) : 356 | if self.IsOption("client_identifier") : 357 | return self.GetOption("client_identifier") 358 | return [] 359 | 360 | def GetGiaddr(self) : 361 | return self.GetOption("giaddr") 362 | 363 | def GetHardwareAddress(self) : 364 | length = self.GetOption("hlen")[0] 365 | full_hw = self.GetOption("chaddr") 366 | if length!=[] and length. 17 | 18 | 19 | MagicCookie = [99,130,83,99] 20 | PyDhcpLibVersion = '0.6' 21 | 22 | # DhcpBaseOptions = '{fieldname':[location,length]} 23 | DhcpFields = {'op':[0,1], 24 | 'htype':[1,1], 25 | 'hlen':[2,1], 26 | 'hops':[3,1], 27 | 'xid':[4,4], 28 | 'secs':[8,2], 29 | 'flags':[10,2], 30 | 'ciaddr':[12,4], 31 | 'yiaddr':[16,4], 32 | 'siaddr':[20,4], 33 | 'giaddr':[24,4], 34 | 'chaddr':[28,16], 35 | 'sname':[44,64], 36 | 'file':[108,128] 37 | } 38 | DhcpFieldsName = { 'op' : { '0': 'ERROR_UNDEF', '1' : 'BOOTREQUEST' , '2' : 'BOOTREPLY'}, 39 | 'dhcp_message_type' : { '0': 'ERROR_UNDEF', '1': 'DHCP_DISCOVER', '2': 'DHCP_OFFER', 40 | '3' : 'DHCP_REQUEST','4':'DHCP_DECLINE', '5': 'DHCP_ACK', '6': 'DHCP_NACK', 41 | '7': 'DHCP_RELEASE', '8' : 'DHCP_INFORM' } 42 | } 43 | DhcpNames = { 'ERROR_UNDEF':0 , 'BOOTREQUEST':1 , 'BOOTREPLY':2 , 44 | 'DHCP_DISCOVER':1 , 'DHCP_OFFER':2 , 'DHCP_REQUEST':3 , 45 | 'DHCP_DECLINE':4 , 'DHCP_ACK':5 , 'DHCP_NACK':6 , 46 | 'DHCP_RELEASE':7 , 'DHCP_INFORM':8 } 47 | 48 | DhcpFieldsTypes = {'op':"int", 49 | 'htype':"int", 50 | 'hlen':"int", 51 | 'hops':"int", 52 | 'xid':"int4", 53 | 'secs':"int2", 54 | 'flags':"int2", 55 | 'ciaddr':"ipv4", 56 | 'yiaddr':"ipv4", 57 | 'siaddr':"ipv4", 58 | 'giaddr':"ipv4", 59 | 'chaddr':"hwmac", 60 | 'sname':"str", 61 | 'file':"str" 62 | } 63 | 64 | # DhcpOptions = 'option_name':option_code 65 | DhcpOptions = {'pad':0, 66 | 67 | # Vendor Extension 68 | 'subnet_mask':1,'time_offset':2, 69 | 'router':3,'time_server':4,'name_server':5, 70 | 'domain_name_server':6,'log_server':7, 71 | 'cookie_server':8,'lpr_server':9, 72 | 'impress_server':10,'resource_location_server':11, 73 | 'host_name':12,'boot_file':13,'merit_dump_file':14, 74 | 'domain_name':15,'swap_server':16,'root_path':17,'extensions_path':18, 75 | 76 | # IP layer parameters per host 77 | 'ip_forwarding':19,'nonlocal_source_rooting':20, 78 | 'policy_filter':21,'maximum_datagram_reassembly_size':22, 79 | 'default_ip_time-to-live':23,'path_mtu_aging_timeout':24, 80 | 'path_mtu_table':25, 81 | 82 | # IP layer parameters per interface 83 | 'interface_mtu':26,'all_subnets_are_local':27, 84 | 'broadcast_address':28,'perform_mask_discovery':29, 85 | 'mask_supplier':30,'perform_router_discovery':31, 86 | 'routeur_solicitation_address':32,'static_route':33, 87 | 88 | # link layer parameters per interface 89 | 'trailer_encapsulation':34,'arp_cache_timeout':35, 90 | 'ethernet_encapsulation':36, 91 | 92 | # TCP parameters 93 | 'tcp_default_ttl':37,'tcp_keepalive_interval':38, 94 | 'tcp_keepalive_garbage':39, 95 | 96 | # Applications and service parameters 97 | 'nis_domain':40, 98 | 'nis_servers':41, 99 | 'ntp_servers':42, 100 | 'vendor_specific':43, 101 | 'nbns':44, 102 | 'nbdd':45,'nb_node_type':46, 103 | 'nb_scope':47,'x_window_system_font_server':48, 104 | 'x_window_system_display_manager':49, 105 | 106 | # DHCP extensions 107 | 'request_ip_address':50, 108 | 'ip_address_lease_time':51, 109 | 'overload':52, 110 | 'dhcp_message_type':53, 111 | 'server_identifier':54, 112 | 'parameter_request_list':55, 113 | 'message':56, 114 | 'maximum_dhcp_message_size':57, 115 | 'renewal_time_value':58, 116 | 'rebinding_time_value':59, 117 | 'vendor_class':60, 118 | 'client_identifier':61, 119 | 120 | # Add from RFC 2132 121 | 'netware_ip_domain_name':62, 122 | 'netware_ip_sub_options':63, 123 | 124 | 'nis+_domain':64, 125 | 'nis+_servers':65, 126 | 'tftp_server_name':66, 127 | 'bootfile_name':67, 128 | 'mobile_ip_home_agent':68, 129 | 'smtp_servers':69, 130 | 'pop_servers':70, 131 | 'nntp_servers':71, 132 | 'default_www_server':72, 133 | 'default_finger_server':73, 134 | 'default_irc_server':74, 135 | 'streettalk_server':75, 136 | 'streettalk_directory_assistance_server':76, 137 | 138 | 'user_class':77, 139 | 'directory_agent':78, 140 | 'service_scope':79, 141 | 'rapid_commit':80, 142 | 143 | 'client_fqdn':81, 144 | 'relay_agent':82, 145 | 'internet_storage_name_service':83, 146 | '84':84, 147 | 'nds_server':85, 148 | 'nds_tree_name':86, 149 | 'nds_context':87, 150 | '88':88, 151 | '89':89, 152 | 'authentication':90, 153 | 'client_last_transaction_time':91, 154 | 'associated_ip':92, 155 | 'client_system':93, 156 | 'client_ndi':94, 157 | 'ldap':95, 158 | 'unassigned':96, 159 | 'uuid_guid':97, 160 | 'open_group_user_auth':98, 161 | 'unassigned':99, 162 | 'unassigned':100, 163 | 'unassigned':101, 164 | 'unassigned':102, 165 | 'unassigned':103, 166 | 'unassigned':104, 167 | 'unassigned':105, 168 | 'unassigned':106, 169 | 'unassigned':107, 170 | 'unassigned':108, 171 | 'unassigned':109, 172 | 'unassigned':110, 173 | 'unassigned':111, 174 | 'netinfo_address':112, 175 | 'netinfo_tag':113, 176 | 'url':114, 177 | 'unassigned':115, 178 | 'auto_config':116, 179 | 'name_service_search':117, 180 | 'subnet_selection':118, 181 | 'domain_search':119, 182 | 'sip_servers':120, 183 | 'classless_static_route':121, 184 | 'cablelabs_client_configuration':122, 185 | 'geoconf':123, 186 | 'vendor_class':124, 187 | 'vendor_specific':125, 188 | '126':126,'127':127,'128':128,'129':129, 189 | '130':130,'131':131,'132':132,'133':133, 190 | '134':134,'135':135,'136':136,'137':137, 191 | '138':138,'139':139,'140':140,'141':141, 192 | '142':142,'143':143,'144':144,'145':145, 193 | '146':146,'147':147,'148':148,'149':149, 194 | '150':150,'151':151,'152':152,'153':153, 195 | '154':154,'155':155,'156':156,'157':157, 196 | '158':158,'159':159,'160':160,'161':161, 197 | '162':162,'163':163,'164':164,'165':165, 198 | '166':166,'167':167,'168':168,'169':169, 199 | '170':170,'171':171,'172':172,'173':173, 200 | '174':174,'175':175,'176':176,'177':177, 201 | '178':178,'179':179,'180':180,'181':181, 202 | '182':182,'183':183,'184':184,'185':185, 203 | '186':186,'187':187,'188':188,'189':189, 204 | '190':190,'191':191,'192':192,'193':193, 205 | '194':194,'195':195,'196':196,'197':197, 206 | '198':198,'199':199,'200':200,'201':201, 207 | '202':202,'203':203,'204':204,'205':205, 208 | '206':206,'207':207,'208':208,'209':209, 209 | '210':210,'211':211,'212':212,'213':213, 210 | '214':214,'215':215,'216':216,'217':217, 211 | '218':218,'219':219,'220':220,'221':221, 212 | '222':222,'223':223,'224':224,'225':225, 213 | '226':226,'227':227,'228':228,'229':229, 214 | '230':230,'231':231,'232':232,'233':233, 215 | '234':234,'235':235,'236':236,'237':237, 216 | '238':238,'239':239,'240':240,'241':241, 217 | '242':242,'243':243,'244':244,'245':245, 218 | '246':246,'247':247,'248':248,'249':249, 219 | '250':250,'251':251,'252':252,'253':253, 220 | '254':254,'end':255 221 | 222 | } 223 | 224 | # DhcpOptionsList : reverse of DhcpOptions 225 | DhcpOptionsList = ['pad', 226 | 227 | # Vendor Extension 228 | 'subnet_mask','time_offset', 229 | 'router','time_server','name_server', 230 | 'domain_name_server','log_server', 231 | 'cookie_server','lpr_server', 232 | 'impress_server','resource_location_server', 233 | 'host_name','boot_file','merit_dump_file', 234 | 'domain_name','swap_server','root_path','extensions_path', 235 | 236 | # IP layer parameters per host 237 | 'ip_forwarding','nonlocal_source_rooting', 238 | 'policy_filter','maximum_datagram_reassembly_size', 239 | 'default_ip_time-to-live','path_mtu_aging_timeout', 240 | 'path_mtu_table', 241 | 242 | # IP layer parameters per interface 243 | 'interface_mtu','all_subnets_are_local', 244 | 'broadcast_address','perform_mask_discovery', 245 | 'mask_supplier','perform_router_discovery', 246 | 'routeur_solicitation_address','static_route', 247 | 248 | # link layer parameters per interface 249 | 'trailer_encapsulation','arp_cache_timeout', 250 | 'ethernet_encapsulation', 251 | 252 | # TCP parameters 253 | 'tcp_default_ttl','tcp_keepalive_interval', 254 | 'tcp_keepalive_garbage', 255 | 256 | # Applications and service parameters 257 | 'nis_domain', 258 | 'nis_servers', 259 | 'ntp_servers', 260 | 'vendor_specific','nbns', 261 | 'nbdd','nd_node_type', 262 | 'nb_scope','x_window_system_font_server', 263 | 'x_window_system_display_manager', 264 | 265 | # DHCP extensions 266 | 'request_ip_address', 267 | 'ip_address_lease_time', 268 | 'overload', 269 | 'dhcp_message_type', 270 | 'server_identifier', 271 | 'parameter_request_list', 272 | 'message', 273 | 'maximum_dhcp_message_size', 274 | 'renewal_time_value', 275 | 'rebinding_time_value', 276 | 'vendor_class', 277 | 'client_identifier', 278 | 279 | 280 | # adds from RFC 2132,2242 281 | 'netware_ip_domain_name', 282 | 'netware_ip_sub_options', 283 | 'nis+_domain', 284 | 'nis+_servers', 285 | 'tftp_server_name', 286 | 'bootfile_name', 287 | 'mobile_ip_home_agent', 288 | 'smtp_servers', 289 | 'pop_servers', 290 | 'nntp_servers', 291 | 'default_www_server', 292 | 'default_finger_server', 293 | 'default_irc_server', 294 | 'streettalk_server', 295 | 'streettalk_directory_assistance_server', 296 | 'user_class','directory_agent','service_scope', 297 | 298 | # 80 299 | 'rapid_commit','client_fqdn','relay_agent', 300 | 'internet_storage_name_service', 301 | '84', 302 | 'nds_server','nds_tree_name','nds_context', 303 | '88','89', 304 | 305 | #90 306 | 'authentication', 307 | 'client_last_transaction_time','associated_ip', #RFC 4388 308 | 'client_system', 'client_ndi', #RFC 3679 309 | 'ldap','unassigned','uuid_guid', #RFC 3679 310 | 'open_group_user_auth', #RFC 2485 311 | 312 | # 99->115 RFC3679 313 | 'unassigned','unassigned','unassigned', 314 | 'unassigned','unassigned','unassigned', 315 | 'unassigned','unassigned','unassigned', 316 | 'unassigned','unassigned','unassigned', 317 | 'unassigned','netinfo_address','netinfo_tag', 318 | 'url','unassigned', 319 | 320 | #116 321 | 'auto_config','name_service_search','subnet_selection', 322 | 'domain_search','sip_servers','classless_static_route', 323 | 'cablelabs_client_configuration','geoconf', 324 | 325 | #124 326 | 'vendor_class', 'vendor_specific', 327 | 328 | '126','127','128','129', 329 | '130','131','132','133','134','135','136','137','138','139', 330 | '140','141','142','143','144','145','146','147','148','149', 331 | '150','151','152','153','154','155','156','157','158','159', 332 | '160','161','162','163','164','165','166','167','168','169', 333 | '170','171','172','173','174','175','176','177','178','179', 334 | '180','181','182','183','184','185','186','187','188','189', 335 | '190','191','192','193','194','195','196','197','198','199', 336 | '200','201','202','203','204','205','206','207','208','209', 337 | '210','211','212','213','214','215','216','217','218','219', 338 | '220','221','222','223','224','225','226','227','228','229', 339 | '230','231','232','233','234','235','236','237','238','239', 340 | '240','241','242','243','244','245','246','247','248','249', 341 | '250','251','252','253','254', 342 | 343 | 'end' 344 | ] 345 | 346 | 347 | # See http://www.iana.org/assignments/bootp-dhcp-parameters 348 | # FIXME : verify all ipv4+ options, somes are 32 bits... 349 | 350 | DhcpOptionsTypes = {0:"none", 1:"ipv4", 2:"ipv4", 3:"ipv4+", 351 | 4:"ipv4+", 5:"ipv4+", 6:"ipv4+", 7:"ipv4+", 352 | 8:"ipv4+", 9:"ipv4+", 10:"ipv4+", 11:"ipv4+", 353 | 12:"string", 13:"16-bits", 14:"string", 15:"string", 354 | 16:"ipv4", 17:"string", 18:"string", 19:"bool", 355 | 20:"bool", 21:"ipv4+", 22:"16-bits", 23:"char", 356 | 24:"ipv4", 25:"16-bits", 26:"16-bits", 27:"bool", 357 | 28:"ipv4", 29:"bool", 30:"bool", 31:"bool", 358 | 32:"ipv4", 33:"ipv4+", 34:"bool", 35:"32-bits", 359 | 36:"bool", 37:"char", 38:"32-bits", 39:"bool", 360 | 40:"string", 41:"ipv4+", 42:"ipv4+", 43:"string", 361 | 44:"ipv4+", 45:"ipv4+", 46:"char", 47:"string", 362 | 48:"ipv4+", 49:"ipv4+", 50:"ipv4", 51:"32-bits", 363 | 52:"char", 53:"char", 54:"32-bits", 55:"char+", 364 | 56:"string", 57:"16-bits", 58:"32-bits", 59:"32-bits", 365 | 60:"string", 61:"identifier", 62:"string", 63:"RFC2242", 366 | 64:"string", 65:"ipv4+", 66:"string", 67:"string", 367 | 68:"ipv4", 69:"ipv4+", 70:"ipv4+", 71:"ipv4+", 368 | 72:"ipv4+", 73:"ipv4+", 74:"ipv4+", 75:"ipv4+", 369 | 76:"ipv4+", 77:"RFC3004", 78:"RFC2610", 79:"RFC2610", 370 | 80:"null", 81:"string", 82:"RFC3046", 83:"RFC4174", 371 | 84:"Unassigned", 85:"ipv4+", 86:"RFC2241", 87:"RFC2241", 372 | 88:"Unassigned", 89:"Unassigned", 90:"RFC3118", 91:"RFC4388", 373 | 92:"ipv4+", 93:"Unassigned", 94:"Unassigned", 95:"Unassigned", 374 | 96:"Unassigned", 97:"Unassigned", 98:"string", 99:"Unassigned", 375 | 100:"Unassigned", 101:"Unassigned", 102:"Unassigned", 103:"Unassigned", 376 | 104:"Unassigned", 105:"Unassigned", 106:"Unassigned", 107:"Unassigned", 377 | 108:"Unassigned", 109:"Unassigned", 110:"Unassigned", 111:"Unassigned", 378 | 112:"Unassigned", 113:"Unassigned", 114:"Unassigned", 115:"Unassigned", 379 | 116:"char", 117:"RFC2937", 118:"ipv4", 119:"RFC3397", 380 | 120:"RFC3361", 381 | 382 | #TODO 383 | 121:"Unassigned", 122:"Unassigned", 123:"Unassigned", 384 | 124:"Unassigned", 125:"Unassigned", 126:"Unassigned", 127:"Unassigned", 385 | 128:"Unassigned", 129:"Unassigned", 130:"Unassigned", 131:"Unassigned", 386 | 132:"Unassigned", 133:"Unassigned", 134:"Unassigned", 135:"Unassigned", 387 | 136:"Unassigned", 137:"Unassigned", 138:"Unassigned", 139:"Unassigned", 388 | 140:"Unassigned", 141:"Unassigned", 142:"Unassigned", 143:"Unassigned", 389 | 144:"Unassigned", 145:"Unassigned", 146:"Unassigned", 147:"Unassigned", 390 | 148:"Unassigned", 149:"Unassigned", 150:"Unassigned", 151:"Unassigned", 391 | 152:"Unassigned", 153:"Unassigned", 154:"Unassigned", 155:"Unassigned", 392 | 156:"Unassigned", 157:"Unassigned", 158:"Unassigned", 159:"Unassigned", 393 | 160:"Unassigned", 161:"Unassigned", 162:"Unassigned", 163:"Unassigned", 394 | 164:"Unassigned", 165:"Unassigned", 166:"Unassigned", 167:"Unassigned", 395 | 168:"Unassigned", 169:"Unassigned", 170:"Unassigned", 171:"Unassigned", 396 | 172:"Unassigned", 173:"Unassigned", 174:"Unassigned", 175:"Unassigned", 397 | 176:"Unassigned", 177:"Unassigned", 178:"Unassigned", 179:"Unassigned", 398 | 180:"Unassigned", 181:"Unassigned", 182:"Unassigned", 183:"Unassigned", 399 | 184:"Unassigned", 185:"Unassigned", 186:"Unassigned", 187:"Unassigned", 400 | 188:"Unassigned", 189:"Unassigned", 190:"Unassigned", 191:"Unassigned", 401 | 192:"Unassigned", 193:"Unassigned", 194:"Unassigned", 195:"Unassigned", 402 | 196:"Unassigned", 197:"Unassigned", 198:"Unassigned", 199:"Unassigned", 403 | 200:"Unassigned", 201:"Unassigned", 202:"Unassigned", 203:"Unassigned", 404 | 204:"Unassigned", 205:"Unassigned", 206:"Unassigned", 207:"Unassigned", 405 | 208:"Unassigned", 209:"Unassigned", 210:"Unassigned", 211:"Unassigned", 406 | 212:"Unassigned", 213:"Unassigned", 214:"Unassigned", 215:"Unassigned", 407 | 216:"Unassigned", 217:"Unassigned", 218:"Unassigned", 219:"Unassigned", 408 | 220:"Unassigned", 221:"Unassigned", 222:"Unassigned", 223:"Unassigned", 409 | 224:"Unassigned", 225:"Unassigned", 226:"Unassigned", 227:"Unassigned", 410 | 228:"Unassigned", 229:"Unassigned", 230:"Unassigned", 231:"Unassigned", 411 | 232:"Unassigned", 233:"Unassigned", 234:"Unassigned", 235:"Unassigned", 412 | 236:"Unassigned", 237:"Unassigned", 238:"Unassigned", 239:"Unassigned", 413 | 240:"Unassigned", 241:"Unassigned", 242:"Unassigned", 243:"Unassigned", 414 | 244:"Unassigned", 245:"Unassigned"} 415 | -------------------------------------------------------------------------------- /docs/dhcp_options_supported.txt: -------------------------------------------------------------------------------- 1 | All DHCP options described in RFC 2131 should be supported. To set an option in a dhcp packet you first create a dhcp packet : 2 | from dhcp_packet import DhcpPacket 3 | mypacket = DhcpPacket() 4 | 5 | Then you set an option like this : 6 | mypacket.SetOption('option_name',option_data) 7 | 8 | MUST be a list of integer between 0 and 255. 9 | 10 | 11 | Data types 12 | ========== 13 | * Single IP : 4 octets list (ex : [191.121.212.11]) 14 | * Multiple IP : MUST be a multiple of 4 octets list (4 octets at least) 15 | * 32-bits : integer of 4 octets. 16 | * String : a list of octet interpreted as ascii characters with a minimal size of 1. 17 | 18 | 19 | RFC 1497 Vendor Extensions 20 | ========================== 21 | * subnet_mask 22 | RFC code : 1 23 | Type : Single IP 24 | 25 | The subnet mask option specifies the client's subnet mask as per RFC 950. 26 | 27 | * time_offset 28 | RFC code : 2 29 | Type : 32-bits 30 | 31 | The time offset field specifies the offset of the client's subnet in seconds from Coordinated Universal Time (UTC). The offset is expressed as a two's complement 32-bit integer. A positive offset indicates a location east of the zero meridian and a negative offset indicates a location west of the zero meridian. 32 | 33 | * router_option (code 3) 34 | RFC code : 3 35 | Type : Multiple IP 36 | 37 | The router option specifies a list of IP addresses for routers on the client's subnet. Routers SHOULD be listed in order of preference. 38 | 39 | * time_server 40 | RFC code : 4 41 | Type : Multiple IP 42 | 43 | The time server option specifies a list of RFC 868 time servers available to the client. Servers SHOULD be listed in order of preference. 44 | 45 | * name_server 46 | RFC code : 5 47 | Type : Multiple IP 48 | 49 | The name server option specifies a list of IEN 116 name servers available to the client. Servers SHOULD be listed in order of preference. 50 | 51 | * domain_name_server 52 | RFC code : 6 53 | Type : Mutltiple IP 54 | 55 | The domain name server option specifies a list of Domain Name System (STD 13, RFC 1035) name servers available to the client. Servers SHOULD be listed in order of preference. 56 | 57 | * log_server 58 | RFC code : 7 59 | Type : Multiple IP 60 | 61 | The log server option specifies a list of MIT-LCS UDP log servers available to the client. Servers SHOULD be listed in order of preference. 62 | 63 | * cookie_server 64 | RFC code : 8 65 | Type : Multiple IP 66 | 67 | The cookie server option specifies a list of RFC 865 cookie servers available to the client. Servers SHOULD be listed in order of preference. 68 | 69 | * lpr_server 70 | RFC code : 9 71 | Type : Multiple IP 72 | 73 | The LPR server option specifies a list of RFC 1179 line printer servers available to the client. Servers SHOULD be listed in order of preference. 74 | 75 | 76 | * impress_server 77 | RFC code : 10 78 | Type : Multiple IP 79 | 80 | The Impress server option specifies a list of Imagen Impress servers available to the client. Servers SHOULD be listed in order of preference. 81 | 82 | * resource_location_ server 83 | Code : 11 84 | Type : Multiple IP 85 | 86 | This option specifies a list of RFC 887 Resource Location servers available to the client. Servers SHOULD be listed in order of preference. 87 | 88 | * host_name 89 | RFC code : 12 90 | Type : String 91 | 92 | This option specifies the name of the client. The name may or may not be qualified with the local domain name. See RFC 1035 for character set restrictions. 93 | 94 | * boot_file_size 95 | RFC code : 13 96 | Type : 16-bits (unsigned integer) 97 | This option specifies the length in 512-octet blocks of the default boot image for the client. 98 | 99 | * merit_dump_file 100 | RFC code : 14 101 | Type : String 102 | 103 | This option specifies the path-name of a file to which the client's core image should be dumped in the event the client crashes. The path is formatted as a character string consisting of characters from the NVT ASCII character set. 104 | 105 | * domain_name 106 | RFC code : 15 107 | Type : String 108 | 109 | This option specifies the domain name that client should use when resolving hostnames via the Domain Name System. 110 | 111 | 112 | * swap_server 113 | RFC code : 16 114 | Type : Single IP 115 | 116 | This specifies the IP address of the client's swap server. 117 | 118 | * root_path 119 | RFC code : 17 120 | Type : String 121 | 122 | This option specifies the path-name that contains the client's root disk. The path is formatted as a character string consisting of characters from the NVT ASCII character set. 123 | 124 | * extensions_path 125 | RFC code : 18 126 | Type : String 127 | 128 | A string to specify a file, retrievable via TFTP, which contains information which can be interpreted in the same way as the 64-octet vendor-extension field within the BOOTP response, with the following exceptions: 129 | - the length of the file is unconstrained; 130 | - all references to Tag 18 (i.e., instances of the BOOTP Extensions Path field) within the file are ignored. 131 | 132 | IP Layer Parameters per Host 133 | ============================ 134 | 135 | This section details the options that affect the operation of the IP layer on a per-host basis. 136 | 137 | * ip_forwarding 138 | RFC code : 19 139 | Type : Bool 140 | 141 | This option specifies whether the client should configure its IP layer for packet forwarding. A value of 0 means disable IP forwarding, and a value of 1 means enable IP forwarding. 142 | 143 | 144 | * nonlocal_source_routing 145 | RFC code : 20 146 | Type : Bool 147 | 148 | This option specifies whether the client should configure its IP layer to allow forwarding of datagrams with non-local source routes. A value of 0 means disallow forwarding of such datagrams, and a value of 1 means allow forwarding. 149 | 150 | * policy_filter 151 | RFC code : 21 152 | Type : Special - Multiple IP/Mask 153 | 154 | This option specifies policy filters for non-local source routing. The filters consist of a list of IP addresses and masks which specify destination/mask pairs with which to filter incoming source routes. Any source routed datagram whose next-hop address does not match one of the filters should be discarded by the client. The minimum length of this option is 8, and the length MUST be a multiple of 8. 155 | 156 | * maximum_datagram_reassembly_size 157 | RFC code : 22 158 | Type : 16-bits 159 | 160 | This option specifies the maximum size datagram that the client should be prepared to reassemble. The size is specified as a 16-bit unsigned integer. The minimum value legal value is 576. 161 | 162 | * default_ip_time-to-live 163 | RFC code : 23 164 | Type : 8-bits unsigned int 165 | 166 | This option specifies the default time-to-live that the client should use on outgoing datagrams. The TTL is specified as an octet with a value between 1 and 255. 167 | 168 | * path_mtu_aging_timeout 169 | RFC code : 24 170 | Type : 32-bits unsigned int 171 | 172 | 173 | This option specifies the timeout (in seconds) to use when aging Path MTU values discovered by the mechanism defined in RFC 1191 [12]. The timeout is specified as a 32-bit unsigned integer. 174 | 175 | * path_mtu_plateau_table 176 | RFC code : 25 177 | Type : 16-bits unsigned integer list 178 | 179 | This option specifies a table of MTU sizes to use when performing Path MTU Discovery as defined in RFC 1191. The table is formatted as a list of 16-bit unsigned integers, ordered from smallest to largest. The minimum MTU value cannot be smaller than 68. 180 | 181 | 182 | IP Layer Parameters per Interface 183 | ================================= 184 | 185 | This section details the options that affect the operation of the IP layer on a per-interface basis. It is expected that a client can issue multiple requests, one per interface, in order to configure interfaces with their specific parameters. 186 | 187 | * Interface MTU Option 188 | RFC code : 26 189 | Type : 16-bit unsigned integer 190 | 191 | This option specifies the MTU to use on this interface. The minimum legal value for the MTU is 68. 192 | 193 | * all_subnets_are_local 194 | RFC code : 27 195 | Type : Bool 196 | 197 | This option specifies whether or not the client may assume that all subnets of the IP network to which the client is connected use the same MTU as the subnet of that network to which the client is directly connected. A value of 1 indicates that all subnets share the same MTU. A value of 0 means that the client should assume that some subnets of the directly connected network may have smaller MTUs. 198 | 199 | * broadcast_address 200 | RFC code : 28 201 | Type : Single IP 202 | 203 | This option specifies the broadcast address in use on the client's subnet. 204 | 205 | * perform_mask_discovery 206 | RFC code : 29 207 | Type : Bool 208 | 209 | This option specifies whether or not the client should perform subnet mask discovery using ICMP. A value of 0 indicates that the client should not perform mask discovery. A value of 1 means that the client should perform mask discovery. 210 | 211 | * mask_supplier 212 | RFC code : 30 213 | Type : Bool 214 | 215 | This option specifies whether or not the client should respond to subnet mask requests using ICMP. A value of 0 indicates that the client should not respond. A value of 1 means that the client should respond. 216 | 217 | * perform_router_discovery 218 | RFC code : 31 219 | Type : Bool 220 | 221 | This option specifies whether or not the client should solicit routers using the Router Discovery mechanism defined in RFC 1256. A value of 0 indicates that the client should not perform router discovery. A value of 1 means that the client should perform router discovery. 222 | 223 | * router_solicitation_address 224 | RFC code : 32 225 | Type : Single IP 226 | 227 | This option specifies the address to which the client should transmit router solicitation requests. 228 | * static_route 229 | RFC code : 33 230 | Type : Special - Multiple of 2 IP. 231 | 232 | This option specifies a list of static routes that the client should install in its routing cache. If multiple routes to the same destination are specified, they are listed in descending order of priority. 233 | 234 | The routes consist of a list of IP address pairs. The first address is the destination address, and the second address is the router for the destination. 235 | 236 | The default route (0.0.0.0) is an illegal destination for a static route. 237 | 238 | 239 | Link Layer Parameters per Interface 240 | =================================== 241 | This section lists the options that affect the operation of the data link layer on a per-interface basis. 242 | 243 | * trailer_encapsulation 244 | RFC code : 34 245 | Type : Bool 246 | 247 | This option specifies whether or not the client should negotiate the use of trailers (RFC 893) when using the ARP protocol. A value of 0 indicates that the client should not attempt to use trailers. A value of 1 means that the client should attempt to use trailers. 248 | 249 | * arp_cache_timeout 250 | RFC code : 35 251 | Type : 32-bits unsigned int 252 | 253 | This option specifies the timeout in seconds for ARP cache entries. The time is specified as a 32-bit unsigned integer. 254 | 255 | * ethernet_encapsulation 256 | RFC code : 36 257 | Type : Bool 258 | 259 | This option specifies whether or not the client should use Ethernet Version 2 (RFC 894) or IEEE 802.3 (RFC 1042) encapsulation if the interface is an Ethernet. A value of 0 indicates that the client should use RFC 894 encapsulation. A value of 1 means that the client should use RFC 1042 encapsulation. 260 | 261 | TCP Parameters 262 | ============== 263 | This section lists the options that affect the operation of the TCP layer on a per-interface basis. 264 | 265 | * tcp_default_ttl 266 | RFC code : 37 267 | Type : 8-bits unsigned integer 268 | 269 | 270 | This option specifies the default TTL that the client should use when 271 | sending TCP segments. The minimum value is 1. 272 | 273 | 274 | * tcp_keepalive_interval 275 | RFC code : 38 276 | Type : 32-bits unsigned integer 277 | 278 | This option specifies the interval (in seconds) that the client TCP should wait before sending a keepalive message on a TCP connection. A value of zero indicates that the client should not generate keepalive messages on connections unless specifically requested by an application. 279 | 280 | * tcp_keepalive_garbage 281 | RFC code : 39 282 | Type : Bool 283 | 284 | This option specifies the whether or not the client should send TCP keepalive messages with a octet of garbage for compatibility with older implementations. A value of 0 indicates that a garbage octet should not be sent. A value of 1 indicates that a garbage octet should be sent. 285 | 286 | 287 | Application and Service Parameters 288 | ================================== 289 | This section details some miscellaneous options used to configure miscellaneous applications and services. 290 | 291 | * nis_domain 292 | RFC code : 40 293 | Type : String 294 | 295 | This option specifies the name of the client's NIS [17] domain. The domain is formatted as a character string consisting of characters from the NVT ASCII character set. 296 | 297 | * nis_servers 298 | RFC code : 41 299 | Type : Multiple IP 300 | 301 | This option specifies a list of IP addresses indicating NIS servers available to the client. Servers SHOULD be listed in order of preference. 302 | 303 | * ntp_servers 304 | RFC code : 42 305 | Type : Multiple IP 306 | 307 | This option specifies a list of IP addresses indicating NTP servers available to the client. Servers SHOULD be listed in order of preference. 308 | 309 | 310 | * vendor_specific_information 311 | RFC code : 43 312 | Type : Special - n-octet 313 | 314 | This option is used by clients and servers to exchange vendor-specific information. The information is an opaque object of N octets, presumably interpreted by vendor-specific code on the clients and servers. The definition of this information is vendor specific. The vendor is indicated in the vendor class identifier option. Servers not equipped to interpret the vendor-specific information sent by a client MUST ignore it (although it may be reported). Clients which do not receive desired vendor-specific information SHOULD make an attempt to operate without it, although they may do so (and announce they are doing so) in a degraded mode. 315 | 316 | If a vendor potentially encodes more than one item of information in this option, then the vendor SHOULD encode the option using "Encapsulated vendor-specific options" as described below: 317 | 318 | The Encapsulated vendor-specific options field SHOULD be encoded as a sequence of code/length/value fields of identical syntax to the DHCP options field with the following exceptions: 319 | * There SHOULD NOT be a "magic cookie" field in the encapsulated vendor-specific extensions field. 320 | * Codes other than 0 or 255 MAY be redefined by the vendor within the encapsulated vendor-specific extensions field, but SHOULD conform to the tag-length-value syntax defined in section 2. 321 | * Code 255 (END), if present, signifies the end of the encapsulated vendor extensions, not the end of the vendor extensions field. If no code 255 is present, then the end of the enclosing vendor-specific information field is taken as the end of the encapsulated vendor-specific extensions field. 322 | 323 | * nbns 324 | RFC code : 44 325 | Type : Multiple IP 326 | 327 | The NetBIOS name server (NBNS) option specifies a list of RFC 1001/1002 NBNS name servers listed in order of preference. 328 | 329 | * nbdd 330 | RFC code : 45 331 | Type : Multiple IP 332 | 333 | The NetBIOS datagram distribution server (NBDD) option specifies a list of RFC 1001/1002 NBDD servers listed in order of preference. 334 | 335 | * nb_node_type 336 | RFC code : 46 337 | Type : special - one octet 338 | 339 | The NetBIOS node type option allows NetBIOS over TCP/IP clients which are configurable to be configured as described in RFC 1001/1002. The value is specified as a single octet which identifies the client type as follows: 340 | 341 | Value Node Type 342 | ----- --------- 343 | 0x1 B-node 344 | 0x2 P-node 345 | 0x4 M-node 346 | 0x8 H-node 347 | 348 | In the above chart, the notation '0x' indicates a number in base-16 (hexadecimal). 349 | 350 | * nb_scope 351 | RFC code :47 352 | Type : Special - String 353 | 354 | 355 | The NetBIOS scope option specifies the NetBIOS over TCP/IP scope 356 | parameter for the client as specified in RFC 1001/1002. 357 | 358 | * x_window_system_font_server 359 | RFC code : 48 360 | Type : Multiple IP 361 | 362 | This option specifies a list of X Window System [21] Font servers available to the client. Servers SHOULD be listed in order of preference. 363 | 364 | The code for this option is 48. The minimum length of this option is 4 octets, and the length MUST be a multiple of 4. 365 | 366 | * x_window_system_display_manager 367 | RFC code : 49 368 | Type : Multiple IP 369 | 370 | This option specifies a list of IP addresses of systems that are running the X Window System Display Manager and are available to the client. 371 | 372 | Addresses SHOULD be listed in order of preference. 373 | 374 | * nis+_domain 375 | RFC code : 64 376 | Type : String 377 | 378 | This option specifies the name of the client's NIS+ [17] domain. The domain is formatted as a character string consisting of characters from the NVT ASCII character set. 379 | 380 | * nis+_servers 381 | RFC code : 65 382 | Type : Multiple IP 383 | 384 | This option specifies a list of IP addresses indicating NIS+ servers available to the client. Servers SHOULD be listed in order of preference. 385 | 386 | * mobile_ip_home_agent 387 | RFC code : 68 388 | Type : Special - Multiple IP 389 | 390 | This option specifies a list of IP addresses indicating mobile IP home agents available to the client. Agents SHOULD be listed in order of preference. Its minimum length is 0 (indicating no home agents are available). 391 | 392 | * smtp_server 393 | RFC code : 69 394 | Type : Multiple IP 395 | 396 | The SMTP server option specifies a list of SMTP servers available to the client. Servers SHOULD be listed in order of preference. 397 | 398 | * pop3_server 399 | RFC code : 70 400 | Type : Multiple IP 401 | 402 | The POP3 server option specifies a list of POP3 available to the client. Servers SHOULD be listed in order of preference. 403 | 404 | * nntp_server 405 | RFC code : 71 406 | Type : Multiple IP 407 | 408 | The NNTP server option specifies a list of NNTP available to the client. Servers SHOULD be listed in order of preference. 409 | 410 | * default_www_server 411 | RFC code : 72 412 | Type : Multiple IP 413 | 414 | The WWW server option specifies a list of WWW available to the client. Servers SHOULD be listed in order of preference. 415 | 416 | * default_finger_server 417 | RFC code : 73 418 | Type : Multiple IP 419 | 420 | The Finger server option specifies a list of Finger available to the client. Servers SHOULD be listed in order of preference. 421 | 422 | * default_irc_server 423 | RFC code : 74 424 | Type : Multiple IP 425 | 426 | The IRC server option specifies a list of IRC available to the client. Servers SHOULD be listed in order of preference. 427 | 428 | * streettalk_server 429 | RFC code : 75 430 | Type : Multiple IP 431 | 432 | The StreetTalk server option specifies a list of StreetTalk servers available to the client. Servers SHOULD be listed in order of preference. 433 | 434 | * streettalk_directory_assistance_server 435 | RFC code : 76 436 | Type : Multiple IP 437 | 438 | The StreetTalk Directory Assistance (STDA) server option specifies a list of STDA servers available to the client. Servers SHOULD be listed in order of preference. 439 | 440 | 441 | 9. DHCP Extensions 442 | ================== 443 | 444 | This section details the options that are specific to DHCP. 445 | 446 | * requested_ip_address 447 | RFC code : 50 448 | Type : Single IP 449 | 450 | This option is used in a client request (DHCPDISCOVER) to allow the client to request that a particular IP address be assigned. 451 | 452 | * ip_address_lease_time 453 | RFC code : 51 454 | Type : 32-bits unsigned integer 455 | 456 | This option is used in a client request (DHCPDISCOVER or DHCPREQUEST) to allow the client to request a lease time for the IP address. In a server reply (DHCPOFFER), a DHCP server uses this option to specify the lease time it is willing to offer. The time is in units of seconds. 457 | 458 | * option_overload 459 | RFC code : 52 460 | Type : 8-bit 461 | 462 | Warning : Do not use. This option will be automagically managed by the pydhcplib. 463 | 464 | This option is used to indicate that the DHCP 'sname' or 'file' fields are being overloaded by using them to carry DHCP options. A DHCP server inserts this option if the returned parameters will exceed the usual space allotted for options. 465 | 466 | If this option is present, the client interprets the specified additional fields after it concludes interpretation of the standard option fields. 467 | 468 | Legal values for this option are: 469 | 470 | Value Meaning 471 | ----- -------- 472 | 1 the 'file' field is used to hold options 473 | 2 the 'sname' field is used to hold options 474 | 3 both fields are used to hold options 475 | 476 | * tftp_server_name 477 | RFC code : 66 478 | Type : String 479 | 480 | This option is used to identify a TFTP server when the 'sname' field in the DHCP header has been used for DHCP options. 481 | 482 | * bootfile_name 483 | RFC code : 67 484 | Type : String 485 | 486 | This option is used to identify a bootfile when the 'file' field in the DHCP header has been used for DHCP options. 487 | 488 | * dhcp_message_type 489 | RFC code : 53 490 | Type : Special - 8-bits 491 | 492 | This option is used to convey the type of the DHCP message. 493 | Legal values for this option are: 494 | 495 | Value Message Type 496 | ----- ------------ 497 | 1 DHCPDISCOVER 498 | 2 DHCPOFFER 499 | 3 DHCPREQUEST 500 | 4 DHCPDECLINE 501 | 5 DHCPACK 502 | 6 DHCPNAK 503 | 7 DHCPRELEASE 504 | 8 DHCPINFORM 505 | 506 | * server_identifier 507 | RFC code : 54 508 | Type : Single IP 509 | 510 | This option is used in DHCPOFFER and DHCPREQUEST messages, and may optionally be included in the DHCPACK and DHCPNAK messages. DHCP servers include this option in the DHCPOFFER in order to allow the client to distinguish between lease offers. DHCP clients use the contents of the 'server identifier' field as the destination address for any DHCP messages unicast to the DHCP server. DHCP clients also indicate which of several lease offers is being accepted by including this option in a DHCPREQUEST message. The identifier is the IP address of the selected server. 511 | 512 | * Parameter Request List 513 | RFC code : 55 514 | Type : Special - N octets 515 | 516 | This option is used by a DHCP client to request values for specified configuration parameters. The list of requested parameters is specified as n octets, where each octet is a valid DHCP option code as defined in this document. 517 | 518 | The client MAY list the options in order of preference. The DHCP server is not required to return the options in the requested order, but MUST try to insert the requested options in the order requested by the client. 519 | 520 | * message 521 | RFC code : 56 522 | Type : String 523 | 524 | This option is used by a DHCP server to provide an error message to a DHCP client in a DHCPNAK message in the event of a failure. A client may use this option in a DHCPDECLINE message to indicate the why the client declined the offered parameters. The message consists of N octets of NVT ASCII text, which the client may display on an available output device. 525 | 526 | * maximum_dhcp_message_size 527 | RFC code : 57 528 | Type : 16-bits unsigned integer 529 | 530 | This option specifies the maximum length DHCP message that it is willing to accept. The length is specified as an unsigned 16-bit integer. A client may use the maximum DHCP message size option in DHCPDISCOVER or DHCPREQUEST messages, but should not use the option in DHCPDECLINE messages. 531 | The minimum legal value is 576 octets. 532 | 533 | * renewal_time_value 534 | RFC code : 58 535 | Type : 32-bits unsigned integer 536 | 537 | This option specifies the time interval from address assignment until the client transitions to the RENEWING state. 538 | 539 | The value is in units of seconds, and is specified as a 32-bit unsigned integer. 540 | 541 | * rebinding_time_value 542 | RFC code : 59 543 | Type : 32-bits unsigned integer 544 | 545 | This option specifies the time interval from address assignment until the client transitions to the REBINDING state. 546 | 547 | * vendor_class_identifier 548 | RFC code : 60 549 | Type : String 550 | 551 | This option is used by DHCP clients to optionally identify the vendor type and configuration of a DHCP client. The information is a string of n octets, interpreted by servers. Vendors may choose to define specific vendor class identifiers to convey particular configuration or other identification information about a client. For example, the identifier may encode the client's hardware configuration. Servers not equipped to interpret the class-specific information sent by a client MUST ignore it (although it may be reported). Servers that respond SHOULD only use option 43 to return the vendor-specific information to the client. 552 | 553 | * client_identifier 554 | RFC code : 61 555 | Type : Special 556 | 557 | This option is used by DHCP clients to specify their unique identifier. DHCP servers use this value to index their database of address bindings. This value is expected to be unique for all clients in an administrative domain. 558 | 559 | Identifiers SHOULD be treated as opaque objects by DHCP servers. 560 | 561 | The client identifier MAY consist of type-value pairs similar to the 'htype'/'chaddr' fields. For instance, it MAY consist of a hardware type and hardware address. In this case the type field SHOULD be one of the ARP hardware types defined in STD2. A hardware type of 0 (zero) should be used when the value field contains an identifier other than a hardware address (e.g. a fully qualified domain name). 562 | 563 | For correct identification of clients, each client's client-identifier MUST be unique among the client-identifiers used on the subnet to which the client is attached. Vendors and system administrators are responsible for choosing client-identifiers that meet this requirement for uniqueness. 564 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------