miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[patch] support for Haiku

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> libnatpmp Compilation/Installation
View previous topic :: View next topic  
Author Message
mmadia



Joined: 11 Jan 2009
Posts: 2

PostPosted: Sun Jan 11, 2009 8:13 pm    Post subject: [patch] support for Haiku Reply with quote

Haiku, http://haiku-os.org is an open-source implementation of BeOS.
For the most part, it is binary and source compatible.
In addition, Haiku has numerous improvements over BeOS, such as better POSIX support and newer hardware support for example.

As you may know, libnatpmp is being used by Transmission , a torrent client http://www.transmissionbt.com/

Recently, I added added support for Haiku to Transmission, which includes libnatpmp.

Below are links to two patch files.
The first is intended to be committed to libnatpmp's source.
http://pastebin.com/f1c35d09b

The second shows additional changes to Makefile that are required to compile libnatpmp on Haiku. However, these changes will affect other platforms. As such, I'm not sure how you would like to manage this.
http://pastebin.com/f615a50a1

Once both of these are applied, `make` successfully builds libnatpmp.
Please contact me if there are any issues.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Mon Jan 12, 2009 11:04 am    Post subject: Reply with quote

getdefaultgateway() is not implemented so the patch is not fonctionnal on Haiku... You should find a way to get default route (and so default gateway) on that OS.
You should look into the sources of the "route" tool (or the tool offering similar functionnality) to see how listing of routes is done
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
titer



Joined: 09 Jul 2009
Posts: 4

PostPosted: Thu Jul 09, 2009 2:18 pm    Post subject: Reply with quote

Here is a functional patch - most if it was stolen from Haiku's route.cpp, and I verified that it correctly finds the gateway on my setup.
Back to top
View user's profile Send private message
titer



Joined: 09 Jul 2009
Posts: 4

PostPosted: Thu Jul 09, 2009 2:19 pm    Post subject: Reply with quote

(phpbb wouldn't let me put code in my first post...)

Code:

diff -Naur transmission-1.72/third-party/libnatpmp/getgateway.c transmission-1.72-haiku/third-party/libnatpmp/getgateway.c
--- transmission-1.72/third-party/libnatpmp/getgateway.c   2009-06-17 00:01:54.000000000 +0000
+++ transmission-1.72-haiku/third-party/libnatpmp/getgateway.c   2009-07-09 10:05:58.000000000 +0000
@@ -75,6 +75,12 @@
 #define MAX_KEY_LENGTH 255
 #define MAX_VALUE_LENGTH 16383
 #endif
+#ifdef __HAIKU__
+#include <stdlib.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/sockio.h>
+#endif
 #include "getgateway.h"
 
 #ifndef WIN32
@@ -421,3 +427,56 @@
 }
 #endif /* #ifdef USE_WIN32_CODE */
 
+#ifdef __HAIKU__
+int getdefaultgateway(in_addr_t *addr)
+{
+    int fd, ret = -1;
+    struct ifconf config;
+    void *buffer = NULL;
+    struct ifreq *interface;
+
+    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+        return -1;
+    }
+    if (ioctl(fd, SIOCGRTSIZE, &config, sizeof(config)) != 0) {
+        goto fail;
+    }
+    if (config.ifc_value < 1) {
+        goto fail; /* No routes */
+    }
+    if ((buffer = malloc(config.ifc_value)) == NULL) {
+        goto fail;
+    }
+    config.ifc_len = config.ifc_value;
+    config.ifc_buf = buffer;
+    if (ioctl(fd, SIOCGRTTABLE, &config, sizeof(config)) != 0) {
+        goto fail;
+    }
+    for (interface = buffer;
+      (uint8_t *)interface < (uint8_t *)buffer + config.ifc_len; ) {
+        struct route_entry route = interface->ifr_route;
+        int intfSize;
+        if (route.flags & (RTF_GATEWAY | RTF_DEFAULT)) {
+            *addr = ((struct sockaddr_in *)route.gateway)->sin_addr.s_addr;
+            ret = 0;
+            break;
+        }
+        intfSize = sizeof(route) + IF_NAMESIZE;
+        if (route.destination != NULL) {
+            intfSize += route.destination->sa_len;
+        }
+        if (route.mask != NULL) {
+            intfSize += route.mask->sa_len;
+        }
+        if (route.gateway != NULL) {
+            intfSize += route.gateway->sa_len;
+        }
+        interface = (struct ifreq *)((uint8_t *)interface + intfSize);
+    }
+fail:
+    free(buffer);
+    close(fd);
+    return ret;
+}
+#endif
+
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Thu Jul 09, 2009 3:53 pm    Post subject: Reply with quote

thank you for the patch. I'm going to integrate it into my sources as soon as I get ten minutes to do so !
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
titer



Joined: 09 Jul 2009
Posts: 4

PostPosted: Thu Jul 09, 2009 5:26 pm    Post subject: Reply with quote

Thank you!
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Mon Jul 13, 2009 8:55 am    Post subject: Reply with quote

done
libnatpmp-20090713.tar.gz
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> libnatpmp Compilation/Installation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.