~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to oRTP/src/port_fct.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
  The oRTP library is an RTP (Realtime Transport Protocol - rfc1889) stack.
4
 
  Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
5
 
 
6
 
  This library is free software; you can redistribute it and/or
7
 
  modify it under the terms of the GNU Lesser General Public
8
 
  License as published by the Free Software Foundation; either
9
 
  version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
  This library is distributed in the hope that it will be useful,
12
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
  Lesser General Public License for more details.
15
 
 
16
 
  You should have received a copy of the GNU Lesser General Public
17
 
  License along with this library; if not, write to the Free Software
18
 
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
*/
20
 
 
21
 
/* port_fct.h.  define methods to help for portability between unix and win32 */
22
 
 
23
 
 
24
 
#include "rtpsession.h"
25
 
 
26
 
#include "port_fct.h"
27
 
 
28
 
 
29
 
 
30
 
/**
31
 
 * this method is an utility method that calls fnctl() on UNIX or
32
 
 * ioctlsocket on Win32.
33
 
 * int retrun the result of the system method
34
 
 */
35
 
int set_non_blocking_socket (RtpSession *session)
36
 
{
37
 
        
38
 
 
39
 
#ifndef _WIN32
40
 
        return fcntl (session->rtp.socket, F_SETFL, O_NONBLOCK);
41
 
#else
42
 
        unsigned long nonBlock = 1;
43
 
        return ioctlsocket(session->rtp.socket, FIONBIO , &nonBlock);
44
 
#endif
45
 
}
46
 
 
47
 
 
48
 
/**
49
 
 * this method is an utility method that calls close() on UNIX or
50
 
 * closesocket on Win32.
51
 
 * int retrun the result of the system method
52
 
 */
53
 
#ifndef _WIN32
54
 
        int close_socket(gint sock)
55
 
        {
56
 
                return close (sock);
57
 
        }
58
 
#else
59
 
        int close_socket(SOCKET sock)
60
 
        {
61
 
                return closesocket(sock);
62
 
        }
63
 
#endif
64
 
 
65
 
 
66
 
 
67
 
/**
68
 
 * getSocketError() return a string describing the error
69
 
 */
70
 
#ifdef _WIN32
71
 
char *getSocketError()
72
 
{
73
 
        int error = WSAGetLastError ();
74
 
        static char buf[80];
75
 
 
76
 
        switch (error)
77
 
        {
78
 
                case WSANOTINITIALISED: return "Windows sockets not initialized : call WSAStartup";
79
 
                case WSAEADDRINUSE:             return "Local Address already in use";
80
 
                case WSAEADDRNOTAVAIL:  return "The specified address is not a valid address for this machine";
81
 
//              case WSAEFAULT:                 return "";
82
 
//              case WSAEINPROGRESS:    return "";
83
 
                case WSAEINVAL:                 return "The socket is already bound to an address.";
84
 
                case WSAENOBUFS:                return "Not enough buffers available, too many connections.";
85
 
                case WSAENOTSOCK:               return "The descriptor is not a socket.";
86
 
                case WSAECONNRESET:             return "Connection reset by peer";
87
 
/*
88
 
 
89
 
                case : return "";
90
 
                case : return "";
91
 
                case : return "";
92
 
                case : return "";
93
 
                case : return "";
94
 
                case : return "";
95
 
*/
96
 
                default :
97
 
                        sprintf (buf,"Error code : %d", error);
98
 
                        return buf;
99
 
                break;
100
 
        }
101
 
 
102
 
        return buf;
103
 
 
104
 
}
105
 
#endif
106
 
 
107
 
#ifndef _WIN32
108
 
        // Use UNIX inet_aton method
109
 
#else
110
 
        int inet_aton (const char * cp, struct in_addr * addr)
111
 
        {
112
 
                unsigned long retval;
113
 
                
114
 
                retval = inet_addr (cp);
115
 
 
116
 
                if (retval == INADDR_NONE) 
117
 
                {
118
 
                        return -1;
119
 
                }
120
 
                else
121
 
                {
122
 
                        addr->S_un.S_addr = retval;
123
 
                        return 1;
124
 
                }
125
 
        }
126
 
#endif