Date: Thu, 25 Jan 2001 00:24:04 -0800 (PST) From: John <youzkz@yahoo.com> To: freebsd-net@FreeBSD.ORG Subject: problems compiling raw socket program Message-ID: <20010125082404.9311.qmail@web3004.mail.yahoo.com>
next in thread | raw e-mail | index | archive | help
--0-197227092-980411044=:7396 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Can anyone enlighten me on why I can't compile? I use gcc -o rawsocket rawsocket.c and I get: bash-2.03$ gcc -o rawsocket rawsocket.c In file included from rawsocket.c:7: /usr/include/netinet/ip.h:152: parse error before `n_long' /usr/include/netinet/ip.h:152: warning: no semicolon at end of struct or union /usr/include/netinet/ip.h:152: warning: no semicolon at end of struct or union /usr/include/netinet/ip.h:155: parse error before `n_long' /usr/include/netinet/ip.h:155: warning: no semicolon at end of struct or union /usr/include/netinet/ip.h:156: warning: data definition has no type or storage class /usr/include/netinet/ip.h:157: parse error before `}' /usr/include/netinet/ip.h:157: warning: data definition has no type or storage class /usr/include/netinet/ip.h:158: parse error before `}' bash-2.03$ thanks john __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ --0-197227092-980411044=:7396 Content-Type: text/plain; name="rawsocket.c" Content-Description: rawsocket.c Content-Disposition: inline; filename="rawsocket.c" #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <netdb.h> #include <stdio.h> #include <netinet/ip.h> #include <netinet/tcp.h> #include <arpa/inet.h> #include <unistd.h> #include <stdlib.h> #define PORTNUMBER 80 int main(void) { int n, s; char buf[4096]; char hostname[64]; //struct hostent *hp; struct sockaddr_in name; struct ip *iph = (struct ip *) buf; struct tcphdr *tcph = (struct tcphdr *) buf + sizeof (struct ip); memset (buf, 0, 4096); /* zero out the buffer */ /* we'll now fill in the ip/tcp header values, see above for explanations */ iph->ip_hl = 5; iph->ip_v = 4; iph->ip_tos = 0; iph->ip_len = sizeof (struct ip) + sizeof (struct tcphdr); /* no payload */ iph->ip_id = htonl (54321); /* the value doesn't matter here */ iph->ip_off = 0; iph->ip_ttl = 255; iph->ip_p = 6; iph->ip_sum = 0; /* set it to 0 before computing the actual checksum later */ iph->ip_src.s_addr = inet_addr ("1.2.3.4");/* SYN's can be blindly spoofed */ iph->ip_dst.s_addr = name.sin_addr.s_addr; tcph->th_sport = htons (1234); /* arbitrary port */ tcph->th_dport = htons (PORTNUMBER); tcph->th_seq = random ();/* in a SYN packet, the sequence is a random */ tcph->th_ack = 0;/* number, and the ack sequence is 0 in the 1st packet */ tcph->th_x2 = 0; tcph->th_off = 0; /* first and only tcp segment */ tcph->th_flags = TH_SYN; /* initial connection request */ tcph->th_win = htonl (65535); /* maximum allowed window size */ tcph->th_sum = 0;/* if you set a checksum to zero, your kernel's IP stack should fill in the correct checksum during transmission */ tcph->th_urp = 0; iph->ip_sum = csum ((unsigned short *) buf, iph->ip_len >> 1); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) < 0) { perror("socket"); exit(1); } /* finally, it is very advisable to do a IP_HDRINCL call, to make sure that the kernel knows the header is included in the data, and doesn't insert its own header into the packet before our data */ { /* lets do it the ugly way.. */ int one = 1; const int *val = &one; if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0) printf ("Warning: Cannot set HDRINCL!\n"); } //create the address of the server, also local memset(&name, 0, sizeof(struct sockaddr_in)); name.sin_family = AF_INET; name.sin_port = htons(PORTNUMBER); name.sin_addr.s_addr = inet_addr ("127.0.0.1"); if (sendto (s, /* our socket */ buf, /* the buffer containing headers and data */ iph->ip_len, /* total length of our datagram */ 0, /* routing flags, normally always 0 */ (struct sockaddr *) &name, /* socket addr, just like in */ sizeof (name)) < 0) /* a normal send() */ printf ("error\n"); else printf ("."); close(s); exit(0); } --0-197227092-980411044=:7396-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010125082404.9311.qmail>