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 /sgsnemu | |
parent | 98200dfdf9ef8b570e91920f25b0225cd5d35ea4 (diff) |
Changes to allow compilation under Solaris
Diffstat (limited to 'sgsnemu')
-rw-r--r-- | sgsnemu/Makefile.am | 2 | ||||
-rw-r--r-- | sgsnemu/Makefile.in | 2 | ||||
-rw-r--r-- | sgsnemu/sgsnemu.c | 54 | ||||
-rw-r--r-- | sgsnemu/tun.c | 27 |
4 files changed, 52 insertions, 33 deletions
diff --git a/sgsnemu/Makefile.am b/sgsnemu/Makefile.am index b92fef5..38e50c6 100644 --- a/sgsnemu/Makefile.am +++ b/sgsnemu/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = sgsnemu 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 sgsnemu_SOURCES = sgsnemu.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c diff --git a/sgsnemu/Makefile.in b/sgsnemu/Makefile.in index 392e78f..5cf2601 100644 --- a/sgsnemu/Makefile.in +++ b/sgsnemu/Makefile.in @@ -90,7 +90,7 @@ bin_PROGRAMS = sgsnemu 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 sgsnemu_SOURCES = sgsnemu.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c subdir = sgsnemu diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c index c63f634..a224386 100644 --- a/sgsnemu/sgsnemu.c +++ b/sgsnemu/sgsnemu.c @@ -43,11 +43,8 @@ #include <sys/ioctl.h> #include <sys/time.h> #include <net/if.h> -#include <features.h> #include <errno.h> -#include <asm/types.h> #include <sys/socket.h> -#include <linux/netlink.h> #include <resolv.h> #include <time.h> @@ -122,22 +119,22 @@ struct { #define CREATEPING_ICMP 8 struct ip_ping { - u_int8_t ipver; /* Type and header length*/ - u_int8_t tos; /* Type of Service */ - u_int16_t length; /* Total length */ - u_int16_t fragid; /* Identifier */ - u_int16_t offset; /* Flags and fragment offset */ - u_int8_t ttl; /* Time to live */ - u_int8_t protocol; /* Protocol */ - u_int16_t ipcheck; /* Header checksum */ - u_int32_t src; /* Source address */ - u_int32_t dst; /* Destination */ - u_int8_t type; /* Type and header length*/ - u_int8_t code; /* Code */ - u_int16_t checksum; /* Header checksum */ - u_int16_t ident; /* Identifier */ - u_int16_t seq; /* Sequence number */ - u_int8_t data[CREATEPING_MAX]; /* Data */ + uint8_t ipver; /* Type and header length*/ + uint8_t tos; /* Type of Service */ + uint16_t length; /* Total length */ + uint16_t fragid; /* Identifier */ + uint16_t offset; /* Flags and fragment offset */ + uint8_t ttl; /* Time to live */ + uint8_t protocol; /* Protocol */ + uint16_t ipcheck; /* Header checksum */ + uint32_t src; /* Source address */ + uint32_t dst; /* Destination */ + uint8_t type; /* Type and header length*/ + uint8_t code; /* Code */ + uint16_t checksum; /* Header checksum */ + uint16_t ident; /* Identifier */ + uint16_t seq; /* Sequence number */ + uint8_t data[CREATEPING_MAX]; /* Data */ } __attribute__((packed)); /* Statistical values for ping */ @@ -205,7 +202,7 @@ void log_pid(char *pidfile) { umask(oldmask); if(!file) return; - fprintf(file, "%d\n", getpid()); + fprintf(file, "%d\n", (int) getpid()); fclose(file); } @@ -782,8 +779,8 @@ int create_ping(void *gsn, struct pdp_t *pdp, struct in_addr *dst, int seq, int datasize) { struct ip_ping pack; - u_int16_t *p = (u_int16_t *) &pack; - u_int8_t *p8 = (u_int8_t *) &pack; + uint16_t *p = (uint16_t *) &pack; + uint8_t *p8 = (uint8_t *) &pack; struct in_addr src; int n; long int sum = 0; @@ -817,14 +814,14 @@ int create_ping(void *gsn, struct pdp_t *pdp, pack.seq = htons(seq); /* Generate ICMP payload */ - p8 = (u_int8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP; + p8 = (uint8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP; for (n=0; n<(datasize); n++) p8[n] = n; if (datasize >= sizeof(struct timeval)) gettimeofday(tp, &tz); /* Calculate IP header checksum */ - p = (u_int16_t *) &pack; + p = (uint16_t *) &pack; count = CREATEPING_IP; sum = 0; while (count>1) { @@ -839,7 +836,7 @@ int create_ping(void *gsn, struct pdp_t *pdp, /* Calculate ICMP checksum */ count = CREATEPING_ICMP + datasize; /* Length of ICMP message */ sum = 0; - p = (u_int16_t *) &pack; + p = (uint16_t *) &pack; p += CREATEPING_IP / 2; while (count>1) { sum += *p++; @@ -1012,7 +1009,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 + /* Process options given in configuration file and command line */ if (process_options(argc, argv)) diff --git a/sgsnemu/tun.c b/sgsnemu/tun.c index 5b8cc95..2ad7cc9 100644 --- a/sgsnemu/tun.c +++ b/sgsnemu/tun.c @@ -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 } |