send message through socket?

Posted on 2006-03-23
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.
Question by:newbie_tw
    LVL 51

    Accepted Solution

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

    Assisted Solution

    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.
    LVL 3

    Assisted Solution

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

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now