31 lines
640 B
C
31 lines
640 B
C
#include <c_AddrInfo.h>
|
|
|
|
c_err_t c_AddrInfo_Init(c_AddrInfo_t* self,
|
|
int family,
|
|
int socktype,
|
|
int flags,
|
|
const char* server, const char* port) {
|
|
|
|
struct addrinfo hints={0};
|
|
hints.ai_family = family;
|
|
hints.ai_socktype = socktype;
|
|
hints.ai_flags = flags;
|
|
|
|
int err = getaddrinfo(server, port, &hints, &self->addrinfo_p);
|
|
if (err != 0) {
|
|
self->addrinfo_p = NULL;
|
|
return C_ERR_FAIL;
|
|
}
|
|
|
|
return C_ERR_OK;
|
|
}
|
|
|
|
void c_AddrInfo_Destroy(c_AddrInfo_t* self) {
|
|
if (!self || !self->addrinfo_p) {
|
|
return;
|
|
}
|
|
freeaddrinfo(self->addrinfo_p);
|
|
self->addrinfo_p = NULL;
|
|
}
|
|
|