raw ip paket sendto error

Stefan stefan at sf-net.com
Mon Apr 10 09:40:53 UTC 2006


Hi,

I'm trying to port my little application to the FreeBSD-system and  
encountered some difficults I can't solve. The program is running  
fine on SunOS, OpenBSD, Mac OS X and Debian GNU/Linux so I thought it  
should run fine on FreeBSD too. Maybe I forget something and you can  
help me out?

The first problem I had was at the function getaddrinfo. If I don't  
submit a hints struct I get an error like this:
  "servname not supported for ai_socktype"

This is the source part where the error occured:

if((getaddrinfoError = getaddrinfo(src_addr, src_port, NULL, &src_ai))
        != 0) {
         fprintf(stderr, "Error getaddrinfo (src address): %s\n",
                 gai_strerror(getaddrinfoError));
         exit(EXIT_FAILURE);
     }

When I changed it to use a hint like this:

struct addrinfo hints;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = 0;
hints.ai_protocol = 0;
hints.ai_addrlen = 0;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;

The function runs fine like I expected. Why does this happen on  
FreeBSD systems?


Another major problem I have is with the sendto function. I've  
created a raw IP paket and tried to send it out and I get this error:

"Invalid argument"

Here is the source part for the sendto function.

sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on));
result = sendto(sockfd, packet, (sizeof(struct ip) + sizeof(struct  
udphdr)
                     + payload_len), 0, (struct sockaddr *)&sin4,
                     (socklen_t)sizeof(struct sockaddr));

I can't figure out where the problem could be. I even don't know what  
the error means or where I should look for. Do you have any suggestions?

Best regards, Stefan


More information about the freebsd-net mailing list