1. 15
  1.  

  2. 21

    Prob better to just modernize the existing C. net-tools shouldn’t have to depend on the installation of a python environment.

    1. 2

      Python can be compiled to native executables with Nuitka or Shedskin.

      1. 15

        Which link against libpython…

        1. 2

          C applications on Linux all depends on shared libraries. Installing a small .so file alongside with the executable should be acceptable, IMO.

          And Shedskin compiles directly to C++.

          1. 0

            An Internet search tells me you still need a python environment to use shedskin and that it only supports python 2.4-2.6.

            1. 1

              No, once you compile/transpile the Python application to C++, the resulting application does not need Python.

              There is also a project named Grumpy, for compiling/transpiling Python to Go. Once that is done, Python is not needed for those executables either. Google used Grumpy to convert the Python code used to run YouTube, from Python to Go.

              1. 2

                I learn something new everyday. Thanks!

    2. 16

      90s C code has plenty of weird properties, but the strangest is an absolute refusal to use proper indentation combined with a massive lack of visual whitespace.

      I do not believe that is actually an essential property of 90s C code.

      1. 2

        And more to the point, I can see pretty clear reasons within the excerpt as to why it’s formatted that way. I probably wouldn’t have written it that way, but it’s not nearly as terrible as the author is trying to make it sound.

        Yes, the lack of indentation under the while loop makes it harder to see what’s contained in the loop. But digging up the actual source, it’s pretty clear that the method in question is basically a little “pre-work”, a “main loop”, and a little “post-work”. The version I linked actually indents the loop body, but it’s not necessary indentation, even for readability.

        I’m a C incompetent, and this code doesn’t particularly bother me.

        Edit: the second excerpt is honestly annoying, as it indents things more than it should, which is the opposite of the first block, which didn’t indent very much at all.

      2. 6
        1. 1

          So literally the only thing I ever use netstat for is showing listening network ports with: netstat -luntp. I’ve tried to get the same output with ss, but this is the closest I’ve come: ss -lpf inet and ss -lpf inet6. It seems that “inet” and “inet6” are mutually exclusive. Short of shell trickery, is there any way to get both in one command?

          1. 1

            Do you mean the explicit notation of tcp6 and udp6?

            shanssian:~ $ sudo netstat -tulpn | awk '{print $1}' | grep '.*6'
            tcp6
            udp6
            udp6
            udp6
            udp6
            shanssian:~ $ sudo ss -tulpn | awk '{print $1}' | grep '.*6'
            shanssian:~$
            

            It looks like for ss you kinda have to guess based on the format of Local Address:Port

        2. 5

          tl;dr: the underlying data is available under /proc and they wrote some Python to traverse those directories and symlinks.

          1. 1

            I wonder if a posix env for webasm would be a good way to upgrade C utilities like this with more security.

            1. 1

              No. Python interpreter startup time is too slow for these tools. The amount of wasted CPU time worldwide from scripts, monitoring tools, etc executing these commands rewritten as python is simply unforgivable.

              1. 1

                I install glances on every physical host and most of the VMs I manage. It does have quite a few dependencies but almost all of them are optional depending on what you need. It works great. Its one of the first things I go to when troubleshooting a problem. Speed is literally not an issue.