Skip to content

Commit

Permalink
Added error checking to UDP socket creation, at various API levels,
Browse files Browse the repository at this point in the history
to stop some bad crash bugs. This also makes it possible for NOS
to eventually do the right thing when trying to pick a proper
ephemeral UDP port number. (Not certain that it's totally ready
for that yet).

Orignal dates:
Jan  7 22:59:34 2019 errlst.c
Jan  7 22:58:15 2019 errno.c
Jan  7 22:57:43 2019 errno.h
Jan  7 22:55:04 2019 socket.c
Jan  7 22:55:01 2019 tcpsock.c
Jan  7 23:00:00 2019 udp.c
Jan  7 23:02:40 2019 udpsock.c
  • Loading branch information
ke6jjj committed Sep 1, 2019
1 parent 4c8aa51 commit 7974b32
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions errlst.c
@@ -1,7 +1,7 @@
/* System error list
*
* Copyright 1991 Phil Karn, KA9Q
* Copyright 2017 Jeremy Cooper, KE6JJJ
* Copyright 2017, 2019 Jeremy Cooper, KE6JJJ
*/
#include "top.h"

Expand All @@ -26,5 +26,6 @@ const char *ksys_errlist[] = {
"address in use", /* 13 - kEADDRINUSE */
"bad file descriptor", /* 14 - kEBADF */
"too many files open", /* 15 - kEMFILE */
"bad address" /* 16 - kEFAULT */
"bad address", /* 16 - kEFAULT */
"out of memory" /* 17 - kENOMEM */
};
1 change: 1 addition & 0 deletions errno.c
Expand Up @@ -26,6 +26,7 @@ translate_sys_errno(int err)
case EBADF: return kEBADF;
case EMFILE: return kEMFILE;
case EFAULT: return kEFAULT;
case ENOMEM: return kENOMEM;
default:
return kEINVAL;
}
Expand Down
3 changes: 2 additions & 1 deletion errno.h
Expand Up @@ -23,7 +23,8 @@ extern const char *ksys_errlist[];
#define kEBADF 14
#define kEMFILE 15
#define kEFAULT 16
#define kEMAX 16
#define kENOMEM 17
#define kEMAX 17

/* Translate native error numbers to KA9Q kerrno */
int translate_sys_errno(int);
Expand Down
1 change: 0 additions & 1 deletion socket.c
Expand Up @@ -205,7 +205,6 @@ int namelen /* Length of name */

/* a bind routine is optional - don't fail if it isn't present */
if(sp->bind != NULL && (*sp->bind)(up) == -1){
kerrno = kEOPNOTSUPP;
free(up->name);
up->name = NULL;
return -1;
Expand Down
5 changes: 5 additions & 0 deletions udp.c
@@ -1,5 +1,6 @@
/* Internet User Data Protocol (UDP)
* Copyright 1991 Phil Karn, KA9Q
* Copyright 2019 Jeremy Cooper, KE6JJJ
*/
#include "top.h"

Expand Down Expand Up @@ -41,6 +42,10 @@ void (*r_upcall)();
return NULL;
}
up = (struct udp_cb *)callocw(1,sizeof (struct udp_cb));
if (up == NULL) {
Net_error = NO_MEM;
return NULL;
}
up->socket.address = lsocket->address;
up->socket.port = lsocket->port;
up->r_upcall = r_upcall;
Expand Down
15 changes: 14 additions & 1 deletion udpsock.c
Expand Up @@ -27,7 +27,20 @@ struct usock *up;
sp = (struct ksockaddr_in *)up->name;
lsock.address = sp->sin_addr.s_addr;
lsock.port = sp->sin_port;
up->cb.udp = open_udp(&lsock,s_urcall);
if ((up->cb.udp = open_udp(&lsock,s_urcall)) == NULL) {
switch (Net_error) {
case NO_MEM:
kerrno = kENOMEM;
break;
case CON_EXISTS:
kerrno = kEADDRINUSE;
break;
default:
kerrno = kEOPNOTSUPP;
break;
}
return -1;
}
up->cb.udp->user = s;
return 0;
}
Expand Down

0 comments on commit 7974b32

Please sign in to comment.