Major changes:
[ipfw.git] / ipfw / glue.c
1 /*
2  * Copyright (C) 2009 Luigi Rizzo, Marta Carbone, Universita` di Pisa
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 /*
27  * $Id$
28  *
29  * Userland functions missing in linux
30  */
31
32 #include <stdlib.h>
33 #include <stdio.h>
34
35 #ifndef HAVE_NAT
36 /* dummy nat functions */
37 void
38 ipfw_show_nat(int ac, char **av)
39 {
40         fprintf(stderr, "%s unsupported\n", __FUNCTION__);
41 }
42
43 void
44 ipfw_config_nat(int ac, char **av)
45 {
46         fprintf(stderr, "%s unsupported\n", __FUNCTION__);
47 }
48 #endif
49
50 #ifdef __linux__
51 int optreset;   /* missing in linux */
52 #endif
53
54 #if defined( __linux__ ) || defined(_WIN32)
55 /*
56  * not implemented in linux.
57  * taken from /usr/src/lib/libc/string/strlcpy.c
58  */
59 size_t
60 strlcpy(char *dst, const char *src, size_t siz)
61 {
62         char *d = dst;
63         const char *s = src;
64         size_t n = siz;
65  
66         /* Copy as many bytes as will fit */
67         if (n != 0 && --n != 0) {
68                 do {
69                         if ((*d++ = *s++) == 0)
70                                 break;
71                 } while (--n != 0);
72         }
73
74         /* Not enough room in dst, add NUL and traverse rest of src */
75         if (n == 0) {
76                 if (siz != 0)
77                         *d = '\0';              /* NUL-terminate dst */
78                 while (*s++)
79                         ;
80         }
81
82         return(s - src - 1);    /* count does not include NUL */
83 }
84
85
86 /* missing in linux and windows */
87 long long int
88 strtonum(const char *nptr, long long minval, long long maxval,
89          const char **errstr)
90 {
91         return strtoll(nptr, (char **)errstr, 0);
92 }
93
94 int
95 sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
96          size_t newlen)
97 {
98         return -1;
99 }
100 #endif /* __linux__ || _WIN32 */