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