[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: Lua 5.3 -- a facility for creating and manipulting Lua file handles (C API)
- From: Sean Conner <sean@...>
- Date: Tue, 19 Nov 2013 12:00:39 -0500
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 Lua.org, PUC-Rio
> net = require "org.conman.net"
> a = net.address('127.0.0.1','udp','domain')
> print(a.family)
ip
> print(a.port)
53
> print(a.addr)
127.0.0.1
>
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('127.0.0.1','ospf')
sock = net.socket(addr.family,'ospf')
sock:bind(addr)
And a standard TCP socket for comparison:
addr = net.address('127.0.0.1','tcp','www')
sock = net.socket(addr.family,'tcp')
sock:bind(addr)