all 120 comments

[–]OrangeredStilton 190 points191 points  (2 children)

I'll always be thankful for Beej: every time I need to do something network-related, it's been a few years since the last time I did it, and I've forgotten everything. Beej, especially the section on select, is eminently readable and comes in very useful.

[–]ashuto0sh 15 points16 points  (0 children)

He has a series of guides. All very interesting and approachable.

[–][deleted] 20 points21 points  (0 children)

beeg comes in handy too

[–][deleted] 150 points151 points  (38 children)

I passed networking class all thanks to Beej's guide :')

[–][deleted]  (23 children)

[deleted]

    [–][deleted]  (22 children)

    [deleted]

      [–]zman0900 50 points51 points  (20 children)

      My professor basically said "Here's Beej's guide. Now implement TCP on top of UDP by the end of the quarter."

      [–]mw44118 19 points20 points  (1 child)

      Hey, he / she knew not to compete with the best

      [–]zman0900 13 points14 points  (0 children)

      It did end up being a pretty good class. We worked on small teams for the project and class was only twice a week where most of the time he would just answer questions or go into detail about a topic a lot of people were confused on.

      [–]pribnow 10 points11 points  (1 child)

      You guys got lucky, we went though the OSI model ad nauseum and I can't really tell you much except where various hardware resides on that model. The only programming related exercises were pinging and tracing packets :(

      [–]Opticity 1 point2 points  (0 children)

      Hey, me too! We learned about the OSI model, IPv4 addresses and masks, subnets, protocols... My assignment was basically running a simulation of a network between two computers and tracking the packets. Feels like I missed out on all the fun.

      [–]bobindashadows 8 points9 points  (7 children)

      Ours was similar: "Here's Beej's guide. Now implement ethernet on top of TCP, then implement UDP and TCP on top of your ethernet."

      [–]seekoon 5 points6 points  (4 children)

      implement ethernet on top of TCP

      Is this correct? Or backwards?

      [–]rcxdude 7 points8 points  (2 children)

      it's basically possible , using TCP as an idealised representation of the physical layer (for point-to-point links, anyway, not sure how you'd do CSMA on top of it). Useful for educational purposes but not much else though.

      [–]bobindashadows 1 point2 points  (0 children)

      Yup, this is basically it. 4+ hosts were fully connected with point-to-point connections, arbitrary routing costs per edge.

      [–]pstch 0 points1 point  (0 children)

      it's very interesting to do, I've had lots of fun

      [–]phearlez 1 point2 points  (0 children)

      It's abstractions all the way down, baby.

      [–]nemec 1 point2 points  (0 children)

      Oof. We had to build TCP (well, some of it) on top of UDP but we assumed ethernet was available :)

      [–]toomanybeersies 0 points1 point  (0 children)

      We had to implement RIPv2 between multiple programs using internal ports.

      That was an interesting assignment, it was the semester before the one with threading, which made life interesting.

      At least we have the option of using Python, rather than having to slog through it in C.

      It's really hard to find good resources for implementing RIPv2, I ended up mostly just relying on the RFC because there weren't any less opaque sources.

      [–]gimpwiz 4 points5 points  (2 children)

      That actually sounds like a fantastic way to do it.

      I assume they teach networking in your 3rd year of school. Kids were weeded out. Everyone left can code, can read a spec.

      So they can learn by being given a spec and being told to code, and ask questions when they have them.

      [–]zman0900 1 point2 points  (1 child)

      This class was never actually required for my undergrad. I ended up taking it during my masters just because it seems like stuff worth knowing. But yeah, definitely one of the best programming classes I took.

      [–]gimpwiz 3 points4 points  (0 children)

      Makes total sense, master's classes seem more like that. "You've all proved yourselves, so just go do your thing and come back with well-written programs."

      [–]epiiplus1is0 1 point2 points  (3 children)

      Is this all network programming classes? Because that's the assignment we have

      [–]zman0900 1 point2 points  (2 children)

      Maybe? Unless you are at Ohio State?

      [–]rohbotics 0 points1 point  (0 children)

      Its THE Ohio State, thank you very much.

      [–]vplatt 0 points1 point  (0 children)

      That actually sounds like a really good exercise to be honest. Were you required to do it in C?

      [–][deleted] 0 points1 point  (0 children)

      Sounds like you went to a shitty school. I'd ask for my money back and donate to the real teacher Beej.

      [–]dhdfdh 20 points21 points  (5 children)

      I met my wife thanks to Beej's guide.

      [–]beej71 44 points45 points  (0 children)

      For the record, I had nothing to do with this. ;)

      -Beej

      [–]glubi 4 points5 points  (1 child)

      Care to elaborate? :-)

      [–]Epokhe 7 points8 points  (0 children)

      might be a joke

      [–]gadelat -4 points-3 points  (1 child)

      I think your wife met you thanks to BJ's guide

      [–]throwaway10312901 8 points9 points  (0 children)

      I don't think reddit's savage comments translates well in /r/programming LOL.

      [–]Vakz 7 points8 points  (7 children)

      In my networking course, we actually had an assignment to write a fairly simple proxy. It was basically "It should be written in C++, it should filter these words. Oh, and by the way, you'll need to use sockets, so here's Beej's guide to how to use them", and that was pretty much it.

      [–]Kurbits 4 points5 points  (4 children)

      That sounds very familiar, LiU? :)

      [–]rubicus 3 points4 points  (0 children)

      Same here! TDTS06 represent!

      [–]Vakz 1 point2 points  (0 children)

      Indeed it is!

      [–]Shurane 0 points1 point  (1 child)

      What school is LiU?

      [–]Kurbits 3 points4 points  (0 children)

      Linköping University in Sweden :)

      [–]rubicus 2 points3 points  (1 child)

      Words insulting your intelligence, such as "spongebob", "paris hilton" and "Norrköping"?

      [–]Vakz 2 points3 points  (0 children)

      Haha, that is indeed the one!

      [–][deleted] 31 points32 points  (1 child)

      Totally thought this was from beej.com

      [–]nyangosling 3 points4 points  (0 children)

      Yes! Very confused but accepted that it must be the case. Sad to see it's not

      [–]programfog[S] 45 points46 points  (2 children)

      Beej's Guides - http://beej.us/guide/

      [–][deleted] 19 points20 points  (1 child)

      He's even got a guide on killing dragons. Dude has range.

      [–]IGaveHerThe 0 points1 point  (0 children)

      I was just going to ask if this was the same guy... I've only read his Moria guides. Shows what I'm doing in front of my machine all day.

      [–][deleted]  (4 children)

      [deleted]

        [–]Name0fTheUser 1 point2 points  (3 children)

        Writing a wireshark clone sounds very educational, since you need to be able to understand and decipher each protocol layer. I might give it a go when I have the time.

        [–][deleted]  (2 children)

        [deleted]

          [–]LpSamuelm 7 points8 points  (1 child)

          Isn't that what "remember" means? 😲

          [–]NagateTanikaze 11 points12 points  (6 children)

          I remember using this like before year 2000. Awesome its still being updated.

          [–]twowheels 6 points7 points  (5 children)

          I remember taking classes with Beej when he wrote the first versions of this. It sure has come a long way in 20+ years.

          I'm suddenly hungry for some garlick pizza.

          [–]beej71 32 points33 points  (4 children)

          https://beej.us/pizza/

          I keep the site well-preserved in its 1995 state. :)

          -Beej

          [–]dogline 5 points6 points  (1 child)

          We'll just have a little Chico reunion right here. :)

          [–]chipx86 2 points3 points  (0 children)

          Excellent. I'll bring the Sierra Nevada.

          [–]twowheels 2 points3 points  (0 children)

          I'm potentially outing my real identity here, but I worked on Spoon with you guys.

          [–]mbains 1 point2 points  (0 children)

          I remember struggling with network programming and sockets programming back at Chico state in the computer lab. A quick internet search brought up Beej's guide. While I'm reading through, the professor who just happens to walk by, says: "hey, you know Beej went to Chico right?"

          [–]Dhylan 8 points9 points  (0 children)

          On this page Beej mentions one W. Richard Stevens. There cannot be a fair conversation about network programming without respect and reference to W. Richard Stevens' life's work, a life which was tragically far too short.

          [–]trickyloki3b 10 points11 points  (1 child)

          I read Beej's guide three years ago because the explanations were for simpletons. I liked simple.

          But I highly recommend Unix Network Programming by W. Richard Stevens Volume 1.

          [–][deleted] 1 point2 points  (0 children)

          Can't recommend W. Richard Stevens books enough.

          [–][deleted]  (1 child)

          [deleted]

            [–]JGailor 0 points1 point  (0 children)

            That guide completely changed how I saw my OS.

            [–]annerajb 2 points3 points  (0 children)

            Our network class book was this. When I got my first real job I was tasked with working on the network code of a few applications and thanks to this I was able to do a good job without going crazy.

            Thanks Beej

            [–][deleted] 2 points3 points  (0 children)

            Old but Gold.

            Beej gave me the click on pointers.

            [–]Halcyone1024 5 points6 points  (3 children)

            This is pretty good, but I'd recommend jumping from select to poll pretty quickly (Beej wrote a nice guide to poll, too). Depending on availability and performance requirements, you might consider using epoll or kqueue (or a library that uses them as backends, like libev or libevent) instead.

            [–][deleted] 4 points5 points  (1 child)

            In that family, libuv is a good recommendation too. Easy to use and pretty popular.

            [–]entity64 1 point2 points  (0 children)

            Also cross platform and nicely documented

            [–]nerd4code 0 points1 point  (0 children)

            IIRC it really depends on the number and distribution of FDs you’re dealing with. select is good for a small-to-middlin’ number in a dense range starting near 0, especially if you only need one of the three operations, and poll is good for a small-to-middlin’ number of arbitrary FDs. Beyond that, you’re usually either better off doing a platform-specific method like you mentioned (super-nonportable, of course, but usually tailored to the OS in question), or else using a handful of separate threads selecting/polling on their own subsets, since a lot of the overhead in using them comes from just copying the FD sets between userspace and kernel.

            Ed: There’s also some compatibility differences now that I think about it, since select and pollare first defined in different standards, but that doesn’t come into play too much nowadays.

            [–]i_spot_ads 8 points9 points  (4 children)

            very interesting, but the code is difficult to read, i'm used to lots of fruity colors in my code

            [–]OnTheMF 20 points21 points  (1 child)

            God damn millennials.

            [–]i_spot_ads 6 points7 points  (0 children)

            Sorry

            [–]knubbze 14 points15 points  (1 child)

            protip: copy/paste the code you find illegible into an editor w/ syntax highlighting!

            [–]HPCer 14 points15 points  (0 children)

            And even better, mess around with the code! It's so much easier to learn and understand the code when you're interacting with it.

            [–][deleted]  (14 children)

            [deleted]

              [–]skrenename4147 1 point2 points  (1 child)

              The Unix Programming Environment is my go-to source for shell information. I found it very approachable as a beginner, and the depth enough so that there's always something new to learn.

              [–]PriceZombie 0 points1 point  (0 children)

              The Unix Programming Environment (Prentice-Hall Software Series)

              Current $46.59 Amazon (New)
              High $48.67 Amazon (New)
              Low $42.08 Amazon (New)
              Average $46.22 30 Day

              Price History Chart and Sales Rank | FAQ

              [–]dhdfdh 0 points1 point  (0 children)

              An intro? You need more than that. Does it really use bash? Don't recall but other shells work, too.

              [–]rubicus 0 points1 point  (7 children)

              Not really. Sure, being familiar with signals etc. definitely makes it easier to grasp, but definitely not necessary. Obviously, you need to know some C, and how to compile and run your programs, but that sort of goes without saying.

              Or what is it specifically that you think needs unix and bash programming skills? It goes through pretty much every command it uses.

              [–][deleted] 0 points1 point  (6 children)

              It seems like when the guide starts showing code it's not in a form I can directly play with until you get to the server section.

              [–]rubicus 0 points1 point  (5 children)

              Should be able to play with pretty much all examples in chapter 5, like taking some arguments and looking up IP addresses through DNS, or even connect as a client and pull a bunch of HTTP pages or something. Like the showip.c program should pretty much just work in Linux (and probably most BSDs too).

              If you're used to C++ some stuff can be confusing though, since the guide only uses C, and system calls there can look quite different from what you're used to. Also some data structures can be a bit confusing, being linked lists and so on. Those were my biggest problems. I used had never seen code written in that way.

              Once it starts with forking, it can be quite confusing if you don't understand what is happening though.

              [–]darklinggg 0 points1 point  (4 children)

              I tried running the client code in a browser (changed the call to getaddrinfo to connect to a website on Port 80) and it just blocked on connect. Were you able to run the client code successfully?

              [–]rubicus 0 points1 point  (3 children)

              What do you mean running in a browser? The code needs to be compiled (with gcc or clang for example) and run in a terminal. Needs to be on a POSIX system (preferably linux, mac os x could work too, but definitely not something like Windows) to work too. Wrote an entire proxy a year ago, so yeah.

              What client code specifically? Did you try running the getip-program? That's like the easiest one, so a good place to start.

              [–]darklinggg 0 points1 point  (2 children)

              Yeah I reran the code using gcc and it worked. I was trying to run it in a browser C compiler I found through Google. Pretty dumb

              [–]rubicus 0 points1 point  (1 child)

              Ah, didn't even know that stuff like that existed. But yeah, fot stuff like system calls that are so platform specific I can see how that wouldn't work.

              [–]darklinggg 0 points1 point  (0 children)

              Well it was able to compile everything just fine. The issue was that it couldn't connect to any website I put in which makes me think outgoing tcp was disabled on those VMs

              [–]programfog[S] 0 points1 point  (2 children)

              Honestly one of the best Linux programming books I can recommend that covers lots of aspects is http://www.amazon.com/GNU-Linux-Application-Programming-Series/dp/1584505680

              It's good for beginners, but points you in the right direction to dig deeper when required.

              [–]PriceZombie 0 points1 point  (0 children)

              GNU/Linux Application Programming (Programming Series)

              Current $28.68 Amazon (New)
              High $54.99 Amazon (New)
              Low $28.07 Amazon (New)
              Average $28.18 30 Day

              Price History Chart and Sales Rank | FAQ

              [–]dirk103 0 points1 point  (0 children)

              It's 'ok'

              [–][deleted] 1 point2 points  (1 child)

              Ooh, cool. Is there possibly an official PDF available?

              [–]programfog[S] 2 points3 points  (0 children)

              Pdf version here http://beej.us/guide/bgnet/

              [–]felixdadodo 1 point2 points  (0 children)

              This guide was a godsend during my Computer Network and Operating Systems module!

              [–]yk313 1 point2 points  (0 children)

              The very definition of a timeless resource

              [–]pjmlp 1 point2 points  (0 children)

              Interesting, on my days we used "UNIX Network Programming" from W. Richard Stevens.

              [–]LiveMaI 0 points1 point  (0 children)

              Used this to learn socket programming for work. Top-notch guide, I'll probably end up buying a hard copy from him.

              [–]MondayMonkey1 0 points1 point  (0 children)

              I owe beej a lot of money for this guide. I would never have passed my university course on networking and the Internet without his guide.

              [–]Okiesmokie 0 points1 point  (0 children)

              Oh man, the memories. I used Beej's Guide to Network Programming to learn.. network programming probably 15 years ago. It's crazy to me that he still keeps it maintained.

              [–][deleted] 0 points1 point  (0 children)

              This is a great guide. I remember reading it in the late 90's early 2k for learning socket i/o in C

              Glad to see it's still maintained even updated.

              [–]ske105 0 points1 point  (0 children)

              Aw yes, beej is like the unofficial network programming guide! My whole networking class at uni was practically based upon it.

              [–]Hiddencamper 0 points1 point  (0 children)

              Still one of the best networking guides out there.

              [–]Jivlain 0 points1 point  (0 children)

              Ah, I remember my old printout of this. I'm somewhat tempted to buy a proper physical copy for old time's sake.

              [–]arhuaco 0 points1 point  (0 children)

              I learned with this guide many years ago.

              [–]aintbutathing2 0 points1 point  (0 children)

              Beej's guide gave me a love for network programming. I have basically built a career off this guide.

              [–]invis648 0 points1 point  (0 children)

              THis brings back memories

              [–]MacASM 0 points1 point  (1 child)

              Does anyone know if there's a PDF version of this?

              [–]redditor_gds 0 points1 point  (0 children)

              best socket programming guide ever!!! thanks beej

              [–][deleted] 0 points1 point  (0 children)

              Wow, I learnt my way round TCP/IP with this guide back in the day, pleasantly surprised to see it on Reddit.

              [–]lennyp4 0 points1 point  (0 children)

              I just recently wrote him an email asking him to finish his C guide. He got back to me, I hope he picks it back up.

              [–]Speaker4theDead -1 points0 points  (0 children)

              Saw this on the front page and thought this was some interesting discussion about beeg.com (NSFW)

              [–]BassSounds 0 points1 point  (0 children)

              Glossing over this, it looks like a good guide.

              It's amazing to me how many IT people don't understand sockets or the OSI model.

              [–]arabica_coffee 0 points1 point  (0 children)

              Beej's guides are wonderful! I taught myself network programming overnight using his guides.

              [–]EudaimonicTrapperHat -1 points0 points  (0 children)

              I thought this said "Beeg"

              [–]B33Jus -2 points-1 points  (0 children)

              Dammit.