Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

send message through socket?

Now I want to write a server - client program to send message between them. I want to use SOCK_RAW and IPPROTO_RAW to send so I don't want to use TCP/IP protocol. At server-side, I use libpcap to capture packet from the client. And I have two questions:
1. In sendto() function, there's parameter "const struct sockaddr *to", if I just want to send to a defined Mac address (ignore the IP address), what info I must supply here?
2. In case we broadcast the message, there're 2 network interface cards, how can I choose exactly what NIC will send out the message, other one will not send out any.

Thanks for your answers.
0
newbie_tw
Asked:
newbie_tw
3 Solutions
 
ahoffmannCommented:
> .. how can I choose exactly what NIC will send out the message
i.g you cannot from within your program
To do that you need to write a driver which plugs in in the TCP/IP stack of your OS (if possible), or you need to replace the TCP/IP stack, or find a patch for your stack.

I guess that you first get used to networking, probably read "TCP/IP Illustrated", Stevens  ;-)
0
 
ravenplCommented:
> IPPROTO_RAW
Since You use IP protocol, You have to address the destination as IP.
You would have to use different protocol, IPX maybe?

Well, those two nics have their IP from different networks(i assume). Instead broadcasting to 255.255.255.255 send it to the broadcast address of the nic.
0
 
leisnerCommented:
1) If you want to send to a raw MAC address instead of a IP address, you have to bypass
the IP layer all together.  I think you need to do a define a PACKET socket and construct the IP frames yourself...TCP/IP is really two protocols -- TCP over IP --  you only get tcp/ip with SOCK_STREAM -- SOCK_DGRAM gets you udp/ip, IPPROTO_RAW sets you on top of the IP layer...if you want to specify MAC address, you can't sit on top of the ip layer.

2) This should work

setsockopt(ifd, SOL_SOCKET, SO_BINDTODEVICE, interface, strlen(interface)+1)

SO_BINDTODEVICE
              Bind this socket to a particular device like "eth0",  as  speci-
              fied  in  the  passed  interface  name.  If the name is an empty
              string or the option length is zero, the socket  device  binding
              is  removed.  The passed option is a variable-length null termi-
              nated interface name string with the maximum size  of  IFNAMSIZ.
              If a socket is bound to an interface, only packets received from
              that particular interface are processed by the socket. Note that
              this  only  works  for  some  socket types, particularly AF_INET
              sockets. It is not supported  for  packet  sockets  (use  normal
              bind(8) there).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now