Porting cmsg, rtnetlink, etc. macros to Go

73 views
Skip to first unread message

Albert Strasheim

unread,
Oct 6, 2010, 9:17:40 AM10/6/10
to golang-dev
Hello all

I have been working on some server code that integrates with Linux.
I've explored some of the lesser used parts of UNIX and Netlink
sockets.

With UNIX sockets, one sends ancillary messages with the sendmsg/
recvmsg syscalls (my attempt at adding them to Go is CL 2331044).

glibc provides a bunch of macros (documented in the cmsg(3) manual
page) for constructing these ancillary messages.

Similarly, there are various parts of Linux that are accessed through
Netlink sockets.

Here, the kernel headers contain a bunch of macros (documented in
netlink(3), rtnetlink(3), etc.) for constructing the messages.

Does anybody have any thoughts on some kind of semi-automatic way to
translate these macros for use in Go (maybe using 8c/6c)? I would
dearly like to avoid rewriting them by hand.

Regards

Albert

Russ Cox

unread,
Oct 6, 2010, 10:07:00 AM10/6/10
to Albert Strasheim, golang-dev
I don't think you have much of a choice here
but to write them by hand. Welcome to the
horrible interface that is BSD networking,
as performed by Linux.

What do other languages do?

Russ

Albert Strasheim

unread,
Oct 6, 2010, 10:50:17 AM10/6/10
to Russ Cox, golang-dev
Hello

I googled a bit for cmsg.

For Python's multiprocessing module, everything happens in C code.

In Android, there is some C code inside a JNI library.

Most other code dealing with cmsg is written in C.

A pattern is starting to emerge...

Wrapping these macros in C functions and using Cgo seems like a nice
solution to me, except that is is going to make the net package depend
on a cgo stub library, which, as you noted before, isn't pretty.

How is your work on cgo without stubs going?

http://groups.google.com/group/golang-dev/browse_thread/thread/ab5654086bad92c5

Regards

Albert

Russ Cox

unread,
Oct 6, 2010, 11:15:13 AM10/6/10
to Albert Strasheim, golang-dev
> How is your work on cgo without stubs going?

It's going to happen, but not today.

Russ

Reply all
Reply to author
Forward
0 new messages