Commit d454a956 authored by Robert Schmidt's avatar Robert Schmidt

Reduce warnings in ASYNC_IF

parent b27cd4dd
...@@ -167,9 +167,8 @@ socket_link_t *new_link_udp_server(int port){ ...@@ -167,9 +167,8 @@ socket_link_t *new_link_udp_server(int port){
socket_link_t *ret = NULL; socket_link_t *ret = NULL;
struct sockaddr_in si_me, si_other; struct sockaddr_in si_me;
int socket_server, i, slen = sizeof(si_other) , recv_bytes; int socket_server = -1;
char buf[1500];
ret = calloc(1, sizeof(socket_link_t)); ret = calloc(1, sizeof(socket_link_t));
if (ret == NULL) { if (ret == NULL) {
...@@ -201,7 +200,7 @@ socket_link_t *new_link_udp_server(int port){ ...@@ -201,7 +200,7 @@ socket_link_t *new_link_udp_server(int port){
return ret; return ret;
error: error:
close(socket_server); if (socket_server != -1) close(socket_server);
if (ret != NULL) close(ret->socket_fd); if (ret != NULL) close(ret->socket_fd);
free(ret); free(ret);
//printf("\n\n\nERROR PROTO_AGENT: ERROR in new_link_udp_server (see above), returning NULL\n"); //printf("\n\n\nERROR PROTO_AGENT: ERROR in new_link_udp_server (see above), returning NULL\n");
...@@ -219,10 +218,9 @@ socket_link_t *new_link_udp_client(char *server, int port){ ...@@ -219,10 +218,9 @@ socket_link_t *new_link_udp_client(char *server, int port){
} }
ret->socket_fd = -1; ret->socket_fd = -1;
struct sockaddr_in si_other, server_info; struct sockaddr_in si_other;
int s, i, slen=sizeof(si_other); int s;
char buf[1500]; socklen_t slen;
char message[1500];
if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){ if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
goto error; goto error;
...@@ -258,14 +256,8 @@ socket_link_t *new_link_sctp_server(int port) ...@@ -258,14 +256,8 @@ socket_link_t *new_link_sctp_server(int port)
{ {
socket_link_t *ret = NULL; socket_link_t *ret = NULL;
ret = calloc(1, sizeof(socket_link_t));
if (ret == NULL) {
LOG_D(PROTO_AGENT, "%s:%d: out of memory\n", __FILE__, __LINE__);
goto error;
}
ret->socket_fd = -1;
int listenSock, temp; int listenSock = -1, temp;
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
listenSock = socket (AF_INET, SOCK_STREAM, IPPROTO_SCTP); listenSock = socket (AF_INET, SOCK_STREAM, IPPROTO_SCTP);
...@@ -296,13 +288,19 @@ socket_link_t *new_link_sctp_server(int port) ...@@ -296,13 +288,19 @@ socket_link_t *new_link_sctp_server(int port)
close(listenSock); close(listenSock);
exit(1); exit(1);
} }
ret = calloc(1, sizeof(socket_link_t));
if (ret == NULL) {
LOG_D(PROTO_AGENT, "%s:%d: out of memory\n", __FILE__, __LINE__);
goto error;
}
ret->socket_fd = -1;
ret->socket_fd = accept (listenSock, (struct sockaddr *) NULL, (int *) NULL); ret->socket_fd = accept (listenSock, NULL, NULL);
return ret; return ret;
error: error:
close(listenSock); if (listenSock != -1) close(listenSock);
if (ret != NULL) close(ret->socket_fd); if (ret != NULL) close(ret->socket_fd);
free(ret); free(ret);
LOG_E(MAC,"ERROR in new_link_sctp_server (see above), returning NULL\n"); LOG_E(MAC,"ERROR in new_link_sctp_server (see above), returning NULL\n");
...@@ -399,13 +397,13 @@ static int socket_udp_receive(int socket_fd, void *buf, int size) ...@@ -399,13 +397,13 @@ static int socket_udp_receive(int socket_fd, void *buf, int size)
LOG_D(PROTO_AGENT,"UDP RECEIVE\n"); LOG_D(PROTO_AGENT,"UDP RECEIVE\n");
struct sockaddr_in client; struct sockaddr_in client;
int slen = sizeof(client); socklen_t slen;
char *s = buf; char *s = buf;
int l; int l;
while (size) { while (size) {
l = recvfrom(socket_fd, s, size, 0, (struct sockaddr *) &client, &slen); l = recvfrom(socket_fd, s, size, 0, (struct sockaddr *) &client, &slen);
getsockname(s, (struct sockaddr *)&client, &slen); getsockname(socket_fd, (struct sockaddr *)&client, &slen);
LOG_D(PROTO_AGENT, "Got message from src port: %u\n", ntohs(client.sin_port)); LOG_D(PROTO_AGENT, "Got message from src port: %u\n", ntohs(client.sin_port));
if (l == -1) goto error; if (l == -1) goto error;
if (l == 0) goto socket_closed; if (l == 0) goto socket_closed;
...@@ -511,7 +509,7 @@ int link_send_packet(socket_link_t *link, void *data, int size, uint16_t proto_t ...@@ -511,7 +509,7 @@ int link_send_packet(socket_link_t *link, void *data, int size, uint16_t proto_t
if (socket_udp_send(link->socket_fd, sizebuf, 4, peer_addr, link->peer_port) == -1) if (socket_udp_send(link->socket_fd, sizebuf, 4, peer_addr, link->peer_port) == -1)
goto error; goto error;
LOG_I(PROTO_AGENT,"sent %d bytes over the channel\n", (int32_t *)sizebuf); LOG_I(PROTO_AGENT,"sent 4 bytes over the channel\n");
link->bytes_sent += 4; link->bytes_sent += 4;
if (socket_udp_send(link->socket_fd, data, size, peer_addr, link->peer_port) == -1) if (socket_udp_send(link->socket_fd, data, size, peer_addr, link->peer_port) == -1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment