Comments (5)
You can modify this simple client to fit your need:
https://github.com/seanmiddleditch/libtelnet/blob/develop/util/telnet-client.c
from libtelnet.
I'm sorry, but I've already seen that code, and that doesn't fit into my concept of simple.
I think it should use some abstraction between sockets, tcp, and telnet. I tried to do it, but I can't understand from that code how is libtelnet supposed to be used.
Do I still need to open the tcp socket myself? I would expect a libtelnet library to handle all that stuff.
Is it a client or a server? Because I see some code trying to open a socket as a server.
I think it will be easier for me to open a pipe with something like this:
FILE *telnet = popen("telnet -l as 192.168.0.1 23", "w");
from libtelnet.
No, libtelnet doesn't design this way, you need manage the socket by yourself. Of course, if you prefer file API, you can create something like telnet_popen on top of libtelnet. This isn't a very hard work.
from libtelnet.
I would like to do it, but I'm having a lot of trouble understanding the code. I'm talking, for example, about lines like this one:
/* bind server socket */
¿server?
In fact, I don't need a file API, but a socket API where libtelnet already gives me a working socket would be nice.
I don't see any benefit in writing the code to get the socket outside of libtelnet. It's always going to be the same. Repeating the same code for every program that uses the library isn't good IMHO.
Couldn't this function be used inside libtelnet to provide a socket? :
int alx_tcp_client_open (const char *restrict server_addr,
const char *restrict server_port)
{
struct protoent *tcp;
int sd;
struct addrinfo hint = {0};
struct addrinfo *addrs;
int status;
tcp = getprotobyname("tcp");
if (!tcp)
return -EINVAL;
hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = tcp->p_proto;
status = getaddrinfo(server_addr, server_port, &hint, &addrs);
if (status)
return -labs(status);
for (struct addrinfo *ad = addrs; ad; ad = ad->ai_next) {
sd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
if (sd < 0)
continue;
if (connect(sd, ad->ai_addr, ad->ai_addrlen))
goto try_next;
break;
try_next:
close(sd);
sd = -1;
}
freeaddrinfo(addrs);
if (sd < 0)
return -errno;
return sd;
}
from libtelnet.
I amn't the libtelnet owner, you can open an issue to discuss this type of API.
from libtelnet.
Related Issues (20)
- Consider providing integrated examples HOT 1
- Deal with the "FIXME" on README HOT 4
- Feature request: make telnet-proxy support multiple connections HOT 6
- Tag 0.22? HOT 7
- Compatibility with telnet client of Mac OS X HOT 2
- Shouldn't telnet_send() do CR-NUL and CR-LF translations? HOT 7
- undefined behaviour - missing va_end() calls HOT 1
- Allocation optimization in _set_rfc1143() is wrong. HOT 4
- telnet clinet HOT 3
- CMake
- sonames and versioning
- Problems when using as submodule
- man 3 libtelnet
- Simplify API HOT 5
- Interpreting the tests HOT 5
- Cannot handle multiple logs HOT 6
- fluffos HOT 8
- Any plans for a 0.24 release?
- How can I automatically pass the login and password using Telnet with libtelnet on Ubuntu?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libtelnet.