| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
#ifdef HAVE_CONFIG_H |
|---|
| 32 |
# include "config.h" |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
#include <vlc_common.h> |
|---|
| 36 |
|
|---|
| 37 |
#include <stdlib.h> |
|---|
| 38 |
#include <stdio.h> |
|---|
| 39 |
#include <limits.h> |
|---|
| 40 |
|
|---|
| 41 |
#include <errno.h> |
|---|
| 42 |
#include <assert.h> |
|---|
| 43 |
|
|---|
| 44 |
#ifdef HAVE_FCNTL_H |
|---|
| 45 |
# include <fcntl.h> |
|---|
| 46 |
#endif |
|---|
| 47 |
#ifdef HAVE_SYS_TIME_H |
|---|
| 48 |
# include <sys/time.h> |
|---|
| 49 |
#endif |
|---|
| 50 |
#ifdef HAVE_UNISTD_H |
|---|
| 51 |
# include <unistd.h> |
|---|
| 52 |
#endif |
|---|
| 53 |
#ifdef HAVE_POLL |
|---|
| 54 |
# include <poll.h> |
|---|
| 55 |
#endif |
|---|
| 56 |
|
|---|
| 57 |
#include <vlc_network.h> |
|---|
| 58 |
|
|---|
| 59 |
#ifndef INADDR_ANY |
|---|
| 60 |
# define INADDR_ANY 0x00000000 |
|---|
| 61 |
#endif |
|---|
| 62 |
#ifndef INADDR_NONE |
|---|
| 63 |
# define INADDR_NONE 0xFFFFFFFF |
|---|
| 64 |
#endif |
|---|
| 65 |
|
|---|
| 66 |
#if defined(WIN32) || defined(UNDER_CE) |
|---|
| 67 |
# undef EAFNOSUPPORT |
|---|
| 68 |
# define EAFNOSUPPORT WSAEAFNOSUPPORT |
|---|
| 69 |
#endif |
|---|
| 70 |
|
|---|
| 71 |
#ifdef HAVE_LINUX_DCCP_H |
|---|
| 72 |
|
|---|
| 73 |
# include <linux/dccp.h> |
|---|
| 74 |
# define SOL_DCCP 269 |
|---|
| 75 |
#endif |
|---|
| 76 |
|
|---|
| 77 |
extern int rootwrap_bind (int family, int socktype, int protocol, |
|---|
| 78 |
const struct sockaddr *addr, size_t alen); |
|---|
| 79 |
|
|---|
| 80 |
int net_SetupSocket (int fd) |
|---|
| 81 |
{ |
|---|
| 82 |
#if defined (WIN32) || defined (UNDER_CE) |
|---|
| 83 |
ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 }); |
|---|
| 84 |
#else |
|---|
| 85 |
fcntl (fd, F_SETFD, FD_CLOEXEC); |
|---|
| 86 |
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK); |
|---|
| 87 |
#endif |
|---|
| 88 |
|
|---|
| 89 |
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int)); |
|---|
| 90 |
return 0; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
int net_Socket (vlc_object_t *p_this, int family, int socktype, |
|---|
| 95 |
int protocol) |
|---|
| 96 |
{ |
|---|
| 97 |
int fd = socket (family, socktype, protocol); |
|---|
| 98 |
if (fd == -1) |
|---|
| 99 |
{ |
|---|
| 100 |
if (net_errno != EAFNOSUPPORT) |
|---|
| 101 |
msg_Err (p_this, "cannot create socket: %m"); |
|---|
| 102 |
return -1; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
net_SetupSocket (fd); |
|---|
| 106 |
|
|---|
| 107 |
#ifdef IPV6_V6ONLY |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
if (family == AF_INET6) |
|---|
| 113 |
setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){ 1 }, sizeof (int)); |
|---|
| 114 |
#endif |
|---|
| 115 |
|
|---|
| 116 |
#if defined (WIN32) || defined (UNDER_CE) |
|---|
| 117 |
# ifndef IPV6_PROTECTION_LEVEL |
|---|
| 118 |
# warning Please update your C library headers. |
|---|
| 119 |
# define IPV6_PROTECTION_LEVEL 23 |
|---|
| 120 |
# define PROTECTION_LEVEL_UNRESTRICTED 10 |
|---|
| 121 |
# endif |
|---|
| 122 |
if (family == AF_INET6) |
|---|
| 123 |
setsockopt (fd, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, |
|---|
| 124 |
&(int){ PROTECTION_LEVEL_UNRESTRICTED }, sizeof (int)); |
|---|
| 125 |
#endif |
|---|
| 126 |
|
|---|
| 127 |
#ifdef DCCP_SOCKOPT_SERVICE |
|---|
| 128 |
if (socktype == SOL_DCCP) |
|---|
| 129 |
{ |
|---|
| 130 |
char *dccps = var_CreateGetNonEmptyString (p_this, "dccp-service"); |
|---|
| 131 |
if (dccps != NULL) |
|---|
| 132 |
{ |
|---|
| 133 |
setsockopt (fd, SOL_DCCP, DCCP_SOCKOPT_SERVICE, dccps, |
|---|
| 134 |
(strlen (dccps) + 3) & ~3); |
|---|
| 135 |
free (dccps); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
#endif |
|---|
| 139 |
|
|---|
| 140 |
return fd; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
int *net_Listen (vlc_object_t *p_this, const char *psz_host, |
|---|
| 145 |
int i_port, int protocol) |
|---|
| 146 |
{ |
|---|
| 147 |
struct addrinfo hints, *res; |
|---|
| 148 |
int socktype = SOCK_DGRAM; |
|---|
| 149 |
|
|---|
| 150 |
switch( protocol ) |
|---|
| 151 |
{ |
|---|
| 152 |
case IPPROTO_TCP: |
|---|
| 153 |
socktype = SOCK_STREAM; |
|---|
| 154 |
break; |
|---|
| 155 |
case 33: |
|---|
| 156 |
#ifdef __linux__ |
|---|
| 157 |
# ifndef SOCK_DCCP |
|---|
| 158 |
# define SOCK_DCCP 6 |
|---|
| 159 |
# endif |
|---|
| 160 |
socktype = SOCK_DCCP; |
|---|
| 161 |
#endif |
|---|
| 162 |
break; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
memset (&hints, 0, sizeof( hints )); |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
hints.ai_socktype = SOCK_DGRAM; |
|---|
| 169 |
hints.ai_flags = AI_PASSIVE; |
|---|
| 170 |
|
|---|
| 171 |
msg_Dbg (p_this, "net: listening to %s port %d", psz_host, i_port); |
|---|
| 172 |
|
|---|
| 173 |
int i_val = vlc_getaddrinfo (p_this, psz_host, i_port, &hints, &res); |
|---|
| 174 |
if (i_val) |
|---|
| 175 |
{ |
|---|
| 176 |
msg_Err (p_this, "Cannot resolve %s port %d : %s", psz_host, i_port, |
|---|
| 177 |
vlc_gai_strerror (i_val)); |
|---|
| 178 |
return NULL; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
int *sockv = NULL; |
|---|
| 182 |
unsigned sockc = 0; |
|---|
| 183 |
|
|---|
| 184 |
for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next) |
|---|
| 185 |
{ |
|---|
| 186 |
int fd = net_Socket (p_this, ptr->ai_family, socktype, protocol); |
|---|
| 187 |
if (fd == -1) |
|---|
| 188 |
{ |
|---|
| 189 |
msg_Dbg (p_this, "socket error: %m"); |
|---|
| 190 |
continue; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
#if defined (WIN32) || defined (UNDER_CE) |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen) |
|---|
| 202 |
&& (sizeof (struct sockaddr_storage) >= ptr->ai_addrlen)) |
|---|
| 203 |
{ |
|---|
| 204 |
|
|---|
| 205 |
struct sockaddr_in6 dumb = |
|---|
| 206 |
{ |
|---|
| 207 |
.sin6_family = ptr->ai_addr->sa_family, |
|---|
| 208 |
.sin6_port = ((struct sockaddr_in *)(ptr->ai_addr))->sin_port |
|---|
| 209 |
}; |
|---|
| 210 |
|
|---|
| 211 |
bind (fd, (struct sockaddr *)&dumb, ptr->ai_addrlen); |
|---|
| 212 |
} |
|---|
| 213 |
else |
|---|
| 214 |
#endif |
|---|
| 215 |
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen)) |
|---|
| 216 |
{ |
|---|
| 217 |
net_Close (fd); |
|---|
| 218 |
#if !defined(WIN32) && !defined(UNDER_CE) |
|---|
| 219 |
fd = rootwrap_bind (ptr->ai_family, socktype, |
|---|
| 220 |
protocol ?: ptr->ai_protocol, ptr->ai_addr, |
|---|
| 221 |
ptr->ai_addrlen); |
|---|
| 222 |
if (fd != -1) |
|---|
| 223 |
{ |
|---|
| 224 |
msg_Dbg (p_this, "got socket %d from rootwrap", fd); |
|---|
| 225 |
} |
|---|
| 226 |
else |
|---|
| 227 |
#endif |
|---|
| 228 |
{ |
|---|
| 229 |
msg_Err (p_this, "socket bind error (%m)"); |
|---|
| 230 |
continue; |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)) |
|---|
| 235 |
{ |
|---|
| 236 |
if (net_Subscribe (p_this, fd, ptr->ai_addr, ptr->ai_addrlen)) |
|---|
| 237 |
{ |
|---|
| 238 |
net_Close (fd); |
|---|
| 239 |
continue; |
|---|
| 240 |
} |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
switch (socktype) |
|---|
| 245 |
{ |
|---|
| 246 |
case SOCK_STREAM: |
|---|
| 247 |
case SOCK_RDM: |
|---|
| 248 |
case SOCK_SEQPACKET: |
|---|
| 249 |
#ifdef SOCK_DCCP |
|---|
| 250 |
case SOCK_DCCP: |
|---|
| 251 |
#endif |
|---|
| 252 |
if (listen (fd, INT_MAX)) |
|---|
| 253 |
{ |
|---|
| 254 |
msg_Err (p_this, "socket listen error (%m)"); |
|---|
| 255 |
net_Close (fd); |
|---|
| 256 |
continue; |
|---|
| 257 |
} |
|---|
| 258 |
} |
|---|
| 259 |
|
|---|
| 260 |
int *nsockv = (int *)realloc (sockv, (sockc + 2) * sizeof (int)); |
|---|
| 261 |
if (nsockv != NULL) |
|---|
| 262 |
{ |
|---|
| 263 |
nsockv[sockc++] = fd; |
|---|
| 264 |
sockv = nsockv; |
|---|
| 265 |
} |
|---|
| 266 |
else |
|---|
| 267 |
net_Close (fd); |
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
vlc_freeaddrinfo (res); |
|---|
| 271 |
|
|---|
| 272 |
if (sockv != NULL) |
|---|
| 273 |
sockv[sockc] = -1; |
|---|
| 274 |
|
|---|
| 275 |
return sockv; |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
ssize_t |
|---|
| 288 |
__net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, |
|---|
| 289 |
uint8_t *restrict p_buf, size_t i_buflen, bool waitall) |
|---|
| 290 |
{ |
|---|
| 291 |
size_t i_total = 0; |
|---|
| 292 |
struct pollfd ufd[2] = { |
|---|
| 293 |
{ .fd = fd, .events = POLLIN }, |
|---|
| 294 |
{ .fd = vlc_object_waitpipe (p_this), .events = POLLIN }, |
|---|
| 295 |
}; |
|---|
| 296 |
|
|---|
| 297 |
if (ufd[1].fd == -1) |
|---|
| 298 |
return -1; |
|---|
| 299 |
|
|---|
| 300 |
while (i_buflen > 0) |
|---|
| 301 |
{ |
|---|
| 302 |
ufd[0].revents = ufd[1].revents = 0; |
|---|
| 303 |
|
|---|
| 304 |
if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0) |
|---|
| 305 |
{ |
|---|
| 306 |
if (errno != EINTR) |
|---|
| 307 |
goto error; |
|---|
| 308 |
continue; |
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
#ifndef POLLRDHUP |
|---|
| 312 |
# define POLLRDHUP 0 |
|---|
| 313 |
#endif |
|---|
| 314 |
if (i_total > 0) |
|---|
| 315 |
{ |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) |
|---|
| 320 |
break; |
|---|
| 321 |
if (ufd[1].revents) |
|---|
| 322 |
break; |
|---|
| 323 |
} |
|---|
| 324 |
else |
|---|
| 325 |
{ |
|---|
| 326 |
if (ufd[1].revents) |
|---|
| 327 |
{ |
|---|
| 328 |
assert (p_this->b_die); |
|---|
| 329 |
msg_Dbg (p_this, "socket %d polling interrupted", fd); |
|---|
| 330 |
#if defined(WIN32) || defined(UNDER_CE) |
|---|
| 331 |
WSASetLastError (WSAEINTR); |
|---|
| 332 |
#else |
|---|
| 333 |
errno = EINTR; |
|---|
| 334 |
#endif |
|---|
| 335 |
goto silent; |
|---|
| 336 |
} |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
assert (ufd[0].revents); |
|---|
| 340 |
|
|---|
| 341 |
ssize_t n; |
|---|
| 342 |
if (vs != NULL) |
|---|
| 343 |
{ |
|---|
| 344 |
n = vs->pf_recv (vs->p_sys, p_buf, i_buflen); |
|---|
| 345 |
} |
|---|
| 346 |
else |
|---|
| 347 |
{ |
|---|
| 348 |
#ifdef WIN32 |
|---|
| 349 |
n = recv (fd, p_buf, i_buflen, 0); |
|---|
| 350 |
#else |
|---|
| 351 |
n = read (fd, p_buf, i_buflen); |
|---|
| 352 |
#endif |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
if (n == -1) |
|---|
| 356 |
{ |
|---|
| 357 |
#if defined(WIN32) || defined(UNDER_CE) |
|---|
| 358 |
switch (WSAGetLastError ()) |
|---|
| 359 |
{ |
|---|
| 360 |
case WSAEWOULDBLOCK: |
|---|
| 361 |
|
|---|
| 362 |
continue; |
|---|
| 363 |
|
|---|
| 364 |
case WSAEMSGSIZE: |
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
msg_Err (p_this, "Receive error: " |
|---|
| 370 |
"Increase the mtu size (--mtu option)"); |
|---|
| 371 |
n = i_buflen; |
|---|
| 372 |
break; |
|---|
| 373 |
} |
|---|
| 374 |
#else |
|---|
| 375 |
switch (errno) |
|---|
| 376 |
{ |
|---|
| 377 |
case EAGAIN: |
|---|
| 378 |
case EINTR: |
|---|
| 379 |
continue; |
|---|
| 380 |
} |
|---|
| 381 |
#endif |
|---|
| 382 |
goto error; |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
if (n == 0) |
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
break; |
|---|
| 393 |
|
|---|
| 394 |
i_total += n; |
|---|
| 395 |
p_buf += n; |
|---|
| 396 |
i_buflen -= n; |
|---|
| 397 |
|
|---|
| 398 |
if (!waitall) |
|---|
| 399 |
break; |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
return i_total; |
|---|
| 403 |
|
|---|
| 404 |
error: |
|---|
| 405 |
msg_Err (p_this, "Read error: %m"); |
|---|
| 406 |
silent: |
|---|
| 407 |
return -1; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
ssize_t __net_Write( vlc_object_t *p_this, int fd, const v_socket_t *p_vs, |
|---|
| 413 |
const uint8_t *p_data, size_t i_data ) |
|---|
| 414 |
{ |
|---|
| 415 |
size_t i_total = 0; |
|---|
| 416 |
struct pollfd ufd[2] = { |
|---|
| 417 |
{ .fd = fd, .events = POLLOUT }, |
|---|
| 418 |
{ .fd = vlc_object_waitpipe (p_this), .events = POLLIN }, |
|---|
| 419 |
}; |
|---|
| 420 |
|
|---|
| 421 |
if (ufd[1].fd == -1) |
|---|
| 422 |
return -1; |
|---|
| 423 |
|
|---|
| 424 |
while( i_data > 0 ) |
|---|
| 425 |
{ |
|---|
| 426 |
ssize_t val; |
|---|
| 427 |
|
|---|
| 428 |
ufd[0].revents = ufd[1].revents = 0; |
|---|
| 429 |
|
|---|
| 430 |
if (poll (ufd, 1, -1) == -1) |
|---|
| 431 |
{ |
|---|
| 432 |
if (errno == EINTR) |
|---|
| 433 |
continue; |
|---|
| 434 |
msg_Err (p_this, "Polling error: %m"); |
|---|
| 435 |
return -1; |
|---|
| 436 |
} |
|---|
| 437 |
|
|---|
| 438 |
if (i_total > 0) |
|---|
| 439 |
{ |
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
if (ufd[0].revents & (POLLHUP|POLLERR|POLLNVAL)) |
|---|
| 443 |
break; |
|---|
| 444 |
if (ufd[1].revents) |
|---|
| 445 |
break; |
|---|
| 446 |
} |
|---|
| 447 |
else |
|---|
| 448 |
{ |
|---|
| 449 |
if (ufd[1].revents) |
|---|
| 450 |
{ |
|---|
| 451 |
assert (p_this->b_die); |
|---|
| 452 |
errno = EINTR; |
|---|
| 453 |
goto error; |
|---|
| 454 |
} |
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
if (p_vs != NULL) |
|---|
| 458 |
val = p_vs->pf_send (p_vs->p_sys, p_data, i_data); |
|---|
| 459 |
else |
|---|
| 460 |
#ifdef WIN32 |
|---|
| 461 |
val = send (fd, p_data, i_data, 0); |
|---|
| 462 |
#else |
|---|
| 463 |
val = write (fd, p_data, i_data); |
|---|
| 464 |
#endif |
|---|
| 465 |
|
|---|
| 466 |
if (val == -1) |
|---|
| 467 |
{ |
|---|
| 468 |
if (errno == EINTR) |
|---|
| 469 |
continue; |
|---|
| 470 |
msg_Err (p_this, "Write error: %m"); |
|---|
| 471 |
break; |
|---|
| 472 |
} |
|---|
| 473 |
|
|---|
| 474 |
p_data += val; |
|---|
| 475 |
i_data -= val; |
|---|
| 476 |
i_total += val; |
|---|
| 477 |
} |
|---|
| 478 |
|
|---|
| 479 |
if ((i_total > 0) || (i_data == 0)) |
|---|
| 480 |
return i_total; |
|---|
| 481 |
|
|---|
| 482 |
error: |
|---|
| 483 |
return -1; |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
char *__net_Gets( vlc_object_t *p_this, int fd, const v_socket_t *p_vs ) |
|---|
| 487 |
{ |
|---|
| 488 |
char *psz_line = NULL, *ptr = NULL; |
|---|
| 489 |
size_t i_line = 0, i_max = 0; |
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
for( ;; ) |
|---|
| 493 |
{ |
|---|
| 494 |
if( i_line == i_max ) |
|---|
| 495 |
{ |
|---|
| 496 |
i_max += 1024; |
|---|
| 497 |
psz_line = realloc( psz_line, i_max ); |
|---|
| 498 |
ptr = psz_line + i_line; |
|---|
| 499 |
} |
|---|
| 500 |
|
|---|
| 501 |
if( net_Read( p_this, fd, p_vs, (uint8_t *)ptr, 1, true ) != 1 ) |
|---|
| 502 |
{ |
|---|
| 503 |
if( i_line == 0 ) |
|---|
| 504 |
{ |
|---|
| 505 |
free( psz_line ); |
|---|
| 506 |
return NULL; |
|---|
| 507 |
} |
|---|
| 508 |
break; |
|---|
| 509 |
} |
|---|
| 510 |
|
|---|
| 511 |
if ( *ptr == '\n' ) |
|---|
| 512 |
break; |
|---|
| 513 |
|
|---|
| 514 |
i_line++; |
|---|
| 515 |
ptr++; |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
*ptr-- = '\0'; |
|---|
| 519 |
|
|---|
| 520 |
if( ( ptr >= psz_line ) && ( *ptr == '\r' ) ) |
|---|
| 521 |
*ptr = '\0'; |
|---|
| 522 |
|
|---|
| 523 |
return psz_line; |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
ssize_t net_Printf( vlc_object_t *p_this, int fd, const v_socket_t *p_vs, |
|---|
| 527 |
const char *psz_fmt, ... ) |
|---|
| 528 |
{ |
|---|
| 529 |
int i_ret; |
|---|
| 530 |
va_list args; |
|---|
| 531 |
va_start( args, psz_fmt ); |
|---|
| 532 |
i_ret = net_vaPrintf( p_this, fd, p_vs, psz_fmt, args ); |
|---|
| 533 |
va_end( args ); |
|---|
| 534 |
|
|---|
| 535 |
return i_ret; |
|---|
| 536 |
} |
|---|
| 537 |
|
|---|
| 538 |
ssize_t __net_vaPrintf( vlc_object_t *p_this, int fd, const v_socket_t *p_vs, |
|---|
| 539 |
const char *psz_fmt, va_list args ) |
|---|
| 540 |
{ |
|---|
| 541 |
char *psz; |
|---|
| 542 |
int i_ret; |
|---|
| 543 |
|
|---|
| 544 |
int i_size = vasprintf( &psz, psz_fmt, args ); |
|---|
| 545 |
if( i_size == -1 ) |
|---|
| 546 |
return -1; |
|---|
| 547 |
i_ret = __net_Write( p_this, fd, p_vs, (uint8_t *)psz, i_size ) < i_size |
|---|
| 548 |
? -1 : i_size; |
|---|
| 549 |
free( psz ); |
|---|
| 550 |
|
|---|
| 551 |
return i_ret; |
|---|
| 552 |
} |
|---|
| 553 |
|
|---|
| 554 |
#ifdef WIN32 |
|---|
| 555 |
|
|---|
| 556 |
#else |
|---|
| 557 |
ssize_t vlc_sendmsg (int s, struct msghdr *hdr, int flags) |
|---|
| 558 |
{ |
|---|
| 559 |
return sendmsg (s, hdr, flags); |
|---|
| 560 |
} |
|---|
| 561 |
|
|---|
| 562 |
ssize_t vlc_recvmsg (int s, struct msghdr *hdr, int flags) |
|---|
| 563 |
{ |
|---|
| 564 |
return recvmsg (s, hdr, flags); |
|---|
| 565 |
} |
|---|
| 566 |
#endif |
|---|
| 567 |
|
|---|