lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great Sir Pogsalot once stated:
> Your getaddrinfo() does look much nicer :]  I just couldn't decide on how
> to make it friendly -- how I would return a table showing which sock types
> and protocols the remote host supports.  Maybe people only really use
> getaddrinfo() to resolve domain names as they already know they want to
> establish a TCP connection.  My other reasoning was that because my
> bindings are pretty direct, it still leaves the option of layering over it
> a friendlier interface while not keeping things like getaddrinfo() from the
> user.

  Well, I did create a struct sockaddr userdata type, and my getaddrinfo()
returns a list of these.

	Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio
	> net = require ""
	> a = net.address('','udp','domain')
	> print(
	> print(a.port)
	> print(a.addr)

I don't support 'a.proto' because the struct sockaddr doesn't have that
field, and in fact, overloads the sin_port (or sin6_port) value to be the
protocol number in the case of non-TCP or non-UDP sockets [1].

  -spc (Does a lot of network programming in Lua at work)

[1]	Say you wanted a socket to communicate with OSPF.  First, you create
	a struct sockaddr with a sin_port value of 89 (which is the protocol
	value for OSPF; TCP is 6 and UDP is 17, for examle).  Then you
	create a raw socket, which when bound, uses the sin_port value as
	the protocol the socket supports.

	Yeah, try finding a lot of information about *that*.

	But with my socket library, it's:

		addr = net.address('','ospf')
		sock = net.socket(,'ospf')

	And a standard TCP socket for comparison:

		addr = net.address('','tcp','www')
		sock = net.socket(,'tcp')