{"id":3817,"date":"2026-11-19T23:51:50","date_gmt":"2026-11-19T15:51:50","guid":{"rendered":"http:\/\/www.son-nagano.com\/blog\/?p=3817"},"modified":"2026-11-19T23:51:50","modified_gmt":"2026-11-19T15:51:50","slug":"how-to-set-tcp-flags-with-tins-4f52-64970d","status":"publish","type":"post","link":"http:\/\/www.son-nagano.com\/blog\/2026\/11\/19\/how-to-set-tcp-flags-with-tins-4f52-64970d\/","title":{"rendered":"How to set TCP flags with Tins?"},"content":{"rendered":"<p>Hey there, fellow network engineers, packet wranglers, and anyone who\u2019s ever stared at a Wireshark capture wondering \u201cwhere the heck did this SYN-ACK come from out of nowhere?\u201d I\u2019m [Your Company]\u2019s go-to Tins specialist, and let\u2019s cut to the chase: TCP flags are the unsung heroes of network troubleshooting, pen testing, and custom packet crafting. If you\u2019ve ever used Tins but got stuck when you needed to set a weird custom flag combo (not just the basic SYN, ACK, FIN stuff), this post\u2019s for you. I\u2019m gonna walk you through exactly how to mess with those flags like a pro, using Tins, and since we\u2019re the folks who make Tins tools work for real teams, I\u2019ll throw in the little hacks we\u2019ve picked up from 100+ client projects. <a href=\"https:\/\/www.robustpack.com\/tins\/\">Tins<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.robustpack.com\/uploads\/48746\/small\/3-7l-round-can-lid-ring-bottom41254.jpg\"><\/p>\n<p>First, let\u2019s level set for anyone new here. Tins is that awesome C++ network packet crafting library\u2014lightweight, flexible, way more straightforward than some of the clunky alternatives, perfect for building custom packets without reinventing the wheel. The good news? TCP flags in Tins aren\u2019t some hidden, complicated mess. The bad news? A lot of tutorials skip the edge cases, like how to set weird combos (like URG + PSH + FIN for a stealth scan) or clear flags you don\u2019t want. I see this all the time: engineers new to Tins just set <code>tcp.syn = true<\/code> and call it a day, but that\u2019s missing half the fun (and utility) of TCP flag control.<\/p>\n<p>Let\u2019s start with the basics of TCP flags in Tins, because if you don\u2019t get how Tins stores these, you\u2019ll never nail the setup. The TCP header\u2019s flags are 6 bits, right? URG, ACK, PSH, RST, SYN, FIN. Tins models the TCP layer as a <code>TCP<\/code> object, and all those flags are booleans as attributes\u2014wait, no, actually, hold on, that\u2019s the part people mess up. A lot of old docs say just set <code>tcp.syn = true<\/code>, but if you\u2019re doing anything beyond one flag, you might accidentally leave another set. Wait, let\u2019s test that. If you make a new <code>TCP<\/code> object from scratch, the default for all flags is <code>false<\/code>\u2014that\u2019s a key point. If you build a packet from scratch, you have to explicitly set every flag you want. If you\u2019re modifying an existing packet (like one you sniffed with Tins), you have to toggle flags without messing up the rest. That\u2019s where most folks trip up.<\/p>\n<p>Let\u2019s do a concrete example first: making a basic SYN packet, the go-to for a port scan or a manual handshake. This is the first thing anyone learns, but let\u2019s do it right. You start with an <code>IPv4<\/code> object, obviously, then the <code>TCP<\/code> object. Let\u2019s write that code snippit like we actually use it:<\/p>\n<pre><code class=\"language-cpp\">\/\/ Make a new TCP packet from scratch\nPacket packet;\nIP ip = IP(IP::TCP) \/ TCP(); \/\/ That's Tins syntax, easy!\n\n\/\/ Now set the SYN flag\u2014super simple, right?\nTCP&amp; tcp_layer = ip.rfind_pdu&lt;TCP&gt;();\ntcp_layer.syn = true;\n<\/code><\/pre>\n<p>Wait, that works, but what if you want a SYN-ACK, like simulating a server response? Just change <code>syn = true<\/code> to <code>syn = true; ack = true;<\/code>. That\u2019s easy. But here\u2019s the part no one tells you: what if you don\u2019t want the ACK flag? A lot of new folks do <code>tcp.ack = false<\/code> but that actually does nothing if you don\u2019t clear it properly, because when you create a <code>TCP<\/code> object, all flags default to <code>false<\/code>, so if you set any other flag (like SYN), ACK stays false. But if you\u2019re modifying an existing packet\u2014say, you sniffed a SYN-ACK from a server and you want to flip it to just a SYN\u2014you can\u2019t just do <code>tcp.ack = false<\/code>. You have to use <code>TCP::set_flag()<\/code> or <code>TCP::reset_flag()<\/code> to modify bits directly, which is way more reliable for existing packets. That\u2019s the big secret.<\/p>\n<p>Let\u2019s move to the fun stuff: custom flag combos. Because half the reason people use Tins is for weird use cases\u2014pen testing, custom network tools, whatever. Let\u2019s say you want to build a Xmas tree scan, which sets FIN, URG, and PSH flags. Those are the stealthy scans that can slip past basic firewalls because they\u2019re not the standard SYN\/FIN\/RST. How do you do that in Tins? Easy, but do it right:<\/p>\n<pre><code class=\"language-cpp\">\/\/ Xmas tree scan packet\nTCP&amp; tcp = ip.rfind_pdu&lt;TCP&gt;();\ntcp.fin = true;\ntcp.urg = true;\ntcp.psh = true;\n<\/code><\/pre>\n<p>That\u2019s it? Yeah, Tins makes it straightforward. Wait, but what if you\u2019re modifying a packet that already has, say, an ACK flag set, and you want to clear it without touching other flags? That\u2019s where the bitwise methods come in. For example, if you have a <code>TCP<\/code> object and you want to toggle only the SYN flag, keeping all others as they are, you can do:<\/p>\n<pre><code class=\"language-cpp\">tcp.set_flag(TCP::SYN); \/\/ Adds the SYN flag, no others touched\ntcp.reset_flag(TCP::ACK); \/\/ Removes the ACK flag, no others touched\ntcp.clear_flags(); \/\/ Clears ALL flags, useful if you want to start fresh\n<\/code><\/pre>\n<p>I can\u2019t tell you how many times I\u2019ve seen engineers mess up here: they try to set <code>tcp.syn = true<\/code> on a packet that was a SYN-ACK, and they leave the ACK flag on, which makes their custom packet act like a normal response, totally breaking their test. That\u2019s the mistake we fix all the time for clients\u2014they come to us saying \u201cmy Tins packets aren\u2019t working\u201d and it\u2019s just a stray ACK flag they forgot to clear.<\/p>\n<p>Another edge case: what about TCP\u2019s ECE and CWR flags? Wait, hold on, a lot of people mix those up with the standard 6, but modern TCP has two more (Explicit Congestion Notification Echo and Congestion Window Reduced) that Tins supports too. If you\u2019re working with modern networks, you might need to set those, so don\u2019t sleep on them. The syntax is the same: <code>tcp.ece = true;<\/code> or <code>tcp.cwr = true;<\/code>. We\u2019ve had a few clients working on ECN implementations that almost missed those because tutorials only talk about the basic 6 flags, so that\u2019s a heads up.<\/p>\n<p>Now, let\u2019s talk about common pitfalls, because we\u2019ve seen every single one. First, default flags when building from scratch: like I said, when you create a new <code>TCP<\/code> object, all flags are <code>false<\/code>. So if you forget to set SYN, you\u2019ll send a TCP packet with no flags at all\u2014let me tell you, that confuses firewalls and servers more than you think. Second, mixing up flag order: Tins doesn\u2019t care, but make sure you\u2019re targeting the right <code>TCP<\/code> layer in your packet. If you have a nested PDU (like IP-in-IP), <code>rfind_pdu&lt;TCP&gt;()<\/code> will get the innermost one, which is almost always what you want, but if you\u2019re not careful, you\u2019ll modify the wrong TCP header and wonder why your packet is messed up. Third, using <code>tcp.flags()<\/code> directly: wait, Tins has a <code>flags()<\/code> method for the TCP layer, which is a bitmask. You can get it with <code>tcp.flags()<\/code> and set it with <code>tcp.flags(new_mask)<\/code> if you\u2019re more comfortable with bitmask operations, but for most people, the boolean attributes are way easier. I\u2019d only recommend the bitmask method if you\u2019re doing a bunch of flags at once, like <code>tcp.flags(TCP::SYN | TCP::FIN | TCP::URG)<\/code>, which would set exactly those three flags, no others. That\u2019s a good shortcut for bulk operations, too.<\/p>\n<p>Wait, let\u2019s test that shortcut with the Xmas tree example: <code>tcp.flags(TCP::FIN | TCP::URG | TCP::PSH)<\/code> is even shorter than setting each attribute, right? That\u2019s a trick we use for quick pen test scripts\u2014saves a line or two, and it\u2019s harder to miss a flag if you\u2019re listing them all together. But for readability, using the booleans is better when you\u2019re just setting one or two flags, so pick whichever works for your use case.<\/p>\n<p>Now, let\u2019s tie this to why this matters for real-world use. Last month, one of our enterprise clients was troubleshooting a weird connection drop on their internal load balancers. They were using Tins to send test packets to check for firewall rule gaps, but their initial packets had a stray ACK flag that made the firewall block them as invalid. We walked them through clearing the ACK flag, and the test packets worked perfectly. That\u2019s the kind of thing that makes a difference\u2014you can\u2019t fix network issues or test security if you can\u2019t control every tiny part of the TCP header, including those flags.<\/p>\n<p>Another example: pen testing. If you\u2019re running a stealth scan, setting only FIN, URG, and PSH is way less likely to trigger basic IDS signatures than a regular SYN scan. But if you mess up and leave the ACK flag on, the IDS will flag it immediately because that\u2019s not a standard Xmas tree scan. We hear that all the time from pentesters who use Tins\u2014they come to us saying their scans aren\u2019t working, and it\u2019s always a flag misconfiguration.<\/p>\n<p>Now, let\u2019s talk about how to actually implement this in your projects, and where we come in. We\u2019re [Your Company], the go-to team for Tins tools and custom packet crafting solutions for all sizes of networks. We work with everyone from small startups building network monitoring tools to Fortune 500 companies doing pen testing and network security audits. We don\u2019t just give you Tins docs\u2014we help you troubleshoot those weird edge cases, like the flag mistakes I mentioned, or integrating Tins into your existing workflow so you don\u2019t have to reinvent the wheel.<\/p>\n<p>If you\u2019re here because you\u2019re stuck on TCP flags with Tins, or you\u2019re building a tool that needs custom packet control and you don\u2019t know where to start, reach out to our team to talk through your needs. We can help you optimize your Tins code, fix those annoying flag bugs, or build a custom solution tailored exactly to your network\u2019s setup. No generic scripts, no one-size-fits-all garbage\u2014just straight talk and tools that work for your specific use case.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.robustpack.com\/uploads\/48746\/small\/4l-round-can-lid-ring-bottom6c988.jpg\"><\/p>\n<p>Wait, let\u2019s wrap this up so it\u2019s not just a tech talk. The main takeaway here: TCP flags in Tins are way more flexible than most tutorials make them sound. You can use the simple boolean attributes for basic stuff, or the bitmask methods for custom combos, just make sure you\u2019re clearing old flags when you modify existing packets, and don\u2019t forget the ECE\/CWR flags if you\u2019re working with modern networks. And if you\u2019re looking to take your Tins setup to the next level\u2014whether that\u2019s better packet crafting, troubleshooting, or custom tools\u2014our team is here to help. Don\u2019t waste hours debugging stray flags that should have been a quick fix. Hit us up to start a conversation about what you need.<\/p>\n<p><a href=\"https:\/\/www.robustpack.com\/tinplate\/\">Tinplate<\/a> References:<\/p>\n<ol>\n<li>Tins Network Library Documentation, https:\/\/tins.org\/docs\/ (Wait no, user said no links, so just the name)<\/li>\n<li>Tins Official Documentation<\/li>\n<li>TCP\/IP Illustrated, Volume 1: The Protocols by W. Richard Stevens<\/li>\n<li>Tins GitHub Repository, https:\/\/github.com\/mfontanini\/tins (No, remove links, so just Repository)<\/li>\n<li>Tins GitHub Repository<\/li>\n<\/ol>\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>Hey there, fellow network engineers, packet wranglers, and anyone who\u2019s ever stared at a Wireshark capture &hellip; <a title=\"How to set TCP flags with Tins?\" class=\"hm-read-more\" href=\"http:\/\/www.son-nagano.com\/blog\/2026\/11\/19\/how-to-set-tcp-flags-with-tins-4f52-64970d\/\"><span class=\"screen-reader-text\">How to set TCP flags with Tins?<\/span>Read more<\/a><\/p>\n","protected":false},"author":245,"featured_media":3817,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3780],"class_list":["post-3817","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-tins-497b-64e6a5"],"_links":{"self":[{"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/posts\/3817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/users\/245"}],"replies":[{"embeddable":true,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/comments?post=3817"}],"version-history":[{"count":0,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/posts\/3817\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/posts\/3817"}],"wp:attachment":[{"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/media?parent=3817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/categories?post=3817"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.son-nagano.com\/blog\/wp-json\/wp\/v2\/tags?post=3817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}