Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "rubysocket.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 static VALUE
00022 tcp_init(int argc, VALUE *argv, VALUE sock)
00023 {
00024 VALUE remote_host, remote_serv;
00025 VALUE local_host, local_serv;
00026
00027 rb_scan_args(argc, argv, "22", &remote_host, &remote_serv,
00028 &local_host, &local_serv);
00029
00030 return rsock_init_inetsock(sock, remote_host, remote_serv,
00031 local_host, local_serv, INET_CLIENT);
00032 }
00033
00034 static VALUE
00035 tcp_sockaddr(struct sockaddr *addr, size_t len)
00036 {
00037 return rsock_make_ipaddr(addr);
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 static VALUE
00051 tcp_s_gethostbyname(VALUE obj, VALUE host)
00052 {
00053 rb_secure(3);
00054 return rsock_make_hostent(host, rsock_addrinfo(host, Qnil, SOCK_STREAM, AI_CANONNAME),
00055 tcp_sockaddr);
00056 }
00057
00058
00059
00060
00061
00062
00063 void
00064 rsock_init_tcpsocket(void)
00065 {
00066 rb_cTCPSocket = rb_define_class("TCPSocket", rb_cIPSocket);
00067 rb_define_singleton_method(rb_cTCPSocket, "gethostbyname", tcp_s_gethostbyname, 1);
00068 rb_define_method(rb_cTCPSocket, "initialize", tcp_init, -1);
00069 }
00070