Use size_t for mtu

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-02-16 15:57:03 +00:00
parent 7013d8e323
commit 53f8d31f77
2 changed files with 12 additions and 13 deletions

21
mud.c
View File

@@ -94,8 +94,8 @@ struct mud_path {
uint64_t send_time; uint64_t send_time;
int remote; int remote;
struct { struct {
int remote; size_t remote;
int local; size_t local;
} mtu; } mtu;
unsigned char kiss[MUD_SID_SIZE]; unsigned char kiss[MUD_SID_SIZE];
} conf; } conf;
@@ -179,7 +179,7 @@ struct mud {
int use_next; int use_next;
int aes; int aes;
} crypto; } crypto;
int mtu; size_t mtu;
int tc; int tc;
struct { struct {
int set; int set;
@@ -646,11 +646,10 @@ mud_set_time_tolerance(struct mud *mud, unsigned long msec)
return 0; return 0;
} }
int size_t
mud_get_mtu(struct mud *mud) mud_get_mtu(struct mud *mud)
{ {
int mtu = mud->mtu; size_t mtu = mud->mtu;
struct mud_path *path; struct mud_path *path;
for (path = mud->path; path; path = path->next) { for (path = mud->path; path; path = path->next) {
@@ -663,10 +662,10 @@ mud_get_mtu(struct mud *mud)
return mtu; return mtu;
} }
int size_t
mud_set_mtu(struct mud *mud, int mtu) mud_set_mtu(struct mud *mud, size_t mtu)
{ {
if (mtu <= 0 || mtu > MUD_PACKET_MAX_SIZE) if (mtu > MUD_PACKET_MAX_SIZE)
mtu = MUD_PACKET_MAX_SIZE; mtu = MUD_PACKET_MAX_SIZE;
if (mtu < sizeof(struct mud_packet)) if (mtu < sizeof(struct mud_packet))
@@ -686,7 +685,7 @@ mud_set_mtu(struct mud *mud, int mtu)
if (!mud->mtu) if (!mud->mtu)
mud->mtu = mtu; mud->mtu = mtu;
return 0; return mtu;
} }
static int static int
@@ -1243,7 +1242,7 @@ mud_send(struct mud *mud, const void *data, size_t size, int tc)
if (!size) if (!size)
return 0; return 0;
if (size > (size_t)mud_get_mtu(mud)) { if (size > mud_get_mtu(mud)) {
errno = EMSGSIZE; errno = EMSGSIZE;
return -1; return -1;
} }

4
mud.h
View File

@@ -13,8 +13,8 @@ int mud_get_fd (struct mud *);
int mud_set_key (struct mud *, unsigned char *, size_t); int mud_set_key (struct mud *, unsigned char *, size_t);
int mud_get_key (struct mud *, unsigned char *, size_t *); int mud_get_key (struct mud *, unsigned char *, size_t *);
int mud_set_mtu (struct mud *, int mtu); size_t mud_set_mtu (struct mud *, size_t);
int mud_get_mtu (struct mud *); size_t mud_get_mtu (struct mud *);
int mud_set_send_timeout (struct mud *, unsigned long); int mud_set_send_timeout (struct mud *, unsigned long);
int mud_set_time_tolerance (struct mud *, unsigned long); int mud_set_time_tolerance (struct mud *, unsigned long);