Hi Guys
I am trying to send a struct to a UDP socket, but I'm not entirely sure how to cast the structure.
Code:
struct CONNECT_REQUEST {
char headersize ;// = 0x06; //static EIB header size
char protocolversion;// = 0x10; //protocol version (1.0)
char servicetype[1];// = 0x0205; //service type in this case a connect_request
char totallength[1];// = 0x0018; //total length (24 byte)
char controllength;// = 0x08; //HPAI header for control endpoint
char protocoltype;// = 0x01; //0x01 UDP, 0x02 TCP
char IPcontrol[3];//; //four chars for conrtol endpoint IP
char portcontrol[1];// //two chars for control endpoint port must be gleaned during discovery
char datalength ;// = 0x08; //HPAI header length for data endpoint
char IPdata[3]; // //fours chars for data endpoint IP use same IP as control endpoint
char portdata[1];// = 0x0e57; //set data port to 3671 default for EIB
char connectheader;// = 0x02; //connection type structue length
char connecttype;// = 0x04; //connection type in this case tunnelling may need 2 extra bytes.
};
struct CONNECT_REQUEST connect; //creat struct called connect of type CONNECT_REQUEST
Code:
/* construct CONNECT_REQUEST structure */
connect.headersize = 0x06; //static EIB header size
connect.protocolversion = 0x10; //protocol version (1.0)
connect.servicetype[1] = 0x02,0x05; //service type in this case a connect_request
connect.totallength[1] = 0x00,0x18; //total length (24 byte)
connect.controllength = 0x08; //HPAI header for control endpoint
connect.protocoltype = 0x01; //0x01 UDP, 0x02 TCP
connect.IPcontrol[0] = oca, connect.IPcontrol[1] = ocb, connect.IPcontrol[2] = occ, connect.IPcontrol[2] = ocd;//set IP endpoint
connect.portcontrol[0] = recv_str[12]&255, connect.portcontrol[13]&255; //set port number for control endpoint
connect.datalength = 0x08; //HPAI header length for data endpoint
connect.IPdata[0] = oca, connect.IPdata[1] = ocb, connect.IPdata[2] = occ, connect.IPdata[3] = ocd;//set data end point IP
connect.portdata[1] = 0x0e,0x57; //set data port to 3671 default for EIB
connect.connectheader = 0x02; //connection type structue length
connect.connecttype = 0x04; //connection type in this case tunneling 04
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) //Creat UDP socket
DieWithError("UDP socket creation failed\n");
/* construct UDP address structure */
memset(&udp_addr, 0, sizeof(udp_addr)); //set udp_addr struct to 000's using memset
udp_addr.sin_family = AF_INET; //set family type to AF_INET
udp_addr.sin_addr.s_addr = htonl((oca,'.',ocb,'.',occ,'.',ocd)); //set address as any
udp_addr.sin_port = htons(mc_port); //set the port as the same multi cast port
if ((sendto(sock, &connect, sizeof(connect), 0, (struct sockaddr *) &udp_addr, sizeof(mc_addr))) != sizeof(connect)) //send data to socket
DieWithError("sendto() sent incorrect number of bytes");
close(sock);
exit(0);
}
This code compiles, but I get the error Invalid argument when sending to the socket. I have also tried casting to a pointer, but this gives an error when comilping.
Any help would be greatly appreciated