Index: src/dynoplibs/Rules.in =================================================================== --- src/dynoplibs/Rules.in (revision 48245) +++ src/dynoplibs/Rules.in (working copy) @@ -126,3 +126,18 @@ src/dynoplibs/io_ops.c: src/dynoplibs/io.ops $(OPS2C) $(OPS2C) --dynamic src/dynoplibs/io.ops --quiet + +######################### + +$(DYNEXT_DIR)/socket_ops$(LOAD_EXT): src/dynoplibs/socket_ops$(O) $(LIBPARROT) + $(LD) @ld_out@$@ src/dynoplibs/socket_ops$(O) $(LINKARGS) +#IF(win32): if exist $@.manifest mt.exe -nologo -manifest $@.manifest -outputresource:$@;2 +#IF(cygwin or hpux): $(CHMOD) 0775 $@ + +src/dynoplibs/socket_ops$(O): $(DYNOP_O_DEPS) \ + src/dynoplibs/socket_ops.c src/dynoplibs/socket_ops.h + +src/dynoplibs/socket_ops.h: src/dynoplibs/socket_ops.c + +src/dynoplibs/socket_ops.c: src/dynoplibs/socket.ops $(OPS2C) + $(OPS2C) --dynamic src/dynoplibs/socket.ops --quiet Index: src/dynoplibs/Defines.in =================================================================== --- src/dynoplibs/Defines.in (revision 48245) +++ src/dynoplibs/Defines.in (working copy) @@ -7,6 +7,7 @@ $(DYNEXT_DIR)/debug_ops$(LOAD_EXT) \ $(DYNEXT_DIR)/sys_ops$(LOAD_EXT) \ $(DYNEXT_DIR)/io_ops$(LOAD_EXT) \ + $(DYNEXT_DIR)/socket_ops$(LOAD_EXT) \ DYNOPLIBS_CLEANUPS = \ src/dynoplibs/*.c \ 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' as a dynamic op +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))