Example #1
0
void setup_epoll_wrappers(void)
{
	LIBC_FUNCTION(epoll_create);
	LIBC_FUNCTION(epoll_ctl);
	LIBC_FUNCTION(epoll_wait);
	setup_epoll_wrappers_called = 1;
}
Example #2
0
int epoll_create(int size)
{
	int epfd = -1;

	if (setup_epoll_wrappers_called) {
		epfd = ofp_epoll_create(size);

		if (epfd == -1)
			errno = NETWRAP_ERRNO(ofp_errno);
		else
			errno = 0;
	} else {
		LIBC_FUNCTION(epoll_create);

		if (libc_epoll_create)
			epfd = libc_epoll_create(size);
		else {
			errno = EACCES;
			epfd = -1;
		}
	}

	return epfd;
}
Example #3
0
ssize_t sendfile64(int out_fd, int in_fd, off64_t *offset, size_t count)
{
	ssize_t sendfile_value = -1;

	if (IS_OFP_SOCKET(out_fd)) {
		off_t orig = 0;
		size_t data_processed = 0;
		char buff[BUF_SIZE];
		ssize_t data_read;
		ofp_ssize_t ofp_data_sent;
		ofp_ssize_t ofp_data_sent_sum;

		if (offset != NULL) {
			orig = lseek(in_fd, 0, SEEK_CUR);
			if (orig == (off_t)-1)
				return -1;
			if (lseek(in_fd, *offset, SEEK_SET) == -1)
				return -1;
		}

		while (data_processed < count) {
			data_read = (*libc_read)(in_fd, buff, BUF_SIZE);
			if (data_read < 0)
				return -1;
			else if (data_read == 0)   /*EOF*/
				break;

			ofp_data_sent_sum = 0;
			while (ofp_data_sent_sum < data_read) {
				ofp_data_sent = ofp_send(out_fd,
					buff + ofp_data_sent_sum,
					data_read - ofp_data_sent_sum, 0);
				if (ofp_data_sent < 0) {
					if (ofp_errno == OFP_EWOULDBLOCK) {
						usleep(100);
						continue;
					}
					errno = NETWRAP_ERRNO(ofp_errno);
					return -1;
				}
				ofp_data_sent_sum += ofp_data_sent;
			}
			data_processed += data_read;
		}

		sendfile_value = data_processed;

		if (offset != NULL) {
			*offset = lseek(in_fd, 0, SEEK_CUR);
			if (*offset == -1)
				return -1;
			if (lseek(in_fd, orig, SEEK_SET) == -1)
				return -1;
		}
	} else if (libc_sendfile64)
		sendfile_value = (*libc_sendfile64)(out_fd, in_fd,
				offset, count);
	else {
		LIBC_FUNCTION(sendfile64);

		if (libc_sendfile64)
			sendfile_value = (*libc_sendfile64)(out_fd, in_fd,
				offset, count);
		else {
			sendfile_value = -1;
			errno = EACCES;
		}
	}

	/*printf("Sendfile64 called on socket '%d' returned:'%d'\n",
		out_fd, (int)sendfile_value);*/
	return sendfile_value;
}
Example #4
0
void setup_sendfile_wrappers(void)
{
	LIBC_FUNCTION(sendfile64);
	LIBC_FUNCTION(read);
}
Example #5
0
static int ofp_libc_init(void)
{
#define LIBC_FUNCTION(func) \
	libc_##func = dlsym(RTLD_NEXT, #func);\
	if(dlerror()) { \
		errno = EACCES; \
		return EXIT_FAILURE; \
	}

	LIBC_FUNCTION(socket);
	LIBC_FUNCTION(bind);
	LIBC_FUNCTION(accept);
	LIBC_FUNCTION(connect);
	LIBC_FUNCTION(listen);
	LIBC_FUNCTION(shutdown);
	LIBC_FUNCTION(close);
	LIBC_FUNCTION(setsockopt);
	LIBC_FUNCTION(read);
	LIBC_FUNCTION(recv);
	LIBC_FUNCTION(write);
	LIBC_FUNCTION(send);

	return EXIT_SUCCESS;
}