Date: Wed, 24 Jun 1998 17:40:43 -0700 (PDT) From: Nate Lawson <nate@almond.elite.net> To: freebsd-bugs@FreeBSD.ORG, freebsd-net@FreeBSD.ORG Subject: Apparent bug in sendto() with raw sockets Message-ID: <199806250040.RAA05172@almond.elite.net>
next in thread | raw e-mail | index | archive | help
I had some code that opens a raw socket and sends packets. It worked on 2.0.5 and I recently had to dust it off. To my surprise, the same code (recompiled, of course) now gets "Invalid argument" in the sendto() call on 2.2.5. I stripped out all irrelevant code, and came up with the code fragment below. It works on: OpenBSD 2.4, Linux 2.0.something It fails on: FreeBSD 2.2.5, 2.2.6, 3.0-current The error is always EINVAL in sendto(). Answers? Thanks, Nate /* Cut here for sample code */ #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> main () { static struct sockaddr sa; int fd; int on=1; struct sockaddr_in *p; u_char buf[] = { 0x45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xa, 0x2, 0x2, 0x2, 0xa, 0x1, 0x1, 0x1 }; p = (struct sockaddr_in*)&sa; p->sin_family = AF_INET; p->sin_addr.s_addr = inet_addr ("10.1.1.1"); if ((fd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { perror("socket"); exit(1); } if (setsockopt (fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) { perror("setsockopt IP_HDRINCL"); exit(1); } if (sendto (fd, buf, sizeof(buf), 0, &sa, sizeof(sa)) < 0) { perror("sendto"); exit(1); } fprintf (stderr, "Success.\n"); exit(0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806250040.RAA05172>