mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-27 15:43:42 +08:00
Add SM4-FF1, update socket API
This commit is contained in:
12
src/http.c
12
src/http.c
@@ -120,7 +120,6 @@ int http_get(const char *uri, uint8_t *buf, size_t *contentlen, size_t buflen)
|
||||
char host[128];
|
||||
int port;
|
||||
char path[256];
|
||||
struct hostent *hp;
|
||||
struct sockaddr_in server;
|
||||
tls_socket_t sock = tls_socket_invalid();
|
||||
char get[sizeof(HTTP_GET_TEMPLATE) + sizeof(host) + sizeof(path)];
|
||||
@@ -141,13 +140,10 @@ int http_get(const char *uri, uint8_t *buf, size_t *contentlen, size_t buflen)
|
||||
}
|
||||
|
||||
// connect and send request
|
||||
if (!(hp = gethostbyname(host))) {
|
||||
if (tls_socket_get_addr(host, port, &server) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
server.sin_addr = *((struct in_addr *)hp->h_addr_list[0]);
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(port);
|
||||
|
||||
if (tls_socket_create(&sock, AF_INET, SOCK_STREAM, 0) != 1) {
|
||||
error_print();
|
||||
@@ -198,7 +194,6 @@ int http_post(const char *uri, const char *content_type,
|
||||
char host[128];
|
||||
int port;
|
||||
char path[256];
|
||||
struct hostent *hp;
|
||||
struct sockaddr_in server;
|
||||
tls_socket_t sock = tls_socket_invalid();
|
||||
char post[1024];
|
||||
@@ -223,13 +218,10 @@ int http_post(const char *uri, const char *content_type,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(hp = gethostbyname(host))) {
|
||||
if (tls_socket_get_addr(host, port, &server) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
server.sin_addr = *((struct in_addr *)hp->h_addr_list[0]);
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(port);
|
||||
|
||||
if (tls_socket_create(&sock, AF_INET, SOCK_STREAM, 0) != 1) {
|
||||
error_print();
|
||||
|
||||
Reference in New Issue
Block a user