sendto on raw-socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




--- Praveen C H <praveenc@sasken.com> schrieb: > Hi
> 	Thanks in advance for the help.
> 	
> 	I am trying to locate where the metric for a route
> is maintained. I 		
> 	could not find it in struct rtable and struct
> dstentry.
> 	
> 	Can anyone help?
> 
> manojs
> -
> : send the line
> "unsubscribe linux-net" in
> the body of a message to majordomo@vger.kernel.org

Thanks in advance,
I'm trying to write a program to send datagram through
a RAW-SOCKET. I encounter following problem>
	1. The sendto function returns "Invalid argument".
After my own investigation i thimk the invalid
argument is the socket. Why do i say that?
	2. When i call recfrom in the program before calling
sendto on the same socket, i can send the packet
without error.
	But When i call directly the sendto function on the
socket, it fails.

Why? I love to have your suggestion.

Here are the programs>
1. Without calling recvfrom

 sprintf(snd_buffer,
"BLABLABLABLABLABLABLABLABLABLABLA...\n");
      if (sendto(sockfd, (const void *)snd_buffer,
sizeof(snd_buffer), 0,
         (struct sockaddr *)&dest_addr, from_len) < 0)
{
         perror("sendto");
         exit(-1);
      }


2. Calling recvfrom before calling sendto>
 #if 1
   if ((recv_ret = recvfrom(sockfd, (void *)buffer,
sizeof(buffer),
                   0, (struct sockaddr *)&from,
&from_len)) >= 0) {
      for (i = 0; i < recv_ret; i++) {
            printf("%02x%s", (unsigned char)buffer[i],
            i == recv_ret - 1 ? "\n" : " ");
      }
      printf("sin_family = %lu\n sin_port = %d\n
sin_addr.s_addr = %08x\n",
      from.sin_family, ntohs(from.sin_port),
from.sin_addr.s_addr);
   }
   #endif
   while ( 1 )
   {

      #if 1
      sprintf(snd_buffer,
"BLABLABLABLABLABLABLABLABLABLABLA...\n");
      if (sendto(sockfd, (const void *)snd_buffer,
sizeof(snd_buffer), 0,
         (struct sockaddr *)&dest_addr, from_len) < 0)
{
         perror("sendto");
         exit(-1);
      }
      printf("I've send\n");
      #endif
   }




__________________________________________________________________
Do You Yahoo!?
Gesendet von Yahoo! Mail - http://mail.yahoo.de
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux