Beispiel #1
0
INTERPOSE (sendto, ssize_t, int sockfd, const void *buf, size_t len,
           int flags, const struct sockaddr * dest_addr, socklen_t addrlen)
{
  v4v_addr_t peer;

  CHECK_INTERPOSE (sendto);

  if (!is_our_fd (sockfd))
    return orig_sendto (sockfd, buf, len, flags, dest_addr, addrlen);

  if (dest_addr && v4v_map_sa_to_v4va (&peer, dest_addr, addrlen))
    return -EINVAL;

  return v4v_sendto (sockfd, buf, len, flags, dest_addr ? &peer : NULL);

}
Beispiel #2
0
ssize_t sendto(int sockfd, const void* buf, size_t len, int flags, const struct sockaddr* dst_addr, socklen_t addrlen) {
	static size_t (*orig_sendto)(int, const void*, size_t, int, const struct sockaddr*, socklen_t) = NULL;
	orig_sendto = dlsym(RTLD_NEXT, "sendto");
	//printf("\ncalling sendto(%d, %p, %u, %d, %p, %u)\n", sockfd, buf, len, flags, dst_addr, addrlen);
	if(dst_addr->sa_family == AF_INET) {
		//char ip[INET_ADDRSTRLEN] = {0};
		//struct sockaddr_in* addr = (struct sockaddr_in*)dst_addr;
		//printf("\nsending to %s:%u\n", inet_ntop(addr->sin_family, &(addr->sin_addr), ip, addrlen), ntohs(addr->sin_port));
		char* buff = (char*)buf;
		/*if(flags == 16448) {
			putchar('\n');
			size_t i;
			for(i = 0; i < len; i++) {
				printf("%#02x ", (unsigned char)(buff[i]));
			}
			putchar('\n');
			putchar('\n');
		}*/
		if(buff[4] == 'I') {
			char ip[INET_ADDRSTRLEN] = {0};
			struct sockaddr_in* addr = (struct sockaddr_in*)dst_addr;
			printf("\nsending query reply to %s:%u\n", inet_ntop(addr->sin_family, &(addr->sin_addr), ip, addrlen), ntohs(addr->sin_port));
			size_t i;
			int nullcount = 0;
			for(i = 6; i < len-1; i++) {
				if(buff[i] == '\0') {
					++nullcount;
				}
				if(nullcount == 4) {
					//char oldnum = buff[i+3];
					//buff[i+3] = 5;
					//buff[i+4] = 20;
					buff[i+5] = 6;
					//printf("\nold number: %d, new number: %d\n", oldnum, buff[i+3]);
					break;
				}
			}
		}
	}
	return orig_sendto(sockfd, buf, len, flags, dst_addr, addrlen);
}
Beispiel #3
0
/* Modified sendto() */
ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
{
	void *new_buf;
	struct sockaddr_in sin, *orig_to;

	orig_to = (struct sockaddr_in *) to;

	// Create new buffer prefixed with address and port to send to the daemon
	new_buf = malloc(len + addr_port_len);
	memcpy(new_buf, &((orig_to->sin_addr).s_addr), addr_len);
	memcpy(new_buf + addr_len, &((orig_to->sin_port)), port_len);
	memcpy(new_buf + addr_port_len, buf, len);

	// Set up new destination modified packet
	memset (&sin, 0, sizeof(struct sockaddr_in));
	sin.sin_family = orig_to->sin_family;
	sin.sin_port = htons(data_port);
	sin.sin_addr.s_addr = inet_addr(DADDRESS);

	return orig_sendto(s, new_buf, len + addr_port_len, flags, (struct sockaddr *) &sin, sizeof(sin));
}