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

From: from-linux-kernel
Date: Tue Jul 25 2006 - 23:28:44 EST


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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/