We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


send message through socket?

newbie_tw asked
Medium Priority
Last Modified: 2010-05-18
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.
Watch Question

> .. 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  ;-)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2005
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 send it to the broadcast address of the nic.
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)

              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).
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.