write() function - no such device or address

This is a discussion on write() function - no such device or address within the Linux Programming forums, part of the Platform Specific Boards category; hi! i want to know how to build my own packets. especially arp packets. here is my code for now ...

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214

    write() function - no such device or address

    hi!
    i want to know how to build my own packets.
    especially arp packets.

    here is my code for now
    Code:
    struct arppacket
    {
    ...
    ...
    } pseudoarp;
    
    ...
    ...
    //every member is filled with the needed infos
    
    sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
    
    write(sockfd, (struct arppacket *)&pseudarp, sizeof((struct arppacket *)&pseudoarp));
    
    //when i do error checking on the write function
    //it give me "no such device or address"
    ...
    i checked the infos i filled the structure members with, and they were correct.
    what could be my problem?

    thank you!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Did you error check the return from the socket() call?

    Also, this is incorrect:
    >>sizeof((struct arppacket *)&pseudoarp)
    You are meant to pass the number of bytes you want to send, so I guess you're wanting something more like this:
    >>sizeof(pseudoarp)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >write(sockfd, (struct arppacket *)&pseudarp, sizeof((struct arppacket *)&pseudoarp));
    should this not be like:
    Code:
    write(sockfd, (struct arppacket *)&pseudarp, sizeof(pseudoarp));
    ???

    The sizeof() in your case will always return the same number irrespective of the members in it, because you are getting the size of the Pointer variable, which will be constant on your machine for any given dat type. Instead, sizeof(pseudoarp) gives you the right number of bytes used for this structure instance.

  4. #4
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    thanks for your replies.

    i figured it out with the sendto() call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 02:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21