* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <libubox/blobmsg.h>
+
#include <unistd.h>
#include <stdio.h>
+#include <libubox/blobmsg.h>
+
#include "uclient.h"
+
static void example_header_done(struct uclient *cl)
{
struct blob_attr *cur;
+ char local[INET6_ADDRSTRLEN], remote[INET6_ADDRSTRLEN];
+ int local_port, remote_port;
int rem;
+ uclient_get_addr(local, &local_port, &cl->local_addr);
+ uclient_get_addr(remote, &remote_port, &cl->remote_addr);
+
+ fprintf(stderr, "Connected: %s:%d -> %s:%d\n",
+ local, local_port, remote, remote_port);
+
printf("Headers (%d): \n", cl->status_code);
blobmsg_for_each_attr(cur, cl->meta, rem) {
printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
static void uclient_http_headers_complete(struct uclient_http *uh)
{
enum auth_type auth_type = uh->auth_type;
+ socklen_t sl;
uh->state = HTTP_STATE_RECV_DATA;
uh->uc.meta = uh->meta.head;
return;
}
+ memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr));
+ memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
+
+ sl = sizeof(uh->uc.local_addr);
+ getsockname(uh->ufd.fd.fd, &uh->uc.local_addr.sa, &sl);
+ getpeername(uh->ufd.fd.fd, &uh->uc.remote_addr.sa, &sl);
+
if (uh->uc.cb->header_done)
uh->uc.cb->header_done(&uh->uc);
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <arpa/inet.h>
#include <libubox/ustream-ssl.h>
#include "uclient.h"
#include "uclient-utils.h"
#include "uclient-backend.h"
+char *uclient_get_addr(char *dest, int *port, union uclient_addr *a)
+{
+ int portval;
+ void *ptr;
+
+ switch(a->sa.sa_family) {
+ case AF_INET:
+ ptr = &a->sin.sin_addr;
+ portval = a->sin.sin_port;
+ break;
+ case AF_INET6:
+ ptr = &a->sin6.sin6_addr;
+ portval = a->sin6.sin6_port;
+ break;
+ default:
+ return strcpy(dest, "Unknown");
+ }
+
+ inet_ntop(a->sa.sa_family, ptr, dest, INET6_ADDRSTRLEN);
+ if (port)
+ *port = ntohs(portval);
+
+ return dest;
+}
+
+
struct uclient_url __hidden *
uclient_get_url(const char *url_str, const char *auth_str)
{
#ifndef __LIBUBOX_UCLIENT_H
#define __LIBUBOX_UCLIENT_H
+#include <netinet/in.h>
+
#include <libubox/blob.h>
#include <libubox/ustream.h>
#include <libubox/ustream-ssl.h>
UCLIENT_ERROR_SSL_CN_MISMATCH,
};
+union uclient_addr {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+};
+
struct uclient {
const struct uclient_backend *backend;
const struct uclient_cb *cb;
+ union uclient_addr local_addr, remote_addr;
+
struct uclient_url *url;
void *priv;
int uclient_write(struct uclient *cl, char *buf, int len);
int uclient_request(struct uclient *cl);
+char *uclient_get_addr(char *dest, int *port, union uclient_addr *a);
+
/* HTTP */
extern const struct uclient_backend uclient_backend_http;