]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
check discovered device on same subnet
authorJohn Melton g0orx/n6lyt <john.d.melton@googlemail.com>
Mon, 2 May 2016 13:26:53 +0000 (13:26 +0000)
committerJohn Melton g0orx/n6lyt <john.d.melton@googlemail.com>
Mon, 2 May 2016 13:26:53 +0000 (13:26 +0000)
discovered.h
main.c
new_discovery.c
old_discovery.c
pihpsdr
release/pihpsdr.tar
release/pihpsdr/pihpsdr

index 417d74212c19c3d0611ea1c47e12afc92e76b9de..429b5236815e3c119be641b2a726f4ab66aaeffe 100644 (file)
@@ -53,6 +53,7 @@ struct _DISCOVERED {
     struct sockaddr_in address;
     int interface_length;
     struct sockaddr_in interface_address;
+    struct sockaddr_in interface_netmask;
     char interface_name[64];
 };
 
diff --git a/main.c b/main.c
index 4bf80d9e2e5e3ef9a3901651b2be31e6c234d39c..db3d11699ceedf54bc2b037b3e97045a209482c6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -810,7 +810,11 @@ gint init(void* arg) {
                 gtk_widget_set_sensitive(start_button, FALSE);
               }
 
-              // check subnet to see if can access
+              // if not on the same subnet then cannot start it
+              if((d->interface_address.sin_addr.s_addr&d->interface_netmask.sin_addr.s_addr) != (d->address.sin_addr.s_addr&d->interface_netmask.sin_addr.s_addr)) {
+                gtk_button_set_label(GTK_BUTTON(start_button),"Subnet!");
+                gtk_widget_set_sensitive(start_button, FALSE);
+              }
 
               GtkWidget *configure_button=gtk_button_new_with_label("Configure");
               gtk_widget_override_font(configure_button, pango_font_description_from_string("Arial 18"));
@@ -827,8 +831,8 @@ gint init(void* arg) {
               _exit(0);
           }
          
-#ifdef INCLUDE_GPIO
           gtk_widget_destroy(discovery_dialog);
+#ifdef INCLUDE_GPIO
           if(result==GTK_RESPONSE_YES) {
               configure_gpio();
           }
index 8d23da4e6f512a27779c96c6e13b52182c895bac..dc4a8f3c8e04b81f9724dbf31827f86450fa5ac8 100644 (file)
@@ -39,6 +39,7 @@
 
 static char interface_name[64];
 static struct sockaddr_in interface_addr={0};
+static struct sockaddr_in interface_netmask={0};
 static int interface_length;
 
 #define DISCOVERY_PORT 1024
@@ -95,7 +96,9 @@ void new_discovery() {
 void new_discover(struct ifaddrs* iface) {
     int rc;
     struct sockaddr_in *sa;
-    //char *addr;
+    struct sockaddr_in *mask;
+    char addr[16];
+    char net_mask[16];
 
     strcpy(interface_name,iface->ifa_name);
     fprintf(stderr,"new_discover: looking for HPSDR devices on %s\n",interface_name);
@@ -111,7 +114,9 @@ void new_discover(struct ifaddrs* iface) {
     setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
 
     sa = (struct sockaddr_in *) iface->ifa_addr;
-    //addr = inet_ntoa(sa->sin_addr);
+    mask = (struct sockaddr_in *) iface->ifa_netmask;
+
+    interface_netmask.sin_addr.s_addr = mask->sin_addr.s_addr;
 
     // bind to this interface and the discovery port
     interface_addr.sin_family = AF_INET;
@@ -122,7 +127,10 @@ void new_discover(struct ifaddrs* iface) {
         exit(-1);
     }
 
-    fprintf(stderr,"new_discover: bound to %s\n",interface_name);
+    strcpy(addr,inet_ntoa(sa->sin_addr));
+    strcpy(net_mask,inet_ntoa(mask->sin_addr));
+
+    fprintf(stderr,"new_discover: bound to %s %s %s\n",interface_name,addr,net_mask);
 
     // allow broadcast on the socket
     int on=1;
@@ -145,7 +153,6 @@ void new_discover(struct ifaddrs* iface) {
         exit(-1);
     }
 
-
     // send discovery packet
     unsigned char buffer[60];
     buffer[0]=0x00;
@@ -239,6 +246,7 @@ void* new_discover_receive_thread(void* arg) {
                     memcpy((void*)&discovered[devices].address,(void*)&addr,sizeof(addr));
                     discovered[devices].address_length=sizeof(addr);
                     memcpy((void*)&discovered[devices].interface_address,(void*)&interface_addr,sizeof(interface_addr));
+                    memcpy((void*)&discovered[devices].interface_netmask,(void*)&interface_netmask,sizeof(interface_netmask));
                     discovered[devices].interface_length=sizeof(interface_addr);
                     strcpy(discovered[devices].interface_name,interface_name);
                     fprintf(stderr,"new_discover: found protocol=%d device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s\n", 
index 5b9835b593fcbd3e9f718ce703ddd34f0401d9fe..7867f6e4524167718ecb5bb307015e5db350ec57 100644 (file)
@@ -37,6 +37,7 @@
 
 static char interface_name[64];
 static struct sockaddr_in interface_addr={0};
+static struct sockaddr_in interface_netmask={0};
 static int interface_length;
 
 #define DISCOVERY_PORT 1024
@@ -49,10 +50,10 @@ static void* discover_receive_thread(void* arg);
 static void discover(struct ifaddrs* iface) {
     int rc;
     struct sockaddr_in *sa;
-    //char *addr;
+    struct sockaddr_in *mask;
 
     strcpy(interface_name,iface->ifa_name);
-    fprintf(stderr,"discover: looking for HPSDR devices on %s\n",interface_name);
+    fprintf(stderr,"discover: looking for HPSDR devices on %s\n", interface_name);
 
     // send a broadcast to locate hpsdr boards on the network
     discovery_socket=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
@@ -65,7 +66,8 @@ static void discover(struct ifaddrs* iface) {
     setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
 
     sa = (struct sockaddr_in *) iface->ifa_addr;
-    //addr = inet_ntoa(sa->sin_addr);
+    mask = (struct sockaddr_in *) iface->ifa_netmask;
+    interface_netmask.sin_addr.s_addr = mask->sin_addr.s_addr;
 
     // bind to this interface and the discovery port
     interface_addr.sin_family = AF_INET;
@@ -186,6 +188,7 @@ fprintf(stderr,"discover_receive_thread\n");
                     memcpy((void*)&discovered[devices].address,(void*)&addr,sizeof(addr));
                     discovered[devices].address_length=sizeof(addr);
                     memcpy((void*)&discovered[devices].interface_address,(void*)&interface_addr,sizeof(interface_addr));
+                    memcpy((void*)&discovered[devices].interface_netmask,(void*)&interface_netmask,sizeof(interface_netmask));
                     discovered[devices].interface_length=sizeof(interface_addr);
                     strcpy(discovered[devices].interface_name,interface_name);
                     fprintf(stderr,"discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s\n",
diff --git a/pihpsdr b/pihpsdr
index 604655ff0539497b7eca3c5c23e92ad6a1cd78f3..8cbefd628f19b90f0fba09271e820a0bfdc57d4f 100755 (executable)
Binary files a/pihpsdr and b/pihpsdr differ
index 23adfafb93047fe2a2731f58bc37eb6adba043de..d3ea57a7262ac555ea01231dd5f3f0c239a4b96e 100644 (file)
Binary files a/release/pihpsdr.tar and b/release/pihpsdr.tar differ
index 604655ff0539497b7eca3c5c23e92ad6a1cd78f3..8cbefd628f19b90f0fba09271e820a0bfdc57d4f 100755 (executable)
Binary files a/release/pihpsdr/pihpsdr and b/release/pihpsdr/pihpsdr differ