network types *_isINVALID

This commit is contained in:
Timerix22 2024-01-03 23:58:11 +06:00
parent 7ba15b208f
commit b430846a0e
3 changed files with 10 additions and 6 deletions

View File

@ -7,6 +7,8 @@ extern "C" {
#include "../base/base.h"
typedef u16 knPort;
#define knPort_INVALID ((knPort)~0)
#define knPort_isINVALID(PORT) (PORT == knPort_INVALID)
typedef union knIPV4Address {
u32 UintBigEndian;
@ -20,9 +22,10 @@ kt_declare(knIPV4Address);
///@return Maybe<knIPV4Address> as Maybe<knIPV4Address>
Maybe knIPV4Address_fromStr(char* addrStr);
#define knIPV4Address_INVALID knIPV4Address_fromBytes(255,255,255,255)
#define knIPV4Address_ANY knIPV4Address_fromBytes(0,0,0,0)
#define knIPV4Address_LOOPBACK knIPV4Address_fromBytes(127,0,0,1)
#define knIPV4Address_INVALID knIPV4Address_fromBytes(255,255,255,255)
#define knIPV4Address_isINVALID(ADDR) (ADDR.UintBigEndian == ~0)
char* knIPV4Address_toString(knIPV4Address* address);
@ -34,7 +37,8 @@ STRUCT(knIPV4Endpoint,
#define knIPV4Endpoint_create(ADDR, PORT) ((knIPV4Endpoint){ADDR, PORT})
#define knIPV4Endpoint_INVALID knIPV4Endpoint_create(knIPV4Address_INVALID, ~0)
#define knIPV4Endpoint_INVALID knIPV4Endpoint_create(knIPV4Address_INVALID, knPort_INVALID)
#define knIPV4Address_isINVALID(ENDP) (knIPV4Address_isINVALID(ENDP.address) || knPort_isINVALID(ENDP.port))
char* knIPV4Endpoint_toString(knIPV4Endpoint* end);

View File

@ -9,8 +9,8 @@ kt_define(knSocketChanneled, __knSocketChanneled_close, NULL);
Maybe knSocketChanneled_open(){
knSocketChanneled* newSocket=malloc(sizeof(knSocketChanneled));
newSocket->localEndpoint=knIPV4Endpoint_create(knIPV4Address_fromBytes(0,0,0,0),0);
newSocket->remoteEndpoint=newSocket->localEndpoint;
newSocket->localEndpoint=knIPV4Endpoint_INVALID;
newSocket->remoteEndpoint=knIPV4Endpoint_INVALID;
newSocket->channels=NULL;
newSocket->channelsAmount=0;
return SUCCESS(UniHeapPtr(knSocketChanneled, newSocket));

View File

@ -6,9 +6,9 @@ kt_define(knSocketUDP, __knSocketUDP_close, NULL);
Maybe knSocketUDP_open(bool allowReuse){
knSocketUDP* newSocket=malloc(sizeof(knSocketUDP));
newSocket->localEndpoint=knIPV4Endpoint_create(knIPV4Address_fromBytes(0,0,0,0),0);
newSocket->localEndpoint=knIPV4Endpoint_INVALID;
newSocket->socketfd=socket(AF_INET, SOCK_DGRAM, 0);
if(newSocket->socketfd==-1)
if(newSocket->socketfd==-1 || newSocket->socketfd == ~0)
safethrow("can't create socket", free(newSocket));
// set value of REUSEADDR socket option