UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#26 2013-11-25 01:52 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Linux

Rob your a genius, look what good old google returns after more digging: http://developerweb.net/viewtopic.php?id=5085 your answer gives all I need to know, as always thank you for sharing!

Robseace wrote:

Waste of a getaddrinfo() call...  There's already a predefined macro for the limited broadcast address: INADDR_BROADCAST...

Does that go for INADDR_ANY Aswell then, since bind() fills it in for you ?

Edit: Ignore that, yes it does, getaddrinfo() simply returns a single node filled with INADDR_ANY, or a second node filled in with in6addr_any depending on AF_XXX

Jesus this site really is a candy shop for network enthusiasts!!!! And I'm starving hungry for this knowledge!!!!
Guys knowing the theory is one thing, but putting into practise which you guys do on a daily bases is two completely different things!!!! ;-)

Edit: Interestingly setsockopt(SO_BINDTODEVICE) only works with eth0, with wlan0 it fails with no such device... which is odd

Last edited by RipRage (2013-11-25 07:38 PM)

Offline

#27 2013-11-25 08:15 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Linux

Edit: Interestingly setsockopt(SO_BINDTODEVICE) only works with eth0, with wlan0 it fails with no such device... which is odd

What are you passing as a length to the setsockopt() call?  It should be the strlen() of the device name, so in the case of "wlan0", 5...  If you're doing something like sizeof(char*) or something, you might be getting just 4 (on 32-bit), which would be enough to allow "eth0" to work, but fail for a longer device name...  (Note: some sources out there show that you should pass a whole ifreq struct, but that's just plain wrong...  It only happens to work because the device name is the first field in that struct...  But, all SO_BINDTODEVICE really wants is a string name...)

Offline

#28 2013-11-26 10:46 AM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Linux

Yeah I figured that was the case, although it doesn't specifically say that in the documentation, in fact, thinking about this since setsockopt(SO_BINDTODEVICE) is the simplest way to handle DHCP, it's certainly not a portable option, I know that windows doesn't support it (there arsenal of socket options is indeed very limited compared to unix type systems, I believe there's a hack sound for ipv6 only) which leaves me thinking how they hell they get around it, as you mention in your post above, binding to INADDR_ANY will allow you to receive inbound traffic on all interfaces but won't do much in the way of outbound, pulling the interface list isn't going to help since the interface of interested will not be addressed...

Last edited by RipRage (2013-11-26 01:42 PM)

Offline

#29 2013-11-26 02:03 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Linux

It may be that the interface just needs to be brought up before you can bind to it...  Ie: "ifconfig wlan0 up"...  Or ioctl(SIOCSIFFLAGS) with IFF_UP specified as one of the flags...

Offline

#30 2013-11-26 02:15 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Linux

Sorry Rob, yes its working as aspected, my question simple put, how can one broadcast over an interface which hasn't been addressed and in addition, does not have setsockopt(SO_BINDTODEVICE) option, any ideas?

Edit: perhaps IP_PKTINFO with ipi_ifindex pointing to the naked interface and using sendmsg() ? Mind I think that's only a linux thing...

Last edited by RipRage (2013-11-26 02:35 PM)

Offline

#31 2013-11-26 08:50 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Linux

It's one of those things where you're probably going to have a bunch of system-specific code, because every system is doing their own thing without standardizing...  Linux has SO_BINDTODEVICE and IP_PKTINFO, I believe FreeBSD has IP_RECVIF and IP_SENDIF, and who the hell knows what Windows has!  Probably the most portable alternative would be using something like libnet to send out fully manually constructed raw packets and libpcap to sniff the replies...  Ugly as hell, but any other solution that needs to work on multiple systems would be pretty ugly too...

Offline

#32 2013-11-27 01:34 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Linux

Yeah I thought that's where the raw socket trickery comes into play, thanks for your time Rob, from reading various sources it seems you have to use raw sockets anyway if the dhclient daemon is running any traffic will be passed to that instead of my application, I was trying to simply come up with a way of auto diagnosing that particular fault, as it is something that can happen, and which my program can put right by either excuting the dhclient or making the program handle it by itself (certainly the more interesting option ;-) )

Edit: Here's an interesting thought, although not a nice way of doing things but it could be a more portable option (excluding packet capture libraries), how about temporally bringing down all interfaces apart from the one of interest, and then sending to the global broadcast address, would that guarantee to leave the interface of Interest? Ill try it out and report back...

Last edited by RipRage (2013-11-27 03:42 PM)

Offline

#33 2016-02-16 01:44 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Linux

Since the spam-bots keep reviving this particular thread for some reason, I figure I might as well post a legit reply related to the earlier talk of gaming...  I did end up buying one of the Alienware Steam Machines, and that's currently my main gaming rig...  I got in early, so things weren't always smooth sailing, and even now they're still making new updates to things just about every weekend I turn it on, but I'm mostly happy with it, and am constantly delighted every time I find a game I enjoy has native SteamOS/Linux support...  I've bought more games on Steam in the past few months than I've probably ever bought previously in my whole life!  Though, I've mostly spent my time replaying games I've already played through previously on XBox360...  Any new-to-me games have mostly been quirky indie type games that don't grab me enough to keep me playing...  And, I have no idea what I'll end up doing when the next big game I want to play comes out...  Eg: a new GTA...  Since none of the existing GTAs has a SteamOS release (though, we do have the very fun GTA-style Saints Row IV, which I've been mostly playing lately!), I doubt a new one will get one either, and that may push me to get a PS4 or XB1, though I would hope to just supplement rather than replace the Steam Machine if so...  But, I keep hoping these Steam Machines gain enough popularity to convince more and more companies to release their games on SteamOS, so maybe by the time a new GTA does roll around, it could happen...

Offline

Board footer

Powered by FluxBB