Over a million developers have joined DZone.

Internet Programming on an ARM Guest

DZone's Guide to

Internet Programming on an ARM Guest

Getting network programming working in embedded Linux used to be a pain. Not anymore. See cross-compiling in action when using an ARM QEMU guest.

· IoT Zone ·
Free Resource

Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More

Okay, so there are a couple of ways you can run networking on an ARM QEMU guest. The easiest is via SLIRP, the default user mode networking. It's slow and chatty, but for most IoT work, that's okay. There are alternative, higher performance approaches, but they hijack your local interface to the virtual bridge, removing networking from your host. This is fine, sometimes, but not that frequently. It's a real pain to work with if you're using it day-to-day, but handy for late-stage testing. Anyway, we're not going to use that. We'll use SLIRP instead.

Okay, first, use buildroot to configure an ARM image that includes libcurl. Using our previous buildroot configuration, just go to Target packages -> Libraries -> Networking, and select libcurl:

Image title

Go ahead and select the binary, too. This is handy for connectivity testing.

Now make your new image, and spin it up with QEMU, like we did in my previous article. You'll need to configure it with a new user too. Then test your internet connectivity:

Image title

Curl is especially useful for this when you're running in SLIRP mode because ICMP traffic (i.e. ping) isn't really supported (you can turn it on, but there's really no need, and it's kind of a hassle).

Now, build your ARM program from the previous article, using the IP address of your host. Remember, the QEMU command we use redirects host port 2222 to guest port 22, so you need to take this into account when you SCP the executable over:

$ scp -P 2222 test <username>@localhost:~/
<username>@localhost's password: 
test        100% 7204     7.0KB/s   00:00

Now, when you compiled the test program, you inserted the host IP address, right? Of course you did. Now, spin up Python's SimpleHTTPServer on your host, and run the test program on your guest:

Image title

Here, you can see my session on the guest on the left, where I ran the test program. The output is the directory listing, HTML-ized. On the right, you can see the GET request recorded in the SimpleHTTPServer session. You can also see all my tmux goodness, but you can ignore that.

Anyway, that's all there is to it! You've successfully run your first ARM cross-compiled networking program!

Digi-Key’s IoT Component Selector is your one-stop-shop for the IoT

qemu ,arm ,cross-compile ,iot ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}