RE: Get name and ip-address for each interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: linux-net-owner@xxxxxxxxxxxxxxx 
> [mailto:linux-net-owner@xxxxxxxxxxxxxxx] On Behalf Of grimson
> Sent: Wednesday, April 15, 2009 7:02 AM
> To: linux-net@xxxxxxxxxxxxxxx
> Subject: Re: Get name and ip-address for each interface
> 
> So far I learned that the information Im looking for, is the interface
> index.
> If I receive a message on one of my interfaces I can receive 
> it with UDP
> (oh yes I forgot to tell you that I have to use UDP) function recvfrom
> or better "recvmsg".
> 
> With recvmesg I do not only receive a message from any 
> client, but also
> get back a filled "struct cmsghdr" (which I have to 
> initialize first, of
> course).
> 
> I got this information from Steven's Unix Network Programming. Amongst
> the data I get back from a filled "struct cmsghdr" is also 
> the interface
> index of my interface. Exactly what Im searching for.
> _BUT_ Unfortunally I get this information only if the symbol
> "HAVE_MSGHDR_MSG_CONTROL" is defined. And this is not the case on my
> system. Please correct me, if I did not unterstand this matter!
> So what can I do to get that symbol defined?  For owner of this book,
> its on page 588-592.
> 
> It would be great if anybody could help me at this point.
> 
> Sincerely Chris
> 
> grimson schrieb:
> > Hello out there,
> > I got an interesting but challenging problem.
> > I want to create a daemon-process, which runs on a host with several
> > NICs. If the daemon gets a request from one of the interfaces, it
> > should, amongst others, send back the IP-address and/or MAC-address,
> > interface-name... of the interface from which the request 
> came. And only
> > of that interface. No infos about local-interfaces and so on.
> >
> > My approach so far was to invoke ioctl with the 
> SIOCGIFCONF-request and
> > collect all informations about every active interface on 
> the host. But I
> > need at least one unique identifier of the interface from which the
> > request came. With the interface-name for exeample I can call the/
> > /SIOCGIFADDR-request to get the IP-address.  How can I achive this.
> >
> > Has anybody an idea.
> >
> > Thanks in advance.
> >

One alterative to the approach you are taking which might get you what
you want might be to create several sockets, one bound to each network
interface/IP address you want to do this on.

Then when you receive a packet on one of these sockets, you know which
interface it came in on from the socket descriptor and can respond
appropriately.

Just a thought,

Jeff Haran
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux