Mercurial > hg > fxanalyse
view dds.c @ 224:45dd6e50fb11
Do not track .cds
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 18 Sep 2014 18:09:50 +0200 |
parents | fcc988c6f841 |
children |
line wrap: on
line source
#ifdef _CVI_ #include <winsock2.h> #include <ansi_c.h> #else #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <ctype.h> #include <math.h> #include <stdarg.h> #endif int msend(int fd, char *buffer, int n) { buffer[n++] = '\r'; buffer[n++] = '\n'; return send(fd, buffer, n, 0); } int mrecv(int fd, char *buffer, int len) { int n; n = recv(fd, buffer, len, 0); if (n < 0) return n; if ((buffer[--n] != '\n') || (buffer[--n] != '\r')) return -1; buffer[n] = '\0'; return n; } int command(int fd, char *frmt, ...) { int r, n; char buffer[1024]; va_list v; va_start(v, frmt); n = vsnprintf(buffer, sizeof(buffer) - 2, frmt, v); va_end(v); r = msend(fd, buffer, n); if (r < 0) return r; r = mrecv(fd, buffer, sizeof(buffer)); if (r < 0) return r; if (strcmp(buffer, "OK") != 0) return -1; return 0; }