Hi,

typical socket ocde currently looks a bit unfriendly due to magic constants, 
e.g.

    socket sock, 2, 1, 6        # PF_INET, SOCK_STREAM, tcp

I'd like to have symbolic constants for all that stuff:

    socket sock .PF_INET, .SOCK_STREAM, .PROTO_tcp

Appended is a C snippet, which produces such constants[1]. It's incomplete and 
not integegrated in Configure/make at all, but maybe it is a starting point.

Q: is there a better option to generate these constants?

leo

[1] # or such
$ cc -DUNIX -o sock_gen -Wall sock_gen.c && ./sock_gen > 
runtime/parrot/include/socket.pasm
#include <stdlib.h>
#include <stdio.h>

#ifdef UNIX
#include <sys/socket.h>
#include <netdb.h>
#endif

#ifdef WIN32
#include <winsock.h>
#endif

int main(int argc, char *argv[])
{
    struct protoent *ent;

    printf("# DO NOT EDIT - autogenerated by Configure.pl & %s\n\n", argv[0]);
    printf("# protocal family\n");
    printf(".constant PF_UNIX %d\n", PF_UNIX);
    printf(".constant PF_LOCAL %d\n", PF_LOCAL);
    printf(".constant PF_INET %d\n", PF_INET);
    printf(".constant PF_INET6 %d\n", PF_INET6);

    printf("\n# socket type\n");
    printf(".constant SOCK_STREAM %d\n", SOCK_STREAM);
    printf(".constant SOCK_DGRAM %d\n", SOCK_DGRAM);
    printf(".constant SOCK_RAW %d\n", SOCK_RAW);

    printf("\n# protocols\n");
    while ( (ent = getprotoent() )) {
	printf(".constant PROTO_%s %d\n", ent->p_name, ent->p_proto);
    }
    endprotoent();

    return 0;
}

Reply via email to