Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

struct sockaddr rant

Name: Anonymous 2012-12-27 1:50

When I look in netinet/in.h on my system it's defined with the type uint32_t. Over here (http://www.beej.us/guide/bgnet/output/html/multipage/sockaddr_inman.html) it's defined as an unsigned long. Why wouldn't they do what they did with IPv6 addresses and just using an array of chars? If they're already using the assumption that CHAR_BIT is 8 for IPv6, why carry the extra, unnecessary assumption that the implementation provides a 32-bit integer type?

The only reason I can really think of is to ensure portability to platforms that use larger chars, but since they aren't going to work with IPv6 structs, why not redesign IPv4 structs?

And if we're fixing that, why not change the following functions:

uint32_t htonl(uint32_t hostlong);
uint32_t ntohl(uint32_t netlong);


to something like:

void *htonl(void *dest, unsigned long val);
unsigned long ntohl(const void *src);


/end rant

Name: Anonymous 2012-12-28 19:52

>>40
moar like power-hungry amirite?

Name: Anonymous 2012-12-28 23:01

>>38

Barring that 32-bit integer types are available, or you're on a system that doesn't have any reason to communicate over your average network protocol, it then turns into, "oh but you can't do it for arbitrary sizes with the arpa functions"

No, it turns into “I can't compile this code that uses ntohl because I wrote it so that it depends on uint32_t.” This is the basis of my argument.

If you have definitions for non-pow2 endianness I'd like to have them though.
I've already provided one in >>30. It converts an unsigned long to a 24-bit big-endian format, and back. These functions do nothing more than represent an arithmetic integer type in a specific binary format, and vice-versa.

Name: Anonymous 2012-12-28 23:19

I'm especially curious of how middle endian looks.
I don't know how it looks like 24-bit quantities either. Perhaps it might look like this:

void *htome24(void *dest, unsigned long val)
{
    unsigned char *ptr = dest;

    ptr[0] = val >> 8;
    ptr[1] = val >> 16;
    ptr[2] = val;
    return dest;
}

unsigned long metoh24(const void *src)
{
    const unsigned char *ptr = src;

    return ptr[0] << 8 | ptr[1] << 16 | ptr[2];
}

Name: Anonymous 2012-12-29 0:06

>>43
Read that as "otome24"

Also, le 16toh face.

Name: Anonymous 2012-12-29 2:57

>>44
awhawhaw le meatball metoh le hvor fa hvwoire.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List