From f621c518887e853fe96c49c5b292acce2f665e96 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 14 Oct 2020 20:48:15 +0800 Subject: [PATCH] struct uh_connection: New api: get_addr Return the host byte order address Signed-off-by: Jianhui Zhao --- src/connection.c | 6 ++++++ src/connection.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/connection.c b/src/connection.c index 2cd3acf..d8691fb 100644 --- a/src/connection.c +++ b/src/connection.c @@ -175,6 +175,11 @@ static void conn_redirect(struct uh_connection *conn, int code, const char *loca conn_done(conn); } +static uint32_t conn_get_addr(struct uh_connection *conn) +{ + return ntohl(conn->addr.sin_addr.s_addr); +} + static enum http_method conn_get_method(struct uh_connection *conn) { return conn->parser.method; @@ -605,6 +610,7 @@ struct uh_connection *uh_new_connection(struct uh_server *srv, int sock, struct conn->chunk_vprintf = conn_chunk_vprintf; conn->chunk_end = conn_chunk_end; + conn->get_addr = conn_get_addr; conn->get_method = conn_get_method; conn->get_method_str = conn_get_method_str; conn->get_path = conn_get_path; diff --git a/src/connection.h b/src/connection.h index 7603be7..ac379a3 100644 --- a/src/connection.h +++ b/src/connection.h @@ -108,6 +108,7 @@ struct uh_connection { void (*chunk_printf)(struct uh_connection *conn, const char *format, ...); void (*chunk_vprintf)(struct uh_connection *conn, const char *format, va_list arg); void (*chunk_end)(struct uh_connection *conn); + uint32_t (*get_addr)(struct uh_connection *conn); enum http_method (*get_method)(struct uh_connection *conn); const char *(*get_method_str)(struct uh_connection *conn); struct uh_str (*get_path)(struct uh_connection *conn);