Question: I must be missing something very simple, but I'm not sure what it is yet.

From [this answer](https://stackoverflow.com/a/18484058/15055) we have the code:

```
app.directive('createTable', function ($compile) {
    return {
        link: function(scope, element, attrs) {
            if (element.next().length) {
                element.next().insertBefore(element);
            }

            var contentTr = angular.element('<tr><td>test</td></tr>');
            contentTr.insertAfter(element);
            $compile(contentTr)(scope);
        }
    }
});

```

The goal is to insert something after every element inside an `ng-repeat` directive.

What does this part do?

```
            if (element.next().length) {
                element.next().insertBefore(element);
            }

```

I read this as: "If there is an element, `X`, after `element`, then stick `element` before `X`". Yet it seems this would already be the case. 

It clearly does something, since if I remove those three lines, all the elements get added to the end of the `tbody`, instead of being interspersed.. See [jsfiddle of the working version](http://jsfiddle.net/3gt9J/3/), and [the jsfiddle when it's commented out](http://jsfiddle.net/3gt9J/142/).

Answer: 
This gets you the maximum number of hosts on the subnet:

```
u_long no_of_hosts = (network_address_long | ~network_mask_long) - network_address_long - 1;

```

You have the starting address, iterating should be straightforward.
Let me share with you some old C function that I wrote to get the dot-decimal string from an unsigned int32 (u\_long in your code):

```
void Int2DotDec(u_long ip, char* buf)
{   u_long b0 = ip & 0xFF, remain = ip >> 8;
    u_long b1 = remain & 0xFF; remain = remain >> 8;
    u_long b2 = remain & 0xFF; remain = remain >> 8;
    u_long b3 = remain & 0xFF;
    snprintf(buf, 16, "%d.%d.%d.%d", b3, b2, b1, b0);
}

```

p.s: purists pardon me, this C-Style thing is old stuff and worked well for me. Just size correctly the buf parameter (`char buf[16]`).
`scanf` is your friend:

```
#include <stdio.h>
...
scanf(ipString, "%u.%u.%u.%u", &a, &b, &c, &d);
__uint32_t ip=(a<<24)|(b<<16)|(c<<8)|d;

```

The `scanf()` function is the anti-these of printf. It is capable to convert and interpret strings.

Best if you separate this string-to-ip conversion into a separate function.