-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.c
More file actions
executable file
·132 lines (124 loc) · 4.26 KB
/
socket.c
File metadata and controls
executable file
·132 lines (124 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//******************************************************************************
//******************************************************************************
//
// FILE: socket.c
//
// CLASSES:
//
// DESCRIPTION: General socket functions used by reconn software
//
//******************************************************************************
//
// CONFIDENTIALITY NOTICE:
//
// THIS FILE CONTAINS MATERIAL THAT IS "HARRIS PROPRIETARY INFORMATION" ANY
// REVIEW, RELIANCE, DISTRIBUTION, DISCLOSURE, OR FORWARDING WITHOUT EXPRESSED
// PERMISSION IS STRICTLY PROHIBITED. PLEASE BE SURE TO PROPERLY DISPOSE ANY
// HARDCOPIES OF THIS DOCUMENT.
//
//******************************************************************************
//
// Government Use Rights:
//
// (Applicable only for source code delivered under U. S.
// Government contracts)
//
// RESTRICTED RIGHTS LEGEND
// Use, duplication, or disclosure is subject to restrictions
// stated in the Government's contract with Harris Corporation,
// RF Communications Division. The applicable contract number is
// indicated on the media containing this software. As a minimum,
// the Government has restricted rights in the software as
// defined in DFARS 252.227-7013.
//
// Commercial Use Rights:
//
// (Applicable only for source code procured under contracts other
// than with the U. S. Government)
//
// TRADE SECRET
// Contains proprietary information of Harris Corporation.
//
// Copyright:
// Protected as an unpublished copyright work,
// (c) Harris Corporation
// First fixed in 2004, all rights reserved.
//
//******************************************************************************
//
// HISTORY: Created <MM>/<DD>/<YYYY> by <USER>
// $Header:$
// $Revision: 1.3 $
// $Log:$
//
//******************************************************************************
//******************************************************************************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/socket.h>
#include <errno.h>
#include "reconn.h"
#include "socket.h"
#include "debugMenu.h"
extern short socketPrint;
extern short clientToPrint;
extern int socketIdList[];
int numberOfOpenSocket = 0;
pthread_mutex_t socketMutex = PTHREAD_MUTEX_INITIALIZER;
extern int libiphoned_tx(unsigned char *, unsigned int);
void sendSocket(int socket_fd, unsigned char * buffer_s, int length, int num)
{
int errCode;
int i;
if((socketPrint == TRUE) &&
((clientToPrint == -1) || (socket_fd == socketIdList[clientToPrint])))
{
reconnDebugPrint("%s(%d): ", __FUNCTION__, socket_fd);
for (i = 0; i < length; ++i)
{
reconnDebugPrint("%x ", (unsigned int) buffer_s[i]);
}
reconnDebugPrint("\n\n");
}
errCode = send(socket_fd, buffer_s, length, num);
if(errCode == -1)
{
reconnDebugPrint("%s: socket_fd == %d send failed %d %s\n", __FUNCTION__, socket_fd, errno, strerror(errno));
}
else if(errCode != length)
{
reconnDebugPrint("%s: send failed to send %d bytes\n", __FUNCTION__, length);
}
}
void sendReconnResponse(int socket_fd, unsigned char c1, unsigned char c2, ReconnErrCodes ErrCode, ReconnMasterClientMode mode)
{
ReconnResponsePacket buff;
int length;
ReconnResponsePacket *thePacket = &buff;
memset((char *)&buff, 0 , sizeof(ReconnResponsePacket));
ADD_RSPID_TO_PACKET(GENERIC_RESPONSE, thePacket);
ADD_DATA_LENGTH_TO_PACKET(1, thePacket);
thePacket->messageId.Byte[LOW] = c1;
thePacket->messageId.Byte[HIGH] = c2;
if(ErrCode == RECONN_ERROR_UNKNOWN)
{
length = 0;
}
else
{
length = 1;
thePacket->dataPayload[0] = ErrCode;
}
ADD_DATA_LENGTH_TO_PACKET(length, thePacket);
if(mode == INSERTEDMASTERMODE)
{
// Send response out the 30 pin USB
libiphoned_tx((unsigned char *)thePacket, RECONN_RSPPACKET_HEADER_SIZE + length);
}
else
{
sendSocket(socket_fd, (unsigned char *)thePacket, RECONN_RSPPACKET_HEADER_SIZE + length, 0);
}
}