Hi,

This is how i get the ARP packet.

#include "packets.h"
#include "netinet++/ethernetaddr.hh"
#include "netinet++/ethernet.hh"
#include "netinet++/arp.hh"

Disposition
Switch::handle(const Event& e)
{
    const Packet_in_event& pi = assert_cast<const Packet_in_event&>(e);
    uint32_t buffer_id = pi.buffer_id;
    Flow flow(pi.in_port, *pi.get_buffer());

if(flow.dl_type == ethernet::ARP){

        Nonowning_buffer b(*pi.get_buffer());
        const arp_eth_header *arp=NULL;
        const eth_header* eth = b.try_pull<eth_header>(); /* Discard eth
header */

        if (b.size() >= ARP_ETH_HEADER_LEN) {
         arp = reinterpret_cast<const arp_eth_header*>(b.try_pull(
ARP_ETH_HEADER_LEN));
         }

        if (arp) {

             if (arp->ar_pro == htons(ARP_PRO_IP)  && arp->ar_pln ==
IP_ADDR_LEN) {
              ethernetaddr arpmac(arp->ar_tha);
              char ipstr[17];#include "packets.h"
              printf("ARP Packet dst mac: "EA_FMT", dst ip:
%s\n",EA_ARGS(&arpmac), ip_to_str(arp->ar_tpa, ipstr, sizeof(ipstr)));
            }
         }else{
            printf("Failed parsing arp packet\n");
        }
    }

....


}



This is how I send ARP


void Switch::sendARP(datapathid dpid, int port,
                    ethernetaddr senderMAC, uint32_t senderIP,
                    ethernetaddr targetMAC, uint32_t targetIP)
{
    ethernet ethPacket;
    arp arpPacket;

    /* Send to broadcast address */
    ethPacket.daddr = ethernetaddr("ff:ff:ff:ff:ff:ff");
    ethPacket.saddr = senderMAC;
    ethPacket.type = ethernet::ARP;

    arpPacket.hrd = arp::ETHER;
    arpPacket.pro = ethernet::IP;
    arpPacket.hln = ethernet::PAYLOAD_MIN;  //6 for ethernet
    arpPacket.pln = sizeof(targetIP);       //4 for IPV4
    arpPacket.sha = senderMAC;
    arpPacket.sip = senderIP;
    arpPacket.tha = targetMAC;
    arpPacket.tip = targetIP;
    arpPacket.op  = arp::REQUEST;

    int size = sizeof(ethernet) + sizeof(arp);
    uint8_t *data = new uint8_t[size];

    memcpy(data, &ethPacket, sizeof(ethPacket));
    memcpy(data + sizeof(ethPacket), &arpPacket, sizeof(arpPacket));
    Array_buffer buffer(data,size);  // data will be deleted automatically

    send_openflow_packet(dpid, buffer,
                                 OFPP_FLOOD,
                                port, true);


}


here example how to use it:

sendARP(pi.datapath_id, pi.in_port,
                        ethernetaddr("00:16:41:e6:2d:ba"),
inet_addr("216.69.85.246"),
                         ethernetaddr("00:00:00:00:00:00"),
inet_addr("216.69.85.250"));


hope that helps

regards

Yeffry Zakizon




2011/11/30 Kimihiko FUKAMI <fukami.kimih...@lab.ntt.co.jp>

> Hi,Murphy!
>
> Thank you for your reply!
>
> I look at arp.hh source code. But, my question is not addressed.
>
> I forgot to tell you the code I want to write...
>
> The code is NAT program. In the NAT, the condition is that arp
> reply should be addressed.
>
> I examined which api to send arp reply by using of Nox(zaku) in
> C++, and I get a hint from attached Nox sample code "switch.cc".
> The hint is Packet_in_event...
>
> Then I want to tell you how to get packet data from Packet_in_event
>  instance. Please give me a hint!
>
>
> Murphy McCauley <jam...@nau.edu> wrote:
>
> >I don't think I've ever used it, but have you taken a look at
> include/netinet++/arp.hh?
> >
> >-- Murphy
> >
> >On Nov 25, 2011, at 1:54 AM, Kimihiko FUKAMI wrote:
> >
> >> Hi,
> >>
> >> Currently, I can not send an ARP Reply by using of Nox(zaku) in
> >> C++ code.
> >>
> >> # I can write a code to reply ARP in python.
> >>
> >> So, I want a code sample to send ARP Reply in C++.
> >>
> >> Please teach me!
> >>
> >> ---
> >> E-mail: fukami.kimih...@lab.ntt.co.jp
> >>
> >> _______________________________________________
> >> nox-dev mailing list
> >> nox-dev@noxrepo.org
> >> http://noxrepo.org/mailman/listinfo/nox-dev
>
>
> ---
> 深見 公彦 (Kimihiko FUKAMI)  TEL:0422-59-2475
> NTT 情報流通プラットホーム研究所
> ネットワークセキュリティプロジェクト
> E-mail: fukami.kimih...@lab.ntt.co.jp
>
> _______________________________________________
> nox-dev mailing list
> nox-dev@noxrepo.org
> http://noxrepo.org/mailman/listinfo/nox-dev
>
_______________________________________________
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev

Reply via email to