This is not a programming question, but a question about NetBSD.
Linux, FreeBSD and OpenBSD have mutually exclusive but similar interfaces to allow binding the local end of a connection to an address that is not present on any local interface. E.g. make a connection from 8.8.8.8. I've been poking around without success in NetBSD to see if there is something to the same effect there. Is there?
Here's (my) sample code, for reference:
https://github.com/UlricE/pen/blob/master/server.c
Function spoof_bind, line ~250.
Greatly simplified examples to illustrate the concept:
Linux:
setsockopt(upfd, SOL_IP, IP_TRANSPARENT, &one, sizeof one);
bind(upfd, (struct sockaddr *)&addr, sizeof addr);
FreeBSD:
setsockopt(upfd, IPPROTO_IP, IP_BINDANY, &one, sizeof one);
bind(upfd, (struct sockaddr *)&addr, sizeof addr);
OpenBSD:
setsockopt(upfd, SOL_SOCKET, SO_BINDANY, &one, sizeof one);
bind(upfd, (struct sockaddr *)&addr, sizeof addr);
Again, this is not a programming question but a question whether such an interface exists on NetBSD.