├── .editorconfig ├── .github └── workflows │ ├── codeql.yml │ ├── linuxbuild.yml │ ├── macosbuild.yml │ └── winbuild.yml ├── .gitignore ├── AUTHORS ├── CONTRIBUTING.rst ├── COPYING ├── COPYING.LIB ├── ChangeLog ├── FAQ.rst ├── ISSUES ├── Makefile.am ├── NEWS ├── README ├── README.rst ├── RELEASE_PROCESS.rst ├── SECURITY.md ├── TODO ├── c++ ├── Makefile.am ├── README.rst ├── examples │ ├── .gitignore │ ├── Makefile.am │ ├── mdns.cc │ ├── telnet_client.cc │ └── telnet_server.cc ├── include │ ├── Makefile.am │ └── gensio │ │ ├── Makefile.am │ │ ├── gensio │ │ ├── gensio_dllvisibility │ │ ├── gensiomdns │ │ ├── gensioosh │ │ └── gensioosh_dllvisibility ├── lib │ ├── Makefile.am │ ├── gensio.cc │ ├── gensiomdns.cc │ ├── gensioosh.cc │ ├── libgensiocpp.pc.in │ ├── libgensiomdnscpp.pc.in │ └── libgensiooshcpp.pc.in ├── swig │ ├── Makefile.am │ ├── go │ │ ├── Makefile.am │ │ ├── README.rst │ │ ├── examples │ │ │ ├── Makefile.am │ │ │ ├── srcexample.go │ │ │ ├── srctelnet_client.go │ │ │ └── srctelnet_server.go │ │ ├── gensio │ │ │ ├── Makefile.am │ │ │ ├── gensio.srcswigcxx │ │ │ ├── gensioapi.srcgo │ │ │ └── go.srcmod │ │ └── tests │ │ │ ├── Makefile.am │ │ │ ├── runtest.in │ │ │ ├── srctest_ax25.go │ │ │ ├── srctest_basic.go │ │ │ ├── srctest_crypto.go │ │ │ ├── srctest_mdns.go │ │ │ ├── srctest_netifs.go │ │ │ ├── srctest_serial.go │ │ │ └── testbase │ │ │ ├── Makefile.am │ │ │ └── testbase.srcgo │ ├── include │ │ ├── Makefile.am │ │ └── gensio_base.i │ └── pygensio │ │ ├── Makefile.am │ │ ├── README.rst │ │ ├── include │ │ ├── Makefile.am │ │ └── gensio │ │ │ ├── Makefile.am │ │ │ └── pygensio.h │ │ ├── pygensio.i │ │ └── tests │ │ ├── Makefile.am │ │ ├── runtest.in │ │ ├── test_ax25.py │ │ ├── test_basic.py │ │ ├── test_crypto.py │ │ ├── test_mdns.py │ │ ├── test_serial.py │ │ └── testbase.py └── tests │ ├── Makefile.am │ ├── basic_cpp_test.cc │ └── serial_test.cc ├── checks ├── README.rst ├── ssl_thread_issue.c └── test_pselect.c ├── configure.ac ├── docs ├── AFSK_Modem.rst ├── AGWPE.pdf └── AX25.2.2-Jul 98-2.pdf ├── examples ├── .gitignore ├── LICENSE.apache ├── Makefile.am ├── basic_client.c ├── basic_client.py ├── basic_server.c ├── basic_server.py ├── basic_server_sync.c ├── basic_server_sync_fork.c ├── poll_and_gensio.c └── use_iods.c ├── gensio.iss ├── glib ├── Makefile.am ├── c++ │ ├── Makefile.am │ ├── include │ │ ├── Makefile.am │ │ └── gensio │ │ │ ├── Makefile.am │ │ │ └── gensioglib │ ├── swig │ │ ├── Makefile.am │ │ └── pygensio │ │ │ ├── .gitignore │ │ │ ├── Makefile.am │ │ │ ├── README.rst │ │ │ └── pygensioglib.i │ └── tests │ │ ├── Makefile.am │ │ └── basic_glib_test.cc ├── gensio_glib.c ├── gensio_glib_funcs_alloc.3 ├── include │ ├── Makefile.am │ └── gensio │ │ ├── Makefile.am │ │ ├── gensio_glib.h │ │ └── gensio_glib_dllvisibility.h ├── libgensioglib.pc.in └── swig │ ├── Makefile.am │ ├── gensioglib.i │ └── python │ ├── .gitignore │ └── Makefile.am ├── include ├── Makefile.am ├── gensio │ ├── .gitignore │ ├── Makefile.am │ ├── argvutils.h │ ├── gensio.h │ ├── gensio_acc_gensio.h │ ├── gensio_addr.h │ ├── gensio_atomics.h │ ├── gensio_ax25_addr.h │ ├── gensio_base.h │ ├── gensio_buffer.h │ ├── gensio_byteswap.h │ ├── gensio_circbuf.h │ ├── gensio_class.h │ ├── gensio_control.h │ ├── gensio_deprecated.h │ ├── gensio_dllvisibility.h │ ├── gensio_err.h │ ├── gensio_list.h │ ├── gensio_ll_fd.h │ ├── gensio_ll_gensio.h │ ├── gensio_mdns.h │ ├── gensio_openipmi_oshandler.h │ ├── gensio_os_funcs.h │ ├── gensio_os_funcs_public.h │ ├── gensio_osops.h │ ├── gensio_osops_addrinfo.h │ ├── gensio_osops_env.h │ ├── gensio_osops_stdsock.h │ ├── gensio_refcount.h │ ├── gensio_selector.h │ ├── gensio_time.h │ ├── gensio_types.h │ ├── gensio_unix.h │ ├── gensio_utils.h │ ├── gensio_version.h.in │ ├── gensio_win.h │ ├── gensioosh_dllvisibility.h │ ├── netif.h │ └── selector.h └── pthread_handler.h ├── lib ├── .gitignore ├── Makefile.am ├── README.rst ├── acc.c ├── acc_gensio.c ├── avahi_watcher.c ├── avahi_watcher.h ├── buffer.c ├── circbuf.c ├── crc.h ├── errtrig.c ├── errtrig.h ├── gensio.c ├── gensio_afskmdm.c ├── gensio_ax25.c ├── gensio_base.c ├── gensio_base_parms.h ├── gensio_certauth.c ├── gensio_cm108gpio.c ├── gensio_conacc.c ├── gensio_dgram.c ├── gensio_dummy.c ├── gensio_echo.c ├── gensio_file.c ├── gensio_keepopen.c ├── gensio_kiss.c ├── gensio_mdns.c ├── gensio_msgdelim.c ├── gensio_mux.c ├── gensio_net.c ├── gensio_net.h ├── gensio_openipmi_oshandler.c ├── gensio_perf.c ├── gensio_pty.c ├── gensio_ratelimit.c ├── gensio_relpkt.c ├── gensio_script.c ├── gensio_sctp.c ├── gensio_sound.c ├── gensio_sound_alsa.h ├── gensio_sound_file.h ├── gensio_sound_portaudio.h ├── gensio_sound_win.h ├── gensio_ssl.c ├── gensio_stdio.c ├── gensio_trace.c ├── gensio_xlt.c ├── heap.h ├── libgensio.pc.in ├── libgensiomdns.pc.in ├── libgensioosh.pc.in ├── ll_fd.c ├── ll_gensio.c ├── mdns.c ├── net_addr.c ├── net_addrinfo.c ├── net_ax25_addr.c ├── net_stdsock.c ├── os_osops.c ├── os_osops_env.c ├── os_unix.c ├── os_unix_selector.c ├── os_win.c ├── sergensio_ipmisol.c ├── sergensio_serialdev.c ├── sergensio_telnet.c ├── seriallock.c ├── seriallock.h ├── telnet.c ├── telnet.h ├── utils.c └── utils.h ├── m4 ├── ax_check_openssl.m4 ├── ax_compare_version.m4 ├── ax_config_feature.m4 ├── ax_cxx_compile_stdcxx.m4 ├── ax_have_epoll.m4 ├── ax_pkg_swig.m4 ├── ax_prog_python_version.m4 ├── ax_pthread.m4 └── ax_python_devel.m4 ├── macos-entitle ├── man ├── Makefile.am ├── gensio.5 ├── gensio_acc_accept_s.3 ├── gensio_acc_control.3 ├── gensio_acc_get_type.3 ├── gensio_acc_set_accept_callback_enable.3 ├── gensio_acc_set_callback.3 ├── gensio_acc_shutdown.3 ├── gensio_acc_startup.3 ├── gensio_accepter_event.3 ├── gensio_add_default.3 ├── gensio_alloc_channel.3 ├── gensio_atomics.3 ├── gensio_bswap.3 ├── gensio_close.3 ├── gensio_control.3 ├── gensio_err.3 ├── gensio_event.3 ├── gensio_get_type.3 ├── gensio_mdns.3 ├── gensio_open.3 ├── gensio_os_funcs.3 ├── gensio_refcount.3 ├── gensio_set_callback.3 ├── gensio_set_log_mask.3 ├── gensio_set_read_callback_enable.3 ├── gensio_set_sync.3 ├── gensio_write.3 ├── str_to_gensio.3 └── str_to_gensio_accepter.3 ├── reconf ├── swig ├── Makefile.am ├── gensio.i ├── include │ ├── Makefile.am │ └── gensio │ │ ├── Makefile.am │ │ ├── gensio_swig.h │ │ └── gensio_swig.i └── python │ ├── .gitignore │ ├── Makefile.am │ ├── gensio_langinfo.i │ ├── gensio_python.h │ ├── gensio_python_swig.c │ ├── gensiodoc.py │ ├── libgensio_python_swig.pc.in │ └── python_swig_internals.h ├── tcl ├── Makefile.am ├── c++ │ ├── Makefile.am │ ├── include │ │ ├── Makefile.am │ │ └── gensio │ │ │ ├── Makefile.am │ │ │ └── gensiotcl │ ├── swig │ │ ├── Makefile.am │ │ └── pygensio │ │ │ ├── Makefile.am │ │ │ └── pygensiotcl.i │ └── tests │ │ ├── Makefile.am │ │ └── basic_tcl_test.cc ├── gensio_tcl.c ├── gensio_tcl_funcs_alloc.3 ├── include │ ├── Makefile.am │ └── gensio │ │ ├── Makefile.am │ │ ├── gensio_tcl.h │ │ └── gensio_tcl_dllvisibility.h ├── libgensiotcl.pc.in └── swig │ ├── Makefile.am │ ├── gensiotcl.i │ └── python │ └── Makefile.am ├── tests ├── .gitignore ├── Makefile.am ├── README ├── echotest.c ├── gensios_enabled.py.in ├── ipmisimdaemon.py ├── make_keys ├── oomtest.c ├── oomtest0 ├── oomtest1 ├── oomtest10 ├── oomtest11 ├── oomtest12 ├── oomtest13 ├── oomtest14 ├── oomtest15 ├── oomtest2 ├── oomtest3 ├── oomtest4 ├── oomtest5 ├── oomtest6 ├── oomtest7 ├── oomtest8 ├── oomtest9 ├── reflector.py.in ├── runtest.in ├── termioschk.py ├── test_accept_certauth_tcp.py ├── test_accept_mux_tcp.py ├── test_accept_sctp.py ├── test_accept_ssl_tcp.py ├── test_accept_tcp.py ├── test_accept_udp.py ├── test_ax25_basics.py ├── test_ax25_small.py ├── test_certauth_ssl_tcp_accept_connect.py ├── test_certauth_tcp_accept_connect.py ├── test_conacc.py ├── test_dummy.py ├── test_echo_device.py ├── test_echo_gensio.py ├── test_file.py ├── test_fuzz_setup.py ├── test_ipmisol.py ├── test_ipmisol_large.py ├── test_ipmisol_small.py ├── test_mdns.py ├── test_modemstate.py ├── test_mux_limits.py ├── test_mux_oob.py ├── test_mux_tcp_large.py ├── test_mux_tcp_small.py ├── test_parmlog.py ├── test_perf.py ├── test_pty_basic.py ├── test_ratelimit.py ├── test_relpkt_basic.py ├── test_relpkt_large.py ├── test_relpkt_medium.py ├── test_relpkt_small.py ├── test_rs485.py ├── test_script.py ├── test_sctp_accept_connect.py ├── test_sctp_oob.py ├── test_sctp_small.py ├── test_sctp_streams.py ├── test_serial_break.py ├── test_serial_pipe_device.py ├── test_ssl_tcp_accept_connect.py ├── test_stdio_basic.py ├── test_stdio_basic_stderr.py ├── test_stdio_small.py ├── test_syncio.py ├── test_tcp_accept_connect.py ├── test_tcp_small.py ├── test_tcp_urgent.py ├── test_telnet.py ├── test_telnet_small.py ├── test_telnet_tcp_accept_connect.py ├── test_trace.py ├── test_udp_accept_connect.py ├── test_udp_nocon.py ├── test_unix_accept_connect.py └── utils.py └── tools ├── .gitignore ├── Makefile.am ├── file_utils.c ├── gagwpe.1 ├── gensio_pty_helper.c ├── gensioagwpe.c ├── gensiomdns.c ├── gensiosound.c ├── gensiot.1 ├── gensiotool.c ├── gmdns.1 ├── greflector.1 ├── gsound.1 ├── gtlssh-keygen.1 ├── gtlssh-keygen.c ├── gtlssh-shared.c ├── gtlssh.1 ├── gtlssh.c ├── gtlssh.h ├── gtlsshd-cert.pam ├── gtlsshd.8 ├── gtlsshd.c ├── gtlsshd.pam ├── gtlsshd.service.in ├── gtlssync ├── gtlssync.1 ├── ioinfo.c ├── ioinfo.h ├── localports.c ├── localports.h ├── pam_2factor_dummy.c ├── run_get_output.c ├── ser_ioinfo.c ├── ser_ioinfo.h ├── utils.c └── utils.h /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | 8 | [{*.c,*.h}] 9 | indent_style = space 10 | indent_size = 4 11 | -------------------------------------------------------------------------------- /.github/workflows/linuxbuild.yml: -------------------------------------------------------------------------------- 1 | name: LinuxBuild 2 | on: 3 | push: 4 | branches: 5 | - 'master' 6 | tags: 7 | - v* 8 | 9 | env: 10 | INSTALLPREFIX: "_local" 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | - name: Install dependencies 19 | run: | 20 | sudo apt install gcc g++ git swig python3-dev libssl-dev pkg-config \ 21 | libavahi-client-dev avahi-daemon libtool autoconf automake make \ 22 | libsctp-dev libpam-dev libwrap0-dev libglib2.0-dev tcl-dev \ 23 | libasound2-dev libudev-dev libopenipmi-dev 24 | - name: Configure 25 | run: | 26 | mkdir $INSTALLPREFIX 27 | ./reconf 28 | ./configure --prefix=$(pwd)/$INSTALLPREFIX/ --enable-internal-trace 29 | - name: Build 30 | run: | 31 | make 32 | make install 33 | make check 34 | -------------------------------------------------------------------------------- /.github/workflows/macosbuild.yml: -------------------------------------------------------------------------------- 1 | name: MacOSBuild 2 | on: 3 | push: 4 | branches: 5 | - 'master' 6 | tags: 7 | - v* 8 | 9 | env: 10 | INSTALLPREFIX: "_local" 11 | 12 | jobs: 13 | build: 14 | runs-on: macos-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | - name: Install autotools 19 | run: | 20 | brew update 21 | brew install libtool 22 | brew install autoconf 23 | brew install automake 24 | brew install swig 25 | brew install openssl 26 | brew install portaudio 27 | - name: Configure 28 | run: | 29 | mkdir $INSTALLPREFIX 30 | ./reconf 31 | ./configure --prefix=$(pwd)/$INSTALLPREFIX/ --enable-internal-trace 32 | - name: Build 33 | run: | 34 | make 35 | make install 36 | make check SKIP_TESTS="test_mdns test_mdns.py" 37 | -------------------------------------------------------------------------------- /.github/workflows/winbuild.yml: -------------------------------------------------------------------------------- 1 | name: WinBuild 2 | on: 3 | push: 4 | branches: 5 | - 'master' 6 | tags: 7 | - v* 8 | 9 | env: 10 | INSTALLPREFIX: "_local" 11 | 12 | jobs: 13 | mingw-build: 14 | strategy: 15 | matrix: 16 | include: 17 | - { sys: mingw64, env: x86_64 } 18 | - { sys: mingw32, env: i686 } 19 | 20 | runs-on: windows-latest 21 | defaults: 22 | run: 23 | shell: msys2 {0} 24 | steps: 25 | - uses: actions/checkout@v4 26 | - uses: msys2/setup-msys2@v2 27 | with: 28 | msystem: ${{matrix.sys}} 29 | update: true 30 | install: >- 31 | git 32 | mingw-w64-${{matrix.env}}-gcc 33 | mingw-w64-${{matrix.env}}-openssl 34 | mingw-w64-${{matrix.env}}-python 35 | mingw-w64-${{matrix.env}}-pcre 36 | libtool 37 | autotools 38 | swig 39 | - name: MSBuild 40 | run: | 41 | ./reconf 42 | mkdir $INSTALLPREFIX 43 | ./configure --prefix=$(pwd)/$INSTALLPREFIX/ --enable-internal-trace 44 | make 45 | make install 46 | # Unfortunately, on github, test_mdns.py hangs. I tried 47 | # it in an AWS windows server 2022 instance and it worked 48 | # fine, so I don't know what is going on. The pygensio 49 | # and go mdns test work fine. 50 | # test_ratelimit.py fails sometimes with a "data too slow". Probably 51 | # from running windows in a VM. 52 | # test_unix_accept_connect.py fails with "A socket operation 53 | # encountered a dead network." It works fine when I run them. 54 | # I assume it has to do with the tests runnign before the system 55 | # is completely up, or something like that. 56 | make check SKIP_TESTS="test_unix_accept_connect.py test_mdns.py test_ratelimit.py oomtest9 oomtest11" 57 | - name: Upload installed files 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: gensio-mingw-${{matrix.env}} 61 | path: ${{ env.INSTALLPREFIX }}/**/* 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # http://www.gnu.org/software/automake 2 | Makefile 3 | Makefile.in 4 | /ar-lib 5 | /test-driver 6 | .deps/ 7 | .dirstamp 8 | 9 | # http://www.gnu.org/software/autoconf 10 | autom4te.cache 11 | /autoscan.log 12 | /autoscan-*.log 13 | /aclocal.m4 14 | /compile 15 | /config.cache 16 | /config.guess 17 | /config.h 18 | /config.h.in 19 | /config.log 20 | /config.status 21 | /config.sub 22 | /configure 23 | /configure.scan 24 | /depcomp 25 | /install-sh 26 | /missing 27 | /stamp-h1 28 | 29 | # https://www.gnu.org/software/libtool/ 30 | libtool 31 | /ltmain.sh 32 | 33 | # http://www.gnu.org/software/m4/ 34 | m4/libtool.m4 35 | m4/ltoptions.m4 36 | m4/ltsugar.m4 37 | m4/ltversion.m4 38 | m4/lt~obsolete.m4 39 | 40 | # compiler generated stuff 41 | .deps/ 42 | .libs/ 43 | *.o 44 | *~ 45 | *.pyc 46 | *.cmd 47 | *.lo 48 | *.la 49 | *.a 50 | *.pc 51 | .tmp_versions 52 | Module.* 53 | modules.* 54 | /out 55 | runtest 56 | 57 | # editor 58 | /CMakeSettings.json 59 | *.ur-safe 60 | /.vs 61 | INSTALL 62 | *.patch 63 | *.orig 64 | *.rej 65 | 66 | # ctags 67 | tags 68 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Corey Minyard - Original (and still only) author. 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | So you want to help with gensio. Well, that's a fine thing, please 2 | do. Here are some things you can do: 3 | 4 | * Report bugs. See SECURITY.md for bugs that might be security 5 | sensitive. Use the normal github bug reporting from the github page 6 | (https://github.com/cminyard/gensio) for other bugs. 7 | 8 | * Write documentation. The world needs good documentation. I've 9 | tried, but I'm only one person. 10 | 11 | * Ask for new features. Obviously, bugs take precedence over new 12 | features, but cool ideas are accepted. Of course, source to 13 | implement those features is even better, so... 14 | 15 | * Write code for gensio. Write your own gensio, or add features to 16 | existing ones. Bug fixes. Examples. 17 | 18 | ======================= 19 | Code Contribution Rules 20 | ======================= 21 | 22 | All contributions must be signed of with a "Signed-off-by:" line 23 | following the Developer Certificate of Origin. See 24 | https://developercertificate.org. 25 | 26 | Please follow the coding style of the existing code. It's basically 27 | Linux kernel style with 4-character indent. 28 | 29 | Submit fixes, documentation updates, and new features through github 30 | pull requests. 31 | 32 | New gensios that go into the main library must be LGPL-2.1. 33 | 34 | If you add a new gensio or feature, you must add a test for it. 35 | 36 | If you make any changes, the changed code must pass all tests. See 37 | "Running Tests" in the README.rst file. 38 | -------------------------------------------------------------------------------- /ISSUES: -------------------------------------------------------------------------------- 1 | This is just a bunch of pending issues, mostly with Windows because 2 | Windows is a royal pain. 3 | 4 | For python, there is an issue if you get an exception and another 5 | python callback gets called. The exception is cleared by the new 6 | python call so it is lost. So even though exceptions are propagated 7 | back through the C/C++ code, they can still get lost. You can see 8 | this in test_mdns.py if there are multiple callbacks to mdns_cb. 9 | There is not an easy workaround, it is probably better to catch 10 | exceptions in all callbacks. 11 | 12 | On Windows, a new pty spews out a bunch of terminal control stuff and 13 | messes things up for testing and for things like rsync. Some way to 14 | disable this is needed. This breaks test_pty_basic.py. See 15 | https://learn.microsoft.com/en-us/answers/questions/1336932/a-new-device-with-createpseudoconsole()-sends-a-bu?comment=question 16 | 17 | You get strange behavior from Windows stdio if you have the console 18 | you are using in raw mode on the console and open another program 19 | using stdio. For instance: 20 | $ gensiot -i stdio(self,raw) stdio,cmd 21 | Microsoft Windows [Version 10.0.19045.3208] 22 | (c) Microsoft Corporation. All rights reserved. 23 | 24 | C:\msys64\home\cminyard\gensio> 25 | but you can't type anything. If you take out the "raw", it works, but 26 | then you get the undesirable side effects of a non-raw console. And 27 | it makes running programs from an application a program if the 28 | application is in raw mode. 29 | 30 | On Windows, python tests pull gensios from the installed directory, 31 | not from the local directory. This is because Windows always loads 32 | shared libraries first from the directory the original program ran in, 33 | and if you have gensio installed, it's going to be in the same 34 | directory as python. So if you have gensio installed this way, you 35 | have to install it again before you run tests. -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | SUBDIRS = lib $(SWIG_DIR) $(CPLUSPLUS_DIR) include $(GLIB_DIR) $(TCL_DIR) \ 5 | tests tools examples 6 | if INSTALL_DOC 7 | SUBDIRS += man 8 | endif 9 | 10 | DIST_SUBDIRS = lib swig c++ include glib tcl tests tools examples man 11 | 12 | EXTRA_DIST = README.rst reconf ISSUES TODO 13 | 14 | # Set distcheck up so python files get installed someplace that will 15 | # work, and enable internal trace so oomtest will work. 16 | AM_DISTCHECK_CONFIGURE_FLAGS=--enable-internal-trace \ 17 | --with-pythoninstall=$(abs_top_builddir)/$(distdir)/_inst/lib/python \ 18 | --with-pythoninstalllib=$(abs_top_builddir)/$(distdir)/_inst/lib/python 19 | 20 | clean_keys: 21 | rm -rf c++/swig/go/tests/ca 22 | rm -rf c++/swig/pygensio/tests/ca 23 | rm -rf tests/ca 24 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | No news is good news 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See README.rst 2 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | ------- | ------------------ | 7 | | 3.0.x | :white_check_mark: | 8 | | 2.8.x | :white_check_mark: | 9 | | 2.7.x | :x: | 10 | | 2.6.x | :x: | 11 | | 2.5.x | :x: | 12 | | 2.4.x | :x: | 13 | | < 2.4 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | To report a security issue, please email me directly at minyard@acm.org. 18 | Please do not create an issue or a pull request, at least until it's 19 | time to do so. 20 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | This is a random-ish list of things that might be done. 2 | 3 | Add a way to stack multiple things on a mux. Idea, use ",;" to 4 | specify the start of a number of things to go onto a mux, ",," to 5 | separate things on top of a mux, and ",." to mark the end of the last 6 | thing on the mux. NOTE - The big problem with this is that there is 7 | nothing to connect to on the top. 8 | 9 | Implement RFC 1408 on telnet. 10 | 11 | Add a "stream" option that tells the gensio to act as a stream, even if it's a 12 | packet oriented gensio. This will allow the gensio to add data to existing 13 | untranmsmitted packets and do other optimizations. 14 | 15 | Report an error if a mux or relpkt client tries to connect to a client. 16 | 17 | serialdev devices cannot be used in a forked process because the UUCP lock 18 | will not be correct. However, flock locking solves this problem. 19 | 20 | Port selector changes to openipmi. 21 | 22 | Add 300 baud support to afskmdm. 23 | 24 | Add 9600 baud 25 | 26 | Add an AGWPE client. 27 | 28 | Add AGWPE server heard list, UI and raw data handling. 29 | 30 | Add a sound mux to support multiple modems on the same radio. 31 | * mux would control the key. 32 | * mux can use the carrier indication from the radio if available. 33 | * mux can get indications from the modem if they are receiving data 34 | (if carrier indication isn't available). 35 | * Used write ready callbacks to allow writing to sound device. 36 | 37 | Add an aux data/ oob data for sent messages that is sent back to the 38 | user of afskmdm. This way, ax.25 can know when a packet was 39 | transmitted and properly set the timers. 40 | 41 | Add controls into afsk for controlling tx delay, tail, etc. and use 42 | them from kiss. 43 | -------------------------------------------------------------------------------- /c++/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = include lib $(SWIG_CPP_DIR) tests examples 3 | 4 | DIST_SUBDIRS = include lib swig tests examples 5 | -------------------------------------------------------------------------------- /c++/examples/.gitignore: -------------------------------------------------------------------------------- 1 | # binaries 2 | mdns 3 | telnet_client 4 | telnet_server 5 | -------------------------------------------------------------------------------- /c++/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir)/c++/include 3 | 4 | noinst_PROGRAMS = telnet_server telnet_client mdns 5 | 6 | telnet_server_SOURCES = telnet_server.cc 7 | 8 | telnet_server_LDADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 9 | $(top_builddir)/c++/lib/libgensiocpp.la \ 10 | $(top_builddir)/lib/libgensioosh.la \ 11 | $(top_builddir)/lib/libgensio.la 12 | 13 | telnet_client_SOURCES = telnet_client.cc 14 | 15 | telnet_client_LDADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 16 | $(top_builddir)/lib/libgensioosh.la \ 17 | $(top_builddir)/c++/lib/libgensiocpp.la \ 18 | $(top_builddir)/lib/libgensio.la 19 | 20 | mdns_SOURCES = mdns.cc 21 | 22 | mdns_LDADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 23 | $(top_builddir)/c++/lib/libgensiomdnscpp.la \ 24 | $(top_builddir)/lib/libgensio.la \ 25 | $(top_builddir)/lib/libgensioosh.la 26 | -------------------------------------------------------------------------------- /c++/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | -------------------------------------------------------------------------------- /c++/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = gensioosh gensio gensiomdns \ 3 | gensioosh_dllvisibility gensio_dllvisibility 4 | -------------------------------------------------------------------------------- /c++/include/gensio/gensio_dllvisibility: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIOCPP_DLLVISIBILITY 9 | #define GENSIOCPP_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIOCPP_DLL_PUBLIC 13 | #define GENSIOCPP_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIOCPP_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIOCPP_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIOCPP_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIOCPP_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIOCPP_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIOCPP_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIOCPP_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIOCPP_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIOCPP_DLL_PUBLIC 35 | #define GENSIOCPP_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIOCPP_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /c++/include/gensio/gensioosh_dllvisibility: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIOOSHCPP_DLLVISIBILITY 9 | #define GENSIOOSHCPP_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIOOSHCPP_DLL_PUBLIC 13 | #define GENSIOOSHCPP_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIOOSHCPP_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIOOSHCPP_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIOOSHCPP_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIOOSHCPP_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIOOSHCPP_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIOOSHCPP_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIOOSHCPP_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIOOSHCPP_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIOOSHCPP_DLL_PUBLIC 35 | #define GENSIOOSHCPP_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIOOSHCPP_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /c++/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | lib_LTLIBRARIES = libgensiooshcpp.la libgensiocpp.la 3 | 4 | pkgconfigexecdir = $(libdir)/pkgconfig 5 | 6 | libgensiooshcpp_la_SOURCES = gensioosh.cc 7 | libgensiooshcpp_la_CPPFLAGS = -DBUILDING_GENSIOOSHCPP_DLL 8 | libgensiooshcpp_la_LIBADD = $(top_builddir)/lib/libgensioosh.la 9 | libgensiooshcpp_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 10 | -version-info $(GENSIO_LIB_VERSION) -fvisibility=hidden 11 | pkgconfigexec_DATA = libgensiooshcpp.pc 12 | 13 | libgensiocpp_la_SOURCES = gensio.cc 14 | libgensiocpp_la_CPPFLAGS = -DBUILDING_GENSIOCPP_DLL 15 | libgensiocpp_la_LIBADD = libgensiooshcpp.la $(top_builddir)/lib/libgensio.la \ 16 | $(top_builddir)/lib/libgensioosh.la 17 | libgensiocpp_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 18 | -version-info $(GENSIO_LIB_VERSION) -fvisibility=hidden 19 | 20 | # This variable must have 'exec' in its name, in order to be installed 21 | # by 'install-exec' target (instead of default 'install-data') 22 | pkgconfigexec_DATA += libgensiocpp.pc 23 | 24 | lib_LTLIBRARIES += libgensiomdnscpp.la 25 | libgensiomdnscpp_la_SOURCES = gensiomdns.cc 26 | libgensiomdnscpp_la_CPPFLAGS = -DBUILDING_GENSIOMDNSCPP_DLL 27 | libgensiomdnscpp_la_LIBADD = libgensiooshcpp.la \ 28 | $(top_builddir)/lib/libgensioosh.la \ 29 | $(top_builddir)/lib/libgensiomdns.la 30 | libgensiomdnscpp_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 31 | -version-info $(GENSIO_LIB_VERSION) -fvisibility=hidden 32 | 33 | pkgconfigexec_DATA += libgensiomdnscpp.pc 34 | 35 | EXTRA_DIST = libgensiooshcpp.pc.in libgensiocpp.pc.in libgensiomdnscpp.pc.in 36 | -------------------------------------------------------------------------------- /c++/lib/libgensiocpp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensiocpp 7 | Description: A C++ library wrapper around gensio 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensiocpp -lgensio -lgensioosh 10 | -------------------------------------------------------------------------------- /c++/lib/libgensiomdnscpp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensiomdnscpp 7 | Description: A C++ library wrapper around gensio MDNS 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensiomdnscpp -lgensiomdns -lgensiooshcpp -lgensioosh 10 | -------------------------------------------------------------------------------- /c++/lib/libgensiooshcpp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensiooshcpp 7 | Description: A C++ library wrapper around gensio OS handler 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensiooshcpp -lgensio -lgensioosh 10 | -------------------------------------------------------------------------------- /c++/swig/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = . include $(PYGENSIO_DIR) $(GO_DIR) 2 | 3 | DIST_SUBDIRS = include pygensio go 4 | -------------------------------------------------------------------------------- /c++/swig/go/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio examples tests 3 | 4 | # A helper to transfer info to where it needs to go and rename everything 5 | # properly. 6 | 7 | GOLANG_INSTALLDIR = /personal/git/go/gensio 8 | 9 | golang-install: 10 | cp $(srcdir)/README.rst $(GOLANG_INSTALLDIR) 11 | cp $(srcdir)/gensio/gensio.srcswigcxx \ 12 | $(GOLANG_INSTALLDIR)/gensio.swigcxx 13 | cp $(srcdir)/gensio/gensioapi.srcgo $(GOLANG_INSTALLDIR)/gensioapi.go 14 | cp $(srcdir)/gensio/go.srcmod $(GOLANG_INSTALLDIR)/go.mod 15 | cp $(srcdir)/../include/gensio_base.i $(GOLANG_INSTALLDIR) 16 | -------------------------------------------------------------------------------- /c++/swig/go/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_SCRIPTS = example telnet_server telnet_client 3 | 4 | GOMOD = github.com/cminyard/go/gensio 5 | 6 | example.go: $(srcdir)/srcexample.go 7 | cp $(srcdir)/srcexample.go example.go 8 | 9 | telnet_server.go: $(srcdir)/srctelnet_server.go 10 | cp $(srcdir)/srctelnet_server.go telnet_server.go 11 | 12 | telnet_client.go: $(srcdir)/srctelnet_client.go 13 | cp $(srcdir)/srctelnet_client.go telnet_client.go 14 | 15 | go.mod: example.go 16 | rm -f go.mod 17 | go mod init examples 18 | go mod edit -replace $(GOMOD)=../gensio 19 | go mod tidy 20 | 21 | MORE_LIBS= 22 | if BUILTIN_MDNS 23 | MORE_LIBS += $(MDNS_LIBS) 24 | endif 25 | if BUILTIN_SOUND 26 | MORE_LIBS += $(SOUND_LIBS) 27 | endif 28 | if BUILTIN_SCTP 29 | MORE_LIBS += $(LIBSCTP_LIBS) 30 | endif 31 | if BUILTIN_SSL 32 | MORE_LIBS += $(OPENSSL_LIBS) 33 | endif 34 | if BUILTIN_IPMISOL 35 | MORE_LIBS += $(OPENIPMI_LIBS) 36 | endif 37 | export CXX 38 | export CC 39 | export CGO_CXXFLAGS = $(CXXFLAGS) $(AM_CXXFLAGS) \ 40 | -I$(top_srcdir)/c++/swig/include 41 | export CGO_CPPFLAGS = $(CPPFLAGS) -I$(top_srcdir)/c++/swig/include 42 | export CGO_LDFLAGS = -L$(top_builddir)/c++/lib/.libs \ 43 | -lgensiooshcpp -lgensiocpp -lgensiomdnscpp \ 44 | -L$(top_builddir)/lib/.libs -lgensioosh -lgensio -lgensiomdns \ 45 | $(MORE_LIBS) 46 | 47 | example: ../gensio/gensio.go \ 48 | ../gensio/gensio_wrap.cxx ../gensio/gensio_wrap.h \ 49 | example.go ../gensio/gensioapi.go go.mod 50 | go build example.go 51 | 52 | telnet_server: ../gensio/gensio.go \ 53 | ../gensio/gensio_wrap.cxx ../gensio/gensio_wrap.h \ 54 | telnet_server.go ../gensio/gensioapi.go go.mod 55 | go build telnet_server.go 56 | 57 | telnet_client: ../gensio/gensio.go \ 58 | ../gensio/gensio_wrap.cxx ../gensio/gensio_wrap.h \ 59 | telnet_client.go ../gensio/gensioapi.go go.mod 60 | go build telnet_client.go 61 | 62 | EXTRA_DIST = srcexample.go srctelnet_server.go srctelnet_client.go 63 | 64 | clean-local: 65 | rm -rf go.mod example example.go telnet_server telnet_server.go \ 66 | telnet_client telnet_client.go 67 | -------------------------------------------------------------------------------- /c++/swig/go/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | GOMOD = github.com/cminyard/go/gensio 3 | 4 | noinst_SCRIPTS = go.mod 5 | 6 | gensio_wrap.cxx gensio_wrap.h gensio.go: \ 7 | gensio.srcswigcxx $(top_srcdir)/c++/include/gensio \ 8 | $(top_srcdir)/c++/swig/include/gensio_base.i \ 9 | $(top_srcdir)/include/gensio/gensio_err.h \ 10 | $(top_srcdir)/include/gensio/gensio_control.h \ 11 | $(top_srcdir)/include/gensio/gensio_types.h 12 | $(SWIG) $(DEFS) -Wall -go -intgosize 64 $(GO_SWIG_FLAGS) \ 13 | -o gensio_wrap.cxx -c++ \ 14 | -I$(top_srcdir)/c++/swig/go -I$(top_srcdir)/c++/include \ 15 | -I$(top_srcdir)/include \ 16 | -I$(top_builddir)/include -I$(top_srcdir)/c++/swig/include \ 17 | $(srcdir)/gensio.srcswigcxx 18 | 19 | 20 | $(builddir)/go.mod: $(srcdir)/go.srcmod gensioapi.go gensio.go 21 | rm -f go.mod 22 | cp $(srcdir)/go.srcmod go.mod 23 | 24 | $(builddir)/gensioapi.go: $(srcdir)/gensioapi.srcgo 25 | cp $(srcdir)/gensioapi.srcgo gensioapi.go 26 | 27 | EXTRA_DIST = gensioapi.srcgo gensio.srcswigcxx go.srcmod 28 | 29 | clean-local: 30 | rm -rf gensioapi.go go.mod 31 | rm -rf gensio_wrap.cxx gensio_wrap.h gensio.go 32 | -------------------------------------------------------------------------------- /c++/swig/go/gensio/go.srcmod: -------------------------------------------------------------------------------- 1 | module github.com/cminyard/go/gensio 2 | 3 | go 1.17 4 | -------------------------------------------------------------------------------- /c++/swig/go/tests/runtest.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SRCDIR="@top_srcdir@" 4 | TEST_SRCDIR="${SRCDIR}/c++/swig/go/tests" 5 | BUILDDIR="@top_builddir@" 6 | TEST_BUILDDIR="${BUILDDIR}/c++/swig/go/tests" 7 | 8 | PRINT_MODE=false 9 | while echo $1 | grep '^-' >/dev/null; do 10 | if [ "X$1" = "X--print" ]; then 11 | PRINT_MODE=true 12 | elif [ "X$1" = "X--" ]; then 13 | break 14 | else 15 | echo "Unknown option: $1" 1>&2 16 | exit 1 17 | fi 18 | shift 19 | done 20 | 21 | if [ -z "$1" ]; then 22 | echo "No test given" 1>&2 23 | exit 1 24 | fi 25 | 26 | # See if we are skipping this test 27 | T1=`basename $1` 28 | if echo "$SKIP_TESTS" | grep -q "$T1"; then 29 | exit 77 30 | fi 31 | 32 | TEST=$1 33 | shift 34 | 35 | if [ -e "${TEST_BUILDDIR}/${TEST}" ]; then 36 | TEST="${TEST_BUILDDIR}/${TEST}" 37 | elif [ -e "${TEST_SRCDIR}/${TEST}" ]; then 38 | TEST="${TEST_SRCDIR}/${TEST}" 39 | else 40 | echo "Test ${TEST} not found" 1>&2 41 | exit 1 42 | fi 43 | 44 | if [ ! -x ${TEST} ]; then 45 | echo "Test ${TEST} is not executable" 1>&2 46 | exit 1 47 | fi 48 | 49 | # We need to put the DLL in PATH for MSYS on Windows 50 | if [ ! -z "$MSYSTEM" ]; then 51 | export PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/c++/lib/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/glib/c++/swig/pygensio/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/tcl/c++/swig/pygensio/.libs:$PATH 52 | else 53 | export LD_LIBRARY_PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/c++/swig/python/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/glib/c++/pygensio/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/tcl/c++/pygensio/.libs:${BUILDDIR}/c++/lib/.libs 54 | fi 55 | if test `uname` = Darwin; then 56 | TEST="DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} ${TEST}" 57 | fi 58 | 59 | if ${PRINT_MODE}; then 60 | echo export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" 61 | echo ${TEST} $* 62 | else 63 | # Run the test with each available OS handler 64 | eval "${TEST} $*" 65 | rv=$? 66 | if test $rv != 0; then 67 | # A test failed, exit 68 | exit $rv 69 | fi 70 | fi 71 | -------------------------------------------------------------------------------- /c++/swig/go/tests/srctest_netifs.go: -------------------------------------------------------------------------------- 1 | // 2 | // gensio - A library for abstracting stream I/O 3 | // Copyright (C) 2021 Corey Minyard 4 | // 5 | // SPDX-License-Identifier: LGPL-2.1-only 6 | 7 | package main 8 | 9 | import ( 10 | "fmt" 11 | "github.com/cminyard/go/gensio" 12 | "testbase" 13 | ) 14 | 15 | func main() { 16 | netifs := gensio.NewNetIfs(testbase.O) 17 | numifs := netifs.GetNumIfs() 18 | var i uint 19 | for i = 0; i < numifs; i++ { 20 | name := netifs.GetName(i) 21 | up := "" 22 | if netifs.IsUp(i) { 23 | up = " up" 24 | } 25 | loopback := "" 26 | if netifs.IsLoopback(i) { 27 | loopback = " loopback" 28 | } 29 | multicast := "" 30 | if netifs.IsMulticast(i) { 31 | multicast = " multicast" 32 | } 33 | ifidx := netifs.GetIfIndex(i) 34 | numaddrs := netifs.GetNumAddrs(i) 35 | fmt.Printf("%s(%d):%s%s%s:\n", name, ifidx, 36 | up, loopback, multicast) 37 | var j uint 38 | for j = 0; j < numaddrs; j++ { 39 | netbits := netifs.GetAddrNetbits(i, j) 40 | family := netifs.GetAddrFamily(i, j) 41 | addrstr := netifs.GetAddrStr(i, j) 42 | fmt.Printf(" %s/%d %d\n", addrstr, netbits, family) 43 | } 44 | } 45 | 46 | testbase.TestShutdown() 47 | } 48 | -------------------------------------------------------------------------------- /c++/swig/go/tests/testbase/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_SCRIPTS = go.mod 3 | 4 | GOMOD = github.com/cminyard/go/gensio 5 | 6 | go.mod: testbase.go 7 | rm -f go.mod 8 | go mod init testbase 9 | go mod edit -replace $(GOMOD)=$(abs_builddir)/../../gensio 10 | go mod tidy 11 | 12 | $(builddir)/testbase.go: $(srcdir)/testbase.srcgo 13 | cp $(srcdir)/testbase.srcgo testbase.go 14 | 15 | EXTRA_DIST = testbase.srcgo 16 | 17 | clean-local: 18 | rm -f testbase.go go.mod 19 | -------------------------------------------------------------------------------- /c++/swig/include/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = gensio_base.i 2 | -------------------------------------------------------------------------------- /c++/swig/pygensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = include tests 3 | 4 | AM_CPPFLAGS = $(PYTHON_CPPFLAGS) -I$(top_srcdir)/c++/swig/pygensio/include 5 | 6 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 7 | pythonlib_LTLIBRARIES = _pygensio.la 8 | 9 | pygensio_wrap.cc pygensio.py: pygensio.i $(top_srcdir)/c++/include/gensio \ 10 | $(top_srcdir)/c++/swig/include/gensio_base.i \ 11 | $(top_srcdir)/include/gensio/gensio_err.h \ 12 | $(top_srcdir)/include/gensio/gensio_control.h \ 13 | $(top_srcdir)/include/gensio/gensio_types.h 14 | $(SWIG) $(DEFS) -Wall -python $(PYTHON_SWIG_FLAGS) \ 15 | -o pygensio_wrap.cc -c++ \ 16 | -I$(top_srcdir)/c++/swig/pygensio -I$(top_srcdir)/c++/include \ 17 | -I$(top_srcdir)/include \ 18 | -I$(top_builddir)/include -I$(top_srcdir)/c++/swig/include \ 19 | $(top_srcdir)/c++/swig/pygensio/pygensio.i 20 | 21 | EXTRA_DIST = pygensio.i 22 | 23 | nodist__pygensio_la_SOURCES = pygensio_wrap.cc 24 | _pygensio_la_LIBADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 25 | $(top_builddir)/c++/lib/libgensiocpp.la \ 26 | $(top_builddir)/c++/lib/libgensiomdnscpp.la \ 27 | $(top_builddir)/lib/libgensioosh.la \ 28 | $(top_builddir)/lib/libgensio.la \ 29 | $(top_builddir)/lib/libgensiomdns.la \ 30 | $(PYTHON_UNDEF_LIBS) 31 | _pygensio_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 32 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 33 | 34 | clean-local: 35 | rm -rf __pycache__ pygensio_wrap.cc pygensio_wrap.h pygensio.py 36 | 37 | install-exec-local: _pygensio.la pygensio.py 38 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 39 | $(INSTALL_DATA) pygensio.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 40 | 41 | uninstall-local: 42 | $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_pygensio.$(PYTHON_EXT_EXT)" 43 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/pygensio.py" 44 | -------------------------------------------------------------------------------- /c++/swig/pygensio/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | -------------------------------------------------------------------------------- /c++/swig/pygensio/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = pygensio.h 3 | -------------------------------------------------------------------------------- /c++/swig/pygensio/include/gensio/pygensio.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PYGENSIO_H__ 3 | #define __PYGENSIO_H__ 4 | 5 | // Increment/decrement refcount for object contained in directors. 6 | // If the python code passed a reference in then loses all it's 7 | // reference to it, we want to make sure it still hangs around. 8 | void pydirobj_incref(Swig::Director *dir) 9 | { 10 | PyObject *po = dir->swig_get_self(); 11 | 12 | /* Make sure it's not deleted if python loses all references. */ 13 | Py_INCREF(po); 14 | } 15 | void pydirobj_decref(Swig::Director *dir) 16 | { 17 | PyObject *po = dir->swig_get_self(); 18 | 19 | /* Make sure it's not deleted if python loses all references. */ 20 | Py_DECREF(po); 21 | } 22 | 23 | class Internal_Log_Handler : public gensios::Os_Funcs_Log_Handler { 24 | public: 25 | Internal_Log_Handler(gensios::Os_Funcs_Log_Handler *pyhandler) 26 | : handler(pyhandler) { 27 | incref(); 28 | } 29 | 30 | virtual ~Internal_Log_Handler() { 31 | decref(); 32 | } 33 | 34 | void set_handler(gensios::Os_Funcs_Log_Handler *pyhandler) { 35 | decref(); 36 | handler = pyhandler; 37 | incref(); 38 | } 39 | 40 | void log(enum gensios::gensio_log_levels level, const std::string log) override { 41 | // Hack. If there is a python error, the call to the log 42 | // function will always fail because this error is not 43 | // cleared and SWIG will think the log call failed. This 44 | // will print some useful information and clear the error 45 | // log. 46 | PyErr_Print(); 47 | 48 | if (handler) 49 | handler->log(level, log); 50 | } 51 | 52 | private: 53 | void decref() { 54 | if (handler) { 55 | Swig::Director *pydir_obj = dynamic_cast(handler); 56 | if (pydir_obj) 57 | pydirobj_decref(pydir_obj); 58 | } 59 | } 60 | 61 | void incref() { 62 | if (handler) { 63 | Swig::Director *pydir_obj = dynamic_cast(handler); 64 | if (pydir_obj) 65 | pydirobj_incref(pydir_obj); 66 | } 67 | } 68 | 69 | gensios::Os_Funcs_Log_Handler *handler; 70 | }; 71 | 72 | #endif /* __PYGENSIO_H__ */ 73 | -------------------------------------------------------------------------------- /c++/swig/pygensio/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | export VERBOSE = 1 3 | 4 | AM_TESTS_ENVIRONMENT = SKIP_TESTS="$(SKIP_TESTS)" 5 | 6 | LOG_COMPILER = $(SHELL) $(builddir)/runtest 7 | 8 | TESTS = test_basic.py test_ax25.py test_crypto.py test_mdns.py \ 9 | test_serial.py 10 | 11 | EXTRA_DIST = testbase.py $(TESTS) 12 | 13 | test_crypto.py: ca/CA.key 14 | 15 | ca/CA.key: 16 | $(top_srcdir)/tests/make_keys 17 | 18 | clean-local: 19 | rm -rf ca __pycache__ 20 | -------------------------------------------------------------------------------- /c++/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir)/c++/include 3 | 4 | TESTS = basic_cpp_test serial_test 5 | 6 | basic_cpp_test_SOURCES = basic_cpp_test.cc 7 | 8 | basic_cpp_test_LDADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 9 | $(top_builddir)/c++/lib/libgensiocpp.la \ 10 | $(top_builddir)/lib/libgensio.la \ 11 | $(top_builddir)/lib/libgensioosh.la \ 12 | $(OPENSSL_LIBS) 13 | 14 | serial_test_SOURCES = serial_test.cc 15 | 16 | serial_test_LDADD = $(top_builddir)/c++/lib/libgensiooshcpp.la \ 17 | $(top_builddir)/c++/lib/libgensiocpp.la \ 18 | $(top_builddir)/lib/libgensio.la \ 19 | $(top_builddir)/lib/libgensioosh.la \ 20 | $(OPENSSL_LIBS) 21 | 22 | check_PROGRAMS = basic_cpp_test serial_test 23 | -------------------------------------------------------------------------------- /checks/README.rst: -------------------------------------------------------------------------------- 1 | ====== 2 | checks 3 | ====== 4 | 5 | This directory contains little programs for checking things. They are 6 | just here for posterity, really, though they may be useful for 7 | checking things on new platforms. 8 | -------------------------------------------------------------------------------- /docs/AGWPE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cminyard/gensio/c6f7c3eef814ba7a4e314c49e77a3c382e1359ee/docs/AGWPE.pdf -------------------------------------------------------------------------------- /docs/AX25.2.2-Jul 98-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cminyard/gensio/c6f7c3eef814ba7a4e314c49e77a3c382e1359ee/docs/AX25.2.2-Jul 98-2.pdf -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | # binaries 2 | basic_client 3 | basic_server 4 | basic_server_sync 5 | basic_server_sync_fork 6 | poll_and_gensio 7 | use_iods 8 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_PROGRAMS = basic_server basic_server_sync basic_client \ 3 | basic_server_sync_fork use_iods poll_and_gensio 4 | 5 | EXTRA_DIST = basic_server.py basic_client.py 6 | 7 | basic_server_SOURCES = basic_server.c 8 | 9 | basic_server_LDADD = $(top_builddir)/lib/libgensio.la \ 10 | $(top_builddir)/lib/libgensioosh.la 11 | 12 | basic_client_SOURCES = basic_client.c 13 | 14 | basic_client_LDADD = $(top_builddir)/lib/libgensio.la \ 15 | $(top_builddir)/lib/libgensioosh.la 16 | 17 | basic_server_sync_SOURCES = basic_server_sync.c 18 | 19 | basic_server_sync_LDADD = $(top_builddir)/lib/libgensio.la \ 20 | $(top_builddir)/lib/libgensioosh.la 21 | 22 | basic_server_sync_fork_SOURCES = basic_server_sync_fork.c 23 | 24 | basic_server_sync_fork_LDADD = $(top_builddir)/lib/libgensio.la \ 25 | $(top_builddir)/lib/libgensioosh.la 26 | 27 | use_iods_SOURCES = use_iods.c 28 | 29 | use_iods_LDADD = $(top_builddir)/lib/libgensio.la \ 30 | $(top_builddir)/lib/libgensioosh.la 31 | 32 | poll_and_gensio_SOURCES = poll_and_gensio.c 33 | 34 | poll_and_gensio_LDADD = $(top_builddir)/lib/libgensio.la \ 35 | $(top_builddir)/lib/libgensioosh.la 36 | 37 | -------------------------------------------------------------------------------- /glib/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -DBUILDING_GENSIOGLIB_DLL 3 | AM_CFLAGS = -I$(top_srcdir)/glib/include @EXTRA_CFLAGS@ 4 | 5 | lib_LTLIBRARIES = libgensioglib.la 6 | 7 | libgensioglib_la_SOURCES = gensio_glib.c 8 | libgensioglib_la_CFLAGS = $(GLIB_CFLAGS) $(AM_CFLAGS) 9 | libgensioglib_la_LIBADD = $(top_builddir)/lib/libgensio.la \ 10 | $(top_builddir)/lib/libgensioosh.la \ 11 | @OPENSSL_LIBS@ @GLIB_LIBS@ 12 | libgensioglib_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 13 | -version-info $(GENSIO_LIB_VERSION) -fvisibility=hidden 14 | 15 | SUBDIRS = . $(SWIG_DIR) include $(CPLUSPLUS_DIR) 16 | DIST_SUBDIRS = swig include c++ 17 | 18 | # This variable must have 'exec' in its name, in order to be installed 19 | # by 'install-exec' target (instead of default 'install-data') 20 | pkgconfigexecdir = $(libdir)/pkgconfig 21 | pkgconfigexec_DATA = libgensioglib.pc 22 | 23 | if INSTALL_DOC 24 | man3_MANS = gensio_glib_funcs_alloc.3 25 | endif 26 | 27 | EXTRA_DIST = libgensioglib.pc.in $(man3_MANS) 28 | -------------------------------------------------------------------------------- /glib/c++/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = include tests $(SWIG_DIR) 3 | 4 | DIST_SUBDIRS = include tests swig 5 | -------------------------------------------------------------------------------- /glib/c++/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | 4 | DIST_SUBDIRS = gensio 5 | -------------------------------------------------------------------------------- /glib/c++/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = gensioglib 2 | -------------------------------------------------------------------------------- /glib/c++/include/gensio/gensioglib: -------------------------------------------------------------------------------- 1 | // 2 | // gensio - A library for abstracting stream I/O 3 | // Copyright (C) 2022 Corey Minyard 4 | // 5 | // SPDX-License-Identifier: LGPL-2.1-only 6 | 7 | // This is a C++ wrapper for the gensio library. 8 | 9 | #ifndef GENSIOGLIB_CPP_INCLUDE 10 | #define GENSIOGLIB_CPP_INCLUDE 11 | 12 | #include 13 | 14 | namespace gensios { 15 | #include 16 | 17 | class Glib_Os_Funcs: public Os_Funcs { 18 | public: 19 | Glib_Os_Funcs(Os_Funcs_Log_Handler *logger = NULL) : Os_Funcs(false) 20 | { 21 | struct gensio_os_funcs *o; 22 | 23 | int err = gensio_glib_funcs_alloc(&o); 24 | if (err) 25 | throw gensio_error(err); 26 | init(o, logger); 27 | } 28 | }; 29 | } 30 | 31 | #endif /* GENSIOGLIB_CPP_INCLUDE */ 32 | -------------------------------------------------------------------------------- /glib/c++/swig/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = . $(PYGENSIO_DIR) 2 | DIST_SUBDIRS = pygensio 3 | -------------------------------------------------------------------------------- /glib/c++/swig/pygensio/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | pygensioglib.py 3 | pygensioglib_wrap.cc 4 | pygensioglib_wrap.h 5 | -------------------------------------------------------------------------------- /glib/c++/swig/pygensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = $(PYTHON_CPPFLAGS) \ 3 | -I$(top_srcdir)/glib/c++/include -I$(top_srcdir)/glib/include \ 4 | -I$(top_srcdir)/c++/swig/pygensio/include 5 | 6 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 7 | pythonlib_LTLIBRARIES = _pygensioglib.la 8 | 9 | pygensioglib_wrap.cc pygensioglib.py: \ 10 | $(top_srcdir)/c++/swig/include/gensio_base.i \ 11 | $(top_srcdir)/c++/swig/pygensio/pygensio.i \ 12 | $(top_srcdir)/glib/c++/swig/pygensio/pygensioglib.i \ 13 | $(top_srcdir)/c++/include/gensio 14 | $(SWIG) $(DEFS) -Wall -python $(PYTHON_SWIG_FLAGS) \ 15 | -o pygensioglib_wrap.cc -c++ \ 16 | -I$(top_srcdir)/glib/c++/include \ 17 | -I$(top_srcdir)/c++/swig/include \ 18 | -I$(top_srcdir)/c++/swig/pygensio -I$(top_srcdir)/c++/include \ 19 | -I$(top_srcdir)/include -I$(top_builddir)/include \ 20 | $(top_srcdir)/glib/c++/swig/pygensio/pygensioglib.i 21 | 22 | EXTRA_DIST = pygensioglib.i 23 | 24 | nodist__pygensioglib_la_SOURCES = pygensioglib_wrap.cc 25 | _pygensioglib_la_LIBADD = $(top_builddir)/c++/lib/libgensiocpp.la \ 26 | $(top_builddir)/glib/libgensioglib.la \ 27 | $(top_builddir)/lib/libgensio.la \ 28 | $(top_builddir)/lib/libgensioosh.la \ 29 | $(OPENSSL_LIBS) $(PYTHON_UNDEF_LIBS) 30 | _pygensioglib_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 31 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 32 | 33 | clean-local: 34 | rm -rf __pycache__ pygensioglib_wrap.cc pygensioglib_wrap.h \ 35 | pygensioglib.py 36 | 37 | install-exec-local: _pygensioglib.la pygensioglib.py 38 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 39 | $(INSTALL_DATA) pygensioglib.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 40 | 41 | uninstall-local: 42 | $(LIBTOOL) --mode=uninstall \ 43 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_pygensioglib.$(PYTHON_EXT_EXT)" 44 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/pygensioglib.py" 45 | -------------------------------------------------------------------------------- /glib/c++/swig/pygensio/README.rst: -------------------------------------------------------------------------------- 1 | ======================================== 2 | pygensio - A python interface for gensio 3 | ======================================== 4 | 5 | This part of the package provides a Python interface for gensio using 6 | the swig tool. It uses the C++ interface to generate a binding, 7 | though it does a lot of work on that binding to make it work properly 8 | with Python. 9 | 10 | This is a replacement for the original python interface based upon C. 11 | The original interafce is a little easier to use, but it's not nearly 12 | as maintainable. That creates it's own interface for the callbacks, 13 | which is messy and non-portable. This binding uses swig directors to 14 | handle the callbacks, and it's less than half the size of the previous 15 | one and much cleaner. 16 | -------------------------------------------------------------------------------- /glib/c++/swig/pygensio/pygensioglib.i: -------------------------------------------------------------------------------- 1 | %module pygensioglib 2 | 3 | %{ 4 | #include 5 | #include 6 | using namespace gensios; 7 | %} 8 | 9 | %import 10 | 11 | %catches(gensios::gensio_error) gensios::Glib_Os_Funcs::Glib_Os_Funcs; 12 | 13 | %extend gensios::Glib_Os_Funcs { 14 | Glib_Os_Funcs(gensios::Os_Funcs_Log_Handler *logger = NULL) 15 | { 16 | gensios::Os_Funcs_Log_Handler *int_handler = NULL; 17 | if (logger) 18 | int_handler = new Internal_Log_Handler(logger); 19 | return new gensios::Glib_Os_Funcs(int_handler); 20 | } 21 | 22 | ~Glib_Os_Funcs() 23 | { 24 | delete self; 25 | } 26 | } 27 | 28 | %ignore gensios::Glib_Os_Funcs::Glib_Os_Funcs; 29 | %ignore gensios::Glib_Os_Funcs::~Glib_Os_Funcs; 30 | 31 | %include 32 | -------------------------------------------------------------------------------- /glib/c++/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir)/c++/include -I$(top_srcdir)/glib/c++/include \ 3 | -I$(top_srcdir)/glib/include 4 | 5 | TESTS = basic_glib_test 6 | 7 | basic_glib_test_SOURCES = basic_glib_test.cc 8 | 9 | basic_glib_test_LDADD = $(top_builddir)/lib/libgensio.la \ 10 | $(top_builddir)/c++/lib/libgensiocpp.la \ 11 | $(top_builddir)/c++/lib/libgensiooshcpp.la \ 12 | $(top_builddir)/lib/libgensio.la \ 13 | $(top_builddir)/lib/libgensioosh.la \ 14 | $(top_builddir)/glib/libgensioglib.la \ 15 | $(OPENSSL_LIBS) 16 | 17 | check_PROGRAMS = basic_glib_test 18 | -------------------------------------------------------------------------------- /glib/gensio_glib_funcs_alloc.3: -------------------------------------------------------------------------------- 1 | .TH gensio_glib_funcs_alloc 3 "03 Feb 2021" 2 | .SH NAME 3 | gensio_glib_funcs_alloc \- Abstraction for some operating system functions 4 | done with glib 5 | .SH SYNOPSIS 6 | .B #include 7 | .PP 8 | .B int gensio_glib_funcs_alloc(struct gensio_os_funcs **o) 9 | .SH "DESCRIPTION" 10 | This structure provides an abstraction for the gensio library that 11 | lets it work on top of glib. See the gensio_os_funcs.3 man page for 12 | details on what this does. This can be used if you have a project 13 | based on glib that you want to integrate gensio into. 14 | 15 | Unfortunately, it has some limitations because of weaknesses in the 16 | glib interface. 17 | 18 | If you use this, you really want to use the gensio wait functions, 19 | not g_cont_wait..() yourself. You don't strictly have have to, 20 | especially if your app is single threaded, but especially in 21 | multithreaded apps you cannot mix calls to the os funcs wait 22 | functions and the glib wait functions. Which means you can't use 23 | the blocking functions, which all use os func waiters. 24 | 25 | Performance should be ok for a single thread. For multiple 26 | threads, though, only on thing at a time can be waiting on the main 27 | glib thread. This is a weakness in glib. For multiple threads, 28 | one function sits in the main context and the others sit on 29 | condition variables. When the thead sitting on the main context 30 | wakes up, it wakes another waiting thread to take over. 31 | 32 | If performance is important, it might be better to put glib on top 33 | of gensio os funcs with 34 | .B g_main_context_set_poll_func(). 35 | I leave that as an exercise to the reader. 36 | .SH "RETURN VALUES" 37 | .B A gensio_err 38 | returns a standard gensio error. 39 | .SH "SEE ALSO" 40 | gensio_os_funcs(3), gensio(5), gensio_err(3) 41 | -------------------------------------------------------------------------------- /glib/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | -------------------------------------------------------------------------------- /glib/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = gensio_glib.h gensio_glib_dllvisibility.h 3 | -------------------------------------------------------------------------------- /glib/include/gensio/gensio_glib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_GLIB_H 9 | #define GENSIO_GLIB_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | /* 19 | * Allocate a glib-based os funcs. 20 | */ 21 | GENSIOGLIB_DLL_PUBLIC 22 | int gensio_glib_funcs_alloc(struct gensio_os_funcs **o); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* GENSIO_GLIB_H */ 29 | -------------------------------------------------------------------------------- /glib/include/gensio/gensio_glib_dllvisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIOGLIB_DLLVISIBILITY 9 | #define GENSIOGLIB_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIOGLIB_DLL_PUBLIC 13 | #define GENSIOGLIB_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIOGLIB_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIOGLIB_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIOGLIB_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIOGLIB_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIOGLIB_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIOGLIB_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIOGLIB_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIOGLIB_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIOGLIB_DLL_PUBLIC 35 | #define GENSIOGLIB_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIOGLIB_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /glib/libgensioglib.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensioglib 7 | Description: A library to abstract stream I/O like serial port, TCP, telnet, UDP, SSL, IPMI SOL, etc. 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensioglib -lgensio 10 | Libs.private: @GLIB_LIBS@ 11 | -------------------------------------------------------------------------------- /glib/swig/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = gensioglib.i 3 | 4 | SUBDIRS = . $(PYTHON_DIR) 5 | DIST_SUBDIRS = python 6 | -------------------------------------------------------------------------------- /glib/swig/gensioglib.i: -------------------------------------------------------------------------------- 1 | %module gensioglib 2 | 3 | %import 4 | 5 | %{ 6 | #include "config.h" 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | struct gensio_os_funcs *alloc_glib_os_funcs(swig_cb *log_handler) 15 | { 16 | struct gensio_os_funcs *o; 17 | int err; 18 | 19 | err = gensio_glib_funcs_alloc(&o); 20 | if (err) { 21 | fprintf(stderr, "Unable to allocate gensio os funcs: %s, giving up\n", 22 | gensio_err_to_str(err)); 23 | exit(1); 24 | } 25 | 26 | err = gensio_swig_setup_os_funcs(o, log_handler); 27 | if (err) { 28 | fprintf(stderr, "Unable to set up gensio os funcs: %s, giving up\n", 29 | gensio_err_to_str(err)); 30 | exit(1); 31 | } 32 | 33 | return o; 34 | } 35 | 36 | %} 37 | 38 | %nodefaultctor gensio_os_funcs; 39 | 40 | struct gensio_os_funcs { }; 41 | 42 | %extend gensio_os_funcs { 43 | ~gensio_os_funcs() { 44 | check_os_funcs_free(self); 45 | } 46 | } 47 | 48 | %newobject alloc_glib_os_funcs; 49 | struct gensio_os_funcs *alloc_glib_os_funcs(swig_cb *log_handler); 50 | -------------------------------------------------------------------------------- /glib/swig/python/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | gensioglib.py 3 | gensioglib_wrap.c 4 | -------------------------------------------------------------------------------- /glib/swig/python/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CFLAGS = $(PYTHON_CPPFLAGS) \ 3 | -I $(top_srcdir)/include \ 4 | -I$(top_builddir)/include \ 5 | -I $(top_srcdir) \ 6 | -I$(top_srcdir)/glib/include \ 7 | -I$(top_srcdir)/swig/include \ 8 | -DPYTHON_HAS_THREADS=@PYTHON_HAS_THREADS@ 9 | 10 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 11 | pythonlib_LTLIBRARIES = _gensioglib.la 12 | 13 | gensioglib_wrap.c gensioglib.py: $(top_srcdir)/glib/swig/gensioglib.i 14 | $(SWIG) $(DEFS) -python $(PYTHON_SWIG_FLAGS) -o gensioglib_wrap.c \ 15 | -I$(top_srcdir)/include -I$(top_srcdir)/swig/include \ 16 | $(top_srcdir)/glib/swig/gensioglib.i 17 | 18 | nodist__gensioglib_la_SOURCES = gensioglib_wrap.c 19 | _gensioglib_la_LIBADD = $(top_builddir)/glib/libgensioglib.la \ 20 | $(top_builddir)/lib/libgensio.la \ 21 | $(top_builddir)/lib/libgensioosh.la \ 22 | $(OPENSSL_LIBS) \ 23 | $(top_builddir)/swig/python/libgensio_python_swig.la \ 24 | $(PYTHON_UNDEF_LIBS) 25 | _gensioglib_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 26 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 27 | 28 | clean-local: 29 | rm -rf __pycache__ gensioglib_wrap.c gensioglib.py 30 | 31 | install-exec-local: _gensioglib.la gensioglib.py 32 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 33 | $(INSTALL_DATA) gensioglib.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 34 | 35 | uninstall-local: 36 | $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_gensioglib.$(PYTHON_EXT_EXT)" 37 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/gensioglib.py" 38 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | 4 | noinst_HEADERS = pthread_handler.h 5 | -------------------------------------------------------------------------------- /include/gensio/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | gensio_version.h 3 | -------------------------------------------------------------------------------- /include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = gensio.h gensio_class.h \ 3 | gensio_addr.h gensio_unix.h gensio_base.h gensio_acc_gensio.h \ 4 | gensio_ll_fd.h gensio_ll_gensio.h selector.h argvutils.h \ 5 | gensio_os_funcs.h gensio_err.h gensio_osops.h \ 6 | gensio_list.h gensio_version.h gensio_dllvisibility.h \ 7 | gensio_deprecated.h gensio_mdns.h gensio_types.h \ 8 | gensio_osops_addrinfo.h gensio_osops_stdsock.h gensio_circbuf.h \ 9 | gensio_selector.h gensio_win.h gensio_osops_env.h \ 10 | gensio_os_funcs_public.h gensio_time.h gensio_ax25_addr.h \ 11 | gensio_control.h netif.h gensio_buffer.h gensioosh_dllvisibility.h \ 12 | gensio_utils.h gensio_atomics.h gensio_refcount.h gensio_byteswap.h \ 13 | gensio_openipmi_oshandler.h 14 | 15 | EXTRA_DIST = gensio_version.h.in 16 | -------------------------------------------------------------------------------- /include/gensio/gensio_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_BUFFER_H 9 | #define GENSIO_BUFFER_H 10 | 11 | #include 12 | 13 | struct gensio_buffer { 14 | unsigned char *buf; 15 | unsigned int maxsize; 16 | unsigned int cursize; 17 | unsigned int pos; 18 | }; 19 | 20 | typedef int (*gensio_buffer_do_write)(void *cbdata, void *buf, 21 | unsigned int buflen, 22 | unsigned int *written); 23 | 24 | /* 25 | * Call do_write() with all the data in the buffer. This may take 26 | * multiple calls to do_write() if the data wraps. 27 | * If do_write() returns an error, buffer_write will exit immediately. 28 | * It may have written some data. 29 | */ 30 | GENSIO_DLL_PUBLIC 31 | int gensio_buffer_write(gensio_buffer_do_write do_write, void *cb_data, 32 | struct gensio_buffer *buf); 33 | 34 | /* 35 | * Add the data to the buffer. If there is not enough room for the data, 36 | * part of the data is added. The number of bytes added is returned. 37 | */ 38 | GENSIO_DLL_PUBLIC 39 | unsigned int gensio_buffer_output(struct gensio_buffer *buf, 40 | const unsigned char *data, unsigned int len); 41 | 42 | /* 43 | * Add a single character to the buffer. Returns the number of 44 | * characters added. 45 | */ 46 | GENSIO_DLL_PUBLIC 47 | unsigned int gensio_buffer_outchar(struct gensio_buffer *buf, 48 | unsigned char data); 49 | 50 | /* 51 | * Initialize the buffer. If data is NULL, it is allocated. 52 | */ 53 | GENSIO_DLL_PUBLIC 54 | int gensio_buffer_init(struct gensio_buffer *buf, 55 | unsigned char *data, unsigned int datalen); 56 | 57 | /* 58 | * Number of bytes left in the buffer. 59 | */ 60 | #define gensio_buffer_left(buf) ((buf)->maxsize - (buf)->cursize) 61 | 62 | /* 63 | * Number of bytes currently held in the buffer. 64 | */ 65 | #define gensio_buffer_cursize(buf) ((buf)->cursize) 66 | 67 | /* 68 | * Consume the given number of bytes in the buffer. 69 | */ 70 | #define gensio_buffer_advance(bufp, count) \ 71 | do { \ 72 | (bufp)->pos += (count); \ 73 | while ((bufp)->pos >= (bufp)->maxsize) \ 74 | (bufp)->pos -= (bufp)->maxsize; \ 75 | } 76 | 77 | /* 78 | * Set the buffer to have no data. 79 | */ 80 | #define gensio_buffer_reset(buf) \ 81 | do { \ 82 | (buf)->cursize = 0; \ 83 | (buf)->pos = 0; \ 84 | } while(0) 85 | 86 | #endif /* _SER2NET_BUFFER_H */ 87 | -------------------------------------------------------------------------------- /include/gensio/gensio_byteswap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2025 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * Basic byte-swapping definitions. 10 | */ 11 | 12 | #ifndef GENSIO_BYTESWAP_H 13 | #define GENSIO_BYTESWAP_H 14 | 15 | #ifdef _WIN32 16 | /* Assume this for Windows. */ 17 | #define GENSIO_IS_BIG_ENDIAN 0 18 | #define GENSIO_IS_LITTLE_ENDIAN 1 19 | #define gensio_bswap_16 _byteswap_ushort 20 | #define gensio_bswap_32 _byteswap_ulong 21 | #define gensio_bswap_64 _byteswap_uint64 22 | 23 | #elif defined(linux) 24 | #include 25 | #include 26 | #define GENSIO_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN) 27 | #define GENSIO_IS_LITTLE_ENDIAN (__BYTE_ORDER != __BIG_ENDIAN) 28 | #define gensio_bswap_16 bswap_16 29 | #define gensio_bswap_32 bswap_32 30 | #define gensio_bswap_64 bswap_64 31 | 32 | #else /* BSD and others? */ 33 | #if defined(__APPLE__) 34 | #include 35 | #include 36 | #define gensio_bswap_16 OSSwapInt16 37 | #define gensio_bswap_32 OSSwapInt32 38 | #define gensio_bswap_64 OSSwapInt64 39 | #else 40 | #include 41 | #define gensio_bswap_16 bswap16 42 | #define gensio_bswap_32 bswap32 43 | #define gensio_bswap_64 bswap64 44 | #endif 45 | #define GENSIO_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN) 46 | #define GENSIO_IS_LITTLE_ENDIAN (BYTE_ORDER != BIG_ENDIAN) 47 | #endif 48 | 49 | #if GENSIO_IS_BIG_ENDIAN 50 | #define gensio_bswap_16_from_be(x) (x) 51 | #define gensio_bswap_32_from_be(x) (x) 52 | #define gensio_bswap_64_from_be(x) (x) 53 | #define gensio_bswap_16_to_be(x) (x) 54 | #define gensio_bswap_32_to_be(x) (x) 55 | #define gensio_bswap_64_to_be(x) (x) 56 | #define gensio_bswap_16_from_le(x) gensio_bswap_16(x) 57 | #define gensio_bswap_32_from_le(x) gensio_bswap_32(x) 58 | #define gensio_bswap_64_from_le(x) gensio_bswap_164(x) 59 | #define gensio_bswap_16_to_le(x) gensio_bswap_16(x) 60 | #define gensio_bswap_32_to_le(x) gensio_bswap_32(x) 61 | #define gensio_bswap_64_to_le(x) gensio_bswap_64(x) 62 | #else 63 | #define gensio_bswap_16_from_be(x) gensio_bswap_16(x) 64 | #define gensio_bswap_32_from_be(x) gensio_bswap_32(x) 65 | #define gensio_bswap_64_from_be(x) gensio_bswap_64(x) 66 | #define gensio_bswap_16_to_be(x) gensio_bswap_16(x) 67 | #define gensio_bswap_32_to_be(x) gensio_bswap_32(x) 68 | #define gensio_bswap_64_to_be(x) gensio_bswap_64(x) 69 | #define gensio_bswap_16_from_le(x) (x) 70 | #define gensio_bswap_32_from_le(x) (x) 71 | #define gensio_bswap_64_from_le(x) (x) 72 | #define gensio_bswap_16_to_le(x) (x) 73 | #define gensio_bswap_32_to_le(x) (x) 74 | #define gensio_bswap_64_to_le(x) (x) 75 | #endif 76 | 77 | #endif /* GENSIO_BYTESWAP_H */ 78 | -------------------------------------------------------------------------------- /include/gensio/gensio_deprecated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_DEPRECATED 9 | #define GENSIO_DEPRECATED 10 | 11 | #if defined(__GNUC__) && (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)) 12 | # define GENSIO_FUNC_DEPRECATED __attribute__ ((deprecated)) 13 | # define GENSIO_TYPE_DEPRECATED __attribute__ ((deprecated)) 14 | # define GENSIO_VAR_DEPRECATED __attribute__ ((deprecated)) 15 | #else 16 | # define GENSIO_FUNC_DEPRECATED 17 | # define GENSIO_TYPE_DEPRECATED 18 | # define GENSIO_VAR_DEPRECATED 19 | #endif 20 | 21 | #endif /* GENSIO_DEPRECATED */ 22 | -------------------------------------------------------------------------------- /include/gensio/gensio_dllvisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_DLLVISIBILITY 9 | #define GENSIO_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIO_DLL_PUBLIC 13 | #define GENSIO_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIO_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIO_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIO_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIO_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIO_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIO_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIO_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIO_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIO_DLL_PUBLIC 35 | #define GENSIO_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIO_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /include/gensio/gensio_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_LIST_H 9 | #define GENSIO_LIST_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* 17 | * Generic doubly-linked list operations. 18 | */ 19 | struct gensio_list; 20 | struct gensio_link { 21 | struct gensio_list *list; 22 | struct gensio_link *next; 23 | struct gensio_link *prev; 24 | }; 25 | 26 | struct gensio_list { 27 | struct gensio_link link; 28 | }; 29 | 30 | GENSIOOSH_DLL_PUBLIC 31 | void gensio_list_rm(struct gensio_list *list, struct gensio_link *link); 32 | GENSIOOSH_DLL_PUBLIC 33 | void gensio_list_add_head(struct gensio_list *list, struct gensio_link *link); 34 | GENSIOOSH_DLL_PUBLIC 35 | void gensio_list_add_tail(struct gensio_list *list, struct gensio_link *link); 36 | GENSIOOSH_DLL_PUBLIC 37 | void gensio_list_add_next(struct gensio_list *list, struct gensio_link *curr, 38 | struct gensio_link *link); 39 | GENSIOOSH_DLL_PUBLIC 40 | void gensio_list_add_prev(struct gensio_list *list, struct gensio_link *curr, 41 | struct gensio_link *link); 42 | GENSIOOSH_DLL_PUBLIC 43 | void gensio_list_init(struct gensio_list *list); 44 | GENSIOOSH_DLL_PUBLIC 45 | bool gensio_list_empty(struct gensio_list *list); 46 | 47 | #define gensio_list_first(list) ((list)->link.next) 48 | #define gensio_list_last(list) ((list)->link.prev) 49 | /* Go to the next entry, returning NULL if at the end. */ 50 | #define gensio_list_next(list, linkv) ((linkv)->next == &(list)->link ? \ 51 | NULL : (linkv)->next) 52 | /* Go to the next entry, wrapping around to the first entry if at end. */ 53 | #define gensio_list_next_wrap(list, linkv) ((linkv)->next == &(list)->link ? \ 54 | (list)->link.next : (linkv)->next) 55 | 56 | #define gensio_list_for_each(list, l) \ 57 | for ((l) = (list)->link.next; (l) != &(list)->link; l = l->next) 58 | 59 | #define gensio_list_for_each_safe(list, l, l2) \ 60 | for ((l) = (list)->link.next, (l2) = (l)->next; \ 61 | (l) != &(list)->link; (l) = (l2), (l2) = (l)->next ) 62 | 63 | /* Is the given list link in a list? */ 64 | #define gensio_list_link_inlist(l) ((l)->list != NULL) 65 | 66 | /* Is the given list link in a specific list? */ 67 | #define gensio_list_link_in_this_list(l, listin) ((l)->list == (listin)) 68 | 69 | #define gensio_list_link_init(l) \ 70 | do { \ 71 | (l)->list = NULL; \ 72 | (l)->prev = NULL; \ 73 | (l)->next = NULL; \ 74 | } while(0) 75 | 76 | #endif /* GENSIO_LIST_H */ 77 | -------------------------------------------------------------------------------- /include/gensio/gensio_ll_gensio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_LL_GENSIO_H 9 | #define GENSIO_LL_GENSIO_H 10 | 11 | #include 12 | #include 13 | 14 | GENSIO_DLL_PUBLIC 15 | struct gensio_ll *gensio_gensio_ll_alloc(struct gensio_os_funcs *o, 16 | struct gensio *child); 17 | 18 | #endif /* GENSIO_LL_GENSIO_H */ 19 | -------------------------------------------------------------------------------- /include/gensio/gensio_openipmi_oshandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2025 Corey Minyard 4 | * 5 | * This is an OpenIPMI os handler that you can create from a 6 | * gensio_os_funcs. 7 | * 8 | * SPDX-License-Identifier: LGPL-2.1-only 9 | */ 10 | 11 | #ifndef GENSIO_OPENPMI_OSHANDLER_H 12 | #define GENSIO_OPENIPM_OSHANDLER_H 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if defined GENSIO_LINK_STATIC 21 | #define GENSIO_OI_OSH_DLL_PUBLIC 22 | #define GENSIO_OI_OSH_DLL_LOCAL 23 | #elif defined _WIN32 || defined __CYGWIN__ 24 | #ifdef BUILDING_GENSIO_OI_OSH_DLL 25 | #ifdef __GNUC__ 26 | #define GENSIO_OI_OSH_DLL_PUBLIC __attribute__ ((dllexport)) 27 | #else 28 | #define GENSIO_OI_OSH_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 29 | #endif 30 | #else 31 | #ifdef __GNUC__ 32 | #define GENSIO_OI_OSH_DLL_PUBLIC __attribute__ ((dllimport)) 33 | #else 34 | #define GENSIO_OI_OSH_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 35 | #endif 36 | #endif 37 | #define GENSIO_OI_OSH_DLL_LOCAL 38 | #else 39 | #if __GNUC__ >= 4 40 | #define GENSIO_OI_OSH_DLL_PUBLIC __attribute__ ((visibility ("default"))) 41 | #define GENSIO_OI_OSH_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 42 | #else 43 | #define GENSIO_OI_OSH_DLL_PUBLIC 44 | #define GENSIO_OI_OSH_DLL_LOCAL 45 | #endif 46 | #endif 47 | 48 | GENSIO_OI_OSH_DLL_PUBLIC 49 | os_handler_t *gensio_openipmi_oshandler_alloc(struct gensio_os_funcs *o); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* GENSIO_OPENIPMI_OSHANDLER_H */ 56 | -------------------------------------------------------------------------------- /include/gensio/gensio_osops_addrinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2019 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * NOTE: DO NOT USE THIS IS APPLICATION CODE! 10 | * 11 | * This is only for use if you are creating your own OS handler and 12 | * using addrinfo based addresses. If you use this and the OS handler 13 | * doesn't use addrinfo based addresses, bad things will happen. 14 | */ 15 | 16 | #ifndef GENSIO_OSOPS_ADDRINFO_H 17 | #define GENSIO_OSOPS_ADDRINFO_H 18 | 19 | /* Avoid including net headers. */ 20 | struct addrinfo; 21 | struct sockaddr; 22 | 23 | #include 24 | #include 25 | 26 | /* Get the entire addrinfo list for the address. */ 27 | GENSIOOSH_DLL_PUBLIC 28 | struct addrinfo *gensio_addr_addrinfo_get(const struct gensio_addr *addr); 29 | 30 | /* Get the current addrinfo. */ 31 | GENSIOOSH_DLL_PUBLIC 32 | struct addrinfo *gensio_addr_addrinfo_get_curr(const struct gensio_addr *addr); 33 | 34 | /* 35 | * Create an address. If size is zero, the addrinfo list is NULL and 36 | * must be set with gensio_addr_addrinfo_set(). Othersize an addrinfo 37 | * with an address of the given size is allocated. 38 | * 39 | * An address used for recvfrom is special, it cannot be duplicated 40 | * with a refcount because the addrinfo memory is reused. So allow it 41 | * to be specially allocated. 42 | */ 43 | GENSIOOSH_DLL_PUBLIC 44 | struct gensio_addr *gensio_addr_addrinfo_make(struct gensio_os_funcs *o, 45 | unsigned int size, 46 | bool is_recvfrom); 47 | 48 | /* 49 | * Set the addrinfo list. The current list must be NULL. All the 50 | * data in ai must be allocated with o->zalloc(); 51 | */ 52 | GENSIOOSH_DLL_PUBLIC 53 | void gensio_addr_addrinfo_set(struct gensio_addr *addr, 54 | struct addrinfo *ai); 55 | 56 | /* Get/set the port for a sockaddr. */ 57 | GENSIOOSH_DLL_PUBLIC 58 | int gensio_sockaddr_get_port(const struct sockaddr *s, unsigned int *port); 59 | GENSIOOSH_DLL_PUBLIC 60 | int gensio_sockaddr_set_port(const struct sockaddr *s, unsigned int port); 61 | 62 | /* Set up the osops with addrinfo based address handling. */ 63 | GENSIOOSH_DLL_PUBLIC 64 | void gensio_addr_addrinfo_set_os_funcs(struct gensio_os_funcs *o); 65 | 66 | /* 67 | * This is a special value for family that is used for returning the 68 | * ifindex from a recvfrom. 69 | */ 70 | #define GENSIO_AF_IFINDEX 236 71 | 72 | #endif /* GENSIO_OSOPS_ADDRINFO_H */ 73 | -------------------------------------------------------------------------------- /include/gensio/gensio_osops_stdsock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2019 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * NOTE: DO NOT USE THIS IS APPLICATION CODE! 10 | * 11 | * This is only for use if you are creating your own OS handler and 12 | * using addrinfo based addresses and standard sockets. If you use 13 | * this and the OS handler doesn't use addrinfo based addresses, bad 14 | * things will happen. 15 | */ 16 | 17 | #ifndef GENSIO_OSOPS_STDSOCK_H 18 | #define GENSIO_OSOPS_STDSOCK_H 19 | 20 | #include 21 | #include 22 | 23 | 24 | /* Set up the osops with addrinfo based standard socket handling. */ 25 | GENSIOOSH_DLL_PUBLIC 26 | int gensio_stdsock_set_os_funcs(struct gensio_os_funcs *o); 27 | GENSIOOSH_DLL_PUBLIC 28 | void gensio_stdsock_cleanup(struct gensio_os_funcs *o); 29 | 30 | #endif /* GENSIO_OSOPS_STDSOCK_H */ 31 | -------------------------------------------------------------------------------- /include/gensio/gensio_refcount.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2024 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_REFCOUNT_H 9 | #define GENSIO_REFCOUNT_H 10 | 11 | /* 12 | * A basic refcount type using atomics. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | typedef struct { 19 | gensio_atomic_uint count; 20 | } gensio_refcount; 21 | 22 | #define gensio_refcount_set(a, v) gensio_atomic_set(&(a)->count, v) 23 | #define gensio_refcount_get(a) gensio_atomic_get(&(a)->count) 24 | 25 | /* 26 | * Set up the refcount. 27 | */ 28 | static inline int gensio_refcount_init(struct gensio_os_funcs *o, 29 | gensio_refcount *a, unsigned int val) 30 | { 31 | return gensio_atomic_init(o, &a->count, val); 32 | } 33 | 34 | /* 35 | * Increment the refcount. The refcount must be non-zero. 36 | */ 37 | static inline void gensio_refcount_inc(gensio_refcount *a) 38 | { 39 | unsigned int gensio_refcount_old; 40 | 41 | gensio_atomic_inc_if_nz(&a->count, &gensio_refcount_old); 42 | assert(gensio_refcount_old != 0); 43 | } 44 | 45 | /* 46 | * Decrement the refcount. The refcount must be non-zero. The new 47 | * value of the refcount is returned. 48 | */ 49 | static inline unsigned int gensio_refcount_dec(gensio_refcount *a) 50 | { 51 | unsigned int gensio_refcount_old; 52 | 53 | gensio_atomic_dec_if_nz(&a->count, &gensio_refcount_old); 54 | assert(gensio_refcount_old != 0); 55 | return gensio_refcount_old - 1; 56 | } 57 | 58 | /* 59 | * If the refcount is non-zero, decrement it. Otherwise no operation 60 | * is done. If the value was decremented, return true, otherwise 61 | * return false. 62 | */ 63 | static inline bool gensio_refcount_dec_if_nz(gensio_refcount *a) 64 | { 65 | unsigned int gensio_refcount_old; 66 | 67 | return gensio_atomic_dec_if_nz(&a->count, &gensio_refcount_old); 68 | } 69 | 70 | /* 71 | * Increment the refcount if the refcount is non-zero. If the refcount 72 | * was zero, return false, otherwise return true. 73 | */ 74 | static inline bool gensio_refcount_inc_if_nz(gensio_refcount *a) 75 | { 76 | unsigned int gensio_refcount_old; 77 | 78 | return gensio_atomic_inc_if_nz(&a->count, &gensio_refcount_old); 79 | } 80 | 81 | /* 82 | * Nothing to do for now. 83 | */ 84 | static inline void gensio_refcount_cleanup(gensio_refcount *a) 85 | { 86 | gensio_atomic_cleanup(&a->count); 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /include/gensio/gensio_selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_SELECTOR_H 9 | #define GENSIO_SELECTOR_H 10 | 11 | #include 12 | 13 | struct selector_s; /* Don't include selector.h to reduce namespace pollution. */ 14 | 15 | /* 16 | * DEPRECATED. 17 | * 18 | * Same as gensio_unix_func_alloc(), use that function instead. This 19 | * is here for backwards compatibility. 20 | */ 21 | GENSIOOSH_DLL_PUBLIC 22 | struct gensio_os_funcs *gensio_selector_alloc(struct selector_s *sel, 23 | int wake_sig); 24 | 25 | #endif /* GENSIO_SELECTOR_H */ 26 | -------------------------------------------------------------------------------- /include/gensio/gensio_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2019 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_TIME_H 9 | #define GENSIO_TIME_H 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* 19 | * Add time v to time t1. 20 | */ 21 | GENSIO_DLL_PUBLIC 22 | void gensio_time_add(gensio_time *t, gensio_time *v); 23 | 24 | /* 25 | * Add the given number of nanoseconds to the time. 26 | */ 27 | GENSIO_DLL_PUBLIC 28 | void gensio_time_add_nsecs(gensio_time *t, int64_t v); 29 | 30 | GENSIO_DLL_PUBLIC 31 | int64_t gensio_time_to_msecs(gensio_time *t); 32 | GENSIO_DLL_PUBLIC 33 | int64_t gensio_time_to_usecs(gensio_time *t); 34 | GENSIO_DLL_PUBLIC 35 | int64_t gensio_time_to_nsecs(gensio_time *t); 36 | GENSIO_DLL_PUBLIC 37 | void gensio_msecs_to_time(gensio_time *t, int64_t v); 38 | GENSIO_DLL_PUBLIC 39 | void gensio_usecs_to_time(gensio_time *t, int64_t v); 40 | GENSIO_DLL_PUBLIC 41 | void gensio_nsecs_to_time(gensio_time *t, int64_t v); 42 | 43 | /* 44 | * Return the value of t1 - t2 in nanoseconds. 45 | */ 46 | GENSIO_DLL_PUBLIC 47 | int64_t gensio_time_diff_nsecs(gensio_time *t1, gensio_time *t2); 48 | 49 | #define GENSIO_NSECS_IN_SEC 1000000000LL 50 | 51 | #define GENSIO_NSECS_TO_USECS(v) (((int64_t) (v) + 500) / 1000) 52 | #define GENSIO_NSECS_TO_MSECS(v) (((int64_t) (v) + 500000) / 1000000) 53 | #define GENSIO_NSECS_TO_SECS(v) (((int64_t) (v) + 500000000) / 1000000000) 54 | 55 | #define GENSIO_USECS_TO_NSECS(v) ((int64_t) (v) * 1000) 56 | #define GENSIO_MSECS_TO_NSECS(v) ((int64_t) (v) * 1000000) 57 | #define GENSIO_SECS_TO_NSECS(v) ((int64_t) (v) * 1000000000) 58 | 59 | #define gensio_time_is_zero(v) ((v).secs == 0 && (v).nsecs == 0) 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* GENSIO_TIME_H */ 66 | -------------------------------------------------------------------------------- /include/gensio/gensio_unix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_UNIX_H 9 | #define GENSIO_UNIX_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | struct selector_s; /* Don't include selector.h to reduce namespace pollution. */ 19 | 20 | /* 21 | * Allocate a selector-based os funcs. 22 | * 23 | * If you pass in NULL for sel, this will allocate a selector along 24 | * with it. The default thread model is chosen. In this case the 25 | * selector allocated is freed when the os funcs are freed, since you 26 | * can't get to it :-). 27 | * 28 | * If you pass in a selector, it will not be freed when the os funcs 29 | * is freed. 30 | */ 31 | GENSIOOSH_DLL_PUBLIC 32 | int gensio_unix_funcs_alloc(struct selector_s *sel, int wake_sig, 33 | struct gensio_os_funcs **ro); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* GENSIO_UNIX_H */ 40 | -------------------------------------------------------------------------------- /include/gensio/gensio_version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_VERSION_H 9 | #define GENSIO_VERSION_H 10 | 11 | #define gensio_version_major @gensio_VERSION_MAJOR@ 12 | #define gensio_version_minor @gensio_VERSION_MINOR@ 13 | #define gensio_version_patch @gensio_VERSION_PATCH@ 14 | #define gensio_version_string "@gensio_VERSION_STRING@" 15 | 16 | /* 17 | * A macro to compare a gensio version, for handling new features. 18 | */ 19 | #define gensio_version_ge(maj, min, patch) \ 20 | ((gensio_version_major > (maj)) || \ 21 | (gensio_version_major == (maj) && gensio_version_minor > (min)) || \ 22 | (gensio_version_major == (maj) && gensio_version_minor == (min) && \ 23 | gensio_version_patch >= (patch))) 24 | 25 | /* 26 | * A macro to compare a gensio version, for handling features being 27 | * removed. 28 | */ 29 | #define gensio_version_lt(maj, min, patch) \ 30 | ((gensio_version_major < (maj)) || \ 31 | (gensio_version_major == (maj) && gensio_version_minor < (min)) || \ 32 | (gensio_version_major == (maj) && gensio_version_minor == (min) && \ 33 | gensio_version_patch < (patch))) 34 | 35 | 36 | #endif /* GENSIO_VERSION_H */ 37 | -------------------------------------------------------------------------------- /include/gensio/gensio_win.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_WIN_H 9 | #define GENSIO_WIN_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | /* 19 | * Allocate a windows os funcs. 20 | */ 21 | GENSIOOSH_DLL_PUBLIC 22 | int gensio_win_funcs_alloc(struct gensio_os_funcs **ro); 23 | 24 | HANDLE gensio_os_proc_win_get_main_handle(struct gensio_os_proc_data *data); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* GENSIO_WIN_H */ 31 | -------------------------------------------------------------------------------- /include/gensio/gensioosh_dllvisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIOOSH_DLLVISIBILITY 9 | #define GENSIOOSH_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIOOSH_DLL_PUBLIC 13 | #define GENSIOOSH_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIOOSH_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIOOSH_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIOOSH_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIOOSH_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIOOSH_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIOOSH_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIOOSH_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIOOSH_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIOOSH_DLL_PUBLIC 35 | #define GENSIOOSH_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIOOSH_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /include/gensio/netif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2019 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_NETIF_H 9 | #define GENSIO_NETIF_H 10 | 11 | /* 12 | * Generic ways to get to network interface information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | enum gensio_net_if_flags { 24 | GENSIO_NET_IF_UP = (1 << 0), 25 | GENSIO_NET_IF_LOOPBACK = (1 << 1), 26 | GENSIO_NET_IF_MULTICAST = (1 << 2), 27 | }; 28 | 29 | struct gensio_net_addr 30 | { 31 | unsigned int family; /* GENSIO_NETTTYPE_xxx */ 32 | unsigned int flags; 33 | uint8_t netbits; /* Bits in netmask */ 34 | uint8_t addrlen; /* Bytes in addr. */ 35 | unsigned char addr[16]; 36 | char *addrstr; 37 | }; 38 | 39 | struct gensio_net_if 40 | { 41 | char *name; 42 | enum gensio_net_if_flags flags; 43 | unsigned int ifindex; 44 | unsigned int naddrs; 45 | struct gensio_net_addr *addrs; 46 | }; 47 | 48 | /* 49 | * Return information about the network interfaces on the system. 50 | */ 51 | GENSIOOSH_DLL_PUBLIC 52 | int gensio_os_get_net_ifs(struct gensio_os_funcs *o, 53 | struct gensio_net_if ***rifs, unsigned int *rnifs); 54 | 55 | GENSIOOSH_DLL_PUBLIC 56 | void gensio_os_free_net_ifs(struct gensio_os_funcs *o, 57 | struct gensio_net_if **ifs, unsigned int nifs); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* GENSIO_NETIF_H */ 64 | -------------------------------------------------------------------------------- /include/pthread_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2020 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * This allows a lot of pthread calls to be dummied out if pthreads is 10 | * disabled. 11 | */ 12 | #ifdef _WIN32 13 | #include 14 | #define lock_type SRWLOCK 15 | #define LOCK_INIT(l) InitializeSRWLock(l) 16 | #define LOCK_DESTROY(l) do {} while(0) 17 | #define LOCK(l) AcquireSRWLockExclusive(l) 18 | #define UNLOCK(l) ReleaseSRWLockExclusive(l) 19 | #define LOCK_INITIALIZER SRWLOCK_INIT 20 | #define lock_thread_type DWORD 21 | #define LOCK_GET_THREAD_ID GetCurrentThreadId() 22 | #define LOCK_THREAD_ID_EQUAL(a,b) ((a) == (b)) 23 | #elif defined(USE_PTHREADS) 24 | #include 25 | #include 26 | #define lock_type pthread_mutex_t 27 | #define LOCK_INIT(l) assert(pthread_mutex_init(l, NULL) == 0) 28 | #define LOCK_DESTROY(l) assert(pthread_mutex_destroy(l)== 0) 29 | #define LOCK(l) assert(pthread_mutex_lock(l) == 0) 30 | #define UNLOCK(l) assert(pthread_mutex_unlock(l) == 0) 31 | #define LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER 32 | #define lock_thread_type pthread_t 33 | #define LOCK_GET_THREAD_ID pthread_self() 34 | #define LOCK_THREAD_ID_EQUAL(a,b) pthread_equal(a,b) 35 | #else 36 | #include 37 | #define lock_type int 38 | #define LOCK_INIT(l) do { *l = 0; } while(0) 39 | #define LOCK_DESTROY(l) do { assert(*l == 0); } while(0) 40 | #define LOCK(l) do { assert(*l == 0); *l = 1; } while(0) 41 | #define UNLOCK(l) do { assert(*l == 1); *l = 0; } while(0) 42 | #define LOCK_INITIALIZER 0 43 | #define lock_thread_type int 44 | #define LOCK_GET_THREAD_ID 0 45 | #define LOCK_THREAD_ID_EQUAL(a,b) ((a) == (b)) 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | builtin_gensios.h 3 | -------------------------------------------------------------------------------- /lib/avahi_watcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2020 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef AVAHI_WATCHER_H 9 | #define AVAHI_WATCHER_H 10 | 11 | #include 12 | #include 13 | 14 | /* 15 | * You must call these before/after doing any Avahi calls. Avahi is 16 | * single-threaded. 17 | */ 18 | void gensio_avahi_lock(AvahiPoll *ap); 19 | void gensio_avahi_unlock(AvahiPoll *ap); 20 | 21 | /* Allocate an Avahi poll structure. You only need one of these. */ 22 | struct AvahiPoll *alloc_gensio_avahi_poll(struct gensio_os_funcs *o); 23 | 24 | typedef void (*gensio_avahi_done)(AvahiPoll *ap, void *userdata); 25 | 26 | void gensio_avahi_poll_disable(AvahiPoll *ap); 27 | 28 | void gensio_avahi_poll_free(AvahiPoll *ap, 29 | gensio_avahi_done done, void *userdata); 30 | 31 | #endif /* AVAHI_WATCHER_H */ 32 | -------------------------------------------------------------------------------- /lib/crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2022 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* See rfc1549 */ 9 | static const unsigned short ccitt_table[256] = { 10 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 11 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 12 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 13 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 14 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 15 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 16 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 17 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 18 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 19 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 20 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 21 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 22 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 23 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 24 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 25 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 26 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 27 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 28 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 29 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 30 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 31 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 32 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 33 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 34 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 35 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 36 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 37 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 38 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 39 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 40 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 41 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 42 | }; 43 | 44 | static void 45 | crc16_ccitt(const unsigned char *buf, unsigned int len, uint16_t *icrc) 46 | { 47 | unsigned int i; 48 | uint16_t crc = *icrc; 49 | 50 | for (i = 0; i < len; i++) 51 | crc = (crc >> 8) ^ ccitt_table[(crc ^ buf[i]) & 0xff]; 52 | 53 | *icrc = crc; 54 | } 55 | -------------------------------------------------------------------------------- /lib/errtrig.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2020 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #include "errtrig.h" 9 | #ifdef _MSC_VER 10 | #include 11 | #endif 12 | 13 | #include "pthread_handler.h" 14 | #include 15 | /* 16 | * Some memory allocation and other failure testing. If the 17 | * GENSIO_ERRTRIG_TEST environment variable is set to number N, the 18 | * Nth call to do_errtrig will return true. The program should call 19 | * gensio_osfunc_exit (below); it will cause specific values to be 20 | * returned on an exit failure. 21 | */ 22 | 23 | static lock_type errtrig_lock = LOCK_INITIALIZER; 24 | static bool errtrig_initialized; 25 | static bool errtrig_ready; 26 | static bool triggered; 27 | static unsigned int errtrig_count; 28 | static unsigned int errtrig_curr; 29 | 30 | static void *trig_caller[4]; 31 | 32 | bool 33 | do_errtrig(void) 34 | { 35 | unsigned int curr; 36 | bool triggerit = false; 37 | 38 | LOCK(&errtrig_lock); 39 | if (!errtrig_initialized) { 40 | char *s = getenv("GENSIO_ERRTRIG_TEST"); 41 | 42 | errtrig_initialized = true; 43 | if (s) { 44 | errtrig_count = strtoul(s, NULL, 0); 45 | errtrig_ready = true; 46 | } 47 | } 48 | if (errtrig_ready) { 49 | curr = errtrig_curr++; 50 | if (curr == errtrig_count) { 51 | triggered = true; 52 | triggerit = true; 53 | #if _MSC_VER 54 | trig_caller[0] = _ReturnAddress(); 55 | #else 56 | trig_caller[0] = __builtin_return_address(0); 57 | #if 0 58 | trig_caller[1] = __builtin_return_address(1); 59 | trig_caller[2] = __builtin_return_address(2); 60 | trig_caller[3] = __builtin_return_address(3); 61 | #endif 62 | #endif 63 | } 64 | } 65 | UNLOCK(&errtrig_lock); 66 | return triggerit; 67 | } 68 | 69 | #include 70 | void errtrig_exit(int rv) 71 | { 72 | if (!errtrig_ready) 73 | exit(rv); 74 | 75 | assert (rv == 1 || rv == 0); /* Only these values are allowed. */ 76 | 77 | /* 78 | * Return an error. The values mean: 79 | * 80 | * 0 - No error occurred and the memory allocation failure didn't happen 81 | * 1 - An error occurred and the memory allocation failure happenned 82 | * 2 - No error occurred and the memory allocation failure happenned 83 | * 3 - An error occurred and the memory allocation failure didn't happen 84 | */ 85 | if (rv == 0 && triggered) 86 | rv = 2; 87 | if (rv == 0 && !triggered) 88 | rv = 0; 89 | if (rv == 1 && triggered) 90 | rv = 1; 91 | if (rv == 1 && !triggered) 92 | rv = 3; 93 | exit(rv); 94 | } 95 | -------------------------------------------------------------------------------- /lib/errtrig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2020 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * Test code to trigger errors at specific counts. See errtrig.c for details. 10 | */ 11 | #ifndef _GENSIO_ERRTRIG_H 12 | #define _GENSIO_ERRTRIG_H 13 | 14 | #include "config.h" 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef ENABLE_INTERNAL_TRACE 21 | #define ENABLE_ERRTRIG_TEST 22 | #endif 23 | 24 | #ifdef ENABLE_ERRTRIG_TEST 25 | GENSIOOSH_DLL_PUBLIC 26 | bool do_errtrig(void); 27 | GENSIOOSH_DLL_PUBLIC 28 | void errtrig_exit(int rv); 29 | #else 30 | #define do_errtrig() false 31 | #define errtrig_exit(rv) exit(rv) 32 | #endif 33 | 34 | #endif /* _GENSIO_ERRTRIG_H */ 35 | -------------------------------------------------------------------------------- /lib/gensio_base_parms.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * gensio - A library for abstracting stream I/O 4 | * Copyright (C) 2018 Corey Minyard 5 | * 6 | * SPDX-License-Identifier: LGPL-2.1-only 7 | */ 8 | 9 | #ifndef _GENSIO_BASEN_PARMS_H 10 | #define _GENSIO_BASEN_PARMS_H 11 | 12 | #include 13 | 14 | struct gensio_base_parms { 15 | struct gensio_os_funcs *o; 16 | int drain_timeout; 17 | }; 18 | 19 | void i_gensio_base_parms_set(struct gensio *io, 20 | const struct gensio_base_parms *parms); 21 | 22 | #endif /* _GENSIO_BASEN_PARMS_H */ 23 | -------------------------------------------------------------------------------- /lib/gensio_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_NET_H 9 | #define GENSIO_NET_H 10 | 11 | enum gensio_tcpd_options { 12 | GENSIO_TCPD_ON, 13 | GENSIO_TCPD_PRINT, 14 | GENSIO_TCPD_OFF, 15 | }; 16 | 17 | #endif /* GENSIO_NET_H */ 18 | -------------------------------------------------------------------------------- /lib/libgensio.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensio 7 | Description: A library to abstract stream I/O like serial port, TCP, telnet, UDP, SSL, IPMI SOL, etc. 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensioosh -lgensio 10 | Libs.private: @BUILTIN_MDNS_LIBS@ @BASE_LIBS@ -------------------------------------------------------------------------------- /lib/libgensiomdns.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensiomdns 7 | Description: A gensiolibrary to abstract MDNS interfaces 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensiomdns -lgensioosh -lgensio 10 | Libs.private: @MDNS_LIBS@ 11 | -------------------------------------------------------------------------------- /lib/libgensioosh.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensioosh 7 | Description: OS handler library for gensio 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensioosh -lgensio 10 | Libs.private: @OSH_LIBS@ 11 | -------------------------------------------------------------------------------- /lib/seriallock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | void serial_rm_lock(struct gensio_os_funcs *o, struct gensio_ll *ll, 14 | bool do_uucp_lock, bool do_flock, 15 | int fd, const char *devname); 16 | 17 | /* Returns gensio errno. */ 18 | int serial_mk_lock(struct gensio_os_funcs *o, struct gensio_ll *ll, 19 | bool do_uucp_lock, bool do_flock, 20 | int fd, const char *devname); 21 | -------------------------------------------------------------------------------- /lib/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef UTILS 9 | #define UTILS 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #ifndef HAVE_STRCASECMP 17 | int strcasecmp(const char *s1, const char *s2); 18 | #endif 19 | #ifndef HAVE_STRNCASECMP 20 | int strncasecmp(const char *s1, const char *s2, int n); 21 | #endif 22 | 23 | struct enum_val 24 | { 25 | char *str; 26 | int val; 27 | }; 28 | 29 | #if ENABLE_PRBUF 30 | #include 31 | static void prbuf(const unsigned char *buf, unsigned int len) 32 | { 33 | unsigned int i; 34 | 35 | for (i = 0; i < len; i++) { 36 | if (i % 16 == 0) 37 | printf("\r\n"); 38 | printf(" %2.2x", buf[i]); 39 | } 40 | printf("\r\n"); 41 | fflush(stdout); 42 | } 43 | #endif 44 | 45 | #endif /* UTILS */ 46 | -------------------------------------------------------------------------------- /m4/ax_prog_python_version.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_prog_python_version.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PROG_PYTHON_VERSION([VERSION],[ACTION-IF-TRUE],[ACTION-IF-FALSE]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Makes sure that python supports the version indicated. If true the shell 12 | # commands in ACTION-IF-TRUE are executed. If not the shell commands in 13 | # ACTION-IF-FALSE are run. Note if $PYTHON is not set (for example by 14 | # running AC_CHECK_PROG or AC_PATH_PROG) the macro will fail. 15 | # 16 | # Example: 17 | # 18 | # AC_PATH_PROG([PYTHON],[python]) 19 | # AX_PROG_PYTHON_VERSION([2.4.4],[ ... ],[ ... ]) 20 | # 21 | # This will check to make sure that the python you have supports at least 22 | # version 2.4.4. 23 | # 24 | # NOTE: This macro uses the $PYTHON variable to perform the check. 25 | # AX_WITH_PYTHON can be used to set that variable prior to running this 26 | # macro. The $PYTHON_VERSION variable will be valorized with the detected 27 | # version. 28 | # 29 | # LICENSE 30 | # 31 | # Copyright (c) 2009 Francesco Salvestrini 32 | # 33 | # Copying and distribution of this file, with or without modification, are 34 | # permitted in any medium without royalty provided the copyright notice 35 | # and this notice are preserved. This file is offered as-is, without any 36 | # warranty. 37 | 38 | #serial 12 39 | 40 | AC_DEFUN([AX_PROG_PYTHON_VERSION],[ 41 | AC_REQUIRE([AC_PROG_SED]) 42 | AC_REQUIRE([AC_PROG_GREP]) 43 | 44 | AS_IF([test -n "$PYTHON"],[ 45 | ax_python_version="$1" 46 | 47 | AC_MSG_CHECKING([for python version]) 48 | changequote(<<,>>) 49 | python_version=`$PYTHON -V 2>&1 | $GREP "^Python " | $SED -e 's/^.* \([0-9]*\.[0-9]*\.[0-9]*\)/\1/'` 50 | changequote([,]) 51 | AC_MSG_RESULT($python_version) 52 | 53 | AC_SUBST([PYTHON_VERSION],[$python_version]) 54 | 55 | AX_COMPARE_VERSION([$ax_python_version],[le],[$python_version],[ 56 | : 57 | $2 58 | ],[ 59 | : 60 | $3 61 | ]) 62 | ],[ 63 | AC_MSG_WARN([could not find the python interpreter]) 64 | $3 65 | ]) 66 | ]) 67 | -------------------------------------------------------------------------------- /macos-entitle: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This sets the entitlements on the programs passed in so they can be 4 | # debugged and generate core dumps. 5 | # 6 | # To run this in a libtool environment, do: 7 | # 8 | # ./libtool execute ../macos-entitle 9 | 10 | ENTITLEMENTS=tmp.entitlements 11 | if [ ! -e "$ENTITLEMENTS" ]; then 12 | /usr/libexec/PlistBuddy -c \ 13 | "Add :com.apple.security.get-task-allow bool true" $ENTITLEMENTS 14 | /usr/libexec/PlistBuddy -c \ 15 | "Add :com.apple.security.cs.disable-library-validation bool true" $ENTITLEMENTS 16 | /usr/libexec/PlistBuddy -c \ 17 | "Add :com.apple.security.cs.allow-unsigned-executable-memory bool true" $ENTITLEMENTS 18 | /usr/libexec/PlistBuddy -c \ 19 | "Add :com.apple.security.get-task-allow bool true" $ENTITLEMENTS 20 | /usr/libexec/PlistBuddy -c \ 21 | "Add :com.apple.security.cs.allow-dyld-environment-variables bool true" $ENTITLEMENTS 22 | fi 23 | codesign -s - -f --entitlements "$ENTITLEMENTS" $* 24 | -------------------------------------------------------------------------------- /man/gensio_acc_accept_s.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_accept_s 3 "27 Jan 2020" 2 | .SH NAME 3 | gensio_acc_set_sync, gensio_acc_accept_s, gensio_acc_accept_s_intr 4 | \- Synchronous I/O operations on a gensio accepter 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B int gensio_acc_set_sync(struct gensio_accepter *acc); 9 | .TP 20 10 | .B int gensio_acc_accept_s(struct gensio_accepter *acc, 11 | .br 12 | .B struct gensio_time *timeout, 13 | .br 14 | .B struct gensio **new_io); 15 | .TP 20 16 | .B int gensio_acc_accept_s_intr(struct gensio_accepter *acc, 17 | .br 18 | .B struct gensio_time *timeout, 19 | .br 20 | .B struct gensio **new_io); 21 | .SH "DESCRIPTION" 22 | Normal gensio accepter operation is asynchronous callback based. This serves 23 | most programs fairly well, especially if they need to handle multiple accepts 24 | on the same or different accepters. 25 | 26 | But occasionally you need to do something synchronous with the program 27 | execution, especially if you have a simple program that just accepts 28 | one connection and then does something. 29 | 30 | .B gensio_acc set_sync 31 | sets up the gensio accepter for synchronous accepts. If you do this, 32 | the event callback that is currently registered will no longer receive 33 | new connection events. It *will* receive other callbacks. You must 34 | call this before starting up the gensio accepter, and once you call it 35 | the gensio accepter is in sync mode until you shut it down. 36 | 37 | .B gensio_accept_s 38 | Waits for an incoming connection on the gensio accepter. 39 | This function waits for the amount of time in 40 | .I timeout. 41 | .I timeout 42 | is updated to the amount of time left to wait. If 43 | .I timeout 44 | is NULL, wait forever. If no error is returned, the new incoming 45 | connection is returned in 46 | .I new_io. 47 | 48 | .B gensio_accept_s_intr 49 | is like 50 | .B gensio_accept_s, 51 | but it return immediately if an signal interrupt occurs. On systems 52 | without signals, this is the same as 53 | .B gensio_accept_s. 54 | .SH "RETURN VALUES" 55 | Zero is returned on success, or a gensio error on failure. 56 | .SH "SEE ALSO" 57 | gensio_err(3), gensio_set_sync(3), gensio(5) 58 | -------------------------------------------------------------------------------- /man/gensio_acc_control.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_control 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_acc_control \- Perform gensio accepter specific actions 4 | .SH SYNOPSIS 5 | .B #include 6 | .TP 20 7 | .B int gensio_acc_control(struct gensio_accepter *acc, int depth, 8 | .br 9 | .B bool get, unsigned int option, 10 | .br 11 | .B char *data, gensiods *datalen); 12 | .SH "DESCRIPTION" 13 | .B gensio_acc_control 14 | performs a gensio accepter specific operation on the gensio accepter. 15 | This works exactly like gensio_control(3), see that for details on get, 16 | depth, and how the data and datalen work. 17 | 18 | gensio control operations in 19 | .I option 20 | depend on the particular gensio. Below some are documented, but there 21 | may be other controls available. See the gensio documentation in 22 | gensio(5) for details. 23 | .SS "GENSIO_ACC_CONTROL_LADDR" 24 | Return the given local address for the given gensio. Since a single 25 | gensio may have more than one local address, this control provides a 26 | means to tell which one. The 27 | .I data 28 | string passed in should be the string representation of a the number (like 29 | created with snprintf()) for the particular index you want to fetch. If 30 | you specify a number larger than the number of open listen sockets, 31 | .I GE_NOTFOUND 32 | is returned. The return data is a string holding the address. 33 | 34 | Note that a single fetched string may contain more than one address. 35 | These will be separated by semicolons. In some cases addresses may 36 | change dynamically (like with SCTP), so you get a single set of 37 | addresses. 38 | .SS "GENSIO_ACC_CONTROL_LPORT" 39 | Return the port for the given local address for the given gensio. 40 | Since a single gensio may have more than one local address, this 41 | control provides a means to tell which one. The 42 | .I data 43 | string passed in should be the string representation of a the number (like 44 | created with snprintf()) for the particular index you want to fetch. If 45 | you specify a number larger than the number of open listen sockets, 46 | .I GE_NOTFOUND 47 | is returned. The return data is a string holding the port number. 48 | .SS "GENSIO_ACC_CONTROL_TCPDNAME" 49 | Get or set the TCPD name for the gensio, only for TCP gensios. 50 | 51 | .SH "RETURN VALUES" 52 | Zero is returned on success, or a gensio error on failure. 53 | .SH "SEE ALSO" 54 | gensio_err(3), gensio(5), gensio_control(3) 55 | -------------------------------------------------------------------------------- /man/gensio_acc_get_type.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_get_type 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_acc_get_type, gensio_acc_is_reliable, gensio_acc_is_packet, 4 | gensio_acc_is_message, gensio_acc_is_mux 5 | \- Return general information about a gensio accepter 6 | .SH SYNOPSIS 7 | .B #include 8 | .TP 20 9 | .B const char *gensio_acc_get_type(struct gensio *io, 10 | .br 11 | .B unsigned int depth); 12 | .TP 20 13 | .B bool gensio_acc_is_reliable(struct gensio *io); 14 | .TP 20 15 | .B bool gensio_acc_is_packet(struct gensio *io); 16 | .TP 20 17 | .B bool gensio_acc_is_mux(struct gensio *io); 18 | .SH "DESCRIPTION" 19 | .B gensio_acc_get_type 20 | return the type string for the gensio accepter (if 21 | .I depth 22 | is 0) or one of its children 23 | .I (depth > 0). 24 | Returns NULL if the depth is greater than the number of children. 25 | 26 | .B gensio_acc_is_reliable 27 | return true if the genios produce by this accepter are reliable. See 28 | gensio_is_reliable(3) for details. 29 | 30 | .B gensio_acc_is_packet 31 | returns if the genios produce by this accepter are packet-oriented. See 32 | gensio_is_packet(3) for details. 33 | 34 | .B gensio_acc_is_message 35 | returns if the genios produce by this accepter are message-oriented. See 36 | gensio_is_message(3) for details. 37 | 38 | .B gensio_acc_is_mux 39 | returns if the genios produced by this accepter are capable of 40 | multiplexing. See gensio_is_mux(3) for details. 41 | 42 | .SH "SEE ALSO" 43 | gensio_err(3), gensio(5), gensio_get_type(3), gensio_is_reliable(3), 44 | gensio_is_packet(3), gensio_is_message(3) 45 | -------------------------------------------------------------------------------- /man/gensio_acc_set_accept_callback_enable.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_set_accept_callback_enable 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_acc_set_accept_callback_enable, 4 | gensio_acc_set_accept_callback_enable_cb, 5 | gensio_acc_set_accept_callback_enable_s 6 | \- Enable or disable the accept ready callback 7 | .SH SYNOPSIS 8 | .B #include 9 | .TP 20 10 | .B void gensio_acc_set_accept_callback_enable( 11 | .br 12 | .B struct gensio_accepter *accepter, 13 | .br 14 | .B bool enabled); 15 | .TP 20 16 | .B int gensio_acc_set_accept_callback_enable_cb( 17 | .br 18 | .B struct gensio_accepter *accepter, 19 | .br 20 | bool enabled, 21 | .br 22 | gensio_acc_done done, 23 | .br 24 | void *done_data); 25 | .TP 20 26 | .B int gensio_acc_set_accept_callback_enable_s( 27 | .br 28 | .B struct gensio_accepter *accepter, 29 | .br 30 | bool enabled); 31 | .SH "DESCRIPTION" 32 | These functions enable/disable the accept callback when connections 33 | come in. 34 | 35 | .B gensio_acc_set_accept_callback_enable 36 | will do an asynchronous disable. Note that this can race with pending 37 | and running callbacks, you must be prepared to handle these races. 38 | 39 | .B gensio_acc_set_accept_callback_enable_cb 40 | is like the above, but do a callback when the enable is complete. 41 | Really only useful for disable, when the done callback is called then 42 | no more accepts will be called and all callbacks are done. Note that 43 | if you call this, you cannot do another enable/disable until done is 44 | called. 45 | 46 | .B gensio_acc_set_accept_callback_enable_s 47 | Like above, but a synchronous call. See the notes on gensio_open_s() 48 | for the dangers of using this function. 49 | .SH "RETURN VALUES" 50 | Zero is returned on success, or a gensio error on failure. 51 | .SH "SEE ALSO" 52 | gensio_err(3), gensio(5), gensio_open_s(3) 53 | -------------------------------------------------------------------------------- /man/gensio_acc_set_callback.3: -------------------------------------------------------------------------------- 1 | .TH gensio_accepter_set_callback 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_accepter_set_callback, gensio_accepter_get_user_data, 4 | gensio_accepter_set_user_data 5 | \- Set the event callback and user data for a gensio accepter 6 | .SH SYNOPSIS 7 | .B #include 8 | .TP 20 9 | .B void gensio_accepter_set_callback(struct gensio *io, 10 | .br 11 | .B gensio_accepter_event cb, void *user_data) 12 | .PP 13 | .TP 20 14 | .B void gensio_accepter_set_user_data(struct gensio *io, void *user_data); 15 | .PP 16 | .TP 20 17 | .B void *gensio_accepter_get_user_data(struct gensio *io) 18 | .SH "DESCRIPTION" 19 | .B gensio_accepter_set_callback 20 | sets the event handler and data for the gensio accepter. This 21 | function may be called again if the gensio accepter cannot generate 22 | any callbacks, generally after it has been shutdown. Otherwise race 23 | conditions may occur. 24 | 25 | .B gensio_accepter_set_user_data 26 | Just sets the user_data field in the gensio accepter. If this is 27 | called when the gensio is running, race conditions may occur. 28 | 29 | .B gensio_accepter_get_user_data 30 | Return the user data passed in with the gensio accepter was created or 31 | set by one of the above two functions. 32 | .SH "SEE ALSO" 33 | gensio(5), gensio_accepter_event(3) 34 | -------------------------------------------------------------------------------- /man/gensio_acc_shutdown.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_shutdown 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_acc_shutdown, gensio_acc_shutdown_s, gensio_acc_disable, gensio_acc_free 4 | \- Stop/free a gensio accepter that is started up 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B typedef void (*gensio_acc_done)(struct gensio_accepter *acc, 9 | .br 10 | void *cb_data); 11 | .TP 20 12 | .B int gensio_acc_shutdown(struct gensio_accepter *accepter, 13 | .br 14 | gensio_acc_done shutdown_done, 15 | .br 16 | void *shutdown_data); 17 | .br 18 | .TP 20 19 | .B int gensio_acc_shutdown_s(struct gensio_accepter *accepter); 20 | .TP 20 21 | .B void gensio_acc_disable(struct gensio_accepter *accepter); 22 | .TP 20 23 | .B void gensio_acc_free(struct gensio_accepter *accepter); 24 | .SH "DESCRIPTION" 25 | 26 | .B gensio_acc_shutdown 27 | Closes all sockets and disables everything in the gensio accepter. 28 | shutdown_done() will be called if successful after the shutdown is 29 | complete, if it is not NULL. Returns a GE_INUSE if the accepter is 30 | already shut down, zero otherwise. 31 | 32 | .B gensio_acc_shutdown_s 33 | shuts down the gensio and wait for the shutdown to finish. See the 34 | notes in gensio_close_s(3) for warning on using this. 35 | 36 | .B gensio_acc_disable 37 | is like gensio_disable(3), but for accepters. See gensio_disable(3) for 38 | details. 39 | 40 | .B gensio_acc_free 41 | frees the network accepter. If the network accepter is started 42 | up, this shuts it down first and shutdown_done() is NOT called. 43 | .SH "RETURN VALUES" 44 | Zero is returned on success, or a gensio error on failure. 45 | .SH "SEE ALSO" 46 | gensio_err(3), gensio(5) 47 | -------------------------------------------------------------------------------- /man/gensio_acc_startup.3: -------------------------------------------------------------------------------- 1 | .TH gensio_acc_startup 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_acc_startup \- Start a gensio accepter 4 | .SH SYNOPSIS 5 | .B #include 6 | .TP 20 7 | .B int gensio_acc_startup(struct gensio_accepter *acc); 8 | .SH "DESCRIPTION" 9 | .B gensio_acc_startup 10 | starts the gensio accepter. A gensio accepter is started not running, 11 | you must call this to start it up. 12 | 13 | Unlike 14 | .B gensio_open 15 | this also enables events from the gensio accepter. 16 | .SH "RETURN VALUES" 17 | Zero is returned on success, or a gensio error on failure. 18 | .SH "SEE ALSO" 19 | gensio_err(3), gensio(5), gensio_open(3) 20 | -------------------------------------------------------------------------------- /man/gensio_alloc_channel.3: -------------------------------------------------------------------------------- 1 | .TH gensio_alloc_channel 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_alloc_channel \- Create a new channel on a 4 | channel-capable gensio 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B int gensio_alloc_channel(struct gensio *io, const char * const args[], 9 | .br 10 | .B gensio_event cb, void *user_data, 11 | .br 12 | .B struct gensio **new_io); 13 | .SH "DESCRIPTION" 14 | .B gensio_alloc_channel 15 | creates a new channel on a channel-capable gensio. The exact meaning 16 | of channel, and the meaning of 17 | .I args 18 | depends on the particular gensio, see the the particular gensio class 19 | in gensio(5). The new gensio created will be closed and you must 20 | call 21 | .B gensio_open 22 | on it to start it up. 23 | .SH "RETURN VALUES" 24 | Zero is returned on success, or a gensio error on failure. 25 | .SH "SEE ALSO" 26 | gensio_err(3), gensio(5), gensio_os_funcs(3), gensio_event(3), gensio_open(3) 27 | -------------------------------------------------------------------------------- /man/gensio_bswap.3: -------------------------------------------------------------------------------- 1 | .TH gensio_bswap 3 "04 Jan 2025" 2 | .SH NAME 3 | gensio_bswap_16, gensio_bswap_32, gensio_bswap_64, GENSIO_IS_BIG_ENDIAN, 4 | GENSIO_IS_LITTLE_ENDIAN, gensio_bswap_16_from_be, gensio_bswap_32_from_be, 5 | gensio_bswap_64_from_be, gensio_bswap_16_to_be, gensio_bswap_32_to_be, 6 | gensio_bswap_64_to_be, gensio_bswap_16_from_le, gensio_bswap_32_from_le, 7 | gensio_bswap_64_from_le, gensio_bswap_16_to_le, gensio_bswap_32_to_le, 8 | gensio_bswap_64_to_le 9 | \- Byte swapping routines. 10 | .SH "SYNOPSIS" 11 | .B #include 12 | .TP 20 13 | .B uint[16|32|64]_t gensio_bswap_[16|32|64](v) 14 | .TP 20 15 | .B uint[16|32|64]_t gensio_bswap_[16|32|64]_[from|to]_[be|le](v) 16 | .SH "DESCRIPTION" 17 | These routine perform normal byte swapping operations in 16, 32, and 18 | 64-bit values. The 19 | .B gensio_bswap_[16|32|64]() 20 | perform an unconditional byte swap. The 21 | .B gensio_bswap_[16|32|64]_[from|to]_[be|le] 22 | will byte swap from/to the given endianness depending on the host 23 | platforms endianness. 24 | 25 | .B GENSIO_IS_BIG_ENDIAN 26 | and 27 | .B GENSIO_IS_LITTLE_ENDIAN 28 | will be true or false depending on the host endian's endianness. 29 | .SH "RETURN VALUES" 30 | The integer, byte swapped, will be returned. 31 | .SH "SEE ALSO" 32 | gensio(5) 33 | -------------------------------------------------------------------------------- /man/gensio_close.3: -------------------------------------------------------------------------------- 1 | .TH gensio_close 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_close, gensio_close_s, gensio_disable, gensio_free 4 | \- Stop/free a gensio that is open 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B typedef void (*gensio_done)(struct gensio *io, void *close_data); 9 | .TP 20 10 | .B int gensio_close(struct gensio *io, gensio_done close_done, 11 | .br 12 | .B void *close_data); 13 | .TP 20 14 | int gensio_close_s(struct gensio *io); 15 | .TP 20 16 | void gensio_disable(struct gensio *io); 17 | .TP 20 18 | void gensio_free(struct gensio *io); 19 | .PP 20 | .B gensio_close 21 | closes an open gensio. Note that the close operation is not complete 22 | until close_done() is called. This shuts down internal file 23 | descriptors and such, but does not free the gensio. If the gensio is 24 | a connecting one, you can generally re-open it. If you 25 | .B gensio_close 26 | before an open done is reported, the results (primarily whether the 27 | open done is called) are undefined. If the open done is called, it 28 | will be called before the close done. 29 | 30 | .B gensio_close_s 31 | is like gensio_close, but blocks until the operation is complete. 32 | .B BE VERY CAREFUL WITH THIS FUNCTION. 33 | Do not call it from a callback because it waits until all operations 34 | on the gensio are done, and they won't be done until the callback 35 | returns. You will deadlock if you do this. 36 | 37 | .B gensio_disable 38 | disables operation of the gensio so that closing will not result in 39 | any data being transmitted. 40 | .B THIS IS FOR EXTREMELY LIMITED USE. 41 | This will not close file descriptors nor disable I/O, necessarily, but 42 | will put the gensio stack into a state where freeing will not result 43 | in any transmission of data to the other end. You 44 | .B MUST 45 | be in a state where no callbacks are running or can run. This is 46 | primarily to allow a close of something like an SSL connection after a 47 | fork. If you didn't have this, the normal close in the one fork would 48 | shut down the SSL connection for the other fork, too. See gensio(5) 49 | for details on forking. 50 | 51 | .B gensio_free 52 | frees data associated with the gensio. If it is open, the gensio is 53 | closed. If you call 54 | .B gensio_free 55 | after 56 | .B gensio_close 57 | before the 58 | .B close_done 59 | callback is called, whether 60 | .B close_done 61 | is called is undefined. 62 | .SH "RETURN VALUES" 63 | Zero is returned on success, or a gensio error on failure. 64 | .SH "SEE ALSO" 65 | gensio_err(3), gensio(5) 66 | -------------------------------------------------------------------------------- /man/gensio_open.3: -------------------------------------------------------------------------------- 1 | .TH gensio_open 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_open, gensio_open_s, gensio_open_nochild, gensio_open_nochild_s 4 | \- Start a connecting gensio 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B typedef void (*gensio_done_err)(struct gensio *io, int err, 9 | .br 10 | .B void *open_data); 11 | .TP 20 12 | .B int gensio_open(struct gensio *io, gensio_done_err open_done, 13 | .br 14 | .B void *open_data); 15 | .TP 20 16 | .B int gensio_open_s(struct gensio *io); 17 | .TP 20 18 | .B int gensio_open_nochild(struct gensio *io, gensio_done_err open_done, 19 | .br 20 | .B void *open_data); 21 | .TP 20 22 | int gensio_open_nochild_s(struct gensio *io); 23 | .SH "DESCRIPTION" 24 | .B gensio_open 25 | starts the gensio. gensios received from an accepter are 26 | open upon receipt, but connecting gensios are started closed and need 27 | to be opened before use. If no error is returned, the 28 | .I open_done 29 | callback will be called, if there is no error in the callback 30 | .I err 31 | value the gensio will be open. This will open all children, too. 32 | 33 | Note that the 34 | .B open_done 35 | callback will always be called even if you close the gensio before the 36 | .B open_done 37 | callback happens or if an error occurs. This is guaranteed. 38 | 39 | .B gensio_open_s 40 | is like 41 | .B gensio_open, but waits for the open to complete. Normal gensio 42 | processing will happen while waiting. Note that you must be careful 43 | to not call this from a callback, you should only call this from a 44 | non-callback thread or a runner (see gensio_os_funcs(3) for details on 45 | runners). 46 | 47 | .B gensio_open_nochild 48 | is like 49 | .B gensio_open, 50 | but assumes any child gensios are already open and just opens this 51 | gensio. This can be useful if you have a gensio that is already 52 | opened (like you received it from an accepter) and you want to stack 53 | another gensio on top of it. Only filter gensios will support this. 54 | 55 | .B gensio_open_nochild_s 56 | is like 57 | .B gensio_open_nochild, 58 | but waits for the open to complete. See the notes on 59 | .B gensio_open_s 60 | above for warnings. 61 | .SH "RETURN VALUES" 62 | Zero is returned on success, or a gensio error on failure. 63 | .SH "SEE ALSO" 64 | gensio_err(3), gensio(5), gensio_os_funcs(3) 65 | -------------------------------------------------------------------------------- /man/gensio_refcount.3: -------------------------------------------------------------------------------- 1 | .TH gensio_refcount 3 "04 Jan 2025" 2 | .SH NAME 3 | gensio_refcount_init, gensio_refcount_cleanup, gensio_refcount_set, 4 | gensio_refcount_get, gensio_refcount_inc, gensio_refcount_dec 5 | gensio_refcount_inc_if_nz, gensio_refcount_dec_if_nz 6 | \- Refcount operations. 7 | .SH "SYNOPSIS" 8 | .B #include 9 | .br 10 | typedef xxx gensio_refcount; 11 | .br 12 | .TP 20 13 | .B int gensio_refcount_init(o, a, v) 14 | .TP 20 15 | .B void gensio_refcount_cleanup(a) 16 | .TP 20 17 | .B void gensio_refcount_set(a, v) 18 | .TP 20 19 | .B unsigned int gensio_refcount_get(a) 20 | .TP 20 21 | .B void gensio_refcount_inc(a) 22 | .TP 20 23 | .B unsigned int gensio_refcount_dec(a) 24 | .TP 20 25 | .B bool gensio_refcount_inc_if_nz(a) 26 | .TP 20 27 | .B bool gensio_refcount_dec_if_nz(a) 28 | .SH "DESCRIPTION" 29 | An atomic refcount. 30 | 31 | You should call 32 | .B gensio_refcount_init() 33 | to initialize the value. The 34 | .B o 35 | value is a gensio_os_funcs struct. This may allocate locks and such, 36 | so you should check the return value of the init function. Once done 37 | with the refcount, you should call 38 | .B gensio_refcount_cleanup(). 39 | 40 | These work like normal atomic refcounts. The operations ending in 41 | .B if_nz 42 | will only perform the operation if the value was not already zero. 43 | .SH "CAVEATS" 44 | Currently these are only implemented on processors that can do this 45 | natively. A non-native implementation with locks could be done, 46 | though. 47 | .SH "RETURN VALUES" 48 | .B gensio_refcount_get() 49 | returns the current value. 50 | 51 | .B gensio_refcount_dec() 52 | returns the new value. 53 | 54 | .B gensio_refcount_dec_if_nz 55 | and 56 | .B gensio_refcount_inc_if_nz 57 | return true if the operation happens, false if not. 58 | 59 | All other functions/macros do not return values. 60 | .SH "SEE ALSO" 61 | gensio(5), gensio_atomics(3) 62 | -------------------------------------------------------------------------------- /man/gensio_set_callback.3: -------------------------------------------------------------------------------- 1 | .TH gensio_set_callback 3 "23 Feb 2019" 2 | .SH NAME 3 | gensio_set_callback, gensio_get_user_data, gensio_set_user_data 4 | \- Set the event callback and user data for a gensio 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B void gensio_set_callback(struct gensio *io, 9 | .br 10 | .B gensio_event cb, void *user_data) 11 | .PP 12 | .TP 20 13 | .B void gensio_set_user_data(struct gensio *io, void *user_data); 14 | .PP 15 | .TP 20 16 | .B void *gensio_get_user_data(struct gensio *io) 17 | .SH "DESCRIPTION" 18 | .B gensio_set_callback 19 | sets the event handler and data for the gensio. This must be done in the 20 | .B GENSIO_ACC_EVENT_NEW_CONNECTION 21 | event from a 22 | .B gensio_accepter 23 | before any other operation is done on the gensio. 24 | The only exception is that 25 | .B gensio_close 26 | may 27 | be called with callbacks not set. This function may be called 28 | again if the gensio cannot generate any callbacks, generally 29 | after it has been closed. Otherwise race conditions may occur. 30 | 31 | .B gensio_set_user_data 32 | Just sets the user_data field in the gensio. If this is called when 33 | the gensio is running, race conditions may occur. 34 | 35 | .B gensio_get_user_data 36 | Return the user data passed in with the gensio was created or set 37 | by one of the above two functions. 38 | .SH "SEE ALSO" 39 | gensio(5), gensio_event(3), gensio_accepter_event(3) 40 | -------------------------------------------------------------------------------- /man/gensio_set_log_mask.3: -------------------------------------------------------------------------------- 1 | .TH gensio_set_log_mask 3 "23 Feb 2019" 2 | .SH NAME 3 | gensio_set_log_mask, gensio_get_log_mask, gensio_log_level_to_str, 4 | \- Logging and seting which gensio logs are passed or ignored 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B void gensio_set_log_mask(unsigned int mask); 9 | .PP 10 | .TP 20 11 | .B unsigned int gensio_get_log_mask(void); 12 | .PP 13 | .TP 20 14 | .B const char *gensio_log_level_to_str(enum gensio_log_levels level); 15 | .PP 16 | .TP 20 17 | .B void gensio_vlog(struct gensio_os_funcs *o, 18 | .br 19 | .B enum gensio_log_levels level, 20 | .br 21 | .B const char *str, va_list args); 22 | .PP 23 | .TP 20 24 | .B void gensio_log(struct gensio_os_funcs *o, 25 | .br 26 | .B enum gensio_log_levels level, 27 | .br 28 | .B const char *str, ...); 29 | .SH "DESCRIPTION" 30 | The log mask is a global variable in the gensio library that sets what 31 | level of logs are delivered through the vlog function pointer in 32 | .B gensio_os_funcs. 33 | Log levels are: 34 | 35 | .IP 36 | GENSIO_LOG_FATAL 37 | GENSIO_LOG_ERR 38 | GENSIO_LOG_WARNING 39 | GENSIO_LOG_INFO 40 | GENSIO_LOG_DEBUG 41 | .PP 42 | 43 | with obvious meanings. There is also: 44 | 45 | .IP 46 | GENSIO_LOG_MASK_ALL 47 | .PP 48 | 49 | which is a bitmask of all the log levels. 50 | 51 | The default log mask is 52 | .B (1 << GENSIO_LOG_FATAL | 1 << GENSIO_LOG_ERR). 53 | Setting other log values can be helpful in debugging problems with gensios. 54 | 55 | .B gensio_log_level_to_str 56 | converts a log level to a string representation of that level. 57 | 58 | .B gensio_vlog 59 | and 60 | .B gensio_log 61 | are the functions used to generate logs. These are primarily for use 62 | in the gensio library, though you may use them, too, if you like. 63 | .SH "SEE ALSO" 64 | gensio(5), gensio_os_funcs(3) 65 | -------------------------------------------------------------------------------- /man/gensio_set_read_callback_enable.3: -------------------------------------------------------------------------------- 1 | .TH gensio_set_read_callback_enable 3 "27 Feb 2019" 2 | .SH NAME 3 | gensio_set_read_callback_enable, gensio_set_write_callback_enable 4 | \- Enable or disable read data and write ready 5 | .SH SYNOPSIS 6 | .B #include 7 | .TP 20 8 | .B void gensio_set_read_callback_enable(struct gensio *io, 9 | .br 10 | .B bool enabled); 11 | .TP 20 12 | .B void gensio_set_write_callback_enable(struct gensio *io, 13 | .br 14 | .B bool enabled); 15 | .SH "DESCRIPTION" 16 | These function enable the write callback, or the read callback, for 17 | gensios (and all child gensios). Generally disabling the read 18 | callback will disable all callbacks except write because it won't 19 | receive any data to do any processing. 20 | 21 | After you open a gensio or receive a gensio from an accepter, the 22 | gensio has all the enables set to false. You would generally want to 23 | enable the read callback and leave it enabled as much as possible so 24 | that low-level processing will happen on the gensio. In particular, 25 | disabling read on a UDP gensio will disable all read an accept 26 | processing. 27 | 28 | Enabling the write callback will enable the callback to tell you if 29 | the gensio can currently write any data. You normally want to leave 30 | this disabled and enable it if you write data and get a partial write. 31 | Or even better, when you have data to write, enable the write callback 32 | and write the data from the callback, disabling when it is all 33 | written. 34 | 35 | Disabling the write callback does not necessarily keep data from being 36 | transmitted by the gensio. The SSL gensio, for instance, may transmit 37 | key information on a rekey, or other gensios may transmit flow-control 38 | information. This only affects the write callback. 39 | 40 | Disabling the callbacks may not be immediate. "Immediate" is hard to 41 | define in a SMP system, anyway. There may be callbacks running or 42 | about to be called when you disable the callback, they may still run. 43 | You must be prepared to handle these race conditions. 44 | .SH "RETURN VALUES" 45 | Zero is returned on success, or a gensio error on failure. 46 | .SH "SEE ALSO" 47 | gensio_err(3), gensio(5) 48 | -------------------------------------------------------------------------------- /man/gensio_write.3: -------------------------------------------------------------------------------- 1 | .TH gensio_write 3 "24 Feb 2019" 2 | .SH NAME 3 | gensio_write \- Write data to a gensio 4 | .SH SYNOPSIS 5 | .B #include 6 | .TP 20 7 | .B int gensio_write(struct gensio *io, gensiods *count, 8 | .br 9 | .B const void *buf, gensiods buflen, 10 | .br 11 | .B const char *const *auxdata); 12 | .PP 13 | .B struct gensio_sg { 14 | .RS 4 15 | .B const void *buf; 16 | .br 17 | .B gensiods buflen; 18 | .RE 19 | .B }; 20 | .TP 20 21 | .B int gensio_write_sg(struct gensio *io, gensiods *count, 22 | .br 23 | .B const struct gensio_sg *sg, gensiods sglen, 24 | .br 25 | .B const char *const *auxdata); 26 | .SH "DESCRIPTION" 27 | Write data to the given gensio. The data is in 28 | .I buf 29 | and the length of 30 | the data is in 31 | .I buflen. 32 | Note that 33 | .B gensio_write 34 | may not write all of the data given, depending on the gensio type and 35 | the internal buffer space. It will return the number of bytes actually 36 | written in 37 | .B count 38 | which may be NULL if you don't care. (Hint: you should almost always 39 | care.) 40 | 41 | If 42 | .B gensio_write 43 | is unable to write the full amount of data, you should generally buffer 44 | the unwritten data and call 45 | .B gensio_set_write_callback_enable(3) 46 | to know when you can write the rest of the data. Many applications 47 | always buffer the data and enable the write callback to do the write 48 | and then disable the write callback when all data is written, for 49 | consistency. 50 | 51 | .B gensio_write 52 | will never block, if it cannot write all the data it will write what 53 | it can and return. 54 | 55 | .B auxdata 56 | is used to pass in gensio specific auxiliary data, such as the stream 57 | number for SCTP or whether the data is out of band data for SCTP or 58 | TCP. 59 | 60 | .B gensio_write_sg 61 | is like 62 | .B gensio_write, 63 | but it takes a scatter-gather structure to allow you to combine multiple 64 | chunks of data without copying. Note that if you get a partial write, 65 | you must figure out where the write ended in your scatter-gather list 66 | and start the next write from there. 67 | .SH "RETURN VALUES" 68 | Zero is returned on success, or a gensio error on failure. 69 | .SH "SEE ALSO" 70 | gensio_err(3), gensio(5) 71 | -------------------------------------------------------------------------------- /reconf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # If you get this code and you don't have a configure, you can run this 4 | # script to create the build infrastructure. 5 | 6 | case `uname` in 7 | Darwin*) glibtoolize ;; 8 | *) libtoolize ;; 9 | esac 10 | aclocal 11 | autoconf 12 | autoheader 13 | automake -a 14 | -------------------------------------------------------------------------------- /swig/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = gensio.i 3 | 4 | SUBDIRS = . $(PYTHON_DIR) include 5 | DIST_SUBDIRS = python include 6 | -------------------------------------------------------------------------------- /swig/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | -------------------------------------------------------------------------------- /swig/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = gensio_swig.h gensio_swig.i 3 | -------------------------------------------------------------------------------- /swig/include/gensio/gensio_swig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * This is for writing os handlers to integrate with the gensio 10 | * swig-generated code. It's designed to be included in swig code, 11 | * it's not stand-alone. 12 | */ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #ifdef SWIGPYTHON 21 | typedef PyObject swig_cb; 22 | #endif 23 | 24 | GENSIO_DLL_PUBLIC 25 | int gensio_swig_setup_os_funcs(struct gensio_os_funcs *o, 26 | swig_cb *log_handler); 27 | 28 | GENSIO_DLL_PUBLIC 29 | void check_os_funcs_free(struct gensio_os_funcs *o); 30 | 31 | GENSIO_DLL_PUBLIC 32 | int get_os_funcs_refcount(struct gensio_os_funcs *o); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /swig/include/gensio/gensio_swig.i: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifdef SWIGPYTHON 9 | %typemap(in) swig_cb * { 10 | if ($input == Py_None) 11 | $1 = NULL; 12 | else 13 | $1 = $input; 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /swig/python/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | gensio.py 3 | gensio_wrap.c 4 | -------------------------------------------------------------------------------- /swig/python/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = $(PYTHON_CPPFLAGS) \ 3 | -I$(top_srcdir)/include \ 4 | -I$(top_builddir)/include \ 5 | -I$(top_srcdir) -I$(top_srcdir)/swig/include \ 6 | -DPYTHON_HAS_THREADS=@PYTHON_HAS_THREADS@ 7 | 8 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 9 | pythonlib_LTLIBRARIES = _gensio.la 10 | 11 | lib_LTLIBRARIES = libgensio_python_swig.la 12 | 13 | libgensio_python_swig_la_SOURCES = gensio_python_swig.c 14 | libgensio_python_swig_la_CFLAGS = -DBUILDING_GENSIO_DLL $(AM_CFLAGS) 15 | libgensio_python_swig_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 16 | -version-info $(GENSIO_LIB_VERSION) 17 | libgensio_python_swig_la_LIBADD = \ 18 | $(top_builddir)/lib/libgensio.la \ 19 | $(top_builddir)/lib/libgensioosh.la \ 20 | $(top_builddir)/lib/libgensiomdns.la \ 21 | $(PYTHON_LIBS) 22 | 23 | noinst_HEADERS = gensio_python.h python_swig_internals.h 24 | 25 | gensio_wrap.c gensio.py: $(top_srcdir)/swig/gensio.i \ 26 | $(top_srcdir)/swig/python/gensio_python.h \ 27 | $(top_srcdir)/swig/python/gensio_langinfo.i 28 | $(SWIG) $(DEFS) -python $(PYTHON_SWIG_FLAGS) -o gensio_wrap.c \ 29 | -I$(top_srcdir)/swig/python -I$(top_srcdir)/include \ 30 | -I$(top_builddir)/include -I$(top_srcdir)/swig/include \ 31 | $(top_srcdir)/swig/gensio.i 32 | 33 | EXTRA_DIST = gensio_langinfo.i libgensio_python_swig.pc.in 34 | 35 | pkgconfigexecdir = $(libdir)/pkgconfig 36 | pkgconfigexec_DATA = libgensio_python_swig.pc 37 | 38 | nodist__gensio_la_SOURCES = gensio_wrap.c 39 | _gensio_la_LIBADD = $(top_builddir)/lib/libgensio.la \ 40 | $(top_builddir)/lib/libgensiomdns.la \ 41 | $(PYTHON_UNDEF_LIBS) libgensio_python_swig.la \ 42 | $(top_builddir)/lib/libgensio.la \ 43 | $(top_builddir)/lib/libgensioosh.la \ 44 | $(top_builddir)/lib/libgensiomdns.la 45 | _gensio_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 46 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 47 | 48 | clean-local: 49 | rm -rf __pycache__ gensio_wrap.c gensio.py 50 | 51 | install-exec-local: _gensio.la gensio.py 52 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 53 | $(INSTALL_DATA) gensio.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 54 | 55 | uninstall-local: 56 | $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_gensio.$(PYTHON_EXT_EXT)" 57 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/gensio.py" 58 | -------------------------------------------------------------------------------- /swig/python/libgensio_python_swig.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libpython_swig_handlers 7 | Description: A library to abstract stream I/O like serial port, TCP, telnet, UDP, SSL, IPMI SOL, etc. 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lpython_swig_handlers -lgensio 10 | -------------------------------------------------------------------------------- /swig/python/python_swig_internals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | /* 9 | * Things I had to split out into their own library so that other os 10 | * handlers could get to the functions they need to interact with 11 | * python. 12 | * 13 | * This is not a general purpose header, it is designed to be included 14 | * only in certain places. 15 | */ 16 | 17 | typedef PyObject swig_cb_val; 18 | 19 | #if PYTHON_HAS_THREADS 20 | #ifdef _WIN32 21 | #include 22 | #define USE_WIN32_THREADS 23 | #else 24 | #include 25 | #define USE_POSIX_THREADS 26 | #endif 27 | #endif 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | struct os_funcs_data { 34 | #ifdef USE_POSIX_THREADS 35 | pthread_mutex_t lock; 36 | #endif 37 | unsigned int refcount; 38 | swig_cb_val *log_handler; 39 | }; 40 | 41 | #define OI_PY_STATE PyGILState_STATE 42 | #define OI_PY_STATE_GET() PyGILState_Ensure() 43 | #define OI_PY_STATE_PUT(s) PyGILState_Release(s) 44 | 45 | GENSIO_DLL_PUBLIC 46 | swig_cb_val *gensio_python_ref_swig_cb_i(swig_cb *cb); 47 | 48 | GENSIO_DLL_PUBLIC 49 | swig_cb_val *gensio_python_deref_swig_cb_val(swig_cb_val *cb); 50 | 51 | #if PY_VERSION_HEX >= 0x03000000 52 | #define OI_PI_FromString PyUnicode_FromString 53 | #define OI_PI_AsString PyUnicode_AsUTF8 54 | #else 55 | #define OI_PI_FromString PyString_FromString 56 | #define OI_PI_AsString PyString_AsString 57 | #endif 58 | 59 | GENSIO_DLL_PUBLIC 60 | PyObject *swig_finish_call_rv(swig_cb_val *cb, const char *method_name, 61 | PyObject *args, bool optional); 62 | 63 | GENSIO_DLL_PUBLIC 64 | extern void (*swig_waiter_wake)(void); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /tcl/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -DBUILDING_GENSIOTCL_DLL 3 | AM_CFLAGS = -I$(top_srcdir)/tcl/include @EXTRA_CFLAGS@ 4 | 5 | lib_LTLIBRARIES = libgensiotcl.la 6 | 7 | libgensiotcl_la_SOURCES = gensio_tcl.c 8 | libgensiotcl_la_CFLAGS = $(TCL_CFLAGS) $(AM_CFLAGS) 9 | libgensiotcl_la_LIBADD = $(top_builddir)/lib/libgensio.la \ 10 | $(top_builddir)/lib/libgensioosh.la \ 11 | @TCL_LIBS@ 12 | libgensiotcl_la_LDFLAGS = -no-undefined -rpath $(libdir) \ 13 | -version-info $(GENSIO_LIB_VERSION) -fvisibility=hidden 14 | 15 | SUBDIRS = . $(SWIG_DIR) include $(CPLUSPLUS_DIR) 16 | DIST_SUBDIRS = swig include c++ 17 | 18 | # This variable must have 'exec' in its name, in order to be installed 19 | # by 'install-exec' target (instead of default 'install-data') 20 | pkgconfigexecdir = $(libdir)/pkgconfig 21 | pkgconfigexec_DATA = libgensiotcl.pc 22 | 23 | if INSTALL_DOC 24 | man3_MANS = gensio_tcl_funcs_alloc.3 25 | endif 26 | 27 | EXTRA_DIST = libgensiotcl.pc.in $(man3_MANS) 28 | -------------------------------------------------------------------------------- /tcl/c++/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = include tests $(SWIG_DIR) 3 | 4 | DIST_SUBDIRS = include tests swig 5 | -------------------------------------------------------------------------------- /tcl/c++/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | 4 | DIST_SUBDIRS = gensio 5 | -------------------------------------------------------------------------------- /tcl/c++/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = gensiotcl 2 | -------------------------------------------------------------------------------- /tcl/c++/include/gensio/gensiotcl: -------------------------------------------------------------------------------- 1 | // 2 | // gensio - A library for abstracting stream I/O 3 | // Copyright (C) 2022 Corey Minyard 4 | // 5 | // SPDX-License-Identifier: LGPL-2.1-only 6 | 7 | // This is a C++ wrapper for the gensio library. 8 | 9 | #ifndef GENSIOGLIB_CPP_INCLUDE 10 | #define GENSIOGLIB_CPP_INCLUDE 11 | 12 | #include 13 | 14 | namespace gensios { 15 | #include 16 | 17 | class Tcl_Os_Funcs: public Os_Funcs { 18 | public: 19 | Tcl_Os_Funcs(Os_Funcs_Log_Handler *logger = NULL) : Os_Funcs(true) 20 | { 21 | struct gensio_os_funcs *o; 22 | 23 | int err = gensio_tcl_funcs_alloc(&o); 24 | if (err) 25 | throw gensio_error(err); 26 | init(o, logger); 27 | } 28 | }; 29 | } 30 | 31 | #endif /* GENSIOGLIB_CPP_INCLUDE */ 32 | -------------------------------------------------------------------------------- /tcl/c++/swig/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = . $(PYGENSIO_DIR) 3 | 4 | DIST_SUBDIRS = pygensio 5 | -------------------------------------------------------------------------------- /tcl/c++/swig/pygensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = $(PYTHON_CPPFLAGS) \ 3 | -I$(top_srcdir)/tcl/c++/include -I$(top_srcdir)/tcl/include \ 4 | -I$(top_srcdir)/c++/swig/pygensio/include 5 | 6 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 7 | pythonlib_LTLIBRARIES = _pygensiotcl.la 8 | 9 | pygensiotcl_wrap.cc pygensiotcl.py: \ 10 | $(top_srcdir)/c++/swig/include/gensio_base.i \ 11 | $(top_srcdir)/c++/swig/pygensio/pygensio.i \ 12 | $(top_srcdir)/tcl/c++/swig/pygensio/pygensiotcl.i \ 13 | $(top_srcdir)/c++/include/gensio 14 | $(SWIG) $(DEFS) -Wall -python $(PYTHON_SWIG_FLAGS) \ 15 | -o pygensiotcl_wrap.cc -c++ \ 16 | -I$(top_srcdir)/tcl/c++/include \ 17 | -I$(top_srcdir)/c++/swig/include \ 18 | -I$(top_srcdir)/c++/swig/pygensio -I$(top_srcdir)/c++/include \ 19 | -I$(top_srcdir)/include -I$(top_builddir)/include \ 20 | $(top_srcdir)/tcl/c++/swig/pygensio/pygensiotcl.i 21 | 22 | EXTRA_DIST = pygensiotcl.i 23 | 24 | nodist__pygensiotcl_la_SOURCES = pygensiotcl_wrap.cc 25 | _pygensiotcl_la_LIBADD = $(top_builddir)/c++/lib/libgensiocpp.la \ 26 | $(top_builddir)/lib/libgensio.la \ 27 | $(top_builddir)/lib/libgensioosh.la \ 28 | $(top_builddir)/tcl/libgensiotcl.la \ 29 | $(OPENSSL_LIBS) $(PYTHON_UNDEF_LIBS) $(TCL_LIBS) 30 | _pygensiotcl_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 31 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 32 | 33 | clean-local: 34 | rm -rf __pycache__ pygensiotcl_wrap.cc pygensiotcl_wrap.h \ 35 | pygensiotcl.py 36 | 37 | install-exec-local: _pygensiotcl.la pygensiotcl.py 38 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 39 | $(INSTALL_DATA) pygensiotcl.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 40 | 41 | uninstall-local: 42 | $(LIBTOOL) --mode=uninstall \ 43 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_pygensiotcl.$(PYTHON_EXT_EXT)" 44 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/pygensiotcl.py" 45 | -------------------------------------------------------------------------------- /tcl/c++/swig/pygensio/pygensiotcl.i: -------------------------------------------------------------------------------- 1 | %module pygensiotcl; 2 | 3 | %{ 4 | #include 5 | #include 6 | using namespace gensios; 7 | %} 8 | 9 | %import 10 | 11 | %extend gensios::Tcl_Os_Funcs { 12 | Tcl_Os_Funcs(gensios::Os_Funcs_Log_Handler *logger = NULL) 13 | { 14 | gensios::Os_Funcs_Log_Handler *int_handler = NULL; 15 | if (logger) 16 | int_handler = new Internal_Log_Handler(logger); 17 | return new gensios::Tcl_Os_Funcs(int_handler); 18 | } 19 | 20 | ~Tcl_Os_Funcs() 21 | { 22 | delete self; 23 | } 24 | } 25 | 26 | %ignore gensios::Tcl_Os_Funcs::Tcl_Os_Funcs; 27 | %ignore gensios::Tcl_Os_Funcs::~Tcl_Os_Funcs; 28 | 29 | %include 30 | -------------------------------------------------------------------------------- /tcl/c++/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir)/c++/include -I$(top_srcdir)/tcl/c++/include \ 3 | -I$(top_srcdir)/tcl/include 4 | 5 | TESTS = basic_tcl_test 6 | 7 | basic_tcl_test_SOURCES = basic_tcl_test.cc 8 | 9 | basic_tcl_test_LDADD = $(top_builddir)/lib/libgensio.la \ 10 | $(top_builddir)/c++/lib/libgensiocpp.la \ 11 | $(top_builddir)/c++/lib/libgensiooshcpp.la \ 12 | $(top_builddir)/lib/libgensio.la \ 13 | $(top_builddir)/lib/libgensioosh.la \ 14 | $(top_builddir)/tcl/libgensiotcl.la \ 15 | $(TCL_LIBS) $(OPENSSL_LIBS) 16 | 17 | check_PROGRAMS = basic_tcl_test 18 | -------------------------------------------------------------------------------- /tcl/gensio_tcl_funcs_alloc.3: -------------------------------------------------------------------------------- 1 | .TH gensio_tcl_funcs_alloc 3 "03 Feb 2021" 2 | .SH NAME 3 | gensio_tcl_funcs_alloc \- Abstraction for some operating system functions 4 | done with tcl 5 | .SH SYNOPSIS 6 | .B #include 7 | .PP 8 | .B int gensio_tcl_funcs_alloc(struct gensio_os_funcs **o) 9 | .SH "DESCRIPTION" 10 | This structure provides an abstraction for the gensio library that 11 | lets it work on top of tcl. See the tcl_os_funcs.3 man page for 12 | details on what this does. This can be used if you have a project 13 | based on tcl that you want to integrate gensio into. 14 | 15 | Unfortunately, it has some limitations because of weaknesses in the 16 | tcl interface. Basically, no threads. 17 | 18 | In tcl, if you start a timer, that timer will only fire in that 19 | thread's call to Tcl_DoOneEvent. Same with file handlers. 20 | Basically, timers, idle calls, and file handlers belong to a thread. 21 | 22 | You could, theoretically, have multiple threads as long as you 23 | allocate an os handler per thread and did everything with an os 24 | handler only in the thread that created it. But that's not very 25 | useful. 26 | 27 | If you really want real threading to work, you put tcl on top of 28 | gensio os funcs using Tcl_NotifierProcs. I leave that as an 29 | exercise to the reader. 30 | .SH "RETURN VALUES" 31 | .B A gensio_err 32 | returns a standard gensio error. 33 | .SH "SEE ALSO" 34 | gensio_os_funcs(3), gensio(5), gensio_err(3) 35 | -------------------------------------------------------------------------------- /tcl/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = gensio 3 | -------------------------------------------------------------------------------- /tcl/include/gensio/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = gensio_tcl.h gensio_tcl_dllvisibility.h 3 | -------------------------------------------------------------------------------- /tcl/include/gensio/gensio_tcl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIO_TCL_H 9 | #define GENSIO_TCL_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | /* 19 | * Allocate a tcl-based os funcs. 20 | */ 21 | GENSIOTCL_DLL_PUBLIC 22 | int gensio_tcl_funcs_alloc(struct gensio_os_funcs **o); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* GENSIO_TCL_H */ 29 | -------------------------------------------------------------------------------- /tcl/include/gensio/gensio_tcl_dllvisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensio - A library for abstracting stream I/O 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: LGPL-2.1-only 6 | */ 7 | 8 | #ifndef GENSIOTCL_DLLVISIBILITY 9 | #define GENSIOTCL_DLLVISIBILITY 10 | 11 | #if defined GENSIO_LINK_STATIC 12 | #define GENSIOTCL_DLL_PUBLIC 13 | #define GENSIOTCL_DLL_LOCAL 14 | #elif defined _WIN32 || defined __CYGWIN__ 15 | #ifdef BUILDING_GENSIOTCL_DLL 16 | #ifdef __GNUC__ 17 | #define GENSIOTCL_DLL_PUBLIC __attribute__ ((dllexport)) 18 | #else 19 | #define GENSIOTCL_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. 20 | #endif 21 | #else 22 | #ifdef __GNUC__ 23 | #define GENSIOTCL_DLL_PUBLIC __attribute__ ((dllimport)) 24 | #else 25 | #define GENSIOTCL_DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. 26 | #endif 27 | #endif 28 | #define GENSIOTCL_DLL_LOCAL 29 | #else 30 | #if __GNUC__ >= 4 31 | #define GENSIOTCL_DLL_PUBLIC __attribute__ ((visibility ("default"))) 32 | #define GENSIOTCL_DLL_LOCAL __attribute__ ((visibility ("hidden"))) 33 | #else 34 | #define GENSIOTCL_DLL_PUBLIC 35 | #define GENSIOTCL_DLL_LOCAL 36 | #endif 37 | #endif 38 | 39 | #endif /* GENSIOTCL_DLLVISIBILITY */ 40 | -------------------------------------------------------------------------------- /tcl/libgensiotcl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgensioglib 7 | Description: A library to abstract stream I/O like serial port, TCP, telnet, UDP, SSL, IPMI SOL, etc. 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lgensiotcl -lgensio 10 | Libs.private: @TCL_LIBS@ 11 | -------------------------------------------------------------------------------- /tcl/swig/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = gensiotcl.i 3 | 4 | SUBDIRS = . $(PYTHON_DIR) 5 | DIST_SUBDIRS = python 6 | -------------------------------------------------------------------------------- /tcl/swig/gensiotcl.i: -------------------------------------------------------------------------------- 1 | %module gensiotcl 2 | 3 | %import 4 | 5 | %{ 6 | #include "config.h" 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | struct gensio_os_funcs *alloc_tcl_os_funcs(swig_cb *log_handler) 15 | { 16 | struct gensio_os_funcs *o; 17 | int err; 18 | 19 | err = gensio_tcl_funcs_alloc(&o); 20 | if (err) { 21 | fprintf(stderr, "Unable to allocate gensio os funcs: %s, giving up\n", 22 | gensio_err_to_str(err)); 23 | exit(1); 24 | } 25 | 26 | err = gensio_swig_setup_os_funcs(o, log_handler); 27 | if (err) { 28 | fprintf(stderr, "Unable to set up gensio os funcs: %s, giving up\n", 29 | gensio_err_to_str(err)); 30 | exit(1); 31 | } 32 | 33 | return o; 34 | } 35 | 36 | %} 37 | 38 | %nodefaultctor gensio_os_funcs; 39 | 40 | struct gensio_os_funcs { }; 41 | 42 | %extend gensio_os_funcs { 43 | ~gensio_os_funcs() { 44 | check_os_funcs_free(self); 45 | } 46 | } 47 | 48 | %newobject alloc_tcl_os_funcs; 49 | struct gensio_os_funcs *alloc_tcl_os_funcs(swig_cb *log_handler); 50 | -------------------------------------------------------------------------------- /tcl/swig/python/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CFLAGS = $(PYTHON_CPPFLAGS) \ 3 | -I $(top_srcdir)/include \ 4 | -I$(top_builddir)/include \ 5 | -I $(top_srcdir) \ 6 | -I$(top_srcdir)/tcl/include \ 7 | -I$(top_srcdir)/swig/include \ 8 | -DPYTHON_HAS_THREADS=@PYTHON_HAS_THREADS@ 9 | 10 | pythonlibdir=$(PYTHON_INSTALL_LIB_DIR) 11 | pythonlib_LTLIBRARIES = _gensiotcl.la 12 | 13 | gensiotcl_wrap.c gensiotcl.py: $(top_srcdir)/tcl/swig/gensiotcl.i 14 | $(SWIG) $(DEFS) -python $(PYTHON_SWIG_FLAGS) -o gensiotcl_wrap.c \ 15 | -I$(top_srcdir)/include -I$(top_srcdir)/swig/include \ 16 | $(top_srcdir)/tcl/swig/gensiotcl.i 17 | 18 | nodist__gensiotcl_la_SOURCES = gensiotcl_wrap.c 19 | _gensiotcl_la_LIBADD = $(top_builddir)/tcl/libgensiotcl.la \ 20 | $(top_builddir)/lib/libgensio.la \ 21 | $(top_builddir)/lib/libgensioosh.la \ 22 | $(OPENSSL_LIBS) $(TCL_LIBS) \ 23 | $(top_builddir)/swig/python/libgensio_python_swig.la \ 24 | $(PYTHON_UNDEF_LIBS) 25 | _gensiotcl_la_LDFLAGS = -module -avoid-version $(OPENSSL_LDFLAGS) \ 26 | $(PYTHON_UNDEF_FLAG) $(PYTHON_EXT_EXT_SET) 27 | 28 | clean-local: 29 | rm -rf __pycache__ gensiotcl_wrap.c gensiotcl.py 30 | 31 | install-exec-local: _gensiotcl.la gensiotcl.py 32 | $(INSTALL) -d $(DESTDIR)$(PYTHON_INSTALL_DIR) 33 | $(INSTALL_DATA) gensiotcl.py "$(DESTDIR)$(PYTHON_INSTALL_DIR)" 34 | 35 | uninstall-local: 36 | $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(PYTHON_INSTALL_LIB_DIR)/_gensiotcl.$(PYTHON_EXT_EXT)" 37 | rm -f "$(DESTDIR)$(PYTHON_INSTALL_DIR)/gensiotcl.py" 38 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | # generated 2 | gensios_enabled.py 3 | reflector.py 4 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | This directory holds tests for gensio. Note that there are also 2 | extensive tests in ser2net. These tests are more basic and 3 | functional. 4 | 5 | These tests require the linux serial simulation module in 6 | linux-serialsim in this package. You must load that module and the 7 | user running the test must be able to access the serial ports 8 | (generally you must be in the dialout group). 9 | 10 | Fuzz testing is also available for some of the filter gensios, see the 11 | makefile for details on what is available. These tests work by 12 | running a standard scenario and saving the data written to the 13 | accepting gensio, then using that as input for the afl fuzz tester. 14 | There's quite a bit of setup involved, but the afl program will tell 15 | you what is wrong and how to fix it. 16 | 17 | To compile for fuzzing, you have to configure it to use the afl 18 | compiler, and you have to use static binaries. To do this, make a 19 | separate build directory in the mai directory, then cd into it and 20 | run: 21 | 22 | ../configure --disable-shared CC=afl-gcc 23 | 24 | Then "make". After that, in the tests directory, you can run the 25 | individual fuzzers for the filters. See Makefile.am for details on 26 | them. -------------------------------------------------------------------------------- /tests/echotest.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | char buf[100]; 8 | size_t len, i; 9 | int rv = 0; 10 | int close = 0; 11 | 12 | do { 13 | len = fread(buf, 1, 1, stdin); 14 | if (len > 0) { 15 | fwrite(buf, 1, len, stdout); fflush(stdout); 16 | for (i = 0; i < len; i++) { 17 | if (buf[i] == 'x') 18 | close = 1; 19 | if (buf[i] == 'e') { 20 | rv = 1; 21 | close = 1; 22 | } 23 | } 24 | } 25 | } while (len > 0 && !close); 26 | return rv; 27 | } 28 | -------------------------------------------------------------------------------- /tests/gensios_enabled.py.in: -------------------------------------------------------------------------------- 1 | import sys 2 | import platform 3 | 4 | def running_on_linux(): 5 | return platform.system() == "Linux" 6 | 7 | def running_on_windows(): 8 | return platform.system() == "Windows" 9 | 10 | # Track which gensios are enabled in the library 11 | gensios_enabled = { 12 | "tcp": 1, 13 | "udp": 1, 14 | "sctp": @HAVE_LIBSCTP@, 15 | "stdio": 1, 16 | "pty": @HAVE_PTY@, 17 | "unix" : 1, 18 | "unixdgram" : not running_on_windows(), 19 | "unixseq" : running_on_linux(), 20 | "ssl": @HAVE_OPENSSL@, 21 | "mux": 1, 22 | "certauth": @HAVE_OPENSSL@, 23 | "telnet": 1, 24 | "serialdev": 1, 25 | "echo": 1, 26 | "file": 1, 27 | "ipmisol": @HAVE_OPENIPMI@, 28 | "dummy": 1, 29 | "msgdelim": 1, 30 | "relpkt": 1, 31 | "trace": 1, 32 | "conacc": 1, 33 | "perf": 1, 34 | "mdns": @HAVE_MDNS@, 35 | "ax25": 1, 36 | "ratelimit": 1 37 | } 38 | 39 | # Gensios that are always last in the list. 40 | final_gensios = [ 41 | "tcp", 42 | "udp", 43 | "sctp", 44 | "stdio", 45 | "pty", 46 | "unix", 47 | "unixdgram", 48 | "unixseq", 49 | "serialdev", 50 | "echo", 51 | "file", 52 | "ipmisol", 53 | "dummy", 54 | "conacc", 55 | "mdns" 56 | ] 57 | 58 | def check_gensio_enabled(g): 59 | return gensios_enabled[g] 60 | 61 | def check_iostr_gensios(s): 62 | while True: 63 | c = s.find(",") 64 | if c == -1: 65 | c = len(s) 66 | p = s.find("(") 67 | if p == -1: 68 | p = len(s) 69 | if (c < p): 70 | g = s[:c] 71 | s = s[c + 1:] 72 | else: 73 | g = s[:p] 74 | p = s.find(")") 75 | s = s[p + 2:] 76 | 77 | if not gensios_enabled[g]: 78 | print("Gensio %s is not enabled, test skipped" % g) 79 | sys.exit(77) 80 | 81 | if g in final_gensios: 82 | break 83 | 84 | have_ptsname_r = @HAVE_PTSNAME_R@ 85 | have_ucred = @HAVE_UCRED@ 86 | -------------------------------------------------------------------------------- /tests/make_keys: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | rm -rf ca 4 | mkdir ca 5 | cd ca 6 | 7 | # NOTE: CN for CA certificate and other certificates must be different. 8 | 9 | # For msys, the leading / in the openssl commands gets translated, turn 10 | # that off. 11 | export MSYS2_ARG_CONV_EXCL="*" 12 | 13 | openssl req -newkey rsa:2048 -nodes -x509 -days 10000 -keyout CA.key \ 14 | -subj "/C=US/ST=Texas/O=ser2net/OU=test/CN=ser2net.admin/emailAddress=ser2net@ser2net.org" \ 15 | -out CA.pem 16 | 17 | # Sign the key with the CA 18 | 19 | openssl req -newkey rsa:2048 -nodes -keyout key.pem \ 20 | -subj "/C=US/ST=Texas/O=ser2net/OU=test/CN=ser2net.org/emailAddress=ser2net@ser2net.org" \ 21 | -out key.csr 22 | openssl x509 -req -in key.csr -CA CA.pem -CAkey CA.key -CAcreateserial -out cert.pem 23 | 24 | # Self-signed certificate for the client 25 | 26 | openssl req -newkey rsa:2048 -nodes -x509 -days 10000 -keyout clientkey.pem \ 27 | -subj "/C=US/ST=Texas/O=ser2net/OU=test/CN=gensio.org/emailAddress=ser2net@ser2net.org" \ 28 | -out clientcert.pem 29 | -------------------------------------------------------------------------------- /tests/oomtest0: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 0 $* -------------------------------------------------------------------------------- /tests/oomtest1: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 1 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest10: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 10 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest11: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 11 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest12: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 12 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest13: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 13 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest14: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 14 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest15: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 15 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 2 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest3: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 3 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest4: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 4 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest5: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 5 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest6: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 6 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest7: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 7 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest8: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 8 $* 3 | -------------------------------------------------------------------------------- /tests/oomtest9: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./oomtest -t 9 $* 3 | -------------------------------------------------------------------------------- /tests/termioschk.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | import termios 9 | import copy 10 | 11 | import gensio 12 | import utils 13 | 14 | # This is the termios gensio sets up when it opens a serial port. 15 | # Same for sergensio_termios gensio. 16 | base_termios = [ 0, 0, 0, 0, 0, 0, 17 | [ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 18 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 19 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 20 | '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' ]] 21 | 22 | def setup_base_termios(): 23 | base_termios[0] = termios.IGNBRK 24 | base_termios[2] = (termios.B9600 | termios.CREAD | termios.CS8) 25 | base_termios[4] = termios.B9600 26 | base_termios[5] = termios.B9600 27 | base_termios[6][termios.VTIME] = 0 28 | base_termios[6][termios.VMIN] = 1 29 | base_termios[6][termios.VSTART] = chr(17) 30 | base_termios[6][termios.VSTOP] = chr(19) 31 | return 32 | 33 | setup_base_termios() 34 | 35 | def dup_termios(t, iflags=0, iflags_mask=0, 36 | oflags=0, oflags_mask=0, 37 | cflags=0, cflags_mask=0, 38 | lflags=0, lflags_mask=0): 39 | """Duplicate the given termios, then apply the masks and or the values 40 | given.""" 41 | n = copy.deepcopy(t) 42 | n[0] = (n[0] & ~iflags_mask) | iflags 43 | n[1] = (n[1] & ~oflags_mask) | oflags 44 | n[2] = (n[2] & ~cflags_mask) | cflags 45 | n[3] = (n[3] & ~lflags_mask) | lflags 46 | return n 47 | 48 | def dup_base_termios(iflags=0, iflags_mask=0, 49 | oflags=0, oflags_mask=0, 50 | cflags=0, cflags_mask=0, 51 | lflags=0, lflags_mask=0): 52 | return dup_termios(base_termios, iflags, iflags_mask, oflags, oflags_mask, 53 | cflags, cflags_mask, lflags, lflags_mask) 54 | 55 | def compare_termios(tio1, tio2): 56 | for i in range(0, 6): 57 | if tio1[i] != tio2[i]: 58 | return i; 59 | for i in range(0, len(tio2[6])): 60 | if tio1[6][i] != tio2[6][i]: 61 | return i + 6; 62 | return -1 63 | -------------------------------------------------------------------------------- /tests/test_accept_certauth_tcp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test accept certauth-ssl-tcp") 12 | ta = TestAccept(o, "certauth(cert=%s/clientcert.pem,key=%s/clientkey.pem,username=testuser,service=myservice),ssl(CA=%s/CA.pem),tcp,localhost," % (keydir, keydir, keydir), "certauth(CA=%s/clientcert.pem),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % (keydir, keydir, keydir), do_test, do_close = False) 13 | cn = ta.io2.control(0, gensio.GENSIO_CONTROL_GET, 14 | gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, 15 | "-1,CN"); 16 | i = cn.index(',') 17 | cn2 = cn[i+1:] 18 | i = cn2.index(',') 19 | if cn2[0:i] != "CN": 20 | raise Exception( 21 | "Invalid object name, expected %s, got %s" % ("CN", cn2[0:i])) 22 | if cn2[i+1:] != "gensio.org": 23 | raise Exception( 24 | "Invalid common name in certificate, expected %s, got %s" % 25 | ("gensio.org", cn2[i+1:])) 26 | username = ta.io2.control(0, gensio.GENSIO_CONTROL_GET, 27 | gensio.GENSIO_CONTROL_USERNAME, None) 28 | if username != "testuser": 29 | raise Exception( 30 | "Invalid username, expected %s, got %s" % ("testuser", username)) 31 | service = ta.io2.control(0, gensio.GENSIO_CONTROL_GET, 32 | gensio.GENSIO_CONTROL_SERVICE, None) 33 | if service != "myservice": 34 | raise Exception( 35 | "Invalid service, expected %s, got %s" % ("myservice", service)) 36 | ta.close() 37 | del ta 38 | del o 39 | test_shutdown() 40 | -------------------------------------------------------------------------------- /tests/test_accept_mux_tcp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test accept mux-tcp") 12 | ta = TestAccept(o, "mux(service=myservice),tcp,ipv4,localhost,", 13 | "mux,tcp,localhost,0", do_test, do_close = False) 14 | service = ta.io2.control(0, gensio.GENSIO_CONTROL_GET, 15 | gensio.GENSIO_CONTROL_SERVICE, None) 16 | if service != "myservice": 17 | raise Exception( 18 | "Invalid service, expected %s, got %s" % ("myservice", service)) 19 | ta.close() 20 | del ta 21 | del o 22 | test_shutdown() 23 | -------------------------------------------------------------------------------- /tests/test_accept_sctp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | check_sctp() 12 | print("Test accept sctp") 13 | # FIXME - the raddr and laddr areq not tested here, it's hard to 14 | # know what it would be because of sctp multihoming. 15 | a = TestAccept(o, "sctp,ipv4,localhost,", "sctp,localhost,0", do_test, do_close = False) 16 | c = a.io1.control(0, gensio.GENSIO_CONTROL_GET, 17 | gensio.GENSIO_CONTROL_STREAMS, None) 18 | if c != "instreams=1,ostreams=1": 19 | raise Exception("Invalid stream settings: %s" % c) 20 | a.close() 21 | del a 22 | del o 23 | test_shutdown() 24 | -------------------------------------------------------------------------------- /tests/test_accept_ssl_tcp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test accept ssl-tcp") 12 | ta = TestAccept(o, "ssl(CA=%s/CA.pem),tcp,ipv4,localhost," % keydir, "ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % (keydir, keydir), do_test, do_close = False, 13 | expected_raddr = "ipv4,127.0.0.1,") 14 | print("Get peer cert"); 15 | cn = ta.io1.control(0, gensio.GENSIO_CONTROL_GET, 16 | gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, "-1,CN"); 17 | i = cn.index(',') 18 | cn2 = cn[i+1:] 19 | i = cn2.index(',') 20 | if cn2[0:i] != "CN": 21 | raise Exception( 22 | "Invalid object name, expected %s, got %s" % ("CN", cn2[0:i])) 23 | if cn2[i+1:] != "ser2net.org": 24 | raise Exception( 25 | "Invalid common name in certificate, expected %s, got %s" % 26 | ("ser2net.org", cn2[i+1:])) 27 | cert = ta.io1.control(0, gensio.GENSIO_CONTROL_GET, 28 | gensio.GENSIO_CONTROL_CERT, None) 29 | print("Cert = \n" + cert) 30 | finger = ta.io1.control(0, gensio.GENSIO_CONTROL_GET, 31 | gensio.GENSIO_CONTROL_CERT_FINGERPRINT, None) 32 | print("Fingerprint = " + finger) 33 | i = 0; 34 | while True: 35 | v = ta.io1.control(0, gensio.GENSIO_CONTROL_GET, 36 | gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, str(i)) 37 | if v is None: 38 | break; 39 | print(v) 40 | i = i + 1 41 | ta.close() 42 | del ta 43 | del o 44 | test_shutdown() 45 | -------------------------------------------------------------------------------- /tests/test_accept_tcp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test accept tcp") 12 | TestAccept(o, "tcp,ipv4,localhost,", "tcp,localhost,0", do_test, 13 | expected_raddr = "ipv4,127.0.0.1,", 14 | expected_acc_laddr = "ipv4,127.0.0.1,") 15 | del o 16 | test_shutdown() 17 | -------------------------------------------------------------------------------- /tests/test_accept_udp.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test accept udp") 12 | TestAccept(o, "udp,ipv4,localhost,", "udp,localhost,0", 13 | do_test, io1_dummy_write = "A", 14 | expected_raddr = "ipv4,127.0.0.1,", 15 | expected_acc_laddr = "ipv4,127.0.0.1,") 16 | del o 17 | test_shutdown() 18 | -------------------------------------------------------------------------------- /tests/test_ax25_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test ax25 small") 12 | TestAccept(o, 13 | "ax25(laddr=AE5KM-2,addr='0,AE5KM-1,AE5KM-2',retries=2,srt=500),udp,localhost,", 14 | "ax25(laddr=AE5KM-1,retries=2,srt=500),udp,localhost,0", do_small_test, chunksize = 64) 15 | del o 16 | test_shutdown() 17 | -------------------------------------------------------------------------------- /tests/test_certauth_ssl_tcp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test certauth over ssl over tcp") 12 | 13 | # First test bypassing authentication from the auth_begin callback; 14 | TestAcceptConnect(o, 15 | ("certauth(),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % 16 | (keydir, keydir)), 17 | ("certauth(),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % 18 | (keydir, keydir)), 19 | "certauth(),ssl(CA=%s/CA.pem),tcp,localhost," % keydir, 20 | do_small_test, auth_begin_rv=0) 21 | 22 | # Now try password authentication. 23 | TestAcceptConnect(o, 24 | ("certauth(enable-password),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % 25 | (keydir, keydir)), 26 | ("certauth(enable-password),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,ipv4,localhost,0" % 27 | (keydir, keydir)), 28 | ("certauth(enable-password,password=asdfasdf),ssl(CA=%s/CA.pem),tcp,localhost," % 29 | keydir), 30 | do_small_test, expect_pw = "asdfasdf", expect_pw_rv = 0) 31 | 32 | # Test the password request 33 | TestAcceptConnect(o, 34 | ("certauth(enable-password),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % 35 | (keydir, keydir)), 36 | ("certauth(enable-password),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % 37 | (keydir, keydir)), 38 | ("certauth(enable-password),ssl(CA=%s/CA.pem),tcp,localhost," % 39 | keydir), 40 | do_small_test, expect_pw = "jkl;", expect_pw_rv = 0, 41 | password = "jkl;") 42 | 43 | # Test the password with 2-factor authentication request 44 | TestAcceptConnect(o, 45 | ("certauth(enable-password,enable-2fa),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % 46 | (keydir, keydir)), 47 | ("certauth(enable-password,enable-2fa),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % 48 | (keydir, keydir)), 49 | ("certauth(enable-password),ssl(CA=%s/CA.pem),tcp,localhost," % 50 | keydir), 51 | do_small_test, expect_pw = "jkl;", expect_pw_rv = 0, 52 | password = "jkl;", 53 | expect_2fa = "Hello There", expect_2fa_rv = 0, 54 | val_2fa = "Hello There") 55 | 56 | del o 57 | test_shutdown() 58 | -------------------------------------------------------------------------------- /tests/test_certauth_tcp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test certauth over ssl over tcp accepter connect") 12 | goterr = False 13 | try: 14 | TestAcceptConnect(o, 15 | "certauth(CA=%s/clientcert.pem),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % (keydir, keydir, keydir), 16 | "certauth(CA=%s/clientcert.pem),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % (keydir, keydir, keydir), 17 | "certauth(cert=%s/cert.pem,key=%s/key.pem,username=test1),ssl(CA=%s/CA.pem),tcp,localhost," % (keydir, keydir, keydir), 18 | do_small_test) 19 | except Exception as E: 20 | s = str(E) 21 | # We can race and get either one of these 22 | if (not (s.endswith("Communication error") or 23 | s.endswith("Authentication tokens rejected") or 24 | s.endswith("Remote end closed connection"))): 25 | raise 26 | print(" Success checking invalid client cert") 27 | goterr = True 28 | if not goterr: 29 | raise Exception("Did not get error on invalid client certificate.") 30 | 31 | TestAcceptConnect(o, 32 | "certauth(),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % (keydir, keydir), 33 | "certauth(),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" % (keydir, keydir), 34 | "certauth(cert=%s/clientcert.pem,key=%s/clientkey.pem,username=test1),ssl(CA=%s/CA.pem),tcp,localhost," % (keydir, keydir, keydir), 35 | do_small_test, CA="%s/clientcert.pem" % keydir) 36 | 37 | del o 38 | test_shutdown() 39 | -------------------------------------------------------------------------------- /tests/test_dummy.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | import utils 9 | import gensio 10 | 11 | print("Test dummy") 12 | 13 | acc = gensio.gensio_accepter(utils.o, "dummy", None); 14 | acc.startup() 15 | waiter = gensio.waiter(utils.o) 16 | waiter.service(1) 17 | acc.shutdown_s() 18 | del waiter 19 | del acc 20 | utils.test_shutdown() 21 | print(" Success!") 22 | -------------------------------------------------------------------------------- /tests/test_echo_device.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test echo device") 12 | check_echo_dev() 13 | io = alloc_io(o, "serialdev," + ttyecho + ",38400,hangup-when-done") 14 | check_raddr(io, "echo device", ttyecho + ",38400N81 RTSHI DTRHI", 15 | ttyecho + ",38400N81,HANGUP_WHEN_DONE RTSHI DTRHI") 16 | test_dataxfer(io, io, "This is a test string!") 17 | io_close([io]) 18 | del io 19 | del o 20 | test_shutdown() 21 | print(" Success!") 22 | -------------------------------------------------------------------------------- /tests/test_echo_gensio.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test echo gensio") 12 | io = alloc_io(o, "echo") 13 | check_raddr(io, "echo", "echo") 14 | test_dataxfer(io, io, "This is a test string!") 15 | io_close([io]) 16 | del io 17 | del o 18 | test_shutdown() 19 | print(" Success!") 20 | 21 | -------------------------------------------------------------------------------- /tests/test_file.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | import utils 9 | import gensio 10 | import os 11 | 12 | test1 = "asdfasdf" 13 | test2 = "jkl;jkl;" 14 | test3 = "01234;" 15 | 16 | print("Test file") 17 | 18 | testfile = "asdffile" 19 | 20 | try: 21 | os.remove(testfile) 22 | except: 23 | pass 24 | 25 | print(" Testing no create") 26 | g = gensio.gensio(utils.o, "file(outfile=" + testfile + ")", None) 27 | g.set_sync() 28 | failed = False 29 | try: 30 | g.open_s() 31 | except Exception as e: 32 | if not str(e).endswith("Value or file not found"): 33 | raise Exception("Unknown exception opening file: " + str(e)) 34 | failed = True 35 | if not failed: 36 | raise Exception("Open didn't fail") 37 | del g 38 | 39 | def writefile(f, data, options = ""): 40 | g = gensio.gensio(utils.o, "file(outfile=%s%s)" % (f, options), None) 41 | g.set_sync() 42 | g.open_s() 43 | g.write_s(data, 1000) 44 | g.close_s() 45 | del g 46 | 47 | def readfile(f, options = ""): 48 | g = gensio.gensio(utils.o, "file(infile=%s%s)" % (f, options), None) 49 | g.set_sync() 50 | g.open_s() 51 | s = g.read_s(100, 1000) 52 | g.close_s() 53 | del g 54 | s = s[0].decode('utf-8') 55 | return s 56 | 57 | print(" Testing file data") 58 | writefile(testfile, test1, ",create") 59 | s = readfile(testfile) 60 | if s != test1: 61 | raise Exception("file data didn't match, expected %s, got %s" % ( 62 | test1, s)) 63 | 64 | print(" Testing append") 65 | writefile(testfile, test2, ",append") 66 | s = readfile(testfile) 67 | if s != test1 + test2: 68 | raise Exception("file data didn't match, expected %s, got %s" % ( 69 | test1 + test2, s)) 70 | 71 | print(" Testing overwrite") 72 | writefile(testfile, test2) 73 | s = readfile(testfile) 74 | if s != test2 + test2: 75 | raise Exception("file data didn't match, expected %s, got %s" % ( 76 | test2 + test2, s)) 77 | 78 | print(" Testing trunc") 79 | writefile(testfile, test3, ",trunc") 80 | s = readfile(testfile) 81 | if s != test3: 82 | raise Exception("file data didn't match, expected %s, got %s" % ( 83 | test3, s)) 84 | 85 | os.remove(testfile) 86 | 87 | utils.test_shutdown() 88 | print(" Success!") 89 | -------------------------------------------------------------------------------- /tests/test_fuzz_setup.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | # 9 | # This program creates some random data into a file and then runs a 10 | # gensio connector and accepter over stdio. The data written to the 11 | # accepter gensio filter is saved in tracefile. 12 | # 13 | # This is for support of fuzz testing. The random data can be used to 14 | # create a completely reproducible testcase with the ssl library. The 15 | # tracefile is used for fuzzing the program. 16 | # 17 | 18 | import sys 19 | import subprocess 20 | import os 21 | 22 | gensiot = sys.argv[1] 23 | randfile = sys.argv[2] 24 | filter1 = sys.argv[3] 25 | filter2 = sys.argv[4] 26 | tracefile = sys.argv[5] 27 | 28 | p = subprocess.Popen(["dd", "if=/dev/urandom", "of=" + randfile, "count=256"], 29 | stderr = subprocess.PIPE) 30 | p.communicate() 31 | 32 | cmd = (filter1 + ',trace(dir=write,raw,file=' + tracefile + '),stdio(noredir-stderr),' + 33 | gensiot + ' --dummyrand ' + randfile + ' -i echo -a "' + filter2 + 34 | ',stdio"') 35 | 36 | p = subprocess.Popen([gensiot, '--dummyrand', randfile, '-i', 'stdio(self)', cmd], 37 | stdin = subprocess.PIPE, 38 | stdout = subprocess.PIPE, 39 | stderr = None) 40 | 41 | p.stdin.write("a".encode(encoding='utf8')) 42 | p.stdin.close() 43 | p.stdout.read(1) 44 | p.wait() 45 | -------------------------------------------------------------------------------- /tests/test_ipmisol_large.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | import ipmisimdaemon 11 | 12 | print("Test ipmisol large") 13 | check_pipe_dev() 14 | gensios_enabled.check_iostr_gensios("ipmisol") 15 | isim = ipmisimdaemon.IPMISimDaemon(o, ttypipe[1]) 16 | io1 = alloc_io(o, "serialdev," + ttypipe[0] + ",115200") 17 | io2 = alloc_io(o, "ipmisol,lan -U ipmiusr -P test -p %d localhost,115200" % 18 | isim.port) 19 | do_medium_test(io1, io2, timeout=30000) 20 | io_close((io1, io2)) 21 | del io1 22 | del io2 23 | del isim 24 | del o 25 | test_shutdown() 26 | -------------------------------------------------------------------------------- /tests/test_ipmisol_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | import ipmisimdaemon 11 | 12 | print("Test ipmisol small") 13 | check_pipe_dev() 14 | gensios_enabled.check_iostr_gensios("ipmisol") 15 | isim = ipmisimdaemon.IPMISimDaemon(o, ttypipe[1]) 16 | io1 = alloc_io(o, "serialdev," + ttypipe[0] + ",9600") 17 | io2 = alloc_io(o, "ipmisol,lan -U ipmiusr -P test -p %d localhost,9600" % 18 | isim.port) 19 | do_small_test(io1, io2) 20 | io_close((io1, io2)) 21 | del io1 22 | del io2 23 | del isim 24 | del o 25 | test_shutdown() 26 | print(" Success") 27 | -------------------------------------------------------------------------------- /tests/test_mux_oob.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test mux tcp oob") 12 | TestAccept(o, "mux,tcp,localhost,", "mux,tcp,localhost,0", do_oob_test, 13 | chunksize = 64, enable_oob = True) 14 | 15 | del o 16 | test_shutdown() 17 | -------------------------------------------------------------------------------- /tests/test_mux_tcp_large.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test mux tcp large") 12 | TestAccept(o, "mux,tcp,localhost,", "mux,tcp,localhost,0", do_large_test, 13 | chunksize = 64) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_mux_tcp_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test mux tcp small") 12 | TestAccept(o, "mux,tcp,localhost,", "mux,tcp,localhost,0", do_small_test, 13 | chunksize = 64) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_parmlog.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2020 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | import utils 9 | import gensio 10 | import gensios_enabled 11 | import sys 12 | 13 | gensios_enabled.check_iostr_gensios("tcp") 14 | 15 | class ParmEvent: 16 | def __init__(self): 17 | self.log = None 18 | return 19 | 20 | def parmlog(self, log): 21 | self.log = log 22 | return 23 | 24 | print("Testing parameter error logs") 25 | 26 | o = utils.o 27 | p = ParmEvent() 28 | 29 | print(" Testing accepter error logs") 30 | 31 | handled = False 32 | try: 33 | a = gensio.gensio_accepter(o, "tcp(x=asdf),localhost,0", p) 34 | except Exception as E: 35 | if str(E) != "gensio:gensio_accepter constructor: Invalid data to parameter": 36 | raise Exception("Unknown exception from accepter: " + str(E)) 37 | handled = True 38 | 39 | if not handled: 40 | raise Exception("Did not get an exception from accepter error") 41 | 42 | if p.log is None: 43 | raise Exception("Did not get a parm log from accepter error") 44 | 45 | if p.log != "accepter tcp: unknown parameter x=asdf": 46 | raise Exception("Invalid parm log: " + p.log) 47 | 48 | print(" Success!") 49 | 50 | print(" Testing gensio error logs") 51 | 52 | p.log = None 53 | handled = False 54 | try: 55 | a = gensio.gensio(o, "tcp(x=asdf),localhost,1234", p) 56 | except Exception as E: 57 | if str(E) != "gensio:gensio alloc: Invalid data to parameter": 58 | raise Exception("Unknown exception from gensio: " + str(E)) 59 | handled = True 60 | 61 | if not handled: 62 | raise Exception("Did not get an exception from gensio error") 63 | 64 | if p.log is None: 65 | raise Exception("Did not get a parm log from gensio error") 66 | 67 | if p.log != "gensio tcp: unknown parameter x=asdf": 68 | raise Exception("Invalid parm log: " + p.log) 69 | 70 | del o 71 | del p 72 | utils.test_shutdown() 73 | 74 | print(" Success!") 75 | -------------------------------------------------------------------------------- /tests/test_perf.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | def do_no_test(io1, io2, timeout=10000): 12 | io1.handler.ignore_input = True 13 | io2.handler.ignore_input = True 14 | io1.handler.waiting_rem_close = True 15 | io2.handler.waiting_rem_close = True 16 | io1.read_cb_enable(True) 17 | io2.read_cb_enable(True) 18 | if (io1.handler.wait_timeout(timeout) == 0): 19 | raise Exception("test_perf: io1 did not finish in time") 20 | if (io2.handler.wait_timeout(timeout) == 0): 21 | raise Exception("test_perf: io2 did not finish in time") 22 | return 23 | 24 | print("Test perf") 25 | TestAccept(o, 26 | "perf(write_len=1000000,expect_len=1000000),tcp,localhost,", 27 | "perf(write_len=1000000,expect_len=1000000),tcp,localhost,0", 28 | do_no_test) 29 | del o 30 | test_shutdown() 31 | print(" Success!") 32 | -------------------------------------------------------------------------------- /tests/test_pty_basic.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | import os 11 | import gensios_enabled 12 | 13 | gensios_enabled.check_iostr_gensios("pty") 14 | 15 | if is_windows(): 16 | sys.exit(77) 17 | 18 | print("Test pty basic echo") 19 | io = alloc_io(o, "pty,cat", chunksize = 64) 20 | check_raddr(io, "pty basic", '"cat"') 21 | test_dataxfer(io, io, "This is a test string!") 22 | io_close([io]) 23 | del io 24 | print(" Success!") 25 | 26 | def test_with_ptsname_r(): 27 | print("Test pty accepter") 28 | TestAccept(o, "serialdev,", "conacc,pty", do_small_test) 29 | 30 | print("Test pty symlinks") 31 | try: 32 | os.unlink("./ptylink1") 33 | except: 34 | pass 35 | 36 | TestAccept(o, "serialdev,./ptylink1", "conacc,pty(link=./ptylink1)", 37 | do_small_test, get_port = False) 38 | 39 | print("Test pty symlink failure") 40 | os.symlink("asdf", "./ptylink1") 41 | try: 42 | TestAccept(o, "serialdev,./ptylink1", "conacc,pty(link=./ptylink1)", 43 | do_small_test, get_port = False, except_on_log = True) 44 | except Exception as E: 45 | if str(E) == "***err LOG: conacc,pty(link=./ptylink1): Error opening gensio: Value already exists": 46 | None 47 | elif str(E) == "gensio:startup: Value already exists": 48 | None 49 | else: 50 | raise 51 | print(" Success!") 52 | 53 | print("Test pty symlink force") 54 | TestAccept(o, "serialdev,./ptylink1", "conacc,pty(link=./ptylink1,forcelink)", 55 | do_small_test, get_port = False) 56 | 57 | if gensios_enabled.have_ptsname_r: 58 | test_with_ptsname_r() 59 | 60 | del o 61 | test_shutdown() 62 | -------------------------------------------------------------------------------- /tests/test_ratelimit.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | def do_ratelimit_test1(io1, io2, timeout=2000): 12 | data = "123456789012345" # 15 characters, 1.5 seconds. 13 | io1.handler.set_write_data(data) 14 | io2.handler.set_compare(data) 15 | if (io1.handler.wait_timeout(1000) != 0): 16 | raise Exception(("%s: %s: " % ("do_ratelimit_test", io1.handler.name)) + 17 | ("Sent data too fast")) 18 | if (io1.handler.wait_timeout(3500) == 0): 19 | raise Exception(("%s: %s: " % ("do_ratelimit_test", io1.handler.name)) + 20 | ("Sent data too slowly")) 21 | if (io2.handler.wait_timeout(1000) == 0): 22 | raise Exception(("%s: %s: " % ("test_dataxfer", io2.handler.name)) + 23 | ("Read data wasn't received")) 24 | 25 | def do_ratelimit_test2(io1, io2, timeout=2000): 26 | do_ratelimit_test1(io2, io1, timeout) 27 | 28 | print("Test ratelimit gensio") 29 | TestAccept(o, "ratelimit(xmit_delay=100m),tcp,localhost,", "tcp,localhost,0", 30 | do_ratelimit_test1, chunksize = 64) 31 | print("Test ratelimit accepter") 32 | TestAccept(o, "tcp,localhost,", "ratelimit(xmit_delay=100m),tcp,localhost,0", 33 | do_ratelimit_test2, chunksize = 64) 34 | del o 35 | test_shutdown() 36 | print("Success!") 37 | -------------------------------------------------------------------------------- /tests/test_relpkt_basic.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test relpkt over msgdelim over serial") 12 | check_pipe_dev() 13 | io1 = alloc_io(o, "mux(mode=server),relpkt(mode=server),msgdelim,serialdev," + ttypipe[0] + ",hangup-when-done", do_open = False) 14 | io2 = alloc_io(o, "mux,relpkt,msgdelim,serialdev," + ttypipe[1] + ",hangup-when-done", do_open = False) 15 | TestConCon(o, io1, io2, do_test, "relpkt1", 16 | expected_raddr1 = ttypipe[0] + ",9600N81 RTSHI DTRHI", 17 | expected_raddr1b = ttypipe[0] + ",9600N81,HANGUP_WHEN_DONE RTSHI DTRHI", 18 | expected_raddr2 = ttypipe[1] + ",9600N81 RTSHI DTRHI", 19 | expected_raddr2b = ttypipe[1] + ",9600N81,HANGUP_WHEN_DONE RTSHI DTRHI") 20 | del io1 21 | del io2 22 | del o 23 | test_shutdown() 24 | -------------------------------------------------------------------------------- /tests/test_relpkt_large.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test large relpkt over udp") 12 | TestAccept(o, "mux,relpkt,udp,localhost,", 13 | "mux,relpkt,udp,localhost,0", do_large_test) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_relpkt_medium.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | 12 | print("Test medium relpkt over msgdelim over serial") 13 | check_pipe_dev() 14 | if is_serialsim_pipe(): 15 | fast_baud = "1000000" 16 | timeout = 10000 17 | else: 18 | # Normal serial ports don't always support high speeds 19 | fast_baud = "115200" 20 | timeout = 100000 21 | 22 | io1 = alloc_io(o, "mux(mode=server),relpkt(mode=server),msgdelim,serialdev," + ttypipe[0] + "," + fast_baud + ",hangup-when-done", do_open = False) 23 | io2 = alloc_io(o, "mux,relpkt,msgdelim,serialdev," + ttypipe[1] + "," + fast_baud + ",hangup-when-done", do_open = False) 24 | TestConCon(o, io1, io2, do_medium_test, "relpkt1", 25 | expected_raddr1 = ttypipe[0] + "," + fast_baud + "N81 RTSHI DTRHI", 26 | expected_raddr1b = ttypipe[0] + "," + fast_baud + "N81,HANGUP_WHEN_DONE RTSHI DTRHI", 27 | expected_raddr2 = ttypipe[1] + "," + fast_baud + "N81 RTSHI DTRHI", 28 | expected_raddr2b = ttypipe[1] + "," + fast_baud + "N81,HANGUP_WHEN_DONE RTSHI DTRHI", 29 | timeout = timeout) 30 | del io1 31 | del io2 32 | del o 33 | test_shutdown() 34 | -------------------------------------------------------------------------------- /tests/test_relpkt_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test small relpkt over msgdelim over serial") 12 | check_pipe_dev() 13 | io1 = alloc_io(o, "relpkt(mode=server),msgdelim,serialdev," + ttypipe[0] + ",hangup-when-done", do_open = False) 14 | io2 = alloc_io(o, "relpkt,msgdelim,serialdev," + ttypipe[1] + ",hangup-when-done", do_open = False) 15 | TestConCon(o, io1, io2, do_small_test, "relpkt1", 16 | expected_raddr1 = ttypipe[0] + ",9600N81 RTSHI DTRHI", 17 | expected_raddr1b = ttypipe[0] + ",9600N81,HANGUP_WHEN_DONE RTSHI DTRHI", 18 | expected_raddr2 = ttypipe[1] + ",9600N81 RTSHI DTRHI", 19 | expected_raddr2b = ttypipe[1] + ",9600N81,HANGUP_WHEN_DONE RTSHI DTRHI") 20 | del io1 21 | del io2 22 | del o 23 | test_shutdown() 24 | -------------------------------------------------------------------------------- /tests/test_rs485.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | check_pipe_dev(is_serialsim = True) 10 | 11 | import gensio 12 | from serialsim import * 13 | 14 | print("Test RS485") 15 | 16 | io1str = "serialdev," + ttypipe[0] + ",9600N81,LOCAL,rs485=50:75:rts_on_send" 17 | io2str = "serialdev," + ttypipe[1] + ",9600N81" 18 | 19 | print("serialdev rs485:\n io1=%s\n io2=%s" % (io1str, io2str)) 20 | 21 | io1 = alloc_io(o, io1str) 22 | io2 = alloc_io(o, io2str) 23 | 24 | rs485 = get_remote_rs485(remote_id_int(io2)) 25 | check_rs485 = "50 75 enabled rts_on_send" 26 | if rs485 != check_rs485: 27 | raise Exception("%s: %s: RS485 was not '%s', it was '%s'" % 28 | ("test rs485", io1.handler.name, check_rs485, rs485)) 29 | 30 | io_close((io1, io2)) 31 | del io1 32 | del io2 33 | del o 34 | test_shutdown() 35 | print(" Success!") 36 | -------------------------------------------------------------------------------- /tests/test_sctp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | check_sctp() 12 | print("Test sctp accepter connect") 13 | TestAcceptConnect(o, "sctp,localhost,0", "sctp,localhost,0", "sctp,localhost,", 14 | do_small_test) 15 | del o 16 | test_shutdown() 17 | -------------------------------------------------------------------------------- /tests/test_sctp_oob.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | check_sctp() 12 | print("Test sctp oob") 13 | TestAccept(o, "sctp,localhost,", "sctp,localhost,0", do_oob_test, chunksize = 64, 14 | enable_oob = True) 15 | del o 16 | test_shutdown() 17 | -------------------------------------------------------------------------------- /tests/test_sctp_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | check_sctp() 12 | print("Test sctp small") 13 | TestAccept(o, "sctp,localhost,", "sctp,localhost,0", do_small_test, chunksize = 64) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_sctp_streams.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | check_sctp() 12 | 13 | def do_stream_test(io1, io2): 14 | rb = os.urandom(10) 15 | print(" testing io1 to io2") 16 | test_dataxfer_stream(io1, io2, rb, 2) 17 | print(" testing io2 to io1") 18 | test_dataxfer_stream(io2, io1, rb, 1) 19 | print(" Success!") 20 | 21 | print("Test sctp streams") 22 | TestAccept(o, "sctp(instreams=2,ostreams=3),localhost,", 23 | "sctp(instreams=3,ostreams=2),localhost,0", do_stream_test, 24 | chunksize = 64) 25 | del o 26 | test_shutdown() 27 | -------------------------------------------------------------------------------- /tests/test_serial_break.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2025 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | import sys 9 | 10 | from utils import * 11 | check_pipe_dev() 12 | 13 | import gensio 14 | 15 | print("Test serial break") 16 | 17 | io1str = "serialdev," + ttypipe[0] + ",9600N81,LOCAL" 18 | io2str = "serialdev," + ttypipe[1] + ",9600N81,LOCAL" 19 | 20 | print("serialdev:\n io1=%s\n io2=%s" % (io1str, io2str)) 21 | 22 | io1 = alloc_io(o, io1str) 23 | io2 = alloc_io(o, io2str) 24 | 25 | print("Make sure 0xff transfers correctly") 26 | 27 | test_dataxfer(io1, io2, "a\xffx\xff\xffy") 28 | 29 | do_small_test(io1, io2) 30 | 31 | # Allow io2 to receive a serial break. 32 | try: 33 | io2.acontrol(0, gensio.GENSIO_CONTROL_SET, 34 | gensio.GENSIO_ACONTROL_SER_SET_LINESTATE_MASK, 35 | str(gensio.GENSIO_SER_LINESTATE_BREAK | 36 | gensio.GENSIO_SER_LINESTATE_PARITY_ERR), 37 | None, -1) 38 | except Exception as e: 39 | print("receive serial break not supported: " + str(e)) 40 | sys.exit(77) 41 | 42 | print("Cause a break") 43 | 44 | io2.handler.set_expected_linestate(gensio.GENSIO_SER_LINESTATE_BREAK) 45 | 46 | io2.read_cb_enable(True); 47 | 48 | io1.control(0, gensio.GENSIO_CONTROL_SET, 49 | gensio.GENSIO_CONTROL_SER_SEND_BREAK, "") 50 | 51 | if (io2.handler.wait_timeout(2000) == 0): 52 | raise Exception("Timed out waiting for serial break") 53 | print(" Success!") 54 | 55 | do_small_test(io1, io2) 56 | 57 | io_close((io1, io2)) 58 | del io1 59 | del io2 60 | del o 61 | test_shutdown() 62 | print("Success!") 63 | 64 | -------------------------------------------------------------------------------- /tests/test_serial_pipe_device.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test serial pipe device") 12 | check_pipe_dev() 13 | io1 = alloc_io(o, "serialdev," + ttypipe[0] + ",9600") 14 | io2 = alloc_io(o, "serialdev," + ttypipe[1] + ",9600") 15 | test_dataxfer(io1, io2, "This is a test string!") 16 | io_close((io1, io2)) 17 | del io1 18 | del io2 19 | del o 20 | test_shutdown() 21 | print(" Success!") 22 | -------------------------------------------------------------------------------- /tests/test_ssl_tcp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test ssl over tcp accepter connect") 12 | goterr = False 13 | try: 14 | TestAcceptConnect(o, 15 | "ssl(key=%s/key.pem,cert=%s/cert.pem,clientauth),tcp,localhost,0" 16 | % (keydir, keydir), 17 | "ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" 18 | % (keydir, keydir), 19 | "ssl(CA=%s/CA.pem),tcp,localhost," % keydir, 20 | do_small_test, 21 | expect_remclose = False) 22 | except Exception as E: 23 | s = str(E) 24 | # We can race and get either one of these 25 | if (not (s.endswith("Communication error") or 26 | s.endswith("Remote end closed connection"))): 27 | raise 28 | print(" Success checking no client cert") 29 | goterr = True 30 | if not goterr: 31 | raise Exception("Did not get error on no client certificate.") 32 | 33 | goterr = False 34 | try: 35 | TestAcceptConnect(o, 36 | "ssl(key=%s/key.pem,cert=%s/cert.pem,clientauth),tcp,localhost,0" 37 | % (keydir, keydir), 38 | "ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" 39 | % (keydir, keydir), 40 | "ssl(CA=%s/CA.pem,key=%s/clientkey.pem,cert=%s/clientcert.pem)" 41 | ",tcp,localhost," 42 | % (keydir, keydir, keydir), 43 | do_small_test, expect_remclose = False) 44 | except Exception as E: 45 | s = str(E) 46 | # We can race and get either one of these 47 | if (not (s.endswith("Communication error") or 48 | s.endswith("Remote end closed connection"))): 49 | raise 50 | print(" Success checking invalid client cert") 51 | goterr = True 52 | if not goterr: 53 | raise Exception("Did not get error on invalid client certificate.") 54 | 55 | TestAcceptConnect(o, 56 | "ssl(key=%s/key.pem,cert=%s/cert.pem,clientauth),tcp,localhost,0" 57 | % (keydir, keydir), 58 | "ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,localhost,0" 59 | % (keydir, keydir), 60 | "ssl(CA=%s/CA.pem,key=%s/clientkey.pem,cert=%s/clientcert.pem)" 61 | ",tcp,localhost," 62 | % (keydir, keydir, keydir), 63 | do_small_test, CA="%s/clientcert.pem" % keydir) 64 | 65 | del o 66 | test_shutdown() 67 | -------------------------------------------------------------------------------- /tests/test_stdio_basic.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test stdio basic echo") 12 | io = alloc_io(o, "stdio,cat", chunksize = 64) 13 | check_raddr(io, "stdio basic", 'stdio,"cat"') 14 | test_dataxfer(io, io, "This is a test string!") 15 | io_close([io]) 16 | del io 17 | del o 18 | test_shutdown() 19 | print(" Success!") 20 | 21 | -------------------------------------------------------------------------------- /tests/test_stdio_basic_stderr.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test stdio basic stderr echo") 12 | io = alloc_io(o, "stdio,sh -c 'cat 1>&2'", chunksize = 64) 13 | io.handler.ignore_input = True 14 | io.read_cb_enable(True) 15 | err = io.alloc_channel(None, None) 16 | err.open_s() 17 | check_raddr(err, "stderr basic", 'stderr,"sh" "-c" "cat 1>&2"') 18 | HandleData(o, "stderr", chunksize = 64, io = err) 19 | test_dataxfer(io, err, "This is a test string!") 20 | io_close((io, err)) 21 | del io 22 | del err 23 | del o 24 | test_shutdown() 25 | print(" Success!") 26 | -------------------------------------------------------------------------------- /tests/test_stdio_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test stdio small echo") 12 | rb = os.urandom(512) 13 | io = alloc_io(o, "stdio,cat", chunksize = 64) 14 | test_dataxfer(io, io, rb) 15 | io_close([io]) 16 | del io 17 | del o 18 | test_shutdown() 19 | print(" Success!") 20 | -------------------------------------------------------------------------------- /tests/test_tcp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test tcp accepter connect") 12 | TestAcceptConnect(o, "tcp,localhost,0", "tcp,localhost,0", "tcp,localhost,", 13 | do_small_test) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_tcp_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test tcp small") 12 | TestAccept(o, "tcp,localhost,", "tcp,localhost,0", do_small_test, chunksize = 64) 13 | del o 14 | test_shutdown() 15 | -------------------------------------------------------------------------------- /tests/test_tcp_urgent.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | def do_urgent_test(io1, io2): 12 | rb = "A" # We only get one byte of urgent data. 13 | print(" testing io1 to io2") 14 | test_dataxfer_oob(io1, io2, rb) 15 | print(" testing io2 to io1") 16 | test_dataxfer_oob(io2, io1, rb) 17 | print(" Success!") 18 | 19 | print("Test tcp urgent") 20 | TestAccept(o, "tcp,localhost,", "tcp,localhost,0", do_urgent_test, 21 | chunksize = 64, enable_oob = True) 22 | del o 23 | test_shutdown() 24 | 25 | -------------------------------------------------------------------------------- /tests/test_telnet_small.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test telnet small") 12 | TestAccept(o, "telnet,tcp,localhost,", "telnet(rfc2217=true),tcp,localhost,0", 13 | do_small_test, chunksize = 64, enable_read_io1 = True) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_telnet_tcp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test telnet over tcp accepter connect") 12 | TestAcceptConnect(o, "telnet,tcp,localhost,0", "telnet,tcp,localhost,0", 13 | "telnet,tcp,localhost,", do_small_test) 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tests/test_trace.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | import os 11 | 12 | test1 = "asdfasdf" 13 | test2 = "jkl;jkl;" 14 | 15 | tracefile1 = "asdftrace" 16 | tracefile2 = "asdftrace2" 17 | 18 | def do_small_test(io1, io2, timeout=2000): 19 | print(" testing io1 to io2") 20 | test_dataxfer(io1, io2, test1, timeout = timeout) 21 | print(" testing io2 to io1") 22 | test_dataxfer(io2, io1, test2, timeout = timeout) 23 | 24 | print("Test trace") 25 | try: 26 | os.remove(tracefile1) 27 | except: 28 | pass 29 | try: 30 | os.remove(tracefile2) 31 | except: 32 | pass 33 | 34 | TestAccept(o, 35 | "trace(file=" + tracefile1 + ",dir=both,raw=yes),tcp,localhost,", 36 | "trace(file=" + tracefile2 + ",dir=both,raw=yes),tcp,localhost,0", 37 | do_small_test, chunksize = 64) 38 | 39 | f = open(tracefile1) 40 | s = f.read() 41 | f.close() 42 | if s != test1 + test2: 43 | raise Exception("Trace 1 data didn't match, expected %s, got %s" % ( 44 | test1 + test2, s)) 45 | 46 | f = open(tracefile2) 47 | s = f.read() 48 | f.close() 49 | if s != test1 + test2: 50 | raise Exception("Trace 1 data didn't match, expected %s, got %s" % ( 51 | test1 + test2, s)) 52 | 53 | os.remove(tracefile1) 54 | os.remove(tracefile2) 55 | del o 56 | test_shutdown() 57 | print(" Success!") 58 | -------------------------------------------------------------------------------- /tests/test_udp_accept_connect.py: -------------------------------------------------------------------------------- 1 | # 2 | # gensio - A library for abstracting stream I/O 3 | # Copyright (C) 2018 Corey Minyard 4 | # 5 | # SPDX-License-Identifier: GPL-2.0-only 6 | # 7 | 8 | from utils import * 9 | import gensio 10 | 11 | print("Test udp accepter connect") 12 | TestAcceptConnect(o, "udp,localhost,0", "udp,localhost,0", "udp,localhost,", 13 | do_small_test, io1_dummy_write = "A") 14 | del o 15 | test_shutdown() 16 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | # binaries 2 | gensiot 3 | gmdns 4 | greflector 5 | gsound 6 | gtlssh 7 | gtlssh-keygen 8 | 9 | # generated 10 | gtlsshd.service 11 | -------------------------------------------------------------------------------- /tools/gagwpe.1: -------------------------------------------------------------------------------- 1 | .TH gagwpe 1 01/02/19 "An AGWPE server using gensio" 2 | 3 | .SH NAME 4 | gensio \- An AGWPE server using gensio 5 | 6 | .SH SYNOPSIS 7 | .B gagwpe [options] io 8 | 9 | .SH DESCRIPTION 10 | The 11 | .BR gagwpe 12 | program AX25 connection to be made using a network connection specified in the 13 | .I io 14 | parameter. 15 | 16 | For a description of how to specify a gensio, see the gensio documentation. 17 | 18 | .SH OPTIONS 19 | .TP 20 | .I "\-p|\-\-listenport " 21 | By default the program listens on 22 | .BR tcp,7001 23 | but this parameter allows the listen port to be overridden. 24 | .TP 25 | .I \-\-version 26 | Print the version number and exit. 27 | .TP 28 | .I \-h|\-\-help 29 | Help output 30 | 31 | .SH "SEE ALSO" 32 | gensio(5) 33 | 34 | .SH "KNOWN PROBLEMS" 35 | None. 36 | 37 | .SH AUTHOR 38 | .PP 39 | Corey Minyard 40 | -------------------------------------------------------------------------------- /tools/greflector.1: -------------------------------------------------------------------------------- 1 | .TH greflector 1 01/02/19 "A program for reflecting data to all connected" 2 | 3 | .SH NAME 4 | greflector \- A program that will reflect data to all connections 5 | 6 | .SH SYNOPSIS 7 | .B greflector [-c] [-t] [ [...]] 8 | 9 | .SH DESCRIPTION 10 | The 11 | .B greflector 12 | program accepts gensio connections on the given accepters. For all 13 | connections, if data comes in, it will send that data out to all other 14 | connections. 15 | 16 | This is useful for debugging. For instance, if you wanted to simulate 17 | an AX25 KISS TNC connection and the air connecting them, and you wanted to 18 | observe the data, you could do: 19 | .IP 20 | $ greflector -t kiss,tcp,1234 21 | .PP 22 | 23 | If you want to make a connection instead of accept a connection, use 24 | the 25 | .B conacc 26 | gensio. See gensio(5) for details. 27 | 28 | .SH OPTIONS 29 | .TP 30 | .I \-c 31 | When all connections have closed, shut down the reflector. 32 | .TP 33 | .I \-t 34 | Trace all connections and incoming data to stdout. 35 | 36 | .SH "SEE ALSO" 37 | gensio(5) 38 | 39 | .SH "KNOWN PROBLEMS" 40 | None. 41 | 42 | .SH AUTHOR 43 | .PP 44 | Corey Minyard 45 | -------------------------------------------------------------------------------- /tools/gsound.1: -------------------------------------------------------------------------------- 1 | .TH gsound 1 15 Aug 2022 "Tool for doing sound I/O" 2 | 3 | .SH NAME 4 | gsound \- Tool for doing sound I/O using the sound gensio 5 | 6 | .SH SYNOPSIS 7 | .B gsound 8 | [\-r|\-\-rate num] [\-n|--nbufs num] [\-c|\-\-channels num] 9 | [\-s|\-\-bufsize num] [\-t|\-\-type num] [\-f|\-\-format str] 10 | [\-p|\-\-play] [\-L|\-\-list\-devs] [\-d|\-\-debug] [\-h|\-\-help] 11 | [] 12 | 13 | .SH DESCRIPTION 14 | The 15 | .BR gsound 16 | program allows you to record/play sound to/from the given sound device. 17 | Sound data goes to/from file, or stdio if the file isn't given. 18 | 19 | .SH OPTIONS 20 | .TP 21 | .I "\-r|\-\-rate num" 22 | The sample rate, defaults to 44100. 23 | .TP 24 | .I "\-n|\-\-nbufs num" 25 | The number of buffers, defaults to 4. 26 | .TP 27 | .I "\-c|\-\-channels num" 28 | The number of channels, defaults to 1. 29 | .TP 30 | .I "\-s|\-\-bufsize num" 31 | The number of buffer size, defaults to 2048. 32 | .TP 33 | .I "\-t|\-\-type num" 34 | The interface type, either alsa (Linux), win (Windows), portaudio 35 | (generally MacOS) or file. Default to alsa, win, or portaudio 36 | depending on the platform. 37 | .TP 38 | .I "\-f|\-\-format str" 39 | The I/O format. Default to float. May be one of double, float, 40 | int32, int24, int16, or int8 41 | .TP 42 | .I "\-p|\-\-play" 43 | Playback data from stdin. The default is to record data to stdout. 44 | .TP 45 | .I "\-L|\-\-list\-devs" 46 | List available devices and exit. 47 | .TP 48 | .I "\-d|\-\-debug" 49 | Enable debug. Specify more than once to increase the debug level 50 | .TP 51 | .I "\-h|\-\-help" 52 | Help 53 | 54 | .SH "SEE ALSO" 55 | gensio(5) 56 | 57 | .SH "KNOWN PROBLEMS" 58 | None. 59 | 60 | .SH AUTHOR 61 | .PP 62 | Corey Minyard 63 | -------------------------------------------------------------------------------- /tools/gtlsshd.pam: -------------------------------------------------------------------------------- 1 | # PAM configuration example for gtlsshd 2 | 3 | # Standard Un*x authentication. 4 | @include common-auth 5 | 6 | # Do your 2-factor authentication. This is just a dummy one, you will 7 | # need to get your own. An example is in the gtlssh tools directory. 8 | #auth required pam_2factor_dummy.so 9 | 10 | # gtlsshd does /etc/nologin on its own. 11 | 12 | # Uncomment and edit /etc/security/access.conf if you need to set complex 13 | # access limits. 14 | # account required pam_access.so 15 | 16 | # Standard Un*x authorization. 17 | @include common-account 18 | 19 | # SELinux needs to be the first session rule. This ensures that any 20 | # lingering context has been cleared. Without this it is possible that a 21 | # module could execute code in the wrong domain. 22 | session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close 23 | 24 | # Set the loginuid process attribute. 25 | session required pam_loginuid.so 26 | 27 | # Create a new session keyring. 28 | session optional pam_keyinit.so force revoke 29 | 30 | # Standard Un*x session setup and teardown. 31 | @include common-session 32 | 33 | # Print the message of the day upon successful login. 34 | # This includes a dynamically generated part from /run/motd.dynamic 35 | # and a static (admin-editable) part from /etc/motd. 36 | session optional pam_motd.so motd=/run/motd.dynamic 37 | session optional pam_motd.so noupdate 38 | 39 | # Print the status of the user's mailbox upon successful login. 40 | session optional pam_mail.so standard noenv # [1] 41 | 42 | # Set the lastlog entry. gtlsshd depends on pam to do this. 43 | session optional pam_lastlog.so 44 | 45 | # Set up user limits from /etc/security/limits.conf. 46 | session required pam_limits.so 47 | 48 | # Read environment variables from /etc/environment and 49 | # /etc/security/pam_env.conf. 50 | session required pam_env.so # [1] 51 | # In Debian 4.0 (etch), locale-related environment variables were moved to 52 | # /etc/default/locale, so read that as well. 53 | session required pam_env.so user_readenv=1 envfile=/etc/default/locale 54 | 55 | # SELinux needs to intervene at login time to ensure that the process starts 56 | # in the proper default security context. Only sessions which are intended 57 | # to run in the user's context should be run after this. 58 | session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open 59 | 60 | # Standard Un*x password updating. 61 | @include common-password 62 | -------------------------------------------------------------------------------- /tools/gtlsshd.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Remote login daemon from gtlssh 3 | Requires=network.target 4 | Documentation=man:gtlsshd(8) 5 | 6 | [Service] 7 | Type=simple 8 | EnvironmentFile=@gtlsshddefault@ 9 | ExecStart=@gtlsshdbindir@/gtlsshd --nodaemon $gtlsshdflags 10 | StandardOutput=null 11 | Restart=on-failure 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /tools/gtlssync: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rsync --rsh=gtlssh $@ -------------------------------------------------------------------------------- /tools/gtlssync.1: -------------------------------------------------------------------------------- 1 | .TH gtlssync 1 01/02/19 "Run rsync over gtlssh" 2 | 3 | .SH NAME 4 | gtlssync \- A wrapper for running rsync over gtlssh 5 | 6 | .SH SYNOPSIS 7 | .B gtlssync [rsync options] 8 | 9 | .SH DESCRIPTION 10 | The 11 | .B gtlssync 12 | program simple wraps 13 | .B rsync 14 | to use 15 | .B gtlssh 16 | as the transport. 17 | .B rsync 18 | is not described here, see rsync(1) for the options. 19 | 20 | .SH "SEE ALSO" 21 | rsync(1) gtlssh(1) 22 | 23 | .SH "KNOWN PROBLEMS" 24 | None. 25 | 26 | .SH AUTHOR 27 | .PP 28 | Corey Minyard 29 | -------------------------------------------------------------------------------- /tools/localports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * localport - A library for handling local gensio connections to mux channel 3 | * Copyright (C) 2019 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: GPL-2.0-only 6 | * 7 | * In addition, as a special exception, the copyright holders of 8 | * gensio give you permission to combine gensio with free software 9 | * programs or libraries that are released under the GNU LGPL and 10 | * with code included in the standard release of OpenSSL under the 11 | * OpenSSL license (or modified versions of such code, with unchanged 12 | * license). You may copy and distribute such a system following the 13 | * terms of the GNU GPL for gensio and the licenses of the other code 14 | * concerned, provided that you include the source code of that 15 | * other code when and as the GNU GPL requires distribution of source 16 | * code. 17 | * 18 | * Note that people who make modified versions of gensio are not 19 | * obligated to grant this special exception for their modified 20 | * versions; it is their choice whether to do so. The GNU General 21 | * Public License gives permission to release a modified version 22 | * without this exception; this exception also makes it possible to 23 | * release a modified version which carries forward this exception. 24 | */ 25 | 26 | #ifndef LOCALPORTS_H 27 | #define LOCALPORTS_H 28 | 29 | #include 30 | #include 31 | 32 | struct local_ports; 33 | 34 | struct local_ports *alloc_local_ports(struct gensio_os_funcs *o, 35 | void (*localport_err)(void *cb_data, 36 | const char *format, 37 | va_list ap), 38 | void *cb_data); 39 | 40 | void free_local_ports(struct local_ports *p); 41 | 42 | void start_local_ports(struct local_ports *p, struct gensio *user_io); 43 | 44 | int add_local_port(struct local_ports *p, 45 | const char *gensio_str, const char *service_str, 46 | const char *id_str); 47 | 48 | void remote_port_new_con(struct local_ports *p, struct gensio *io, 49 | const char *connecter_str, char *id_str); 50 | 51 | #endif /* LOCALPORTS_H */ 52 | -------------------------------------------------------------------------------- /tools/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gensiotools - General tools using gensio 3 | * Copyright (C) 2018 Corey Minyard 4 | * 5 | * SPDX-License-Identifier: GPL-2.0-only 6 | * 7 | * In addition, as a special exception, the copyright holders of 8 | * gensio give you permission to combine gensio with free software 9 | * programs or libraries that are released under the GNU LGPL and 10 | * with code included in the standard release of OpenSSL under the 11 | * OpenSSL license (or modified versions of such code, with unchanged 12 | * license). You may copy and distribute such a system following the 13 | * terms of the GNU GPL for gensio and the licenses of the other code 14 | * concerned, provided that you include the source code of that 15 | * other code when and as the GNU GPL requires distribution of source 16 | * code. 17 | * 18 | * Note that people who make modified versions of gensio are not 19 | * obligated to grant this special exception for their modified 20 | * versions; it is their choice whether to do so. The GNU General 21 | * Public License gives permission to release a modified version 22 | * without this exception; this exception also makes it possible to 23 | * release a modified version which carries forward this exception. 24 | */ 25 | 26 | #ifndef GENSIOTOOL_UTILS_H 27 | #define GENSIOTOOL_UTILS_H 28 | #include 29 | #include 30 | 31 | int strtocc(const char *str, int *rc); 32 | int cmparg(int argc, char *argv[], int *arg, char *sarg, char *larg, 33 | const char **opt); 34 | int cmparg_int(int argc, char *argv[], int *arg, char *sarg, 35 | char *larg, int *rc); 36 | int cmparg_uint(int argc, char *argv[], int *arg, char *sarg, 37 | char *larg, unsigned int *rc); 38 | char *alloc_sprintf(const char *fmt, ...); 39 | char *alloc_vsprintf(const char *fmt, va_list ap); 40 | 41 | bool strstartswith(const char *str, const char *cmp); 42 | 43 | #if defined(_WIN32) 44 | bool can_do_raw(void); 45 | #elif defined(HAVE_ISATTY) 46 | # include 47 | # define can_do_raw() isatty(0) 48 | #else 49 | # define can_do_raw() false 50 | #endif 51 | 52 | #endif /* GENSIOTOOL_UTILS_H */ 53 | --------------------------------------------------------------------------------