pax_global_header00006660000000000000000000000064145434037240014520gustar00rootroot0000000000000052 comment=0f12bddf6a877b28db1d93492ed4554a88922cec adasockets-v1.14/000077500000000000000000000000001454340372400137545ustar00rootroot00000000000000adasockets-v1.14/.builds/000077500000000000000000000000001454340372400153145ustar00rootroot00000000000000adasockets-v1.14/.builds/archlinux-test-build.yml000066400000000000000000000004421454340372400221060ustar00rootroot00000000000000image: archlinux arch: x86_64 packages: - gcc-ada - autoconf - automake - libtool - autogen - texinfo - texlive-basic - texlive-plaingeneric - make sources: - https://git.sr.ht/~rfc1149/adasockets tasks: - test-build: | cd adasockets support/test-build.sh adasockets-v1.14/.builds/archlinux.yml000066400000000000000000000007111454340372400200330ustar00rootroot00000000000000image: archlinux arch: x86_64 packages: - gcc-ada - autoconf - automake - libtool - autogen - texinfo - texlive-basic - texlive-plaingeneric - make sources: - https://git.sr.ht/~rfc1149/adasockets tasks: - autoreconf: | cd adasockets autoreconf -fvi - configure: | cd adasockets ./configure --enable-maintainer-mode - build: | cd adasockets make - test: | cd adasockets make check adasockets-v1.14/.builds/debian-stable.yml000066400000000000000000000006411454340372400205320ustar00rootroot00000000000000image: debian/stable arch: amd64 packages: - gnat - autoconf - automake - libtool - autogen - texinfo - texlive sources: - https://git.sr.ht/~rfc1149/adasockets tasks: - autoreconf: | cd adasockets autoreconf -fvi - configure: | cd adasockets ./configure --enable-maintainer-mode - build: | cd adasockets make - test: | cd adasockets make check adasockets-v1.14/.builds/nixos-flake.yml000066400000000000000000000002511454340372400202550ustar00rootroot00000000000000image: nixos/unstable arch: x86_64 environment: NIX_CONFIG: "experimental-features = nix-command flakes" tasks: - build-flake: | cd adasockets nix build adasockets-v1.14/.envrc000066400000000000000000000000121454340372400150630ustar00rootroot00000000000000use flake adasockets-v1.14/.gitignore000066400000000000000000000033721454340372400157510ustar00rootroot00000000000000*~ Makefile.in Makefile aclocal.m4 autom4te.cache/ configure src/config.h.in support/config.guess support/config.sub support/install-sh support/libtool.m4 support/ltmain.sh support/ltoptions.m4 support/ltsugar.m4 support/ltversion.m4 support/lt~obsolete.m4 support/mdate-sh support/missing support/compile support/depcomp support/texinfo.tex Makefile Makefile.in aclocal.m4 autom4te.cache/output.0 autom4te.cache/output.1 autom4te.cache/output.2 autom4te.cache/requests autom4te.cache/traces.0 autom4te.cache/traces.1 autom4te.cache/traces.2 config.log config.status doc/Makefile doc/Makefile.in examples/Makefile examples/Makefile.in libtool man/Makefile man/Makefile.in src/Makefile src/Makefile.in src/config.h src/config.h.in src/sockets-link.ads src/sockets-types.ads src/stamp-h1 support/config.guess support/config.sub support/install-sh support/libtool.m4 support/ltmain.sh support/ltoptions.m4 support/ltsugar.m4 support/ltversion.m4 support/lt~obsolete.m4 support/mdate-sh support/missing support/test-driver b~*.* *.o *.lo *.ali *.la .*.swp doc/adasockets.aux doc/adasockets.cp doc/adasockets.cps doc/adasockets.ct doc/adasockets.dvi doc/adasockets.ex doc/adasockets.fn doc/adasockets.info doc/adasockets.ky doc/adasockets.log doc/adasockets.pdf doc/adasockets.pg doc/adasockets.toc doc/adasockets.tp doc/adasockets.vr doc/sockets-multicast.texi doc/sockets-naming.texi doc/sockets.texi doc/stamp-vti doc/version.texi examples/listener examples/multi examples/stream_listener examples/stream_sender examples/tcprelay src/constants_nodef src/sockets-constants.ads src/sockets-thin.ads src/split src/.libs ChangeLog adasockets-*.tar.gz src/adasockets.pc tests/multicast_test tests/value tests/*.log tests/*.trs lib/ /INSTALL /README /src/constants /src/constants-inc.c .direnv adasockets-v1.14/.pre-commit-config.yaml000066400000000000000000000012101454340372400202270ustar00rootroot00000000000000default_language_version: python: python3 # Defaults to python2, so override it. repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: check-added-large-files - id: check-byte-order-marker - id: check-case-conflict - id: check-merge-conflict - id: check-symlinks - id: check-yaml - id: detect-private-key - id: end-of-file-fixer - id: forbid-submodules - id: mixed-line-ending args: ['--fix=lf'] - id: trailing-whitespace - repo: https://github.com/codespell-project/codespell rev: v2.2.2 hooks: - id: codespell adasockets-v1.14/AUTHORS.md000066400000000000000000000002031454340372400154160ustar00rootroot00000000000000AdaSockets has been written by Samuel Tardieu with the contribution of many users. WWW: http://www.rfc1149.net/ adasockets-v1.14/COPYING000066400000000000000000000431271454340372400150160ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the 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 a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 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. 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 convey 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) 19yy 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This 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 Library General Public License instead of this License. adasockets-v1.14/GMGPL000066400000000000000000000020341454340372400145440ustar00rootroot00000000000000AdaSockets is free software; you can redistribute it and/or modify it under terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. AdaSockets 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 distributed with AdaSockets; see file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, if other files instantiate generics from this unit, or you link this unit with other files to produce an executable, this unit does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Public License. adasockets-v1.14/INSTALL.md000066400000000000000000000026061454340372400154100ustar00rootroot00000000000000# Installing AdaSockets ## Building on Unix or Cygwin/Windows ``` % ./configure --prefix= % make install ``` This will build and install this software under **`/lib/adasockets`. The `adasockets-config` program and its associated man page will be installed respectively under **`/bin` and **`/man/`. In the examples subdirectory, you will find an example called `tcprelay` which illustrates how this package can be used. GNU make is not strictly necessary but is recommended. It is needed if you want to rebuild the documentation. You need to install the autogen software if you want to rebuild the documentation. You also need the autotools if you plan on modifying the AdaSockets build structure. ## Building the development version If you build from the current development version (for example the git head version), you need to regenerate the configure file: ``` % autoreconf -fiv ``` This will invoke `autoconf`, `automake` and `libtool` (which all must be installed) with the right arguments. ## Building on OpenVMS ``` % make ``` GNU make must be available as well as the DEC C compiler. If no C compiler is available on your system, the file `sockets-constants.ads` in the `contrib/vms` directory must be copied into the `vms` one. This file is given as is and has not been tested on other host than the one used to port AdaSockets. adasockets-v1.14/Makefile.VMS000066400000000000000000000006171454340372400160640ustar00rootroot00000000000000# Main Makefile.VMS # # $Revision$ # # # This file is part of adasockets port on OpenVMS # .PHONY: all clean distclean .DEFAULT: all all: make "-C" [.vms] all make "-C" [.src] all make "-C" [.examples] all clean: make "-C" [.vms] clean make "-C" [.src] clean make "-C" [.examples] clean distclean: make "-C" [.vms] distclean make "-C" [.src] distclean make "-C" [.examples] distclean adasockets-v1.14/Makefile.am000066400000000000000000000021341454340372400160100ustar00rootroot00000000000000AUTOMAKE_OPTIONS = foreign no-dependencies ACLOCAL_AMFLAGS = -I support AUTOHEADER_AMFLAGS = -l support SUBDIRS = src man $(SUBDIR_DOC) $(SUBDIR_EXAMPLES) $(SUBDIR_TESTS) if BUILD_DOC SUBDIR_DOC = doc else SUBDIR_DOC = endif if BUILD_EXAMPLES SUBDIR_EXAMPLES = examples else SUBDIR_EXAMPLES = endif if BUILD_TESTS SUBDIR_TESTS = tests else SUBDIR_TESTS = endif EXTRA_DIST = AUTHORS.md COPYING GMGPL README.md README-RTEMS.md INSTALL.md \ rtems/ChangeLog rtems/create_constants_c.sh rtems/Makefile.RTEMS \ rtems/README rtems/rtems_main.c rtems/sockets-constants-rtems.ads \ ChangeLog Makefile.VMS \ contrib/vms/README contrib/vms/sockets-constants.ads \ contrib/win32/adasockets/build.bat contrib/win32/adasockets/clean.bat \ contrib/win32/adasockets/Readme.txt contrib/win32/distr \ contrib/win32/Readme.txt \ src/adasockets.gpr.in support/adacompiler \ vms/constants.c_pre vms/constants.list vms/create_constants_ads.com \ vms/create_constants_c.com vms/Makefile.VMS CLEANFILES = ChangeLog ChangeLog: never (cd ${srcdir} && support/git2cl) > ChangeLog never:: version: @echo $(PACKAGE)-$(VERSION) adasockets-v1.14/README-RTEMS.md000066400000000000000000000043211454340372400161230ustar00rootroot00000000000000# Building AdaSockets to target RTEMS. Prerequisites ============= Build and install a working GNAT/RTEMS toolset and a BSP. Make sure networking and POSIX are enabled. Detailed instructions are available online in the RTEMS Wiki at: http://www.rtems.org/wiki/index.php/RTEMSAda Run at least one sample from the RTEMS build (e.g. `hello.exe` or `sample.exe`) to confirm that RTEMS itself was properly built. Build and run the RTEMS `hello_world_ada` from the `ada-examples` package using your GNAT/RTEMS development environment. If everything is working at this point, then you are ready to build AdaSockets. Generate `sockets-constants.ads` ================================ Subdirectory: `rtems` We will use the RTEMS you installed to build and run a program called `constants.exe`. The output of this program needs to be saved as `sockets-constants.ads`. To compile this program use the `Makefile.RTEMS`. ``` % RTEMS_MAKEFILE_PATH=install_path_of_BSP make -f Makefile.RTEMS ``` Then run the program `o-optimize/constants.exe` on the target hardware. Your saved target board output may end up with DOS style CR/LF's. Run `dos2unix` on the file to get it back to Unix style. There is a version of this file generated using `psim` using a pre-4.8 CVS snapshot of RTEMS which should work on any target. You can use this but you would be safer to generate your own. Consider it an example of how it should look when it works. Building AdaSockets =================== Subdirectory: `src` Now that you have a `sockets-constants.ads`, we can build the AdaSockets library. `Makefile.adasockets` is provided for this step: ``` % RTEMS_MAKEFILE_PATH=install_patch_of_BSP make -f Makefile.RTEMS ``` After the library is compiled, it may be installed using the following: ``` % RTEMS_MAKEFILE_PATH=install_patch_of_BSP make -f Makefile.RTEMS install ``` Building examples ================= Subdirectory: `examples` After building the sockets package, build the examples the same way ``` % RTEMS_MAKEFILE_PATH=install_patch_of_BSP make -f Makefile.RTEMS ``` BUGS: - stream_listener core dumps if the endian of the `stream_sender` is not the same as the listener. - multicast does not yet work. This is probably an RTEMS issue. adasockets-v1.14/README.md000066400000000000000000000044071454340372400152400ustar00rootroot00000000000000AdaSockets is a medium binding (it is not a thin binding because it uses Ada types and not a thick binding because you have the same subprogram names as in C) for using BSD-style sockets in Ada. Since the original release, I have been adding multicast and fixed some bugs. However, it is likely that others remain. To use AdaSockets with gnatmake once installed, type: $ gnatmake $(adasockets-config) ... The `adasockets-config` part will add the correct options to gnatmake command line. ## License AdaSockets is distributed under the GNAT-modified General Public License (GMGPL): > AdaSockets is free software; you can redistribute it and/or modify it > under terms of the GNU General Public License as published by the Free > Software Foundation; either version 2, or (at your option) any later > version. AdaSockets 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 distributed with AdaSockets; > see file COPYING. If not, write to the Free Software Foundation, 59 > Temple Place - Suite 330, Boston, MA 02111-1307, USA. > > As a special exception, if other files instantiate generics from this > unit, or you link this unit with other files to produce an executable, > this unit does not by itself cause the resulting executable to be > covered by the GNU General Public License. This exception does not > however invalidate any other reasons why the executable file might be > covered by the GNU Public License. ## Contributing The main page for this software is located at https://rfc1149.net/devel/adasockets The code is [hosted on sourcehut](https://sr.ht/~rfc1149/adasockets/). New versions of AdaSockets are announced on the [~rfc1149/adasockets-announce@lists.sr.ht](https://lists.sr.ht/~rfc1149/adasockets-announce) mailing-list. Defects, questions, and patches (which are welcomed) must be sent to the [~rfc1149/adasockets-devel@lists.sr.ht](https://lists.sr.ht/~rfc1149/adasockets-devel) mailing-list. Note that you neither need to subscribe to this mailing-list nor create an account on sourcehut to report bugs or send patches. adasockets-v1.14/configure.ac000066400000000000000000000111321454340372400162400ustar00rootroot00000000000000AC_INIT([adasockets],[1.14]) AC_CONFIG_SRCDIR([src/sockets.ads]) AC_CONFIG_AUX_DIR([support]) AC_CONFIG_MACRO_DIR([support]) AC_CONFIG_HEADERS(src/config.h) AM_INIT_AUTOMAKE # # Package description # AC_ARG_WITH([libversioninfo], [AS_HELP_STRING([--with-libversion=VSN], [Shared Object version for relocatable library [1:0:0]])], [LIBVERSIONINFO=$withval], [LIBVERSIONINFO=1:0:0]) AC_SUBST(LIBVERSIONINFO) # AC_ARG_WITH([adasrcinstalldir], [AS_HELP_STRING([--with-adasrcinstalldir=DIR], [Ada sources go under DIR/adasockets [LIBDIR]])], [ada_src_install_dir=$withval], [ada_src_install_dir='${libdir}']) AC_SUBST(ada_src_install_dir) # AC_ARG_WITH([aliinstalldir], [AS_HELP_STRING([--with-aliinstalldir=DIR], [Ada Lib Info go under DIR/adasockets [LIBDIR]])], [ali_install_dir=$withval], [ali_install_dir='${libdir}']) AC_SUBST(ali_install_dir) # AC_ARG_WITH([gprinstalldir], [AS_HELP_STRING([--with-gprinstalldir=DIR], [GPRBuild project goes under DIR [DATADIR/gpr]])], [gpr_install_dir=$withval], [gpr_install_dir='${datadir}/gpr']) AC_SUBST(gpr_install_dir) # LT_INIT # AC_CHECK_PROGS(AWK, [gnuawk gawk awk]) # # Check for maintainer mode # AC_ARG_VAR(ADAFLAGS,[Ada compiler flags]) AC_ARG_ENABLE(maintainer-mode, AS_HELP_STRING(--enable-maintainer-mode,turn on debugging options), [ADAFLAGS="-g -O2 -Wall -Werror -gnatag -gnatwa -gnatwe -gnatg $ADAFLAGS"], [ADAFLAGS="-O2 -gnatpng $ADAFLAGS"]) # # Check for documentation build and installation # AC_ARG_ENABLE(doc, AS_HELP_STRING(--disable-doc,do not build and install documentation), [case "${enableval}" in yes) doc=true ;; no) doc=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-doc) ;; esac],[doc=true]) AM_CONDITIONAL(BUILD_DOC, test x$doc = xtrue) # # Check for examples build and installation # AC_ARG_ENABLE(examples, AS_HELP_STRING(--disable-examples,do not build and install examples), [case "${enableval}" in yes) examples=true ;; no) examples=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-examples) ;; esac],[examples=true]) AM_CONDITIONAL(BUILD_EXAMPLES, test x$examples = xtrue) # # Check for tests build # AC_ARG_ENABLE(tests, AS_HELP_STRING(--disable-tests,do not build tests), [case "${enableval}" in yes) tests=true ;; no) tests=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-tests) ;; esac],[tests=true]) AM_CONDITIONAL(BUILD_TESTS, test x$tests = xtrue) # # Check for documentation software # AC_CHECK_PROG(GETDEFS, getdefs, getdefs) AC_CHECK_PROG(MAKEINFO, makeinfo, makeinfo) AC_CHECK_PROG(TEXI2PDF, texi2pdf, texi2pdf) # # Look for the C compiler # AC_PROG_CC # # Look for the Ada compiler # AC_CHECK_PROG([GNATMAKE], [gnatmake], [gnatmake]) if test -z "$GNATMAKE"; then AC_MSG_ERROR([unable to find gnatmake]) fi # # Libtool checks # LT_INIT # # Test for -lnsl, -lsocket and -lresolv # AC_CHECK_FUNC(gethostbyname,NSLNEEDED="-- ", AC_CHECK_LIB(nsl,gethostbyname,,NSLNEEDED="-- ")) AC_SUBST(NSLNEEDED) AC_CHECK_FUNC(connect,SOCKETNEEDED="-- ", AC_CHECK_LIB(socket,connect,,SOCKETNEEDED="-- ")) AC_SUBST(SOCKETNEEDED) AC_CHECK_FUNC(inet_aton,RESOLVNEEDED="-- ", AC_CHECK_LIB(resolv,inet_aton,,RESOLVNEEDED="-- ")) AC_SUBST(RESOLVNEEDED) # # Extra libraries # AC_ARG_WITH(extra-libs, [ --with-extra-libs=libs Add extra libraries when building a program], [EXTRA_LIBS="${withval}"]) AC_SUBST(EXTRA_LIBS) # # Header files # AC_CHECK_HEADERS([stdio.h sys/types.h sys/socket.h errno.h netdb.h stdlib.h]) AC_CHECK_HEADERS([netinet/in.h signal.h fcntl.h termio.h termios.h sys/file.h]) AC_CHECK_HEADERS([sys/ioctl.h netinet/tcp.h sys/systeminfo.h poll.h stropts.h]) AC_CHECK_HEADERS([sys/conf.h sys/param.h time.h windows.h string.h linux/sockios.h]) AC_CHECK_HEADERS(windows.h, [usewin32=true useunix=false], [usewin32=false useunix=true]) # # sa_len field ? # AC_CHECK_MEMBER(struct sockaddr.sa_len,[SA_LEN="" NO_SA_LEN="-- "],[SA_LEN="-- " NO_SA_LEN=""],[#include AC_SUBST(SA_LEN) AC_SUBST(NO_SA_LEN) #include ]) # # Conditional import for Win32 and substitution # AM_CONDITIONAL(WIN32, $usewin32) if $useunix; then WINNEEDED="-- " fi AC_SUBST(WINNEEDED) # # Output # AC_CONFIG_FILES([Makefile src/Makefile src/sockets-link.ads src/sockets-types.ads src/adasockets.pc man/Makefile examples/Makefile doc/Makefile tests/Makefile]) AC_OUTPUT adasockets-v1.14/contrib/000077500000000000000000000000001454340372400154145ustar00rootroot00000000000000adasockets-v1.14/contrib/vms/000077500000000000000000000000001454340372400162215ustar00rootroot00000000000000adasockets-v1.14/contrib/vms/README000066400000000000000000000003631454340372400171030ustar00rootroot00000000000000The file sockets-constants.ads is usually produced by compiling a small C program that dumps several network and system constants. However, as I assumed every body doesn't have a C compiler installed, I put here the file generated on my host. adasockets-v1.14/contrib/vms/sockets-constants.ads000066400000000000000000000071251454340372400224040ustar00rootroot00000000000000-- This file has been generated automatically by -- CREATE_CONSTANTS_ADS.COM. -- -- This file is part of adasockets port to OpenVMS -- package sockets.constants is Tcp_Nodelay : constant := 16#0001#; Af_Inet : constant := 16#0002#; Af_Unix : constant := 16#0001#; Sock_Stream : constant := 16#0001#; Sock_Dgram : constant := 16#0002#; Eintr : constant := 16#0004#; Eagain : constant := 16#000B#; Ewouldblock : constant := 16#0023#; Einprogress : constant := 16#0024#; Ealready : constant := 16#0025#; Eisconn : constant := 16#0038#; Econnrefused : constant := 16#003D#; Fndelay : constant := -1; Fasync : constant := -1; Fioasync : constant := -2147195267; F_Getfl : constant := -1; F_Setfl : constant := -1; F_Setown : constant := -1; Fiossaioown : constant := -1; So_Rcvbuf : constant := 16#1002#; So_Reuseaddr : constant := 16#0004#; So_Reuseport : constant := 16#0200#; Sol_Socket : constant := 16#FFFF#; Sigterm : constant := 16#000F#; Sigkill : constant := 16#0009#; O_Rdonly : constant := -1; O_Wronly : constant := -1; O_Rdwr : constant := 16#0002#; Host_Not_Found : constant := 16#0001#; Try_Again : constant := 16#0002#; No_Recovery : constant := 16#0003#; No_Data : constant := 16#0004#; No_Address : constant := 16#0004#; Pollin : constant := 16#00C7#; Pollpri : constant := 16#0008#; Pollout : constant := 16#0300#; Pollerr : constant := -1; Pollhup : constant := 16#0010#; Pollnval : constant := -1; I_Setsig : constant := -1; S_Rdnorm : constant := -1; S_Wrnorm : constant := -1; Ipproto_Ip : constant := 16#0000#; Ip_Add_Membership : constant := 16#000C#; Ip_Multicast_Loop : constant := 16#000B#; Ip_Multicast_Ttl : constant := 16#000A#; Ip_Drop_Membership : constant := 16#000D#; O_Nonblock : constant := 16#20000#; Msg_Peek : constant := 16#0002#; Fionbio : constant := -2147195266; Fionread : constant := 16#4004667F#; So_Sndbuf : constant := 16#1001#; Af_Inet6 : constant := -1; Ai_Addrconfig : constant := -1; Ai_All : constant := -1; Ai_Canonname : constant := -1; Ai_Default : constant := -1; Ai_Mask : constant := -1; Ai_Numerichost : constant := -1; Ai_Passive : constant := -1; Ai_V4mapped : constant := -1; Ai_V4mapped_Cfg : constant := -1; Ni_Dgram : constant := -1; Ni_Maxhost : constant := -1; Ni_Maxserv : constant := -1; Ni_Namereqd : constant := -1; Ni_Nofqdn : constant := -1; Ni_Numerichost : constant := -1; Ni_Numericserv : constant := -1; Ni_Withscopeid : constant := -1; Ipproto_Ipv6 : constant := -1; Ipv6_Unicast_Hops : constant := -1; Ipv6_Multicast_If : constant := -1; Ipv6_Multicast_Hops : constant := -1; Ipv6_Multicast_Loop : constant := -1; Ipv6_Join_Group : constant := -1; Ipv6_Leave_Group : constant := -1; end sockets.constants; adasockets-v1.14/contrib/win32/000077500000000000000000000000001454340372400163565ustar00rootroot00000000000000adasockets-v1.14/contrib/win32/Readme.txt000066400000000000000000000012421454340372400203130ustar00rootroot00000000000000This directory containts files to create a simple installation only for win32 platform. The users of the installation would not have to have any unix command tool for Windows to build the library. The shell script ./distr achives the subset of win32 sources with batch file for compilation to the adasockets.tgz archive. You should call it from the current directory. AdaSockets should be already maked under the Win32 platform as a regular process under the any unix command tools. For example cygwin http://cygwin.com/ ATTENTION: For the cygwin unit command tools. gcc should be used from GNAT installation, but make utility should be used from the cygwin installation.adasockets-v1.14/contrib/win32/adasockets/000077500000000000000000000000001454340372400204775ustar00rootroot00000000000000adasockets-v1.14/contrib/win32/adasockets/Readme.txt000066400000000000000000000002711454340372400224350ustar00rootroot00000000000000It is subset and spetial files of AdaSockets library for Win32 platforms. call the build.bat to build the library and examples. call the clean.bat to remove files created in build.adasockets-v1.14/contrib/win32/adasockets/build.bat000066400000000000000000000010471454340372400222700ustar00rootroot00000000000000echo with > tmp_make.adb echo sockets, >> tmp_make.adb echo sockets.multicast, >> tmp_make.adb echo sockets.stream_io, >> tmp_make.adb echo sockets.naming; >> tmp_make.adb echo procedure Tmp_Make is >> tmp_make.adb echo begin >> tmp_make.adb echo null; >> tmp_make.adb echo end; >> tmp_make.adb set ADA_OBJECTS_PATH= set ADA_INCLUDE_PATH= gnatmake -c -O2 tmp_make del tmp_make.* attrib +r *.ali cd examples gnatmake -I../ multi gnatmake -I../ stream_sender gnatmake -I../ stream_listener gnatmake -I../ tcprelay gnatmake -I../ listener adasockets-v1.14/contrib/win32/adasockets/clean.bat000066400000000000000000000000751454340372400222530ustar00rootroot00000000000000attrib -r *.ali del /S *.ali del /S *.o del examples\*.exeadasockets-v1.14/contrib/win32/distr000066400000000000000000000003151454340372400174250ustar00rootroot00000000000000#! /bin/sh cp ../../src/sockets*.ad? adasockets (if ! [ -e adasockets/examples ]; then mkdir adasockets/examples; fi) cp ../../examples/*.adb adasockets/examples/ tar czf adasockets.tgz adasockets/* adasockets-v1.14/doc/000077500000000000000000000000001454340372400145215ustar00rootroot00000000000000adasockets-v1.14/doc/Makefile.am000066400000000000000000000027711454340372400165640ustar00rootroot00000000000000AUTOMAKE_OPTIONS = info-in-builddir info_TEXINFOS = adasockets.texi adasockets_TEXINFOS = sockets.texi sockets-multicast.texi sockets-naming.texi version.texi ADADOC_ARGS = --subblock=arg=argname,argmode,argtype,argdefault,argdesc \ --subblock=ret=rettype,retdesc \ --subblock=exc=excname,excdesc \ --template=${srcdir}/adadoc DISTCLEANFILES = *.defs ${adasockets_TEXINFOS} stamp-vti CLEANFILES = adasockets.aux adasockets.cp adasockets.cps adasockets.fn adasockets.fns adasockets.info adasockets.log adasockets.toc EXTRA_DIST = adasockets.pdf \ ${info_TEXINFOS} ${adasockets_TEXINFOS} \ adadoc.tpl sockets.desc sockets-multicast.desc \ sockets-naming.desc docdir = ${prefix}/share/doc/adasockets doc_DATA = adasockets.pdf adasockets.info: ${srcdir}/adasockets.texi ${adasockets_TEXINFOS} ${MAKEINFO} --force --no-validate -I ${srcdir} \ ${srcdir}/adasockets.texi sockets.texi: ${srcdir}/sockets.desc ${srcdir}/adadoc.tpl ${GETDEFS} ${ADADOC_ARGS} \ --input="${srcdir}/sockets.desc" --base-name=sockets sockets-multicast.texi: ${srcdir}/sockets-multicast.desc ${srcdir}/adadoc.tpl ${GETDEFS} ${ADADOC_ARGS} \ --input="${srcdir}/sockets-multicast.desc" \ --base-name=sockets-multicast sockets-naming.texi: ${srcdir}/sockets-naming.desc ${srcdir}/adadoc.tpl ${GETDEFS} ${ADADOC_ARGS} \ --input="${srcdir}/sockets-naming.desc" --base-name=sockets-naming adasockets.pdf: ${srcdir}/adasockets.texi ${adasockets_TEXINFOS} -${TEXI2PDF} -I ${top_srcdir}/support --pdf ${srcdir}/adasockets.texi adasockets-v1.14/doc/adadoc.tpl000066400000000000000000000050421454340372400164560ustar00rootroot00000000000000[+ autogen5 template texi +][+ (define *args* #f) (define (end-args kind return) (let ((args *args*)) (set! *args* #f) (if (string=? kind "procedure") (if args ");" ";") (sprintf "%s@*@w{return %s;}" (if args ")" "") return)))) (define (format-arg name mode type default) (let ((prefix (if *args* "; " " (")) (mode-mark (if (string-ci=? "IN" mode) "" (sprintf " %s" mode))) (default-expr (if (string=? default "") "" (sprintf " := %s" default)))) (set! *args* #t) (sprintf "%s@w{@var{%s} :%s %s%s}" prefix name mode-mark type default-expr))) +][+ CASE (suffix) +][+ == texi +] [+ intro +] [+ FOR type +] @deftypefn [+ package +].[+ name +] type [+ name +] [+ IF discr +]([+ discr +]) [+ ENDIF +]is [+ def +]; [+ doc +] [+ IF (exist? "see") +]See also: [+ FOR see "," +]@ref{[+ see +]}[+ ENDFOR +]. [+ ENDIF +] @end deftypefn [+ ENDFOR +] @menu [+ FOR subprogram +]* [+ (let ((w (get "what")) (n (string-append (get "name") " (" (get "kind") ")"))) (sprintf (if (> (string-length n) 19) "%s\n %s" "%-21s %s") (string-append n "::") w)) +] [+ ENDFOR +]@end menu [+ FOR subprogram +] @node [+ name +] ([+ kind +]) @unnumberedsubsec [+ name +] ([+ kind +]) [+ FOR concept +]@cindex [+ concept +] [+ ENDFOR +] @table @sc @item Purpose [+ what +] @item Prototype @deftypefn [+ package +].[+ name +] [+ kind +] [+ name +][+ IF (exist? "arg") +][+ FOR arg +][+ (format-arg (get "argname") (get "argmode") (get "argtype") (get "argdefault")) +][+ ENDFOR +][+ (end-args (get "kind") (get "ret.rettype")) +][+ ENDIF +] @end deftypefn @fnindex [+ package +].[+ name +] [+ IF (exist? "arg") +] @item Parameters @multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} [+ FOR arg +]@item @var{[+ argname +]} @tab [+ argmode +] @tab [+ argdesc +] [+ ENDFOR +]@end multitable [+ ENDIF +][+ IF (exist? "ret") +] @item Return value [+ ret.retdesc +][+ ENDIF +] [+ IF doc +] @item Description [+ doc +] [+ ENDIF +] [+ IF (exist? "exc") +] @item Exceptions @multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} [+ FOR exc +]@item @code{[+ excname +]} @tab [+ excdesc +]@exindex [+ excname +] [+ ENDFOR +]@end multitable [+ FOR exc +] [+ ENDFOR +] [+ ENDIF +] [+ IF example +] @item Example @example [+ (out-push-new ".example") +][+ example +][+ (out-pop) +][+ `sed 's/^\\$ //' .example; rm -f .example` +] @end example [+ ENDIF +] [+ IF see +] @item See also [+ FOR see ",@*" +]@ref{[+ see +]}[+ ENDFOR +]. [+ ENDIF +] @end table [+ ENDFOR +] [+ ESAC +] adasockets-v1.14/doc/adasockets.texi000066400000000000000000000313141454340372400175370ustar00rootroot00000000000000\input texinfo @c -*-texinfo-*- @setfilename adasockets.info @settitle AdaSockets reference manual @setchapternewpage odd @include version.texi @ifinfo @dircategory Libraries @direntry * adasockets: (adasockets). AdaSockets reference manual @end direntry @end ifinfo @ifinfo Copyright @copyright{} 2002-2023 Samuel Tardieu Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. @ignore Permission is granted to process this file through TeX and print the results, provided the printed document carries a copying permission notice identical to this one except for the removal of this paragraph (this paragraph not being relevant to the printed manual). @end ignore Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions. @end ifinfo @titlepage @finalout @title AdaSockets reference manual @subtitle for AdaSockets version @value{VERSION} @subtitle @value{UPDATED} @author Samuel Tardieu @page @vskip 0pt plus 1filll Copyright @copyright{} 2002-2023 Samuel Tardieu Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions. @end titlepage @c New indices: constants (ct) and exceptions (ex) @defindex ct @defindex ex @syncodeindex ex cp @syncodeindex ct cp @syncodeindex vr cp @syncodeindex fn cp @syncodeindex tp cp @contents @c --------------------------------------------------------------- @node Top, What is AdaSockets?, (dir), (dir) @menu * What is AdaSockets?:: * Installing AdaSockets:: * Using AdaSockets:: * Sockets package:: * Sockets.Multicast package:: * Sockets.Naming package:: * Contributors:: * Resources on the Internet:: * Index:: @detailmenu --- The Detailed Node Listing --- Using AdaSockets * Compiling an Ada application:: * Setting up unicast sockets:: * Setting up multicast sockets:: * Sending and receiving data:: Sending and receiving data * Raw data manipulation:: * String-oriented exchanges:: @end detailmenu @end menu @node What is AdaSockets?, Installing AdaSockets, Top, Top @chapter What is AdaSockets? @cindex AdaSockets presentation @cindex Comparaison with @code{GNAT.Sockets} AdaSockets is a set of free software Ada packages allowing Ada programmers to use the so-called BSD sockets from their favourite programming language. AdaSockets has been designed and tested with the GNAT free software Ada compiler, but should be portable to other compilers quite easily. Starting from release 3.14, the GNAT compiler started to integrate a @code{GNAT.Sockets} package. However, this package is GNAT specific and contains at this time less features than AdaSockets. At some point, AdaSockets may use @code{GNAT.Sockets} as its underlying sockets structure. AdaSockets philosophy is to help the Ada programmer by providing easy-to-use objects. Special care has been taken to ensure that performances do however remain good. @node Installing AdaSockets, Using AdaSockets, What is AdaSockets?, Top @chapter Installing AdaSockets @cindex Installing AdaSockets Installing AdaSockets on a Unix or OpenVMS machine is as simple as typing a few commands. Once you got the latest version of AdaSockets (@pxref{Resources on the Internet}), uncompress and untar it and go to the top-level directory of the distribution. You must configure the AdaSockets distribution by using the @command{configure} command, such as in: @example ./configure --prefix=/users/sam/adasockets @end example If you want to install AdaSockets under the @file{/usr/local} hierarchy, you do not need to specify the @option{--prefix} option. Make sure you have write permission on the target directories. Once AdaSockets is configured, you can compile and install it by using the @command{make} command: @example make install @end example The GNU make program is recommended but not mandatory. On your system, it may be installed under the @command{gmake} name. @node Using AdaSockets, Sockets package, Installing AdaSockets, Top @chapter Using AdaSockets @menu * Compiling an Ada application:: * Setting up unicast sockets:: * Setting up multicast sockets:: * Sending and receiving data:: @end menu @node Compiling an Ada application, Setting up unicast sockets, Using AdaSockets, Using AdaSockets @section Compiling an Ada application AdaSockets comes with an @code{adasockets-config} application that can be used to retrieve installation parameters while using @code{gnatmake} to compile your Ada application. The @code{--cflags} parameters tells @code{adasockets-config} to output the path to the Ada packages sources, while @code{--libs} asks for the path to the Ada library. @example gnatmake `adasockets-config --cflags` mainprog -largs `adasockets-config --libs` @end example @node Setting up unicast sockets, Setting up multicast sockets, Compiling an Ada application, Using AdaSockets @section Setting up unicast sockets @cindex Unicast sockets @cindex Creating a unicast socket @cindex Creating a TCP socket @cindex Creating a UDP socket @cindex TCP socket @cindex UDP socket @cindex Creating a socket @tindex Socket_FD @findex Sockets.Socket @findex Socket Unicast sockets are used everywhere on the Internet, for surfing the web, sending electronic mails or accessing remote files. They come in two flavours: @table @asis @item TCP TCP is a connected mode, in which packets are sent in a reliable and ordered way. Everything sent at one end will eventually arrive in the same order at the other end, the underlying operating system takes care of retransmitting missing packets and reordering out-of-order ones. @item UDP UDP is a non-connected mode. A packet sent on a UDP socket may or may not arrive at the other end. This is a much lighter protocol when reliability is not needed as the operating system does not have to use large buffers to reorder packets. Also, this generates less traffic as no acknowledgments need to be sent by the kernels. @end table The package @code{Sockets} defines a @code{Socket_FD} tagged type. An instance of this type (or of any of its descendants) represents an incoming or outgoing socket. Two different kinds of sockets can be created: unicast (one-to-one) and multicast (many-to-many). @node Setting up multicast sockets, Sending and receiving data, Setting up unicast sockets, Using AdaSockets @section Setting up multicast sockets @cindex Multicast sockets @cindex Creating a multicast socket @cindex Mbone @cindex Group communication Multicast sockets are used for group communication over the Internet. To use multicast sockets, you must be connected to a multicast network and use a multicast-enabled operating system (such as most Unices, Linux or even recent Windows versions). Unless you are connected to the mbone (multicast backbone) or have setup a private multicast network, you will only be able to use multicast on your local network. A multicast socket is somewhat similar to a UDP socket; in particular, packets may be lost or misordered. @findex Create_Multicast_Socket @findex Sockets.Multicast.Create_Multicast_Socket @tindex Multicast_Socket_FD You can create a multicast socket using the function @code{Create_Multicast_Socket} in the package @code{Sockets.Multicast}. This function returns a @code{Multicast_Socket_FD} object, which derives from @code{Socket_FD}. @code{Create_Multicast_Socket} takes care of the whole setup of your multicast socket. You do not need to call any additionnal subprogram before using it. In particular, @code{Create_Multicast_Socket} will take care of registering the multicast socket to the operating system, so that the latter can tell the connected routers to propagate the subscription to the mbone as needed. @node Sending and receiving data, , Setting up multicast sockets, Using AdaSockets @section Sending and receiving data @cindex Sending data @cindex Receiving data In AdaSockets, data can be sent and received in three different ways: raw, string-oriented and stream-oriented. @menu * Raw data manipulation:: * String-oriented exchanges:: @end menu @node Raw data manipulation, String-oriented exchanges, Sending and receiving data, Sending and receiving data @subsection Raw data manipulation @cindex Raw data manipulation @tindex Ada.Streams.Stream_Element_Array @tindex Stream_Element_Array Raw data is manipulated using the predefined @code{Ada.Streams.Stream_Element_Array} Ada type. This corresponds to an array of bytes, or an @code{unsigned char *} in the C programming language. @node String-oriented exchanges, , Raw data manipulation, Sending and receiving data @subsection String-oriented exchanges String-oriented exchanges provides the programmer with @code{Ada.Text_IO} like subprograms. Most Internet protocols are line-oriented and those subprograms are perfectly suited to implement those. When sending data, the classical @code{CR + LF} sequence will be sent at the end of each line. When receiving data, @code{CR} characters are discarded and @code{LF} is used as the end-of-line marker. The @code{Get} function is tied to the size of the operating system buffer. It is better to use @code{Get_Line} to get a full line. The line can be as long as the length of the Ada buffer. The Ada buffer can be adjusted by using the @code{Set_Buffer} and @code{Unset_Buffer} procedures. When using string-oriented exchanges with datagram protocols such as UDP, setting a buffer using @code{Set_Buffer} for the receiving socket is mandatory. If you don't, the receiving socket will loose data and will be unable to reconstitute the string. @node Sockets package, Sockets.Multicast package, Using AdaSockets, Top @chapter Sockets package @include sockets.texi @node Sockets.Multicast package, Sockets.Naming package, Sockets package, Top @chapter Sockets.Multicast package @include sockets-multicast.texi @node Sockets.Naming package, Contributors, Sockets.Multicast package, Top @chapter Sockets.Naming package @include sockets-naming.texi @node Contributors, Resources on the Internet, Sockets.Naming package, Top @appendix Contributors @cindex Contributing AdaSockets has been originally developped by Samuel Tardieu who still maintains it. However, the following people have made crucial contributions to AdaSockets, be they new code, bug fixes or porting to new operating systems: @itemize @bullet @item Dmitriy Anisimkov (@email{anisimkov@@yahoo.com}) @item Alan Barnes (@email{barnesa@@aston.ac.uk}) @item Juanma Barranquero (@email{lektu@@terra.es}) @item Bobby D. Bryant (@email{bdbryant@@mail.utexas.edu}) @item Sander Cox (@email{sander.cox@@philips.com}) @item Sune Falk (@email{sune.falck@@telia.com}) @item Guillaume Foliard (@email{guifo@@wanadoo.fr}) @item Laurent Guerby (@email{guerby@@club-internet.fr}) @item David J. Kristola (@email{David95037@@aol.com}) @item Dominik Madon (@email{dominik@@acm.org}) @item Pascal Obry (@email{p.obry@@wanadoo.fr}) @item Nicolas Ollinger (@email{Nicolas.Ollinger@@ens-lyon.fr}) @item Stéphane Patureau (@email{spaturea@@meletu.univ-valenciennes.fr}) @item Thomas Quinot (@email{thomas@@cuivre.fr.eu.org}) @item Preben Randhol (@email{randhol@@pvv.org}) @item Maxim Reznik (@email{max1@@mbank.com.ua}) @item Joel Sherrill (@email{joel.sherrill@@oarcorp.com}) @item Samuel Tardieu (@email{sam@@rfc1149.net}) @end itemize If you feel that you have been forgotten, please send me a mail so that I can fix it in the next version. @xref{Resources on the Internet}, for how to contribute. @node Resources on the Internet, Index, Contributors, Top @appendix Resources on the Internet @cindex Sending patches @cindex Reporting a bug @cindex Suggesting a feature @cindex Finding AdaSockets on the Internet @cindex Contributing The latest version of AdaSockets can always be found at: @center @url{https://www.rfc1149.net/devel/adasockets} You can report issues or the AdaSockets mailing-list at @center @url{https://lists.sr.ht/~rfc1149/adasockets-devel} Contributions and patches are welcomed. @node Index, , Resources on the Internet, Top @unnumbered Index @printindex cp @bye adasockets-v1.14/doc/sockets-multicast.desc000066400000000000000000000067651454340372400210550ustar00rootroot00000000000000/*=* Global settings. * * package: Sockets.Multicast * intro: * The @code{Sockets.Multicast} allows the creation of IP multicast * sockets. =*/ /*=type Multicast_Socket_FD * * what: IP multicast socket object * def: new Socket_FD with private * doc: * The @code{Multicast_Socket_FD} tagged type derives from the * @code{Socket_FD} type. It gets initialized by calling * @ref{Create_Multicast_Socket (function)}. An uninitialized * @code{Multicast_Socket_FD} can be successfully compared to * @code{Null_Multicast_Socket_FD}. =*/ /*=subprogram Create_Multicast_Socket * * what: Create an IP multicast socket * kind: function * arg: Group, in, String,, IP address of the multicast group to join * arg: Port, in, Natural,, Port of the multicast group to join * arg: TTL, in, Positive, 16, Time-to-live of sent packets * arg: * Self_Loop, in, Boolean, True, Should the socket receive the packets * sent from the local host? * arg: Local_If, in, String, "0.0.0.0", Address of the local interface * to use, or "0.0.0.0" to designate any possible interface * ret: Multicast_Socket_FD, The new initialized multicast socket * doc: * This function creates an IP multicast socket attached to a given * group, identified by its class E IP address and port. * * Be careful when choosing the TTL parameter of your IP multicast * socket. Most IP multicast routers do implement threshold-based * filtering and will not let IP multicast packets leave your * organization if the TTL on the last router is smaller than 16. * * If 0 is given for the Port, a local one will be chosen. It can * then later be retrieved using Get_Sock_Port. * concept: Creating a socket * concept: Creating a multicast socket * example: * $ declare * $ Sock : Multicast_Socket_FD; * $ begin * $ -- Create a multicast socket on group 224.1.2.3 port 8763 * $ Sock := Create_Multicast_Socket ("224.1.2.3", 8763); * $ -- Perform some operations on socket * $ [...] * $ -- Shutdown the socket in both directions * $ Shutdown (Sock, Both); * $ end; * see: Send (procedure) * see: Shutdown (procedure) =*/ /*=subprogram Create_Multicast_Socket * * what: Create an IP multicast socket * kind: function * arg: Group, in, String,, IP address of the multicast group to join * arg: Port, in, Positive,, Port of the multicast group to join * arg: Local_Port, in, Natural,, Local port number to use * arg: TTL, in, Positive, 16, Time-to-live of sent packets * arg: Local_If, in, String, "0.0.0.0", Address of the local interface * to use, or "0.0.0.0" to designate any possible interface * ret: Multicast_Socket_FD, The new initialized multicast socket * doc: * This function creates an IP multicast socket attached to a given * group, identified by its class E IP address and port. If * Local_Port is 0, a free port will automatically be chosen by * your operating system. * * This function should be used when you want to send packets * to a multicast group without receiving any packet yourself. * concept: Creating a socket * concept: Creating a multicast socket * example: * $ declare * $ Sock : Multicast_Socket_FD; * $ begin * $ -- Create a multicast socket on group 224.1.2.3 port 8763 * $ Sock := Create_Multicast_Socket ("224.1.2.3", 8763); * $ -- Perform some operations on socket * $ [...] * $ -- Shutdown the socket in both directions * $ Shutdown (Sock, Both); * $ end; * see: Send (procedure) * see: Shutdown (procedure) =*/ adasockets-v1.14/doc/sockets-naming.desc000066400000000000000000000111161454340372400203030ustar00rootroot00000000000000/*=* Global settings. * * package: Sockets.Naming * intro: * The @code{Sockets.Naming} package contains types and helper functions * needed to manipulate Internet host names and addresses. =*/ /*=type String_Access * * what: Access on string * def: access String * doc: * Helper type =*/ /*=type String_Array * * what: Array of strings * def: array (Positive range <>) of String_Access * doc: * Helper type =*/ /*=type Address_Component * * what: IPv4 address component (subtype) * def: Natural range 0 .. 255 * doc: * Helper type =*/ /*=type Address * * what: IPv4 address (subtype) * def: record@*@w{ }H1, H2, H3, H4 : Address_Component;@*end record * doc: * This type represents an IPv4 address with @code{H1} being the first * octet and @code{H4} the last one. For example, 137.194.161.2 is * represented by @code{H1=137, H2=194, H3=161, H4=2}. =*/ /*=type Address_Array * * what: array of IPv4 addresses * def: array (Positive range <>) of Address * doc: * Helper type =*/ /*=type Host_Entry * * discr: N_Aliases, N_Addresses : Natural * def: new Ada.Finalization.Controlled with record@*@w{ } Name : String_Access;@*@w{ } Aliases : String_Array (1 .. N_Aliases);@*@w{ } Addresses : Address_Array (1 .. N_Addresses);@* end record * doc: * The @code{Host_Entry} type holds a set of names and IP addresses * associated with a host. Each host can have several IP address * as well as several aliases. =*/ /*=subprogram Image * * what: Make a string from an address * kind: function * arg: Add, in, Address,, IP address * ret: String, String representation of the IP address * concept: Representing IP addresses * see: Value (function) =*/ /*=subprogram Value * * what: Transform a string into an address * kind: function * arg: Add, in, String,, Textual representation of an IP address * ret: Address, Corresponding Address * concept: Representing IP addresses * see: Image (function) =*/ /*=subprogram Is_IP_Address * * what: Check if given string is a valid IP address * kind: function * arg: Something, in, String,, String to check * ret: Boolean, @samp{True} if @var{Something} is an IP address =*/ /*=subprogram Info_Of_Name_Or_IP * * what: Get addresses and names of a host * kind: function * arg: Something, in, String,, Host name or IP address * ret: Host_Entry, Corresponding host entry * exc: Naming_Error, No information available for this name or address * doc: * This function extracts all the names and addresses from the * naming service. =*/ /*=subprogram Address_Of * * what: Get the IP address of a host * kind: function * arg: Something, in, String,, Host name or IP address * ret: Address, IPv4 address * exc: Naming_Error, No information available for this name or address * see: Name_Of (function) =*/ /*=subprogram Host_Name * * what: Get the name of the current host * kind: function * ret: String, Name of the current host * doc: * This function returns the name of the current host. Depending on * the local configuration, it may or may not be a fully qualified * domain name (FQDN). =*/ /*=subprogram Name_Of * * what: Official name of the host * kind: function * arg: Something, in, String,, Host name or IP address * ret: String, Name of the host * exc: Naming_Error, No information available for this name or address * see: Address_Of (function) =*/ /*=subprogram Any_Address * * what: Special address representing any address on the local host * kind: function * ret: Address, Equivalent to @code{INADDR_ANY} in the C programming language =*/ /*=subprogram Get_Peer_Addr * * what: Retrieve IP address of remote host * kind: function * arg: Socket, in, Socket_FD,, Connected socket object * ret: Address, Peer address * see: Get_Peer_Port (function) * see: Get_Sock_Addr (function) =*/ /*=subprogram Get_Peer_Port * * what: Retrieve port used by remote host * kind: function * arg: Socket, in, Socket_FD,, Connected socket object * ret: Positive, Port used on the remote host * see: Get_Sock_Port (function) * see: Get_Peer_Addr (function) =*/ /*=subprogram Get_Sock_Addr * * what: Retrieve IP address of local host * kind: function * arg: Socket, in, Socket_FD,, Connected socket object * ret: Address, Address of local interface used * see: Get_Sock_Port (function) * see: Get_Peer_Addr (function) =*/ /*=subprogram Get_Sock_Port * * what: Retrieve port used by local host * kind: function * arg: Socket, in, Socket_FD,, Connected socket object * ret: Positive, Port used on the local host * see: Get_Peer_Port (function) * see: Get_Sock_Addr (function) =*/ adasockets-v1.14/doc/sockets.desc000066400000000000000000000506301454340372400170400ustar00rootroot00000000000000/*=* Global settings. * * package: Sockets * intro: * The @code{Sockets} package contains all the definitions and * subprograms needed to build a simple unicast client or server. =*/ /*=type Socket_FD * * what: Socket object * def: tagged private * doc: * The @code{Socket_FD} tagged type is the root type of all * sockets. It gets initialized by calling @ref{Socket (procedure)}. * An uninitialized @code{Socket_FD} can be successfully compared to * @code{Null_Socket_FD}. =*/ /*=subprogram Socket * * what: Create a socket of the given mode * kind: procedure * arg: Socket, out, Socket_FD,, Socket object to initialize * arg: Domain, in, Socket_Domain, PF_INET, Protocol family * arg: Typ, in, Socket_Type, SOCK_STREAM, Kind of sockets * doc: * @ctindex PF_INET * @ctindex AF_INET * @ctindex SOCK_STREAM * @ctindex SOCK_DGRAM * This procedure initializes a new socket object by reserving a file * descriptor to the operating system. For backward compatibility with * older versions of this library, @code{AF_INET} is still accepted as * a value but should be replaced as soon as possible with the proper * @code{PF_INET}. Using @code{SOCK_STREAM} for the @var{Typ} * argument will create a TCP socket while a @code{SOCK_DGRAM} will * create a UDP one. * concept: Creating a socket * example: * $ declare * $ Sock : Socket_FD; * $ begin * $ -- Create a TCP socket * $ Socket (Sock, PF_INET, SOCK_STREAM); * $ -- Perform some operations on socket * $ [...] * $ -- Shutdown the socket in both directions * $ Shutdown (Sock, Both); * $ end; * see: Shutdown (procedure) =*/ /*=subprogram Connect * * what: Connect a socket on a given host/port * kind: procedure * arg: Socket, in, Socket_FD,, Initialized socket object * arg: Host, in, String,, Host to connect to * arg: Port, in, Positive,, Port to connect to * exc: Connection_Refused, The connection has been refused by the server * exc: Socket_Error, Another error occurred during the connection * doc: * This procedure connects an initialized socket to a given host on * a given port. In the case of a TCP socket, a real connection is * attempted. In the case of a UDP socket, no connection takes place * but the endpoint coordinates are recorded. * concept: Connecting a socket * example: * $ declare * $ Sock : Socket_FD; * $ begin * $ -- Create a TCP socket * $ Socket (Sock, PF_INET, SOCK_STREAM); * $ -- Connect it to rfc1149.net's mail server * $ Connect (Sock, "mail.rfc1149.net", 25); * $ -- Do a mail transaction then close the socket * $ [...] * $ end; * see: Socket (procedure) =*/ /*=subprogram Bind * * what: Associate a local port to a socket * kind: procedure * arg: Socket, in, Socket_FD,, Initialized socket object * arg: Port, in, Natural,, Local port to bind to * arg: Host, in, String, @w{}"", Local interface to bind to * exc: Socket_Error, Requested port or interface not available * doc: * This procedure requests a local port from the operating * system. If 0 is given in @var{Port}, the system will assign a * free port whose number can later be retrieved using * @ref{Get_Sock_Port (function)}. Also, most operating systems require * special privileges if you want to bind to ports below 1024. * * If @var{Host} is not the empty string, it must contain the * IP address of a local interface to bind to, or a name which * resolves into such an address. If an empty string is given (the * default), the socket will be bound to all the available * interfaces. * concept: Binding a socket * concept: Assigning a local port * concept: Creating a server * see: Listen (procedure) * see: Socket (procedure) =*/ /*=subprogram Listen * * what: Establish a listen queue * kind: procedure * arg: Socket, in, Socket_FD,, Initialized and bound socket object * arg: Queue_Size, in, Positive, 5, Requested slots in the listen queue * doc: * This procedure establishes a listen queue after a TCP socket as been * initialized and bound. Each slot in the queue can hold one * incoming connection that has not been accepted yet. Note that * most operating systems ignore queue sizes larger than five. * concept: Establishing a listen queue * concept: Listen queue * see: Accept_Socket (procedure) * see: Bind (procedure) * see: Socket (procedure) =*/ /*=subprogram Getsockopt * * what: Retrieve a socket option * kind: procedure * arg: Socket, in, Socket_FD,, Initialized and bound socket object * arg: Level, in, Socket_Level, SOL_SOCKET, Protocol level * arg: Optname, in, Socket_Option,, Option name * arg: Optval, out, Integer,, Option value * doc: * @ctindex Sockets.SOL_SOCKET * @ctindex Sockets.IPPROTO_IP * @ctindex Sockets.SO_REUSEADDR * @ctindex Sockets.SO_REUSEPORT * @ctindex Sockets.IP_MULTICAST_TTL * @ctindex Sockets.IP_ADD_MEMBERSHIP * @ctindex Sockets.IP_DROP_MEMBERSHIP * @ctindex Sockets.IP_MULTICAST_LOOP * @ctindex Sockets.SO_SNDBUF * @ctindex Sockets.SO_RCVBUF * @ctindex SOL_SOCKET * @ctindex IPPROTO_IP * @ctindex SO_REUSEADDR * @ctindex SO_REUSEPORT * @ctindex IP_MULTICAST_TTL * @ctindex IP_ADD_MEMBERSHIP * @ctindex IP_DROP_MEMBERSHIP * @ctindex IP_MULTICAST_LOOP * @ctindex SO_SNDBUF * @ctindex SO_RCVBUF * This procedure retrieves options applicable to a socket. Please * see your operating system manual for usable levels and options. * * Two levels are defined: @code{SOL_SOCKET} (the default) and * @code{IPPROTO_IP}. The options are @code{SO_REUSEADDR}, * @code{SO_REUSEPORT}, @code{IP_MULTICAST_TTL}, * @code{IP_ADD_MEMBERSHIP}, @code{IP_DROP_MEMBERSHIP}, * @code{IP_MULTICAST_LOOP}, @code{SO_SNDBUF} and * @code{IP_RCVBUF}. * * Note that unlike their C language counterpart, @code{Getsockopt} * and @code{Setsockopt} do not require an extra parameter * representing the length in bytes of the option value. AdaSockets * knows the right size for every option. * concept: Manipulating socket options * concept: Retrieving socket options * see: Setsockopt (procedure) =*/ /*=subprogram Setsockopt * * what: Set a socket option * kind: procedure * arg: Socket, in, Socket_FD,, Initialized and bound socket object * arg: Level, in, Socket_Level, SOL_SOCKET, Protocol level * arg: Optname, in, Socket_Option,, Option name * arg: Optval, in, Integer,, Option value * doc: * @ctindex Sockets.SOL_SOCKET * @ctindex Sockets.IPPROTO_IP * @ctindex Sockets.SO_REUSEADDR * @ctindex Sockets.SO_REUSEPORT * @ctindex Sockets.IP_MULTICAST_TTL * @ctindex Sockets.IP_ADD_MEMBERSHIP * @ctindex Sockets.IP_DROP_MEMBERSHIP * @ctindex Sockets.IP_MULTICAST_LOOP * @ctindex Sockets.SO_SNDBUF * @ctindex Sockets.SO_RCVBUF * @ctindex SOL_SOCKET * @ctindex IPPROTO_IP * @ctindex SO_REUSEADDR * @ctindex SO_REUSEPORT * @ctindex IP_MULTICAST_TTL * @ctindex IP_ADD_MEMBERSHIP * @ctindex IP_DROP_MEMBERSHIP * @ctindex IP_MULTICAST_LOOP * @ctindex SO_SNDBUF * @ctindex SO_RCVBUF * This procedure sets options applicable to a socket. Please * see your operating system manual for usable levels and options. * * Two levels are defined: @code{SOL_SOCKET} (the default) and * @code{IPPROTO_IP}. The options are @code{SO_REUSEADDR}, * @code{SO_REUSEPORT}, @code{IP_MULTICAST_TTL}, * @code{IP_ADD_MEMBERSHIP}, @code{IP_DROP_MEMBERSHIP}, * @code{IP_MULTICAST_LOOP}, @code{SO_SNDBUF} and * @code{IP_RCVBUF}. * * Note that unlike their C language counterpart, @code{Getsockopt} * and @code{Setsockopt} do not require an extra parameter * representing the length in bytes of the option value. AdaSockets * knows the right size for every option. * concept: Manipulating socket options * concept: Setting socket options * see: Getsockopt (procedure) =*/ /*=subprogram Accept_Socket * * what: Accept an incoming connection * kind: procedure * arg: Socket, in, Socket_FD,, Initialized, bound and listening socket object * arg: New_Socket, out, Socket_FD,, Incoming socket object * doc: * This procedure creates a new socket corresponding to an incoming * connection on TCP socket @var{Socket}. All the communications * with the peer will take place on @var{New_Socket}, while the * program can accept another connection on @var{Socket}. * * @var{New_Socket} must not be initialized before calling this * procedure, or must have been cleaned up by calling * @code{Shutdown}, in order to avoid a file descriptors leak. * * @code{Accept_Socket} will block until an incoming connection is * ready to be accepted. * concept: Accepting a new connection * concept: Handling a new connection * example: * $ declare * $ Sock : Socket_FD; * $ Incoming : Socket_FD; * $ begin * $ -- Create a TCP socket listening on local port 4161 * $ Socket (Sock, PF_INET, SOCK_STREAM); * $ Bind (Sock, 4161); * $ Listen (Sock, 3); * $ -- One-connection-at-a-time server (3 may be pending) * $ loop * $ -- Wait for a new connection and accept it * $ Accept_Socket (Sock, Incoming); * $ -- Do some dialog with the remote host * $ Do_Some_Dialog (Incoming); * $ -- Close incoming socket and wait for next connection * $ Shutdown (Incoming); * $ end loop; * $ end; * see: Bind (procedure) * see: Listen (procedure) * see: Shutdown (procedure) * see: Socket (procedure) =*/ /*=subprogram Send * * what: Send raw data over a socket * kind: procedure * arg: Socket, in, Socket_FD,, Initialized and connected socket object * arg: Data, out, Ada.Streams.Stream_Element_Array,, Data to be sent * doc: * @tindex Ada.Streams.Stream_Element_Array * @tindex Stream_Element_Array * This procedure sends data over a connected outgoing socket or * over an incoming socket. * concept: Sending data * exc: Connection_Closed, Peer has prematurely closed the connection * see: Put (procedure) * see: Put_Line (procedure) =*/ /*=subprogram Receive * * what: Receive raw data over a socket * kind: function * arg: * Socket, in, Socket_FD,, Initialized and bound or connected socket object * arg: Max, in, Ada.Streams.Stream_Element_Count, 4096, Maximum data length * ret: Ada.Streams.Stream_Element_Array, Received raw data * doc: * @tindex Ada.Streams.Stream_Element_Count * @tindex Ada.Streams.Stream_Element_Array * @tindex Stream_Element_Count * @tindex Stream_Element_Array * This procedure receives data from a bound UDP socket or a connected * TCP socket. Only one system call will be performed; this * function will return whatever data has arrived. Note that in * GNAT the secondary stack may be used to store the data and may * result in stack storage exhaustion. * concept: Receiving data * exc: * Connection_Closed, Peer has closed the connection before sending any data * see: Receive (procedure) * see: Receive_Some (procedure) * see: Get_Line (function) * see: Get_Line (procedure) =*/ /*=subprogram Receive * * what: Receive raw data over a socket * kind: procedure * arg: * Socket, in, Socket_FD'Class,, * Initialized and bound or connected socket object * arg: Data, out, Ada.Streams.Stream_Element_Array,, Incoming data buffer * doc: * @tindex Ada.Streams.Stream_Element_Array * @tindex Stream_Element_Array * This procedure receives data from a bound UDP socket or a connected * TCP socket. It will block until the @var{Data} reception buffer * has been totally filled. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before @code{Data'Length} bytes@* * were received * see: Get_Line (function) * see: Get_Line (procedure) * see: Receive (function) * see: Receive_Some (procedure) =*/ /*=subprogram Receive_Some * * what: Receive raw data over a socket * kind: procedure * arg: * Socket, in, Socket_FD'Class,, * Initialized and bound or connected socket object * arg: Data, out, Ada.Streams.Stream_Element_Array,, Incoming data buffer * arg: * Last, out, Ada.Streams.Stream_Element_Offset,, * Index of last element placed into @var{Data} * doc: * @tindex Ada.Streams.Stream_Element_Array * @tindex Stream_Element_Array * @tindex Ada.Streams.Stream_Element_Count * @tindex Stream_Element_Count * This procedure receives data from a bound UDP socket or a connected * TCP socket. As soon as at least one byte has been read, it returns * with @var{Last} set to the index of the latest written element * of @var{Data}. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before sending any data * see: Get_Line (function) * see: Get_Line (procedure) * see: Receive (function) * see: Receive (procedure) =*/ /*=subprogram Shutdown * * what: Shutdown a socket * kind: procedure * arg: Socket, in out, Socket_FD,, Socket object to shutdown * arg: How, in, Shutdown_Type, Both, Direction to shutdown * doc: * @ctindex Send * @ctindex Receive * @ctindex Both * This procedure shutdowns either direction of the socket. @var{How} * can take the value @samp{Send}, @samp{Receive} or @samp{Both}. * concept: Closing a socket * concept: Socket shutdown * see: Socket (procedure) =*/ /*=subprogram Put * * what: Send a string to a remote host * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Str, in, String,, String to send * doc: * This procedure sends the content of @var{Str} over an outgoing * or incoming socket. * concept: Sending data * exc: Connection_Closed, Peer has prematurely closed the connection * see: New_Line (procedure) * see: Put_Line (procedure) * see: Send (procedure) =*/ /*=subprogram New_Line * * what: Send a CR/LF to a remote host * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Count, in, Natural, 1, Number of CR/LF sequences to send * doc: * @ctindex CR * @ctindex LF * This procedure sends one or more CR/LF combinations to the peer. * concept: Sending data * exc: Connection_Closed, Peer has prematurely closed the connection * see: Put (procedure) * see: Put_Line (procedure) =*/ /*=subprogram Put_Line * * what: Send a CR/LF terminated string to a remote host * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Str, in, String,, String to send * doc: * This procedure sends the content of @var{Str} plus a CR/LF combination * over an outgoing or incoming socket. * concept: Sending data * exc: Connection_Closed, Peer has prematurely closed the connection * see: New_Line (procedure) * see: Put (procedure) * see: Send (procedure) =*/ /*=subprogram Get * * what: Get a string from a remote host * kind: function * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * ret: String, Some characters that have been received * doc: * This function receives some characters from a remote host. * As soon that at least one character is available, the current * reception buffer is returned. * * There is usually little gain in using this function whose behavior is * comparable to the one of @ref{Receive (function)}. Other * functions such as @ref{Get_Char (function)}, or * @ref{Get_Line (function)}, allow more structured programming. * * However, this function may be used to avoid losing characters * when calling @ref{Unset_Buffer (procedure)}, if, for some reason, * the remote host may have sent some. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before sending any data =*/ /*=subprogram Get_Char * * what: Get a character from a remote host * kind: function * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * ret: Character, One character sent by the remote host * doc: * This function receives exactly one character from the remote host. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before sending the character * see: Get (function) * see: Get_Line (function) * see: Get_Line (procedure) * see: Receive (procedure) * see: Set_Buffer (procedure) =*/ /*=subprogram Get_Line * * what: Get a whole line from a remote host * kind: function * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Max_Length, in, Positive, 2048, Maximum returned line length * ret: String, A line without the CR and LF separators * doc: * @ctindex CR * @ctindex LF * This function receives one line from the remote host. A line * consists into zero or more characters followed by an optional CR * and by a LF. Those terminators are stripped before the line is * returned. * * This function blocks until one full line has been received. The line * length is limited with the value of the Max_Length argument, to avoid * exhaustion of the secondary stack. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before sending a whole line * see: Get (function) * see: Get_Char (function) * see: Get_Line (procedure) * see: Receive (procedure) * see: Set_Buffer (procedure) =*/ /*=subprogram Get_Line * * what: Get a whole line from a remote host * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Str, in out, String,, String to fill * arg: Last, out, Natural,, Last index used in the string * doc: * @ctindex CR * @ctindex LF * This procedure receives one line from the remote host. A line * consists into zero or more characters followed by an optional CR * and by a LF. Those terminators are stripped before the line is * returned. * * This procedure blocks until one full line has been received. * concept: Receiving data * exc: * Connection_Closed, * Peer has closed the connection before sending a whole line * see: Get (function) * see: Get_Char (function) * see: Get_Line (function) * see: Receive (procedure) * see: Set_Buffer (procedure) =*/ /*=subprogram Set_Buffer * * what: Install a line-oriented buffer of the socket object * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * arg: Length, in, Positive, 1500, Size in bytes of the newly installed buffer * doc: * This procedure puts the socket object in buffered mode. If the * socket was already buffered, the content of the previous buffer * will be lost. The buffered mode only affects character- and * line-oriented read operation such as @ref{Get (function)}, * @ref{Get_Char (function)}, and @ref{Get_Line (function)}. Other * reception subprograms will not function properly if buffered mode * is used at the same time. * * The size of the buffer has to be greater than the biggest * possible packet sent by the remote host, otherwise data loss may * occur. * concept: Receiving data * see: Unset_Buffer (procedure) =*/ /*=subprogram Unset_Buffer * * what: Deinstall the line-oriented buffer of the socket object * kind: procedure * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * doc: * This procedure uninstalls the buffer previously installed by * @ref{Set_Buffer (procedure)}. If any data is still present in * the buffer, it will be lost. To avoid this situation, the buffer * can be flushed by calling @ref{Get (function)}. * concept: Receiving data =*/ /*=subprogram Get_Send_Queue_Size * * what: Return the size of the unsent data in the output queue * kind: function * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * ret: Integer, The non-negative size in bytes of the output queue, or a negative value in case of error * doc: * This function is only available on Linux platforms. On other operating * systems, it will return -2 to indicate that the necessary mechanisms to * retrieve the information are not available. * concept: Sending data * see: Send (procedure) =*/ /*=subprogram Get_Receive_Queue_Size * * what: Return the size of the unread data in the input queue * kind: function * arg: Socket, in, Socket_FD'Class,, Initialized and connected socket object * ret: Integer, The non-negative size in bytes of the input queue, or a negative value in case of error * doc: * This function is only available on Linux platforms. On other operating * systems, it will return -2 to indicate that the necessary mechanisms to * retrieve the information are not available. * concept: Receiving data * see: Receive (procedure) =*/ adasockets-v1.14/examples/000077500000000000000000000000001454340372400155725ustar00rootroot00000000000000adasockets-v1.14/examples/Makefile.RTEMS000066400000000000000000000037141454340372400201300ustar00rootroot00000000000000# # Makefile for Ada sockets example # # Directly produces an executable for a BSP which directly runs # the format (usually ELF) produced by just linking an application. # The executables produced by this Makefile should run on at least the # following BSPs: # arm/edb7312 # mips/jmr3904 # powerpc/psim # powerpc/score603e # sparc/erc32 # sparc/sis # # Some BSPs require extra manipulation of the ELF file before it can # be run on the target hardware. # EXAMPLES=stream_listener stream_sender listener multi tcprelay include $(RTEMS_MAKEFILE_PATH)/Makefile.inc include $(RTEMS_CUSTOM) include $(PROJECT_ROOT)/make/leaf.cfg # GEN5200 Specific Information ifeq ($(RTEMS_BSP_FAMILY),gen5200) LINKARGS+=-qnolinkcmds -T$(RTEMS_LINKCMDS) endif # PC386 Specific Information ifeq ($(RTEMS_BSP_FAMILY),pc386) HEADERADDR=0x00097E00 START16FILE=$(RTEMS_MAKEFILE_PATH)/lib/start16.bin START16ADDR=0x00097C00 RELOCADDR=0x00100000 LINKARGS+= -Wl,-Ttext,$(RELOCADDR) endif # Tool helpers GNATMAKE=$(AS:as=gnatmake) CARGS =-B${RTEMS_MAKEFILE_PATH}/lib/ -specs bsp_specs -qrtems $(CPU_CFLAGS) CARGS+=-DGNAT_MAIN_STACKSPACE=100 all: $(EXAMPLES) stream_listener stream_sender listener multi tcprelay: rtems_init.o *.adb $(GNATMAKE) -v -O -gnata -gnatE -gnato $(@) -g \ -I../src \ -bargs -Mgnat_main \ -largs $(CARGS) $(LINKARGS) rtems_init.o $(SIZE) $(@) ifeq ($(RTEMS_BSP_FAMILY),pc386) mv $(@) $(@).obj $(OBJCOPY) -O elf32-i386 \ --remove-section=.rodata \ --remove-section=.comment \ --remove-section=.note \ --strip-unneeded $(@).obj $(@) $(OBJCOPY) -O binary $(@).obj $(@).bin $(RTEMS_MAKEFILE_PATH)/build-tools/bin2boot -v $(@).bt $(HEADERADDR) \ $(START16FILE) $(START16ADDR) 0 $(@).bin $(RELOCADDR) 0 else endif rtems_init.o: rtems_init.c $(CC) $(CFLAGS) $(CPU_CFLAGS) -c rtems_init.c clean: rm -f b~*.* *.o *.ali $(EXAMPLES) rm -f *.num *.exe *.obj *.bin *.bt adasockets-v1.14/examples/Makefile.VMS000066400000000000000000000006341454340372400177010ustar00rootroot00000000000000# Makefile for OpenVMS (GNU Make) # # $Revision$ # # # This file is part of adasockets port to OpenVMS # .PHONY: all distclean clean .DEFAULT: all FILES= stream_listener.adb\ stream_sender.adb\ listener.adb\ multi.adb\ tcprelay.adb all: $(FILES:.adb=.exe) %.exe: %.adb gnat make /search=([-.src]) $< distclean: del/noconf/log *.ali;*, *.obj;*, *.exe;* clean: del/noconf/log *.ali;*, *.obj;* adasockets-v1.14/examples/Makefile.am000066400000000000000000000017011454340372400176250ustar00rootroot00000000000000all-local: tcprelay listener multi stream_listener stream_sender tcprelay: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) tcprelay -cargs $(ADAFLAGS) -largs $(LDFLAGS) listener: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) listener -cargs $(ADAFLAGS) -largs $(LDFLAGS) multi: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) multi -cargs $(ADAFLAGS) -largs $(LDFLAGS) stream_listener: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) stream_listener -cargs $(ADAFLAGS) -largs $(LDFLAGS) stream_sender: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) stream_sender -cargs $(ADAFLAGS) -largs $(LDFLAGS) DISTCLEANFILES = tcprelay listener multi stream_listener stream_sender CLEANFILES = *.o *.ali b_*.c b~*.ad[bs] EXTRA_DIST = Makefile.RTEMS Makefile.VMS \ multi.adb rtems_init.c rtems_networkconfig.h stream_listener.adb \ listener.adb stream_sender.adb tcprelay.adb never:: adasockets-v1.14/examples/header.txt000066400000000000000000000051441454340372400175670ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- XXXXX -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- adasockets-v1.14/examples/listener.adb000066400000000000000000000115361454340372400200750ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- L I S T E N E R -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets; use Sockets; procedure Listener is -- Usage: listener port -- Example: listener 5000 -- then telnet localhost 5000 task type Echo is entry Start (FD : Socket_FD); end Echo; function Rev (S : String) return String; -- Reverse a string ---------- -- Echo -- ---------- task body Echo is Sock : Socket_FD; begin select accept Start (FD : Socket_FD) do Sock := FD; end Start; or terminate; end select; loop Put_Line (Sock, Rev (Get_Line (Sock))); end loop; exception when Connection_Closed => Put_Line ("Connection closed"); Shutdown (Sock, Both); end Echo; Accepting_Socket : Socket_FD; Incoming_Socket : Socket_FD; type Echo_Access is access Echo; Dummy : Echo_Access; --------- -- Rev -- --------- function Rev (S : String) return String is Result : String (1 .. S'Length); Index : Natural := 0; begin for I in reverse S'Range loop Index := Index + 1; Result (Index) := S (I); end loop; return Result; end Rev; begin if Argument_Count /= 1 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " port"); end if; Socket (Accepting_Socket, PF_INET, SOCK_STREAM); Setsockopt (Accepting_Socket, SOL_SOCKET, SO_REUSEADDR, 1); Bind (Accepting_Socket, Positive'Value (Argument (1))); Listen (Accepting_Socket); loop Put_Line ("Waiting for new connection"); Accept_Socket (Accepting_Socket, Incoming_Socket); Put_Line ("New connection acknowledged"); -- This step is optional, especially for TCP sockets Set_Buffer (Incoming_Socket, 4096); Put_Line ("New socket buffered"); Dummy := new Echo; Dummy.Start (Incoming_Socket); end loop; end Listener; adasockets-v1.14/examples/multi.adb000066400000000000000000000076161454340372400174060ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- M U L T I -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Multicast; use Sockets, Sockets.Multicast; procedure Multi is Sock : constant Multicast_Socket_FD := Create_Multicast_Socket ("224.13.194.161", 0); task Send_Packets; task body Send_Packets is Message : constant String := Argument (1); begin for I in 1 .. 30 loop delay 2.0; Put_Line ("Emitting """ & Message & """"); Put (Sock, Message); end loop; exception when E : others => Put_Line ("Exception raised in Send_Packets task:" & Exception_Information (E)); end Send_Packets; begin loop Put_Line ("Waiting for input"); Put_Line ("Received """ & Get (Sock) & """"); end loop; exception when E : others => Put_Line ("Exception raised in main task:" & Exception_Information (E)); if Argument_Count < 1 then Put_Line ("Btw, usage is: multi ""string to send"""); end if; end Multi; adasockets-v1.14/examples/rtems_init.c000066400000000000000000000120261454340372400201140ustar00rootroot00000000000000/* * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be found in * the file LICENSE in this distribution or at * http://www.rtems.com/license/LICENSE. * * $Id: rtems_init.c,v 1.2 2007/09/17 20:46:23 joel Exp $ */ #define MAIN_USE_NETWORKING #define MAIN_USE_REQUIRES_COMMAND_LINE #include #include #include #include #include #include "rtems_networkconfig.h" extern rtems_configuration_table BSP_Configuration; /* * Using GNAT's Distributed Systems Annex support requires * each node in the system to have different pid's. In a * single CPU RTEMS system, it is always one. This lets the * user override the RTEMS default. */ #ifdef GNAT_PID #include pid_t getpid() { return GNAT_PID; } #endif static int argc = 1; static char arg0[20] = "rtems"; static char *argv[20] = { arg0 }; #if defined(MAIN_USE_REQUIRES_COMMAND_LINE) #define COMMAND_LINE_MAXIMUM 200 #include #include void parse_arguments( char *buffer, size_t maximum_length ) { char *cp; char *linebuf = buffer; size_t length; for (;;) { /* * Set up first argument */ #if 0 argc = 1; strcpy (arg0, "rtems"); argv[0] = arg0; #endif #if (defined (MAIN_COMMAND_LINE)) strncpy (linebuf, MAIN_COMMAND_LINE, maximum_length); #else /* * Read a line */ printf (">>> %s ", argv[0]); fflush (stdout); fgets (linebuf, maximum_length, stdin); length = strnlen( linebuf, maximum_length ); if ( linebuf[length - 1] == '\n' || linebuf[length - 1] == '\r' ) { linebuf[length - 1] = '\0'; } #endif /* * Break line into arguments */ cp = linebuf; for (;;) { while (isspace (*cp)) *cp++ = '\0'; if (*cp == '\0') break; if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) { printf ("Too many arguments.\n"); argc = 0; break; } argv[argc++] = cp; while (!isspace (*cp)) { if (*cp == '\0') break; cp++; } } if (argc > 1) { argv[argc] = NULL; break; } printf ("You must give some arguments!\n"); } #if 0 { int i; for (i=0; i adasockets-v1.14/examples/rtems_networkconfig.h000066400000000000000000000073611454340372400220430ustar00rootroot00000000000000/* * Network configuration for an IceCube in RTEMS Lab * ************************************************************ * EDIT THIS FILE TO REFLECT YOUR NETWORK CONFIGURATION * * BEFORE RUNNING ANY RTEMS PROGRAMS WHICH USE THE NETWORK! * ************************************************************ * * $Id: rtems_networkconfig.h,v 1.1 2007/09/17 20:46:23 joel Exp $ */ #ifndef _RTEMS_NETWORKCONFIG_H_ #define _RTEMS_NETWORKCONFIG_H_ /* * The following will normally be set by the BSP if it supports * a single network device driver. In the event, it supports * multiple network device drivers, then the user's default * network device driver will have to be selected by a BSP * specific mechanism. */ #ifndef RTEMS_BSP_NETWORK_DRIVER_NAME #warning "RTEMS_BSP_NETWORK_DRIVER_NAME is not defined" #define RTEMS_BSP_NETWORK_DRIVER_NAME "no_network1" #endif #ifndef RTEMS_BSP_NETWORK_DRIVER_ATTACH #warning "RTEMS_BSP_NETWORK_DRIVER_ATTACH is not defined" #define RTEMS_BSP_NETWORK_DRIVER_ATTACH 0 #endif /* #define RTEMS_USE_BOOTP */ #include /* * Define RTEMS_SET_ETHERNET_ADDRESS if you want to specify the * Ethernet address here. If RTEMS_SET_ETHERNET_ADDRESS is not * defined the driver will choose an address. */ #define RTEMS_SET_ETHERNET_ADDRESS #if (defined (RTEMS_SET_ETHERNET_ADDRESS)) static char ethernet_address[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; #endif #ifdef RTEMS_USE_LOOPBACK /* * Loopback interface */ extern void rtems_bsdnet_loopattach(); static struct rtems_bsdnet_ifconfig loopback_config = { "lo0", /* name */ rtems_bsdnet_loopattach, /* attach function */ NULL, /* link to next interface */ "127.0.0.1", /* IP address */ "255.0.0.0", /* IP net mask */ }; #endif /* * Default network interface */ static struct rtems_bsdnet_ifconfig netdriver_config = { RTEMS_BSP_NETWORK_DRIVER_NAME, /* name */ RTEMS_BSP_NETWORK_DRIVER_ATTACH, /* attach function */ #ifdef RTEMS_USE_LOOPBACK &loopback_config, /* link to next interface */ #else NULL, /* No more interfaces */ #endif #if (defined (RTEMS_USE_BOOTP)) NULL, /* BOOTP supplies IP address */ NULL, /* BOOTP supplies IP net mask */ #else "192.168.1.244", /* IP address */ "255.255.255.0", /* IP net mask */ #endif /* !RTEMS_USE_BOOTP */ #if (defined (RTEMS_SET_ETHERNET_ADDRESS)) ethernet_address, /* Ethernet hardware address */ #else NULL, /* Driver supplies hardware address */ #endif 0, /* Use default driver parameters */ 0, /* mtu */ 0, /* rbuf_count */ 0, /* xbuf_count */ 0, /* port */ 0 /* irq */ }; /* * Network configuration */ struct rtems_bsdnet_config rtems_bsdnet_config = { &netdriver_config, #if (defined (RTEMS_USE_BOOTP)) rtems_bsdnet_do_bootp, #else NULL, #endif 0, /* Default network task priority */ 256 * 1024, /* Default mbuf capacity */ 256 * 1024, /* Default mbuf cluster capacity */ #if (!defined (RTEMS_USE_BOOTP)) "rtems", /* Host name */ "nodomain.com", /* Domain name */ "192.168.1.14", /* Gateway */ "192.168.1.1", /* Log host */ {"192.168.1.1" }, /* Name server(s) */ {"192.168.1.1" }, /* NTP server(s) */ #endif /* !RTEMS_USE_BOOTP */ }; /* * For TFTP test application */ #if (defined (RTEMS_USE_BOOTP)) #define RTEMS_TFTP_TEST_HOST_NAME "BOOTP_HOST" #define RTEMS_TFTP_TEST_FILE_NAME "BOOTP_FILE" #else #define RTEMS_TFTP_TEST_HOST_NAME "XXX.YYY.ZZZ.XYZ" #define RTEMS_TFTP_TEST_FILE_NAME "tftptest" #endif /* * For NFS test application * * NFS server/path to mount and a directory to ls once mounted */ #define RTEMS_NFS_SERVER "192.168.1.210" #define RTEMS_NFS_SERVER_PATH "/home" #define RTEMS_NFS_LS_PATH "/mnt/nfstest" #endif /* _RTEMS_NETWORKCONFIG_H_ */ adasockets-v1.14/examples/stream_listener.adb000066400000000000000000000107611454340372400214470ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S T R E A M _ L I S T E N E R -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Stream_IO; use Sockets, Sockets.Stream_IO; procedure Stream_Listener is -- Usage: stream_listener port -- Example: stream_listener 5000 -- then stream_sender localhost 5000 task type Echo is entry Start (FD : Socket_FD); end Echo; ---------- -- Echo -- ---------- task body Echo is Sock : Socket_FD; Stream : aliased Socket_Stream_Type; begin select accept Start (FD : Socket_FD) do Sock := FD; Initialize (Stream, Sock); end Start; or terminate; end select; loop Put_Line ("I received: " & String'Input (Stream'Access)); end loop; exception when Connection_Closed => Put_Line ("Connection closed"); Shutdown (Sock, Both); end Echo; Accepting_Socket : Socket_FD; Incoming_Socket : Socket_FD; type Echo_Access is access Echo; Dummy : Echo_Access; begin if Argument_Count /= 1 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " port"); end if; Socket (Accepting_Socket, PF_INET, SOCK_STREAM); Setsockopt (Accepting_Socket, SOL_SOCKET, SO_REUSEADDR, 1); Bind (Accepting_Socket, Positive'Value (Argument (1))); Listen (Accepting_Socket); loop Put_Line ("Waiting for new connection"); Accept_Socket (Accepting_Socket, Incoming_Socket); Put_Line ("New connection acknowledged"); Dummy := new Echo; Dummy.Start (Incoming_Socket); end loop; end Stream_Listener; adasockets-v1.14/examples/stream_sender.adb000066400000000000000000000075021454340372400211010ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S T R E A M _ S E N D E R -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Stream_IO; use Sockets, Sockets.Stream_IO; procedure Stream_Sender is -- Usage: stream_sender remotehost remoteport -- Example: stream_sender localhost 5000 Outgoing_Socket : Socket_FD; Stream : aliased Socket_Stream_Type; Line : String (1 .. 200); Last : Natural; begin if Argument_Count /= 2 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " remotehost remoteport"); end if; Socket (Outgoing_Socket, PF_INET, SOCK_STREAM); Connect (Outgoing_Socket, Argument (1), Positive'Value (Argument (2))); Initialize (Stream, Outgoing_Socket); loop Put ("Type a string> "); Flush; Get_Line (Line, Last); String'Output (Stream'Access, Line (Line'First .. Last)); end loop; exception when End_Error => null; end Stream_Sender; adasockets-v1.14/examples/tcprelay.adb000066400000000000000000000114711454340372400200710ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- T C P R E L A Y -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets; use Sockets; procedure TCPRelay is -- Usage: tcprelay localport remotehost remoteport -- Example: tcprelay 5000 localhost 25, -- then telnet localhost 5000 task type Relay is entry Start (From, To : Socket_FD); end Relay; ----------- -- Relay -- ----------- task body Relay is From_FD, To_FD : Socket_FD; begin select accept Start (From, To : Socket_FD) do From_FD := From; To_FD := To; end Start; or terminate; end select; loop Send (To_FD, Receive (From_FD)); end loop; exception when Connection_Closed => Put_Line ("Connection closed"); Shutdown (From_FD, Receive); Shutdown (To_FD, Send); end Relay; Accepting_Socket, Incoming_Socket, Outgoing_Socket : Socket_FD; type Relay_Access is access Relay; Dummy : Relay_Access; begin if Argument_Count /= 3 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " localport remotehost remoteport"); end if; Socket (Accepting_Socket, PF_INET, SOCK_STREAM); Setsockopt (Accepting_Socket, SOL_SOCKET, SO_REUSEADDR, 1); Bind (Accepting_Socket, Positive'Value (Argument (1))); Listen (Accepting_Socket); loop Put_Line ("Waiting for new connection"); Accept_Socket (Accepting_Socket, Incoming_Socket); Put_Line ("New connection acknowledged"); Socket (Outgoing_Socket, PF_INET, SOCK_STREAM); Put_Line ("Connecting to remote host"); Connect (Outgoing_Socket, Argument (2), Positive'Value (Argument (3))); Put_Line ("Connection established"); Dummy := new Relay; Dummy.Start (Incoming_Socket, Outgoing_Socket); Dummy := new Relay; Dummy.Start (Outgoing_Socket, Incoming_Socket); end loop; end TCPRelay; adasockets-v1.14/flake.lock000066400000000000000000000027211454340372400157120ustar00rootroot00000000000000{ "nodes": { "flake-utils": { "inputs": { "systems": "systems" }, "locked": { "lastModified": 1701680307, "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "owner": "numtide", "repo": "flake-utils", "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { "lastModified": 1703625305, "narHash": "sha256-siq0PKYsQ/RUPUKnuvq8nzZNEu12kMnWVaXBqLpRMY4=", "owner": "nixos", "repo": "nixpkgs", "rev": "719483f4a866418d5ef889adbe11553828167ce7", "type": "github" }, "original": { "owner": "nixos", "ref": "master", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, "systems": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "owner": "nix-systems", "repo": "default", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { "owner": "nix-systems", "repo": "default", "type": "github" } } }, "root": "root", "version": 7 } adasockets-v1.14/flake.nix000066400000000000000000000016401454340372400155570ustar00rootroot00000000000000{ description = "BSD sockets for Ada"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/master"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; in { packages.default = pkgs.stdenv.mkDerivation { name = "adasockets"; src = self; nativeBuildInputs = with pkgs; [ autoreconfHook gnat autoconf automake libtool gnum4 texinfo texlive.combined.scheme-small autogen pre-commit makeWrapper ]; configureFlags = [ "--disable-examples" "--disable-tests" ]; postInstall = '' wrapProgram $out/bin/adasockets-config \ --prefix PATH : ${pkgs.pkg-config}/bin \ --prefix PKG_CONFIG_PATH : $out/lib/pkgconfig ''; }; }); } adasockets-v1.14/man/000077500000000000000000000000001454340372400145275ustar00rootroot00000000000000adasockets-v1.14/man/Makefile.am000066400000000000000000000000701454340372400165600ustar00rootroot00000000000000man_MANS = adasockets-config.1 EXTRA_DIST = ${man_MANS} adasockets-v1.14/man/adasockets-config.1000066400000000000000000000006511454340372400201770ustar00rootroot00000000000000'\" t .TH adasockets-config 1 "18 March 2010" .SH NAME adasockets-config \- script to get information about the installed AdaSockets library .SH SYNOPSIS .B adasockets-config [\-\-version] [\-\-libs] [\-\-cflags] .SH DESCRIPTION .B adasockets-config will echo a line on standard output with appropriate flags for .B gnatmake . .SH "SEE ALSO" .BR gnatmake (1), .BR pkg-config (1) .SH AUTHORS Samuel Tardieu adasockets-v1.14/rtems/000077500000000000000000000000001454340372400151065ustar00rootroot00000000000000adasockets-v1.14/rtems/ChangeLog000066400000000000000000000010051454340372400166540ustar00rootroot000000000000002007-09-11 Joel Sherrill * .cvsignore: Add more to ignore. 2007-09-11 Joel Sherrill * README: Move instructions to top level README.RTEMS. * Makefile.RTEMS: New file. * Makefile.constants: Removed. 2007-09-11 Joel Sherrill * .cvsignore: New file. 2007-09-11 Joel Sherrill * ChangeLog, Makefile.constants, README, create_constants_c.sh, rtems_main.c, sockets-constants-rtems.ads: New files. adasockets-v1.14/rtems/Makefile.RTEMS000066400000000000000000000016051454340372400174410ustar00rootroot00000000000000# # Makefile.constants # # Build the constants.exe program that MUST be run on an RTEMS target. # It should be able to be ANY target including a simulator since the # constants in question should be the same across all architectures # and BSPs # # $Id: Makefile.RTEMS,v 1.1 2007/09/11 15:12:56 joel Exp $ # # # RTEMS_MAKEFILE_PATH is typically set in an environment variable # or make is invoked like "RTEMS_MAKEFILE_PATH=XXX make" # # optional managers required MANAGERS=all # C source names COBJS = ${ARCH}/rtems_main.o ${ARCH}/constants.o include $(RTEMS_MAKEFILE_PATH)/Makefile.inc include $(RTEMS_CUSTOM) include $(PROJECT_ROOT)/make/leaf.cfg CLEAN_ADDITIONS += constants.c OBJS= $(COBJS) all: $(ARCH)/constants.exe $(ARCH)/constants.exe: $(ARCH) $(OBJS) $(make-exe) constants.c: create_constants_c.sh ../vms/constants.list sh ./create_constants_c.sh ../vms/constants.list $@ adasockets-v1.14/rtems/README000066400000000000000000000037061454340372400157740ustar00rootroot00000000000000# # $Id: README,v 1.2 2007/09/11 15:12:57 joel Exp $ # This directory contains the support files for building the sockets-constants.ads file for RTEMS. See the README.RTEMS in the top level directory for complete build instructions. Prerequisites ============= Build and install a working GNAT/RTEMS toolset and a BSP. Make sure networking and POSIX are enabled. Detailed instructions are available online in the RTEMS Wiki at: http://www.rtems.org/wiki/index.php/RTEMSAda Run at least one sample from the RTEMS build (e.g. hello.exe or sample.exe) to confirm that RTEMS itself was properly built. Build and run the RTEMS hello_world_ada from the ada-examples package using your GNAT/RTEMS development environment. If everything is working at this point, then you are ready to build Ada Sockets. Generate sockets-constants-ads ============================== We will use the RTEMS you installed to build and run a program called "constants.exe". The output of this program needs to be saved as sockets-constants.ads. To compile this program use the Makefile.constants. RTEMS_MAKEFILE_PATH=install_patch_of_BSP \ make -f Makefile.constants Then run the program o-optimize/constants.exe on the target hardware. Your saved target board output may end up with DOS style CR/LF's. Run "dos2unix" on the file to get it back to Unix style. There is a version of this file generated using psim using a pre-4.8 CVS snapshot of RTEMS which should work on any target. You can use this but you would be safer to generate your own. Consider it an example of how it should look when it works. Building Ada Sockets ==================== Now that you have a sockets-constants.ads, we can build the Ada Sockets library. Makefile.adasockets is provided for this step: RTEMS_MAKEFILE_PATH=install_patch_of_BSP \ make -f Makefile.lib After the library is compiled, it may be installed using the following: RTEMS_MAKEFILE_PATH=install_patch_of_BSP \ make -f Makefile.lib install adasockets-v1.14/rtems/create_constants_c.sh000066400000000000000000000042141454340372400213040ustar00rootroot00000000000000#! /bin/sh # # # This script completes the constants.c_pre file with the # the list of defines needed to build the adasockets constant # package. # # This file is part of Adasockets for RTEMS. # if [ $# -ne 2 ] ; then echo $0: constantsFile outputFile exit 1 fi constantListFile=$1 outputFile=$2 cat >${outputFile} < #include #include #include #include #include #include #include #include #include #include #include #include #include static char * capitalize (char *name) { int beginning = 1; char *result = (char *) malloc (strlen (name) + 1); char *ptr; for (ptr = result; *name; ptr++, name++) { *ptr = *name; if (beginning) { beginning = 0; } else if (*ptr == '_') { beginning = 1; } else if (isupper(*ptr)) { *ptr = tolower(*ptr); } } *ptr = '\0'; return result; } static void output (char *name, int value) { char *capitalized = capitalize (name); if (value != -1) { printf (" %-20s : constant := 16#%04X#;\n", capitalized, value); } else { printf (" %-20s : constant := %d;\n", capitalized, value); } } void print_body(void); void print_socket_constants_ads( void ) { printf( "-- This file has been generated automatically by\n" "-- the constants.c file generated by create_constants_c.sh.\n" "--\n" "-- This file is part of adasockets port to RTEMS.\n" "--\n" "\n" "package sockets.constants is\n" ); print_body(); printf( "end sockets.constants;\n"); } void print_body() { EOF # # Now generate the body of the function that acr # while read line do echo "#ifdef ${line}" echo " output( \"${line}\", ${line});" echo "#else" echo " output( \"${line}\", -1);" echo "#endif" done < ${constantListFile} >>${outputFile} echo "}" >>${outputFile} exit 0 adasockets-v1.14/rtems/rtems_main.c000066400000000000000000000010041454340372400174030ustar00rootroot00000000000000/* * Simple test program -- simplified version of sample test hello. */ #include #include #include rtems_task Init( rtems_task_argument ignored ) { extern void print_socket_constants_ads( void ); print_socket_constants_ads(); exit( 0 ); } /* configuration information */ #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_INIT #include /* end of file */ adasockets-v1.14/rtems/sockets-constants-rtems.ads000066400000000000000000000073421454340372400224220ustar00rootroot00000000000000-- This file has been generated automatically by -- the constants.c file generated by create_constants_c.sh. -- -- This file is part of adasockets port to RTEMS. -- package sockets.constants is Tcp_Nodelay : constant := 16#0001#; Af_Inet : constant := 16#0002#; Af_Unix : constant := 16#0001#; Sock_Stream : constant := 16#0001#; Sock_Dgram : constant := 16#0002#; Eintr : constant := 16#0004#; Eagain : constant := 16#000B#; Ewouldblock : constant := 16#000B#; Einprogress : constant := 16#0077#; Ealready : constant := 16#0078#; Eisconn : constant := 16#007F#; Econnrefused : constant := 16#006F#; Fndelay : constant := 16#4000#; Fasync : constant := 16#0040#; Fioasync : constant := 16#8004667D#; F_Getfl : constant := 16#0003#; F_Setfl : constant := 16#0004#; F_Setown : constant := 16#0006#; Fiossaioown : constant := -1; So_Rcvbuf : constant := 16#1002#; So_Reuseaddr : constant := 16#0004#; So_Reuseport : constant := -1; Sol_Socket : constant := 16#FFFF#; Sigterm : constant := 16#000F#; Sigkill : constant := 16#0009#; O_Rdonly : constant := 16#0000#; O_Wronly : constant := 16#0001#; O_Rdwr : constant := 16#0002#; Host_Not_Found : constant := 16#0001#; Try_Again : constant := 16#0002#; No_Recovery : constant := 16#0003#; No_Data : constant := 16#0004#; No_Address : constant := 16#0004#; Pollin : constant := -1; Pollpri : constant := -1; Pollout : constant := -1; Pollerr : constant := -1; Pollhup : constant := -1; Pollnval : constant := -1; I_Setsig : constant := -1; S_Rdnorm : constant := -1; S_Wrnorm : constant := -1; Ipproto_Ip : constant := 16#0000#; Ip_Add_Membership : constant := 16#000C#; Ip_Multicast_Loop : constant := 16#000B#; Ip_Multicast_Ttl : constant := 16#000A#; Ip_Drop_Membership : constant := 16#000D#; O_Nonblock : constant := 16#4000#; Msg_Peek : constant := 16#0002#; Fionbio : constant := 16#8004667E#; Fionread : constant := 16#4004667F#; So_Sndbuf : constant := 16#1001#; Af_Inet6 : constant := 16#001C#; Ai_Addrconfig : constant := -1; Ai_All : constant := -1; Ai_Canonname : constant := -1; Ai_Default : constant := -1; Ai_Mask : constant := -1; Ai_Numerichost : constant := -1; Ai_Passive : constant := -1; Ai_V4mapped : constant := -1; Ai_V4mapped_Cfg : constant := -1; Ni_Dgram : constant := -1; Ni_Maxhost : constant := -1; Ni_Maxserv : constant := -1; Ni_Namereqd : constant := -1; Ni_Nofqdn : constant := -1; Ni_Numerichost : constant := -1; Ni_Numericserv : constant := -1; Ni_Withscopeid : constant := -1; Ipproto_Ipv6 : constant := 16#0029#; Ipv6_Unicast_Hops : constant := -1; Ipv6_Multicast_If : constant := -1; Ipv6_Multicast_Hops : constant := -1; Ipv6_Multicast_Loop : constant := -1; Ipv6_Join_Group : constant := -1; Ipv6_Leave_Group : constant := -1; end sockets.constants; adasockets-v1.14/src/000077500000000000000000000000001454340372400145435ustar00rootroot00000000000000adasockets-v1.14/src/Makefile.RTEMS000066400000000000000000000034241454340372400170770ustar00rootroot00000000000000# # Makefile.RTEMS # # Build the Ada Sockets packages for a SPECIFIC RTEMS BSP. # This Makefile should work for any RTEMS BSP as long as # it is installed and you set RTEMS_MAKEFILE_PATCH appropriately. # # RTEMS_MAKEFILE_PATH is typically set in an environment variable # or make is invoked like "RTEMS_MAKEFILE_PATH=XXX make" # # $Id: Makefile.RTEMS,v 1.1 2007/09/11 22:38:24 joel Exp $ # # # .PHONY: all distclean clean .DEFAULT: all include $(RTEMS_MAKEFILE_PATH)/Makefile.inc include $(RTEMS_CUSTOM) include $(PROJECT_ROOT)/make/leaf.cfg # RTEMS specific files that are generated by copy or sed RTEMS_FILES=\ sockets-types.ads\ sockets-thin.ads\ sockets-link.ads\ sockets-constants.ads FILES= sockets-multicast.adb\ sockets-naming.adb\ sockets-stream_io.adb\ sockets-utils.adb\ sockets.adb\ $(RTEMS_FILES) ADS_OBJ=$(patsubst %.ads, %.o, $(filter %.ads, $(FILES))) ADB_OBJ=$(patsubst %.adb, %.o, $(filter %.adb, $(FILES))) # These get removed by RTEMS clean and distclean rules CLEAN_ADDITIONS+= *.ali *.o b$*.* $(RTEMS_FILES) all: $(FILES) $(ADB_OBJ) $(ADS_OBJ) sockets-types.ads: sockets-types.ads.in Makefile.RTEMS sed -e 's/^@SA_LEN@//' \ -e '/@NO_SA_LEN@/d' <$< >$@ sockets-link.ads: sockets-link.ads.in Makefile.RTEMS sed -e '/@WINNEEDED@/d' \ -e '/@NSLNEEDED@/d' \ -e '/@SOCKETNEEDED@/d' \ -e '/@RESOLVNEEDED@/d' $< >$@ sockets-thin.ads: sockets-thin.ads.unix cp -p $< $@ sockets-constants.ads: ../rtems/sockets-constants.ads cp -p $< $@ $(ADB_OBJ): %.o: %.adb $(CC) $(CPU_CFLAGS) $(CFLAGS)-c $< $(ADS_OBJ): %.o: %.ads $(CC) $(CPU_CFLAGS) $(CFLAGS)-c $< # Install this with the BSP the user has specified with RTEMS_MAKEFILE_PATH install: $(INSTALL_VARIANT) $(FILES) $(ADS_OBJ) $(ADB_OBJ) $(PROJECT_RELEASE)/lib/include/adainclude adasockets-v1.14/src/Makefile.VMS000066400000000000000000000022571454340372400166550ustar00rootroot00000000000000# Makefile for OpenVMS (GNU Make) # # $Revision$ # # # This file is part of adasockets port to OpenVMS # .PHONY: all distclean clean .DEFAULT: all FILES= sockets-thin.adb\ sockets-multicast.adb\ sockets-naming.adb\ sockets-stream_io.adb\ sockets-utils.adb\ sockets.adb\ sockets-constants.ads\ sockets-vms_link.ads\ sockets-link.ads VMS_FILES=\ sockets-thin.adb\ sockets-thin.ads\ sockets-link.ads\ sockets-constants.ads ADS_OBJ=$(patsubst %.ads, %.obj, $(filter %.ads, $(FILES))) ADB_OBJ=$(patsubst %.adb, %.obj, $(filter %.adb, $(FILES))) all: $(VMS_FILES) $(FILES) $(ADB_OBJ) $(ADS_OBJ) sockets-thin.adb: copy/log sockets-thin.adb_vms sockets-thin.adb sockets-thin.ads: copy/log sockets-thin.ads_vms sockets-thin.ads sockets-link.ads: copy/log sockets-link.ads_vms sockets-link.ads sockets-constants.ads: make "-C" [-.vms] -f Makefile.VMS all copy/log [-.vms]sockets-constants.ads [-.src]*.* $(ADB_OBJ): %.obj: %.adb gnat comp /debug $< $(ADS_OBJ): %.obj: %.ads gnat comp /debug $< distclean: del/noconf/log *.ali;*, *.obj;*, b$*.*;*, sockets-link.ads;* del/noconf/log sockets-thin.ads;*, sockets-thin.adb;* del/noconf/log sockets-constants.ads;* clean: adasockets-v1.14/src/Makefile.am000066400000000000000000000106441454340372400166040ustar00rootroot00000000000000CCLD = $(CC) bin_SCRIPTS = adasockets-config lib_LTLIBRARIES = libadasockets.la dist_libadasockets_la_SOURCES = \ sockets-multicast.ads \ sockets-multicast.adb \ sockets-naming.ads \ sockets-naming.adb \ sockets-stream_io.ads \ sockets-stream_io.adb \ sockets-utils.ads \ sockets-utils.adb \ sockets.ads \ sockets.adb nodist_libadasockets_la_SOURCES = \ sockets-thin.ads \ sockets-constants.ads \ sockets-link.ads \ sockets-types.ads libadasockets_la_LDFLAGS = -version-info $(LIBVERSIONINFO) EXTRA_DIST = Makefile.RTEMS Makefile.VMS sockets-vms_link.ads \ sockets-windows_link.ads sockets-windows_link.adb \ sockets-link.ads.vms \ sockets-thin.adb.vms sockets-thin.adb.win32 \ sockets-thin.ads.unix sockets-thin.ads.vms sockets-thin.ads.win32 \ constants.c constants.sh \ adasockets-config ADA_OBJECTS = \ sockets-constants.o \ sockets-link.o \ sockets-multicast.o \ sockets-naming.o \ sockets-stream_io.o \ sockets-thin.o \ sockets-types.o \ sockets-utils.o \ sockets.o ALIS = $(ADA_OBJECTS:.o=.ali) ADACOMPILER = $(top_srcdir)/support/adacompiler ADAFLAGS = @ADAFLAGS@ -I. -I$(srcdir) CLEANFILES = *.o *.ali b~* DISTCLEANFILES = sockets-thin.ads sockets-thin.adb sockets-constants.ads constants: $(srcdir)/constants.c constants-inc.c $(CC) -I. -o constants $(srcdir)/constants.c $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) constants-inc.c: $(srcdir)/constants.sh $(SHELL) $(srcdir)/constants.sh sockets-constants.ads: constants ./constants > sockets-constants.ads pkgconfigexecdir = $(libdir)/pkgconfig pkgconfigexec_DATA = adasockets.pc if WIN32 nodist_libadasockets_la_SOURCES += \ sockets-windows_link.ads sockets-windows_link.adb \ sockets-thin.adb ADA_OBJECTS += sockets-windows_link.o sockets-thin.ads: $(srcdir)/sockets-thin.ads.win32 cp -p $(srcdir)/sockets-thin.ads.win32 sockets-thin.ads cp -p $(srcdir)/sockets-thin.adb.win32 sockets-thin.adb else sockets-thin.ads: $(srcdir)/sockets-thin.ads.unix cp -p -f $(srcdir)/sockets-thin.ads.unix sockets-thin.ads endif SUFFIXES = .ads .lo .ali .ads.lo: if [ -f `echo $< | sed -e 's/s$$/b/'` ]; then \ $(LIBTOOL) --tag=CC --mode=compile \ $(ADACOMPILER) $(GNATMAKE) -cargs $(ADAFLAGS) -largs $(LDFLAGS) -margs \ `echo $< | sed -e 's/s$$/b/'`; \ else \ $(LIBTOOL) --tag=CC --mode=compile \ $(ADACOMPILER) $(GNATMAKE) -cargs $(ADAFLAGS) -largs $(LDFLAGS) -margs $<; \ fi .lo.ali: # ./configure would not substitute ${prefix} in the project. install-exec-local: all rm -fr $(DESTDIR)$(ada_src_install_dir)/adasockets \ $(DESTDIR)$(ali_install_dir)/adasockets $(mkinstalldirs) \ $(DESTDIR)$(ada_src_install_dir)/adasockets \ $(DESTDIR)$(ali_install_dir)/adasockets \ $(DESTDIR)$(gpr_install_dir) $(INSTALL) -m 444 $(ALIS) $(DESTDIR)$(ali_install_dir)/adasockets for i in $(dist_libadasockets_la_SOURCES) $(nodist_libadasockets_la_SOURCES); do \ if test -f $$i; then \ $(INSTALL) -m 644 $$i $(DESTDIR)$(ada_src_install_dir)/adasockets; \ else \ $(INSTALL) -m 644 $(srcdir)/$$i $(DESTDIR)$(ada_src_install_dir)/adasockets; \ fi \ done sed -e 's|@libdir[@]|$(libdir)|' \ -e 's|@ada_src_install_dir[@]|$(ada_src_install_dir)|' \ -e 's|@ali_install_dir[@]|$(ali_install_dir)|' \ $(srcdir)/adasockets.gpr.in > $(DESTDIR)$(gpr_install_dir)/adasockets.gpr chmod 644 $(DESTDIR)$(gpr_install_dir)/adasockets.gpr uninstall-local: rm -fr $(DESTDIR)$(ada_src_install_dir)/adasockets \ $(DESTDIR)$(ali_install_dir)/adasockets rm -f $(DESTDIR)$(gpr_install_dir)/adasockets.gpr ### DO NOT REMOVE THIS LINE, IT IS USED BY MAKEDEPEND ### sockets-multicast.lo : sockets.ads sockets.adb sockets-constants.ads \ sockets-link.ads sockets-multicast.ads sockets-multicast.adb \ sockets-naming.ads sockets-thin.ads sockets-types.ads sockets-utils.ads sockets.lo : sockets.ads sockets.adb sockets-constants.ads sockets-link.ads \ sockets-naming.ads sockets-thin.ads sockets-types.ads sockets-utils.ads sockets-constants.lo : sockets.ads sockets-constants.ads sockets-naming.lo : sockets.ads sockets-constants.ads sockets-naming.ads \ sockets-naming.adb sockets-thin.ads sockets-types.ads sockets-utils.ads sockets-thin.lo : sockets.ads sockets-thin.ads sockets-types.ads sockets-types.lo : sockets.ads sockets-types.ads sockets-utils.lo : sockets.ads sockets-thin.ads sockets-types.ads \ sockets-utils.ads sockets-utils.adb sockets-link.lo : sockets.ads sockets-link.ads sockets-stream_io.lo : sockets.ads sockets-stream_io.ads sockets-stream_io.adb adasockets-v1.14/src/adasockets-config000066400000000000000000000002301454340372400200450ustar00rootroot00000000000000#! /bin/sh # if [ "x$1" = "x--version" ]; then set -- --modversion elif [ "x$1" = "x" ]; then set -- --cflags --libs fi pkg-config adasockets "$@" adasockets-v1.14/src/adasockets.gpr.in000066400000000000000000000004721454340372400200060ustar00rootroot00000000000000library project Adasockets is for Library_Name use "adasockets"; for Library_Kind use "relocatable"; for Library_Dir use "@libdir@"; for Source_Dirs use ("@ada_src_install_dir@/adasockets"); for Library_ALI_Dir use "@ali_install_dir@/adasockets"; for Externally_Built use "true"; end Adasockets; adasockets-v1.14/src/adasockets.pc.in000066400000000000000000000004141454340372400176140ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE@ Description: BSD sockets in Ada. Requires: Version: @VERSION@ Libs: -L${libdir} -ladasockets Cflags: -aI@ada_src_install_dir@/adasockets -aO@ali_install_dir@/adasockets adasockets-v1.14/src/constants.c000066400000000000000000000060671454340372400167340ustar00rootroot00000000000000/* * This program must be called with the constant name as the CONSTANT_NAME * define. If this is not the case, then a generic version which takes a * symbol to undefine as the first argument will be built. */ #include #ifdef HAVE_SYS_CONF_H #ifdef HAVE_SYS_PARAM_H #include #endif #ifdef HAVE_TIME_H #include #endif #include #endif #ifdef HAVE_SYS_FILE_H #include #endif #ifdef HAVE_SYS_IOCTL_H #include #endif #ifdef HAVE_SYS_SOCKET_H #include #endif #ifdef HAVE_SYS_SYSTEMINFO_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_NETDB_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_NETINET_TCP_H #include #endif #ifdef HAVE_POLL_H #include #endif #ifdef HAVE_SIGNAL_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STROPTS_H #include #endif #ifdef HAVE_TERMIO_H #include #endif #ifdef HAVE_TERMIOS_H #include #endif #ifdef HAVE_LINUX_SOCKIOS_H #include #endif #ifdef HAVE_WINDOWS_H #define Win32_Winsock #include /* This directive is checked only for mingw32 2.8.1 */ #if (_WIN32_WINNT >= 0x0400) #include #endif /* Absent declarations */ #define POLLIN 1 #define POLLPRI 2 #define POLLOUT 4 /* Undefine cygwin specific declarations to replace them */ #undef EINTR #undef EWOULDBLOCK #undef EINPROGRESS #undef EALREADY #undef EISCONN #undef ECONNREFUSED /* Replace with Windows sockets declaration */ #define EINTR WSAEINTR #define EWOULDBLOCK WSAEWOULDBLOCK #define EINPROGRESS WSAEINPROGRESS #define EALREADY WSAEALREADY #define EISCONN WSAEISCONN #define ECONNREFUSED WSAECONNREFUSED #endif #include static char *capitalize(char *name) { int beginning = 1; char *result = (char *)malloc(strlen(name) + 1); char *ptr; for (ptr = result; *name; ptr++, name++) { *ptr = *name; if (beginning) { beginning = 0; } else if (*ptr == '_') { beginning = 1; } else if (isupper(*ptr)) { *ptr = tolower(*ptr); } } *ptr = '\0'; return result; } #define OUTPUT(name, value) \ if (value == -1) { \ printf(" %-20s : constant := -1;\n", capitalize(name)); \ } else { \ printf(" %-20s : constant := 16#%04X#;\n", capitalize(name), value); \ } int main() { printf("-- This package has been generated automatically.\n"); printf("-- Any change you make here is likely to be lost !\n"); printf("package Sockets.Constants is\n"); #include "constants-inc.c" printf("end Sockets.Constants;\n"); exit(0); } adasockets-v1.14/src/constants.sh000066400000000000000000000043031454340372400171130ustar00rootroot00000000000000#!/bin/sh # # This file generates the constants-inc.c file. # List of constants we need to know constants="TCP_NODELAY AF_INET AF_UNIX SOCK_STREAM SOCK_DGRAM EINTR EAGAIN" constants="${constants} EWOULDBLOCK EINPROGRESS EALREADY EISCONN" constants="${constants} ECONNREFUSED FNDELAY FASYNC-FIOASYNC F_GETFL F_SETFL" constants="${constants} F_SETOWN-FIOSSAIOOWN SO_RCVBUF SO_REUSEADDR" constants="${constants} SO_REUSEPORT" constants="${constants} SOL_SOCKET SIGTERM SIGKILL O_RDONLY O_WRONLY" constants="${constants} O_RDWR HOST_NOT_FOUND TRY_AGAIN NO_RECOVERY" constants="${constants} NO_DATA NO_ADDRESS POLLIN POLLPRI POLLOUT POLLERR" constants="${constants} POLLHUP POLLNVAL I_SETSIG S_RDNORM S_WRNORM" constants="${constants} IPPROTO_IP IP_ADD_MEMBERSHIP IP_MULTICAST_LOOP" constants="${constants} IP_MULTICAST_TTL IP_DROP_MEMBERSHIP" constants="${constants} O_NONBLOCK MSG_PEEK FIONBIO FIONREAD SO_SNDBUF" constants="${constants} SOL_TCP SO_KEEPALIVE TCP_KEEPCNT TCP_KEEPIDLE TCP_KEEPINTVL" constants="${constants} SO_NOSIGPIPE MSG_NOSIGNAL" # ipv6 constants="${constants} AF_INET6" # Constants for protocol independent nodename-address translations constants="${constants} AI_ADDRCONFIG AI_ALL AI_CANONNAME" constants="${constants} AI_DEFAULT AI_MASK AI_NUMERICHOST" constants="${constants} AI_PASSIVE AI_V4MAPPED AI_V4MAPPED_CFG" constants="${constants} NI_DGRAM NI_MAXHOST NI_MAXSERV" constants="${constants} NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST" constants="${constants} NI_NUMERICSERV NI_WITHSCOPEID" # setsockopt constants="${constants} IPPROTO_IPV6" constants="${constants} IPV6_UNICAST_HOPS IPV6_MULTICAST_IF" constants="${constants} IPV6_MULTICAST_HOPS IPV6_MULTICAST_LOOP" constants="${constants} IPV6_JOIN_GROUP IPV6_LEAVE_GROUP" # ioctl constants="${constants} SIOCINQ SIOCOUTQ" # For each constant, try to output its value or -1 if undefined for c in ${constants}; do OIFS=${IFS}; IFS="-"; set ${c}; IFS=${OIFS}; echo "#if defined($1)" echo " OUTPUT(\"$1\", $1);" if [ -n "$2" ]; then echo "#elif defined $2" echo " OUTPUT(\"$1\", $1);" fi echo "#else" echo "OUTPUT(\"$1\", -1);" echo "#endif" done > constants-inc.c adasockets-v1.14/src/header.txt000066400000000000000000000051441454340372400165400ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- XXXXX -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- adasockets-v1.14/src/sockets-link.ads.in000066400000000000000000000061611454340372400202530ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . L I N K -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- @WINNEEDED@with Sockets.Windows_Link; @WINNEEDED@pragma Elaborate (Sockets.Windows_Link); private package Sockets.Link is @NSLNEEDED@pragma Linker_Options ("-lnsl"); @SOCKETNEEDED@pragma Linker_Options ("-lsocket"); @RESOLVNEEDED@pragma Linker_Options ("-lresolv"); end Sockets.Link; adasockets-v1.14/src/sockets-link.ads.vms000066400000000000000000000056241454340372400204550ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . L I N K -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Sockets.VMS_Link; private package Sockets.Link is end Sockets.Link; adasockets-v1.14/src/sockets-multicast.adb000066400000000000000000000173161454340372400207010ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . M U L T I C A S T -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Exceptions; use Ada.Exceptions; with Interfaces.C; use Interfaces.C; with Sockets.Constants; use Sockets.Constants; with Sockets.Naming; use Sockets.Naming; with Sockets.Thin; use Sockets.Thin; with Sockets.Types; use Sockets.Types; with Sockets.Utils; use Sockets.Utils; pragma Elaborate_All (Sockets); package body Sockets.Multicast is use Ada.Streams; procedure Setsockopt_Add_Membership is new Customized_Setsockopt (IPPROTO_IP, IP_ADD_MEMBERSHIP, Ip_Mreq); function Create_Multicast_Socket (Group : String; Port : Natural; Local_Port : Natural; TTL : Positive := 16; Self_Loop : Boolean := True; Local_If : String := "0.0.0.0") return Multicast_Socket_FD; ----------------------------- -- Create_Multicast_Socket -- ----------------------------- function Create_Multicast_Socket (Group : String; Port : Natural; Local_Port : Natural; TTL : Positive := 16; Self_Loop : Boolean := True; Local_If : String := "0.0.0.0") return Multicast_Socket_FD is Result : Multicast_Socket_FD; Mreq : aliased Ip_Mreq; C_Self_Loop : Integer; begin Socket (Socket_FD (Result), PF_INET, SOCK_DGRAM); if Self_Loop then C_Self_Loop := 1; else C_Self_Loop := 0; end if; Setsockopt (Result, SOL_SOCKET, SO_REUSEADDR, 1); pragma Warnings (Off); -- Statically determined if Constants.So_Reuseport /= -1 then Setsockopt (Result, SOL_SOCKET, SO_REUSEPORT, 1); end if; pragma Warnings (On); Bind (Result, Local_Port); Mreq.Imr_Multiaddr := To_In_Addr (Address_Of (Group)); Mreq.Imr_Interface := To_In_Addr (Address_Of (Local_If)); Setsockopt_Add_Membership (Result, Mreq); Setsockopt (Result, IPPROTO_IP, IP_MULTICAST_TTL, TTL); Setsockopt (Result, IPPROTO_IP, IP_MULTICAST_LOOP, C_Self_Loop); Result.Target.Sin_Family := Constants.Af_Inet; if Port /= 0 then Result.Target.Sin_Port := Port_To_Network (unsigned_short (Port)); else Result.Target.Sin_Port := Port_To_Network (unsigned_short (Get_Sock_Port (Socket_FD (Result)))); end if; Result.Target.Sin_Addr := To_In_Addr (Address_Of (Group)); return Result; end Create_Multicast_Socket; ----------------------------- -- Create_Multicast_Socket -- ----------------------------- function Create_Multicast_Socket (Group : String; Port : Natural; TTL : Positive := 16; Self_Loop : Boolean := True; Local_If : String := "0.0.0.0") return Multicast_Socket_FD is begin return Create_Multicast_Socket (Group => Group, Port => Port, Local_Port => Port, TTL => TTL, Self_Loop => Self_Loop, Local_If => Local_If); end Create_Multicast_Socket; ----------------------------- -- Create_Multicast_Socket -- ----------------------------- function Create_Multicast_Socket (Group : String; Port : Positive; Local_Port : Natural; TTL : Positive := 16; Local_If : String := "0.0.0.0") return Multicast_Socket_FD is begin return Create_Multicast_Socket (Group => Group, Port => Port, Local_Port => Local_Port, TTL => TTL, Self_Loop => False, Local_If => Local_If); end Create_Multicast_Socket; ---------- -- Send -- ---------- procedure Send (Socket : Multicast_Socket_FD; Data : Stream_Element_Array) is Sin : aliased Sockaddr_In := Socket.Target; Index : Stream_Element_Offset := Data'First; Rest : Stream_Element_Count := Data'Length; Count : int; begin while Rest > 0 loop Count := C_Sendto (Socket.FD, Data (Index) 'Address, int (Rest), 0, Sin'Address, Sin'Size / 8); if Count < 0 then Raise_With_Message ("Send failed"); elsif Count = 0 then raise Connection_Closed; end if; Index := Index + Stream_Element_Count (Count); Rest := Rest - Stream_Element_Count (Count); end loop; end Send; ------------ -- Socket -- ------------ procedure Socket (Sock : out Multicast_Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM) is begin Raise_Exception (Program_Error'Identity, "Use Create_Multicast_Socket instead"); end Socket; end Sockets.Multicast; adasockets-v1.14/src/sockets-multicast.ads000066400000000000000000000107411454340372400207150ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . M U L T I C A S T -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Sockets.Types; package Sockets.Multicast is pragma Elaborate_Body; -- This package aims at helping the creation of multicast sockets type Multicast_Socket_FD is new Socket_FD with private; Null_Multicast_Socket_FD : constant Multicast_Socket_FD; function Create_Multicast_Socket (Group : String; Port : Natural; TTL : Positive := 16; Self_Loop : Boolean := True; Local_If : String := "0.0.0.0") return Multicast_Socket_FD; -- Create a multicast socket. If Port is 0, this will be a local -- socket with a system-chosen port. function Create_Multicast_Socket (Group : String; Port : Positive; Local_Port : Natural; TTL : Positive := 16; Local_If : String := "0.0.0.0") return Multicast_Socket_FD; -- Create a multicast socket that can only send data and is bound -- to the local port Local_Port. Use 0 if you do not care about -- the local port. procedure Send (Socket : Multicast_Socket_FD; Data : Ada.Streams.Stream_Element_Array); -- Send data over a multicast socket private procedure Socket (Sock : out Multicast_Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM); pragma No_Return (Socket); -- Do not call this one, it will raise Program_Error type Multicast_Socket_FD is new Socket_FD with record Target : Sockets.Types.Sockaddr_In; end record; Null_Multicast_Socket_FD : constant Multicast_Socket_FD := (Sockets.Null_Socket_FD with Target => Sockets.Types.Null_Sockaddr_In); end Sockets.Multicast; adasockets-v1.14/src/sockets-naming.adb000066400000000000000000000360721454340372400201450ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . N A M I N G -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Exceptions; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with Sockets.Constants; use Sockets.Constants; with Sockets.Thin; use Sockets.Thin; with Sockets.Types; use Sockets.Types; with Sockets.Utils; use Sockets.Utils; package body Sockets.Naming is function Is_IP_Address (Something : String) return Boolean renames Sockets.Utils.Is_IP_Address; Default_Buffer_Size : constant := 16384; procedure Free is new Ada.Unchecked_Deallocation (String, String_Access); procedure Free is new Ada.Unchecked_Deallocation (char_array, char_array_access); function Allocate (Size : Positive := Default_Buffer_Size) return char_array_access; -- Allocate a buffer function Parse_Entry (Host : Hostent) return Host_Entry; -- Parse an entry procedure Raise_Naming_Error (Errno : Integer; Message : String); -- Raise the exception Naming_Error with an appropriate error message protected Naming_Lock is entry Lock; procedure Unlock; private Locked : Boolean := False; end Naming_Lock; -- A locking object function Get_Peer (Socket : Socket_FD) return Sockaddr_In; function Get_Sock (Socket : Socket_FD) return Sockaddr_In; ---------------- -- Address_Of -- ---------------- function Address_Of (Something : String) return Address is begin if Is_IP_Address (Something) then return Value (Something); else return Info_Of (Something) .Addresses (1); end if; end Address_Of; ------------ -- Adjust -- ------------ procedure Adjust (Object : in out Host_Entry) is Aliases : String_Array renames Object.Aliases; begin Object.Name := new String'(Object.Name.all); for I in Aliases'Range loop Aliases (I) := new String'(Aliases (I) .all); end loop; end Adjust; -------------- -- Allocate -- -------------- function Allocate (Size : Positive := Default_Buffer_Size) return char_array_access is begin return new char_array (1 .. size_t (Size)); end Allocate; ----------------- -- Any_Address -- ----------------- function Any_Address return Address is begin return To_Address (Inaddr_Any); end Any_Address; -------------- -- Finalize -- -------------- procedure Finalize (Object : in out Host_Entry) is Aliases : String_Array renames Object.Aliases; begin Free (Object.Name); for I in Aliases'Range loop Free (Aliases (I)); end loop; end Finalize; -------------- -- Get_Peer -- -------------- function Get_Peer (Socket : Socket_FD) return Sockaddr_In is Name : aliased Sockaddr_In; Len : aliased int := Name'Size / 8; begin if C_Getpeername (Socket.FD, Name'Address, Len'Access) = Failure then Raise_Naming_Error (Errno, ""); end if; return Name; end Get_Peer; ------------------- -- Get_Peer_Addr -- ------------------- function Get_Peer_Addr (Socket : Socket_FD) return Types.In_Addr is begin return Get_Peer (Socket) .Sin_Addr; end Get_Peer_Addr; ------------------- -- Get_Peer_Addr -- ------------------- function Get_Peer_Addr (Socket : Socket_FD) return Address is begin return To_Address (Get_Peer_Addr (Socket)); end Get_Peer_Addr; ------------------- -- Get_Peer_Port -- ------------------- function Get_Peer_Port (Socket : Socket_FD) return Positive is begin return Positive (Network_To_Port (Get_Peer (Socket) .Sin_Port)); end Get_Peer_Port; -------------- -- Get_Sock -- -------------- function Get_Sock (Socket : Socket_FD) return Sockaddr_In is Name : aliased Sockaddr_In; Len : aliased int := Name'Size / 8; begin if C_Getsockname (Socket.FD, Name'Address, Len'Access) = Failure then Raise_Naming_Error (Errno, ""); end if; return Name; end Get_Sock; ------------------- -- Get_Sock_Addr -- ------------------- function Get_Sock_Addr (Socket : Socket_FD) return In_Addr is begin return Get_Sock (Socket) .Sin_Addr; end Get_Sock_Addr; ------------------- -- Get_Sock_Addr -- ------------------- function Get_Sock_Addr (Socket : Socket_FD) return Address is begin return To_Address (Get_Sock_Addr (Socket)); end Get_Sock_Addr; ------------------- -- Get_Sock_Port -- ------------------- function Get_Sock_Port (Socket : Socket_FD) return Positive is begin return Positive (Network_To_Port (Get_Sock (Socket) .Sin_Port)); end Get_Sock_Port; --------------- -- Host_Name -- --------------- function Host_Name return String is Buff : char_array_access := Allocate; Buffer : constant chars_ptr := To_Chars_Ptr (Buff); Res : constant int := C_Gethostname (Buffer, Buff'Length); begin if Res = Failure then Free (Buff); Raise_Naming_Error (Errno, ""); end if; declare Result : constant String := Value (Buffer); begin Free (Buff); return Result; end; end Host_Name; ----------- -- Image -- ----------- function Image (Add : Address) return String is function Image (A : Address_Component) return String; -- Return the string corresponding to its argument without -- the leading space. ----------- -- Image -- ----------- function Image (A : Address_Component) return String is Im : constant String := Address_Component'Image (A); begin return Im (Im'First + 1 .. Im'Last); end Image; begin return Image (Add.H1) & "." & Image (Add.H2) & "." & Image (Add.H3) & "." & Image (Add.H4); end Image; ----------- -- Image -- ----------- function Image (Add : Types.In_Addr) return String is begin return Image (To_Address (Add)); end Image; ------------- -- Info_Of -- ------------- function Info_Of (Name : String) return Host_Entry is Res : Hostent_Access; C_Name : chars_ptr := New_String (Name); begin Naming_Lock.Lock; Res := C_Gethostbyname (C_Name); Free (C_Name); if Res = null then Naming_Lock.Unlock; Raise_Naming_Error (Errno, Name); end if; declare Result : constant Host_Entry := Parse_Entry (Res.all); begin Naming_Lock.Unlock; return Result; end; end Info_Of; ------------- -- Info_Of -- ------------- function Info_Of (Addr : Address) return Host_Entry is function Convert is new Ada.Unchecked_Conversion (Source => In_Addr_Access, Target => chars_ptr); Temp : aliased In_Addr := To_In_Addr (Addr); C_Addr : constant chars_ptr := Convert (Temp'Unchecked_Access); Res : Hostent_Access; begin Naming_Lock.Lock; Res := C_Gethostbyaddr (C_Addr, int (Temp'Size / CHAR_BIT), Constants.Af_Inet); if Res = null then Naming_Lock.Unlock; Raise_Naming_Error (Errno, Image (Addr)); end if; declare Result : constant Host_Entry := Parse_Entry (Res.all); begin Naming_Lock.Unlock; return Result; end; end Info_Of; ------------------------ -- Info_Of_Name_Or_IP -- ------------------------ function Info_Of_Name_Or_IP (Something : String) return Host_Entry is begin if Is_IP_Address (Something) then return Info_Of (Value (Something)); else return Info_Of (Something); end if; end Info_Of_Name_Or_IP; ------------- -- Name_Of -- ------------- function Name_Of (Something : String) return String is Hostent : constant Host_Entry := Info_Of_Name_Or_IP (Something); begin if Hostent.Name = null then Ada.Exceptions.Raise_Exception (Naming_Error'Identity, "No name for " & Something); end if; return Hostent.Name.all; end Name_Of; ----------------- -- Naming_Lock -- ----------------- protected body Naming_Lock is ---------- -- Lock -- ---------- entry Lock when not Locked is begin Locked := True; end Lock; ------------ -- Unlock -- ------------ procedure Unlock is begin Locked := False; end Unlock; end Naming_Lock; ----------------- -- Parse_Entry -- ----------------- function Parse_Entry (Host : Hostent) return Host_Entry is C_Aliases : constant Thin.Chars_Ptr_Array := Chars_Ptr_Pointers.Value (Host.H_Aliases); C_Addr : constant In_Addr_Access_Array := In_Addr_Access_Pointers.Value (Host.H_Addr_List); Result : Host_Entry (N_Aliases => C_Aliases'Length - 1, N_Addresses => C_Addr'Length - 1); begin Result.Name := new String'(Value (Host.H_Name)); for I in 1 .. Result.Aliases'Last loop declare Index : constant Natural := I - 1 + Natural (C_Aliases'First); Current : chars_ptr renames C_Aliases (size_t (Index)); begin Result.Aliases (I) := new String'(Value (Current)); end; end loop; for I in Result.Addresses'Range loop declare Index : constant Natural := I - 1 + Natural (C_Addr'First); Current : In_Addr_Access renames C_Addr (Index); begin Result.Addresses (I) := To_Address (Current.all); end; end loop; return Result; end Parse_Entry; ------------------------ -- Raise_Naming_Error -- ------------------------ procedure Raise_Naming_Error (Errno : Integer; Message : String) is function Error_Message return String; -- Return the message according to Errno. ------------------- -- Error_Message -- ------------------- function Error_Message return String is begin case Errno is when Host_Not_Found => return "Host not found"; when Try_Again => return "Try again"; when No_Recovery => return "No recovery"; when No_Address => return "No address"; when others => return "Unknown error" & Integer'Image (Errno); end case; end Error_Message; begin Ada.Exceptions.Raise_Exception (Naming_Error'Identity, Error_Message & ": " & Message); end Raise_Naming_Error; ---------------- -- To_Address -- ---------------- function To_Address (Addr : In_Addr) return Address is begin return (H1 => Address_Component (Addr.S_B1), H2 => Address_Component (Addr.S_B2), H3 => Address_Component (Addr.S_B3), H4 => Address_Component (Addr.S_B4)); end To_Address; ---------------- -- To_In_Addr -- ---------------- function To_In_Addr (Addr : Address) return In_Addr is begin return (S_B1 => unsigned_char (Addr.H1), S_B2 => unsigned_char (Addr.H2), S_B3 => unsigned_char (Addr.H3), S_B4 => unsigned_char (Addr.H4)); end To_In_Addr; ----------- -- Value -- ----------- function Value (Add : String) return Address is C_Add : chars_ptr := New_String (Add); Converted : aliased In_Addr; begin if C_Inet_Aton (C_Add, Converted'Unchecked_Access) = 0 then Ada.Exceptions.Raise_Exception (Naming_Error'Identity, Add & " is not an IP address"); end if; Free (C_Add); return (H1 => Address_Component (Converted.S_B1), H2 => Address_Component (Converted.S_B2), H3 => Address_Component (Converted.S_B3), H4 => Address_Component (Converted.S_B4)); end Value; end Sockets.Naming; adasockets-v1.14/src/sockets-naming.ads000066400000000000000000000134541454340372400201650ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . N A M I N G -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Finalization; with Sockets.Types; package Sockets.Naming is type String_Access is access String; type String_Array is array (Positive range <>) of String_Access; subtype Address_Component is Natural range 0 .. 255; type Address is record H1, H2, H3, H4 : Address_Component; end record; -- An IPv4 address such as 137.194.160.12 type Address_Array is array (Positive range <>) of Address; type Host_Entry (N_Aliases, N_Addresses : Natural) is new Ada.Finalization.Controlled with record Name : String_Access; Aliases : String_Array (1 .. N_Aliases); Addresses : Address_Array (1 .. N_Addresses); end record; -- A complete host structure. A host may have several IP addresses as -- well as several aliases. procedure Adjust (Object : in out Host_Entry); procedure Finalize (Object : in out Host_Entry); Naming_Error : exception; -- This exception is raised when a name cannot be resolved function Image (Add : Address) return String; -- The dotted form corresponding to an IP address function Image (Add : Types.In_Addr) return String; -- The dotted form corresponding to the packed form of an IP address function Value (Add : String) return Address; -- The IP address corresponding to a dotted form function Info_Of (Name : String) return Host_Entry; -- Host entry of an IP name function Info_Of (Addr : Address) return Host_Entry; -- Host entry of an IP address function Is_IP_Address (Something : String) return Boolean; -- Return True if the name looks like an IP address, False otherwise function Info_Of_Name_Or_IP (Something : String) return Host_Entry; -- Host entry of an IP name or a dotted form function Address_Of (Something : String) return Address; -- Address of an IP name or a dotted form function Host_Name return String; -- Return the name of the current host function Name_Of (Something : String) return String; -- Return the official name of an IP name or a dotted form function To_In_Addr (Addr : Address) return Types.In_Addr; -- Convert an IP address to a In_Addr structure function To_Address (Addr : Types.In_Addr) return Address; -- Convert a In_Addr structure to an IP address function Any_Address return Address; -- Return the value of inaddr_any function Get_Peer_Addr (Socket : Socket_FD) return Types.In_Addr; -- Return the address of the peer in a dotted form function Get_Peer_Addr (Socket : Socket_FD) return Address; -- Ditto function Get_Peer_Port (Socket : Socket_FD) return Positive; -- Return the port of the peer function Get_Sock_Addr (Socket : Socket_FD) return Types.In_Addr; -- Return the local address of a bound socket function Get_Sock_Addr (Socket : Socket_FD) return Address; -- Ditto function Get_Sock_Port (Socket : Socket_FD) return Positive; -- Return the local port of a bound socket end Sockets.Naming; adasockets-v1.14/src/sockets-stream_io.adb000066400000000000000000000071271454340372400206550ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . S T R E A M _ I O -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- package body Sockets.Stream_IO is ---------------- -- Initialize -- ---------------- procedure Initialize (Stream : in out Socket_Stream_Type; FD : Socket_FD) is begin Stream.FD := FD; end Initialize; ---------- -- Read -- ---------- procedure Read (Stream : in out Socket_Stream_Type; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is begin Receive (Stream.FD, Item); Last := Item'Last; end Read; ----------- -- Write -- ----------- procedure Write (Stream : in out Socket_Stream_Type; Item : Ada.Streams.Stream_Element_Array) is begin Send (Stream.FD, Item); end Write; end Sockets.Stream_IO; adasockets-v1.14/src/sockets-stream_io.ads000066400000000000000000000070721454340372400206750ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . S T R E A M _ I O -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Streams; package Sockets.Stream_IO is type Socket_Stream_Type is new Ada.Streams.Root_Stream_Type with private; procedure Initialize (Stream : in out Socket_Stream_Type; FD : Socket_FD); -- Initialize must be called with an opened socket as parameter before -- being used as a stream. procedure Read (Stream : in out Socket_Stream_Type; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset); procedure Write (Stream : in out Socket_Stream_Type; Item : Ada.Streams.Stream_Element_Array); private type Socket_Stream_Type is new Ada.Streams.Root_Stream_Type with record FD : Socket_FD; end record; end Sockets.Stream_IO; adasockets-v1.14/src/sockets-thin.adb.vms000066400000000000000000000134561454340372400204430ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- -- Platform specific file for OpenVMS -- -- -- -- Based on Windows specific file written -- -- by Maxim Reznik -- ----------------------------------------------------------------------------- with Sockets.Constants; with System.Address_To_Access_Conversions; package body Sockets.Thin is use type System.Address; package Int_Conversion is new System.Address_To_Access_Conversions (C.int); ------------------ -- C_Socketpair -- ------------------ function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int is use System.Storage_Elements; use type C.char_array; INVALID_SOCKET : constant := Failure; Listen_Socket : C.int; Sin : aliased Sockaddr_In; Sin_Len : aliased C.int := Sin'Size / 8; fd : Two_Int; fd_ptr : Int_Conversion.Object_Pointer; Result : C.int; begin if Domain /= Constants.Af_Inet or Typ /= Constants.Sock_Stream or Filedes = System.Null_Address then return Failure; end if; Listen_Socket := C_Socket (Domain, Typ, Protocol); if Listen_Socket = INVALID_SOCKET then return Failure; end if; Sin.Sin_Family := Constants.Af_Inet; Sin.Sin_Addr := Inaddr_Any; Sin.Sin_Port := 0; if C_Bind (Listen_Socket, Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Listen (Listen_Socket, 1) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Getsockname (Listen_Socket, Sin'Address, Sin_Len'Access) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; Sin.Sin_Addr := (127, 0, 0, 1); fd (1) := C_Socket (Domain, Typ, Protocol); if fd (1) = INVALID_SOCKET then Result := C_Close (Listen_Socket); return Failure; end if; if C_Connect (fd (1), Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd (0) := C_Accept (Listen_Socket, Sin'Address, Sin_Len'Access); if fd (0) = INVALID_SOCKET then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd_ptr := Int_Conversion.To_Pointer (Filedes); fd_ptr.all := fd (0); fd_ptr := Int_Conversion.To_Pointer (Filedes + (C.int'Size / 8)); fd_ptr.all := fd (1); return Success; end C_Socketpair; end Sockets.Thin; adasockets-v1.14/src/sockets-thin.adb.win32000066400000000000000000000330041454340372400205670ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- -- Platform specific file for MS Windows -- -- Unix Net/IO functions absent in Win32 platform -- -- -- -- Written by Maxim Reznik -- ----------------------------------------------------------------------------- with Sockets.Constants; with System.Address_To_Access_Conversions; package body Sockets.Thin is use type System.Address; package Int_Conversion is new System.Address_To_Access_Conversions (C.int); package Conversion is new System.Address_To_Access_Conversions (Iovec); FD_SETSIZE : constant := 64; type fds is array (C.int range 1 .. FD_SETSIZE) of C.int; pragma Convention (C, fds); type fd_set_type is record fd_count : C.int; fd_array : fds; end record; pragma Convention (C, fd_set_type); type Timeval is record tv_sec : C.long; -- Seconds tv_usec : C.long; -- Microseconds end record; pragma Convention (C, Timeval); procedure FD_ZERO (set : in out fd_set_type); procedure FD_SET (fd : C.int; set : in out fd_set_type); function FD_ISSET (fd : C.int; set : System.Address) return C.int; pragma Import (Stdcall, FD_ISSET, "__WSAFDIsSet"); function C_Select (Nfds : C.int; readfds : System.Address; writefds : System.Address; exceptfds : System.Address; timeout : System.Address) return C.int; pragma Import (Stdcall, C_Select, "select"); function C_WSAGetLastError return C.int; pragma Import (Stdcall, C_WSAGetLastError, "WSAGetLastError"); ------------ -- C_Poll -- ------------ function C_Poll (Fds : System.Address; Nfds : C.unsigned_long; Timeout : C.int) return C.int is use System.Storage_Elements; use type C.short; use type C.long; package Conversion is new System.Address_To_Access_Conversions (Pollfd); type Poll_Event is mod 2**16; for Poll_Event'Size use 16; fd_addr : System.Address := Fds; fd_ptr : Conversion.Object_Pointer; fd_events : Poll_Event; timeout_v : aliased Timeval; rfds : aliased fd_set_type; wfds : aliased fd_set_type; efds : aliased fd_set_type; rs : C.int; Good : Boolean; begin if Fds = System.Null_Address then return Failure; end if; timeout_v.tv_sec := C.long (Timeout) / 1000; timeout_v.tv_usec := C.long (Timeout) mod 1000; FD_ZERO (rfds); FD_ZERO (wfds); FD_ZERO (efds); for i in 1 .. Nfds loop fd_ptr := Conversion.To_Pointer (fd_addr); fd_events := Poll_Event (fd_ptr.Events); if (fd_events and Constants.Pollin) /= 0 then FD_SET (fd_ptr.Fd, rfds); elsif (fd_events and Constants.Pollout) /= 0 then FD_SET (fd_ptr.Fd, wfds); elsif (fd_events and Constants.Pollpri) /= 0 then FD_SET (fd_ptr.Fd, efds); end if; fd_addr := fd_addr + Pollfd'Size / 8; end loop; if Timeout < 0 then rs := C_Select (0, rfds'Address, wfds'Address, efds'Address, System.Null_Address); else rs := C_Select (0, rfds'Address, wfds'Address, efds'Address, timeout_v'Address); end if; if rs > 0 then rs := 0; fd_addr := Fds; for i in 1 .. Nfds loop fd_ptr := Conversion.To_Pointer (fd_addr); Good := False; fd_ptr.Revents := 0; if FD_ISSET (fd_ptr.Fd, rfds'Address) /= 0 then Good := True; fd_ptr.Revents := fd_ptr.Revents + Constants.Pollin; end if; if FD_ISSET (fd_ptr.Fd, wfds'Address) /= 0 then Good := True; fd_ptr.Revents := fd_ptr.Revents + Constants.Pollout; end if; if FD_ISSET (fd_ptr.Fd, efds'Address) /= 0 then Good := True; fd_ptr.Revents := fd_ptr.Revents + Constants.Pollpri; end if; if Good then rs := rs + 1; end if; fd_addr := fd_addr + Pollfd'Size / 8; end loop; end if; return rs; end C_Poll; ------------ -- C_Read -- ------------ function C_Read (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int is begin return C_Recv (Fildes, Buf, Nbyte, 0); end C_Read; ------------- -- C_Readv -- ------------- function C_Readv (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int is use System.Storage_Elements; Total : C.int := 0; Processed : Storage_Offset; Result : C.int; Ptr : System.Address := Iov; Iovec_Ptr : Conversion.Object_Pointer; begin if Iov = System.Null_Address then return Failure; end if; for i in 1 .. Iovcnt loop Iovec_Ptr := Conversion.To_Pointer (Ptr); Processed := 0; while Processed < Iovec_Ptr.Iov_Len loop Result := C_Recv (Fildes, Buf => Iovec_Ptr.Iov_Base + Processed, Len => C.int (Iovec_Ptr.Iov_Len - Processed), Flags => 0); if Result < 0 then if Total = 0 then return -1; -- Return error code else return Total; -- Return total bytes processed end if; end if; Processed := Processed + Storage_Offset (Result); Total := Total + Result; end loop; Ptr := Ptr + Iovec'Size / 8; end loop; return Total; end C_Readv; ------------------ -- C_Socketpair -- ------------------ function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int is use System.Storage_Elements; use type C.char_array; INVALID_SOCKET : constant := Failure; Listen_Socket : C.int; Sin : aliased Sockaddr_In; Sin_Len : aliased C.int := Sin'Size / 8; fd : Two_Int; fd_ptr : Int_Conversion.Object_Pointer; Result : C.int; begin if Domain /= Constants.Af_Inet or Typ /= Constants.Sock_Stream or Filedes = System.Null_Address then return Failure; end if; Listen_Socket := C_Socket (Domain, Typ, Protocol); if Listen_Socket = INVALID_SOCKET then return Failure; end if; Sin.Sin_Family := Constants.Af_Inet; Sin.Sin_Addr := Inaddr_Any; Sin.Sin_Port := 0; if C_Bind (Listen_Socket, Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Listen (Listen_Socket, 1) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Getsockname (Listen_Socket, Sin'Address, Sin_Len'Access) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; Sin.Sin_Addr := (127, 0, 0, 1); fd (1) := C_Socket (Domain, Typ, Protocol); if fd (1) = INVALID_SOCKET then Result := C_Close (Listen_Socket); return Failure; end if; if C_Connect (fd (1), Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd (0) := C_Accept (Listen_Socket, Sin'Address, Sin_Len'Access); if fd (0) = INVALID_SOCKET then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd_ptr := Int_Conversion.To_Pointer (Filedes); fd_ptr.all := fd (0); fd_ptr := Int_Conversion.To_Pointer (Filedes + (C.int'Size / 8)); fd_ptr.all := fd (1); return Success; end C_Socketpair; ------------- -- C_Write -- ------------- function C_Write (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int is begin return C_Send (Fildes, Buf, Nbyte, 0); end C_Write; -------------- -- C_Writev -- -------------- function C_Writev (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int is use System.Storage_Elements; Total : C.int := 0; Processed : Storage_Offset; Result : C.int; Ptr : System.Address := Iov; Iovec_Ptr : Conversion.Object_Pointer; begin if Iov = System.Null_Address then return Failure; end if; for i in 1 .. Iovcnt loop Iovec_Ptr := Conversion.To_Pointer (Ptr); Processed := 0; while Processed < Iovec_Ptr.Iov_Len loop Result := C_Send (Fildes, Msg => Iovec_Ptr.Iov_Base + Processed, Len => C.int (Iovec_Ptr.Iov_Len - Processed), Flags => 0); if Result < 0 then if Total = 0 then return -1; -- Return error code else return Total; -- Return total bytes processed end if; end if; Processed := Processed + Storage_Offset (Result); Total := Total + Result; end loop; Ptr := Ptr + Iovec'Size / 8; end loop; return Total; end C_Writev; ----------- -- Errno -- ----------- function Errno return Integer is begin return Integer (C_WSAGetLastError); end Errno; ------------ -- FD_SET -- ------------ procedure FD_SET (fd : C.int; set : in out fd_set_type) is begin if set.fd_count < FD_SETSIZE then set.fd_count := set.fd_count + 1; set.fd_array (set.fd_count) := fd; end if; end FD_SET; ------------- -- FD_ZERO -- ------------- procedure FD_ZERO (set : in out fd_set_type) is begin set.fd_count := 0; end FD_ZERO; end Sockets.Thin; adasockets-v1.14/src/sockets-thin.ads.unix000066400000000000000000000321401454340372400206310ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with GNAT.OS_Lib; with Interfaces.C.Pointers; with Interfaces.C.Strings; with Sockets.Types; use Sockets.Types; with System.Storage_Elements; package Sockets.Thin is package C renames Interfaces.C; package Strings renames C.Strings; generic package Pointers renames C.Pointers; use type C.int; -- This is an ugly hack to be able to declare the Failure constant -- below. Success : constant C.int := 0; Failure : constant C.int := -1; type Int_Access is access all C.int; pragma Convention (C, Int_Access); -- Access to C integers type pid_t is new C.int; pragma Convention (C, pid_t); type mode_t is new C.int; pragma Convention (C, mode_t); type key_t is new C.int; pragma Convention (C, key_t); type Chars_Ptr_Array is array (C.size_t range <>) of aliased Strings.chars_ptr; package Chars_Ptr_Pointers is new Pointers (C.size_t, Strings.chars_ptr, Chars_Ptr_Array, Strings.Null_Ptr); -- Arrays of C (char *) type In_Addr_Access_Array is array (Positive range <>) of aliased In_Addr_Access; pragma Convention (C, In_Addr_Access_Array); package In_Addr_Access_Pointers is new Pointers (Positive, In_Addr_Access, In_Addr_Access_Array, null); -- Array of internet addresses type Sockaddr_Access is access all Sockaddr; pragma Convention (C, Sockaddr_Access); -- Access to socket address type Sockaddr_In_Access is access all Sockaddr_In; pragma Convention (C, Sockaddr_In_Access); -- Access to internet socket address type Ip_Mreq is record Imr_Multiaddr : In_Addr; Imr_Interface : In_Addr := Inaddr_Any; end record; pragma Convention (C, Ip_Mreq); -- Multicast structure type Hostent is record H_Name : Strings.chars_ptr; H_Aliases : Chars_Ptr_Pointers.Pointer; H_Addrtype : C.int; H_Length : C.int; H_Addr_List : In_Addr_Access_Pointers.Pointer; end record; pragma Convention (C, Hostent); -- Host entry type Hostent_Access is access all Hostent; pragma Convention (C, Hostent_Access); -- Access to host entry type Iovec is record Iov_Base : System.Address; Iov_Len : System.Storage_Elements.Storage_Offset; end record; pragma Convention (C, Iovec); -- Iovec C type type Msghdr is record Msg_Name : System.Address; Msg_Namelen : C.int; Msg_Iov : System.Address; Msg_Iovlen : C.int; Msg_Accrights : System.Address; Msg_Accrightslen : C.int; end record; pragma Convention (C, Msghdr); -- Message header type Msghdr_Access is access all Msghdr; pragma Convention (C, Msghdr_Access); -- Access to message header. type Two_Int is array (0 .. 1) of C.int; pragma Convention (C, Two_Int); -- Used with socketpair() type Pollfd is record Fd : C.int; Events : C.short; Revents : C.short; end record; pragma Convention (C, Pollfd); type Pollfd_Array is array (Positive range <>) of Pollfd; pragma Convention (C, Pollfd_Array); function C_Accept (S : C.int; Addr : System.Address; Addrlen : access C.int) return C.int; function C_Bind (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Close (Fildes : C.int) return C.int; function C_Connect (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Dup2 (Fildes, Fildes2 : C.int) return C.int; function C_Fcntl (Fildes : C.int; Cmd : C.int; Arg : C.int := 0) return C.int; function C_Getenv (Name : Strings.chars_ptr) return Strings.chars_ptr; function C_Gethostbyaddr (Addr : Strings.chars_ptr; Length : C.int; Typ : C.int) return Hostent_Access; function C_Gethostbyname (Name : Strings.chars_ptr) return Hostent_Access; function C_Gethostname (Name : Strings.chars_ptr; Namelen : C.int) return C.int; function C_Gethostname (Name : System.Address; Namelen : C.int) return C.int; function C_Getpeername (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getpid return pid_t; function C_Getsockname (S : C.int; Name : Sockaddr_Access; Namelen : access C.int) return C.int; function C_Getsockname (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : Strings.chars_ptr; Optlen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : access C.int) return C.int; function C_Inet_Addr (Cp : Strings.chars_ptr) return Types.In_Addr; function C_Inet_Network (Cp : Strings.chars_ptr) return Interfaces.Unsigned_32; function C_Inet_Makeaddr (Net : C.int; Lna : C.int) return In_Addr; function C_Inet_Lnaof (I : In_Addr) return C.int; function C_Inet_Netof (I : In_Addr) return C.int; function C_Inet_Ntoa (I : In_Addr) return Strings.chars_ptr; function C_Inet_Aton (Cp : Strings.chars_ptr; I : In_Addr_Access) return C.int; function C_Kill (Pid : pid_t; Sig : C.int) return C.int; function C_Listen (S, Backlog : C.int) return C.int; function C_Msgget (Key : key_t; Msgflg : C.int) return C.int; function C_Msgrcv (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgtyp : C.long; Msgflg : C.int) return C.int; function C_Msgsnd (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgflg : C.int) return C.int; function C_Open (Path : Strings.chars_ptr; Oflag : C.int; Mode : mode_t := 0) return C.int; function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int; function C_Poll (Fds : System.Address; Nfds : C.unsigned_long; Timeout : C.int) return C.int; function C_Read (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Readv (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Recv (S : C.int; Buf : System.Address; Len, Flags : C.int) return C.int; function C_Recvfrom (S : C.int; Buf : System.Address; Len : C.int; Flags : C.int; From : System.Address; Fromlen : access C.int) return C.int; function C_Recvmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Send (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int) return C.int; function C_Sendmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Sendto (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int; To : System.Address; Tolen : C.int) return C.int; function C_Setsid return pid_t; function C_Setsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : C.int) return C.int; procedure C_Shutdown (S : C.int; How : C.int); function C_Socket (Domain, Typ, Protocol : C.int) return C.int; function C_Strerror (Errnum : C.int) return Strings.chars_ptr; function C_Write (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Writev (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Ioctl (S : C.int; Req : C.int; Arg : access C.int) return C.int; function Errno return Integer; private pragma Import (C, C_Accept, "accept"); pragma Import (C, C_Bind, "bind"); pragma Import (C, C_Close, "close"); pragma Import (C, C_Connect, "connect"); pragma Import (C, C_Dup2, "dup2"); pragma Import (C, C_Fcntl, "fcntl"); pragma Import (C, C_Getenv, "getenv"); pragma Import (C, C_Gethostbyaddr, "gethostbyaddr"); pragma Import (C, C_Gethostbyname, "gethostbyname"); pragma Import (C, C_Gethostname, "gethostname"); pragma Import (C, C_Getpeername, "getpeername"); pragma Import (C, C_Getpid, "getpid"); pragma Import (C, C_Getsockname, "getsockname"); pragma Import (C, C_Getsockopt, "getsockopt"); pragma Import (C, C_Inet_Addr, "inet_addr"); pragma Import (C, C_Inet_Network, "inet_network"); pragma Import (C, C_Inet_Makeaddr, "inet_makeaddr"); pragma Import (C, C_Inet_Lnaof, "inet_lnaof"); pragma Import (C, C_Inet_Netof, "inet_netof"); pragma Import (C, C_Inet_Ntoa, "inet_ntoa"); pragma Import (C, C_Inet_Aton, "inet_aton"); pragma Import (C, C_Kill, "kill"); pragma Import (C, C_Listen, "listen"); pragma Import (C, C_Msgget, "msgget"); pragma Import (C, C_Msgrcv, "msgrcv"); pragma Import (C, C_Msgsnd, "msgsnd"); pragma Import (C, C_Open, "open"); pragma Import (C, C_Socketpair, "socketpair"); pragma Import (C, C_Poll, "poll"); pragma Import (C, C_Read, "read"); pragma Import (C, C_Readv, "readv"); pragma Import (C, C_Recv, "recv"); pragma Import (C, C_Recvfrom, "recvfrom"); pragma Import (C, C_Recvmsg, "recvmsg"); pragma Import (C, C_Send, "send"); pragma Import (C, C_Sendmsg, "sendmsg"); pragma Import (C, C_Sendto, "sendto"); pragma Import (C, C_Setsid, "setsid"); pragma Import (C, C_Setsockopt, "setsockopt"); pragma Import (C, C_Shutdown, "shutdown"); pragma Import (C, C_Socket, "socket"); pragma Import (C, C_Strerror, "strerror"); pragma Import (C, C_Write, "write"); pragma Import (C, C_Writev, "writev"); pragma Import (C, C_Ioctl, "ioctl"); function Errno return Integer renames GNAT.OS_Lib.Errno; end Sockets.Thin; adasockets-v1.14/src/sockets-thin.ads.vms000066400000000000000000000316261454340372400204630ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with GNAT.OS_Lib; with Interfaces.C.Pointers; with Interfaces.C.Strings; with Sockets.Types; use Sockets.Types; with System.Storage_Elements; package Sockets.Thin is package C renames Interfaces.C; package Strings renames C.Strings; generic package Pointers renames C.Pointers; use type C.int; -- This is an ugly hack to be able to declare the Failure constant -- below. Success : constant C.int := 0; Failure : constant C.int := -1; type Int_Access is access all C.int; pragma Convention (C, Int_Access); -- Access to C integers type pid_t is new C.int; pragma Convention (C, pid_t); type mode_t is new C.int; pragma Convention (C, mode_t); type key_t is new C.int; pragma Convention (C, key_t); type Chars_Ptr_Array is array (C.size_t range <>) of aliased Strings.chars_ptr; package Chars_Ptr_Pointers is new Pointers (C.size_t, Strings.chars_ptr, Chars_Ptr_Array, Strings.Null_Ptr); -- Arrays of C (char *) type In_Addr_Access_Array is array (Positive range <>) of aliased In_Addr_Access; pragma Convention (C, In_Addr_Access_Array); package In_Addr_Access_Pointers is new Pointers (Positive, In_Addr_Access, In_Addr_Access_Array, null); -- Array of internet addresses type Sockaddr_Access is access all Sockaddr; pragma Convention (C, Sockaddr_Access); -- Access to socket address type Sockaddr_In_Access is access all Sockaddr_In; pragma Convention (C, Sockaddr_In_Access); -- Access to internet socket address type Ip_Mreq is record Imr_Multiaddr : In_Addr; Imr_Interface : In_Addr := Inaddr_Any; end record; pragma Convention (C, Ip_Mreq); -- Multicast structure type Hostent is record H_Name : Strings.chars_ptr; H_Aliases : Chars_Ptr_Pointers.Pointer; H_Addrtype : C.int; H_Length : C.int; H_Addr_List : In_Addr_Access_Pointers.Pointer; end record; pragma Convention (C, Hostent); -- Host entry type Hostent_Access is access all Hostent; pragma Convention (C, Hostent_Access); -- Access to host entry type Iovec is record Iov_Base : System.Address; Iov_Len : System.Storage_Elements.Storage_Offset; end record; pragma Convention (C, Iovec); -- Iovec C type type Msghdr is record Msg_Name : System.Address; Msg_Namelen : C.int; Msg_Iov : System.Address; Msg_Iovlen : C.int; Msg_Accrights : System.Address; Msg_Accrightslen : C.int; end record; pragma Convention (C, Msghdr); -- Message header type Msghdr_Access is access all Msghdr; pragma Convention (C, Msghdr_Access); -- Access to message header. type Two_Int is array (0 .. 1) of C.int; pragma Convention (C, Two_Int); -- Used with socketpair() type Pollfd is record Fd : C.int; Events : C.short; Revents : C.short; end record; pragma Convention (C, Pollfd); type Pollfd_Array is array (Positive range <>) of Pollfd; pragma Convention (C, Pollfd_Array); function C_Accept (S : C.int; Addr : System.Address; Addrlen : access C.int) return C.int; function C_Bind (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Close (Fildes : C.int) return C.int; function C_Connect (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Dup2 (Fildes, Fildes2 : C.int) return C.int; function C_Fcntl (Fildes : C.int; Cmd : C.int; Arg : C.int := 0) return C.int; function C_Getenv (Name : Strings.chars_ptr) return Strings.chars_ptr; function C_Gethostbyaddr (Addr : Strings.chars_ptr; Length : C.int; Typ : C.int) return Hostent_Access; function C_Gethostbyname (Name : Strings.chars_ptr) return Hostent_Access; function C_Gethostname (Name : Strings.chars_ptr; Namelen : C.int) return C.int; function C_Gethostname (Name : System.Address; Namelen : C.int) return C.int; function C_Getpeername (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getpid return pid_t; function C_Getsockname (S : C.int; Name : Sockaddr_Access; Namelen : access C.int) return C.int; function C_Getsockname (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : Strings.chars_ptr; Optlen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : access C.int) return C.int; function C_Inet_Addr (Cp : Strings.chars_ptr) return Types.In_Addr; function C_Inet_Network (Cp : Strings.chars_ptr) return Interfaces.Unsigned_32; function C_Inet_Makeaddr (Net : C.int; Lna : C.int) return In_Addr; function C_Inet_Lnaof (I : In_Addr) return C.int; function C_Inet_Netof (I : In_Addr) return C.int; function C_Inet_Ntoa (I : In_Addr) return Strings.chars_ptr; function C_Kill (Pid : pid_t; Sig : C.int) return C.int; function C_Listen (S, Backlog : C.int) return C.int; function C_Msgget (Key : key_t; Msgflg : C.int) return C.int; function C_Msgrcv (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgtyp : C.long; Msgflg : C.int) return C.int; function C_Msgsnd (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgflg : C.int) return C.int; function C_Open (Path : Strings.chars_ptr; Oflag : C.int; Mode : mode_t := 0) return C.int; function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int; function C_Poll (Fds : System.Address; Nfds : C.unsigned_long; Timeout : C.int) return C.int; function C_Read (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Readv (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Recv (S : C.int; Buf : System.Address; Len, Flags : C.int) return C.int; function C_Recvfrom (S : C.int; Buf : System.Address; Len : C.int; Flags : C.int; From : System.Address; Fromlen : access C.int) return C.int; function C_Recvmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Send (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int) return C.int; function C_Sendmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Sendto (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int; To : System.Address; Tolen : C.int) return C.int; function C_Setsid return pid_t; function C_Setsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : C.int) return C.int; procedure C_Shutdown (S : C.int; How : C.int); function C_Socket (Domain, Typ, Protocol : C.int) return C.int; function C_Strerror (Errnum : C.int) return Strings.chars_ptr; function C_Write (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Writev (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Ioctl (S : C.int; Req : C.int; Arg : access C.int) return C.int; function Errno return Integer; private pragma Import (C, C_Accept, "accept"); pragma Import (C, C_Bind, "bind"); pragma Import (C, C_Close, "close"); pragma Import (C, C_Connect, "connect"); pragma Import (C, C_Dup2, "dup2"); pragma Import (C, C_Fcntl, "fcntl"); pragma Import (C, C_Getenv, "getenv"); pragma Import (C, C_Gethostbyaddr, "gethostbyaddr"); pragma Import (C, C_Gethostbyname, "gethostbyname"); pragma Import (C, C_Gethostname, "gethostname"); pragma Import (C, C_Getpeername, "getpeername"); pragma Import (C, C_Getpid, "getpid"); pragma Import (C, C_Getsockname, "getsockname"); pragma Import (C, C_Getsockopt, "getsockopt"); pragma Import (C, C_Inet_Addr, "inet_addr"); pragma Import (C, C_Inet_Network, "inet_network"); pragma Import (C, C_Inet_Makeaddr, "inet_makeaddr"); pragma Import (C, C_Inet_Lnaof, "inet_lnaof"); pragma Import (C, C_Inet_Netof, "inet_netof"); pragma Import (C, C_Inet_Ntoa, "inet_ntoa"); pragma Import (C, C_Kill, "kill"); pragma Import (C, C_Listen, "listen"); pragma Import (C, C_Msgget, "msgget"); pragma Import (C, C_Msgrcv, "msgrcv"); pragma Import (C, C_Msgsnd, "msgsnd"); pragma Import (C, C_Open, "open"); pragma Import (C, C_Poll, "poll"); pragma Import (C, C_Read, "read"); pragma Import (C, C_Readv, "readv"); pragma Import (C, C_Recv, "recv"); pragma Import (C, C_Recvfrom, "recvfrom"); pragma Import (C, C_Recvmsg, "recvmsg"); pragma Import (C, C_Send, "send"); pragma Import (C, C_Sendmsg, "sendmsg"); pragma Import (C, C_Sendto, "sendto"); pragma Import (C, C_Setsid, "setsid"); pragma Import (C, C_Setsockopt, "setsockopt"); pragma Import (C, C_Shutdown, "shutdown"); pragma Import (C, C_Socket, "socket"); pragma Import (C, C_Strerror, "strerror"); pragma Import (C, C_Write, "write"); pragma Import (C, C_Writev, "writev"); pragma Import (C, C_Ioctl, "ioctl"); function Errno return Integer renames GNAT.OS_Lib.Errno; end Sockets.Thin; adasockets-v1.14/src/sockets-thin.ads.win32000066400000000000000000000315651454340372400206220ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Interfaces.C.Pointers; with Interfaces.C.Strings; with Sockets.Types; use Sockets.Types; with System.Storage_Elements; package Sockets.Thin is package C renames Interfaces.C; package Strings renames C.Strings; generic package Pointers renames C.Pointers; use type C.int; -- This is an ugly hack to be able to declare the Failure constant -- below. Success : constant C.int := 0; Failure : constant C.int := -1; type Int_Access is access all C.int; pragma Convention (C, Int_Access); -- Access to C integers type pid_t is new C.int; pragma Convention (C, pid_t); type mode_t is new C.int; pragma Convention (C, mode_t); type key_t is new C.int; pragma Convention (C, key_t); type Chars_Ptr_Array is array (C.size_t range <>) of aliased Strings.chars_ptr; package Chars_Ptr_Pointers is new Pointers (C.size_t, Strings.chars_ptr, Chars_Ptr_Array, Strings.Null_Ptr); -- Arrays of C (char *) type In_Addr_Access_Array is array (Positive range <>) of aliased In_Addr_Access; pragma Convention (C, In_Addr_Access_Array); package In_Addr_Access_Pointers is new Pointers (Positive, In_Addr_Access, In_Addr_Access_Array, null); -- Array of internet addresses type Sockaddr_Access is access all Sockaddr; pragma Convention (C, Sockaddr_Access); -- Access to socket address type Sockaddr_In_Access is access all Sockaddr_In; pragma Convention (C, Sockaddr_In_Access); -- Access to internet socket address type Ip_Mreq is record Imr_Multiaddr : In_Addr; Imr_Interface : In_Addr := Inaddr_Any; end record; pragma Convention (C, Ip_Mreq); -- Multicast structure type Hostent is record H_Name : Strings.chars_ptr; H_Aliases : Chars_Ptr_Pointers.Pointer; H_Addrtype : C.short; H_Length : C.short; H_Addr_List : In_Addr_Access_Pointers.Pointer; end record; pragma Convention (C, Hostent); -- Host entry type Hostent_Access is access all Hostent; pragma Convention (C, Hostent_Access); -- Access to host entry type Iovec is record Iov_Base : System.Address; Iov_Len : System.Storage_Elements.Storage_Offset; end record; pragma Convention (C, Iovec); -- Iovec C type type Msghdr is record Msg_Name : System.Address; Msg_Namelen : C.int; Msg_Iov : System.Address; Msg_Iovlen : C.int; Msg_Accrights : System.Address; Msg_Accrightslen : C.int; end record; pragma Convention (C, Msghdr); -- Message header type Msghdr_Access is access all Msghdr; pragma Convention (C, Msghdr_Access); -- Access to message header. type Two_Int is array (0 .. 1) of C.int; pragma Convention (C, Two_Int); -- Used with socketpair() type Pollfd is record Fd : C.int; Events : C.short; Revents : C.short; end record; pragma Convention (C, Pollfd); type Pollfd_Array is array (Positive range <>) of Pollfd; pragma Convention (C, Pollfd_Array); function C_Accept (S : C.int; Addr : System.Address; Addrlen : access C.int) return C.int; function C_Bind (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Close (Fildes : C.int) return C.int; function C_Connect (S : C.int; Name : System.Address; Namelen : C.int) return C.int; function C_Dup2 (Fildes, Fildes2 : C.int) return C.int; function C_Fcntl (Fildes : C.int; Cmd : C.int; Arg : C.int := 0) return C.int; function C_Getenv (Name : Strings.chars_ptr) return Strings.chars_ptr; function C_Gethostbyaddr (Addr : Strings.chars_ptr; Length : C.int; Typ : C.int) return Hostent_Access; function C_Gethostbyname (Name : Strings.chars_ptr) return Hostent_Access; function C_Gethostname (Name : Strings.chars_ptr; Namelen : C.int) return C.int; function C_Gethostname (Name : System.Address; Namelen : C.int) return C.int; function C_Getpeername (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getpid return pid_t; function C_Getsockname (S : C.int; Name : Sockaddr_Access; Namelen : access C.int) return C.int; function C_Getsockname (S : C.int; Name : System.Address; Namelen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : Strings.chars_ptr; Optlen : access C.int) return C.int; function C_Getsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : access C.int) return C.int; function C_Inet_Addr (Cp : Strings.chars_ptr) return Types.In_Addr; function C_Inet_Network (Cp : Strings.chars_ptr) return Interfaces.Unsigned_32; function C_Inet_Makeaddr (Net : C.int; Lna : C.int) return In_Addr; function C_Inet_Lnaof (I : In_Addr) return C.int; function C_Inet_Netof (I : In_Addr) return C.int; function C_Inet_Ntoa (I : In_Addr) return Strings.chars_ptr; function C_Kill (Pid : pid_t; Sig : C.int) return C.int; function C_Listen (S, Backlog : C.int) return C.int; function C_Msgget (Key : key_t; Msgflg : C.int) return C.int; function C_Msgrcv (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgtyp : C.long; Msgflg : C.int) return C.int; function C_Msgsnd (Msqid : C.int; Msgp : Strings.chars_ptr; Msgsz : C.int; Msgflg : C.int) return C.int; function C_Open (Path : Strings.chars_ptr; Oflag : C.int; Mode : mode_t := 0) return C.int; function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int; function C_Poll (Fds : System.Address; Nfds : C.unsigned_long; Timeout : C.int) return C.int; function C_Read (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Readv (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Recv (S : C.int; Buf : System.Address; Len, Flags : C.int) return C.int; function C_Recvfrom (S : C.int; Buf : System.Address; Len : C.int; Flags : C.int; From : System.Address; Fromlen : access C.int) return C.int; function C_Recvmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Send (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int) return C.int; function C_Sendmsg (S : C.int; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_Sendto (S : C.int; Msg : System.Address; Len : C.int; Flags : C.int; To : System.Address; Tolen : C.int) return C.int; function C_Setsid return pid_t; function C_Setsockopt (S : C.int; Level : C.int; Optname : C.int; Optval : System.Address; Optlen : C.int) return C.int; procedure C_Shutdown (S : C.int; How : C.int); function C_Socket (Domain, Typ, Protocol : C.int) return C.int; function C_Strerror (Errnum : C.int) return Strings.chars_ptr; function C_Write (Fildes : C.int; Buf : System.Address; Nbyte : C.int) return C.int; function C_Writev (Fildes : C.int; Iov : System.Address; Iovcnt : C.int) return C.int; function C_Ioctl (S : C.int; Req : C.int; Arg : access C.int) return C.int; function Errno return Integer; private pragma Import (Stdcall, C_Accept, "accept"); pragma Import (Stdcall, C_Bind, "bind"); pragma Import (Stdcall, C_Close, "closesocket"); pragma Import (Stdcall, C_Connect, "connect"); pragma Import (Stdcall, C_Dup2, "dup2"); pragma Import (Stdcall, C_Fcntl, "fcntl"); pragma Import (Stdcall, C_Getenv, "getenv"); pragma Import (Stdcall, C_Gethostbyaddr, "gethostbyaddr"); pragma Import (Stdcall, C_Gethostbyname, "gethostbyname"); pragma Import (Stdcall, C_Gethostname, "gethostname"); pragma Import (Stdcall, C_Getpeername, "getpeername"); pragma Import (Stdcall, C_Getpid, "getpid"); pragma Import (Stdcall, C_Getsockname, "getsockname"); pragma Import (Stdcall, C_Getsockopt, "getsockopt"); pragma Import (Stdcall, C_Inet_Addr, "inet_addr"); pragma Import (Stdcall, C_Inet_Network, "inet_network"); pragma Import (Stdcall, C_Inet_Makeaddr, "inet_makeaddr"); pragma Import (Stdcall, C_Inet_Lnaof, "inet_lnaof"); pragma Import (Stdcall, C_Inet_Netof, "inet_netof"); pragma Import (Stdcall, C_Inet_Ntoa, "inet_ntoa"); pragma Import (Stdcall, C_Kill, "kill"); pragma Import (Stdcall, C_Listen, "listen"); pragma Import (Stdcall, C_Msgget, "msgget"); pragma Import (Stdcall, C_Msgrcv, "msgrcv"); pragma Import (Stdcall, C_Msgsnd, "msgsnd"); pragma Import (Stdcall, C_Open, "open"); pragma Import (Stdcall, C_Recv, "recv"); pragma Import (Stdcall, C_Recvfrom, "recvfrom"); pragma Import (Stdcall, C_Recvmsg, "recvmsg"); pragma Import (Stdcall, C_Send, "send"); pragma Import (Stdcall, C_Sendmsg, "sendmsg"); pragma Import (Stdcall, C_Sendto, "sendto"); pragma Import (Stdcall, C_Setsid, "setsid"); pragma Import (Stdcall, C_Setsockopt, "setsockopt"); pragma Import (Stdcall, C_Shutdown, "shutdown"); pragma Import (Stdcall, C_Socket, "socket"); pragma Import (Stdcall, C_Strerror, "strerror"); pragma Import (Stdcall, C_Ioctl, "ioctlsocket"); end Sockets.Thin; adasockets-v1.14/src/sockets-types.ads.in000066400000000000000000000107321454340372400204610ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T Y P E S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Interfaces.C; package Sockets.Types is package C renames Interfaces.C; type In_Addr is record S_B1, S_B2, S_B3, S_B4 : C.unsigned_char; end record; pragma Convention (C, In_Addr); -- Internet address type In_Addr_Access is access all In_Addr; pragma Convention (C, In_Addr_Access); -- Access to internet address Inaddr_Any : aliased constant In_Addr := (others => 0); -- Any internet address (all the interfaces) type Sockaddr is record @SA_LEN@ Sa_Len : C.unsigned_char := 18; @SA_LEN@ Sa_Family : C.unsigned_char; @NO_SA_LEN@ Sa_Family : C.unsigned_short; Sa_Data : C.char_array (1 .. 14); end record; pragma Convention (C, Sockaddr); -- Socket address type Sockaddr_Access is access all Sockaddr; pragma Convention (C, Sockaddr_Access); -- Access to socket address type Sockaddr_In is record @SA_LEN@ Sin_Len : C.unsigned_char := 18; @SA_LEN@ Sin_Family : C.unsigned_char := 0; @NO_SA_LEN@ Sin_Family : C.unsigned_short := 0; Sin_Port : C.unsigned_short := 0; Sin_Addr : In_Addr := Inaddr_Any; Sin_Zero : C.char_array (1 .. 8) := (others => C.char'Val (0)); end record; pragma Convention (C, Sockaddr_In); -- Internet socket address Null_Sockaddr_In : constant Sockaddr_In := ( @SA_LEN@ Sin_Len => 18, Sin_Family => 0, Sin_Port => 0, Sin_Addr => Inaddr_Any, Sin_Zero => (others => C.char'Val (0))); type Sockaddr_In_Access is access all Sockaddr_In; pragma Convention (C, Sockaddr_In_Access); -- Access to internet socket address end Sockets.Types; adasockets-v1.14/src/sockets-utils.adb000066400000000000000000000122261454340372400200270ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . U T I L S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Exceptions; use Ada.Exceptions; with Sockets.Thin; use Sockets.Thin; with System; use System; package body Sockets.Utils is use Interfaces.C; --------- -- "*" -- --------- function "*" (Left : String; Right : Natural) return String is Result : String (1 .. Left'Length * Right); First : Positive := 1; Last : Natural := First + Left'Length - 1; begin for I in 1 .. Right loop Result (First .. Last) := Left; First := First + Left'Length; Last := Last + Left'Length; end loop; return Result; end "*"; ------------------- -- Is_Ip_Address -- ------------------- function Is_IP_Address (Something : String) return Boolean is begin for Index in Something'Range loop declare Current : Character renames Something (Index); begin if (Current < '0' or else Current > '9') and then Current /= '.' then return False; end if; end; end loop; return True; end Is_IP_Address; --------------------- -- Port_To_Network -- --------------------- function Port_To_Network (Port : unsigned_short) return unsigned_short is begin pragma Warnings (Off); -- Test is statically always True or False if Default_Bit_Order = High_Order_First then return Port; else return (Port / 256) + (Port mod 256) * 256; end if; pragma Warnings (On); end Port_To_Network; ------------------------ -- Raise_With_Message -- ------------------------ procedure Raise_With_Message (Message : String; With_Errno : Boolean := True) is Current_Errno : constant Integer := Errno; begin if With_Errno then declare -- Using a local block avoids implicit memory allocation, -- which would erase the Errno value on Win32. Message_Text : constant String := Message & " (errno is" & Integer'Image (Current_Errno) & ")"; begin Raise_Exception (Socket_Error'Identity, Message_Text); end; else Raise_Exception (Socket_Error'Identity, Message); end if; end Raise_With_Message; end Sockets.Utils; adasockets-v1.14/src/sockets-utils.ads000066400000000000000000000072661454340372400200600ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . U T I L S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Interfaces.C; private package Sockets.Utils is pragma Elaborate_Body; procedure Raise_With_Message (Message : String; With_Errno : Boolean := True); pragma No_Return (Raise_With_Message); -- Raise Socket_Error with an associated error message function Port_To_Network (Port : Interfaces.C.unsigned_short) return Interfaces.C.unsigned_short; pragma Inline (Port_To_Network); function Network_To_Port (Port : Interfaces.C.unsigned_short) return Interfaces.C.unsigned_short renames Port_To_Network; function "*" (Left : String; Right : Natural) return String; pragma Inline ("*"); -- Return Left string repeated Right times function Is_IP_Address (Something : String) return Boolean; -- Return True if the name looks like an IP address, False otherwise end Sockets.Utils; adasockets-v1.14/src/sockets-vms_link.ads000066400000000000000000000061151454340372400205320ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . V M S _ L I N K -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- -- Dominik Madon changes only for OpenVMS platform -- ----------------------------------------------------------------------------- private package Sockets.VMS_Link is -- pragma Linker_Options ("-lwsock32"); end Sockets.VMS_Link; adasockets-v1.14/src/sockets-windows_link.adb000066400000000000000000000102531454340372400213740ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . W I N D O W S _ L I N K -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- -- Dmitiry Anisimkov changes only for Win32 platform -- ----------------------------------------------------------------------------- with Interfaces.C.Strings; package body Sockets.Windows_Link is use Interfaces, Interfaces.C, Interfaces.C.Strings; Function_Unsupported_On_Win32 : exception; WSAVERNOTSUPPORTED : exception; type WSADATA is record wVersion : Unsigned_16; wHighVersion : Unsigned_16; szDescription : char_array (1 .. 129); szSystemStatus : char_array (1 .. 257); iMaxSockets : Unsigned_16; iMaxUdpDg : Unsigned_16; lpVendorInfo : chars_ptr; end record; pragma Convention (C, WSADATA); WSAInfo : aliased WSADATA; type LPWSADATA is access all WSADATA; pragma Convention (C, LPWSADATA); function WSAStartup (VersionRequested : Short_Integer; WSAData : LPWSADATA) return Integer; pragma Import (StdCall, WSAStartup, "WSAStartup"); ----------------- -- Unsupported -- ----------------- procedure Unsupported is begin raise Function_Unsupported_On_Win32; end Unsupported; Version : constant Short_Integer := 16#0101#; begin if WSAStartup (Version, WSAInfo'Access) /= 0 then raise WSAVERNOTSUPPORTED; end if; end Sockets.Windows_Link; adasockets-v1.14/src/sockets-windows_link.ads000066400000000000000000000062501454340372400214170ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . W I N D O W S _ L I N K -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- -- Dmitriy Anisimkov changes only for Win32 platform -- ----------------------------------------------------------------------------- private package Sockets.Windows_Link is pragma Linker_Options ("-lwsock32"); private procedure Unsupported; pragma Export (C, Unsupported, "socketpair"); end Sockets.Windows_Link; adasockets-v1.14/src/sockets.adb000066400000000000000000000554041454340372400166760ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Unchecked_Deallocation; with Sockets.Constants; use Sockets.Constants; with Sockets.Link; pragma Warnings (Off, Sockets.Link); with Sockets.Naming; use Sockets.Naming; with Sockets.Thin; use Sockets.Thin; with Sockets.Types; use Sockets.Types; with Sockets.Utils; use Sockets.Utils; package body Sockets is use Ada.Streams, Interfaces.C; Socket_Domain_Match : constant array (Socket_Domain) of int := (PF_INET => Constants.Af_Inet, AF_INET => Constants.Af_Inet); -- They hold the same value Socket_Type_Match : constant array (Socket_Type) of int := (SOCK_STREAM => Constants.Sock_Stream, SOCK_DGRAM => Constants.Sock_Dgram); Shutdown_Type_Match : constant array (Shutdown_Type) of int := (Receive => 0, Send => 1, Both => 2); Socket_Level_Match : constant array (Socket_Level) of int := (SOL_SOCKET => Constants.Sol_Socket, IPPROTO_IP => Constants.Ipproto_Ip, SOL_TCP => Constants.Sol_Tcp); Socket_Option_Match : constant array (Socket_Option) of int := (SO_REUSEADDR => Constants.So_Reuseaddr, SO_REUSEPORT => Constants.So_Reuseport, IP_MULTICAST_TTL => Constants.Ip_Multicast_Ttl, IP_ADD_MEMBERSHIP => Constants.Ip_Add_Membership, IP_DROP_MEMBERSHIP => Constants.Ip_Drop_Membership, IP_MULTICAST_LOOP => Constants.Ip_Multicast_Loop, SO_SNDBUF => Constants.So_Sndbuf, SO_RCVBUF => Constants.So_Rcvbuf, SO_KEEPALIVE => Constants.So_Keepalive, SO_NOSIGPIPE => Constants.So_Nosigpipe, TCP_KEEPCNT => Constants.Tcp_Keepcnt, TCP_KEEPIDLE => Constants.Tcp_Keepidle, TCP_KEEPINTVL => Constants.Tcp_Keepintvl, TCP_NODELAY => Constants.Tcp_Nodelay); Socket_Option_Size : constant array (Socket_Option) of Natural := (SO_REUSEADDR => 4, SO_REUSEPORT => 4, IP_MULTICAST_TTL => 1, IP_ADD_MEMBERSHIP => 8, IP_DROP_MEMBERSHIP => 8, IP_MULTICAST_LOOP => 1, SO_SNDBUF => 4, SO_RCVBUF => 4, SO_KEEPALIVE => 4, SO_NOSIGPIPE => 4, TCP_KEEPCNT => 4, TCP_KEEPIDLE => 4, TCP_KEEPINTVL => 4, TCP_NODELAY => 4); CRLF : constant String := CR & LF; procedure Refill (Socket : Socket_FD'Class); -- Refill the socket when in buffered mode by receiving one packet -- and putting it in the buffer. function To_String (S : Stream_Element_Array) return String; function Empty_Buffer (Socket : Socket_FD'Class) return Boolean; -- Return True if buffered socket has an empty buffer ------------------- -- Accept_Socket -- ------------------- procedure Accept_Socket (Socket : Socket_FD; New_Socket : out Socket_FD) is Sin : aliased Sockaddr_In; Size : aliased int := Sin'Size / 8; Code : int; begin Code := C_Accept (Socket.FD, Sin'Address, Size'Access); if Code = Failure then Raise_With_Message ("Accept system call failed"); else New_Socket := (FD => Code, Shutdown => (others => False), Buffer => null); end if; end Accept_Socket; ---------- -- Bind -- ---------- procedure Bind (Socket : Socket_FD; Port : Natural; Host : String := "") is Sin : aliased Sockaddr_In; begin Sin.Sin_Family := Constants.Af_Inet; if Host /= "" then Sin.Sin_Addr := To_In_Addr (Address_Of (Host)); end if; Sin.Sin_Port := Port_To_Network (unsigned_short (Port)); if C_Bind (Socket.FD, Sin'Address, Sin'Size / 8) = Failure then Raise_With_Message ("Bind failed"); end if; end Bind; ------------- -- Connect -- ------------- procedure Connect (Socket : Socket_FD; Host : String; Port : Positive) is Sin : aliased Sockaddr_In; Current_Errno : Integer; begin Sin.Sin_Family := Constants.Af_Inet; Sin.Sin_Addr := To_In_Addr (Address_Of (Host)); Sin.Sin_Port := Port_To_Network (unsigned_short (Port)); if C_Connect (Socket.FD, Sin'Address, Sin'Size / 8) = Failure then Current_Errno := Thin.Errno; if Current_Errno = Constants.Econnrefused then raise Connection_Refused; else Raise_With_Message ("Connection failed (errno was" & Integer'Image (Current_Errno) & ')', False); end if; end if; end Connect; --------------------------- -- Customized_Setsockopt -- --------------------------- procedure Customized_Setsockopt (Socket : Socket_FD'Class; Optval : Opt_Type) is begin pragma Assert (Optval'Size / 8 = Socket_Option_Size (Optname)); if C_Setsockopt (Socket.FD, Socket_Level_Match (Level), Socket_Option_Match (Optname), Optval'Address, Optval'Size / 8) = Failure then Raise_With_Message ("Setsockopt failed"); end if; end Customized_Setsockopt; ------------------ -- Empty_Buffer -- ------------------ function Empty_Buffer (Socket : Socket_FD'Class) return Boolean is begin return Socket.Buffer.First > Socket.Buffer.Last; end Empty_Buffer; --------- -- Get -- --------- function Get (Socket : Socket_FD'Class) return String is begin if Socket.Buffer /= null and then not Empty_Buffer (Socket) then declare S : constant String := To_String (Socket.Buffer.Content (Socket.Buffer.First .. Socket.Buffer.Last)); begin Socket.Buffer.First := Socket.Buffer.Last + 1; return S; end; else return To_String (Receive (Socket)); end if; end Get; -------------- -- Get_Char -- -------------- function Get_Char (Socket : Socket_FD'Class) return Character is C : Stream_Element_Array (0 .. 0); begin if Socket.Buffer = null then -- Unbuffered mode Receive (Socket, C); else -- Buffered mode if Empty_Buffer (Socket) then Refill (Socket); end if; C (0) := Socket.Buffer.Content (Socket.Buffer.First); Socket.Buffer.First := Socket.Buffer.First + 1; end if; return Character'Val (C (0)); end Get_Char; ------------ -- Get FD -- ------------ function Get_FD (Socket : Socket_FD) return Interfaces.C.int is begin return Socket.FD; end Get_FD; -------------- -- Get_Line -- -------------- procedure Get_Line (Socket : Socket_FD'Class; Str : out String; Last : out Natural) is Index : Positive := Str'First; Char : Character; begin loop Char := Get_Char (Socket); if Char = LF then Last := Index - 1; return; elsif Char /= CR then Str (Index) := Char; Index := Index + 1; if Index > Str'Last then Last := Str'Last; return; end if; end if; end loop; end Get_Line; -------------- -- Get_Line -- -------------- function Get_Line (Socket : Socket_FD'Class; Max_Length : Positive := 2048) return String is Result : String (1 .. Max_Length); Last : Natural; begin Get_Line (Socket, Result, Last); return Result (1 .. Last); end Get_Line; ---------------------------- -- Get_Receive_Queue_Size -- ---------------------------- function Get_Receive_Queue_Size (Socket : Socket_FD) return Integer is Error : Interfaces.C.int; Size : aliased Interfaces.C.int := 0; begin -- The check always evaluates statically pragma Warnings (Off, "condition is always *"); if Siocinq = -1 then return -2; end if; pragma Warnings (On, "condition is always *"); Error := C_Ioctl (Socket.FD, Siocinq, Size'Access); if Error < 0 then return Integer (Error); else return Integer (Size); end if; end Get_Receive_Queue_Size; ------------------------- -- Get_Send_Queue_Size -- ------------------------- function Get_Send_Queue_Size (Socket : Socket_FD) return Integer is Error : Interfaces.C.int; Size : aliased Interfaces.C.int := 0; begin -- The check always evaluates statically pragma Warnings (Off, "condition is always *"); if Siocoutq = -1 then return -2; end if; pragma Warnings (On, "condition is always *"); Error := C_Ioctl (Socket.FD, Siocoutq, Size'Access); if Error < 0 then return Integer (Error); else return Integer (Size); end if; end Get_Send_Queue_Size; ---------------- -- Getsockopt -- ---------------- procedure Getsockopt (Socket : Socket_FD'Class; Level : Socket_Level := SOL_SOCKET; Optname : Socket_Option; Optval : out Integer) is Len : aliased int; begin case Socket_Option_Size (Optname) is when 1 => declare C_Char_Optval : aliased char; begin pragma Assert (C_Char_Optval'Size = 8); Len := 1; if C_Getsockopt (Socket.FD, Socket_Level_Match (Level), Socket_Option_Match (Optname), C_Char_Optval'Address, Len'Access) = Failure then Raise_With_Message ("Getsockopt failed"); end if; Optval := char'Pos (C_Char_Optval); end; when 4 => declare C_Int_Optval : aliased int; begin pragma Assert (C_Int_Optval'Size = 32); Len := 4; if C_Getsockopt (Socket.FD, Socket_Level_Match (Level), Socket_Option_Match (Optname), C_Int_Optval'Address, Len'Access) = Failure then Raise_With_Message ("Getsockopt failed"); end if; Optval := Integer (C_Int_Optval); end; when others => Raise_With_Message ("Getsockopt called with wrong arguments", False); end case; end Getsockopt; ------------ -- Listen -- ------------ procedure Listen (Socket : Socket_FD; Queue_Size : Positive := 5) is begin if C_Listen (Socket.FD, int (Queue_Size)) = Failure then Raise_With_Message ("Listen failed"); end if; end Listen; -------------- -- New_Line -- -------------- procedure New_Line (Socket : Socket_FD'Class; Count : Natural := 1) is begin Put (Socket, CRLF * Count); end New_Line; --------- -- Put -- --------- procedure Put (Socket : Socket_FD'Class; Str : String) is Stream : Stream_Element_Array (Stream_Element_Offset (Str'First) .. Stream_Element_Offset (Str'Last)); begin for I in Str'Range loop Stream (Stream_Element_Offset (I)) := Stream_Element'Val (Character'Pos (Str (I))); end loop; Send (Socket, Stream); end Put; -------------- -- Put_Line -- -------------- procedure Put_Line (Socket : Socket_FD'Class; Str : String) is begin Put (Socket, Str & CRLF); end Put_Line; ------------- -- Receive -- ------------- function Receive (Socket : Socket_FD; Max : Stream_Element_Count := 4096) return Stream_Element_Array is Buffer : Stream_Element_Array (1 .. Max); Addr : aliased Sockaddr_In; Addrlen : aliased int := Addr'Size / 8; Count : int; begin if Socket.Shutdown (Receive) then raise Connection_Closed; end if; Count := C_Recvfrom (Socket.FD, Buffer'Address, Buffer'Length, 0, Addr'Address, Addrlen'Access); if Count < 0 then Raise_With_Message ("Receive error"); elsif Count = 0 then raise Connection_Closed; end if; return Buffer (1 .. Stream_Element_Offset (Count)); end Receive; ------------- -- Receive -- ------------- procedure Receive (Socket : Socket_FD'Class; Data : out Stream_Element_Array) is Index : Stream_Element_Offset := Data'First; Rest : Stream_Element_Count := Data'Length; Addr : aliased Sockaddr_In; Addrlen : aliased int := Addr'Size / 8; Count : int; begin while Rest > 0 loop Count := C_Recvfrom (Socket.FD, Data (Index) 'Address, int (Rest), 0, Addr'Address, Addrlen'Access); if Count < 0 then Raise_With_Message ("Receive error"); elsif Count = 0 then raise Connection_Closed; end if; Index := Index + Stream_Element_Count (Count); Rest := Rest - Stream_Element_Count (Count); end loop; end Receive; ------------------ -- Receive_Some -- ------------------ procedure Receive_Some (Socket : Socket_FD'Class; Data : out Stream_Element_Array; Last : out Stream_Element_Offset) is Addr : aliased Sockaddr_In; Addrlen : aliased int := Addr'Size / 8; Count : int; begin Count := C_Recvfrom (Socket.FD, Data (Data'First) 'Address, int (Data'Length), 0, Addr'Address, Addrlen'Access); if Count < 0 then Raise_With_Message ("Receive error"); elsif Count = 0 then raise Connection_Closed; end if; Last := Data'First + Stream_Element_Count (Count) - 1; end Receive_Some; ------------ -- Refill -- ------------ procedure Refill (Socket : Socket_FD'Class) is begin pragma Assert (Socket.Buffer /= null); Receive_Some (Socket, Socket.Buffer.Content, Socket.Buffer.Last); Socket.Buffer.First := 0; end Refill; ---------- -- Send -- ---------- procedure Send (Socket : Socket_FD; Data : Stream_Element_Array) is Index : Stream_Element_Offset := Data'First; Rest : Stream_Element_Count := Data'Length; Count : int; Flags : int := 0; begin if Socket.Shutdown (Send) then raise Connection_Closed; end if; pragma Warnings (Off, "condition is always *"); if Constants.So_Nosigpipe = -1 and Constants.Msg_Nosignal /= -1 then Flags := Constants.Msg_Nosignal; end if; pragma Warnings (On, "condition is always *"); while Rest > 0 loop Count := C_Send (Socket.FD, Data (Index) 'Address, int (Rest), Flags); if Count <= 0 then -- Count could be zero if the socket was in non-blocking mode -- and the output buffers were full. Since we do not support -- non-blocking mode, this is an error. raise Connection_Closed; end if; Index := Index + Stream_Element_Count (Count); Rest := Rest - Stream_Element_Count (Count); end loop; end Send; ---------------- -- Set_Buffer -- ---------------- procedure Set_Buffer (Socket : in out Socket_FD'Class; Length : Positive := 1500) is begin Unset_Buffer (Socket); Socket.Buffer := new Buffer_Type (Stream_Element_Count (Length)); end Set_Buffer; ---------------- -- Setsockopt -- ---------------- procedure Setsockopt (Socket : Socket_FD'Class; Level : Socket_Level := SOL_SOCKET; Optname : Socket_Option; Optval : Integer) is begin case Socket_Option_Size (Optname) is when 1 => declare C_Char_Optval : aliased char := char'Val (Optval); begin pragma Assert (C_Char_Optval'Size = 8); if C_Setsockopt (Socket.FD, Socket_Level_Match (Level), Socket_Option_Match (Optname), C_Char_Optval'Address, 1) = Failure then Raise_With_Message ("Setsockopt failed"); end if; end; when 4 => declare C_Int_Optval : aliased int := int (Optval); begin pragma Assert (C_Int_Optval'Size = 32); if C_Setsockopt (Socket.FD, Socket_Level_Match (Level), Socket_Option_Match (Optname), C_Int_Optval'Address, 4) = Failure then Raise_With_Message ("Setsockopt failed"); end if; end; when others => Raise_With_Message ("Setsockopt called with wrong arguments", False); end case; end Setsockopt; -------------- -- Shutdown -- -------------- procedure Shutdown (Socket : in out Socket_FD; How : Shutdown_Type := Both) is begin if How /= Both then Socket.Shutdown (How) := True; else Socket.Shutdown := (others => True); end if; C_Shutdown (Socket.FD, Shutdown_Type_Match (How)); if Socket.Shutdown (Receive) and then Socket.Shutdown (Send) then declare Result : constant int := C_Close (Socket.FD); pragma Unreferenced (Result); begin Unset_Buffer (Socket); end; end if; end Shutdown; ------------ -- Socket -- ------------ procedure Socket (Sock : out Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM) is Result : constant int := C_Socket (Socket_Domain_Match (Domain), Socket_Type_Match (Typ), 0); begin if Result = Failure then Raise_With_Message ("Unable to create socket"); end if; Sock := (FD => Result, Shutdown => (others => False), Buffer => null); pragma Warnings (Off, "condition is always *"); if Constants.So_Nosigpipe /= -1 then Setsockopt (Sock, SOL_SOCKET, SO_NOSIGPIPE, 1); end if; pragma Warnings (On, "condition is always *"); end Socket; ---------------- -- Socketpair -- ---------------- procedure Socketpair (Read_End : out Socket_FD; Write_End : out Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM) is Filedes : aliased Two_Int; Result : constant int := C_Socketpair (Socket_Domain_Match (Domain), Socket_Type_Match (Typ), 0, Filedes'Address); begin if Result = Failure then Raise_With_Message ("Unable to create socket"); end if; Read_End := (FD => Filedes (0), Shutdown => (others => False), Buffer => null); Write_End := (FD => Filedes (1), Shutdown => (others => False), Buffer => null); end Socketpair; --------------- -- To_String -- --------------- function To_String (S : Stream_Element_Array) return String is Result : String (1 .. S'Length); begin for I in Result'Range loop Result (I) := Character'Val (Stream_Element'Pos (S (Stream_Element_Offset (I) + S'First - 1))); end loop; return Result; end To_String; ------------------ -- Unset_Buffer -- ------------------ procedure Unset_Buffer (Socket : in out Socket_FD'Class) is procedure Free is new Ada.Unchecked_Deallocation (Buffer_Type, Buffer_Access); begin Free (Socket.Buffer); end Unset_Buffer; end Sockets; adasockets-v1.14/src/sockets.ads000066400000000000000000000245461454340372400167220ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1998-2023 Samuel Tardieu -- -- Copyright (C) 1999-2003 Télécom Paris -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets.html -- -- -- -- If you have any question, please use the issues tracker at: -- -- https://github.com/samueltardieu/adasockets/issues -- -- -- ----------------------------------------------------------------------------- with Ada.Streams; with Interfaces.C; package Sockets is type Socket_FD is tagged private; -- A socket Null_Socket_FD : constant Socket_FD; -- An empty socket type Socket_Domain is (PF_INET, AF_INET); -- PF_INET: Internet sockets -- AF_INET: This entry is bogus and should never be used, but it is -- kept here for some time for compatibility reasons. type Socket_Type is (SOCK_STREAM, SOCK_DGRAM); -- SOCK_STREAM: Stream mode (TCP) -- SOCK_DGRAM: Datagram mode (UDP, Multicast) procedure Socket (Sock : out Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM); -- Create a socket of the given mode Connection_Refused : exception; Socket_Error : exception; procedure Connect (Socket : Socket_FD; Host : String; Port : Positive); -- Connect a socket on a given host/port. Raise Connection_Refused if -- the connection has not been accepted by the other end, or -- Socket_Error (with a more precise exception message) for another error. procedure Bind (Socket : Socket_FD; Port : Natural; Host : String := ""); -- Bind a socket on a given port. Using 0 for the port will tell the -- OS to allocate a non-privileged free port. The port can be later -- retrieved using Get_Sock_Port on the bound socket. -- If Host is not the empty string, it is used to designate the interface -- to bind on. -- Socket_Error can be raised if the system refuses to bind the port. procedure Listen (Socket : Socket_FD; Queue_Size : Positive := 5); -- Create a socket's listen queue type Socket_Level is (SOL_SOCKET, IPPROTO_IP, SOL_TCP); type Socket_Option is (SO_REUSEADDR, SO_REUSEPORT, IP_MULTICAST_TTL, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_LOOP, SO_SNDBUF, SO_RCVBUF, SO_KEEPALIVE, SO_NOSIGPIPE, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_NODELAY); procedure Getsockopt (Socket : Socket_FD'Class; Level : Socket_Level := SOL_SOCKET; Optname : Socket_Option; Optval : out Integer); -- Get a socket option procedure Setsockopt (Socket : Socket_FD'Class; Level : Socket_Level := SOL_SOCKET; Optname : Socket_Option; Optval : Integer); -- Set a socket option generic Level : Socket_Level; Optname : Socket_Option; type Opt_Type is private; procedure Customized_Setsockopt (Socket : Socket_FD'Class; Optval : Opt_Type); -- Low level control on setsockopt procedure Accept_Socket (Socket : Socket_FD; New_Socket : out Socket_FD); -- Accept a connection on a socket Connection_Closed : exception; procedure Send (Socket : Socket_FD; Data : Ada.Streams.Stream_Element_Array); -- Send data on a socket. Raise Connection_Closed if the socket -- has been closed. function Receive (Socket : Socket_FD; Max : Ada.Streams.Stream_Element_Count := 4096) return Ada.Streams.Stream_Element_Array; -- Receive data from a socket. May raise Connection_Closed procedure Receive (Socket : Socket_FD'Class; Data : out Ada.Streams.Stream_Element_Array); -- Get data from a socket. Raise Connection_Closed if the socket has -- been closed before the end of the array. procedure Receive_Some (Socket : Socket_FD'Class; Data : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset); -- Get some data from a socket. The index of the last element will -- be placed in Last. type Shutdown_Type is (Receive, Send, Both); procedure Shutdown (Socket : in out Socket_FD; How : Shutdown_Type := Both); -- Close a previously opened socket procedure Socketpair (Read_End : out Socket_FD; Write_End : out Socket_FD; Domain : Socket_Domain := PF_INET; Typ : Socket_Type := SOCK_STREAM); -- Create a socketpair. function Get_FD (Socket : Socket_FD) return Interfaces.C.int; pragma Inline (Get_FD); -- Get a socket's FD field --------------------------------- -- String-oriented subprograms -- --------------------------------- procedure Put (Socket : Socket_FD'Class; Str : String); -- Send a string on the socket procedure New_Line (Socket : Socket_FD'Class; Count : Natural := 1); -- Send CR/LF sequences on the socket procedure Put_Line (Socket : Socket_FD'Class; Str : String); -- Send a string + CR/LF on the socket function Get (Socket : Socket_FD'Class) return String; -- Get a string from the socket function Get_Char (Socket : Socket_FD'Class) return Character; -- Get one character from the socket procedure Get_Line (Socket : Socket_FD'Class; Str : out String; Last : out Natural); -- Get a full line from the socket. CR is ignored and LF is considered -- as an end-of-line marker. function Get_Line (Socket : Socket_FD'Class; Max_Length : Positive := 2048) return String; -- Function form for the former procedure procedure Set_Buffer (Socket : in out Socket_FD'Class; Length : Positive := 1500); -- Put socket in buffered mode. If the socket is already buffered, -- the content of the previous buffer will be lost. The buffered mode -- only affects read operation, through Get, Get_Char and Get_Line. Other -- reception subprograms will not function properly if buffered mode -- is used at the same time. The size of the buffer has to be greater -- than the biggest possible packet, otherwise data loss may occur. procedure Unset_Buffer (Socket : in out Socket_FD'Class); -- Put socket in unbuffered mode. If the socket was unbuffered already, -- no error will be raised. If it was buffered and the buffer was not -- empty, its content will be lost. function Get_Send_Queue_Size (Socket : Socket_FD) return Integer; -- Return size of unsent data in socket output buffer. -- Return a value less than 0 in case of error. -2 means that the -- information is not available (Linux only). function Get_Receive_Queue_Size (Socket : Socket_FD) return Integer; -- Return size of unread data in socket input buffer. -- Return a value less than 0 in case of error. -2 means that the -- information is not available (Linux only). private use type Ada.Streams.Stream_Element_Count; type Buffer_Type (Length : Ada.Streams.Stream_Element_Count) is record -- One byte will stay unused, but this does not have any consequence First : Ada.Streams.Stream_Element_Offset := Ada.Streams.Stream_Element_Offset'Last; Last : Ada.Streams.Stream_Element_Offset := 0; Content : Ada.Streams.Stream_Element_Array (0 .. Length); end record; type Buffer_Access is access Buffer_Type; type Shutdown_Array is array (Receive .. Send) of Boolean; type Socket_FD is tagged record FD : Interfaces.C.int := Interfaces.C."-" (1); Shutdown : Shutdown_Array := (others => True); Buffer : Buffer_Access; end record; Null_Socket_FD : constant Socket_FD := (FD => Interfaces.C."-" (1), Shutdown => (others => True), Buffer => null); end Sockets; adasockets-v1.14/support/000077500000000000000000000000001454340372400154705ustar00rootroot00000000000000adasockets-v1.14/support/.gitignore000066400000000000000000000002241454340372400174560ustar00rootroot00000000000000/00gnulib.m4 /gnulib-common.m4 /gnulib-comp.m4 /gnulib-tool.m4 /zzgnulib.m4 /bootstrap.in /extract-trace /funclib.sh /inline-source /options-parser adasockets-v1.14/support/adacompiler000077500000000000000000000006121454340372400176750ustar00rootroot00000000000000#! /bin/sh # # Extract the directory name from "-o .libs/foobar.lo" and do the move # after the compilation. # GNATMAKE=$1 shift cline="$@" fname=`echo $cline | sed -e 's/^.* -o \([^ ]*\)$/\1/'` rname=`basename $fname | sed -e 's/lo$/o/'` cline=`echo $cline | sed -e "s, -o \([^ ]*\)\$,,"` $GNATMAKE -f -u $cline if [ "$rname" != "$fname" ]; then echo mv $rname $fname mv $rname $fname fi adasockets-v1.14/support/git2cl000077500000000000000000000262671454340372400166170ustar00rootroot00000000000000#!/usr/bin/env perl # Copyright (C) 2007, 2008 Simon Josefsson # Copyright (C) 2007 Luis Mondesi # * calls git directly. To use it just: # cd ~/Project/my_git_repo; git2cl > ChangeLog # * implements strptime() # * fixes bugs in $comment parsing # - copy input before we remove leading spaces # - skip "merge branch" statements as they don't # have information about files (i.e. we never # go into $state 2) # - behaves like a pipe/filter if input is given from the CLI # else it calls git log by itself # # The functions mywrap, last_line_len, wrap_log_entry are derived from # the cvs2cl tool, see : # Copyright (C) 2001,2002,2003,2004 Martyn J. Pearce # Copyright (C) 1999 Karl Fogel # # git2cl 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 2, or (at your option) # any later version. # # git2cl 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 git2cl; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA. =head1 NAME git2cl - tool to convert git logs to GNU ChangeLog =head1 SYNOPSIS git2cl > ChangeLog If you don't want git2cl to invoke git log internally, you can use it as a pipe. It needs a git log generated with --pretty --numstat and --summary. You can use it as follows: git log --pretty --numstat --summary | git2cl > ChangeLog =head1 DESCRIPTION This is a quick'n'dirty tool to convert git logs to GNU ChangeLog format. The tool invokes `git log` internally unless you pipe a log to it. Thus, typically you would use it as follows: =head1 SEE ALSO Output format specification: =head1 AUTHORS git2cl is developed by Simon Josefsson and Luis Mondesi =cut use strict; use POSIX qw(strftime); use Text::Wrap qw(wrap); use FileHandle; use constant EMPTY_LOG_MESSAGE => '*** empty log message ***'; # this is a helper hash for stptime. # Assumes you are calling 'git log ...' with LC_ALL=C my %month = ( 'Jan'=>0, 'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4, 'Jun'=>5, 'Jul'=>6, 'Aug'=>7, 'Sep'=>8, 'Oct'=>9, 'Nov'=>10, 'Dec'=>11, ); my $fh = new FileHandle; sub key_ready { my ($rin, $nfd); vec($rin, fileno(STDIN), 1) = 1; return $nfd = select($rin, undef, undef, 0); } sub strptime { my $str = shift; return undef if not defined $str; # we are parsing this format # Fri Oct 26 00:42:56 2007 -0400 # to these fields # sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1 # Luis Mondesi my @date; if ($str =~ /([[:alpha:]]{3})\s+([[:alpha:]]{3})\s+([[:digit:]]{1,2})\s+([[:digit:]]{1,2}):([[:digit:]]{1,2}):([[:digit:]]{1,2})\s+([[:digit:]]{4})/){ push(@date,$6,$5,$4,$3,$month{$2},($7 - 1900),-1,-1,-1); } else { die ("Cannot parse date '$str'\n'"); } return @date; } sub mywrap { my ($indent1, $indent2, @text) = @_; # If incoming text looks preformatted, don't get clever my $text = Text::Wrap::wrap($indent1, $indent2, @text); if ( grep /^\s+/m, @text ) { return $text; } my @lines = split /\n/, $text; $indent2 =~ s!^((?: {8})+)!"\t" x (length($1)/8)!e; $lines[0] =~ s/^$indent1\s+/$indent1/; s/^$indent2\s+/$indent2/ for @lines[1..$#lines]; my $newtext = join "\n", @lines; $newtext .= "\n" if substr($text, -1) eq "\n"; return $newtext; } sub last_line_len { my $files_list = shift; my @lines = split (/\n/, $files_list); my $last_line = pop (@lines); return length ($last_line); } # A custom wrap function, sensitive to some common constructs used in # log entries. sub wrap_log_entry { my $text = shift; # The text to wrap. my $left_pad_str = shift; # String to pad with on the left. # These do NOT take left_pad_str into account: my $length_remaining = shift; # Amount left on current line. my $max_line_length = shift; # Amount left for a blank line. my $wrapped_text = ''; # The accumulating wrapped entry. my $user_indent = ''; # Inherited user_indent from prev line. my $first_time = 1; # First iteration of the loop? my $suppress_line_start_match = 0; # Set to disable line start checks. my @lines = split (/\n/, $text); while (@lines) # Don't use `foreach' here, it won't work. { my $this_line = shift (@lines); chomp $this_line; if ($this_line =~ /^(\s+)/) { $user_indent = $1; } else { $user_indent = ''; } # If it matches any of the line-start regexps, print a newline now... if ($suppress_line_start_match) { $suppress_line_start_match = 0; } elsif (($this_line =~ /^(\s*)\*\s+[a-zA-Z0-9]/) || ($this_line =~ /^(\s*)\* [a-zA-Z0-9_\.\/\+-]+/) || ($this_line =~ /^(\s*)\([a-zA-Z0-9_\.\/\+-]+(\)|,\s*)/) || ($this_line =~ /^(\s+)(\S+)/) || ($this_line =~ /^(\s*)- +/) || ($this_line =~ /^()\s*$/) || ($this_line =~ /^(\s*)\*\) +/) || ($this_line =~ /^(\s*)[a-zA-Z0-9](\)|\.|\:) +/)) { $length_remaining = $max_line_length - (length ($user_indent)); } # Now that any user_indent has been preserved, strip off leading # whitespace, so up-folding has no ugly side-effects. $this_line =~ s/^\s*//; # Accumulate the line, and adjust parameters for next line. my $this_len = length ($this_line); if ($this_len == 0) { # Blank lines should cancel any user_indent level. $user_indent = ''; $length_remaining = $max_line_length; } elsif ($this_len >= $length_remaining) # Line too long, try breaking it. { # Walk backwards from the end. At first acceptable spot, break # a new line. my $idx = $length_remaining - 1; if ($idx < 0) { $idx = 0 }; while ($idx > 0) { if (substr ($this_line, $idx, 1) =~ /\s/) { my $line_now = substr ($this_line, 0, $idx); my $next_line = substr ($this_line, $idx); $this_line = $line_now; # Clean whitespace off the end. chomp $this_line; # The current line is ready to be printed. $this_line .= "\n${left_pad_str}"; # Make sure the next line is allowed full room. $length_remaining = $max_line_length - (length ($user_indent)); # Strip next_line, but then preserve any user_indent. $next_line =~ s/^\s*//; # Sneak a peek at the user_indent of the upcoming line, so # $next_line (which will now precede it) can inherit that # indent level. Otherwise, use whatever user_indent level # we currently have, which might be none. my $next_next_line = shift (@lines); if ((defined ($next_next_line)) && ($next_next_line =~ /^(\s+)/)) { $next_line = $1 . $next_line if (defined ($1)); # $length_remaining = $max_line_length - (length ($1)); $next_next_line =~ s/^\s*//; } else { $next_line = $user_indent . $next_line; } if (defined ($next_next_line)) { unshift (@lines, $next_next_line); } unshift (@lines, $next_line); # Our new next line might, coincidentally, begin with one of # the line-start regexps, so we temporarily turn off # sensitivity to that until we're past the line. $suppress_line_start_match = 1; last; } else { $idx--; } } if ($idx == 0) { # We bottomed out because the line is longer than the # available space. But that could be because the space is # small, or because the line is longer than even the maximum # possible space. Handle both cases below. if ($length_remaining == ($max_line_length - (length ($user_indent)))) { # The line is simply too long -- there is no hope of ever # breaking it nicely, so just insert it verbatim, with # appropriate padding. $this_line = "\n${left_pad_str}${this_line}"; } else { # Can't break it here, but may be able to on the next round... unshift (@lines, $this_line); $length_remaining = $max_line_length - (length ($user_indent)); $this_line = "\n${left_pad_str}"; } } } else # $this_len < $length_remaining, so tack on what we can. { # Leave a note for the next iteration. $length_remaining = $length_remaining - $this_len; if ($this_line =~ /\.$/) { $this_line .= " "; $length_remaining -= 2; } else # not a sentence end { $this_line .= " "; $length_remaining -= 1; } } # Unconditionally indicate that loop has run at least once. $first_time = 0; $wrapped_text .= "${user_indent}${this_line}"; } # One last bit of padding. $wrapped_text .= "\n"; return $wrapped_text; } # main my @date; my $author; my @files; my $comment; my $state; # 0-header 1-comment 2-files my $done = 0; $state = 0; # if reading from STDIN, we assume that we are # getting git log as input if (key_ready()) { #my $dummyfh; # don't care about writing #($fh,$dummyfh) = FileHandle::pipe; $fh->fdopen(*STDIN, 'r'); } else { $fh->open("LC_ALL=C git log --pretty --numstat --summary|") or die("Cannot execute git log...$!\n"); } while (my $_l = <$fh>) { #print STDERR "debug ($state, " . (@date ? (strftime "%Y-%m-%d", @date) : "") . "): `$_'\n"; if ($state == 0) { if ($_l =~ m,^Author: (.*),) { $author = $1; } if ($_l =~ m,^Date: (.*),) { @date = strptime($1); } $state = 1 if ($_l =~ m,^$, and $author and (@date+0>0)); } elsif ($state == 1) { # * modifying our input text is a bad choice # let's make a copy of it first, then we remove spaces # * if we meet a "merge branch" statement, we need to start # over and find a real entry # Luis Mondesi my $_s = $_l; $_s =~ s/^ //g; if ($_s =~ m/^Merge branch/) { $state=0; next; } $comment = $comment . $_s; $state = 2 if ($_l =~ m,^$,); } elsif ($state == 2) { if ($_l =~ m,^([0-9]+)\t([0-9]+)\t(.*)$,) { push @files, $3; } $done = 1 if ($_l =~ m,^$,); } if ($done) { print (strftime "%Y-%m-%d $author\n\n", @date); my $files = join (", ", @files); $files = mywrap ("\t", "\t", "* $files"), ": "; if (index($comment, EMPTY_LOG_MESSAGE) > -1 ) { $comment = "[no log message]\n"; } my $files_last_line_len = 0; $files_last_line_len = last_line_len($files) + 1; my $msg = wrap_log_entry($comment, "\t", 69-$files_last_line_len, 69); $msg =~ s/[ \t]+\n/\n/g; print "$files: $msg\n"; @date = (); $author = ""; @files = (); $comment = ""; $state = 0; $done = 0; } } if (@date + 0) { print (strftime "%Y-%m-%d $author\n\n", @date); my $msg = wrap_log_entry($comment, "\t", 69, 69); $msg =~ s/[ \t]+\n/\n/g; print "\t* $msg\n"; } adasockets-v1.14/support/test-build.sh000077500000000000000000000004011454340372400200760ustar00rootroot00000000000000#! /bin/sh -e autoreconf -fvi rm -rf *.tar.gz ./configure make dist rm -rf _build mkdir _build cd _build tar zxvf ../*.tar.gz cd adasockets* mkdir _build _install parent="$PWD" cd _build ../configure --prefix="$parent/_install" make make check make install adasockets-v1.14/tests/000077500000000000000000000000001454340372400151165ustar00rootroot00000000000000adasockets-v1.14/tests/Makefile.am000066400000000000000000000010601454340372400171470ustar00rootroot00000000000000TESTS = value-localhost.test value-invalid.test \ value-regular.test value-compressed.test \ multicast_test XFAIL_TESTS = value-invalid.test all-local: multicast_test value multicast_test: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) multicast_test -cargs $(ADAFLAGS) -largs $(LDFLAGS) value: never $(GNATMAKE) -m -A../src -A$(top_srcdir)/src -I$(srcdir) value -cargs $(ADAFLAGS) -largs $(LDFLAGS) CLEANFILES = *.o *.ali b_*.c b~*.ad[bs] DISTCLEANFILES = multicast_test value EXTRA_DIST = *.test multicast_test.adb value.adb never:: adasockets-v1.14/tests/multicast_test.adb000066400000000000000000000076731454340372400206470ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- M U L T I C A S T - T E S T -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2020 Samuel Tardieu -- -- Copyright (C) 1999-2003 ENST http://www.enst.fr/ -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Multicast; use Sockets, Sockets.Multicast; procedure Multicast_Test is Sock : constant Multicast_Socket_FD := Create_Multicast_Socket ("224.13.194.161", 0); task Send_Packets; task body Send_Packets is begin for I in 1 .. 30 loop delay 0.01; Put_Line ("Emitting ""foo"""); Put (Sock, "foo"); end loop; exception when E : others => Put_Line ("Exception raised in Send_Packets task:" & Exception_Information (E)); end Send_Packets; begin Set_Exit_Status (1); select delay 1.0; then abort Put_Line ("Waiting for input"); if Get (Sock) = "foo" then Put_Line ("Got ""foo"""); Set_Exit_Status (0); abort Send_Packets; else Put_Line ("Got something else"); end if; end select; exception when E : others => Put_Line ("Exception raised in main task:" & Exception_Information (E)); end Multicast_Test; adasockets-v1.14/tests/value-compressed.test000077500000000000000000000000701454340372400212750ustar00rootroot00000000000000#! /bin/sh # [ $(./value 2311233794) = 137.194.161.2 ] adasockets-v1.14/tests/value-invalid.test000077500000000000000000000000441454340372400205600ustar00rootroot00000000000000#! /bin/sh # ./value 137.194.257.1 adasockets-v1.14/tests/value-localhost.test000077500000000000000000000000571454340372400211260ustar00rootroot00000000000000#! /bin/sh # [ $(./value 127.1) = 127.0.0.1 ] adasockets-v1.14/tests/value-regular.test000077500000000000000000000000731454340372400205750ustar00rootroot00000000000000#! /bin/sh # [ $(./value 137.194.161.2) = 137.194.161.2 ] adasockets-v1.14/tests/value.adb000066400000000000000000000064371454340372400167140ustar00rootroot00000000000000----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- V A L U E -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2020 Samuel Tardieu -- -- Copyright (C) 1999-2003 ENST http://www.enst.fr/ -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets 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 distributed -- -- with AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from -- -- this unit, or you link this unit with other files to produce an -- -- executable, this unit does not by itself cause the resulting -- -- executable to be covered by the GNU General Public License. This -- -- exception does not however invalidate any other reasons why the -- -- executable file might be covered by the GNU Public License. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to the AdaSockets list -- -- adasockets@lists.rfc1149.net -- -- -- ----------------------------------------------------------------------------- with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Naming; use Sockets, Sockets.Naming; procedure Value is -- Usage: value IP -- Example: value 137.194.161.2 begin if Argument_Count /= 1 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " IP"); end if; Put_Line (Image (Value (Argument (1)))); end Value; adasockets-v1.14/utils/000077500000000000000000000000001454340372400151145ustar00rootroot00000000000000adasockets-v1.14/utils/update-headers.el000066400000000000000000000053431454340372400203360ustar00rootroot00000000000000;;; ;;; This file contains the update-header command which can be used to ;;; update headers depending on the header.txt file in the current directory. ;;; ;;; It should be used as: ;;; emacs -batch -l ../utils/update-headers.el -f update-headers ;;; ;;; XXXXX will be replaced by context-dependent information. ;;; (defun update-header () "Update headers according to header.txt." (interactive) (let (name spec) (goto-char (point-min)) (if (re-search-forward "^-- $Id" nil t) (progn (next-line 2) (beginning-of-line) (delete-region (point-min) (point)))) (goto-char (point-min)) (next-line 1) (if (re-search-forward "^----------" nil t) (progn (next-line 1) (beginning-of-line) (delete-region (point-min) (point)))) (goto-char (point-min)) (if (re-search-forward "package body \\(.+\\) is" nil t) (setq name (buffer-substring (match-beginning 1) (match-end 1))) (goto-char (point-min)) (if (re-search-forward "package \\(.+\\) is" nil t) (setq name (buffer-substring (match-beginning 1) (match-end 1)) spec t) (goto-char (point-min)) (if (re-search-forward "^procedure \\([^ ;]+\\)" nil t) (setq name (buffer-substring (match-beginning 1) (match-end 1)) spec (string-match "ads" (buffer-name))) (goto-char (point-min)) (if (re-search-forward "^function \\([^ ;]+\\)" nil t) (setq name (buffer-substring (match-beginning 1) (match-end 1)) spec (string-match "ads" (buffer-name))))))) (goto-char (point-min)) (insert-file "header.txt") (goto-char (point-min)) (re-search-forward "^XXXXX" nil) (beginning-of-line) (let ((beg (point))) (next-line 1) (delete-region beg (point))) (insert (center-ada (upcase (expand-ada-name name)))) (insert (center-ada "")) (insert (center-ada (if spec "S p e c" "B o d y"))) (re-search-forward "----------") (next-line 1) (let ((beg (point))) (end-of-line) (if (not (equal (buffer-substring beg (point)) "")) (progn (beginning-of-line) (insert "\n")))))) (defun expand-ada-name (n) (if (<= (length n) 1) n (concat (substring n 0 1) " " (expand-ada-name (substring n 1))))) (defun center-ada (l) (let* ((tt 70) (n (length l)) (s (/ (- tt n) 2))) (concat "-- " (spaces-ada s) l (spaces-ada (- tt (+ s n))) " --\n"))) (defun spaces-ada (n) (if (<= n 0) "" (concat " " (spaces-ada (- n 1))))) (defun update-headers () "Update headers of files given on the command line" (interactive) (let ((l (directory-files "." nil "\\.ad[bs]" nil))) (while l (let ((current (car l))) (message "Updating %s..." current) (find-file current) (update-header) (write-file current) (message "Updating %s... done" current) (setq l (cdr l)))))) adasockets-v1.14/vms/000077500000000000000000000000001454340372400145615ustar00rootroot00000000000000adasockets-v1.14/vms/Makefile.VMS000066400000000000000000000007541454340372400166730ustar00rootroot00000000000000# # VMS specific Makefile to build the # sockets-constants.ads file. # # $Revision$ # # This file is part of adasockets port to OpenVMS .PHONY: all distclean clean .DEFAULT: all all: sockets-constants.ads sockets-constants.ads: constants.exe \@create_constants_ads.com constants.exe: constants.c cc constants link constants constants.c: constants.list \@create_constants_c.com distclean: del *.exe;*, *.obj;*, *.c;*, sockets-constants.ads;* clean: del *.exe;*, *.obj;*, *.c;* adasockets-v1.14/vms/constants.c_pre000066400000000000000000000021761454340372400176150ustar00rootroot00000000000000/* * This is an incomplete C program preamble aimed to extract * constants' values. The complete source is generated by * CREATE_CONSTANTS_C.COM. * * NOTE: THIS CODE IS SPECIFIC TO OPENVMS 7.2 OR ABOVE PLATFORMS * */ #include #include #include #include #include #include #include #include #include #include #include #include static char * capitalize (char *name) { int beginning = 1; char *result = (char *) malloc (strlen (name) + 1); char *ptr; for (ptr = result; *name; ptr++, name++) { *ptr = *name; if (beginning) { beginning = 0; } else if (*ptr == '_') { beginning = 1; } else if (isupper(*ptr)) { *ptr = tolower(*ptr); } } *ptr = '\0'; return result; } static void output (char *name, int value) { char *capitalized = capitalize (name); if (value >= 0) { printf (" %-20s : constant := 16#%04X#;\n", capitalized, value); } else { printf (" %-20s : constant := %d;\n", capitalized, value); } } int main (int argc, char *argv[]) { adasockets-v1.14/vms/constants.list000066400000000000000000000015401454340372400174720ustar00rootroot00000000000000TCP_NODELAY AF_INET AF_UNIX SOCK_STREAM SOCK_DGRAM EINTR EAGAIN EWOULDBLOCK EINPROGRESS EALREADY EISCONN ECONNREFUSED FNDELAY FASYNC FIOASYNC F_GETFL F_SETFL F_SETOWN FIOSSAIOOWN SO_RCVBUF SO_REUSEADDR SO_REUSEPORT SOL_SOCKET SIGTERM SIGKILL O_RDONLY O_WRONLY O_RDWR HOST_NOT_FOUND TRY_AGAIN NO_RECOVERY NO_DATA NO_ADDRESS POLLIN POLLPRI POLLOUT POLLERR POLLHUP POLLNVAL I_SETSIG S_RDNORM S_WRNORM IPPROTO_IP IP_ADD_MEMBERSHIP IP_MULTICAST_LOOP IP_MULTICAST_TTL IP_DROP_MEMBERSHIP O_NONBLOCK MSG_PEEK FIONBIO FIONREAD SO_SNDBUF AF_INET6 AI_ADDRCONFIG AI_ALL AI_CANONNAME AI_DEFAULT AI_MASK AI_NUMERICHOST AI_PASSIVE AI_V4MAPPED AI_V4MAPPED_CFG NI_DGRAM NI_MAXHOST NI_MAXSERV NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST NI_NUMERICSERV NI_WITHSCOPEID IPPROTO_IPV6 IPV6_UNICAST_HOPS IPV6_MULTICAST_IF IPV6_MULTICAST_HOPS IPV6_MULTICAST_LOOP IPV6_JOIN_GROUP IPV6_LEAVE_GROUP adasockets-v1.14/vms/create_constants_ads.com000066400000000000000000000017451454340372400214560ustar00rootroot00000000000000$! $! This script produces a sockets-constants.ads file $! for adasockets on OpenVMS platform. $! $! This file is part of adasockets port to OpenVMS $! $! $! Let's write the header $! $ OPEN/WRITE OUT SOCKETS-CONSTANTS.ADS $ WRITE OUT "-- This file has been generated automatically by" $ WRITE OUT "-- CREATE_CONSTANTS_ADS.COM." $ WRITE OUT "--" $ WRITE OUT "-- This file is part of adasockets port to OpenVMS" $ WRITE OUT "--" $ WRITE OUT "package sockets.constants is" $! $! Now Include the contents. $! Make a line copy to get rid of the file attribut $! compatibility between TMP.OUT and SOCKETS-CONSTANTS.ADS $! $ PIPE RUN CONSTANTS.EXE | TYPE/OUT=TMP.OUT SYS$INPUT $ loop_label: $ OPEN IN TMP.OUT $ READ/END_OF_FILE=end_label IN LINE $ WRITE OUT LINE $ GOTO loop_label $ end_label: $ CLOSE IN $ DEL/NOCONF/LOG TMP.OUT;* $! $! Then close the specification file $! $ WRITE OUT "end sockets.constants;" $ CLOSE OUT $ EXIT adasockets-v1.14/vms/create_constants_c.com000066400000000000000000000012101454340372400211140ustar00rootroot00000000000000$! $! $Revision$ $! $! $! This script completes the constants.c_pre file with the $! the list of defines needed to build the adasockets constant $! package. $! $! This file is part of Adasockets for OpenVMS. $! $ OPEN/READ in CONSTANTS.LIST $ COPY CONSTANTS.C_PRE CONSTANTS.C $ OPEN/APPEND out CONSTANTS.C $! $ Loop: $ READ/END_OF_FILE=End_Loop in line $ WRITE out "#ifdef ''line'" $ WRITE out " output (""''line'"", ''line');" $ WRITE out "#else" $ WRITE out " output (""''line'"", -1);" $ WRITE out "#endif" $ GOTO Loop $! $ End_Loop: $ WRITE out "}" $ CLOSE in $ CLOSE out $ EXIT