Results 1 to 3 of 3

Thread: how to send ICMP packet

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Posts
    96

    Default how to send ICMP packet

    Hi, I've build ICMP echo request packet:

    Qt Code:
    1. #include <string.h>
    2.  
    3. class CIcmp {
    4. public:
    5. CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData=0);
    6. ~CIcmp();
    7. char* icmpBuildPacket(char *packet);
    8.  
    9. };
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "icmp.h"
    2.  
    3. CIcmp::CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData) {
    4. char packet[strlen(type) + strlen(code) + strlen(checksum) + strlen(identifier) + strlen(sequenceNumber) + strlen(additionalData)];
    5.  
    6. //packet[0] = *type;
    7. strcpy(packet, type);
    8. strcpy(packet, code);
    9. strcpy(packet, checksum);
    10. strcpy(packet, identifier);
    11. strcpy(packet, sequenceNumber);
    12. strcpy(packet, additionalData);
    13.  
    14. icmpBuildPacket(packet);
    15.  
    16. }
    17.  
    18. CIcmp::~CIcmp() {
    19.  
    20. }
    21.  
    22. char* CIcmp::icmpBuildPacket(char *packet) {
    23. return packet;
    24. }
    To copy to clipboard, switch view to plain text mode 

    Now I want to know, if I did that correctly? (I know I have to calculate the checksum, but let's say the additionalData is always 0 for now)

    Well, now I need a way to send this packet over the network to destination --> what would be the best way to do that?

  2. #2
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to send ICMP packet

    raw socket.
    i think you have to write an own rawsocket class, which handles the socket platform specific.

    maybe this helps you:
    http://www.c-worker.ch/winsock/ping.cpp
    http://www.alhem.net/Sockets/index.html
    Last edited by kernel_panic; 30th October 2007 at 13:52.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to send ICMP packet

    If you are using a secure* system, you need super-user priviledges to craft icmp packets and you have to use platform dependent code as already suggested.


    *) non-Windows

Similar Threads

  1. QtNetwork send ICMP Packet
    By SlowTree in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 20:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.