12345678910111213141516171819202122232425262728293031323334 |
- #include "tlm.h"
- int tlm_start(){
- return udp_start(CLIENT_PORT);
- }
- int external_start(){
- return udp_start(EXT_CMD_PORT);
- }
- int udp_start(int port){
- int sock;
- struct sockaddr_in addr;
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- assert(sock != -1);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = htonl(CLIENT_IP);
- assert(fcntl(sock, F_SETFL, O_NONBLOCK, 1) != -1);
- int sock_buf_size = 256;
- assert(setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &sock_buf_size, sizeof(int)) != -1);
- assert(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) != -1);
- return sock;
- }
- int recv_external_cmd(int sock, char* payload){
- return recv(sock, payload, sizeof(char), 0);
- }
|