Fix ipfw/Mac OS X specific source files to compile ok with -ansi flag

This commit is contained in:
Thomas Bernard 2012-02-12 13:42:37 +01:00
parent 45db6b8b0f
commit a08258f549
4 changed files with 53 additions and 50 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.257 2012/02/09 20:15:48 nanard Exp $
$Id: Changelog.txt,v 1.258 2012/02/11 14:21:49 nanard Exp $
2012/02/11:
Fix ipfw/Mac OS X specific source files to compile ok with -ansi flag
2012/02/09:
Make HTTP listen socket non blocking (so accept() can't block)

View File

@ -1,9 +1,9 @@
/* $Id: ipfwrdr.c,v 1.11 2011/07/12 19:17:05 nanard Exp $ */
/* $Id: ipfwrdr.c,v 1.12 2012/02/11 13:10:57 nanard Exp $ */
/*
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2009 Jardel Weyrich
* (c) 2011 Thomas Bernard
* (c) 2011-2012 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution
*/
@ -14,11 +14,11 @@
#include <sys/types.h>
#include <sys/file.h>
//
// This is a workaround for <sys/uio.h> troubles on FreeBSD, HPUX, OpenBSD.
// Needed here because on some systems <sys/uio.h> gets included by things
// like <sys/socket.h>
//
/*
This is a workaround for <sys/uio.h> troubles on FreeBSD, HPUX, OpenBSD.
Needed here because on some systems <sys/uio.h> gets included by things
like <sys/socket.h>
*/
#ifndef _KERNEL
# define ADD_KERNEL
# define _KERNEL
@ -173,16 +173,18 @@ int add_redirect_rule2(
memset(&rule, 0, sizeof(struct ip_fw));
rule.version = IP_FW_CURRENT_API_VERSION;
//rule.fw_number = 1000; // rule number
//rule.context = (void *)desc; // The description is kept in a separate list
rule.fw_prot = proto; // protocol
rule.fw_flg |= IP_FW_F_IIFACE; // interfaces to check
rule.fw_flg |= IP_FW_F_IIFNAME; // interfaces to check by name
rule.fw_flg |= (IP_FW_F_IN | IP_FW_F_OUT); // packet direction
rule.fw_flg |= IP_FW_F_FWD; // forward action
#if 0
rule.fw_number = 1000; /* rule number */
rule.context = (void *)desc; /* The description is kept in a separate list */
#endif
rule.fw_prot = proto; /* protocol */
rule.fw_flg |= IP_FW_F_IIFACE; /* interfaces to check */
rule.fw_flg |= IP_FW_F_IIFNAME; /* interfaces to check by name */
rule.fw_flg |= (IP_FW_F_IN | IP_FW_F_OUT); /* packet direction */
rule.fw_flg |= IP_FW_F_FWD; /* forward action */
#ifdef USE_IFNAME_IN_RULES
if (ifname != NULL) {
strlcpy(rule.fw_in_if.fu_via_if.name, ifname, IFNAMSIZ); // src interface
strlcpy(rule.fw_in_if.fu_via_if.name, ifname, IFNAMSIZ); /* src interface */
rule.fw_in_if.fu_via_if.unit = -1;
}
#endif
@ -192,10 +194,10 @@ int add_redirect_rule2(
}
memcpy(&rule.fw_dst, &rule.fw_out_if.fu_via_ip, sizeof(struct in_addr));
memcpy(&rule.fw_fwd_ip.sin_addr, &rule.fw_out_if.fu_via_ip, sizeof(struct in_addr));
rule.fw_dmsk.s_addr = INADDR_BROADCAST; //TODO check this
IP_FW_SETNDSTP(&rule, 1); // number of external ports
rule.fw_uar.fw_pts[0] = eport; // external port
rule.fw_fwd_ip.sin_port = iport; // internal port
rule.fw_dmsk.s_addr = INADDR_BROADCAST; /* TODO check this */
IP_FW_SETNDSTP(&rule, 1); /* number of external ports */
rule.fw_uar.fw_pts[0] = eport; /* external port */
rule.fw_fwd_ip.sin_port = iport; /* internal port */
if (rhost && rhost[0] != '\0') {
inet_aton(rhost, &rule.fw_src);
rule.fw_smsk.s_addr = htonl(INADDR_NONE);
@ -252,7 +254,7 @@ int get_redirect_rule(
*iport = ptr->fw_fwd_ip.sin_port;
if (iaddr != NULL && iaddrlen > 0) {
/* looks like fw_out_if.fu_via_ip is zero */
//if (inet_ntop(AF_INET, &ptr->fw_out_if.fu_via_ip, iaddr, iaddrlen) == NULL) {
/*if (inet_ntop(AF_INET, &ptr->fw_out_if.fu_via_ip, iaddr, iaddrlen) == NULL) {*/
if (inet_ntop(AF_INET, &ptr->fw_fwd_ip.sin_addr, iaddr, iaddrlen) == NULL) {
syslog(LOG_ERR, "inet_ntop(): %m");
goto error;
@ -266,7 +268,7 @@ int get_redirect_rule(
goto error;
}
}
// And what if we found more than 1 matching rule?
/* And what if we found more than 1 matching rule? */
ipfw_free_ruleset(&rules);
get_desc_time(eport, proto, desc, desclen, timestamp);
return 0;
@ -303,7 +305,7 @@ int delete_redirect_rule(
if (proto == ptr->fw_prot && eport == ptr->fw_uar.fw_pts[0]) {
if (ipfw_exec(IP_FW_DEL, (struct ip_fw *)ptr, sizeof(*ptr)) < 0)
goto error;
// And what if we found more than 1 matching rule?
/* And what if we found more than 1 matching rule? */
ipfw_free_ruleset(&rules);
del_desc_time(eport, proto);
return 0;
@ -325,7 +327,6 @@ int add_filter_rule2(
int proto,
const char * desc)
{
//return -1;
return 0; /* nothing to do, always success */
}
@ -334,7 +335,6 @@ int delete_filter_rule(
unsigned short eport,
int proto)
{
//return -1;
return 0; /* nothing to do, always success */
}
@ -357,7 +357,7 @@ int get_redirect_rule_by_index(
int total_rules = 0;
struct ip_fw * rules = NULL;
if (index < 0) // TODO shouldn't we also validate the maximum?
if (index < 0) /* TODO shouldn't we also validate the maximum? */
return -1;
if(timestamp)
@ -367,7 +367,7 @@ int get_redirect_rule_by_index(
if (total_rules > index) {
const struct ip_fw const * ptr = &rules[index];
if (ptr->fw_prot == 0) // invalid rule
if (ptr->fw_prot == 0) /* invalid rule */
goto error;
if (proto != NULL)
*proto = ptr->fw_prot;
@ -385,7 +385,7 @@ int get_redirect_rule_by_index(
*iport = ptr->fw_fwd_ip.sin_port;
if (iaddr != NULL && iaddrlen > 0) {
/* looks like fw_out_if.fu_via_ip is zero */
//if (inet_ntop(AF_INET, &ptr->fw_out_if.fu_via_ip, iaddr, iaddrlen) == NULL) {
/*if (inet_ntop(AF_INET, &ptr->fw_out_if.fu_via_ip, iaddr, iaddrlen) == NULL) {*/
if (inet_ntop(AF_INET, &ptr->fw_fwd_ip.sin_addr, iaddr, iaddrlen) == NULL) {
syslog(LOG_ERR, "inet_ntop(): %m");
goto error;

View File

@ -1,4 +1,4 @@
/* $Id: ipfwrdr.h,v 1.5 2011/06/04 15:47:18 nanard Exp $ */
/* $Id: ipfwrdr.h,v 1.6 2012/02/11 13:10:57 nanard Exp $ */
/*
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -13,11 +13,11 @@
#include "../commonrdr.h"
int add_redirect_rule2(
const char * ifname, // src interface (external)
const char * rhost, // remote host (ip)
unsigned short eport, // src port (external)
const char * iaddr, // dst address (internal)
unsigned short iport, // dst port (internal)
const char * ifname, /* src interface (external) */
const char * rhost, /* remote host (ip) */
unsigned short eport, /* src port (external) */
const char * iaddr, /* dst address (internal) */
unsigned short iport, /* dst port (internal) */
int proto,
const char * desc,
unsigned int timestamp);
@ -33,10 +33,10 @@ int add_filter_rule2(
#if 0
//
// get_redirect_rule() gets internal IP and port from
// interface, external port and protocl
//
/*
* get_redirect_rule() gets internal IP and port from
* interface, external port and protocl
*/
int get_redirect_rule(
const char * ifname,
unsigned short eport,
@ -64,14 +64,14 @@ int get_redirect_rule_by_index(
#endif
//
// delete_redirect_rule()
//
/*
* delete_redirect_rule()
*/
int delete_redirect_rule(const char * ifname, unsigned short eport, int proto);
//
// delete_filter_rule()
//
/*
* delete_filter_rule()
*/
int delete_filter_rule(const char * ifname, unsigned short eport, int proto);
int clear_redirect_rules(void);

View File

@ -1,4 +1,4 @@
/* $Id: getifstats.c,v 1.5 2011/07/03 22:22:04 nanard Exp $ */
/* $Id: getifstats.c,v 1.6 2012/02/11 13:10:57 nanard Exp $ */
/*
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -36,7 +36,7 @@ int getifstats(const char * ifname, struct ifdata * data) {
#endif
if (data == NULL || ifname == NULL || ifname[0] == '\0')
return -1; // error
return -1; /* error */
data->baudrate = 4200000;
data->opackets = 0;
@ -62,11 +62,11 @@ int getifstats(const char * ifname, struct ifdata * data) {
}
buf = (char *) malloc(needed);
if (buf == NULL)
return -1; // error
return -1; /* error */
if (sysctl(mib, mib_len, buf, &needed, NULL, 0) == -1) {
syslog(LOG_ERR, "sysctl(): %m");
free(buf);
return -1; // error
return -1; /* error */
} else {
for (end = buf + needed, p = buf; p < end; p += ifm->ifm_msglen) {
ifm = (struct if_msghdr *) p;
@ -84,11 +84,11 @@ int getifstats(const char * ifname, struct ifdata * data) {
memcpy(&cache_data, data, sizeof(struct ifdata));
}
#endif
return 0; // found, ok
return 0; /* found, ok */
}
}
}
free(buf);
return -1; // not found or error
return -1; /* not found or error */
}