Hello everybody.
I need a little help.
I'm trying to compile miniSAPserve r for my Xiaomi Router 3G (v1)
If I normally compile the sources for my x86 computer, it works properly.
But when I use the cross compiler for mipsel : when I "make" I have this error :
message.cpp:53:5: error: 'u_long' was not declared in this scope
Do you know where is the problem ?
Thanks
The code that's not working is this one :
u_long ip_server = inet_addr (ip); //TODO automaticaly get it ?
in this file :
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
#include "sapserver.h"
#include "program.h"
#include "message.h"
static const char mime_type[] = "application/sdp";
/*****************************************************************************
* Constructors
*****************************************************************************/
Message::Message(uint16_t v, const char* ip)
{
version = v;
u_long ip_server = inet_addr (ip); //TODO automaticaly get it ?
msg_len = 4
+ 4 /* (IPv4 specific) */
/*+ authentification length (N/A) */
+ sizeof (mime_type);
msg = (uint8_t *)realloc (NULL, msg_len);
if (msg == NULL)
return; // TODO: throw an exception
// Build the Message Header once initialized according to RFC 2974 (SAP)
/* Byte 0 : Version number V1 = 001 (3 bits)
* Address type IPv4/IPv6 = 0/1 (1 bit)
* Reserved 0 (1 bit)
* Message Type ann/del = 0/1 (1 bit)
* Encryption on/off = 0/1 (1 bit)
* Compressed on/off = 0/1 (1 bit) */
msg[0] = 0x20;
//if ( ip_version == SAP_IPV6 ) msg[0] |= 0x10;
//if ( type == SAP_DELETE ) msg[0] |= 0x04;
//if ( encrypted ) msg[0] |= 0x02;
//if ( compressed ) msg[0] |= 0x01;
/* Byte 1 : Authentification length - Not supported */
msg[1] = 0x00;
/* Bytes 2-3 : Message Id Hash */
msg[2] = version & 0xff;
msg[3] = version >> 8;
/* Bytes 4-7 (or 4-19) byte: Originating source */
memcpy (msg + 4, &ip_server, 4);
/* finally MIME type */
memcpy (msg + 8, mime_type, sizeof (mime_type));
}
/*****************************************************************************
* Destructor
*****************************************************************************/
Message::~Message(void)
{
if (msg != NULL)
free (msg);
}
bool Message::AddProgram(Program *p)
{
string sdp = "v=0\r\n"; // SDP version
/* FIXME */
/* RFC 2327 Compliance ? */
if (p->HasCustomSDP())
{
sdp = p->GetCustomSDP();
}
else
{
string ipv = (p->GetAddress().find(':') == string::npos) ? "IP4" : "IP6";
string ver="";
stringstream ssin(ver);
ssin << version;
ver = ssin.str();
sdp += "o=" + p->GetUser() + " " + ver + " 1 IN " + ipv + " "
+ p->GetMachine() + "\r\n";
sdp += "s=" + p->GetName() + "\r\n";
sdp += "u=" + p->GetSite() + "\r\n";
sdp += "c=IN " + ipv + " " + p->GetAddress();
if (ipv == "IP4")
sdp += "/" + p->GetTTL(); /* only IPv4 multicast shall have a TTL */
sdp += "\r\n";
if (p->IsPermanent())
sdp += "t=0 0\r\n";
else
return false;
/* Session level attributes */
sdp += "a=tool:" + (string)PACKAGE_STRING + "\r\n";
if (p->HasPlGroup())
{
sdp += "a=cat:" + p->GetPlGroup() + "\r\n";
sdp += "a=x-plgroup:" + p->GetPlGroup() + "\r\n";
}
/* Media and media-level attributes */
sdp += "a=type:broadcast\r\n";
sdp += "a=charset:UTF-8\r\n";
char portbuf[6];
snprintf(portbuf, sizeof(portbuf), "%u", (unsigned)p->GetPort());
string port = portbuf;
string m = "m=video " + port + " "
+ (p->IsRTP() ? "RTP/AVP 33" : "udp mpeg") +"\r\n";
if (p->IsRTP())
{
m += "a=rtpmap:33 MP2T/90000\r\n";
if (p->IsRTP() & 1)
{
snprintf(portbuf, sizeof(portbuf), "%u", 1 + p->GetPort());
port = portbuf;
m += "a=rtcp:" + port + "\r\n";
}
}
sdp += m;
}
puts (sdp.c_str ());
if (msg_len + sdp.length () > 1024)
//RFC 2974 Chap 6.
return false;
// updates full message
uint8_t *newmsg = (uint8_t *)realloc (msg, msg_len + sdp.length ());
if (newmsg == NULL)
return false;
// TODO: don't identically overwrite earlier programs
memcpy (newmsg + msg_len, sdp.c_str(), sdp.length ());
msg = newmsg;
msg_len += sdp.length ();
return true;
}
I managed to solve the problem by changing the definition of the variable that was causing the problem.
I made a repository on github with the sources modified to be able to compile for OpenWrt :
There is also the binary compiled for MIPS processors
system
Closed
March 18, 2020, 3:15pm
4
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.