From: timsuth@... (Tim Sutherland) Date: 2002-04-07T17:17:01+09:00 Subject: Re: Socket API In article <20020407021324.GE6112@killik.co.uk>, Tom Gilbert wrote: >Could someone tell me how to create a "struct sockaddr stored in a >string" in order to pass it to Socket.bind? Use Array#pack. For example, noting struct sockaddr_in { short int sin_family; unsigned short int sin_port; struct in_addr sin_addr; unsigned char sin_zero[8]; } and using the Pragmatic Programmers' documentation on Array#pack, sockaddr = [Socket::AF_INET, 1234, 192, 168, 1, 1, ''].pack('snCCCCa8') >All of Socket's instance methods take "struct sockaddr strings" and I >can't for the life of me see how to create one. It's 3 lines of C to do >what I want to and it doesn't seem possible in Ruby... (connect to a >remote host using a specific local address). > >If someone could explain the reasoning behind wrapping C structs in >strings instead of having a SockAddr class I'd love to hear it too. >Because frankly it looks disgusting.