Ticket #1724: getprotobyname.patch
File getprotobyname.patch, 4.9 KB (added by ocharles, 11 years ago) |
---|
-
src/pmc/socket.pmc
177 177 178 178 /* 179 179 180 =item C<getprotobyname(STRING * name)> 181 182 C<getprotobyname> returns a protocol number suitable for passing to 183 C<socket>, based on the given protocol name. This is normal only 184 necessary when opening sockets in raw mode. 185 186 =cut 187 188 */ 189 190 METHOD getprotobyname(STRING * name) { 191 INTVAL proto = Parrot_io_get_proto_by_name(INTERP, name); 192 RETURN(INTVAL proto); 193 } 194 195 /* 196 180 197 =item C<connect(PMC * address)> 181 198 182 199 Connects a socket object to an address. -
src/io/socket_api.c
353 353 354 354 return new_io; 355 355 } 356 357 PARROT_EXPORT 358 PARROT_WARN_UNUSED_RESULT 359 INTVAL 360 Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name)) 361 { 362 ASSERT_ARGS(Parrot_io_get_proto_by_name) 363 364 return PIO_GET_PROTO_BY_NAME(interp, name); 365 } 366 356 367 /* 357 368 358 369 =back -
src/io/socket_unix.c
35 35 #ifdef PIO_OS_UNIX 36 36 37 37 # include <sys/socket.h> 38 # include <netdb.h> 38 39 39 40 /* HEADERIZER HFILE: include/parrot/io_unix.h */ 40 41 … … 479 480 sa->sin_port = htons(port); 480 481 } 481 482 483 /* 482 484 485 =item C<INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, STRING * name)> 486 487 Return a protocol number based on the name of a protocol 488 489 =cut 490 491 */ 492 493 PARROT_WARN_UNUSED_RESULT 494 INTVAL 495 Parrot_io_get_proto_by_name_unix(PARROT_INTERP, ARGIN(STRING *name)) 496 { 497 ASSERT_ARGS(Parrot_io_get_proto_by_name_unix) 498 499 char * const s = Parrot_str_to_cstring(interp, name); 500 struct protoent * const protoent = getprotobyname(s); 501 int proto_number; 502 503 Parrot_str_free_cstring(s); 504 proto_number = protoent->p_proto; 505 return proto_number; 506 } 507 483 508 #endif /* PIO_OS_UNIX */ 484 509 485 510 /* -
CREDITS
787 787 N: OOLLEY kj 788 788 D: Miscellaneous cleanup and PDD07-conformance 789 789 790 N: Oliver Charles 791 D: Initial patch to add 'getprotobyname' to Socket PMC 792 U: ocharles 793 E: oliver@ocharles.org.uk 794 790 795 N: Ovid 791 796 D: Rename 'pbc_to_c' to 'pbc_to_exe' 792 797 -
include/parrot/io_unix.h
198 198 __attribute__nonnull__(3) 199 199 FUNC_MODIFIES(*socket); 200 200 201 PARROT_WARN_UNUSED_RESULT 202 INTVAL Parrot_io_get_proto_by_name_unix(PARROT_INTERP, ARGIN(STRING *name)) 203 __attribute__nonnull__(1) 204 __attribute__nonnull__(2); 205 201 206 INTVAL Parrot_io_listen_unix(SHIM_INTERP, ARGMOD(PMC *socket), INTVAL sec) 202 207 __attribute__nonnull__(2) 203 208 FUNC_MODIFIES(*socket); … … 254 259 PARROT_ASSERT_ARG(interp) \ 255 260 , PARROT_ASSERT_ARG(socket) \ 256 261 , PARROT_ASSERT_ARG(r)) 262 #define ASSERT_ARGS_Parrot_io_get_proto_by_name_unix \ 263 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 264 PARROT_ASSERT_ARG(interp) \ 265 , PARROT_ASSERT_ARG(name)) 257 266 #define ASSERT_ARGS_Parrot_io_listen_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 258 267 PARROT_ASSERT_ARG(socket)) 259 268 #define ASSERT_ARGS_Parrot_io_poll_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ … … 313 322 Parrot_io_listen_unix((interp), (pmc), (backlog)) 314 323 #define PIO_ACCEPT(interp, pmc) \ 315 324 Parrot_io_accept_unix((interp), (pmc)) 325 #define PIO_GET_PROTO_BY_NAME(interp, name) \ 326 Parrot_io_get_proto_by_name_unix((interp), (name)) 316 327 317 328 #endif /* PARROT_IO_UNIX_H_GUARD */ 318 329 -
include/parrot/io.h
825 825 826 826 PARROT_EXPORT 827 827 PARROT_WARN_UNUSED_RESULT 828 INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name)) 829 __attribute__nonnull__(1) 830 __attribute__nonnull__(2); 831 832 PARROT_EXPORT 833 PARROT_WARN_UNUSED_RESULT 828 834 INTVAL Parrot_io_listen(PARROT_INTERP, ARGMOD(PMC *pmc), INTVAL backlog) 829 835 __attribute__nonnull__(1) 830 836 __attribute__nonnull__(2) … … 892 898 PARROT_ASSERT_ARG(interp) \ 893 899 , PARROT_ASSERT_ARG(pmc) \ 894 900 , PARROT_ASSERT_ARG(address)) 901 #define ASSERT_ARGS_Parrot_io_get_proto_by_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 902 PARROT_ASSERT_ARG(interp) \ 903 , PARROT_ASSERT_ARG(name)) 895 904 #define ASSERT_ARGS_Parrot_io_listen __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 896 905 PARROT_ASSERT_ARG(interp) \ 897 906 , PARROT_ASSERT_ARG(pmc))