mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
server interface: ip made to use inet_ntop, mac address and ip to string made common
This commit is contained in:
parent
9315768159
commit
1943e77b24
Binary file not shown.
@ -21,6 +21,8 @@ extern int debugflag;
|
||||
|
||||
// Global variable from communication_funcs.c
|
||||
extern int isControlServer;
|
||||
extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
|
||||
extern void getIpAddressinString(char* cip, uint32_t ip);
|
||||
|
||||
int firmware_compatibility = OK;
|
||||
int firmware_check_done = 0;
|
||||
@ -1213,24 +1215,14 @@ enum externalCommunicationMode getTiming() {
|
||||
int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2) {
|
||||
#ifndef VIRTUAL
|
||||
FILE_LOG(logINFO, ("Configuring MAC\n"));
|
||||
char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50];
|
||||
int src_port = 0xE185;
|
||||
sprintf(src_ip,"%d.%d.%d.%d",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff);
|
||||
sprintf(dst_ip,"%d.%d.%d.%d",(destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff);
|
||||
sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((sourcemac>>40)&0xFF),
|
||||
(unsigned int)((sourcemac>>32)&0xFF),
|
||||
(unsigned int)((sourcemac>>24)&0xFF),
|
||||
(unsigned int)((sourcemac>>16)&0xFF),
|
||||
(unsigned int)((sourcemac>>8)&0xFF),
|
||||
(unsigned int)((sourcemac>>0)&0xFF));
|
||||
sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((destmac>>40)&0xFF),
|
||||
(unsigned int)((destmac>>32)&0xFF),
|
||||
(unsigned int)((destmac>>24)&0xFF),
|
||||
(unsigned int)((destmac>>16)&0xFF),
|
||||
(unsigned int)((destmac>>8)&0xFF),
|
||||
(unsigned int)((destmac>>0)&0xFF));
|
||||
|
||||
|
||||
int src_port = DEFAULT_UDP_SOURCE_PORT;
|
||||
|
||||
char src_mac[50], src_ip[INET_ADDRSTRLEN],dst_mac[50], dst_ip[INET_ADDRSTRLEN];
|
||||
getMacAddressinString(src_mac, 50, sourcemac);
|
||||
getMacAddressinString(dst_mac, 50, destmac);
|
||||
getIpAddressinString(src_ip, sourceip);
|
||||
getIpAddressinString(dst_ip, destip);
|
||||
|
||||
FILE_LOG(logINFO, (
|
||||
"\tSource IP : %s\n"
|
||||
|
@ -47,6 +47,7 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE};
|
||||
#define NORMAL_HIGHVOLTAGE_OUTPUTPORT "/sys/class/hwmon/hwmon5/device/out0_output"
|
||||
#define SPECIAL9M_HIGHVOLTAGE_PORT "/dev/ttyS1"
|
||||
#define SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE (16)
|
||||
#define DEFAULT_UDP_SOURCE_PORT (0xE185)
|
||||
|
||||
/** Default Parameters */
|
||||
#define DEFAULT_NUM_FRAMES (1)
|
||||
|
@ -520,3 +520,19 @@ int Server_SendResult(int fileDes, intType itype, int update, void* retval, int
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void getMacAddressinString(char* cmac, int size, uint64_t mac) {
|
||||
memset(cmac, 0, size);
|
||||
sprintf(cmac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((mac>>40)&0xFF),
|
||||
(unsigned int)((mac>>32)&0xFF),
|
||||
(unsigned int)((mac>>24)&0xFF),
|
||||
(unsigned int)((mac>>16)&0xFF),
|
||||
(unsigned int)((mac>>8)&0xFF),
|
||||
(unsigned int)((mac>>0)&0xFF));
|
||||
}
|
||||
|
||||
void getIpAddressinString(char* cip, uint32_t ip) {
|
||||
memset(cip, 0, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &ip, cip, INET_ADDRSTRLEN);
|
||||
}
|
@ -52,4 +52,19 @@ int Server_VerifyLock();
|
||||
*/
|
||||
int Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize);
|
||||
|
||||
/**
|
||||
* Convert mac address from integer to char array
|
||||
* @param cmac char arrary result
|
||||
* @param size size of char array result
|
||||
* @param mac mac address as an integer
|
||||
*/
|
||||
void getMacAddressinString(char* cmac, int size, uint64_t mac);
|
||||
|
||||
/**
|
||||
* Convert ip address from integer to char array
|
||||
* @param cip char arrary result
|
||||
* @param ip ip address as an integer
|
||||
*/
|
||||
void getIpAddressinString(char* cip, uint32_t ip);
|
||||
|
||||
#endif
|
||||
|
@ -2298,8 +2298,6 @@ int send_update(int file_des) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int configure_mac(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
@ -2323,9 +2321,12 @@ int configure_mac(int file_des) {
|
||||
// dest ip
|
||||
uint32_t dstIp = 0;
|
||||
sscanf(args[1], "%x", &dstIp);
|
||||
FILE_LOG(logDEBUG1, ("Dst Ip Addr: %d.%d.%d.%d = 0x%x \n",
|
||||
(dstIp >> 24) & 0xff, (dstIp >> 16) & 0xff, (dstIp >> 8) & 0xff, (dstIp) & 0xff,
|
||||
dstIp));
|
||||
{
|
||||
char ipstring[INET_ADDRSTRLEN];
|
||||
getIpAddressinString(ipstring, dstIp);
|
||||
FILE_LOG(logINFO, ("Dst Ip Addr: %s\n", ipstring));
|
||||
}
|
||||
|
||||
// dest mac
|
||||
uint64_t dstMac = 0;
|
||||
#ifdef VIRTUAL
|
||||
@ -2333,23 +2334,19 @@ int configure_mac(int file_des) {
|
||||
#else
|
||||
sscanf(args[2], "%llx", &dstMac);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Dst Mac Addr: (0x) "));
|
||||
{
|
||||
int iloop = 5;
|
||||
for (iloop = 5; iloop >= 0; --iloop) {
|
||||
printf ("%x", (unsigned int)(((dstMac >> (8 * iloop)) & 0xFF)));
|
||||
if (iloop > 0) {
|
||||
printf(":");
|
||||
}
|
||||
}
|
||||
char macstring[50];
|
||||
getMacAddressinString(macstring, 50, dstMac);
|
||||
FILE_LOG(logDEBUG1, ("Dst Mac Addr: %s\n", macstring));
|
||||
}
|
||||
FILE_LOG(logDEBUG1, (" = %llx\n", dstMac));
|
||||
// source ip
|
||||
uint32_t srcIp = 0;
|
||||
sscanf(args[3], "%x", &srcIp);
|
||||
FILE_LOG(logDEBUG1, ("Src Ip Addr: %d.%d.%d.%d = 0x%x \n",
|
||||
(srcIp >> 24) & 0xff, (srcIp >> 16) & 0xff, (srcIp >> 8) & 0xff, (srcIp) & 0xff,
|
||||
srcIp));
|
||||
{
|
||||
char ipstring[INET_ADDRSTRLEN];
|
||||
getIpAddressinString(ipstring, srcIp);
|
||||
FILE_LOG(logINFO, ("Src Ip Addr: %s\n", ipstring));
|
||||
}
|
||||
// source mac
|
||||
uint64_t srcMac = 0;
|
||||
#ifdef VIRTUAL
|
||||
@ -2357,17 +2354,11 @@ int configure_mac(int file_des) {
|
||||
#else
|
||||
sscanf(args[4], "%llx", &srcMac);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Src Mac Addr: (0x) "));
|
||||
{
|
||||
int iloop = 5;
|
||||
for (iloop = 5; iloop >= 0; --iloop) {
|
||||
printf("%x", (unsigned int)(((srcMac >> (8 * iloop)) & 0xFF)));
|
||||
if (iloop > 0) {
|
||||
printf(":");
|
||||
}
|
||||
}
|
||||
char macstring[50];
|
||||
getMacAddressinString(macstring, 50, srcMac);
|
||||
FILE_LOG(logDEBUG1, ("Src Mac Addr: %s\n", macstring));
|
||||
}
|
||||
FILE_LOG(logDEBUG1, (" = %llx\n", srcMac));
|
||||
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
// source port 2
|
||||
@ -2379,9 +2370,11 @@ int configure_mac(int file_des) {
|
||||
// dest ip2
|
||||
uint32_t dstIp2 = 0;
|
||||
sscanf(args[6], "%x", &dstIp2);
|
||||
FILE_LOG(logDEBUG1, ("Dst Ip Addr: %d.%d.%d.%d = 0x%x \n",
|
||||
(dstIp2 >> 24) & 0xff, (dstIp2 >> 16) & 0xff, (dstIp2 >> 8) & 0xff, (dstIp2) & 0xff,
|
||||
dstIp2));
|
||||
{
|
||||
char ipstring[INET_ADDRSTRLEN];
|
||||
getIpAddressinString(ipstring, dstIp2);
|
||||
FILE_LOG(logDEBUG1, ("Dst Ip Addr2: %s\n", ipstring));
|
||||
}
|
||||
// dest mac2
|
||||
uint64_t dstMac2 = 0;
|
||||
#ifdef VIRTUAL
|
||||
@ -2389,23 +2382,19 @@ int configure_mac(int file_des) {
|
||||
#else
|
||||
sscanf(args[7], "%llx", &dstMac2);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Dst Mac Addr: (0x) "));
|
||||
{
|
||||
int iloop = 5;
|
||||
for (iloop = 5; iloop >= 0; --iloop) {
|
||||
printf ("%x", (unsigned int)(((dstMac2 >> (8 * iloop)) & 0xFF)));
|
||||
if (iloop > 0) {
|
||||
printf(":");
|
||||
}
|
||||
}
|
||||
char macstring[50];
|
||||
getMacAddressinString(macstring, 50, dstMac2);
|
||||
FILE_LOG(logDEBUG1, ("Dst Mac Addr2: %s\n", macstring));
|
||||
}
|
||||
FILE_LOG(logDEBUG1, (" = %llx\n", dstMac2));
|
||||
// source ip2
|
||||
uint32_t srcIp2 = 0;
|
||||
sscanf(args[8], "%x", &srcIp2);
|
||||
FILE_LOG(logDEBUG1, ("Src Ip Addr: %d.%d.%d.%d = 0x%x \n",
|
||||
(srcIp2 >> 24) & 0xff, (srcIp2 >> 16) & 0xff, (srcIp2 >> 8) & 0xff, (srcIp2) & 0xff,
|
||||
srcIp2));
|
||||
{
|
||||
char ipstring[INET_ADDRSTRLEN];
|
||||
getIpAddressinString(ipstring, srcIp2);
|
||||
FILE_LOG(logDEBUG1, ("Src Ip Addr2: %s\n", ipstring));
|
||||
}
|
||||
// source mac2
|
||||
uint64_t srcMac2 = 0;
|
||||
#ifdef VIRTUAL
|
||||
@ -2413,17 +2402,11 @@ int configure_mac(int file_des) {
|
||||
#else
|
||||
sscanf(args[9], "%llx", &srcMac2);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Src Mac Addr: (0x) "));
|
||||
{
|
||||
int iloop = 5;
|
||||
for (iloop = 5; iloop >= 0; --iloop) {
|
||||
printf("%x", (unsigned int)(((srcMac2 >> (8 * iloop)) & 0xFF)));
|
||||
if (iloop > 0) {
|
||||
printf(":");
|
||||
}
|
||||
}
|
||||
char macstring[50];
|
||||
getMacAddressinString(macstring, 50, srcMac2);
|
||||
FILE_LOG(logDEBUG1, ("Src Mac Addr2: %s\n", macstring));
|
||||
}
|
||||
FILE_LOG(logDEBUG1, (" = %llx\n", srcMac2));
|
||||
|
||||
// number of interfaces
|
||||
int numInterfaces = 0;
|
||||
|
@ -6,5 +6,5 @@
|
||||
#define APILIB 0x190405
|
||||
#define APIRECEIVER 0x190405
|
||||
#define APIGUI 0x190405
|
||||
#define APIEIGER 0x190514
|
||||
#define APICTB 0x190514
|
||||
#define APIEIGER 0x190516
|
||||
|
Loading…
x
Reference in New Issue
Block a user