5 ms·
> The specific task is so obscure, that only a language as widespread as C would have an example online for it. Well you could do it in Python I suppose - here
by nineteen999 7y ago
> The specific task is so obscure, that only a language as widespread as C would have an example online for it.
Well you could do it in Python I suppose - here's someone mentioning a solution using scapy, although it likely wouldn't work too well for my particular case due to Python performance.
https://stackoverflow.com/questions/51311741/generating-a-spoofed-udp-packet-in-python https://stackoverflow.com/questions/51311741/generating-a-sp...
> So people are confused when you name this as a criteria for selecting a language, since it’s a criteria that most likely only C can satisfy
Rust is intended to be a replacement for C and C++, no? Eventually it will need to be able to do things like this if it is to be effective in that role. It's OK in my mind if it is not mature enough to do these kind of tasks yet, or if it can but I can't find a good reference yet. I wanted to use it for this task, but I selected C instead since it was easy to do that way and I didn't have a lot of time. Not holding it against Rust, it's a much younger language.
> Then someone jumped to the conclusion that you were actually saying that Rust doesn’t have enough low level kernel APIs because that would make sense.
I am almost completely certain I don't understand this sentence the way it is phrased.
- woah 7y agoExample code (for ARP though): https://github.com/libpnet/libpnet/blob/master/examples/arp_packet.rs https://github.com/libpnet/libpnet/blob/master/examples/arp_... Documentation: https://docs.rs/pnet/0.22.0/pnet/packet/udp/struct.MutableUdpPacket.html https://docs.rs/pnet/0.22.0/pnet/packet/udp/struct.MutableUd...
- nineteen999 7y agoThanks for this, those do look very helpful.
- rixed 7y agoIn case you want to give OCaml a try one day, I've done plenty of stuff like that in the past when I needed a (much) faster scappy. UDP exemple here: https://github.com/rixed/robinet/blob/master/udp.ml https://github.com/rixed/robinet/blob/master/udp.ml
- nineteen999 7y agoI'm not really a career programmer or language enthusiast, rather, I'm more of a utilitarian/imperative coder - I write programs to plug gaps in existing infrastructure as quickly, as securely, and as future-proofed as possible, even if it means dumbing the code down somewhat. So I think my head would explode if I tried to learn a FP language without being able to have months off work to study. In addition to that, my team would kill me, as it's hard enough to find good C/C++ programmers in my city, let alone something like OCaml. Given that we run emergency services infrastructure, unfortunately we have to use more popular languages to ensure that the business doesn't end up with a lot of code written in languages they can't support. Regardless, thank you very much for the example. It's nice to see that this can be done in other languages even if I can't understand it. Unfortunately too many years of C/C++ have made it hard for me to grok FP code - the C example I posted up before is much more readable to me.
- ernst_klim 7y ago> So I think my head would explode if I tried to learn a FP language without being able to have months off work to study. What's so hard you find about OCaml or FP in general you haven't had to deal with in your day-to-day imperative programming? > Unfortunately too many years of C/C++ You mean you find OCaml making your head to explode after years of C and C++?
- nineteen999 7y ago> What's so hard you find about OCaml or FP in general you haven't had to deal with in your day-to-day imperative programming? I guess I still find FP very abstract as a concept. I'm starting to like the notion of immutability as a design goal. But then I'm the kind of sicko who enjoys assembly language to some degree, where practically every instruction has a side effect, whether it be assigning a value to a register, or setting a bit in a flag register, or doing I/O whether port mapped or memory mapped. > You mean you find OCaml making your head to explode after years of C and C++? Not specifically OCaml, but most FP languages in general. I find the OCaml code posted up a couple of levels to be very hard to understand. But I'm very used to the POSIX interface and honestly programming against much else tends to get me out of my comfort zone a little too much. Shell, Perl and Python I can manage as well because I've been doing them so long, but I don't excel at those, particularly the latter two. I think the paper referenced in this (https://news.ycombinator.com/item?id=15179188 https://news.ycombinator.com/item?id=15179188) HN article ("Some were meant for C") captures my mindset very well. Some of us are just a bit broken as programmers. I also enjoy the ubiquity of C compilers - knowing that I can program in it from anything from a microcontroller to a multicore CPU (even being able to use the same compiler version accross many platforms) is a huge boost.