Re: [PATCH][IPv4/IPv6] Setting 0 for unused port field.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I ran the following programs and I confirmed that
applying the patch attached to the previous message
suppresses returning random u16 values.

As with IPv4, I found that using
"sin->sin_port = sin->sin_port = htons(skb->nh.iph->protocol);"
instead of "sin->sin_port = 0;"
seems to set protocol number in port field,
but I couldn't find appropriate field for IPv6.

Regards.
--
  Tetsuo Handa

------- send.c -------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/ip.h>

int main(int argc, char *argv[]) {
	static struct iphdr ip;
	struct sockaddr_in addr;
	const int fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	ip.version = 4;
	ip.ihl = sizeof(struct iphdr) / 4;
	ip.protocol = IPPROTO_RAW;
	ip.saddr = ip.daddr = addr.sin_addr.s_addr;
	while (1) {
		if (sendto(fd, &ip, sizeof(ip), 0, (struct sockaddr *) &addr, sizeof(addr)) == EOF) break;
		sleep(1);
	}
	return 0;
}

------- recv.c -------

#include <stdio.h>
#include <string.h> 
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
	const int fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
	while (1) {
		static int counter = 0;
		static char buffer[16384];
		struct sockaddr_in addr;
		socklen_t len = sizeof(addr);
		if (counter++ % 5 == 0) {
			sendto(fd, NULL, 0, 0, (struct sockaddr *) &addr, 0);
		}
		memset(&addr, 0, sizeof(addr));
		if (recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr *) &addr, &len) >= 0) {
			printf("%d %08X %d\n", addr.sin_family, ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
		}
	}
	return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux