Thread: write() function - no such device or address

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

    write() function - no such device or address

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

    here is my code for now
    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
    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:
    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
    Bangalore, India
    >write(sockfd, (struct arppacket *)&pseudarp, sizeof((struct arppacket *)&pseudoarp));
    should this not be like:
    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
    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, 02:07 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM