#endif
int
-expect(int s, int match, char *buf)
+recvline(int s, char *buf)
{
int size;
char *p;
ptr = buf;
n = recv(s, ptr, size, MSG_PEEK);
if (n <= 0) {
- fprintf(stderr, "Expecting code %d\n", match);
#ifdef _WIN32
errno = WSAGetLastError();
#endif
}
ptr += n;
if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) {
- fprintf(stderr, "Expecting %d, got %s\n", match, buf);
+#ifdef _WIN32
+ errno = WSAGetLastError();
+#endif
+ perror("recv");
return 0;
}
size -= n;
(void)alarm(0);
#endif
if (!isxdigit(*buf)) {
- fprintf(stderr, "Expecting %d, got %s\n", match, buf);
+ fprintf(stderr, "Malformed line %s\n", buf);
return 0;
}
if (isdigit(*buf))
*buf = tolower(*buf);
code = 10 + *buf - 'a';
}
- if (code == match)
- return 1;
- return 0;
+ return code;
+}
+
+int
+expect(int s, int match, char *buf)
+{
+ int code = recvline(s, buf);
+ return code == match;
}
void