commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r7409 - usrp2/trunk/host/lib


From: eb
Subject: [Commit-gnuradio] r7409 - usrp2/trunk/host/lib
Date: Sat, 12 Jan 2008 17:56:31 -0700 (MST)

Author: eb
Date: 2008-01-12 17:56:29 -0700 (Sat, 12 Jan 2008)
New Revision: 7409

Modified:
   usrp2/trunk/host/lib/gri_ethernet.cc
   usrp2/trunk/host/lib/gri_ethernet.h
   usrp2/trunk/host/lib/usrp2_basic.cc
Log:
version that doesn't use BPF

Modified: usrp2/trunk/host/lib/gri_ethernet.cc
===================================================================
--- usrp2/trunk/host/lib/gri_ethernet.cc        2008-01-12 22:19:23 UTC (rev 
7408)
+++ usrp2/trunk/host/lib/gri_ethernet.cc        2008-01-13 00:56:29 UTC (rev 
7409)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2005,2007 Free Software Foundation, Inc.
+ * Copyright 2005,2007,2008 Free Software Foundation, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,9 +37,12 @@
 #include <linux/filter.h>      // packet filter
 
 static int
-open_packet_socket (std::string ifname)
+open_packet_socket (std::string ifname, int protocol)
 {
-  int fd = socket (PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+  if (protocol == 0)
+    protocol = htons(ETH_P_ALL);
+
+  int fd = socket (PF_PACKET, SOCK_RAW, protocol);
   if (fd == -1){
     fprintf (stderr, "%s: socket: %s\n", ifname.c_str(), strerror (errno));
     return -1;
@@ -61,7 +64,7 @@
   sockaddr_ll sa;
   memset (&sa, 0, sizeof (sa));
   sa.sll_family = AF_PACKET;
-  sa.sll_protocol = htons(ETH_P_ALL);  // get all packets
+  sa.sll_protocol = protocol;
   sa.sll_ifindex = ifindex;
   res = bind (fd, (struct sockaddr *)&sa, sizeof (sa));
   if (res != 0){
@@ -125,13 +128,13 @@
 }
 
 bool
-gri_ethernet::open (std::string ifname)
+gri_ethernet::open (std::string ifname, int protocol)
 {
   if (d_fd != -1){
     fprintf (stderr, "gri_ethernet: already open\n");
     return false;
   }
-  if ((d_fd = open_packet_socket (ifname)) == -1){
+  if ((d_fd = open_packet_socket (ifname, protocol)) == -1){
     return false;
   }
   get_mac_addr (ifname, d_fd, d_mac);
@@ -151,20 +154,33 @@
 int
 gri_ethernet::read_packet (void *buf, int buflen, struct sockaddr_ll *sa)
 {
+  struct sockaddr_ll sock_addr;
+  if (0 && sa == 0)
+    sa = &sock_addr;
+  
   socklen_t    fromlen = sizeof (*sa);
   int len = recvfrom (d_fd, buf, buflen, 0, (sockaddr *) sa, &fromlen);
+  if (0 && len != -1)
+    fprintf(stderr, "pkttype = %d\n", sa->sll_pkttype);
+
   return len;
 }
 
 int
 gri_ethernet::read_packet_dont_block (void *buf, int buflen, struct 
sockaddr_ll *sa)
 {
+  struct sockaddr_ll sock_addr;
+  if (0 && sa == 0)
+    sa = &sock_addr;
+
   socklen_t    fromlen = sizeof (*sa);
   int len = recvfrom (d_fd, buf, buflen, MSG_DONTWAIT,
                      (sockaddr *) sa, &fromlen);
   if (len == -1 && errno == EAGAIN)
     return 0;
   
+  if (0)
+    fprintf(stderr, "pkttype = %d\n", sa->sll_pkttype);
   return len;
 }
 

Modified: usrp2/trunk/host/lib/gri_ethernet.h
===================================================================
--- usrp2/trunk/host/lib/gri_ethernet.h 2008-01-12 22:19:23 UTC (rev 7408)
+++ usrp2/trunk/host/lib/gri_ethernet.h 2008-01-13 00:56:29 UTC (rev 7409)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2005,2007 Free Software Foundation, Inc.
+ * Copyright 2005,2007,2008 Free Software Foundation, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,8 +40,11 @@
 
   /*!
    * \param ifname ethernet interface name, e.g., "eth0"
+   * \param protocol is the ethertype protocol number in network order.
+   *    Use 0 to receive all protocols.
    */
-  bool open (std::string ifname);
+  bool open (std::string ifname, int protocol);
+
   bool close ();
 
   /*!

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-01-12 22:19:23 UTC (rev 7408)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-01-13 00:56:29 UTC (rev 7409)
@@ -54,15 +54,17 @@
 bool
 usrp2_basic::open(std::string ifname)
 {
-  if (!d_ethernet->open(ifname))
+  if (!d_ethernet->open(ifname, htons(U2_ETHERTYPE)))
     return false;
 
   if (d_pf)
     delete d_pf;
 
-  d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, 
d_ethernet->mac());
-  if (!d_ethernet->attach_pktfilter(d_pf))
-    return false;
+  if (0){
+    d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, 
d_ethernet->mac());
+    if (!d_ethernet->attach_pktfilter(d_pf))
+      return false;
+  }
 
   return true;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]