Index: src/pmc/socket.pmc =================================================================== --- src/pmc/socket.pmc (revision 48245) +++ src/pmc/socket.pmc (working copy) @@ -177,6 +177,23 @@ /* +=item C + +C returns a protocol number suitable for passing to +C, based on the given protocol name. This is normal only +necessary when opening sockets in raw mode. + +=cut + +*/ + + METHOD getprotobyname(STRING * name) { + INTVAL proto = Parrot_io_get_proto_by_name(INTERP, name); + RETURN(INTVAL proto); + } + +/* + =item C Connects a socket object to an address. Index: src/io/socket_api.c =================================================================== --- src/io/socket_api.c (revision 48245) +++ src/io/socket_api.c (working copy) @@ -353,6 +353,17 @@ return new_io; } + +PARROT_EXPORT +PARROT_WARN_UNUSED_RESULT +INTVAL +Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name)) +{ + ASSERT_ARGS(Parrot_io_get_proto_by_name) + + return PIO_GET_PROTO_BY_NAME(interp, name); +} + /* =back Index: src/io/socket_unix.c =================================================================== --- src/io/socket_unix.c (revision 48245) +++ src/io/socket_unix.c (working copy) @@ -35,6 +35,7 @@ #ifdef PIO_OS_UNIX # include +# include /* HEADERIZER HFILE: include/parrot/io_unix.h */ @@ -479,7 +480,31 @@ sa->sin_port = htons(port); } +/* +=item C + +Return a protocol number based on the name of a protocol + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +INTVAL +Parrot_io_get_proto_by_name_unix(PARROT_INTERP, ARGIN(STRING *name)) +{ + ASSERT_ARGS(Parrot_io_get_proto_by_name_unix) + + char * const s = Parrot_str_to_cstring(interp, name); + struct protoent * const protoent = getprotobyname(s); + int proto_number; + + Parrot_str_free_cstring(s); + proto_number = protoent->p_proto; + return proto_number; +} + #endif /* PIO_OS_UNIX */ /* Index: CREDITS =================================================================== --- CREDITS (revision 48245) +++ CREDITS (working copy) @@ -787,6 +787,11 @@ N: OOLLEY kj D: Miscellaneous cleanup and PDD07-conformance +N: Oliver Charles +D: Initial patch to add 'getprotobyname' to Socket PMC +U: ocharles +E: oliver@ocharles.org.uk + N: Ovid D: Rename 'pbc_to_c' to 'pbc_to_exe' Index: include/parrot/io_unix.h =================================================================== --- include/parrot/io_unix.h (revision 48245) +++ include/parrot/io_unix.h (working copy) @@ -198,6 +198,11 @@ __attribute__nonnull__(3) FUNC_MODIFIES(*socket); +PARROT_WARN_UNUSED_RESULT +INTVAL Parrot_io_get_proto_by_name_unix(PARROT_INTERP, ARGIN(STRING *name)) + __attribute__nonnull__(1) + __attribute__nonnull__(2); + INTVAL Parrot_io_listen_unix(SHIM_INTERP, ARGMOD(PMC *socket), INTVAL sec) __attribute__nonnull__(2) FUNC_MODIFIES(*socket); @@ -254,6 +259,10 @@ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(socket) \ , PARROT_ASSERT_ARG(r)) +#define ASSERT_ARGS_Parrot_io_get_proto_by_name_unix \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(name)) #define ASSERT_ARGS_Parrot_io_listen_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(socket)) #define ASSERT_ARGS_Parrot_io_poll_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ @@ -313,6 +322,8 @@ Parrot_io_listen_unix((interp), (pmc), (backlog)) #define PIO_ACCEPT(interp, pmc) \ Parrot_io_accept_unix((interp), (pmc)) +#define PIO_GET_PROTO_BY_NAME(interp, name) \ + Parrot_io_get_proto_by_name_unix((interp), (name)) #endif /* PARROT_IO_UNIX_H_GUARD */ Index: include/parrot/io.h =================================================================== --- include/parrot/io.h (revision 48245) +++ include/parrot/io.h (working copy) @@ -825,6 +825,12 @@ PARROT_EXPORT PARROT_WARN_UNUSED_RESULT +INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name)) + __attribute__nonnull__(1) + __attribute__nonnull__(2); + +PARROT_EXPORT +PARROT_WARN_UNUSED_RESULT INTVAL Parrot_io_listen(PARROT_INTERP, ARGMOD(PMC *pmc), INTVAL backlog) __attribute__nonnull__(1) __attribute__nonnull__(2) @@ -892,6 +898,9 @@ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(pmc) \ , PARROT_ASSERT_ARG(address)) +#define ASSERT_ARGS_Parrot_io_get_proto_by_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(name)) #define ASSERT_ARGS_Parrot_io_listen __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(pmc))