summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorDavid McCullough <davidm@snapgear.com>2002-01-17 03:58:58 +0000
committerDavid McCullough <davidm@snapgear.com>2002-01-17 03:58:58 +0000
commit9557844c482a3a2302df69e06677178247634d56 (patch)
tree12f452f04f869fdd063f54bb964e96ac8ca49f2c /libc
parentae36d86f4cd1172196b21e5775ff75b288b24d9a (diff)
Add in support for inet_netof, inet_lnaof, inet_makeaddr and hstrerror.
Diffstat (limited to 'libc')
-rw-r--r--libc/inet/Makefile14
-rw-r--r--libc/inet/addr.c66
-rw-r--r--libc/inet/herror.c11
3 files changed, 88 insertions, 3 deletions
diff --git a/libc/inet/Makefile b/libc/inet/Makefile
index c9157bb84..8ca400649 100644
--- a/libc/inet/Makefile
+++ b/libc/inet/Makefile
@@ -32,7 +32,8 @@ endif
ALL_SUBDIRS = rpc
MSRC=addr.c
-MOBJ=inet_aton.o inet_addr.o inet_ntoa.o
+MOBJ=inet_aton.o inet_addr.o inet_ntoa.o inet_makeaddr.o inet_lnaof.o \
+ inet_netof.o
MSRC2=resolv.c
MOBJ2=encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \
@@ -48,12 +49,15 @@ MOBJ3= accept.o bind.o connect.o getpeername.o getsockname.o getsockopt.o \
listen.o recv.o recvfrom.o recvmsg.o send.o sendmsg.o sendto.o \
setsockopt.o shutdown.o socket.o socketpair.o
+MSRC4=herror.c
+MOBJ4=herror.o hstrerror.o
+
CSRC =getservice.c getproto.c hostid.c getnetent.c getnetbynm.c getnetbyad.c \
- herror.c inet_net.c ntop.c
+ inet_net.c ntop.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
-OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
+OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3) $(MOBJ4) $(COBJS)
all: $(OBJS) $(LIBC)
@@ -75,6 +79,10 @@ $(MOBJ3): $(MSRC3)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
+$(MOBJ4): $(MSRC4)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
$(COBJS): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
$(STRIPTOOL) -x -R .note -R .comment $*.o
diff --git a/libc/inet/addr.c b/libc/inet/addr.c
index 15f6d0a5a..d1f9c04e6 100644
--- a/libc/inet/addr.c
+++ b/libc/inet/addr.c
@@ -112,3 +112,69 @@ struct in_addr in;
return p+1;
}
#endif
+
+#ifdef L_inet_makeaddr
+/*
+ * Formulate an Internet address from network + host. Used in
+ * building addresses stored in the ifnet structure.
+ */
+struct in_addr inet_makeaddr(net, host)
+unsigned long net, host;
+{
+ unsigned long addr;
+
+ if (net < 128)
+ addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+ else if (net < 65536)
+ addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+ else if (net < 16777216L)
+ addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+ else
+ addr = net | host;
+ addr = htonl(addr);
+ return (*(struct in_addr *)&addr);
+}
+
+#endif
+
+#ifdef L_inet_lnaof
+/*
+ * Return the local network address portion of an
+ * internet address; handles class a/b/c network
+ * number formats.
+ */
+unsigned long inet_lnaof(in)
+struct in_addr in;
+{
+ unsigned long i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return ((i)&IN_CLASSA_HOST);
+ else if (IN_CLASSB(i))
+ return ((i)&IN_CLASSB_HOST);
+ else
+ return ((i)&IN_CLASSC_HOST);
+}
+#endif
+
+#ifdef L_inet_netof
+
+/*
+ * Return the network number from an internet
+ * address; handles class a/b/c network #'s.
+ */
+u_int32_t
+inet_netof(in)
+ struct in_addr in;
+{
+ u_int32_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ else if (IN_CLASSB(i))
+ return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ else
+ return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}
+
+#endif
diff --git a/libc/inet/herror.c b/libc/inet/herror.c
index b95d3d913..51b858f54 100644
--- a/libc/inet/herror.c
+++ b/libc/inet/herror.c
@@ -23,6 +23,8 @@
#include <string.h>
#include <netdb.h>
+#ifdef L_herror
+
static const char *const h_errlist[] = {
"Error 0",
"Unknown host", /* 1 HOST_NOT_FOUND */
@@ -51,3 +53,12 @@ void herror(const char *s)
}
fprintf(stderr, "%s%s%s\n", s, c, p);
}
+
+#endif
+
+#ifdef L_hstrerror
+const char *hstrerror(int err)
+{
+ return(strerror(err));
+}
+#endif