*/
+
+// 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)
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);
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;
--- /dev/null
+#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;
+}
// 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>
+
#include "toys.h"
#include "toynet.h"
-#include <net/if.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
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
# 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.