Does TCPdump strip any headers when receiving packets?











up vote
1
down vote

favorite












So i am attempting to send an already constructed packet over a RAW socket interface (these are packets that have been previously captured and i want to resend them without changing the packet integrity) and am using TCPdump to check that the packets are going over correctly (surprise they are not).



The packets are physically being sent but are always 24 bytes short of what my "sent" returns.



In wireshark my eth headers seem to be erased as my source and dest MAC addresses are "00:00:00:00:00



sock setup is as follows



sock = socket(AF_PACKET,SOCK_RAW,IPPROTO_RAW);
if(sock==-1)
{
qDebug() << "sock error";
}

int reuse = 1;

if(setsockopt(sock, IPPROTO_RAW, IP_HDRINCL, (char *)&reuse, sizeof(reuse)) < 0)
{
qDebug() << "error setting reuse"
}
else
{
"setting reuse"
}

struct sockaddr_ll sll;
struct ifreq ifr;

bzero(&sll, sizeof(sll));
bzero(&ifr, sizeof(ifr));

sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
sll.sll_protocol = htons(IPPROTO_RAW);
sll.sll_halen = ETH_ALEN;

strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
if(ioctl(sock,SIOCGIFINDEX,&ifr) == -1)
{
qDebug() << "error getting interface name";
}
strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
if(ioctl(sock,SIOCGIFHWADDR,&ifr) == -1)
{
qDebug() << "error getting interface name";
}

if(bind(sock,(struct sockaddr *)&sll,sizeof(sll))==-1)
{
qDebug() << "error binding sock";
}


after this im using



int size = write(sock,(const void*)&packet,hdr.caplen);


i've tried sendto in the past but it would always reconfigure things so this was my next solution which also isnt working as i would like.



I'm not the most savy with TCP/IP stuff so any help would be greatly appreciated!










share|improve this question




























    up vote
    1
    down vote

    favorite












    So i am attempting to send an already constructed packet over a RAW socket interface (these are packets that have been previously captured and i want to resend them without changing the packet integrity) and am using TCPdump to check that the packets are going over correctly (surprise they are not).



    The packets are physically being sent but are always 24 bytes short of what my "sent" returns.



    In wireshark my eth headers seem to be erased as my source and dest MAC addresses are "00:00:00:00:00



    sock setup is as follows



    sock = socket(AF_PACKET,SOCK_RAW,IPPROTO_RAW);
    if(sock==-1)
    {
    qDebug() << "sock error";
    }

    int reuse = 1;

    if(setsockopt(sock, IPPROTO_RAW, IP_HDRINCL, (char *)&reuse, sizeof(reuse)) < 0)
    {
    qDebug() << "error setting reuse"
    }
    else
    {
    "setting reuse"
    }

    struct sockaddr_ll sll;
    struct ifreq ifr;

    bzero(&sll, sizeof(sll));
    bzero(&ifr, sizeof(ifr));

    sll.sll_family = AF_PACKET;
    sll.sll_ifindex = ifr.ifr_ifindex;
    sll.sll_protocol = htons(IPPROTO_RAW);
    sll.sll_halen = ETH_ALEN;

    strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
    if(ioctl(sock,SIOCGIFINDEX,&ifr) == -1)
    {
    qDebug() << "error getting interface name";
    }
    strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
    if(ioctl(sock,SIOCGIFHWADDR,&ifr) == -1)
    {
    qDebug() << "error getting interface name";
    }

    if(bind(sock,(struct sockaddr *)&sll,sizeof(sll))==-1)
    {
    qDebug() << "error binding sock";
    }


    after this im using



    int size = write(sock,(const void*)&packet,hdr.caplen);


    i've tried sendto in the past but it would always reconfigure things so this was my next solution which also isnt working as i would like.



    I'm not the most savy with TCP/IP stuff so any help would be greatly appreciated!










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      So i am attempting to send an already constructed packet over a RAW socket interface (these are packets that have been previously captured and i want to resend them without changing the packet integrity) and am using TCPdump to check that the packets are going over correctly (surprise they are not).



      The packets are physically being sent but are always 24 bytes short of what my "sent" returns.



      In wireshark my eth headers seem to be erased as my source and dest MAC addresses are "00:00:00:00:00



      sock setup is as follows



      sock = socket(AF_PACKET,SOCK_RAW,IPPROTO_RAW);
      if(sock==-1)
      {
      qDebug() << "sock error";
      }

      int reuse = 1;

      if(setsockopt(sock, IPPROTO_RAW, IP_HDRINCL, (char *)&reuse, sizeof(reuse)) < 0)
      {
      qDebug() << "error setting reuse"
      }
      else
      {
      "setting reuse"
      }

      struct sockaddr_ll sll;
      struct ifreq ifr;

      bzero(&sll, sizeof(sll));
      bzero(&ifr, sizeof(ifr));

      sll.sll_family = AF_PACKET;
      sll.sll_ifindex = ifr.ifr_ifindex;
      sll.sll_protocol = htons(IPPROTO_RAW);
      sll.sll_halen = ETH_ALEN;

      strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
      if(ioctl(sock,SIOCGIFINDEX,&ifr) == -1)
      {
      qDebug() << "error getting interface name";
      }
      strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
      if(ioctl(sock,SIOCGIFHWADDR,&ifr) == -1)
      {
      qDebug() << "error getting interface name";
      }

      if(bind(sock,(struct sockaddr *)&sll,sizeof(sll))==-1)
      {
      qDebug() << "error binding sock";
      }


      after this im using



      int size = write(sock,(const void*)&packet,hdr.caplen);


      i've tried sendto in the past but it would always reconfigure things so this was my next solution which also isnt working as i would like.



      I'm not the most savy with TCP/IP stuff so any help would be greatly appreciated!










      share|improve this question















      So i am attempting to send an already constructed packet over a RAW socket interface (these are packets that have been previously captured and i want to resend them without changing the packet integrity) and am using TCPdump to check that the packets are going over correctly (surprise they are not).



      The packets are physically being sent but are always 24 bytes short of what my "sent" returns.



      In wireshark my eth headers seem to be erased as my source and dest MAC addresses are "00:00:00:00:00



      sock setup is as follows



      sock = socket(AF_PACKET,SOCK_RAW,IPPROTO_RAW);
      if(sock==-1)
      {
      qDebug() << "sock error";
      }

      int reuse = 1;

      if(setsockopt(sock, IPPROTO_RAW, IP_HDRINCL, (char *)&reuse, sizeof(reuse)) < 0)
      {
      qDebug() << "error setting reuse"
      }
      else
      {
      "setting reuse"
      }

      struct sockaddr_ll sll;
      struct ifreq ifr;

      bzero(&sll, sizeof(sll));
      bzero(&ifr, sizeof(ifr));

      sll.sll_family = AF_PACKET;
      sll.sll_ifindex = ifr.ifr_ifindex;
      sll.sll_protocol = htons(IPPROTO_RAW);
      sll.sll_halen = ETH_ALEN;

      strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
      if(ioctl(sock,SIOCGIFINDEX,&ifr) == -1)
      {
      qDebug() << "error getting interface name";
      }
      strncpy((char*)ifr.ifr_ifrn.ifrn_name,interface.toUtf8.constData(),IFNAMSIZ);
      if(ioctl(sock,SIOCGIFHWADDR,&ifr) == -1)
      {
      qDebug() << "error getting interface name";
      }

      if(bind(sock,(struct sockaddr *)&sll,sizeof(sll))==-1)
      {
      qDebug() << "error binding sock";
      }


      after this im using



      int size = write(sock,(const void*)&packet,hdr.caplen);


      i've tried sendto in the past but it would always reconfigure things so this was my next solution which also isnt working as i would like.



      I'm not the most savy with TCP/IP stuff so any help would be greatly appreciated!







      c++ c posix tcp-ip raw-sockets






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 16:53









      Oliv

      8,1351954




      8,1351954










      asked Nov 20 at 15:57









      beethreepeeoh

      161




      161
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          okay so after just trying a bunch of different stuff i landed on what seems to be my solution.



          i created a second pointer that will point to the top of the packet and send that instead.



          (char *)sendingPacket;
          struct ethhdr *ethh = (struct ethhdr*)packet;
          sendingPacket = (char*) ethh;


          i don't really understand why this works but sending the other packet doesn't so if anyone has insight please share!






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396869%2fdoes-tcpdump-strip-any-headers-when-receiving-packets%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            okay so after just trying a bunch of different stuff i landed on what seems to be my solution.



            i created a second pointer that will point to the top of the packet and send that instead.



            (char *)sendingPacket;
            struct ethhdr *ethh = (struct ethhdr*)packet;
            sendingPacket = (char*) ethh;


            i don't really understand why this works but sending the other packet doesn't so if anyone has insight please share!






            share|improve this answer

























              up vote
              0
              down vote













              okay so after just trying a bunch of different stuff i landed on what seems to be my solution.



              i created a second pointer that will point to the top of the packet and send that instead.



              (char *)sendingPacket;
              struct ethhdr *ethh = (struct ethhdr*)packet;
              sendingPacket = (char*) ethh;


              i don't really understand why this works but sending the other packet doesn't so if anyone has insight please share!






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                okay so after just trying a bunch of different stuff i landed on what seems to be my solution.



                i created a second pointer that will point to the top of the packet and send that instead.



                (char *)sendingPacket;
                struct ethhdr *ethh = (struct ethhdr*)packet;
                sendingPacket = (char*) ethh;


                i don't really understand why this works but sending the other packet doesn't so if anyone has insight please share!






                share|improve this answer












                okay so after just trying a bunch of different stuff i landed on what seems to be my solution.



                i created a second pointer that will point to the top of the packet and send that instead.



                (char *)sendingPacket;
                struct ethhdr *ethh = (struct ethhdr*)packet;
                sendingPacket = (char*) ethh;


                i don't really understand why this works but sending the other packet doesn't so if anyone has insight please share!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 18:11









                beethreepeeoh

                161




                161






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396869%2fdoes-tcpdump-strip-any-headers-when-receiving-packets%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen