{"id":765,"date":"2026-11-16T15:15:28","date_gmt":"2026-11-16T07:15:28","guid":{"rendered":"http:\/\/www.tanitbennajash.com\/blog\/?p=765"},"modified":"2026-11-16T15:15:28","modified_gmt":"2026-11-16T07:15:28","slug":"how-to-send-custom-packets-with-tins-43c1-00e72a","status":"publish","type":"post","link":"http:\/\/www.tanitbennajash.com\/blog\/2026\/11\/16\/how-to-send-custom-packets-with-tins-43c1-00e72a\/","title":{"rendered":"How to send custom packets with Tins?"},"content":{"rendered":"<p>If you\u2019ve ever worked with network programming, you know how frustrating it can be when built-in tools feel too restrictive\u2014whether you\u2019re testing firewall rules, troubleshooting custom network behavior, or building a low-level network tool that needs to do things no off-the-shelf software can. That\u2019s where Tins comes in, and as someone who\u2019s worked with this powerful library for years\u2014my team is the go-to Tins supplier for developers and engineers who need reliable, production-ready support\u2014I\u2019ve seen firsthand how it simplifies sending custom packets when every other option falls short. <a href=\"https:\/\/www.robustpack.com\/tins\/\">Tins<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.robustpack.com\/uploads\/48746\/small\/printed-tinplate-sheets-for-chemical-can95ca5.jpg\"><\/p>\n<p>Let me start by being honest: a lot of people new to packet crafting get intimidated by the layers of network protocols. There\u2019s Ethernet, IP, TCP, UDP, ICMP\u2026 and each has its own set of headers and rules. Building a custom packet from scratch in C++ (the language Tins is built for) means manually constructing each byte, making sure checksums are correct, handling endianness, and avoiding common bugs that can make your packet get dropped by routers or firewalls. Tins takes all that complexity and wraps it into a clean, intuitive API, so you can focus on what you\u2019re trying to test or build, not the nitty-gritty of packet formatting.<\/p>\n<p>First, let\u2019s make sure we\u2019re on the same page. Tins is a portable C++ network packet library that supports parsing, crafting, sending, and sniffing packets for dozens of protocols. It\u2019s lightweight, designed to work on Linux, macOS, and Windows, and it\u2019s used by everyone from cybersecurity researchers building penetration testing tools to network engineers testing IoT device communication stacks. As a Tins supplier, I\u2019ve seen users come to us because they\u2019ve tried other libraries\u2014like libnet or raw sockets\u2014only to run into portability issues, bad documentation, or limited support when they hit a problem. Tins solves those pain points, but only if you know how to use it correctly to send custom packets.<\/p>\n<p>Let\u2019s walk through a practical example. Suppose you want to send a custom TCP SYN packet to test whether a port on a remote server is open. That\u2019s a common use case for packet crafting, and it\u2019s surprisingly straightforward with Tins. First, you\u2019ll need to set up your development environment: make sure you have a C++ compiler (GCC, Clang, or MSVC), and you\u2019ll need to install Tins. If you\u2019re working with us as a Tins supplier, we can provide pre-built binaries for all major operating systems, plus detailed setup guides that cut out the guesswork of compiling from source. For this example, let\u2019s assume you\u2019ve got Tins installed and are working in a C++ project.<\/p>\n<p>First, we need to define the network layers of our packet. A TCP SYN packet needs four core layers: Ethernet (for layer 2 communication), IPv4 (or IPv6, if you\u2019re working with newer networks), TCP, and a payload (even if it\u2019s empty for a basic SYN). Tins makes creating each layer trivial. You don\u2019t have to calculate the Ethernet header length or handle MAC address formatting; Tins does that for you. Let\u2019s write the code step by step, so it\u2019s clear:<\/p>\n<p>Start by including the necessary Tins headers:<br \/>\n#include &lt;tins\/tins.h&gt;<br \/>\nusing namespace Tins;<\/p>\n<p>Next, we\u2019ll create the packet layers. Let\u2019s say our source MAC address is <code>00:11:22:33:44:55<\/code>, our source IP is <code>192.168.1.100<\/code>, the destination MAC is <code>aa:bb:cc:dd:ee:ff<\/code>, the destination IP is <code>192.168.1.200<\/code>, and we want to test port 80 on the destination.<\/p>\n<p>EthernetII eth = EthernetII(&quot;aa:bb:cc:dd:ee:ff&quot;, &quot;00:11:22:33:44:55&quot;);<br \/>\nIP ip = IP(&quot;192.168.1.100&quot;, &quot;192.168.1.200&quot;);<br \/>\nTCP tcp = TCP();<br \/>\ntcp.sport(12345); \/\/ Random source port, we can use any unused port<br \/>\ntcp.dport(80); \/\/ Destination port we want to test<br \/>\ntcp.flags(TCP::SYN); \/\/ Set the SYN flag, this is what makes this a SYN packet<\/p>\n<p>Wait a second\u2014did you notice that we didn\u2019t set the Ethernet type, the IP checksum, or the TCP checksum? That\u2019s Tins working for you. It automatically calculates all of those values when you send the packet, because it knows that routers and firewalls expect correct checksums to accept the packet. You could manually set them if you needed to, but for most use cases, Tins handles that automatically, which saves you from one of the most common packet crafting mistakes.<\/p>\n<p>Now, we need to combine all the layers into a single packet. Tins uses the concept of PDU (Protocol Data Unit) layers, and when you chain them, it automatically builds the correct encapsulation. So we just need to add the TCP layer to the IP layer, and the IP layer to the Ethernet layer:<\/p>\n<p>PDU::serialization_type packet_data = (eth \/ ip \/ tcp).serialize();<\/p>\n<p>Wait, actually, we don\u2019t even need to call serialize() manually\u2014Tins\u2019 sender class will handle that for us, but it\u2019s good to see what\u2019s happening under the hood. Now, we need to create a sender object to send the packet. The sender needs to know which network interface to use. Let\u2019s say our interface is <code>eth0<\/code> (you can check your interfaces with tools like <code>ip link<\/code> on Linux or <code>ifconfig<\/code> on macOS):<\/p>\n<p>Sender sender(&quot;eth0&quot;);<\/p>\n<p>\/\/ Now send the packet<br \/>\nsender.send(eth \/ ip \/ tcp);<\/p>\n<p>That\u2019s it? That\u2019s the core of sending a custom TCP SYN packet with Tins. If you run this code, it will send exactly the packet you built, with all correct headers and checksums, to the destination you specified. No more manual byte counting, no more buggy checksum calculations. As a Tins supplier, I can tell you that this is one of the most common use cases our customers come to us for\u2014building custom scan tools, testing firewall rules, or troubleshooting port communication. And this example works for almost any protocol, too: if you want to send an ICMP echo request (a ping), you just replace the TCP layer with an ICMP layer, set the type to ICMP::ECHO_REQUEST, and you\u2019re done.<\/p>\n<p>But sending custom packets isn\u2019t just about simple TCP or ICMP. A lot of our more advanced customers need to build packets with non-standard headers, modify existing headers, or even build custom protocols for testing. For example, if you\u2019re testing a custom IoT protocol that runs over UDP, you might need to add a custom payload, or even a custom header, that Tins doesn\u2019t have a built-in class for. Tins makes that easy too. Let\u2019s say you want to add a custom 8-byte header to your UDP packet. Tins lets you create a custom PDU class by inheriting from the PDU base class, and you just define how to serialize and deserialize your header. Our team provides support for building these custom PDUs, which is one of the biggest advantages of working with a dedicated Tins supplier\u2014we\u2019ve helped hundreds of customers implement custom protocols without having to reverse-engineer raw packet bytes.<\/p>\n<p>Another common pitfall when sending custom packets is handling network address translation (NAT) or firewalls. A lot of new Tins users build a packet with a source IP that\u2019s not in their network, and wonder why it never arrives. Tins has options to handle that, but it\u2019s important to remember that when you send a packet on a live network, the network interface might modify the packet (like rewriting the source MAC address). If you want to send a raw packet without any modification from the kernel, Tins has a <code>Sender<\/code> option called <code>cooked<\/code> mode that skips the kernel\u2019s stack, which is essential for some testing scenarios like penetration testing. We walk our customers through that in detail, because getting that setting wrong can lead to hours of troubleshooting.<\/p>\n<p>Let\u2019s talk about another example that\u2019s useful for network engineers: sending a custom IP fragment. If you want to test how a router handles fragmented packets, Tins lets you split a single IP packet into multiple fragments automatically, or build the fragments manually. That\u2019s something that raw sockets make really difficult, because you have to calculate fragment offsets, set the more fragments flag, and handle all the IP fragmentation rules. With Tins, you just call <code>ip.frag()<\/code>, and it splits your packet into the correct fragments, ready to send. Our customers in network security often use this to test intrusion detection systems (IDS) that need to reassemble fragmented packets correctly, and Tins\u2019 support for fragments is one of the most reliable parts of the library for that use case.<\/p>\n<p>Now, I should be transparent: Tins isn\u2019t perfect. It\u2019s a C++ library, so you need to have some familiarity with C++ to use it effectively, and while it\u2019s portable, some protocol features work differently on different operating systems. For example, on Windows, you might need to run your code with administrator privileges to send packets, just like on Linux or macOS. That\u2019s a common question we get from customers\u2014they try to run their code without sudo or admin rights, and wonder why the packet isn\u2019t being sent. We provide clear, platform-specific guides for that, which is part of the service we offer as a Tins supplier.<\/p>\n<p>If you\u2019re new to Tins, start small. Don\u2019t jump into building a complex custom protocol right away. Start with the TCP SYN example I walked you through, test it on your local network, and make sure you can send and receive packets correctly. Tins has excellent documentation, but it\u2019s focused on the library API, not on real-world use cases, which is where our team\u2019s support comes in. We\u2019ve built dozens of custom tools using Tins, and we can help you avoid common mistakes that new users make\u2014like forgetting that endianness matters, or not setting the correct flags for a protocol.<\/p>\n<p>For example, another common mistake is when users build a UDP packet and forget to set the UDP length field. Tins usually handles that, but if you\u2019re adding a custom payload, you have to make sure the length includes both the UDP header and the payload size. We\u2019ve seen customers waste days troubleshooting why their UDP packets are being dropped, just because of that one missing line of code. That\u2019s the kind of small, easy-to-miss detail that makes a big difference, and that\u2019s what we help our customers fix quickly.<\/p>\n<p>As a Tins supplier, our goal isn\u2019t just to sell you the library\u2014it\u2019s to make sure you can actually use it to solve your problems. Whether you\u2019re building a custom security tool, testing network infrastructure, or troubleshooting a weird network issue, Tins gives you the power to send exactly the custom packets you need, without all the boilerplate and bugs that come with building packet crafting from scratch.<\/p>\n<p>Let\u2019s wrap this up. Sending custom packets with Tins is about simplifying a complex task, not making it more complicated. You don\u2019t have to be a network protocol expert to use Tins, but it helps to understand the basics of how network layers work. Start with simple packets, test them, and don\u2019t hesitate to reach out if you run into a roadblock. If you\u2019re looking for reliable Tins binaries, production support, or custom implementation help, we\u2019re here to help you get your project off the ground. We can walk you through every step, from setting up your environment to debugging tricky packet issues, so you can focus on what matters most: your application, not the low-level details of packet crafting.<\/p>\n<p>For more information on Tins\u2019 core features, its official documentation provides detailed API references and protocol support lists. Other useful resources include network programming textbooks that cover low-level packet concepts, and community forums where Tins developers share tips and troubleshooting advice. When you\u2019re ready to implement Tins in your project, don\u2019t forget to check the licensing terms, which are available in full on the official Tins website. And if you have specific requirements for custom packets or need help integrating Tins into your workflow, we encourage you to reach out to our team to discuss your needs in detail.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.robustpack.com\/uploads\/48746\/small\/165mm-diameter-lid-ring-bottom9119c.jpg\"><\/p>\n<p>References<\/p>\n<ol>\n<li>Tins Library Official Documentation<\/li>\n<li>Stevens, W.R., Fenner, B., Rudoff, A. Unix Network Programming, Volume 1: The Sockets Networking API<\/li>\n<li>Tins GitHub Repository<\/li>\n<\/ol>\n<hr \/>\n<p><a href=\"https:\/\/www.robustpack.com\/tinplate\/tinplate-sheet\/\">Tinplate Sheet<\/a> (Note: If you would like to discuss implementing custom packets with Tins, or need access to Tins resources and support, please reach out to our team for a consultation.)<\/p>\n<hr>\n<p><a href=\"https:\/\/www.robustpack.com\/\">Zhangjiagang Great Robust Packing Material Co., Ltd.<\/a><br \/>Zhangjiagang Great Robust Packing Material Co., Ltd. is one of the most professional tins manufacturers and suppliers in China. We are committed to providing high quality customized products with low price. Please rest assured to wholesale bulk durable tins from our factory. Contact us for pricelist.<br \/>Address: No. 16, Xinzha Middle Road, Yangshe Town, Zhangjiagang City, Jiangsu Province<br \/>E-mail: robustpacking@vip.163.com<br \/>WebSite: <a href=\"https:\/\/www.robustpack.com\/\">https:\/\/www.robustpack.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve ever worked with network programming, you know how frustrating it can be when built-in &hellip; <a title=\"How to send custom packets with Tins?\" class=\"hm-read-more\" href=\"http:\/\/www.tanitbennajash.com\/blog\/2026\/11\/16\/how-to-send-custom-packets-with-tins-43c1-00e72a\/\"><span class=\"screen-reader-text\">How to send custom packets with Tins?<\/span>Read more<\/a><\/p>\n","protected":false},"author":209,"featured_media":765,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[728],"class_list":["post-765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-tins-4d32-011d11"],"_links":{"self":[{"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/posts\/765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/users\/209"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/comments?post=765"}],"version-history":[{"count":0,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/posts\/765"}],"wp:attachment":[{"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tanitbennajash.com\/blog\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}