Есть такая вот функция
int send_sres(uint8_t *rand, char *imsi, uint8_t *sres)
{
//const char* cmdPath = DEFAULT_CMD_PATH;
//char rspPath[200];
//sprintf(rspPath,"/tmp/OpenBTS.console.%d.%8lx",getpid(),time(NULL));
//printf("command socket path is %s\n", cmdPath);
// the socket
int sock = socket(AF_INET,SOCK_DGRAM,0);
if (sock<0) {
perror("opening datagram socket");
exit(1);
}
FILE *bts_addr;
bts_addr = fopen(DEFAULT_BTS_ADDR,"r");
if(bts_addr == NULL)
perror("Error while loading bts_addr file\n");
char *inaddr=NULL;
size_t inaddr_len=0;
getline(&inaddr,&inaddr_len,bts_addr);
fclose(bts_addr);
// destination address
struct sockaddr_in cmdSockName;
memset(&cmdSockName, 0, sizeof(struct sockaddr_in));
cmdSockName.sin_family = AF_INET;
cmdSockName.sin_addr.s_addr = inet_addr(inaddr);
printf("Server addr %s\n", inaddr);
cmdSockName.sin_port = htons(5065);
// locally bound address
struct sockaddr_in rspSockName;
memset(&rspSockName, 0, sizeof(struct sockaddr_in));
rspSockName.sin_family = AF_INET;
rspSockName.sin_addr.s_addr = inet_addr("127.0.0.1");
rspSockName.sin_port=htons(5066);
if (bind(sock, (struct sockaddr *) &rspSockName, sizeof(struct sockaddr_in))) {
perror("binding name to datagram socket");
free(inaddr);
exit(1);
}
char *randc; //fgets(inbuf,199,stdin);
//char *cmd;
char buf[128];
randc=osmo_hexdump_nospc(rand,16);
strcat(strcat(strcat(strcpy(buf, "getsres "), imsi), " "), randc);
printf("rand : %s\n",buf);
// use the socket
if (sendto(sock, buf, sizeof(buf),0,(struct sockaddr*)&cmdSockName,sizeof(struct sockaddr))<0) {
perror("sending datagram");
printf("Error sent to socket\n");
}
else{
printf("We successfully sended rand\n");
}
const int bufsz = 100000;
char resbuf[bufsz];
int nread = recv(sock,resbuf,bufsz-1,0);
if (nread<0) {
perror("receiving response");
}
resbuf[nread] = '\0';
printf("%s\n",resbuf);
if (nread==(bufsz-1)) printf("(response truncated at %d characters)\n",nread);
osmo_hexparse(resbuf,sres,4);
free(inaddr);
close(sock);
}
rand : getsres 250016387796246 89eef4f1949bb3d686fc49179d415847
sending datagram: Invalid argument
Error sent to socket