aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-04-26 02:41:05 -0500
committerRob Landley <rob@landley.net>2013-04-26 02:41:05 -0500
commitf01534401412812bc1d904812dfb4b0a31ee8fff (patch)
treedb23ecd59e456f54cfd071eeca8806328e29b8d9
parenta4a6dfb584a3de8c947d2ccf159b53bf56daebb7 (diff)
downloadtoybox-f01534401412812bc1d904812dfb4b0a31ee8fff.tar.gz
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
-rw-r--r--lib/lib.c22
-rw-r--r--lib/lib.h5
-rw-r--r--lib/net.c10
-rw-r--r--toynet.h9
-rw-r--r--toys/pending/ifconfig.c17
5 files changed, 43 insertions, 20 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 87ff12cb..4d8e23a4 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -739,6 +739,28 @@ char *xreadfile(char *name)
*/
+
+// Sleep for this many thousandths of a second
+void msleep(long miliseconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = miliseconds/1000;
+ ts.tv_nsec = (miliseconds%1000)*1000000;
+ nanosleep(&ts, &ts);
+}
+
+int xioctl(int fd, int request, void *data)
+{
+ int rc;
+
+ errno = 0;
+ rc = ioctl(fd, request, data);
+ if (rc == -1 && errno) perror_exit("ioctl %d", request);
+
+ return rc;
+}
+
// Open a /var/run/NAME.pid file, dying if we can't write it or if it currently
// exists and is this executable.
void xpidfile(char *name)
diff --git a/lib/lib.h b/lib/lib.h
index 18c0155f..ab858f90 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -119,6 +119,8 @@ off_t xlseek(int fd, off_t offset, int whence);
off_t lskip(int fd, off_t offset);
char *readfile(char *name);
char *xreadfile(char *name);
+void msleep(long miliseconds);
+int xioctl(int fd, int request, void *data);
char *xgetcwd(void);
void xstat(char *path, struct stat *st);
char *xabspath(char *path, int exact);
@@ -152,6 +154,9 @@ int yesno(char *prompt, int def);
void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid, char *name));
unsigned long xstrtoul(const char *nptr, char **endptr, int base);
+// net.c
+int xsocket(int domain, int type, int protocol);
+
// getmountlist.c
struct mtab_list {
struct mtab_list *next;
diff --git a/lib/net.c b/lib/net.c
new file mode 100644
index 00000000..f4b26439
--- /dev/null
+++ b/lib/net.c
@@ -0,0 +1,10 @@
+#include "toys.h"
+#include "toynet.h"
+
+int xsocket(int domain, int type, int protocol)
+{
+ int fd = socket(domain, type, protocol);
+
+ if (fd < 0) perror_exit("socket %x %x", type, protocol);
+ return fd;
+}
diff --git a/toynet.h b/toynet.h
index 4f87feb3..3cfb0159 100644
--- a/toynet.h
+++ b/toynet.h
@@ -2,9 +2,12 @@
// don't include network support, so we shouldn't include it unless we're
// going to build it.
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <poll.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
diff --git a/toys/pending/ifconfig.c b/toys/pending/ifconfig.c
index 0a511506..14a7de2d 100644
--- a/toys/pending/ifconfig.c
+++ b/toys/pending/ifconfig.c
@@ -32,7 +32,6 @@ config IFCONFIG
#include "toys.h"
#include "toynet.h"
-#include <net/if.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
@@ -61,9 +60,6 @@ struct if_list {
unsigned long long val[16];
};
-#define HW_NAME_LEN 20
-#define HW_TITLE_LEN 30
-
#define IO_MAP_INDEX 0x100
//from kernel header ipv6.h
@@ -96,19 +92,6 @@ struct ifreq_inet6 {
# define INFINIBAND_ALEN 20
#endif
-void xioctl(int fd, int request, void *data)
-{
- if (ioctl(fd, request, data) < 0) perror_exit("ioctl %d", request);
-}
-
-int xsocket(int domain, int type, int protocol)
-{
- int fd = socket(domain, type, protocol);
-
- if (fd < 0) perror_exit("socket %x %x", type, protocol);
- return fd;
-}
-
/*
* verify the host is local unix path.
* if so, set the swl input param accordingly.