58 struct sockaddr_in *sin;
70 ctx->buf = (
char *)malloc(BUFSIZ);
77 ctx->sd = socket(PF_INET, SOCK_STREAM, 0);
89 sin = (
struct sockaddr_in *)&s;
90 sin->sin_family = AF_INET;
92 sin->sin_addr.s_addr = addr;
93 if (-1 == connect(ctx->sd, &s,
sizeof(s))) {
94 if (ETIMEDOUT == errno && retries-- > 0) {
176 struct pollfd fd = { ctx->sd, POLLIN, 0 };
178 int i, first = 1, cont = 1, result = 0;
180 for (i = 0; script[i]; i++) {
182 if (!strlen(script[i])) {
183 result = poll(&fd, 1, 0);
185 lseek(ctx->sd, 0, SEEK_END);
187 if (wait_substr(ctx, script[i])) {
195 if (strlen(script[i])) {
196 TELL(
"Sending line: '%s'", script[i]);
197 if (-1 == write(ctx->sd, script[i], strlen(script[i]))) {
205 char *ptr = ctx->buf;
208 result = poll(&fd, 1, EXPECT_POLL_TIMEOUT);
225 if (-1 == write(ctx->sd,
"\n", 1))
228 len = read(ctx->sd, ctx->buf, BUFSIZ);
239 TELL(
"Read line: '%s'", ctx->buf);
244 ptr = strchr(ctx->buf,
'\n');
251 TELL(
"Comparing '%s' with '%s'", ptr, script[i - 2]);
254 tmp = strstr(ptr, script[i - 2]);
256 TELL(
"OK, last line. Good bye!");
261 tmp = strrchr(ptr,
'\n');
266 if (output && *ptr) {
267 if (EOF == fputs(ptr, output)) {