View previous topic :: View next topic |
Author |
Message |
mmadia
Joined: 11 Jan 2009 Posts: 2
|
Posted: Sun Jan 11, 2009 8:13 pm Post subject: [patch] support for Haiku |
|
|
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 |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Jan 12, 2009 11:04 am Post subject: |
|
|
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 |
|
|
titer
Joined: 09 Jul 2009 Posts: 4
|
Posted: Thu Jul 09, 2009 2:18 pm Post subject: |
|
|
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 |
|
|
titer
Joined: 09 Jul 2009 Posts: 4
|
Posted: Thu Jul 09, 2009 2:19 pm Post subject: |
|
|
(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 |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Thu Jul 09, 2009 3:53 pm Post subject: |
|
|
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 |
|
|
titer
Joined: 09 Jul 2009 Posts: 4
|
Posted: Thu Jul 09, 2009 5:26 pm Post subject: |
|
|
Thank you! |
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
|
|