Date: Wed, 21 Jan 2004 04:45:14 +0700 (GMT-7) From: "lattera" <lattera@nosleep.info> To: freebsd-ipfw@freebsd.org Subject: Re: divert sockets code Message-ID: <1651.204.113.120.202.1074635114.squirrel@vulcan.g3host.net>
next in thread | raw e-mail | index | archive | help
Correction: if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) { perror("bind"); exit(1); } exit(1); should read: if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) { perror("bind"); exit(1); } > I can't seem to get pointers right in my code: > > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > #include <unistd.h> > > #define USE_BSD > #include <sys/types.h> > #include <sys/socket.h> > #include <netinet/in.h> > > #include <netinet/tcp.h> > #include <netinet/in_systm.h> > #include <netinet/ip.h> > > #define PORT 6137 > > int main(int argc, char *argv[]) > { > int sockfd, n, clisize, ipsize, tcpsize, i; > struct sockaddr_in server, client; > char buf[65536], *payload; > struct tcphdr *tcp; > struct ip *iphdr; > > if ((sockfd = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) < 0) > { > perror("socket"); > exit(1); > } > server.sin_family = PF_INET; > server.sin_port = htons(PORT); > server.sin_addr.s_addr = INADDR_ANY; > if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) { > perror("bind"); > exit(1); > } exit(1); > > while (1) > { > clisize = sizeof(client); > if ((n=recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&client, > &clisize))<0) > { > perror("recv"); > exit(1); > } > iphdr = (struct ip *)buf; > if (iphdr->ip_p != IPPROTO_TCP) > { > if (sendto(sockfd, buf, n, 0, (struct sockaddr *)&client, clisize) != > n) > { > perror("send"); > exit(1); > } > } > tcp = (struct tcphdr *)(buf + (4*(iphdr->ip_hl))); > if (!(tcp->th_flags & TH_PUSH)) > { > if (sendto(sockfd, buf, n, 0, (struct sockaddr *)&client, clisize) != > n) > { > perror("send"); > exit(1); > } > continue; > } > > payload = (char *)(tcp + ((tcp->th_off)*4)); > if (strstr(payload, "GET /etc/passwd")) > continue; > > if (sendto(sockfd, buf, n, 0, (struct sockaddr *)&client, clisize) != n) { > perror("send"); > exit(1); > } > } > } > > Can someone tell me what I need to do? > > Attached is the C source file of the above code (for readability) > > > -- > "So crucify the go before it's far too late to leave behind this place so negative and blind and cynical and you will come to find that we are all one mind capable of all that's imagined and all conceivable." -- Tool - Reflection > http://lattera.nosleep.info > http://www.sf.net/projects/hidprox_______________________________________________ freebsd-ipfw@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw > To unsubscribe, send any mail to "freebsd-ipfw-unsubscribe@freebsd.org" > -- "So crucify the go before it's far too late to leave behind this place so negative and blind and cynical and you will come to find that we are all one mind capable of all that's imagined and all conceivable." -- Tool - Reflection http://lattera.nosleep.info http://www.sf.net/projects/hidprox
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1651.204.113.120.202.1074635114.squirrel>