C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 12-22-2009, 02:38 AM   #1
Registered User
 
Join Date: Dec 2009
Posts: 1
Specific ether type with raw socket under linux

Hello,
I'm trying to specify ether type when opening a raw socket. I've already done it under Windows and MacOSX but dunno how to do it under Linux.
Under MacOSX, I'm using:
Code:
struct ndrv_protocol_desc desc;
struct ndrv_demux_desc demux_desc[1];

/*... some code to create the socket and bind the socket to the selected network interface ...*/

bzero(&desc, sizeof(desc));
bzero(&demux_desc, sizeof(demux_desc));

desc.version = NDRV_PROTOCOL_DESC_VERS;
desc.protocol_family = NDRV_DEMUXTYPE_ETHERTYPE;
desc.demux_count = (u_int32_t)1;
desc.demux_list = (struct ndrv_demux_desc*)&demux_desc;

demux_desc[0].type = NDRV_DEMUXTYPE_ETHERTYPE;
demux_desc[0].length = sizeof(demux_desc[0].data.ether_type);
demux_desc[0].data.ether_type = MY_ETHER_TYPE;
if (setsockopt( fd, SOL_NDRVPROTO, NDRV_SETDMXSPEC, (caddr_t)&desc, sizeof(desc))) {
  /*failed, perform some cleanup and leave function*/
}
/*succeed, get mac address and other stuff then leave function*/
What would be the equivalent under Linux ?

Thanks,

SinaC
sinacbe is offline   Reply With Quote
Old 12-25-2009, 08:04 AM   #2
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
ndrv.h?

Mate this looks like something that is Apple-specific; I (and probably anybody) can get you there using BSD sockets (which AFAIK OS/X supports) and is more portable than the Apple-specific API it seems like you are using...Google for Beej's Networking how-to and you will find a method that will/should work on both platforms but probably not Windows w/o a lot of #ifdefs to block out the platform-specific code...but now we are talking about a whole other discipline in code, cross-platform development which could fill volumes...

Peace and Happy Holidays...

J.
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass a matrix/array from main to a function Inukami C Programming 7 12-09-2009 09:03 PM
LDAP Query Travoiz C++ Programming 0 08-13-2009 02:58 PM
Question on l-values. Hulag C++ Programming 6 10-13-2005 04:33 PM
Dynamic array of pointers csisz3r C Programming 8 09-25-2005 02:06 PM
Problem with Visual C++ Object-Oriented Programming Book. GameGenie C++ Programming 9 08-29-2005 11:21 PM


All times are GMT -6. The time now is 12:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22