Skip to content

Commit 59409e6

Browse files
authored
Merge pull request #92 from skliper/fix80-v2-plus-general-cleanup
cFS Header Version 2 (includes CCSDS Extended header) support and major update
2 parents d298b9c + eb15866 commit 59409e6

File tree

6 files changed

+968
-513
lines changed

6 files changed

+968
-513
lines changed

Subsystems/cmdUtil/Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
all::
1+
all:
22
gcc -o cmdUtil SendUdp.c cmdUtil.c
33

4+
debug:
5+
gcc -o cmdUtil -DDEBUG -g SendUdp.c cmdUtil.c
6+
7+
thirtytwo:
8+
gcc -o cmdUtil -DDEBUG -g -m32 SendUdp.c cmdUtil.c
9+

Subsystems/cmdUtil/SendUdp.c

+59-52
Original file line numberDiff line numberDiff line change
@@ -23,99 +23,107 @@
2323
#include "SendUdp.h"
2424

2525
#ifdef WIN32
26-
#pragma warning (disable:4786)
27-
#include <winsock2.h>
28-
#include <ws2tcpip.h>
29-
#include <windows.h>
30-
typedef int socklen_t;
26+
#pragma warning(disable : 4786)
27+
#include <winsock2.h>
28+
#include <ws2tcpip.h>
29+
#include <windows.h>
30+
typedef int socklen_t;
3131
#else
32-
#include <sys/types.h>
33-
#include <sys/socket.h>
34-
#include <arpa/inet.h>
35-
#include <netdb.h>
36-
#include <unistd.h>
37-
#include <ctype.h>
38-
#include <stdio.h>
39-
#include <string.h>
40-
#include <stdlib.h>
41-
#define SOCKET int
42-
#define closesocket(fd) close(fd)
32+
#include <sys/types.h>
33+
#include <sys/socket.h>
34+
#include <arpa/inet.h>
35+
#include <netdb.h>
36+
#include <unistd.h>
37+
#include <ctype.h>
38+
#include <stdio.h>
39+
#include <string.h>
40+
#include <stdlib.h>
41+
#define SOCKET int
42+
#define closesocket(fd) close(fd)
4343
#endif
4444

4545
/*
4646
** SendUdp
4747
*/
48-
int SendUdp(char *hostname, char *portNum, char *packetData, int packetSize) {
49-
SOCKET sd;
50-
int rc;
51-
int port;
52-
int errcode;
53-
unsigned int i;
54-
struct sockaddr_in cliAddr;
55-
struct addrinfo hints;
56-
struct addrinfo *result;
57-
58-
#ifdef WIN32
59-
WSADATA wsaData;
60-
WSAStartup(WINSOCK_VERSION, &wsaData);
61-
#endif
62-
63-
if (hostname == NULL) {
48+
int SendUdp(char *hostname, char *portNum, unsigned char *packetData, int packetSize)
49+
{
50+
SOCKET sd;
51+
int rc;
52+
int port;
53+
int errcode;
54+
unsigned int i;
55+
struct sockaddr_in cliAddr;
56+
struct addrinfo hints;
57+
struct addrinfo * result;
58+
59+
#ifdef WIN32
60+
WSADATA wsaData;
61+
WSAStartup(WINSOCK_VERSION, &wsaData);
62+
#endif
63+
64+
if (hostname == NULL)
65+
{
6466
return -1;
6567
}
66-
68+
6769
/*
6870
** Check port
6971
*/
7072
port = atoi(portNum);
71-
if (port == -1) {
73+
if (port == -1)
74+
{
7275
return -2;
7376
}
74-
77+
7578
/*
76-
**Criteria for selecting socket address
79+
**Criteria for selecting socket address
7780
*/
7881
memset(&hints, 0, sizeof(struct addrinfo));
79-
hints.ai_family = AF_INET; /*IPv4*/
82+
hints.ai_family = AF_INET; /*IPv4*/
8083
hints.ai_socktype = SOCK_DGRAM; /*Datagram socket*/
81-
hints.ai_flags = AI_CANONNAME;
84+
hints.ai_flags = AI_CANONNAME;
8285
hints.ai_protocol = 0; /*Any Protocol*/
83-
86+
8487
errcode = getaddrinfo(hostname, portNum, &hints, &result);
85-
if (errcode != 0) {
88+
if (errcode != 0)
89+
{
8690
return -3;
8791
}
8892

8993
printf("sending data to '%s' (IP : %s); port %d\n", result->ai_canonname,
90-
inet_ntoa(((struct sockaddr_in*)result->ai_addr)->sin_addr), port);
94+
inet_ntoa(((struct sockaddr_in *)result->ai_addr)->sin_addr), port);
9195

9296
/*
9397
** Create Socket
9498
*/
9599
sd = socket(AF_INET, SOCK_DGRAM, 0);
96100

97-
if(sd < 0){
101+
if (sd < 0)
102+
{
98103
return -4;
99104
}
100105

101106
/*
102107
** bind any port
103108
*/
104-
cliAddr.sin_family = AF_INET;
109+
cliAddr.sin_family = AF_INET;
105110
cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
106-
cliAddr.sin_port = htons(0);
111+
cliAddr.sin_port = htons(0);
107112

108-
rc = bind(sd, (struct sockaddr *) &cliAddr, sizeof(cliAddr));
109-
if (rc < 0) {
113+
rc = bind(sd, (struct sockaddr *)&cliAddr, sizeof(cliAddr));
114+
if (rc < 0)
115+
{
110116
printf("%s: cannot bind port\n", portNum);
111117
return -5;
112118
}
113119

114120
printf("Data to send:\n");
115121
i = 0;
116-
while (i < packetSize) {
122+
while (i < packetSize)
123+
{
117124
printf("0x%02X ", packetData[i] & 0xFF);
118-
if (++i % 8 == 0) {
125+
if (++i % 8 == 0)
126+
{
119127
puts("");
120128
}
121129
}
@@ -124,11 +132,10 @@ int SendUdp(char *hostname, char *portNum, char *packetData, int packetSize) {
124132
/*
125133
** send the event
126134
*/
127-
rc = sendto(sd, (char*)packetData, packetSize, 0,
128-
result->ai_addr, result->ai_addrlen);
129-
135+
rc = sendto(sd, (char *)packetData, packetSize, 0, result->ai_addr, result->ai_addrlen);
130136

131-
if (rc < 0) {
137+
if (rc < 0)
138+
{
132139
freeaddrinfo(result);
133140
closesocket(sd);
134141
return -6;

Subsystems/cmdUtil/SendUdp.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
** See the License for the specific language governing permissions and
1818
** limitations under the License.
1919
*/
20-
int SendUdp(char *hostname, char *portNum, char *packetData, int packetSize);
20+
#ifndef _sendudp_
21+
#define _sendudp_
2122

23+
int SendUdp(char *hostname, char *portNum, unsigned char *packetData, int packetSize);
24+
25+
#endif /* _sendudp_ */

0 commit comments

Comments
 (0)