diff options
author | jjako <jjako> | 2004-01-09 15:19:20 +0000 |
---|---|---|
committer | jjako <jjako> | 2004-01-09 15:19:20 +0000 |
commit | 0141d2023243fbbaba1d04fd157e8ffc729e5e70 (patch) | |
tree | 9fe6a3df502901a889a15fe9cfb1b9547858d8cf /ggsn | |
parent | 98200dfdf9ef8b570e91920f25b0225cd5d35ea4 (diff) |
Changes to allow compilation under Solaris
Diffstat (limited to 'ggsn')
-rw-r--r-- | ggsn/Makefile.am | 2 | ||||
-rw-r--r-- | ggsn/Makefile.in | 2 | ||||
-rw-r--r-- | ggsn/ggsn.c | 43 | ||||
-rw-r--r-- | ggsn/tun.c | 27 |
4 files changed, 60 insertions, 14 deletions
diff --git a/ggsn/Makefile.am b/ggsn/Makefile.am index d3bbcad..f80bc37 100644 --- a/ggsn/Makefile.am +++ b/ggsn/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = ggsn LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@ -CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp +CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp ggsn_SOURCES = ggsn.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c diff --git a/ggsn/Makefile.in b/ggsn/Makefile.in index f4a0da6..b8ed78b 100644 --- a/ggsn/Makefile.in +++ b/ggsn/Makefile.in @@ -90,7 +90,7 @@ bin_PROGRAMS = ggsn LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@ -CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp +CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp ggsn_SOURCES = ggsn.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c subdir = ggsn diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 25da64c..75a76a4 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -36,19 +36,15 @@ #include <arpa/inet.h> #include <sys/wait.h> #include <sys/stat.h> +#include <fcntl.h> #include <unistd.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> -#include <features.h> #include <errno.h> -#include <asm/types.h> -#include <sys/socket.h> -#include <linux/netlink.h> - #include <time.h> #include "tun.h" @@ -88,10 +84,38 @@ void log_pid(char *pidfile) { "Failed to create process ID file: %s!", pidfile); return; } - fprintf(file, "%d\n", getpid()); + fprintf(file, "%d\n", (int) getpid()); fclose(file); } +#ifdef __sun__ +int daemon(int nochdir, int noclose) { + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) chdir("/"); + + if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if (fd > 2) close (fd); + } + return (0); +} +#endif + int encaps_printf(void *p, void *packet, unsigned len) { @@ -192,7 +216,14 @@ int main(int argc, char **argv) /* open a connection to the syslog daemon */ /*openlog(PACKAGE, LOG_PID, LOG_DAEMON);*/ + + /* TODO: Only use LOG__PERROR for linux */ +#ifdef __linux__ openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON); +#else + openlog(PACKAGE, (LOG_PID), LOG_DAEMON); +#endif + if (cmdline_parser (argc, argv, &args_info) != 0) exit(1); @@ -43,19 +43,24 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> -#include <linux/if.h> #include <errno.h> -#include <linux/if_tun.h> #include <net/route.h> +#ifdef __linux__ +#include <linux/if.h> +#include <linux/if_tun.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> +#elif defined (__sun__) +#include <net/if_tun.h> +#endif + #include "tun.h" #include "syserr.h" - +#ifdef __linux__ int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen) { int len = RTA_LENGTH(dlen); @@ -69,6 +74,7 @@ int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen) n->nlmsg_len = alen + len; return 0; } +#endif int tun_gifindex(struct tun_t *this, int *index) { struct ifreq ifr; @@ -118,7 +124,7 @@ int tun_sifflags(struct tun_t *this, int flags) { } -/* Currently unused */ +/* Currently unused int tun_addroute2(struct tun_t *this, struct in_addr *dst, struct in_addr *gateway, @@ -208,16 +214,18 @@ int tun_addroute2(struct tun_t *this, req.n.nlmsg_seq = 0; req.n.nlmsg_flags |= NLM_F_ACK; - status = sendmsg(fd, &msg, 0); /* TODO: Error check */ + status = sendmsg(fd, &msg, 0); * TODO: Error check * close(fd); return 0; } - +*/ int tun_addaddr(struct tun_t *this, struct in_addr *addr, struct in_addr *dstaddr, struct in_addr *netmask) { + +#ifdef __linux__ struct { struct nlmsghdr n; struct ifaddrmsg i; @@ -232,10 +240,16 @@ int tun_addaddr(struct tun_t *this, struct sockaddr_nl nladdr; struct iovec iov; struct msghdr msg; +#endif if (!this->addrs) /* Use ioctl for first addr to make ping work */ return tun_setaddr(this, addr, dstaddr, netmask); +#ifndef __linux__ + sys_err(LOG_ERR, __FILE__, __LINE__, errno, + "Setting multiple addresses only possible on linux"); + return -1; +#else memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE; @@ -315,6 +329,7 @@ int tun_addaddr(struct tun_t *this, close(fd); this->addrs++; return 0; +#endif } |