Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×

TwIP - An IP Stack In a Tweet 81

Adam Dunkels writes "Inspired by the Twitter-sized program that crashes Mac OS X, I just wrote a really, really rudimentary IP stack called twIP, small enough to fit in a Twitter tweet. Although twIP is very far away from a real IP stack, it can do the first task of any IP stack: respond to pings. The entire source code can be found in this 128-character-long tweet. For those who are interested in low-level network programming, a code walkthrough with instructions on how to run the code under FreeBSD is available here. The FAQ: Q: why? A: for fun."
This discussion has been archived. No new comments can be posted.

TwIP - An IP Stack In a Tweet

Comments Filter:
  • by Looce ( 1062620 ) * on Sunday August 30, 2009 @05:22PM (#29254979) Journal

    The underlying system must provide a way for user programs to receive and send IP packets.

    This is where I stopped reading. Just... no. This is just a program that echoes every single thing back to the originator.

    • by something_wicked_thi ( 918168 ) on Sunday August 30, 2009 @05:38PM (#29255133)

      Yeah, I've got a program for the author that fits in a tweet:

      #include
      int main() {
          puts("You're a moron and a braggart.");
      }

      • Re: (Score:2, Insightful)

        by Anonymous Coward

        Apparently, slashdot could use a -1, Don't be a dick moderation.

        Just give the story a - and move on.

      • by cecom ( 698048 )

        I am with you! Thank god I am not the only sane person here.
        When garbage like this is on the front page of Slashdot, perhaps it is time to stop reading it.

    • Addendum (Score:5, Interesting)

      by Looce ( 1062620 ) * on Sunday August 30, 2009 @05:41PM (#29255157) Journal

      Haha! This article is rated purple (2 levels above the lowest -- black) already. Wow.

      Anyhow. The fact that the TwIP program requires an IP stack to work is the prime indication that it doesn't really do all that much. Since it can work with raw socket access, and switches the addresses around, well, props, but TFA's "header" code comment says this:

      updating the ICMP checksum

      which is then contradicted by the code comment before the address swap:

      Since we only swap bytes in the IP header, we do not need to update the IP header checksum.

      using ICMP and IP interchangeably..?

      timothy, take this down. Now. It's your only chance to save face with this article.

      • by Mr_Toph ( 843301 )

        Haha! This article is rated purple (2 levels above the lowest -- black) already. Wow.

        And now it's black :P

        • by Looce ( 1062620 ) *

          I haven't seen a story get pwned into the ground this fast before. ... I must be new here.

        • where are you seeing these "rating colors"?
          • Re:Addendum (Score:4, Informative)

            by cyberstealth1024 ( 860459 ) on Sunday August 30, 2009 @08:15PM (#29256133)

            where are you seeing these "rating colors"?

            i didn't know either, so i looked it up -- it's the /. firehose quality filter [slashdot.org]. When you're logged in, you can see the popularity color on the left side of the summary heading. You can also increase/decrease this rating. See screen cap [tinypic.com]. Also, when browsing the front page of /., you can filter based on the color...see top-right of screenshot. The rating colors are ROYGBIV + Black. Red is the highest (most popular), black is the lowest. submitted articles initially have the color rating of blue.

            I had seen the color filtering before on the front page, but never looked into enough to find out. I learned something new. Hope you did too!

      • by fatphil ( 181876 )
        "The fact that the TwIP program requires an IP stack to work is ..." ... false.

        You're confused that he uses a raw network interface to test it, but he could just have easily have done something like ./twip < /dev/ttyS0 > /dev/ttyS0 instead. All he requires is a link layer that trasnmits a stream of bytes in tact.

        And your pedantry regarding calling the Header Checksum both the IP checksum and the ICMP checksum is misplaced too. Look at the two relevant RFCs - both of them define the header to h
    • Re: (Score:3, Insightful)

      by BitZtream ( 692029 )

      . This is just a program that echoes every single thing back to the originator.

      using the IP stack that already exists on the OS.

      Responding to IP requests using someone elses IP stack does not mean you actually created your own stack.

      • Re: (Score:1, Interesting)

        by Anonymous Coward

        Adam Dunkel has created his fair share of IP stacks including the original uIP and uIPv6. And some other insignificant things like protothreads and the Contiki embedded operating system.

        What's your contribution?

    • Re: (Score:1, Interesting)

      by Anonymous Coward
      It's also wrong. char b[140]; unsigned short *s=b; *l=b; t; main(){ while(1) { read(0,b,140); b[20]=0; s[11]+=8; t=l[4]; l[4]=l[3]; l[3]=t; write(1,b,140); } } l is undefined. t is a syntax error. main() is incorrectly declared.
  • Now if you could figure out a way to encode a full 1500 byte packet into 160 characters you'd make some big money.

    • Re:Pretty Cool (Score:4, Interesting)

      by Plug ( 14127 ) on Sunday August 30, 2009 @05:43PM (#29255173) Homepage

      Sounds kind-of like this [stackoverflow.com].

      • Re: (Score:3, Informative)

        Awesome, I love the difference between the first two approaches!

        If you're not sure whether to click the link: It is a competition to compress images into 140 chars.

    • by dgatwood ( 11270 )

      Oh, TCP/IP is actually pretty easy. You don't need to handle the entire payload of an ethernet frames (1500 bytes). Just set the MTU to something tiny and let the TCP stack segment it for you. I was thinking pretty much the same thought as you. I hereby dub the concept IPoT (IP over Twitter). The minimum MTU allowed for TCP/IP is 88 bytes. Assuming you have to encode them in something 7-bit-clean (say base64), this means that you would need 118 bytes. 160 is a piece of cake. You'd get an MTU of 120

  • by flowerp ( 512865 ) on Sunday August 30, 2009 @05:28PM (#29255037)

    Shit doesn't smell like roses when it is made to fits into a tweet or is in any other way related to Twitter.

  • That's no stack. A stack has a queue, and a set of operations that can be done on items entering and leaving that queue. Description fail!

  • Geek alert (Score:1, Informative)

    by Anonymous Coward

    I knew I picked the right man when I cited this guy's PhD thesis in my dissertation. Folk who write things like this know their shit, and are probably safe citations, despite the use of Twitter.

    I'd have thought that someone that spent his time studying and implementing minimal-waste embedded network stacks and coming up with something like Contiki would be annoyed by the huge waste of bytes that is Twitter.

  • by Anonymous Coward

    ... in low level system programming, I recommend reading a good book, like this [amazon.com], and not spending any more time reading this.

    Seriously.

  • by QuantumG ( 50515 ) * <qg@biodome.org> on Sunday August 30, 2009 @05:33PM (#29255089) Homepage Journal

    Here comes the lameness filter:

    unsigned short s[70];*l=s+6;t;main(){for(;;){read(0,s,140);s[10]&=65280;s[11]+=8;t=l[1];l[1]=*l;*l=t;write(1,s,140);}}

    And with those 9 chars perhaps you could make it better.

    • I assume the first two ;s are supposed to be ,

    • As another poster noted below, you can make it even shorter by omitting "unsigned." The only operations performed on the members of s are & and +, which operate identically on signed and unsigned integers.
    • by Mozk ( 844858 ) on Sunday August 30, 2009 @10:58PM (#29257027)

      Yeah, but for(;;) loops forever, whereas while(1) only loops while 1 is true. It's completely different! What if 1 becomes false?!

    • by fatphil ( 181876 )
      Visual inspection (i.e. not touched a compiler) says to me:

      Comma-up the loop into 1 expression and bin the {}?
      Replace 65280 with -256?
      for(;read(0,s,140);) or while(read(0,s,140)) to save a ;
      That's 4 more, after that it's a bit tricky.

      (Of course, unsigned's aleady been spotted as toast too, which can be taken as read.)
  • by Gopal.V ( 532678 ) on Sunday August 30, 2009 @05:40PM (#29255147) Homepage Journal

    I tried this particular piece of code out and it works! Of course, the ping buffer and the IP swap is just so obviously simple ... WOW!

    The "everything is a file" unix philosophy really does kick in and pull its weight in this example. Sockets, network devices, hardware block devices ... You can write an app to do pretty much anything with any of these, with just file streams. Oh, yeah ... dd'ing entire flash drives, netcating sockets, rsync'ing root partitions over. I often am completely amazed by the complexity that simple pieces can produce.

    Now everyone - stop talking bad about twitter ... it's awesome, it's simple and it's given random people the idea that I'm interesting & intelligent ;)

  • by jellomizer ( 103300 ) on Sunday August 30, 2009 @05:47PM (#29255197)

    I hope this isn't a new trend of 7337 |-|@(|0%$ to try to brag of their mad skill by seeing what code can fit in a Tweet.

    The less the code doesn't mean better performance.
    The less code can mean less functionality and error checking.
    The less code does mean less documentation
    The less code could mean harder readability.

    We need less people taking their time and effort making unreadable small code and more effort in making good and useful applications and libraries. Granted such exercises may be useful to allow you to think of problems differently but you can get the same effect by changing languages say from C to LISP. Also these examples seem to take in include headers which accounts for thousands of lines of code, which are often limited to either the OS or even just the Programming language.

    It is like me saying I can make a Web Browser using a shell script with 2 lines.

    #!/bin/bash
    apachectl start

    • I just forgot this isn't reddit, so I can't upmod your post arbitrarily. But the thought is there.Your comment regarding the header includes hits the nail on the metaphorical head.
    • by pathological liar ( 659969 ) on Sunday August 30, 2009 @06:07PM (#29255335)

      If you converted Apache into a web browser that might actually be worthy of a story...

    • Re: (Score:2, Funny)

      by maharius ( 1235912 )

      It is like me saying I can make a Web Browser using a shell script with 2 lines.
      #!/bin/bash
      apachectl start

      If that's what you're using as a web browser, you're doing it wrong.

    • by MavEtJu ( 241979 )

      > It is like me saying I can make a Web Browser using a shell script with 2 lines.

      Besides your server / browser confusion:

      Your implementation needs an external program to function, his does not.

    • http://twitter.com/samv/status/3654963074 [twitter.com]

      Well, straight from the IO::All man page but still. It supports CGI! (easily ownable of course)

    • Re: (Score:3, Informative)

      by loconet ( 415875 )

      I hope this isn't a new trend of 7337 |-|@(|0%$ to try to brag of their mad skill by seeing what code can fit in a Tweet.

      Oh it is. [twitter.com]

    • I hope this isn't a new trend of 7337 |-|@(|0%$ to try to brag of their mad skill by seeing what code can fit in a Tweet.

      Check this out, hello world in a tweet! I really had to work hard shortening it to under 140 characters.

      extern int puts( const char* ); int main( int argc, char* argv [] ) { puts( "Hello, world!\n" ); /* prints string */ return 0; /* OK */ }

    • I hope this isn't a new trend of 7337 |-|@(|0%$ to try to brag of their mad skill by seeing what code can fit in a Tweet.

      Nah, it's really nothing new. We've been playing perl golf for how long now?

  • Very cool (Score:4, Insightful)

    by bjourne ( 1034822 ) on Sunday August 30, 2009 @05:58PM (#29255273) Homepage Journal
    Very cool program! Taught me some things about IP. The program could be made one byte shorter by using for(;;) instead of while(1) and it is not strictly necessary to use "unsigned short" instead of "short" afaict. I wonder what other interesting programs that can be written in only 140 bytes.
    • I can do it in 1 byte, hell 1 bit.

      Since he's completely ignore the fact that he's actually using the stack already built into the OS and not writing his own.

      Just write everything into the compiler and supporting libraries, which is what is being done here.

      This isn't a IP stack in a tweet, its a twit who is sensationalising and ignoring all the things that make his statement an outright lie.

      I can create a human life from a few chemicals and in a matter of minutes have a living breathing baby or a full grown

  • Is this a implementation of RFC5514? I know that it needs to be IPoSN ( IPv6 over Social Networks) and is probably not, but I wonder how hard it would be to have this do IPv6.
  • Or is it enough, to boot a normal JavaScript based virtual machine on a normal browser, to use this?

  • that program just echoes stdin to stdout (maybe some char manipulations) and YOU have to connect this crap to some prog, which provides the network abilities (netcat might be suitable, i guess)
  • by k2dbk ( 724898 ) on Sunday August 30, 2009 @06:30PM (#29255507) Homepage Journal
    It's not an IP stack at all (and requires one to function). It replies to a packet that is assumed to be a ping without any error checking. In other words, it's a very short, clever, but minimally functional ping function. The fact that it's short is nice, but that's about it.
    • It doesn't even function as a ping function, some pings will cause it to generate the wrong checksum in the reply.

  • by AlgorithMan ( 937244 ) on Sunday August 30, 2009 @06:37PM (#29255545) Homepage
    hey, I wrote a webbrowser in 8 bytes of BATCH: here's the source code:

    IEXPLORE

    impressive, huh?

    • Re: (Score:3, Funny)

      by AlgorithMan ( 937244 )
      oh and don't forget my downloading prog in BASH:

      wget $@

      man, I'm so f*cking 1337!

    • by rdnetto ( 955205 )

      That's not a web browser! *This* is a web browser:

      lynx

      (And yes, it runs on Linux...)

      • by sorak ( 246725 )

        That's not a web browser! *This* is a web browser:

        lynx

        (And yes, it runs on Linux...)

        Too simple. Try this:

        browser="lynx";begin_comment="Now starting ";echo $begin_comment $browser; `$browser`;end_comment="terminated";echo $browser $terminated;

        All in one line of code. Now, that is some l33t coding skills, yo!

        • by sorak ( 246725 )

          browser="lynx";begin_comment="Now starting ";echo $begin_comment $browser; `$browser`;end_comment="terminated";echo $browser $terminated;

          Crap! That should have read:

          browser="lynx";begin_comment="Now starting ";echo $begin_comment $browser; `$browser`;end_comment="terminated";echo $browser $end_comment;

          Maybe this twitter guy is better at this than I am.

  • Cool yet small... (Score:3, Informative)

    by Spatial ( 1235392 ) on Sunday August 30, 2009 @08:11PM (#29256121)
    ...is big in the demoscene.

    Check out this 4KB realtime demo called 'Receptor'. (Download [daimi.au.dk] / Video [capped.tv])
  • Except for the part where the "stack" requires an underlying sockets implementation.
  • I admire you for this -- not a NOOP sled, not a trojan, not a game, you built a freaking IP stack in 128 chars. I officially declare you my hero, at least until lunch.
  • I propose TwERP -- an Enterprise Resource Planning app coded in a tweet.

"The following is not for the weak of heart or Fundamentalists." -- Dave Barry

Working...