]> git.sesse.net Git - vlc/blob - extras/contrib/src/Patches/live-inet_ntop.patch
65a2a75045f6ecd72ab717a98d8b679f5ca36653
[vlc] / extras / contrib / src / Patches / live-inet_ntop.patch
1 Copyright (C) 2010 RĂ©mi Denis-Courmont.
2 Licensed under GNU General Public License version 2 or higher.
3 diff -ru live.orig/groupsock/Groupsock.cpp live/groupsock/Groupsock.cpp
4 --- live.orig/groupsock/Groupsock.cpp   2010-05-30 01:20:31.000000000 +0300
5 +++ live/groupsock/Groupsock.cpp        2010-06-06 00:34:03.000000000 +0300
6 @@ -331,8 +331,10 @@
7      }
8    }
9    if (DebugLevel >= 3) {
10 +    char buf[16];
11 +
12      env() << *this << ": read " << bytesRead << " bytes from ";
13 -    env() << our_inet_ntoa(fromAddress.sin_addr);
14 +    env() << our_inet_ntoa(fromAddress.sin_addr, buf);
15      if (numMembers > 0) {
16        env() << "; relayed to " << numMembers << " members";
17      }
18 @@ -441,13 +443,14 @@
19  }
20  
21  UsageEnvironment& operator<<(UsageEnvironment& s, const Groupsock& g) {
22 +  char buf[16];
23    UsageEnvironment& s1 = s << timestampString() << " Groupsock("
24                            << g.socketNum() << ": "
25 -                          << our_inet_ntoa(g.groupAddress())
26 +                          << our_inet_ntoa(g.groupAddress(), buf)
27                            << ", " << g.port() << ", ";
28    if (g.isSSM()) {
29      return s1 << "SSM source: "
30 -             <<  our_inet_ntoa(g.sourceFilterAddress()) << ")";
31 +             <<  our_inet_ntoa(g.sourceFilterAddress(), buf) << ")";
32    } else {
33      return s1 << (unsigned)(g.ttl()) << ")";
34    }
35 diff -ru live.orig/groupsock/include/GroupsockHelper.hh live/groupsock/include/GroupsockHelper.hh
36 --- live.orig/groupsock/include/GroupsockHelper.hh      2010-05-30 01:20:31.000000000 +0300
37 +++ live/groupsock/include/GroupsockHelper.hh   2010-06-06 00:34:03.000000000 +0300
38 @@ -124,7 +124,7 @@
39  
40  // The following are implemented in inet.c:
41  extern "C" netAddressBits our_inet_addr(char const*);
42 -extern "C" char* our_inet_ntoa(struct in_addr);
43 +extern "C" char* our_inet_ntoa(struct in_addr, char *);
44  extern "C" struct hostent* our_gethostbyname(char* name);
45  extern "C" void our_srandom(int x);
46  extern "C" long our_random();
47 diff -ru live.orig/groupsock/inet.c live/groupsock/inet.c
48 --- live.orig/groupsock/inet.c  2010-05-30 01:20:31.000000000 +0300
49 +++ live/groupsock/inet.c       2010-06-06 00:39:12.000000000 +0300
50 @@ -21,26 +21,19 @@
51  }
52  
53  char *
54 -our_inet_ntoa(in)
55 -        struct in_addr in;
56 +our_inet_ntoa(in, result)
57 +       struct in_addr in;
58 +       char *result;
59  {
60 -#ifndef VXWORKS
61 -  return inet_ntoa(in);
62 +#ifdef WIN32
63 +  char *ret = inet_ntoa(in);
64 +  if(ret != NULL)
65 +     strncpy(result, ret, 16);
66 +  return ret;
67 +#elif !defined (VXWORKS)
68 +  inet_ntop(AF_INET, &in, result, 16);
69 +  return(result);
70  #else
71 -  /* according the man pages of inet_ntoa :
72 -
73 -     NOTES
74 -     The return value from inet_ntoa() points to a  buffer  which
75 -     is  overwritten on each call.  This buffer is implemented as
76 -     thread-specific data in multithreaded applications.
77 -
78 -     the vxworks version of inet_ntoa allocates a buffer for each
79 -     ip address string, and does not reuse the same buffer.
80 -
81 -     this is merely to simulate the same behaviour (not multithread
82 -     safe though):
83 -  */
84 -  static char result[INET_ADDR_LEN];
85    inet_ntoa_b(in, result);
86    return(result);
87  #endif
88 diff -ru live.orig/liveMedia/DarwinInjector.cpp live/liveMedia/DarwinInjector.cpp
89 --- live.orig/liveMedia/DarwinInjector.cpp      2010-05-30 01:20:31.000000000 +0300
90 +++ live/liveMedia/DarwinInjector.cpp   2010-06-06 00:34:03.000000000 +0300
91 @@ -128,7 +128,8 @@
92        NetAddress const* address = addresses.firstAddress();
93        addr.s_addr = *(unsigned*)(address->data());
94      }
95 -    char const* remoteRTSPServerAddressStr = our_inet_ntoa(addr);
96 +    char buf[16];
97 +    char const* remoteRTSPServerAddressStr = our_inet_ntoa(addr, buf);
98  
99      // Construct a SDP description for the session that we'll be streaming:
100      char const* const sdpFmt =
101 diff -ru live.orig/liveMedia/OnDemandServerMediaSubsession.cpp live/liveMedia/OnDemandServerMediaSubsession.cpp
102 --- live.orig/liveMedia/OnDemandServerMediaSubsession.cpp       2010-05-30 01:20:31.000000000 +0300
103 +++ live/liveMedia/OnDemandServerMediaSubsession.cpp    2010-06-06 00:34:03.000000000 +0300
104 @@ -365,7 +365,8 @@
105    char const* mediaType = rtpSink->sdpMediaType();
106    unsigned char rtpPayloadType = rtpSink->rtpPayloadType();
107    struct in_addr serverAddrForSDP; serverAddrForSDP.s_addr = fServerAddressForSDP;
108 -  char* const ipAddressStr = strDup(our_inet_ntoa(serverAddrForSDP));
109 +  char ipAddressStr[16];
110 +  our_inet_ntoa(serverAddrForSDP, ipAddressStr);
111    char* rtpmapLine = rtpSink->rtpmapLine();
112    char const* rangeLine = rangeSDPLine();
113    char const* auxSDPLine = getAuxSDPLine(rtpSink, inputSource);
114 @@ -398,7 +399,7 @@
115           rangeLine, // a=range:... (if present)
116           auxSDPLine, // optional extra SDP line
117           trackId()); // a=control:<track-id>
118 -  delete[] (char*)rangeLine; delete[] rtpmapLine; delete[] ipAddressStr;
119 +  delete[] (char*)rangeLine; delete[] rtpmapLine;
120  
121    fSDPLines = strDup(sdpLines);
122    delete[] sdpLines;
123 diff -ru live.orig/liveMedia/PassiveServerMediaSubsession.cpp live/liveMedia/PassiveServerMediaSubsession.cpp
124 --- live.orig/liveMedia/PassiveServerMediaSubsession.cpp        2010-05-30 01:20:31.000000000 +0300
125 +++ live/liveMedia/PassiveServerMediaSubsession.cpp     2010-06-06 00:34:03.000000000 +0300
126 @@ -54,7 +54,8 @@
127      char const* auxSDPLine = fRTPSink.auxSDPLine();
128      if (auxSDPLine == NULL) auxSDPLine = "";
129  
130 -    char* const ipAddressStr = strDup(our_inet_ntoa(ipAddress));
131 +    char ipAddressStr[16];
132 +    our_inet_ntoa(ipAddress, ipAddressStr);
133  
134      char const* const sdpFmt =
135        "m=%s %d RTP/AVP %d\r\n"
136 @@ -84,7 +85,7 @@
137             rangeLine, // a=range:... (if present)
138             auxSDPLine, // optional extra SDP line
139             trackId()); // a=control:<track-id>
140 -    delete[] ipAddressStr; delete[] (char*)rangeLine; delete[] rtpmapLine;
141 +    delete[] (char*)rangeLine; delete[] rtpmapLine;
142  
143      fSDPLines = strDup(sdpLines);
144      delete[] sdpLines;
145 diff -ru live.orig/liveMedia/RTSPClient.cpp live/liveMedia/RTSPClient.cpp
146 --- live.orig/liveMedia/RTSPClient.cpp  2010-05-30 01:20:31.000000000 +0300
147 +++ live/liveMedia/RTSPClient.cpp       2010-06-06 00:39:08.000000000 +0300
148 @@ -415,7 +415,8 @@
149  int RTSPClient::connectToServer(int socketNum, portNumBits remotePortNum) {
150    MAKE_SOCKADDR_IN(remoteName, fServerAddress, htons(remotePortNum));
151    if (fVerbosityLevel >= 1) {
152 -    envir() << "Opening connection to " << our_inet_ntoa(remoteName.sin_addr) << ", port " << remotePortNum << "...\n";
153 +    char buf[16];
154 +    envir() << "Opening connection to " << our_inet_ntoa(remoteName.sin_addr, buf) << ", port " << remotePortNum << "...\n";
155    }
156    if (connect(socketNum, (struct sockaddr*) &remoteName, sizeof remoteName) != 0) {
157      if (envir().getErrno() == EINPROGRESS) {
158 diff -ru live.orig/liveMedia/RTSPOverHTTPServer.cpp live/liveMedia/RTSPOverHTTPServer.cpp
159 --- live.orig/liveMedia/RTSPOverHTTPServer.cpp  2010-05-30 01:20:31.000000000 +0300
160 +++ live/liveMedia/RTSPOverHTTPServer.cpp       2010-06-06 00:34:03.000000000 +0300
161 @@ -128,7 +128,8 @@
162    makeSocketNonBlocking(clientSocket);
163    increaseSendBufferTo(envir(), clientSocket, 50*1024);
164  #if defined(DEBUG) || defined(DEBUG_CONNECTIONS)
165 -  fprintf(stderr, "accept()ed connection from %s\n", our_inet_ntoa(clientAddr.sin_addr));
166 +  char buf[16];
167 +  fprintf(stderr, "accept()ed connection from %s\n", our_inet_ntoa(clientAddr.sin_addr, buf));
168  #endif
169  
170    // Create a new object for handling this HTTP connection:
171 diff -ru live.orig/liveMedia/RTSPServer.cpp live/liveMedia/RTSPServer.cpp
172 --- live.orig/liveMedia/RTSPServer.cpp  2010-05-30 01:20:31.000000000 +0300
173 +++ live/liveMedia/RTSPServer.cpp       2010-06-06 00:34:03.000000000 +0300
174 @@ -112,11 +112,12 @@
175    char urlBuffer[100]; // more than big enough for "rtsp://<ip-address>:<port>/"
176  
177    portNumBits portNumHostOrder = ntohs(fServerPort.num());
178 +  char buf[16];
179    if (portNumHostOrder == 554 /* the default port number */) {
180 -    sprintf(urlBuffer, "rtsp://%s/", our_inet_ntoa(ourAddress.sin_addr));
181 +    sprintf(urlBuffer, "rtsp://%s/", our_inet_ntoa(ourAddress.sin_addr, buf));
182    } else {
183      sprintf(urlBuffer, "rtsp://%s:%hu/",
184 -           our_inet_ntoa(ourAddress.sin_addr), portNumHostOrder);
185 +           our_inet_ntoa(ourAddress.sin_addr, buf), portNumHostOrder);
186    }
187  
188    return strDup(urlBuffer);
189 @@ -233,7 +234,8 @@
190    increaseSendBufferTo(envir(), clientSocket, 50*1024);
191  
192  #if defined(DEBUG) || defined(DEBUG_CONNECTIONS)
193 -  envir() << "accept()ed connection from " << our_inet_ntoa(clientAddr.sin_addr) << '\n';
194 +  char buf[16];
195 +  envir() << "accept()ed connection from " << our_inet_ntoa(clientAddr.sin_addr, buf) << '\n';
196  #endif
197  
198    // Create a new object for this RTSP session.
199 @@ -747,10 +749,12 @@
200                                   serverRTPPort, serverRTCPPort,
201                                   fStreamStates[streamNum].streamToken);
202    struct in_addr destinationAddr; destinationAddr.s_addr = destinationAddress;
203 -  char* destAddrStr = strDup(our_inet_ntoa(destinationAddr));
204 +  char destAddrStr[16];
205 +  our_inet_ntoa(destinationAddr, destAddrStr);
206    struct sockaddr_in sourceAddr; SOCKLEN_T namelen = sizeof sourceAddr;
207    getsockname(fClientSocket, (struct sockaddr*)&sourceAddr, &namelen);
208 -  char* sourceAddrStr = strDup(our_inet_ntoa(sourceAddr.sin_addr));
209 +  char sourceAddrStr[16];
210 +  our_inet_ntoa(sourceAddr.sin_addr, sourceAddrStr);
211    if (fIsMulticast) {
212      switch (streamingMode) {
213      case RTP_UDP:
214 @@ -825,7 +829,7 @@
215      }
216      }
217    }
218 -  delete[] destAddrStr; delete[] sourceAddrStr; delete[] streamingModeString;
219 +  delete[] streamingModeString;
220  }
221  
222  void RTSPServer::RTSPClientSession
223 @@ -1226,7 +1230,8 @@
224    // If this gets called, the client session is assumed to have timed out,
225    // so delete it:
226  #ifdef DEBUG
227 -  fprintf(stderr, "RTSP client session from %s has timed out (due to inactivity)\n", our_inet_ntoa(clientSession->fClientAddr.sin_addr));
228 +  char buf[16];
229 +  fprintf(stderr, "RTSP client session from %s has timed out (due to inactivity)\n", our_inet_ntoa(clientSession->fClientAddr.sin_addr, buf));
230  #endif
231    delete clientSession;
232  }
233 diff -ru live.orig/liveMedia/ServerMediaSession.cpp live/liveMedia/ServerMediaSession.cpp
234 --- live.orig/liveMedia/ServerMediaSession.cpp  2010-05-30 01:20:31.000000000 +0300
235 +++ live/liveMedia/ServerMediaSession.cpp       2010-06-06 00:34:03.000000000 +0300
236 @@ -185,7 +185,8 @@
237  char* ServerMediaSession::generateSDPDescription() {
238    struct in_addr ipAddress;
239    ipAddress.s_addr = ourIPAddress(envir());
240 -  char* const ipAddressStr = strDup(our_inet_ntoa(ipAddress));
241 +  char ipAddressStr[16];
242 +  our_inet_ntoa(ipAddress, ipAddressStr);
243    unsigned ipAddressStrSize = strlen(ipAddressStr);
244  
245    // For a SSM sessions, we need a "a=source-filter: incl ..." line also:
246 @@ -281,7 +282,7 @@
247      }
248    } while (0);
249  
250 -  delete[] rangeLine; delete[] sourceFilterLine; delete[] ipAddressStr;
251 +  delete[] rangeLine; delete[] sourceFilterLine;
252    return sdp;
253  }
254  
255 diff -ru live.orig/liveMedia/SIPClient.cpp live/liveMedia/SIPClient.cpp
256 --- live.orig/liveMedia/SIPClient.cpp   2010-05-30 01:20:31.000000000 +0300
257 +++ live/liveMedia/SIPClient.cpp        2010-06-06 00:34:03.000000000 +0300
258 @@ -60,13 +60,14 @@
259  
260    struct in_addr ourAddress;
261    ourAddress.s_addr = ourIPAddress(env); // hack
262 -  fOurAddressStr = strDup(our_inet_ntoa(ourAddress));
263 +  char buf[16];
264 +  fOurAddressStr = strDup(our_inet_ntoa(ourAddress, buf));
265    fOurAddressStrSize = strlen(fOurAddressStr);
266  
267    fOurSocket = new Groupsock(env, ourAddress, 0, 255);
268    if (fOurSocket == NULL) {
269      env << "ERROR: Failed to create socket for addr "
270 -       << our_inet_ntoa(ourAddress) << ": "
271 +       << our_inet_ntoa(ourAddress, buf) << ": "
272         << env.getResultMsg() << "\n";
273    }
274  
275 @@ -84,7 +85,7 @@
276      fOurSocket = new Groupsock(env, ourAddress, fOurPortNum, 255);
277      if (fOurSocket == NULL) {
278        env << "ERROR: Failed to create socket for addr "
279 -         << our_inet_ntoa(ourAddress) << ", port "
280 +         << our_inet_ntoa(ourAddress, buf) << ", port "
281           << fOurPortNum << ": "
282           << env.getResultMsg() << "\n";
283      }
284 diff -ru live.orig/testProgs/sapWatch.cpp live/testProgs/sapWatch.cpp
285 --- live.orig/testProgs/sapWatch.cpp    2010-05-30 01:20:31.000000000 +0300
286 +++ live/testProgs/sapWatch.cpp 2010-06-06 00:34:03.000000000 +0300
287 @@ -49,13 +49,14 @@
288    struct sockaddr_in fromAddress;
289    while (inputGroupsock.handleRead(packet, maxPacketSize,
290                                    packetSize, fromAddress)) {
291 +    char buf[16];
292      printf("\n[packet from %s (%d bytes)]\n",
293 -          our_inet_ntoa(fromAddress.sin_addr), packetSize);
294 +          our_inet_ntoa(fromAddress.sin_addr, buf), packetSize);
295  
296      // Ignore the first 8 bytes (SAP header).
297      if (packetSize < 8) {
298        *env << "Ignoring short packet from "
299 -          << our_inet_ntoa(fromAddress.sin_addr) << "%s!\n";
300 +          << our_inet_ntoa(fromAddress.sin_addr, buf) << "%s!\n";
301        continue;
302      }
303