#include #include #include #include #include #include #if HAVE_STRING_H #include #else #include #endif #if HAVE_STDLIB_H #include #endif #if HAVE_UNISTD_H #include #endif #if HAVE_SYS_SOCKET_H #include #endif #if HAVE_NETINET_IN_H #include #endif #if HAVE_ARPA_INET_H #include #endif #if HAVE_FCNTL_H #include #endif #include #include #include /* * You can write something into opaque that will subsequently get passed back * to your send function if you like. For instance, you might want to * remember where a PDU came from, so that you can send a reply there... */ int netsnmp_tcpbase_recv(netsnmp_transport *t, void *buf, int size, void **opaque, int *olength) { int rc = -1; if (t != NULL && t->sock >= 0) { while (rc < 0) { rc = recvfrom(t->sock, buf, size, 0, NULL, NULL); if (rc < 0 && errno != EINTR) { DEBUGMSGTL(("netsnmp_tcpbase", "recv fd %d err %d (\"%s\")\n", t->sock, errno, strerror(errno))); break; } DEBUGMSGTL(("netsnmp_tcpbase", "recv fd %d got %d bytes\n", t->sock, rc)); } } else { return -1; } if (opaque != NULL && olength != NULL) { if (t->data_length > 0) { if ((*opaque = malloc(t->data_length)) != NULL) { memcpy(*opaque, t->data, t->data_length); *olength = t->data_length; } else { *olength = 0; } } else { *opaque = NULL; *olength = 0; } } return rc; } int netsnmp_tcpbase_send(netsnmp_transport *t, const void *buf, int size, void **opaque, int *olength) { int rc = -1; if (t != NULL && t->sock >= 0) { while (rc < 0) { rc = sendto(t->sock, buf, size, 0, NULL, 0); if (rc < 0 && errno != EINTR) { break; } } } return rc; }